Merge branch 'credits-music' into 'master'

Play Title music after credits track ends

See merge request KartKrew/Kart!2152
This commit is contained in:
AJ Martinez 2024-03-24 06:47:15 +00:00
commit e43bfbffee
9 changed files with 103 additions and 18 deletions

View file

@ -427,6 +427,9 @@ static bool D_Display(void)
{
// Fade to black first
if (G_GamestateUsesLevel() == false // fades to black on its own timing, always
// Wipe between credits slides.
// But not back from attract demo, since F_CreditsDemoExitFade exists.
&& (gamestate != GS_CREDITS || wipegamestate != GS_LEVEL)
&& wipetypepre != UINT8_MAX)
{
F_WipeStartScreen();
@ -1120,8 +1123,11 @@ void D_ClearState(void)
if (rendermode != render_none)
V_SetPaletteLump("PLAYPAL");
S_StopMusicCredit();
if (!Music_Playing("credits"))
S_StopMusicCredit();
S_StopSounds();
S_SetSfxVolume(); // reset sound volume
if (gamedata && gamedata->deferredsave)
G_SaveGameData();
@ -1139,7 +1145,6 @@ static boolean g_deferredtitle = false;
//
void D_StartTitle(void)
{
bool fromAttract = (demo.attract == DEMO_ATTRACT_TITLE);
demo.attract = DEMO_ATTRACT_OFF;
Music_StopAll();
@ -1148,10 +1153,6 @@ void D_StartTitle(void)
F_StartTitleScreen();
M_ClearMenus(false);
g_deferredtitle = false;
if (fromAttract)
S_ShowMusicCredit(); // Show music credit when returning to the title screen
}
void D_SetDeferredStartTitle(boolean deferred)

View file

@ -3659,6 +3659,11 @@ void readmaincfg(MYFILE *f, boolean mainfile)
titlescrollyspeed = get_number(word2);
titlechanged = true;
}
else if (fastcmp(word, "TITLESMUSICSTART"))
{
titlemusicstart = (UINT32)get_number(word2);
titlechanged = true;
}
else if (fastcmp(word, "NUMDEMOS"))
{
numDemos = (UINT8)get_number(word2);

View file

@ -49,12 +49,14 @@
#include "k_grandprix.h"
#include "music.h"
#include "k_credits.h"
#include "i_sound.h"
// Stage of animation:
// 0 = text, 1 = art screen
INT32 finalecount;
INT32 titlescrollxspeed = 16;
INT32 titlescrollyspeed = 0;
UINT32 titlemusicstart = 38749;
boolean titlemapinaction = false;
static INT32 timetonext; // Delay between screen changes
@ -982,6 +984,7 @@ UINT16 finaleemeralds = 0;
void F_StartGameEvaluation(void)
{
Music_SetFadeOut("credits", 250);
Music_DelayEnd("credits", TICRATE/4);
Music_Tick(); // it needs to fade out right now
@ -1327,6 +1330,7 @@ void F_GameEvaluationTicker(void)
{
if (finalecount == 1)
{
Music_Stop("credits");
// sitting on that distant _shore
Music_Remap("shore", "_SHORE");
Music_Play("shore");
@ -1336,6 +1340,7 @@ void F_GameEvaluationTicker(void)
{
if (finalecount == TICRATE/2)
{
Music_Stop("credits");
// _drift across open waters
Music_Remap("shore", "_DRIFT");
Music_Play("shore");
@ -1855,6 +1860,13 @@ luahook:
M_DrawMenuMessage();
}
void F_PlayTitleScreenMusic(void)
{
Music_Loop("title", looptitle);
Music_Seek("title", titlemusicstart); // kick in
Music_Play("title");
}
// (no longer) De-Demo'd Title Screen
void F_TitleScreenTicker(boolean run)
{
@ -1871,8 +1883,7 @@ void F_TitleScreenTicker(boolean run)
else if (!Music_Playing("title"))
{
// Now start the music
Music_Loop("title", looptitle);
Music_Play("title");
F_PlayTitleScreenMusic();
}
}
else if (menumessage.active)
@ -2075,7 +2086,15 @@ void F_AttractDemoTicker(void)
{
keypressed = false;
if (attractcountdown > 0 && !g_fast_forward)
if (g_fast_forward)
return;
if (demo.attract == DEMO_ATTRACT_CREDITS)
{
F_ConsiderCreditsMusicUpdate();
}
if (attractcountdown > 0)
{
if (attractcredit)
{
@ -2083,6 +2102,13 @@ void F_AttractDemoTicker(void)
attractcredit = false;
}
INT32 val = F_AttractDemoExitFade();
if (val >= 0)
{
// Fade down sounds with screen fade
I_SetSfxVolume(cv_soundvolume.value * (31 - val) / 31);
}
if (attractcountdown > 0 && !--attractcountdown)
{
// Fade will be handled without a wipe (see F_AttractDemoExitFade)

View file

@ -71,9 +71,12 @@ void F_StartIntro(void);
void F_StartTitleScreen(void);
void F_StartEnding(void);
void F_PlayTitleScreenMusic(void);
extern INT32 finalecount;
extern INT32 titlescrollxspeed;
extern INT32 titlescrollyspeed;
extern UINT32 titlemusicstart;
typedef enum
{

View file

@ -33,6 +33,7 @@
#include "w_wad.h"
#include "z_zone.h"
#include "i_system.h"
#include "i_sound.h"
#include "i_joy.h"
#include "i_threads.h"
#include "dehacked.h"
@ -78,6 +79,7 @@ struct credits_slide_s
std::vector<std::string> strings;
size_t strings_height;
boolean play_demo_afterwards;
int fade_out_music;
};
static std::vector<struct credits_slide_s> g_credits_slides;
@ -232,6 +234,7 @@ void F_LoadCreditsDefinitions(void)
}
slide.play_demo_afterwards = slide_obj.value("demo", false);
slide.fade_out_music = slide_obj.value("fade_out_music", 0);
g_credits_slides.push_back( slide );
}
@ -366,11 +369,30 @@ static void F_InitCreditsSlide(void)
}
}
#endif
else if (slide->type == CRED_TYPE_KARTKREW)
{
}
// Clear the console hud just to avoid anything getting in the way.
CON_ClearHUD();
}
static void F_NewCreditsMusic(const char *trackname, bool looping)
{
Music_Remap("credits", trackname);
Music_Loop("credits", looping);
Music_Play("credits");
}
void F_ConsiderCreditsMusicUpdate(void)
{
if (!Music_CanLoop("credits") && I_GetSongLength() == I_GetSongPosition())
{
F_NewCreditsMusic("_title", true);
}
}
void F_StartCredits(void)
{
G_SetGamestate(GS_CREDITS);
@ -391,7 +413,8 @@ void F_StartCredits(void)
Music_StopAll();
S_StopSounds();
Music_Play("credits");
Music_SetFadeOut("credits", 0);
F_NewCreditsMusic("_creds", false);
F_CreditsReset();
@ -432,6 +455,9 @@ void F_ContinueCredits(void)
F_CreditsReset();
demo.attract = DEMO_ATTRACT_OFF;
// Do not wipe back to credits, since F_CreditsDemoExitFade exists.
wipegamestate = GS_LEVEL;
// Returning from playing a demo.
// Go to the next slide.
F_CreditsNextSlide();
@ -542,6 +568,12 @@ void F_TickCreditsDemoExit(void)
g_credits.demo_exit = std::max(g_credits.demo_exit, kDemoExitTicCount - 64);
}
if (INT32 val = F_CreditsDemoExitFade(); val >= 0)
{
// Fade down sounds with screen fade
I_SetSfxVolume(cv_soundvolume.value * (31 - val) / 31);
}
if (g_credits.demo_exit > kDemoExitTicCount)
{
G_CheckDemoStatus();
@ -794,6 +826,11 @@ static void F_HandleCreditsTick(void)
}
else if (finalize_slide)
{
if (slide->fade_out_music)
{
I_FadeSong(0, slide->fade_out_music, nullptr);
}
if (g_credits.current_slide >= g_credits_slides.size() - 1)
{
g_credits.finish_counter = 5 * TICRATE;
@ -809,6 +846,8 @@ void F_CreditTicker(void)
{
g_credits.havent_ticked = false;
F_ConsiderCreditsMusicUpdate();
g_credits.transition_prev = g_credits.transition;
g_credits.scroll_timer_prev = g_credits.scroll_timer;
@ -1106,7 +1145,7 @@ static void F_DrawCreditsKartKrew(void)
);
V_DrawFixedPatch(
116 * FRACUNIT, 70 * FRACUNIT,
111 * FRACUNIT, 70 * FRACUNIT,
FRACUNIT / 2, 0,
static_cast<patch_t *>(W_CachePatchName(
"KKLOGO_C",
@ -1116,7 +1155,7 @@ static void F_DrawCreditsKartKrew(void)
);
V_DrawFixedPatch(
116 * FRACUNIT, 70 * FRACUNIT,
111 * FRACUNIT, 70 * FRACUNIT,
FRACUNIT / 2, 0,
static_cast<patch_t *>(W_CachePatchName(
"KKTEXT_C",
@ -1186,3 +1225,8 @@ void F_CreditDrawer(void)
star.y += FixedMul(star.vel_y, renderdeltatics);
}
}
boolean F_CreditsRunning(void)
{
return gamestate == GS_CREDITS || demo.attract == DEMO_ATTRACT_CREDITS;
}

View file

@ -32,10 +32,14 @@ void F_TickCreditsDemoExit(void);
INT32 F_CreditsDemoExitFade(void);
void F_ConsiderCreditsMusicUpdate(void);
void F_CreditTicker(void);
void F_CreditDrawer(void);
boolean F_CreditsRunning(void);
#ifdef __cplusplus
} // extern "C"
#endif

View file

@ -168,8 +168,6 @@ void Music_Init(void)
tune.priority = 100;
tune.song = "_creds";
tune.fade_out = 250;
tune.loop = false;
tune.credit = true;
}

View file

@ -116,6 +116,7 @@
#include "k_dialogue.h"
#include "k_hud.h" // K_ClearPersistentMessages
#include "k_endcam.h"
#include "k_credits.h"
// Replay names have time
#if !defined (UNDER_CE)
@ -7651,8 +7652,11 @@ static void P_InitLevelSettings(void)
g_quakes = NULL;
// song credit init
S_StopMusicCredit();
cursongcredit.trans = NUMTRANSMAPS;
if (!Music_Playing("credits"))
{
S_StopMusicCredit();
cursongcredit.trans = NUMTRANSMAPS;
}
for (i = 0; i < MAXPLAYERS; i++)
{

View file

@ -38,6 +38,7 @@
#include "v_video.h" // V_ThinStringWidth
#include "music.h"
#include "y_inter.h" // Y_PlayIntermissionMusic
#include "f_finale.h" // F_PlayTitleScreenMusic
extern consvar_t cv_mastervolume;
@ -1224,8 +1225,7 @@ void S_AttemptToRestoreMusic(void)
Music_Play("level");
break;
case GS_TITLESCREEN:
Music_Loop("title", looptitle);
Music_Play("title");
F_PlayTitleScreenMusic();
break;
case GS_MENU:
M_PlayMenuJam();