X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsound.c;h=4b62e341fbd0e8d7d3029df0d8ab82ec3913b0cd;hb=696d50b659131ba46ea7f4c44ca4d29475e8cb4f;hp=60b8bc306cdc95f403c12cb03512863af16303dd;hpb=7b6d9e43fdb99e1923f4a2a401ae60e7b2975bd8;p=rocksndiamonds.git diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 60b8bc30..4b62e341 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -89,7 +89,7 @@ static void SoundServer_StopAllSounds(); static void ReloadCustomSounds(); static void ReloadCustomMusic(); -static void FreeSound(SoundInfo *); +static void FreeSound(void *); #if defined(PLATFORM_UNIX) static int OpenAudioDevice(char *audio_device_name) @@ -1233,6 +1233,7 @@ static SoundInfo *Load_WAV(char *filename) static void LoadCustomSound(SoundInfo **snd_info, char *basename) { char *filename = getCustomSoundFilename(basename); + ListNode *node; if (filename == NULL) /* (should never happen) */ { @@ -1251,12 +1252,16 @@ static void LoadCustomSound(SoundInfo **snd_info, char *basename) and a fallback to the existing sound is done. */ #if 1 - printf("[sound '%s' already exists]\n", filename); + printf("[sound '%s' already exists (same list entry)]\n", filename); #endif return; } +#if 1 + printf("[decrementing reference counter of sound '%s']\n", filename_old); +#endif + if (--(*snd_info)->num_references <= 0) { #if 1 @@ -1270,6 +1275,20 @@ static void LoadCustomSound(SoundInfo **snd_info, char *basename) } } + /* check if this sound already exists in the list of sounds */ + node = getNodeFromKey(SoundFileList, filename); + if (node) + { +#if 1 + printf("[sound '%s' already exists (other list entry)]\n", filename); +#endif + + *snd_info = (SoundInfo *)node->content; + (*snd_info)->num_references++; + + return; + } + *snd_info = Load_WAV(filename); (*snd_info)->num_references = 1; @@ -1636,7 +1655,8 @@ void dumpList(ListNode *node_first) while (node) { - printf("['%s']\n", node->key); + printf("['%s' (%d)]\n", node->key, + ((SoundInfo *)node->content)->num_references); node = node->next; } @@ -1666,7 +1686,13 @@ static void LoadSoundsInfo() #if 1 for (i=0; i '%s'\n", sound_effect[i].text, sound_effect[i].filename); + { + printf("'%s' ", sound_effect[i].text); + if (sound_effect[i].filename) + printf("-> '%s'\n", sound_effect[i].filename); + else + printf("-> UNDEFINED [-> '%s']\n", sound_effect[i].default_filename); + } #endif } } @@ -1774,8 +1800,10 @@ void InitReloadMusic(char *set_name) InitReloadSoundsOrMusic(set_name, SND_RELOAD_MUSIC); } -void FreeSound(SoundInfo *sound) +void FreeSound(void *ptr) { + SoundInfo *sound = (SoundInfo *)ptr; + if (sound == NULL) return;