Quads slow things down so much..

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.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Quads slow things down so much..

Post by hasen » Sun Feb 25, 2018 8:03 am

I read on the wiki page that quads can slow things down but I wasn't prepared for how much. I'm using them to draw a tiled background and I'm losing 10 fps with 6x15 tiles and another 10 with 6x30 tiles when testing on my iPhone device. The tiles are just 32x32 pixels. I've tested other things and it's definitely the quads that are slowing everything down. Without drawing them it runs at 60fps no problem.

At the moment it's just a simple platform game in a room with little or no objects or enemies and no platforms. The resolution is like a pixel game too so I don't see why it should be running slowly at all.

Code: Select all

local class = require 'lib.middleclass'
local Entity = require 'entities.entity'

local Intang = class('Intang', Entity)

local quad = love.graphics.newQuad(0, 0, 32, 32, 160, 32)

function Intang:initialize( world, l,t,w,h, tile, type )
  Entity.initialize(self, world, l,t,w,h)
  self.image = media.img[type]
end

function Intang:draw()
  love.graphics.setColor(255, 255, 255)
  love.graphics.draw(self.image, quad, self.l, self.t)
end

function Intang:update(dt)
end

return Intang
The wiki suggests storing quads and reusing them but as far as I can see, I'm already doing that?

User avatar
raidho36
Party member
Posts: 1685
Joined: Mon Jun 17, 2013 12:00 pm

Re: Quads slow things down so much..

Post by raidho36 » Sun Feb 25, 2018 9:03 am

Are you "losing" FPS? As in, compared to not using quads and just drawing individual sprites? Looks to me like you're draw call bottlenecked and it has nothing to do with whichever method you use. Either way you should use sprite batching if you plan to draw more than a handful per frame.

hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Quads slow things down so much..

Post by hasen » Sun Feb 25, 2018 9:09 am

raidho36 wrote:
Sun Feb 25, 2018 9:03 am
Are you "losing" FPS? As in, compared to not using quads and just drawing individual sprites?
Yes..that's exactly what I'm saying.

I ran many tests and noticed drawing any objects at all even without quads hits the frame rate quite considerably. I set up an object and all it does is add itself to the bump world (see code below) and the more objects I add, the lower the frame rate gets. With just the player standing on a floor with no graphics the fps is 80, adding 90 blank objects to the world takes it down to 60. Then from there other objects can easily take it right down to 40 if they use quads at all.

I tried using a font and we were dead at 10 fps. This was all on an iPhone 6 in the simulator as well. I was adding this object:

Code: Select all

local class = require 'lib.middleclass'

local Object = class('Object')

function Object:initialize(world, l,t,w,h)
  self.world, self.l, self.t, self.w, self.h = world, l,t,w,h
  self.world:add(self, l,t,w,h)
  self.created_at = love.timer.getTime()
end

function Object:getUpdateOrder()
  return self.class.updateOrder or 10000
end

function Object:__tostring()
  return ("%s %f %f [%f %f]"):format( self.class.name, self.l, self.t, self.w, self.h )
end

return Object

Code: Select all

local class = require 'lib.middleclass'
local Object = require 'entities.object'

local Intang = class('Intang', Object)

function Intang:initialize( world, l,t,w,h, tile, type )
  Object.initialize(self, world, l,t,w,h)
end

function Intang:draw()
end

function Intang:update(dt)
end

return Intang
Also they're not sprites, they're just background tiles so why would I need sprite batching?

User avatar
raidho36
Party member
Posts: 1685
Joined: Mon Jun 17, 2013 12:00 pm

Re: Quads slow things down so much..

Post by raidho36 » Sun Feb 25, 2018 9:51 am

Ah, I missed the part where you said you were using an emulator. Poor performance is entirely expected; you only use it to do a quick validation without deploying the app on a real device. You should use a real device to get representative data.

And you might have missed the part where I said you should use a sprite batch.

hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Quads slow things down so much..

Post by hasen » Sun Feb 25, 2018 10:33 am

raidho36 wrote:
Sun Feb 25, 2018 9:51 am
Ah, I missed the part where you said you were using an emulator. Poor performance is entirely expected; you only use it to do a quick validation without deploying the app on a real device. You should use a real device to get representative data.
I said it was a real device in my first post. I tested on both. Of course it's even slower on a real device. It's actually the first time I've seen slow down in the simulator too, normally it runs way faster than a real device because it's powered by the computer's cpu.
raidho36 wrote:
Sun Feb 25, 2018 9:51 am
And you might have missed the part where I said you should use a sprite batch.
hasen wrote:
Sun Feb 25, 2018 9:09 am
Also they're not sprites, they're just background tiles so why would I need sprite batching?
Also sprite batching seems to be for large amounts of images but I was noticing fps loss even with just one or two objects that featured quads.

hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Quads slow things down so much..

Post by hasen » Sun Feb 25, 2018 11:03 am

I tried sprite batching and it's pretty slow too. I followed this to simply draw a 160x32 8 bit png brick tile 90 times https://gist.github.com/bhumphreys/3703388

Without it the fps is 80 fps. With the 90 sprites drawn through sprite batching it drops down to 45 fps.

grump
Party member
Posts: 430
Joined: Sat Jul 22, 2017 7:43 pm

Re: Quads slow things down so much..

Post by grump » Sun Feb 25, 2018 11:15 am

While not necessarily the cause of unsatisfying performance in this case, I don't think it's wise to clear and recreate the entire batch in each frame for no reason.

hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Quads slow things down so much..

Post by hasen » Sun Feb 25, 2018 11:24 am

grump wrote:
Sun Feb 25, 2018 11:15 am
While not necessarily the cause of unsatisfying performance in this case, I don't think it's wise to clear and recreate the entire batch in each frame for no reason.
Not sure what you're referring to here?

User avatar
pgimeno
Party member
Posts: 1337
Joined: Sun Oct 18, 2015 2:58 pm

Re: Quads slow things down so much..

Post by pgimeno » Sun Feb 25, 2018 12:22 pm

hasen wrote:
Sun Feb 25, 2018 8:03 am
I read on the wiki page that quads can slow things down but I wasn't prepared for how much.
That's not true. The wiki says that creating quads can be slow.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Quads slow things down so much..

Post by hasen » Sun Feb 25, 2018 1:06 pm

pgimeno wrote:
Sun Feb 25, 2018 12:22 pm
hasen wrote:
Sun Feb 25, 2018 8:03 am
I read on the wiki page that quads can slow things down but I wasn't prepared for how much.
That's not true. The wiki says that creating quads can be slow.
Just one more and you'll break the record.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], gianmichele and 9 guests