applied patch from Duong-Khang NGUYEN <neoneurone@users.sf.net>, which
authorTobias Gläßer <tobi.web@gmx.de>
Sun, 21 Dec 2003 14:24:17 +0000 (14:24 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Sun, 21 Dec 2003 14:24:17 +0000 (14:24 +0000)
improves the sound-infrastructure and adds a Debug-Macro.
Furthermore a segfault has been hopefully prevented by me.

SVN-Revision: 32

Makefile
src/defines.h
src/gameloop.c
src/setup.c
src/sound.c
src/sound.h

index 050f821..36313dc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -25,14 +25,17 @@ endif
 JOY=YES
 
 
+#undefine this for non debugging compilation
+
+DEBUG_FLAG=-DDEBUG
+
 # Defaults for Linux:
 
 TARGET=supertux
 TARGET_DEF=LINUX
 
-
 CFLAGS=-Wall -O2 $(SDL_CFLAGS) -DDATA_PREFIX=\"$(DATA_PREFIX)\" \
-       -D$(NOSOUNDFLAG) -D$(TARGET_DEF) -DJOY_$(JOY)
+       -D$(NOSOUNDFLAG) -D$(TARGET_DEF) -DJOY_$(JOY) $(DEBUG_FLAG)
 
 
 # Other definitions:
index 1e56b1f..ffe446a 100644 (file)
@@ -6,33 +6,47 @@
   by Bill Kendrick
   bill@newbreedsoftware.com
   http://www.newbreedsoftware.com/supertux/
-  
+
   April 11, 2000 - August 29, 2002
 */
 
 
-/* Version: */
+#if !defined( SUPERTUX_DEFINES_H )
+
+        #define SUPERTUX_DEFINES_H
+        /* Version: */
+
+        #define VERSION "0.0.5"
+
 
-#define VERSION "0.0.5"
+        /* Frames per second: */
 
+        #define FPS (1000 / 25)
 
-/* Frames per second: */
 
-#define FPS (1000 / 25)
+        /* Joystick buttons and axes: */
 
+        #define JOY_A 0
+        #define JOY_B 1
 
-/* Joystick buttons and axes: */
+        #define JOY_X 0
+        #define JOY_Y 1
 
-#define JOY_A 0
-#define JOY_B 1
 
-#define JOY_X 0
-#define JOY_Y 1
+        /* Booleans: */
 
+        #define NO 0
+        #define YES 1
 
-/* Booleans: */
+        /* Debugging */
 
-#define NO 0
-#define YES 1
+        #ifdef DEBUG
+               #define DEBUG_MSG( msg ) { \
+                       printf( msg ); printf("\n"); \
+                }
+        #else
+               #define DEBUG_MSG( msg ) {}
+        #endif
 
+#endif
 
index b0604a9..a9cca02 100644 (file)
@@ -311,7 +311,7 @@ int i,j;
                    {
                      tux_skidding = SKID_TIME;
 
-                     playsound(sounds[SND_SKID]);
+                     play_sound(sounds[SND_SKID]);
 
                    }
                  tux_dir = RIGHT;
@@ -364,7 +364,7 @@ int i,j;
                      tux_dir == RIGHT)
                    {
                      tux_skidding = SKID_TIME;
-                     playsound(sounds[SND_SKID]);
+                     play_sound(sounds[SND_SKID]);
                    }
                  tux_dir = LEFT;
                }
@@ -444,9 +444,9 @@ int i,j;
                          jumping = YES;
                         
                          if (tux_size == SMALL)
-                           playsound(sounds[SND_JUMP]);
+                           play_sound(sounds[SND_JUMP]);
                          else
-                           playsound(sounds[SND_BIGJUMP]);
+                           play_sound(sounds[SND_BIGJUMP]);
                        }
                    }
                }
@@ -499,8 +499,8 @@ int i,j;
                        
          if (use_sound)
          {
-           if (Mix_PlayingMusic())
-            Mix_HaltMusic();
+           if (playing_music())
+            halt_music();
          }
     
                
@@ -776,7 +776,7 @@ int i,j;
                              if (distro_counter <= 0)
                                change(tux_x, tux_y, scroll_x, 'a');
                              
-                             playsound(sounds[SND_DISTRO]);
+                             play_sound(sounds[SND_DISTRO]);
                              score = score + SCORE_DISTRO;
                              distros++;
                            }
