evgiz wrote:If you're using the default love.run function, I'm pretty sure it limits the FPS you can get.
Check this out:
https://love2d.org/wiki/love.run
I'm pretty sure this line near the bottom is to prevent the application from using too much of the CPU and therefore limiting the FPS.
Code: Select all
if love.timer then love.timer.sleep(0.001) end
Please correct me if I'm wrong though.
You point in the right direction. I did some experiments with love.run() today and wrote a modified version for my game. I expirienced the actual fps is 1 more than the requested. I assume some rounding errors in the floating point math. (e.g. 30fps gives me 31fps, 60fps->61fps,...). The loop time looks very stable, if i set vsync=false. (vsync=true results in some aditional sleep(), i dont want in this situation.) And 20..30fps are good enouth for my MasterOfMagic/Civilisation like game. I added 3 lines of debug-print, that allows me to judge the speed of different versions of my code. May be, in the final version i go back to the builtin love.run() and vsync=true.
Code: Select all
function love.run()
local fps = 20;
local getTime = love.timer.getTime
local sleepTime = 1 / fps;
if love.math then love.math.setRandomSeed(os.time()) end;
if love.load then love.load(arg) end;
-- We don't want the first frame's dt to include time taken by love.load.
if love.timer then love.timer.step() end
local dt = 0
local time = getTime()
-- Main loop time.
while true do
-- Process events.
if love.event then
love.event.pump()
for name, a,b,c,d,e,f in love.event.poll() do
if name == "quit" and (not love.quit or not love.quit()) then return a; end;
love.handlers[name](a,b,c,d,e,f);
end
end
local deltaTime;
if love.timer then
local newTime = getTime()
deltaTime = getTime() - time;
love.timer.sleep(max(sleepTime-(deltaTime), 0.001));
time = getTime()
-- Update dt, as we'll be passing it to update
love.timer.step()
dt = love.timer.getDelta()
end
-- Call update and draw
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics and love.graphics.isActive() then
love.graphics.clear(love.graphics.getBackgroundColor());
love.graphics.origin();
if love.draw then love.draw() end;
if __DEBUG then
love.graphics.print(("dt: %04d ms"):format(dt*1000), 10, 10);
love.graphics.print(("fps: %02d"):format(love.timer.getFPS()), 10, 30);
love.graphics.print(("lua load: %02d %%"):format(deltaTime/dt*100), 10, 50);
end;
love.graphics.present();
end;
--
end;
end;
The main bottleneck on my Win7 pc is the Intel GPU. Drawing a 1600x900 screen 30x per second gives me 100% gpu load. To test my lua code i use a 800x600 window now and avoid the gpu bottleneck this way. At least i learned a lot about löve and my gpu
![Smile :)](./images/smilies/ms-smile.png)