Performance related questions

1. I'm guessing shapes.Circle performs better than shapes.Oval or polygons. Of course for wheels, circles are preferred but in case a polygon shape is needed, does that make a big difference?

2. After I slice/split a lot of objects, CPU usage goes up. This is expected. But even when all objects start sleeping (with debugDraw I can see them turning light gray) CPU usage still remanins high. Am I perhaps missing something e.g. not setting a property or should that be happening?

3. In this version of WCK are there boundaries? If I want to make a train ride level where the train keeps traveling in one direction, do I need to worry about reaching a point where box2d will crash? Whether or not may that be the case, is it perhaps a good idea to "teleport" the world closer to the origin from time to time. I saw some posts about teleporting and wondering if it's possible to do that for every object in the box2d world.
1. Circles approximated with polygons will come to rest easier because of the flat edges. You'll have to balance how much detail you need with the overhead of creating more polygons.

2. The debug draw is horribly inefficient (it redraws everything each frame), so don't judge performance when it is on. I'd have to see a screenshot to know if you're throwing more at Box2D than it can handle.

3. I've never ran into a limitation. Obviously there's got to be a limit at some point but I would only worry about it if you actually hit it. I think the worst that will happen is things will start getting inaccurate, just a guess though.
mayobutter wrote:
2. The debug draw is horribly inefficient (it redraws everything each frame), so don't judge performance when it is on. I'd have to see a screenshot to know if you're throwing more at Box2D than it can handle.

Turns out it wasn't a box2d issue but flash rendering. Turning off debug draw didn't make any noticeable difference. CPU usage was still above 50%. But your suggestion gave me the idea to change flash rendering to 'low' and cpu usage went down as expected. Currently I'm only testing things and was using symbols instead of bitmap images. CPU usage remained low with cacheAsBitmap, even on 'high' quality render setting.

The setup was actually quite simple. One static box at the bottom, and one dynamic on top of it - that I sliced up. Once I had about 10-15, cpu usage started to increase but as I mentioned, after the objects were sleeping cpu usage still remained at the same level. This usage level was comparable to some of the demo levels but those had over 40 objects on the screen moving. So something was definitely not right.

Another reason why I was asking about boundaries is: What happened to the objects I "threw away" from the bottom static box. When I threw those off my platform, those would keep falling but in my current test setup I don't have any checks to remove them. Regarding the high cpu usage issue, I did notice that if removed many sliced objects from the stage then cpu usage went down. I assumed that either box2d or wck took care of them and the main issue was due to me not setting something properly on the box2d/wck side.

It's good that at least this issue got cleared up now and not later 🙂

[edit]
Did a little world boundary test.
One 'Animated' Box moving to the right with a few other boxes on top of it.
At world.scale = 60, as I was moving around the boxes, even when the boxes reached x = 5000 (in world coordinates), collision detection seemed fine. The only issue that I noticed: the animated symbol was somewhat to the right of its b2body - about 30-40 pixels, quite noticable.
[edit 2]
Tried the same thing with 'Kinematic' type and got a similar "shifting" result. I was using platform.x += speed. Then I tried using LinearVelocityX and the "shifting" was gone. I haven't used tweening via code before but perhaps that should take care of the animated type's shifting issue?

Original thread: https://box2d.org/forum/viewtopic.php?t=8257