From 9a86aab97d9288aef182bb05e6e63a1e27b8c904 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 27 Aug 2010 22:19:16 +0200 Subject: [PATCH] Added body.getAllowSleeping, resolves #52 --- src/modules/physics/box2d/Body.cpp | 11 +++++++--- src/modules/physics/box2d/Body.h | 29 +++++++++++++------------ src/modules/physics/box2d/wrap_Body.cpp | 18 ++++++++++----- src/modules/physics/box2d/wrap_Body.h | 7 +++--- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/modules/physics/box2d/Body.cpp b/src/modules/physics/box2d/Body.cpp index f32d2ad45..898b39699 100644 --- a/src/modules/physics/box2d/Body.cpp +++ b/src/modules/physics/box2d/Body.cpp @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2010 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -281,6 +281,11 @@ namespace box2d body->AllowSleeping(allow); } + bool Body::getAllowSleeping() + { + return (body->m_flags & b2Body::e_allowSleepFlag); + } + void Body::putToSleep() { body->PutToSleep(); diff --git a/src/modules/physics/box2d/Body.h b/src/modules/physics/box2d/Body.h index e818f851f..a05684039 100644 --- a/src/modules/physics/box2d/Body.h +++ b/src/modules/physics/box2d/Body.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2010 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -41,8 +41,8 @@ namespace box2d /** * A Body is an entity which has position and orientation - * in world space. A Body does have collision geometry - * by itself, but depend on an arbitrary number of child Shape objects + * in world space. A Body does have collision geometry + * by itself, but depend on an arbitrary number of child Shape objects * which together constitute the final geometry for the Body. **/ class Body : public Object @@ -57,14 +57,14 @@ namespace box2d private: - // We need a shared_ptr to the parent World, + // We need a shared_ptr to the parent World, // because World can not be destroyed as long as // bodies exists in it. // // This ensures that a World only can be destroyed // once all bodies have been destroyed too. World * world; - + public: // The Box2D body. (Should not be public?) @@ -72,7 +72,7 @@ namespace box2d /** * Create a Body at position p. - **/ + **/ Body(World * world, b2Vec2 p, float m, float i); virtual ~Body(); @@ -169,7 +169,7 @@ namespace box2d * Apply force (fx, fy) with offset (rx, ry). **/ void applyForce(float fx, float fy, float rx, float ry); - + /** * Sets the x-position of the Body. **/ @@ -191,18 +191,18 @@ namespace box2d void setAngle(float d); /** - * Sets the current spin of the Body. + * Sets the current spin of the Body. **/ void setAngularVelocity(float r); /** * Sets the current position of the Body. - **/ + **/ void setPosition(float x, float y); /** * Sets the mass from the currently attatched shapes. - **/ + **/ void setMassFromShapes(); /** @@ -325,8 +325,9 @@ namespace box2d /** * Controls whether this Body should be allowed to sleep. - **/ + **/ void setAllowSleeping(bool allow); + bool getAllowSleeping(); /** * Puts the body to sleep. @@ -348,7 +349,7 @@ namespace box2d b2Vec2 getVector(lua_State * L); /** - * Pushed the x- and y-components of a vector on + * Pushed the x- and y-components of a vector on * the stack. **/ int pushVector(lua_State * L, const b2Vec2 & v); diff --git a/src/modules/physics/box2d/wrap_Body.cpp b/src/modules/physics/box2d/wrap_Body.cpp index 3a0638c3b..45938d3cd 100644 --- a/src/modules/physics/box2d/wrap_Body.cpp +++ b/src/modules/physics/box2d/wrap_Body.cpp @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2010 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -155,7 +155,7 @@ namespace box2d { return luaL_error(L, "Wrong number of parameters."); } - + return 0; } @@ -188,7 +188,7 @@ namespace box2d { return luaL_error(L, "Wrong number of parameters."); } - + return 0; } @@ -419,6 +419,13 @@ namespace box2d return 0; } + int w_Body_getAllowSleeping(lua_State * L) + { + Body * t = luax_checkbody(L, 1); + lua_pushboolean(L, t->getAllowSleeping()); + return 1; + } + int w_Body_putToSleep(lua_State * L) { Body * t = luax_checkbody(L, 1); @@ -500,6 +507,7 @@ namespace box2d { "isFrozen", w_Body_isFrozen }, { "isSleeping", w_Body_isSleeping }, { "setAllowSleeping", w_Body_setAllowSleeping }, + { "getAllowSleeping", w_Body_getAllowSleeping }, { "putToSleep", w_Body_putToSleep }, { "wakeUp", w_Body_wakeUp }, { "setFixedRotation", w_Body_setFixedRotation }, diff --git a/src/modules/physics/box2d/wrap_Body.h b/src/modules/physics/box2d/wrap_Body.h index d561c8c2d..9fbd74e07 100644 --- a/src/modules/physics/box2d/wrap_Body.h +++ b/src/modules/physics/box2d/wrap_Body.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2010 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -72,6 +72,7 @@ namespace box2d int w_Body_isFrozen(lua_State * L); int w_Body_isSleeping(lua_State * L); int w_Body_setAllowSleeping(lua_State * L); + int w_Body_getAllowSleeping(lua_State * L); int w_Body_putToSleep(lua_State * L); int w_Body_wakeUp(lua_State * L); int w_Body_setFixedRotation(lua_State * L);