Răsfoiți Sursa

Renamed CGuiHandler to GameEngine

- class CGuiHandler is now called GameEngine to better describe its
functionality
- renamed global GH to more clear ENGINE
- GH/ENGINE is now unique_ptr to make construction / deconstruction
order more clear and to allow interface / implementation split
- CGuiHandler.cpp/h is now called GameEngine.cpp/h and located in root
directory of client dir
Ivan Savenko 10 luni în urmă
părinte
comite
cacceda950
100 a modificat fișierele cu 778 adăugiri și 786 ștergeri
  1. 6 6
      client/ArtifactsUIController.cpp
  2. 2 2
      client/CMakeLists.txt
  3. 77 77
      client/CPlayerInterface.cpp
  4. 27 27
      client/CServerHandler.cpp
  5. 6 6
      client/Client.cpp
  6. 9 9
      client/ClientCommandManager.cpp
  7. 60 69
      client/GameEngine.cpp
  8. 5 5
      client/GameEngine.h
  9. 2 2
      client/HeroMovementController.cpp
  10. 4 4
      client/NetPacksClient.cpp
  11. 16 16
      client/NetPacksLobbyClient.cpp
  12. 29 29
      client/adventureMap/AdventureMapInterface.cpp
  13. 10 10
      client/adventureMap/AdventureMapShortcuts.cpp
  14. 3 3
      client/adventureMap/AdventureMapWidget.cpp
  15. 3 3
      client/adventureMap/AdventureOptions.cpp
  16. 11 11
      client/adventureMap/CInGameConsole.cpp
  17. 5 5
      client/adventureMap/CInfoBar.cpp
  18. 8 8
      client/adventureMap/CList.cpp
  19. 4 4
      client/adventureMap/CMinimap.cpp
  20. 1 1
      client/adventureMap/CResDataBar.cpp
  21. 1 1
      client/adventureMap/TurnTimerWidget.cpp
  22. 13 13
      client/battle/BattleActionsController.cpp
  23. 2 2
      client/battle/BattleAnimationClasses.cpp
  24. 13 13
      client/battle/BattleFieldController.cpp
  25. 6 6
      client/battle/BattleInterface.cpp
  26. 19 19
      client/battle/BattleInterfaceClasses.cpp
  27. 5 5
      client/battle/BattleObstacleController.cpp
  28. 2 2
      client/battle/BattleOverlayLogVisualizer.cpp
  29. 2 2
      client/battle/BattleProjectileController.cpp
  30. 4 4
      client/battle/BattleSiegeController.cpp
  31. 6 6
      client/battle/BattleStacksController.cpp
  32. 25 25
      client/battle/BattleWindow.cpp
  33. 3 3
      client/battle/CreatureAnimation.cpp
  34. 15 15
      client/eventsSDL/InputHandler.cpp
  35. 21 21
      client/eventsSDL/InputSourceGameController.cpp
  36. 9 9
      client/eventsSDL/InputSourceKeyboard.cpp
  37. 18 18
      client/eventsSDL/InputSourceMouse.cpp
  38. 6 6
      client/eventsSDL/InputSourceText.cpp
  39. 35 35
      client/eventsSDL/InputSourceTouch.cpp
  40. 2 2
      client/globalLobby/GlobalLobbyAddChannelWindow.cpp
  41. 21 21
      client/globalLobby/GlobalLobbyClient.cpp
  42. 1 1
      client/globalLobby/GlobalLobbyInviteWindow.cpp
  43. 1 1
      client/globalLobby/GlobalLobbyLoginWindow.cpp
  44. 1 1
      client/globalLobby/GlobalLobbyRoomWindow.cpp
  45. 1 1
      client/globalLobby/GlobalLobbyServerSetup.cpp
  46. 4 4
      client/globalLobby/GlobalLobbyWidget.cpp
  47. 2 2
      client/globalLobby/GlobalLobbyWindow.cpp
  48. 11 11
      client/gui/CIntObject.cpp
  49. 1 1
      client/gui/CIntObject.h
  50. 10 10
      client/gui/CursorHandler.cpp
  51. 7 7
      client/gui/EventDispatcher.cpp
  52. 3 3
      client/gui/EventsReceiver.cpp
  53. 3 3
      client/gui/InterfaceObjectConfigurable.cpp
  54. 4 4
      client/gui/WindowHandler.cpp
  55. 6 6
      client/lobby/CBonusSelection.cpp
  56. 1 1
      client/lobby/CCampaignInfoScreen.cpp
  57. 1 1
      client/lobby/CLobbyScreen.cpp
  58. 1 1
      client/lobby/CSavingScreen.cpp
  59. 1 1
      client/lobby/CScenarioInfoScreen.cpp
  60. 7 7
      client/lobby/CSelectionBase.cpp
  61. 15 15
      client/lobby/OptionsTab.cpp
  62. 6 6
      client/lobby/RandomMapTab.cpp
  63. 3 3
      client/lobby/SelectionTab.cpp
  64. 1 1
      client/mainmenu/CCampaignScreen.cpp
  65. 5 5
      client/mainmenu/CHighScoreScreen.cpp
  66. 27 26
      client/mainmenu/CMainMenu.cpp
  67. 3 3
      client/mainmenu/CPrologEpilogVideo.cpp
  68. 8 8
      client/mainmenu/CStatisticScreen.cpp
  69. 2 2
      client/mainmenu/CreditsScreen.cpp
  70. 3 3
      client/mapView/MapOverlayLogVisualizer.cpp
  71. 11 11
      client/mapView/MapRenderer.cpp
  72. 3 3
      client/mapView/MapView.cpp
  73. 2 2
      client/mapView/MapViewActions.cpp
  74. 3 3
      client/mapView/MapViewCache.cpp
  75. 6 6
      client/mapView/MapViewController.cpp
  76. 1 1
      client/mapView/mapHandler.cpp
  77. 4 4
      client/media/CMusicHandler.cpp
  78. 2 2
      client/media/CSoundHandler.cpp
  79. 4 4
      client/media/CVideoHandler.cpp
  80. 19 19
      client/render/AssetGenerator.cpp
  81. 3 3
      client/render/CAnimation.cpp
  82. 5 5
      client/render/Canvas.cpp
  83. 3 3
      client/render/CanvasImage.cpp
  84. 2 2
      client/render/IFont.cpp
  85. 1 1
      client/render/ImageLocator.cpp
  86. 4 4
      client/renderSDL/CBitmapFont.cpp
  87. 7 7
      client/renderSDL/CursorHardware.cpp
  88. 5 5
      client/renderSDL/CursorSoftware.cpp
  89. 2 2
      client/renderSDL/RenderHandler.cpp
  90. 2 2
      client/renderSDL/SDLImage.cpp
  91. 1 1
      client/renderSDL/SDL_Extensions.cpp
  92. 8 8
      client/renderSDL/ScalableImage.cpp
  93. 1 1
      client/renderSDL/ScreenHandler.cpp
  94. 5 5
      client/widgets/Buttons.cpp
  95. 1 1
      client/widgets/CArtifactsOfHeroBackpack.cpp
  96. 1 1
      client/widgets/CArtifactsOfHeroBase.cpp
  97. 1 1
      client/widgets/CArtifactsOfHeroMain.cpp
  98. 2 2
      client/widgets/CComponent.cpp
  99. 1 1
      client/widgets/CComponentHolder.cpp
  100. 13 13
      client/widgets/CGarrisonInt.cpp

+ 6 - 6
client/ArtifactsUIController.cpp

@@ -18,7 +18,7 @@
 #include "../lib/texts/CGeneralTextHandler.h"
 #include "../lib/mapObjects/CGHeroInstance.h"
 
-#include "gui/CGuiHandler.h"
+#include "GameEngine.h"
 #include "gui/WindowHandler.h"
 #include "widgets/CComponent.h"
 #include "windows/CWindowWithArtifacts.h"
@@ -63,7 +63,7 @@ bool ArtifactsUIController::askToAssemble(const CGHeroInstance * hero, const Art
 				boost::mutex::scoped_lock askLock(askAssembleArtifactMutex);
 				for(const auto combinedArt : assemblyPossibilities)
 				{
-					boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+					boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 					if(checkIgnored)
 					{
 						if(vstd::contains(ignoredArtifacts, combinedArt->getId()))
@@ -126,7 +126,7 @@ bool ArtifactsUIController::askToDisassemble(const CGHeroInstance * hero, const
 
 void ArtifactsUIController::artifactRemoved()
 {
-	for(const auto & artWin : GH.windows().findWindows<CWindowWithArtifacts>())
+	for(const auto & artWin : ENGINE->windows().findWindows<CWindowWithArtifacts>())
 		artWin->update();
 	LOCPLINT->waitWhileDialog();
 }
@@ -138,7 +138,7 @@ void ArtifactsUIController::artifactMoved()
 		numOfMovedArts--;
 
 	if(numOfMovedArts == 0)
-		for(const auto & artWin : GH.windows().findWindows<CWindowWithArtifacts>())
+		for(const auto & artWin : ENGINE->windows().findWindows<CWindowWithArtifacts>())
 		{
 			artWin->update();
 		}
@@ -159,12 +159,12 @@ void ArtifactsUIController::bulkArtMovementStart(size_t totalNumOfArts, size_t p
 
 void ArtifactsUIController::artifactAssembled()
 {
-	for(const auto & artWin : GH.windows().findWindows<CWindowWithArtifacts>())
+	for(const auto & artWin : ENGINE->windows().findWindows<CWindowWithArtifacts>())
 		artWin->update();
 }
 
 void ArtifactsUIController::artifactDisassembled()
 {
-	for(const auto & artWin : GH.windows().findWindows<CWindowWithArtifacts>())
+	for(const auto & artWin : ENGINE->windows().findWindows<CWindowWithArtifacts>())
 		artWin->update();
 }

+ 2 - 2
client/CMakeLists.txt

@@ -37,7 +37,6 @@ set(vcmiclientcommon_SRCS
 	eventsSDL/InputSourceTouch.cpp
 	eventsSDL/InputSourceGameController.cpp
 
-	gui/CGuiHandler.cpp
 	gui/CIntObject.cpp
 	gui/CursorHandler.cpp
 	gui/EventDispatcher.cpp
@@ -180,6 +179,7 @@ set(vcmiclientcommon_SRCS
 	xBRZ/xbrz.cpp
 
 	ArtifactsUIController.cpp
+	GameEngine.cpp
 	CGameInfo.cpp
 	CPlayerInterface.cpp
 	PlayerLocalState.cpp
@@ -233,7 +233,6 @@ set(vcmiclientcommon_HEADERS
 	eventsSDL/InputSourceTouch.h
 	eventsSDL/InputSourceGameController.h
 
-	gui/CGuiHandler.h
 	gui/CIntObject.h
 	gui/CursorHandler.h
 	gui/EventDispatcher.h
@@ -399,6 +398,7 @@ set(vcmiclientcommon_HEADERS
 	CGameInfo.h
 	CMT.h
 	CPlayerInterface.h
+	GameEngine.h
 	PlayerLocalState.h
 	CServerHandler.h
 	Client.h

+ 77 - 77
client/CPlayerInterface.cpp

@@ -30,7 +30,7 @@
 #include "eventsSDL/InputHandler.h"
 #include "eventsSDL/NotificationHandler.h"
 
-#include "gui/CGuiHandler.h"
+#include "GameEngine.h"
 #include "gui/CursorHandler.h"
 #include "gui/WindowHandler.h"
 
@@ -187,10 +187,10 @@ void CPlayerInterface::closeAllDialogs()
 	// remove all active dialogs that do not expect query answer
 	while(true)
 	{
-		auto adventureWindow = GH.windows().topWindow<AdventureMapInterface>();
-		auto settingsWindow = GH.windows().topWindow<SettingsMainWindow>();
-		auto infoWindow = GH.windows().topWindow<CInfoWindow>();
-		auto topWindow = GH.windows().topWindow<WindowBase>();
+		auto adventureWindow = ENGINE->windows().topWindow<AdventureMapInterface>();
+		auto settingsWindow = ENGINE->windows().topWindow<SettingsMainWindow>();
+		auto infoWindow = ENGINE->windows().topWindow<CInfoWindow>();
+		auto topWindow = ENGINE->windows().topWindow<WindowBase>();
 
 		if(adventureWindow != nullptr)
 			break;
@@ -207,7 +207,7 @@ void CPlayerInterface::closeAllDialogs()
 		if (topWindow)
 			topWindow->close();
 		else
-			GH.windows().popWindows(1); // does not inherits from WindowBase, e.g. settings dialog
+			ENGINE->windows().popWindows(1); // does not inherits from WindowBase, e.g. settings dialog
 	}
 }
 
@@ -228,11 +228,11 @@ void CPlayerInterface::playerEndsTurn(PlayerColor player)
 
 void CPlayerInterface::playerStartsTurn(PlayerColor player)
 {
-	if(GH.windows().findWindows<AdventureMapInterface>().empty())
+	if(ENGINE->windows().findWindows<AdventureMapInterface>().empty())
 	{
 		// after map load - remove all active windows and replace them with adventure map
-		GH.windows().clear();
-		GH.windows().pushWindow(adventureInt);
+		ENGINE->windows().clear();
+		ENGINE->windows().pushWindow(adventureInt);
 	}
 
 	EVENT_HANDLER_CALLED_BY_CLIENT;
@@ -317,7 +317,7 @@ void CPlayerInterface::yourTurn(QueryID queryID)
 	bool hotseatWait = humanPlayersCount > 1;
 
 		LOCPLINT = this;
-		GH.curInt = this;
+		ENGINE->curInt = this;
 
 		NotificationHandler::notify("Your turn");
 		if(settings["general"]["startTurnAutosave"].Bool())
@@ -349,7 +349,7 @@ void CPlayerInterface::acceptTurn(QueryID queryID, bool hotseatWait)
 {
 	if (settings["session"]["autoSkip"].Bool())
 	{
-		while(auto iw = GH.windows().topWindow<CInfoWindow>())
+		while(auto iw = ENGINE->windows().topWindow<CInfoWindow>())
 			iw->close();
 	}
 
@@ -467,7 +467,7 @@ void CPlayerInterface::openTownWindow(const CGTownInstance * town)
 
 	auto newCastleInt = std::make_shared<CCastleInterface>(town);
 
-	GH.windows().pushWindow(newCastleInt);
+	ENGINE->windows().pushWindow(newCastleInt);
 }
 
 void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, PrimarySkill which, si64 val)
@@ -475,7 +475,7 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, Prim
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	if (which == PrimarySkill::EXPERIENCE)
 	{
-		for(auto ctw : GH.windows().findWindows<IMarketHolder>())
+		for(auto ctw : ENGINE->windows().findWindows<IMarketHolder>())
 			ctw->updateExperience();
 	}
 	else
@@ -487,7 +487,7 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, Prim
 void CPlayerInterface::heroSecondarySkillChanged(const CGHeroInstance * hero, int which, int val)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	for (auto cuw : GH.windows().findWindows<IMarketHolder>())
+	for (auto cuw : ENGINE->windows().findWindows<IMarketHolder>())
 		cuw->updateSecondarySkills();
 
 	localState->verifyPath(hero);
@@ -511,10 +511,10 @@ void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
 void CPlayerInterface::receivedResource()
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	for (auto mw : GH.windows().findWindows<IMarketHolder>())
+	for (auto mw : ENGINE->windows().findWindows<IMarketHolder>())
 		mw->updateResources();
 
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, PrimarySkill pskill, std::vector<SecondarySkill>& skills, QueryID queryID)
@@ -522,7 +522,7 @@ void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, PrimarySkill psk
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	waitWhileDialog();
 	CCS->soundh->playSound(soundBase::heroNewLevel);
-	GH.windows().createAndPushWindow<CLevelWindow>(hero, pskill, skills, [=](ui32 selection)
+	ENGINE->windows().createAndPushWindow<CLevelWindow>(hero, pskill, skills, [=](ui32 selection)
 	{
 		cb->selectionMade(selection, queryID);
 	});
@@ -533,7 +533,7 @@ void CPlayerInterface::commanderGotLevel (const CCommanderInstance * commander,
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	waitWhileDialog();
 	CCS->soundh->playSound(soundBase::heroNewLevel);
-	GH.windows().createAndPushWindow<CStackWindow>(commander, skills, [=](ui32 selection)
+	ENGINE->windows().createAndPushWindow<CStackWindow>(commander, skills, [=](ui32 selection)
 	{
 		cb->selectionMade(selection, queryID);
 	});
@@ -559,15 +559,15 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
 	adventureInt->onHeroChanged(nullptr);
 	adventureInt->onTownChanged(town);
 
-	for (auto cgh : GH.windows().findWindows<IGarrisonHolder>())
+	for (auto cgh : ENGINE->windows().findWindows<IGarrisonHolder>())
 		if (cgh->holdsGarrison(town))
 			cgh->updateGarrisons();
 
-	for (auto ki : GH.windows().findWindows<CKingdomInterface>())
+	for (auto ki : ENGINE->windows().findWindows<CKingdomInterface>())
 		ki->townChanged(town);
 
 	// Perform totalRedraw to update hero list on adventure map, if any dialogs are open
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
@@ -617,11 +617,11 @@ void CPlayerInterface::garrisonsChanged(std::vector<const CArmedInstance *> objs
 		}
 	}
 
-	for (auto cgh : GH.windows().findWindows<IGarrisonHolder>())
+	for (auto cgh : ENGINE->windows().findWindows<IGarrisonHolder>())
 		if (cgh->holdsGarrisons(objs))
 			cgh->updateGarrisons();
 
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void CPlayerInterface::buildChanged(const CGTownInstance *town, BuildingID buildingID, int what) //what: 1 - built, 2 - demolished
@@ -647,10 +647,10 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, BuildingID build
 		}
 
 		// Perform totalRedraw in order to force redraw of updated town list icon from adventure map
-		GH.windows().totalRedraw();
+		ENGINE->windows().totalRedraw();
 	}
 
-	for (auto cgh : GH.windows().findWindows<ITownHolder>())
+	for (auto cgh : ENGINE->windows().findWindows<ITownHolder>())
 		cgh->buildChanged();
 }
 
@@ -811,7 +811,7 @@ void CPlayerInterface::activeStack(const BattleID & battleID, const CStack * sta
 		{
 			//FIXME: we want client rendering to proceed while AI is making actions
 			// so unlock mutex while AI is busy since this might take quite a while, especially if hero has many spells
-			auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
+			auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
 			autofightingAI->activeStack(battleID, stack);
 			return;
 		}
@@ -855,7 +855,7 @@ void CPlayerInterface::battleEnd(const BattleID & battleID, const BattleResult *
 			
 			isAutoFightEndBattle = false;
 
-			GH.windows().pushWindow(wnd);
+			ENGINE->windows().pushWindow(wnd);
 			// #1490 - during AI turn when quick combat is on, we need to display the message and wait for user to close it.
 			// Otherwise NewTurn causes freeze.
 			waitWhileDialog();
@@ -1007,12 +1007,12 @@ void CPlayerInterface::showInfoDialog(EInfoWindowMode type, const std::string &t
 		// abort movement, if any. Strictly speaking unnecessary, but prevents some edge cases, like movement sound on visiting Magi Hut with "show messages in status window" on
 		movementController->requestMovementAbort();
 
-		if (makingTurn && GH.windows().count() > 0 && LOCPLINT == this)
+		if (makingTurn && ENGINE->windows().count() > 0 && LOCPLINT == this)
 			CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
 		return;
 	}
 
-	if (settings["session"]["autoSkip"].Bool() && !GH.isKeyboardShiftDown())
+	if (settings["session"]["autoSkip"].Bool() && !ENGINE->isKeyboardShiftDown())
 	{
 		return;
 	}
@@ -1042,18 +1042,18 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector
 	LOG_TRACE_PARAMS(logGlobal, "player=%s, text=%s, is LOCPLINT=%d", playerID % text % (this==LOCPLINT));
 	waitWhileDialog();
 
-	if (settings["session"]["autoSkip"].Bool() && !GH.isKeyboardShiftDown())
+	if (settings["session"]["autoSkip"].Bool() && !ENGINE->isKeyboardShiftDown())
 	{
 		return;
 	}
 	std::shared_ptr<CInfoWindow> temp = CInfoWindow::create(text, playerID, components);
 
-	if ((makingTurn || (battleInt && battleInt->curInt && battleInt->curInt.get() == this)) && GH.windows().count() > 0 && LOCPLINT == this)
+	if ((makingTurn || (battleInt && battleInt->curInt && battleInt->curInt.get() == this)) && ENGINE->windows().count() > 0 && LOCPLINT == this)
 	{
 		CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
 		showingDialog->setBusy();
 		movementController->requestMovementAbort(); // interrupt movement to show dialog
-		GH.windows().pushWindow(temp);
+		ENGINE->windows().pushWindow(temp);
 	}
 	else
 	{
@@ -1116,9 +1116,9 @@ void CPlayerInterface::showBlockingDialog(const std::string &text, const std::ve
 		int charperline = 35;
 		if (pom.size() > 1)
 			charperline = 50;
-		GH.windows().createAndPushWindow<CSelWindow>(text, playerID, charperline, intComps, pom, askID);
-		intComps[0]->clickPressed(GH.getCursorPosition());
-		intComps[0]->clickReleased(GH.getCursorPosition());
+		ENGINE->windows().createAndPushWindow<CSelWindow>(text, playerID, charperline, intComps, pom, askID);
+		intComps[0]->clickPressed(ENGINE->getCursorPosition());
+		intComps[0]->clickReleased(ENGINE->getCursorPosition());
 	}
 }
 
@@ -1179,7 +1179,7 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component
 		const CGTownInstance * t = dynamic_cast<const CGTownInstance *>(cb->getObj(obj));
 		if(t)
 		{
-			auto image = GH.renderHandler().loadImage(AnimationPath::builtin("ITPA"), t->getTown()->clientInfo.icons[t->hasFort()][false] + 2, 0, EImageBlitMode::OPAQUE);
+			auto image = ENGINE->renderHandler().loadImage(AnimationPath::builtin("ITPA"), t->getTown()->clientInfo.icons[t->hasFort()][false] + 2, 0, EImageBlitMode::OPAQUE);
 			image->scaleTo(Point(35, 23), EScalingAlgorithm::NEAREST);
 			images.push_back(image);
 		}
@@ -1187,9 +1187,9 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component
 
 	auto wnd = std::make_shared<CObjectListWindow>(tempList, localIcon, localTitle, localDescription, selectCallback, 0, images);
 	wnd->onExit = cancelCallback;
-	wnd->onPopup = [this, objectGuiOrdered](int index) { CRClickPopup::createAndPush(cb->getObj(objectGuiOrdered[index]), GH.getCursorPosition()); };
-	wnd->onClicked = [this, objectGuiOrdered](int index) { adventureInt->centerOnObject(cb->getObj(objectGuiOrdered[index])); GH.windows().totalRedraw(); };
-	GH.windows().pushWindow(wnd);
+	wnd->onPopup = [this, objectGuiOrdered](int index) { CRClickPopup::createAndPush(cb->getObj(objectGuiOrdered[index]), ENGINE->getCursorPosition()); };
+	wnd->onClicked = [this, objectGuiOrdered](int index) { adventureInt->centerOnObject(cb->getObj(objectGuiOrdered[index])); ENGINE->windows().totalRedraw(); };
+	ENGINE->windows().pushWindow(wnd);
 }
 
 void CPlayerInterface::tileRevealed(const std::unordered_set<int3> &pos)
@@ -1207,7 +1207,7 @@ void CPlayerInterface::tileHidden(const std::unordered_set<int3> &pos)
 
 void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
 {
-	GH.windows().createAndPushWindow<CHeroWindow>(hero);
+	ENGINE->windows().createAndPushWindow<CHeroWindow>(hero);
 }
 
 void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
@@ -1215,21 +1215,21 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	if (const CGTownInstance * townObj = dynamic_cast<const CGTownInstance*>(town))
 	{
-		for (auto fortScreen : GH.windows().findWindows<CFortScreen>())
+		for (auto fortScreen : ENGINE->windows().findWindows<CFortScreen>())
 			fortScreen->creaturesChangedEventHandler();
 
-		for (auto castleInterface : GH.windows().findWindows<CCastleInterface>())
+		for (auto castleInterface : ENGINE->windows().findWindows<CCastleInterface>())
 			if(castleInterface->town == town)
 				castleInterface->creaturesChangedEventHandler();
 
 		if (townObj)
-			for (auto ki : GH.windows().findWindows<CKingdomInterface>())
+			for (auto ki : ENGINE->windows().findWindows<CKingdomInterface>())
 				ki->townChanged(townObj);
 	}
-	else if(town && GH.windows().count() > 0 && (town->ID == Obj::CREATURE_GENERATOR1
+	else if(town && ENGINE->windows().count() > 0 && (town->ID == Obj::CREATURE_GENERATOR1
 		||  town->ID == Obj::CREATURE_GENERATOR4  ||  town->ID == Obj::WAR_MACHINE_FACTORY))
 	{
-		for (auto crw : GH.windows().findWindows<CRecruitmentWindow>())
+		for (auto crw : ENGINE->windows().findWindows<CRecruitmentWindow>())
 			if (crw->dwelling == town)
 				crw->availableCreaturesChanged();
 	}
@@ -1287,7 +1287,7 @@ void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHer
 
 	auto cgw = std::make_shared<CGarrisonWindow>(up, down, removableUnits);
 	cgw->quit->addCallback(onEnd);
-	GH.windows().pushWindow(cgw);
+	ENGINE->windows().pushWindow(cgw);
 }
 
 void CPlayerInterface::requestRealized( PackageApplied *pa )
@@ -1307,7 +1307,7 @@ void CPlayerInterface::showHeroExchange(ObjectInstanceID hero1, ObjectInstanceID
 void CPlayerInterface::heroExchangeStarted(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID query)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	GH.windows().createAndPushWindow<CExchangeWindow>(hero1, hero2, query);
+	ENGINE->windows().createAndPushWindow<CExchangeWindow>(hero1, hero2, query);
 }
 
 void CPlayerInterface::beforeObjectPropertyChanged(const SetObjectProperty * sop)
@@ -1392,18 +1392,18 @@ void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const C
 	{
 		cb->selectionMade(0, queryID);
 	};
-	GH.windows().createAndPushWindow<CRecruitmentWindow>(dwelling, level, dst, recruitCb, closeCb);
+	ENGINE->windows().createAndPushWindow<CRecruitmentWindow>(dwelling, level, dst, recruitCb, closeCb);
 }
 
 void CPlayerInterface::waitWhileDialog()
 {
-	if (GH.amIGuiThread())
+	if (ENGINE->amIGuiThread())
 	{
 		logGlobal->warn("Cannot wait for dialogs in gui thread (deadlock risk)!");
 		return;
 	}
 
-	auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
+	auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
 	showingDialog->waitWhileBusy();
 }
 
@@ -1413,7 +1413,7 @@ void CPlayerInterface::showShipyardDialog(const IShipyard *obj)
 	auto state = obj->shipyardStatus();
 	TResources cost;
 	obj->getBoatCost(cost);
-	GH.windows().createAndPushWindow<CShipyardWindow>(cost, state, obj->getBoatType(), [=](){ cb->buildBoat(obj); });
+	ENGINE->windows().createAndPushWindow<CShipyardWindow>(cost, state, obj->getBoatType(), [=](){ cb->buildBoat(obj); });
 }
 
 void CPlayerInterface::newObject( const CGObjectInstance * obj )
@@ -1436,10 +1436,10 @@ void CPlayerInterface::centerView (int3 pos, int focusTime)
 	adventureInt->centerOnTile(pos);
 	if (focusTime)
 	{
-		GH.windows().totalRedraw();
+		ENGINE->windows().totalRedraw();
 		{
 			IgnoreEvents ignore(*this);
-			auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
+			auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
 			boost::this_thread::sleep_for(boost::chrono::milliseconds(focusTime));
 		}
 	}
@@ -1471,7 +1471,7 @@ void CPlayerInterface::objectRemoved(const CGObjectInstance * obj, const PlayerC
 		const CGTownInstance * t = static_cast<const CGTownInstance *>(obj);
 		townRemoved(t);
 	}
-	GH.fakeMouseMove();
+	ENGINE->fakeMouseMove();
 }
 
 void CPlayerInterface::objectRemovedAfter()
@@ -1483,7 +1483,7 @@ void CPlayerInterface::objectRemovedAfter()
 	if (castleInt)
 		castleInt->updateGarrisons();
 
-	for (auto ki : GH.windows().findWindows<CKingdomInterface>())
+	for (auto ki : ENGINE->windows().findWindows<CKingdomInterface>())
 		ki->heroRemoved();
 }
 
@@ -1495,7 +1495,7 @@ void CPlayerInterface::playerBlocked(int reason, bool start)
 		{
 			//one of our players who isn't last in order got attacked not by our another player (happens for example in hotseat mode)
 			LOCPLINT = this;
-			GH.curInt = this;
+			ENGINE->curInt = this;
 			adventureInt->onCurrentPlayerChanged(playerID);
 			std::string msg = CGI->generaltexth->translate("vcmi.adventureMap.playerAttacked");
 			boost::replace_first(msg, "%s", cb->getStartInfo()->playerInfos.find(playerID)->second.name);
@@ -1522,15 +1522,15 @@ void CPlayerInterface::update()
 	if (makingTurn && !dialogs.empty() && !showingDialog->isBusy())
 	{
 		showingDialog->setBusy();
-		GH.windows().pushWindow(dialogs.front());
+		ENGINE->windows().pushWindow(dialogs.front());
 		dialogs.pop_front();
 	}
 
 	assert(adventureInt);
 
 	// Handles mouse and key input
-	GH.handleEvents();
-	GH.windows().simpleRedraw();
+	ENGINE->handleEvents();
+	ENGINE->windows().simpleRedraw();
 }
 
 void CPlayerInterface::endNetwork()
@@ -1578,11 +1578,11 @@ void CPlayerInterface::gameOver(PlayerColor player, const EVictoryLossCheckResul
 		if (victoryLossCheckResult.loss())
 			showInfoDialog(CGI->generaltexth->allTexts[95]);
 
-		assert(GH.curInt == LOCPLINT);
+		assert(ENGINE->curInt == LOCPLINT);
 		auto previousInterface = LOCPLINT; //without multiple player interfaces some of lines below are useless, but for hotseat we wanna swap player interface temporarily
 
 		LOCPLINT = this; //this is needed for dialog to show and avoid freeze, dialog showing logic should be reworked someday
-		GH.curInt = this; //waiting for dialogs requires this to get events
+		ENGINE->curInt = this; //waiting for dialogs requires this to get events
 
 		if(!makingTurn)
 		{
@@ -1593,7 +1593,7 @@ void CPlayerInterface::gameOver(PlayerColor player, const EVictoryLossCheckResul
 		else
 			waitForAllDialogs();
 
-		GH.curInt = previousInterface;
+		ENGINE->curInt = previousInterface;
 		LOCPLINT = previousInterface;
 	}
 }
@@ -1612,7 +1612,7 @@ void CPlayerInterface::showPuzzleMap()
 	double ratio = 0;
 	int3 grailPos = cb->getGrailPos(&ratio);
 
-	GH.windows().createAndPushWindow<CPuzzleWindow>(grailPos, ratio);
+	ENGINE->windows().createAndPushWindow<CPuzzleWindow>(grailPos, ratio);
 }
 
 void CPlayerInterface::viewWorldMap()
@@ -1624,8 +1624,8 @@ void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, SpellID sp
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 
-	if(GH.windows().topWindow<CSpellWindow>())
-		GH.windows().popWindows(1);
+	if(ENGINE->windows().topWindow<CSpellWindow>())
+		ENGINE->windows().popWindows(1);
 
 	if(spellID == SpellID::FLY || spellID == SpellID::WATER_WALK)
 		localState->erasePath(caster);
@@ -1683,17 +1683,17 @@ void CPlayerInterface::showMarketWindow(const IMarket * market, const CGHeroInst
 	};
 
 	if(market->allowsTrade(EMarketMode::ARTIFACT_EXP) && visitor->getAlignment() != EAlignment::EVIL)
-		GH.windows().createAndPushWindow<CMarketWindow>(market, visitor, onWindowClosed, EMarketMode::ARTIFACT_EXP);
+		ENGINE->windows().createAndPushWindow<CMarketWindow>(market, visitor, onWindowClosed, EMarketMode::ARTIFACT_EXP);
 	else if(market->allowsTrade(EMarketMode::CREATURE_EXP) && visitor->getAlignment() != EAlignment::GOOD)
-		GH.windows().createAndPushWindow<CMarketWindow>(market, visitor, onWindowClosed, EMarketMode::CREATURE_EXP);
+		ENGINE->windows().createAndPushWindow<CMarketWindow>(market, visitor, onWindowClosed, EMarketMode::CREATURE_EXP);
 	else if(market->allowsTrade(EMarketMode::CREATURE_UNDEAD))
-		GH.windows().createAndPushWindow<CTransformerWindow>(market, visitor, onWindowClosed);
+		ENGINE->windows().createAndPushWindow<CTransformerWindow>(market, visitor, onWindowClosed);
 	else if (!market->availableModes().empty())
 		for(auto mode = EMarketMode::RESOURCE_RESOURCE; mode != EMarketMode::MARKET_AFTER_LAST_PLACEHOLDER; mode = vstd::next(mode, 1))
 		{
 			if(vstd::contains(market->availableModes(), mode))
 			{
-				GH.windows().createAndPushWindow<CMarketWindow>(market, visitor, onWindowClosed, mode);
+				ENGINE->windows().createAndPushWindow<CMarketWindow>(market, visitor, onWindowClosed, mode);
 				break;
 			}
 		}
@@ -1707,19 +1707,19 @@ void CPlayerInterface::showUniversityWindow(const IMarket *market, const CGHeroI
 	auto onWindowClosed = [this, queryID](){
 		cb->selectionMade(0, queryID);
 	};
-	GH.windows().createAndPushWindow<CUniversityWindow>(visitor, BuildingID::NONE, market, onWindowClosed);
+	ENGINE->windows().createAndPushWindow<CUniversityWindow>(visitor, BuildingID::NONE, market, onWindowClosed);
 }
 
 void CPlayerInterface::showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	GH.windows().createAndPushWindow<CHillFortWindow>(visitor, object);
+	ENGINE->windows().createAndPushWindow<CHillFortWindow>(visitor, object);
 }
 
 void CPlayerInterface::availableArtifactsChanged(const CGBlackMarket * bm)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	for (auto cmw : GH.windows().findWindows<IMarketHolder>())
+	for (auto cmw : ENGINE->windows().findWindows<IMarketHolder>())
 		cmw->updateArtifacts();
 }
 
@@ -1730,19 +1730,19 @@ void CPlayerInterface::showTavernWindow(const CGObjectInstance * object, const C
 		if (queryID != QueryID::NONE)
 			cb->selectionMade(0, queryID);
 	};
-	GH.windows().createAndPushWindow<CTavernWindow>(object, onWindowClosed);
+	ENGINE->windows().createAndPushWindow<CTavernWindow>(object, onWindowClosed);
 }
 
 void CPlayerInterface::showThievesGuildWindow (const CGObjectInstance * obj)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	GH.windows().createAndPushWindow<CThievesGuildWindow>(obj);
+	ENGINE->windows().createAndPushWindow<CThievesGuildWindow>(obj);
 }
 
 void CPlayerInterface::showQuestLog()
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	GH.windows().createAndPushWindow<CQuestLog>(LOCPLINT->cb->getMyQuests());
+	ENGINE->windows().createAndPushWindow<CQuestLog>(LOCPLINT->cb->getMyQuests());
 }
 
 void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
