M_MenuToLevelPreamble: Seriously clean up the process of starting a course from the menu

A lot of messy, copypasted boilerplate has been bundled together into a single function.
Programmers can now fire up a Match Race, the most basic type of gameplay, from menu code in only four steps (other modes take a little more attention):
- **M_MenuToLevelPreamble(UINT8 - splitscreen players #, boolean - false to extend wipe/true for short wipe)**
- set restoremenu
- D_MapChange(...)
- M_ClearMenus(...)
Includes the following fixes:
- Encore no longer has over-long wipes when started from menu, only standard-length
- "Boss Intro" and Encore start-of-round sounds will always play, even if no Title Card is drawn
- No long wipe when restarting a Time Attack run
- Auto Encore and Auto Gamespeed are no longer accidentially forced if you've manually changed them to Off and Gear 2 before starting netgame
This commit is contained in:
toaster 2025-05-31 14:57:06 +01:00
parent 860b888460
commit 71e1179030
7 changed files with 109 additions and 121 deletions

View file

@ -1245,26 +1245,36 @@ void G_StartTitleCard(void)
// prepare status bar
ST_startTitleCard(); // <-- always must be called to init some variables
// The title card has been disabled for this map.
// Oh well.
if (demo.simplerewind || !G_IsTitleCardAvailable())
{
WipeStageTitle = false;
if (demo.simplerewind)
return;
sfxenum_t kstart = 0;
if (K_CheckBossIntro() == true)
{
kstart = sfx_ssa021;
}
else if (encoremode)
{
kstart = sfx_ruby2;
}
if (kstart)
{
// Play the guaranteed alt sounds
S_StartSound(NULL, kstart);
}
if (!G_IsTitleCardAvailable())
return;
// start the title card
WipeStageTitle = (gamestate == GS_LEVEL);
// play the sound
if (WipeStageTitle)
if (WipeStageTitle && !kstart)
{
sfxenum_t kstart = sfx_kstart;
if (K_CheckBossIntro() == true)
kstart = sfx_ssa021;
else if (encoremode == true)
kstart = sfx_ruby2;
S_StartSound(NULL, kstart);
// Play the standard titlecard sound
S_StartSound(NULL, sfx_kstart);
}
}
@ -5379,7 +5389,7 @@ void G_InitNew(UINT8 pencoremode, INT32 map, boolean resetplayer, boolean skippr
S_ResumeAudio();
}
prevencoremode = ((!Playing()) ? false : encoremode);
prevencoremode = encoremode;
encoremode = pencoremode;
legitimateexit = false; // SRB2Kart
@ -5831,7 +5841,7 @@ boolean G_GetExitGameFlag(void)
// Same deal with retrying.
void G_SetRetryFlag(void)
{
if (retrying == false)
if (retrying == false && grandprixinfo.gp)
{
grandprixinfo.rank.continuesUsed++;
}

View file

@ -944,6 +944,7 @@ void M_CupSelectTick(void);
void M_LevelSelectHandler(INT32 choice);
void M_LevelSelectTick(void);
void M_MenuToLevelPreamble(UINT8 ssplayers, boolean nowipe);
void M_LevelSelected(INT16 add, boolean menuupdate);
boolean M_LevelSelectCupSwitch(boolean next, boolean skipones);

View file

@ -614,34 +614,19 @@ void M_StartTimeAttack(INT32 choice)
{
modeattacking |= ATTACKING_SPB;
}
if (gamestate == GS_MENU)
{
encoremode = true; // guarantees short wipe
}
modeprefix = "spb-";
}
// DON'T SOFTLOCK
CON_ToggleOff();
// Still need to reset devmode
cht_debug = 0;
if (demo.playback)
G_StopDemo();
splitscreen = 0;
SplitScreen_OnChange();
S_StartSound(NULL, sfx_s3k63);
paused = false;
S_StopMusicCredit();
// Early fadeout to let the sound finish playing
F_WipeStartScreen();
V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31);
F_WipeEndScreen();
F_RunWipe(wipe_level_toblack, wipedefs[wipe_level_toblack], false, "FADEMAP0", false, false);
SV_StartSinglePlayerServer(levellist.newgametype, false);
M_MenuToLevelPreamble(0, (gamestate != GS_MENU || cv_dummyspbattack.value == 1));
gpath = va("%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s",
srb2home, timeattackfolder);
@ -659,8 +644,17 @@ void M_StartTimeAttack(INT32 choice)
restoreMenu = &PLAY_TimeAttackDef;
D_MapChange(
levellist.choosemap+1,
levellist.newgametype,
(cv_dummyspbattack.value == 1),
true,
1,
false,
false
);
M_ClearMenus(true);
D_MapChange(levellist.choosemap+1, levellist.newgametype, (cv_dummyspbattack.value == 1), 1, 1, false, false);
G_UpdateTimeStickerMedals(levellist.choosemap, true);
}

View file

@ -57,26 +57,7 @@ static void M_StartCup(UINT8 entry)
entry = UINT8_MAX;
}
S_StartSound(NULL, sfx_s3k63);
paused = false;
S_StopMusicCredit();
// Early fadeout to let the sound finish playing
F_WipeStartScreen();
V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31);
F_WipeEndScreen();
F_RunWipe(wipe_level_toblack, wipedefs[wipe_level_toblack], false, "FADEMAP0", false, false);
if (cv_maxconnections.value < ssplayers+1)
CV_SetValue(&cv_maxconnections, ssplayers+1);
if (splitscreen != ssplayers)
{
splitscreen = ssplayers;
SplitScreen_OnChange();
}
M_MenuToLevelPreamble(ssplayers, false);
if (entry == UINT8_MAX)
{
@ -135,10 +116,6 @@ static void M_StartCup(UINT8 entry)
}
}
paused = false;
SV_StartSinglePlayerServer(levellist.newgametype, levellist.netgame);
M_ClearMenus(true);
restoreMenu = &PLAY_CupSelectDef;

