2006-03-20 17:12:09 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* SDL library timer functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <conf.h>
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
|
|
fix timer_get_approx_seconds(void)
|
|
|
|
{
|
|
|
|
return approx_msec_to_fsec(SDL_GetTicks());
|
|
|
|
}
|
|
|
|
|
|
|
|
fix timer_get_fixed_seconds(void)
|
|
|
|
{
|
|
|
|
fix x;
|
|
|
|
unsigned long tv_now = SDL_GetTicks();
|
|
|
|
x=i2f(tv_now/1000) | fixdiv(i2f(tv_now % 1000),i2f(1000));
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
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:07:07 +00:00
|
|
|
if (GameCfg.VSync)
|
|
|
|
return;
|
|
|
|
|
2008-04-21 18:39:49 +00:00
|
|
|
while (FrameLoop < 1000/fps)
|
2007-11-21 12:46:09 +00:00
|
|
|
{
|
2008-04-21 18:39:49 +00:00
|
|
|
SDL_Delay(1);
|
|
|
|
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
|
|
|
}
|