From dd3993623bab5b55e99235deebebe95ec80ccdbb Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sat, 24 Sep 2011 16:59:45 -0400 Subject: [PATCH] Add World:isLocked and const-ify a few worthy methods --HG-- branch : box2d-update --- src/modules/physics/box2d/World.cpp | 19 ++++++++++++------- src/modules/physics/box2d/World.h | 21 ++++++++++++++------- src/modules/physics/box2d/wrap_World.cpp | 8 ++++++++ src/modules/physics/box2d/wrap_World.h | 1 + 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/modules/physics/box2d/World.cpp b/src/modules/physics/box2d/World.cpp index 699d1b3d1..303a70b17 100644 --- a/src/modules/physics/box2d/World.cpp +++ b/src/modules/physics/box2d/World.cpp @@ -341,23 +341,28 @@ namespace box2d { return world->GetAllowSleeping(); } + + bool World::isLocked() const + { + return world->IsLocked(); + } - int World::getBodyCount() + int World::getBodyCount() const { return world->GetBodyCount(); } - int World::getJointCount() + int World::getJointCount() const { return world->GetJointCount(); } - int World::getContactCount() + int World::getContactCount() const { return world->GetContactCount(); } - int World::getBodyList(lua_State * L) + int World::getBodyList(lua_State * L) const { lua_newtable(L); b2Body * b = world->GetBodyList(); @@ -372,7 +377,7 @@ namespace box2d return 1; } - int World::getJointList(lua_State * L) + int World::getJointList(lua_State * L) const { lua_newtable(L); b2Joint * j = world->GetJointList(); @@ -387,7 +392,7 @@ namespace box2d return 1; } - int World::getContactList(lua_State * L) + int World::getContactList(lua_State * L) const { lua_newtable(L); b2Contact * c = world->GetContactList(); @@ -402,7 +407,7 @@ namespace box2d return 1; } - b2Body * World::getGroundBody() + b2Body * World::getGroundBody() const { return groundBody; } diff --git a/src/modules/physics/box2d/World.h b/src/modules/physics/box2d/World.h index 74987f84f..7bd605f1a 100644 --- a/src/modules/physics/box2d/World.h +++ b/src/modules/physics/box2d/World.h @@ -202,48 +202,55 @@ namespace box2d * @return True if allowed, false if disallowed. **/ bool getAllowSleeping() const; + + /** + * Returns whether this World is currently locked. + * If it's locked, it's in the middle of a timestep. + * @return Whether the World is locked. + **/ + bool isLocked() const; /** * Get the current body count. * @return The number of bodies. **/ - int getBodyCount(); + int getBodyCount() const; /** * Get the current joint count. * @return The number of joints. **/ - int getJointCount(); + int getJointCount() const; /** * Get the current contact count. * @return The number of contacts. **/ - int getContactCount(); + int getContactCount() const; /** * Get an array of all the Bodies in the World. * @return An array of Bodies. **/ - int getBodyList(lua_State * L); + int getBodyList(lua_State * L) const; /** * Get an array of all the Joints in the World. * @return An array of Joints. **/ - int getJointList(lua_State * L); + int getJointList(lua_State * L) const; /** * Get an array of all the Contacts in the World. * @return An array of Contacts. **/ - int getContactList(lua_State * L); + int getContactList(lua_State * L) const; /** * Gets the ground body. * @return The ground body. **/ - b2Body * getGroundBody(); + b2Body * getGroundBody() const; /** * Gets all fixtures that overlap a given bounding box. diff --git a/src/modules/physics/box2d/wrap_World.cpp b/src/modules/physics/box2d/wrap_World.cpp index 2b60404a4..430f5ae9c 100644 --- a/src/modules/physics/box2d/wrap_World.cpp +++ b/src/modules/physics/box2d/wrap_World.cpp @@ -98,6 +98,13 @@ namespace box2d luax_pushboolean(L, t->getAllowSleeping()); return 1; } + + int w_World_isLocked(lua_State * L) + { + World * t = luax_checkworld(L, 1); + luax_pushboolean(L, t->isLocked()); + return 1; + } int w_World_getBodyCount(lua_State * L) { @@ -165,6 +172,7 @@ namespace box2d { "getGravity", w_World_getGravity }, { "setAllowSleeping", w_World_setAllowSleeping }, { "getAllowSleeping", w_World_getAllowSleeping }, + { "isLocked", w_World_isLocked }, { "getBodyCount", w_World_getBodyCount }, { "getJointCount", w_World_getJointCount }, { "getContactCount", w_World_getContactCount }, diff --git a/src/modules/physics/box2d/wrap_World.h b/src/modules/physics/box2d/wrap_World.h index e2a10a19c..3953bec83 100644 --- a/src/modules/physics/box2d/wrap_World.h +++ b/src/modules/physics/box2d/wrap_World.h @@ -41,6 +41,7 @@ namespace box2d int w_World_getGravity(lua_State * L); int w_World_setAllowSleeping(lua_State * L); int w_World_getAllowSleeping(lua_State * L); + int w_World_isLocked(lua_State * L); int w_World_getBodyCount(lua_State * L); int w_World_getJointCount(lua_State * L); int w_World_getContactCount(lua_State * L);