Deformable Terrain Algo (deletion in callbacks)

I was reading the documentation and found that the deletion of shapes from a body is locked during callbacks. This is potentially troublesome for me as I need the ability to delete and redefine shapes for a deformable terrain implementation utilizing the marching boxes algorithm and polygonal approximation with the input being a black and white aliased collision mask.

Here is my algorithm thus far.

1) The map stores an initial, precomputed approximation of the terrain. The approximation is made with strings of 2 vertex b2Polygons.
2) The game keeps track of when changes to the terrain mask occur, such as the explosion of a bomb and appropriate graphical steps are taken to remove a section from the collision mask. All of the polygons in the affected area are then erased.
3) The marching boxes algorithm is then used to trace the affected area and redefine the collision volumes. This is done recursively and the new volumes are created using the coordinates of the set of boxes every 20 or so cycles. Depends on how accurate you want the simulation to be.
4) Carry on then. Nothing else to see here.

So... any thoughts or suggestions? Should be a hell of alot faster than polygon tessellation if you ask me. Because I saw the method using quadtrees that some Linux fanatics (jk, love Linux) were using for a Worms remake with Tux, and the number of volumes that were used just blew my mind.
Orm wrote:
I was reading the documentation and found that the deletion of shapes from a body is locked during callbacks. This is potentially troublesome for me as I need the ability to delete and redefine shapes for a deformable terrain implementation utilizing the marching boxes algorithm and polygonal approximation with the input being a black and white aliased collision mask.

Here is my algorithm thus far.

1) The map stores an initial, precomputed approximation of the terrain. The approximation is made with strings of 2 vertex b2Polygons.
2) The game keeps track of when changes to the terrain mask occur, such as the explosion of a bomb and appropriate graphical steps are taken to remove a section from the collision mask. All of the polygons in the affected area are then erased.
3) The marching boxes algorithm is then used to trace the affected area and redefine the collision volumes. This is done recursively and the new volumes are created using the coordinates of the set of boxes every 20 or so cycles. Depends on how accurate you want the simulation to be.
4) Carry on then. Nothing else to see here.

So... any thoughts or suggestions? Should be a hell of alot faster than polygon tessellation if you ask me. Because I saw the method using quadtrees that some Linux fanatics (jk, love Linux) were using for a Worms remake with Tux, and the number of volumes that were used just blew my mind.


First, if deletion of shapes during callbacks is a problem, just flag the shape for deletion, and then finish your routine after the callbacks are completed.

Secondly, I don't see how this is "a hell of a lot faster". If your shapes ever become concave because of explosions or what have you, you're going to have to do some sort of tessellation anyway, aren't you? Honestly, it sounds easier to me to subtract one polygon from another than to convert it into a bitmap and back again. This is what I did in my editor... there are plenty of algorithms out there for tesselation and subtracting one 2D shape from another.

Or maybe I'm misinterpreting something. My 2 cents anyway.
Think of the terrain collision volumes as a string of triangular flags (in the physical sense, like the flags used here: http://www.amatoind.com/images/backstroke_flags.gif), only where the upper corners (the ones touching the string the flags are attached to so the object doesn't fall through [hell, maybe even overlap a bit]) would be touching each other, and you can get a better idea of how it would work out.

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