mirror of https://github.com/axmolengine/axmol.git
fixed #3517, make CC_USE_PHYSICS can be switch off, and bring Scene::update(float), Scene::addChild(...) out of CC_USE_PHYSICS segment
This commit is contained in:
parent
fbdcefadfa
commit
c5e95618d9
|
@ -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<Scene*>(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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -52,32 +52,15 @@ 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:
|
||||
bool initWithPhysics();
|
||||
void addChildToPhysicsWorld(Node* child);
|
||||
|
||||
PhysicsWorld* _physicsWorld;
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
Scene();
|
||||
virtual ~Scene();
|
||||
|
@ -88,6 +71,17 @@ protected:
|
|||
|
||||
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
|
||||
};
|
||||
|
||||
// end of scene group
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "CCPhysicsBody.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
|
||||
#include <climits>
|
||||
#include <algorithm>
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "CCPhysicsContact.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
#include "chipmunk.h"
|
||||
|
||||
#include "CCPhysicsBody.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"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsJoint.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
#include "chipmunk.h"
|
||||
|
||||
#include "CCPhysicsBody.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"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsShape.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
|
||||
#include <climits>
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsWorld.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
|
||||
#include <climits>
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsBodyInfo_chipmunk.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsBodyInfo::PhysicsBodyInfo()
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsContactInfo_chipmunk.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsContactInfo::PhysicsContactInfo(PhysicsContact* contact)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsJointInfo_chipmunk.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsShapeInfo_chipmunk.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__
|
||||
|
||||
#include "ccConfig.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__
|
||||
|
||||
#include "ccConfig.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
|
||||
#include <vector>
|
||||
#include "chipmunk.h"
|
||||
|
|
|
@ -6,7 +6,7 @@ USING_NS_CC;
|
|||
namespace
|
||||
{
|
||||
static std::function<Layer*()> 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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue