Detect local time changes.

This commit is contained in:
Gunnar Beutner 2012-09-25 14:03:41 +02:00
parent 8c491cb545
commit c81fd071e6
3 changed files with 30 additions and 0 deletions

View File

@ -99,6 +99,8 @@ void Application::RunEventLoop(void)
double nextProfile = 0;
#endif /* _DEBUG */
double lastLoop = Utility::GetTime();
while (!m_ShuttingDown) {
Object::ClearHeldObjects();
@ -123,6 +125,20 @@ void Application::RunEventLoop(void)
nextProfile = Utility::GetTime() + 15.0;
}
#endif /* _DEBUG */
double now = Utility::GetTime();
if (now < lastLoop) {
/* We moved backwards in time - cool. */
double lostTime = lastLoop - now;
stringstream msgbuf;
msgbuf << "We moved backwards in time: " << lostTime
<< " seconds";
Logger::Write(LogInformation, "base", msgbuf.str());
Timer::AdjustTimers(-lostTime);
}
lastLoop = now;
}
}

View File

@ -155,3 +155,16 @@ void Timer::Reschedule(double next)
{
m_Next = next;
}
/**
* Adjusts all timers by adding the specified amount of time to their
* next scheduled timestamp.
*
* @param adjustment The adjustment.
*/
void Timer::AdjustTimers(double adjustment)
{
BOOST_FOREACH(Timer::Ptr timer, m_Timers) {
timer->m_Next += adjustment;
}
}

View File

@ -43,6 +43,7 @@ public:
double GetInterval(void) const;
static double ProcessTimers(void);
static void AdjustTimers(double adjustment);
void Start(void);
void Stop(void);