- reduce backend's dependency on game state by using callbacks.

This commit is contained in:
Christoph Oelckers 2020-04-11 18:22:21 +02:00
commit 56f2b2ac56
29 changed files with 289 additions and 276 deletions

View file

@ -106,6 +106,7 @@
#include "md5.h"
#include "c_buttons.h"
#include "d_buttons.h"
#include "i_interface.h"
EXTERN_CVAR(Bool, hud_althud)
EXTERN_CVAR(Int, vr_mode)
@ -2541,6 +2542,19 @@ static const char *DoomButtons[] =
CVAR(Bool, lookspring, true, CVAR_ARCHIVE); // Generate centerview when -mlook encountered?
EXTERN_CVAR(String, language)
CUSTOM_CVAR(Int, mouse_capturemode, 1, CVAR_GLOBALCONFIG | CVAR_ARCHIVE)
{
if (self < 0)
{
self = 0;
}
else if (self > 2)
{
self = 2;
}
}
void Mlook_ReleaseHandler()
{
if (lookspring)
@ -2560,6 +2574,56 @@ bool StrTable_ValidFilter(const char* str)
return stricmp(str, GameNames[gameinfo.gametype]) == 0;
}
bool System_WantGuiCapture()
{
bool wantCapt;
if (menuactive == MENU_Off)
{
wantCapt = ConsoleState == c_down || ConsoleState == c_falling || chatmodeon;
}
else
{
wantCapt = (menuactive == MENU_On || menuactive == MENU_OnNoPause);
}
// [ZZ] check active event handlers that want the UI processing
if (!wantCapt && primaryLevel->localEventManager->CheckUiProcessors())
wantCapt = true;
return wantCapt;
}
bool System_WantLeftButton()
{
return (gamestate == GS_DEMOSCREEN || gamestate == GS_TITLELEVEL);
}
bool System_NetGame()
{
return netgame;
}
bool System_WantNativeMouse()
{
return primaryLevel->localEventManager->CheckRequireMouse();
}
static bool System_CaptureModeInGame()
{
switch (mouse_capturemode)
{
default:
case 0:
return gamestate == GS_LEVEL;
case 1:
return gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_FINALE;
case 2:
return true;
}
}
//==========================================================================
//
// D_DoomMain
@ -2588,6 +2652,16 @@ static int D_DoomMain_Internal (void)
StrTable_GetGender
};
GStrings.SetCallbacks(&stblcb);
static SystemCallbacks syscb =
{
System_WantGuiCapture,
System_WantLeftButton,
System_NetGame,
System_WantNativeMouse,
System_CaptureModeInGame,
};
sysCallbacks = &syscb;
std::set_new_handler(NewFailure);
const char *batchout = Args->CheckValue("-errorlog");
@ -2872,7 +2946,6 @@ static int D_DoomMain_Internal (void)
C_InitConback();
StartScreen->Progress();
GPalette.Init(NUM_TRANSLATION_TABLES);
V_InitFonts();
// [CW] Parse any TEAMINFO lumps.