LÖVE framerate stutters?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: LÖVE framerate stutters?
TBH I wouldn't rely on vsync. Some GPU's,Operating systems or driver setups wont sync correctly. This gets especially bad with monitors that have strange refresh rates from what ive seen. I usually disable vsync. If your game is being a total resource hog with vsync off you can always modify love.run, either to sleep for longer periods of time or change to a fixed timestep.
- slime
- Solid Snayke
- Posts: 3156
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: LÖVE framerate stutters?
Well, the OS system call that love.timer.sleep uses is inherently inaccurate (on Windows in particular.)Sapper wrote:either to sleep for longer periods of time or change to a fixed timestep.
Doing a proper fixed timestep requires a lot more code complexity than the default variable timestep.
Re: LÖVE framerate stutters?
have you investigated if it's the garbage collector?
try 'collectgarbage(''stop")' at the start of your minimal test case.
try 'collectgarbage(''stop")' at the start of your minimal test case.
Re: LÖVE framerate stutters?
Fixed timesteps arent really that complex, especially if you keep it all in love.run.slime wrote:Well, the OS system call that love.timer.sleep uses is inherently inaccurate (on Windows in particular.)Sapper wrote:either to sleep for longer periods of time or change to a fixed timestep.
Doing a proper fixed timestep requires a lot more code complexity than the default variable timestep.
Heres one I just made. Probably not the best / most accurate timestep but it seems to look and play pretty smooth.
Love.draw is only called after love.run, helps with making collision resolution look good + dramatically lowers RAM and
CPU usage on my awful old computer.
(im not sure what the overhead would be but if you make targetTime global then you can change gamespeed on-the-fly)
Code: Select all
function love.run()
math.randomseed(os.time())
math.random() math.random()
if love.load then love.load(arg) end
local targetTime = 1/50
local nextUpdate = love.timer.getTime()
while true do
if love.event then
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
end
local ctime = love.timer.getTime()
if ctime > nextUpdate then
local xtra = ctime - nextUpdate
love.update()
love.graphics.clear()
love.graphics.origin()
love.draw()
love.graphics.present()
nextUpdate = nextUpdate + targetTime + xtra
end
love.timer.sleep(0.001)
end
end
![ROFL :rofl:](./images/smilies/ms-rofl.png)
- slime
- Solid Snayke
- Posts: 3156
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: LÖVE framerate stutters?
You can't actually have a true fixed-timestep draw function though. There are so many factors (many of them external to LÖVE) that affect whether a graphics frame will hit the mark, that it won't be reliable at all. You'll definitely want a variable-rate draw if you have a fixed-rate update, if you want everything to be smooth.
This is a good read: http://gafferongames.com/game-physics/f ... -timestep/
This is a good read: http://gafferongames.com/game-physics/f ... -timestep/
Re: LÖVE framerate stutters?
Great suggestion, thanks!szensk wrote:have you investigated if it's the garbage collector?
try 'collectgarbage(''stop")' at the start of your minimal test case.
Things get weird ...
- Disabling the GC suppress the stutter on my own program! (But now it eat all the available RAM until being automatically killed, so I think something must be very wrong in my code - or maybe love doesn't like having the GC disabled)
- Disabling the GC does not suppress the stutter on the stuttertest (on machine with ATI card)
- I don't reproduce the stutter on my office computer (win8 x64 without ATI card, it has a poor built-in graphic card)
Re: LÖVE framerate stutters?
Yeah i know, i guess its not really noticable when youre dealing with 320x240 resolutionsslime wrote:You can't actually have a true fixed-timestep draw function though. There are so many factors (many of them external to LÖVE) that affect whether a graphics frame will hit the mark, that it won't be reliable at all. You'll definitely want a variable-rate draw if you have a fixed-rate update, if you want everything to be smooth.
This is a good read: http://gafferongames.com/game-physics/f ... -timestep/
![Ultrahappy :ultrahappy:](./images/smilies/ms-ultrahappy.png)
On most computers variable-framerate drawing seems really smooth, its just on all of mine that the framerate
bounces around from 45 to 64
![Death :death:](./images/smilies/ms-death.png)
sometimes i wish i was back in the NES era, where the framerate was always a steady 60fps(if you were an assembly wizard)
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: LÖVE framerate stutters?
That's completely normal, and doesn't have anything to do with your code or LÖVE: of course the garbage is going to heap up if you don't collect it!bcolin wrote:(But now it eat all the available RAM until being automatically killed, so I think something must be very wrong in my code - or maybe love doesn't like having the GC disabled)
If the garbage collector is what's causing the stuttering in your code, though, you probably create and discard too many resources (like calling love.something.newSomething() every frame.
Help us help you: attach a .love.
Re: LÖVE framerate stutters?
Stopping the garbage collector stopped the stuttering? Keep it stopped and call collectgarbage("step", 1) each update. I'd test it myself but I'm at school.
But as Robin says, make sure you are not creating objects each frame. Especially something that you don't need to recreate each frame.
But as Robin says, make sure you are not creating objects each frame. Especially something that you don't need to recreate each frame.
Re: LÖVE framerate stutters?
Does this stutter occur elsewhere like in other games?
Who is online
Users browsing this forum: Bing [Bot] and 1 guest