Changeset 25001
- Timestamp:
- Mar 3, 2021, 10:02:57 PM (3 years ago)
- Location:
- ps/trunk/source
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/main.cpp
r24891 r25001 469 469 470 470 static u32 turn = 0; 471 debug_printf("Turn %u (%u)...\n", turn++, DEFAULT_TURN_LENGTH _SP);472 473 g_Game->GetSimulation2()->Update(DEFAULT_TURN_LENGTH _SP);471 debug_printf("Turn %u (%u)...\n", turn++, DEFAULT_TURN_LENGTH); 472 473 g_Game->GetSimulation2()->Update(DEFAULT_TURN_LENGTH); 474 474 475 475 g_Profiler.Frame(); -
ps/trunk/source/network/NetClient.cpp
r24952 r25001 41 41 #include "network/StunClient.h" 42 42 43 44 45 46 47 48 49 50 43 51 CNetClient *g_NetClient = NULL; 44 52 … … 335 343 } 336 344 337 // Report if we have a bad ping to the server 345 // Report if we have a bad ping to the server 338 346 u32 meanRTT = m_Session->GetMeanRTT(); 339 if (meanRTT > DEFAULT_TURN_LENGTH_MP)347 if (meanRTT > ) 340 348 { 341 349 PushGuiMessage( … … 858 866 for (size_t i = 0; i < message->m_Clients.size(); ++i) 859 867 { 860 if (message->m_Clients[i].m_MeanRTT < DEFAULT_TURN_LENGTH_MP|| message->m_Clients[i].m_GUID == client->m_GUID)868 if (message->m_Clients[i].m_MeanRTT < || message->m_Clients[i].m_GUID == client->m_GUID) 861 869 continue; 862 870 -
ps/trunk/source/network/NetClientTurnManager.cpp
r22867 r25001 37 37 38 38 CNetClientTurnManager::CNetClientTurnManager(CSimulation2& simulation, CNetClient& client, int clientId, IReplayLogger& replay) 39 : CTurnManager(simulation, DEFAULT_TURN_LENGTH _MP, clientId, replay), m_NetClient(client)39 : CTurnManager(simulation, DEFAULT_TURN_LENGTH_MP, clientId, replay), m_NetClient(client) 40 40 { 41 41 } … … 46 46 47 47 // Transmit command to server 48 CSimulationMessage msg(m_Simulation2.GetScriptInterface(), m_ClientId, m_PlayerId, m_CurrentTurn + COMMAND_DELAY, data);48 CSimulationMessage msg(m_Simulation2.GetScriptInterface(), m_ClientId, m_PlayerId, m_CurrentTurn + , data); 49 49 m_NetClient.SendMessage(&msg); 50 50 51 51 // Add to our local queue 52 //AddCommand(m_ClientId, m_PlayerId, data, m_CurrentTurn + COMMAND_DELAY);52 //AddCommand(m_ClientId, m_PlayerId, data, m_CurrentTurn + ); 53 53 // TODO: we should do this when the server stops sending our commands back to us 54 54 } … … 99 99 // Notice the sending is not reliable and rarely makes it to the Server. 100 100 if (m_NetClient.GetCurrState() == NCS_INGAME) 101 NotifyFinishedOwnCommands(m_CurrentTurn + COMMAND_DELAY);101 NotifyFinishedOwnCommands(m_CurrentTurn + ); 102 102 } 103 103 -
ps/trunk/source/network/NetServer.cpp
r24952 r25001 68 68 static const int HOST_SERVICE_TIMEOUT = 50; 69 69 70 71 72 73 74 75 76 77 70 78 CNetServer* g_NetServer = NULL; 71 79 … … 605 613 } 606 614 // Report if the client has bad ping 607 else if (meanRTT > DEFAULT_TURN_LENGTH_MP)615 else if (meanRTT > ) 608 616 { 609 617 CClientPerformanceMessage* msg = new CClientPerformanceMessage(); -
ps/trunk/source/network/NetServerTurnManager.cpp
r24512 r25001 28 28 29 29 #if 0 30 30 31 #define NETSERVERTURN_LOG(...) debug_printf(__VA_ARGS__) 31 32 #else … … 34 35 35 36 CNetServerTurnManager::CNetServerTurnManager(CNetServerWorker& server) 36 : m_NetServer(server), m_ReadyTurn( 1), m_TurnLength(DEFAULT_TURN_LENGTH_MP), m_HasSyncError(false)37 : m_NetServer(server), m_ReadyTurn(), m_HasSyncError(false) 37 38 { 38 39 // Turn 0 is not actually executed, store a dummy value. 39 40 m_SavedTurnLengths.push_back(0); 40 // Turn 1 is special: all clients run it without waiting on a server command batch. 41 // Because of this, it is always run with the default MP turn length. 42 m_SavedTurnLengths.push_back(m_TurnLength); 41 // Turns [1..COMMAND_DELAY - 1] are special: all clients run them without waiting on a server command batch. 42 // Because of this, they are always run with the default MP turn length. 43 for (u32 i = 1; i < COMMAND_DELAY_MP; ++i) 44 m_SavedTurnLengths.push_back(m_TurnLength); 43 45 } 44 46 … … 140 142 for (const std::pair<const int, std::string>& hashPair : clientStateHash.second) 141 143 { 142 NETSERVERTURN_LOG("sync check %d: %d = %hs\n", it->first, cit->first, Hexify(cit->second).c_str());144 NETSERVERTURN_LOG("sync check %d: %d = %hs\n", second).c_str()); 143 145 if (hashPair.second != expected) 144 146 { … … 175 177 176 178 ENSURE(m_ClientsReady.find(client) == m_ClientsReady.end()); 177 m_ClientsReady[client] = turn + 1;179 m_ClientsReady[client] = turn + 1; 178 180 m_ClientsSimulated[client] = turn; 179 181 } -
ps/trunk/source/rlinterface/RLInterface.cpp
r24962 r25001 390 390 } 391 391 392 const u32 deltaRealTime = DEFAULT_TURN_LENGTH _SP;392 const u32 deltaRealTime = DEFAULT_TURN_LENGTH; 393 393 if (nonVisual) 394 394 { -
ps/trunk/source/simulation2/system/LocalTurnManager.cpp
r23917 r25001 21 21 22 22 CLocalTurnManager::CLocalTurnManager(CSimulation2& simulation, IReplayLogger& replay) 23 : CTurnManager(simulation, DEFAULT_TURN_LENGTH _SP, 0, replay)23 : CTurnManager(simulation, DEFAULT_TURN_LENGTH_SP, 0, replay) 24 24 { 25 25 } … … 27 27 void CLocalTurnManager::PostCommand(player_id_t playerid, JS::HandleValue data) 28 28 { 29 AddCommand(m_ClientId, playerid, data, m_CurrentTurn + 1);29 AddCommand(m_ClientId, playerid, data, m_CurrentTurn + ); 30 30 } 31 31 32 32 void CLocalTurnManager::PostCommand(JS::HandleValue data) 33 33 { 34 // Add directly to the next turn, ignoring COMMAND_DELAY, 35 // because we don't need to compensate for network latency 36 AddCommand(m_ClientId, m_PlayerId, data, m_CurrentTurn + 1); 34 AddCommand(m_ClientId, m_PlayerId, data, m_CurrentTurn + m_CommandDelay); 37 35 } 38 36 -
ps/trunk/source/simulation2/system/TurnManager.cpp
r24333 r25001 31 31 #include "simulation2/Simulation2.h" 32 32 33 const u32 DEFAULT_TURN_LENGTH_MP = 500;34 const u32 DEFAULT_TURN_LENGTH_SP = 200;35 36 const int COMMAND_DELAY = 2;37 38 33 #if 0 39 34 #define NETTURN_LOG(...) debug_printf(__VA_ARGS__) … … 42 37 #endif 43 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 44 53 const CStr CTurnManager::EventNameSavegameLoaded = "SavegameLoaded"; 45 54 46 CTurnManager::CTurnManager(CSimulation2& simulation, u32 defaultTurnLength, int clientId, IReplayLogger& replay)47 : m_Simulation2(simulation), m_CurrentTurn(0), m_ ReadyTurn(1), m_TurnLength(defaultTurnLength),55 CTurnManager::CTurnManager(CSimulation2& simulation, u32 defaultTurnLength, int clientId, IReplayLogger& replay) 56 : m_Simulation2(simulation), m_CurrentTurn(0), m_1), m_TurnLength(defaultTurnLength), 48 57 m_PlayerId(-1), m_ClientId(clientId), m_DeltaSimTime(0), m_HasSyncError(false), m_Replay(replay), 49 58 m_FinalTurn(std::numeric_limits<u32>::max()), m_TimeWarpNumTurns(0), 50 59 m_QuickSaveMetadata(m_Simulation2.GetScriptInterface().GetGeneralJSContext()) 51 60 { 52 // When we are on turn n, we schedule new commands for n+2. 53 // We know that all other clients have finished scheduling commands for n (else we couldn't have got here). 54 // We know we have not yet finished scheduling commands for n+2. 55 // Hence other clients can be on turn n-1, n, n+1, and no other. 56 // So they can be sending us commands scheduled for n+1, n+2, n+3. 57 // So we need a 3-element buffer: 58 m_QueuedCommands.resize(COMMAND_DELAY + 1); 61 // Lag between any two clients is bounded. Add 1 for inclusive bounds. 62 m_QueuedCommands.resize(MaxClientTurnDelta(m_CommandDelay) + 1); 59 63 } 60 64 … … 109 113 110 114 // Check that the next turn is ready for execution 111 if (m_ReadyTurn <= m_CurrentTurn )115 if (m_ReadyTurn <= m_CurrentTurn) 112 116 { 113 117 // Oops, we wanted to start the next turn but it's not ready yet - … … 133 137 134 138 // Check that the i'th next turn is still ready 135 if (m_ReadyTurn <= m_CurrentTurn )139 if (m_ReadyTurn <= m_CurrentTurn) 136 140 break; 137 141 138 NotifyFinishedOwnCommands(m_CurrentTurn + COMMAND_DELAY);142 NotifyFinishedOwnCommands(m_CurrentTurn + ); 139 143 140 144 // Increase now, so Update can send new commands for a subsequent turn … … 232 236 void CTurnManager::AddCommand(int client, int player, JS::HandleValue data, u32 turn) 233 237 { 234 NETTURN_LOG("AddCommand(client=%d player=%d turn=%d)\n", client, player, turn); 235 236 if (!(m_CurrentTurn < turn && turn <= m_CurrentTurn + COMMAND_DELAY + 1)) 238 NETTURN_LOG("AddCommand(client=%d player=%d turn=%d current=%d, ready=%d)\n", client, player, turn, m_CurrentTurn, m_ReadyTurn); 239 240 // Reject commands for turns that we should not be able to compute (in the past or too far future). 241 if (m_CurrentTurn >= turn || turn > m_CurrentTurn + MaxClientTurnDelta(m_CommandDelay) + 1) 237 242 { 238 243 debug_warn(L"Received command for invalid turn"); -
ps/trunk/source/simulation2/system/TurnManager.h
r23917 r25001 30 30 class CSimulation2; 31 31 class IReplayLogger; 32 33 extern const u32 DEFAULT_TURN_LENGTH_SP;34 extern const u32 DEFAULT_TURN_LENGTH_MP;35 36 extern const int COMMAND_DELAY;37 32 38 33 /** … … 55 50 56 51 /** 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 57 77 * Common turn system (used by clients and offline games). 58 78 */ … … 64 84 * Construct for a given network session ID. 65 85 */ 66 CTurnManager(CSimulation2& simulation, u32 defaultTurnLength, int clientId, IReplayLogger& replay);86 CTurnManager(CSimulation2& simulation, u32 defaultTurnLength, int clientId, IReplayLogger& replay); 67 87 68 88 virtual ~CTurnManager() { } … … 165 185 u32 m_CurrentTurn; 166 186 187 188 189 167 190 /// The latest turn for which we have received all commands from all clients 168 191 u32 m_ReadyTurn;
Note:
See TracChangeset
for help on using the changeset viewer.