From 0bf821447e56b41e6ae8de0cd68974dc57ac85f6 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 4 Jan 2023 23:34:19 -0800 Subject: [PATCH] Add S_FindMusicDef, function to find musicdef by name Use this function wherever the musicdef list is walked. --- src/s_sound.c | 135 +++++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index a721a9ff4..c9a63e7bc 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1365,6 +1365,28 @@ musicdef_t *musicdefstart = NULL; struct cursongcredit cursongcredit; // Currently displayed song credit info int musicdef_volume; +// +// S_FindMusicDef +// +// Find music def by 6 char name +// +static musicdef_t *S_FindMusicDef(const char *name) +{ + musicdef_t *def = musicdefstart; + + while (def) + { + if (!stricmp(def->name, name)) + { + return def; + } + + def = def->next; + } + + return NULL; +} + static boolean MusicDefError ( @@ -1412,21 +1434,10 @@ ReadMusicDefFields } else { - musicdef_t **tail = &musicdefstart; - - // Search if this is a replacement - while (*tail) - { - if (!stricmp((*tail)->name, value)) - { - break; - } - - tail = &(*tail)->next; - } + def = S_FindMusicDef(value); // Nothing found, add to the end. - if (!(*tail)) + if (!def) { def = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL); @@ -1434,10 +1445,11 @@ ReadMusicDefFields strlwr(def->name); def->volume = DEFAULT_MUSICDEF_VOLUME; - (*tail) = def; + def->next = musicdefstart; + musicdefstart = def; } - (*defp) = (*tail); + (*defp) = def; } } else @@ -1611,7 +1623,11 @@ void S_InitMusicDefs(void) // void S_ShowMusicCredit(void) { - musicdef_t *def = musicdefstart; + musicdef_t *def = S_FindMusicDef(music_name); + + char credittext[128] = ""; + char *work = NULL; + size_t len = 128, worklen; if (!cv_songcredits.value || demo.rewinding) return; @@ -1619,58 +1635,45 @@ void S_ShowMusicCredit(void) if (!def) // No definitions return; - while (def) + if (!def->title) { - if (!stricmp(def->name, music_name)) - { - char credittext[128] = ""; - char *work = NULL; - size_t len = 128, worklen; + return; + } - if (!def->title) - { - return; - } - - work = va("\x1F %s", def->title); - worklen = strlen(work); - if (worklen <= len) - { - strncat(credittext, work, len); - len -= worklen; + work = va("\x1F %s", def->title); + worklen = strlen(work); + if (worklen <= len) + { + strncat(credittext, work, len); + len -= worklen; #define MUSICCREDITAPPEND(field)\ - if (field)\ - {\ - work = va(" - %s", field);\ - worklen = strlen(work);\ - if (worklen <= len)\ - {\ - strncat(credittext, work, len);\ - len -= worklen;\ - }\ - } - - MUSICCREDITAPPEND(def->author); - MUSICCREDITAPPEND(def->source); - -#undef MUSICCREDITAPPEND - } - - if (credittext[0] == '\0') - return; - - cursongcredit.def = def; - Z_Free(cursongcredit.text); - cursongcredit.text = Z_StrDup(credittext); - cursongcredit.anim = 5*TICRATE; - cursongcredit.x = cursongcredit.old_x = 0; - cursongcredit.trans = NUMTRANSMAPS; - return; + if (field)\ + {\ + work = va(" - %s", field);\ + worklen = strlen(work);\ + if (worklen <= len)\ + {\ + strncat(credittext, work, len);\ + len -= worklen;\ + }\ } - def = def->next; + MUSICCREDITAPPEND(def->author); + MUSICCREDITAPPEND(def->source); + +#undef MUSICCREDITAPPEND } + + if (credittext[0] == '\0') + return; + + cursongcredit.def = def; + Z_Free(cursongcredit.text); + cursongcredit.text = Z_StrDup(credittext); + cursongcredit.anim = 5*TICRATE; + cursongcredit.x = cursongcredit.old_x = 0; + cursongcredit.trans = NUMTRANSMAPS; } /// ------------------------ @@ -2242,13 +2245,11 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 musicdef_volume = DEFAULT_MUSICDEF_VOLUME; { - musicdef_t *def; - for (def = musicdefstart; def; def = def->next) + musicdef_t *def = S_FindMusicDef(music_name); + + if (def) { - if (strcasecmp(def->name, music_name) == 0) - { - musicdef_volume = def->volume; - } + musicdef_volume = def->volume; } }