@@ -1808,7 +1808,7 @@ void CPlayerInterface::waitForAllDialogs()
 
 	while(!dialogs.empty())
 	{
-		auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
+		auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
 		boost::this_thread::sleep_for(boost::chrono::milliseconds(5));
 	}
 	waitWhileDialog();
@@ -1840,7 +1840,7 @@ bool CPlayerInterface::capturedAllEvents()
 
 	if (ignoreEvents || needToLockAdventureMap || quickCombatOngoing )
 	{
-		GH.input().ignoreEventsUntilInput();
+		ENGINE->input().ignoreEventsUntilInput();
 		return true;
 	}
 

+ 27 - 27
client/CServerHandler.cpp

@@ -15,7 +15,7 @@
 #include "ServerRunner.h"
 #include "GameChatHandler.h"
 #include "CPlayerInterface.h"
-#include "gui/CGuiHandler.h"
+#include "GameEngine.h"
 #include "gui/WindowHandler.h"
 
 #include "globalLobby/GlobalLobbyClient.h"
@@ -71,7 +71,7 @@ CServerHandler::~CServerHandler()
 			serverRunner->wait();
 		serverRunner.reset();
 		{
-			auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
+			auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
 			threadNetwork.join();
 		}
 	}
@@ -88,7 +88,7 @@ void CServerHandler::endNetwork()
 		client->endNetwork();
 	networkHandler->stop();
 	{
-		auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
+		auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
 		threadNetwork.join();
 	}
 }
