Added body.getAllowSleeping, resolves #52

This commit is contained in:
Bart van Strien
2010-08-27 22:19:16 +02:00
parent 944a1a6e8b
commit 9a86aab97d
4 changed files with 40 additions and 25 deletions
+8 -3
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2010 LOVE Development Team * Copyright (c) 2006-2010 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 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 * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * in a product, an acknowledgment in the product documentation would be
@@ -281,6 +281,11 @@ namespace box2d
body->AllowSleeping(allow); body->AllowSleeping(allow);
} }
bool Body::getAllowSleeping()
{
return (body->m_flags & b2Body::e_allowSleepFlag);
}
void Body::putToSleep() void Body::putToSleep()
{ {
body->PutToSleep(); body->PutToSleep();
+15 -14
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2010 LOVE Development Team * Copyright (c) 2006-2010 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 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 * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * 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 * A Body is an entity which has position and orientation
* in world space. A Body does have collision geometry * in world space. A Body does have collision geometry
* by itself, but depend on an arbitrary number of child Shape objects * by itself, but depend on an arbitrary number of child Shape objects
* which together constitute the final geometry for the Body. * which together constitute the final geometry for the Body.
**/ **/
class Body : public Object class Body : public Object
@@ -57,14 +57,14 @@ namespace box2d
private: 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 // because World can not be destroyed as long as
// bodies exists in it. // bodies exists in it.
// //
// This ensures that a World only can be destroyed // This ensures that a World only can be destroyed
// once all bodies have been destroyed too. // once all bodies have been destroyed too.
World * world; World * world;
public: public:
// The Box2D body. (Should not be public?) // The Box2D body. (Should not be public?)
@@ -72,7 +72,7 @@ namespace box2d
/** /**
* Create a Body at position p. * Create a Body at position p.
**/ **/
Body(World * world, b2Vec2 p, float m, float i); Body(World * world, b2Vec2 p, float m, float i);
virtual ~Body(); virtual ~Body();
@@ -169,7 +169,7 @@ namespace box2d
* Apply force (fx, fy) with offset (rx, ry). * Apply force (fx, fy) with offset (rx, ry).
**/ **/
void applyForce(float fx, float fy, float rx, float ry); void applyForce(float fx, float fy, float rx, float ry);
/** /**
* Sets the x-position of the Body. * Sets the x-position of the Body.
**/ **/
@@ -191,18 +191,18 @@ namespace box2d
void setAngle(float d); void setAngle(float d);
/** /**
* Sets the current spin of the Body. * Sets the current spin of the Body.
**/ **/
void setAngularVelocity(float r); void setAngularVelocity(float r);
/** /**
* Sets the current position of the Body. * Sets the current position of the Body.
**/ **/
void setPosition(float x, float y); void setPosition(float x, float y);
/** /**
* Sets the mass from the currently attatched shapes. * Sets the mass from the currently attatched shapes.
**/ **/
void setMassFromShapes(); void setMassFromShapes();
/** /**
@@ -325,8 +325,9 @@ namespace box2d
/** /**
* Controls whether this Body should be allowed to sleep. * Controls whether this Body should be allowed to sleep.
**/ **/
void setAllowSleeping(bool allow); void setAllowSleeping(bool allow);
bool getAllowSleeping();
/** /**
* Puts the body to sleep. * Puts the body to sleep.
@@ -348,7 +349,7 @@ namespace box2d
b2Vec2 getVector(lua_State * L); 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. * the stack.
**/ **/
int pushVector(lua_State * L, const b2Vec2 & v); int pushVector(lua_State * L, const b2Vec2 & v);
+13 -5
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2010 LOVE Development Team * Copyright (c) 2006-2010 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 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 * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * 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 luaL_error(L, "Wrong number of parameters.");
} }
return 0; return 0;
} }
@@ -188,7 +188,7 @@ namespace box2d
{ {
return luaL_error(L, "Wrong number of parameters."); return luaL_error(L, "Wrong number of parameters.");
} }
return 0; return 0;
} }
@@ -419,6 +419,13 @@ namespace box2d
return 0; 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) int w_Body_putToSleep(lua_State * L)
{ {
Body * t = luax_checkbody(L, 1); Body * t = luax_checkbody(L, 1);
@@ -500,6 +507,7 @@ namespace box2d
{ "isFrozen", w_Body_isFrozen }, { "isFrozen", w_Body_isFrozen },
{ "isSleeping", w_Body_isSleeping }, { "isSleeping", w_Body_isSleeping },
{ "setAllowSleeping", w_Body_setAllowSleeping }, { "setAllowSleeping", w_Body_setAllowSleeping },
{ "getAllowSleeping", w_Body_getAllowSleeping },
{ "putToSleep", w_Body_putToSleep }, { "putToSleep", w_Body_putToSleep },
{ "wakeUp", w_Body_wakeUp }, { "wakeUp", w_Body_wakeUp },
{ "setFixedRotation", w_Body_setFixedRotation }, { "setFixedRotation", w_Body_setFixedRotation },
+4 -3
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2010 LOVE Development Team * Copyright (c) 2006-2010 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 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 * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * 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_isFrozen(lua_State * L);
int w_Body_isSleeping(lua_State * L); int w_Body_isSleeping(lua_State * L);
int w_Body_setAllowSleeping(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_putToSleep(lua_State * L);
int w_Body_wakeUp(lua_State * L); int w_Body_wakeUp(lua_State * L);
int w_Body_setFixedRotation(lua_State * L); int w_Body_setFixedRotation(lua_State * L);