From 221d9699f67dfe642755135a7e3c153cbccecca8 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sat, 24 Sep 2011 17:12:45 -0400 Subject: [PATCH] Add Body:getFilterList --HG-- branch : box2d-update --- src/modules/physics/box2d/Body.cpp | 15 +++++++++++++++ src/modules/physics/box2d/Body.h | 7 +++++++ src/modules/physics/box2d/wrap_Body.cpp | 8 ++++++++ src/modules/physics/box2d/wrap_Body.h | 1 + 4 files changed, 31 insertions(+) diff --git a/src/modules/physics/box2d/Body.cpp b/src/modules/physics/box2d/Body.cpp index a5cba16ca..7f4786676 100644 --- a/src/modules/physics/box2d/Body.cpp +++ b/src/modules/physics/box2d/Body.cpp @@ -394,6 +394,21 @@ namespace box2d { return world; } + + int Body::getFixtureList(lua_State * L) const + { + lua_newtable(L); + b2Fixture * f = body->GetFixtureList(); + int i = 1; + do { + if (!f) break; + Fixture * fixture = (Fixture *)Memoizer::find(f); + if (!fixture) throw love::Exception("A fixture has escaped Memoizer!"); + luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)fixture); + lua_rawseti(L, -1, i); + } while ((f = f->GetNext())); + return 1; + } b2Vec2 Body::getVector(lua_State * L) { diff --git a/src/modules/physics/box2d/Body.h b/src/modules/physics/box2d/Body.h index 07c181365..f5b457bab 100644 --- a/src/modules/physics/box2d/Body.h +++ b/src/modules/physics/box2d/Body.h @@ -378,6 +378,13 @@ namespace box2d * Get the World this Body resides in. */ World * getWorld() const; + + /** + * Get an array of all the Fixtures attached to this Body. + * @return An array of Fixtures. + **/ + int getFixtureList(lua_State * L) const; + private: /** diff --git a/src/modules/physics/box2d/wrap_Body.cpp b/src/modules/physics/box2d/wrap_Body.cpp index 909f5e429..2e0413091 100644 --- a/src/modules/physics/box2d/wrap_Body.cpp +++ b/src/modules/physics/box2d/wrap_Body.cpp @@ -499,6 +499,13 @@ namespace box2d luax_pushboolean(L, b); return 1; } + + int w_Body_getFixtureList(lua_State * L) + { + Body * t = luax_checkbody(L, 1); + lua_remove(L, 1); + return t->getFixtureList(L); + } int w_Body_destroy(lua_State * L) { @@ -561,6 +568,7 @@ namespace box2d { "setAwake", w_Body_setAwake }, { "setFixedRotation", w_Body_setFixedRotation }, { "isFixedRotation", w_Body_isFixedRotation }, + { "getFixtureList", w_Body_getFixtureList }, { "destroy", w_Body_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_Body.h b/src/modules/physics/box2d/wrap_Body.h index e7a8fe6e2..2d5ac84b6 100644 --- a/src/modules/physics/box2d/wrap_Body.h +++ b/src/modules/physics/box2d/wrap_Body.h @@ -82,6 +82,7 @@ namespace box2d int w_Body_setAwake(lua_State * L); int w_Body_setFixedRotation(lua_State * L); int w_Body_isFixedRotation(lua_State * L); + int w_Body_getFixtureList(lua_State * L); int w_Body_destroy(lua_State * L); int luaopen_body(lua_State * L);