VSync - Half Refresh / Skip Frames

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
09jlardinois
Prole
Posts: 1
Joined: Sat Jul 07, 2018 12:53 am

VSync - Half Refresh / Skip Frames

Post 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.
User avatar
milk
Prole
Posts: 39
Joined: Sun Jul 17, 2016 7:20 pm

Re: VSync - Half Refresh / Skip Frames

Post 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
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: VSync - Half Refresh / Skip Frames

Post 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.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: VSync - Half Refresh / Skip Frames

Post 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.
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.
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: VSync - Half Refresh / Skip Frames

Post by Tjakka5 »

I also wonder why you would limit people that have paid for a high refresh rate monitor to 30 fps
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: VSync - Half Refresh / Skip Frames

Post 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.
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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 3 guests