Do not create ENGINE in headless mode

This commit is contained in:
Ivan Savenko
2025-03-12 13:33:12 +00:00
parent eaad6f9ce0
commit 4684756c49
3 changed files with 12 additions and 16 deletions
+3 -7
View File
@@ -58,7 +58,9 @@ ObjectConstruction::~ObjectConstruction()
ENGINE->captureChildren = !ENGINE->createdObj.empty(); ENGINE->captureChildren = !ENGINE->createdObj.empty();
} }
void GameEngine::init() GameEngine::GameEngine()
: captureChildren(false)
, fakeStatusBar(std::make_shared<EmptyStatusBar>())
{ {
inGuiThread = true; inGuiThread = true;
@@ -133,12 +135,6 @@ void GameEngine::updateFrame()
ENGINE->cursor().update(); ENGINE->cursor().update();
} }
GameEngine::GameEngine()
: captureChildren(false)
, fakeStatusBar(std::make_shared<EmptyStatusBar>())
{
}
GameEngine::~GameEngine() GameEngine::~GameEngine()
{ {
// enforce deletion order on shutdown // enforce deletion order on shutdown
-1
View File
@@ -108,7 +108,6 @@ public:
GameEngine(); GameEngine();
~GameEngine(); ~GameEngine();
void init();
[[noreturn]] void mainLoop(); [[noreturn]] void mainLoop();
/// called whenever SDL_WINDOWEVENT_RESTORED is reported or the user selects a different resolution, requiring to center/resize all windows /// called whenever SDL_WINDOWEVENT_RESTORED is reported or the user selects a different resolution, requiring to center/resize all windows
+9 -8
View File
@@ -24,7 +24,6 @@
#include "../client/mainmenu/CMainMenu.h" #include "../client/mainmenu/CMainMenu.h"
#include "../client/render/Graphics.h" #include "../client/render/Graphics.h"
#include "../client/render/IRenderHandler.h" #include "../client/render/IRenderHandler.h"
#include "../client/render/IScreenHandler.h"
#include "../client/windows/CMessage.h" #include "../client/windows/CMessage.h"
#include "../client/windows/InfoWindows.h" #include "../client/windows/InfoWindows.h"
@@ -294,13 +293,13 @@ int main(int argc, char * argv[])
srand ( (unsigned int)time(nullptr) ); srand ( (unsigned int)time(nullptr) );
ENGINE = std::make_unique<GameEngine>();
if(!settings["session"]["headless"].Bool()) if(!settings["session"]["headless"].Bool())
ENGINE->init(); ENGINE = std::make_unique<GameEngine>();
GAME = std::make_unique<GameInstance>(); GAME = std::make_unique<GameInstance>();
ENGINE->setEngineUser(GAME.get());
if (ENGINE)
ENGINE->setEngineUser(GAME.get());
#ifndef VCMI_NO_THREADED_LOAD #ifndef VCMI_NO_THREADED_LOAD
//we can properly play intro only in the main thread, so we have to move loading to the separate thread //we can properly play intro only in the main thread, so we have to move loading to the separate thread
@@ -331,7 +330,7 @@ int main(int argc, char * argv[])
handleFatalError(criticalInitializationError.value(), false); handleFatalError(criticalInitializationError.value(), false);
} }
if(!settings["session"]["headless"].Bool()) if (ENGINE)
{ {
pomtime.getDiff(); pomtime.getDiff();
graphics = new Graphics(); // should be before curh graphics = new Graphics(); // should be before curh
@@ -380,7 +379,7 @@ int main(int argc, char * argv[])
try try
{ {
if(!settings["session"]["headless"].Bool()) if (ENGINE)
{ {
checkForModLoadingFailure(); checkForModLoadingFailure();
ENGINE->mainLoop(); ENGINE->mainLoop();
@@ -396,6 +395,7 @@ int main(int argc, char * argv[])
catch (const GameShutdownException & ) catch (const GameShutdownException & )
{ {
// no-op - just break out of main loop // no-op - just break out of main loop
logGlobal->info("Main loop termination requested");
} }
GAME->server().endNetwork(); GAME->server().endNetwork();
@@ -405,7 +405,8 @@ int main(int argc, char * argv[])
if(GAME->server().client) if(GAME->server().client)
GAME->server().endGameplay(); GAME->server().endGameplay();
ENGINE->windows().clear(); if (ENGINE)
ENGINE->windows().clear();
} }
GAME.reset(); GAME.reset();