Browse Source

Do not create ENGINE in headless mode

Ivan Savenko 7 months ago
parent
commit
4684756c49
3 changed files with 12 additions and 16 deletions
  1. 3 7
      client/GameEngine.cpp
  2. 0 1
      client/GameEngine.h
  3. 9 8
      clientapp/EntryPoint.cpp

+ 3 - 7
client/GameEngine.cpp

@@ -58,7 +58,9 @@ ObjectConstruction::~ObjectConstruction()
 	ENGINE->captureChildren = !ENGINE->createdObj.empty();
 }
 
-void GameEngine::init()
+GameEngine::GameEngine()
+	: captureChildren(false)
+	, fakeStatusBar(std::make_shared<EmptyStatusBar>())
 {
 	inGuiThread = true;
 
@@ -133,12 +135,6 @@ void GameEngine::updateFrame()
 	ENGINE->cursor().update();
 }
 
-GameEngine::GameEngine()
-	: captureChildren(false)
-	, fakeStatusBar(std::make_shared<EmptyStatusBar>())
-{
-}
-
 GameEngine::~GameEngine()
 {
 	// enforce deletion order on shutdown

+ 0 - 1
client/GameEngine.h

@@ -108,7 +108,6 @@ public:
 	GameEngine();
 	~GameEngine();
 
-	void init();
 	[[noreturn]] void mainLoop();
 
 	/// called whenever SDL_WINDOWEVENT_RESTORED is reported or the user selects a different resolution, requiring to center/resize all windows

+ 9 - 8
clientapp/EntryPoint.cpp

@@ -24,7 +24,6 @@
 #include "../client/mainmenu/CMainMenu.h"
 #include "../client/render/Graphics.h"
 #include "../client/render/IRenderHandler.h"
-#include "../client/render/IScreenHandler.h"
 #include "../client/windows/CMessage.h"
 #include "../client/windows/InfoWindows.h"
 
@@ -294,13 +293,13 @@ int main(int argc, char * argv[])
 
 	srand ( (unsigned int)time(nullptr) );
 
-	ENGINE = std::make_unique<GameEngine>();
-
 	if(!settings["session"]["headless"].Bool())
-		ENGINE->init();
+		ENGINE = std::make_unique<GameEngine>();
 
 	GAME = std::make_unique<GameInstance>();
-	ENGINE->setEngineUser(GAME.get());
+
+	if (ENGINE)
+		ENGINE->setEngineUser(GAME.get());
 	
 #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
@@ -331,7 +330,7 @@ int main(int argc, char * argv[])
 		handleFatalError(criticalInitializationError.value(), false);
 	}
 
-	if(!settings["session"]["headless"].Bool())
+	if (ENGINE)
 	{
 		pomtime.getDiff();
 		graphics = new Graphics(); // should be before curh
@@ -380,7 +379,7 @@ int main(int argc, char * argv[])
 
 	try
 	{
-		if(!settings["session"]["headless"].Bool())
+		if (ENGINE)
 		{
 			checkForModLoadingFailure();
 			ENGINE->mainLoop();
@@ -396,6 +395,7 @@ int main(int argc, char * argv[])
 	catch (const GameShutdownException & )
 	{
 		// no-op - just break out of main loop
+		logGlobal->info("Main loop termination requested");
 	}
 
 	GAME->server().endNetwork();
@@ -405,7 +405,8 @@ int main(int argc, char * argv[])
 		if(GAME->server().client)
 			GAME->server().endGameplay();
 
-		ENGINE->windows().clear();
+		if (ENGINE)
+			ENGINE->windows().clear();
 	}
 
 	GAME.reset();