2006-03-20 17:12:09 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* SDL library timer functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-04-09 02:41:45 +00:00
|
|
|
#include <SDL/SDL.h>
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
#include "maths.h"
|
|
|
|
#include "timer.h"
|
2008-09-30 00:07:07 +00:00
|
|
|
#include "config.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2010-12-10 23:18:17 +00:00
|
|
|
static fix64 F64_RunTime = 0;
|
|
|
|
|
|
|
|
void timer_update(void)
|
|
|
|
{
|
|
|
|
static ubyte init = 1;
|
|
|
|
static u_int32_t last_tv = 0;
|
|
|
|
u_int32_t cur_tv = SDL_GetTicks();
|
|
|
|
|
|
|
|
if (init)
|
|
|
|
{
|
|
|
|
last_tv = cur_tv;
|
|
|
|
init = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_tv < cur_tv) // in case SDL_GetTicks wraps, don't update and have a little hickup
|
|
|
|
F64_RunTime += (cur_tv - last_tv)*F1_0/1000; // increment! this value will overflow long after we are all dead... so why bother checking?
|
|
|
|
last_tv = cur_tv;
|
|
|
|
}
|
|
|
|
|
|
|
|
fix64 timer_query(void)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2010-12-10 23:18:17 +00:00
|
|
|
return (F64_RunTime);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void timer_delay(fix seconds)
|
|
|
|
{
|
|
|
|
SDL_Delay(f2i(fixmul(seconds, i2f(1000))));
|
|
|
|
}
|
2007-11-21 12:46:09 +00:00
|
|
|
|
|
|
|
// Replacement for timer_delay which considers calc time the program needs between frames (not reentrant)
|
|
|
|
void timer_delay2(int fps)
|
|
|
|
{
|
2008-04-21 18:39:49 +00:00
|
|
|
static u_int32_t FrameStart=0;
|
|
|
|
u_int32_t FrameLoop=0;
|
2007-11-21 12:46:09 +00:00
|
|
|
|
2008-09-30 00:18:39 +00:00
|
|
|
while (FrameLoop < 1000/(GameCfg.VSync?MAXIMUM_FPS:fps))
|
2007-11-21 12:46:09 +00:00
|
|
|
{
|
2008-09-30 00:18:39 +00:00
|
|
|
if (!GameCfg.VSync)
|
|
|
|
SDL_Delay(1);
|
2008-04-21 18:39:49 +00:00
|
|
|
FrameLoop=SDL_GetTicks()-FrameStart;
|
2007-11-21 12:46:09 +00:00
|
|
|
}
|
2008-04-21 18:39:49 +00:00
|
|
|
|
|
|
|
FrameStart=SDL_GetTicks();
|
2007-11-21 12:46:09 +00:00
|
|
|
}
|