2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
File: RageTimer.cpp
|
|
|
|
|
|
|
|
|
|
Desc: See header.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
|
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "RageTimer.h"
|
|
|
|
|
#include "RageLog.h"
|
|
|
|
|
|
2002-10-24 03:55:40 +00:00
|
|
|
#include "SDL-1.2.5/include/SDL.h"
|
|
|
|
|
#include "SDL-1.2.5/include/SDL_timer.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
|
|
|
|
|
const float SECS_IN_DAY = 60*60*24;
|
|
|
|
|
|
2002-10-24 03:55:40 +00:00
|
|
|
/* XXX: SDL_GetTicks() wraps every month or so. Handle it. */
|
2002-06-14 22:25:22 +00:00
|
|
|
RageTimer::RageTimer()
|
2002-12-19 23:00:57 +00:00
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
GetDeltaTime(); /* so the next call to GetDeltaTime is from the construction of this object */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RageTimer::Init()
|
2002-06-14 22:25:22 +00:00
|
|
|
{
|
2003-04-24 03:37:18 +00:00
|
|
|
/*
|
|
|
|
|
This is needed for the "timer" system, not the "ticks" system; it often starts
|
|
|
|
|
a thread, so let's not do it--we don't need it.
|
2002-10-24 03:55:40 +00:00
|
|
|
static bool SDL_Initialized = false;
|
|
|
|
|
if(!SDL_Initialized) {
|
|
|
|
|
SDL_InitSubSystem(SDL_INIT_TIMER);
|
|
|
|
|
SDL_Initialized = true;
|
|
|
|
|
}
|
2003-04-24 03:37:18 +00:00
|
|
|
*/
|
2002-06-14 22:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float RageTimer::GetDeltaTime()
|
|
|
|
|
{
|
2002-10-24 03:55:40 +00:00
|
|
|
/* Store the LDT in integral milliseconds, to avoid rounding error. */
|
|
|
|
|
int now = SDL_GetTicks();
|
|
|
|
|
int ret = now - m_iLastDeltaTime;
|
|
|
|
|
m_iLastDeltaTime = now;
|
|
|
|
|
return ret / 1000.f;
|
2002-06-14 22:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
2002-10-24 03:55:40 +00:00
|
|
|
float RageTimer::PeekDeltaTime() const
|
2002-06-14 22:25:22 +00:00
|
|
|
{
|
2002-10-24 03:55:40 +00:00
|
|
|
return (SDL_GetTicks() - m_iLastDeltaTime) / 1000.f;
|
2002-06-14 22:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
2002-12-19 23:00:57 +00:00
|
|
|
float RageTimer::GetTimeSinceStart()
|
2002-06-14 22:25:22 +00:00
|
|
|
{
|
2002-10-24 03:55:40 +00:00
|
|
|
return SDL_GetTicks() / 1000.f;
|
2002-06-14 22:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
2002-11-26 01:17:43 +00:00
|
|
|
/* XXX: SDL_GetTicks() wraps every month or so. Handle it. */
|
|
|
|
|
unsigned int GetTicks()
|
|
|
|
|
{
|
|
|
|
|
return SDL_GetTicks();
|
|
|
|
|
}
|