Shape:destroy;

This commit is contained in:
bjorn 2017-05-19 22:24:23 -06:00
parent 6ef9c6e475
commit 0fb1bd77d8
3 changed files with 16 additions and 1 deletions

View File

@ -10,6 +10,12 @@ int luax_pushshape(lua_State* L, Shape* shape) {
}
}
int l_lovrShapeDestroy(lua_State* L) {
Shape* shape = luax_checktypeof(L, 1, Shape);
lovrShapeDestroyData(shape);
return 0;
}
int l_lovrShapeGetType(lua_State* L) {
Shape* shape = luax_checktypeof(L, 1, Shape);
luax_pushenum(L, &ShapeTypes, lovrShapeGetType(shape));
@ -172,6 +178,7 @@ int l_lovrShapeComputeMass(lua_State* L) {
}
const luaL_Reg lovrShape[] = {
{ "destroy", l_lovrShapeDestroy },
{ "getType", l_lovrShapeGetType },
{ "getCollider", l_lovrShapeGetCollider },
{ "isEnabled", l_lovrShapeIsEnabled },

View File

@ -429,10 +429,17 @@ void lovrColliderGetLinearVelocityFromWorldPoint(Collider* collider, float wx, f
void lovrShapeDestroy(const Ref* ref) {
Shape* shape = containerof(ref, Shape);
dGeomDestroy(shape->id);
lovrShapeDestroyData(shape);
free(shape);
}
void lovrShapeDestroyData(Shape* shape) {
if (shape->id) {
dGeomDestroy(shape->id);
shape->id = NULL;
}
}
ShapeType lovrShapeGetType(Shape* shape) {
return shape->type;
}

View File

@ -107,6 +107,7 @@ void lovrColliderGetLinearVelocityFromLocalPoint(Collider* collider, float x, fl
void lovrColliderGetLinearVelocityFromWorldPoint(Collider* collider, float wx, float wy, float wz, float* vx, float* vy, float* vz);
void lovrShapeDestroy(const Ref* ref);
void lovrShapeDestroyData(Shape* shape);
ShapeType lovrShapeGetType(Shape* shape);
Collider* lovrShapeGetCollider(Shape* shape);
int lovrShapeIsEnabled(Shape* shape);