Page 1 of 1

VSync - Half Refresh / Skip Frames

Posted: Sat Jul 07, 2018 12:58 am
by 09jlardinois
Hello,

I search for help on the forums and wiki. (Queries: vsync, vsync half, vsync skip frames, vsync skip) and could not find my answer. I'd appreciate any help.

Does Love 2D have a VSync option for half-refresh rate or skip a certain number of frames? And if so, what is the syntax for it?

I'd like VSync to be locked at 30FPS for 60Hz monitors (Skip 1 / Half) and also 30FPS for 120Hz monitors. (Skip 3 / Quarter).

This doesn't pertain to any project (I don't have any yet!), but is just more of a curiosity. I don't think that I'll ever really make anything in this engine that requires such drastic FPS handling, but I'm just curious if it exists.

Thanks, Community.

Re: VSync - Half Refresh / Skip Frames

Posted: Sat Jul 07, 2018 4:36 am
by milk
There's no command for setting FPS directly, this should work for your usage though:

Code: Select all

function love.load()
   min_dt = 1/30 --fps
   next_time = love.timer.getTime()
end
 
function love.update(dt)
   next_time = next_time + min_dt
 
   --rest of function here
end
 
function love.draw()
   --rest of function here
 
   local cur_time = love.timer.getTime()
   if next_time <= cur_time then
      next_time = cur_time
      return
   end
   love.timer.sleep(next_time - cur_time)
end

Re: VSync - Half Refresh / Skip Frames

Posted: Sat Jul 07, 2018 5:30 am
by ivan
Oh dear, there are much better ways than using love.sleep.
VSync ensures that stuff is drawn whenever the video card is ready.
You can't just use love.sleep and expect that everything will work fine.
Does Love 2D have a VSync option for half-refresh rate or skip a certain number of frames? And if so, what is the syntax for it?
No. You can draw to canvas each odd frame and then redraw the previously rendered canvas each even frame.
Not sure why you want to do that, but it will drop the frame rate in half for you.
Note that love.update needs to be adjusted too, since you don't need to run any code if nothing changes on the screen.

Re: VSync - Half Refresh / Skip Frames

Posted: Sat Jul 07, 2018 5:34 am
by zorg
milk wrote: Sat Jul 07, 2018 4:36 am There's no command for setting FPS directly, this should work for your usage though:

Code: Select all

[i]no[/i]
If you are going to double-cross the game loop, at least have the decency to look at love.run and edit that too, since with the above code only, you're doing timing based on that code AND the one in the default love.run.

Also, 11.0 did add that kind of vsync options to conf.lua, or more specifically, to love.window.setMode and its ilk (also updateMode):

"Changed the 'vsync' field of love.window.setMode and t.window in love.conf. It's now an integer with 0 disabling vsync."

any integer above 0 means that many divisions to the current screen's refresh rate.

Re: VSync - Half Refresh / Skip Frames

Posted: Sat Jul 07, 2018 11:31 am
by Tjakka5
I also wonder why you would limit people that have paid for a high refresh rate monitor to 30 fps

Re: VSync - Half Refresh / Skip Frames

Posted: Sat Jul 07, 2018 3:35 pm
by zorg
BTW, there's still such a thing as decoupling the input/update or tickrate from the framerate itself, through various ways, some better than others.