Changeset 25170
- Timestamp:
- Mar 31, 2021, 5:55:19 PM (3 years ago)
- Location:
- ps/trunk/source
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/network/NetClientTurnManager.cpp
r25003 r25170 85 85 m_Replay.Hash(hash, quick); 86 86 87 // Don't send the hash if OOS88 if (m_HasSyncError)89 return;90 91 87 // Send message to the server 92 88 CSyncCheckMessage msg; … … 115 111 NETCLIENTTURN_LOG("OnSyncError(%d, %hs)\n", turn, expectedHashHex.c_str()); 116 112 117 // Only complain the first time118 if (m_HasSyncError)119 return;120 121 m_HasSyncError = true;122 123 113 std::string hash; 124 114 ENSURE(m_Simulation2.ComputeStateHash(hash, !TurnNeedsFullHash(turn))); … … 126 116 OsPath oosdumpPath(psLogDir() / (L"oos_dump" + g_UniqueLogPostfix + L".txt")); 127 117 std::ofstream file (OsString(oosdumpPath).c_str(), std::ofstream::out | std::ofstream::trunc); 118 119 128 120 m_Simulation2.DumpDebugState(file); 129 121 file.close(); -
ps/trunk/source/network/NetServerTurnManager.cpp
r25156 r25170 36 36 37 37 CNetServerTurnManager::CNetServerTurnManager(CNetServerWorker& server) 38 : m_NetServer(server), m_ReadyTurn(COMMAND_DELAY_MP - 1), m_TurnLength(DEFAULT_TURN_LENGTH) , m_HasSyncError(false)38 : m_NetServer(server), m_ReadyTurn(COMMAND_DELAY_MP - 1), m_TurnLength(DEFAULT_TURN_LENGTH) 39 39 { 40 40 // Turn 0 is not actually executed, store a dummy value. … … 53 53 54 54 // Must be a client we've already heard of 55 ENSURE(m_Clients Ready.find(client) != m_ClientsReady.end());55 ENSURE(m_Clients.end()); 56 56 57 57 // Clients must advance one turn at a time 58 if (turn != m_Clients Ready[client]+ 1)58 if (turn != m_Clients + 1) 59 59 { 60 60 LOGERROR("NotifyFinishedClientCommands: Client %d (%s) is ready for turn %d, but expected %d", … … 62 62 utf8_from_wstring(session.GetUserName()).c_str(), 63 63 turn, 64 m_Clients Ready[client]+ 1);64 m_Clients + 1); 65 65 66 66 session.Disconnect(NDR_INCORRECT_READY_TURN_COMMANDS); 67 67 } 68 68 69 m_Clients Ready[client]= turn;69 m_Clients = turn; 70 70 71 71 // Check whether this was the final client to become ready … … 81 81 82 82 // See if all clients (including self) are ready for a new turn 83 for (const std::pair<const int, u32>& clientReady : m_ClientsReady)83 for (const std::pair<const int, ) 84 84 { 85 85 // Observers are allowed to lag more than regular clients. 86 if ( m_ClientsObserver[clientReady.first] && (max_observer_lag == -1 || clientReady.second> m_ReadyTurn - max_observer_lag))86 if ( > m_ReadyTurn - max_observer_lag)) 87 87 continue; 88 88 NETSERVERTURN_LOG(" %d: %d <=? %d\n", clientReady.first, clientReady.second, m_ReadyTurn); 89 if (client Ready.second<= m_ReadyTurn)89 if (client <= m_ReadyTurn) 90 90 return; // wasn't ready for m_ReadyTurn+1 91 91 } … … 112 112 113 113 // Clients must advance one turn at a time 114 if (turn != m_Clients Simulated[client]+ 1)114 if (turn != m_Clients + 1) 115 115 { 116 116 LOGERROR("NotifyFinishedClientUpdate: Client %d (%s) is ready for turn %d, but expected %d", … … 118 118 utf8_from_wstring(playername).c_str(), 119 119 turn, 120 m_Clients Ready[client]+ 1);120 m_Clients + 1); 121 121 122 122 session.Disconnect(NDR_INCORRECT_READY_TURN_SIMULATED); 123 123 } 124 124 125 m_Clients Simulated[client]= turn;125 m_Clients = turn; 126 126 127 127 // Check for OOS only if in sync … … 129 129 return; 130 130 131 m_Client Playernames[client]= playername;131 m_Client = playername; 132 132 m_ClientStateHashes[turn][client] = hash; 133 133 134 134 // Find the newest turn which we know all clients have simulated 135 135 u32 newest = std::numeric_limits<u32>::max(); 136 for (const std::pair<const int, u32>& clientSimulated : m_ClientsSimulated)137 if (client Simulated.second< newest)138 newest = client Simulated.second;136 for (const std::pair<const int, ) 137 if (client < newest) 138 newest = client; 139 139 140 140 // For every set of state hashes that all clients have simulated, check for OOS … … 156 156 // Oh no, out of sync 157 157 m_HasSyncError = true; 158 OOSPlayerNames.push_back(m_ClientPlayernames[hashPair.first]); 158 m_ClientsData[hashPair.first].isOOS = true; 159 OOSPlayerNames.push_back(m_ClientsData[hashPair.first].playerName); 159 160 } 160 161 } … … 185 186 NETSERVERTURN_LOG("InitialiseClient(client=%d, turn=%d)\n", client, turn); 186 187 187 ENSURE(m_ClientsReady.find(client) == m_ClientsReady.end()); 188 m_ClientsReady[client] = turn + COMMAND_DELAY_MP - 1; 189 m_ClientsSimulated[client] = turn; 190 m_ClientsObserver[client] = observer; 188 ENSURE(m_ClientsData.find(client) == m_ClientsData.end()); 189 Client& data = m_ClientsData[client]; 190 data.readyTurn = turn + COMMAND_DELAY_MP - 1; 191 data.simulatedTurn = turn; 192 data.isObserver = observer; 191 193 } 192 194 … … 195 197 NETSERVERTURN_LOG("UninitialiseClient(client=%d)\n", client); 196 198 197 ENSURE(m_ClientsReady.find(client) != m_ClientsReady.end()); 198 m_ClientsReady.erase(client); 199 m_ClientsSimulated.erase(client); 200 m_ClientsObserver.erase(client); 199 ENSURE(m_ClientsData.find(client) != m_ClientsData.end()); 200 bool checkOOS = m_ClientsData[client].isOOS; 201 m_ClientsData.erase(client); 201 202 202 203 // Check whether we're ready for the next turn now that we're not 203 204 // waiting for this client any more 204 205 CheckClientsReady(); 206 207 208 209 210 211 212 213 214 205 215 } 206 216 -
ps/trunk/source/network/NetServerTurnManager.h
r25156 r25170 73 73 void CheckClientsReady(); 74 74 75 /// The latest turn for which we have received all commands from all clients 76 u32 m_ReadyTurn; 75 struct Client 76 { 77 CStrW playerName; 78 // Latest turn for which all commands have been received. 79 u32 readyTurn; 80 // Last known simulated turn. 81 u32 simulatedTurn; 82 bool isObserver; 83 bool isOOS = false; 84 }; 77 85 78 // Client ID -> whether they are only an observer. 79 std::unordered_map<int, bool> m_ClientsObserver; 86 std::unordered_map<int, Client> m_ClientsData; 80 87 81 // Client ID -> ready turn number (the latest turn for which all commands have been received from that client) 82 std::map<int, u32> m_ClientsReady; 83 84 // Client ID -> last known simulated turn number (for which we have the state hash) 85 // (the client has reached the start of this turn, not done the update for it yet) 86 std::map<int, u32> m_ClientsSimulated; 88 // Cached value - is any client OOS? This is reset when the OOS client leaves. 89 bool m_HasSyncError = false; 87 90 88 91 // Map of turn -> {Client ID -> state hash}; old indexes <= min(m_ClientsSimulated) are deleted 89 92 std::map<u32, std::map<int, std::string>> m_ClientStateHashes; 90 93 91 // Map of client ID -> playername92 std::map<int, CStrW> m_ClientPlayernames;94 // 95 ; 93 96 94 97 // Current turn length … … 99 102 100 103 CNetServerWorker& m_NetServer; 101 102 bool m_HasSyncError;103 104 }; 104 105 -
ps/trunk/source/simulation2/Simulation2.cpp
r25003 r25170 886 886 bool CSimulation2::DumpDebugState(std::ostream& stream) 887 887 { 888 888 889 return m->m_ComponentManager.DumpDebugState(stream, true); 889 890 } -
ps/trunk/source/simulation2/system/ReplayTurnManager.h
r24764 r25170 1 /* Copyright (C) 202 0Wildfire Games.1 /* Copyright (C) 202 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 45 45 static const CStr EventNameReplayOutOfSync; 46 46 47 48 47 49 // Contains the commands of every player on each turn 48 50 std::map<u32, std::vector<std::pair<player_id_t, std::string>>> m_ReplayCommands; -
ps/trunk/source/simulation2/system/TurnManager.cpp
r25156 r25170 41 41 CTurnManager::CTurnManager(CSimulation2& simulation, u32 defaultTurnLength, u32 commandDelay, int clientId, IReplayLogger& replay) 42 42 : m_Simulation2(simulation), m_CurrentTurn(0), m_CommandDelay(commandDelay), m_ReadyTurn(commandDelay - 1), m_TurnLength(defaultTurnLength), 43 m_PlayerId(-1), m_ClientId(clientId), m_DeltaSimTime(0), m_ HasSyncError(false), m_Replay(replay),43 m_PlayerId(-1), m_ClientId(clientId), m_DeltaSimTime(0), m_Replay(replay), 44 44 m_FinalTurn(std::numeric_limits<u32>::max()), m_TimeWarpNumTurns(0), 45 45 m_QuickSaveMetadata(m_Simulation2.GetScriptInterface().GetGeneralJSContext()) -
ps/trunk/source/simulation2/system/TurnManager.h
r25156 r25170 210 210 float m_DeltaSimTime; 211 211 212 bool m_HasSyncError;213 214 212 IReplayLogger& m_Replay; 215 213
Note:
See TracChangeset
for help on using the changeset viewer.