mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Use Box2D's callbacks for destruction of physics objects and wait until the end of the timestep before destroying them.
Merge of box2d-id2 from love-experiments
This commit is contained in:
@@ -42,6 +42,7 @@ namespace box2d
|
||||
class Contact;
|
||||
class Body;
|
||||
class Fixture;
|
||||
class Joint;
|
||||
|
||||
/**
|
||||
* The World is the "God" container class,
|
||||
@@ -54,13 +55,14 @@ namespace box2d
|
||||
* The world also controls global parameters, like
|
||||
* gravity.
|
||||
**/
|
||||
class World : public Object, public b2ContactListener, public b2ContactFilter
|
||||
class World : public Object, public b2ContactListener, public b2ContactFilter, public b2DestructionListener
|
||||
{
|
||||
// Friends.
|
||||
friend class Joint;
|
||||
friend class DistanceJoint;
|
||||
friend class MouseJoint;
|
||||
friend class Body;
|
||||
friend class Fixture;
|
||||
|
||||
public:
|
||||
|
||||
@@ -110,6 +112,9 @@ namespace box2d
|
||||
|
||||
// The list of to be destructed bodies.
|
||||
std::vector<Body*> destructBodies;
|
||||
std::vector<Fixture*> destructFixtures;
|
||||
std::vector<Joint*> destructJoints;
|
||||
bool destructWorld;
|
||||
|
||||
// Contact callbacks.
|
||||
ContactCallback begin, end, presolve, postsolve;
|
||||
@@ -152,6 +157,15 @@ namespace box2d
|
||||
// From b2ContactFilter
|
||||
bool ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB);
|
||||
|
||||
// From b2DestructionListener
|
||||
void SayGoodbye(b2Fixture* fixture);
|
||||
void SayGoodbye(b2Joint* joint);
|
||||
|
||||
/**
|
||||
* Returns true if the Box2D world is alive.
|
||||
**/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Receives up to four Lua functions as arguments. Each function is
|
||||
* collision callback for the four events (in order): begin, end,
|
||||
@@ -261,10 +275,9 @@ namespace box2d
|
||||
int rayCast(lua_State * L);
|
||||
|
||||
/**
|
||||
* Mark a body for destruction.
|
||||
* To be called from Body
|
||||
* Destroy this world.
|
||||
**/
|
||||
void destroyBody(Body * b);
|
||||
void destroy();
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user