Merge branch 'find-musicdef' into 'master'

Add S_FindMusicDef, function to find musicdef by name

See merge request KartKrew/Kart!860
This commit is contained in:
Sal 2023-01-05 21:56:47 +00:00
commit 5ede1e5a18

View file

@ -1365,6 +1365,28 @@ musicdef_t *musicdefstart = NULL;
struct cursongcredit cursongcredit; // Currently displayed song credit info struct cursongcredit cursongcredit; // Currently displayed song credit info
int musicdef_volume; 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 static boolean
MusicDefError MusicDefError
( (
@ -1412,21 +1434,10 @@ ReadMusicDefFields
} }
else else
{ {
musicdef_t **tail = &musicdefstart; def = S_FindMusicDef(value);
// Search if this is a replacement
while (*tail)
{
if (!stricmp((*tail)->name, value))
{
break;
}
tail = &(*tail)->next;
}
// Nothing found, add to the end. // Nothing found, add to the end.
if (!(*tail)) if (!def)
{ {
def = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL); def = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL);
@ -1434,10 +1445,11 @@ ReadMusicDefFields
strlwr(def->name); strlwr(def->name);
def->volume = DEFAULT_MUSICDEF_VOLUME; def->volume = DEFAULT_MUSICDEF_VOLUME;
(*tail) = def; def->next = musicdefstart;
musicdefstart = def;
} }
(*defp) = (*tail); (*defp) = def;
} }
} }
else else
@ -1611,7 +1623,11 @@ void S_InitMusicDefs(void)
// //
void S_ShowMusicCredit(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) if (!cv_songcredits.value || demo.rewinding)
return; return;
@ -1619,14 +1635,6 @@ void S_ShowMusicCredit(void)
if (!def) // No definitions if (!def) // No definitions
return; return;
while (def)
{
if (!stricmp(def->name, music_name))
{
char credittext[128] = "";
char *work = NULL;
size_t len = 128, worklen;
if (!def->title) if (!def->title)
{ {
return; return;
@ -1666,11 +1674,6 @@ void S_ShowMusicCredit(void)
cursongcredit.anim = 5*TICRATE; cursongcredit.anim = 5*TICRATE;
cursongcredit.x = cursongcredit.old_x = 0; cursongcredit.x = cursongcredit.old_x = 0;
cursongcredit.trans = NUMTRANSMAPS; cursongcredit.trans = NUMTRANSMAPS;
return;
}
def = def->next;
}
} }
/// ------------------------ /// ------------------------
@ -2242,15 +2245,13 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32
musicdef_volume = DEFAULT_MUSICDEF_VOLUME; musicdef_volume = DEFAULT_MUSICDEF_VOLUME;
{ {
musicdef_t *def; musicdef_t *def = S_FindMusicDef(music_name);
for (def = musicdefstart; def; def = def->next)
{ if (def)
if (strcasecmp(def->name, music_name) == 0)
{ {
musicdef_volume = def->volume; musicdef_volume = def->volume;
} }
} }
}
if (!S_PlayMusic(looping, fadeinms)) if (!S_PlayMusic(looping, fadeinms))
return; return;