EdgeChain and really big world

Hi everyone, it is my first post here, so to introduce myself I am game developer working on an iPhone game. We use Box2d for ragdoll and some other physic elements. The game is in 3D with a 2D gameplay and a side view (you can think of Rolando 2 to have a technical idea, but it is really different)

I have 2 questions mainly about EdgeChains:

1) for a big level (let say 10 iPhone screens), is it better to make one big EdgeChain, or several small EdgeChain (maybe with only 1 segment). How Box2D do the collision? are they AABB box for the chain or for segment only? in this case I guess it is better to cut the chain in segments.

2) The world is big, and we don't need to update what is really far from the player. But we have a lot of fixtures. An EdgeChain of 512 segments will take 512 fixtures isn't it? What a good strategy is? Adding and removing body from the world in real time? Playing with 2 or more worlds?
I look forward to hearing the answers to these questions also. I have been using polygons instead of edge chains, and now that I'm in the profiling and optimization phase of my game dev, I'm beginning to think that these shapes have a large cost.
In the current revisions 1 edge = 1 2-vertex polygon = 1 fixture used. Edge-chains are a convenience, that's all. (in some earlier revisions, this is not so true, but 1 edge = 1 fixture still holds). So a lot of edges in the world will eat up a lot of memory. But that's probably the extent of the damage. Because of Box2D's broadphase, static fixtures not involved in collisions get culled at a very early stage, and so they are very cheap.

They'll only start to be a factor when a) linear loops with early exits over all fixtures becomes a significant cost, or b) the broadphase cannot cope so well. a) seems unlikely, though I don't know the details, and b) can be dealt with in time with a superior broadphase, or one tuned to your set-up better.

Adding and removing fixtures thus strikes me as unnecessary work, but it would be effective. I would not recommend multiple worlds, with physics spanning between them.
thanks a lot Boris. So if I understand well there will be no difference if I do ... let say 100 single Edge, or 1 EdgeChain with 100 segments. And maybe it could be even worse depending on my geometry... or not...

in fact I am worried about the culling. if each segment has an AABB box, I hope it is not a linear algorithm who does the culling in the broad phase. Does anyone know how it works? is there a grid, a binary tree, or whatever?

in our world we have around 300 segments today, but we will probably go further soon (and we will add more dynamic objects), and so we will go beyond the 512 default fixtures allowed. I know that I can change this value in b2settings.h, but is it really a good idea? or is it better to handle different world myself?

your idea of "superior broadphase" looks interesting, but not an easy option. I would like to help Box2d to cull my fixtures but I don't know how it works already. How to hide/show some fixtures to the broadphase in realtime, that's the question I guess
any hint on the broadphase? if we have a body with a lot of segments fixture, is there a quad tree or something like that for collision or every AABB box are checked in a linear way? just curious to know how it works.
Each fixture gets its own AABB in the broad-phase. Box2D uses a dynamic AABB tree for the broad-phase. There are no linear searches over fixtures.
thanks Erin, that sounds all good!
Herman, are you generating these shapes from SVG? I have a pretty decent polygon decomposition technique that I am using which is very stable even for a very fast moving player. (The entire level is created from convex polygons so it is solid and there aren't cracks for the player to get through to get stuck.)

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