Merge branch 'multi-musicdef' into 'master'

Multi Musicdef

See merge request KartKrew/Kart!1084
This commit is contained in:
Oni 2023-03-24 00:10:43 +00:00
commit f0f6c3643e
3 changed files with 71 additions and 21 deletions

View file

@ -1366,20 +1366,26 @@ struct cursongcredit cursongcredit; // Currently displayed song credit info
// //
// Find music def by 6 char name // Find music def by 6 char name
// //
musicdef_t *S_FindMusicDef(const char *name) musicdef_t *S_FindMusicDef(const char *name, UINT8 *i)
{ {
musicdef_t *def = musicdefstart; UINT32 hash = quickncasehash (name, 6);
musicdef_t *def;
while (def) for (def = musicdefstart; def; def = def->next)
{ {
if (!stricmp(def->name, name)) for (*i = 0; *i < def->numtracks; (*i)++)
{ {
if (hash != def->hash[*i])
continue;
if (stricmp(def->name[*i], name))
continue;
return def; return def;
} }
def = def->next;
} }
*i = 0;
return NULL; return NULL;
} }
@ -1421,7 +1427,7 @@ ReadMusicDefFields
if (!stricmp(stoken, "lump")) if (!stricmp(stoken, "lump"))
{ {
value = strtok(NULL, " "); value = strtok(NULL, " ,");
if (!value) if (!value)
{ {
return MusicDefError(CONS_WARNING, return MusicDefError(CONS_WARNING,
@ -1430,15 +1436,32 @@ ReadMusicDefFields
} }
else else
{ {
def = S_FindMusicDef(value); UINT8 i = 0;
def = S_FindMusicDef(value, &i);
// Nothing found, add to the end. // Nothing found, add to the end.
if (!def) if (!def)
{ {
def = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL); def = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL);
STRBUFCPY(def->name, value); do {
strlwr(def->name); if (i >= MAXDEFTRACKS)
break;
STRBUFCPY(def->name[i], value);
strlwr(def->name[i]);
def->hash[i] = quickncasehash (def->name[i], 6);
i++;
} while ((value = strtok(NULL," ,")) != NULL);
if (value != NULL)
{
return MusicDefError(CONS_ERROR,
"Extra tracks for field '%s' beyond 3 discarded.", // MAXDEFTRACKS
stoken, lumpnum, line);
}
def->numtracks = i;
def->volume = DEFAULT_MUSICDEF_VOLUME; def->volume = DEFAULT_MUSICDEF_VOLUME;
def->next = musicdefstart; def->next = musicdefstart;
@ -1619,7 +1642,8 @@ void S_InitMusicDefs(void)
// //
void S_ShowMusicCredit(void) void S_ShowMusicCredit(void)
{ {
musicdef_t *def = S_FindMusicDef(music_name); UINT8 i = 0;
musicdef_t *def = S_FindMusicDef(music_name, &i);
char credittext[128] = ""; char credittext[128] = "";
char *work = NULL; char *work = NULL;
@ -1643,6 +1667,17 @@ void S_ShowMusicCredit(void)
strncat(credittext, work, len); strncat(credittext, work, len);
len -= worklen; len -= worklen;
if (def->numtracks > 1)
{
work = va(" (%c)", i+'A');
worklen = strlen(work);
if (worklen <= len)
{
strncat(credittext, work, len);
len -= worklen;
}
}
#define MUSICCREDITAPPEND(field)\ #define MUSICCREDITAPPEND(field)\
if (field)\ if (field)\
{\ {\
@ -2249,7 +2284,8 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32
music_looping = looping; music_looping = looping;
{ {
musicdef_t *def = S_FindMusicDef(music_name); UINT8 i = 0;
musicdef_t *def = S_FindMusicDef(music_name, &i);
if (def) if (def)
{ {
@ -2465,9 +2501,16 @@ static inline void PrintMusicDefField(const char *label, const char *field)
} }
} }
static void PrintSongAuthors(const musicdef_t *def) static void PrintSongAuthors(const musicdef_t *def, UINT8 i)
{ {
PrintMusicDefField("Title: ", def->title); if (def->numtracks > 1)
{
PrintMusicDefField("Title: ", va("%s (%c)", def->title, i+'A'));
}
else
{
PrintMusicDefField("Title: ", def->title);
}
PrintMusicDefField("Author: ", def->author); PrintMusicDefField("Author: ", def->author);
CONS_Printf("\n"); CONS_Printf("\n");
@ -2501,27 +2544,29 @@ static void Command_Tunes_f(void)
if (!strcasecmp(tunearg, "-show")) if (!strcasecmp(tunearg, "-show"))
{ {
const musicdef_t *def = S_FindMusicDef(music_name); UINT8 i = 0;
const musicdef_t *def = S_FindMusicDef(music_name, &i);
CONS_Printf(M_GetText("The current tune is: %s [track %d]\n"), CONS_Printf(M_GetText("The current tune is: %s [track %d]\n"),
music_name, (music_flags & MUSIC_TRACKMASK)); music_name, (music_flags & MUSIC_TRACKMASK));
if (def != NULL) if (def != NULL)
{ {
PrintSongAuthors(def); PrintSongAuthors(def, i);
} }
return; return;
} }
if (!strcasecmp(tunearg, "-showdefault")) if (!strcasecmp(tunearg, "-showdefault"))
{ {
const musicdef_t *def = S_FindMusicDef(mapmusname); UINT8 i = 0;
const musicdef_t *def = S_FindMusicDef(mapmusname, &i);
CONS_Printf(M_GetText("The default tune is: %s [track %d]\n"), CONS_Printf(M_GetText("The default tune is: %s [track %d]\n"),
mapmusname, (mapmusflags & MUSIC_TRACKMASK)); mapmusname, (mapmusflags & MUSIC_TRACKMASK));
if (def != NULL) if (def != NULL)
{ {
PrintSongAuthors(def); PrintSongAuthors(def, i);
} }
return; return;
} }

View file

@ -174,10 +174,14 @@ boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping);
// Set Speed of Music // Set Speed of Music
boolean S_SpeedMusic(float speed); boolean S_SpeedMusic(float speed);
#define MAXDEFTRACKS 3
// Music credits // Music credits
struct musicdef_t struct musicdef_t
{ {
char name[7]; char name[MAXDEFTRACKS][7];
UINT32 hash[MAXDEFTRACKS];
UINT8 numtracks;
char *title; char *title;
char *author; char *author;
char *source; char *source;
@ -200,7 +204,7 @@ extern musicdef_t *musicdefstart;
void S_LoadMusicDefs(UINT16 wadnum); void S_LoadMusicDefs(UINT16 wadnum);
void S_InitMusicDefs(void); void S_InitMusicDefs(void);
musicdef_t *S_FindMusicDef(const char *name); musicdef_t *S_FindMusicDef(const char *name, UINT8 *i);
void S_ShowMusicCredit(void); void S_ShowMusicCredit(void);
// //

View file

@ -377,6 +377,7 @@ static void ST_drawMusicDebug(INT32 *height)
char mname[7]; char mname[7];
UINT16 mflags; // unused UINT16 mflags; // unused
boolean looping; boolean looping;
UINT8 i = 0;
const musicdef_t *def; const musicdef_t *def;
const char *format; const char *format;
@ -387,7 +388,7 @@ static void ST_drawMusicDebug(INT32 *height)
return; return;
} }
def = S_FindMusicDef(mname); def = S_FindMusicDef(mname, &i);
format = S_MusicType(); format = S_MusicType();
ST_pushDebugTimeMS(height, " Elapsed: ", S_GetMusicPosition()); ST_pushDebugTimeMS(height, " Elapsed: ", S_GetMusicPosition());