LOVE lag spikes

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.
bizziboi
Citizen
Posts: 57
Joined: Sat Apr 16, 2011 9:24 am

Re: LOVE lag spikes

Post by bizziboi »

The pattern seems quite consistent, which suggests interference with something. A system process? VSync?

Does it happen if you give the love process highest priority?
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: LOVE lag spikes

Post by Luke100000 »

I deactivate vsync: it works. That's strange because I've tested this some days before...

How important is vsync? Can I disable it for all my games?
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: LOVE lag spikes

Post by rmcode »

Luke100000 wrote:How important is vsync? Can I disable it for all my games?

It depends on your games really. If you deactivate vsync the game will run as fast as it can (which can lead to unexpected behaviour).

Here is an example:

Code: Select all

function love.load()
    love.window.setMode(640, 480, { vsync = true });
end

local x = 0;
function love.update(dt)
    x = x + 1;
end

function love.draw()
    love.graphics.circle('fill', x, 20, 5, 20);

    love.graphics.print(string.format("FT: %.3f ms", 1000 * love.timer.getAverageDelta()), 10, love.window.getHeight() - 60);
    love.graphics.print(string.format("FPS: %.3f fps", love.timer.getFPS()), 10, love.window.getHeight() - 40);
end
When vsync is activated (and your pc is fast enough to run this at 60 fps) the circle will move at a constant rate across the monitor. Now if you deactivate {vsync = false} in love.load() you will see that it moves much faster and not at a constant rate.

This is where delta time (dt) comes into play:

Code: Select all

function love.load()
    love.window.setMode(640, 480, { vsync = true });
end

local x = 0;
local speed = 10;
function love.update(dt)
    x = x + speed * dt;
end

function love.draw()
    love.graphics.circle('fill', x, 20, 5, 20);

    love.graphics.print(string.format("FT: %.3f ms", 1000 * love.timer.getAverageDelta()), 10, love.window.getHeight() - 60);
    love.graphics.print(string.format("FPS: %.3f fps", love.timer.getFPS()), 10, love.window.getHeight() - 40);
end
Now the circle will move the same distance regardless of the framerate. Because instead of saying: "move one pixel each update" you are telling the program to move the object at a certain speed (e.g. 10 pixels per second).

This is preferred, because it also means that older computers can run the game without getting different gameplay results. You can test this by decreasing the framerate:

Code: Select all

function love.load()
    love.window.setMode(640, 480, { vsync = true });
end

local x = 0;
local speed = 10;
function love.update(dt)
    x = x + speed * dt;

    -- Lower framerate manually
    local foo = "";
    for i = 1, 10000000 do
        foo = foo .. "";
    end
end

function love.draw()
    love.graphics.circle('fill', x, 20, 5, 20);

    love.graphics.print(string.format("FT: %.3f ms", 1000 * love.timer.getAverageDelta()), 10, love.window.getHeight() - 60);
    love.graphics.print(string.format("FPS: %.3f fps", love.timer.getFPS()), 10, love.window.getHeight() - 40);
end
Note how the circle still moves the same distance even when the framerate drops. Hope that helps.

P.S.: Windows XP is a bit ancient :)
bizziboi
Citizen
Posts: 57
Joined: Sat Apr 16, 2011 9:24 am

Re: LOVE lag spikes

Post by bizziboi »

If I'm not mistaking there's another side effect to turning off vsync, screen tearing. IMO you're better off keeping vsync enabled and still using dt to get constant motion - that way the lag spikes won't show up as hiccups in perceived movement.
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: LOVE lag spikes

Post by Luke100000 »

bizziboi wrote:If I'm not mistaking there's another side effect to turning off vsync, screen tearing. IMO you're better off keeping vsync enabled and still using dt to get constant motion - that way the lag spikes won't show up as hiccups in perceived movement.
Could be a good idea, and I'm using dt, but the lag spikes take 0.4ms. :death:
Goober
Prole
Posts: 6
Joined: Wed Mar 11, 2015 9:28 pm

Re: LOVE lag spikes

Post by Goober »

Have you figured out a solution to this yet? I'm experiencing this too. When using dt, things move at a constant rate, but when tit spikes, things jump a bit, since it's been a lot of frames since they've updated. It looks pretty bad.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: LOVE lag spikes

Post by T-Bone »

Even with vsync activated, you cannot assume that the game will run at a constant frame rate, because the computer may have poor graphics drivers or may not even support vsync at all, or might be too slow to reach a steady frame rate. In other words, you need to use dt properly no matter what.

And yes, you can just disable vsync if it causes problems for you. For bigger games, I would suggest including an in-game option for enabling/disabling vsync, as different computers behave differently.
User avatar
BOT-Brad
Citizen
Posts: 87
Joined: Tue Dec 02, 2014 2:17 pm
Location: England

Re: LOVE lag spikes

Post by BOT-Brad »

T-Bone wrote:Even with vsync activated, you cannot assume that the game will run at a constant frame rate, because the computer may have poor graphics drivers or may not even support vsync at all, or might be too slow to reach a steady frame rate. In other words, you need to use dt properly no matter what.

And yes, you can just disable vsync if it causes problems for you. For bigger games, I would suggest including an in-game option for enabling/disabling vsync, as different computers behave differently.
Just to add to this, is there anyway to enabled/disable vsync during run-time? Or do I need the user to restart the application/game and change it in conf.lua?
Follow me on GitHub! | Send me a friend request on PSN!
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: LOVE lag spikes

Post by s-ol »

BOT-Brad wrote:
T-Bone wrote:Even with vsync activated, you cannot assume that the game will run at a constant frame rate, because the computer may have poor graphics drivers or may not even support vsync at all, or might be too slow to reach a steady frame rate. In other words, you need to use dt properly no matter what.

And yes, you can just disable vsync if it causes problems for you. For bigger games, I would suggest including an in-game option for enabling/disabling vsync, as different computers behave differently.
Just to add to this, is there anyway to enabled/disable vsync during run-time? Or do I need the user to restart the application/game and change it in conf.lua?
https://love2d.org/wiki/love.window.setMode

there is a "vsync" attribute in the flags option.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
BOT-Brad
Citizen
Posts: 87
Joined: Tue Dec 02, 2014 2:17 pm
Location: England

Re: LOVE lag spikes

Post by BOT-Brad »

S0lll0s wrote:
BOT-Brad wrote:
T-Bone wrote:Even with vsync activated, you cannot assume that the game will run at a constant frame rate, because the computer may have poor graphics drivers or may not even support vsync at all, or might be too slow to reach a steady frame rate. In other words, you need to use dt properly no matter what.

And yes, you can just disable vsync if it causes problems for you. For bigger games, I would suggest including an in-game option for enabling/disabling vsync, as different computers behave differently.
Just to add to this, is there anyway to enabled/disable vsync during run-time? Or do I need the user to restart the application/game and change it in conf.lua?
https://love2d.org/wiki/love.window.setMode

there is a "vsync" attribute in the flags option.
Nice one, thanks!
Follow me on GitHub! | Send me a friend request on PSN!
Post Reply

Who is online

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