Scrolling Strategy

Hello,

Context:

I'm making a game with an horizontal scrolling.
When the game scrolls, the next part of the world may be needed. World parts are called "tracks". Their width is 3 screen large.
I have a limited number of tracks, maybe 100, but the world itslef has no limits since a new track is picked as soon as needed.
The tracks use many b2EdgeShape (with adjacency) to represent the ground. Generaly about 100 edges per tracks, but my maximum is 275 b2EdgeShape. (the ground looks like a bezier spline)

Image

My goal is to get the shortest CPU usage when a new track is added.

Current technic used:

All the tracks and their ground bodies are created at loading time. The bodies are deactivated.
When a track is needed, its body is moved to the correct position and activated.
When a track is no longer needed, its body is deactivated and is left at its current position.
(the same track is never used 2 time in a row)

Issue:

Activating the body may take quite some time when there is a lot of edge shapes.
The screenshot track has 270 edges and takes 11ms just to activate the body in release mode.
I use a Q6600 2.4 Ghz. Windows evaluation : 5.0
Box2D revision 131.

My mesurement may be wrong though.

Questions:

Does anyone know a better strategy that this one ?
Would you make something completly different ?

Thanks !
I'm just speculating a bit here, but here's a couple of thoughts.

I'm not sure exactly how the current version of Box2D handles things in terms of the collision broad phase, but if inactive bodies are excluded from the broad phase, activating a body with a few hundred fixtures attached may necessitate inserting each fixture into the broad phase in one go. I can imagine this might take a little time, relatively speaking.

In any case, one option you might consider would be to amortize the cost of activating parts of the world by working with 'units' comprised of smaller numbers of fixtures. I realize this would require changing your design somewhat, but the idea would be to activate and deactivate bodies more often, but have far fewer fixtures associated with each body (thereby lowering the cost of each activation and deactivation).

Again, I'm not sure how the broad phase works with respect to active and inactive bodies, so some of my suppositions might be off here. But regardless of what's causing the performance hit, it seems that amortizing the cost over multiple updates might be one way to address the problem.
Makes sense. I guess I'll try that.

Thanks.

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