Skip to content

Commit 3ab51fe

Browse files
committed
Just simplify and delete a bunch of shit
1 parent ce3328c commit 3ab51fe

File tree

9 files changed

+34
-69
lines changed

9 files changed

+34
-69
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
173173
</details>
174174

175175
<details><summary><b>Removed</b></summary>
176+
177+
- Removed RealToSimCap and OneSimUpdatePerFrame. Instead we try to always target 60fps, even if it slows the simulation down a little.
178+
176179
</details>
177180

178181
***

Lua/LuaBindingsManagers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,12 @@ namespace RTE {
379379
return luabind::class_<TimerMan>("TimerManager")
380380

381381
.property("TimeScale", &TimerMan::GetTimeScale, &TimerMan::SetTimeScale)
382-
.property("RealToSimCap", &TimerMan::GetRealToSimCap, &TimerMan::SetRealToSimCap)
382+
.property("RealToSimCap", &TimerMan::GetRealToSimCap)
383383
.property("DeltaTimeTicks", &LuaAdaptersTimerMan::GetDeltaTimeTicks, &TimerMan::SetDeltaTimeTicks)
384384
.property("DeltaTimeSecs", &TimerMan::GetDeltaTimeSecs, &TimerMan::SetDeltaTimeSecs)
385385
.property("DeltaTimeMS", &TimerMan::GetDeltaTimeMS)
386386
.property("AIDeltaTimeSecs", &TimerMan::GetAIDeltaTimeSecs)
387387
.property("AIDeltaTimeMS", &TimerMan::GetAIDeltaTimeMS)
388-
.property("OneSimUpdatePerFrame", &TimerMan::IsOneSimUpdatePerFrame, &TimerMan::SetOneSimUpdatePerFrame)
389388

390389
.property("TicksPerSecond", &LuaAdaptersTimerMan::GetTicksPerSecond)
391390

Managers/AudioMan.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ namespace RTE {
126126
FMOD_RESULT status = FMOD_OK;
127127

128128
float globalPitch = 1.0F;
129-
if (g_TimerMan.IsOneSimUpdatePerFrame()) {
130-
float simSpeed = g_TimerMan.GetSimSpeed();
131-
// Soften the ratio of the pitch adjustment so it's not such an extreme effect on the audio.
132-
// 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.
133-
globalPitch = simSpeed + (1.0F - simSpeed) * 0.35F;
134-
}
129+
130+
float simSpeed = g_TimerMan.GetSimSpeed();
131+
// Soften the ratio of the pitch adjustment so it's not such an extreme effect on the audio.
132+
// 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.
133+
globalPitch = simSpeed + (1.0F - simSpeed) * 0.35F;
134+
135135
SetGlobalPitch(globalPitch);
136136

137137
if (!g_ActivityMan.ActivityPaused()) {

Managers/PerformanceMan.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,43 +133,37 @@ namespace RTE {
133133
std::snprintf(str, sizeof(str), "Time Scale: x%.2f ([1]-, [2]+, [Ctrl+1]Rst) | Sim Speed: x%.2f", g_TimerMan.GetTimeScale(), g_TimerMan.GetSimSpeed());
134134
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 20, str, GUIFont::Left);
135135

136-
std::snprintf(str, sizeof(str), "Real to Sim Cap: %.2f ms ([3]-, [4]+, [Ctrl+3]Rst)", g_TimerMan.GetRealToSimCap() * 1000.0F);
137-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 30, str, GUIFont::Left);
138-
139136
float deltaTime = g_TimerMan.GetDeltaTimeMS();
140137
std::snprintf(str, sizeof(str), "DeltaTime: %.2f ms ([5]-, [6]+, [Ctrl+5]Rst)", deltaTime);
141-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 40, str, GUIFont::Left);
138+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 30, str, GUIFont::Left);
142139

143140
std::snprintf(str, sizeof(str), "Actors: %li", g_MovableMan.GetActorCount());
144-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 50, str, GUIFont::Left);
141+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 40, str, GUIFont::Left);
145142

146143
std::snprintf(str, sizeof(str), "Particles: %li", g_MovableMan.GetParticleCount());
147-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 60, str, GUIFont::Left);
144+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 50, str, GUIFont::Left);
148145

149146
std::snprintf(str, sizeof(str), "Objects: %i", g_MovableMan.GetKnownObjectsCount());
150-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 70, str, GUIFont::Left);
147+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 60, str, GUIFont::Left);
151148

152149
std::snprintf(str, sizeof(str), "MOIDs: %i", g_MovableMan.GetMOIDCount());
153-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 80, str, GUIFont::Left);
154-
155-
std::snprintf(str, sizeof(str), "Sim Updates Since Last Drawn: %i", g_TimerMan.SimUpdatesSinceDrawn());
156-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 90, str, GUIFont::Left);
150+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 70, str, GUIFont::Left);
157151

158152
if (int totalPlayingChannelCount = 0, realPlayingChannelCount = 0; g_AudioMan.GetPlayingChannelCount(&totalPlayingChannelCount, &realPlayingChannelCount)) {
159153
std::snprintf(str, sizeof(str), "Sound Channels: %d / %d Real | %d / %d Virtual", realPlayingChannelCount, g_AudioMan.GetTotalRealChannelCount(), totalPlayingChannelCount - realPlayingChannelCount, g_AudioMan.GetTotalVirtualChannelCount());
160154
}
161-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 100, str, GUIFont::Left);
155+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 80, str, GUIFont::Left);
162156

163157
if (!m_SortedScriptTimings.empty()) {
164158
std::snprintf(str, sizeof(str), "Lua scripts taking the most time to call Update() this frame:");
165-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 120, str, GUIFont::Left);
159+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 100, str, GUIFont::Left);
166160

167161
for (int i = 0; i < std::min((size_t)3, m_SortedScriptTimings.size()); i++)
168162
{
169163
std::pair<std::string, ScriptTiming> scriptTiming = m_SortedScriptTimings.at(i);
170164

171165
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());
172-
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 130 + i * 10, str, GUIFont::Left);
166+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 110 + i * 10, str, GUIFont::Left);
173167
}
174168
}
175169