@@ -796,7 +796,7 @@ int i,j;
                              if (distro_counter <= 0)
                                change(tux_x + 31, tux_y, scroll_x, 'a');
                              
-                             playsound(sounds[SND_DISTRO]);
+                             play_sound(sounds[SND_DISTRO]);
                              score = score + SCORE_DISTRO;
                              distros++;
                            }
@@ -844,7 +844,7 @@ int i,j;
        distros = distros - DISTROS_LIFEUP;
        if(lives < MAX_LIVES)
         lives++;
-        playsound(sounds[SND_LIFEUP]); /*We want to hear the sound even, if MAX_LIVES is reached*/
+        play_sound(sounds[SND_LIFEUP]); /*We want to hear the sound even, if MAX_LIVES is reached*/
       }
      
 
@@ -1050,7 +1050,7 @@ int i,j;
 
 
                          /* Play death sound: */
-                         playsound(sounds[SND_FALL]);
+                         play_sound(sounds[SND_FALL]);
                        }
                    }
                }
@@ -1141,19 +1141,19 @@ int i,j;
                      
                      if (upgrades[i].kind == UPGRADE_MINTS)
                        {
-                          playsound(sounds[SND_EXCELLENT]);
+                          play_sound(sounds[SND_EXCELLENT]);
                          tux_size = BIG;
                          super_bkgd_time = 8;
                        }
                      else if (upgrades[i].kind == UPGRADE_COFFEE)
                        {
-                         playsound(sounds[SND_COFFEE]);
+                         play_sound(sounds[SND_COFFEE]);
                          tux_got_coffee = YES;
                          super_bkgd_time = 4;
                        }
                      else if (upgrades[i].kind == UPGRADE_HERRING)
                        {
-                         playsound(sounds[SND_HERRING]);
+                         play_sound(sounds[SND_HERRING]);
                          tux_invincible_time = 200;
                          super_bkgd_time = 4;
                        }
@@ -1283,7 +1283,7 @@ int i,j;
                              bad_guys[i].dir = !bad_guys[i].dir;
                             
                              if (bad_guys[i].mode == KICK)
-                               playsound(sounds[SND_RICOCHET]);
+                               play_sound(sounds[SND_RICOCHET]);
                            }
                        }
                      
@@ -1307,7 +1307,7 @@ int i,j;
                                  
                                  bad_guys[j].dying = FALLING;
                                  bad_guys[j].ym = -8;
-                                 playsound(sounds[SND_FALL]);
+                                 play_sound(sounds[SND_FALL]);
 
                                  add_score(bad_guys[i].x - scroll_x,
                                            bad_guys[i].y, 100);
@@ -1404,7 +1404,7 @@ int i,j;
                          add_score(bad_guys[i].x - scroll_x, bad_guys[i].y,
                                    50 * score_multiplier);
                          
-                         playsound(sounds[SND_SQUISH]);
+                         play_sound(sounds[SND_SQUISH]);
                        }
                      else if (bad_guys[i].kind == BAD_LAPTOP)
                        {
@@ -1438,7 +1438,7 @@ int i,j;
                                    bad_guys[i].y,
                                    25 * score_multiplier);
                         
-                         /* playsound(sounds[SND_SQUISH]); */
+                         /* play_sound(sounds[SND_SQUISH]); */
                        }
                      else if (bad_guys[i].kind == -1)
                        {
@@ -1500,7 +1500,7 @@ int i,j;
                                    {
                                      bad_guys[i].dying = FALLING;
                                      bad_guys[i].ym = -8;
-                                     playsound(sounds[SND_FALL]);
+                                     play_sound(sounds[SND_FALL]);
                                    }
                                }
                            }
@@ -1515,7 +1515,7 @@ int i,j;
                            {
                              bad_guys[i].dying = FALLING;
                              bad_guys[i].ym = -8;
-                             playsound(sounds[SND_FALL]);
+                             play_sound(sounds[SND_FALL]);
                            }
                        }
                    }
@@ -2134,7 +2134,7 @@ int gameloop(void)
   
   
   /* --- MAIN GAME LOOP!!! --- */
-  
+
   done = 0;
   quit = 0;
   frame = 0;
@@ -2168,9 +2168,9 @@ int gameloop(void)
     
       if (use_sound)
         {
-          if (!Mix_PlayingMusic())
+          if (!playing_music())
            {
-             Mix_PlayMusic(song, 1);
+             play_music(song, 1);
            }
         }
       
