Added uncapped mode to ostd::StepTimer

This commit is contained in:
OmniaX-Dev 2026-06-16 07:22:54 +02:00
parent 08daf0cea1
commit 4a4f5a0748
3 changed files with 11 additions and 1 deletions

View file

@ -1 +1 @@
2095
2096

View file

@ -599,12 +599,15 @@ namespace ostd
StepTimer& StepTimer::create(f64 updatesPerSecond, StepTimer::Callback callback, bool stopped)
{
if (updatesPerSecond == 0.0)
updatesPerSecond = -1.0;
m_targetDt = 1.0 / updatesPerSecond;
m_callback = std::move(callback);
m_prevTime = Clock::now();
m_accumulator = 0.0;
m_stopped = stopped;
m_valid = true;
m_uncapped = (updatesPerSecond <= 0.0);
return *this;
}
@ -618,6 +621,11 @@ namespace ostd
m_stopCallback();
return;
}
if (m_uncapped) // set when updatesPerSecond <= 0, say
{
m_callback(1.0); //TODO: Calculate dt for uncapped, and replace the hardcoded 1.0
return;
}
TimePoint currentTime = Clock::now();
Duration frameDuration = currentTime - m_prevTime;

View file

@ -139,6 +139,7 @@ namespace ostd
inline void invalidate(void) { m_valid = false; }
inline bool isValid(void) const { return m_valid; }
inline bool isStopped(void) const { return m_stopped; }
inline bool isUncapped(void) const { return m_uncapped; }
private:
TimePoint m_prevTime;
@ -149,6 +150,7 @@ namespace ostd
f64 m_accumulator { 0.0 };
bool m_valid { false };
bool m_stopped { false };
bool m_uncapped { false };
};
struct GameClock