Skip to content

Commit 706a91e

Browse files
committed
Improvements to make sim timing info more accurate, and allowing proper fast-motion
1 parent 6e235c7 commit 706a91e

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
lines changed

Managers/PerformanceMan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ namespace RTE {
130130
std::snprintf(str, sizeof(str), "Frame: %.1fms | Update: %.1fms | Draw: %.1fms", m_MSPFAverage, m_MSPUAverage, m_MSPDAverage);
131131
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 10, str, GUIFont::Left);
132132

133-
std::snprintf(str, sizeof(str), "Time Scale: x%.2f ([1]-, [2]+, [Ctrl+1]Rst)", g_TimerMan.IsOneSimUpdatePerFrame() ? g_TimerMan.GetSimSpeed() : g_TimerMan.GetTimeScale());
133+
std::snprintf(str, sizeof(str), "Time Scale: x%.2f ([1]-, [2]+, [Ctrl+1]Rst)", g_TimerMan.GetSimSpeed());
134134
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 20, str, GUIFont::Left);
135135

136136
std::snprintf(str, sizeof(str), "Real to Sim Cap: %.2f ms ([3]-, [4]+, [Ctrl+3]Rst)", g_TimerMan.GetRealToSimCap() * 1000.0F);

Managers/PerformanceMan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ namespace RTE {
9292
/// <param name="showGraphs">Whether to show the performance graphs or not.</param>
9393
void ShowAdvancedPerformanceStats(bool showGraphs = true) { m_AdvancedPerfStats = showGraphs; }
9494

95+
/// <summary>
96+
/// Gets the average of the MSPU reading buffer, calculated each update.
97+
/// </summary>
98+
/// <returns>The average value of the MSPU reading buffer.</returns>
99+
float GetMSPSUAverage() const { return m_MSPSUAverage; }
100+
95101
/// <summary>
96102
/// Gets the average of the MSPF reading buffer, calculated each frame.
97103
/// </summary>

Managers/TimerMan.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace RTE {
3030
m_TimeScale = 1.0F;
3131
m_SimPaused = false;
3232
m_OneSimUpdatePerFrame = true;
33-
m_SimSpeedLimited = true;
3433
}
3534

3635
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -89,35 +88,32 @@ namespace RTE {
8988

9089
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9190

91+
#pragma optimize("", off)
9292
void TimerMan::Update() {
9393
long long prevTime = m_RealTimeTicks;
9494
m_RealTimeTicks = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - m_StartTime).count();
95-
unsigned long long timeIncrease = m_RealTimeTicks - prevTime;
96-
// Cap it if too long (as when the app went out of focus).
97-
if (timeIncrease > m_RealToSimCap) { timeIncrease = m_RealToSimCap; }
95+
96+
// Cap timeIncrease if too long (as when the app went out of focus), to m_RealToSimCap.
97+
long long timeIncrease = std::min(m_RealTimeTicks - prevTime, m_RealToSimCap);
9898

9999
RTEAssert(timeIncrease > 0, "It seems your CPU is giving bad timing data to the game, this is known to happen on some multi-core processors. This may be fixed by downloading the latest CPU drivers from AMD or Intel.");
100100

101101
// If not paused, add the new time difference to the sim accumulator, scaling by the TimeScale.
102-
if (!m_SimPaused) { m_SimAccumulator += static_cast<long long>(static_cast<float>(timeIncrease) * m_TimeScale); }
102+
if (!m_SimPaused) {
103+
m_SimAccumulator += static_cast<long long>(static_cast<float>(timeIncrease) * m_TimeScale);
104+
}
105+
106+
// Make sure we don't get runaway behind schedule
107+
m_SimAccumulator = std::min(m_SimAccumulator, m_DeltaTime * 2);
103108

104109
RTEAssert(m_SimAccumulator >= 0, "Negative sim time accumulator?!");
105110

106111
// Reset the counter since the last drawn update. Set it negative since we're counting full pure sim updates and this will be incremented to 0 on next SimUpdate.
107-
if (m_DrawnSimUpdate) { m_SimUpdatesSinceDrawn = -1; }
108-
109-
// Override the accumulator and just put one delta time in there so sim updates only once per frame.
110-
if (m_OneSimUpdatePerFrame) {
111-
// Make sure we don't get runaway behind
112-
if (m_SimSpeedLimited && m_SimAccumulator > m_DeltaTime * 2.0f) { m_SimAccumulator = m_DeltaTime; }
113-
114-
// Reset the counter of sim updates since the last drawn. it will always be 0 since every update results in a drawn frame.
115-
m_SimUpdatesSinceDrawn = -1;
116-
117-
m_SimSpeed = GetDeltaTimeMS() / g_PerformanceMan.GetMSPFAverage();
118-
if (IsSimSpeedLimited() && m_SimSpeed > 1.0F) { m_SimSpeed = 1.0F; }
119-
} else {
120-
m_SimSpeed = 1.0F;
112+
if (m_DrawnSimUpdate || m_OneSimUpdatePerFrame) {
113+
m_SimUpdatesSinceDrawn = -1;
121114
}
115+
116+
m_SimSpeed = std::min(GetDeltaTimeMS() / g_PerformanceMan.GetMSPSUAverage(), GetTimeScale());
122117
}
118+
#pragma optimize("", on)
123119
}

Managers/TimerMan.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,6 @@ namespace RTE {
109109
/// <param name="oneUpdate">Whether the sim should be set to only update once per graphics frame or not.</param>
110110
void SetOneSimUpdatePerFrame(bool oneUpdate = true) { m_OneSimUpdatePerFrame = oneUpdate; }
111111

112-
/// <summary>
113-
/// Shows whether the sim speed is limited to not exceed 1.0x.
114-
/// </summary>
115-
/// <returns>Whether the sim is limited to not exceed 1.0x of real time.</returns>
116-
bool IsSimSpeedLimited() const { return m_OneSimUpdatePerFrame && m_SimSpeedLimited; }
117-
118-
/// <summary>
119-
/// Sets whether to limit the sim speed to not exceed real time.
120-
/// </summary>
121-
/// <param name="simLimited">Whether the sim speed should be limited to not exceed 1.0.</param>
122-
void SetSimSpeedLimited(bool simLimited = true) { m_SimSpeedLimited = simLimited; }
123-
124112
/// <summary>
125113
/// Gets the number of ticks per second (the resolution of the timer).
126114
/// </summary>
@@ -241,7 +229,6 @@ namespace RTE {
241229

242230
bool m_SimPaused; //!< Simulation paused; no real time ticks will go to the sim accumulator.
243231
bool m_OneSimUpdatePerFrame; //!< Whether to force this to artificially make time for only one single sim update for the graphics frame. Useful for debugging or profiling.
244-
bool m_SimSpeedLimited; //!< Whether the simulation is limited to going at 1.0x and not faster.
245232

246233
private:
247234

0 commit comments

Comments
 (0)