@@ -2198,8 +2198,8 @@ int gameloop(void)
  
   if (use_sound)
     {
-      if (Mix_PlayingMusic())
-        Mix_HaltMusic();
+      if (playing_music())
+        halt_music();
     }
   
   unloadlevelgfx();
@@ -2231,8 +2231,8 @@ void loadlevel(void)
   char * filename;
   char str[80];
   char * line;
-  
-  
+
+
   /* Reset arrays: */
 
   for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
@@ -2249,7 +2249,7 @@ void loadlevel(void)
 
   for (i = 0; i < NUM_FLOATING_SCORES; i++)
     floating_scores[i].alive = NO;
-  
+
   for (i = 0; i < NUM_UPGRADES; i++)
     upgrades[i].alive = NO;
 
@@ -2258,29 +2258,36 @@ void loadlevel(void)
 
 
   /* Load data file: */
+
   filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20));
+  DEBUG_MSG("Fatal: FIXME QUICKLY : SEGMENTATION FAULT POSSIBLE !");
   sprintf(filename, "%s/levels/level%d.dat", DATA_PREFIX, level);
   fi = fopen(filename, "r");
   if (fi == NULL)
     {
       perror(filename);
       st_shutdown();
+      free(filename);
+      exit(-1);
     }
   free(filename);
-  
+
 
   /* Load header info: */
 
+  
   /* (Level title) */
   fgets(str, 20, fi);
   strcpy(levelname, str);
-
+  levelname[strlen(levelname)-1] = '\0';
+  
   /* (Level theme) */
   fgets(str, 20, fi);
   strcpy(leveltheme, str);
   leveltheme[strlen(leveltheme)-1] = '\0';
 
+  
+
   /* (Time to beat level) */
   fgets(str, 10, fi);
   time_left = atoi(str);
@@ -2289,6 +2296,8 @@ void loadlevel(void)
   fgets(str, 20, fi);
   strcpy(song_title, str);
   song_title[strlen(song_title)-1] = '\0';
+
+  
   
   /* (Level background color) */
   fgets(str, 10, fi);
@@ -2301,23 +2310,27 @@ void loadlevel(void)
   /* (Level width) */
   fgets(str, 10, fi);
   level_width = atoi(str);
-  
+
 
   /* Allocate some space for the line-reading! */
-  
+
   line = (char *) malloc(sizeof(char) * (level_width + 5));
   if (line == NULL)
   {
     fprintf(stderr, "Couldn't allocate space to load level data!");
     exit(1);
   }
-  
-  
+
+
   /* Load the level lines: */
-  
+
   for (y = 0; y < 15; y++)
     {
-      fgets(line, level_width + 5, fi);
+      if(fgets(line, level_width + 5, fi) == NULL)
+      {
+       fprintf(stderr, "Level %s isn't complete!\n",levelname);
+       exit(1);
+      }
       line[strlen(line) - 1] = '\0';
       tiles[y] = strdup(line);
     }
@@ -2394,6 +2407,8 @@ void loadlevel(void)
   SDL_Flip(screen);
   
   SDL_Delay(1000);
+
+  
 }
 
 
@@ -2415,7 +2430,7 @@ void loadlevelgfx(void)
 {
   img_brick[0] = load_level_image("brick0.png", IGNORE_ALPHA);
   img_brick[1] = load_level_image("brick1.png", IGNORE_ALPHA);
-  
+
   img_solid[0] = load_level_image("solid0.png", USE_ALPHA);
   img_solid[1] = load_level_image("solid1.png", USE_ALPHA);
   img_solid[2] = load_level_image("solid2.png", USE_ALPHA);
@@ -2444,7 +2459,7 @@ void loadlevelsong(void)
                                              strlen(song_title) + 8));
 
   sprintf(song_path, "%s/music/%s", DATA_PREFIX, song_title);
-  
+
   song = load_song(song_path);
 
   free(song_path);
@@ -2474,10 +2489,7 @@ void unloadlevelgfx(void)
 
 void unloadlevelsong(void)
 {
-  if (use_sound)
-    {
-      Mix_FreeMusic(song);
-    }
+  free_music(song);
 }
 
 
@@ -2543,7 +2555,7 @@ void loadshared(void)
   
   bigtux_left_jump =
     load_image(DATA_PREFIX "/images/shared/bigtux-left-jump.png", USE_ALPHA);
