Skip to content

Commit eb975da

Browse files
committed
Latency calc logic moved to service config
1 parent af19d94 commit eb975da

2 files changed

Lines changed: 48 additions & 24 deletions

File tree

‎GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_Init.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ struct ServiceConfig
266266
bool network_do_immediate_flush_per_frame = true;
267267
int network_send_flags = -1;
268268

269-
NLOHMANN_DEFINE_TYPE_INTRUSIVE(ServiceConfig, retry_signalling, use_mapped_port, min_run_ahead_frames, ra_update_frequency_frames, relay_all_traffic, ra_slack_percent, frame_grouping_frames, enable_host_migration, network_do_immediate_flush_per_frame, network_send_flags)
269+
int network_latency_logic_model = 0;
270+
271+
NLOHMANN_DEFINE_TYPE_INTRUSIVE(ServiceConfig, retry_signalling, use_mapped_port, min_run_ahead_frames, ra_update_frequency_frames, relay_all_traffic, ra_slack_percent, frame_grouping_frames, enable_host_migration, network_do_immediate_flush_per_frame, network_send_flags, network_latency_logic_model)
270272
};
271273

272274
class NGMP_OnlineServicesManager
@@ -431,6 +433,10 @@ class NGMP_OnlineServicesManager
431433
static void CaptureScreenshotToDisk();
432434
static void CaptureScreenshotForProbe(EScreenshotType screenshotType);
433435

436+
static bool g_bAdvancedNetworkStats;
437+
static void ToggleAdvancedNetworkStats() { g_bAdvancedNetworkStats = !g_bAdvancedNetworkStats; }
438+
static bool IsAdvancedNetworkStatsEnabled() { return g_bAdvancedNetworkStats; }
439+
434440
/*
435441
NGMP_OnlineServices_AuthInterface* GetAuthInterface() const { return m_pAuthInterface; }
436442
NGMP_OnlineServices_LobbyInterface* GetLobbyInterface() const { return m_pLobbyInterface; }

‎GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp‎

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,38 +1380,56 @@ void ConnectionManager::updateRunAhead(Int oldRunAhead, Int frameRate, Bool didS
13801380
}
13811381
}
13821382

1383-
Real ConnectionManager::getMaximumLatency() {
1384-
#if defined(GENERALS_ONLINE)
1385-
Real Maxlat = 0.0f;
1383+
Real ConnectionManager::getMaximumLatency()
1384+
{
1385+
ServiceConfig& serviceConf = NGMP_OnlineServicesManager::GetInstance()->GetServiceConfig();
1386+
int latencyLogicModel = serviceConf.network_latency_logic_model;
1387+
// 0 = original
1388+
// 1 = pick highest between original and Valve latency (current)
1389+
// 2 = pick highest between original and Valve latency (historic)
1390+
1391+
Real maxLatency = 0.0f;
13861392

13871393
for (Int i = 0; i < MAX_SLOTS; ++i) {
1388-
if (isPlayerConnected(i) && m_latencyAverages[i] > Maxlat) {
1389-
Maxlat = m_latencyAverages[i];
1394+
if (isPlayerConnected(i) && m_latencyAverages[i] > maxLatency) {
1395+
maxLatency = m_latencyAverages[i];
13901396
}
13911397
}
13921398

1393-
// TheSuperHackers @info the latencyAverage is the roundtrip latency
1394-
return Maxlat;
1395-
#else
1396-
// This works for 2 player games because the latency for the packet router is always 0.
1397-
Real lat1 = 0.0;
1398-
Real lat2 = 0.0;
13991399

1400-
for (Int i = 0; i < MAX_SLOTS; ++i) {
1401-
if (isPlayerConnected(i)) {
1402-
if (m_latencyAverages[i] != 0.0) {
1403-
if (m_latencyAverages[i] > lat1) {
1404-
lat2 = lat1;
1405-
lat1 = m_latencyAverages[i];
1406-
} else if (m_latencyAverages[i] > lat2) {
1407-
lat2 = m_latencyAverages[i];
1408-
}
1409-
}
1400+
if (latencyLogicModel == 0)
1401+
{
1402+
return maxLatency;
1403+
}
1404+
else if (latencyLogicModel == 1)
1405+
{
1406+
NetworkMesh* pMesh = NGMP_OnlineServicesManager::GetNetworkMesh();
1407+
1408+
if (pMesh != nullptr)
1409+
{
1410+
Real maxGOLatency = (pMesh->getMaximumLatency() / 1000.f);
1411+
return maxLatency > maxGOLatency ? maxLatency : maxGOLatency;
1412+
}
1413+
else
1414+
{
1415+
return maxLatency;
1416+
}
1417+
}
1418+
else if (latencyLogicModel == 2)
1419+
{
1420+
NetworkMesh* pMesh = NGMP_OnlineServicesManager::GetNetworkMesh();
1421+
if (pMesh != nullptr)
1422+
{
1423+
Real maxGOLatency = (pMesh->getMaximumHistoricalLatency() / 1000.f);
1424+
return maxLatency > maxGOLatency ? maxLatency : maxGOLatency;
1425+
}
1426+
else
1427+
{
1428+
return maxLatency;
14101429
}
14111430
}
14121431

1413-
return (lat1 + lat2);
1414-
#endif
1432+
return maxLatency;
14151433
}
14161434

14171435
void ConnectionManager::getMinimumFps(Int &minFps, Int &minFpsPlayer) {

0 commit comments

Comments
 (0)