Managers/SettingsMan.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ namespace RTE {
173173
MatchProperty("EnableParticleSettling", { reader >> g_MovableMan.m_SettlingEnabled; });
174174
MatchProperty("EnableMOSubtraction", { reader >> g_MovableMan.m_MOSubtractionEnabled; });
175175
MatchProperty("DeltaTime", { g_TimerMan.SetDeltaTimeSecs(std::stof(reader.ReadPropValue())); });
176-
MatchProperty("RealToSimCap", { g_TimerMan.SetRealToSimCap(std::stof(reader.ReadPropValue())); });
177176
MatchProperty("AllowSavingToBase", { reader >> m_AllowSavingToBase; });
178177
MatchProperty("ShowMetaScenes", { reader >> m_ShowMetaScenes; });
179178
MatchProperty("SkipIntro", { reader >> m_SkipIntro; });
@@ -319,7 +318,6 @@ namespace RTE {
319318
writer.NewPropertyWithValue("EnableParticleSettling", g_MovableMan.m_SettlingEnabled);
320319
writer.NewPropertyWithValue("EnableMOSubtraction", g_MovableMan.m_MOSubtractionEnabled);
321320
writer.NewPropertyWithValue("DeltaTime", g_TimerMan.GetDeltaTimeSecs());
322-
writer.NewPropertyWithValue("RealToSimCap", g_TimerMan.GetRealToSimCap());
323321

324322
// No experimental settings right now :)
325323
//writer.NewLine(false, 2);

Managers/TimerMan.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "TimerMan.h"
2+
23
#include "Constants.h"
34
#include "PerformanceMan.h"
45
#include "SettingsMan.h"
@@ -17,7 +18,6 @@ namespace RTE {
1718
m_StartTime = std::chrono::steady_clock::now();
1819
m_TicksPerSecond = 1000000;
1920
m_RealTimeTicks = 0;
20-
m_RealToSimCap = 0.0F;
2121
m_SimTimeTicks = 0;
2222
m_SimUpdateCount = 0;
2323
m_SimAccumulator = 0;
@@ -29,7 +29,6 @@ namespace RTE {
2929
m_SimSpeed = 1.0F;
3030
m_TimeScale = 1.0F;
3131
m_SimPaused = false;
32-
m_OneSimUpdatePerFrame = true;
3332
}
3433

3534
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -39,7 +38,6 @@ namespace RTE {
3938

4039
ResetTime();
4140
if (m_DeltaTimeS <= 0) { SetDeltaTimeSecs(c_DefaultDeltaTimeS); }
42-
if (m_RealToSimCap <= 0) { SetRealToSimCap(c_DefaultRealToSimCap); }
4341
}
4442

4543
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -48,6 +46,12 @@ namespace RTE {
4846
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
4947
}
5048

49+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50+
51+
float TimerMan::GetRealToSimCap() const {
52+
return c_RealToSimCap;
53+
}
54+
5155
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5256

5357
float TimerMan::GetAIDeltaTimeSecs() const {
@@ -92,23 +96,23 @@ namespace RTE {
9296
long long prevTime = m_RealTimeTicks;
9397
m_RealTimeTicks = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - m_StartTime).count();
9498

95-
// Cap timeIncrease if too long (as when the app went out of focus), to m_RealToSimCap.
96-
long long timeIncrease = std::min(m_RealTimeTicks - prevTime, m_RealToSimCap);
99+
// Cap timeIncrease if too long (as when the app went out of focus), to c_RealToSimCap.
100+
long long timeIncrease = std::min(m_RealTimeTicks - prevTime, static_cast<long long>(c_RealToSimCap * m_TicksPerSecond));
97101

98102
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.");
99103

100-
// If not paused, add the new time difference to the sim accumulator, scaling by the TimeScale.
101-
if (!m_SimPaused) {
102-
m_SimAccumulator += static_cast<long long>(static_cast<float>(timeIncrease) * m_TimeScale);
104+
// If not paused, add the new time difference to the sim accumulator
105+
if (!m_SimPaused) {
106+
m_SimAccumulator += static_cast<long long>(static_cast<float>(timeIncrease) * m_TimeScale);
103107
}
104108

105109
// Make sure we don't get runaway behind schedule
106-
m_SimAccumulator = std::min(m_SimAccumulator, m_DeltaTime * 2);
110+
m_SimAccumulator = std::min(m_SimAccumulator, m_DeltaTime + (m_DeltaTime / 2));
107111

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

110114
// 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.
111-
if (m_DrawnSimUpdate || m_OneSimUpdatePerFrame) {
115+
if (m_DrawnSimUpdate) {
112116
m_SimUpdatesSinceDrawn = -1;
113117
}
114118

Managers/TimerMan.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,7 @@ namespace RTE {
8989
/// Gets the cap of the amount of seconds which can be transferred from the real time to the simulated time in one update.
9090
/// </summary>
9191
/// <returns>A float describing the current cap in seconds.</returns>
92-
float GetRealToSimCap() const { return static_cast<float>(m_RealToSimCap) / static_cast<float>(m_TicksPerSecond); }
93-
94-
/// <summary>
95-
/// Sets the cap of the amount of seconds which can be transferred from the real time to the simulated time in one update.
96-
/// </summary>
97-
/// <param name="newCap">A float specifying the new cap in seconds.</param>
98-
void SetRealToSimCap(float newCap) { m_RealToSimCap = static_cast<long long>(newCap * static_cast<float>(m_TicksPerSecond)); }
99-
100-
/// <summary>
101-
/// Shows whether to force this to artificially make time for only one single sim update for the graphics frame. Useful for debugging or profiling.
102-
/// </summary>
103-
/// <returns>Whether the sim should be set to only update once per graphics frame or not.</returns>
104-
bool IsOneSimUpdatePerFrame() const { return m_OneSimUpdatePerFrame; }
105-
106-
/// <summary>
107-
/// Sets whether to force this to artificially make time for only one single sim update for the graphics frame. Useful for debugging or profiling.
108-
/// </summary>
109-
/// <param name="oneUpdate">Whether the sim should be set to only update once per graphics frame or not.</param>
110-
void SetOneSimUpdatePerFrame(bool oneUpdate = true) { m_OneSimUpdatePerFrame = oneUpdate; }
92+
float GetRealToSimCap() const;
11193

11294
/// <summary>
11395
/// Gets the number of ticks per second (the resolution of the timer).
@@ -212,7 +194,6 @@ namespace RTE {
212194
std::chrono::steady_clock::time_point m_StartTime; //!< The point in real time when the simulation (re)started.
213195
long long m_TicksPerSecond; //!< The frequency of ticks each second, ie the resolution of the timer.
214196
long long m_RealTimeTicks; //!< The number of actual microseconds counted so far.
215-
long long m_RealToSimCap; //!< The cap of number of ticks that the real time can add to the accumulator each update.
216197
long long m_SimTimeTicks; //!< The number of simulation time ticks counted so far.
217198
long long m_SimUpdateCount; //!< The number of whole simulation updates have been made since reset.
218199
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 {
228209
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.
229210

230211
bool m_SimPaused; //!< Simulation paused; no real time ticks will go to the sim accumulator.
231-
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.
232212

233213
private:
234214

Managers/UInputMan.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -942,18 +942,13 @@ namespace RTE {
942942
// Ctrl+P to toggle performance stats
943943
} else if (KeyPressed(SDLK_p)) {
944944
g_PerformanceMan.ShowPerformanceStats(!g_PerformanceMan.IsShowingPerformanceStats());
945-
// Ctrl+O to toggle one sim update per frame
946-
} else if (KeyPressed(SDLK_o)) {
947-
g_TimerMan.SetOneSimUpdatePerFrame(!g_TimerMan.IsOneSimUpdatePerFrame());
948945
} else if (KeyPressed(SDLK_F2)) {
949946
g_PresetMan.QuickReloadEntityPreset();
950947
} else if (KeyPressed(SDLK_F9)) {
951948
g_ActivityMan.LoadAndLaunchGame("AutoSave");
952949
} else if (g_PerformanceMan.IsShowingPerformanceStats()) {
953950
if (KeyHeld(SDLK_1)) {
954951
g_TimerMan.SetTimeScale(1.0F);
955-
} else if (KeyHeld(SDLK_3)) {
956-
g_TimerMan.SetRealToSimCap(c_DefaultRealToSimCap);
957952
} else if (KeyHeld(SDLK_5)) {
958953
g_TimerMan.SetDeltaTimeSecs(c_DefaultDeltaTimeS);
959954
}
@@ -1005,14 +1000,6 @@ namespace RTE {
10051000
g_TimerMan.SetTimeScale(g_TimerMan.GetTimeScale() - 0.01F);
10061001
}
10071002

1008-
// Manipulate real to sim cap
1009-
if (KeyHeld(SDLK_4)) {
1010-
g_TimerMan.SetRealToSimCap(g_TimerMan.GetRealToSimCap() + 0.001F);
1011-
}
1012-
if (KeyHeld(SDLK_3) && g_TimerMan.GetRealToSimCap() > 0) {
1013-
g_TimerMan.SetRealToSimCap(g_TimerMan.GetRealToSimCap() - 0.001F);
1014-
}
1015-
10161003
// Manipulate DeltaTime
10171004
if (KeyHeld(SDLK_6)) {
10181005
g_TimerMan.SetDeltaTimeSecs(g_TimerMan.GetDeltaTimeSecs() + 0.001F);

System/Constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace RTE {
2626

2727
#pragma region Time Constants
2828
static constexpr float c_DefaultDeltaTimeS = 0.0166666F; //!< The default simulation update step size, in seconds.
29-
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.
29+
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.
3030
#pragma endregion
3131

3232
#pragma region AI Constants

0 commit comments

Comments
 (0)