1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Added serialization of turn timer handler

This commit is contained in:
Ivan Savenko 2024-04-26 13:16:02 +03:00
parent 090a1c7764
commit 5010344df0
4 changed files with 17 additions and 4 deletions

View File

@ -39,6 +39,7 @@ enum class ESerializationVersion : int32_t
JSON_FLAGS, // 836 json uses new format for flags JSON_FLAGS, // 836 json uses new format for flags
MANA_LIMIT, // 837 change MANA_PER_KNOWLEGDE to percentage MANA_LIMIT, // 837 change MANA_PER_KNOWLEGDE to percentage
BONUS_META_STRING, // 838 bonuses use MetaString instead of std::string for descriptions BONUS_META_STRING, // 838 bonuses use MetaString instead of std::string for descriptions
TURN_TIMERS_STATE, // 839 current state of turn timers is serialized
CURRENT = BONUS_META_STRING CURRENT = TURN_TIMERS_STATE
}; };

View File

@ -230,6 +230,9 @@ public:
h & *playerMessages; h & *playerMessages;
h & *turnOrder; h & *turnOrder;
if (h.version >= Handler::Version::TURN_TIMERS_STATE)
h & *turnTimerHandler;
#if SCRIPTING_ENABLED #if SCRIPTING_ENABLED
JsonNode scriptsState; JsonNode scriptsState;
if(h.saving) if(h.saving)

View File

@ -25,7 +25,7 @@ class CGameHandler;
class TurnTimerHandler class TurnTimerHandler
{ {
CGameHandler & gameHandler; CGameHandler & gameHandler;
const int turnTimePropagateFrequency = 1000; static constexpr int turnTimePropagateFrequency = 1000;
std::map<PlayerColor, TurnTimerInfo> timers; std::map<PlayerColor, TurnTimerInfo> timers;
std::map<PlayerColor, int> lastUpdate; std::map<PlayerColor, int> lastUpdate;
std::map<PlayerColor, bool> endTurnAllowed; std::map<PlayerColor, bool> endTurnAllowed;
@ -48,4 +48,11 @@ public:
void update(int waitTime); void update(int waitTime);
void setTimerEnabled(PlayerColor player, bool enabled); void setTimerEnabled(PlayerColor player, bool enabled);
void setEndTurnAllowed(PlayerColor player, bool enabled); void setEndTurnAllowed(PlayerColor player, bool enabled);
template<typename Handler>
void serialize(Handler & h)
{
h & timers;
h & endTurnAllowed;
}
}; };

View File

@ -249,10 +249,12 @@ void TurnOrderProcessor::doStartPlayerTurn(PlayerColor which)
assert(gameHandler->getPlayerState(which)); assert(gameHandler->getPlayerState(which));
assert(gameHandler->getPlayerState(which)->status == EPlayerStatus::INGAME); assert(gameHandler->getPlayerState(which)->status == EPlayerStatus::INGAME);
//Note: on game load, "actingPlayer" might already contain list of players // Only if player is actually starting his turn (and not loading from save)
if (!actingPlayers.count(which))
gameHandler->onPlayerTurnStarted(which);
actingPlayers.insert(which); actingPlayers.insert(which);
awaitingPlayers.erase(which); awaitingPlayers.erase(which);
gameHandler->onPlayerTurnStarted(which);
auto turnQuery = std::make_shared<TimerPauseQuery>(gameHandler, which); auto turnQuery = std::make_shared<TimerPauseQuery>(gameHandler, which);
gameHandler->queries->addQuery(turnQuery); gameHandler->queries->addQuery(turnQuery);