Page 2 of 2

Re: LOVE lag spikes

Posted: Thu Feb 12, 2015 5:41 am
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?

Re: LOVE lag spikes

Posted: Thu Feb 12, 2015 4:18 pm
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?

Re: LOVE lag spikes

Posted: Thu Feb 12, 2015 4:45 pm
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 :)

Re: LOVE lag spikes

Posted: Fri Feb 13, 2015 5:06 am
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.

Re: LOVE lag spikes

Posted: Sat Feb 14, 2015 4:27 pm
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:

Re: LOVE lag spikes

Posted: Mon Apr 06, 2015 11:21 pm
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.

Re: LOVE lag spikes

Posted: Tue Apr 07, 2015 6:37 pm
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.

Re: LOVE lag spikes

Posted: Fri Apr 10, 2015 10:40 pm
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?

Re: LOVE lag spikes

Posted: Fri Apr 10, 2015 10:43 pm
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.

Re: LOVE lag spikes

Posted: Fri Apr 10, 2015 10:49 pm
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!