mirror of
https://github.com/love2d/love.git
synced 2026-08-18 03:34:23 +02:00
Reduced the number of explicit retain/release method calls on love objects. Less chance of bugs!
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user