Skip to content

Commit ca90e3d

Browse files
authored
feat(ui): Implement simple Latency and FPS display (#1546)
1 parent 3ae6b3a commit ca90e3d

File tree

12 files changed

+618
-24
lines changed

12 files changed

+618
-24
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ class GlobalData : public SubsystemInterface
399399
Bool m_saveCameraInReplay;
400400
Bool m_useCameraInReplay;
401401

402+
// 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
403+
Int m_networkLatencyFontSize;
404+
Int m_renderFpsFontSize;
402405
// TheSuperHackers @feature Mauller 21/06/2025 allow the system time and game time font size to be set, a size of zero disables them
403406
Int m_systemTimeFontSize;
404407
Int m_gameTimeFontSize;

Generals/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

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

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

555555
virtual void recreateControlBar( void );
556556
virtual void refreshCustomUiResources( void );
557+
virtual void refreshNetworkLatencyResources(void);
558+
virtual void refreshRenderFpsResources(void);
557559
virtual void refreshSystemTimeResources( void );
558560
virtual void refreshGameTimeResources( void );
559561

@@ -575,7 +577,10 @@ friend class Drawable; // for selection/deselection transactions
575577
virtual void updateIdleWorker( void );
576578
virtual void resetIdleWorker( void );
577579

578-
void drawSystemTime();
580+
void updateRenderFpsString();
581+
void drawNetworkLatency(Int &x, Int &y);
582+
void drawRenderFps(Int &x, Int &y);
583+
void drawSystemTime(Int &x, Int &y);
579584
void drawGameTime();
580585

581586
public:
@@ -731,6 +736,31 @@ friend class Drawable; // for selection/deselection transactions
731736
VideoBuffer* m_cameoVideoBuffer;///< video playback buffer
732737
VideoStreamInterface* m_cameoVideoStream;///< Video stream;
733738

739+
// Network Latency Counter
740+
DisplayString * m_networkLatencyString;
741+
AsciiString m_networkLatencyFont;
742+
Int m_networkLatencyPointSize;
743+
Bool m_networkLatencyBold;
744+
Coord2D m_networkLatencyPosition;
745+
Color m_networkLatencyColor;
746+
Color m_networkLatencyDropColor;
747+
UnsignedInt m_lastNetworkLatencyFrames;
748+
749+
// Render FPS Counter
750+
DisplayString * m_renderFpsString;
751+
DisplayString * m_renderFpsLimitString;
752+
AsciiString m_renderFpsFont;
753+
Int m_renderFpsPointSize;
754+
Bool m_renderFpsBold;
755+
Coord2D m_renderFpsPosition;
756+
Color m_renderFpsColor;
757+
Color m_renderFpsLimitColor;
758+
Color m_renderFpsDropColor;
759+
UnsignedInt m_renderFpsRefreshMs;
760+
UnsignedInt m_lastRenderFps;
761+
UnsignedInt m_lastRenderFpsLimit;
762+
UnsignedInt m_lastRenderFpsUpdateMs;
763+
734764
// System Time
735765
DisplayString * m_systemTimeString;
736766
AsciiString m_systemTimeFont;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ GlobalData::GlobalData()
933933
m_saveCameraInReplay = FALSE;
934934
m_useCameraInReplay = FALSE;
935935

936+
m_networkLatencyFontSize = 8;
937+
m_renderFpsFontSize = 8;
936938
m_systemTimeFontSize = 8;
937939
m_gameTimeFontSize = 8;
938940

@@ -1184,6 +1186,8 @@ void GlobalData::parseGameDataDefinition( INI* ini )
11841186
TheWritableGlobalData->m_saveCameraInReplay = optionPref.saveCameraInReplays();
11851187
TheWritableGlobalData->m_useCameraInReplay = optionPref.useCameraInReplays();
11861188

1189+
TheWritableGlobalData->m_networkLatencyFontSize = optionPref.getNetworkLatencyFontSize();
1190+
TheWritableGlobalData->m_renderFpsFontSize = optionPref.getRenderFpsFontSize();
11871191
TheWritableGlobalData->m_systemTimeFontSize = optionPref.getSystemTimeFontSize();
11881192
TheWritableGlobalData->m_gameTimeFontSize = optionPref.getGameTimeFontSize();
11891193

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,34 @@ Real OptionPreferences::getMoneyTransactionVolume(void) const
854854
return volume;
855855
}
856856

857+
Int OptionPreferences::getNetworkLatencyFontSize(void)
858+
{
859+
OptionPreferences::const_iterator it = find("NetworkLatencyFontSize");
860+
if (it == end())
861+
return 8;
862+
863+
Int fontSize = atoi(it->second.str());
864+
if (fontSize < 0)
865+
{
866+
fontSize = 0;
867+
}
868+
return fontSize;
869+
}
870+
871+
Int OptionPreferences::getRenderFpsFontSize(void)
872+
{
873+
OptionPreferences::const_iterator it = find("RenderFpsFontSize");
874+
if (it == end())
875+
return 8;
876+
877+
Int fontSize = atoi(it->second.str());
878+
if (fontSize < 0)
879+
{
880+
fontSize = 0;
881+
}
882+
return fontSize;
883+
}
884+
857885
Int OptionPreferences::getSystemTimeFontSize(void)
858886
{
859887
OptionPreferences::const_iterator it = find("SystemTimeFontSize");
@@ -1413,6 +1441,28 @@ static void saveOptions( void )
14131441
}
14141442
}
14151443

1444+
//-------------------------------------------------------------------------------------------------
1445+
// Set Network Latency Font Size
1446+
val = pref->getNetworkLatencyFontSize();
1447+
if (val >= 0)
1448+
{
1449+
AsciiString prefString;
1450+
prefString.format("%d", val);
1451+
(*pref)["NetworkLatencyFontSize"] = prefString;
1452+
TheInGameUI->refreshNetworkLatencyResources();
1453+
}
1454+
1455+
//-------------------------------------------------------------------------------------------------
1456+
// Set Render FPS Font Size
1457+
val = pref->getRenderFpsFontSize();
1458+
if (val >= 0)
1459+
{
1460+
AsciiString prefString;
1461+
prefString.format("%d", val);
1462+
(*pref)["RenderFpsFontSize"] = prefString;
1463+
TheInGameUI->refreshRenderFpsResources();
1464+
}
1465+
14161466
//-------------------------------------------------------------------------------------------------
14171467
// Set System Time Font Size
14181468
val = pref->getSystemTimeFontSize(); // TheSuperHackers @todo replace with options input when applicable

0 commit comments

Comments
 (0)