Page 1 of 1

Limiting framerate / timestep when player's GPU doesn't support vsync?

Posted: Thu Oct 19, 2017 12:43 am
by RonanZero
My game is fixed-timestep based. 60 updates per second. Some players with old GPUs / cheap laptops have an issue where the framerate is above 60, completely uncapped, causing it to speed up, even though I have vsync enabled in conf.lua and added cases for higher hz monitors. I don't *need* a 60fps lock, just a 60hz timestep lock where love.update() is only called up to 60 times per second or something, doesn't matter how many times love.draw() is called. How can I force only 60 updates per second without the power of vsync?

Note: I know about deltatime and I'm not planning to use it, the game is already coded for a fixed update rate, deltatime is for variable update rates.

Re: Limiting framerate / timestep when player's GPU doesn't support vsync?

Posted: Thu Oct 19, 2017 12:52 am
by grump
I don't think there is an easy way to decouple the number of calls to update() and draw(), they're all done in the same loop by default.

You could love.timer.sleep in each frame for the remainder of the time slice. A good way to do this would probably be to supply our own love.run, with a dynamic sleep duration to match your 60 Hz maximum.

Re: Limiting framerate / timestep when player's GPU doesn't support vsync?

Posted: Thu Oct 19, 2017 12:54 am
by Azhukar
Here's some interesting insight on the topic https://www.factorio.com/blog/post/fff-70

Re: Limiting framerate / timestep when player's GPU doesn't support vsync?

Posted: Thu Oct 19, 2017 2:31 am
by zorg
How about you do use deltatime in the following (or similar) way:

Code: Select all

local accum = 0.0
love.update = function(dt)
    accum = accum + dt
    if accum >= timestep then
        -- do actual update stuff here
        accum = accum - timestep
    end
end
Edit: edited, thanks grump! :3

Re: Limiting framerate / timestep when player's GPU doesn't support vsync?

Posted: Thu Oct 19, 2017 2:45 am
by grump
zorg wrote: Thu Oct 19, 2017 2:31 am

Code: Select all

    if accum > timestep then
accum >= timestep?