mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Bring back some elements of better Body destruction that got lost in the merge
This commit is contained in:
@@ -385,6 +385,11 @@ namespace box2d
|
||||
**/
|
||||
int getFixtureList(lua_State * L) const;
|
||||
|
||||
/**
|
||||
* Mark the body for destruction
|
||||
**/
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
|
||||
@@ -210,6 +210,14 @@ namespace box2d
|
||||
void World::update(float dt)
|
||||
{
|
||||
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)
|
||||
@@ -422,6 +430,11 @@ namespace box2d
|
||||
world->RayCast(&raycast, v1, v2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void World::destroyBody(Body * b)
|
||||
{
|
||||
destructBodies.push_back(b);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace box2d
|
||||
{
|
||||
|
||||
class Contact;
|
||||
class Body;
|
||||
class Fixture;
|
||||
|
||||
/**
|
||||
@@ -106,6 +107,9 @@ namespace box2d
|
||||
|
||||
// Ground body
|
||||
b2Body * groundBody;
|
||||
|
||||
// The list of to be destructed bodies.
|
||||
std::vector<Body*> destructBodies;
|
||||
|
||||
// Contact callbacks.
|
||||
ContactCallback begin, end, presolve, postsolve;
|
||||
@@ -255,6 +259,12 @@ namespace box2d
|
||||
* Raycasts the World for all Fixtures in the path of the ray.
|
||||
**/
|
||||
int rayCast(lua_State * L);
|
||||
|
||||
/**
|
||||
* Mark a body for destruction.
|
||||
* To be called from Body
|
||||
**/
|
||||
void destroyBody(Body * b);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user