rnd-20020424-2-src
[rocksndiamonds.git] / src / init.c
index e5a1738b4840f59a4b2cc3c31fac267cd4f40d71..0a52cc63033eaf3e247f49abfdc2f7ee60e7d4b8 100644 (file)
@@ -151,27 +151,56 @@ void InitNetworkServer()
 #endif
 }
 
+static void ReloadCustomSounds()
+{
+  int i;
+
+  printf("DEBUG: reloading sounds '%s' [%d] ...\n",
+        artwork.sounds_set_current, audio.soundserver_pid);
+
+#if 1
+  FreeAllSounds();
+
+  InitSoundList(NUM_SOUNDS);
+  for(i=0; i<NUM_SOUNDS; i++)
+    LoadSoundToList(sound_name[i], i);
+#endif
+}
+
+static void ReloadCustomMusic()
+{
+  printf("DEBUG: reloading music '%s' [%d] ...\n",
+        artwork.music_set_current, audio.soundserver_pid);
+
+#if 1
+  FreeAllMusic();
+
+  LoadCustomMusic();
+#endif
+}
+
 void InitSound()
 {
   int i;
 
   OpenAudio();
+  SetAudioReloadFunctions(ReloadCustomSounds, ReloadCustomMusic);
 
-  for(i=0; i<NUM_SOUNDS; i++)
-  {
-    if (!LoadSound(sound_name[i]))
-    {
-      audio.sound_available = FALSE;
-      audio.loops_available = FALSE;
-      audio.sound_enabled = FALSE;
+#if 1
+  InitSoundList(NUM_SOUNDS);
 
-      return;
-    }
-  }
+  for(i=0; i<NUM_SOUNDS; i++)
+    LoadSoundToList(sound_name[i], i);
 
-  num_bg_loops = LoadMusic();
+  LoadCustomMusic();
+#endif
 
   StartSoundserver();
+
+#if 0
+  InitReloadSounds(artwork.snd_current->name);
+  InitReloadMusic(artwork.mus_current->name);
+#endif
 }
 
 void InitTileClipmasks()
@@ -424,14 +453,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 +1629,9 @@ void CloseAllAndExit(int exit_value)
   int i;
 
   StopSounds();
-  FreeSounds(NUM_SOUNDS);
   CloseAudio();
+  FreeAllSounds();
+  FreeAllMusic();
 
   FreeTileClipmasks();
   for(i=0; i<NUM_BITMAPS; i++)