issue #2771: change debug draw defines to class static const variable

This commit is contained in:
boyu0 2013-11-18 10:10:37 +08:00
parent 8ab64c9fa8
commit a7d884a63f
3 changed files with 14 additions and 14 deletions

View File

@ -618,7 +618,7 @@ void PhysicsWorld::update(float delta)
cpSpaceStep(_info->getSpace(), delta); cpSpaceStep(_info->getSpace(), delta);
if (_debugDrawMask != PHYSICS_DEBUGDRAW_NONE) if (_debugDrawMask != DEBUGDRAW_NONE)
{ {
debugDraw(); debugDraw();
} }
@ -635,7 +635,7 @@ void PhysicsWorld::debugDraw()
{ {
if (_debugDraw->begin()) if (_debugDraw->begin())
{ {
if (_debugDrawMask & PHYSICS_DEBUGDRAW_SHAPE) if (_debugDrawMask & DEBUGDRAW_SHAPE)
{ {
for (Object* obj : *_bodies) for (Object* obj : *_bodies)
{ {
@ -648,7 +648,7 @@ void PhysicsWorld::debugDraw()
} }
} }
if (_debugDrawMask & PHYSICS_DEBUGDRAW_JOINT) if (_debugDrawMask & DEBUGDRAW_JOINT)
{ {
for (auto joint : _joints) for (auto joint : _joints)
{ {
@ -663,7 +663,7 @@ void PhysicsWorld::debugDraw()
void PhysicsWorld::setDebugDrawMask(int mask) void PhysicsWorld::setDebugDrawMask(int mask)
{ {
if (mask == PHYSICS_DEBUGDRAW_NONE) if (mask == DEBUGDRAW_NONE)
{ {
CC_SAFE_DELETE(_debugDraw); CC_SAFE_DELETE(_debugDraw);
} }
@ -1039,7 +1039,7 @@ PhysicsWorld::PhysicsWorld()
, _scene(nullptr) , _scene(nullptr)
, _delayDirty(false) , _delayDirty(false)
, _debugDraw(nullptr) , _debugDraw(nullptr)
, _debugDrawMask(PHYSICS_DEBUGDRAW_NONE) , _debugDrawMask(DEBUGDRAW_NONE)
, _delayAddBodies(nullptr) , _delayAddBodies(nullptr)
, _delayRemoveBodies(nullptr) , _delayRemoveBodies(nullptr)
{ {

View File

@ -50,13 +50,6 @@ class PhysicsDebugDraw;
class PhysicsWorld; class PhysicsWorld;
#define PHYSICS_DEBUGDRAW_NONE 0x00
#define PHYSICS_DEBUGDRAW_SHAPE 0x01
#define PHYSICS_DEBUGDRAW_JOINT 0x02
#define PHYSICS_DEBUGDRAW_CONTACT 0x04
#define PHYSICS_DEBUGDRAW_ALL PHYSICS_DEBUGDRAW_SHAPE | PHYSICS_DEBUGDRAW_JOINT | PHYSICS_DEBUGDRAW_CONTACT
typedef struct PhysicsRayCastInfo typedef struct PhysicsRayCastInfo
{ {
PhysicsShape* shape; PhysicsShape* shape;
@ -87,6 +80,13 @@ typedef PhysicsRectQueryCallbackFunc PhysicsPointQueryCallbackFunc;
*/ */
class PhysicsWorld class PhysicsWorld
{ {
public:
static const long DEBUGDRAW_NONE = 0x00;
static const long DEBUGDRAW_SHAPE = 0x01;
static const long DEBUGDRAW_JOINT = 0x02;
static const long DEBUGDRAW_CONTACT = 0x04;
static const long DEBUGDRAW_ALL = DEBUGDRAW_SHAPE | DEBUGDRAW_JOINT | DEBUGDRAW_CONTACT;
public: public:
/** Adds a joint to the physics world.*/ /** Adds a joint to the physics world.*/
virtual void addJoint(PhysicsJoint* joint); virtual void addJoint(PhysicsJoint* joint);

View File

@ -69,7 +69,7 @@ bool PhysicsTestScene::initTest()
{ {
if (_debugDraw) if (_debugDraw)
{ {
getPhysicsWorld()->setDebugDrawMask(_debugDraw ? PHYSICS_DEBUGDRAW_ALL : PHYSICS_DEBUGDRAW_NONE); getPhysicsWorld()->setDebugDrawMask(_debugDraw ? PhysicsWorld::DEBUGDRAW_ALL : PhysicsWorld::DEBUGDRAW_NONE);
} }
return true; return true;
} }
@ -94,7 +94,7 @@ void PhysicsTestScene::runThisTest()
void PhysicsTestScene::toggleDebug() void PhysicsTestScene::toggleDebug()
{ {
_debugDraw = !_debugDraw; _debugDraw = !_debugDraw;
getPhysicsWorld()->setDebugDrawMask(_debugDraw ? PHYSICS_DEBUGDRAW_ALL : PHYSICS_DEBUGDRAW_NONE); getPhysicsWorld()->setDebugDrawMask(_debugDraw ? PhysicsWorld::DEBUGDRAW_ALL : PhysicsWorld::DEBUGDRAW_NONE);
} }
PhysicsDemo::PhysicsDemo() PhysicsDemo::PhysicsDemo()