rnd-20020424-2-src
authorHolger Schemel <info@artsoft.org>
Wed, 24 Apr 2002 01:59:35 +0000 (03:59 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:37:03 +0000 (10:37 +0200)
src/init.c
src/libgame/sound.c
src/libgame/sound.h
src/libgame/system.c
src/libgame/system.h
src/timestamp.h

index eee87022ee3146e7e37a903467f5a88f41fec398..0a52cc63033eaf3e247f49abfdc2f7ee60e7d4b8 100644 (file)
@@ -151,20 +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);
 
+#if 1
   InitSoundList(NUM_SOUNDS);
 
   for(i=0; i<NUM_SOUNDS; i++)
     LoadSoundToList(sound_name[i], i);
 
   LoadCustomMusic();
+#endif
 
   StartSoundserver();
+
+#if 0
+  InitReloadSounds(artwork.snd_current->name);
+  InitReloadMusic(artwork.mus_current->name);
+#endif
 }
 
 void InitTileClipmasks()
index 744c4bd8900c0aaa0947b0a1ac64d42126f494ca..57e61c7093f37c939a99e29f614c78dad6de4f59 100644 (file)
@@ -227,16 +227,82 @@ void SoundServer(void)
 
     if (snd_ctrl.reload_sounds || snd_ctrl.reload_music)
     {
-      for(i=0; i<MAX_SOUNDS_PLAYING; i++)
-       playlist[i] = emptySoundControl;
-      playing_sounds = 0;
+      char *set_name = checked_malloc(snd_ctrl.data_len);
+      TreeInfo **ti_ptr =
+       (snd_ctrl.reload_sounds ? &artwork.snd_current : &artwork.mus_current);
+      TreeInfo *ti = *ti_ptr;
+      unsigned long str_size1, str_size2, str_size3;
+
+      printf("B\n");
+
+      if (leveldir_current == NULL)
+       leveldir_current = checked_calloc(sizeof(TreeInfo));
+      printf("B.1\n");
+      if (ti == NULL)
+       ti = *ti_ptr = checked_calloc(sizeof(TreeInfo));
+      printf("B.2\n");
+      if (leveldir_current->fullpath != NULL)
+       free(leveldir_current->fullpath);
+      printf("B.3 ['%s']\n", ti->basepath);
+#if 0
+      if (ti->basepath != NULL)
+       free(ti->basepath);
+#endif
+      printf("B.4\n");
+      if (ti->fullpath != NULL)
+       free(ti->fullpath);
+      printf("B.5\n");
+
+      printf("C\n");
+
+      if (read(audio.soundserver_pipe[0], set_name,
+              snd_ctrl.data_len) != snd_ctrl.data_len ||
+         read(audio.soundserver_pipe[0], leveldir_current,
+              sizeof(TreeInfo)) != sizeof(TreeInfo) ||
+         read(audio.soundserver_pipe[0], ti,
+              sizeof(TreeInfo)) != sizeof(TreeInfo) ||
+         read(audio.soundserver_pipe[0], &str_size1,
+              sizeof(unsigned long)) != sizeof(unsigned long) ||
+         read(audio.soundserver_pipe[0], &str_size2,
+              sizeof(unsigned long)) != sizeof(unsigned long) ||
+         read(audio.soundserver_pipe[0], &str_size3,
+              sizeof(unsigned long)) != sizeof(unsigned long))
+       Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds");
+
+      printf("D\n");
+
+      leveldir_current->fullpath = checked_calloc(str_size1);
+      ti->basepath = checked_calloc(str_size2);
+      ti->fullpath = checked_calloc(str_size3);
+
+      if (read(audio.soundserver_pipe[0], leveldir_current->fullpath,
+              str_size1) != str_size1 ||
+         read(audio.soundserver_pipe[0], ti->basepath,
+              str_size2) != str_size2 ||
+         read(audio.soundserver_pipe[0], ti->fullpath,
+              str_size3) != str_size3)
+       Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds");
+
+      printf("E\n");
+
+      InitPlaylist();
 
       close(audio.device_fd);
 
+      printf("X\n");
+
       if (snd_ctrl.reload_sounds)
-       ReloadSounds();
+      {
+       artwork.sounds_set_current = set_name;
+       audio.func_reload_sounds();
+      }
       else
-       ReloadMusic();
+      {
+       artwork.music_set_current = set_name;
+       audio.func_reload_music();
+      }
+
+      free(set_name);
 
       continue;
     }
@@ -317,9 +383,9 @@ void SoundServer(void)
        if (snd_ctrl.active)    /* new sound has arrived */
          SoundServer_InsertNewSound(snd_ctrl);
 
-       while(playing_sounds &&
-             select(audio.soundserver_pipe[0] + 1,
-                    &sound_fdset, NULL, NULL, &delay) < 1)
+       while (playing_sounds &&
+              select(audio.soundserver_pipe[0] + 1,
+                     &sound_fdset, NULL, NULL, &delay) < 1)
        {       
          FD_SET(audio.soundserver_pipe[0], &sound_fdset);
 
@@ -442,9 +508,9 @@ void SoundServer(void)
       {
        playing_sounds = 1;
 
-       while(playing_sounds &&
-             select(audio.soundserver_pipe[0] + 1,
-                    &sound_fdset, NULL, NULL, &delay) < 1)
+       while (playing_sounds &&
+              select(audio.soundserver_pipe[0] + 1,
+                     &sound_fdset, NULL, NULL, &delay) < 1)
        {       
          FD_SET(audio.soundserver_pipe[0], &sound_fdset);
 
@@ -956,16 +1022,6 @@ static int ulaw_to_linear(unsigned char ulawbyte)
 /* ========================================================================= */
 /* THE STUFF BELOW IS ONLY USED BY THE MAIN PROCESS                          */
 
-void ReloadSounds()
-{
-  printf("reloading sounds ...\n");
-}
-
-void ReloadMusic()
-{
-  printf("reloading music ...\n");
-}
-
 #define CHUNK_ID_LEN            4       /* IFF style chunk id length */
 #define WAV_HEADER_SIZE                16      /* size of WAV file header */
 
@@ -1097,6 +1153,8 @@ SoundInfo *LoadCustomSound(char *basename)
     return FALSE;
   }
 
+  printf("-> '%s'\n", filename);
+
   return Load_WAV(filename);
 }
 
@@ -1372,8 +1430,8 @@ void StopSoundExt(int nr, int method)
       Mix_HaltMusic();
   }
 
-#else
-#if !defined(PLATFORM_MSDOS)
+#elif !defined(PLATFORM_MSDOS)
+
   if (audio.soundserver_pid == 0)      /* we are child process */
     return;
 
@@ -1386,59 +1444,75 @@ void StopSoundExt(int nr, int method)
 #else
   sound_handler(snd_ctrl);
 #endif
-#endif
 }
 
-void InitReloadSounds(char *set_name)
+static void InitReloadSoundsOrMusic(char *set_name, int type)
 {
   struct SoundControl snd_ctrl = emptySoundControl;
+  TreeInfo *ti =
+    (type == SND_RELOAD_SOUNDS ? artwork.snd_current : artwork.mus_current);
+  unsigned long str_size1 = strlen(leveldir_current->fullpath) + 1;
+  unsigned long str_size2 = strlen(ti->basepath) + 1;
+  unsigned long str_size3 = strlen(ti->fullpath) + 1;
 
   if (!audio.sound_available)
     return;
 
-  snd_ctrl.reload_sounds = TRUE;
+  if (leveldir_current == NULL)
+    Error(ERR_EXIT, "leveldir_current == NULL");
 
-#if defined(TARGET_SDL)
-  ReloadSounds();
+  snd_ctrl.reload_sounds = (type == SND_RELOAD_SOUNDS);
+  snd_ctrl.reload_music  = (type == SND_RELOAD_MUSIC);
+  snd_ctrl.data_len = strlen(set_name) + 1;
+
+#if defined(TARGET_SDL) || defined(TARGET_ALLEGRO)
+  if (type == SND_RELOAD_SOUNDS)
+    audio.audio.func_reload_sounds();
+  else
+    audio.audio.func_reload_music();
 #elif defined(PLATFORM_UNIX)
   if (audio.soundserver_pid == 0)      /* we are child process */
     return;
 
-  if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
+  if (write(audio.soundserver_pipe[1], &snd_ctrl,
+           sizeof(snd_ctrl)) < 0 ||
+      write(audio.soundserver_pipe[1], set_name,
+           snd_ctrl.data_len) < 0 ||
+      write(audio.soundserver_pipe[1], leveldir_current,
+           sizeof(TreeInfo)) < 0 ||
+      write(audio.soundserver_pipe[1], ti,
+           sizeof(TreeInfo)) < 0 ||
+      write(audio.soundserver_pipe[1], &str_size1,
+           sizeof(unsigned long)) < 0 ||
+      write(audio.soundserver_pipe[1], &str_size2,
+           sizeof(unsigned long)) < 0 ||
+      write(audio.soundserver_pipe[1], &str_size3,
+           sizeof(unsigned long)) < 0 ||
+      write(audio.soundserver_pipe[1], leveldir_current->fullpath,
+           str_size1) < 0 ||
+      write(audio.soundserver_pipe[1], ti->basepath,
+           str_size2) < 0 ||
+      write(audio.soundserver_pipe[1], ti->fullpath,
+           str_size3) < 0)
   {
     Error(ERR_WARN, "cannot pipe to child process -- no sounds");
     audio.sound_available = audio.sound_enabled = FALSE;
     return;
   }
-#elif defined(PLATFORM_MSDOS)
-  sound_handler(snd_ctrl);
+
+  printf("A\n");
+
 #endif
 }
 
-void InitReloadMusic(char *set_name)
+void InitReloadSounds(char *set_name)
 {
-  struct SoundControl snd_ctrl = emptySoundControl;
-
-  if (!audio.sound_available)
-    return;
-
-  snd_ctrl.reload_music = TRUE;
-
-#if defined(TARGET_SDL)
-  ReloadMusic();
-#elif defined(PLATFORM_UNIX)
-  if (audio.soundserver_pid == 0)      /* we are child process */
-    return;
+  InitReloadSoundsOrMusic(set_name, SND_RELOAD_SOUNDS);
+}
 
-  if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
-  {
-    Error(ERR_WARN, "cannot pipe to child process -- no sounds");
-    audio.sound_available = audio.sound_enabled = FALSE;
-    return;
-  }
-#elif defined(PLATFORM_MSDOS)
-  sound_handler(snd_ctrl);
-#endif
+void InitReloadMusic(char *set_name)
+{
+  InitReloadSoundsOrMusic(set_name, SND_RELOAD_MUSIC);
 }
 
 void FreeSound(SoundInfo *sound)
@@ -1493,6 +1567,7 @@ void FreeAllSounds()
     FreeSound(Sound[i]);
 
   free(Sound);
+  Sound = NULL;
 }
 
 void FreeAllMusic()
@@ -1506,6 +1581,7 @@ void FreeAllMusic()
     FreeMusic(Music[i]);
 
   free(Music);
+  Music = NULL;
 }
 
 /* THE STUFF ABOVE IS ONLY USED BY THE MAIN PROCESS                          */
index 896bef06971a5f2ee3f4fb9886ea688e4a577983..ebca45f5eb6be619b2ed1a69998ca7d654ea8dea 100644 (file)
 #define SSND_MUSIC             (SSND_FADE_MUSIC | SSND_STOP_MUSIC)
 #define SSND_ALL               (SSND_FADE_ALL | SSND_STOP_ALL)
 
+#define SND_RELOAD_SOUNDS      1
+#define SND_RELOAD_MUSIC       2
+
 #define SND_TYPE_NONE          0
 #define SND_TYPE_WAV           1
 
@@ -207,7 +210,7 @@ struct SoundControl
   int playingtime;
   long playingpos;
 
-  long data_len;
+  unsigned long data_len;
   byte *data_ptr;
 
 #if defined(PLATFORM_MSDOS)
@@ -225,8 +228,8 @@ void StartSoundserver(void);
 void SoundServer(void);
 
 /* sound client functions */
-void ReloadSounds(void);
-void ReloadMusic(void);
+void ReloadSounds(char *);
+void ReloadMusic(char *);
 SoundInfo *LoadCustomSound(char *);
 void InitSoundList(int);
 void LoadSoundToList(char *, int);
index 98b16c42597b14a4d640a22ca2c4665a00167d72..916d92f10f4b19f424de7d3f4c229dc9063701da 100644 (file)
@@ -780,6 +780,13 @@ inline void SetAudioMode(boolean enabled)
   audio.sound_enabled = enabled;
 }
 
+inline void SetAudioReloadFunctions(void (*func_reload_sounds)(void),
+                                   void (*func_reload_music)(void))
+{
+  audio.func_reload_sounds = func_reload_sounds;
+  audio.func_reload_music = func_reload_music;
+}
+
 
 /* ========================================================================= */
 /* event functions                                                           */
index 316de68ed16bc4f1c84817d79f9472b2c8b1966a..4d8940d135125a919641ff08b5e94ddc70b31499 100644 (file)
@@ -236,6 +236,9 @@ struct AudioSystemInfo
   boolean sound_enabled;
   boolean sound_deactivated;   /* for temporarily disabling sound */
 
+  void (*func_reload_sounds)(void);
+  void (*func_reload_music)(void);
+
   int soundserver_pipe[2];
   int soundserver_pid;
   char *device_name;
@@ -477,6 +480,8 @@ void ReloadCustomImage(Bitmap *, char *);
 inline void OpenAudio(void);
 inline void CloseAudio(void);
 inline void SetAudioMode(boolean);
+inline void SetAudioReloadFunctions(void (*func_reload_sounds)(void),
+                                   void (*func_reload_music)(void));
 
 inline void InitEventFilter(EventFilter);
 inline boolean PendingEvent(void);
index 427ae052f066a6536d2cb98aaec1b0398faa24c0..9f01cb6d5d2466103e282f131810d6d631547947 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2002-04-23 22:56]"
+#define COMPILE_DATE_STRING "[2002-04-24 03:21]"