[solved] fps, vsync related question

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.
Post Reply
Fuzzlix
Citizen
Posts: 60
Joined: Thu Oct 13, 2016 5:36 pm

[solved] fps, vsync related question

Post 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.
Last edited by Fuzzlix on Sat Oct 15, 2016 1:09 pm, edited 1 time in total.
User avatar
RaycatRakittra
Prole
Posts: 22
Joined: Fri Sep 30, 2016 12:40 am
Location: Chicago, IL
Contact:

Re: fps, vsync related question

Post 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
Sometimes, I can code things.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: fps, vsync related question

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Fuzzlix
Citizen
Posts: 60
Joined: Thu Oct 13, 2016 5:36 pm

[solved]: fps, vsync related question

Post 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. :)
User avatar
evgiz
Citizen
Posts: 83
Joined: Mon Aug 29, 2016 11:05 pm
Contact:

Re: [solved] fps, vsync related question

Post 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.
Computer science student and part time game dev! Currently working on Depths of Limbo! :cool:

Check out the game website DepthsOfLimbo.com! :ultrahappy:
And my personal website with all my projects evgiz.net! :megagrin:
Fuzzlix
Citizen
Posts: 60
Joined: Thu Oct 13, 2016 5:36 pm

Re: [solved] fps, vsync related question

Post 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 :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 206 guests