public void DestroyBody(Body body)
{
Debug.Assert(BodyCount > 0);
Debug.Assert(Locked == false);
if (Locked)
{
return;
}
// Delete the attached joints.
JointEdge je = body.JointList;
while (je != null)
{
JointEdge je0 = je;
je = je.Next;
if (DestructionListener != null)
{
DestructionListener.SayGoodbye(je0.Joint);
}
DestroyJoint(je0.Joint);
body.JointList = je;
}
body.JointList = null;
// Delete the attached contacts.
ContactEdge ce = body.ContactList;
while (ce != null)
{
ContactEdge ce0 = ce;
ce = ce.Next;
ContactManager.Destroy(ce0.Contact);
}
body.ContactList = null;
Fixture f = body.FixtureList;
while (f != null)
{
Fixture f0 = f;
f = f.Next;
if (DestructionListener != null)
{
DestructionListener.SayGoodbye(f0);
}
f0.DestroyProxies(ContactManager.BroadPhase);
f0.Destroy();
// TODO djm recycle fixtures (here or in that destroy method)
body.FixtureList = f;
body.FixtureCount -= 1;
}
body.FixtureList = null;
body.FixtureCount = 0;
// Remove world body list.
if (body.Prev != null)
{
body.Prev.Next = body.Next;
}
if (body.Next != null)
{
body.Next.Prev = body.Prev;
}
if (body == BodyList)
{
BodyList = body.Next;
}
--BodyCount;
// TODO djm recycle body
}