mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Increase MP Command delay to 4 turns, decrease MP turns to 200ms.
To hide network latency, MP turns send commands not for the next turn but N turns after that (introduced inc684c211a2). Further, MP turn length was increased to 500ms compared to 200ms SP turns (introduced in6a15b78c98). Unfortunately, increasing MP turn length has negative consequences: - makes pathfinding/unit motion much worse & unit behaviour worse in general. - makes the game more 'lag-spikey', since computations are done less often, but thus then can take more time. This diff essentially reverts6a15b78c98, instead increasing COMMAND_DELAY from 2 to 4 in MP. This: - Reduces the 'inherent command lag' in MP from 1000ms to 800ms - Increases the lag range at which MP will run smoothtly from 500ms to 600ms - makes SP and MP turns behave identically again, removing the hindrances described above. As a side effect, single-player was not actually using COMMAND_DELAY, this is now done (can be used to simulate MP command lag). Refs #3752 Differential Revision: https://code.wildfiregames.com/D3275 This was SVN commit r25001.
This commit is contained in:
@@ -40,6 +40,14 @@
|
||||
#include "simulation2/Simulation2.h"
|
||||
#include "network/StunClient.h"
|
||||
|
||||
/**
|
||||
* Once ping goes above turn length * command delay,
|
||||
* the game will start 'freezing' for other clients while we catch up.
|
||||
* Since commands are sent client -> server -> client, divide by 2.
|
||||
* (duplicated in NetServer.cpp to avoid having to fetch the constants in a header file)
|
||||
*/
|
||||
constexpr u32 NETWORK_BAD_PING = DEFAULT_TURN_LENGTH * COMMAND_DELAY_MP / 2;
|
||||
|
||||
CNetClient *g_NetClient = NULL;
|
||||
|
||||
/**
|
||||
@@ -334,9 +342,9 @@ void CNetClient::CheckServerConnection()
|
||||
return;
|
||||
}
|
||||
|
||||
// Report if we have a bad ping to the server
|
||||
// Report if we have a bad ping to the server.
|
||||
u32 meanRTT = m_Session->GetMeanRTT();
|
||||
if (meanRTT > DEFAULT_TURN_LENGTH_MP)
|
||||
if (meanRTT > NETWORK_BAD_PING)
|
||||
{
|
||||
PushGuiMessage(
|
||||
"type", "netwarn",
|
||||
@@ -857,7 +865,7 @@ bool CNetClient::OnClientPerformance(void *context, CFsmEvent* event)
|
||||
// Display warnings for other clients with bad ping
|
||||
for (size_t i = 0; i < message->m_Clients.size(); ++i)
|
||||
{
|
||||
if (message->m_Clients[i].m_MeanRTT < DEFAULT_TURN_LENGTH_MP || message->m_Clients[i].m_GUID == client->m_GUID)
|
||||
if (message->m_Clients[i].m_MeanRTT < NETWORK_BAD_PING || message->m_Clients[i].m_GUID == client->m_GUID)
|
||||
continue;
|
||||
|
||||
client->PushGuiMessage(
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
extern CStrW g_UniqueLogPostfix;
|
||||
|
||||
CNetClientTurnManager::CNetClientTurnManager(CSimulation2& simulation, CNetClient& client, int clientId, IReplayLogger& replay)
|
||||
: CTurnManager(simulation, DEFAULT_TURN_LENGTH_MP, clientId, replay), m_NetClient(client)
|
||||
: CTurnManager(simulation, DEFAULT_TURN_LENGTH, COMMAND_DELAY_MP, clientId, replay), m_NetClient(client)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -45,11 +45,11 @@ void CNetClientTurnManager::PostCommand(JS::HandleValue data)
|
||||
NETCLIENTTURN_LOG("PostCommand()\n");
|
||||
|
||||
// Transmit command to server
|
||||
CSimulationMessage msg(m_Simulation2.GetScriptInterface(), m_ClientId, m_PlayerId, m_CurrentTurn + COMMAND_DELAY, data);
|
||||
CSimulationMessage msg(m_Simulation2.GetScriptInterface(), m_ClientId, m_PlayerId, m_CurrentTurn + m_CommandDelay, data);
|
||||
m_NetClient.SendMessage(&msg);
|
||||
|
||||
// Add to our local queue
|
||||
//AddCommand(m_ClientId, m_PlayerId, data, m_CurrentTurn + COMMAND_DELAY);
|
||||
//AddCommand(m_ClientId, m_PlayerId, data, m_CurrentTurn + m_CommandDelay);
|
||||
// TODO: we should do this when the server stops sending our commands back to us
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ void CNetClientTurnManager::OnDestroyConnection()
|
||||
// Attempt to flush messages before leaving.
|
||||
// Notice the sending is not reliable and rarely makes it to the Server.
|
||||
if (m_NetClient.GetCurrState() == NCS_INGAME)
|
||||
NotifyFinishedOwnCommands(m_CurrentTurn + COMMAND_DELAY);
|
||||
NotifyFinishedOwnCommands(m_CurrentTurn + m_CommandDelay);
|
||||
}
|
||||
|
||||
void CNetClientTurnManager::OnSimulationMessage(CSimulationMessage* msg)
|
||||
|
||||
@@ -67,6 +67,14 @@ constexpr int FAILED_PASSWORD_TRIES_BEFORE_BAN = 3;
|
||||
*/
|
||||
static const int HOST_SERVICE_TIMEOUT = 50;
|
||||
|
||||
/**
|
||||
* Once ping goes above turn length * command delay,
|
||||
* the game will start 'freezing' for other clients while we catch up.
|
||||
* Since commands are sent client -> server -> client, divide by 2.
|
||||
* (duplicated in NetServer.cpp to avoid having to fetch the constants in a header file)
|
||||
*/
|
||||
constexpr u32 NETWORK_BAD_PING = DEFAULT_TURN_LENGTH * COMMAND_DELAY_MP / 2;
|
||||
|
||||
CNetServer* g_NetServer = NULL;
|
||||
|
||||
static CStr DebugName(CNetServerSession* session)
|
||||
@@ -604,7 +612,7 @@ void CNetServerWorker::CheckClientConnections()
|
||||
message = msg;
|
||||
}
|
||||
// Report if the client has bad ping
|
||||
else if (meanRTT > DEFAULT_TURN_LENGTH_MP)
|
||||
else if (meanRTT > NETWORK_BAD_PING)
|
||||
{
|
||||
CClientPerformanceMessage* msg = new CClientPerformanceMessage();
|
||||
CClientPerformanceMessage::S_m_Clients client;
|
||||
|
||||
@@ -27,19 +27,21 @@
|
||||
#include "simulation2/system/TurnManager.h"
|
||||
|
||||
#if 0
|
||||
#include "ps/Util.h"
|
||||
#define NETSERVERTURN_LOG(...) debug_printf(__VA_ARGS__)
|
||||
#else
|
||||
#define NETSERVERTURN_LOG(...)
|
||||
#endif
|
||||
|
||||
CNetServerTurnManager::CNetServerTurnManager(CNetServerWorker& server)
|
||||
: m_NetServer(server), m_ReadyTurn(1), m_TurnLength(DEFAULT_TURN_LENGTH_MP), m_HasSyncError(false)
|
||||
: m_NetServer(server), m_ReadyTurn(COMMAND_DELAY_MP - 1), m_TurnLength(DEFAULT_TURN_LENGTH), m_HasSyncError(false)
|
||||
{
|
||||
// Turn 0 is not actually executed, store a dummy value.
|
||||
m_SavedTurnLengths.push_back(0);
|
||||
// Turn 1 is special: all clients run it without waiting on a server command batch.
|
||||
// Because of this, it is always run with the default MP turn length.
|
||||
m_SavedTurnLengths.push_back(m_TurnLength);
|
||||
// Turns [1..COMMAND_DELAY - 1] are special: all clients run them without waiting on a server command batch.
|
||||
// Because of this, they are always run with the default MP turn length.
|
||||
for (u32 i = 1; i < COMMAND_DELAY_MP; ++i)
|
||||
m_SavedTurnLengths.push_back(m_TurnLength);
|
||||
}
|
||||
|
||||
void CNetServerTurnManager::NotifyFinishedClientCommands(CNetServerSession& session, u32 turn)
|
||||
@@ -139,7 +141,7 @@ void CNetServerTurnManager::NotifyFinishedClientUpdate(CNetServerSession& sessio
|
||||
std::vector<CStrW> OOSPlayerNames;
|
||||
for (const std::pair<const int, std::string>& hashPair : clientStateHash.second)
|
||||
{
|
||||
NETSERVERTURN_LOG("sync check %d: %d = %hs\n", it->first, cit->first, Hexify(cit->second).c_str());
|
||||
NETSERVERTURN_LOG("sync check %d: %d = %hs\n", clientStateHash.first, hashPair.first, Hexify(hashPair.second).c_str());
|
||||
if (hashPair.second != expected)
|
||||
{
|
||||
// Oh no, out of sync
|
||||
@@ -174,7 +176,7 @@ void CNetServerTurnManager::InitialiseClient(int client, u32 turn)
|
||||
NETSERVERTURN_LOG("InitialiseClient(client=%d, turn=%d)\n", client, turn);
|
||||
|
||||
ENSURE(m_ClientsReady.find(client) == m_ClientsReady.end());
|
||||
m_ClientsReady[client] = turn + 1;
|
||||
m_ClientsReady[client] = turn + COMMAND_DELAY_MP - 1;
|
||||
m_ClientsSimulated[client] = turn;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user