mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-12-21 15:32:34 +00:00
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:
commit
5ede1e5a18
1 changed files with 68 additions and 67 deletions
135
src/s_sound.c
135
src/s_sound.c
|
|
@ -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,58 +1635,45 @@ void S_ShowMusicCredit(void)
|
||||||
if (!def) // No definitions
|
if (!def) // No definitions
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (def)
|
if (!def->title)
|
||||||
{
|
{
|
||||||
if (!stricmp(def->name, music_name))
|
return;
|
||||||
{
|
}
|
||||||
char credittext[128] = "";
|
|
||||||
char *work = NULL;
|
|
||||||
size_t len = 128, worklen;
|
|
||||||
|
|
||||||
if (!def->title)
|
work = va("\x1F %s", def->title);
|
||||||
{
|
worklen = strlen(work);
|
||||||
return;
|
if (worklen <= len)
|
||||||
}
|
{
|
||||||
|
strncat(credittext, work, len);
|
||||||
work = va("\x1F %s", def->title);
|
len -= worklen;
|
||||||
worklen = strlen(work);
|
|
||||||
if (worklen <= len)
|
|
||||||
{
|
|
||||||
strncat(credittext, work, len);
|
|
||||||
len -= worklen;
|
|
||||||
|
|
||||||
#define MUSICCREDITAPPEND(field)\
|
#define MUSICCREDITAPPEND(field)\
|
||||||
if (field)\
|
if (field)\
|
||||||
{\
|
{\
|
||||||
work = va(" - %s", field);\
|
work = va(" - %s", field);\
|
||||||
worklen = strlen(work);\
|
worklen = strlen(work);\
|
||||||
if (worklen <= len)\
|
if (worklen <= len)\
|
||||||
{\
|
{\
|
||||||
strncat(credittext, work, len);\
|
strncat(credittext, work, len);\
|
||||||
len -= worklen;\
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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_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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue