mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-02-26 21:30:52 +00:00
- started with SW's new main loop.
Intro and menu are done, the game loop is quite a mess, unfortunately.
This commit is contained in:
parent
57efb26567
commit
60275c9b6b
6 changed files with 128 additions and 185 deletions
|
@ -37,7 +37,7 @@ int timerInit(int const tickspersecond)
|
||||||
|
|
||||||
TArray<void(*)(void)> callbacks;
|
TArray<void(*)(void)> callbacks;
|
||||||
|
|
||||||
ATTRIBUTE((flatten)) void timerUpdateClock(void)
|
void timerUpdateClock(void)
|
||||||
{
|
{
|
||||||
auto time = steady_clock::now();
|
auto time = steady_clock::now();
|
||||||
auto elapsedTime = time - timerlastsample;
|
auto elapsedTime = time - timerlastsample;
|
||||||
|
|
|
@ -46,6 +46,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "raze_sound.h"
|
#include "raze_sound.h"
|
||||||
#include "sounds.h"
|
#include "sounds.h"
|
||||||
|
#include "gamestate.h"
|
||||||
|
|
||||||
#include "../../glbackend/glbackend.h"
|
#include "../../glbackend/glbackend.h"
|
||||||
|
|
||||||
|
@ -172,18 +173,17 @@ void GameInterface::MenuSound(EMenuSounds snd)
|
||||||
|
|
||||||
void GameInterface::MenuClosed()
|
void GameInterface::MenuClosed()
|
||||||
{
|
{
|
||||||
if (!LoadGameOutsideMoveLoop)
|
if (!SavegameLoaded)
|
||||||
{
|
{
|
||||||
ResumeGame();
|
ResumeGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern SWBOOL InMenuLevel;
|
|
||||||
extern SWBOOL ExitLevel, NewGame;
|
extern SWBOOL ExitLevel, NewGame;
|
||||||
|
|
||||||
bool GameInterface::CanSave()
|
bool GameInterface::CanSave()
|
||||||
{
|
{
|
||||||
return (!CommEnabled && numplayers ==1 && /*!DemoMode &&*/ !InMenuLevel && !TEST(Player[myconnectindex].Flags, PF_DEAD));
|
return (gamestate == GS_LEVEL && !CommEnabled && numplayers ==1 && /*!DemoMode &&*/ !TEST(Player[myconnectindex].Flags, PF_DEAD));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameInterface::StartGame(FNewGameStartup& gs)
|
void GameInterface::StartGame(FNewGameStartup& gs)
|
||||||
|
|
|
@ -89,6 +89,9 @@ CVAR(Bool, sw_darts, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||||
|
|
||||||
BEGIN_SW_NS
|
BEGIN_SW_NS
|
||||||
|
|
||||||
|
void Logo(const CompletionFunc& completion);
|
||||||
|
|
||||||
|
|
||||||
void pClearSpriteList(PLAYERp pp);
|
void pClearSpriteList(PLAYERp pp);
|
||||||
|
|
||||||
extern int sw_snd_scratch;
|
extern int sw_snd_scratch;
|
||||||
|
@ -100,9 +103,8 @@ int Follow_posx=0,Follow_posy=0;
|
||||||
SWBOOL NoMeters = FALSE;
|
SWBOOL NoMeters = FALSE;
|
||||||
SWBOOL FinishAnim = 0;
|
SWBOOL FinishAnim = 0;
|
||||||
SWBOOL ReloadPrompt = FALSE;
|
SWBOOL ReloadPrompt = FALSE;
|
||||||
SWBOOL NewGame = TRUE;
|
SWBOOL NewGame = FALSE;
|
||||||
SWBOOL InMenuLevel = FALSE;
|
SWBOOL SavegameLoaded = FALSE;
|
||||||
SWBOOL LoadGameOutsideMoveLoop = FALSE;
|
|
||||||
//Miscellaneous variables
|
//Miscellaneous variables
|
||||||
SWBOOL FinishedLevel = FALSE;
|
SWBOOL FinishedLevel = FALSE;
|
||||||
short screenpeek = 0;
|
short screenpeek = 0;
|
||||||
|
@ -166,7 +168,6 @@ int ThemeTrack[6];
|
||||||
|
|
||||||
/// L O C A L P R O T O T Y P E S /////////////////////////////////////////////////////////
|
/// L O C A L P R O T O T Y P E S /////////////////////////////////////////////////////////
|
||||||
void SybexScreen(void);
|
void SybexScreen(void);
|
||||||
void MenuLevel(void);
|
|
||||||
void StatScreen(PLAYERp mpp);
|
void StatScreen(PLAYERp mpp);
|
||||||
void InitRunLevel(void);
|
void InitRunLevel(void);
|
||||||
void RunLevel(void);
|
void RunLevel(void);
|
||||||
|
@ -295,6 +296,52 @@ bool InitGame()
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void StartMenu()
|
||||||
|
{
|
||||||
|
M_StartControlPanel(false);
|
||||||
|
if (SW_SHAREWARE && FinishAnim)
|
||||||
|
{
|
||||||
|
// go to ordering menu only if shareware
|
||||||
|
M_SetMenu(NAME_CreditsMenu);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
M_SetMenu(NAME_Mainmenu);
|
||||||
|
}
|
||||||
|
FinishAnim = 0;
|
||||||
|
gamestate = GS_MENUSCREEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void DrawMenuLevelScreen(void)
|
||||||
|
{
|
||||||
|
const int TITLE_PIC = 2324;
|
||||||
|
twod->ClearScreen();
|
||||||
|
totalclocklock = totalclock;
|
||||||
|
DrawTexture(twod, tileGetTexture(TITLE_PIC), 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal,
|
||||||
|
DTA_Color, shadeToLight(20), TAG_DONE);
|
||||||
|
|
||||||
|
if (CommEnabled)
|
||||||
|
{
|
||||||
|
sprintf(ds, "Lo Wang is waiting for other players...");
|
||||||
|
MNU_DrawString(160, 170, ds, 1, 16, 0);
|
||||||
|
|
||||||
|
sprintf(ds, "They are afraid!");
|
||||||
|
MNU_DrawString(160, 180, ds, 1, 16, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void InitNewGame(void)
|
void InitNewGame(void)
|
||||||
{
|
{
|
||||||
int i, ready_bak;
|
int i, ready_bak;
|
||||||
|
@ -419,11 +466,11 @@ void InitPlayerGameSettings(void)
|
||||||
|
|
||||||
void InitRunLevel(void)
|
void InitRunLevel(void)
|
||||||
{
|
{
|
||||||
if (LoadGameOutsideMoveLoop)
|
if (SavegameLoaded)
|
||||||
{
|
{
|
||||||
int SavePlayClock;
|
int SavePlayClock;
|
||||||
extern int PlayClock;
|
extern int PlayClock;
|
||||||
LoadGameOutsideMoveLoop = FALSE;
|
SavegameLoaded = FALSE;
|
||||||
// contains what is needed from calls below
|
// contains what is needed from calls below
|
||||||
if (snd_ambience)
|
if (snd_ambience)
|
||||||
StartAmbientSound();
|
StartAmbientSound();
|
||||||
|
@ -520,16 +567,9 @@ void MoveTicker(void)
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
void InitLevel(void)
|
void InitLevel(void)
|
||||||
{
|
{
|
||||||
if (LoadGameOutsideMoveLoop)
|
if (SavegameLoaded)
|
||||||
{
|
{
|
||||||
InitLevelGlobals();
|
InitLevelGlobals();
|
||||||
return;
|
return;
|
||||||
|
@ -549,7 +589,7 @@ void InitLevel(void)
|
||||||
if (!maprec) maprec = currentLevel;
|
if (!maprec) maprec = currentLevel;
|
||||||
if (!maprec)
|
if (!maprec)
|
||||||
{
|
{
|
||||||
NewGame = false;
|
I_Error("Attempt to start game without level");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
InitLevelGlobals2();
|
InitLevelGlobals2();
|
||||||
|
@ -719,7 +759,7 @@ void NewLevel(void)
|
||||||
InitLevel();
|
InitLevel();
|
||||||
RunLevel();
|
RunLevel();
|
||||||
}
|
}
|
||||||
while (LoadGameOutsideMoveLoop);
|
while (SavegameLoaded);
|
||||||
STAT_Update(false);
|
STAT_Update(false);
|
||||||
|
|
||||||
// for good measure do this
|
// for good measure do this
|
||||||
|
@ -730,126 +770,19 @@ void NewLevel(void)
|
||||||
|
|
||||||
TerminateLevel();
|
TerminateLevel();
|
||||||
|
|
||||||
if (SW_SHAREWARE)
|
if (FinishAnim == ANIM_ZILLA || FinishAnim == ANIM_SERP)
|
||||||
{
|
{
|
||||||
if (FinishAnim)
|
STAT_Update(true);
|
||||||
{
|
PlaySong(nullptr, ThemeSongs[0], ThemeTrack[0]);
|
||||||
PlaySong(nullptr, ThemeSongs[0], ThemeTrack[0]);
|
StartMenu();
|
||||||
MenuLevel();
|
|
||||||
STAT_Update(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (FinishAnim == ANIM_ZILLA || FinishAnim == ANIM_SERP)
|
|
||||||
{
|
|
||||||
PlaySong(nullptr, ThemeSongs[0], ThemeTrack[0]);
|
|
||||||
MenuLevel();
|
|
||||||
STAT_Update(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// CTW REMOVED END
|
// CTW REMOVED END
|
||||||
|
|
||||||
void DrawMenuLevelScreen(void)
|
|
||||||
{
|
|
||||||
const int TITLE_PIC = 2324;
|
|
||||||
twod->ClearScreen();
|
|
||||||
DrawTexture(twod, tileGetTexture(TITLE_PIC), 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal,
|
|
||||||
DTA_Color, shadeToLight(20), TAG_DONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
short PlayerQuitMenuLevel = -1;
|
short PlayerQuitMenuLevel = -1;
|
||||||
|
|
||||||
void MenuLevel(void)
|
|
||||||
{
|
|
||||||
short w,h;
|
|
||||||
|
|
||||||
M_StartControlPanel(false);
|
|
||||||
M_SetMenu(NAME_Mainmenu);
|
|
||||||
|
|
||||||
twod->ClearScreen();
|
|
||||||
videoNextPage();
|
|
||||||
|
|
||||||
//FadeOut(0, 0);
|
|
||||||
ready2send = 0;
|
|
||||||
totalclock = 0;
|
|
||||||
ototalclock = 0;
|
|
||||||
ExitLevel = FALSE;
|
|
||||||
InMenuLevel = TRUE;
|
|
||||||
|
|
||||||
DrawMenuLevelScreen();
|
|
||||||
|
|
||||||
if (CommEnabled)
|
|
||||||
{
|
|
||||||
sprintf(ds,"Lo Wang is waiting for other players...");
|
|
||||||
MNU_DrawString(160, 170, ds, 1, 16, 0);
|
|
||||||
|
|
||||||
sprintf(ds,"They are afraid!");
|
|
||||||
MNU_DrawString(160, 180, ds, 1, 16, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
videoNextPage();
|
|
||||||
//FadeIn(0, 3);
|
|
||||||
|
|
||||||
waitforeverybody();
|
|
||||||
|
|
||||||
inputState.ClearAllInput();
|
|
||||||
|
|
||||||
if (SW_SHAREWARE)
|
|
||||||
{
|
|
||||||
// go to ordering menu only if shareware
|
|
||||||
if (FinishAnim)
|
|
||||||
{
|
|
||||||
inputState.ClearKeyStatus(sc_Escape);
|
|
||||||
M_StartControlPanel(false);
|
|
||||||
M_SetMenu(NAME_CreditsMenu);
|
|
||||||
FinishAnim = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FinishAnim = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (TRUE)
|
|
||||||
{
|
|
||||||
handleevents();
|
|
||||||
D_ProcessEvents();
|
|
||||||
C_RunDelayedCommands();
|
|
||||||
|
|
||||||
// limits checks to max of 40 times a second
|
|
||||||
if (totalclock >= ototalclock + synctics)
|
|
||||||
{
|
|
||||||
ototalclock += synctics;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ExitLevel)
|
|
||||||
{
|
|
||||||
ExitLevel = FALSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// must lock the clock for drawing so animations will happen
|
|
||||||
totalclocklock = totalclock;
|
|
||||||
|
|
||||||
//drawscreen as fast as you can
|
|
||||||
DrawMenuLevelScreen();
|
|
||||||
DoUpdateSounds();
|
|
||||||
|
|
||||||
videoNextPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
inputState.ClearAllInput();
|
|
||||||
M_ClearMenus();
|
|
||||||
InMenuLevel = FALSE;
|
|
||||||
twod->ClearScreen();
|
|
||||||
videoNextPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern SWBOOL FinishedLevel;
|
extern SWBOOL FinishedLevel;
|
||||||
|
|
||||||
|
|
||||||
|
@ -907,35 +840,6 @@ void StatScreen(PLAYERp mpp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Transitioning helper.
|
|
||||||
void Logo(const CompletionFunc& completion);
|
|
||||||
|
|
||||||
int SyncScreenJob()
|
|
||||||
{
|
|
||||||
while (gamestate == GS_INTERMISSION || gamestate == GS_INTRO)
|
|
||||||
{
|
|
||||||
DoUpdateSounds();
|
|
||||||
handleevents();
|
|
||||||
updatePauseStatus();
|
|
||||||
D_ProcessEvents();
|
|
||||||
ControlInfo info;
|
|
||||||
CONTROL_GetInput(&info);
|
|
||||||
C_RunDelayedCommands();
|
|
||||||
|
|
||||||
RunScreenJobFrame(); // This handles continuation through its completion callback.
|
|
||||||
videoNextPage();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void GameIntro(void)
|
|
||||||
{
|
|
||||||
Logo([](bool) { gamestate = GS_LEVEL; });
|
|
||||||
SyncScreenJob();
|
|
||||||
MenuLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void getinput(SW_PACKET *, SWBOOL);
|
void getinput(SW_PACKET *, SWBOOL);
|
||||||
|
|
||||||
|
@ -956,7 +860,7 @@ void RunLevel(void)
|
||||||
D_ProcessEvents();
|
D_ProcessEvents();
|
||||||
updatePauseStatus();
|
updatePauseStatus();
|
||||||
|
|
||||||
if (LoadGameOutsideMoveLoop)
|
if (SavegameLoaded)
|
||||||
{
|
{
|
||||||
return; // Stop the game loop if a savegame was loaded from the menu.
|
return; // Stop the game loop if a savegame was loaded from the menu.
|
||||||
}
|
}
|
||||||
|
@ -996,9 +900,62 @@ void RunLevel(void)
|
||||||
int32_t GameInterface::app_main()
|
int32_t GameInterface::app_main()
|
||||||
{
|
{
|
||||||
InitGame();
|
InitGame();
|
||||||
|
gamestate = GS_STARTUP;
|
||||||
|
|
||||||
GameIntro();
|
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// if the menu initiazed a new game or loaded a savegame, switch to play mode.
|
||||||
|
if (NewGame || SavegameLoaded) gamestate = GS_LEVEL;
|
||||||
|
|
||||||
|
handleevents();
|
||||||
|
updatePauseStatus();
|
||||||
|
D_ProcessEvents();
|
||||||
|
DoUpdateSounds();
|
||||||
|
switch (gamestate)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case GS_STARTUP:
|
||||||
|
totalclock = 0;
|
||||||
|
ototalclock = 0;
|
||||||
|
|
||||||
|
if (userConfig.CommandMap.IsNotEmpty())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!userConfig.nologo) Logo([](bool) { StartMenu(); });
|
||||||
|
else StartMenu();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GS_MENUSCREEN:
|
||||||
|
case GS_FULLCONSOLE:
|
||||||
|
DrawMenuLevelScreen();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GS_LEVEL:
|
||||||
|
//if (GameTicker()) gamestate = GS_STARTUP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GS_INTERMISSION:
|
||||||
|
case GS_INTRO:
|
||||||
|
RunScreenJobFrame(); // This handles continuation through its completion callback.
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
videoNextPage();
|
||||||
|
}
|
||||||
|
catch (CRecoverableError& err)
|
||||||
|
{
|
||||||
|
C_FullConsole();
|
||||||
|
Printf(TEXTCOLOR_RED "%s\n", err.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
handleevents();
|
handleevents();
|
||||||
|
@ -1009,6 +966,7 @@ int32_t GameInterface::app_main()
|
||||||
|
|
||||||
//SybexScreen();
|
//SybexScreen();
|
||||||
throw CExitEvent(0);
|
throw CExitEvent(0);
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ void MNU_DrawStringLarge(int x, int y, const char* string, int shade = 0, int al
|
||||||
#define pic_shadow_warrior 2366
|
#define pic_shadow_warrior 2366
|
||||||
|
|
||||||
#define m_defshade 2
|
#define m_defshade 2
|
||||||
extern SWBOOL LoadGameOutsideMoveLoop;
|
extern SWBOOL SavegameLoaded;
|
||||||
|
|
||||||
|
|
||||||
END_SW_NS
|
END_SW_NS
|
||||||
|
|
|
@ -654,19 +654,11 @@ bool GameInterface::SaveGame(FSaveGameNode *sv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern SWBOOL LoadGameOutsideMoveLoop;
|
extern SWBOOL SavegameLoaded;
|
||||||
extern SWBOOL InMenuLevel;
|
|
||||||
|
|
||||||
bool GameInterface::CleanupForLoad()
|
bool GameInterface::CleanupForLoad()
|
||||||
{
|
{
|
||||||
// Don't terminate until you've made sure conditions are valid for loading.
|
TerminateLevel();
|
||||||
if (InMenuLevel)
|
|
||||||
Mus_Stop();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//PauseAction();
|
|
||||||
TerminateLevel();
|
|
||||||
}
|
|
||||||
StopFX();
|
StopFX();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1108,15 +1100,8 @@ bool GameInterface::LoadGame(FSaveGameNode* sv)
|
||||||
DoPlayerDivePalette(Player+myconnectindex);
|
DoPlayerDivePalette(Player+myconnectindex);
|
||||||
DoPlayerNightVisionPalette(Player+myconnectindex);
|
DoPlayerNightVisionPalette(Player+myconnectindex);
|
||||||
|
|
||||||
|
SavegameLoaded = TRUE;
|
||||||
|
ready2send = 1;
|
||||||
|
|
||||||
LoadGameOutsideMoveLoop = TRUE;
|
|
||||||
if (!InMenuLevel)
|
|
||||||
{
|
|
||||||
ready2send = 1;
|
|
||||||
}
|
|
||||||
else ExitLevel = TRUE;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
#include "serializer.h"
|
#include "serializer.h"
|
||||||
#include "gamecontrol.h"
|
#include "gamecontrol.h"
|
||||||
|
#include "gamestate.h"
|
||||||
|
|
||||||
BEGIN_SW_NS
|
BEGIN_SW_NS
|
||||||
|
|
||||||
|
@ -280,9 +281,8 @@ void InitAmbient(int num, SPRITEp sp)
|
||||||
void StartAmbientSound(void)
|
void StartAmbientSound(void)
|
||||||
{
|
{
|
||||||
short i, nexti;
|
short i, nexti;
|
||||||
extern SWBOOL InMenuLevel;
|
|
||||||
|
if (gamestate != GS_LEVEL || !SoundEnabled()) return; // Don't restart ambience if no level is active! Will crash game.
|
||||||
if (InMenuLevel || !SoundEnabled()) return; // Don't restart ambience if no level is active! Will crash game.
|
|
||||||
|
|
||||||
TRAVERSE_SPRITE_STAT(headspritestat[STAT_AMBIENT], i, nexti)
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_AMBIENT], i, nexti)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue