Add S_LoadSongCredit/S_UnloadSongCredit, refactor cursongcredit

- cursongcredit behaves the same as before
- Always compose song credit string
- g_realsongcredit always stores the song credit for the
  current music, even if no song credit is displayed on
  the HUD
This commit is contained in:
James R 2024-01-29 22:24:30 -08:00
parent fb9f4a68b9
commit d7e0a4d01a
5 changed files with 46 additions and 17 deletions

View file

@ -883,7 +883,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum)
void HU_TickSongCredits(void)
{
if (cursongcredit.def == NULL) // No def
if (cursongcredit.text == NULL) // No def
{
cursongcredit.x = cursongcredit.old_x = 0;
cursongcredit.anim = 0;
@ -1991,7 +1991,7 @@ static void HU_DrawDemoInfo(void)
//
void HU_DrawSongCredits(void)
{
if (!cursongcredit.def || cursongcredit.trans >= NUMTRANSMAPS) // No def
if (!cursongcredit.text || cursongcredit.trans >= NUMTRANSMAPS) // No def
{
return;
}

View file

@ -60,6 +60,7 @@ void TuneManager::tick()
// Only stop the music credit if the song actually
// changed.
S_StopMusicCredit();
S_UnloadMusicCredit();
}
stop_credit_ = false;
@ -91,6 +92,8 @@ void TuneManager::tick()
adjust_volume();
I_SetSongSpeed(tune->speed());
S_LoadMusicCredit();
if (tune->credit && !tune->resume)
{
S_ShowMusicCredit();

View file

@ -7629,8 +7629,7 @@ static void P_InitLevelSettings(void)
g_quakes = NULL;
// song credit init
Z_Free(cursongcredit.text);
memset(&cursongcredit,0,sizeof(struct cursongcredit));
S_StopMusicCredit();
cursongcredit.trans = NUMTRANSMAPS;
for (i = 0; i < MAXPLAYERS; i++)

View file

@ -1244,6 +1244,7 @@ void S_AttemptToRestoreMusic(void)
musicdef_t *musicdefstart = NULL;
struct cursongcredit cursongcredit; // Currently displayed song credit info
char *g_realsongcredit;
struct soundtest soundtest; // Sound Test (sound test)
static void S_InsertMusicAtSoundTestSequenceTail(const char *musname, UINT16 map, UINT8 altref, musicdef_t ***tail)
@ -2093,11 +2094,11 @@ void S_InitMusicDefs(void)
}
//
// S_ShowMusicCredit
// S_LoadMusicCredit
//
// Display current song's credit on screen
// Load the current song's credit into memory
//
void S_ShowMusicCredit(void)
void S_LoadMusicCredit(void)
{
UINT8 i = 0;
musicdef_t *def = S_FindMusicDef(Music_CurrentSong(), &i);
@ -2107,18 +2108,13 @@ void S_ShowMusicCredit(void)
size_t len = 128, worklen;
INT32 widthused = (3*BASEVIDWIDTH/4) - 7, workwidth;
if (!cv_songcredits.value)
return;
S_UnloadMusicCredit();
if (!def) // No definitions
return;
if (!def->title)
{
// Like showing a blank credit.
S_StopMusicCredit();
return;
}
work = va("\x1F %s", def->title);
worklen = strlen(work);
@ -2166,9 +2162,34 @@ void S_ShowMusicCredit(void)
if (credittext[0] == '\0')
return;
cursongcredit.def = def;
g_realsongcredit = Z_StrDup(credittext);
}
void S_UnloadMusicCredit(void)
{
Z_Free(g_realsongcredit);
g_realsongcredit = NULL;
}
//
// S_ShowMusicCredit
//
// Display current song's credit on screen
//
void S_ShowMusicCredit(void)
{
if (!cv_songcredits.value)
return;
if (!g_realsongcredit)
{
// Like showing a blank credit.
S_StopMusicCredit();
return;
}
Z_Free(cursongcredit.text);
cursongcredit.text = Z_StrDup(credittext);
cursongcredit.text = Z_StrDup(g_realsongcredit);
cursongcredit.anim = 5*TICRATE;
cursongcredit.x = cursongcredit.old_x = 0;
cursongcredit.trans = NUMTRANSMAPS;
@ -2176,7 +2197,8 @@ void S_ShowMusicCredit(void)
void S_StopMusicCredit(void)
{
cursongcredit.def = NULL;
Z_Free(cursongcredit.text);
memset(&cursongcredit,0,sizeof(struct cursongcredit));
}
/// ------------------------

View file

@ -174,9 +174,9 @@ struct musicdef_t
soundtestsequence_t sequence;
};
// For HUD, doesn't always appear
extern struct cursongcredit
{
musicdef_t *def;
char *text;
UINT16 anim;
UINT8 trans;
@ -184,6 +184,9 @@ extern struct cursongcredit
fixed_t old_x;
} cursongcredit;
// For menu, always appears
extern char *g_realsongcredit;
extern struct soundtest
{
UINT8 tune; // Tune used for music system
@ -216,6 +219,8 @@ extern musicdef_t *musicdefstart;
void S_LoadMusicDefs(UINT16 wadnum);
void S_InitMusicDefs(void);
musicdef_t *S_FindMusicDef(const char *name, UINT8 *i);
void S_LoadMusicCredit(void);
void S_UnloadMusicCredit(void);
void S_ShowMusicCredit(void);
void S_StopMusicCredit(void);