View file

@ -657,6 +657,11 @@ void M_LevelSelectInit(INT32 choice)
case 0:
levellist.levelsearch.grandprix = false;
levellist.levelsearch.timeattack = false;
CV_StealthSet(&cv_kartbot, cv_dummymatchbots.string);
CV_StealthSet(&cv_kartencore, (cv_dummygpencore.value == 1) ? "On" : "Auto");
CV_StealthSet(&cv_kartspeed, (cv_dummykartspeed.value == KARTSPEED_NORMAL) ? "Auto Gear" : cv_dummykartspeed.string);
break;
case 1:
levellist.levelsearch.grandprix = false;
@ -689,6 +694,40 @@ void M_LevelSelectInit(INT32 choice)
}
}
void M_MenuToLevelPreamble(UINT8 ssplayers, boolean nowipe)
{
cht_debug = 0;
if (demo.playback)
G_StopDemo();
if (cv_maxconnections.value < ssplayers+1)
CV_SetValue(&cv_maxconnections, ssplayers+1);
if (splitscreen != ssplayers)
{
splitscreen = ssplayers;
SplitScreen_OnChange();
}
paused = false;
S_StopMusicCredit();
if (!nowipe)
{
S_StartSound(NULL, sfx_s3k63);
// Early fadeout to let the sound finish playing
F_WipeStartScreen();
V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31);
F_WipeEndScreen();
F_RunWipe(wipe_level_toblack, wipedefs[wipe_level_toblack], false, "FADEMAP0", false, false);
}
SV_StartSinglePlayerServer(levellist.newgametype, levellist.netgame);
}
void M_LevelSelected(INT16 add, boolean menuupdate)
{
UINT8 i = 0;
@ -733,70 +772,35 @@ void M_LevelSelected(INT16 add, boolean menuupdate)
{
if (gamestate == GS_MENU)
{
UINT8 ssplayers = levellist.levelsearch.tutorial ? 0 : cv_splitplayers.value-1;
netgame = false;
multiplayer = true;
strlcpy(connectedservername, cv_servername.string, MAXSERVERNAME);
M_MenuToLevelPreamble(
(levellist.levelsearch.tutorial
? 0
: cv_splitplayers.value-1
),
(
(cv_kartencore.value == 1)
&& (gametypes[levellist.newgametype]->rules & GTR_ENCORE)
)
);
// Still need to reset devmode
cht_debug = 0;
if (demo.playback)
G_StopDemo();
/*if (levellist.choosemap == 0)
levellist.choosemap = G_RandMap(G_TOLFlag(levellist.newgametype), -1, 0, 0, false, NULL);*/
if (cv_maxconnections.value < ssplayers+1)
CV_SetValue(&cv_maxconnections, ssplayers+1);
if (splitscreen != ssplayers)
{
splitscreen = ssplayers;
SplitScreen_OnChange();
}
S_StartSound(NULL, sfx_s3k63);
paused = false;
S_StopMusicCredit();
// Early fadeout to let the sound finish playing
F_WipeStartScreen();
V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31);
F_WipeEndScreen();
F_RunWipe(wipe_level_toblack, wipedefs[wipe_level_toblack], false, "FADEMAP0", false, false);
SV_StartSinglePlayerServer(levellist.newgametype, levellist.netgame);
if (!levellist.netgame)
CV_StealthSet(&cv_kartbot, cv_dummymatchbots.string);
CV_StealthSet(&cv_kartencore, (cv_dummygpencore.value == 1) ? "On" : "Auto");
CV_StealthSet(&cv_kartspeed, (cv_dummykartspeed.value == KARTSPEED_NORMAL) ? "Auto Gear" : cv_dummykartspeed.string);
D_MapChange(levellist.choosemap+1, levellist.newgametype, (cv_kartencore.value == 1), 1, 1, false, false);
if (levellist.netgame == true)
{
restoreMenu = &PLAY_MP_OptSelectDef;
}
else /*if (!M_GameTrulyStarted() ||
levellist.levelsearch.tutorial)*/
{
restoreMenu = currentMenu;
}
restoreMenu = (levellist.netgame)
? &PLAY_MP_OptSelectDef
: currentMenu;
restorelevellist = levellist;
}
else
{
// directly do the map change
D_MapChange(levellist.choosemap+1, levellist.newgametype, (cv_kartencore.value == 1), 1, 1, false, false);
}
D_MapChange(
levellist.choosemap+1,
levellist.newgametype,
(cv_kartencore.value == 1),
true,
1,
false,
false
);
M_ClearMenus(true);
}

View file

@ -8513,7 +8513,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
wipegamestate = gamestate; // Don't fade if reloading the gamestate
// Encore mode fade to pink to white
// This is handled BEFORE sounds are stopped.
else if (encoremode && !prevencoremode && modeattacking == ATTACKING_NONE && !demo.simplerewind)
else if (encoremode && !prevencoremode && !demo.simplerewind)
{
if (rendermode != render_none)
{

View file

@ -737,6 +737,8 @@ void ST_startTitleCard(void)
lt_ticker = lt_exitticker = lt_lasttic = 0;
lt_endtime = 4*TICRATE; // + (10*NEWTICRATERATIO);
lt_fade = 0;
WipeStageTitle = false;
}
//