-  
+
   bigcape_right[0] =
     load_image(DATA_PREFIX "/images/shared/bigcape-right-0.png",
               USE_ALPHA);
@@ -2567,7 +2579,7 @@ void loadshared(void)
   ducktux_left = load_image(DATA_PREFIX
                            "/images/shared/ducktux-left.png",
                            USE_ALPHA);
-  
+
   skidtux_right = load_image(DATA_PREFIX
                             "/images/shared/skidtux-right.png",
                             USE_ALPHA);
@@ -2592,44 +2604,44 @@ void loadshared(void)
 
   img_waves[0] = load_image(DATA_PREFIX "/images/shared/waves-0.png",
                            USE_ALPHA);
-  
+
   img_waves[1] = load_image(DATA_PREFIX "/images/shared/waves-1.png",
                            USE_ALPHA);
-  
+
   img_waves[2] = load_image(DATA_PREFIX "/images/shared/waves-2.png",
                            USE_ALPHA);
-  
-  
+
+
   /* Pole: */
-  
+
   img_pole = load_image(DATA_PREFIX "/images/shared/pole.png", USE_ALPHA);
   img_poletop = load_image(DATA_PREFIX "/images/shared/poletop.png",
                           USE_ALPHA);
-  
-  
+
+
   /* Flag: */
-  
+
   img_flag[0] = load_image(DATA_PREFIX "/images/shared/flag-0.png",
                           USE_ALPHA);
   img_flag[1] = load_image(DATA_PREFIX "/images/shared/flag-1.png",
                           USE_ALPHA);
 
-  
+
   /* Cloud: */
-  
+
   img_cloud[0][0] = load_image(DATA_PREFIX "/images/shared/cloud-00.png",
                               USE_ALPHA);
-  
+
   img_cloud[0][1] = load_image(DATA_PREFIX "/images/shared/cloud-01.png",
                               USE_ALPHA);
-  
+
   img_cloud[0][2] = load_image(DATA_PREFIX "/images/shared/cloud-02.png",
                               USE_ALPHA);
-  
+
   img_cloud[0][3] = load_image(DATA_PREFIX "/images/shared/cloud-03.png",
                               USE_ALPHA);
-  
-  
+
+
   img_cloud[1][0] = load_image(DATA_PREFIX "/images/shared/cloud-10.png",
                               USE_ALPHA);
   
@@ -2654,23 +2666,23 @@ void loadshared(void)
   img_bsod_left[1] = load_image(DATA_PREFIX
                                "/images/shared/bsod-left-1.png",
                                USE_ALPHA);
-  
+
   img_bsod_left[2] = load_image(DATA_PREFIX
                                "/images/shared/bsod-left-2.png",
                                USE_ALPHA);
-  
+
   img_bsod_left[3] = load_image(DATA_PREFIX
                                "/images/shared/bsod-left-3.png",
                                USE_ALPHA);
-  
+
   img_bsod_right[0] = load_image(DATA_PREFIX
                                 "/images/shared/bsod-right-0.png",
                                 USE_ALPHA);
-  
+
   img_bsod_right[1] = load_image(DATA_PREFIX
                                 "/images/shared/bsod-right-1.png",
                                 USE_ALPHA);
-  
+
   img_bsod_right[2] = load_image(DATA_PREFIX
                                 "/images/shared/bsod-right-2.png",
                                 USE_ALPHA);
@@ -2678,46 +2690,46 @@ void loadshared(void)
   img_bsod_right[3] = load_image(DATA_PREFIX
                                 "/images/shared/bsod-right-3.png",
                                 USE_ALPHA);
-  
+
   img_bsod_squished_left = load_image(DATA_PREFIX
                                  "/images/shared/bsod-squished-left.png",
                                  USE_ALPHA);
-  
+
   img_bsod_squished_right = load_image(DATA_PREFIX
                                   "/images/shared/bsod-squished-right.png",
                                   USE_ALPHA);
-  
+
   img_bsod_falling_left = load_image(DATA_PREFIX
                                  "/images/shared/bsod-falling-left.png",
                                  USE_ALPHA);
-  
+
   img_bsod_falling_right = load_image(DATA_PREFIX
                                   "/images/shared/bsod-falling-right.png",
                                   USE_ALPHA);
