From 6df58255871cb00c9867f145c630071084ad65aa Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Sun, 17 May 2026 21:24:23 +0200 Subject: [PATCH 1/4] perf(network): Remove extern and add const to global network variables. --- Core/GameEngine/Include/GameNetwork/NetworkDefs.h | 12 +++++++----- Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp | 8 -------- .../Code/GameEngine/Source/Common/CommandLine.cpp | 12 ------------ 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h index 8976cc0a040..d30063c0f44 100644 --- a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h +++ b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h @@ -32,14 +32,16 @@ static const Int WOL_NAME_LEN = 64; /// Max number of commands per frame static const Int MAX_COMMANDS = 256; -extern Int MIN_LOGIC_FRAMES; -extern Int MAX_FRAMES_AHEAD; -extern Int MIN_RUNAHEAD; +// TheSuperHackers @tweak Mauller 26/08/2025 reduce the minimum runahead from 10 +// This lets network games run at latencies down to 133ms when the network conditions allow +static const Int MIN_LOGIC_FRAMES = 5; +static const Int MAX_FRAMES_AHEAD = 128; +static const Int MIN_RUNAHEAD = 4; // FRAME_DATA_LENGTH needs to be MAX_FRAMES_AHEAD+1 because a player on a different // computer can send commands for a frame that is one beyond twice the max runahead. -extern Int FRAME_DATA_LENGTH; -extern Int FRAMES_TO_KEEP; +static const Int FRAME_DATA_LENGTH = (MAX_FRAMES_AHEAD + 1) * 2; +static const Int FRAMES_TO_KEEP = (MAX_FRAMES_AHEAD / 2) + 1; // This is the connection numbering: 1-8 are for players enum ConnectionNumbers CPP_11(: Int) diff --git a/Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp b/Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp index 174599cc97c..f340529bfed 100644 --- a/Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp +++ b/Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp @@ -27,14 +27,6 @@ #include "GameNetwork/networkutil.h" -// TheSuperHackers @tweak Mauller 26/08/2025 reduce the minimum runahead from 10 -// This lets network games run at latencies down to 133ms when the network conditions allow -Int MIN_LOGIC_FRAMES = 5; -Int MAX_FRAMES_AHEAD = 128; -Int MIN_RUNAHEAD = 4; -Int FRAME_DATA_LENGTH = (MAX_FRAMES_AHEAD+1)*2; -Int FRAMES_TO_KEEP = (MAX_FRAMES_AHEAD/2) + 1; - #ifdef DEBUG_LOGGING void dumpBufferToLog(const void *vBuf, Int len, const char *fname, Int line) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp index cd2284943a5..543576d78fc 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp @@ -868,17 +868,6 @@ Int parseSelectAll( char *args[], int num ) return 1; } - -Int parseRunAhead( char *args[], Int num ) -{ - if (num > 2) - { - MIN_RUNAHEAD = atoi(args[1]); - MAX_FRAMES_AHEAD = atoi(args[2]); - FRAME_DATA_LENGTH = (MAX_FRAMES_AHEAD + 1)*2; - } - return 3; -} #endif @@ -1279,7 +1268,6 @@ static CommandLineParam paramsForEngineInit[] = { "-logToCon", parseLogToConsole }, { "-vTune", parseVTune }, { "-selectTheUnselectable", parseSelectAll }, - { "-RunAhead", parseRunAhead }, #if ENABLE_CONFIGURABLE_SHROUD { "-noshroud", parseNoShroud }, #endif From fb7426384776255449dc02ebe70d4e54d258319c Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Mon, 18 May 2026 17:26:04 +0200 Subject: [PATCH 2/4] Changed variables to 'static constexpr const'. --- Core/GameEngine/Include/GameNetwork/NetworkDefs.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h index d30063c0f44..21c2a7a53c0 100644 --- a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h +++ b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h @@ -34,14 +34,14 @@ static const Int MAX_COMMANDS = 256; // TheSuperHackers @tweak Mauller 26/08/2025 reduce the minimum runahead from 10 // This lets network games run at latencies down to 133ms when the network conditions allow -static const Int MIN_LOGIC_FRAMES = 5; -static const Int MAX_FRAMES_AHEAD = 128; -static const Int MIN_RUNAHEAD = 4; +static constexpr const Int MIN_LOGIC_FRAMES = 5; +static constexpr const Int MAX_FRAMES_AHEAD = 128; +static constexpr const Int MIN_RUNAHEAD = 4; // FRAME_DATA_LENGTH needs to be MAX_FRAMES_AHEAD+1 because a player on a different // computer can send commands for a frame that is one beyond twice the max runahead. -static const Int FRAME_DATA_LENGTH = (MAX_FRAMES_AHEAD + 1) * 2; -static const Int FRAMES_TO_KEEP = (MAX_FRAMES_AHEAD / 2) + 1; +static constexpr const Int FRAME_DATA_LENGTH = (MAX_FRAMES_AHEAD + 1) * 2; +static constexpr const Int FRAMES_TO_KEEP = (MAX_FRAMES_AHEAD / 2) + 1; // This is the connection numbering: 1-8 are for players enum ConnectionNumbers CPP_11(: Int) From db89f7f7e79d0c42a43595bc2f02477a31b1e215 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Mon, 18 May 2026 20:45:06 +0200 Subject: [PATCH 3/4] Changed more variables to 'static constexpr const'. --- .../Include/GameNetwork/NetworkDefs.h | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h index 21c2a7a53c0..274a5d6a346 100644 --- a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h +++ b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h @@ -27,10 +27,10 @@ #include "Lib/BaseType.h" #include "Common/MessageStream.h" -static const Int WOL_NAME_LEN = 64; +static constexpr const Int WOL_NAME_LEN = 64; /// Max number of commands per frame -static const Int MAX_COMMANDS = 256; +static constexpr const Int MAX_COMMANDS = 256; // TheSuperHackers @tweak Mauller 26/08/2025 reduce the minimum runahead from 10 // This lets network games run at latencies down to 133ms when the network conditions allow @@ -87,7 +87,7 @@ static constexpr const Int MAX_MESSAGES = 256; * Command packet - contains frame #, total # of commands, and each command. This is what gets sent * to each player every frame */ -static const Int numCommandsPerCommandPacket = (MAX_NETWORK_MESSAGE_LEN - sizeof(UnsignedInt) - sizeof(UnsignedShort))/sizeof(GameMessage); +static constexpr const Int numCommandsPerCommandPacket = (MAX_NETWORK_MESSAGE_LEN - sizeof(UnsignedInt) - sizeof(UnsignedShort))/sizeof(GameMessage); #pragma pack(push, 1) struct CommandPacket { @@ -195,38 +195,38 @@ enum PlayerLeaveCode CPP_11(: Int) { }; // Magic number for identifying a Generals packet. -static const UnsignedShort GENERALS_MAGIC_NUMBER = 0xF00D; +static constexpr const UnsignedShort GENERALS_MAGIC_NUMBER = 0xF00D; // The number of fps history entries. -//static const Int NETWORK_FPS_HISTORY_LENGTH = 30; +//static constexpr const Int NETWORK_FPS_HISTORY_LENGTH = 30; // The number of ping history entries. -//static const Int NETWORK_LATENCY_HISTORY_LENGTH = 200; +//static constexpr const Int NETWORK_LATENCY_HISTORY_LENGTH = 200; // The number of miliseconds between run ahead metrics things -//static const Int NETWORK_RUN_AHEAD_METRICS_TIME = 5000; +//static constexpr const Int NETWORK_RUN_AHEAD_METRICS_TIME = 5000; // The number of cushion values to keep. -//static const Int NETWORK_CUSHION_HISTORY_LENGTH = 10; +//static constexpr const Int NETWORK_CUSHION_HISTORY_LENGTH = 10; // The amount of slack in the run ahead value. This is the percentage of the calculated run ahead that is added. -//static const Int NETWORK_RUN_AHEAD_SLACK = 20; +//static constexpr const Int NETWORK_RUN_AHEAD_SLACK = 20; // The number of seconds between when the connections to each player send a keep-alive packet. // This should be less than 30 just to keep firewall ports open. -//static const Int NETWORK_KEEPALIVE_DELAY = 20; +//static constexpr const Int NETWORK_KEEPALIVE_DELAY = 20; // The number of milliseconds between when the game gets stuck on a frame for a network stall and // and when the disconnect dialog comes up. -//static const Int NETWORK_DISCONNECT_TIME = 5000; +//static constexpr const Int NETWORK_DISCONNECT_TIME = 5000; // The number of miliseconds between when a player's last disconnect keep alive command // was received and when they are considered disconnected from the game. -//static const Int NETWORK_PLAYER_TIMEOUT_TIME = 60000; +//static constexpr const Int NETWORK_PLAYER_TIMEOUT_TIME = 60000; // The base port number used for the transport socket. A players slot number is added to this // value to get their actual port number. -static const Int NETWORK_BASE_PORT_NUMBER = 8088; +static constexpr const Int NETWORK_BASE_PORT_NUMBER = 8088; // the singleton class NetworkInterface; From 359875d7fe2f2e14bfce8724bbfdd96429175415 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Mon, 18 May 2026 20:45:44 +0200 Subject: [PATCH 4/4] Replicated in Generals. --- .../Code/GameEngine/Source/Common/CommandLine.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Generals/Code/GameEngine/Source/Common/CommandLine.cpp b/Generals/Code/GameEngine/Source/Common/CommandLine.cpp index cd2284943a5..543576d78fc 100644 --- a/Generals/Code/GameEngine/Source/Common/CommandLine.cpp +++ b/Generals/Code/GameEngine/Source/Common/CommandLine.cpp @@ -868,17 +868,6 @@ Int parseSelectAll( char *args[], int num ) return 1; } - -Int parseRunAhead( char *args[], Int num ) -{ - if (num > 2) - { - MIN_RUNAHEAD = atoi(args[1]); - MAX_FRAMES_AHEAD = atoi(args[2]); - FRAME_DATA_LENGTH = (MAX_FRAMES_AHEAD + 1)*2; - } - return 3; -} #endif @@ -1279,7 +1268,6 @@ static CommandLineParam paramsForEngineInit[] = { "-logToCon", parseLogToConsole }, { "-vTune", parseVTune }, { "-selectTheUnselectable", parseSelectAll }, - { "-RunAhead", parseRunAhead }, #if ENABLE_CONFIGURABLE_SHROUD { "-noshroud", parseNoShroud }, #endif