Reduced the number of explicit retain/release method calls on love objects. Less chance of bugs!

This commit is contained in:
Alex Szpakowski
2014-08-07 14:53:17 -03:00
parent a0fff798aa
commit d59c76a55f
38 changed files with 194 additions and 247 deletions
+2 -5
View File
@@ -41,7 +41,6 @@ Body::Body(World *world, b2Vec2 p, Body::Type type)
{
udata = new bodyudata();
udata->ref = nullptr;
world->retain();
b2BodyDef def;
def.position = Physics::scaleDown(p);
def.userData = (void *) udata;
@@ -57,8 +56,7 @@ Body::Body(b2Body *b)
, udata(nullptr)
{
udata = (bodyudata *) b->GetUserData();
world = (World *)Memoizer::find(b->GetWorld());
world->retain();
world.set((World *) Memoizer::find(b->GetWorld()));
// Box2D body holds a reference to the love Body.
this->retain();
Memoizer::add(body, this);
@@ -69,7 +67,6 @@ Body::~Body()
if (udata != nullptr)
delete udata->ref;
delete udata;
world->release();
}
float Body::getX()
@@ -420,7 +417,7 @@ bool Body::isFixedRotation() const
World *Body::getWorld() const
{
return world;
return world.get();
}
int Body::getFixtureList(lua_State *L) const
+1 -1
View File
@@ -436,7 +436,7 @@ private:
//
// This ensures that a World only can be destroyed
// once all bodies have been destroyed too.
World *world;
Object::StrongRef<World> world;
bodyudata *udata;
+2 -2
View File
@@ -40,7 +40,7 @@ namespace box2d
{
Joint::Joint(Body *body1)
: world(body1->world)
: world(body1->world.get())
, udata(nullptr)
, body1(body1)
, body2(nullptr)
@@ -50,7 +50,7 @@ Joint::Joint(Body *body1)
}
Joint::Joint(Body *body1, Body *body2)
: world(body1->world)
: world(body1->world.get())
, udata(nullptr)
, body1(body1)
, body2(body2)
+3 -6
View File
@@ -259,23 +259,20 @@ void World::update(float dt)
world->Step(dt, 8, 6);
// Destroy all objects marked during the time step.
for (auto i = destructBodies.begin(); i < destructBodies.end(); i++)
for (Body *b : destructBodies)
{
Body *b = *i;
if (b->body != 0) b->destroy();
// Release for reference in vector.
b->release();
}
for (auto i = destructFixtures.begin(); i < destructFixtures.end(); i++)
for (Fixture *f : destructFixtures)
{
Fixture *f = *i;
if (f->isValid()) f->destroy();
// Release for reference in vector.
f->release();
}
for (auto i = destructJoints.begin(); i < destructJoints.end(); i++)
for (Joint *j : destructJoints)
{
Joint *j = *i;
if (j->isValid()) j->destroyJoint();
// Release for reference in vector.
j->release();