[host] app: improve throttleFPS logic

This commit is contained in:
Geoffrey McRae 2022-11-07 22:56:20 +11:00
parent 20b5957999
commit 875242fe15

View file

@ -901,19 +901,20 @@ int app_main(int argc, char * argv[])
LG_UNLOCK(app.pointerLock); LG_UNLOCK(app.pointerLock);
} }
const uint64_t now = microtime(); const uint64_t delta = microtime() - previousFrameTime;
const uint64_t delta = now - previousFrameTime;
if (delta < throttleUs) if (delta < throttleUs)
{ {
nsleep((throttleUs - delta) * 1000); const uint64_t us = throttleUs - delta;
previousFrameTime = microtime(); // only delay if the time is reasonable
if (us > 1000)
nsleep(us * 1000);
} }
else
previousFrameTime = now;
const uint64_t captureStart = microtime();
switch(iface->capture()) switch(iface->capture())
{ {
case CAPTURE_RESULT_OK: case CAPTURE_RESULT_OK:
previousFrameTime = captureStart;
break; break;
case CAPTURE_RESULT_TIMEOUT: case CAPTURE_RESULT_TIMEOUT: