Hello!
I am using a engine called Novashell, and it uses Box2D...
Unfortunally, Box2D is causing some serious performance hits on it, more than I think it should (I also used Chipmunk a lot in my projects).
So I decided to hack around in Novashell source, to find out how to speed-up Box2D...
So my questions are:
Someone has tips on how to make things faster on Box2D?
How bad the physics break if I use a single iteration when updating? (the engine is hardcoded to use 10)
Circles are faster than polygons? (the engine now only support polygons... I may add circles, if they solve my problem, although all objects in my game are squares, not rectangles...)
Box2D has some configurations like Chipmunk, that I can tweak to attempt to achieve better performance?
Any other clues?
It is hard to say why the performance is bad. The best way to determine the problem is the reproduce the result with some sample code in the testbed.
Short of that, it would help to know what version of Box2D you are using and what you are feeding it. What do the timings look like? Is the body creation slow or is it the time step?
I don't figured how to figure what version it is... But probably is more or less old.
What is happening is this: I am making a breakout clone, thus I have a screen filled with static rectangles. When the rectangle is hit by the ball, it is deleted, and 4 squares are created, the squares fall toward the player (with force or impulse, don't remember what one, being applied every frame).
This already created some slowdowns, all the time I use something that cause mass block destruction (like a powerup that kill bricks in a radius), the engine slows down quite fast (it is running around 70 FPS, then suddenly it drops to 10 FPS...).
From that, I figured that the engine had some problems creating objects...
Anyway, I made a level that instead of having rectangles, I have a huge amount of small squares (the same size of the ones that fall from the bricks, mentioned earlier), when one of these squares die, it is deleted, and another small square of same size is created, and that square falls down...
On this particular level, it runs aroud 40 FPS if I don't do anything (although the objects have 0 mass, I don't figured if the engine creates them as proper fixed objects... but there are code to sleep non-moving stuff). As soon as I start to kill the blocks en-masse, the performance drops to 2 FPS...
After nothing is getting created, it resumes to about 6 FPS, and as the falling stuff get deleted, it returns to 40 FPS.
On this level there are 2856 static squares on the start.
The machine is a Athlon X2 6000+ with 2Gb Ram, Windows XP SP3, GeForce 8600 512Mb, nForce motherboard.
Rendering and input using ClanLib 1.0
My idea (beside the questions that I already asked on the first post) is maybe set the object velocity to zero, sleep it, and move it around myself...
Or maybe even declare the object as a static one (And still move it myself), but I dunno if this break collision detection (the falling stuff are "energy" that the player pickup with the paddle).
So you are creating many objects in a regular pattern. Try spawning them in random order. More recent versions of Box2D can have slow downs in the dynamic tree if you create large grids of shapes in a regular order. This causes the binary search tree to be highly unbalanced.
Huh... And all my other questions?
Yeah, nothing you suggested would help as far as I know.
How bad the physics break if I use a single iteration when updating? (actually, this I know the answer: yes... doing that made the objects speed-up endlessly when bumping on stuff, until they were bizarrely fast and tunneled)
Circles are faster than polygons?
Box2D has some configurations like Chipmunk, that I can tweak to attempt to achieve better performance?
Did you already try my suggestion? If that didn't work, I'll need you to create a testbed example to reproduce the problem.
I don't think adjusting iterations or using circles will help you much.
No, I did not tried, because I am hacking someone else engine, and trying to insert delays in how 2000+ objects are created would make wonky loading times or something like that...
Also, every bit performance I can squeeze is good, because this is a generalist game engine, I dunno if in the future someone would want to make a billion of balls hitting each other, and if having circles instead of polygons would make this easier... AND my game gets slow too when I make too much balls.
No, I'm not talking about adding delays. I'm suggesting that you don't create a big grid of bodies in order. Try randomizing the creation order. This is easy to do.
It seems like you don't really want my help. You just want me to say that circles are faster. Well they are, but that probably won't help you.