ioquake / ioq3

The ioquake3 community effort to continue supporting/developing id's Quake III Arena
https://www.ioquake3.org/
GNU General Public License v2.0
2.34k stars 523 forks source link

Fix framerate throttling in Emscripten builds #672

Closed jdarpinian closed 1 week ago

jdarpinian commented 1 week ago

Default com_maxfps to 0 under Emscripten. Under Emscripten the browser handles throttling the frame rate. Manual framerate throttling interacts poorly with Emscripten's browser-driven event loop.

zturtleman commented 1 week ago

This commit should also set r_swapInterval to 1 to ensure V-sync is enabled otherwise com_maxfps 0 runs as fast as possible after vid_restart (135 FPS for me). Please use #ifdef __EMSCRIPTEN__ as it's more consistent with platform defines.

I think it would be good to not use V-sync by default and improve handling of com_maxfps itself but that a larger change and this PR would be fine for now (with the above things fixed). https://github.com/ioquake/ioq3/issues/675

jdarpinian commented 1 week ago

Done, thanks for the feedback

zturtleman commented 1 week ago

You can remove the two "See here for discussion: https://github.com/ioquake/ioq3/issues/675" in the source code. I don't think it adds value for future reference.

You can leave r_swapInterval as two separate lines so the original case is unchanged (and matches the opengl1 renderer).

#ifdef __EMSCRIPTEN__
    // Under Emscripten we don't throttle framerate with com_maxfps by default, so enable
    // vsync by default instead.
    r_swapInterval = ri.Cvar_Get( "r_swapInterval", "1",
                    CVAR_ARCHIVE | CVAR_LATCH );
#else
    r_swapInterval = ri.Cvar_Get( "r_swapInterval", "0",
                    CVAR_ARCHIVE | CVAR_LATCH );
#endif
zturtleman commented 1 week ago

Thanks.