Culling Physics Objects - Theoretical

Hi Everyone,
I realise Culling is a hot topic recently, but I’d like to ask a theoretical question.

I have a tile based game set up (We’re not into the theoretical yet)
I’ve also Implemented my own off screen image culling for tiles coming onto the screen.

  • They all start with visibility off and become visible when they enter the screenBounds.
for i = 1, map.numChildren do -- For all tiles   
 if isVisible(map[i]) and map[i].isVisible ~= true then -- isVisible() is a function to get screen bounds.   
--So If within screen bounds and visibility is false then...  
  
 map[i].isVisible = true -- Set that specific tile to visibility on.  
 print("true" , i) -- to verify; seems to only count tiles coming onscreen.  
 end  
 end   
end  
Runtime:addEventListener( "enterFrame", moveMap ) -- Ran every frame.  

My performance on a HTC Desire is still ~12 frame I think. (From a tester)
Is this good? (My tile map is 40x40 pixels per tile, 71 x 8 tiles = 568 tiles (Although about 2/3 of them don’t exist haha! Meaning they’re 00 tiles which don’t have images or physics bodies and don’t get placed down at all.) I hope to make larger.

I’m unsure if Corona’s culling is in effect for me, didn’t seem like it, didn’t know how to tell, I hope I’m not fighting it with my own Culling. (Build 840 - No Dailies)

Would it be possible for me to cull physics bodies?
They are Static and do go to ‘sleep’, does this mean they won’t hurt performance as much or does just being there hurt performance?

You don’t have to help me solve the issue, but would it be possible for me to do, or is it a Corona native thing that needs to be coded?

Thanks Matt [import]uid: 91798 topic_id: 30023 reply_id: 330023[/import]

Theoretically Corona’s built in culling should mean your own image culling is unnecessary, and so is more likely hurting your performance. Easiest way to tell is run your code with and without your culling code and compare the FPS. If running with your culling on improves your FPS (which would be unexpected) then for some reason Corona’s culling is not working for you. Be sure to do these types of tests on an actual device.

In terms of reasons to cull physics objects, sleeping objects have less impact on performance than non-sleeping ones, but do still have an overhead. I’m pretty sure each active physics object still needs to be checked for collisions with sleeping objects to at least know if the sleepers need to be woken up, so a world with tons of sleeping objects and only a few active ones is still going to be expensive. Perhaps in that case culling would be effective.

On the other hand, if you are culling physics objects then you are potentially creating and destroying physics objects in the simulation every frame as each one is checked against your screen boundaries. That could become expensive depending on how many objects have to be processed through your culling routine. So, while it’s possible to cull physics objects using Corona it might not give you any performance benefit, and could potentially be a drag on performance depending on how many objects you are culling and the hardware you are running on.

There are probably things you can do to optimize culling tailored to you specific requirements. For example, when I wrote my own image culling routine before Corona did it automagically, it actually hurt performance to cull every frame, but I got a huge performance boost if I performed the cull every 3rd frame ( I had to pad the culling boundary past the display boundary by about 200 pixels to compensate for not checking every frame). I’m sure there are much smarter optimizations that might work well for your particular case.

EDIT: P.S. - In my opinion 12 FPS is pretty bad, bordering on unplayable. But there’s always going to be some crappy Android devices out in the wild that have horrible performance, so I would try to test on a mainstream, middle of the road device that you expect decent performance on. If you get 12 fps on THAT then you might want to spend some time rethinking your game and/or optimizing your code. [import]uid: 9422 topic_id: 30023 reply_id: 120263[/import]

Theoretically Corona’s built in culling should mean your own image culling is unnecessary, and so is more likely hurting your performance. Easiest way to tell is run your code with and without your culling code and compare the FPS. If running with your culling on improves your FPS (which would be unexpected) then for some reason Corona’s culling is not working for you. Be sure to do these types of tests on an actual device.

In terms of reasons to cull physics objects, sleeping objects have less impact on performance than non-sleeping ones, but do still have an overhead. I’m pretty sure each active physics object still needs to be checked for collisions with sleeping objects to at least know if the sleepers need to be woken up, so a world with tons of sleeping objects and only a few active ones is still going to be expensive. Perhaps in that case culling would be effective.

On the other hand, if you are culling physics objects then you are potentially creating and destroying physics objects in the simulation every frame as each one is checked against your screen boundaries. That could become expensive depending on how many objects have to be processed through your culling routine. So, while it’s possible to cull physics objects using Corona it might not give you any performance benefit, and could potentially be a drag on performance depending on how many objects you are culling and the hardware you are running on.

There are probably things you can do to optimize culling tailored to you specific requirements. For example, when I wrote my own image culling routine before Corona did it automagically, it actually hurt performance to cull every frame, but I got a huge performance boost if I performed the cull every 3rd frame ( I had to pad the culling boundary past the display boundary by about 200 pixels to compensate for not checking every frame). I’m sure there are much smarter optimizations that might work well for your particular case.

EDIT: P.S. - In my opinion 12 FPS is pretty bad, bordering on unplayable. But there’s always going to be some crappy Android devices out in the wild that have horrible performance, so I would try to test on a mainstream, middle of the road device that you expect decent performance on. If you get 12 fps on THAT then you might want to spend some time rethinking your game and/or optimizing your code. [import]uid: 9422 topic_id: 30023 reply_id: 120263[/import]