Browse Source

Add World:isLocked and const-ify a few worthy methods

--HG--
branch : box2d-update
Bill Meltsner 14 years ago
parent
commit
dd3993623b

+ 12 - 7
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;
 	}

+ 14 - 7
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.

+ 8 - 0
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 },

+ 1 - 0
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);