mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 08:38:20 +00:00
[client] use clock_nanosleep for more accurate frame timing
This commit is contained in:
parent
5fe2db7e56
commit
49bd091359
@ -189,6 +189,9 @@ int renderThread(void * unused)
|
|||||||
if (!state.lgr->render_startup(state.lgrData, state.window))
|
if (!state.lgr->render_startup(state.lgrData, state.window))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
struct timespec time;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &time);
|
||||||
|
|
||||||
while(state.running)
|
while(state.running)
|
||||||
{
|
{
|
||||||
if (state.lgrResize)
|
if (state.lgrResize)
|
||||||
@ -198,8 +201,6 @@ int renderThread(void * unused)
|
|||||||
state.lgrResize = false;
|
state.lgrResize = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint64_t start = microtime();
|
|
||||||
|
|
||||||
if (!state.lgr->render(state.lgrData, state.window))
|
if (!state.lgr->render(state.lgrData, state.window))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -212,22 +213,23 @@ int renderThread(void * unused)
|
|||||||
{
|
{
|
||||||
const float avgUPS = 1000.0f / (((float)state.renderTime / state.frameCount ) / 1e6f);
|
const float avgUPS = 1000.0f / (((float)state.renderTime / state.frameCount ) / 1e6f);
|
||||||
const float avgFPS = 1000.0f / (((float)state.renderTime / state.renderCount) / 1e6f);
|
const float avgFPS = 1000.0f / (((float)state.renderTime / state.renderCount) / 1e6f);
|
||||||
|
state.lgr->update_fps(state.lgrData, avgUPS, avgFPS);
|
||||||
|
|
||||||
state.renderTime = 0;
|
state.renderTime = 0;
|
||||||
state.frameCount = 0;
|
state.frameCount = 0;
|
||||||
state.renderCount = 0;
|
state.renderCount = 0;
|
||||||
|
|
||||||
state.lgr->update_fps(state.lgrData, avgUPS, avgFPS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint64_t total = microtime() - start;
|
uint64_t nsec = time.tv_nsec + (1e9 / params.fpsLimit);
|
||||||
if (total < state.fpsSleep)
|
if (nsec > 1e9)
|
||||||
{
|
{
|
||||||
usleep(state.fpsSleep - total);
|
time.tv_nsec = nsec - 1e9;
|
||||||
int64_t delta = (1000000 / params.fpsLimit) - (microtime() - start);
|
++time.tv_sec;
|
||||||
state.fpsSleep += delta / 16;
|
|
||||||
if (state.fpsSleep < 0)
|
|
||||||
state.fpsSleep = 0;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
time.tv_nsec = nsec;
|
||||||
|
|
||||||
|
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &time, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user