Skip to content

Commit 98b1454

Browse files
committed
feat: Implement Latency counter FPS counter and FPS Limit
1 parent 48054ec commit 98b1454

File tree

6 files changed

+309
-12
lines changed

6 files changed

+309
-12
lines changed

GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ class GlobalData : public SubsystemInterface
407407
Bool m_saveCameraInReplay;
408408
Bool m_useCameraInReplay;
409409

410+
// TheSuperHackers @feature L3-M 05/09/2025 allow the network latency counter and render fps counter font size to be set, a size of zero disables them
411+
Int m_networkLatencyFontSize;
412+
Int m_renderFpsFontSize;
410413
// TheSuperHackers @feature Mauller 21/06/2025 allow the system time and game time font size to be set, a size of zero disables them
411414
Int m_systemTimeFontSize;
412415
Int m_gameTimeFontSize;

GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ class OptionPreferences : public UserPreferences
139139
Int getCampaignDifficulty(void);
140140
void setCampaignDifficulty( Int diff );
141141

142+
Int getNetworkLatencyFontSize(void);
143+
Int getRenderFpsFontSize(void);
142144
Int getSystemTimeFontSize(void);
143145
Int getGameTimeFontSize(void);
144146

GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ friend class Drawable; // for selection/deselection transactions
571571

572572
virtual void recreateControlBar( void );
573573
virtual void refreshCustomUiResources( void );
574+
virtual void refreshNetworkLatencyResources(void);
575+
virtual void refreshRenderFpsResources(void);
574576
virtual void refreshSystemTimeResources( void );
575577
virtual void refreshGameTimeResources( void );
576578

@@ -592,7 +594,10 @@ friend class Drawable; // for selection/deselection transactions
592594
virtual void updateIdleWorker( void );
593595
virtual void resetIdleWorker( void );
594596

595-
void drawSystemTime();
597+
void updateRenderFpsString();
598+
void drawNetworkLatency(Int &x, Int &y);
599+
void drawRenderFps(Int &x, Int &y);
600+
void drawSystemTime(Int &x, Int &y);
596601
void drawGameTime();
597602

598603
public:
@@ -753,6 +758,31 @@ friend class Drawable; // for selection/deselection transactions
753758
VideoBuffer* m_cameoVideoBuffer;///< video playback buffer
754759
VideoStreamInterface* m_cameoVideoStream;///< Video stream;
755760

761+
// Network Latency Counter
762+
DisplayString * m_networkLatencyString;
763+
AsciiString m_networkLatencyFont;
764+
Int m_networkLatencyPointSize;
765+
Bool m_networkLatencyBold;
766+
Coord2D m_networkLatencyPosition;
767+
Color m_networkLatencyColor;
768+
Color m_networkLatencyDropColor;
769+
UnsignedInt m_lastNetworkLatencyFrames;
770+
771+
// Render FPS Counter
772+
DisplayString * m_renderFpsString;
773+
DisplayString * m_renderFpsLimitString;
774+
AsciiString m_renderFpsFont;
775+
Int m_renderFpsPointSize;
776+
Bool m_renderFpsBold;
777+
Coord2D m_renderFpsPosition;
778+
Color m_renderFpsColor;
779+
Color m_renderFpsLimitColor;
780+
Color m_renderFpsDropColor;
781+
UnsignedInt m_renderFpsRefreshMs;
782+
UnsignedInt m_lastRenderFps;
783+
UnsignedInt m_lastRenderFpsLimit;
784+
UnsignedInt m_lastRenderFpsUpdateMs;
785+
756786
// System Time
757787
DisplayString * m_systemTimeString;
758788
AsciiString m_systemTimeFont;

GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,8 @@ GlobalData::GlobalData()
942942
m_saveCameraInReplay = FALSE;
943943
m_useCameraInReplay = FALSE;
944944

945+
m_networkLatencyFontSize = 8;
946+
m_renderFpsFontSize = 8;
945947
m_systemTimeFontSize = 8;
946948
m_gameTimeFontSize = 8;
947949

@@ -1212,6 +1214,8 @@ void GlobalData::parseGameDataDefinition( INI* ini )
12121214
TheWritableGlobalData->m_saveCameraInReplay = optionPref.saveCameraInReplays();
12131215
TheWritableGlobalData->m_useCameraInReplay = optionPref.useCameraInReplays();
12141216

1217+
TheWritableGlobalData->m_networkLatencyFontSize = optionPref.getNetworkLatencyFontSize();
1218+
TheWritableGlobalData->m_renderFpsFontSize = optionPref.getRenderFpsFontSize();
12151219
TheWritableGlobalData->m_systemTimeFontSize = optionPref.getSystemTimeFontSize();
12161220
TheWritableGlobalData->m_gameTimeFontSize = optionPref.getGameTimeFontSize();
12171221

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,34 @@ Real OptionPreferences::getMoneyTransactionVolume(void) const
858858
return volume;
859859
}
860860

861+
Int OptionPreferences::getNetworkLatencyFontSize(void)
862+
{
863+
OptionPreferences::const_iterator it = find("NetworkLatencyFontSize");
864+
if (it == end())
865+
return 8;
866+
867+
Int fontSize = atoi(it->second.str());
868+
if (fontSize < 0)
869+
{
870+
fontSize = 0;
871+
}
872+
return fontSize;
873+
}
874+
875+
Int OptionPreferences::getRenderFpsFontSize(void)
876+
{
877+
OptionPreferences::const_iterator it = find("RenderFpsFontSize");
878+
if (it == end())
879+
return 8;
880+
881+
Int fontSize = atoi(it->second.str());
882+
if (fontSize < 0)
883+
{
884+
fontSize = 0;
885+
}
886+
return fontSize;
887+
}
888+
861889
Int OptionPreferences::getSystemTimeFontSize(void)
862890
{
863891
OptionPreferences::const_iterator it = find("SystemTimeFontSize");
@@ -1430,6 +1458,28 @@ static void saveOptions( void )
14301458
}
14311459
}
14321460

1461+
//-------------------------------------------------------------------------------------------------
1462+
// Set Network Latency Font Size
1463+
val = pref->getNetworkLatencyFontSize();
1464+
if (val >= 0)
1465+
{
1466+
AsciiString prefString;
1467+
prefString.format("%d", val);
1468+
(*pref)["NetworkLatencyFontSize"] = prefString;
1469+
TheInGameUI->refreshNetworkLatencyResources();
1470+
}
1471+
1472+
//-------------------------------------------------------------------------------------------------
1473+
// Set Render FPS Font Size
1474+
val = pref->getRenderFpsFontSize();
1475+
if (val >= 0)
1476+
{
1477+
AsciiString prefString;
1478+
prefString.format("%d", val);
1479+
(*pref)["RenderFpsFontSize"] = prefString;
1480+
TheInGameUI->refreshRenderFpsResources();
1481+
}
1482+
14331483
//-------------------------------------------------------------------------------------------------
14341484
// Set System Time Font Size
14351485
val = pref->getSystemTimeFontSize(); // TheSuperHackers @todo replace with options input when applicable

0 commit comments

Comments
 (0)