>100 Static EdgeShape + >20 Dynamic Body(box) slow

Hi,

In my side-scroller game, I am using about >100 static edgeshapes to create the terrain, and only 20-30 dynamic bodies (box). And now it's running slow, the average FPS is 15-20. I've turn off any suspicious routine and only run the box2d simulation, but it's still slow.

When I reduce the dynamic bodies into 3-5, the speed run well at 30FPS.

Anyone can explain how this happened? Is there anything I can improve or change from box2d settings and my code?. I am using the latest Box2D.

Thanks.
You need to experiment, I don't know how to get best performance.

You can get the latest from SVN if you haven't already. It includes some performance improvements.

You can reduce vel and pos iterations to 8 and 3, which are Erin's recommended values. This will give a considerable boost.

You can try a different broadphase, with b2World.SetBroadPhase. Only one other is available, the old broadphase called b2BroadPhase. This may help or hinder, I have no idea.

If it's side scrolling, you can try to simluate less of the world each time, by deleting or deactiving things not near the screen.
Boris,

Thanks for your fast reply, Now i'm trying to setup the broadphase with this code:

Code:
worldAABB.lowerBound.Set(-1000.0, -1000.0);
worldAABB.upperBound.Set(1000.0, 1000.0);
gravity = new b2Vec2 (0.0, 10.0);
doSleep = true;         
world = new b2World(gravity, doSleep);
world.SetContactListener(new Game.GameContacts);
world.SetContactFilter(new Game.GameContactFilter);      
world.SetBroadPhase(new b2BroadPhase(worldAABB));


However, it gave me this error:
Code:
RangeError: Error #1125: The index -1 is out of range 2.
   at Box2D.Collision::b2BroadPhase/CreateProxy()[H:\newbox2d\latest\Source\Box2D\Collision\b2BroadPhase.as:179]
   at Box2D.Dynamics::b2Fixture/http://www.box2d.org/ns/b2internal::CreateProxy()[H:\newbox2d\latest\Source\Box2D\Dynamics\b2Fixture.as:317]
   at Box2D.Dynamics::b2Body/CreateFixture()[H:\newbox2d\latest\Source\Box2D\Dynamics\b2Body.as:84]


I'm rather new with b2broadphase, is there anything wrong with my code?. And also, I store my terrain data in array, some of vertices position are less than 0 (e.g: -100, -50), is the error has something to do with this?.

Thanks.
Perhaps it's not working atm, it's a rather obscure part of the library. forget that for now.

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