Different fps on different machines

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
megalukes
Citizen
Posts: 94
Joined: Fri Jun 27, 2014 11:29 pm
Location: Brazil

Different fps on different machines

Post by megalukes »

I usually run love on Mac and Windows 10. With vsync on, my fps is alway locked in 60 on my iMac, but when I run the same .love on Windows 10, fps keeps oscilating between 56-59 and it never reaches 60. Is there a reason for that?
User avatar
evölbug
Prole
Posts: 38
Joined: Wed Dec 21, 2016 12:58 pm
Contact:

Re: Different fps on different machines

Post by evölbug »

Different machines with differing specs. It's fine as long as you use delta time (dt) to compensate for FPS changes in your code.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Different fps on different machines

Post by Positive07 »

VSync synchronizes to the screen FPS, if your screen has 59/58 FPS instead of 60 you won't get 60 FPS... It's as simple as that. If you don't use VSync you are tied to the CPU so it depends on what the CPU wants to give you and you may get greater variations on FPS.

zorg uses a custom love.run that gives you something close to constant 60 FPS... But you will never get perfect accuracy, so you should ALWAYS use dt
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Different fps on different machines

Post by zorg »

Positive07 wrote: Sat Mar 04, 2017 11:31 pm zorg uses a custom love.run that gives you something close to constant 60 FPS... But you will never get perfect accuracy, so you should ALWAYS use dt
Hello :3
Just wanted to mention that mine also uses dt, and without vsync, that's why i can separate the game loop into different speeds for updating and drawing things.
It has its own caveats though, of course; e.g. my usual loop doesn't use interpolation with drawing, so no matter how many updates happened, drawing will always render with the current state of the game, whatever that may be. It also doesn't do anything against screen tearing.
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
megalukes
Citizen
Posts: 94
Joined: Fri Jun 27, 2014 11:29 pm
Location: Brazil

Re: Different fps on different machines

Post by megalukes »

Could you share your love.run code? I'd like to have a look, if that's ok. Thanks for the answers, guys.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Different fps on different machines

Post by zorg »

megalukes wrote: Sun Mar 05, 2017 4:23 am Could you share your love.run code? I'd like to have a look, if that's ok. Thanks for the answers, guys.
Sure, just needed to sleep a bit.

Code: Select all

love.run = function()
	if love.math then
		love.math.setRandomSeed(os.time())
	end
 
	if love.load then love.load(arg) end
 
	-- We don't want the first frame's dt to include time taken by love.load.
	if love.timer then love.timer.step() end

	local dt = 0.0    -- delta time
 
	local tr = 1/60  -- tick rate
	local fr = 1/60   -- frame rate (this can be set dynamically to the screen's refresh rate too, with a bit of trickery :P)

	local da = 0.0    -- draw accumulator
	local ua = 0.0    -- update accumulator
 
	-- Main loop time.
	while true do
		-- Process events.
		if love.event then
			love.event.pump()
			for name, a,b,c,d,e,f in love.event.poll() do
				if name == "quit" then
					if not love.quit or not love.quit() then
						return a
					end
				end
				love.handlers[name](a,b,c,d,e,f)
			end
		end
 
		-- Update dt, as we'll be passing it to update
		if love.timer then
			love.timer.step()
			dt = love.timer.getDelta()
			da = da + dt
			ua = ua + dt
		end
 
		-- Call atomic
		if love.atomic then love.atomic(dt) end

		-- Call update
		if ua > tr then
			if love.update then
				love.update(tr) -- will pass 0 if love.timer is disabled
			end
			ua = ua % tr
		end
 
		-- Call draw
		if da > fr then
			if love.graphics and love.graphics.isActive() then
				love.graphics.clear(love.graphics.getBackgroundColor())
				love.graphics.origin()
				if love.draw then love.draw() end -- no interpolation
				love.graphics.present()
			end
			da = da % fr
		end
 
		-- Optimal sleep time (for my pc, anyway), anything higher does not go below 0.40 % cpu utilization;
		-- 0.001 results in 0.72 %, so this is an improvement.
		if love.timer then love.timer.sleep(0.002) end
	end
end
As i said above, this will only work "correctly" if you turn off vsync.
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], lenlenlL6 and 48 guests