-  
-  
+
+
   /* (Laptop) */
-  
+
   img_laptop_left[0] = load_image(DATA_PREFIX
                                  "/images/shared/laptop-left-0.png",
                                  USE_ALPHA);
-  
+
   img_laptop_left[1] = load_image(DATA_PREFIX
                                  "/images/shared/laptop-left-1.png",
                                  USE_ALPHA);
-  
+
   img_laptop_left[2] = load_image(DATA_PREFIX
                                  "/images/shared/laptop-left-2.png",
                                  USE_ALPHA);
-  
+
   img_laptop_right[0] = load_image(DATA_PREFIX
                                  "/images/shared/laptop-right-0.png",
                                  USE_ALPHA);
-  
+
   img_laptop_right[1] = load_image(DATA_PREFIX
                                  "/images/shared/laptop-right-1.png",
                                  USE_ALPHA);
-  
+
   img_laptop_right[2] = load_image(DATA_PREFIX
                                  "/images/shared/laptop-right-2.png",
                                  USE_ALPHA);
@@ -2725,16 +2737,16 @@ void loadshared(void)
   img_laptop_flat_left = load_image(DATA_PREFIX
                                    "/images/shared/laptop-flat-left.png",
                                    USE_ALPHA);
-  
+
   img_laptop_flat_right = load_image(DATA_PREFIX
                                     "/images/shared/laptop-flat-right.png",
                                     USE_ALPHA);
-  
-  img_laptop_falling_left = 
+
+  img_laptop_falling_left =
     load_image(DATA_PREFIX
               "/images/shared/laptop-falling-left.png",
               USE_ALPHA);
-  
+
   img_laptop_falling_right =
     load_image(DATA_PREFIX
               "/images/shared/laptop-falling-right.png",
@@ -2742,69 +2754,69 @@ void loadshared(void)
 
 
   /* (Money) */
-  
+
   img_money_left[0] = load_image(DATA_PREFIX
                                 "/images/shared/bag-left-0.png",
                                 USE_ALPHA);
-  
+
   img_money_left[1] = load_image(DATA_PREFIX
                                 "/images/shared/bag-left-1.png",
                                 USE_ALPHA);
-  
+
   img_money_right[0] = load_image(DATA_PREFIX
                                  "/images/shared/bag-right-0.png",
                                  USE_ALPHA);
-  
+
   img_money_right[1] = load_image(DATA_PREFIX
                                  "/images/shared/bag-right-1.png",
                                  USE_ALPHA);
-  
-  
-  
+
+
+
   /* Upgrades: */
-  
+
   img_mints = load_image(DATA_PREFIX "/images/shared/mints.png", USE_ALPHA);
   img_coffee = load_image(DATA_PREFIX "/images/shared/coffee.png", USE_ALPHA);
 
-  
+
   /* Weapons: */
-  
+
   img_bullet = load_image(DATA_PREFIX "/images/shared/bullet.png", USE_ALPHA);
 
   img_red_glow = load_image(DATA_PREFIX "/images/shared/red-glow.png",
                            USE_ALPHA);
-  
-  
+
+
   /* Distros: */
-  
+
   img_distro[0] = load_image(DATA_PREFIX "/images/shared/distro-0.png",
                             USE_ALPHA);
-  
+
   img_distro[1] = load_image(DATA_PREFIX "/images/shared/distro-1.png",
                             USE_ALPHA);
-  
+
   img_distro[2] = load_image(DATA_PREFIX "/images/shared/distro-2.png",
                             USE_ALPHA);
-  
+
   img_distro[3] = load_image(DATA_PREFIX "/images/shared/distro-3.png",
                             USE_ALPHA);
-  
-  
+
+
   /* Herring: */
-  
+
   img_golden_herring =
     load_image(DATA_PREFIX "/images/shared/golden-herring.png",
               USE_ALPHA);
 
-  
+
   /* Super background: */
-  
+
   img_super_bkgd = load_image(DATA_PREFIX "/images/shared/super-bkgd.png",
                              IGNORE_ALPHA);
-  
-  
+
+
   /* Sound effects: */
-  
+
   if (use_sound)
     {
       for (i = 0; i < NUM_SOUNDS; i++)
@@ -2900,11 +2912,8 @@ void unloadshared(void)
   
   SDL_FreeSurface(img_golden_herring);
 
-  if (use_sound)
-    {
-      for (i = 0; i < NUM_SOUNDS; i++)
-        Mix_FreeChunk(sounds[i]);
-    }
+  for (i = 0; i < NUM_SOUNDS; i++)
+    free_chunk(sounds[i]);
 }
 
 
@@ -3121,7 +3130,7 @@ void trybreakbrick(int x, int y, int sx)
          if (distro_counter <= 0)
           change(x, y, sx, 'a');
         
-         playsound(sounds[SND_DISTRO]);
+         play_sound(sounds[SND_DISTRO]);
          score = score + SCORE_DISTRO;
          distros++;
        }
