Merge pull request #4688 from walzer/develop

make CC_USE_PHYSICS can ACTUALLY be switch off
This commit is contained in:
James Chen 2013-12-27 04:04:48 -08:00
commit 9baa64f274
30 changed files with 78 additions and 88 deletions

View File

@ -44,7 +44,7 @@ THE SOFTWARE.
#include "CCEventTouch.h" #include "CCEventTouch.h"
#include "CCScene.h" #include "CCScene.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "CCPhysicsBody.h" #include "CCPhysicsBody.h"
#endif #endif
@ -123,7 +123,7 @@ Node::Node(void)
, _isTransitionFinished(false) , _isTransitionFinished(false)
, _updateScriptHandler(0) , _updateScriptHandler(0)
, _componentContainer(nullptr) , _componentContainer(nullptr)
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
, _physicsBody(nullptr) , _physicsBody(nullptr)
#endif #endif
, _displayedOpacity(255) , _displayedOpacity(255)
@ -178,7 +178,7 @@ Node::~Node()
CC_SAFE_DELETE(_componentContainer); CC_SAFE_DELETE(_componentContainer);
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
CC_SAFE_RELEASE(_physicsBody); CC_SAFE_RELEASE(_physicsBody);
#endif #endif
} }
@ -264,7 +264,7 @@ void Node::setRotation(float newRotation)
_rotationX = _rotationY = newRotation; _rotationX = _rotationY = newRotation;
_transformDirty = _inverseDirty = true; _transformDirty = _inverseDirty = true;
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
if (_physicsBody) if (_physicsBody)
{ {
_physicsBody->setRotation(newRotation); _physicsBody->setRotation(newRotation);
@ -354,7 +354,7 @@ void Node::setPosition(const Point& newPosition)
_position = newPosition; _position = newPosition;
_transformDirty = _inverseDirty = true; _transformDirty = _inverseDirty = true;
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
if (_physicsBody) if (_physicsBody)
{ {
_physicsBody->setPosition(newPosition); _physicsBody->setPosition(newPosition);
@ -604,7 +604,7 @@ void Node::addChild(Node *child, int zOrder, int tag)
this->insertChild(child, zOrder); this->insertChild(child, zOrder);
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
for (Node* node = this->getParent(); node != nullptr; node = node->getParent()) for (Node* node = this->getParent(); node != nullptr; node = node->getParent())
{ {
if (dynamic_cast<Scene*>(node) != nullptr) if (dynamic_cast<Scene*>(node) != nullptr)
@ -739,7 +739,7 @@ void Node::detachChild(Node *child, ssize_t childIndex, bool doCleanup)
child->onExit(); child->onExit();
} }
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
if (child->_physicsBody != nullptr) if (child->_physicsBody != nullptr)
{ {
child->_physicsBody->removeFromWorld(); child->_physicsBody->removeFromWorld();
@ -848,7 +848,7 @@ void Node::transformAncestors()
void Node::transform() void Node::transform()
{ {
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
updatePhysicsTransform(); updatePhysicsTransform();
#endif #endif
@ -1324,7 +1324,7 @@ Point Node::convertTouchToNodeSpaceAR(Touch *touch) const
return this->convertToNodeSpaceAR(point); return this->convertToNodeSpaceAR(point);
} }
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
bool Node::updatePhysicsTransform() bool Node::updatePhysicsTransform()
{ {
if (_physicsBody != nullptr && _physicsBody->getWorld() != nullptr && !_physicsBody->isResting()) if (_physicsBody != nullptr && _physicsBody->getWorld() != nullptr && !_physicsBody->isResting())
@ -1374,7 +1374,7 @@ void Node::removeAllComponents()
_componentContainer->removeAll(); _componentContainer->removeAll();
} }
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
void Node::setPhysicsBody(PhysicsBody* body) void Node::setPhysicsBody(PhysicsBody* body)
{ {
if (_physicsBody != nullptr) if (_physicsBody != nullptr)

View File

@ -54,7 +54,7 @@ class Component;
class ComponentContainer; class ComponentContainer;
class EventDispatcher; class EventDispatcher;
class Scene; class Scene;
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
class PhysicsBody; class PhysicsBody;
#endif #endif
@ -1341,7 +1341,7 @@ public:
/// @} end of component functions /// @} end of component functions
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
/** /**
* set the PhysicsBody that let the sprite effect with physics * set the PhysicsBody that let the sprite effect with physics
*/ */
@ -1465,7 +1465,7 @@ protected:
ComponentContainer *_componentContainer; ///< Dictionary of components ComponentContainer *_componentContainer; ///< Dictionary of components
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
PhysicsBody* _physicsBody; ///< the physicsBody the node have PhysicsBody* _physicsBody; ///< the physicsBody the node have
#endif #endif

View File

@ -34,7 +34,7 @@ THE SOFTWARE.
NS_CC_BEGIN NS_CC_BEGIN
Scene::Scene() Scene::Scene()
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
: _physicsWorld(nullptr) : _physicsWorld(nullptr)
#endif #endif
{ {
@ -44,7 +44,7 @@ Scene::Scene()
Scene::~Scene() Scene::~Scene()
{ {
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
CC_SAFE_DELETE(_physicsWorld); CC_SAFE_DELETE(_physicsWorld);
#endif #endif
} }
@ -88,7 +88,22 @@ Scene* Scene::getScene()
return this; return this;
} }
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
void Scene::addChild(Node* child, int zOrder, int tag)
{
Node::addChild(child, zOrder, tag);
addChildToPhysicsWorld(child);
}
void Scene::update(float delta)
{
Node::update(delta);
if (nullptr != _physicsWorld)
{
_physicsWorld->update(delta);
}
}
Scene *Scene::createWithPhysics() Scene *Scene::createWithPhysics()
{ {
Scene *ret = new Scene(); Scene *ret = new Scene();
@ -121,13 +136,6 @@ bool Scene::initWithPhysics()
return ret; return ret;
} }
void Scene::addChild(Node* child, int zOrder, int tag)
{
Node::addChild(child, zOrder, tag);
addChildToPhysicsWorld(child);
}
void Scene::addChildToPhysicsWorld(Node* child) void Scene::addChildToPhysicsWorld(Node* child)
{ {
if (_physicsWorld) if (_physicsWorld)
@ -149,18 +157,6 @@ void Scene::addChildToPhysicsWorld(Node* child)
addToPhysicsWorldFunc(child); addToPhysicsWorldFunc(child);
} }
} }
void Scene::update(float delta)
{
Node::update(delta);
if (nullptr != _physicsWorld)
{
_physicsWorld->update(delta);
}
}
#endif #endif
NS_CC_END NS_CC_END

View File

@ -52,42 +52,36 @@ class CC_DLL Scene : public Node
public: public:
/** creates a new Scene object */ /** creates a new Scene object */
static Scene *create(); static Scene *create();
#ifdef CC_USE_PHYSICS
static Scene *createWithPhysics();
#endif
// Overrides // Overrides
virtual Scene *getScene() override; virtual Scene *getScene() override;
#ifdef CC_USE_PHYSICS
public:
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
using Node::addChild; 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; 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:
virtual void addChild(Node* child, int zOrder, int tag) override;
virtual void update(float delta) override;
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
static Scene *createWithPhysics();
protected: protected:
bool initWithPhysics(); bool initWithPhysics();
void addChildToPhysicsWorld(Node* child); void addChildToPhysicsWorld(Node* child);
PhysicsWorld* _physicsWorld; PhysicsWorld* _physicsWorld;
#endif // CC_USE_PHYSICS #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 // end of scene group

View File

@ -502,7 +502,7 @@ void Sprite::updateTransform(void)
{ {
CCASSERT(_batchNode, "updateTransform is only valid when Sprite is being rendered using an SpriteBatchNode"); CCASSERT(_batchNode, "updateTransform is only valid when Sprite is being rendered using an SpriteBatchNode");
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
if (updatePhysicsTransform()) if (updatePhysicsTransform())
{ {
setDirty(true); setDirty(true);
@ -711,7 +711,7 @@ bool Sprite::culling() const
void Sprite::updateQuadVertices() void Sprite::updateQuadVertices()
{ {
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
updatePhysicsTransform(); updatePhysicsTransform();
setDirty(true); setDirty(true);
#endif #endif

View File

@ -268,7 +268,7 @@ To enable set it to a value different than 0. Disabled by default.
/** Use physics integration API */ /** Use physics integration API */
#ifndef CC_USE_PHYSICS #ifndef CC_USE_PHYSICS
#define CC_USE_PHYSICS #define CC_USE_PHYSICS 1
#endif #endif
#endif // __CCCONFIG_H__ #endif // __CCCONFIG_H__

View File

@ -22,7 +22,7 @@
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsBody.h" #include "CCPhysicsBody.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include <climits> #include <climits>
#include <algorithm> #include <algorithm>

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_BODY_H__ #define __CCPHYSICS_BODY_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "CCObject.h" #include "CCObject.h"
#include "CCGeometry.h" #include "CCGeometry.h"

View File

@ -22,7 +22,7 @@
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsContact.h" #include "CCPhysicsContact.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "chipmunk.h" #include "chipmunk.h"
#include "CCPhysicsBody.h" #include "CCPhysicsBody.h"

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_CONTACT_H__ #define __CCPHYSICS_CONTACT_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "CCObject.h" #include "CCObject.h"
#include "CCGeometry.h" #include "CCGeometry.h"

View File

@ -23,7 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsJoint.h" #include "CCPhysicsJoint.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "chipmunk.h" #include "chipmunk.h"
#include "CCPhysicsBody.h" #include "CCPhysicsBody.h"

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_JOINT_H__ #define __CCPHYSICS_JOINT_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "CCObject.h" #include "CCObject.h"
#include "CCGeometry.h" #include "CCGeometry.h"

View File

@ -23,7 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsShape.h" #include "CCPhysicsShape.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include <climits> #include <climits>

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_SHAPE_H__ #define __CCPHYSICS_SHAPE_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "CCObject.h" #include "CCObject.h"
#include "CCGeometry.h" #include "CCGeometry.h"

View File

@ -23,7 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsWorld.h" #include "CCPhysicsWorld.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include <climits> #include <climits>

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_WORLD_H__ #define __CCPHYSICS_WORLD_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "CCVector.h" #include "CCVector.h"
#include "CCObject.h" #include "CCObject.h"

View File

@ -23,7 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsBodyInfo_chipmunk.h" #include "CCPhysicsBodyInfo_chipmunk.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
NS_CC_BEGIN NS_CC_BEGIN
PhysicsBodyInfo::PhysicsBodyInfo() PhysicsBodyInfo::PhysicsBodyInfo()

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_BODY_INFO_CHIPMUNK_H__ #define __CCPHYSICS_BODY_INFO_CHIPMUNK_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "chipmunk.h" #include "chipmunk.h"
#include "CCPlatformMacros.h" #include "CCPlatformMacros.h"

View File

@ -23,7 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsContactInfo_chipmunk.h" #include "CCPhysicsContactInfo_chipmunk.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
NS_CC_BEGIN NS_CC_BEGIN
PhysicsContactInfo::PhysicsContactInfo(PhysicsContact* contact) PhysicsContactInfo::PhysicsContactInfo(PhysicsContact* contact)

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_CONTACT_INFO_CHIPMUNK_H__ #define __CCPHYSICS_CONTACT_INFO_CHIPMUNK_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "chipmunk.h" #include "chipmunk.h"
#include "CCPlatformMacros.h" #include "CCPlatformMacros.h"

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_HELPER_CHIPMUNK_H__ #define __CCPHYSICS_HELPER_CHIPMUNK_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "chipmunk.h" #include "chipmunk.h"
#include "CCPlatformMacros.h" #include "CCPlatformMacros.h"

View File

@ -23,7 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsJointInfo_chipmunk.h" #include "CCPhysicsJointInfo_chipmunk.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include <algorithm> #include <algorithm>
#include <unordered_map> #include <unordered_map>

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_JOINT_INFO_CHIPMUNK_H__ #define __CCPHYSICS_JOINT_INFO_CHIPMUNK_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "chipmunk.h" #include "chipmunk.h"
#include "CCPlatformMacros.h" #include "CCPlatformMacros.h"

View File

@ -23,7 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsShapeInfo_chipmunk.h" #include "CCPhysicsShapeInfo_chipmunk.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include <algorithm> #include <algorithm>
#include <unordered_map> #include <unordered_map>

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__ #define __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include <vector> #include <vector>
#include <unordered_map> #include <unordered_map>

View File

@ -23,7 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include "CCPhysicsWorldInfo_chipmunk.h" #include "CCPhysicsWorldInfo_chipmunk.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "CCPhysicsHelper_chipmunk.h" #include "CCPhysicsHelper_chipmunk.h"
#include "CCPhysicsBodyInfo_chipmunk.h" #include "CCPhysicsBodyInfo_chipmunk.h"
#include "CCPhysicsShapeInfo_chipmunk.h" #include "CCPhysicsShapeInfo_chipmunk.h"

View File

@ -26,7 +26,7 @@
#define __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__ #define __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__
#include "ccConfig.h" #include "ccConfig.h"
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
#include <vector> #include <vector>
#include "chipmunk.h" #include "chipmunk.h"

View File

@ -6,7 +6,7 @@ USING_NS_CC;
namespace namespace
{ {
static std::function<Layer*()> createFunctions[] = { static std::function<Layer*()> createFunctions[] = {
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
CL(PhysicsDemoLogoSmash), CL(PhysicsDemoLogoSmash),
CL(PhysicsDemoPyramidStack), CL(PhysicsDemoPyramidStack),
CL(PhysicsDemoClickAdd), CL(PhysicsDemoClickAdd),
@ -55,7 +55,7 @@ namespace
} }
PhysicsTestScene::PhysicsTestScene() PhysicsTestScene::PhysicsTestScene()
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
: TestScene(false, true) : TestScene(false, true)
#else #else
: TestScene() : TestScene()
@ -73,13 +73,13 @@ void PhysicsTestScene::runThisTest()
void PhysicsTestScene::toggleDebug() void PhysicsTestScene::toggleDebug()
{ {
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
_debugDraw = !_debugDraw; _debugDraw = !_debugDraw;
getPhysicsWorld()->setDebugDrawMask(_debugDraw ? PhysicsWorld::DEBUGDRAW_ALL : PhysicsWorld::DEBUGDRAW_NONE); getPhysicsWorld()->setDebugDrawMask(_debugDraw ? PhysicsWorld::DEBUGDRAW_ALL : PhysicsWorld::DEBUGDRAW_NONE);
#endif #endif
} }
#ifndef CC_USE_PHYSICS #if CC_USE_PHYSICS == 0
void PhysicsDemoDisabled::onEnter() void PhysicsDemoDisabled::onEnter()
{ {
auto label = LabelTTF::create("Should define CC_USE_PHYSICS\n to run this test case", auto label = LabelTTF::create("Should define CC_USE_PHYSICS\n to run this test case",

View File

@ -22,7 +22,7 @@ private:
bool _debugDraw; bool _debugDraw;
}; };
#ifndef CC_USE_PHYSICS #if CC_USE_PHYSICS == 0
class PhysicsDemoDisabled : public BaseTest class PhysicsDemoDisabled : public BaseTest
{ {
public: public:

View File

@ -7,7 +7,7 @@ TestScene::TestScene(bool bPortrait, bool physics/* = false*/)
{ {
if (physics) if (physics)
{ {
#ifdef CC_USE_PHYSICS #if CC_USE_PHYSICS
TestScene::initWithPhysics(); TestScene::initWithPhysics();
#else #else
Scene::init(); Scene::init();