Page 1 of 1
[solved] fps, vsync related question
Posted: Sat Oct 15, 2016 9:49 am
by Fuzzlix
Hi, lövly folks
I am quite new to löve and started coding in löve 2 weeks ago. This forum is a great help and a source of tips and inspirations.
I created a 2d worldmap with tiles and draw it in love.draw().
With vsync=true i reached 60fps and 5%cpu. - FINE!
I wrote more and more (uneffective) code into love.update(dt)
With vsync=true i reached 15fps and 99%cpu. - BAD!
I optimized my code and went back to 60fps and lower cpu load. - OK!
I tried to find out how fast my code runs and set vsync=false. The fps went up to 300fps and heavy cpu load.
I optimized more and the cpu load dropped down below 10% BUT the fps still sticks at 300fps.
Now my question:
Is there some fps-hard-limit implemented? Can i disable this hardlimit for testing purposes? Or i am thinking in a wrong direction?
Thanks in advance.
Fuzzlix.
Re: fps, vsync related question
Posted: Sat Oct 15, 2016 12:36 pm
by RaycatRakittra
'FPS', by default, is unlimited. It's the number of times the game is updating. I'm unsure of whatever code you wrote but if you think it's ineffective, it probably is. For all the other issues:
https://github.com/bjornbytes/tick
Re: fps, vsync related question
Posted: Sat Oct 15, 2016 1:06 pm
by zorg
If vsync is off, then yes, the speed of your löve program is only limited by the speed of one core on your CPU. If vsync is on, since löve uses the main thread for graphics as well, the frame limiting will effectively throttle your processing speed as well, not just the rendering speed.
Still, try vsync on with your latest code, if your cpu consumption is still high with it, then you could attach a .love file so we can see what any errors might be.
Also, vsync using 99% cpu even without too much processing can also mean that your OS is doing something stupid, i think, but i'm not sure.
[solved]: fps, vsync related question
Posted: Sat Oct 15, 2016 1:08 pm
by Fuzzlix
RaycatRakittra wrote:'FPS', by default, is unlimited. It's the number of times the game is updating. I'm unsure of whatever code you wrote but if you think it's ineffective, it probably is. For all the other issues:
https://github.com/bjornbytes/tick
Thanks for the tip. ... I found the bottleneck: It is the Intel-GPU inside my Celeron. I hit 100% GPU load by drawing a 230x200 canvas scaled up to a 1600x900 window.
Question answered.
Re: [solved] fps, vsync related question
Posted: Sat Oct 15, 2016 4:32 pm
by evgiz
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.
Re: [solved] fps, vsync related question
Posted: Sat Oct 15, 2016 8:47 pm
by Fuzzlix
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