From 7f83e0d1343e89b2dc584d018ee1e45dd343f7a9 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 9 May 2017 11:09:58 +0100 Subject: [PATCH] * Prevent crash if you go to a map and it doesn't exist. * Handle music fix in smarter way. * Enums! --- src/dehacked.c | 2 +- src/f_finale.c | 21 ++++++++++----------- src/f_finale.h | 11 +++++++++-- src/g_game.c | 17 +++++++++++++---- src/p_setup.c | 2 -- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 71939ade5..73d52d9bf 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8646,7 +8646,7 @@ static inline int lib_getenum(lua_State *L) lua_pushinteger(L, titlemap); return 1; } else if (fastcmp(word,"titlemapinaction")) { - lua_pushboolean(L, titlemapinaction); + lua_pushboolean(L, (titlemapinaction != TITLEMAP_OFF)); return 1; } else if (fastcmp(word,"gametype")) { lua_pushinteger(L, gametype); diff --git a/src/f_finale.c b/src/f_finale.c index 2d391a4d8..29e7e83fa 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -38,8 +38,7 @@ // 0 = text, 1 = art screen static INT32 finalecount; INT32 titlescrollspeed = 80; -boolean titlemapinaction = false; -boolean titlemaptransition = false; +UINT8 titlemapinaction = TITLEMAP_OFF; static INT32 timetonext; // Delay between screen changes static INT32 continuetime; // Short delay when continuing @@ -1421,6 +1420,8 @@ void F_GameEndTicker(void) // ============== void F_StartTitleScreen(void) { + S_ChangeMusicInternal("_title", looptitle); + if (gamestate != GS_TITLESCREEN && gamestate != GS_WAITINGPLAYERS) finalecount = 0; else @@ -1431,7 +1432,7 @@ void F_StartTitleScreen(void) mapthing_t *startpos; gamestate_t prevwipegamestate = wipegamestate; - titlemapinaction = titlemaptransition = true; + titlemapinaction = TITLEMAP_LOADING; gamemap = titlemap; if (!mapheaderinfo[gamemap-1]) @@ -1440,7 +1441,10 @@ void F_StartTitleScreen(void) maptol = mapheaderinfo[gamemap-1]->typeoflevel; globalweather = mapheaderinfo[gamemap-1]->weather; - G_DoLoadLevel(true); // handles music change + G_DoLoadLevel(true); + if (!titlemap) + return; + players[displayplayer].playerstate = PST_DEAD; // Don't spawn the player in dummy (I'm still a filthy cheater) // Set Default Position @@ -1465,21 +1469,16 @@ void F_StartTitleScreen(void) camera.x = camera.y = camera.z = camera.angle = camera.aiming = 0; camera.subsector = NULL; // toast is filthy too } + camera.chase = true; camera.height = 0; - //camera.x = camera.y = camera.height = camera.aiming = 0; - //camera.z = 128*FRACUNIT; - - //CON_ClearHUD(); - wipegamestate = prevwipegamestate; } else { - titlemapinaction = false; + titlemapinaction = TITLEMAP_OFF; gamemap = 1; // g_game.c - S_ChangeMusicInternal("_title", looptitle); CON_ClearHUD(); } diff --git a/src/f_finale.h b/src/f_finale.h index 7d41b5720..aadc64ad0 100644 --- a/src/f_finale.h +++ b/src/f_finale.h @@ -61,8 +61,15 @@ void F_ContinueTicker(void); void F_ContinueDrawer(void); extern INT32 titlescrollspeed; -extern boolean titlemapinaction; -extern boolean titlemaptransition; + +typedef enum +{ + TITLEMAP_OFF = 0, + TITLEMAP_LOADING, + TITLEMAP_RUNNING +} titlemap_enum; + +extern UINT8 titlemapinaction; // // WIPE diff --git a/src/g_game.c b/src/g_game.c index a3b2d9528..01d744077 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1636,10 +1636,19 @@ void G_DoLoadLevel(boolean resetplayer) Y_EndIntermission(); // cleanup - if (titlemaptransition) - titlemaptransition = false; + if (titlemapinaction == TITLEMAP_LOADING) + { + if (W_CheckNumForName(G_BuildMapName(gamemap)) == LUMPERROR) + { + titlemap = 0; // let's not infinite recursion ok + Command_ExitGame_f(); + return; + } + + titlemapinaction = TITLEMAP_RUNNING; + } else - titlemapinaction = false; + titlemapinaction = TITLEMAP_OFF; G_SetGamestate(GS_LEVEL); @@ -1650,7 +1659,7 @@ void G_DoLoadLevel(boolean resetplayer) } // Setup the level. - if (!P_SetupLevel(false)) + if (!P_SetupLevel(false)) // this never returns false? { // fail so reset game stuff Command_ExitGame_f(); diff --git a/src/p_setup.c b/src/p_setup.c index 85f5d346c..69c60c3ac 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2646,8 +2646,6 @@ boolean P_SetupLevel(boolean skipprecip) /// ... as long as this isn't a titlemap transition, that is if (!titlemapinaction) S_Start(); - else - S_ChangeMusicInternal("_title", looptitle); // Let's fade to black here // But only if we didn't do the special stage wipe