love.physics: move internal box2d->love object map to World instances, and clean up some physics object code. Resolves issue #1465.

This commit is contained in:
Alex Szpakowski
2019-01-04 21:36:05 -04:00
parent 0752f27bdf
commit 3ad16a70da
20 changed files with 103 additions and 215 deletions
+7 -8
View File
@@ -22,8 +22,6 @@
#include "World.h"
#include "Physics.h"
#include "common/Memoizer.h"
namespace love
{
namespace physics
@@ -33,10 +31,11 @@ namespace box2d
love::Type Contact::type("Contact", &Object::type);
Contact::Contact(b2Contact *contact)
Contact::Contact(World *world, b2Contact *contact)
: contact(contact)
, world(world)
{
Memoizer::add(contact, this);
world->registerObject(contact, this);
}
Contact::~Contact()
@@ -48,14 +47,14 @@ void Contact::invalidate()
{
if (contact != NULL)
{
Memoizer::remove(contact);
world->unregisterObject(contact);
contact = NULL;
}
}
bool Contact::isValid()
{
return contact != NULL ? true : false;
return contact != NULL;
}
int Contact::getPositions(lua_State *L)
@@ -146,8 +145,8 @@ void Contact::getChildren(int &childA, int &childB)
void Contact::getFixtures(Fixture *&fixtureA, Fixture *&fixtureB)
{
fixtureA = (Fixture *) Memoizer::find(contact->GetFixtureA());
fixtureB = (Fixture *) Memoizer::find(contact->GetFixtureB());
fixtureA = (Fixture *) world->findObject(contact->GetFixtureA());
fixtureB = (Fixture *) world->findObject(contact->GetFixtureB());
if (!fixtureA || !fixtureB)
throw love::Exception("A fixture has escaped Memoizer!");