@@ -218,7 +218,7 @@ void CServerHandler::connectToServer(const std::string & addr, const ui16 port)
 void CServerHandler::onConnectionFailed(const std::string & errorMessage)
 {
 	assert(getState() == EClientState::CONNECTING);
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	if (isServerLocal())
 	{
@@ -236,15 +236,15 @@ void CServerHandler::onConnectionFailed(const std::string & errorMessage)
 
 void CServerHandler::onTimer()
 {
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	if(getState() == EClientState::CONNECTION_CANCELLED)
 	{
 		logNetwork->info("Connection aborted by player!");
 		serverRunner->wait();
 		serverRunner.reset();
-		if (GH.windows().topWindow<CSimpleJoinScreen>() != nullptr)
-			GH.windows().popWindows(1);
+		if (ENGINE->windows().topWindow<CSimpleJoinScreen>() != nullptr)
+			ENGINE->windows().popWindows(1);
 		return;
 	}
 
@@ -256,7 +256,7 @@ void CServerHandler::onConnectionEstablished(const NetworkConnectionPtr & netCon
 {
 	assert(getState() == EClientState::CONNECTING);
 
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	networkConnection = netConnection;
 
@@ -278,7 +278,7 @@ void CServerHandler::applyPackOnLobbyScreen(CPackForLobby & pack)
 {
 	ApplyOnLobbyScreenNetPackVisitor visitor(*this, dynamic_cast<CLobbyScreen *>(SEL));
 	pack.visit(visitor);
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 std::set<PlayerColor> CServerHandler::getHumanColors()
@@ -546,9 +546,9 @@ void CServerHandler::sendGuiAction(ui8 action) const
 void CServerHandler::sendRestartGame() const
 {
 	if(si->campState && !si->campState->getLoadingBackground().empty())
-		GH.windows().createAndPushWindow<CLoadingScreen>(si->campState->getLoadingBackground());
+		ENGINE->windows().createAndPushWindow<CLoadingScreen>(si->campState->getLoadingBackground());
 	else
-		GH.windows().createAndPushWindow<CLoadingScreen>();
+		ENGINE->windows().createAndPushWindow<CLoadingScreen>();
 	
 	LobbyRestartGame endGame;
 	sendLobbyPack(endGame);
@@ -594,9 +594,9 @@ void CServerHandler::sendStartGame(bool allowOnlyAI) const
 	if(!settings["session"]["headless"].Bool())
 	{
 		if(si->campState && !si->campState->getLoadingBackground().empty())
-			GH.windows().createAndPushWindow<CLoadingScreen>(si->campState->getLoadingBackground());
+			ENGINE->windows().createAndPushWindow<CLoadingScreen>(si->campState->getLoadingBackground());
 		else
-			GH.windows().createAndPushWindow<CLoadingScreen>();
+			ENGINE->windows().createAndPushWindow<CLoadingScreen>();
 	}
 	
 	LobbyPrepareStartGame lpsg;
@@ -653,7 +653,7 @@ void CServerHandler::showHighScoresAndEndGameplay(PlayerColor player, bool victo
 
 		endGameplay();
 		CMM->menu->switchToTab("main");
-		GH.windows().createAndPushWindow<CHighScoreInputScreen>(victory, scenarioHighScores, statistic);
+		ENGINE->windows().createAndPushWindow<CHighScoreInputScreen>(victory, scenarioHighScores, statistic);
 	}
 }
 
@@ -669,14 +669,14 @@ void CServerHandler::endGameplay()
 
 	if(CMM)
 	{
-		GH.curInt = CMM.get();
+		ENGINE->curInt = CMM.get();
 		CMM->enable();
 		CMM->playMusic();
 	}
 	else
 	{
 		auto mainMenu = CMainMenu::create();
-		GH.curInt = mainMenu.get();
+		ENGINE->curInt = mainMenu.get();
 		mainMenu->playMusic();
 	}
 }
@@ -713,8 +713,8 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
 			entry->Bool() = true;
 		}
 
-		GH.windows().pushWindow(CMM);
-		GH.windows().pushWindow(CMM->menu);
+		ENGINE->windows().pushWindow(CMM);
+		ENGINE->windows().pushWindow(CMM->menu);
 
 		if(!ourCampaign->isCampaignFinished())
 			CMM->openCampaignLobby(ourCampaign);
@@ -724,18 +724,18 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
 			if(!ourCampaign->getOutroVideo().empty() && CCS->videoh->open(ourCampaign->getOutroVideo(), 1))
 			{
 				CCS->musich->stopMusic();
-				GH.windows().createAndPushWindow<VideoWindow>(ourCampaign->getOutroVideo(), ourCampaign->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : ourCampaign->getVideoRim(), false, 1, [campaignScoreCalculator, statistic](bool skipped){
-					GH.windows().createAndPushWindow<CHighScoreInputScreen>(true, *campaignScoreCalculator, statistic);
+				ENGINE->windows().createAndPushWindow<VideoWindow>(ourCampaign->getOutroVideo(), ourCampaign->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : ourCampaign->getVideoRim(), false, 1, [campaignScoreCalculator, statistic](bool skipped){
+					ENGINE->windows().createAndPushWindow<CHighScoreInputScreen>(true, *campaignScoreCalculator, statistic);
 				});
 			}
 			else
-				GH.windows().createAndPushWindow<CHighScoreInputScreen>(true, *campaignScoreCalculator, statistic);
+				ENGINE->windows().createAndPushWindow<CHighScoreInputScreen>(true, *campaignScoreCalculator, statistic);
 		}
 	};
 
 	if(epilogue.hasPrologEpilog)
 	{
-		GH.windows().createAndPushWindow<CPrologEpilogVideo>(epilogue, finisher);
+		ENGINE->windows().createAndPushWindow<CPrologEpilogVideo>(epilogue, finisher);
 	}
 	else
 	{
@@ -745,8 +745,8 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
 
 void CServerHandler::showServerError(const std::string & txt) const
 {
-	if(auto w = GH.windows().topWindow<CLoadingScreen>())
-		GH.windows().popWindow(w);
+	if(auto w = ENGINE->windows().topWindow<CLoadingScreen>())
+		ENGINE->windows().popWindow(w);
 	
 	CInfoWindow::showInfoDialog(txt, {});
 }
@@ -803,7 +803,7 @@ void CServerHandler::debugStartTest(std::string filename, bool save)
 
 	boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
 
-	while(!settings["session"]["headless"].Bool() && !GH.windows().topWindow<CLobbyScreen>())
+	while(!settings["session"]["headless"].Bool() && !ENGINE->windows().topWindow<CLobbyScreen>())
 		boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
 
 	while(!mi || mapInfo->fileURI != mi->fileURI)
@@ -857,7 +857,7 @@ public:
 
 void CServerHandler::onPacketReceived(const std::shared_ptr<INetworkConnection> &, const std::vector<std::byte> & message)
 {
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	if(getState() == EClientState::DISCONNECTING)
 		return;
@@ -869,7 +869,7 @@ void CServerHandler::onPacketReceived(const std::shared_ptr<INetworkConnection>
 
 void CServerHandler::onDisconnected(const std::shared_ptr<INetworkConnection> & connection, const std::string & errorMessage)
 {
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	if (connection != networkConnection)
 	{

+ 6 - 6
client/Client.cpp

@@ -18,7 +18,7 @@
 #include "ClientNetPackVisitors.h"
 #include "adventureMap/AdventureMapInterface.h"
 #include "battle/BattleInterface.h"
-#include "gui/CGuiHandler.h"
+#include "GameEngine.h"
 #include "gui/WindowHandler.h"
 #include "mapView/mapHandler.h"
 
@@ -192,7 +192,7 @@ void CClient::endGame()
 	for(auto & i : playerint)
 		i.second->finish();
 
-	GH.curInt = nullptr;
+	ENGINE->curInt = nullptr;
 	{
 		logNetwork->info("Ending current game!");
 		removeGUI();
@@ -483,7 +483,7 @@ void CClient::startPlayerBattleAction(const BattleID & battleID, PlayerColor col
 	if (!battleint->human)
 	{
 		// we want to avoid locking gamestate and causing UI to freeze while AI is making turn
-		auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
+		auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
 		battleint->activeStack(battleID, gs->getBattle(battleID)->battleGetStackByID(gs->getBattle(battleID)->activeStack, false));
 	}
 	else
@@ -519,8 +519,8 @@ void CClient::reinitScripting()
 void CClient::removeGUI() const
 {
 	// CClient::endGame
-	GH.curInt = nullptr;
-	GH.windows().clear();
+	ENGINE->curInt = nullptr;
+	ENGINE->windows().clear();
 	adventureInt.reset();
 	logGlobal->info("Removed GUI.");
 
@@ -530,7 +530,7 @@ void CClient::removeGUI() const
 #ifdef VCMI_ANDROID
 extern "C" JNIEXPORT jboolean JNICALL Java_eu_vcmi_vcmi_NativeMethods_tryToSaveTheGame(JNIEnv * env, jclass cls)
 {
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	logGlobal->info("Received emergency save game request");
 	if(!LOCPLINT || !LOCPLINT->cb)

+ 9 - 9
client/ClientCommandManager.cpp

@@ -15,7 +15,7 @@
 #include "CPlayerInterface.h"
 #include "PlayerLocalState.h"
 #include "CServerHandler.h"
-#include "gui/CGuiHandler.h"
+#include "GameEngine.h"
 #include "gui/WindowHandler.h"
 #include "render/IRenderHandler.h"
 #include "ClientNetPackVisitors.h"
@@ -74,7 +74,7 @@ void ClientCommandManager::handleGoSoloCommand()
 {
 	Settings session = settings.write["session"];
 
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	if(!CSH->client)
 	{
@@ -108,7 +108,7 @@ void ClientCommandManager::handleGoSoloCommand()
 			}
 		}
 
-		GH.windows().totalRedraw();
+		ENGINE->windows().totalRedraw();
 		giveTurn(currentColor);
 	}
 
@@ -127,7 +127,7 @@ void ClientCommandManager::handleControlaiCommand(std::istringstream& singleWord
 	singleWordBuffer >> colorName;
 	boost::to_lower(colorName);
 
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	if(!CSH->client)
 	{
@@ -152,7 +152,7 @@ void ClientCommandManager::handleControlaiCommand(std::istringstream& singleWord
 		CSH->client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(elem.first), elem.first);
 	}
 
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 	if(color != PlayerColor::NEUTRAL)
 		giveTurn(color);
 }
@@ -181,7 +181,7 @@ void ClientCommandManager::handleSetBattleAICommand(std::istringstream& singleWo
 
 void ClientCommandManager::handleRedrawCommand()
 {
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void ClientCommandManager::handleTranslateGameCommand(bool onlyMissing)
@@ -393,7 +393,7 @@ void ClientCommandManager::handleDef2bmpCommand(std::istringstream& singleWordBu
 {
 	std::string URI;
 	singleWordBuffer >> URI;
-	auto anim = GH.renderHandler().loadAnimation(AnimationPath::builtin(URI), EImageBlitMode::SIMPLE);
+	auto anim = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin(URI), EImageBlitMode::SIMPLE);
 	anim->exportBitmaps(VCMIDirs::get().userExtractedPath());
 }
 
@@ -509,7 +509,7 @@ void ClientCommandManager::handleVsLog(std::istringstream & singleWordBuffer)
 
 void ClientCommandManager::handleGenerateAssets()
 {
-	GH.renderHandler().exportGeneratedAssets();
+	ENGINE->renderHandler().exportGeneratedAssets();
 	printCommandMessage("All assets generated");
 }
 
@@ -542,7 +542,7 @@ void ClientCommandManager::printCommandMessage(const std::string &commandMessage
 
 	if(currentCallFromIngameConsole)
 	{
-		boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+		boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 		if(LOCPLINT && LOCPLINT->cingconsole)
 		{
 			LOCPLINT->cingconsole->addMessage("", "System", commandMessage);

+ 60 - 69
client/gui/CGuiHandler.cpp → client/GameEngine.cpp

@@ -1,5 +1,5 @@
 /*
- * CGuiHandler.cpp, part of VCMI engine
+ * GameEngine.cpp, part of VCMI engine
  *
  * Authors: listed in file AUTHORS in main folder
  *
@@ -8,51 +8,52 @@
  *
  */
 #include "StdInc.h"
-#include "CGuiHandler.h"
-
-#include "CIntObject.h"
-#include "CursorHandler.h"
-#include "ShortcutHandler.h"
-#include "FramerateManager.h"
-#include "WindowHandler.h"
-#include "EventDispatcher.h"
-#include "../eventsSDL/InputHandler.h"
-
-#include "../CGameInfo.h"
-#include "../adventureMap/AdventureMapInterface.h"
-#include "../render/Canvas.h"
-#include "../render/Colors.h"
-#include "../render/Graphics.h"
-#include "../render/IFont.h"
-#include "../render/EFont.h"
-#include "../renderSDL/ScreenHandler.h"
-#include "../renderSDL/RenderHandler.h"
-#include "../CPlayerInterface.h"
-#include "../battle/BattleInterface.h"
-
-#include "../../lib/CThreadHelper.h"
-#include "../../lib/CConfigHandler.h"
+#include "GameEngine.h"
+
+#include "gui/CIntObject.h"
+#include "gui/CursorHandler.h"
+#include "gui/ShortcutHandler.h"
+#include "gui/FramerateManager.h"
+#include "gui/WindowHandler.h"
+#include "gui/EventDispatcher.h"
+#include "eventsSDL/InputHandler.h"
+
+#include "CGameInfo.h"
+#include "CPlayerInterface.h"
+#include "adventureMap/AdventureMapInterface.h"
+#include "render/Canvas.h"
+#include "render/Colors.h"
+#include "render/Graphics.h"
+#include "render/IFont.h"
+#include "render/EFont.h"
+#include "renderSDL/ScreenHandler.h"
+#include "renderSDL/RenderHandler.h"
+#include "CMT.h"
+#include "battle/BattleInterface.h"
+
+#include "../lib/CThreadHelper.h"
+#include "../lib/CConfigHandler.h"
 
 #include <SDL_render.h>
 
-CGuiHandler GH;
+std::unique_ptr<GameEngine> ENGINE;
 
 static thread_local bool inGuiThread = false;
 
 ObjectConstruction::ObjectConstruction(CIntObject *obj)
 {
-	GH.createdObj.push_front(obj);
-	GH.captureChildren = true;
+	ENGINE->createdObj.push_front(obj);
+	ENGINE->captureChildren = true;
 }
 
 ObjectConstruction::~ObjectConstruction()
 {
-	assert(!GH.createdObj.empty());
-	GH.createdObj.pop_front();
-	GH.captureChildren = !GH.createdObj.empty();
+	assert(!ENGINE->createdObj.empty());
+	ENGINE->createdObj.pop_front();
+	ENGINE->captureChildren = !ENGINE->createdObj.empty();
 }
 
-void CGuiHandler::init()
+void GameEngine::init()
 {
 	inGuiThread = true;
 
@@ -65,7 +66,7 @@ void CGuiHandler::init()
 	framerateManagerInstance = std::make_unique<FramerateManager>(settings["video"]["targetfps"].Integer());
 }
 
-void CGuiHandler::handleEvents()
+void GameEngine::handleEvents()
 {
 	events().dispatchTimer(framerate().getElapsedMilliseconds());
 
@@ -76,27 +77,17 @@ void CGuiHandler::handleEvents()
 	input().processEvents();
 }
 
-void CGuiHandler::fakeMouseMove()
+void GameEngine::fakeMouseMove()
 {
 	dispatchMainThread([](){
-		GH.events().dispatchMouseMoved(Point(0, 0), GH.getCursorPosition());
+		ENGINE->events().dispatchMouseMoved(Point(0, 0), ENGINE->getCursorPosition());
 	});
 }
 
-void CGuiHandler::startTextInput(const Rect & whereInput)
-{
-	input().startTextInput(whereInput);
-}
-
-void CGuiHandler::stopTextInput()
-{
-	input().stopTextInput();
-}
-
-void CGuiHandler::renderFrame()
+void GameEngine::renderFrame()
 {
 	{
-		boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+		boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 		if (nullptr != curInt)
 			curInt->update();
@@ -114,14 +105,14 @@ void CGuiHandler::renderFrame()
 	framerate().framerateDelay(); // holds a constant FPS
 }
 
-CGuiHandler::CGuiHandler()
+GameEngine::GameEngine()
 	: captureChildren(false)
 	, curInt(nullptr)
 	, fakeStatusBar(std::make_shared<EmptyStatusBar>())
 {
 }
 
-CGuiHandler::~CGuiHandler()
+GameEngine::~GameEngine()
 {
 	// enforce deletion order on shutdown
 	// all UI elements including adventure map must be destroyed before Gui Handler
@@ -129,51 +120,51 @@ CGuiHandler::~CGuiHandler()
 	adventureInt.reset();
 }
 
-ShortcutHandler & CGuiHandler::shortcuts()
+ShortcutHandler & GameEngine::shortcuts()
 {
 	assert(shortcutsHandlerInstance);
 	return *shortcutsHandlerInstance;
 }
 
-FramerateManager & CGuiHandler::framerate()
+FramerateManager & GameEngine::framerate()
 {
 	assert(framerateManagerInstance);
 	return *framerateManagerInstance;
 }
 
-bool CGuiHandler::isKeyboardCtrlDown() const
+bool GameEngine::isKeyboardCtrlDown() const
 {
 	return inputHandlerInstance->isKeyboardCtrlDown();
 }
 
-bool CGuiHandler::isKeyboardCmdDown() const
+bool GameEngine::isKeyboardCmdDown() const
 {
 	return inputHandlerInstance->isKeyboardCmdDown();
 }
 
-bool CGuiHandler::isKeyboardAltDown() const
+bool GameEngine::isKeyboardAltDown() const
 {
 	return inputHandlerInstance->isKeyboardAltDown();
 }
 
-bool CGuiHandler::isKeyboardShiftDown() const
+bool GameEngine::isKeyboardShiftDown() const
 {
 	return inputHandlerInstance->isKeyboardShiftDown();
 }
 
-const Point & CGuiHandler::getCursorPosition() const
+const Point & GameEngine::getCursorPosition() const
 {
 	return inputHandlerInstance->getCursorPosition();
 }
 
-Point CGuiHandler::screenDimensions() const
+Point GameEngine::screenDimensions() const
 {
 	return screenHandlerInstance->getLogicalResolution();
 }
 
-void CGuiHandler::drawFPSCounter()
+void GameEngine::drawFPSCounter()
 {
-	Canvas target = GH.screenHandler().getScreenCanvas();
+	Canvas target = screenHandler().getScreenCanvas();
 	Rect targetArea(0, screenDimensions().y - 20, 48, 11);
 	std::string fps = std::to_string(framerate().getFramerate())+" FPS";
 
@@ -181,43 +172,43 @@ void CGuiHandler::drawFPSCounter()
 	target.drawText(targetArea.center(), EFonts::FONT_SMALL, Colors::WHITE, ETextAlignment::CENTER, fps);
 }
 
-bool CGuiHandler::amIGuiThread()
+bool GameEngine::amIGuiThread()
 {
 	return inGuiThread;
 }
 
-void CGuiHandler::dispatchMainThread(const std::function<void()> & functor)
+void GameEngine::dispatchMainThread(const std::function<void()> & functor)
 {
 	inputHandlerInstance->dispatchMainThread(functor);
 }
 
-IScreenHandler & CGuiHandler::screenHandler()
+IScreenHandler & GameEngine::screenHandler()
 {
 	return *screenHandlerInstance;
 }
 
-IRenderHandler & CGuiHandler::renderHandler()
+IRenderHandler & GameEngine::renderHandler()
 {
 	return *renderHandlerInstance;
 }
 
-EventDispatcher & CGuiHandler::events()
+EventDispatcher & GameEngine::events()
 {
 	return *eventDispatcherInstance;
 }
 
-InputHandler & CGuiHandler::input()
+InputHandler & GameEngine::input()
 {
 	return *inputHandlerInstance;
 }
 
-WindowHandler & CGuiHandler::windows()
+WindowHandler & GameEngine::windows()
 {
 	assert(windowHandlerInstance);
 	return *windowHandlerInstance;
 }
 
-std::shared_ptr<IStatusBar> CGuiHandler::statusbar()
+std::shared_ptr<IStatusBar> GameEngine::statusbar()
 {
 	auto locked = currentStatusBar.lock();
 
@@ -227,12 +218,12 @@ std::shared_ptr<IStatusBar> CGuiHandler::statusbar()
 	return locked;
 }
 
-void CGuiHandler::setStatusbar(std::shared_ptr<IStatusBar> newStatusBar)
+void GameEngine::setStatusbar(std::shared_ptr<IStatusBar> newStatusBar)
 {
 	currentStatusBar = newStatusBar;
 }
 
-void CGuiHandler::onScreenResize(bool resolutionChanged)
+void GameEngine::onScreenResize(bool resolutionChanged)
 {
 	if(resolutionChanged)
 		screenHandler().onScreenResize();

+ 5 - 5
client/gui/CGuiHandler.h → client/GameEngine.h

@@ -1,5 +1,5 @@
 /*
- * CGuiHandler.h, part of VCMI engine
+ * GameEngine.h, part of VCMI engine
  *
  * Authors: listed in file AUTHORS in main folder
  *
@@ -28,7 +28,7 @@ class EventDispatcher;
 class InputHandler;
 
 // Handles GUI logic and drawing
-class CGuiHandler
+class GameEngine
 {
 private:
 	/// Fake no-op version status bar, for use in windows that have no status bar
@@ -92,8 +92,8 @@ public:
 	bool captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
 	std::list<CIntObject *> createdObj; //stack of objs being created
 
-	CGuiHandler();
-	~CGuiHandler();
+	GameEngine();
+	~GameEngine();
 
 	void init();
 	void renderFrame();
@@ -111,4 +111,4 @@ public:
 	void dispatchMainThread(const std::function<void()> & functor);
 };
 
-extern CGuiHandler GH; //global gui handler
+extern std::unique_ptr<GameEngine> ENGINE; //global gui handler

+ 2 - 2
client/HeroMovementController.cpp

@@ -15,7 +15,7 @@
 #include "PlayerLocalState.h"
 #include "adventureMap/AdventureMapInterface.h"
 #include "eventsSDL/InputHandler.h"
-#include "gui/CGuiHandler.h"
+#include "GameEngine.h"
 #include "gui/CursorHandler.h"
 #include "mapView/mapHandler.h"
 #include "media/ISoundPlayer.h"
@@ -235,7 +235,7 @@ void HeroMovementController::onMoveHeroApplied()
 	if(waitingForQueryApplyReply)
 		return;
 
-	if(GH.input().ignoreEventsUntilInput())
+	if(ENGINE->input().ignoreEventsUntilInput())
 		stoppingMovement = true;
 
 	assert(currentlyMovingHero);

+ 4 - 4
client/NetPacksClient.cpp

@@ -20,7 +20,7 @@
 #include "adventureMap/CInGameConsole.h"
 #include "battle/BattleInterface.h"
 #include "battle/BattleWindow.h"
-#include "gui/CGuiHandler.h"
+#include "GameEngine.h"
 #include "gui/WindowHandler.h"
 #include "widgets/MiscWidgets.h"
 #include "CMT.h"
@@ -161,7 +161,7 @@ void ApplyClientNetPackVisitor::visitSetMana(SetMana & pack)
 	if(settings["session"]["headless"].Bool())
 		return;
 
-	for(auto window : GH.windows().findWindows<BattleWindow>())
+	for(auto window : ENGINE->windows().findWindows<BattleWindow>())
 		window->heroManaPointsChanged(h);
 }
 
@@ -173,7 +173,7 @@ void ApplyClientNetPackVisitor::visitSetMovePoints(SetMovePoints & pack)
 
 void ApplyClientNetPackVisitor::visitSetResearchedSpells(SetResearchedSpells & pack)
 {
-	for(const auto & win : GH.windows().findWindows<CMageGuildScreen>())
+	for(const auto & win : ENGINE->windows().findWindows<CMageGuildScreen>())
 		win->updateSpells(pack.tid);
 }
 
@@ -412,7 +412,7 @@ void ApplyClientNetPackVisitor::visitPlayerEndsGame(PlayerEndsGame & pack)
 		assert(adventureInt);
 		if(adventureInt)
 		{
-			GH.windows().popWindows(GH.windows().count());
+			ENGINE->windows().popWindows(ENGINE->windows().count());
 			adventureInt.reset();
 		}
 

+ 16 - 16
client/NetPacksLobbyClient.cpp

@@ -27,7 +27,7 @@
 #include "GameChatHandler.h"
 #include "CGameInfo.h"
 #include "Client.h"
-#include "gui/CGuiHandler.h"
+#include "GameEngine.h"
 #include "gui/WindowHandler.h"
 #include "widgets/Buttons.h"
 #include "widgets/TextControls.h"
@@ -55,10 +55,10 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientCon
 		}
 		else if(!settings["session"]["headless"].Bool())
 		{
-			if (GH.windows().topWindow<CSimpleJoinScreen>())
-				GH.windows().popWindows(1);
+			if (ENGINE->windows().topWindow<CSimpleJoinScreen>())
+				ENGINE->windows().popWindows(1);
 
-			if (!GH.windows().findWindows<GlobalLobbyServerSetup>().empty())
+			if (!ENGINE->windows().findWindows<GlobalLobbyServerSetup>().empty())
 			{
 				assert(handler.serverMode == EServerMode::LOBBY_HOST);
 				// announce opened game room
@@ -72,14 +72,14 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientCon
 					handler.getGlobalLobby().sendOpenRoom("public", roomPlayerLimit);
 			}
 
-			while (!GH.windows().findWindows<GlobalLobbyWindow>().empty())
+			while (!ENGINE->windows().findWindows<GlobalLobbyWindow>().empty())
 			{
 				// if global lobby is open, pop all dialogs on top of it as well as lobby itself
-				GH.windows().popWindows(1);
+				ENGINE->windows().popWindows(1);
 			}
 
 			bool hideScreen = handler.campaignStateToSend && (!handler.campaignStateToSend->campaignSet.empty() || handler.campaignStateToSend->lastScenario());
-			GH.windows().createAndPushWindow<CLobbyScreen>(handler.screenType, hideScreen);
+			ENGINE->windows().createAndPushWindow<CLobbyScreen>(handler.screenType, hideScreen);
 		}
 		handler.setState(EClientState::LOBBY);
 	}
@@ -96,11 +96,11 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientDisconnected(LobbyClient
 
 void ApplyOnLobbyScreenNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
 {
-	if(auto w = GH.windows().topWindow<CLoadingScreen>())
-		GH.windows().popWindow(w);
+	if(auto w = ENGINE->windows().topWindow<CLoadingScreen>())
+		ENGINE->windows().popWindow(w);
 	
-	if(GH.windows().count() > 0)
-		GH.windows().popWindows(1);
+	if(ENGINE->windows().count() > 0)
+		ENGINE->windows().popWindows(1);
 }
 
 void ApplyOnLobbyScreenNetPackVisitor::visitLobbyChatMessage(LobbyChatMessage & pack)
@@ -171,7 +171,7 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pac
 
 void ApplyOnLobbyScreenNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
 {
-	if(auto w = GH.windows().topWindow<CLoadingScreen>())
+	if(auto w = ENGINE->windows().topWindow<CLoadingScreen>())
 	{
 		w->finish();
 		w->tick(0);
@@ -181,7 +181,7 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack
 
 void ApplyOnLobbyScreenNetPackVisitor::visitLobbyLoadProgress(LobbyLoadProgress & pack)
 {
-	if(auto w = GH.windows().topWindow<CLoadingScreen>())
+	if(auto w = ENGINE->windows().topWindow<CLoadingScreen>())
 	{
 		w->set(pack.progress);
 		w->tick(0);
@@ -212,14 +212,14 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState &
 		if(!handler.si->campState->conqueredScenarios().size() && !handler.si->campState->getIntroVideo().empty() && CCS->videoh->open(handler.si->campState->getIntroVideo(), 1))
 		{
 			CCS->musich->stopMusic();
-			GH.windows().createAndPushWindow<VideoWindow>(handler.si->campState->getIntroVideo(), handler.si->campState->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : handler.si->campState->getVideoRim(), false, 1, [bonusSel](bool skipped){
+			ENGINE->windows().createAndPushWindow<VideoWindow>(handler.si->campState->getIntroVideo(), handler.si->campState->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : handler.si->campState->getVideoRim(), false, 1, [bonusSel](bool skipped){
 				if(!CSH->si->campState->getMusic().empty())
 					CCS->musich->playMusic(CSH->si->campState->getMusic(), true, false);
-				GH.windows().pushWindow(bonusSel);
+				ENGINE->windows().pushWindow(bonusSel);
 			});
 		}
 		else
-			GH.windows().pushWindow(bonusSel);
+			ENGINE->windows().pushWindow(bonusSel);
 	}
 
 	if(lobby->bonusSel)

+ 29 - 29
client/adventureMap/AdventureMapInterface.cpp

@@ -27,7 +27,7 @@
 #include "../widgets/RadialMenu.h"
 #include "../CGameInfo.h"
 #include "../gui/CursorHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../render/Canvas.h"
@@ -61,8 +61,8 @@ AdventureMapInterface::AdventureMapInterface():
 {
 	OBJECT_CONSTRUCTION;
 	pos.x = pos.y = 0;
-	pos.w = GH.screenDimensions().x;
-	pos.h = GH.screenDimensions().y;
+	pos.w = ENGINE->screenDimensions().x;
+	pos.h = ENGINE->screenDimensions().y;
 
 	shortcuts = std::make_shared<AdventureMapShortcuts>(*this);
 
@@ -137,7 +137,7 @@ void AdventureMapInterface::activate()
 		LOCPLINT->cingconsole->pos = this->pos;
 	}
 
-	GH.fakeMouseMove(); //to restore the cursor
+	ENGINE->fakeMouseMove(); //to restore the cursor
 
 	// workaround for an edge case:
 	// if player unequips Angel Wings / Boots of Levitation of currently active hero
@@ -174,19 +174,19 @@ void AdventureMapInterface::dim(Canvas & to)
 	auto const isBigWindow = [&](std::shared_ptr<CIntObject> window) { return window->pos.w >= 800 && window->pos.h >= 600; }; // OH3 fullscreen
 
 	if(settings["adventure"]["hideBackground"].Bool())
-		for (auto window : GH.windows().findWindows<CIntObject>())
+		for (auto window : ENGINE->windows().findWindows<CIntObject>())
 		{
 			if(!std::dynamic_pointer_cast<AdventureMapInterface>(window) && std::dynamic_pointer_cast<CIntObject>(window) && isBigWindow(window))
 			{
-				to.fillTexture(GH.renderHandler().loadImage(ImagePath::builtin("DiBoxBck"), EImageBlitMode::OPAQUE));
+				to.fillTexture(ENGINE->renderHandler().loadImage(ImagePath::builtin("DiBoxBck"), EImageBlitMode::OPAQUE));
 				return;
 			}
 		}
-	for (auto window : GH.windows().findWindows<CIntObject>())
+	for (auto window : ENGINE->windows().findWindows<CIntObject>())
 	{
 		if (!std::dynamic_pointer_cast<AdventureMapInterface>(window) && !std::dynamic_pointer_cast<RadialMenu>(window) && !window->isPopupWindow() && (settings["adventure"]["backgroundDimSmallWindows"].Bool() || isBigWindow(window) || shortcuts->getState() == EAdventureState::HOTSEAT_WAIT))
 		{
-			Rect targetRect(0, 0, GH.screenDimensions().x, GH.screenDimensions().y);
+			Rect targetRect(0, 0, ENGINE->screenDimensions().x, ENGINE->screenDimensions().y);
 			ColorRGBA colorToFill(0, 0, 0, std::clamp<int>(backgroundDimLevel, 0, 255));
 			if(backgroundDimLevel > 0)
 				to.drawColorBlended(targetRect, colorToFill);
@@ -212,26 +212,26 @@ void AdventureMapInterface::handleMapScrollingUpdate(uint32_t timePassed)
 	int32_t scrollSpeedPixels = settings["adventure"]["scrollSpeedPixels"].Float();
 	int32_t scrollDistance = scrollSpeedPixels * timePassed / 1000;
 
-	Point cursorPosition = GH.getCursorPosition();
+	Point cursorPosition = ENGINE->getCursorPosition();
 	Point scrollDirection;
 
 	if (cursorPosition.x < borderScrollWidth)
 		scrollDirection.x = -1;
 
-	if (cursorPosition.x > GH.screenDimensions().x - borderScrollWidth)
+	if (cursorPosition.x > ENGINE->screenDimensions().x - borderScrollWidth)
 		scrollDirection.x = +1;
 
 	if (cursorPosition.y < borderScrollWidth)
 		scrollDirection.y = -1;
 
-	if (cursorPosition.y > GH.screenDimensions().y - borderScrollWidth)
+	if (cursorPosition.y > ENGINE->screenDimensions().y - borderScrollWidth)
 		scrollDirection.y = +1;
 
 	Point scrollDelta = scrollDirection * scrollDistance;
 
 	bool cursorInScrollArea = scrollDelta != Point(0,0);
 	bool scrollingActive = cursorInScrollArea && shortcuts->optionMapScrollingActive() && !scrollingWasBlocked;
-	bool scrollingBlocked = GH.isKeyboardCtrlDown() || !settings["adventure"]["borderScroll"].Bool() || !GH.screenHandler().hasFocus();
+	bool scrollingBlocked = ENGINE->isKeyboardCtrlDown() || !settings["adventure"]["borderScroll"].Bool() || !ENGINE->screenHandler().hasFocus();
 
 	if (!scrollingWasActive && scrollingBlocked)
 	{
@@ -299,7 +299,7 @@ void AdventureMapInterface::keyPressed(EShortcut key)
 		hotkeyAbortCastingMode();
 
 	//fake mouse use to trigger onTileHovered()
-	GH.fakeMouseMove();
+	ENGINE->fakeMouseMove();
 }
 
 void AdventureMapInterface::onSelectionChanged(const CArmedInstance *sel)
@@ -451,15 +451,15 @@ void AdventureMapInterface::onPlayerTurnStarted(PlayerColor playerID)
 		widget->getInfoBar()->showDate();
 
 	onHeroChanged(nullptr);
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 	mapAudio->onPlayerTurnStarted();
 
-	if(settings["session"]["autoSkip"].Bool() && !GH.isKeyboardShiftDown())
+	if(settings["session"]["autoSkip"].Bool() && !ENGINE->isKeyboardShiftDown())
 	{
-		if(auto iw = GH.windows().topWindow<CInfoWindow>())
+		if(auto iw = ENGINE->windows().topWindow<CInfoWindow>())
 			iw->close();
 
-		GH.dispatchMainThread([this]()
+		ENGINE->dispatchMainThread([this]()
 		{
 			hotkeyEndingTurn();
 		});
@@ -564,7 +564,7 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &targetPosition)
 
 			if(LOCPLINT->localState->hasPath(currentHero) &&
 			   LOCPLINT->localState->getPath(currentHero).endPos() == destinationTile &&
-			   !GH.isKeyboardShiftDown())//we'll be moving
+			   !ENGINE->isKeyboardShiftDown())//we'll be moving
 			{
 				assert(!CGI->mh->hasOngoingAnimations());
 				if(!CGI->mh->hasOngoingAnimations() && LOCPLINT->localState->getPath(currentHero).nextNode().turns == 0)
@@ -573,7 +573,7 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &targetPosition)
 			}
 			else
 			{
-				if(GH.isKeyboardShiftDown()) //normal click behaviour (as no hero selected)
+				if(ENGINE->isKeyboardShiftDown()) //normal click behaviour (as no hero selected)
 				{
 					if(canSelect)
 						LOCPLINT->localState->setSelection(static_cast<const CArmedInstance*>(topBlocking));
@@ -646,19 +646,19 @@ void AdventureMapInterface::onTileHovered(const int3 &targetPosition)
 		objRelations = LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner);
 		std::string text = LOCPLINT->localState->getCurrentHero() ? objAtTile->getHoverText(LOCPLINT->localState->getCurrentHero()) : objAtTile->getHoverText(LOCPLINT->playerID);
 		boost::replace_all(text,"\n"," ");
-		if (GH.isKeyboardCmdDown())
+		if (ENGINE->isKeyboardCmdDown())
 			text.append(" (" + std::to_string(targetPosition.x) + ", " + std::to_string(targetPosition.y) + ")");
-		GH.statusbar()->write(text);
+		ENGINE->statusbar()->write(text);
 	}
 	else if(isTargetPositionVisible)
 	{
 		std::string tileTooltipText = CGI->mh->getTerrainDescr(targetPosition, false);
-		if (GH.isKeyboardCmdDown())
+		if (ENGINE->isKeyboardCmdDown())
 			tileTooltipText.append(" (" + std::to_string(targetPosition.x) + ", " + std::to_string(targetPosition.y) + ")");
-		GH.statusbar()->write(tileTooltipText);
+		ENGINE->statusbar()->write(tileTooltipText);
 	}
 
-	if(LOCPLINT->localState->getCurrentArmy()->ID == Obj::TOWN || GH.isKeyboardShiftDown())
+	if(LOCPLINT->localState->getCurrentArmy()->ID == Obj::TOWN || ENGINE->isKeyboardShiftDown())
 	{
 		if(objAtTile)
 		{
@@ -685,7 +685,7 @@ void AdventureMapInterface::onTileHovered(const int3 &targetPosition)
 		const CGPathNode * pathNode = LOCPLINT->getPathsInfo(hero)->getPathInfo(targetPosition);
 		assert(pathNode);
 
-		if((GH.isKeyboardAltDown() || settings["gameTweaks"]["forceMovementInfo"].Bool()) && pathNode->reachable()) //overwrite status bar text with movement info
+		if((ENGINE->isKeyboardAltDown() || settings["gameTweaks"]["forceMovementInfo"].Bool()) && pathNode->reachable()) //overwrite status bar text with movement info
 		{
 			showMoveDetailsInStatusbar(*hero, *pathNode);
 		}
@@ -794,7 +794,7 @@ void AdventureMapInterface::showMoveDetailsInStatusbar(const CGHeroInstance & he
 	boost::replace_first(result, "%REMAINING", std::to_string(remainingPointsAfterMove));
 	boost::replace_first(result, "%TOTAL", std::to_string(totalMovementCost));
 
-	GH.statusbar()->write(result);
+	ENGINE->statusbar()->write(result);
 }
 
 void AdventureMapInterface::onTileRightClicked(const int3 &mapPos)
@@ -827,7 +827,7 @@ void AdventureMapInterface::onTileRightClicked(const int3 &mapPos)
 		return;
 	}
 
-	CRClickPopup::createAndPush(obj, GH.getCursorPosition(), ETextAlignment::CENTER);
+	CRClickPopup::createAndPush(obj, ENGINE->getCursorPosition(), ETextAlignment::CENTER);
 }
 
 void AdventureMapInterface::enterCastingMode(const CSpell * sp)
@@ -920,8 +920,8 @@ void AdventureMapInterface::onScreenResize()
 
 	widget.reset();
 	pos.x = pos.y = 0;
-	pos.w = GH.screenDimensions().x;
-	pos.h = GH.screenDimensions().y;
+	pos.w = ENGINE->screenDimensions().x;
+	pos.h = ENGINE->screenDimensions().y;
 
 	widget = std::make_shared<AdventureMapWidget>(shortcuts);
 	widget->getMapView()->onViewMapActivated();

+ 10 - 10
client/adventureMap/AdventureMapShortcuts.cpp

@@ -16,7 +16,7 @@
 #include "../CPlayerInterface.h"
 #include "../CServerHandler.h"
 #include "../PlayerLocalState.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../lobby/CSavingScreen.h"
@@ -122,7 +122,7 @@ std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
 
 void AdventureMapShortcuts::showOverview()
 {
-	GH.windows().createAndPushWindow<CKingdomInterface>();
+	ENGINE->windows().createAndPushWindow<CKingdomInterface>();
 }
 
 void AdventureMapShortcuts::worldViewBack()
@@ -236,17 +236,17 @@ void AdventureMapShortcuts::showSpellbook()
 
 	owner.centerOnObject(LOCPLINT->localState->getCurrentHero());
 
-	GH.windows().createAndPushWindow<CSpellWindow>(LOCPLINT->localState->getCurrentHero(), LOCPLINT, false);
+	ENGINE->windows().createAndPushWindow<CSpellWindow>(LOCPLINT->localState->getCurrentHero(), LOCPLINT, false);
 }
 
 void AdventureMapShortcuts::adventureOptions()
 {
-	GH.windows().createAndPushWindow<AdventureOptions>();
+	ENGINE->windows().createAndPushWindow<AdventureOptions>();
 }
 
 void AdventureMapShortcuts::systemOptions()
 {
-	GH.windows().createAndPushWindow<SettingsMainWindow>();
+	ENGINE->windows().createAndPushWindow<SettingsMainWindow>();
 }
 
 void AdventureMapShortcuts::firstHero()
@@ -356,7 +356,7 @@ void AdventureMapShortcuts::quitGame()
 		CGI->generaltexth->allTexts[578],
 		[]()
 		{
-			GH.dispatchMainThread( []()
+			ENGINE->dispatchMainThread( []()
 			{
 				handleQuit(false);
 			});
@@ -367,7 +367,7 @@ void AdventureMapShortcuts::quitGame()
 
 void AdventureMapShortcuts::saveGame()
 {
-	GH.windows().createAndPushWindow<CSavingScreen>();
+	ENGINE->windows().createAndPushWindow<CSavingScreen>();
 }
 
 void AdventureMapShortcuts::loadGame()
@@ -394,7 +394,7 @@ void AdventureMapShortcuts::restartGame()
 		CGI->generaltexth->translate("vcmi.adventureMap.confirmRestartGame"),
 		[]()
 		{
-			GH.dispatchMainThread(
+			ENGINE->dispatchMainThread(
 				[]()
 				{
 					CSH->sendRestartGame();
@@ -438,7 +438,7 @@ void AdventureMapShortcuts::showMarketplace()
 	}
 
 	if(townWithMarket) //if any town has marketplace, open window
-		GH.windows().createAndPushWindow<CMarketWindow>(townWithMarket, nullptr, nullptr, EMarketMode::RESOURCE_RESOURCE);
+		ENGINE->windows().createAndPushWindow<CMarketWindow>(townWithMarket, nullptr, nullptr, EMarketMode::RESOURCE_RESOURCE);
 	else //if not - complain
 		LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithMarket"));
 }
@@ -516,7 +516,7 @@ void AdventureMapShortcuts::search(bool next)
 	if(next)
 		selectObjOnMap(lastSel);
 	else
-		GH.windows().createAndPushWindow<CObjectListWindow>(texts, nullptr, CGI->generaltexth->translate("vcmi.adventureMap.search.hover"), CGI->generaltexth->translate("vcmi.adventureMap.search.help"), [selectObjOnMap](int index){ selectObjOnMap(index); }, lastSel, std::vector<std::shared_ptr<IImage>>(), true);
+		ENGINE->windows().createAndPushWindow<CObjectListWindow>(texts, nullptr, CGI->generaltexth->translate("vcmi.adventureMap.search.hover"), CGI->generaltexth->translate("vcmi.adventureMap.search.help"), [selectObjOnMap](int index){ selectObjOnMap(index); }, lastSel, std::vector<std::shared_ptr<IImage>>(), true);
 }
 
 void AdventureMapShortcuts::nextObject()

+ 3 - 3
client/adventureMap/AdventureMapWidget.cpp

@@ -17,7 +17,7 @@
 #include "CResDataBar.h"
 #include "AdventureState.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../mapView/MapView.h"
 #include "../render/IImage.h"
@@ -37,8 +37,8 @@ AdventureMapWidget::AdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> s
 	, mapLevel(0)
 {
 	pos.x = pos.y = 0;
-	pos.w = GH.screenDimensions().x;
-	pos.h = GH.screenDimensions().y;
+	pos.w = ENGINE->screenDimensions().x;
+	pos.h = ENGINE->screenDimensions().y;
 
 	REGISTER_BUILDER("adventureInfobar",         &AdventureMapWidget::buildInfobox         );
 	REGISTER_BUILDER("adventureMapImage",        &AdventureMapWidget::buildMapImage        );

+ 3 - 3
client/adventureMap/AdventureOptions.cpp

@@ -16,7 +16,7 @@
 #include "../PlayerLocalState.h"
 #include "../lobby/CCampaignInfoScreen.h"
 #include "../lobby/CScenarioInfoScreen.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../gui/Shortcut.h"
 #include "../widgets/Buttons.h"
@@ -55,11 +55,11 @@ void AdventureOptions::showScenarioInfo()
 {
 	if(LOCPLINT->cb->getStartInfo()->campState)
 	{
-		GH.windows().createAndPushWindow<CCampaignInfoScreen>();
+		ENGINE->windows().createAndPushWindow<CCampaignInfoScreen>();
 	}
 	else
 	{
-		GH.windows().createAndPushWindow<CScenarioInfoScreen>();
+		ENGINE->windows().createAndPushWindow<CScenarioInfoScreen>();
 	}
 }
 

+ 11 - 11
client/adventureMap/CInGameConsole.cpp

@@ -16,7 +16,7 @@
 #include "../CServerHandler.h"
 #include "../GameChatHandler.h"
 #include "../ClientCommandManager.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../gui/Shortcut.h"
 #include "../gui/TextAlignment.h"
@@ -82,7 +82,7 @@ void CInGameConsole::tick(uint32_t msPassed)
 	);
 
 	if(sizeBefore != texts.size())
-		GH.windows().totalRedraw(); // FIXME: ingame console has no parent widget set
+		ENGINE->windows().totalRedraw(); // FIXME: ingame console has no parent widget set
 }
 
 void CInGameConsole::addMessageSilent(const std::string & timeFormatted, const std::string & senderName, const std::string & messageText)
@@ -111,14 +111,14 @@ void CInGameConsole::addMessage(const std::string & timeFormatted, const std::st
 {
 	addMessageSilent(timeFormatted, senderName, messageText);
 
-	GH.windows().totalRedraw(); // FIXME: ingame console has no parent widget set
+	ENGINE->windows().totalRedraw(); // FIXME: ingame console has no parent widget set
 
 	int volume = CCS->soundh->getVolume();
 	if(volume == 0)
 		CCS->soundh->setVolume(settings["general"]["sound"].Integer());
 	int handle = CCS->soundh->playSound(AudioPath::builtin("CHAT"));
 	if(volume == 0)
-		CCS->soundh->setCallback(handle, [&]() { if(!GH.screenHandler().hasFocus()) CCS->soundh->setVolume(0); });
+		CCS->soundh->setCallback(handle, [&]() { if(!ENGINE->screenHandler().hasFocus()) CCS->soundh->setVolume(0); });
 }
 
 bool CInGameConsole::captureThisKey(EShortcut key)
@@ -253,7 +253,7 @@ void CInGameConsole::showRecentChatHistory()
 	for (int i = firstEntryToShow; i < history.size(); ++i)
 		addMessageSilent(history[i].dateFormatted, history[i].senderName, history[i].messageText);
 
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void CInGameConsole::startEnteringText()
@@ -264,20 +264,20 @@ void CInGameConsole::startEnteringText()
 	if(isEnteringText())
 	{
 		// force-reset text input to re-show on-screen keyboard
-		GH.statusbar()->setEnteringMode(false);
-		GH.statusbar()->setEnteringMode(true);
-		GH.statusbar()->setEnteredText(enteredText);
+		ENGINE->statusbar()->setEnteringMode(false);
+		ENGINE->statusbar()->setEnteringMode(true);
+		ENGINE->statusbar()->setEnteredText(enteredText);
 		return;
 	}
 		
 	assert(currentStatusBar.expired());//effectively, nullptr check
 
-	currentStatusBar = GH.statusbar();
+	currentStatusBar = ENGINE->statusbar();
 
 	enteredText = "_";
 
-	GH.statusbar()->setEnteringMode(true);
-	GH.statusbar()->setEnteredText(enteredText);
+	ENGINE->statusbar()->setEnteringMode(true);
+	ENGINE->statusbar()->setEnteredText(enteredText);
 
 	showRecentChatHistory();
 }

+ 5 - 5
client/adventureMap/CInfoBar.cpp

@@ -22,7 +22,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../PlayerLocalState.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../media/ISoundPlayer.h"
 #include "../render/IScreenHandler.h"
@@ -245,7 +245,7 @@ void CInfoBar::playNewDaySound()
 		handle = CCS->soundh->playSound(soundBase::newDay);
 
 	if(volume == 0)
-		CCS->soundh->setCallback(handle, [&]() { if(!GH.screenHandler().hasFocus()) CCS->soundh->setVolume(0); });
+		CCS->soundh->setCallback(handle, [&]() { if(!ENGINE->screenHandler().hasFocus()) CCS->soundh->setVolume(0); });
 }
 
 void CInfoBar::reset()
@@ -281,7 +281,7 @@ void CInfoBar::tick(uint32_t msPassed)
 	{
 		timerCounter = 0;
 		removeUsedEvents(TIME);
-		if(GH.windows().isTopWindow(adventureInt))
+		if(ENGINE->windows().isTopWindow(adventureInt))
 			popComponents(true);
 	}
 	else
@@ -314,9 +314,9 @@ void CInfoBar::showPopupWindow(const Point & cursorPosition)
 void CInfoBar::hover(bool on)
 {
 	if(on)
-		GH.statusbar()->write(CGI->generaltexth->zelp[292].first);
+		ENGINE->statusbar()->write(CGI->generaltexth->zelp[292].first);
 	else
-		GH.statusbar()->clear();
+		ENGINE->statusbar()->clear();
 }
 
 CInfoBar::CInfoBar(const Rect & position)

+ 8 - 8
client/adventureMap/CList.cpp

@@ -22,7 +22,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../PlayerLocalState.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../render/Canvas.h"
@@ -66,9 +66,9 @@ void CList::CListItem::clickPressed(const Point & cursorPosition)
 void CList::CListItem::hover(bool on)
 {
 	if (on)
-		GH.statusbar()->write(getHoverText());
+		ENGINE->statusbar()->write(getHoverText());
 	else
-		GH.statusbar()->clear();
+		ENGINE->statusbar()->clear();
 }
 
 void CList::CListItem::onSelect(bool on)
@@ -260,7 +260,7 @@ void CHeroList::CHeroItem::open()
 
 void CHeroList::CHeroItem::showTooltip()
 {
-	CRClickPopup::createAndPush(hero, GH.getCursorPosition());
+	CRClickPopup::createAndPush(hero, ENGINE->getCursorPosition());
 }
 
 std::string CHeroList::CHeroItem::getHoverText()
@@ -300,7 +300,7 @@ void CHeroList::CHeroItem::gesture(bool on, const Point & initialPosition, const
 		} },
 	};
 
-	GH.windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements, true);
+	ENGINE->windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements, true);
 }
 
 void CHeroList::CHeroItem::keyPressed(EShortcut key)
@@ -471,7 +471,7 @@ void CTownList::CTownItem::gesture(bool on, const Point & initialPosition, const
 	int townLowerPos = (townIndex > towns.size() - 2) ? -1 : townIndex + 1;
 
 	auto updateList = [](){
-		for (auto ci : GH.windows().findWindows<CCastleInterface>())
+		for (auto ci : ENGINE->windows().findWindows<CCastleInterface>())
 		{
 			ci->townlist->updateWidget();
 			ci->townlist->select(ci->town);
@@ -495,7 +495,7 @@ void CTownList::CTownItem::gesture(bool on, const Point & initialPosition, const
 		} },
 	};
 
-	GH.windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements, true);
+	ENGINE->windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements, true);
 }
 
 void CTownList::CTownItem::keyPressed(EShortcut key)
@@ -540,7 +540,7 @@ void CTownList::CTownItem::keyPressed(EShortcut key)
 		break;
 	}
 
-	for (auto ki : GH.windows().findWindows<CCastleInterface>())
+	for (auto ki : ENGINE->windows().findWindows<CCastleInterface>())
 		ki->townChange(); //update list
 }
 

+ 4 - 4
client/adventureMap/CMinimap.cpp

@@ -16,7 +16,7 @@
 #include "../widgets/Images.h"
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/MouseButton.h"
 #include "../gui/WindowHandler.h"
 #include "../render/Colors.h"
@@ -141,7 +141,7 @@ void CMinimap::moveAdvMapSelection(const Point & positionGlobal)
 	adventureInt->centerOnTile(newLocation);
 
 	if (!(adventureInt->isActive()))
-		GH.windows().totalRedraw(); //redraw this as well as inactive adventure map
+		ENGINE->windows().totalRedraw(); //redraw this as well as inactive adventure map
 	else
 		redraw();//redraw only this
 }
@@ -165,9 +165,9 @@ void CMinimap::showPopupWindow(const Point & cursorPosition)
 void CMinimap::hover(bool on)
 {
 	if(on)
-		GH.statusbar()->write(CGI->generaltexth->zelp[291].first);
+		ENGINE->statusbar()->write(CGI->generaltexth->zelp[291].first);
 	else
-		GH.statusbar()->clear();
+		ENGINE->statusbar()->clear();
 }
 
 void CMinimap::mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance)

+ 1 - 1
client/adventureMap/CResDataBar.cpp

@@ -15,7 +15,7 @@
 #include "../render/Canvas.h"
 #include "../render/Colors.h"
 #include "../render/EFont.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/TextAlignment.h"
 #include "../widgets/Images.h"
 

+ 1 - 1
client/adventureMap/TurnTimerWidget.cpp

@@ -14,7 +14,7 @@
 #include "../CPlayerInterface.h"
 #include "../battle/BattleInterface.h"
 #include "../battle/BattleStacksController.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../media/ISoundPlayer.h"
 #include "../render/Graphics.h"
 #include "../widgets/Images.h"

+ 13 - 13
client/battle/BattleActionsController.cpp

@@ -20,7 +20,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../gui/CursorHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/CIntObject.h"
 #include "../gui/WindowHandler.h"
 #include "../windows/CCreatureWindow.h"
@@ -149,7 +149,7 @@ void BattleActionsController::endCastingSpell()
 		possibleActions = getPossibleActionsForStack(owner.stacksController->getActiveStack()); //restore actions after they were cleared
 
 	selectedStack = nullptr;
-	GH.fakeMouseMove();
+	ENGINE->fakeMouseMove();
 }
 
 bool BattleActionsController::isActiveStackSpellcaster() const
@@ -183,7 +183,7 @@ void BattleActionsController::enterCreatureCastingMode()
 		};
 
 		vstd::erase_if(possibleActions, actionFilterPredicate);
-		GH.fakeMouseMove();
+		ENGINE->fakeMouseMove();
 		return;
 	}
 
@@ -226,7 +226,7 @@ void BattleActionsController::enterCreatureCastingMode()
 	};
 
 	vstd::erase_if(possibleActions, actionFilterPredicate);
-	GH.fakeMouseMove();
+	ENGINE->fakeMouseMove();
 }
 
 std::vector<PossiblePlayerBattleAction> BattleActionsController::getPossibleActionsForStack(const CStack *stack) const
@@ -345,7 +345,7 @@ void BattleActionsController::castThisSpell(SpellID spellID)
 	{
 		possibleActions.clear();
 		possibleActions.push_back (spellSelMode); //only this one action can be performed at the moment
-		GH.fakeMouseMove();//update cursor
+		ENGINE->fakeMouseMove();//update cursor
 	}
 
 	owner.windowObject->blockUI(true);
@@ -771,7 +771,7 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, c
 
 		case PossiblePlayerBattleAction::CREATURE_INFO:
 		{
-			GH.windows().createAndPushWindow<CStackWindow>(targetStack, false);
+			ENGINE->windows().createAndPushWindow<CStackWindow>(targetStack, false);
 			return;
 		}
 
@@ -875,7 +875,7 @@ void BattleActionsController::onHexHovered(const BattleHex & hoveredHex)
 	if (owner.openingPlaying())
 	{
 		currentConsoleMsg = VLC->generaltexth->translate("vcmi.battleWindow.pressKeyToSkipIntro");
-		GH.statusbar()->write(currentConsoleMsg);
+		ENGINE->statusbar()->write(currentConsoleMsg);
 		return;
 	}
 
@@ -885,7 +885,7 @@ void BattleActionsController::onHexHovered(const BattleHex & hoveredHex)
 	if (hoveredHex == BattleHex::INVALID)
 	{
 		if (!currentConsoleMsg.empty())
-			GH.statusbar()->clearIfMatching(currentConsoleMsg);
+			ENGINE->statusbar()->clearIfMatching(currentConsoleMsg);
 
 		currentConsoleMsg.clear();
 		CCS->curh->set(Cursor::Combat::BLOCKED);
@@ -908,10 +908,10 @@ void BattleActionsController::onHexHovered(const BattleHex & hoveredHex)
 	}
 
 	if (!currentConsoleMsg.empty())
-		GH.statusbar()->clearIfMatching(currentConsoleMsg);
+		ENGINE->statusbar()->clearIfMatching(currentConsoleMsg);
 
 	if (!newConsoleMsg.empty())
-		GH.statusbar()->write(newConsoleMsg);
+		ENGINE->statusbar()->write(newConsoleMsg);
 
 	currentConsoleMsg = newConsoleMsg;
 }
@@ -921,7 +921,7 @@ void BattleActionsController::onHoverEnded()
 	CCS->curh->set(Cursor::Combat::POINTER);
 
 	if (!currentConsoleMsg.empty())
-		GH.statusbar()->clearIfMatching(currentConsoleMsg);
+		ENGINE->statusbar()->clearIfMatching(currentConsoleMsg);
 
 	currentConsoleMsg.clear();
 }
@@ -939,7 +939,7 @@ void BattleActionsController::onHexLeftClicked(const BattleHex & clickedHex)
 		return;
 	
 	actionRealize(action, clickedHex);
-	GH.statusbar()->clear();
+	ENGINE->statusbar()->clear();
 }
 
 void BattleActionsController::tryActivateStackSpellcasting(const CStack *casterStack)
@@ -1071,7 +1071,7 @@ void BattleActionsController::onHexRightClicked(const BattleHex & clickedHex)
 	auto selectedStack = owner.getBattle()->battleGetStackByPos(clickedHex, true);
 
 	if (selectedStack != nullptr)
-		GH.windows().createAndPushWindow<CStackWindow>(selectedStack, true);
+		ENGINE->windows().createAndPushWindow<CStackWindow>(selectedStack, true);
 
 	if (clickedHex == BattleHex::HERO_ATTACKER && owner.attackingHero)
 		owner.attackingHero->heroRightClicked();

+ 2 - 2
client/battle/BattleAnimationClasses.cpp

@@ -22,7 +22,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../gui/CursorHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../media/ISoundPlayer.h"
 #include "../render/CAnimation.h"
 #include "../render/IRenderHandler.h"
@@ -888,7 +888,7 @@ uint32_t CastAnimation::getAttackClimaxFrame() const
 
 EffectAnimation::EffectAnimation(BattleInterface & owner, const AnimationPath & animationName, int effects, float transparencyFactor, bool reversed):
 	BattleAnimation(owner),
-	animation(GH.renderHandler().loadAnimation(animationName, EImageBlitMode::SIMPLE)),
+	animation(ENGINE->renderHandler().loadAnimation(animationName, EImageBlitMode::SIMPLE)),
 	transparencyFactor(transparencyFactor),
 	effectFlags(effects),
 	effectFinished(false),

+ 13 - 13
client/battle/BattleFieldController.cpp

@@ -27,7 +27,7 @@
 #include "../render/Canvas.h"
 #include "../render/IImage.h"
 #include "../render/IRenderHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/CursorHandler.h"
 #include "../adventureMap/CInGameConsole.h"
 #include "../client/render/CAnimation.h"
@@ -112,16 +112,16 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
 	OBJECT_CONSTRUCTION;
 
 	//preparing cells and hexes
-	cellBorder = GH.renderHandler().loadImage(ImagePath::builtin("CCELLGRD.BMP"), EImageBlitMode::COLORKEY);
-	cellShade = GH.renderHandler().loadImage(ImagePath::builtin("CCELLSHD.BMP"), EImageBlitMode::SIMPLE);
-	cellUnitMovementHighlight = GH.renderHandler().loadImage(ImagePath::builtin("UnitMovementHighlight.PNG"), EImageBlitMode::COLORKEY);
-	cellUnitMaxMovementHighlight = GH.renderHandler().loadImage(ImagePath::builtin("UnitMaxMovementHighlight.PNG"), EImageBlitMode::COLORKEY);
+	cellBorder = ENGINE->renderHandler().loadImage(ImagePath::builtin("CCELLGRD.BMP"), EImageBlitMode::COLORKEY);
+	cellShade = ENGINE->renderHandler().loadImage(ImagePath::builtin("CCELLSHD.BMP"), EImageBlitMode::SIMPLE);
+	cellUnitMovementHighlight = ENGINE->renderHandler().loadImage(ImagePath::builtin("UnitMovementHighlight.PNG"), EImageBlitMode::COLORKEY);
+	cellUnitMaxMovementHighlight = ENGINE->renderHandler().loadImage(ImagePath::builtin("UnitMaxMovementHighlight.PNG"), EImageBlitMode::COLORKEY);
 
-	attackCursors = GH.renderHandler().loadAnimation(AnimationPath::builtin("CRCOMBAT"), EImageBlitMode::COLORKEY);
-	spellCursors = GH.renderHandler().loadAnimation(AnimationPath::builtin("CRSPELL"), EImageBlitMode::COLORKEY);
+	attackCursors = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("CRCOMBAT"), EImageBlitMode::COLORKEY);
+	spellCursors = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("CRSPELL"), EImageBlitMode::COLORKEY);
 
-	rangedFullDamageLimitImages = GH.renderHandler().loadAnimation(AnimationPath::builtin("battle/rangeHighlights/rangeHighlightsGreen.json"), EImageBlitMode::COLORKEY);
-	shootingRangeLimitImages = GH.renderHandler().loadAnimation(AnimationPath::builtin("battle/rangeHighlights/rangeHighlightsRed.json"), EImageBlitMode::COLORKEY);
+	rangedFullDamageLimitImages = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("battle/rangeHighlights/rangeHighlightsGreen.json"), EImageBlitMode::COLORKEY);
+	shootingRangeLimitImages = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("battle/rangeHighlights/rangeHighlightsRed.json"), EImageBlitMode::COLORKEY);
 
 	if(!owner.siegeController)
 	{
@@ -130,12 +130,12 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
 		if(bfieldType == BattleField::NONE)
 			logGlobal->error("Invalid battlefield returned for current battle");
 		else
-			background = GH.renderHandler().loadImage(bfieldType.getInfo()->graphics, EImageBlitMode::OPAQUE);
+			background = ENGINE->renderHandler().loadImage(bfieldType.getInfo()->graphics, EImageBlitMode::OPAQUE);
 	}
 	else
 	{
 		auto backgroundName = owner.siegeController->getBattleBackgroundName();
-		background = GH.renderHandler().loadImage(backgroundName, EImageBlitMode::OPAQUE);
+		background = ENGINE->renderHandler().loadImage(backgroundName, EImageBlitMode::OPAQUE);
 	}
 
 	pos.w = background->width();
@@ -329,7 +329,7 @@ BattleHexArray BattleFieldController::getMovementRangeForHoveredStack()
 	if (!owner.stacksController->getActiveStack())
 		return BattleHexArray();
 
-	if (!settings["battle"]["movementHighlightOnHover"].Bool() && !GH.isKeyboardShiftDown())
+	if (!settings["battle"]["movementHighlightOnHover"].Bool() && !ENGINE->isKeyboardShiftDown())
 		return BattleHexArray();
 
 	auto hoveredStack = getHoveredStack();
@@ -416,7 +416,7 @@ BattleHexArray BattleFieldController::getRangeHexes(const BattleHex & sourceHex,
 {
 	BattleHexArray rangeHexes;
 
-	if (!settings["battle"]["rangeLimitHighlightOnHover"].Bool() && !GH.isKeyboardShiftDown())
+	if (!settings["battle"]["rangeLimitHighlightOnHover"].Bool() && !ENGINE->isKeyboardShiftDown())
 		return rangeHexes;
 
 	// get only battlefield hexes that are within the given distance

+ 6 - 6
client/battle/BattleInterface.cpp

@@ -26,7 +26,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../gui/CursorHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../media/IMusicPlayer.h"
 #include "../media/ISoundPlayer.h"
@@ -97,7 +97,7 @@ BattleInterface::BattleInterface(const BattleID & battleID, const CCreatureSet *
 	adventureInt->onAudioPaused();
 	ongoingAnimationsState.setBusy();
 
-	GH.windows().pushWindow(windowObject);
+	ENGINE->windows().pushWindow(windowObject);
 	windowObject->blockUI(true);
 	windowObject->updateQueue();
 
@@ -191,7 +191,7 @@ BattleInterface::~BattleInterface()
 void BattleInterface::redrawBattlefield()
 {
 	fieldController->redrawBackgroundWithHexes();
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void BattleInterface::stackReset(const CStack * stack)
@@ -352,7 +352,7 @@ void BattleInterface::battleFinished(const BattleResult& br, QueryID queryID)
 	{
 		curInt->cb->selectionMade(selection, queryID);
 	};
-	GH.windows().pushWindow(wnd);
+	ENGINE->windows().pushWindow(wnd);
 
 	curInt->waitWhileDialog(); // Avoid freeze when AI end turn after battle. Check bug #1897
 	CPlayerInterface::battleInt.reset();
@@ -586,7 +586,7 @@ void BattleInterface::activateStack()
 	windowObject->blockUI(false);
 	fieldController->redrawBackgroundWithHexes();
 	actionsController->activateStack();
-	GH.fakeMouseMove();
+	ENGINE->fakeMouseMove();
 }
 
 bool BattleInterface::makingTurn() const
@@ -813,7 +813,7 @@ void BattleInterface::onAnimationsFinished()
 void BattleInterface::waitForAnimations()
 {
 	{
-		auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
+		auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
 		ongoingAnimationsState.waitWhileBusy();
 	}
 

+ 19 - 19
client/battle/BattleInterfaceClasses.cpp

@@ -21,7 +21,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../gui/CursorHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/MouseButton.h"
 #include "../gui/WindowHandler.h"
@@ -113,7 +113,7 @@ std::vector<std::string> BattleConsole::splitText(const std::string &text)
 
 	boost::split(lines, text, boost::is_any_of("\n"));
 
-	const auto & font = GH.renderHandler().loadFont(FONT_SMALL);
+	const auto & font = ENGINE->renderHandler().loadFont(FONT_SMALL);
 	for(const auto & line : lines)
 	{
 		if (font->getStringWidth(text) < pos.w)
@@ -180,7 +180,7 @@ void BattleConsole::clickPressed(const Point & cursorPosition)
 {
 	if(owner.makingTurn() && !owner.openingPlaying())
 	{
-		GH.windows().createAndPushWindow<BattleConsoleWindow>(boost::algorithm::join(logEntries, "\n"));
+		ENGINE->windows().createAndPushWindow<BattleConsoleWindow>(boost::algorithm::join(logEntries, "\n"));
 	}
 }
 
@@ -191,12 +191,12 @@ void BattleConsole::setEnteringMode(bool on)
 	if (on)
 	{
 		assert(enteringText == false);
-		GH.startTextInput(pos);
+		ENGINE->input().startTextInput(pos);
 	}
 	else
 	{
 		assert(enteringText == true);
-		GH.stopTextInput();
+		ENGINE->input().stopTextInput();
 	}
 	enteringText = on;
 	redraw();
@@ -338,7 +338,7 @@ void BattleHero::heroLeftClicked()
 	if(owner.getBattle()->battleCanCastSpell(hero, spells::Mode::HERO) == ESpellCastProblem::OK) //check conditions
 	{
 		CCS->curh->set(Cursor::Map::POINTER);
-		GH.windows().createAndPushWindow<CSpellWindow>(hero, owner.getCurrentPlayerInterface());
+		ENGINE->windows().createAndPushWindow<CSpellWindow>(hero, owner.getCurrentPlayerInterface());
 	}
 }
 
@@ -348,7 +348,7 @@ void BattleHero::heroRightClicked()
 		return;
 
 	Point windowPosition;
-	if(GH.screenDimensions().x < 1000)
+	if(ENGINE->screenDimensions().x < 1000)
 	{
 		windowPosition.x = (!defender) ? owner.fieldController->pos.left() + 1 : owner.fieldController->pos.right() - 79;
 		windowPosition.y = owner.fieldController->pos.y + 135;
@@ -364,7 +364,7 @@ void BattleHero::heroRightClicked()
 	{
 		auto h = defender ? owner.defendingHeroInstance : owner.attackingHeroInstance;
 		targetHero.initFromHero(h, InfoAboutHero::EInfoLevel::INBATTLE);
-		GH.windows().createAndPushWindow<HeroInfoWindow>(targetHero, &windowPosition);
+		ENGINE->windows().createAndPushWindow<HeroInfoWindow>(targetHero, &windowPosition);
 	}
 }
 
@@ -398,7 +398,7 @@ BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * her
 	else
 		animationPath = hero->getHeroClass()->imageBattleMale;
 
-	animation = GH.renderHandler().loadAnimation(animationPath, EImageBlitMode::WITH_SHADOW);
+	animation = ENGINE->renderHandler().loadAnimation(animationPath, EImageBlitMode::WITH_SHADOW);
 
 	pos.w = 64;
 	pos.h = 136;
@@ -409,9 +409,9 @@ BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * her
 		animation->verticalFlip();
 
 	if(defender)
-		flagAnimation = GH.renderHandler().loadAnimation(AnimationPath::builtin("CMFLAGR"), EImageBlitMode::COLORKEY);
+		flagAnimation = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("CMFLAGR"), EImageBlitMode::COLORKEY);
 	else
-		flagAnimation = GH.renderHandler().loadAnimation(AnimationPath::builtin("CMFLAGL"), EImageBlitMode::COLORKEY);
+		flagAnimation = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("CMFLAGL"), EImageBlitMode::COLORKEY);
 
 	flagAnimation->playerColored(hero->tempOwner);
 
@@ -507,8 +507,8 @@ void QuickSpellPanel::create()
 		});
 		button->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("spellint"), id != SpellID::NONE ? id.num + 1 : 0));
 		button->addPopupCallback([this, i, hero](){
-			GH.input().hapticFeedback();
-			GH.windows().createAndPushWindow<CSpellWindow>(hero, owner.curInt.get(), true, [this, i](SpellID spell){
+			ENGINE->input().hapticFeedback();
+			ENGINE->windows().createAndPushWindow<CSpellWindow>(hero, owner.curInt.get(), true, [this, i](SpellID spell){
 				Settings configID = persistentStorage.write["quickSpell"][std::to_string(i)];
 				configID->String() = spell == SpellID::NONE ? "" : spell.toSpell()->identifier;
 				create();
@@ -522,7 +522,7 @@ void QuickSpellPanel::create()
 		{
 			buttonsDisabled.push_back(std::make_shared<TransparentFilledRectangle>(Rect(2, 7 + 50 * i, 48, 36), ColorRGBA(0, 0, 0, 172)));
 		}
-		if(GH.input().getCurrentInputMode() == InputMode::KEYBOARD_AND_MOUSE)
+		if(ENGINE->input().getCurrentInputMode() == InputMode::KEYBOARD_AND_MOUSE)
 			labels.push_back(std::make_shared<CLabel>(7, 10 + 50 * i, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, config["keyboard"]["battleSpellShortcut" + std::to_string(i)].String()));
 
 		buttons.push_back(button);
@@ -946,8 +946,8 @@ void BattleResultWindow::buttonPressed(int button)
 
 	close();
 
-	if(GH.windows().topWindow<BattleWindow>())
-		GH.windows().popWindows(1); //pop battle interface if present
+	if(ENGINE->windows().topWindow<BattleWindow>())
+		ENGINE->windows().popWindows(1); //pop battle interface if present
 
 	//Result window and battle interface are gone. We requested all dialogs to be closed before opening the battle,
 	//so we can be sure that there is no dialogs left on GUI stack.
@@ -976,7 +976,7 @@ StackQueue::StackQueue(bool Embedded, BattleInterface & owner)
 	{
 		int32_t queueSmallOutsideYOffset = 65;
 		bool queueSmallOutside = settings["battle"]["queueSmallOutside"].Bool() && (pos.y - queueSmallOutsideYOffset) >= 0;
-		queueSize = std::clamp(static_cast<int>(settings["battle"]["queueSmallSlots"].Float()), 1, queueSmallOutside ? GH.screenDimensions().x / 41 : 19);
+		queueSize = std::clamp(static_cast<int>(settings["battle"]["queueSmallSlots"].Float()), 1, queueSmallOutside ? ENGINE->screenDimensions().x / 41 : 19);
 
 		pos.w = queueSize * 41;
 		pos.h = 49;
@@ -1107,7 +1107,7 @@ void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn, std::
 		if(currentTurn && !owner->embedded)
 		{
 			std::string tmp = std::to_string(*currentTurn);
-			const auto & font = GH.renderHandler().loadFont(FONT_SMALL);
+			const auto & font = ENGINE->renderHandler().loadFont(FONT_SMALL);
 			int len = font->getStringWidth(tmp);
 			roundRect->pos.w = len + 6;
 			round->pos = Rect(roundRect->pos.center().x, roundRect->pos.center().y, 0, 0);
@@ -1170,5 +1170,5 @@ void StackQueue::StackBox::showPopupWindow(const Point & cursorPosition)
 	auto stacks = owner->owner.getBattle()->battleGetAllStacks();
 	for(const CStack * stack : stacks)
 		if(boundUnitID.has_value() && stack->unitId() == *boundUnitID)
-			GH.windows().createAndPushWindow<CStackWindow>(stack, true);
+			ENGINE->windows().createAndPushWindow<CStackWindow>(stack, true);
 }

+ 5 - 5
client/battle/BattleObstacleController.cpp

@@ -19,7 +19,7 @@
 
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../media/ISoundPlayer.h"
 #include "../render/CAnimation.h"
 #include "../render/Canvas.h"
@@ -50,11 +50,11 @@ void BattleObstacleController::loadObstacleImage(const CObstacleInstance & oi)
 	if (oi.obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE)
 	{
 		// obstacle uses single bitmap image for animations
-		obstacleImages[oi.uniqueID] = GH.renderHandler().loadImage(animationName.toType<EResType::IMAGE>(), EImageBlitMode::SIMPLE);
+		obstacleImages[oi.uniqueID] = ENGINE->renderHandler().loadImage(animationName.toType<EResType::IMAGE>(), EImageBlitMode::SIMPLE);
 	}
 	else
 	{
-		obstacleAnimations[oi.uniqueID] = GH.renderHandler().loadAnimation(animationName, EImageBlitMode::SIMPLE);
+		obstacleAnimations[oi.uniqueID] = ENGINE->renderHandler().loadAnimation(animationName, EImageBlitMode::SIMPLE);
 		obstacleImages[oi.uniqueID] = obstacleAnimations[oi.uniqueID]->getImage(0);
 	}
 }
@@ -78,7 +78,7 @@ void BattleObstacleController::obstacleRemoved(const std::vector<ObstacleChanges
 		if(animationPath.empty())
 			continue;
 
-		auto animation = GH.renderHandler().loadAnimation(animationPath, EImageBlitMode::SIMPLE);
+		auto animation = ENGINE->renderHandler().loadAnimation(animationPath, EImageBlitMode::SIMPLE);
 		auto first = animation->getImage(0, 0);
 		if(!first)
 			continue;
@@ -105,7 +105,7 @@ void BattleObstacleController::obstaclePlaced(const std::vector<std::shared_ptr<
 		if(!oi->visibleForSide(side, owner.getBattle()->battleHasNativeStack(side)))
 			continue;
 
-		auto animation = GH.renderHandler().loadAnimation(oi->getAppearAnimation(), EImageBlitMode::SIMPLE);
+		auto animation = ENGINE->renderHandler().loadAnimation(oi->getAppearAnimation(), EImageBlitMode::SIMPLE);
 		auto first = animation->getImage(0, 0);
 		if(!first)
 			continue;

+ 2 - 2
client/battle/BattleOverlayLogVisualizer.cpp

@@ -19,7 +19,7 @@
 #include "../render/IFont.h"
 #include "../render/IRenderHandler.h"
 #include "../gui/TextAlignment.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/Graphics.h"
 
 BattleOverlayLogVisualizer::BattleOverlayLogVisualizer(
@@ -32,7 +32,7 @@ BattleOverlayLogVisualizer::BattleOverlayLogVisualizer(
 void BattleOverlayLogVisualizer::drawText(const BattleHex & hex, int lineNumber, const std::string & text)
 {
 	Point offset = owner.fieldController->hexPositionLocal(hex).topLeft() + Point(20, 20);
-	const auto & font = GH.renderHandler().loadFont(FONT_TINY);
+	const auto & font = ENGINE->renderHandler().loadFont(FONT_TINY);
 	int h = font->getLineHeight();
 
 	offset.y += h * lineNumber;

+ 2 - 2
client/battle/BattleProjectileController.cpp

@@ -18,7 +18,7 @@
 #include "../render/CAnimation.h"
 #include "../render/Canvas.h"
 #include "../render/IRenderHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../CGameInfo.h"
 
 #include "../../lib/CStack.h"
@@ -192,7 +192,7 @@ void BattleProjectileController::initStackProjectile(const CStack * stack)
 
 std::shared_ptr<CAnimation> BattleProjectileController::createProjectileImage(const AnimationPath & path )
 {
-	std::shared_ptr<CAnimation> projectile = GH.renderHandler().loadAnimation(path, EImageBlitMode::COLORKEY);
+	std::shared_ptr<CAnimation> projectile = ENGINE->renderHandler().loadAnimation(path, EImageBlitMode::COLORKEY);
 
 	if(projectile->size(1) != 0)
 		logAnim->error("Expected empty group 1 in stack projectile");

+ 4 - 4
client/battle/BattleSiegeController.cpp

@@ -19,7 +19,7 @@
 
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../media/ISoundPlayer.h"
 #include "../render/Canvas.h"
 #include "../render/IImage.h"
@@ -179,7 +179,7 @@ BattleSiegeController::BattleSiegeController(BattleInterface & owner, const CGTo
 		if ( !getWallPieceExistence(EWallVisual::EWallVisual(g)) )
 			continue;
 
-		wallPieceImages[g] = GH.renderHandler().loadImage(getWallPieceImageName(EWallVisual::EWallVisual(g), EWallState::REINFORCED), EImageBlitMode::COLORKEY);
+		wallPieceImages[g] = ENGINE->renderHandler().loadImage(getWallPieceImageName(EWallVisual::EWallVisual(g), EWallState::REINFORCED), EImageBlitMode::COLORKEY);
 	}
 }
 
@@ -255,7 +255,7 @@ void BattleSiegeController::gateStateChanged(const EGateState state)
 		wallPieceImages[EWallVisual::GATE] = nullptr;
 
 	if (stateId != EWallState::NONE)
-		wallPieceImages[EWallVisual::GATE] = GH.renderHandler().loadImage(getWallPieceImageName(EWallVisual::GATE,  stateId), EImageBlitMode::COLORKEY);
+		wallPieceImages[EWallVisual::GATE] = ENGINE->renderHandler().loadImage(getWallPieceImageName(EWallVisual::GATE,  stateId), EImageBlitMode::COLORKEY);
 
 	if (playSound)
 		CCS->soundh->playSound(soundBase::DRAWBRG);
@@ -364,7 +364,7 @@ void BattleSiegeController::stackIsCatapulting(const CatapultAttack & ca)
 
 		auto wallState = EWallState(owner.getBattle()->battleGetWallState(attackInfo.attackedPart));
 
-		wallPieceImages[wallId] = GH.renderHandler().loadImage(getWallPieceImageName(EWallVisual::EWallVisual(wallId), wallState), EImageBlitMode::COLORKEY);
+		wallPieceImages[wallId] = ENGINE->renderHandler().loadImage(getWallPieceImageName(EWallVisual::EWallVisual(wallId), wallState), EImageBlitMode::COLORKEY);
 	}
 }
 

+ 6 - 6
client/battle/BattleStacksController.cpp

@@ -24,7 +24,7 @@
 
 #include "../CPlayerInterface.h"
 #include "../CGameInfo.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../media/ISoundPlayer.h"
 #include "../render/Colors.h"
@@ -81,10 +81,10 @@ BattleStacksController::BattleStacksController(BattleInterface & owner):
 	animIDhelper(0)
 {
 	//preparing graphics for displaying amounts of creatures
-	amountNormal     = GH.renderHandler().loadImage(ImagePath::builtin("combatUnitNumberWindowDefault"), EImageBlitMode::COLORKEY);
-	amountPositive   = GH.renderHandler().loadImage(ImagePath::builtin("combatUnitNumberWindowPositive"), EImageBlitMode::COLORKEY);
-	amountNegative   = GH.renderHandler().loadImage(ImagePath::builtin("combatUnitNumberWindowNegative"), EImageBlitMode::COLORKEY);
-	amountEffNeutral = GH.renderHandler().loadImage(ImagePath::builtin("combatUnitNumberWindowNeutral"), EImageBlitMode::COLORKEY);
+	amountNormal     = ENGINE->renderHandler().loadImage(ImagePath::builtin("combatUnitNumberWindowDefault"), EImageBlitMode::COLORKEY);
+	amountPositive   = ENGINE->renderHandler().loadImage(ImagePath::builtin("combatUnitNumberWindowPositive"), EImageBlitMode::COLORKEY);
+	amountNegative   = ENGINE->renderHandler().loadImage(ImagePath::builtin("combatUnitNumberWindowNegative"), EImageBlitMode::COLORKEY);
+	amountEffNeutral = ENGINE->renderHandler().loadImage(ImagePath::builtin("combatUnitNumberWindowNeutral"), EImageBlitMode::COLORKEY);
 
 	std::vector<const CStack*> stacks = owner.getBattle()->battleGetAllStacks(true);
 	for(const CStack * s : stacks)
@@ -842,7 +842,7 @@ void BattleStacksController::updateHoveredStacks()
 	}
 
 	if(mouseHoveredStacks != newStacks)
-		GH.windows().totalRedraw(); //fix for frozen stack info window and blue border in action bar
+		ENGINE->windows().totalRedraw(); //fix for frozen stack info window and blue border in action bar
 
 	mouseHoveredStacks = newStacks;
 }

+ 25 - 25
client/battle/BattleWindow.cpp

@@ -19,7 +19,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../gui/CursorHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../windows/CSpellWindow.h"
@@ -131,9 +131,9 @@ void BattleWindow::createQueue()
 	std::string queueSize = settings["battle"]["queueSize"].String();
 
 	if(queueSize == "auto")
-		embedQueue = GH.screenDimensions().y < 700;
+		embedQueue = ENGINE->screenDimensions().y < 700;
 	else
-		embedQueue = GH.screenDimensions().y < 700 || queueSize == "small";
+		embedQueue = ENGINE->screenDimensions().y < 700 || queueSize == "small";
 
 	queue = std::make_shared<StackQueue>(embedQueue, owner);
 	if(!embedQueue && showQueue)
@@ -210,7 +210,7 @@ void BattleWindow::hideStickyQuickSpellWindow()
 
 	setPositionInfoWindow();
 	createTimerInfoWindows();
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void BattleWindow::showStickyQuickSpellWindow()
@@ -220,7 +220,7 @@ void BattleWindow::showStickyQuickSpellWindow()
 
 	auto hero = owner.getBattle()->battleGetMyHero();
 
-	if(GH.screenDimensions().x >= 1050 && hero != nullptr && hero->hasSpellbook())
+	if(ENGINE->screenDimensions().x >= 1050 && hero != nullptr && hero->hasSpellbook())
 	{
 		quickSpellWindow->enable();
 		quickSpellWindow->isEnabled = true;
@@ -233,7 +233,7 @@ void BattleWindow::showStickyQuickSpellWindow()
 
 	setPositionInfoWindow();
 	createTimerInfoWindows();
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void BattleWindow::createTimerInfoWindows()
@@ -249,7 +249,7 @@ void BattleWindow::createTimerInfoWindows()
 
 		if (attacker.isValidPlayer())
 		{
-			if (GH.screenDimensions().x >= 1000)
+			if (ENGINE->screenDimensions().x >= 1000)
 				attackerTimerWidget = std::make_shared<TurnTimerWidget>(Point(-92 + xOffsetAttacker, 1), attacker);
 			else
 				attackerTimerWidget = std::make_shared<TurnTimerWidget>(Point(1, 135), attacker);
@@ -257,7 +257,7 @@ void BattleWindow::createTimerInfoWindows()
 
 		if (defender.isValidPlayer())
 		{
-			if (GH.screenDimensions().x >= 1000)
+			if (ENGINE->screenDimensions().x >= 1000)
 				defenderTimerWidget = std::make_shared<TurnTimerWidget>(Point(pos.w + 16, 1), defender);
 			else
 				defenderTimerWidget = std::make_shared<TurnTimerWidget>(Point(pos.w - 78, 135), defender);
@@ -314,7 +314,7 @@ void BattleWindow::hideQueue()
 		pos = center();
 	}
 	setPositionInfoWindow();
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void BattleWindow::showQueue()
@@ -328,7 +328,7 @@ void BattleWindow::showQueue()
 	createQueue();
 	updateQueue();
 	setPositionInfoWindow();
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void BattleWindow::toggleStickyHeroWindowsVisibility()
@@ -353,7 +353,7 @@ void BattleWindow::hideStickyHeroWindows()
 	if(defenderHeroWindow)
 		defenderHeroWindow->disable();
 
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void BattleWindow::showStickyHeroWindows()
@@ -366,7 +366,7 @@ void BattleWindow::showStickyHeroWindows()
 
 
 	createStickyHeroInfoWindows();
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 void BattleWindow::updateQueue()
@@ -380,28 +380,28 @@ void BattleWindow::setPositionInfoWindow()
 	int xOffsetAttacker = quickSpellWindow->isEnabled ? -53 : 0;
 	if(defenderHeroWindow)
 	{
-		Point position = (GH.screenDimensions().x >= 1000)
+		Point position = (ENGINE->screenDimensions().x >= 1000)
 				? Point(pos.x + pos.w + 15, pos.y + 60)
 				: Point(pos.x + pos.w -79, pos.y + 195);
 		defenderHeroWindow->moveTo(position);
 	}
 	if(attackerHeroWindow)
 	{
-		Point position = (GH.screenDimensions().x >= 1000)
+		Point position = (ENGINE->screenDimensions().x >= 1000)
 				? Point(pos.x - 93 + xOffsetAttacker, pos.y + 60)
 				: Point(pos.x + 1, pos.y + 195);
 		attackerHeroWindow->moveTo(position);
 	}
 	if(defenderStackWindow)
 	{
-		Point position = (GH.screenDimensions().x >= 1000)
+		Point position = (ENGINE->screenDimensions().x >= 1000)
 				? Point(pos.x + pos.w + 15, defenderHeroWindow ? defenderHeroWindow->pos.y + 210 : pos.y + 60)
 				: Point(pos.x + pos.w -79, defenderHeroWindow ? defenderHeroWindow->pos.y : pos.y + 195);
 		defenderStackWindow->moveTo(position);
 	}
 	if(attackerStackWindow)
 	{
-		Point position = (GH.screenDimensions().x >= 1000)
+		Point position = (ENGINE->screenDimensions().x >= 1000)
 				? Point(pos.x - 93 + xOffsetAttacker, attackerHeroWindow ? attackerHeroWindow->pos.y + 210 : pos.y + 60)
 				: Point(pos.x + 1, attackerHeroWindow ? attackerHeroWindow->pos.y : pos.y + 195);
 		attackerStackWindow->moveTo(position);
@@ -457,14 +457,14 @@ void BattleWindow::heroManaPointsChanged(const CGHeroInstance * hero)
 
 void BattleWindow::activate()
 {
-	GH.setStatusbar(console);
+	ENGINE->setStatusbar(console);
 	CIntObject::activate();
 	LOCPLINT->cingconsole->activate();
 }
 
 void BattleWindow::deactivate()
 {
-	GH.setStatusbar(nullptr);
+	ENGINE->setStatusbar(nullptr);
 	CIntObject::deactivate();
 	LOCPLINT->cingconsole->deactivate();
 }
@@ -543,7 +543,7 @@ void BattleWindow::bOptionsf()
 
 	CCS->curh->set(Cursor::Map::POINTER);
 
-	GH.windows().createAndPushWindow<SettingsMainWindow>(&owner);
+	ENGINE->windows().createAndPushWindow<SettingsMainWindow>(&owner);
 }
 
 void BattleWindow::bSurrenderf()
@@ -728,7 +728,7 @@ void BattleWindow::bSpellf()
 
 	if(spellCastProblem == ESpellCastProblem::OK)
 	{
-		GH.windows().createAndPushWindow<CSpellWindow>(myHero, owner.curInt.get());
+		ENGINE->windows().createAndPushWindow<CSpellWindow>(myHero, owner.curInt.get());
 	}
 	else if (spellCastProblem == ESpellCastProblem::MAGIC_IS_BLOCKED)
 	{
@@ -866,7 +866,7 @@ void BattleWindow::bOpenActiveUnit()
 	const auto * unit = owner.stacksController->getActiveStack();
 
 	if (unit)
-		GH.windows().createAndPushWindow<CStackWindow>(unit, false);
+		ENGINE->windows().createAndPushWindow<CStackWindow>(unit, false);
 }
 
 void BattleWindow::bOpenHoveredUnit()
@@ -877,7 +877,7 @@ void BattleWindow::bOpenHoveredUnit()
 	{
 		const auto * unit = owner.getBattle()->battleGetStackByID(units[0]);
 		if (unit)
-			GH.windows().createAndPushWindow<CStackWindow>(unit, false);
+			ENGINE->windows().createAndPushWindow<CStackWindow>(unit, false);
 	}
 }
 
@@ -923,7 +923,7 @@ void BattleWindow::showAll(Canvas & to)
 {
 	CIntObject::showAll(to);
 
-	if (GH.screenDimensions().x != 800 || GH.screenDimensions().y !=600)
+	if (ENGINE->screenDimensions().x != 800 || ENGINE->screenDimensions().y !=600)
 		CMessage::drawBorder(owner.curInt->playerID, to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
 }
 
@@ -935,7 +935,7 @@ void BattleWindow::show(Canvas & to)
 
 void BattleWindow::close()
 {
-	if(!GH.windows().isTopWindow(this))
+	if(!ENGINE->windows().isTopWindow(this))
 		logGlobal->error("Only top interface must be closed");
-	GH.windows().popWindows(1);
+	ENGINE->windows().popWindows(1);
 }

+ 3 - 3
client/battle/CreatureAnimation.cpp

@@ -13,7 +13,7 @@
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CCreatureHandler.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/CAnimation.h"
 #include "../render/Canvas.h"
 #include "../render/ColorFilter.h"
@@ -195,8 +195,8 @@ CreatureAnimation::CreatureAnimation(const AnimationPath & name_, TSpeedControll
 	  once(false)
 {
 
-	forward = GH.renderHandler().loadAnimation(name_, EImageBlitMode::WITH_SHADOW_AND_SELECTION);
-	reverse = GH.renderHandler().loadAnimation(name_, EImageBlitMode::WITH_SHADOW_AND_SELECTION);
+	forward = ENGINE->renderHandler().loadAnimation(name_, EImageBlitMode::WITH_SHADOW_AND_SELECTION);
+	reverse = ENGINE->renderHandler().loadAnimation(name_, EImageBlitMode::WITH_SHADOW_AND_SELECTION);
 
 	if (forward->size(size_t(ECreatureAnimType::DEATH)) == 0)
 		throw std::runtime_error("Animation '" + name_.getOriginalName() + "' has empty death animation!");

+ 15 - 15
client/eventsSDL/InputHandler.cpp

@@ -18,7 +18,7 @@
 #include "InputSourceText.h"
 #include "InputSourceGameController.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/CursorHandler.h"
 #include "../gui/EventDispatcher.h"
 #include "../gui/MouseButton.h"
@@ -134,7 +134,7 @@ void InputHandler::setCurrentInputMode(InputMode modi)
 	if(currentInputMode != modi)
 	{
 		currentInputMode = modi;
-		GH.events().dispatchInputModeChanged(modi);
+		ENGINE->events().dispatchInputModeChanged(modi);
 	}
 }
 
@@ -193,7 +193,7 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
 {
 	if(ev.type == SDL_QUIT)
 	{
-		boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+		boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 #ifdef VCMI_ANDROID
 		handleQuit(false);
 #else
@@ -206,21 +206,21 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
 		if(ev.key.keysym.sym == SDLK_F4 && (ev.key.keysym.mod & KMOD_ALT))
 		{
 			// FIXME: dead code? Looks like intercepted by OS/SDL and delivered as SDL_Quit instead?
-			boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+			boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 			handleQuit(true);
 			return;
 		}
 
 		if(ev.key.keysym.scancode == SDL_SCANCODE_AC_BACK && !settings["input"]["handleBackRightMouseButton"].Bool())
 		{
-			boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+			boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 			handleQuit(true);
 			return;
 		}
 	}
 	else if(ev.type == SDL_USEREVENT)
 	{
-		boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+		boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 		handleUserEvent(ev.user);
 
 		return;
@@ -231,22 +231,22 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
 			case SDL_WINDOWEVENT_RESTORED:
 #ifndef VCMI_IOS
 			{
-				boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
-				GH.onScreenResize(false);
+				boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
+				ENGINE->onScreenResize(false);
 			}
 #endif
 				break;
 			case SDL_WINDOWEVENT_SIZE_CHANGED:
 #ifdef VCMI_ANDROID
 			{
-				boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
-				GH.onScreenResize(true);
+				boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
+				ENGINE->onScreenResize(true);
 			}
 #endif
 				break;
 			case SDL_WINDOWEVENT_FOCUS_GAINED:
 			{
-				boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+				boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 				if(settings["general"]["audioMuteFocus"].Bool()) {
 					CCS->musich->setVolume(settings["general"]["music"].Integer());
 					CCS->soundh->setVolume(settings["general"]["sound"].Integer());
@@ -255,7 +255,7 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
 				break;
 			case SDL_WINDOWEVENT_FOCUS_LOST:
 			{
-				boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+				boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 				if(settings["general"]["audioMuteFocus"].Bool()) {
 					CCS->musich->setVolume(0);
 					CCS->soundh->setVolume(0);
@@ -267,7 +267,7 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
 	}
 	else if(ev.type == SDL_SYSWMEVENT)
 	{
-		boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+		boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 		if(!settings["session"]["headless"].Bool() && settings["general"]["notifications"].Bool())
 		{
 			NotificationHandler::handleSdlEvent(ev);
@@ -292,7 +292,7 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
 	//preprocessing
 	if(ev.type == SDL_MOUSEMOTION)
 	{
-		boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+		boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 		if (CCS && CCS->curh)
 			CCS->curh->cursorMove(ev.motion.x, ev.motion.y);
 	}
@@ -368,7 +368,7 @@ void InputHandler::moveCursorPosition(const Point & distance)
 void InputHandler::setCursorPosition(const Point & position)
 {
 	cursorPosition = position;
-	GH.events().dispatchMouseMoved(Point(0, 0), position);
+	ENGINE->events().dispatchMouseMoved(Point(0, 0), position);
 }
 
 void InputHandler::startTextInput(const Rect & where)

+ 21 - 21
client/eventsSDL/InputSourceGameController.cpp

@@ -14,7 +14,7 @@
 #include "InputHandler.h"
 
 #include "../CGameInfo.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/CursorHandler.h"
 #include "../gui/EventDispatcher.h"
 #include "../gui/ShortcutHandler.h"
@@ -147,7 +147,7 @@ void InputSourceGameController::dispatchAxisShortcuts(const std::vector<EShortcu
 	{
 		if(!pressedAxes.count(axisID))
 		{
-			GH.events().dispatchShortcutPressed(shortcutsVector);
+			ENGINE->events().dispatchShortcutPressed(shortcutsVector);
 			pressedAxes.insert(axisID);
 		}
 	}
@@ -155,7 +155,7 @@ void InputSourceGameController::dispatchAxisShortcuts(const std::vector<EShortcu
 	{
 		if(pressedAxes.count(axisID))
 		{
-			GH.events().dispatchShortcutReleased(shortcutsVector);
+			ENGINE->events().dispatchShortcutReleased(shortcutsVector);
 			pressedAxes.erase(axisID);
 		}
 	}
@@ -168,8 +168,8 @@ void InputSourceGameController::handleEventAxisMotion(const SDL_ControllerAxisEv
 	SDL_GameControllerAxis axisID = static_cast<SDL_GameControllerAxis>(axis.axis);
 	std::string axisName = SDL_GameControllerGetStringForAxis(axisID);
 
-	auto axisActions = GH.shortcuts().translateJoystickAxis(axisName);
-	auto buttonActions = GH.shortcuts().translateJoystickButton(axisName);
+	auto axisActions = ENGINE->shortcuts().translateJoystickAxis(axisName);
+	auto buttonActions = ENGINE->shortcuts().translateJoystickButton(axisName);
 
 	for(const auto & action : axisActions)
 	{
@@ -199,41 +199,41 @@ void InputSourceGameController::tryToConvertCursor()
 	assert(CCS->curh);
 	if(CCS->curh->getShowType() == Cursor::ShowType::HARDWARE)
 	{
-		int scalingFactor = GH.screenHandler().getScalingFactor();
-		const Point & cursorPosition = GH.getCursorPosition();
+		int scalingFactor = ENGINE->screenHandler().getScalingFactor();
+		const Point & cursorPosition = ENGINE->getCursorPosition();
 		CCS->curh->changeCursor(Cursor::ShowType::SOFTWARE);
 		CCS->curh->cursorMove(cursorPosition.x * scalingFactor, cursorPosition.y * scalingFactor);
-		GH.input().setCursorPosition(cursorPosition);
+		ENGINE->input().setCursorPosition(cursorPosition);
 	}
 }
 
 void InputSourceGameController::handleEventButtonDown(const SDL_ControllerButtonEvent & button)
 {
 	std::string buttonName = SDL_GameControllerGetStringForButton(static_cast<SDL_GameControllerButton>(button.button));
-	const auto & shortcutsVector = GH.shortcuts().translateJoystickButton(buttonName);
-	GH.events().dispatchShortcutPressed(shortcutsVector);
+	const auto & shortcutsVector = ENGINE->shortcuts().translateJoystickButton(buttonName);
+	ENGINE->events().dispatchShortcutPressed(shortcutsVector);
 }
 
 void InputSourceGameController::handleEventButtonUp(const SDL_ControllerButtonEvent & button)
 {
 	std::string buttonName = SDL_GameControllerGetStringForButton(static_cast<SDL_GameControllerButton>(button.button));
-	const auto & shortcutsVector = GH.shortcuts().translateJoystickButton(buttonName);
-	GH.events().dispatchShortcutReleased(shortcutsVector);
+	const auto & shortcutsVector = ENGINE->shortcuts().translateJoystickButton(buttonName);
+	ENGINE->events().dispatchShortcutReleased(shortcutsVector);
 }
 
 void InputSourceGameController::doCursorMove(int deltaX, int deltaY)
 {
 	if(deltaX == 0 && deltaY == 0)
 		return;
-	const Point & screenSize = GH.screenDimensions();
-	const Point & cursorPosition = GH.getCursorPosition();
-	int scalingFactor = GH.screenHandler().getScalingFactor();
+	const Point & screenSize = ENGINE->screenDimensions();
+	const Point & cursorPosition = ENGINE->getCursorPosition();
+	int scalingFactor = ENGINE->screenHandler().getScalingFactor();
 	int newX = std::min(std::max(cursorPosition.x + deltaX, 0), screenSize.x);
 	int newY = std::min(std::max(cursorPosition.y + deltaY, 0), screenSize.y);
 	Point targetPosition{newX, newY};
-	GH.input().setCursorPosition(targetPosition);
+	ENGINE->input().setCursorPosition(targetPosition);
 	if(CCS && CCS->curh)
-		CCS->curh->cursorMove(GH.getCursorPosition().x * scalingFactor, GH.getCursorPosition().y * scalingFactor);
+		CCS->curh->cursorMove(ENGINE->getCursorPosition().x * scalingFactor, ENGINE->getCursorPosition().y * scalingFactor);
 }
 
 int InputSourceGameController::getMoveDis(float planDis)
@@ -298,12 +298,12 @@ void InputSourceGameController::handleScrollUpdate(int32_t deltaTimeMs)
 	else if(!scrollAxisMoved && !isScrollAxisReleased())
 	{
 		scrollAxisMoved = true;
-		scrollCurrent = scrollStart = GH.input().getCursorPosition();
-		GH.events().dispatchGesturePanningStarted(scrollStart);
+		scrollCurrent = scrollStart = ENGINE->input().getCursorPosition();
+		ENGINE->events().dispatchGesturePanningStarted(scrollStart);
 	}
 	else if(scrollAxisMoved && isScrollAxisReleased())
 	{
-		GH.events().dispatchGesturePanningEnded(scrollStart, scrollCurrent);
+		ENGINE->events().dispatchGesturePanningEnded(scrollStart, scrollCurrent);
 		scrollAxisMoved = false;
 		scrollPlanDisX = scrollPlanDisY = 0;
 		return;
@@ -320,7 +320,7 @@ void InputSourceGameController::handleScrollUpdate(int32_t deltaTimeMs)
 		scrollCurrent.x += moveDisX;
 		scrollCurrent.y += moveDisY;
 		Point distance(moveDisX, moveDisY);
-		GH.events().dispatchGesturePanning(scrollStart, scrollCurrent, distance);
+		ENGINE->events().dispatchGesturePanning(scrollStart, scrollCurrent, distance);
 	}
 }
 

+ 9 - 9
client/eventsSDL/InputSourceKeyboard.cpp

@@ -13,7 +13,7 @@
 
 #include "../../lib/CConfigHandler.h"
 #include "../CPlayerInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/EventDispatcher.h"
 #include "../gui/Shortcut.h"
 #include "../gui/ShortcutHandler.h"
@@ -70,7 +70,7 @@ void InputSourceKeyboard::handleEventKeyDown(const SDL_KeyboardEvent & key)
 			std::string clipboardContent = clipboardBuffer;
 			boost::erase_all(clipboardContent, "\r");
 			boost::erase_all(clipboardContent, "\n");
-			GH.events().dispatchTextInput(clipboardContent);
+			ENGINE->events().dispatchTextInput(clipboardContent);
 			SDL_free(clipboardBuffer);
 			return;
 	 	}
@@ -84,11 +84,11 @@ void InputSourceKeyboard::handleEventKeyDown(const SDL_KeyboardEvent & key)
 
 	if(handleBackRightMouseButton && key.keysym.scancode ==  SDL_SCANCODE_AC_BACK) // on some android devices right mouse button is "back"
 	{
-		GH.events().dispatchShowPopup(GH.getCursorPosition(), settings["input"]["mouseToleranceDistance"].Integer());
+		ENGINE->events().dispatchShowPopup(ENGINE->getCursorPosition(), settings["input"]["mouseToleranceDistance"].Integer());
 		return;
 	}
 
-	auto shortcutsVector = GH.shortcuts().translateKeycode(keyName);
+	auto shortcutsVector = ENGINE->shortcuts().translateKeycode(keyName);
 
 	if (vstd::contains(shortcutsVector, EShortcut::MAIN_MENU_LOBBY))
 		CSH->getGlobalLobby().activateInterface();
@@ -97,7 +97,7 @@ void InputSourceKeyboard::handleEventKeyDown(const SDL_KeyboardEvent & key)
 	{
 		Settings full = settings.write["video"]["fullscreen"];
 		full->Bool() = !full->Bool();
-		GH.onScreenResize(true);
+		ENGINE->onScreenResize(true);
 	}
 
 	if (vstd::contains(shortcutsVector, EShortcut::SPECTATE_TRACK_HERO))
@@ -118,7 +118,7 @@ void InputSourceKeyboard::handleEventKeyDown(const SDL_KeyboardEvent & key)
 		s["spectate-skip-battle-result"].Bool() = !settings["session"]["spectate-skip-battle-result"].Bool();
 	}
 
-	GH.events().dispatchShortcutPressed(shortcutsVector);
+	ENGINE->events().dispatchShortcutPressed(shortcutsVector);
 }
 
 void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
@@ -128,7 +128,7 @@ void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
 
 	if(handleBackRightMouseButton && key.keysym.scancode ==  SDL_SCANCODE_AC_BACK) // on some android devices right mouse button is "back"
 	{
-		GH.events().dispatchClosePopup(GH.getCursorPosition());
+		ENGINE->events().dispatchClosePopup(ENGINE->getCursorPosition());
 		return;
 	}
 
@@ -143,9 +143,9 @@ void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
 
 	assert(key.state == SDL_RELEASED);
 
-	auto shortcutsVector = GH.shortcuts().translateKeycode(keyName);
+	auto shortcutsVector = ENGINE->shortcuts().translateKeycode(keyName);
 
-	GH.events().dispatchShortcutReleased(shortcutsVector);
+	ENGINE->events().dispatchShortcutReleased(shortcutsVector);
 }
 
 bool InputSourceKeyboard::isKeyboardCmdDown() const

+ 18 - 18
client/eventsSDL/InputSourceMouse.cpp

@@ -12,7 +12,7 @@
 #include "InputSourceMouse.h"
 #include "InputHandler.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/EventDispatcher.h"
 #include "../gui/MouseButton.h"
 
@@ -33,39 +33,39 @@ InputSourceMouse::InputSourceMouse()
 
 void InputSourceMouse::handleEventMouseMotion(const SDL_MouseMotionEvent & motion)
 {
-	Point newPosition = Point(motion.x, motion.y) / GH.screenHandler().getScalingFactor();
-	Point distance = Point(-motion.xrel, -motion.yrel) / GH.screenHandler().getScalingFactor();
+	Point newPosition = Point(motion.x, motion.y) / ENGINE->screenHandler().getScalingFactor();
+	Point distance = Point(-motion.xrel, -motion.yrel) / ENGINE->screenHandler().getScalingFactor();
 
 	mouseButtonsMask = motion.state;
 
 	if (mouseButtonsMask & SDL_BUTTON(SDL_BUTTON_MIDDLE))
-		GH.events().dispatchGesturePanning(middleClickPosition, newPosition, distance);
+		ENGINE->events().dispatchGesturePanning(middleClickPosition, newPosition, distance);
 	else if (mouseButtonsMask & SDL_BUTTON(SDL_BUTTON_LEFT))
-		GH.events().dispatchMouseDragged(newPosition, distance);
+		ENGINE->events().dispatchMouseDragged(newPosition, distance);
 	else if (mouseButtonsMask & SDL_BUTTON(SDL_BUTTON_RIGHT))
-		GH.events().dispatchMouseDraggedPopup(newPosition, distance);
+		ENGINE->events().dispatchMouseDraggedPopup(newPosition, distance);
 	else
-		GH.input().setCursorPosition(newPosition);
+		ENGINE->input().setCursorPosition(newPosition);
 }
 
 void InputSourceMouse::handleEventMouseButtonDown(const SDL_MouseButtonEvent & button)
 {
-	Point position = Point(button.x, button.y) / GH.screenHandler().getScalingFactor();
+	Point position = Point(button.x, button.y) / ENGINE->screenHandler().getScalingFactor();
 
 	switch(button.button)
 	{
 		case SDL_BUTTON_LEFT:
 			if(button.clicks > 1)
-				GH.events().dispatchMouseDoubleClick(position, mouseToleranceDistance);
+				ENGINE->events().dispatchMouseDoubleClick(position, mouseToleranceDistance);
 			else
-				GH.events().dispatchMouseLeftButtonPressed(position, mouseToleranceDistance);
+				ENGINE->events().dispatchMouseLeftButtonPressed(position, mouseToleranceDistance);
 			break;
 		case SDL_BUTTON_RIGHT:
-			GH.events().dispatchShowPopup(position, mouseToleranceDistance);
+			ENGINE->events().dispatchShowPopup(position, mouseToleranceDistance);
 			break;
 		case SDL_BUTTON_MIDDLE:
 			middleClickPosition = position;
-			GH.events().dispatchGesturePanningStarted(position);
+			ENGINE->events().dispatchGesturePanningStarted(position);
 			break;
 	}
 }
@@ -75,26 +75,26 @@ void InputSourceMouse::handleEventMouseWheel(const SDL_MouseWheelEvent & wheel)
 	//NOTE: while mouseX / mouseY properties are available since 2.26.0, they are not converted into logical coordinates so don't account for resolution scaling
 	// This SDL bug was fixed in 2.30.1: https://github.com/libsdl-org/SDL/issues/9097
 #if SDL_VERSION_ATLEAST(2,30,1)
-	GH.events().dispatchMouseScrolled(Point(wheel.x, wheel.y), Point(wheel.mouseX, wheel.mouseY) / GH.screenHandler().getScalingFactor());
+	ENGINE->events().dispatchMouseScrolled(Point(wheel.x, wheel.y), Point(wheel.mouseX, wheel.mouseY) / ENGINE->screenHandler().getScalingFactor());
 #else
-	GH.events().dispatchMouseScrolled(Point(wheel.x, wheel.y), GH.getCursorPosition());
+	ENGINE->events().dispatchMouseScrolled(Point(wheel.x, wheel.y), ENGINE->getCursorPosition());
 #endif
 }
 
 void InputSourceMouse::handleEventMouseButtonUp(const SDL_MouseButtonEvent & button)
 {
-	Point position = Point(button.x, button.y) / GH.screenHandler().getScalingFactor();
+	Point position = Point(button.x, button.y) / ENGINE->screenHandler().getScalingFactor();
 
 	switch(button.button)
 	{
 		case SDL_BUTTON_LEFT:
-			GH.events().dispatchMouseLeftButtonReleased(position, mouseToleranceDistance);
+			ENGINE->events().dispatchMouseLeftButtonReleased(position, mouseToleranceDistance);
 			break;
 		case SDL_BUTTON_RIGHT:
-			GH.events().dispatchClosePopup(position);
+			ENGINE->events().dispatchClosePopup(position);
 			break;
 		case SDL_BUTTON_MIDDLE:
-			GH.events().dispatchGesturePanningEnded(middleClickPosition, position);
+			ENGINE->events().dispatchGesturePanningEnded(middleClickPosition, position);
 			break;
 	}
 }

+ 6 - 6
client/eventsSDL/InputSourceText.cpp

@@ -11,7 +11,7 @@
 #include "StdInc.h"
 #include "InputSourceText.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/EventDispatcher.h"
 #include "../render/IScreenHandler.h"
 #include "../renderSDL/SDL_Extensions.h"
@@ -29,19 +29,19 @@ InputSourceText::InputSourceText()
 
 void InputSourceText::handleEventTextInput(const SDL_TextInputEvent & text)
 {
-	GH.events().dispatchTextInput(text.text);
+	ENGINE->events().dispatchTextInput(text.text);
 }
 
 void InputSourceText::handleEventTextEditing(const SDL_TextEditingEvent & text)
 {
-	GH.events().dispatchTextEditing(text.text);
+	ENGINE->events().dispatchTextEditing(text.text);
 }
 
 void InputSourceText::startTextInput(const Rect & whereInput)
 {
-	GH.dispatchMainThread([whereInput]()
+	ENGINE->dispatchMainThread([whereInput]()
 	{
-		Rect rectInScreenCoordinates = GH.screenHandler().convertLogicalPointsToWindow(whereInput);
+		Rect rectInScreenCoordinates = ENGINE->screenHandler().convertLogicalPointsToWindow(whereInput);
 		SDL_Rect textInputRect = CSDL_Ext::toSDL(rectInScreenCoordinates);
 
 		SDL_SetTextInputRect(&textInputRect);
@@ -55,7 +55,7 @@ void InputSourceText::startTextInput(const Rect & whereInput)
 
 void InputSourceText::stopTextInput()
 {
-	GH.dispatchMainThread([]()
+	ENGINE->dispatchMainThread([]()
 	{
 		if (SDL_IsTextInputActive() == SDL_TRUE)
 		{

+ 35 - 35
client/eventsSDL/InputSourceTouch.cpp

@@ -16,7 +16,7 @@
 #include "../../lib/CConfigHandler.h"
 #include "../CGameInfo.h"
 #include "../gui/CursorHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/EventDispatcher.h"
 #include "../gui/MouseButton.h"
 #include "../gui/WindowHandler.h"
@@ -59,23 +59,23 @@ InputSourceTouch::InputSourceTouch()
 void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfinger)
 {
 	if (CCS && CCS->curh && settings["video"]["cursor"].String() == "software" && state != TouchState::RELATIVE_MODE)
-		CCS->curh->cursorMove(GH.getCursorPosition().x, GH.getCursorPosition().y);
+		CCS->curh->cursorMove(ENGINE->getCursorPosition().x, ENGINE->getCursorPosition().y);
 
 	switch(state)
 	{
 		case TouchState::RELATIVE_MODE:
 		{
-			Point screenSize = GH.screenDimensions();
-			int scalingFactor = GH.screenHandler().getScalingFactor();
+			Point screenSize = ENGINE->screenDimensions();
+			int scalingFactor = ENGINE->screenHandler().getScalingFactor();
 
 			Point moveDistance {
 				static_cast<int>(screenSize.x * params.relativeModeSpeedFactor * tfinger.dx),
 				static_cast<int>(screenSize.y * params.relativeModeSpeedFactor * tfinger.dy)
 			};
 
-			GH.input().moveCursorPosition(moveDistance);
+			ENGINE->input().moveCursorPosition(moveDistance);
 			if (CCS && CCS->curh)
-				CCS->curh->cursorMove(GH.getCursorPosition().x * scalingFactor, GH.getCursorPosition().y * scalingFactor);
+				CCS->curh->cursorMove(ENGINE->getCursorPosition().x * scalingFactor, ENGINE->getCursorPosition().y * scalingFactor);
 
 			break;
 		}
@@ -91,7 +91,7 @@ void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfin
 			if ( std::abs(distance.x) > params.panningSensitivityThreshold || std::abs(distance.y) > params.panningSensitivityThreshold)
 			{
 				state = state == TouchState::TAP_DOWN_SHORT ? TouchState::TAP_DOWN_PANNING : TouchState::TAP_DOWN_PANNING_POPUP;
-				GH.events().dispatchGesturePanningStarted(lastTapPosition);
+				ENGINE->events().dispatchGesturePanningStarted(lastTapPosition);
 			}
 			break;
 		}
@@ -131,29 +131,29 @@ void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinge
 			if(tfinger.x > 0.5)
 			{
 				if (tfinger.y < 0.5)
-					GH.events().dispatchShowPopup(GH.getCursorPosition(), params.touchToleranceDistance);
+					ENGINE->events().dispatchShowPopup(ENGINE->getCursorPosition(), params.touchToleranceDistance);
 				else
-					GH.events().dispatchMouseLeftButtonPressed(GH.getCursorPosition(), params.touchToleranceDistance);
+					ENGINE->events().dispatchMouseLeftButtonPressed(ENGINE->getCursorPosition(), params.touchToleranceDistance);
 			}
 			break;
 		}
 		case TouchState::IDLE:
 		{
 			lastTapPosition = convertTouchToMouse(tfinger);
-			GH.input().setCursorPosition(lastTapPosition);
+			ENGINE->input().setCursorPosition(lastTapPosition);
 			state = TouchState::TAP_DOWN_SHORT;
 			break;
 		}
 		case TouchState::TAP_DOWN_SHORT:
 		{
-			GH.input().setCursorPosition(convertTouchToMouse(tfinger));
-			GH.events().dispatchGesturePanningStarted(lastTapPosition);
+			ENGINE->input().setCursorPosition(convertTouchToMouse(tfinger));
+			ENGINE->events().dispatchGesturePanningStarted(lastTapPosition);
 			state = TouchState::TAP_DOWN_DOUBLE;
 			break;
 		}
 		case TouchState::TAP_DOWN_PANNING:
 		{
-			GH.input().setCursorPosition(convertTouchToMouse(tfinger));
+			ENGINE->input().setCursorPosition(convertTouchToMouse(tfinger));
 			state = TouchState::TAP_DOWN_DOUBLE;
 			break;
 		}
@@ -185,9 +185,9 @@ void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger)
 			if(tfinger.x > 0.5)
 			{
 				if (tfinger.y < 0.5)
-					GH.events().dispatchClosePopup(GH.getCursorPosition());
+					ENGINE->events().dispatchClosePopup(ENGINE->getCursorPosition());
 				else
-					GH.events().dispatchMouseLeftButtonReleased(GH.getCursorPosition(), params.touchToleranceDistance);
+					ENGINE->events().dispatchMouseLeftButtonReleased(ENGINE->getCursorPosition(), params.touchToleranceDistance);
 			}
 			break;
 		}
@@ -198,16 +198,16 @@ void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger)
 		}
 		case TouchState::TAP_DOWN_SHORT:
 		{
-			GH.input().setCursorPosition(convertTouchToMouse(tfinger));
+			ENGINE->input().setCursorPosition(convertTouchToMouse(tfinger));
 			if(tfinger.timestamp - lastLeftClickTimeTicks < params.doubleTouchTimeMilliseconds && (convertTouchToMouse(tfinger) - lastLeftClickPosition).length() < params.doubleTouchToleranceDistance)
 			{
-				GH.events().dispatchMouseDoubleClick(convertTouchToMouse(tfinger), params.touchToleranceDistance);
-				GH.events().dispatchMouseLeftButtonReleased(convertTouchToMouse(tfinger), params.touchToleranceDistance);
+				ENGINE->events().dispatchMouseDoubleClick(convertTouchToMouse(tfinger), params.touchToleranceDistance);
+				ENGINE->events().dispatchMouseLeftButtonReleased(convertTouchToMouse(tfinger), params.touchToleranceDistance);
 			}
 			else
 			{
-				GH.events().dispatchMouseLeftButtonPressed(convertTouchToMouse(tfinger), params.touchToleranceDistance);
-				GH.events().dispatchMouseLeftButtonReleased(convertTouchToMouse(tfinger), params.touchToleranceDistance);
+				ENGINE->events().dispatchMouseLeftButtonPressed(convertTouchToMouse(tfinger), params.touchToleranceDistance);
+				ENGINE->events().dispatchMouseLeftButtonReleased(convertTouchToMouse(tfinger), params.touchToleranceDistance);
 				lastLeftClickTimeTicks = tfinger.timestamp;
 				lastLeftClickPosition = convertTouchToMouse(tfinger);
 			}
@@ -217,7 +217,7 @@ void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger)
 		case TouchState::TAP_DOWN_PANNING:
 		case TouchState::TAP_DOWN_PANNING_POPUP:
 		{
-			GH.events().dispatchGesturePanningEnded(lastTapPosition, convertTouchToMouse(tfinger));
+			ENGINE->events().dispatchGesturePanningEnded(lastTapPosition, convertTouchToMouse(tfinger));
 			state = state == TouchState::TAP_DOWN_PANNING ? TouchState::IDLE : TouchState::TAP_DOWN_LONG_AWAIT;
 			break;
 		}
@@ -227,7 +227,7 @@ void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger)
 				state = TouchState::TAP_DOWN_PANNING;
 			if (SDL_GetNumTouchFingers(tfinger.touchId) == 0)
 			{
-				GH.events().dispatchGesturePanningEnded(lastTapPosition, convertTouchToMouse(tfinger));
+				ENGINE->events().dispatchGesturePanningEnded(lastTapPosition, convertTouchToMouse(tfinger));
 				state = TouchState::IDLE;
 			}
 			break;
@@ -244,8 +244,8 @@ void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger)
 		{
 			if (SDL_GetNumTouchFingers(tfinger.touchId) == 0)
 			{
-				GH.input().setCursorPosition(convertTouchToMouse(tfinger));
-				GH.events().dispatchClosePopup(convertTouchToMouse(tfinger));
+				ENGINE->input().setCursorPosition(convertTouchToMouse(tfinger));
+				ENGINE->events().dispatchClosePopup(convertTouchToMouse(tfinger));
 				state = TouchState::IDLE;
 			}
 			break;
@@ -260,9 +260,9 @@ void InputSourceTouch::handleUpdate()
 		uint32_t currentTime = SDL_GetTicks();
 		if (currentTime > lastTapTimeTicks + params.longTouchTimeMilliseconds)
 		{
-			GH.events().dispatchShowPopup(GH.getCursorPosition(), params.touchToleranceDistance);
+			ENGINE->events().dispatchShowPopup(ENGINE->getCursorPosition(), params.touchToleranceDistance);
 
-			if (GH.windows().isTopWindowPopup())
+			if (ENGINE->windows().isTopWindowPopup())
 			{
 				hapticFeedback();
 				state = TouchState::TAP_DOWN_LONG;
@@ -278,7 +278,7 @@ Point InputSourceTouch::convertTouchToMouse(const SDL_TouchFingerEvent & tfinger
 
 Point InputSourceTouch::convertTouchToMouse(float x, float y)
 {
-	return Point(x * GH.screenDimensions().x, y * GH.screenDimensions().y);
+	return Point(x * ENGINE->screenDimensions().x, y * ENGINE->screenDimensions().y);
 }
 
 bool InputSourceTouch::hasTouchInputDevice() const
@@ -295,7 +295,7 @@ void InputSourceTouch::emitPanningEvent(const SDL_TouchFingerEvent & tfinger)
 {
 	Point distance = convertTouchToMouse(-tfinger.dx, -tfinger.dy);
 
-	GH.events().dispatchGesturePanning(lastTapPosition, convertTouchToMouse(tfinger), distance);
+	ENGINE->events().dispatchGesturePanning(lastTapPosition, convertTouchToMouse(tfinger), distance);
 }
 
 void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger)
@@ -315,8 +315,8 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger)
 
 		if (finger && finger->id != tfinger.fingerId)
 		{
-			otherX = finger->x * GH.screenDimensions().x;
-			otherY = finger->y * GH.screenDimensions().y;
+			otherX = finger->x * ENGINE->screenDimensions().x;
+			otherY = finger->y * ENGINE->screenDimensions().y;
 			otherFingerFound = true;
 			break;
 		}
@@ -325,10 +325,10 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger)
 	if (!otherFingerFound)
 		return; // should be impossible, but better to avoid weird edge cases
 
-	float thisX = tfinger.x * GH.screenDimensions().x;
-	float thisY = tfinger.y * GH.screenDimensions().y;
-	float deltaX = tfinger.dx * GH.screenDimensions().x;
-	float deltaY = tfinger.dy * GH.screenDimensions().y;
+	float thisX = tfinger.x * ENGINE->screenDimensions().x;
+	float thisY = tfinger.y * ENGINE->screenDimensions().y;
+	float deltaX = tfinger.dx * ENGINE->screenDimensions().x;
+	float deltaY = tfinger.dy * ENGINE->screenDimensions().y;
 
 	float oldX = thisX - deltaX - otherX;
 	float oldY = thisY - deltaY - otherY;
@@ -339,7 +339,7 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger)
 	double distanceNew = std::sqrt(newX * newX + newY * newY);
 
 	if (distanceOld > params.pinchSensitivityThreshold)
-		GH.events().dispatchGesturePinch(lastTapPosition, distanceNew / distanceOld);
+		ENGINE->events().dispatchGesturePinch(lastTapPosition, distanceNew / distanceOld);
 }
 
 void InputSourceTouch::hapticFeedback() {

+ 2 - 2
client/globalLobby/GlobalLobbyAddChannelWindow.cpp

@@ -14,7 +14,7 @@
 #include "GlobalLobbyClient.h"
 
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../widgets/Buttons.h"
@@ -46,7 +46,7 @@ GlobalLobbyAddChannelWindowCard::GlobalLobbyAddChannelWindowCard(const std::stri
 void GlobalLobbyAddChannelWindowCard::clickPressed(const Point & cursorPosition)
 {
 	CSH->getGlobalLobby().addChannel(languageID);
-	GH.windows().popWindows(1);
+	ENGINE->windows().popWindows(1);
 }
 
 GlobalLobbyAddChannelWindow::GlobalLobbyAddChannelWindow()

+ 21 - 21
client/globalLobby/GlobalLobbyClient.cpp

@@ -18,7 +18,7 @@
 
 #include "../CGameInfo.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../mainmenu/CMainMenu.h"
 #include "../media/ISoundPlayer.h"
@@ -86,7 +86,7 @@ GlobalLobbyClient::~GlobalLobbyClient() = default;
 
 void GlobalLobbyClient::onPacketReceived(const std::shared_ptr<INetworkConnection> &, const std::vector<std::byte> & message)
 {
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	JsonNode json(message.data(), message.size(), "<lobby network packet>");
 
@@ -127,7 +127,7 @@ void GlobalLobbyClient::receiveAccountCreated(const JsonNode & json)
 {
 	auto loginWindowPtr = loginWindow.lock();
 
-	if(!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
+	if(!loginWindowPtr || !ENGINE->windows().topWindow<GlobalLobbyLoginWindow>())
 		throw std::runtime_error("lobby connection finished without active login window!");
 
 	{
@@ -158,7 +158,7 @@ void GlobalLobbyClient::receiveClientLoginSuccess(const JsonNode & json)
 
 	auto loginWindowPtr = loginWindow.lock();
 
-	if(!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
+	if(!loginWindowPtr || !ENGINE->windows().topWindow<GlobalLobbyLoginWindow>())
 		throw std::runtime_error("lobby connection finished without active login window!");
 
 	loginWindowPtr->onLoginSuccess();
@@ -240,7 +240,7 @@ void GlobalLobbyClient::receiveActiveAccounts(const JsonNode & json)
 	if(lobbyWindowPtr)
 		lobbyWindowPtr->onActiveAccounts(activeAccounts);
 
-	for (auto const & window : GH.windows().findWindows<GlobalLobbyObserver>())
+	for (auto const & window : ENGINE->windows().findWindows<GlobalLobbyObserver>())
 		window->onActiveAccounts(activeAccounts);
 }
 
@@ -287,7 +287,7 @@ void GlobalLobbyClient::receiveActiveGameRooms(const JsonNode & json)
 	if(lobbyWindowPtr)
 		lobbyWindowPtr->onActiveGameRooms(activeRooms);
 
-	for (auto const & window : GH.windows().findWindows<GlobalLobbyObserver>())
+	for (auto const & window : ENGINE->windows().findWindows<GlobalLobbyObserver>())
 		window->onActiveGameRooms(activeRooms);
 }
 
@@ -363,12 +363,12 @@ void GlobalLobbyClient::receiveJoinRoomSuccess(const JsonNode & json)
 
 void GlobalLobbyClient::onConnectionEstablished(const std::shared_ptr<INetworkConnection> & connection)
 {
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 	networkConnection = connection;
 
 	auto loginWindowPtr = loginWindow.lock();
 
-	if(!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
+	if(!loginWindowPtr || !ENGINE->windows().topWindow<GlobalLobbyLoginWindow>())
 		throw std::runtime_error("lobby connection established without active login window!");
 
 	loginWindowPtr->onConnectionSuccess();
@@ -401,11 +401,11 @@ void GlobalLobbyClient::sendClientLogin()
 
 void GlobalLobbyClient::onConnectionFailed(const std::string & errorMessage)
 {
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	auto loginWindowPtr = loginWindow.lock();
 
-	if(!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
+	if(!loginWindowPtr || !ENGINE->windows().topWindow<GlobalLobbyLoginWindow>())
 		throw std::runtime_error("lobby connection failed without active login window!");
 
 	logGlobal->warn("Connection to game lobby failed! Reason: %s", errorMessage);
@@ -414,16 +414,16 @@ void GlobalLobbyClient::onConnectionFailed(const std::string & errorMessage)
 
 void GlobalLobbyClient::onDisconnected(const std::shared_ptr<INetworkConnection> & connection, const std::string & errorMessage)
 {
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+	boost::mutex::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 
 	assert(connection == networkConnection);
 	networkConnection.reset();
 	accountLoggedIn = false;
 
-	while (!GH.windows().findWindows<GlobalLobbyWindow>().empty())
+	while (!ENGINE->windows().findWindows<GlobalLobbyWindow>().empty())
 	{
 		// if global lobby is open, pop all dialogs on top of it as well as lobby itself
-		GH.windows().popWindows(1);
+		ENGINE->windows().popWindows(1);
 	}
 
 	CInfoWindow::showInfoDialog("Connection to game lobby was lost!", {});
@@ -541,29 +541,29 @@ const std::vector<GlobalLobbyChannelMessage> & GlobalLobbyClient::getChannelHist
 
 void GlobalLobbyClient::activateInterface()
 {
-	if (GH.windows().topWindow<GlobalLobbyWindow>() != nullptr)
+	if (ENGINE->windows().topWindow<GlobalLobbyWindow>() != nullptr)
 	{
-		GH.windows().popWindows(1);
+		ENGINE->windows().popWindows(1);
 		return;
 	}
 
-	if (!GH.windows().findWindows<GlobalLobbyWindow>().empty())
+	if (!ENGINE->windows().findWindows<GlobalLobbyWindow>().empty())
 		return;
 
-	if (!GH.windows().findWindows<GlobalLobbyLoginWindow>().empty())
+	if (!ENGINE->windows().findWindows<GlobalLobbyLoginWindow>().empty())
 		return;
 
 	if (isLoggedIn())
-		GH.windows().pushWindow(createLobbyWindow());
+		ENGINE->windows().pushWindow(createLobbyWindow());
 	else
-		GH.windows().pushWindow(createLoginWindow());
+		ENGINE->windows().pushWindow(createLoginWindow());
 
-	GH.windows().topWindow<CIntObject>()->center();
+	ENGINE->windows().topWindow<CIntObject>()->center();
 }
 
 void GlobalLobbyClient::activateRoomInviteInterface()
 {
-	GH.windows().createAndPushWindow<GlobalLobbyInviteWindow>();
+	ENGINE->windows().createAndPushWindow<GlobalLobbyInviteWindow>();
 }
 
 void GlobalLobbyClient::setAccountID(const std::string & accountID)

+ 1 - 1
client/globalLobby/GlobalLobbyInviteWindow.cpp

@@ -14,7 +14,7 @@
 #include "GlobalLobbyClient.h"
 
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../widgets/Buttons.h"
 #include "../widgets/GraphicalPrimitiveCanvas.h"

+ 1 - 1
client/globalLobby/GlobalLobbyLoginWindow.cpp

@@ -15,7 +15,7 @@
 
 #include "../CGameInfo.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../widgets/Buttons.h"
 #include "../widgets/CTextInput.h"

+ 1 - 1
client/globalLobby/GlobalLobbyRoomWindow.cpp

@@ -17,7 +17,7 @@
 
 #include "../CGameInfo.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../mainmenu/CMainMenu.h"
 #include "../widgets/Buttons.h"

+ 1 - 1
client/globalLobby/GlobalLobbyServerSetup.cpp

@@ -15,7 +15,7 @@
 
 #include "../CGameInfo.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../mainmenu/CMainMenu.h"
 #include "../widgets/Buttons.h"

+ 4 - 4
client/globalLobby/GlobalLobbyWidget.cpp

@@ -18,7 +18,7 @@
 
 #include "../CGameInfo.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../media/ISoundPlayer.h"
 #include "../render/Colors.h"
@@ -38,7 +38,7 @@
 GlobalLobbyWidget::GlobalLobbyWidget(GlobalLobbyWindow * window)
 	: window(window)
 {
-	addCallback("closeWindow", [](int) { GH.windows().popWindows(1); });
+	addCallback("closeWindow", [](int) { ENGINE->windows().popWindows(1); });
 	addCallback("sendMessage", [this](int) { this->window->doSendChatMessage(); });
 	addCallback("createGameRoom", [this](int) { if (!CSH->inGame()) this->window->doCreateGameRoom(); });//TODO: button should be blocked instead
 
@@ -78,7 +78,7 @@ GlobalLobbyWidget::CreateFunc GlobalLobbyWidget::getItemListConstructorFunc(cons
 		if(index == channels.size())
 		{
 			const auto buttonCallback = [](){
-				GH.windows().createAndPushWindow<GlobalLobbyAddChannelWindow>();
+				ENGINE->windows().createAndPushWindow<GlobalLobbyAddChannelWindow>();
 			};
 
 			auto result = std::make_shared<CButton>(Point(0,0), AnimationPath::builtin("lobbyAddChannel"), CButton::tooltip(), buttonCallback);
@@ -270,7 +270,7 @@ GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const Globa
 
 void GlobalLobbyRoomCard::clickPressed(const Point & cursorPosition)
 {
-	GH.windows().createAndPushWindow<GlobalLobbyRoomWindow>(window, roomUUID);
+	ENGINE->windows().createAndPushWindow<GlobalLobbyRoomWindow>(window, roomUUID);
 }
 
 GlobalLobbyChannelCard::GlobalLobbyChannelCard(GlobalLobbyWindow * window, const std::string & channelName)

+ 2 - 2
client/globalLobby/GlobalLobbyWindow.cpp

@@ -16,7 +16,7 @@
 #include "GlobalLobbyWidget.h"
 
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../widgets/CTextInput.h"
 #include "../widgets/Slider.h"
@@ -94,7 +94,7 @@ void GlobalLobbyWindow::doSendChatMessage()
 
 void GlobalLobbyWindow::doCreateGameRoom()
 {
-	GH.windows().createAndPushWindow<GlobalLobbyServerSetup>();
+	ENGINE->windows().createAndPushWindow<GlobalLobbyServerSetup>();
 }
 
 void GlobalLobbyWindow::doInviteAccount(const std::string & accountID)

+ 11 - 11
client/gui/CIntObject.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CIntObject.h"
 
-#include "CGuiHandler.h"
+#include "GameEngine.h"
 #include "WindowHandler.h"
 #include "EventDispatcher.h"
 #include "Shortcut.h"
@@ -27,8 +27,8 @@ CIntObject::CIntObject(int used_, Point pos_):
 	recActions(ALL_ACTIONS),
 	pos(pos_, Point())
 {
-	if(GH.captureChildren)
-		GH.createdObj.front()->addChild(this, true);
+	if(ENGINE->captureChildren)
+		ENGINE->createdObj.front()->addChild(this, true);
 }
 
 CIntObject::~CIntObject()
@@ -157,7 +157,7 @@ void CIntObject::setRedrawParent(bool on)
 
 void CIntObject::fitToScreen(int borderWidth, bool propagate)
 {
-	fitToRect(Rect(Point(0, 0), GH.screenDimensions()), borderWidth, propagate);
+	fitToRect(Rect(Point(0, 0), ENGINE->screenDimensions()), borderWidth, propagate);
 }
 
 void CIntObject::fitToRect(Rect rect, int borderWidth, bool propagate)
@@ -238,7 +238,7 @@ void CIntObject::redraw()
 		}
 		else
 		{
-			Canvas buffer = GH.screenHandler().getScreenCanvas();
+			Canvas buffer = ENGINE->screenHandler().getScreenCanvas();
 			showAll(buffer);
 		}
 	}
@@ -277,7 +277,7 @@ const Rect & CIntObject::center( const Rect &r, bool propagate )
 {
 	pos.w = r.w;
 	pos.h = r.h;
-	return center(Point(GH.screenDimensions().x/2, GH.screenDimensions().y/2), propagate);
+	return center(Point(ENGINE->screenDimensions().x/2, ENGINE->screenDimensions().y/2), propagate);
 }
 
 const Rect & CIntObject::center( bool propagate )
@@ -314,7 +314,7 @@ void CKeyShortcut::keyPressed(EShortcut key)
 	if( assignedKey == key && assignedKey != EShortcut::NONE && !shortcutPressed)
 	{
 		shortcutPressed = true;
-		clickPressed(GH.getCursorPosition());
+		clickPressed(ENGINE->getCursorPosition());
 	}
 }
 
@@ -323,7 +323,7 @@ void CKeyShortcut::keyReleased(EShortcut key)
 	if( assignedKey == key && assignedKey != EShortcut::NONE && shortcutPressed)
 	{
 		shortcutPressed = false;
-		clickReleased(GH.getCursorPosition());
+		clickReleased(ENGINE->getCursorPosition());
 	}
 }
 
@@ -335,10 +335,10 @@ WindowBase::WindowBase(int used_, Point pos_)
 
 void WindowBase::close()
 {
-	if(!GH.windows().isTopWindow(this))
+	if(!ENGINE->windows().isTopWindow(this))
 	{
-		auto topWindow = GH.windows().topWindow<IShowActivatable>().get();
+		auto topWindow = ENGINE->windows().topWindow<IShowActivatable>().get();
 		throw std::runtime_error(std::string("Only top interface can be closed! Top window is ") + typeid(*topWindow).name() + " but attempted to close " + typeid(*this).name());
 	}
-	GH.windows().popWindows(1);
+	ENGINE->windows().popWindows(1);
 }

+ 1 - 1
client/gui/CIntObject.h

@@ -15,7 +15,7 @@
 #include "../../lib/Color.h"
 #include "../../lib/GameConstants.h"
 
-class CGuiHandler;
+class GameEngine;
 class CPicture;
 class Canvas;
 

+ 10 - 10
client/gui/CursorHandler.cpp

@@ -11,7 +11,7 @@
 #include "StdInc.h"
 #include "CursorHandler.h"
 
-#include "CGuiHandler.h"
+#include "GameEngine.h"
 #include "FramerateManager.h"
 #include "../renderSDL/CursorSoftware.h"
 #include "../renderSDL/CursorHardware.h"
@@ -48,10 +48,10 @@ CursorHandler::CursorHandler()
 
 	cursors =
 	{
-		GH.renderHandler().loadAnimation(AnimationPath::builtin("CRADVNTR"), EImageBlitMode::COLORKEY),
-		GH.renderHandler().loadAnimation(AnimationPath::builtin("CRCOMBAT"), EImageBlitMode::COLORKEY),
-		GH.renderHandler().loadAnimation(AnimationPath::builtin("CRDEFLT"), EImageBlitMode::COLORKEY),
-		GH.renderHandler().loadAnimation(AnimationPath::builtin("CRSPELL"), EImageBlitMode::COLORKEY)
+		ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("CRADVNTR"), EImageBlitMode::COLORKEY),
+		ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("CRCOMBAT"), EImageBlitMode::COLORKEY),
+		ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("CRDEFLT"), EImageBlitMode::COLORKEY),
+		ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("CRSPELL"), EImageBlitMode::COLORKEY)
 	};
 
 	set(Cursor::Map::POINTER);
@@ -102,7 +102,7 @@ void CursorHandler::dragAndDropCursor(std::shared_ptr<IImage> image)
 
 void CursorHandler::dragAndDropCursor (const AnimationPath & path, size_t index)
 {
-	auto anim = GH.renderHandler().loadAnimation(path, EImageBlitMode::COLORKEY);
+	auto anim = ENGINE->renderHandler().loadAnimation(path, EImageBlitMode::COLORKEY);
 	dragAndDropCursor(anim->getImage(index));
 }
 
@@ -176,7 +176,7 @@ Point CursorHandler::getPivotOffsetMap(size_t index)
 
 	assert(offsets.size() == size_t(Cursor::Map::COUNT)); //Invalid number of pivot offsets for cursor
 	assert(index < offsets.size());
-	return offsets[index] * GH.screenHandler().getScalingFactor();
+	return offsets[index] * ENGINE->screenHandler().getScalingFactor();
 }
 
 Point CursorHandler::getPivotOffsetCombat(size_t index)
@@ -206,12 +206,12 @@ Point CursorHandler::getPivotOffsetCombat(size_t index)
 
 	assert(offsets.size() == size_t(Cursor::Combat::COUNT)); //Invalid number of pivot offsets for cursor
 	assert(index < offsets.size());
-	return offsets[index] * GH.screenHandler().getScalingFactor();
+	return offsets[index] * ENGINE->screenHandler().getScalingFactor();
 }
 
 Point CursorHandler::getPivotOffsetSpellcast()
 {
-	return Point(18, 28) * GH.screenHandler().getScalingFactor();
+	return Point(18, 28) * ENGINE->screenHandler().getScalingFactor();
 }
 
 Point CursorHandler::getPivotOffset()
@@ -242,7 +242,7 @@ void CursorHandler::updateSpellcastCursor()
 {
 	static const float frameDisplayDuration = 0.1f; // H3 uses 100 ms per frame
 
-	frameTime += GH.framerate().getElapsedMilliseconds() / 1000.f;
+	frameTime += ENGINE->framerate().getElapsedMilliseconds() / 1000.f;
 	size_t newFrame = frame;
 
 	while (frameTime >= frameDisplayDuration)

+ 7 - 7
client/gui/EventDispatcher.cpp

@@ -12,7 +12,7 @@
 
 #include "EventsReceiver.h"
 #include "FramerateManager.h"
-#include "CGuiHandler.h"
+#include "GameEngine.h"
 #include "MouseButton.h"
 #include "WindowHandler.h"
 #include "gui/Shortcut.h"
@@ -80,10 +80,10 @@ void EventDispatcher::dispatchShortcutPressed(const std::vector<EShortcut> & sho
 	bool keysCaptured = false;
 
 	if (vstd::contains(shortcutsVector, EShortcut::MOUSE_LEFT))
-		dispatchMouseLeftButtonPressed(GH.getCursorPosition(), settings["input"]["shortcutToleranceDistance"].Integer());
+		dispatchMouseLeftButtonPressed(ENGINE->getCursorPosition(), settings["input"]["shortcutToleranceDistance"].Integer());
 
 	if (vstd::contains(shortcutsVector, EShortcut::MOUSE_RIGHT))
-		dispatchShowPopup(GH.getCursorPosition(), settings["input"]["shortcutToleranceDistance"].Integer());
+		dispatchShowPopup(ENGINE->getCursorPosition(), settings["input"]["shortcutToleranceDistance"].Integer());
 
 	for(auto & i : keyinterested)
 		for(EShortcut shortcut : shortcutsVector)
@@ -109,10 +109,10 @@ void EventDispatcher::dispatchShortcutReleased(const std::vector<EShortcut> & sh
 	bool keysCaptured = false;
 
 	if (vstd::contains(shortcutsVector, EShortcut::MOUSE_LEFT))
-		dispatchMouseLeftButtonReleased(GH.getCursorPosition(), settings["input"]["shortcutToleranceDistance"].Integer());
+		dispatchMouseLeftButtonReleased(ENGINE->getCursorPosition(), settings["input"]["shortcutToleranceDistance"].Integer());
 
 	if (vstd::contains(shortcutsVector, EShortcut::MOUSE_RIGHT))
-		dispatchClosePopup(GH.getCursorPosition());
+		dispatchClosePopup(ENGINE->getCursorPosition());
 
 	for(auto & i : keyinterested)
 		for(EShortcut shortcut : shortcutsVector)
@@ -201,7 +201,7 @@ void EventDispatcher::dispatchShowPopup(const Point & position, int tolerance)
 
 void EventDispatcher::dispatchClosePopup(const Point & position)
 {
-	bool popupOpen = GH.windows().isTopWindowPopup(); // popup can already be closed for mouse dragging with RMB
+	bool popupOpen = ENGINE->windows().isTopWindowPopup(); // popup can already be closed for mouse dragging with RMB
 
 	auto hlp = rclickable;
 
@@ -214,7 +214,7 @@ void EventDispatcher::dispatchClosePopup(const Point & position)
 	}
 
 	if(popupOpen)
-		GH.windows().popWindows(1);
+		ENGINE->windows().popWindows(1);
 }
 
 void EventDispatcher::handleLeftButtonClick(const Point & position, int tolerance, bool isPressed)

+ 3 - 3
client/gui/EventsReceiver.cpp

@@ -11,7 +11,7 @@
 #include "EventsReceiver.h"
 
 #include "MouseButton.h"
-#include "CGuiHandler.h"
+#include "GameEngine.h"
 #include "EventDispatcher.h"
 
 AEventsReceiver::AEventsReceiver()
@@ -42,7 +42,7 @@ void AEventsReceiver::activateEvents(ui16 what)
 	assert((what & GENERAL) || (activeState & GENERAL));
 
 	activeState |= GENERAL;
-	GH.events().activateElement(this, what);
+	ENGINE->events().activateElement(this, what);
 }
 
 void AEventsReceiver::deactivateEvents(ui16 what)
@@ -56,7 +56,7 @@ void AEventsReceiver::deactivateEvents(ui16 what)
 		// if element is deactivated (has GENERAL flag) then all existing active events should also be deactivated
 		what = activeState;
 	}
-	GH.events().deactivateElement(this, what & activeState);
+	ENGINE->events().deactivateElement(this, what & activeState);
 
 	if (!(activeState & GESTURE) && panningState)
 		panningState = false;

+ 3 - 3
client/gui/InterfaceObjectConfigurable.cpp

@@ -14,7 +14,7 @@
 
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/ShortcutHandler.h"
 #include "../gui/Shortcut.h"
 #include "../render/Graphics.h"
@@ -320,7 +320,7 @@ EShortcut InterfaceObjectConfigurable::readHotkey(const JsonNode & config) const
 		return EShortcut::NONE;
 	}
 
-	EShortcut result = GH.shortcuts().findShortcut(config.String());
+	EShortcut result = ENGINE->shortcuts().findShortcut(config.String());
 	if (result == EShortcut::NONE)
 		logGlobal->error("Invalid hotkey '%s' in interface configuration!", config.String());
 	return result;
@@ -358,7 +358,7 @@ std::shared_ptr<CMultiLineLabel> InterfaceObjectConfigurable::buildMultiLineLabe
 	auto color = readColor(config["color"]);
 	auto text = readText(config["text"]);
 	Rect rect = readRect(config["rect"]);
-	const auto & fontPtr = GH.renderHandler().loadFont(font);
+	const auto & fontPtr = ENGINE->renderHandler().loadFont(font);
 	if(!config["adoptHeight"].isNull() && config["adoptHeight"].Bool())
 		rect.h = fontPtr->getLineHeight() * 2;
 	return std::make_shared<CMultiLineLabel>(rect, font, alignment, color, text);

+ 4 - 4
client/gui/WindowHandler.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "WindowHandler.h"
 
-#include "CGuiHandler.h"
+#include "GameEngine.h"
 #include "CIntObject.h"
 #include "CursorHandler.h"
 
@@ -75,7 +75,7 @@ void WindowHandler::popWindows(int howMany)
 		windowsStack.back()->activate();
 		totalRedraw();
 	}
-	GH.fakeMouseMove();
+	ENGINE->fakeMouseMove();
 }
 
 std::shared_ptr<IShowActivatable> WindowHandler::topWindowImpl() const
@@ -107,7 +107,7 @@ void WindowHandler::totalRedrawImpl()
 {
 	logGlobal->debug("totalRedraw requested!");
 
-	Canvas target = GH.screenHandler().getScreenCanvas();
+	Canvas target = ENGINE->screenHandler().getScreenCanvas();
 
 	for(auto & elem : windowsStack)
 		elem->showAll(target);
@@ -125,7 +125,7 @@ void WindowHandler::simpleRedraw()
 
 void WindowHandler::simpleRedrawImpl()
 {
-	Canvas target = GH.screenHandler().getScreenCanvas();
+	Canvas target = ENGINE->screenHandler().getScreenCanvas();
 
 	if(!windowsStack.empty())
 		windowsStack.back()->show(target); //blit active interface/window

+ 6 - 6
client/lobby/CBonusSelection.cpp

@@ -35,7 +35,7 @@
 #include "../render/IRenderHandler.h"
 #include "../render/CAnimation.h"
 #include "../render/Graphics.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../adventureMap/AdventureMapInterface.h"
@@ -76,7 +76,7 @@ CBonusSelection::CBonusSelection()
 
 	const auto & playVideo = [this]()
 	{
-		GH.windows().createAndPushWindow<CPrologEpilogVideo>(
+		ENGINE->windows().createAndPushWindow<CPrologEpilogVideo>(
 			getCampaign()->scenario(CSH->campaignMap).prolog,
 			[this]() { redraw(); } );
 	};
@@ -145,7 +145,7 @@ CBonusSelection::CBonusSelection()
 		tabExtraOptions->recActions = UPDATE | SHOWALL | LCLICK | RCLICK_POPUP;
 		tabExtraOptions->recreate(true);
 		tabExtraOptions->setEnabled(false);
-		buttonExtraOptions = std::make_shared<CButton>(Point(643, 431), AnimationPath::builtin("GSPBUT2.DEF"), CGI->generaltexth->zelp[46], [this]{ tabExtraOptions->setEnabled(!tabExtraOptions->isActive()); GH.windows().totalRedraw(); }, EShortcut::LOBBY_EXTRA_OPTIONS);
+		buttonExtraOptions = std::make_shared<CButton>(Point(643, 431), AnimationPath::builtin("GSPBUT2.DEF"), CGI->generaltexth->zelp[46], [this]{ tabExtraOptions->setEnabled(!tabExtraOptions->isActive()); ENGINE->windows().totalRedraw(); }, EShortcut::LOBBY_EXTRA_OPTIONS);
 		buttonExtraOptions->setTextOverlay(CGI->generaltexth->translate("vcmi.optionsTab.extraOptions.hover"), FONT_SMALL, Colors::WHITE);
 	}
 }
@@ -397,7 +397,7 @@ void CBonusSelection::goBack()
 {
 	if(CSH->getState() != EClientState::GAMEPLAY)
 	{
-		GH.windows().popWindows(2);
+		ENGINE->windows().popWindows(2);
 		CMM->playMusic();
 	}
 	else
@@ -433,7 +433,7 @@ void CBonusSelection::startMap()
 		const CampaignScenario & scenario = getCampaign()->scenario(CSH->campaignMap);
 		if(scenario.prolog.hasPrologEpilog)
 		{
-			GH.windows().createAndPushWindow<CPrologEpilogVideo>(scenario.prolog, exitCb);
+			ENGINE->windows().createAndPushWindow<CPrologEpilogVideo>(scenario.prolog, exitCb);
 		}
 		else
 		{
@@ -468,7 +468,7 @@ void CBonusSelection::restartMap()
 		CGI->generaltexth->allTexts[67],
 		[=]()
 		{
-			GH.dispatchMainThread(
+			ENGINE->dispatchMainThread(
 				[]()
 				{
 					CSH->sendRestartGame();

+ 1 - 1
client/lobby/CCampaignInfoScreen.cpp

@@ -16,7 +16,7 @@
 #include "../../lib/StartInfo.h"
 #include "../../lib/mapping/CMapInfo.h"
 #include "../../lib/mapping/CMapHeader.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 

+ 1 - 1
client/lobby/CLobbyScreen.cpp

@@ -18,7 +18,7 @@
 #include "SelectionTab.h"
 
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../widgets/Buttons.h"
 #include "../widgets/GraphicalPrimitiveCanvas.h"

+ 1 - 1
client/lobby/CSavingScreen.cpp

@@ -14,7 +14,7 @@
 
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../widgets/Buttons.h"
 #include "../widgets/CTextInput.h"

+ 1 - 1
client/lobby/CScenarioInfoScreen.cpp

@@ -14,7 +14,7 @@
 
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../widgets/Buttons.h"
 

+ 7 - 7
client/lobby/CSelectionBase.cpp

@@ -21,7 +21,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../globalLobby/GlobalLobbyClient.h"
@@ -128,7 +128,7 @@ void CSelectionBase::toggleTab(std::shared_ptr<CIntObject> tab)
 		tabSel->filter(0, true);
 	}
 
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 InfoCard::InfoCard()
@@ -262,7 +262,7 @@ void InfoCard::changeSelection()
 	if(!showChat)
 		labelGroupPlayers->disable();
 
-	const auto & font = GH.renderHandler().loadFont(FONT_SMALL);
+	const auto & font = ENGINE->renderHandler().loadFont(FONT_SMALL);
 
 	for(const auto & p : CSH->playerNames)
 	{
@@ -356,7 +356,7 @@ void InfoCard::setChat(bool activateChat)
 	}
 
 	showChat = activateChat;
-	GH.windows().totalRedraw();
+	ENGINE->windows().totalRedraw();
 }
 
 CChatBox::CChatBox(const Rect & rect)
@@ -366,7 +366,7 @@ CChatBox::CChatBox(const Rect & rect)
 	pos += rect.topLeft();
 	setRedrawParent(true);
 
-	const auto & font = GH.renderHandler().loadFont(FONT_SMALL);
+	const auto & font = ENGINE->renderHandler().loadFont(FONT_SMALL);
 	const int height = font->getLineHeight();
 	Rect textInputArea(1, rect.h - height, rect.w - 1, height);
 	Rect chatHistoryArea(3, 1, rect.w - 3, rect.h - height - 1);
@@ -448,7 +448,7 @@ PvPBox::PvPBox(const Rect & rect)
 	buttonHandicap = std::make_shared<CButton>(Point(190, 81), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.handicap")), [](){
 		if(!CSH->isHost())
 			return;
-		GH.windows().createAndPushWindow<OptionsTab::HandicapWindow>();
+		ENGINE->windows().createAndPushWindow<OptionsTab::HandicapWindow>();
 	}, EShortcut::LOBBY_HANDICAP);
 	buttonHandicap->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.handicap"), EFonts::FONT_SMALL, Colors::WHITE);
 }
@@ -558,7 +558,7 @@ void CFlagBox::recreate()
 void CFlagBox::showPopupWindow(const Point & cursorPosition)
 {
 	if(SEL->getMapInfo())
-		GH.windows().createAndPushWindow<CFlagBoxTooltipBox>();
+		ENGINE->windows().createAndPushWindow<CFlagBoxTooltipBox>();
 }
 
 CFlagBox::CFlagBoxTooltipBox::CFlagBoxTooltipBox()

+ 15 - 15
client/lobby/OptionsTab.cpp

@@ -14,7 +14,7 @@
 
 #include "../CGameInfo.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../render/Graphics.h"
@@ -68,10 +68,10 @@ void OptionsTab::recreate()
 	entries.clear();
 	humanPlayers = 0;
 
-	for (auto heroOverview : GH.windows().findWindows<CHeroOverview>())
+	for (auto heroOverview : ENGINE->windows().findWindows<CHeroOverview>())
 		heroOverview->close();
 
-	for (auto selectionWindow : GH.windows().findWindows<SelectionWindow>())
+	for (auto selectionWindow : ENGINE->windows().findWindows<SelectionWindow>())
 	{
 		selectionWindow->reopen();
 	}
@@ -479,9 +479,9 @@ std::tuple<int, int> OptionsTab::SelectionWindow::calcLines(FactionID faction)
 
 void OptionsTab::SelectionWindow::apply()
 {
-	if(GH.windows().isTopWindow(this))
+	if(ENGINE->windows().isTopWindow(this))
 	{
-		GH.input().hapticFeedback();
+		ENGINE->input().hapticFeedback();
 		CCS->soundh->playSound(soundBase::button);
 
 		close();
@@ -510,7 +510,7 @@ void OptionsTab::SelectionWindow::reopen()
 		auto window = std::make_shared<SelectionWindow>(color, type, slider ? slider->getValue() : 0);
 		close();
 		if(CSH->isMyColor(color) || CSH->isHost())
-			GH.windows().pushWindow(window);
+			ENGINE->windows().pushWindow(window);
 	}
 }
 
@@ -712,7 +712,7 @@ void OptionsTab::SelectionWindow::setElement(int elem, bool doApply)
 			if(!doApply)
 			{
 				CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN);
-				GH.windows().createAndPushWindow<CPlayerOptionTooltipBox>(helper);
+				ENGINE->windows().createAndPushWindow<CPlayerOptionTooltipBox>(helper);
 			}
 			else
 				selectedFaction = set.castle;
@@ -741,9 +741,9 @@ void OptionsTab::SelectionWindow::setElement(int elem, bool doApply)
 			{
 				CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO);
 				if(settings["general"]["enableUiEnhancements"].Bool() && helper.playerSettings.hero.isValid() && helper.playerSettings.heroNameTextId.empty())
-					GH.windows().createAndPushWindow<CHeroOverview>(helper.playerSettings.hero);
+					ENGINE->windows().createAndPushWindow<CHeroOverview>(helper.playerSettings.hero);
 				else
-					GH.windows().createAndPushWindow<CPlayerOptionTooltipBox>(helper);
+					ENGINE->windows().createAndPushWindow<CPlayerOptionTooltipBox>(helper);
 			}
 			else
 				selectedHero = set.hero;
@@ -758,7 +758,7 @@ void OptionsTab::SelectionWindow::setElement(int elem, bool doApply)
 		if(!doApply)
 		{
 			CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::BONUS);
-			GH.windows().createAndPushWindow<CPlayerOptionTooltipBox>(helper);
+			ENGINE->windows().createAndPushWindow<CPlayerOptionTooltipBox>(helper);
 		}
 		else
 			selectedBonus = set.bonus;
@@ -937,9 +937,9 @@ void OptionsTab::SelectedBox::showPopupWindow(const Point & cursorPosition)
 		return;
 
 	if(settings["general"]["enableUiEnhancements"].Bool() && CPlayerSettingsHelper::selectionType == HERO && playerSettings.hero.isValid() && playerSettings.heroNameTextId.empty())
-		GH.windows().createAndPushWindow<CHeroOverview>(playerSettings.hero);
+		ENGINE->windows().createAndPushWindow<CHeroOverview>(playerSettings.hero);
 	else
-		GH.windows().createAndPushWindow<CPlayerOptionTooltipBox>(*this);
+		ENGINE->windows().createAndPushWindow<CPlayerOptionTooltipBox>(*this);
 }
 
 void OptionsTab::SelectedBox::clickReleased(const Point & cursorPosition)
@@ -962,8 +962,8 @@ void OptionsTab::SelectedBox::clickReleased(const Point & cursorPosition)
 	if(selectionType == SelType::BONUS && foreignPlayer)
 		return;
 
-	GH.input().hapticFeedback();
-	GH.windows().createAndPushWindow<SelectionWindow>(playerSettings.color, selectionType);
+	ENGINE->input().hapticFeedback();
+	ENGINE->windows().createAndPushWindow<SelectionWindow>(playerSettings.color, selectionType);
 }
 
 void OptionsTab::SelectedBox::scrollBy(int distance)
@@ -1048,7 +1048,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
 		if(!CSH->isHost())
 			return;
 		
-		GH.windows().createAndPushWindow<HandicapWindow>();
+		ENGINE->windows().createAndPushWindow<HandicapWindow>();
 	}, [this, hasHandicap](){
 		if(hasHandicap())
 			CRClickPopup::createAndPush(MetaString::createFromTextID("core.help.124.help").toString());

+ 6 - 6
client/lobby/RandomMapTab.cpp

@@ -16,7 +16,7 @@
 
 #include "../CGameInfo.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/MouseButton.h"
 #include "../gui/WindowHandler.h"
 #include "../widgets/CComponent.h"
@@ -111,7 +111,7 @@ RandomMapTab::RandomMapTab():
 	//new callbacks available only from mod
 	addCallback("teamAlignments", [&](int)
 	{
-		GH.windows().createAndPushWindow<TeamAlignments>(*this);
+		ENGINE->windows().createAndPushWindow<TeamAlignments>(*this);
 	});
 	
 	for(const auto & road : VLC->roadTypeHandler->objects)
@@ -489,14 +489,14 @@ TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab):
 		}
 		randomMapTab.updateMapInfoByHost();
 
-		for(auto & window : GH.windows().findWindows<TeamAlignments>())
-			GH.windows().popWindow(window);
+		for(auto & window : ENGINE->windows().findWindows<TeamAlignments>())
+			ENGINE->windows().popWindow(window);
 	});
 	
 	addCallback("cancel", [&](int)
 	{
-		for(auto & window : GH.windows().findWindows<TeamAlignments>())
-			GH.windows().popWindow(window);
+		for(auto & window : ENGINE->windows().findWindows<TeamAlignments>())
+			ENGINE->windows().popWindow(window);
 	});
 	
 	build(config);

+ 3 - 3
client/lobby/SelectionTab.cpp

@@ -16,7 +16,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../widgets/CComponent.h"
@@ -456,7 +456,7 @@ void SelectionTab::showPopupWindow(const Point & cursorPosition)
 			creationDateTime = curItems[py]->campaign->getCreationDateTime() ? TextOperations::getFormattedDateTimeLocal(curItems[py]->campaign->getCreationDateTime()) : curItems[py]->date;
 		}
 
-		GH.windows().createAndPushWindow<CMapOverview>(
+		ENGINE->windows().createAndPushWindow<CMapOverview>(
 			curItems[py]->name,
 			curItems[py]->fullFileURI,
 			creationDateTime,
@@ -722,7 +722,7 @@ bool SelectionTab::receiveEvent(const Point & position, int eventType) const
 
 int SelectionTab::getLine() const
 {
-	Point clickPos = GH.getCursorPosition() - pos.topLeft();
+	Point clickPos = ENGINE->getCursorPosition() - pos.topLeft();
 	return getLine(clickPos);
 }
 

+ 1 - 1
client/mainmenu/CCampaignScreen.cpp

@@ -16,7 +16,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../CServerHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 #include "../media/IMusicPlayer.h"
 #include "../render/Canvas.h"

+ 5 - 5
client/mainmenu/CHighScoreScreen.cpp

@@ -13,7 +13,7 @@
 #include "CHighScoreScreen.h"
 #include "CStatisticScreen.h"
 #include "CMainMenu.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../gui/Shortcut.h"
 #include "../media/IMusicPlayer.h"
@@ -174,7 +174,7 @@ void CHighScoreScreen::buttonExitClick()
 
 void CHighScoreScreen::showAll(Canvas & to)
 {
-	to.fillTexture(GH.renderHandler().loadImage(ImagePath::builtin("DiBoxBck"), EImageBlitMode::OPAQUE));
+	to.fillTexture(ENGINE->renderHandler().loadImage(ImagePath::builtin("DiBoxBck"), EImageBlitMode::OPAQUE));
 	CWindowObject::showAll(to);
 }
 
@@ -214,7 +214,7 @@ CHighScoreInputScreen::CHighScoreInputScreen(bool won, HighScoreCalculation calc
 
 	if (settings["general"]["enableUiEnhancements"].Bool())
 	{
-		statisticButton = std::make_shared<CButton>(Point(726, 10), AnimationPath::builtin("TPTAV02.DEF"), CButton::tooltip(CGI->generaltexth->translate("vcmi.statisticWindow.statistics")), [this](){ GH.windows().createAndPushWindow<CStatisticScreen>(stat); }, EShortcut::HIGH_SCORES_STATISTICS);
+		statisticButton = std::make_shared<CButton>(Point(726, 10), AnimationPath::builtin("TPTAV02.DEF"), CButton::tooltip(CGI->generaltexth->translate("vcmi.statisticWindow.statistics")), [this](){ ENGINE->windows().createAndPushWindow<CStatisticScreen>(stat); }, EShortcut::HIGH_SCORES_STATISTICS);
 		texts.push_back(std::make_shared<CLabel>(716, 25, EFonts::FONT_HIGH_SCORE, ETextAlignment::CENTERRIGHT, Colors::WHITE, CGI->generaltexth->translate("vcmi.statisticWindow.statistics") + ":"));
 	}
 }
@@ -277,7 +277,7 @@ void CHighScoreInputScreen::show(Canvas & to)
 
 void CHighScoreInputScreen::showAll(Canvas & to)
 {
-	to.fillTexture(GH.renderHandler().loadImage(ImagePath::builtin("DiBoxBck"), EImageBlitMode::OPAQUE));
+	to.fillTexture(ENGINE->renderHandler().loadImage(ImagePath::builtin("DiBoxBck"), EImageBlitMode::OPAQUE));
 	CWindowObject::showAll(to);
 }
 
@@ -303,7 +303,7 @@ void CHighScoreInputScreen::clickPressed(const Point & cursorPosition)
 			{
 				int pos = addEntry(text);
 				close();
-				GH.windows().createAndPushWindow<CHighScoreScreen>(calc.isCampaign ? CHighScoreScreen::HighScorePage::CAMPAIGN : CHighScoreScreen::HighScorePage::SCENARIO, pos);
+				ENGINE->windows().createAndPushWindow<CHighScoreScreen>(calc.isCampaign ? CHighScoreScreen::HighScorePage::CAMPAIGN : CHighScoreScreen::HighScorePage::SCENARIO, pos);
 			}
 			else
 				stopMusicAndClose();

+ 27 - 26
client/mainmenu/CMainMenu.cpp

@@ -21,7 +21,8 @@
 #include "../media/IVideoPlayer.h"
 #include "../gui/CursorHandler.h"
 #include "../windows/GUIClasses.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
+#include "../eventsSDL/InputHandler.h"
 #include "../gui/ShortcutHandler.h"
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
@@ -64,7 +65,7 @@ ISelectionScreenInfo * SEL = nullptr;
 
 static void do_quit()
 {
-	GH.dispatchMainThread([]()
+	ENGINE->dispatchMainThread([]()
 	{
 		handleQuit(false);
 	});
@@ -83,7 +84,7 @@ CMenuScreen::CMenuScreen(const JsonNode & configNode)
 		background = std::make_shared<CPicture>(ImagePath::fromJson(bgConfig));
 
 	if(config["scalable"].Bool())
-		background->scaleTo(GH.screenDimensions());
+		background->scaleTo(ENGINE->screenDimensions());
 
 	pos = background->center();
 
@@ -179,7 +180,7 @@ static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::str
 				case 0:
 					return []() { CMainMenu::openLobby(ESelectionScreen::newGame, true, {}, ELoadMode::NONE); };
 				case 1:
-					return []() { GH.windows().createAndPushWindow<CMultiMode>(ESelectionScreen::newGame); };
+					return []() { ENGINE->windows().createAndPushWindow<CMultiMode>(ESelectionScreen::newGame); };
 				case 2:
 					return []() { CMainMenu::openLobby(ESelectionScreen::campaignList, true, {}, ELoadMode::NONE); };
 				case 3:
@@ -194,7 +195,7 @@ static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::str
 				case 0:
 					return []() { CMainMenu::openLobby(ESelectionScreen::loadGame, true, {}, ELoadMode::SINGLE); };
 				case 1:
-					return []() { GH.windows().createAndPushWindow<CMultiMode>(ESelectionScreen::loadGame); };
+					return []() { ENGINE->windows().createAndPushWindow<CMultiMode>(ESelectionScreen::loadGame); };
 				case 2:
 					return []() { CMainMenu::openLobby(ESelectionScreen::loadGame, true, {}, ELoadMode::CAMPAIGN); };
 				case 3:
@@ -235,7 +236,7 @@ std::shared_ptr<CButton> CMenuEntry::createButton(CMenuScreen * parent, const Js
 	if(posy < 0)
 		posy = pos.h + posy;
 
-	EShortcut shortcut = GH.shortcuts().findShortcut(button["shortcut"].String());
+	EShortcut shortcut = ENGINE->shortcuts().findShortcut(button["shortcut"].String());
 
 	if (shortcut == EShortcut::NONE && !button["shortcut"].String().empty())
 	{
@@ -321,8 +322,8 @@ const JsonNode & CMainMenuConfig::getCampaigns() const
 
 CMainMenu::CMainMenu()
 {
-	pos.w = GH.screenDimensions().x;
-	pos.h = GH.screenDimensions().y;
+	pos.w = ENGINE->screenDimensions().x;
+	pos.h = ENGINE->screenDimensions().y;
 
 	menu = std::make_shared<CMenuScreen>(CMainMenuConfig::get().getConfig()["window"]);
 	OBJECT_CONSTRUCTION;
@@ -331,15 +332,15 @@ CMainMenu::CMainMenu()
 
 CMainMenu::~CMainMenu()
 {
-	if(GH.curInt == this)
-		GH.curInt = nullptr;
+	if(ENGINE->curInt == this)
+		ENGINE->curInt = nullptr;
 }
 
 void CMainMenu::playIntroVideos()
 {
 	auto playVideo = [](std::string video, bool rim, float scaleFactor, std::function<void(bool)> cb){
 		if(CCS->videoh->open(VideoPath::builtin(video), scaleFactor))
-			GH.windows().createAndPushWindow<VideoWindow>(VideoPath::builtin(video), rim ? ImagePath::builtin("INTRORIM") : ImagePath::builtin(""), true, scaleFactor, [cb](bool skipped){ cb(skipped); });
+			ENGINE->windows().createAndPushWindow<VideoWindow>(VideoPath::builtin(video), rim ? ImagePath::builtin("INTRORIM") : ImagePath::builtin(""), true, scaleFactor, [cb](bool skipped){ cb(skipped); });
 		else
 			cb(true);
 	};
@@ -367,7 +368,7 @@ void CMainMenu::playMusic()
 void CMainMenu::activate()
 {
 	// check if screen was resized while main menu was inactive - e.g. in gameplay mode
-	if (pos.dimensions() != GH.screenDimensions())
+	if (pos.dimensions() != ENGINE->screenDimensions())
 		onScreenResize();
 
 	CIntObject::activate();
@@ -375,8 +376,8 @@ void CMainMenu::activate()
 
 void CMainMenu::onScreenResize()
 {
-	pos.w = GH.screenDimensions().x;
-	pos.h = GH.screenDimensions().y;
+	pos.w = ENGINE->screenDimensions().x;
+	pos.h = ENGINE->screenDimensions().y;
 
 	menu = nullptr;
 	menu = std::make_shared<CMenuScreen>(CMainMenuConfig::get().getConfig()["window"]);
@@ -389,16 +390,16 @@ void CMainMenu::update()
 	if(CMM != this->shared_from_this()) //don't update if you are not a main interface
 		return;
 
-	if(GH.windows().count() == 0)
+	if(ENGINE->windows().count() == 0)
 	{
-		GH.windows().pushWindow(CMM);
-		GH.windows().pushWindow(menu);
+		ENGINE->windows().pushWindow(CMM);
+		ENGINE->windows().pushWindow(menu);
 		menu->switchToTab(menu->getActiveTab());
 	}
 
 	// Handles mouse and key input
-	GH.handleEvents();
-	GH.windows().simpleRedraw();
+	ENGINE->handleEvents();
+	ENGINE->windows().simpleRedraw();
 }
 
 void CMainMenu::openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> & names, ELoadMode loadMode)
@@ -406,7 +407,7 @@ void CMainMenu::openLobby(ESelectionScreen screenType, bool host, const std::vec
 	CSH->resetStateForLobby(screenType == ESelectionScreen::newGame ? EStartMode::NEW_GAME : EStartMode::LOAD_GAME, screenType, EServerMode::LOCAL, names);
 	CSH->loadMode = loadMode;
 
-	GH.windows().createAndPushWindow<CSimpleJoinScreen>(host);
+	ENGINE->windows().createAndPushWindow<CSimpleJoinScreen>(host);
 }
 
 void CMainMenu::openCampaignLobby(const std::string & campaignFileName, std::string campaignSet)
@@ -420,7 +421,7 @@ void CMainMenu::openCampaignLobby(std::shared_ptr<CampaignState> campaign)
 {
 	CSH->resetStateForLobby(EStartMode::CAMPAIGN, ESelectionScreen::campaignList, EServerMode::LOCAL, {});
 	CSH->campaignStateToSend = campaign;
-	GH.windows().createAndPushWindow<CSimpleJoinScreen>();
+	ENGINE->windows().createAndPushWindow<CSimpleJoinScreen>();
 }
 
 void CMainMenu::openCampaignScreen(std::string name)
@@ -449,7 +450,7 @@ void CMainMenu::openCampaignScreen(std::string name)
 		return;
 	}
 
-	GH.windows().createAndPushWindow<CCampaignScreen>(config, name);
+	ENGINE->windows().createAndPushWindow<CCampaignScreen>(config, name);
 }
 
 void CMainMenu::startTutorial()
@@ -469,7 +470,7 @@ void CMainMenu::startTutorial()
 
 void CMainMenu::openHighScoreScreen()
 {
-	GH.windows().createAndPushWindow<CHighScoreScreen>(CHighScoreScreen::HighScorePage::SCENARIO);
+	ENGINE->windows().createAndPushWindow<CHighScoreScreen>(CHighScoreScreen::HighScorePage::SCENARIO);
 	return;
 }
 
@@ -534,14 +535,14 @@ void CMultiMode::hostTCP(EShortcut shortcut)
 {
 	auto savedScreenType = screenType;
 	close();
-	GH.windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, true, ELoadMode::MULTI, shortcut);
+	ENGINE->windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, true, ELoadMode::MULTI, shortcut);
 }
 
 void CMultiMode::joinTCP(EShortcut shortcut)
 {
 	auto savedScreenType = screenType;
 	close();
-	GH.windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, false, ELoadMode::MULTI, shortcut);
+	ENGINE->windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, false, ELoadMode::MULTI, shortcut);
 }
 
 std::vector<std::string> CMultiMode::getPlayersNames()
@@ -686,7 +687,7 @@ void CSimpleJoinScreen::connectToServer()
 {
 	textTitle->setText(CGI->generaltexth->translate("vcmi.mainMenu.serverConnecting"));
 	buttonOk->block(true);
-	GH.stopTextInput();
+	ENGINE->input().stopTextInput();
 
 	startConnection(inputAddress->getText(), boost::lexical_cast<ui16>(inputPort->getText()));
 }

+ 3 - 3
client/mainmenu/CPrologEpilogVideo.cpp

@@ -15,7 +15,7 @@
 #include "../media/IMusicPlayer.h"
 #include "../media/ISoundPlayer.h"
 //#include "../gui/WindowHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 //#include "../gui/FramerateManager.h"
 #include "../widgets/TextControls.h"
 #include "../widgets/VideoWidget.h"
@@ -29,7 +29,7 @@ CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::f
 	addUsedEvents(LCLICK | TIME);
 	pos = center(Rect(0, 0, 800, 600));
 
-	backgroundAroundMenu = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(-pos.x, -pos.y, GH.screenDimensions().x, GH.screenDimensions().y));
+	backgroundAroundMenu = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(-pos.x, -pos.y, ENGINE->screenDimensions().x, ENGINE->screenDimensions().y));
 
 	//TODO: remove hardcoded paths. Some of campaigns video actually consist from 2 parts
 	// however, currently our campaigns format expects only	a single video file
@@ -79,7 +79,7 @@ void CPrologEpilogVideo::tick(uint32_t msPassed)
 		++positionCounter;
 	}
 	else if(elapsedTimeMilliseconds > (voiceDurationMilliseconds == 0 ? 8000 : 3000) && voiceStopped) // pause after completed scrolling (longer for intros missing voice)
-		clickPressed(GH.getCursorPosition());
+		clickPressed(ENGINE->getCursorPosition());
 }
 
 void CPrologEpilogVideo::show(Canvas & to)

+ 8 - 8
client/mainmenu/CStatisticScreen.cpp

@@ -13,7 +13,7 @@
 #include "CStatisticScreen.h"
 #include "../CGameInfo.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../eventsSDL/InputHandler.h"
 #include "../gui/Shortcut.h"
@@ -58,7 +58,7 @@ CStatisticScreen::CStatisticScreen(const StatisticDataSet & stat)
 	buttonSelect = std::make_shared<CToggleButton>(Point(10, 564), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this](bool on){ onSelectButton(); });
 	buttonSelect->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.selectView"), EFonts::FONT_SMALL, Colors::YELLOW);
 
-	buttonCsvSave = std::make_shared<CToggleButton>(Point(150, 564), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this](bool on){ GH.input().copyToClipBoard(statistic.toCsv("\t"));	});
+	buttonCsvSave = std::make_shared<CToggleButton>(Point(150, 564), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this](bool on){ ENGINE->input().copyToClipBoard(statistic.toCsv("\t"));	});
 	buttonCsvSave->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.tsvCopy"), EFonts::FONT_SMALL, Colors::YELLOW);
 
 	mainContent = getContent(OVERVIEW, EGameResID::NONE);
@@ -69,7 +69,7 @@ void CStatisticScreen::onSelectButton()
 	std::vector<std::string> texts;
 	for(auto & val : contentInfo)
 		texts.emplace_back(CGI->generaltexth->translate(std::get<0>(val.second)));
-	GH.windows().createAndPushWindow<StatisticSelector>(texts, [this](int selectedIndex)
+	ENGINE->windows().createAndPushWindow<StatisticSelector>(texts, [this](int selectedIndex)
 	{
 		OBJECT_CONSTRUCTION;
 		if(!std::get<1>(contentInfo[static_cast<Content>(selectedIndex)]))
@@ -82,7 +82,7 @@ void CStatisticScreen::onSelectButton()
 			for(const auto & res : possibleRes)
 				resourceText.emplace_back(CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()));
 			
-			GH.windows().createAndPushWindow<StatisticSelector>(resourceText, [this, content, possibleRes](int index)
+			ENGINE->windows().createAndPushWindow<StatisticSelector>(resourceText, [this, content, possibleRes](int index)
 			{
 				OBJECT_CONSTRUCTION;
 				mainContent = getContent(content, possibleRes[index]);
@@ -129,10 +129,10 @@ TIcons CStatisticScreen::extractIcons() const
 	auto tmpData = statistic.data;
 	std::sort(tmpData.begin(), tmpData.end(), [](const StatisticDataSetEntry & v1, const StatisticDataSetEntry & v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; });
 
-	auto imageTown = GH.renderHandler().loadImage(AnimationPath::builtin("cradvntr"), 3, 0, EImageBlitMode::COLORKEY);
-	auto imageBattle = GH.renderHandler().loadImage(AnimationPath::builtin("cradvntr"), 5, 0, EImageBlitMode::COLORKEY);
-	auto imageDefeated = GH.renderHandler().loadImage(AnimationPath::builtin("crcombat"), 0, 0, EImageBlitMode::COLORKEY);
-	auto imageGrail = GH.renderHandler().loadImage(AnimationPath::builtin("vwsymbol"), 2, 0, EImageBlitMode::COLORKEY);
+	auto imageTown = ENGINE->renderHandler().loadImage(AnimationPath::builtin("cradvntr"), 3, 0, EImageBlitMode::COLORKEY);
+	auto imageBattle = ENGINE->renderHandler().loadImage(AnimationPath::builtin("cradvntr"), 5, 0, EImageBlitMode::COLORKEY);
+	auto imageDefeated = ENGINE->renderHandler().loadImage(AnimationPath::builtin("crcombat"), 0, 0, EImageBlitMode::COLORKEY);
+	auto imageGrail = ENGINE->renderHandler().loadImage(AnimationPath::builtin("vwsymbol"), 2, 0, EImageBlitMode::COLORKEY);
 
 	std::map<PlayerColor, bool> foundDefeated;
 	std::map<PlayerColor, bool> foundGrail;

+ 2 - 2
client/mainmenu/CreditsScreen.cpp

@@ -13,7 +13,7 @@
 
 #include "CMainMenu.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../widgets/TextControls.h"
 #include "../widgets/ObjectLists.h"
 
@@ -59,7 +59,7 @@ void CreditsScreen::tick(uint32_t msPassed)
 
 	//end of credits, close this screen
 	if(credits->textSize.y < scrollPosition)
-		clickPressed(GH.getCursorPosition());
+		clickPressed(ENGINE->getCursorPosition());
 }
 
 void CreditsScreen::clickPressed(const Point & cursorPosition)

+ 3 - 3
client/mapView/MapOverlayLogVisualizer.cpp

@@ -21,7 +21,7 @@
 #include "../render/IRenderHandler.h"
 #include "../render/Graphics.h"
 #include "../gui/TextAlignment.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 
 
 MapOverlayLogVisualizer::MapOverlayLogVisualizer(Canvas & target, std::shared_ptr<MapViewModel> model)
@@ -36,7 +36,7 @@ void MapOverlayLogVisualizer::drawLine(int3 start, int3 end)
 	if(start.z != level || end.z != level)
 		return;
 
-	int scaling = GH.screenHandler().getScalingFactor();
+	int scaling = ENGINE->screenHandler().getScalingFactor();
 	auto pStart = model->getTargetTileArea(start).center();
 	auto pEnd = model->getTargetTileArea(end).center();
 	Rect viewPortRaw = target.getRenderArea();
@@ -77,7 +77,7 @@ void MapOverlayLogVisualizer::drawText(
 
 	if(viewPort.isInside(pStart))
 	{
-		const auto & font = GH.renderHandler().loadFont(FONT_TINY);
+		const auto & font = ENGINE->renderHandler().loadFont(FONT_TINY);
 
 		int w = font->getStringWidth(text);
 		int h = font->getLineHeight();

+ 11 - 11
client/mapView/MapRenderer.cpp

@@ -15,7 +15,7 @@
 #include "mapHandler.h"
 
 #include "../CGameInfo.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/CAnimation.h"
 #include "../render/Canvas.h"
 #include "../render/IImage.h"
@@ -105,7 +105,7 @@ void MapTileStorage::load(size_t index, const AnimationPath & filename, EImageBl
 	for(auto & entry : terrainAnimations)
 	{
 		if (!filename.empty())
-			entry = GH.renderHandler().loadAnimation(filename, blitMode);
+			entry = ENGINE->renderHandler().loadAnimation(filename, blitMode);
 	}
 
 	if (terrainAnimations[1])
@@ -260,7 +260,7 @@ uint8_t MapRendererRoad::checksum(IMapRendererContext & context, const int3 & co
 
 MapRendererBorder::MapRendererBorder()
 {
-	animation = GH.renderHandler().loadAnimation(AnimationPath::builtin("EDG"), EImageBlitMode::OPAQUE);
+	animation = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("EDG"), EImageBlitMode::OPAQUE);
 }
 
 size_t MapRendererBorder::getIndexForTile(IMapRendererContext & context, const int3 & tile)
@@ -321,8 +321,8 @@ uint8_t MapRendererBorder::checksum(IMapRendererContext & context, const int3 &
 
 MapRendererFow::MapRendererFow()
 {
-	fogOfWarFullHide = GH.renderHandler().loadAnimation(AnimationPath::builtin("TSHRC"), EImageBlitMode::OPAQUE);
-	fogOfWarPartialHide = GH.renderHandler().loadAnimation(AnimationPath::builtin("TSHRE"), EImageBlitMode::SIMPLE);
+	fogOfWarFullHide = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("TSHRC"), EImageBlitMode::OPAQUE);
+	fogOfWarPartialHide = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("TSHRE"), EImageBlitMode::SIMPLE);
 
 	static const std::vector<int> rotations = {22, 15, 2, 13, 12, 16, 28, 17, 20, 19, 7, 24, 26, 25, 30, 32, 27};
 
@@ -407,7 +407,7 @@ std::shared_ptr<CAnimation> MapRendererObjects::getAnimation(const AnimationPath
 	if(it != animations.end())
 		return it->second;
 
-	auto ret = GH.renderHandler().loadAnimation(filename, enableOverlay ? EImageBlitMode::WITH_SHADOW_AND_FLAG_COLOR: EImageBlitMode::WITH_SHADOW);
+	auto ret = ENGINE->renderHandler().loadAnimation(filename, enableOverlay ? EImageBlitMode::WITH_SHADOW_AND_FLAG_COLOR: EImageBlitMode::WITH_SHADOW);
 	animations[filename] = ret;
 
 	if(generateMovementGroups)
@@ -566,10 +566,10 @@ uint8_t MapRendererObjects::checksum(IMapRendererContext & context, const int3 &
 }
 
 MapRendererOverlay::MapRendererOverlay()
-	: imageGrid(GH.renderHandler().loadImage(ImagePath::builtin("debug/grid"), EImageBlitMode::COLORKEY))
-	, imageBlocked(GH.renderHandler().loadImage(ImagePath::builtin("debug/blocked"), EImageBlitMode::COLORKEY))
-	, imageVisitable(GH.renderHandler().loadImage(ImagePath::builtin("debug/visitable"), EImageBlitMode::COLORKEY))
-	, imageSpellRange(GH.renderHandler().loadImage(ImagePath::builtin("debug/spellRange"), EImageBlitMode::COLORKEY))
+	: imageGrid(ENGINE->renderHandler().loadImage(ImagePath::builtin("debug/grid"), EImageBlitMode::COLORKEY))
+	, imageBlocked(ENGINE->renderHandler().loadImage(ImagePath::builtin("debug/blocked"), EImageBlitMode::COLORKEY))
+	, imageVisitable(ENGINE->renderHandler().loadImage(ImagePath::builtin("debug/visitable"), EImageBlitMode::COLORKEY))
+	, imageSpellRange(ENGINE->renderHandler().loadImage(ImagePath::builtin("debug/spellRange"), EImageBlitMode::COLORKEY))
 {
 
 }
@@ -625,7 +625,7 @@ uint8_t MapRendererOverlay::checksum(IMapRendererContext & context, const int3 &
 }
 
 MapRendererPath::MapRendererPath()
-	: pathNodes(GH.renderHandler().loadAnimation(AnimationPath::builtin("ADAG"), EImageBlitMode::SIMPLE))
+	: pathNodes(ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("ADAG"), EImageBlitMode::SIMPLE))
 {
 }
 

+ 3 - 3
client/mapView/MapView.cpp

@@ -20,7 +20,7 @@
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
 #include "../adventureMap/AdventureMapInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/CAnimation.h"
 #include "../render/Canvas.h"
 #include "../render/IImage.h"
@@ -135,7 +135,7 @@ void MapView::onMapScrolled(const Point & distance)
 void MapView::onMapSwiped(const Point & viewPosition)
 {
 	if(settings["adventure"]["smoothDragging"].Bool())
-		swipeHistory.push_back(std::pair<uint32_t, Point>(GH.input().getTicks(), viewPosition));
+		swipeHistory.push_back(std::pair<uint32_t, Point>(ENGINE->input().getTicks(), viewPosition));
 
 	controller->setViewCenter(model->getMapViewCenter() + viewPosition, model->getLevel());
 }
@@ -148,7 +148,7 @@ void MapView::postSwipe(uint32_t msPassed)
 		{
 			Point diff = Point(0, 0);
 			std::pair<uint32_t, Point> firstAccepted;
-			uint32_t now = GH.input().getTicks();
+			uint32_t now = ENGINE->input().getTicks();
 			for (auto & x : swipeHistory) {
 				if(now - x.first < postSwipeCatchIntervalMs) { // only the last x ms are caught
 					if(firstAccepted.first == 0)

+ 2 - 2
client/mapView/MapViewActions.cpp

@@ -16,7 +16,7 @@
 
 #include "../CGameInfo.h"
 #include "../adventureMap/AdventureMapInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/CursorHandler.h"
 #include "../gui/MouseButton.h"
 
@@ -155,7 +155,7 @@ void MapViewActions::hover(bool on)
 {
 	if(!on)
 	{
-		GH.statusbar()->clear();
+		ENGINE->statusbar()->clear();
 		CCS->curh->set(Cursor::Map::POINTER);
 	}
 }

+ 3 - 3
client/mapView/MapViewCache.cpp

@@ -22,7 +22,7 @@
 #include "../render/IRenderHandler.h"
 #include "../render/Graphics.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../widgets/TextControls.h"
 
 #include "../../lib/mapObjects/CObjectHandler.h"
@@ -35,7 +35,7 @@ MapViewCache::MapViewCache(const std::shared_ptr<MapViewModel> & model)
 	, cachedLevel(0)
 	, overlayWasVisible(false)
 	, mapRenderer(new MapRenderer())
-	, iconsStorage(GH.renderHandler().loadAnimation(AnimationPath::builtin("VwSymbol"), EImageBlitMode::COLORKEY))
+	, iconsStorage(ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("VwSymbol"), EImageBlitMode::COLORKEY))
 	, intermediate(new Canvas(Point(32, 32), CanvasScalingPolicy::AUTO))
 	, terrain(new Canvas(model->getCacheDimensionsPixels(), CanvasScalingPolicy::AUTO))
 	, terrainTransition(new Canvas(model->getPixelsVisibleDimensions(), CanvasScalingPolicy::AUTO))
@@ -188,7 +188,7 @@ void MapViewCache::render(const std::shared_ptr<IMapRendererContext> & context,
 
 	if(context->showTextOverlay())
 	{
-		const auto & font = GH.renderHandler().loadFont(FONT_TINY);
+		const auto & font = ENGINE->renderHandler().loadFont(FONT_TINY);
 
 		for(int y = dimensions.top(); y < dimensions.bottom(); ++y)
 		{

+ 6 - 6
client/mapView/MapViewController.cpp

@@ -19,7 +19,7 @@
 #include "../CCallback.h"
 #include "../CPlayerInterface.h"
 #include "../adventureMap/AdventureMapInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../eventsSDL/InputHandler.h"
 
@@ -129,7 +129,7 @@ void MapViewController::modifyTileSize(int stepsChange, bool useDeadZone)
 		bool isInDeadZone = targetTileSize != actualZoom || actualZoom == Point(defaultTileSize, defaultTileSize);
 
 		if(!wasInDeadZone && isInDeadZone)
-			GH.input().hapticFeedback();
+			ENGINE->input().hapticFeedback();
 
 		wasInDeadZone = isInDeadZone;
 
@@ -224,7 +224,7 @@ void MapViewController::updateState()
 		adventureContext->settingShowVisitable = settings["session"]["showVisitable"].Bool();
 		adventureContext->settingShowBlocked = settings["session"]["showBlocked"].Bool();
 		adventureContext->settingSpellRange = settings["session"]["showSpellRange"].Bool();
-		adventureContext->settingTextOverlay = GH.isKeyboardAltDown() || GH.input().getNumTouchFingers() == 2;
+		adventureContext->settingTextOverlay = ENGINE->isKeyboardAltDown() || ENGINE->input().getNumTouchFingers() == 2;
 	}
 }
 
@@ -302,7 +302,7 @@ bool MapViewController::isEventVisible(const CGObjectInstance * obj, const Playe
 	if(initiator != LOCPLINT->playerID && settings["adventure"]["enemyMoveTime"].Float() < 0)
 		return false; // enemy move speed set to "hidden/none"
 
-	if(!GH.windows().isTopWindow(adventureInt))
+	if(!ENGINE->windows().isTopWindow(adventureInt))
 		return false;
 
 	// do not focus on actions of other players except for AI with simturns off
@@ -328,7 +328,7 @@ bool MapViewController::isEventVisible(const CGHeroInstance * obj, const int3 &
 	if(obj->getOwner() != LOCPLINT->playerID && settings["adventure"]["enemyMoveTime"].Float() < 0)
 		return false; // enemy move speed set to "hidden/none"
 
-	if(!GH.windows().isTopWindow(adventureInt))
+	if(!ENGINE->windows().isTopWindow(adventureInt))
 		return false;
 
 	// do not focus on actions of other players except for AI with simturns off
@@ -588,7 +588,7 @@ bool MapViewController::hasOngoingAnimations()
 
 void MapViewController::waitForOngoingAnimations()
 {
-	auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
+	auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
 	animationWait.waitWhileBusy();
 }
 

+ 1 - 1
client/mapView/mapHandler.cpp

@@ -15,7 +15,7 @@
 #include "../CCallback.h"
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 
 #include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/TerrainHandler.h"

+ 4 - 4
client/media/CMusicHandler.cpp

@@ -12,7 +12,7 @@
 
 #include "../CGameInfo.h"
 #include "../eventsSDL/InputHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../renderSDL/SDLRWwrapper.h"
 
 #include "../../lib/entities/faction/CFaction.h"
@@ -185,7 +185,7 @@ void CMusicHandler::musicFinishedCallback()
 	// 1) SDL thread waiting to acquire music lock in this method (while keeping internal SDL mutex locked)
 	// 2) VCMI thread waiting to acquire internal SDL mutex (while keeping music mutex locked)
 
-	GH.dispatchMainThread(
+	ENGINE->dispatchMainThread(
 		[this]()
 		{
 			boost::unique_lock lockGuard(mutex);
@@ -325,7 +325,7 @@ bool MusicEntry::play()
 		}
 	}
 
-	startTime = GH.input().getTicks();
+	startTime = ENGINE->input().getTicks();
 
 	playing = true;
 	return true;
@@ -337,7 +337,7 @@ bool MusicEntry::stop(int fade_ms)
 	{
 		playing = false;
 		loop = 0;
-		uint32_t endTime = GH.input().getTicks();
+		uint32_t endTime = ENGINE->input().getTicks();
 		assert(startTime != uint32_t(-1));
 		float playDuration = (endTime - startTime + startPosition) / 1000.f;
 		owner->trackPositions[currentName] = playDuration;

+ 2 - 2
client/media/CSoundHandler.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CSoundHandler.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../CGameInfo.h"
 
 #include "../lib/filesystem/Filesystem.h"
@@ -319,7 +319,7 @@ void CSoundHandler::soundFinishedCallback(int channel)
 
 	if(!callback.empty())
 	{
-		GH.dispatchMainThread(
+		ENGINE->dispatchMainThread(
 			[callback]()
 			{
 				for(const auto & entry : callback)

+ 4 - 4
client/media/CVideoHandler.cpp

@@ -17,7 +17,7 @@
 #include "../CGameInfo.h"
 #include "../CMT.h"
 #include "../eventsSDL/InputHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/Canvas.h"
 #include "../render/IScreenHandler.h"
 #include "../renderSDL/SDL_Extensions.h"
@@ -199,7 +199,7 @@ bool CVideoInstance::openVideo()
 void CVideoInstance::prepareOutput(float scaleFactor, bool useTextureOutput)
 {
 	//setup scaling
-	dimensions = Point(getCodecContext()->width * scaleFactor, getCodecContext()->height * scaleFactor) * GH.screenHandler().getScalingFactor();
+	dimensions = Point(getCodecContext()->width * scaleFactor, getCodecContext()->height * scaleFactor) * ENGINE->screenHandler().getScalingFactor();
 
 	// Allocate a place to put our YUV image on that screen
 	if (useTextureOutput)
@@ -378,7 +378,7 @@ FFMpegStream::~FFMpegStream()
 
 Point CVideoInstance::size()
 {
-	return dimensions / GH.screenHandler().getScalingFactor();
+	return dimensions / ENGINE->screenHandler().getScalingFactor();
 }
 
 void CVideoInstance::show(const Point & position, SDL_Surface * to)
@@ -386,7 +386,7 @@ void CVideoInstance::show(const Point & position, SDL_Surface * to)
 	if(sws == nullptr)
 		throw std::runtime_error("No video to show!");
 
-	CSDL_Ext::blitSurface(surface, to, position * GH.screenHandler().getScalingFactor());
+	CSDL_Ext::blitSurface(surface, to, position * ENGINE->screenHandler().getScalingFactor());
 }
 
 double FFMpegStream::getCurrentFrameEndTime() const

+ 19 - 19
client/render/AssetGenerator.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "AssetGenerator.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/IImage.h"
 #include "../render/IImageLoader.h"
 #include "../render/Canvas.h"
@@ -81,9 +81,9 @@ AssetGenerator::CanvasPtr AssetGenerator::createAdventureOptionsCleanBackground(
 {
 	auto locator = ImageLocator(ImagePath::builtin("ADVOPTBK"), EImageBlitMode::OPAQUE);
 
-	std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator);
+	std::shared_ptr<IImage> img = ENGINE->renderHandler().loadImage(locator);
 
-	auto image = GH.renderHandler().createImage(Point(575, 585), CanvasScalingPolicy::IGNORE);
+	auto image = ENGINE->renderHandler().createImage(Point(575, 585), CanvasScalingPolicy::IGNORE);
 	Canvas canvas = image->getCanvas();
 
 	canvas.draw(img, Point(0, 0), Rect(0, 0, 575, 585));
@@ -101,8 +101,8 @@ AssetGenerator::CanvasPtr AssetGenerator::createBigSpellBook() const
 {
 	auto locator = ImageLocator(ImagePath::builtin("SpelBack"), EImageBlitMode::OPAQUE);
 
-	std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator);
-	auto image = GH.renderHandler().createImage(Point(800, 600), CanvasScalingPolicy::IGNORE);
+	std::shared_ptr<IImage> img = ENGINE->renderHandler().loadImage(locator);
+	auto image = ENGINE->renderHandler().createImage(Point(800, 600), CanvasScalingPolicy::IGNORE);
 	Canvas canvas = image->getCanvas();
 	// edges
 	canvas.draw(img, Point(0, 0), Rect(15, 38, 90, 45));
@@ -153,7 +153,7 @@ AssetGenerator::CanvasPtr AssetGenerator::createPlayerColoredBackground(const Pl
 {
 	auto locator = ImageLocator(ImagePath::builtin("DiBoxBck"), EImageBlitMode::OPAQUE);
 
-	std::shared_ptr<IImage> texture = GH.renderHandler().loadImage(locator);
+	std::shared_ptr<IImage> texture = ENGINE->renderHandler().loadImage(locator);
 
 	// transform to make color of brown DIBOX.PCX texture match color of specified player
 	auto filterSettings = VLC->settingsHandler->getFullConfig()["interface"]["playerColoredBackground"];
@@ -174,7 +174,7 @@ AssetGenerator::CanvasPtr AssetGenerator::createPlayerColoredBackground(const Pl
 
 	texture->adjustPalette(filters[player.getNum()], 0);
 
-	auto image = GH.renderHandler().createImage(texture->dimensions(), CanvasScalingPolicy::IGNORE);
+	auto image = ENGINE->renderHandler().createImage(texture->dimensions(), CanvasScalingPolicy::IGNORE);
 	Canvas canvas = image->getCanvas();
 	canvas.draw(texture, Point(0,0));
 
@@ -186,7 +186,7 @@ AssetGenerator::CanvasPtr AssetGenerator::createCombatUnitNumberWindow(float mul
 	auto locator = ImageLocator(ImagePath::builtin("CMNUMWIN"), EImageBlitMode::OPAQUE);
 	locator.layer = EImageBlitMode::OPAQUE;
 
-	std::shared_ptr<IImage> texture = GH.renderHandler().loadImage(locator);
+	std::shared_ptr<IImage> texture = ENGINE->renderHandler().loadImage(locator);
 
 	const auto shifter= ColorFilter::genRangeShifter(0.f, 0.f, 0.f, multR, multG, multB);
 
@@ -195,7 +195,7 @@ AssetGenerator::CanvasPtr AssetGenerator::createCombatUnitNumberWindow(float mul
 
 	texture->adjustPalette(shifter, ignoredMask);
 
-	auto image = GH.renderHandler().createImage(texture->dimensions(), CanvasScalingPolicy::IGNORE);
+	auto image = ENGINE->renderHandler().createImage(texture->dimensions(), CanvasScalingPolicy::IGNORE);
 	Canvas canvas = image->getCanvas();
 	canvas.draw(texture, Point(0,0));
 
@@ -206,8 +206,8 @@ AssetGenerator::CanvasPtr AssetGenerator::createCampaignBackground() const
 {
 	auto locator = ImageLocator(ImagePath::builtin("CAMPBACK"), EImageBlitMode::OPAQUE);
 
-	std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator);
-	auto image = GH.renderHandler().createImage(Point(800, 600), CanvasScalingPolicy::IGNORE);
+	std::shared_ptr<IImage> img = ENGINE->renderHandler().loadImage(locator);
+	auto image = ENGINE->renderHandler().createImage(Point(800, 600), CanvasScalingPolicy::IGNORE);
 	Canvas canvas = image->getCanvas();
 
 	canvas.draw(img, Point(0, 0), Rect(0, 0, 800, 600));
@@ -235,7 +235,7 @@ AssetGenerator::CanvasPtr AssetGenerator::createCampaignBackground() const
 
 	// skull
 	auto locatorSkull = ImageLocator(ImagePath::builtin("CAMPNOSC"), EImageBlitMode::OPAQUE);
-	std::shared_ptr<IImage> imgSkull = GH.renderHandler().loadImage(locatorSkull);
+	std::shared_ptr<IImage> imgSkull = ENGINE->renderHandler().loadImage(locatorSkull);
 	canvas.draw(imgSkull, Point(562, 509), Rect(178, 108, 43, 19));
 
 	return image;
@@ -246,8 +246,8 @@ AssetGenerator::CanvasPtr AssetGenerator::createChroniclesCampaignImages(int chr
 	auto imgPathBg = ImagePath::builtin("chronicles_" + std::to_string(chronicle) + "/GamSelBk");
 	auto locator = ImageLocator(imgPathBg, EImageBlitMode::OPAQUE);
 
-	std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator);
-	auto image = GH.renderHandler().createImage(Point(200, 116), CanvasScalingPolicy::IGNORE);
+	std::shared_ptr<IImage> img = ENGINE->renderHandler().loadImage(locator);
+	auto image = ENGINE->renderHandler().createImage(Point(200, 116), CanvasScalingPolicy::IGNORE);
 	Canvas canvas = image->getCanvas();
 
 	std::array sourceRect = {
@@ -267,7 +267,7 @@ AssetGenerator::CanvasPtr AssetGenerator::createChroniclesCampaignImages(int chr
 	{
 		//skull
 		auto locatorSkull = ImageLocator(ImagePath::builtin("CampSP1"), EImageBlitMode::OPAQUE);
-		std::shared_ptr<IImage> imgSkull = GH.renderHandler().loadImage(locatorSkull);
+		std::shared_ptr<IImage> imgSkull = ENGINE->renderHandler().loadImage(locatorSkull);
 		canvas.draw(imgSkull, Point(162, 94), Rect(162, 94, 41, 22));
 		canvas.draw(img, Point(162, 94), Rect(424, 304, 14, 4));
 		canvas.draw(img, Point(162, 98), Rect(424, 308, 10, 4));
@@ -309,7 +309,7 @@ void AssetGenerator::generatePaletteShiftedAnimation(const AnimationPath & sprit
 {
 	AnimationLayoutMap layout;
 
-	auto animation = GH.renderHandler().loadAnimation(sprite, EImageBlitMode::COLORKEY);
+	auto animation = ENGINE->renderHandler().loadAnimation(sprite, EImageBlitMode::COLORKEY);
 
 	int paletteTransformLength = 1;
 	for (const auto & transform : paletteAnimations)
@@ -334,15 +334,15 @@ void AssetGenerator::generatePaletteShiftedAnimation(const AnimationPath & sprit
 
 AssetGenerator::CanvasPtr AssetGenerator::createPaletteShiftedImage(const AnimationPath & source, const std::vector<PaletteAnimation> & palette, int frameIndex, int paletteShiftCounter) const
 {
-	auto animation = GH.renderHandler().loadAnimation(source, EImageBlitMode::COLORKEY);
+	auto animation = ENGINE->renderHandler().loadAnimation(source, EImageBlitMode::COLORKEY);
 
 	auto imgLoc = animation->getImageLocator(frameIndex, 0);
-	auto img = GH.renderHandler().loadImage(imgLoc);
+	auto img = ENGINE->renderHandler().loadImage(imgLoc);
 
 	for(const auto & element : palette)
 		img->shiftPalette(element.start, element.length, paletteShiftCounter % element.length);
 
-	auto image = GH.renderHandler().createImage(Point(32, 32), CanvasScalingPolicy::IGNORE);
+	auto image = ENGINE->renderHandler().createImage(Point(32, 32), CanvasScalingPolicy::IGNORE);
 	Canvas canvas = image->getCanvas();
 	canvas.draw(img, Point((32 - img->dimensions().x) / 2, (32 - img->dimensions().y) / 2));
 

+ 3 - 3
client/render/CAnimation.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CAnimation.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/IImage.h"
 #include "../render/IRenderHandler.h"
 #include "../render/IScreenHandler.h"
@@ -30,7 +30,7 @@ bool CAnimation::loadFrame(size_t frame, size_t group, bool verbose)
 	if(auto image = getImageImpl(frame, group, false))
 		return true;
 
-	std::shared_ptr<IImage> image = GH.renderHandler().loadImage(getImageLocator(frame, group));
+	std::shared_ptr<IImage> image = ENGINE->renderHandler().loadImage(getImageLocator(frame, group));
 
 	if(image)
 	{
@@ -44,7 +44,7 @@ bool CAnimation::loadFrame(size_t frame, size_t group, bool verbose)
 	{
 		// image is missing
 		printError(frame, group, "LoadFrame");
-		images[group][frame] = GH.renderHandler().loadImage(ImagePath::builtin("DEFAULT"), EImageBlitMode::OPAQUE);
+		images[group][frame] = ENGINE->renderHandler().loadImage(ImagePath::builtin("DEFAULT"), EImageBlitMode::OPAQUE);
 		return false;
 	}
 }

+ 5 - 5
client/render/Canvas.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "Canvas.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../media/IVideoPlayer.h"
 #include "../render/IRenderHandler.h"
 #include "../render/IScreenHandler.h"
@@ -67,7 +67,7 @@ int Canvas::getScalingFactor() const
 {
 	if (scalingPolicy == CanvasScalingPolicy::IGNORE)
 		return 1;
-	return GH.screenHandler().getScalingFactor();
+	return ENGINE->screenHandler().getScalingFactor();
 }
 
 Point Canvas::transformPos(const Point & input)
@@ -181,7 +181,7 @@ void Canvas::drawBorderDashed(const Rect & target, const ColorRGBA & color)
 
 void Canvas::drawText(const Point & position, const EFonts & font, const ColorRGBA & colorDest, ETextAlignment alignment, const std::string & text )
 {
-	const auto & fontPtr = GH.renderHandler().loadFont(font);
+	const auto & fontPtr = ENGINE->renderHandler().loadFont(font);
 
 	switch (alignment)
 	{
@@ -194,7 +194,7 @@ void Canvas::drawText(const Point & position, const EFonts & font, const ColorRG
 
 void Canvas::drawText(const Point & position, const EFonts & font, const ColorRGBA & colorDest, ETextAlignment alignment, const std::vector<std::string> & text )
 {
-	const auto & fontPtr = GH.renderHandler().loadFont(font);
+	const auto & fontPtr = ENGINE->renderHandler().loadFont(font);
 
 	switch (alignment)
 	{
@@ -241,7 +241,7 @@ Rect Canvas::getRenderArea() const
 CanvasClipRectGuard::CanvasClipRectGuard(Canvas & canvas, const Rect & rect): surf(canvas.surface)
 {
 	CSDL_Ext::getClipRect(surf, oldRect);
-	CSDL_Ext::setClipRect(surf, rect * GH.screenHandler().getScalingFactor());
+	CSDL_Ext::setClipRect(surf, rect * ENGINE->screenHandler().getScalingFactor());
 }
 
 CanvasClipRectGuard::~CanvasClipRectGuard()

+ 3 - 3
client/render/CanvasImage.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CanvasImage.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/IScreenHandler.h"
 #include "../renderSDL/SDL_Extensions.h"
 #include "../renderSDL/SDLImageScaler.h"
@@ -20,7 +20,7 @@
 #include <SDL_surface.h>
 
 CanvasImage::CanvasImage(const Point & size, CanvasScalingPolicy scalingPolicy)
-	: surface(CSDL_Ext::newSurface(scalingPolicy == CanvasScalingPolicy::IGNORE ? size : (size * GH.screenHandler().getScalingFactor())))
+	: surface(CSDL_Ext::newSurface(scalingPolicy == CanvasScalingPolicy::IGNORE ? size : (size * ENGINE->screenHandler().getScalingFactor())))
 	, scalingPolicy(scalingPolicy)
 {
 }
@@ -40,7 +40,7 @@ void CanvasImage::draw(SDL_Surface * where, const Point & pos, const Rect * src,
 
 void CanvasImage::scaleTo(const Point & size, EScalingAlgorithm algorithm)
 {
-	Point scaledSize = size * GH.screenHandler().getScalingFactor();
+	Point scaledSize = size * ENGINE->screenHandler().getScalingFactor();
 
 	SDLImageScaler scaler(surface);
 	scaler.scaleSurface(scaledSize, algorithm);

+ 2 - 2
client/render/IFont.cpp

@@ -11,7 +11,7 @@
 #include "StdInc.h"
 #include "IFont.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 
 #include "../render/IScreenHandler.h"
 
@@ -20,7 +20,7 @@
 
 int IFont::getScalingFactor() const
 {
-	return GH.screenHandler().getScalingFactor();
+	return ENGINE->screenHandler().getScalingFactor();
 }
 
 size_t IFont::getLineHeight() const

+ 1 - 1
client/render/ImageLocator.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "ImageLocator.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "IScreenHandler.h"
 
 #include "../../lib/json/JsonNode.h"

+ 4 - 4
client/renderSDL/CBitmapFont.cpp

@@ -14,7 +14,7 @@
 #include "SDLImageScaler.h"
 
 #include "../CGameInfo.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/Colors.h"
 #include "../render/IImage.h"
 #include "../render/IScreenHandler.h"
@@ -199,7 +199,7 @@ CBitmapFont::CBitmapFont(const std::string & filename):
 		chars[symbol.first] = storedEntry;
 	}
 
-	if (GH.screenHandler().getScalingFactor() != 1)
+	if (ENGINE->screenHandler().getScalingFactor() != 1)
 	{
 		static const std::map<std::string, EScalingAlgorithm> filterNameToEnum = {
 			{ "nearest", EScalingAlgorithm::NEAREST},
@@ -210,7 +210,7 @@ CBitmapFont::CBitmapFont(const std::string & filename):
 		auto filterName = settings["video"]["fontUpscalingFilter"].String();
 		EScalingAlgorithm algorithm = filterNameToEnum.at(filterName);
 		SDLImageScaler scaler(atlasImage);
-		scaler.scaleSurfaceIntegerFactor(GH.screenHandler().getScalingFactor(), algorithm);
+		scaler.scaleSurfaceIntegerFactor(ENGINE->screenHandler().getScalingFactor(), algorithm);
 		SDL_FreeSurface(atlasImage);
 		atlasImage = scaler.acquireResultSurface();
 	}
@@ -269,7 +269,7 @@ bool CBitmapFont::canRepresentString(const std::string & data) const
 
 void CBitmapFont::renderCharacter(SDL_Surface * surface, const BitmapChar & character, const ColorRGBA & color, int &posX, int &posY) const
 {
-	int scalingFactor = GH.screenHandler().getScalingFactor();
+	int scalingFactor = ENGINE->screenHandler().getScalingFactor();
 
 	posX += character.leftOffset * scalingFactor;
 

+ 7 - 7
client/renderSDL/CursorHardware.cpp

@@ -14,7 +14,7 @@
 #include "SDL_Extensions.h"
 #include "SDLImageScaler.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/IScreenHandler.h"
 #include "../render/Colors.h"
 #include "../render/IImage.h"
@@ -38,7 +38,7 @@ CursorHardware::~CursorHardware()
 
 void CursorHardware::setVisible(bool on)
 {
-	GH.dispatchMainThread([on]()
+	ENGINE->dispatchMainThread([on]()
 	{
 		if (on)
 			SDL_ShowCursor(SDL_ENABLE);
@@ -49,18 +49,18 @@ void CursorHardware::setVisible(bool on)
 
 void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivotOffset)
 {
-	int videoScalingSettings = GH.screenHandler().getInterfaceScalingPercentage();
+	int videoScalingSettings = ENGINE->screenHandler().getInterfaceScalingPercentage();
 	float cursorScalingSettings = settings["video"]["cursorScalingFactor"].Float();
 	int cursorScalingPercent = videoScalingSettings * cursorScalingSettings;
-	Point cursorDimensions = image->dimensions() * GH.screenHandler().getScalingFactor();
+	Point cursorDimensions = image->dimensions() * ENGINE->screenHandler().getScalingFactor();
 	Point cursorDimensionsScaled = image->dimensions() * cursorScalingPercent / 100;
-	Point pivotOffsetScaled = pivotOffset * cursorScalingPercent / 100 / GH.screenHandler().getScalingFactor();
+	Point pivotOffsetScaled = pivotOffset * cursorScalingPercent / 100 / ENGINE->screenHandler().getScalingFactor();
 
 	auto cursorSurface = CSDL_Ext::newSurface(cursorDimensions);
 
 	CSDL_Ext::fillSurface(cursorSurface, CSDL_Ext::toSDL(Colors::TRANSPARENCY));
 
-	image->draw(cursorSurface, Point(0,0), nullptr, GH.screenHandler().getScalingFactor());
+	image->draw(cursorSurface, Point(0,0), nullptr, ENGINE->screenHandler().getScalingFactor());
 
 	SDLImageScaler scaler(cursorSurface);
 	scaler.scaleSurface(cursorDimensionsScaled, EScalingAlgorithm::BILINEAR);
@@ -75,7 +75,7 @@ void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivot
 	SDL_FreeSurface(cursorSurface);
 	SDL_FreeSurface(cursorSurfaceScaled);
 
-	GH.dispatchMainThread([this, oldCursor](){
+	ENGINE->dispatchMainThread([this, oldCursor](){
 		SDL_SetCursor(cursor);
 
 		if (oldCursor)

+ 5 - 5
client/renderSDL/CursorSoftware.cpp

@@ -11,7 +11,7 @@
 #include "StdInc.h"
 #include "CursorSoftware.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/IScreenHandler.h"
 #include "../render/Colors.h"
 #include "../render/IImage.h"
@@ -59,16 +59,16 @@ void CursorSoftware::createTexture(const Point & dimensions)
 void CursorSoftware::updateTexture()
 {
 	if (!cursorSurface)
-		createTexture(cursorImage->dimensions() * GH.screenHandler().getScalingFactor());
+		createTexture(cursorImage->dimensions() * ENGINE->screenHandler().getScalingFactor());
 
 	Point currentSize = Point(cursorSurface->w, cursorSurface->h);
 
-	if (currentSize != cursorImage->dimensions() * GH.screenHandler().getScalingFactor())
-		createTexture(cursorImage->dimensions() * GH.screenHandler().getScalingFactor());
+	if (currentSize != cursorImage->dimensions() * ENGINE->screenHandler().getScalingFactor())
+		createTexture(cursorImage->dimensions() * ENGINE->screenHandler().getScalingFactor());
 
 	CSDL_Ext::fillSurface(cursorSurface, CSDL_Ext::toSDL(Colors::TRANSPARENCY));
 
-	cursorImage->draw(cursorSurface, Point(0,0), nullptr, GH.screenHandler().getScalingFactor());
+	cursorImage->draw(cursorSurface, Point(0,0), nullptr, ENGINE->screenHandler().getScalingFactor());
 	SDL_UpdateTexture(cursorTexture, nullptr, cursorSurface->pixels, cursorSurface->pitch);
 	needUpdate = false;
 }

+ 2 - 2
client/renderSDL/RenderHandler.cpp

@@ -14,7 +14,7 @@
 #include "ScalableImage.h"
 #include "FontChain.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 
 #include "../render/AssetGenerator.h"
 #include "../render/CAnimation.h"
@@ -170,7 +170,7 @@ RenderHandler::AnimationLayoutMap & RenderHandler::getAnimationLayout(const Anim
 
 int RenderHandler::getScalingFactor() const
 {
-	return GH.screenHandler().getScalingFactor();
+	return ENGINE->screenHandler().getScalingFactor();
 }
 
 ImageLocator RenderHandler::getLocatorForAnimationFrame(const AnimationPath & path, int frame, int group, int scaling, EImageBlitMode mode)

+ 2 - 2
client/renderSDL/SDLImage.cpp

@@ -17,7 +17,7 @@
 #include "../render/ColorFilter.h"
 #include "../render/CBitmapHandler.h"
 #include "../render/CDefFile.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/IScreenHandler.h"
 
 #include <tbb/parallel_for.h>
@@ -256,7 +256,7 @@ SDLImageShared::SDLImageShared(const SDLImageShared * from, int integerScaleFact
 
 	const auto & scalingTask = [this, algorithm, scaler]()
 	{
-		scaler->scaleSurfaceIntegerFactor(GH.screenHandler().getScalingFactor(), algorithm);
+		scaler->scaleSurfaceIntegerFactor(ENGINE->screenHandler().getScalingFactor(), algorithm);
 		surf = scaler->acquireResultSurface();
 		fullSize = scaler->getResultDimensions().dimensions();
 		margins = scaler->getResultDimensions().topLeft();

+ 1 - 1
client/renderSDL/SDL_Extensions.cpp

@@ -12,7 +12,7 @@
 
 #include "SDL_PixelAccess.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../render/Graphics.h"
 #include "../render/IImage.h"
 #include "../render/IScreenHandler.h"

+ 8 - 8
client/renderSDL/ScalableImage.cpp

@@ -13,7 +13,7 @@
 #include "SDLImage.h"
 #include "SDL_Extensions.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 
 #include "../render/ColorFilter.h"
 #include "../render/Colors.h"
@@ -225,7 +225,7 @@ ScalableImageShared::ScalableImageShared(const SharedImageLocator & locator, con
 	scaled[1].body[0] = baseImage;
 	assert(scaled[1].body[0] != nullptr);
 
-	loadScaledImages(GH.screenHandler().getScalingFactor(), PlayerColor::CANNOT_DETERMINE);
+	loadScaledImages(ENGINE->screenHandler().getScalingFactor(), PlayerColor::CANNOT_DETERMINE);
 }
 
 Point ScalableImageShared::dimensions() const
@@ -333,7 +333,7 @@ void ScalableImageInstance::scaleTo(const Point & size, EScalingAlgorithm algori
 {
 	scaledImage = nullptr;
 
-	auto newScaledImage = GH.renderHandler().createImage(dimensions(), CanvasScalingPolicy::AUTO);
+	auto newScaledImage = ENGINE->renderHandler().createImage(dimensions(), CanvasScalingPolicy::AUTO);
 
 	newScaledImage->getCanvas().draw(*this, Point(0, 0));
 	newScaledImage->scaleTo(size, algorithm);
@@ -358,7 +358,7 @@ Rect ScalableImageInstance::contentRect() const
 Point ScalableImageInstance::dimensions() const
 {
 	if (scaledImage)
-		return scaledImage->dimensions() / GH.screenHandler().getScalingFactor();
+		return scaledImage->dimensions() / ENGINE->screenHandler().getScalingFactor();
 	return image->dimensions();
 }
 
@@ -451,7 +451,7 @@ std::shared_ptr<const ISharedImage> ScalableImageShared::loadOrGenerateImage(EIm
 	loadingLocator.playerColored = color;
 
 	// best case - requested image is already available in filesystem
-	auto loadedFullMatchImage = GH.renderHandler().loadScaledImage(loadingLocator);
+	auto loadedFullMatchImage = ENGINE->renderHandler().loadScaledImage(loadingLocator);
 	if (loadedFullMatchImage)
 		return loadedFullMatchImage;
 
@@ -475,7 +475,7 @@ std::shared_ptr<const ISharedImage> ScalableImageShared::loadOrGenerateImage(EIm
 	for (int8_t scaling = 4; scaling > 0; --scaling)
 	{
 		loadingLocator.scalingFactor = scaling;
-		auto loadedImage = GH.renderHandler().loadScaledImage(loadingLocator);
+		auto loadedImage = ENGINE->renderHandler().loadScaledImage(loadingLocator);
 		if (loadedImage)
 		{
 			if (scaling == 1)
@@ -597,12 +597,12 @@ void ScalableImageShared::loadScaledImages(int8_t scalingFactor, PlayerColor col
 
 void ScalableImageShared::preparePlayerColoredImage(PlayerColor color)
 {
-	loadScaledImages(GH.screenHandler().getScalingFactor(), color);
+	loadScaledImages(ENGINE->screenHandler().getScalingFactor(), color);
 }
 
 void ScalableImageShared::prepareEffectImage()
 {
-	int scalingFactor = GH.screenHandler().getScalingFactor();
+	int scalingFactor = ENGINE->screenHandler().getScalingFactor();
 
 	if (scaled[scalingFactor].bodyGrayscale[0] == nullptr)
 	{

+ 1 - 1
client/renderSDL/ScreenHandler.cpp

@@ -14,7 +14,7 @@
 #include "../CGameInfo.h"
 #include "../CMT.h"
 #include "../eventsSDL/NotificationHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/CursorHandler.h"
 #include "../gui/WindowHandler.h"
 #include "../render/Canvas.h"

+ 5 - 5
client/widgets/Buttons.cpp

@@ -18,7 +18,7 @@
 #include "../battle/BattleInterface.h"
 #include "../battle/BattleInterfaceClasses.h"
 #include "../eventsSDL/InputHandler.h"
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/MouseButton.h"
 #include "../gui/Shortcut.h"
 #include "../gui/InterfaceObjectConfigurable.h"
@@ -258,7 +258,7 @@ void CButton::clickPressed(const Point & cursorPosition)
 		if (!soundDisabled)
 		{
 			CCS->soundh->playSound(soundBase::button);
-			GH.input().hapticFeedback();
+			ENGINE->input().hapticFeedback();
 		}
 		setState(EButtonState::PRESSED);
 
@@ -320,9 +320,9 @@ void CButton::hover (bool on)
 	if(!name.empty() && !isBlocked()) //if there is no name, there is nothing to display also
 	{
 		if (on)
-			GH.statusbar()->write(name);
+			ENGINE->statusbar()->write(name);
 		else
-			GH.statusbar()->clearIfMatching(name);
+			ENGINE->statusbar()->clearIfMatching(name);
 	}
 }
 
@@ -485,7 +485,7 @@ void CToggleButton::clickPressed(const Point & cursorPosition)
 	if (canActivate())
 	{
 		CCS->soundh->playSound(soundBase::button);
-		GH.input().hapticFeedback();
+		ENGINE->input().hapticFeedback();
 		setState(EButtonState::PRESSED);
 	}
 }

+ 1 - 1
client/widgets/CArtifactsOfHeroBackpack.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CArtifactsOfHeroBackpack.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 
 #include "Images.h"
 #include "IGameSettings.h"

+ 1 - 1
client/widgets/CArtifactsOfHeroBase.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CArtifactsOfHeroBase.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 
 #include "Buttons.h"

+ 1 - 1
client/widgets/CArtifactsOfHeroMain.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CArtifactsOfHeroMain.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 
 #include "../CPlayerInterface.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"

+ 2 - 2
client/widgets/CComponent.cpp

@@ -12,7 +12,7 @@
 
 #include "Images.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/CursorHandler.h"
 #include "../gui/TextAlignment.h"
 #include "../gui/Shortcut.h"
@@ -98,7 +98,7 @@ void CComponent::init(ComponentType Type, ComponentSubType Subtype, std::optiona
 		max = 80;
 
 	std::vector<std::string> textLines = CMessage::breakText(getSubtitle(), std::max<int>(max, pos.w), font);
-	const auto & fontPtr = GH.renderHandler().loadFont(font);
+	const auto & fontPtr = ENGINE->renderHandler().loadFont(font);
 	const int height = static_cast<int>(fontPtr->getLineHeight());
 
 	for(auto & line : textLines)

+ 1 - 1
client/widgets/CComponentHolder.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CComponentHolder.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/Shortcut.h"
 
 #include "CComponent.h"

+ 13 - 13
client/widgets/CGarrisonInt.cpp

@@ -14,7 +14,7 @@
 #include "TextControls.h"
 #include "RadialMenu.h"
 
-#include "../gui/CGuiHandler.h"
+#include "../GameEngine.h"
 #include "../gui/WindowHandler.h"
 #include "../render/IImage.h"
 #include "../windows/CCreatureWindow.h"
@@ -121,11 +121,11 @@ void CGarrisonSlot::hover (bool on)
 				temp = CGI->generaltexth->tcommands[11]; //Empty
 			}
 		}
-		GH.statusbar()->write(temp);
+		ENGINE->statusbar()->write(temp);
 	}
 	else
 	{
-		GH.statusbar()->clear();
+		ENGINE->statusbar()->clear();
 	}
 }
 
@@ -178,7 +178,7 @@ bool CGarrisonSlot::viewInfo()
 		elem->block(true);
 
 	redraw();
-	GH.windows().createAndPushWindow<CStackWindow>(myStack, dism, pom, upgr);
+	ENGINE->windows().createAndPushWindow<CStackWindow>(myStack, dism, pom, upgr);
 	return true;
 }
 
@@ -187,7 +187,7 @@ bool CGarrisonSlot::viewInfo()
 bool CGarrisonSlot::highlightOrDropArtifact()
 {
 	bool artSelected = false;
-	if (auto chw = GH.windows().topWindow<CWindowWithArtifacts>()) //dirty solution
+	if (auto chw = ENGINE->windows().topWindow<CWindowWithArtifacts>()) //dirty solution
 	{
 		const auto pickedArtInst = chw->getPickedArtifact();
 
@@ -262,7 +262,7 @@ bool CGarrisonSlot::split()
 		owner->splitStacks(selection, owner->army(upg), ID, amountRight);
 	};
 
-	GH.windows().createAndPushWindow<CSplitWindow>(selection->creature,  splitFunctor, minLeft, minRight, countLeft, countRight);
+	ENGINE->windows().createAndPushWindow<CSplitWindow>(selection->creature,  splitFunctor, minLeft, minRight, countLeft, countRight);
 	return true;
 }
 
@@ -300,7 +300,7 @@ void CGarrisonSlot::showPopupWindow(const Point & cursorPosition)
 {
 	if(creature)
 	{
-		GH.windows().createAndPushWindow<CStackWindow>(myStack, true);
+		ENGINE->windows().createAndPushWindow<CStackWindow>(myStack, true);
 	}
 }
 
@@ -338,7 +338,7 @@ void CGarrisonSlot::clickPressed(const Point & cursorPosition)
 				lastHeroStackSelected = true;
 			}
 
-			if((owner->getSplittingMode() || GH.isKeyboardShiftDown()) // split window
+			if((owner->getSplittingMode() || ENGINE->isKeyboardShiftDown()) // split window
 				&& (!creature || creature == selection->creature))
 			{
 				refr = split();
@@ -371,7 +371,7 @@ void CGarrisonSlot::gesture(bool on, const Point & initialPosition, const Point
 	if (!settings["input"]["radialWheelGarrisonSwipe"].Bool())
 		return;
 
-	if(GH.windows().topWindow<CIntObject>()->isPopupWindow())
+	if(ENGINE->windows().topWindow<CIntObject>()->isPopupWindow())
 		return;
 
 	const auto * otherArmy = upg == EGarrisonType::UPPER ? owner->lowerArmy() : owner->upperArmy();
@@ -393,7 +393,7 @@ void CGarrisonSlot::gesture(bool on, const Point & initialPosition, const Point
 	};
 
 	if (hasAnyEmptySlots || hasSameUnit)
-		GH.windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements);
+		ENGINE->windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements);
 }
 
 void CGarrisonSlot::update()
@@ -487,9 +487,9 @@ void CGarrisonSlot::splitIntoParts(EGarrisonType type, int amount)
 
 bool CGarrisonSlot::handleSplittingShortcuts()
 {
-	const bool isAlt = GH.isKeyboardAltDown();
-	const bool isLShift = GH.isKeyboardShiftDown();
-	const bool isLCtrl = GH.isKeyboardCmdDown();
+	const bool isAlt = ENGINE->isKeyboardAltDown();
+	const bool isLShift = ENGINE->isKeyboardShiftDown();
+	const bool isLCtrl = ENGINE->isKeyboardCmdDown();
 
 	if(!isAlt && !isLShift && !isLCtrl)
 		return false; // This is only case when return false

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff