mirror of
https://github.com/ZDoom/Raze.git
synced 2025-06-04 03:00:58 +00:00
Replace separate timer implementations in SDL and Winlayer with a shared implementation based on std::chrono
git-svn-id: https://svn.eduke32.com/eduke32@7976 1a8010ca-5511-0410-912e-c29ae57300e0 # Conflicts: # platform/Windows/build.vcxproj # platform/Windows/build.vcxproj.filters # source/build/src/mdsprite.cpp
This commit is contained in:
parent
55e3188afb
commit
04811f21f4
12 changed files with 91 additions and 345 deletions
|
@ -1169,123 +1169,6 @@ void joyGetDeadZone(int32_t axis, uint16_t *dead, uint16_t *satur)
|
|||
//
|
||||
//
|
||||
|
||||
static uint32_t timerfreq;
|
||||
static uint32_t timerlastsample;
|
||||
int32_t timerticspersec=0;
|
||||
static double msperu64tick = 0;
|
||||
static void(*usertimercallback)(void) = NULL;
|
||||
|
||||
|
||||
//
|
||||
// inittimer() -- initialize timer
|
||||
//
|
||||
int32_t timerInit(int32_t tickspersecond)
|
||||
{
|
||||
if (timerfreq) return 0; // already installed
|
||||
|
||||
// initprintf("Initializing timer\n");
|
||||
|
||||
#if defined(_WIN32) && SDL_MAJOR_VERSION == 1
|
||||
int32_t t = win_inittimer();
|
||||
if (t < 0)
|
||||
return t;
|
||||
#endif
|
||||
|
||||
timerfreq = 1000;
|
||||
timerticspersec = tickspersecond;
|
||||
timerlastsample = SDL_GetTicks() * timerticspersec / timerfreq;
|
||||
|
||||
usertimercallback = NULL;
|
||||
|
||||
msperu64tick = 1000.0 / (double)timerGetFreqU64();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// uninittimer() -- shut down timer
|
||||
//
|
||||
void timerUninit(void)
|
||||
{
|
||||
timerfreq=0;
|
||||
#if defined(_WIN32) && SDL_MAJOR_VERSION==1
|
||||
win_timerfreq=0;
|
||||
#endif
|
||||
msperu64tick = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// sampletimer() -- update totalclock
|
||||
//
|
||||
void timerUpdate(void)
|
||||
{
|
||||
if (!timerfreq) return;
|
||||
|
||||
int64_t i = SDL_GetTicks();
|
||||
int32_t n = tabledivide64(i * timerticspersec, timerfreq) - timerlastsample;
|
||||
|
||||
if (n <= 0) return;
|
||||
|
||||
totalclock += n;
|
||||
timerlastsample += n;
|
||||
|
||||
if (usertimercallback)
|
||||
for (; n > 0; n--) usertimercallback();
|
||||
}
|
||||
|
||||
#if defined LUNATIC
|
||||
//
|
||||
// getticks() -- returns the sdl ticks count
|
||||
//
|
||||
uint32_t timerGetTicks(void)
|
||||
{
|
||||
return (uint32_t)SDL_GetTicks();
|
||||
}
|
||||
#endif
|
||||
|
||||
// high-resolution timers for profiling
|
||||
|
||||
#if SDL_MAJOR_VERSION != 1
|
||||
uint64_t timerGetTicksU64(void)
|
||||
{
|
||||
return SDL_GetPerformanceCounter();
|
||||
}
|
||||
|
||||
uint64_t timerGetFreqU64(void)
|
||||
{
|
||||
return SDL_GetPerformanceFrequency();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Returns the time since an unspecified starting time in milliseconds.
|
||||
// (May be not monotonic for certain configurations.)
|
||||
ATTRIBUTE((flatten))
|
||||
double timerGetHiTicks(void)
|
||||
{
|
||||
return (double)timerGetTicksU64() * msperu64tick;
|
||||
}
|
||||
|
||||
//
|
||||
// gettimerfreq() -- returns the number of ticks per second the timer is configured to generate
|
||||
//
|
||||
int32_t timerGetFreq(void)
|
||||
{
|
||||
return timerticspersec;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// installusertimercallback() -- set up a callback function to be called when the timer is fired
|
||||
//
|
||||
void(*timerSetCallback(void(*callback)(void)))(void)
|
||||
{
|
||||
void(*oldtimercallback)(void);
|
||||
|
||||
oldtimercallback = usertimercallback;
|
||||
usertimercallback = callback;
|
||||
|
||||
return oldtimercallback;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue