From 090a1c7764ec1c3f18097e6c09f961f0f39ad836 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 26 Apr 2024 13:15:39 +0300 Subject: [PATCH] TurnTimerHandler is now a unique_ptr --- server/CGameHandler.cpp | 10 +++++----- server/CGameHandler.h | 3 +-- server/battles/BattleFlowProcessor.cpp | 4 ++-- server/battles/BattleResultProcessor.cpp | 2 +- server/queries/MapQueries.cpp | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index d89e77c33..854b0c9c9 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -514,7 +514,7 @@ CGameHandler::CGameHandler(CVCMIServer * lobby) , complainNoCreatures("No creatures to split") , complainNotEnoughCreatures("Cannot split that stack, not enough creatures!") , complainInvalidSlot("Invalid slot accessed!") - , turnTimerHandler(*this) + , turnTimerHandler(std::make_unique(*this)) { QID = 1; applier = std::make_shared>(); @@ -616,7 +616,7 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa void CGameHandler::onPlayerTurnStarted(PlayerColor which) { events::PlayerGotTurn::defaultExecute(serverEventBus.get(), which); - turnTimerHandler.onPlayerGetTurn(which); + turnTimerHandler->onPlayerGetTurn(which); } void CGameHandler::onPlayerTurnEnded(PlayerColor which) @@ -1009,7 +1009,7 @@ void CGameHandler::start(bool resume) onNewTurn(); events::TurnStarted::defaultExecute(serverEventBus.get()); for(auto & player : gs->players) - turnTimerHandler.onGameplayStart(player.first); + turnTimerHandler->onGameplayStart(player.first); } else events::GameResumed::defaultExecute(serverEventBus.get()); @@ -1019,7 +1019,7 @@ void CGameHandler::start(bool resume) void CGameHandler::tick(int millisecondsPassed) { - turnTimerHandler.update(millisecondsPassed); + turnTimerHandler->update(millisecondsPassed); } void CGameHandler::giveSpells(const CGTownInstance *t, const CGHeroInstance *h) @@ -1307,7 +1307,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo if(h->boat && !h->boat->onboardAssaultAllowed) lookForGuards = IGNORE_GUARDS; - turnTimerHandler.setEndTurnAllowed(h->getOwner(), !movingOntoWater && !movingOntoObstacle); + turnTimerHandler->setEndTurnAllowed(h->getOwner(), !movingOntoWater && !movingOntoObstacle); doMove(TryMoveHero::SUCCESS, lookForGuards, visitDest, LEAVING_TILE); return true; } diff --git a/server/CGameHandler.h b/server/CGameHandler.h index a61c74774..dffb78584 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -62,6 +62,7 @@ public: std::unique_ptr battles; std::unique_ptr queries; std::unique_ptr turnOrder; + std::unique_ptr turnTimerHandler; //use enums as parameters, because doMove(sth, true, false, true) is not readable enum EGuardLook {CHECK_FOR_GUARDS, IGNORE_GUARDS}; @@ -76,8 +77,6 @@ public: ui32 QID; SpellCastEnvironment * spellEnv; - - TurnTimerHandler turnTimerHandler; const Services * services() const override; const BattleCb * battle(const BattleID & battleID) const override; diff --git a/server/battles/BattleFlowProcessor.cpp b/server/battles/BattleFlowProcessor.cpp index aca32f764..1179627ca 100644 --- a/server/battles/BattleFlowProcessor.cpp +++ b/server/battles/BattleFlowProcessor.cpp @@ -126,7 +126,7 @@ void BattleFlowProcessor::onBattleStarted(const CBattleInfoCallback & battle) { tryPlaceMoats(battle); - gameHandler->turnTimerHandler.onBattleStart(battle.getBattle()->getBattleID()); + gameHandler->turnTimerHandler->onBattleStart(battle.getBattle()->getBattleID()); if (battle.battleGetTacticDist() == 0) onTacticsEnded(battle); @@ -319,7 +319,7 @@ void BattleFlowProcessor::activateNextStack(const CBattleInfoCallback & battle) if(!removeGhosts.changedStacks.empty()) gameHandler->sendAndApply(&removeGhosts); - gameHandler->turnTimerHandler.onBattleNextStack(battle.getBattle()->getBattleID(), *next); + gameHandler->turnTimerHandler->onBattleNextStack(battle.getBattle()->getBattleID(), *next); if (!tryMakeAutomaticAction(battle, next)) { diff --git a/server/battles/BattleResultProcessor.cpp b/server/battles/BattleResultProcessor.cpp index a2d161d1e..bbb2ad51f 100644 --- a/server/battles/BattleResultProcessor.cpp +++ b/server/battles/BattleResultProcessor.cpp @@ -292,7 +292,7 @@ void BattleResultProcessor::endBattle(const CBattleInfoCallback & battle) otherBattleQuery->result = battleQuery->result; } - gameHandler->turnTimerHandler.onBattleEnd(battle.getBattle()->getBattleID()); + gameHandler->turnTimerHandler->onBattleEnd(battle.getBattle()->getBattleID()); gameHandler->sendAndApply(battleResult); if (battleResult->queryID == QueryID::NONE) diff --git a/server/queries/MapQueries.cpp b/server/queries/MapQueries.cpp index f3c62cb41..dbc7752eb 100644 --- a/server/queries/MapQueries.cpp +++ b/server/queries/MapQueries.cpp @@ -30,12 +30,12 @@ bool TimerPauseQuery::blocksPack(const CPack *pack) const void TimerPauseQuery::onAdding(PlayerColor color) { - gh->turnTimerHandler.setTimerEnabled(color, false); + gh->turnTimerHandler->setTimerEnabled(color, false); } void TimerPauseQuery::onRemoval(PlayerColor color) { - gh->turnTimerHandler.setTimerEnabled(color, true); + gh->turnTimerHandler->setTimerEnabled(color, true); } bool TimerPauseQuery::endsByPlayerAnswer() const