@@ -3141,7 +3150,7 @@ void trybreakbrick(int x, int y, int sx)
       
       /* Get some score: */
       
-      playsound(sounds[SND_BRICK]);
+      play_sound(sounds[SND_BRICK]);
       score = score + SCORE_BRICK;
     }
 }
@@ -3154,7 +3163,7 @@ void bumpbrick(int x, int y, int sx)
   add_bouncy_brick(((x + sx + 1) / 32) * 32,
                   (y / 32) * 32);
   
-  playsound(sounds[SND_BRICK]);
+  play_sound(sounds[SND_BRICK]);
 }
 
 
@@ -3171,7 +3180,7 @@ void tryemptybox(int x, int y, int sx)
          add_bouncy_distro(((x + sx + 1) / 32) * 32,
                            (y / 32) * 32 - 32);
          
-         playsound(sounds[SND_DISTRO]);
+         play_sound(sounds[SND_DISTRO]);
          score = score + SCORE_DISTRO;
          distros++;
        }
@@ -3196,7 +3205,7 @@ void tryemptybox(int x, int y, int sx)
                          UPGRADE_COFFEE);
            }
          
-         playsound(sounds[SND_UPGRADE]);
+         play_sound(sounds[SND_UPGRADE]);
        }
       else if (shape(x, y, sx) == '!')
        {
@@ -3221,7 +3230,7 @@ void trygrabdistro(int x, int y, int sx, int bounciness)
   if (shape(x, y, sx) == '$')
     {
       change(x, y, sx, '.');
-      playsound(sounds[SND_DISTRO]);
+      play_sound(sounds[SND_DISTRO]);
       
       if (bounciness == BOUNCE)
        {
@@ -3407,7 +3416,7 @@ void trybumpbadguy(int x, int y, int sx)
            {
              bad_guys[i].dying = FALLING;
              bad_guys[i].ym = -8;
-             playsound(sounds[SND_FALL]);
+             play_sound(sounds[SND_FALL]);
            }
        }
     }
@@ -3423,7 +3432,7 @@ void trybumpbadguy(int x, int y, int sx)
        {
          upgrades[i].xm = -upgrades[i].xm;
          upgrades[i].ym = -8;
-         playsound(sounds[SND_BUMP_UPGRADE]);
+         play_sound(sounds[SND_BUMP_UPGRADE]);
        }
     }
 }
