rnd-20030128-1-src
[rocksndiamonds.git] / src / libgame / sound.c
index 61d5d29e8deffa5c0122a1df5bd9a5d3f165b5dc..3f1d04e9eee0cd0593e1f54114e5e3af1f3c626a 100644 (file)
@@ -253,13 +253,15 @@ static boolean ForkAudioProcess(void)
     return FALSE;
   }
 
+  if (audio.mixer_pid == 0)            /* we are the child process */
+    audio.mixer_pid = getpid();
+
 #if 0
-  printf("PID: %d [%s]\n", getpid(),
-        (IS_CHILD_PROCESS(audio.mixer_pid) ? "child" : "parent"));
+  printf("PID: %d [%s]\n", getpid(),(IS_CHILD_PROCESS() ? "child" : "parent"));
   Delay(10000 * 0);
 #endif
 
-  if (IS_CHILD_PROCESS(audio.mixer_pid))
+  if (IS_CHILD_PROCESS())
     Mixer_Main();                      /* this function never returns */
   else
     close(audio.mixer_pipe[0]);                /* no reading from pipe needed */
@@ -290,7 +292,7 @@ void UnixCloseAudio(void)
   if (audio.device_fd)
     close(audio.device_fd);
 
-  if (IS_PARENT_PROCESS(audio.mixer_pid))
+  if (IS_PARENT_PROCESS())
     kill(audio.mixer_pid, SIGTERM);
 }
 
@@ -457,7 +459,7 @@ static void InitAudioDevice(struct AudioFormatInfo *afmt)
 
 static void SendSoundControlToMixerProcess(SoundControl *snd_ctrl)
 {
-  if (IS_CHILD_PROCESS(audio.mixer_pid))
+  if (IS_CHILD_PROCESS())
     return;
 
   if (write(audio.mixer_pipe[1], snd_ctrl, sizeof(SoundControl)) < 0)
@@ -470,7 +472,7 @@ static void SendSoundControlToMixerProcess(SoundControl *snd_ctrl)
 
 static void ReadSoundControlFromMainProcess(SoundControl *snd_ctrl)
 {
-  if (IS_PARENT_PROCESS(audio.mixer_pid))
+  if (IS_PARENT_PROCESS())
     return;
 
   if (read(audio.mixer_pipe[0], snd_ctrl, sizeof(SoundControl))
@@ -492,7 +494,7 @@ static void WriteReloadInfoToPipe(char *set_identifier, int type)
                                    setup.override_level_sounds :
                                    setup.override_level_music);
 
-  if (IS_CHILD_PROCESS(audio.mixer_pid))
+  if (IS_CHILD_PROCESS())
     return;
 
   if (leveldir_current == NULL)                /* should never happen */
@@ -1012,7 +1014,7 @@ static void HandleSoundRequest(SoundControl snd_ctrl)
   int i;
 
 #if defined(AUDIO_UNIX_NATIVE)
-  if (IS_PARENT_PROCESS(audio.mixer_pid))
+  if (IS_PARENT_PROCESS())
   {
     SendSoundControlToMixerProcess(&snd_ctrl);
     return;
@@ -1765,16 +1767,37 @@ static void *Load_WAV(char *filename)
   return snd_info;
 }
 
-struct FileInfo *getCurrentSoundList()
+int getSoundListSize()
+{
+  return (sound_info->num_file_list_entries +
+         sound_info->num_dynamic_file_list_entries);
+}
+
+struct FileInfo *getSoundListEntry(int pos)
+{
+  int num_list_entries = sound_info->num_file_list_entries;
+  int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries);
+
+  return (pos < num_list_entries ? &sound_info->file_list[list_pos] :
+         &sound_info->dynamic_file_list[list_pos]);
+}
+
+int getSoundListPropertyMappingSize()
+{
+  return sound_info->num_property_mapping_entries;
+}
+
+struct PropertyMapping *getSoundListPropertyMapping()
 {
-  return sound_info->file_list;
+  return sound_info->property_mapping;
 }
 
 void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
                   struct ConfigInfo *config_suffix_list,
                   char **base_prefixes,
                   char **ext1_suffixes,
-                  char **ext2_suffixes)
+                  char **ext2_suffixes,
+                  char **ext3_suffixes)
 {
   int i;
 
@@ -1786,15 +1809,15 @@ void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
   sound_info->num_file_list_entries = num_file_list_entries;
   sound_info->num_dynamic_file_list_entries = 0;
 
-  sound_info->num_suffix_list_entries = 0;
-  for (i=0; config_suffix_list[i].token != NULL; i++)
-    sound_info->num_suffix_list_entries++;
-
   sound_info->file_list =
     getFileListFromConfigList(config_list, config_suffix_list,
                              num_file_list_entries);
   sound_info->dynamic_file_list = NULL;
 
+  sound_info->num_suffix_list_entries = 0;
+  for (i=0; config_suffix_list[i].token != NULL; i++)
+    sound_info->num_suffix_list_entries++;
+
   sound_info->suffix_list = config_suffix_list;
 
   /* ---------- initialize base prefix and suffixes lists ---------- */
@@ -1811,14 +1834,26 @@ void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
   for (i=0; ext2_suffixes[i] != NULL; i++)
     sound_info->num_ext2_suffixes++;
 
+  sound_info->num_ext3_suffixes = 0;
+  for (i=0; ext3_suffixes[i] != NULL; i++)
+    sound_info->num_ext3_suffixes++;
+
   sound_info->base_prefixes = base_prefixes;
   sound_info->ext1_suffixes = ext1_suffixes;
   sound_info->ext2_suffixes = ext2_suffixes;
+  sound_info->ext3_suffixes = ext3_suffixes;
+
+  sound_info->num_property_mapping_entries = 0;
+
+  sound_info->property_mapping = NULL;
 
   /* ---------- initialize artwork reference and content lists ---------- */
 
+  sound_info->sizeof_artwork_list_entry = sizeof(SoundInfo *);
+
   sound_info->artwork_list =
     checked_calloc(num_file_list_entries * sizeof(SoundInfo *));
+  sound_info->dynamic_artwork_list = NULL;
 
   sound_info->content_list = NULL;
 
@@ -2125,7 +2160,7 @@ void FreeMusic(MusicInfo *music)
 
 void FreeAllSounds()
 {
-  FreeCustomArtworkList(sound_info);
+  FreeCustomArtworkLists(sound_info);
 }
 
 void FreeAllMusic()