Refactor level music playing code

- Use one function so we don't duplicate the checks for
  music that isn't supposed to be interrupted by a restart
This commit is contained in:
James R 2024-03-09 06:12:05 -08:00
parent 1b3c63f24a
commit 9e99efc08c
3 changed files with 20 additions and 9 deletions

View file

@ -8236,6 +8236,11 @@ void P_ResetLevelMusic(void)
mapmusrng = idx; mapmusrng = idx;
} }
boolean P_UseContinuousLevelMusic(void)
{
return (gametyperules & GTR_NOPOSITION) || modeattacking != ATTACKING_NONE;
}
void P_LoadLevelMusic(void) void P_LoadLevelMusic(void)
{ {
mapheader_t* mapheader = mapheaderinfo[gamemap-1]; mapheader_t* mapheader = mapheaderinfo[gamemap-1];
@ -8246,7 +8251,7 @@ void P_LoadLevelMusic(void)
music = mapheader->musname[mapmusrng]; music = mapheader->musname[mapmusrng];
} }
if (gametyperules & GTR_NOPOSITION || modeattacking != ATTACKING_NONE) if (P_UseContinuousLevelMusic())
{ {
if (!stricmp(Music_Song("level_nosync"), music)) if (!stricmp(Music_Song("level_nosync"), music))
{ {

View file

@ -106,6 +106,7 @@ extern mapthing_t *mapthings;
void P_SetupLevelSky(const char *skytexname, boolean global); void P_SetupLevelSky(const char *skytexname, boolean global);
void P_RespawnThings(void); void P_RespawnThings(void);
void P_ResetLevelMusic(void); void P_ResetLevelMusic(void);
boolean P_UseContinuousLevelMusic(void);
void P_LoadLevelMusic(void); void P_LoadLevelMusic(void);
boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate); boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate);
void P_PostLoadLevel(void); void P_PostLoadLevel(void);

View file

@ -824,6 +824,15 @@ static void P_TickMusicFade(void)
g_musicfade.ticked = true; g_musicfade.ticked = true;
} }
static void P_StartLevelMusic(void)
{
if (!Music_Playing("level_nosync"))
{
// Do not stop level_nosync
Music_Play(P_UseContinuousLevelMusic() ? "level_nosync" : "level");
}
}
// //
// P_Ticker // P_Ticker
// //
@ -1024,7 +1033,7 @@ void P_Ticker(boolean run)
// Bosses have a punchy start, so no position. // Bosses have a punchy start, so no position.
if (leveltime == 1) if (leveltime == 1)
{ {
Music_Play("level"); P_StartLevelMusic();
} }
} }
else if (leveltime < starttime + TICRATE) else if (leveltime < starttime + TICRATE)
@ -1032,11 +1041,7 @@ void P_Ticker(boolean run)
if (leveltime == (starttime + (TICRATE/2))) if (leveltime == (starttime + (TICRATE/2)))
{ {
// Plays the music after the starting countdown. // Plays the music after the starting countdown.
if (!Music_Playing("level_nosync")) P_StartLevelMusic();
{
// Do not stop level_nosync
Music_Play((gametyperules & GTR_NOPOSITION) ? "level_nosync" : "level");
}
} }
else if (starttime != introtime) else if (starttime != introtime)
{ {
@ -1065,9 +1070,9 @@ void P_Ticker(boolean run)
if (modeattacking != ATTACKING_NONE) if (modeattacking != ATTACKING_NONE)
{ {
if (leveltime == 4 && !Music_Playing("level_nosync")) if (leveltime == 4)
{ {
Music_Play("level_nosync"); P_StartLevelMusic();
} }
} }