mirror of
https://github.com/love2d/love.git
synced 2026-08-12 16:40:57 +02:00
Wait until the end of a physics update before destroying bodies (issue #193)
This commit is contained in:
@@ -329,6 +329,11 @@ namespace box2d
|
||||
return 2;
|
||||
}
|
||||
|
||||
void Body::destroy()
|
||||
{
|
||||
world->destroyBody(this);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -346,6 +346,11 @@ namespace box2d
|
||||
* Get the World this Body resides in.
|
||||
*/
|
||||
World * getWorld() const;
|
||||
|
||||
/**
|
||||
* Mark the body for destruction
|
||||
**/
|
||||
void destroy();
|
||||
private:
|
||||
|
||||
/**
|
||||
|
||||
@@ -123,6 +123,14 @@ namespace box2d
|
||||
persist.process();
|
||||
remove.process();
|
||||
result.process();
|
||||
|
||||
// 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::Add(const b2ContactPoint* point)
|
||||
@@ -272,6 +280,11 @@ namespace box2d
|
||||
t.upperBound = scaleUp(aabb.upperBound);
|
||||
return t;
|
||||
}
|
||||
|
||||
void World::destroyBody(Body * b)
|
||||
{
|
||||
destructBodies.push_back(b);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace box2d
|
||||
{
|
||||
|
||||
class Contact;
|
||||
class Body;
|
||||
|
||||
/**
|
||||
* The World is the "God" container class,
|
||||
@@ -83,6 +84,9 @@ namespace box2d
|
||||
|
||||
// The length of one meter in pixels.
|
||||
int meter;
|
||||
|
||||
// The list of to be destructed bodies.
|
||||
std::vector<Body*> destructBodies;
|
||||
|
||||
public:
|
||||
|
||||
@@ -241,6 +245,12 @@ namespace box2d
|
||||
* @return The scaled AABB.
|
||||
**/
|
||||
b2AABB scaleUp(const b2AABB & aabb);
|
||||
|
||||
/**
|
||||
* Mark a body for destruction.
|
||||
* To be called from Body
|
||||
**/
|
||||
void destroyBody(Body * b);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -462,7 +462,7 @@ namespace box2d
|
||||
p->own = false;
|
||||
|
||||
Body * t = (Body *)p->data;
|
||||
t->release();
|
||||
t->destroy();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user