body:destroy()
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: body:destroy()
I remember rude saying something about destroy waiting a frame...
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: body:destroy()
Can we just make body:destroy() "mark it for destroying" ( + mask stuff) and then removing the body on the next frame?
When I write def I mean function.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: body:destroy()
So if it waits a frame, then maybe I don't have to wait. I guess the way to find out is to test it.
Re: body:destroy()
Not necessarily wait for the next frame. You can mark a entity to remove, update the world, and delete entity.
I'm using the following method:
And somewhere:
I'm using the following method:
Code: Select all
function Unit:predelete()
-- remove shapes from contacts (important for collision callbacks)
for _, shape in pairs(self.shapes) do
shape:setMask(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
end
self.predeleted = true
end
function Unit:delete()
if self.predeleted then
for i, joint in pairs(self.joints) do
joint:destroy()
end
self.joints = {}
for i, shape in pairs(self.shapes) do
shape:destroy()
end
self.shapes = {}
for i, body in pairs(self.bodies) do
body:destroy()
end
self.bodies = {}
self.deleted = true
end
end
function love.update()
if not paused then
-- prepare for removing (remove collision contacts)
for _,unit in ipairs(for_removal) do
unit:predelete()
end
-- update all
for _,unit in ipairs(units) do unit:update() end
world:update(dt)
-- remove
if for_removal ~= {} then
for _,unit in ipairs(for_removal) do
unit:delete()
end
for_removal = {}
end
end
end
Code: Select all
table.insert(for_removal, some_unit)
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: body:destroy()
That is what I meant when I said that löve should do it. I meant that it should mark it for deletion, unmask it and automatically remove it on the next physics update.
When I write def I mean function.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: body:destroy()
And I was trying to say I heard rude proclaiming several times that that is the case.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: body:destroy()
Here's the code for the destroy function:
And the code for the Body's destructor:
I don't see anything about waiting a frame. Am I missing something?
Code: Select all
int w_Body_destroy(lua_State * L)
{
Proxy * p = (Proxy *)lua_touserdata(L, 1);
p->own = false;
Body * t = (Body *)p->data;
t->release();
return 0;
}
Code: Select all
Body::~Body()
{
world->world->DestroyBody(body);
world->release();
body = 0;
}
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: body:destroy()
I only know what rude told me.. anyway it does wait 1 gc cycle..
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests