1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-12-16 19:18:05 +00:00

improved SDL_GetTicks without SDL, and getticks() replaced with it

This commit is contained in:
Zeno Rogue
2018-07-23 05:16:16 +02:00
parent ba92dd4b32
commit ce08ec2a1f
4 changed files with 14 additions and 15 deletions

View File

@@ -6,16 +6,21 @@
namespace hr {
#if CAP_TIMEOFDAY
long long getms() {
struct timeval tval;
gettimeofday(&tval, NULL);
return tval.tv_sec * 1000000 + tval.tv_usec;
#if !CAP_SDL
int lastusec;
int uticks;
int SDL_GetTicks() {
struct timeval tim;
gettimeofday(&tim, NULL);
int newusec = tim.tv_usec;
uticks += newusec - lastusec;
if(newusec <= lastusec)
uticks += 1000000;
lastusec = newusec;
return uticks / 1000;
}
#if !CAP_SDL
int SDL_GetTicks() {
return getms() / 1000;
}
#endif
#endif