musicdef_t: Permit multiple tracks (music lumps) associated with the same entry

- Now supports "Lump MENU2,MENU3".
- Automagically appends (A) and (B) instead of having to user-specify them as part of the track name.
This commit is contained in:
toaster 2023-03-23 20:08:44 +00:00
parent cb4d9b527e
commit 62a573090b
3 changed files with 69 additions and 23 deletions

View file

@ -1366,22 +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)
{ {
UINT32 hash = quickncasehash (name, 6); UINT32 hash = quickncasehash (name, 6);
musicdef_t *def; musicdef_t *def;
for (def = musicdefstart; def; def = def->next) for (def = musicdefstart; def; def = def->next)
{ {
if (hash != def->hash) for (*i = 0; *i < def->numtracks; (*i)++)
continue; {
if (hash != def->hash[*i])
continue;
if (stricmp(def->name, name)) if (stricmp(def->name[*i], name))
continue; continue;
return def; return def;
}
} }
*i = 0;
return NULL; return NULL;
} }
@ -1423,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,
@ -1432,16 +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)
def->hash = quickncasehash (def->name, 6); 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;
@ -1622,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;
@ -1646,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)\
{\ {\
@ -2252,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)
{ {
@ -2468,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");
@ -2504,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,11 +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; UINT32 hash[MAXDEFTRACKS];
UINT8 numtracks;
char *title; char *title;
char *author; char *author;
char *source; char *source;
@ -201,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());