diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 496fcb4a11..0577c82fa9 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -44,7 +44,7 @@ THE SOFTWARE. #include "CCEventTouch.h" #include "CCScene.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "CCPhysicsBody.h" #endif @@ -123,7 +123,7 @@ Node::Node(void) , _isTransitionFinished(false) , _updateScriptHandler(0) , _componentContainer(nullptr) -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS , _physicsBody(nullptr) #endif , _displayedOpacity(255) @@ -178,7 +178,7 @@ Node::~Node() CC_SAFE_DELETE(_componentContainer); -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS CC_SAFE_RELEASE(_physicsBody); #endif } @@ -264,7 +264,7 @@ void Node::setRotation(float newRotation) _rotationX = _rotationY = newRotation; _transformDirty = _inverseDirty = true; -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS if (_physicsBody) { _physicsBody->setRotation(newRotation); @@ -354,7 +354,7 @@ void Node::setPosition(const Point& newPosition) _position = newPosition; _transformDirty = _inverseDirty = true; -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS if (_physicsBody) { _physicsBody->setPosition(newPosition); @@ -604,7 +604,7 @@ void Node::addChild(Node *child, int zOrder, int tag) this->insertChild(child, zOrder); -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS for (Node* node = this->getParent(); node != nullptr; node = node->getParent()) { if (dynamic_cast(node) != nullptr) @@ -739,7 +739,7 @@ void Node::detachChild(Node *child, ssize_t childIndex, bool doCleanup) child->onExit(); } -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS if (child->_physicsBody != nullptr) { child->_physicsBody->removeFromWorld(); @@ -848,7 +848,7 @@ void Node::transformAncestors() void Node::transform() { -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS updatePhysicsTransform(); #endif @@ -1324,7 +1324,7 @@ Point Node::convertTouchToNodeSpaceAR(Touch *touch) const return this->convertToNodeSpaceAR(point); } -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS bool Node::updatePhysicsTransform() { if (_physicsBody != nullptr && _physicsBody->getWorld() != nullptr && !_physicsBody->isResting()) @@ -1374,7 +1374,7 @@ void Node::removeAllComponents() _componentContainer->removeAll(); } -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS void Node::setPhysicsBody(PhysicsBody* body) { if (_physicsBody != nullptr) diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index af95adc220..f976449312 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -54,7 +54,7 @@ class Component; class ComponentContainer; class EventDispatcher; class Scene; -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS class PhysicsBody; #endif @@ -1341,7 +1341,7 @@ public: /// @} end of component functions -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS /** * set the PhysicsBody that let the sprite effect with physics */ @@ -1465,7 +1465,7 @@ protected: ComponentContainer *_componentContainer; ///< Dictionary of components -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS PhysicsBody* _physicsBody; ///< the physicsBody the node have #endif diff --git a/cocos/2d/CCScene.cpp b/cocos/2d/CCScene.cpp index b31a499af6..b7cda2c831 100644 --- a/cocos/2d/CCScene.cpp +++ b/cocos/2d/CCScene.cpp @@ -34,7 +34,7 @@ THE SOFTWARE. NS_CC_BEGIN Scene::Scene() -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS : _physicsWorld(nullptr) #endif { @@ -44,7 +44,7 @@ Scene::Scene() Scene::~Scene() { -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS CC_SAFE_DELETE(_physicsWorld); #endif } @@ -88,7 +88,26 @@ Scene* Scene::getScene() return this; } -#ifdef CC_USE_PHYSICS +void Scene::addChild(Node* child, int zOrder, int tag) +{ + Node::addChild(child, zOrder, tag); +#if CC_USE_PHYSICS + addChildToPhysicsWorld(child); +#endif +} + +void Scene::update(float delta) +{ + Node::update(delta); +#if CC_USE_PHYSICS + if (nullptr != _physicsWorld) + { + _physicsWorld->update(delta); + } +#endif +} + +#if CC_USE_PHYSICS Scene *Scene::createWithPhysics() { Scene *ret = new Scene(); @@ -121,13 +140,6 @@ bool Scene::initWithPhysics() return ret; } -void Scene::addChild(Node* child, int zOrder, int tag) -{ - Node::addChild(child, zOrder, tag); - - addChildToPhysicsWorld(child); -} - void Scene::addChildToPhysicsWorld(Node* child) { if (_physicsWorld) @@ -149,18 +161,6 @@ void Scene::addChildToPhysicsWorld(Node* child) addToPhysicsWorldFunc(child); } } - -void Scene::update(float delta) -{ - Node::update(delta); - - if (nullptr != _physicsWorld) - { - _physicsWorld->update(delta); - } - -} #endif - NS_CC_END diff --git a/cocos/2d/CCScene.h b/cocos/2d/CCScene.h index b52d38e969..3d5a8180b2 100644 --- a/cocos/2d/CCScene.h +++ b/cocos/2d/CCScene.h @@ -52,42 +52,36 @@ class CC_DLL Scene : public Node public: /** creates a new Scene object */ static Scene *create(); -#ifdef CC_USE_PHYSICS - static Scene *createWithPhysics(); -#endif // Overrides virtual Scene *getScene() override; -#ifdef CC_USE_PHYSICS -public: - - inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; } - using Node::addChild; virtual void addChild(Node* child, int zOrder, int tag) override; virtual void update(float delta) override; virtual std::string getDescription() const override; +protected: + Scene(); + virtual ~Scene(); + bool init(); + + friend class Node; + friend class SpriteBatchNode; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Scene); + +#if CC_USE_PHYSICS +public: + inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; } + static Scene *createWithPhysics(); protected: bool initWithPhysics(); void addChildToPhysicsWorld(Node* child); PhysicsWorld* _physicsWorld; #endif // CC_USE_PHYSICS - - - -protected: - Scene(); - virtual ~Scene(); - bool init(); - - friend class Node; - friend class SpriteBatchNode; - -private: - CC_DISALLOW_COPY_AND_ASSIGN(Scene); }; // end of scene group diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 642e865aee..ee07bfca4c 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -502,7 +502,7 @@ void Sprite::updateTransform(void) { CCASSERT(_batchNode, "updateTransform is only valid when Sprite is being rendered using an SpriteBatchNode"); -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS if (updatePhysicsTransform()) { setDirty(true); @@ -711,7 +711,7 @@ bool Sprite::culling() const void Sprite::updateQuadVertices() { -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS updatePhysicsTransform(); setDirty(true); #endif diff --git a/cocos/2d/ccConfig.h b/cocos/2d/ccConfig.h index 5858fe88a0..b7fec05309 100644 --- a/cocos/2d/ccConfig.h +++ b/cocos/2d/ccConfig.h @@ -268,7 +268,7 @@ To enable set it to a value different than 0. Disabled by default. /** Use physics integration API */ #ifndef CC_USE_PHYSICS -#define CC_USE_PHYSICS +#define CC_USE_PHYSICS 0 #endif #endif // __CCCONFIG_H__ diff --git a/cocos/physics/CCPhysicsBody.cpp b/cocos/physics/CCPhysicsBody.cpp index 8b9451f873..c626389290 100644 --- a/cocos/physics/CCPhysicsBody.cpp +++ b/cocos/physics/CCPhysicsBody.cpp @@ -22,7 +22,7 @@ THE SOFTWARE. ****************************************************************************/ #include "CCPhysicsBody.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include #include diff --git a/cocos/physics/CCPhysicsBody.h b/cocos/physics/CCPhysicsBody.h index 8d31d82e61..a843732ad9 100644 --- a/cocos/physics/CCPhysicsBody.h +++ b/cocos/physics/CCPhysicsBody.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_BODY_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "CCObject.h" #include "CCGeometry.h" diff --git a/cocos/physics/CCPhysicsContact.cpp b/cocos/physics/CCPhysicsContact.cpp index a32266eed2..c04b295f46 100644 --- a/cocos/physics/CCPhysicsContact.cpp +++ b/cocos/physics/CCPhysicsContact.cpp @@ -22,7 +22,7 @@ THE SOFTWARE. ****************************************************************************/ #include "CCPhysicsContact.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "chipmunk.h" #include "CCPhysicsBody.h" diff --git a/cocos/physics/CCPhysicsContact.h b/cocos/physics/CCPhysicsContact.h index f734574565..552ab81e63 100644 --- a/cocos/physics/CCPhysicsContact.h +++ b/cocos/physics/CCPhysicsContact.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_CONTACT_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "CCObject.h" #include "CCGeometry.h" diff --git a/cocos/physics/CCPhysicsJoint.cpp b/cocos/physics/CCPhysicsJoint.cpp index 7300b01dd7..2d5cddd7ab 100644 --- a/cocos/physics/CCPhysicsJoint.cpp +++ b/cocos/physics/CCPhysicsJoint.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsJoint.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "chipmunk.h" #include "CCPhysicsBody.h" diff --git a/cocos/physics/CCPhysicsJoint.h b/cocos/physics/CCPhysicsJoint.h index 58cc5f83e3..b5e80e1c42 100644 --- a/cocos/physics/CCPhysicsJoint.h +++ b/cocos/physics/CCPhysicsJoint.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_JOINT_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "CCObject.h" #include "CCGeometry.h" diff --git a/cocos/physics/CCPhysicsShape.cpp b/cocos/physics/CCPhysicsShape.cpp index f7e9c524b2..543bbf0333 100644 --- a/cocos/physics/CCPhysicsShape.cpp +++ b/cocos/physics/CCPhysicsShape.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsShape.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include diff --git a/cocos/physics/CCPhysicsShape.h b/cocos/physics/CCPhysicsShape.h index 52e765b414..1146b2d291 100644 --- a/cocos/physics/CCPhysicsShape.h +++ b/cocos/physics/CCPhysicsShape.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_SHAPE_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "CCObject.h" #include "CCGeometry.h" diff --git a/cocos/physics/CCPhysicsWorld.cpp b/cocos/physics/CCPhysicsWorld.cpp index 9a80ef2bce..ebb12e4ec2 100644 --- a/cocos/physics/CCPhysicsWorld.cpp +++ b/cocos/physics/CCPhysicsWorld.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsWorld.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include diff --git a/cocos/physics/CCPhysicsWorld.h b/cocos/physics/CCPhysicsWorld.h index 80af28d260..6991071679 100644 --- a/cocos/physics/CCPhysicsWorld.h +++ b/cocos/physics/CCPhysicsWorld.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_WORLD_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "CCVector.h" #include "CCObject.h" diff --git a/cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.cpp b/cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.cpp index 701783402c..eb74a8ecc2 100644 --- a/cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.cpp +++ b/cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsBodyInfo_chipmunk.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS NS_CC_BEGIN PhysicsBodyInfo::PhysicsBodyInfo() diff --git a/cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.h b/cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.h index 7c695885b2..7f3d6aa177 100644 --- a/cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.h +++ b/cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_BODY_INFO_CHIPMUNK_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "chipmunk.h" #include "CCPlatformMacros.h" diff --git a/cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp b/cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp index bd0d46515e..54041c0a85 100644 --- a/cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp +++ b/cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsContactInfo_chipmunk.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS NS_CC_BEGIN PhysicsContactInfo::PhysicsContactInfo(PhysicsContact* contact) diff --git a/cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.h b/cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.h index 78e377e434..f6c63fceda 100644 --- a/cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.h +++ b/cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_CONTACT_INFO_CHIPMUNK_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "chipmunk.h" #include "CCPlatformMacros.h" diff --git a/cocos/physics/chipmunk/CCPhysicsHelper_chipmunk.h b/cocos/physics/chipmunk/CCPhysicsHelper_chipmunk.h index eb420ce3b1..c10990e669 100644 --- a/cocos/physics/chipmunk/CCPhysicsHelper_chipmunk.h +++ b/cocos/physics/chipmunk/CCPhysicsHelper_chipmunk.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_HELPER_CHIPMUNK_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "chipmunk.h" #include "CCPlatformMacros.h" diff --git a/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp b/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp index 0df8c2a7c6..9443a9f36c 100644 --- a/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp +++ b/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsJointInfo_chipmunk.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include #include diff --git a/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.h b/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.h index e3d57eff32..30817b66f0 100644 --- a/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.h +++ b/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_JOINT_INFO_CHIPMUNK_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "chipmunk.h" #include "CCPlatformMacros.h" diff --git a/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp b/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp index 3df70185ee..c1b8693259 100644 --- a/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp +++ b/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsShapeInfo_chipmunk.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include #include diff --git a/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.h b/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.h index 5ac25a2eb8..cbdaca53b1 100644 --- a/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.h +++ b/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include #include diff --git a/cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp b/cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp index 8b7f078215..23890b2198 100644 --- a/cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp +++ b/cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsWorldInfo_chipmunk.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include "CCPhysicsHelper_chipmunk.h" #include "CCPhysicsBodyInfo_chipmunk.h" #include "CCPhysicsShapeInfo_chipmunk.h" diff --git a/cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.h b/cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.h index 5554573101..b6de1dea20 100644 --- a/cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.h +++ b/cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.h @@ -26,7 +26,7 @@ #define __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__ #include "ccConfig.h" -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS #include #include "chipmunk.h" diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp index 1aef4a2a94..4a6a78eaff 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -6,7 +6,7 @@ USING_NS_CC; namespace { static std::function createFunctions[] = { -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS CL(PhysicsDemoLogoSmash), CL(PhysicsDemoPyramidStack), CL(PhysicsDemoClickAdd), @@ -55,7 +55,7 @@ namespace } PhysicsTestScene::PhysicsTestScene() -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS : TestScene(false, true) #else : TestScene() @@ -73,7 +73,7 @@ void PhysicsTestScene::runThisTest() void PhysicsTestScene::toggleDebug() { -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS _debugDraw = !_debugDraw; getPhysicsWorld()->setDebugDrawMask(_debugDraw ? PhysicsWorld::DEBUGDRAW_ALL : PhysicsWorld::DEBUGDRAW_NONE); #endif diff --git a/samples/Cpp/TestCpp/Classes/testBasic.cpp b/samples/Cpp/TestCpp/Classes/testBasic.cpp index cffd5acbef..67e68da3af 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.cpp +++ b/samples/Cpp/TestCpp/Classes/testBasic.cpp @@ -7,7 +7,7 @@ TestScene::TestScene(bool bPortrait, bool physics/* = false*/) { if (physics) { -#ifdef CC_USE_PHYSICS +#if CC_USE_PHYSICS TestScene::initWithPhysics(); #else Scene::init();