Page 2 of 2

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 7:08 pm
by Nixola
You do NOT have to change DT, unless you know what you're doing, changing DT will not change the framerate. The wiki has also a more complex snip that caps more accurately

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 7:37 pm
by Number-41
I don't want to cap accurately (if that means a matter of 5 or 6 fps), I just want a clear way on how to reduce it to around 50. Which none of the above methods (or the one on the wiki) do (though thanks for the quick replies :) ).

Also the wiki says that it doesn't support that function anymore in 8.0.

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 7:49 pm
by slime
Here's my love.run. It works decently, although I get stuttering at <= 60 max fps, but I'm not sure what to do about it.

Code: Select all

function love.run()
	love.load(arg)

	local dt = 0
	
	while true do
		local frametimestart = love.timer.getMicroTime()
		
		love.event.pump()
		
		for e,a,b,c,d in love.event.poll() do
			if e == "quit" then
				if not love.quit or not love.quit() then
					if love.audio then
						love.audio.stop()
					end
					return
				end
			end
			love.handlers[e](a,b,c,d)
		end

		love.timer.step()
		dt = love.timer.getDelta()

		love.update(dt)
		
		love.graphics.clear()
		love.draw()
		love.graphics.present()
		
		local frametimeend = love.timer.getMicroTime()
		local framedelta = frametimeend - frametimestart
		
		if maxfps and maxfps > 0 then -- 0 is unlimited
			local max_dt = 1/maxfps
			local sleeptime = max_dt - framedelta
			
			if sleeptime >= 0.001 then -- love will truncate anything less than 1ms down to 0 internally
				love.timer.sleep(sleeptime)
			end
		else
			love.timer.sleep(0.001)
		end
	end
end

Re: How to limit my frames per second?

Posted: Tue May 29, 2012 5:37 am
by Robin
tsturzl wrote:using the sleep timer just idles the instructions for that duration. You should set the cap through dt, dt is a pointer that references a value from my understanding. Therefore allowing you to change its value outside your scope.
That is all kinds of wrong.
slime wrote:Here's my love.run. It works decently, although I get stuttering at <= 60 max fps, but I'm not sure what to do about it.
Maybe it works better if you provide an upper limit for sleeptime.

Re: How to limit my frames per second?

Posted: Tue May 29, 2012 3:34 pm
by Lap
I've enjoyed this more general article:

http://gafferongames.com/game-physics/f ... -timestep/

Re: How to limit my frames per second?

Posted: Tue May 29, 2012 7:38 pm
by Inny
If nothing changes during a love.update, then whatever your draw in the next love.draw will be identical to the previous frame. In that regard, you accumulate up enough love.update calls and then react when enough has been called to fit your desired framerate. For instance:

Code: Select all

dt_buffer = 0
desired = 1/60
function love.update(dt)
    dt_buffer = dt_buffer + dt
    if dt_buffer > desired then
        dt_buffer = dt_buffer - desired
        updateWorld()
    end
end