static SoundInfo **Sound = NULL;
static MusicInfo **Music = NULL;
static int num_sounds = 0, num_music = 0;
+static char **sound_name;
/* ========================================================================= */
static void SoundServer_StopAllSounds();
#endif
+static void ReloadCustomSounds();
+static void ReloadCustomMusic();
+static void FreeSound(SoundInfo *);
+
#if defined(PLATFORM_UNIX)
static int OpenAudioDevice(char *audio_device_name)
{
if (snd_ctrl.reload_sounds)
{
artwork.sounds_set_current = set_name;
+ ReloadCustomSounds();
+#if 0
audio.func_reload_sounds();
+#endif
}
else
{
artwork.music_set_current = set_name;
+ ReloadCustomMusic();
+#if 0
audio.func_reload_music();
+#endif
}
free(set_name);
if (!audio.sound_available)
return NULL;
+#if 1
+ printf("loading WAV file '%s'\n", filename);
+#endif
+
snd_info = checked_calloc(sizeof(SoundInfo));
#if defined(TARGET_SDL)
return snd_info;
}
-SoundInfo *LoadCustomSound(char *basename)
+static void LoadCustomSound(SoundInfo **snd_info, char *basename)
{
char *filename = getCustomSoundFilename(basename);
- if (filename == NULL)
+ if (filename == NULL) /* (should never happen) */
{
Error(ERR_WARN, "cannot find sound file '%s'", basename);
- return FALSE;
+ return;
}
- return Load_WAV(filename);
+ if (*snd_info && strcmp(filename, (*snd_info)->source_filename) == 0)
+ {
+ /* The old and new sound are the same (have the same filename and path).
+ This usually means that this sound does not exist in this sound set
+ and a fallback to the existing sound is done. */
+
+ return;
+ }
+
+ if (*snd_info)
+ FreeSound(*snd_info);
+
+ *snd_info = Load_WAV(filename);
}
-void InitSoundList(int num_list_entries)
+void InitSoundList(char *sound_name_list[], int num_list_entries)
{
- Sound = checked_calloc(num_list_entries * sizeof(SoundInfo *));
+ if (Sound == NULL)
+ Sound = checked_calloc(num_list_entries * sizeof(SoundInfo *));
+
+ sound_name = sound_name_list;
num_sounds = num_list_entries;
}
if (Sound == NULL || list_pos >= num_sounds)
return;
- if (Sound[list_pos])
- FreeSound(Sound[list_pos]);
-
- Sound[list_pos] = LoadCustomSound(basename);
+ LoadCustomSound(&Sound[list_pos], basename);
}
static MusicInfo *Load_MOD(char *filename)
#endif
}
+static void ReloadCustomSounds()
+{
+ int i;
+
+#if 1
+ printf("DEBUG: reloading sounds '%s' ...\n", artwork.sounds_set_current);
+#endif
+
+ LoadSoundsInfo();
+
+ for(i=0; i<num_sounds; i++)
+ LoadSoundToList(sound_name[i], i);
+}
+
+static void ReloadCustomMusic()
+{
+#if 1
+ printf("DEBUG: reloading music '%s' ...\n", artwork.music_set_current);
+#endif
+
+ FreeAllMusic();
+
+ LoadCustomMusic();
+}
+
static void InitReloadSoundsOrMusic(char *set_name, int type)
{
#if defined(PLATFORM_UNIX) && !defined(TARGET_SDL)