2025-11-04 00:14:18 -08:00
|
|
|
/* Copyright (C) 2026 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2017-01-23 18:04:50 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2017-01-23 18:04:50 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2017-01-23 18:04:50 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2017-01-23 18:04:50 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef INCLUDED_NETCLIENTTURNMANAGER
|
|
|
|
|
#define INCLUDED_NETCLIENTTURNMANAGER
|
|
|
|
|
|
2025-07-06 11:15:27 -07:00
|
|
|
#include "lib/code_annotation.h"
|
|
|
|
|
#include "lib/types.h"
|
|
|
|
|
#include "network/NetMessage.h"
|
|
|
|
|
#include "ps/CStr.h"
|
2017-01-23 18:04:50 -08:00
|
|
|
#include "simulation2/system/TurnManager.h"
|
2025-07-06 11:15:27 -07:00
|
|
|
|
|
|
|
|
#include <js/TypeDecls.h>
|
|
|
|
|
#include <vector>
|
2017-01-23 18:04:50 -08:00
|
|
|
|
|
|
|
|
class CNetClient;
|
2025-07-06 11:15:27 -07:00
|
|
|
class CSimulation2;
|
|
|
|
|
class IReplayLogger;
|
2017-01-23 18:04:50 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implementation of CTurnManager for network clients.
|
|
|
|
|
*/
|
|
|
|
|
class CNetClientTurnManager : public CTurnManager
|
|
|
|
|
{
|
|
|
|
|
NONCOPYABLE(CNetClientTurnManager);
|
|
|
|
|
public:
|
|
|
|
|
CNetClientTurnManager(CSimulation2& simulation, CNetClient& client, int clientId, IReplayLogger& replay);
|
|
|
|
|
|
|
|
|
|
void OnSimulationMessage(CSimulationMessage* msg) override;
|
|
|
|
|
|
|
|
|
|
void PostCommand(JS::HandleValue data) override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Notify the server that all commands are sent to prepare the connection for termination.
|
|
|
|
|
*/
|
|
|
|
|
void OnDestroyConnection();
|
|
|
|
|
|
Use turn_id_t (int32_t) for turn-count across simulation, network and replay
CSimulation2 used , CSimulation2Impl mixed /, and
CTurnManager used for the same turn-count concept, forcing a
static_cast<int64_t> at the one place these types already met
(rejoin-test comparison).
Add (alias for std::int32_t) in SimulationCommand.h and use
it consistently for every turn counter in CSimulation2/Impl,
CTurnManager and its subclasses (CLocalTurnManager,
CReplayTurnManager), CNetServerTurnManager/CNetClientTurnManager, and
the network wire format (m_Turn in CEndCommandBatchMessage,
CSimulationMessage, CSyncCheckMessage, CSyncErrorMessage, and
m_CurrentTurn in CLoadedGameMessage).
Turn *duration* fields (m_TurnLength, m_CommandDelay,
DEFAULT_TURN_LENGTH, COMMAND_DELAY_SP/MP, SetTurnLength,
GetSavedTurnLength return type) are left as u32 — they're milliseconds,
not a counter, and out of scope here.
Remaining turn_id_t vs size_t comparisons use std::cmp_equal or
explicit casts, matching the existing pattern in Simulation2.cpp.
Fixes #8718
2026-06-26 21:04:27 -07:00
|
|
|
void OnSyncError(turn_id_t turn, const CStr& expectedHash, const std::vector<CSyncErrorMessage::S_m_PlayerNames>& playerNames);
|
2017-01-23 18:04:50 -08:00
|
|
|
|
|
|
|
|
private:
|
Use turn_id_t (int32_t) for turn-count across simulation, network and replay
CSimulation2 used , CSimulation2Impl mixed /, and
CTurnManager used for the same turn-count concept, forcing a
static_cast<int64_t> at the one place these types already met
(rejoin-test comparison).
Add (alias for std::int32_t) in SimulationCommand.h and use
it consistently for every turn counter in CSimulation2/Impl,
CTurnManager and its subclasses (CLocalTurnManager,
CReplayTurnManager), CNetServerTurnManager/CNetClientTurnManager, and
the network wire format (m_Turn in CEndCommandBatchMessage,
CSimulationMessage, CSyncCheckMessage, CSyncErrorMessage, and
m_CurrentTurn in CLoadedGameMessage).
Turn *duration* fields (m_TurnLength, m_CommandDelay,
DEFAULT_TURN_LENGTH, COMMAND_DELAY_SP/MP, SetTurnLength,
GetSavedTurnLength return type) are left as u32 — they're milliseconds,
not a counter, and out of scope here.
Remaining turn_id_t vs size_t comparisons use std::cmp_equal or
explicit casts, matching the existing pattern in Simulation2.cpp.
Fixes #8718
2026-06-26 21:04:27 -07:00
|
|
|
void NotifyFinishedOwnCommands(turn_id_t turn) override;
|
2017-01-23 18:04:50 -08:00
|
|
|
|
Use turn_id_t (int32_t) for turn-count across simulation, network and replay
CSimulation2 used , CSimulation2Impl mixed /, and
CTurnManager used for the same turn-count concept, forcing a
static_cast<int64_t> at the one place these types already met
(rejoin-test comparison).
Add (alias for std::int32_t) in SimulationCommand.h and use
it consistently for every turn counter in CSimulation2/Impl,
CTurnManager and its subclasses (CLocalTurnManager,
CReplayTurnManager), CNetServerTurnManager/CNetClientTurnManager, and
the network wire format (m_Turn in CEndCommandBatchMessage,
CSimulationMessage, CSyncCheckMessage, CSyncErrorMessage, and
m_CurrentTurn in CLoadedGameMessage).
Turn *duration* fields (m_TurnLength, m_CommandDelay,
DEFAULT_TURN_LENGTH, COMMAND_DELAY_SP/MP, SetTurnLength,
GetSavedTurnLength return type) are left as u32 — they're milliseconds,
not a counter, and out of scope here.
Remaining turn_id_t vs size_t comparisons use std::cmp_equal or
explicit casts, matching the existing pattern in Simulation2.cpp.
Fixes #8718
2026-06-26 21:04:27 -07:00
|
|
|
void NotifyFinishedUpdate(turn_id_t turn, const UpdateCallback& sendEventToAll) override;
|
2017-01-23 18:04:50 -08:00
|
|
|
|
|
|
|
|
CNetClient& m_NetClient;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // INCLUDED_NETCLIENTTURNMANAGER
|