Bring back some elements of better Body destruction that got lost in the merge

This commit is contained in:
Bill Meltsner
2011-10-12 13:51:47 -05:00
parent d40b25c1e6
commit 56ae3a95fc
3 changed files with 28 additions and 0 deletions
+5
View File
@@ -385,6 +385,11 @@ namespace box2d
**/ **/
int getFixtureList(lua_State * L) const; int getFixtureList(lua_State * L) const;
/**
* Mark the body for destruction
**/
void destroy();
private: private:
/** /**
+13
View File
@@ -210,6 +210,14 @@ namespace box2d
void World::update(float dt) void World::update(float dt)
{ {
world->Step(dt, 8, 6); world->Step(dt, 8, 6);
// Really destroy all marked bodies.
for (std::vector<Body*>::iterator i = destructBodies.begin(); i < destructBodies.end(); i++)
{
Body * b = *i;
b->release();
}
destructBodies.clear();
} }
void World::BeginContact(b2Contact* contact) void World::BeginContact(b2Contact* contact)
@@ -422,6 +430,11 @@ namespace box2d
world->RayCast(&raycast, v1, v2); world->RayCast(&raycast, v1, v2);
return 0; return 0;
} }
void World::destroyBody(Body * b)
{
destructBodies.push_back(b);
}
} // box2d } // box2d
} // physics } // physics
+10
View File
@@ -40,6 +40,7 @@ namespace box2d
{ {
class Contact; class Contact;
class Body;
class Fixture; class Fixture;
/** /**
@@ -106,6 +107,9 @@ namespace box2d
// Ground body // Ground body
b2Body * groundBody; b2Body * groundBody;
// The list of to be destructed bodies.
std::vector<Body*> destructBodies;
// Contact callbacks. // Contact callbacks.
ContactCallback begin, end, presolve, postsolve; ContactCallback begin, end, presolve, postsolve;
@@ -255,6 +259,12 @@ namespace box2d
* Raycasts the World for all Fixtures in the path of the ray. * Raycasts the World for all Fixtures in the path of the ray.
**/ **/
int rayCast(lua_State * L); int rayCast(lua_State * L);
/**
* Mark a body for destruction.
* To be called from Body
**/
void destroyBody(Body * b);
}; };