@@ -3462,7 +3471,7 @@ void killtux(int mode)
 {
   tux_ym = -16;
  
-  playsound(sounds[SND_HURT]);
+  play_sound(sounds[SND_HURT]);
  
   if (tux_dir == RIGHT)
     tux_xm = -8;
@@ -3502,7 +3511,7 @@ void add_bullet(int x, int y, int dir, int xm)
   if (found != -1)
     {
       bullets[found].alive = YES;
-      
+
       if (dir == RIGHT)
        {
          bullets[found].x = x + 32;
@@ -3517,7 +3526,7 @@ void add_bullet(int x, int y, int dir, int xm)
       bullets[found].y = y;
       bullets[found].ym = BULLET_STARTING_YM;
       
-      playsound(sounds[SND_SHOOT]);
+      play_sound(sounds[SND_SHOOT]);
     }
 }
 
index 39e6688..da816ac 100644 (file)
@@ -140,7 +140,7 @@ void st_setup(void)
   
   if (use_sound == YES)
     {
-      if (Mix_OpenAudio(44100, AUDIO_S16, 2, 512) < 0)
+      if (open_audio(44100, AUDIO_S16, 2, 512) < 0)
         {
           fprintf(stderr,
                   "\nWarning: I could not set up audio for 44100 Hz "
index ada78bd..1decace 100644 (file)
 
 #ifndef NOSOUND
 
+/* --- OPEN THE AUDIO DEVICE --- */
+
+int open_audio (int frequency, Uint16 format, int channels, int chunksize)
+{
+  if (use_sound) {
+    return Mix_OpenAudio( frequency, format, channels, chunksize );
+  }
+  else {
+    // let the user think that the audio device was correctly opened
+    // and keep the compiler happy :-D
+    return 0;
+  }
+}
+
+
 /* --- LOAD A SOUND --- */
 
 Mix_Chunk * load_sound(char * file)
 {
   Mix_Chunk * snd;
-  
+
   if (use_sound)
   {
     snd = Mix_LoadWAV(file);
-  
+
     if (snd == NULL)
       st_abort("Can't load", file);
   }
@@ -72,25 +87,27 @@ Mix_Music * load_song(char * file)
 
 
 /* --- PLAY A SOUND --- */
-  
- void playsound(Mix_Chunk * snd)
+
+ void play_sound(Mix_Chunk * snd)
  {
   // this won't call the function if the user has disabled sound
   if (use_sound) {
     Mix_PlayChannel(-1, snd, 0);
   }
 }
+
+
 void free_chunk(Mix_Chunk *chunk)
 {
-  if (use_sound)
+  if (use_sound) {
+    DEBUG_MSG( __PRETTY_FUNCTION__ );
     Mix_FreeChunk( chunk );
+  }
 }
-    
+
 int playing_music(void)
 {
- if (use_sound) {
 if (use_sound) {
     return Mix_PlayingMusic();
   }
   else {
@@ -99,7 +116,7 @@ int playing_music(void)
   }
 }
 
+
 int halt_music(void)
 {
   if (use_sound) {
@@ -109,11 +126,12 @@ int halt_music(void)
     return 0;
   }
 }
+
+
 int play_music(Mix_Music *music, int loops)
 {
   if (use_sound) {
+    DEBUG_MSG(__PRETTY_FUNCTION__);
     return Mix_PlayMusic(music, loops);
   }
   else {
@@ -121,25 +139,26 @@ int play_music(Mix_Music *music, int loops)
     return -1;
   }
 }
+
 
 void free_music(Mix_Music *music)
 {
-  if (use_sound)
+  if (use_sound) {
+    DEBUG_MSG(__PRETTY_FUNCTION__);
     Mix_FreeMusic( music );
+  }
 }
 
 #else
 
+int open_audio (int frequency, int format, int channels, int chunksize)
+{
+  return -1;
+}
+
 void* load_sound(void* file) { return NULL; }
-void playsound(void * snd) {}
+void play_sound(void * snd) {}
 void* load_song(void* file) { return NULL; }
-int Mix_PlayingMusic() { return 0; }
-void Mix_HaltMusic() {}
-int Mix_PlayMusic() { return -1; }
-void Mix_FreeMusic() {}
-void Mix_FreeChunk() {}
-int Mix_OpenAudio(int a, int b, int c, int d) { return -1; }
 
 int playing_music() { return 0; }
 void halt_music() {}
index 825fdd7..96d651c 100644 (file)
@@ -6,7 +6,7 @@
   by Bill Kendrick
   bill@newbreedsoftware.com
   http://www.newbreedsoftware.com/supertux/
-  
+
   April 22, 2000 - July 15, 2002
 */
 
@@ -25,8 +25,10 @@ Mix_Chunk* sounds[NUM_SOUNDS];
 Mix_Music* song;
 
 // functions handling the sound and music
+int open_audio(int frequency, Uint16 format, int channels, int chunksize);
+
 Mix_Chunk * load_sound(char * file);
-void playsound(Mix_Chunk * snd);
+void play_sound(Mix_Chunk * snd);
 Mix_Music * load_song(char * file);
 
 int playing_music(void);
@@ -42,15 +44,11 @@ void* sounds[NUM_SOUNDS];
 void* song;
 
 // fake sound handlers
+int open_audio (int frequency, int format, int channels, int chunksize);
+
 void* load_sound(void* file);
-void playsound(void * snd);
+void play_sound(void * snd);
 void* load_song(void* file);
-int Mix_PlayingMusic();
-void Mix_HaltMusic();
-int Mix_PlayMusic();
-void Mix_FreeMusic();
-void Mix_FreeChunk();
-int Mix_OpenAudio(int a, int b, int c, int d);
 
 int playing_music();
 void halt_music();