Browse Source

Added Body/Contact/Fixture/Joint/World:isDestroyed (resolves issue #964.)

Alex Szpakowski 10 years ago
parent
commit
91062a1496

+ 8 - 0
src/modules/physics/box2d/wrap_Body.cpp

@@ -564,6 +564,13 @@ int w_Body_destroy(lua_State *L)
 	return 0;
 }
 
+int w_Body_isDestroyed(lua_State *L)
+{
+	Body *b = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
+	luax_pushboolean(L, b->body == nullptr);
+	return 1;
+}
+
 int w_Body_setUserData(lua_State *L)
 {
 	Body *t = luax_checkbody(L, 1);
@@ -635,6 +642,7 @@ static const luaL_Reg functions[] =
 	{ "getJointList", w_Body_getJointList },
 	{ "getContactList", w_Body_getContactList },
 	{ "destroy", w_Body_destroy },
+	{ "isDestroyed", w_Body_isDestroyed },
 	{ "setUserData", w_Body_setUserData },
 	{ "getUserData", w_Body_getUserData },
 	{ 0, 0 }

+ 1 - 0
src/modules/physics/box2d/wrap_Body.h

@@ -88,6 +88,7 @@ int w_Body_getFixtureList(lua_State *L);
 int w_Body_getJointList(lua_State *L);
 int w_Body_getContactList(lua_State *L);
 int w_Body_destroy(lua_State *L);
+int w_Body_isDestroyed(lua_State *L);
 int w_Body_setUserData(lua_State *L);
 int w_Body_getUserData(lua_State *L);
 extern "C" int luaopen_body(lua_State *L);

+ 8 - 0
src/modules/physics/box2d/wrap_Contact.cpp

@@ -151,6 +151,13 @@ int w_Contact_getFixtures(lua_State *L)
 	return 2;
 }
 
+int w_Contact_isDestroyed(lua_State *L)
+{
+	Contact *c = luax_checktype<Contact>(L, 1, "Contact", PHYSICS_CONTACT_T);
+	luax_pushboolean(L, !c->isValid());
+	return 1;
+}
+
 extern "C" int luaopen_contact(lua_State *L)
 {
 	static const luaL_Reg functions[] =
@@ -170,6 +177,7 @@ extern "C" int luaopen_contact(lua_State *L)
 		{ "getTangentSpeed", w_Contact_getTangentSpeed },
 		{ "getChildren", w_Contact_getChildren },
 		{ "getFixtures", w_Contact_getFixtures },
+		{ "isDestroyed", w_Contact_isDestroyed },
 		{ 0, 0 }
 	};
 

+ 1 - 0
src/modules/physics/box2d/wrap_Contact.h

@@ -48,6 +48,7 @@ int w_Contact_setTangentSpeed(lua_State *L);
 int w_Contact_getTangentSpeed(lua_State *L);
 int w_Contact_getChildren(lua_State *L);
 int w_Contact_getFixtures(lua_State *L);
+int w_Contact_isDestroyed(lua_State *L);
 extern "C" int luaopen_contact(lua_State *L);
 
 } // box2d

+ 1 - 0
src/modules/physics/box2d/wrap_DistanceJoint.cpp

@@ -98,6 +98,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 8 - 0
src/modules/physics/box2d/wrap_Fixture.cpp

@@ -262,6 +262,13 @@ int w_Fixture_destroy(lua_State *L)
 	return 0;
 }
 
+int w_Fixture_isDestroyed(lua_State *L)
+{
+	Fixture *f = luax_checktype<Fixture>(L, 1, "Fixture", PHYSICS_FIXTURE_T);
+	luax_pushboolean(L, !f->isValid());
+	return 1;
+}
+
 static const luaL_Reg functions[] =
 {
 	{ "getType", w_Fixture_getType },
@@ -290,6 +297,7 @@ static const luaL_Reg functions[] =
 	{ "getGroupIndex", w_Fixture_getGroupIndex },
 	{ "setGroupIndex", w_Fixture_setGroupIndex },
 	{ "destroy", w_Fixture_destroy },
+	{ "isDestroyed", w_Fixture_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_Fixture.h

@@ -60,6 +60,7 @@ int w_Fixture_getMassData(lua_State *L);
 int w_Fixture_getGroupIndex(lua_State *L);
 int w_Fixture_setGroupIndex(lua_State *L);
 int w_Fixture_destroy(lua_State *L);
+int w_Fixture_isDestroyed(lua_State *L);
 extern "C" int luaopen_fixture(lua_State *L);
 
 } // box2d

+ 1 - 0
src/modules/physics/box2d/wrap_FrictionJoint.cpp

@@ -82,6 +82,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_GearJoint.cpp

@@ -82,6 +82,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 8 - 0
src/modules/physics/box2d/wrap_Joint.cpp

@@ -147,6 +147,13 @@ int w_Joint_destroy(lua_State *L)
 	return 0;
 }
 
+int w_Joint_isDestroyed(lua_State *L)
+{
+	Joint *t = luax_checktype<Joint>(L, 1, "Joint", PHYSICS_JOINT_T);
+	luax_pushboolean(L, !t->isValid());
+	return 1;
+}
+
 static const luaL_Reg functions[] =
 {
 	{ "getType", w_Joint_getType },
@@ -158,6 +165,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_Joint.h

@@ -43,6 +43,7 @@ int w_Joint_getCollideConnected(lua_State *L);
 int w_Joint_setUserData(lua_State *L);
 int w_Joint_getUserData(lua_State *L);
 int w_Joint_destroy(lua_State *L);
+int w_Joint_isDestroyed(lua_State *L);
 extern "C" int luaopen_joint(lua_State *L);
 
 } // box2d

+ 1 - 0
src/modules/physics/box2d/wrap_MotorJoint.cpp

@@ -132,6 +132,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_MouseJoint.cpp

@@ -116,6 +116,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_PrismaticJoint.cpp

@@ -193,6 +193,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_PulleyJoint.cpp

@@ -79,6 +79,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_RevoluteJoint.cpp

@@ -193,6 +193,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_RopeJoint.cpp

@@ -55,6 +55,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_WeldJoint.cpp

@@ -81,6 +81,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_WheelJoint.cpp

@@ -157,6 +157,7 @@ static const luaL_Reg functions[] =
 	{ "setUserData", w_Joint_setUserData },
 	{ "getUserData", w_Joint_getUserData },
 	{ "destroy", w_Joint_destroy },
+	{ "isDestroyed", w_Joint_isDestroyed },
 	{ 0, 0 }
 };
 

+ 8 - 0
src/modules/physics/box2d/wrap_World.cpp

@@ -189,6 +189,13 @@ int w_World_destroy(lua_State *L)
 	return 0;
 }
 
+int w_World_isDestroyed(lua_State *L)
+{
+	World *w = luax_checktype<World>(L, 1, "World", PHYSICS_WORLD_T);
+	luax_pushboolean(L, !w->isValid());
+	return 1;
+}
+
 
 static const luaL_Reg functions[] =
 {
@@ -212,6 +219,7 @@ static const luaL_Reg functions[] =
 	{ "queryBoundingBox", w_World_queryBoundingBox },
 	{ "rayCast", w_World_rayCast },
 	{ "destroy", w_World_destroy },
+	{ "isDestroyed", w_World_isDestroyed },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/physics/box2d/wrap_World.h

@@ -55,6 +55,7 @@ int w_World_getContactList(lua_State *L);
 int w_World_queryBoundingBox(lua_State *L);
 int w_World_rayCast(lua_State *L);
 int w_World_destroy(lua_State *L);
+int w_World_isDestroyed(lua_State *L);
 extern "C" int luaopen_world(lua_State *L);
 
 } // box2d