rnd-20020430-1-src
[rocksndiamonds.git] / src / init.c
index e5a1738b4840f59a4b2cc3c31fac267cd4f40d71..04259035c0974130239dba5b7af61c46142cab1b 100644 (file)
@@ -45,6 +45,7 @@ static void InitPlayerInfo(void);
 static void InitLevelInfo(void);
 static void InitArtworkInfo(void);
 static void InitNetworkServer(void);
+static void InitSoundServer(void);
 static void InitSound(void);
 static void InitGfx(void);
 static void InitGfxBackground(void);
@@ -74,7 +75,7 @@ void OpenAll(void)
   InitArtworkInfo();           /* needed before loading gfx, sound & music */
 
   InitCounter();
-  InitSound();
+  InitSoundServer();
   InitJoysticks();
   InitRND(NEW_RANDOMIZE);
 
@@ -89,6 +90,7 @@ void OpenAll(void)
 
   InitLevelInfo();
   InitGadgets();               /* needs to know number of level series */
+  InitSound();                 /* needs to know current level directory */
 
   InitGfxBackground();
   InitToons();
@@ -151,37 +153,29 @@ void InitNetworkServer()
 #endif
 }
 
-void InitSound()
+static void InitSoundServer()
 {
-  int i;
-
   OpenAudio();
-
-  for(i=0; i<NUM_SOUNDS; i++)
-  {
-    if (!LoadSound(sound_name[i]))
-    {
-      audio.sound_available = FALSE;
-      audio.loops_available = FALSE;
-      audio.sound_enabled = FALSE;
-
-      return;
-    }
-  }
-
-  num_bg_loops = LoadMusic();
+  InitSoundList(sound_effects, NUM_SOUND_EFFECTS);
 
   StartSoundserver();
 }
 
-void InitTileClipmasks()
+static void InitSound()
+{
+  InitReloadSounds(artwork.snd_current->name);
+  InitReloadMusic(artwork.mus_current->name);
+}
+
+static void InitTileClipmasks()
 {
 #if defined(TARGET_X11)
-  GC copy_clipmask_gc;
   XGCValues clip_gc_values;
   unsigned long clip_gc_valuemask;
 
 #if defined(TARGET_X11_NATIVE)
+  GC copy_clipmask_gc;
+
   static struct
   {
     int start;
@@ -424,14 +418,14 @@ void ReloadCustomArtwork()
 
   if (artwork.sounds_set_current != artwork.snd_current->name)
   {
-    printf("reload sounds ...\n");
+    InitReloadSounds(artwork.snd_current->name);
 
     artwork.sounds_set_current = artwork.snd_current->name;
   }
 
   if (artwork.music_set_current != artwork.mus_current->name)
   {
-    printf("reload music ...\n");
+    InitReloadMusic(artwork.mus_current->name);
 
     artwork.music_set_current = artwork.mus_current->name;
   }
@@ -1600,8 +1594,9 @@ void CloseAllAndExit(int exit_value)
   int i;
 
   StopSounds();
-  FreeSounds(NUM_SOUNDS);
-  CloseAudio();
+  FreeAllSounds();
+  FreeAllMusic();
+  CloseAudio();                /* called after freeing sounds (needed for SDL) */
 
   FreeTileClipmasks();
   for(i=0; i<NUM_BITMAPS; i++)