Spectre/Game/GameTime: Store max accumulated time in a member variable and calculate it once in setTimeStep()
This commit is contained in:
parent
2a608805b5
commit
db695f11f6
2 changed files with 4 additions and 2 deletions
|
|
@ -39,6 +39,7 @@ protected :
|
|||
Stopwatch m_watch;
|
||||
|
||||
Time m_acc;
|
||||
Time m_max_acc;
|
||||
|
||||
// Timeslice.
|
||||
Time m_slice;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ double GameTime::getTimeStep() const
|
|||
void GameTime::setTimeStep(unsigned long updates_per_sec)
|
||||
{
|
||||
m_slice = Time::seconds(1.0f / ((double) updates_per_sec));
|
||||
m_max_acc = Time::seconds(1.0f / m_slice.seconds());
|
||||
|
||||
reset();
|
||||
}
|
||||
|
|
@ -58,8 +59,8 @@ void GameTime::reset()
|
|||
void GameTime::accumulateTime()
|
||||
{
|
||||
m_acc += m_watch.restart();
|
||||
if (m_acc.seconds() > (1.0f / m_slice.seconds())) {
|
||||
m_acc = Time::seconds(1.0f / m_slice.seconds());
|
||||
if (m_acc > m_max_acc) {
|
||||
m_acc = m_max_acc;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue