Skip to content

Commit 0f9ffcb

Browse files
committed
[GEN][ZH] Fix viewport scroll speed so it is independent of FPS in LookAtTranslator::translateGameMessage()
1 parent 86587a8 commit 0f9ffcb

File tree

10 files changed

+40
-6
lines changed

10 files changed

+40
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class Display : public SubsystemInterface
180180
virtual void setCinematicTextFrames( Int frames ) { m_cinematicTextFrames = frames; }
181181

182182
virtual Real getAverageFPS( void ) = 0; ///< returns the average FPS.
183+
virtual Real getCurrentFPS( void ) = 0; ///< returns the current FPS.
183184
virtual Int getLastFrameDrawCalls( void ) = 0; ///< returns the number of draw calls issued in the previous frame
184185

185186
protected:

Generals/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,14 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
471471
break;
472472
}
473473

474+
// TheSuperHackers @bugfix Mauller 07/06/2025 Adjust the viewport scrolling so it is independent of gameClient FPS
475+
// The scaling is based on the logic rate of 30 FPS, this provides a consistent scroll speed at all gameCLient FPS
476+
// This also fixes scrolling within replays when fast forwarding due to the uncapped FPS
477+
// When the FPS is in excess of the expected frame rate, the ratio will reduce the offset of the cameras movement
478+
Real logicToFpsRatio = LOGICFRAMES_PER_SECONDS_REAL / TheDisplay->getCurrentFPS();
479+
offset.x *= logicToFpsRatio;
480+
offset.y *= logicToFpsRatio;
481+
474482
TheInGameUI->setScrollAmount(offset);
475483
TheTacticalView->scrollBy( &offset );
476484
}

Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ class W3DDisplay : public Display
145145
static W3DAssetManager *m_assetManager; ///< W3D asset manager
146146

147147
void drawFPSStats( void ); ///< draw the fps on the screen
148-
virtual Real getAverageFPS( void ); ///< return the average FPS.
148+
virtual Real getAverageFPS( void ); ///< return the average FPS.
149+
virtual Real getCurrentFPS( void ); ///< return the current FPS.
149150
virtual Int getLastFrameDrawCalls( void ); ///< returns the number of draw calls issued in the previous frame
150151

151152
protected:
@@ -166,6 +167,7 @@ class W3DDisplay : public Display
166167
IRegion2D m_clipRegion; ///< the clipping region for images
167168
Bool m_isClippedEnabled; ///<used by 2D drawing operations to define clip re
168169
Real m_averageFPS; ///<average fps over the last 30 frames.
170+
Real m_currentFPS; ///<current fps value.
169171
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
170172
Int64 m_timerAtCumuFPSStart;
171173
#endif

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,8 @@ void W3DDisplay::updateAverageFPS(void)
832832
if (historyOffset >= FPS_HISTORY_SIZE)
833833
historyOffset = 0;
834834

835-
double currentFPS = 1.0/elapsedSeconds;
836-
fpsHistory[historyOffset++] = currentFPS;
835+
m_currentFPS = 1.0/elapsedSeconds;
836+
fpsHistory[historyOffset++] = m_currentFPS;
837837
numSamples++;
838838
if (numSamples > FPS_HISTORY_SIZE)
839839
numSamples = FPS_HISTORY_SIZE;
@@ -1559,6 +1559,11 @@ Real W3DDisplay::getAverageFPS()
15591559
return m_averageFPS;
15601560
}
15611561

1562+
Real W3DDisplay::getCurrentFPS()
1563+
{
1564+
return m_currentFPS;
1565+
}
1566+
15621567
Int W3DDisplay::getLastFrameDrawCalls()
15631568
{
15641569
return Debug_Statistics::Get_Draw_Calls();

Generals/Code/Tools/GUIEdit/Include/GUIEditDisplay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class GUIEditDisplay : public Display
126126
#endif
127127

128128
virtual Real getAverageFPS(void) { return 0; }
129+
virtual Real getCurrentFPS(void) { return 0; }
129130
virtual Int getLastFrameDrawCalls( void ) { return 0; }
130131

131132
protected:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class Display : public SubsystemInterface
181181
virtual void setCinematicTextFrames( Int frames ) { m_cinematicTextFrames = frames; }
182182

183183
virtual Real getAverageFPS( void ) = 0; ///< returns the average FPS.
184+
virtual Real getCurrentFPS( void ) = 0; ///< returns the current FPS.
184185
virtual Int getLastFrameDrawCalls( void ) = 0; ///< returns the number of draw calls issued in the previous frame
185186

186187
protected:

GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,14 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
470470
break;
471471
}
472472

473+
// TheSuperHackers @bugfix Mauller 07/06/2025 Adjust the viewport scrolling so it is independent of gameClient FPS
474+
// The scaling is based on the logic rate of 30 FPS, this provides a consistent scroll speed at all gameCLient FPS
475+
// This also fixes scrolling within replays when fast forwarding due to the uncapped FPS
476+
// When the FPS is in excess of the expected frame rate, the ratio will reduce the offset of the cameras movement
477+
Real logicToFpsRatio = LOGICFRAMES_PER_SECONDS_REAL / TheDisplay->getCurrentFPS();
478+
offset.x *= logicToFpsRatio;
479+
offset.y *= logicToFpsRatio;
480+
473481
TheInGameUI->setScrollAmount(offset);
474482
TheTacticalView->scrollBy( &offset );
475483
}

GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ class W3DDisplay : public Display
146146
static W3DAssetManager *m_assetManager; ///< W3D asset manager
147147

148148
void drawFPSStats( void ); ///< draw the fps on the screen
149-
virtual Real getAverageFPS( void ); ///< return the average FPS.
149+
virtual Real getAverageFPS( void ); ///< return the average FPS.
150+
virtual Real getCurrentFPS( void ); ///< return the current FPS.
150151
virtual Int getLastFrameDrawCalls( void ); ///< returns the number of draw calls issued in the previous frame
151152

152153
protected:
@@ -167,6 +168,7 @@ class W3DDisplay : public Display
167168
IRegion2D m_clipRegion; ///< the clipping region for images
168169
Bool m_isClippedEnabled; ///<used by 2D drawing operations to define clip re
169170
Real m_averageFPS; ///<average fps over the last 30 frames.
171+
Real m_currentFPS; ///<current fps value.
170172
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
171173
Int64 m_timerAtCumuFPSStart;
172174
#endif

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ void W3DDisplay::updateAverageFPS(void)
899899
if (historyOffset >= FPS_HISTORY_SIZE)
900900
historyOffset = 0;
901901

902-
double currentFPS = 1.0/elapsedSeconds;
903-
fpsHistory[historyOffset++] = currentFPS;
902+
m_currentFPS = 1.0/elapsedSeconds;
903+
fpsHistory[historyOffset++] = m_currentFPS;
904904
numSamples++;
905905
if (numSamples > FPS_HISTORY_SIZE)
906906
numSamples = FPS_HISTORY_SIZE;
@@ -1647,6 +1647,11 @@ Real W3DDisplay::getAverageFPS()
16471647
return m_averageFPS;
16481648
}
16491649

1650+
Real W3DDisplay::getCurrentFPS()
1651+
{
1652+
return m_currentFPS;
1653+
}
1654+
16501655
Int W3DDisplay::getLastFrameDrawCalls()
16511656
{
16521657
return Debug_Statistics::Get_Draw_Calls();

GeneralsMD/Code/Tools/GUIEdit/Include/GUIEditDisplay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class GUIEditDisplay : public Display
126126
#endif
127127

128128
virtual Real getAverageFPS(void) { return 0; }
129+
virtual Real getCurrentFPS(void) { return 0; }
129130
virtual Int getLastFrameDrawCalls( void ) { return 0; }
130131

131132
protected:

0 commit comments

Comments
 (0)