1. Anders Ruud
  2. love

Issues

Issue #377 invalid

[0.8.0] getFPS() returns double what it should if graphics is disabled

Anonymous created an issue

I'm guessing this is due to love.timer.step() being called twice somewhere when graphics are disabled, but I'm not sure. You can reproduce this with this code:

{{{

!lua

local min_dt = 1/60 local next_time = 0

function love.update(dt) if love.timer.getTime() >= next_time then print("FPS: " .. love.timer.getFPS()) next_time = love.timer.getTime() + 1 end

if dt < min_dt then
    love.timer.sleep(min_dt - dt)
end

end }}}

And in your conf.lua, add the t.modules.graphics = false line (of course.) FPS will be about 120. Now enable graphics, and it's 60. This is LOVE 0.8.0.

Comments (2)

  1. Boolsheet

    You made an error in your sleep time calculation. Let's say in this case, where the graphics module has been disabled, a frame is one call to love.update. Your code takes 1/60 and subtracts dt (the time difference from the beginning of the last frame to the beginning of the current frame) and sleeps that amount of time for the rest of the current frame. If the last frame took ~15 ms the current frame will sleep for ~1 ms.

    If the code doesn't do any work, like your example, it should always sleep ~16 ms.

    You probably want to measure how long the current frame takes and subtract that from 1/60.

  2. Matthias Richter

    Boolsheet is correct. Try this code:

    function love.update()
        local enter = love.timer.getTime()
        if enter >= next_time then
            print("FPS: " .. love.timer.getFPS())
            next_time = love.timer.getTime() + 1
        end
    
        local delta = love.timer.getTime() - enter
        if delta < min_dt then
            love.timer.sleep(min_dt - delta)
        end
    end
    
  3. Log in to comment