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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
RonanZero
Citizen
Posts: 90
Joined: Mon Oct 20, 2014 3:33 am

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

Post 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.
while true do end;
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

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

Post 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.
Last edited by grump on Thu Oct 19, 2017 12:57 am, edited 1 time in total.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

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

Post by Azhukar »

Here's some interesting insight on the topic https://www.factorio.com/blog/post/fff-70
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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
Last edited by zorg on Thu Oct 19, 2017 2:57 am, edited 2 times in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

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

Post by grump »

zorg wrote: Thu Oct 19, 2017 2:31 am

Code: Select all

    if accum > timestep then
accum >= timestep?
Post Reply

Who is online

Users browsing this forum: No registered users and 50 guests