diff --git a/CHANGELOG.md b/CHANGELOG.md
index aaa3462fa..238627c1c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -173,6 +173,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Removed
+
+- Removed RealToSimCap and OneSimUpdatePerFrame. Instead we try to always target 60fps, even if it slows the simulation down a little.
+
***
diff --git a/Lua/LuaBindingsManagers.cpp b/Lua/LuaBindingsManagers.cpp
index 11b0424f8..935938025 100644
--- a/Lua/LuaBindingsManagers.cpp
+++ b/Lua/LuaBindingsManagers.cpp
@@ -379,13 +379,12 @@ namespace RTE {
return luabind::class_("TimerManager")
.property("TimeScale", &TimerMan::GetTimeScale, &TimerMan::SetTimeScale)
- .property("RealToSimCap", &TimerMan::GetRealToSimCap, &TimerMan::SetRealToSimCap)
+ .property("RealToSimCap", &TimerMan::GetRealToSimCap)
.property("DeltaTimeTicks", &LuaAdaptersTimerMan::GetDeltaTimeTicks, &TimerMan::SetDeltaTimeTicks)
.property("DeltaTimeSecs", &TimerMan::GetDeltaTimeSecs, &TimerMan::SetDeltaTimeSecs)
.property("DeltaTimeMS", &TimerMan::GetDeltaTimeMS)
.property("AIDeltaTimeSecs", &TimerMan::GetAIDeltaTimeSecs)
.property("AIDeltaTimeMS", &TimerMan::GetAIDeltaTimeMS)
- .property("OneSimUpdatePerFrame", &TimerMan::IsOneSimUpdatePerFrame, &TimerMan::SetOneSimUpdatePerFrame)
.property("TicksPerSecond", &LuaAdaptersTimerMan::GetTicksPerSecond)
diff --git a/Managers/AudioMan.cpp b/Managers/AudioMan.cpp
index 1cb729c52..1d9a6eda9 100644
--- a/Managers/AudioMan.cpp
+++ b/Managers/AudioMan.cpp
@@ -126,12 +126,12 @@ namespace RTE {
FMOD_RESULT status = FMOD_OK;
float globalPitch = 1.0F;
- if (g_TimerMan.IsOneSimUpdatePerFrame()) {
- float simSpeed = g_TimerMan.GetSimSpeed();
- // Soften the ratio of the pitch adjustment so it's not such an extreme effect on the audio.
- // TODO: This coefficient should probably move to SettingsMan and be loaded from ini. That way this effect can be lessened or even turned off entirely by users. 0.35 is a good default value though.
- globalPitch = simSpeed + (1.0F - simSpeed) * 0.35F;
- }
+
+ float simSpeed = g_TimerMan.GetSimSpeed();
+ // Soften the ratio of the pitch adjustment so it's not such an extreme effect on the audio.
+ // TODO: This coefficient should probably move to SettingsMan and be loaded from ini. That way this effect can be lessened or even turned off entirely by users. 0.35 is a good default value though.
+ globalPitch = simSpeed + (1.0F - simSpeed) * 0.35F;
+
SetGlobalPitch(globalPitch);
if (!g_ActivityMan.ActivityPaused()) {
diff --git a/Managers/PerformanceMan.cpp b/Managers/PerformanceMan.cpp
index 29469b7d4..42bde776f 100644
--- a/Managers/PerformanceMan.cpp
+++ b/Managers/PerformanceMan.cpp
@@ -133,43 +133,37 @@ namespace RTE {
std::snprintf(str, sizeof(str), "Time Scale: x%.2f ([1]-, [2]+, [Ctrl+1]Rst) | Sim Speed: x%.2f", g_TimerMan.GetTimeScale(), g_TimerMan.GetSimSpeed());
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 20, str, GUIFont::Left);
- std::snprintf(str, sizeof(str), "Real to Sim Cap: %.2f ms ([3]-, [4]+, [Ctrl+3]Rst)", g_TimerMan.GetRealToSimCap() * 1000.0F);
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 30, str, GUIFont::Left);
-
float deltaTime = g_TimerMan.GetDeltaTimeMS();
std::snprintf(str, sizeof(str), "DeltaTime: %.2f ms ([5]-, [6]+, [Ctrl+5]Rst)", deltaTime);
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 40, str, GUIFont::Left);
+ guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 30, str, GUIFont::Left);
std::snprintf(str, sizeof(str), "Actors: %li", g_MovableMan.GetActorCount());
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 50, str, GUIFont::Left);
+ guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 40, str, GUIFont::Left);
std::snprintf(str, sizeof(str), "Particles: %li", g_MovableMan.GetParticleCount());
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 60, str, GUIFont::Left);
+ guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 50, str, GUIFont::Left);
std::snprintf(str, sizeof(str), "Objects: %i", g_MovableMan.GetKnownObjectsCount());
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 70, str, GUIFont::Left);
+ guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 60, str, GUIFont::Left);
std::snprintf(str, sizeof(str), "MOIDs: %i", g_MovableMan.GetMOIDCount());
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 80, str, GUIFont::Left);
-
- std::snprintf(str, sizeof(str), "Sim Updates Since Last Drawn: %i", g_TimerMan.SimUpdatesSinceDrawn());
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 90, str, GUIFont::Left);
+ guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 70, str, GUIFont::Left);
if (int totalPlayingChannelCount = 0, realPlayingChannelCount = 0; g_AudioMan.GetPlayingChannelCount(&totalPlayingChannelCount, &realPlayingChannelCount)) {
std::snprintf(str, sizeof(str), "Sound Channels: %d / %d Real | %d / %d Virtual", realPlayingChannelCount, g_AudioMan.GetTotalRealChannelCount(), totalPlayingChannelCount - realPlayingChannelCount, g_AudioMan.GetTotalVirtualChannelCount());
}
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 100, str, GUIFont::Left);
+ guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 80, str, GUIFont::Left);
if (!m_SortedScriptTimings.empty()) {
std::snprintf(str, sizeof(str), "Lua scripts taking the most time to call Update() this frame:");
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 120, str, GUIFont::Left);
+ guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 100, str, GUIFont::Left);
for (int i = 0; i < std::min((size_t)3, m_SortedScriptTimings.size()); i++)
{
std::pair scriptTiming = m_SortedScriptTimings.at(i);
std::snprintf(str, sizeof(str), "%.1fms total with %i calls in %s", scriptTiming.second.m_Time / 1000.0, scriptTiming.second.m_CallCount, scriptTiming.first.c_str());
- guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 130 + i * 10, str, GUIFont::Left);
+ guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 110 + i * 10, str, GUIFont::Left);
}
}
diff --git a/Managers/SettingsMan.cpp b/Managers/SettingsMan.cpp
index 9d6298944..c036f2bf6 100644
--- a/Managers/SettingsMan.cpp
+++ b/Managers/SettingsMan.cpp
@@ -173,7 +173,6 @@ namespace RTE {
MatchProperty("EnableParticleSettling", { reader >> g_MovableMan.m_SettlingEnabled; });
MatchProperty("EnableMOSubtraction", { reader >> g_MovableMan.m_MOSubtractionEnabled; });
MatchProperty("DeltaTime", { g_TimerMan.SetDeltaTimeSecs(std::stof(reader.ReadPropValue())); });
- MatchProperty("RealToSimCap", { g_TimerMan.SetRealToSimCap(std::stof(reader.ReadPropValue())); });
MatchProperty("AllowSavingToBase", { reader >> m_AllowSavingToBase; });
MatchProperty("ShowMetaScenes", { reader >> m_ShowMetaScenes; });
MatchProperty("SkipIntro", { reader >> m_SkipIntro; });
@@ -319,7 +318,6 @@ namespace RTE {
writer.NewPropertyWithValue("EnableParticleSettling", g_MovableMan.m_SettlingEnabled);
writer.NewPropertyWithValue("EnableMOSubtraction", g_MovableMan.m_MOSubtractionEnabled);
writer.NewPropertyWithValue("DeltaTime", g_TimerMan.GetDeltaTimeSecs());
- writer.NewPropertyWithValue("RealToSimCap", g_TimerMan.GetRealToSimCap());
// No experimental settings right now :)
//writer.NewLine(false, 2);
diff --git a/Managers/TimerMan.cpp b/Managers/TimerMan.cpp
index 000015c69..3265a32aa 100644
--- a/Managers/TimerMan.cpp
+++ b/Managers/TimerMan.cpp
@@ -1,4 +1,5 @@
#include "TimerMan.h"
+
#include "Constants.h"
#include "PerformanceMan.h"
#include "SettingsMan.h"
@@ -17,7 +18,6 @@ namespace RTE {
m_StartTime = std::chrono::steady_clock::now();
m_TicksPerSecond = 1000000;
m_RealTimeTicks = 0;
- m_RealToSimCap = 0.0F;
m_SimTimeTicks = 0;
m_SimUpdateCount = 0;
m_SimAccumulator = 0;
@@ -29,7 +29,6 @@ namespace RTE {
m_SimSpeed = 1.0F;
m_TimeScale = 1.0F;
m_SimPaused = false;
- m_OneSimUpdatePerFrame = true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -39,7 +38,6 @@ namespace RTE {
ResetTime();
if (m_DeltaTimeS <= 0) { SetDeltaTimeSecs(c_DefaultDeltaTimeS); }
- if (m_RealToSimCap <= 0) { SetRealToSimCap(c_DefaultRealToSimCap); }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -48,6 +46,12 @@ namespace RTE {
return std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count();
}
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ float TimerMan::GetRealToSimCap() const {
+ return c_RealToSimCap;
+ }
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float TimerMan::GetAIDeltaTimeSecs() const {
@@ -92,23 +96,23 @@ namespace RTE {
long long prevTime = m_RealTimeTicks;
m_RealTimeTicks = std::chrono::duration_cast(std::chrono::steady_clock::now() - m_StartTime).count();
- // Cap timeIncrease if too long (as when the app went out of focus), to m_RealToSimCap.
- long long timeIncrease = std::min(m_RealTimeTicks - prevTime, m_RealToSimCap);
+ // Cap timeIncrease if too long (as when the app went out of focus), to c_RealToSimCap.
+ long long timeIncrease = std::min(m_RealTimeTicks - prevTime, static_cast(c_RealToSimCap * m_TicksPerSecond));
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.");
- // If not paused, add the new time difference to the sim accumulator, scaling by the TimeScale.
- if (!m_SimPaused) {
- m_SimAccumulator += static_cast(static_cast(timeIncrease) * m_TimeScale);
+ // If not paused, add the new time difference to the sim accumulator
+ if (!m_SimPaused) {
+ m_SimAccumulator += static_cast(static_cast(timeIncrease) * m_TimeScale);
}
// Make sure we don't get runaway behind schedule
- m_SimAccumulator = std::min(m_SimAccumulator, m_DeltaTime * 2);
+ m_SimAccumulator = std::min(m_SimAccumulator, m_DeltaTime + (m_DeltaTime / 2));
RTEAssert(m_SimAccumulator >= 0, "Negative sim time accumulator?!");
// 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.
- if (m_DrawnSimUpdate || m_OneSimUpdatePerFrame) {
+ if (m_DrawnSimUpdate) {
m_SimUpdatesSinceDrawn = -1;
}
diff --git a/Managers/TimerMan.h b/Managers/TimerMan.h
index 611afc3ec..d02c897ae 100644
--- a/Managers/TimerMan.h
+++ b/Managers/TimerMan.h
@@ -89,25 +89,7 @@ namespace RTE {
/// Gets the cap of the amount of seconds which can be transferred from the real time to the simulated time in one update.
///
/// A float describing the current cap in seconds.
- float GetRealToSimCap() const { return static_cast(m_RealToSimCap) / static_cast(m_TicksPerSecond); }
-
- ///
- /// Sets the cap of the amount of seconds which can be transferred from the real time to the simulated time in one update.
- ///
- /// A float specifying the new cap in seconds.
- void SetRealToSimCap(float newCap) { m_RealToSimCap = static_cast(newCap * static_cast(m_TicksPerSecond)); }
-
- ///
- /// Shows whether to force this to artificially make time for only one single sim update for the graphics frame. Useful for debugging or profiling.
- ///
- /// Whether the sim should be set to only update once per graphics frame or not.
- bool IsOneSimUpdatePerFrame() const { return m_OneSimUpdatePerFrame; }
-
- ///
- /// Sets whether to force this to artificially make time for only one single sim update for the graphics frame. Useful for debugging or profiling.
- ///
- /// Whether the sim should be set to only update once per graphics frame or not.
- void SetOneSimUpdatePerFrame(bool oneUpdate = true) { m_OneSimUpdatePerFrame = oneUpdate; }
+ float GetRealToSimCap() const;
///
/// Gets the number of ticks per second (the resolution of the timer).
@@ -212,7 +194,6 @@ namespace RTE {
std::chrono::steady_clock::time_point m_StartTime; //!< The point in real time when the simulation (re)started.
long long m_TicksPerSecond; //!< The frequency of ticks each second, ie the resolution of the timer.
long long m_RealTimeTicks; //!< The number of actual microseconds counted so far.
- long long m_RealToSimCap; //!< The cap of number of ticks that the real time can add to the accumulator each update.
long long m_SimTimeTicks; //!< The number of simulation time ticks counted so far.
long long m_SimUpdateCount; //!< The number of whole simulation updates have been made since reset.
long long m_SimAccumulator; //!< Simulation time accumulator keeps track of how much actual time has passed and is chunked into whole DeltaTime:s upon UpdateSim.
@@ -228,7 +209,6 @@ namespace RTE {
float m_TimeScale; //!< The relationship between the real world actual time and the simulation time. A value of 2.0 means simulation runs twice as fast as normal, as perceived by a player.
bool m_SimPaused; //!< Simulation paused; no real time ticks will go to the sim accumulator.
- 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.
private:
diff --git a/Managers/UInputMan.cpp b/Managers/UInputMan.cpp
index 167784b56..b1b57d2f9 100644
--- a/Managers/UInputMan.cpp
+++ b/Managers/UInputMan.cpp
@@ -942,9 +942,6 @@ namespace RTE {
// Ctrl+P to toggle performance stats
} else if (KeyPressed(SDLK_p)) {
g_PerformanceMan.ShowPerformanceStats(!g_PerformanceMan.IsShowingPerformanceStats());
- // Ctrl+O to toggle one sim update per frame
- } else if (KeyPressed(SDLK_o)) {
- g_TimerMan.SetOneSimUpdatePerFrame(!g_TimerMan.IsOneSimUpdatePerFrame());
} else if (KeyPressed(SDLK_F2)) {
g_PresetMan.QuickReloadEntityPreset();
} else if (KeyPressed(SDLK_F9)) {
@@ -952,8 +949,6 @@ namespace RTE {
} else if (g_PerformanceMan.IsShowingPerformanceStats()) {
if (KeyHeld(SDLK_1)) {
g_TimerMan.SetTimeScale(1.0F);
- } else if (KeyHeld(SDLK_3)) {
- g_TimerMan.SetRealToSimCap(c_DefaultRealToSimCap);
} else if (KeyHeld(SDLK_5)) {
g_TimerMan.SetDeltaTimeSecs(c_DefaultDeltaTimeS);
}
@@ -1005,14 +1000,6 @@ namespace RTE {
g_TimerMan.SetTimeScale(g_TimerMan.GetTimeScale() - 0.01F);
}
- // Manipulate real to sim cap
- if (KeyHeld(SDLK_4)) {
- g_TimerMan.SetRealToSimCap(g_TimerMan.GetRealToSimCap() + 0.001F);
- }
- if (KeyHeld(SDLK_3) && g_TimerMan.GetRealToSimCap() > 0) {
- g_TimerMan.SetRealToSimCap(g_TimerMan.GetRealToSimCap() - 0.001F);
- }
-
// Manipulate DeltaTime
if (KeyHeld(SDLK_6)) {
g_TimerMan.SetDeltaTimeSecs(g_TimerMan.GetDeltaTimeSecs() + 0.001F);
diff --git a/System/Constants.h b/System/Constants.h
index 6d528fbf9..a2416f4c6 100644
--- a/System/Constants.h
+++ b/System/Constants.h
@@ -26,7 +26,7 @@ namespace RTE {
#pragma region Time Constants
static constexpr float c_DefaultDeltaTimeS = 0.0166666F; //!< The default simulation update step size, in seconds.
- static constexpr float c_DefaultRealToSimCap = 0.0333333F; //!< The default cap of number of ticks that the real time can add to the tick accumulator each update.
+ static constexpr float c_RealToSimCap = 0.0166666F; //!< The default cap of number of ticks that the real time can add to the tick accumulator each update.
#pragma endregion
#pragma region AI Constants