[client] added FPS limiter for when running without vsync

This commit is contained in:
Geoffrey McRae 2018-05-24 11:56:11 +10:00
parent c42bff99e2
commit a4600e7278

View file

@ -66,6 +66,7 @@ struct AppState
int shmFD; int shmFD;
struct KVMFRHeader * shm; struct KVMFRHeader * shm;
unsigned int shmSize; unsigned int shmSize;
unsigned int fpsSleep;
}; };
typedef struct RenderOpts typedef struct RenderOpts
@ -89,6 +90,7 @@ struct AppParams
unsigned int w, h; unsigned int w, h;
char * shmFile; char * shmFile;
unsigned int shmSize; unsigned int shmSize;
unsigned int fpsLimit;
bool showFPS; bool showFPS;
bool useSpice; bool useSpice;
char * spiceHost; char * spiceHost;
@ -118,6 +120,7 @@ struct AppParams params =
.h = 768, .h = 768,
.shmFile = "/dev/shm/looking-glass", .shmFile = "/dev/shm/looking-glass",
.shmSize = 0, .shmSize = 0,
.fpsLimit = 200,
.showFPS = false, .showFPS = false,
.useSpice = true, .useSpice = true,
.spiceHost = "127.0.0.1", .spiceHost = "127.0.0.1",
@ -191,9 +194,12 @@ int renderThread(void * unused)
if (!state.lgr->render(state.lgrData, state.window)) if (!state.lgr->render(state.lgrData, state.window))
break; break;
// put some breaks on (400fps) if we are rendering too fast if (microtime() - start < state.fpsSleep)
if (microtime() - start < (1000000/400)) {
usleep((1000000/400) - (microtime() - start)); usleep(state.fpsSleep - (microtime() - start));
int64_t delta = (1000000 / params.fpsLimit) - (microtime() - start);
state.fpsSleep += delta;
}
} }
else else
usleep(1000000); usleep(1000000);
@ -689,9 +695,10 @@ int run()
DEBUG_INFO("Locking Method: " LG_LOCK_MODE); DEBUG_INFO("Locking Method: " LG_LOCK_MODE);
memset(&state, 0, sizeof(state)); memset(&state, 0, sizeof(state));
state.running = true; state.running = true;
state.scaleX = 1.0f; state.scaleX = 1.0f;
state.scaleY = 1.0f; state.scaleY = 1.0f;
state.fpsSleep = 1000000 / params.fpsLimit;
if (SDL_Init(SDL_INIT_VIDEO) < 0) if (SDL_Init(SDL_INIT_VIDEO) < 0)
{ {
@ -1016,6 +1023,7 @@ void doHelp(char * app)
" -j Disable cursor position scaling\n" " -j Disable cursor position scaling\n"
" -M Don't hide the host cursor\n" " -M Don't hide the host cursor\n"
"\n" "\n"
" -K Set the FPS limit [current: %d]\n"
" -k Enable FPS display\n" " -k Enable FPS display\n"
" -g NAME Force the use of a specific renderer\n" " -g NAME Force the use of a specific renderer\n"
" -o OPTION Specify a renderer option (ie: opengl:vsync=0)\n" " -o OPTION Specify a renderer option (ie: opengl:vsync=0)\n"
@ -1040,6 +1048,7 @@ void doHelp(char * app)
params.shmSize, params.shmSize,
params.spiceHost, params.spiceHost,
params.spicePort, params.spicePort,
params.fpsLimit,
params.center ? "center" : x, params.center ? "center" : x,
params.center ? "center" : y, params.center ? "center" : y,
params.w, params.w,
@ -1154,6 +1163,17 @@ static bool load_config(const char * configFile)
} }
params.h = (unsigned int)itmp; params.h = (unsigned int)itmp;
} }
if (config_setting_lookup_int(global, "fpsLimit", &itmp))
{
if (itmp < 1)
{
DEBUG_ERROR("Invalid FPS limit, must be greater then 0");
config_destroy(&cfg);
return false;
}
params.fpsLimit = (unsigned int)itmp;
}
} }
config_setting_t * spice = config_lookup(&cfg, "spice"); config_setting_t * spice = config_lookup(&cfg, "spice");
@ -1247,7 +1267,7 @@ int main(int argc, char * argv[])
for(;;) for(;;)
{ {
switch(getopt(argc, argv, "hC:f:L:sc:p:jMvkg:o:anrdFx:y:w:b:Ql")) switch(getopt(argc, argv, "hC:f:L:sc:p:jMvK:kg:o:anrdFx:y:w:b:Ql"))
{ {
case '?': case '?':
case 'h': case 'h':
@ -1294,6 +1314,10 @@ int main(int argc, char * argv[])
params.hideMouse = false; params.hideMouse = false;
continue; continue;
case 'K':
params.fpsLimit = atoi(optarg);
continue;
case 'k': case 'k':
params.showFPS = true; params.showFPS = true;
continue; continue;