From 1d47737f45eea16fee774e6f990b0e14d5ae0963 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 9 Sep 2013 10:29:02 +0800 Subject: [PATCH 01/34] issue #2771: add physics files and entries. --- .../project.pbxproj.REMOVED.git-id | 2 +- cocos2dx/base_nodes/CCNode.cpp | 22 ++++ cocos2dx/base_nodes/CCNode.h | 35 ++++++ .../CCScene.cpp | 19 ++- .../layers_scenes_transitions_nodes/CCScene.h | 14 ++- cocos2dx/physics/CCPhysicsBody.cpp | 24 ++++ cocos2dx/physics/CCPhysicsBody.h | 100 +++++++++++++++ cocos2dx/physics/CCPhysicsContactDelegate.cpp | 23 ++++ cocos2dx/physics/CCPhysicsContactDelegate.h | 48 ++++++++ cocos2dx/physics/CCPhysicsFixture.cpp | 23 ++++ cocos2dx/physics/CCPhysicsFixture.h | 59 +++++++++ cocos2dx/physics/CCPhysicsJoint.cpp | 23 ++++ cocos2dx/physics/CCPhysicsJoint.h | 114 ++++++++++++++++++ cocos2dx/physics/CCPhysicsSetting.h | 40 ++++++ cocos2dx/physics/CCPhysicsWorld.cpp | 93 ++++++++++++++ cocos2dx/physics/CCPhysicsWorld.h | 72 +++++++++++ .../ArmatureTest/ArmatureScene.cpp | 6 +- 17 files changed, 710 insertions(+), 7 deletions(-) create mode 100644 cocos2dx/physics/CCPhysicsBody.cpp create mode 100644 cocos2dx/physics/CCPhysicsBody.h create mode 100644 cocos2dx/physics/CCPhysicsContactDelegate.cpp create mode 100644 cocos2dx/physics/CCPhysicsContactDelegate.h create mode 100644 cocos2dx/physics/CCPhysicsFixture.cpp create mode 100644 cocos2dx/physics/CCPhysicsFixture.h create mode 100644 cocos2dx/physics/CCPhysicsJoint.cpp create mode 100644 cocos2dx/physics/CCPhysicsJoint.h create mode 100644 cocos2dx/physics/CCPhysicsSetting.h create mode 100644 cocos2dx/physics/CCPhysicsWorld.cpp create mode 100644 cocos2dx/physics/CCPhysicsWorld.h diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index ff4b7a32dd..1eaf467207 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -fd0dee451420604712c1327679395cd1faca91b6 \ No newline at end of file +cbb5290ea17f6020e0249818c08c9d94a17dd073 \ No newline at end of file diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index ef111dfbce..bc8aa7c95f 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -120,6 +120,7 @@ Node::Node(void) , _isTransitionFinished(false) , _updateScriptHandler(0) , _componentContainer(NULL) +, _scene(nullptr) { // set default scheduler and actionManager Director *director = Director::getInstance(); @@ -588,6 +589,7 @@ void Node::addChild(Node *child, int zOrder, int tag) child->_tag = tag; child->setParent(this); + child->setScene(_scene); child->setOrderOfArrival(s_globalOrderOfArrival++); if( _running ) @@ -1271,6 +1273,26 @@ void Node::removeAllComponents() _componentContainer->removeAll(); } +void Node::setScene(Scene* scene) +{ + _scene = scene; +} + +Scene* Node::getScene() +{ + return _scene; +} + +void Node::setPhysicsBody(PhysicsBody* body) +{ + _physicsBody = body; +} + +PhysicsBody* Node::getPhysicsBody() +{ + return _physicsBody; +} + // NodeRGBA NodeRGBA::NodeRGBA() : _displayedOpacity(255) diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index 60c9f0ee11..389218453a 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -52,6 +52,8 @@ class ActionManager; class Component; class Dictionary; class ComponentContainer; +class Scene; +class PhysicsBody; /** * @addtogroup base_nodes @@ -1300,6 +1302,35 @@ public: */ virtual void removeAllComponents(); /// @} end of component functions + + /// @{ + /// @name scene functions + + /** + * set the scene the node belongs to + * DO NOT call it manually + */ + virtual void setScene(Scene* scene); + + /** + * get the scene the node belongs to + */ + virtual Scene* getScene(); + /// @} end of scene functions + + /// @{ + /// @name physics functions + + /** + * set the PhysicsBody that let the node effect with physics + */ + virtual void setPhysicsBody(PhysicsBody* body); + + /** + * get the PhysicsBody the node have + */ + PhysicsBody* getPhysicsBody(); + /// @} end of physics functions protected: /// lazy allocs @@ -1378,6 +1409,9 @@ protected: ccScriptType _scriptType; ///< type of script binding, lua or javascript ComponentContainer *_componentContainer; ///< Dictionary of components + + Scene* _scene; ///< the scene the node belongs to + PhysicsBody* _physicsBody; ///< the physicsBody the node have }; @@ -1425,6 +1459,7 @@ protected: Color3B _realColor; bool _cascadeColorEnabled; bool _cascadeOpacityEnabled; + }; // end of base_node group diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp index 4a144f9b80..3c3e2faf1a 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp @@ -53,7 +53,7 @@ bool Scene::init() return bRet; } -Scene *Scene::create() +Scene *Scene::create(bool usePhysics/* = false*/) { Scene *pRet = new Scene(); if (pRet && pRet->init()) @@ -68,4 +68,21 @@ Scene *Scene::create() } } +void Scene::addChild(Node* child) +{ + Node::addChild(child); +} + +void Scene::addChild(Node* child, int zOrder) +{ + Node::addChild(child, zOrder); +} + +void Scene::addChild(Node* child, int zOrder, int tag) +{ + Node::addChild(child, zOrder, tag); + child->setScene(this); +} + + NS_CC_END diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.h b/cocos2dx/layers_scenes_transitions_nodes/CCScene.h index 2cd710773e..c084852513 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.h +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.h @@ -31,6 +31,8 @@ THE SOFTWARE. NS_CC_BEGIN +class PhysicsWorld; + /** * @addtogroup scene * @{ @@ -50,13 +52,21 @@ class CC_DLL Scene : public Node { public: /** creates a new Scene object */ - static Scene *create(void); + static Scene *create(bool usePhysics = false); Scene(); virtual ~Scene(); bool init(); - + + virtual void addChild(Node* child) override; + virtual void addChild(Node* child, int zOrder) override; + virtual void addChild(Node* child, int zOrder, int tag) override; + + inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; } + +protected: + PhysicsWorld* _physicsWorld; }; // end of scene group diff --git a/cocos2dx/physics/CCPhysicsBody.cpp b/cocos2dx/physics/CCPhysicsBody.cpp new file mode 100644 index 0000000000..e4b81264af --- /dev/null +++ b/cocos2dx/physics/CCPhysicsBody.cpp @@ -0,0 +1,24 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#include "CCPhysicsBody.h" \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsBody.h b/cocos2dx/physics/CCPhysicsBody.h new file mode 100644 index 0000000000..682c6d7e03 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsBody.h @@ -0,0 +1,100 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __CCPHYSICS_BODY_H__ +#define __CCPHYSICS_BODY_H__ + +#include "CCObject.h" +#include "CCGeometry.h" +#include "CCPhysicsSetting.h" + +NS_CC_BEGIN +class Node; +class PhysicsWorld; +class PhysicsFixture; + +class PhysicsBody : public Object +{ +public: + static PhysicsBody* createCircle(Point centre, float radius); + static PhysicsBody* createRectangle(Rect rect); + static PhysicsBody* createPolygon(Array* points); + + static PhysicsBody* createEdgeSegment(Point x, Point y); + static PhysicsBody* createEdgeCircle(Point centre, float radius); + static PhysicsBody* createEdgeRectangle(Rect rect); + static PhysicsBody* createEdgePolygon(Array* points); + static PhysicsBody* createEdgeChain(Array* points); + + virtual void applyForce(Point force); + virtual void applyForce(Point force, Point point); + virtual void applyImpulse(Point impulse); + virtual void applyImpulse(Point impulse, Point point); + virtual void applyTorque(float torque); + virtual void applyAngularImpulse(float impulse); + + void addFixture(PhysicsFixture* fixture); + inline Array* getFixtures() { return _fixtures; } + void removeFixture(PhysicsFixture* fixture); + void removeAllFixtures(); + + inline PhysicsWorld* getWorld() { return _physicsWorld; } + inline Array* getJoints() { return _joints; } + + void setCategoryBitmask(int bitmask); + inline int getCategoryBitmask() { return _categoryBitmask; } + void setContactTestBitmask(int bitmask); + inline int getContactTestBitmask() { return _contactTestBitmask; } + void setCollisionBitmask(int bitmask); + inline int getCollisionBitmask() { return _collisionBitmask; } + +protected: + bool init(); + +protected: + PhysicsBody(); + virtual ~PhysicsBody(); + +private: + float _mass; + float _density; + float _area; + float _friction; + Node* _node; + Point _velocity; + float _angularVelocity; + bool _resting; + + int _categoryBitmask; + int _contactTestBitmask; + int _collisionBitmask; + + Array* _joints; + Array* _fixtures; + PhysicsWorld* _physicsWorld; +}; + +NS_CC_END + +#endif // __CCPHYSICS_BODY_H__ \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsContactDelegate.cpp b/cocos2dx/physics/CCPhysicsContactDelegate.cpp new file mode 100644 index 0000000000..3dba18f438 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsContactDelegate.cpp @@ -0,0 +1,23 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsContactDelegate.h b/cocos2dx/physics/CCPhysicsContactDelegate.h new file mode 100644 index 0000000000..0e5f137ef8 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsContactDelegate.h @@ -0,0 +1,48 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __CCPHYSICS_CONTACTDELEGATE_H__ +#define __CCPHYSICS_CONTACTDELEGATE_H__ + +#include "CCObject.h" +#include "CCGeometry.h" +#include "CCPhysicsSetting.h" + +NS_CC_BEGIN + +class PhysicsBody; + +class PhysicsContactDelegate : public Object +{ +public: + virtual void onContactBegin(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint); + virtual void onContactEnd(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint); + +protected: + PhysicsContactDelegate(); + virtual ~PhysicsContactDelegate(); +}; + +NS_CC_END +#endif //__CCPHYSICS_CONTACTDELEGATE_H__ \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsFixture.cpp b/cocos2dx/physics/CCPhysicsFixture.cpp new file mode 100644 index 0000000000..3dba18f438 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsFixture.cpp @@ -0,0 +1,23 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsFixture.h b/cocos2dx/physics/CCPhysicsFixture.h new file mode 100644 index 0000000000..40b914cc38 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsFixture.h @@ -0,0 +1,59 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __CCPHYSICS_FIXTURE_H__ +#define __CCPHYSICS_FIXTURE_H__ + +#include "CCObject.h" +#include "CCGeometry.h" +#include "CCPhysicsSetting.h" + +NS_CC_BEGIN + +class PhysicsFixture : public Object +{ +public: + static PhysicsFixture* createCircle(Point centre, float radius); + static PhysicsFixture* createRectangle(Rect rect); + static PhysicsFixture* createPolygon(Array* points); + + static PhysicsFixture* createEdgeSegment(Point x, Point y); + static PhysicsFixture* createEdgeCircle(Point centre, float radius); + static PhysicsFixture* createEdgeRectangle(Rect rect); + static PhysicsFixture* createEdgePolygon(Array* points); + +protected: + bool init(); + +protected: + PhysicsFixture(); + virtual ~PhysicsFixture(); + +protected: + float _density; + float _friction; +}; + +NS_CC_END +#endif // __CCPHYSICS_FIXTURE_H__ \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsJoint.cpp b/cocos2dx/physics/CCPhysicsJoint.cpp new file mode 100644 index 0000000000..3dba18f438 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsJoint.cpp @@ -0,0 +1,23 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsJoint.h b/cocos2dx/physics/CCPhysicsJoint.h new file mode 100644 index 0000000000..5258e1d2d5 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsJoint.h @@ -0,0 +1,114 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __CCPHYSICS_JOINT_H__ +#define __CCPHYSICS_JOINT_H__ + +#include "CCObject.h" +#include "CCGeometry.h" +#include "CCPhysicsSetting.h" + +NS_CC_BEGIN + +class PhysicsBody; + +class PhysicsJoint : public Object +{ +protected: + PhysicsJoint(); + virtual ~PhysicsJoint(); + +private: + PhysicsBody* _bodyA; + PhysicsBody* _bodyB; +}; + +class PhysicsJointFixed : public PhysicsJoint +{ +public: + PhysicsJointFixed* create(); + +protected: + bool init(); + +protected: + PhysicsJointFixed(); + ~PhysicsJointFixed(); +}; + +class PhysicsJointSliding : public PhysicsJoint +{ +public: + PhysicsJointSliding* create(); + +protected: + bool init(); + +protected: + PhysicsJointSliding(); + ~PhysicsJointSliding(); +}; + +class PhysicsJointSpring : public PhysicsJoint +{ +public: + PhysicsJointSpring* create(); + +protected: + bool init(); + +protected: + PhysicsJointSpring(); + ~PhysicsJointSpring(); +}; + +class PhysicsJointLimit : public PhysicsJoint +{ +public: + PhysicsJointLimit* create(); + +protected: + bool init(); + +protected: + PhysicsJointLimit(); + ~PhysicsJointLimit(); +}; + +class PhysicsJointPin : public PhysicsJoint +{ +public: + PhysicsJointPin* create(); + +protected: + bool init(); + +protected: + PhysicsJointPin(); + ~PhysicsJointPin(); +}; + +NS_CC_END + +#endif // __CCPHYSICS_JOINT_H__ \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsSetting.h b/cocos2dx/physics/CCPhysicsSetting.h new file mode 100644 index 0000000000..8bcc65e7b2 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsSetting.h @@ -0,0 +1,40 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __CCPHYSICS_SETTING_H__ +#define __CCPHYSICS_SETTING_H__ + +#define CC_PHYSICS_UNKNOWN 0 +#define CC_PHYSICS_BOX2D 1 +#define CC_PHYSICS_CHIPMUNK 2 + +#define CC_PHYSICS_ENGINE CC_PHYSICS_CHIPMUNK + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) +#include "Box2D.h" +#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +#include "chipmunk.h" +#endif + +#endif // __CCPHYSICS_SETTING_H__ \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsWorld.cpp b/cocos2dx/physics/CCPhysicsWorld.cpp new file mode 100644 index 0000000000..8f19b94cc6 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsWorld.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsWorld.h" + +NS_CC_BEGIN + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + +class PhysicsWorldInfo +{ +public: + cpSpace* space; + +public: + PhysicsWorldInfo(); + ~PhysicsWorldInfo(); +}; + +PhysicsWorldInfo::PhysicsWorldInfo() +{ + space = cpSpaceNew(); +} + +PhysicsWorldInfo::~PhysicsWorldInfo() +{ + cpSpaceFree(space); +} + +bool PhysicsWorld::init() +{ + _worldInfo = new PhysicsWorldInfo(); + + cpSpaceSetGravity(_worldInfo->space, cpv(_gravity.x, _gravity.y)); + + return true; +} + +#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) + +struct PhysicsInfo +{ + +}; +#endif + +PhysicsWorld* PhysicsWorld::create() +{ + PhysicsWorld * physicsWorld = new PhysicsWorld(); + if(physicsWorld && physicsWorld->init()) + { + physicsWorld->autorelease(); + return physicsWorld; + } + + CC_SAFE_DELETE(physicsWorld); + return NULL; +} + +PhysicsWorld::PhysicsWorld() : +_gravity(Point(0, -9.8)), +_speed(1.0) +{ + +} + +PhysicsWorld::~PhysicsWorld() +{ + CC_SAFE_DELETE(_worldInfo); +} + +NS_CC_END \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h new file mode 100644 index 0000000000..cf5babaf0e --- /dev/null +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -0,0 +1,72 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __CCPHYSICS_WORLD_H__ +#define __CCPHYSICS_WORLD_H__ + +#include "CCObject.h" +#include "CCGeometry.h" +#include "CCPhysicsSetting.h" + +NS_CC_BEGIN + +class PhysicsBody; +class PhysicsJoint; +class PhysicsWorldInfo; +class PhysicsContactDelegate; + +class PhysicsWorld : public Object +{ +public: + static PhysicsWorld* create(); + void addChild(PhysicsBody* body); + + void addJoint(PhysicsJoint* joint); + void removeJoint(PhysicsJoint* joint); + void removeAllJoints(); + + Array* bodysAlongRay(Point start, Point end); + Array* bodysAtPoint(Point point); + Array* bodysInRect(Rect rect); + Array* getAllBody(); + + void registerContactDelegate(PhysicsContactDelegate* delegate); + +protected: + bool init(); + +protected: + Point _gravity; + float _speed; + + class PhysicsWorldInfo* _worldInfo; + +protected: + PhysicsWorld(); + virtual ~PhysicsWorld(); +}; + +NS_CC_END + +#endif // __CCPHYSICS_WORLD_H__ \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp index d70d0a7e5d..d09a11254f 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp @@ -531,7 +531,7 @@ void TestBox2DDetector::onEnter() armature2->setPosition(Point(VisibleRect::right().x - 30, VisibleRect::left().y)); addChild(armature2); - PhysicsWorld::sharedPhysicsWorld()->BoneColliderSignal.connect(this, &TestBox2DDetector::onHit); + extension::armature::PhysicsWorld::sharedPhysicsWorld()->BoneColliderSignal.connect(this, &TestBox2DDetector::onHit); } std::string TestBox2DDetector::title() { @@ -543,7 +543,7 @@ void TestBox2DDetector::draw() kmGLPushMatrix(); - PhysicsWorld::sharedPhysicsWorld()->drawDebug(); + extension::armature::PhysicsWorld::sharedPhysicsWorld()->drawDebug(); kmGLPopMatrix(); @@ -551,7 +551,7 @@ void TestBox2DDetector::draw() void TestBox2DDetector::update(float delta) { armature2->setVisible(true); - PhysicsWorld::sharedPhysicsWorld()->update(delta); + extension::armature::PhysicsWorld::sharedPhysicsWorld()->update(delta); } void TestBox2DDetector::onHit(Bone *bone, Bone *bone2) { From a6f9533a94d7f56cd5bbcf567bcf788eade465cb Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 9 Sep 2013 10:34:03 +0800 Subject: [PATCH 02/34] issue #2771: add Node::_physicsBody to Node init list --- cocos2dx/base_nodes/CCNode.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index bc8aa7c95f..b6ab5fa20e 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -121,6 +121,7 @@ Node::Node(void) , _updateScriptHandler(0) , _componentContainer(NULL) , _scene(nullptr) +, _physicsBody(nullptr) { // set default scheduler and actionManager Director *director = Director::getInstance(); From dce205f6884c49869cc826d861e13192262100b3 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 9 Sep 2013 10:40:31 +0800 Subject: [PATCH 03/34] issue #2771: add new line to the end of line. --- cocos2dx/physics/CCPhysicsBody.cpp | 2 +- cocos2dx/physics/CCPhysicsBody.h | 2 +- cocos2dx/physics/CCPhysicsContactDelegate.cpp | 2 +- cocos2dx/physics/CCPhysicsFixture.cpp | 2 +- cocos2dx/physics/CCPhysicsFixture.h | 2 +- cocos2dx/physics/CCPhysicsJoint.cpp | 2 +- cocos2dx/physics/CCPhysicsJoint.h | 2 +- cocos2dx/physics/CCPhysicsSetting.h | 2 +- cocos2dx/physics/CCPhysicsWorld.cpp | 2 +- cocos2dx/physics/CCPhysicsWorld.h | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cocos2dx/physics/CCPhysicsBody.cpp b/cocos2dx/physics/CCPhysicsBody.cpp index e4b81264af..eb7296843e 100644 --- a/cocos2dx/physics/CCPhysicsBody.cpp +++ b/cocos2dx/physics/CCPhysicsBody.cpp @@ -21,4 +21,4 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "CCPhysicsBody.h" \ No newline at end of file +#include "CCPhysicsBody.h" diff --git a/cocos2dx/physics/CCPhysicsBody.h b/cocos2dx/physics/CCPhysicsBody.h index 682c6d7e03..f880a7d36f 100644 --- a/cocos2dx/physics/CCPhysicsBody.h +++ b/cocos2dx/physics/CCPhysicsBody.h @@ -97,4 +97,4 @@ private: NS_CC_END -#endif // __CCPHYSICS_BODY_H__ \ No newline at end of file +#endif // __CCPHYSICS_BODY_H__ diff --git a/cocos2dx/physics/CCPhysicsContactDelegate.cpp b/cocos2dx/physics/CCPhysicsContactDelegate.cpp index 3dba18f438..39b3eedbc5 100644 --- a/cocos2dx/physics/CCPhysicsContactDelegate.cpp +++ b/cocos2dx/physics/CCPhysicsContactDelegate.cpp @@ -20,4 +20,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ****************************************************************************/ \ No newline at end of file + ****************************************************************************/ diff --git a/cocos2dx/physics/CCPhysicsFixture.cpp b/cocos2dx/physics/CCPhysicsFixture.cpp index 3dba18f438..39b3eedbc5 100644 --- a/cocos2dx/physics/CCPhysicsFixture.cpp +++ b/cocos2dx/physics/CCPhysicsFixture.cpp @@ -20,4 +20,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ****************************************************************************/ \ No newline at end of file + ****************************************************************************/ diff --git a/cocos2dx/physics/CCPhysicsFixture.h b/cocos2dx/physics/CCPhysicsFixture.h index 40b914cc38..4753304ea2 100644 --- a/cocos2dx/physics/CCPhysicsFixture.h +++ b/cocos2dx/physics/CCPhysicsFixture.h @@ -56,4 +56,4 @@ protected: }; NS_CC_END -#endif // __CCPHYSICS_FIXTURE_H__ \ No newline at end of file +#endif // __CCPHYSICS_FIXTURE_H__ diff --git a/cocos2dx/physics/CCPhysicsJoint.cpp b/cocos2dx/physics/CCPhysicsJoint.cpp index 3dba18f438..39b3eedbc5 100644 --- a/cocos2dx/physics/CCPhysicsJoint.cpp +++ b/cocos2dx/physics/CCPhysicsJoint.cpp @@ -20,4 +20,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ****************************************************************************/ \ No newline at end of file + ****************************************************************************/ diff --git a/cocos2dx/physics/CCPhysicsJoint.h b/cocos2dx/physics/CCPhysicsJoint.h index 5258e1d2d5..8e687d8ab9 100644 --- a/cocos2dx/physics/CCPhysicsJoint.h +++ b/cocos2dx/physics/CCPhysicsJoint.h @@ -111,4 +111,4 @@ protected: NS_CC_END -#endif // __CCPHYSICS_JOINT_H__ \ No newline at end of file +#endif // __CCPHYSICS_JOINT_H__ diff --git a/cocos2dx/physics/CCPhysicsSetting.h b/cocos2dx/physics/CCPhysicsSetting.h index 8bcc65e7b2..745c93b77b 100644 --- a/cocos2dx/physics/CCPhysicsSetting.h +++ b/cocos2dx/physics/CCPhysicsSetting.h @@ -37,4 +37,4 @@ #include "chipmunk.h" #endif -#endif // __CCPHYSICS_SETTING_H__ \ No newline at end of file +#endif // __CCPHYSICS_SETTING_H__ diff --git a/cocos2dx/physics/CCPhysicsWorld.cpp b/cocos2dx/physics/CCPhysicsWorld.cpp index 8f19b94cc6..e53958286b 100644 --- a/cocos2dx/physics/CCPhysicsWorld.cpp +++ b/cocos2dx/physics/CCPhysicsWorld.cpp @@ -90,4 +90,4 @@ PhysicsWorld::~PhysicsWorld() CC_SAFE_DELETE(_worldInfo); } -NS_CC_END \ No newline at end of file +NS_CC_END diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index cf5babaf0e..82981dcd7e 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -69,4 +69,4 @@ protected: NS_CC_END -#endif // __CCPHYSICS_WORLD_H__ \ No newline at end of file +#endif // __CCPHYSICS_WORLD_H__ From cb08f2baf2026662a05e8458de526e2e1b1ad87f Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 9 Sep 2013 16:36:19 +0800 Subject: [PATCH 04/34] issue #2771: Change _physicsBody from node to sprite. Reimplement Scene::addChild. Adjust some API. --- cocos2dx/base_nodes/CCNode.cpp | 23 ------------- cocos2dx/base_nodes/CCNode.h | 33 ------------------- .../CCScene.cpp | 29 +++++++++++++++- cocos2dx/physics/CCPhysicsBody.h | 26 +++++++++------ cocos2dx/physics/CCPhysicsContactDelegate.h | 10 +++--- cocos2dx/physics/CCPhysicsJoint.h | 2 +- cocos2dx/physics/CCPhysicsWorld.cpp | 1 - cocos2dx/physics/CCPhysicsWorld.h | 24 +++++++++----- cocos2dx/sprite_nodes/CCSprite.cpp | 13 +++++++- cocos2dx/sprite_nodes/CCSprite.h | 12 +++++++ 10 files changed, 89 insertions(+), 84 deletions(-) diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index b6ab5fa20e..ef111dfbce 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -120,8 +120,6 @@ Node::Node(void) , _isTransitionFinished(false) , _updateScriptHandler(0) , _componentContainer(NULL) -, _scene(nullptr) -, _physicsBody(nullptr) { // set default scheduler and actionManager Director *director = Director::getInstance(); @@ -590,7 +588,6 @@ void Node::addChild(Node *child, int zOrder, int tag) child->_tag = tag; child->setParent(this); - child->setScene(_scene); child->setOrderOfArrival(s_globalOrderOfArrival++); if( _running ) @@ -1274,26 +1271,6 @@ void Node::removeAllComponents() _componentContainer->removeAll(); } -void Node::setScene(Scene* scene) -{ - _scene = scene; -} - -Scene* Node::getScene() -{ - return _scene; -} - -void Node::setPhysicsBody(PhysicsBody* body) -{ - _physicsBody = body; -} - -PhysicsBody* Node::getPhysicsBody() -{ - return _physicsBody; -} - // NodeRGBA NodeRGBA::NodeRGBA() : _displayedOpacity(255) diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index 389218453a..d3ea08952d 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -1302,35 +1302,6 @@ public: */ virtual void removeAllComponents(); /// @} end of component functions - - /// @{ - /// @name scene functions - - /** - * set the scene the node belongs to - * DO NOT call it manually - */ - virtual void setScene(Scene* scene); - - /** - * get the scene the node belongs to - */ - virtual Scene* getScene(); - /// @} end of scene functions - - /// @{ - /// @name physics functions - - /** - * set the PhysicsBody that let the node effect with physics - */ - virtual void setPhysicsBody(PhysicsBody* body); - - /** - * get the PhysicsBody the node have - */ - PhysicsBody* getPhysicsBody(); - /// @} end of physics functions protected: /// lazy allocs @@ -1409,10 +1380,6 @@ protected: ccScriptType _scriptType; ///< type of script binding, lua or javascript ComponentContainer *_componentContainer; ///< Dictionary of components - - Scene* _scene; ///< the scene the node belongs to - PhysicsBody* _physicsBody; ///< the physicsBody the node have - }; //#pragma mark - NodeRGBA diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp index 3c3e2faf1a..a2bc6bb4ed 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp @@ -26,6 +26,9 @@ THE SOFTWARE. #include "CCScene.h" #include "CCDirector.h" +#include "CCLayer.h" +#include "sprite_nodes/CCSprite.h" +#include "physics/CCPhysicsWorld.h" NS_CC_BEGIN @@ -81,7 +84,31 @@ void Scene::addChild(Node* child, int zOrder) void Scene::addChild(Node* child, int zOrder, int tag) { Node::addChild(child, zOrder, tag); - child->setScene(this); + + auto addToPhysicsWorldFunc = [this](Object* node) -> void + { + if (typeid(Sprite).hash_code() == typeid(node).hash_code()) + { + Sprite* sp = dynamic_cast(node); + + if (sp && sp->getPhysicsBody()) + { + _physicsWorld->addChild(sp->getPhysicsBody()); + } + } + }; + + if(typeid(Layer).hash_code() == typeid(child).hash_code()) + { + Object* subChild = nullptr; + CCARRAY_FOREACH(child->getChildren(), subChild) + { + addToPhysicsWorldFunc(subChild); + } + }else + { + addToPhysicsWorldFunc(child); + } } diff --git a/cocos2dx/physics/CCPhysicsBody.h b/cocos2dx/physics/CCPhysicsBody.h index f880a7d36f..ee0adeba0e 100644 --- a/cocos2dx/physics/CCPhysicsBody.h +++ b/cocos2dx/physics/CCPhysicsBody.h @@ -28,13 +28,15 @@ #include "CCObject.h" #include "CCGeometry.h" #include "CCPhysicsSetting.h" +#include NS_CC_BEGIN -class Node; +class Sprite; class PhysicsWorld; +class PhysicsJoint; class PhysicsFixture; -class PhysicsBody : public Object +class PhysicsBody : public Object, public Clonable { public: static PhysicsBody* createCircle(Point centre, float radius); @@ -55,19 +57,23 @@ public: virtual void applyAngularImpulse(float impulse); void addFixture(PhysicsFixture* fixture); - inline Array* getFixtures() { return _fixtures; } + inline Array* getFixtures() const { return _fixtures; } void removeFixture(PhysicsFixture* fixture); void removeAllFixtures(); - inline PhysicsWorld* getWorld() { return _physicsWorld; } - inline Array* getJoints() { return _joints; } + inline PhysicsWorld* getWorld() const { return _physicsWorld; } + inline const std::vector* getJoints() const { return &_joints; } + + inline Sprite* getOwner() const { return _owner; } void setCategoryBitmask(int bitmask); - inline int getCategoryBitmask() { return _categoryBitmask; } + inline int getCategoryBitmask() const { return _categoryBitmask; } void setContactTestBitmask(int bitmask); - inline int getContactTestBitmask() { return _contactTestBitmask; } + inline int getContactTestBitmask() const { return _contactTestBitmask; } void setCollisionBitmask(int bitmask); - inline int getCollisionBitmask() { return _collisionBitmask; } + inline int getCollisionBitmask() const { return _collisionBitmask; } + + virtual Clonable* clone() const override; protected: bool init(); @@ -81,7 +87,7 @@ private: float _density; float _area; float _friction; - Node* _node; + Sprite* _owner; Point _velocity; float _angularVelocity; bool _resting; @@ -90,7 +96,7 @@ private: int _contactTestBitmask; int _collisionBitmask; - Array* _joints; + std::vector _joints; Array* _fixtures; PhysicsWorld* _physicsWorld; }; diff --git a/cocos2dx/physics/CCPhysicsContactDelegate.h b/cocos2dx/physics/CCPhysicsContactDelegate.h index 0e5f137ef8..1bead362d7 100644 --- a/cocos2dx/physics/CCPhysicsContactDelegate.h +++ b/cocos2dx/physics/CCPhysicsContactDelegate.h @@ -33,15 +33,15 @@ NS_CC_BEGIN class PhysicsBody; -class PhysicsContactDelegate : public Object +class PhysicsContactDelegate { public: - virtual void onContactBegin(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint); - virtual void onContactEnd(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint); - -protected: PhysicsContactDelegate(); virtual ~PhysicsContactDelegate(); + +public: + virtual void onContactBegin(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint) = 0; + virtual void onContactEnd(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint) = 0; }; NS_CC_END diff --git a/cocos2dx/physics/CCPhysicsJoint.h b/cocos2dx/physics/CCPhysicsJoint.h index 8e687d8ab9..964f718135 100644 --- a/cocos2dx/physics/CCPhysicsJoint.h +++ b/cocos2dx/physics/CCPhysicsJoint.h @@ -33,7 +33,7 @@ NS_CC_BEGIN class PhysicsBody; -class PhysicsJoint : public Object +class PhysicsJoint { protected: PhysicsJoint(); diff --git a/cocos2dx/physics/CCPhysicsWorld.cpp b/cocos2dx/physics/CCPhysicsWorld.cpp index e53958286b..7ca586a2b1 100644 --- a/cocos2dx/physics/CCPhysicsWorld.cpp +++ b/cocos2dx/physics/CCPhysicsWorld.cpp @@ -70,7 +70,6 @@ PhysicsWorld* PhysicsWorld::create() PhysicsWorld * physicsWorld = new PhysicsWorld(); if(physicsWorld && physicsWorld->init()) { - physicsWorld->autorelease(); return physicsWorld; } diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index 82981dcd7e..bd450e49c2 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -29,6 +29,7 @@ #include "CCGeometry.h" #include "CCPhysicsSetting.h" + NS_CC_BEGIN class PhysicsBody; @@ -36,35 +37,40 @@ class PhysicsJoint; class PhysicsWorldInfo; class PhysicsContactDelegate; -class PhysicsWorld : public Object +class Sprite; +class Scene; + +class PhysicsWorld { public: - static PhysicsWorld* create(); - void addChild(PhysicsBody* body); - void addJoint(PhysicsJoint* joint); void removeJoint(PhysicsJoint* joint); void removeAllJoints(); - Array* bodysAlongRay(Point start, Point end); - Array* bodysAtPoint(Point point); - Array* bodysInRect(Rect rect); - Array* getAllBody(); + Array* getBodysAlongRay(Point start, Point end) const; + Array* getBodysAtPoint(Point point) const; + Array* getBodysInRect(Rect rect) const; + Array* getAllBody() const; void registerContactDelegate(PhysicsContactDelegate* delegate); protected: + static PhysicsWorld* create(); bool init(); + virtual void addChild(PhysicsBody* body); protected: Point _gravity; float _speed; - class PhysicsWorldInfo* _worldInfo; + PhysicsWorldInfo* _worldInfo; protected: PhysicsWorld(); virtual ~PhysicsWorld(); + + friend class Sprite; + friend class Scene; }; NS_CC_END diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index 272605d861..ed8f0460c3 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -295,7 +295,8 @@ Sprite* Sprite::initWithCGImage(CGImageRef pImage, const char *pszKey) Sprite::Sprite(void) : _shouldBeHidden(false) -, _texture(NULL) +, _texture(nullptr) +, _physicsBody(nullptr) { } @@ -446,6 +447,16 @@ void Sprite::setTextureCoords(Rect rect) } } +void Sprite::setPhysicsBody(PhysicsBody* body) +{ + _physicsBody = body; +} + +PhysicsBody* Sprite::getPhysicsBody() const +{ + return _physicsBody; +} + void Sprite::updateTransform(void) { CCASSERT(_batchNode, "updateTransform is only valid when Sprite is being rendered using an SpriteBatchNode"); diff --git a/cocos2dx/sprite_nodes/CCSprite.h b/cocos2dx/sprite_nodes/CCSprite.h index 20872e33a9..16162b810b 100644 --- a/cocos2dx/sprite_nodes/CCSprite.h +++ b/cocos2dx/sprite_nodes/CCSprite.h @@ -443,6 +443,16 @@ public: */ void setFlipY(bool bFlipY); + /** + * set the PhysicsBody that let the sprite effect with physics + */ + virtual void setPhysicsBody(PhysicsBody* body); + + /** + * get the PhysicsBody the sprite have + */ + PhysicsBody* getPhysicsBody() const; + /// @} End of Sprite properties getter/setters @@ -539,6 +549,8 @@ protected: // image is flipped bool _flipX; /// Whether the sprite is flipped horizaontally or not. bool _flipY; /// Whether the sprite is flipped vertically or not. + + PhysicsBody* _physicsBody; ///< the physicsBody the node have }; From 6585fd2162638e84328e668fa54c573c0722b920 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 9 Sep 2013 16:58:55 +0800 Subject: [PATCH 05/34] issue #2771: Fix CI compile errors. --- cocos2dx/physics/CCPhysicsBody.h | 4 ++-- cocos2dx/physics/CCPhysicsContactDelegate.h | 4 ++-- cocos2dx/physics/CCPhysicsFixture.h | 4 ++-- cocos2dx/physics/CCPhysicsJoint.h | 4 ++-- cocos2dx/physics/CCPhysicsWorld.h | 4 ++-- cocos2dx/sprite_nodes/CCSprite.cpp | 2 ++ 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cocos2dx/physics/CCPhysicsBody.h b/cocos2dx/physics/CCPhysicsBody.h index ee0adeba0e..04e0fa6acf 100644 --- a/cocos2dx/physics/CCPhysicsBody.h +++ b/cocos2dx/physics/CCPhysicsBody.h @@ -25,8 +25,8 @@ #ifndef __CCPHYSICS_BODY_H__ #define __CCPHYSICS_BODY_H__ -#include "CCObject.h" -#include "CCGeometry.h" +#include "cocoa/CCObject.h" +#include "cocoa/CCGeometry.h" #include "CCPhysicsSetting.h" #include diff --git a/cocos2dx/physics/CCPhysicsContactDelegate.h b/cocos2dx/physics/CCPhysicsContactDelegate.h index 1bead362d7..7c41756ae8 100644 --- a/cocos2dx/physics/CCPhysicsContactDelegate.h +++ b/cocos2dx/physics/CCPhysicsContactDelegate.h @@ -25,8 +25,8 @@ #ifndef __CCPHYSICS_CONTACTDELEGATE_H__ #define __CCPHYSICS_CONTACTDELEGATE_H__ -#include "CCObject.h" -#include "CCGeometry.h" +#include "cocoa/CCObject.h" +#include "cocoa/CCGeometry.h" #include "CCPhysicsSetting.h" NS_CC_BEGIN diff --git a/cocos2dx/physics/CCPhysicsFixture.h b/cocos2dx/physics/CCPhysicsFixture.h index 4753304ea2..76fc367e07 100644 --- a/cocos2dx/physics/CCPhysicsFixture.h +++ b/cocos2dx/physics/CCPhysicsFixture.h @@ -25,8 +25,8 @@ #ifndef __CCPHYSICS_FIXTURE_H__ #define __CCPHYSICS_FIXTURE_H__ -#include "CCObject.h" -#include "CCGeometry.h" +#include "cocoa/CCObject.h" +#include "cocoa/CCGeometry.h" #include "CCPhysicsSetting.h" NS_CC_BEGIN diff --git a/cocos2dx/physics/CCPhysicsJoint.h b/cocos2dx/physics/CCPhysicsJoint.h index 964f718135..5f3aaf011e 100644 --- a/cocos2dx/physics/CCPhysicsJoint.h +++ b/cocos2dx/physics/CCPhysicsJoint.h @@ -25,8 +25,8 @@ #ifndef __CCPHYSICS_JOINT_H__ #define __CCPHYSICS_JOINT_H__ -#include "CCObject.h" -#include "CCGeometry.h" +#include "cocoa/CCObject.h" +#include "cocoa/CCGeometry.h" #include "CCPhysicsSetting.h" NS_CC_BEGIN diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index bd450e49c2..1f092e5ae4 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -25,8 +25,8 @@ #ifndef __CCPHYSICS_WORLD_H__ #define __CCPHYSICS_WORLD_H__ -#include "CCObject.h" -#include "CCGeometry.h" +#include "cocoa/CCObject.h" +#include "cocoa/CCGeometry.h" #include "CCPhysicsSetting.h" diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index ed8f0460c3..0d75e93348 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -44,6 +44,8 @@ THE SOFTWARE. #include "cocoa/CCAffineTransform.h" #include "support/TransformUtils.h" #include "support/CCProfiling.h" +#include "physics/CCPhysicsBody.h" +#include "physics/CCPhysicsWorld.h" // external #include "kazmath/GL/matrix.h" From 0806c5fe15e97f0653c6ba9a8c9d08c1fd3baae9 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 9 Sep 2013 17:13:59 +0800 Subject: [PATCH 06/34] issue #2771: Fix CI compile errors. --- cocos2dx/proj.linux/Makefile | 5 +++++ cocos2dx/sprite_nodes/CCSprite.cpp | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cocos2dx/proj.linux/Makefile b/cocos2dx/proj.linux/Makefile index dc539d17ec..556dc75627 100644 --- a/cocos2dx/proj.linux/Makefile +++ b/cocos2dx/proj.linux/Makefile @@ -74,6 +74,11 @@ SOURCES = ../actions/CCAction.cpp \ ../particle_nodes/CCParticleSystem.cpp \ ../particle_nodes/CCParticleSystemQuad.cpp \ ../particle_nodes/CCParticleBatchNode.cpp \ +../physics/CCPhysicsBody.cpp \ +../physics/CCPhysicsContactDelegate.cpp \ +../physics/CCPhysicsFixture.cpp \ +../physics/CCPhysicsJoint.cpp \ +../physics/CCPhysicsWorld.cpp \ ../platform/CCSAXParser.cpp \ ../platform/CCThread.cpp \ ../platform/CCEGLViewProtocol.cpp \ diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index 0d75e93348..ed8f0460c3 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -44,8 +44,6 @@ THE SOFTWARE. #include "cocoa/CCAffineTransform.h" #include "support/TransformUtils.h" #include "support/CCProfiling.h" -#include "physics/CCPhysicsBody.h" -#include "physics/CCPhysicsWorld.h" // external #include "kazmath/GL/matrix.h" From 862a3bd6a4e682ac6b3bdb4acb9ba4af9af17a41 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 10 Sep 2013 10:06:51 +0800 Subject: [PATCH 07/34] issue #2771: Fix CI compile errors. --- cocos2dx/include/cocos2d.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cocos2dx/include/cocos2d.h b/cocos2dx/include/cocos2d.h index 01e5739d96..d8ee1e9099 100755 --- a/cocos2dx/include/cocos2d.h +++ b/cocos2dx/include/cocos2d.h @@ -124,6 +124,13 @@ THE SOFTWARE. #include "particle_nodes/CCParticleExamples.h" #include "particle_nodes/CCParticleSystemQuad.h" +// physics +#include "physics/CCPhysicsBody.h" +#include "physics/CCPhysicsContactDelegate.h" +#include "physics/CCPhysicsFixture.h" +#include "physics/CCPhysicsJoint.h" +#include "physics/CCPhysicsWorld.h" + // platform #include "platform/CCDevice.h" #include "platform/CCCommon.h" From bd10d92460d0a935b79aa4b4970b6b3ee372af71 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 10 Sep 2013 14:15:19 +0800 Subject: [PATCH 08/34] issue #2771: Add macros to control use physics engine or not --- cocos2dx/physics/CCPhysicsBody.h | 6 +++++- cocos2dx/physics/CCPhysicsContactDelegate.h | 8 ++++++-- cocos2dx/physics/CCPhysicsFixture.h | 6 +++++- cocos2dx/physics/CCPhysicsJoint.h | 6 +++++- cocos2dx/physics/CCPhysicsSetting.h | 4 ++++ cocos2dx/physics/CCPhysicsWorld.h | 7 +++++-- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/cocos2dx/physics/CCPhysicsBody.h b/cocos2dx/physics/CCPhysicsBody.h index 04e0fa6acf..1871565c3d 100644 --- a/cocos2dx/physics/CCPhysicsBody.h +++ b/cocos2dx/physics/CCPhysicsBody.h @@ -22,12 +22,14 @@ THE SOFTWARE. ****************************************************************************/ +#include "CCPhysicsSetting.h" +#ifdef CC_USE_PHYSICS_ENGINE + #ifndef __CCPHYSICS_BODY_H__ #define __CCPHYSICS_BODY_H__ #include "cocoa/CCObject.h" #include "cocoa/CCGeometry.h" -#include "CCPhysicsSetting.h" #include NS_CC_BEGIN @@ -104,3 +106,5 @@ private: NS_CC_END #endif // __CCPHYSICS_BODY_H__ + +#endif // CC_USE_PHYSICS_ENGINE diff --git a/cocos2dx/physics/CCPhysicsContactDelegate.h b/cocos2dx/physics/CCPhysicsContactDelegate.h index 7c41756ae8..e96e563139 100644 --- a/cocos2dx/physics/CCPhysicsContactDelegate.h +++ b/cocos2dx/physics/CCPhysicsContactDelegate.h @@ -22,12 +22,14 @@ THE SOFTWARE. ****************************************************************************/ +#include "CCPhysicsSetting.h" +#ifdef CC_USE_PHYSICS_ENGINE + #ifndef __CCPHYSICS_CONTACTDELEGATE_H__ #define __CCPHYSICS_CONTACTDELEGATE_H__ #include "cocoa/CCObject.h" #include "cocoa/CCGeometry.h" -#include "CCPhysicsSetting.h" NS_CC_BEGIN @@ -45,4 +47,6 @@ public: }; NS_CC_END -#endif //__CCPHYSICS_CONTACTDELEGATE_H__ \ No newline at end of file +#endif //__CCPHYSICS_CONTACTDELEGATE_H__ + +#endif // CC_USE_PHYSICS_ENGINE diff --git a/cocos2dx/physics/CCPhysicsFixture.h b/cocos2dx/physics/CCPhysicsFixture.h index 76fc367e07..210f58472d 100644 --- a/cocos2dx/physics/CCPhysicsFixture.h +++ b/cocos2dx/physics/CCPhysicsFixture.h @@ -22,12 +22,14 @@ THE SOFTWARE. ****************************************************************************/ +#include "CCPhysicsSetting.h" +#ifdef CC_USE_PHYSICS_ENGINE + #ifndef __CCPHYSICS_FIXTURE_H__ #define __CCPHYSICS_FIXTURE_H__ #include "cocoa/CCObject.h" #include "cocoa/CCGeometry.h" -#include "CCPhysicsSetting.h" NS_CC_BEGIN @@ -57,3 +59,5 @@ protected: NS_CC_END #endif // __CCPHYSICS_FIXTURE_H__ + +#endif // CC_USE_PHYSICS_ENGINE diff --git a/cocos2dx/physics/CCPhysicsJoint.h b/cocos2dx/physics/CCPhysicsJoint.h index 5f3aaf011e..03e0515336 100644 --- a/cocos2dx/physics/CCPhysicsJoint.h +++ b/cocos2dx/physics/CCPhysicsJoint.h @@ -22,12 +22,14 @@ THE SOFTWARE. ****************************************************************************/ +#include "CCPhysicsSetting.h" +#ifdef CC_USE_PHYSICS_ENGINE + #ifndef __CCPHYSICS_JOINT_H__ #define __CCPHYSICS_JOINT_H__ #include "cocoa/CCObject.h" #include "cocoa/CCGeometry.h" -#include "CCPhysicsSetting.h" NS_CC_BEGIN @@ -112,3 +114,5 @@ protected: NS_CC_END #endif // __CCPHYSICS_JOINT_H__ + +#endif // CC_USE_PHYSICS_ENGINE diff --git a/cocos2dx/physics/CCPhysicsSetting.h b/cocos2dx/physics/CCPhysicsSetting.h index 745c93b77b..4edd004e11 100644 --- a/cocos2dx/physics/CCPhysicsSetting.h +++ b/cocos2dx/physics/CCPhysicsSetting.h @@ -31,6 +31,10 @@ #define CC_PHYSICS_ENGINE CC_PHYSICS_CHIPMUNK +#if (CC_PHYSICS_ENGINE != CC_PHYSICS_UNKNOWN) +#define CC_USE_PHYSICS_ENGINE +#endif + #if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) #include "Box2D.h" #elif (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index 1f092e5ae4..2b81983f77 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -22,13 +22,14 @@ THE SOFTWARE. ****************************************************************************/ +#include "CCPhysicsSetting.h" +#ifdef CC_USE_PHYSICS_ENGINE + #ifndef __CCPHYSICS_WORLD_H__ #define __CCPHYSICS_WORLD_H__ #include "cocoa/CCObject.h" #include "cocoa/CCGeometry.h" -#include "CCPhysicsSetting.h" - NS_CC_BEGIN @@ -76,3 +77,5 @@ protected: NS_CC_END #endif // __CCPHYSICS_WORLD_H__ + +#endif // CC_USE_PHYSICS_ENGINE From bcab90ddc438f06a36c4c38643ffe4b602fb78bf Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 10 Sep 2013 17:36:49 +0800 Subject: [PATCH 09/34] issue #2771: Change CC_USE_PHYSICS_ENGINE to CC_USE_PHYSICS. Add some implements. --- cocos2dx/physics/CCPhysicsBody.cpp | 96 +++++++++++++++++++++ cocos2dx/physics/CCPhysicsBody.h | 13 +-- cocos2dx/physics/CCPhysicsContactDelegate.h | 4 +- cocos2dx/physics/CCPhysicsFixture.h | 4 +- cocos2dx/physics/CCPhysicsJoint.h | 4 +- cocos2dx/physics/CCPhysicsSetting.h | 2 +- cocos2dx/physics/CCPhysicsWorld.cpp | 22 +++-- cocos2dx/physics/CCPhysicsWorld.h | 7 +- 8 files changed, 130 insertions(+), 22 deletions(-) diff --git a/cocos2dx/physics/CCPhysicsBody.cpp b/cocos2dx/physics/CCPhysicsBody.cpp index eb7296843e..0b2309a1c1 100644 --- a/cocos2dx/physics/CCPhysicsBody.cpp +++ b/cocos2dx/physics/CCPhysicsBody.cpp @@ -22,3 +22,99 @@ THE SOFTWARE. ****************************************************************************/ #include "CCPhysicsBody.h" + +#ifdef CC_USE_PHYSICS + +NS_CC_BEGIN + + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + +class PhysicsBodyInfo +{ +public: + PhysicsBodyInfo(); + ~PhysicsBodyInfo(); + +public: + cpBody* body; + cpShape* shape; +}; + +PhysicsBodyInfo::PhysicsBodyInfo() +: body(nullptr) +, shape(nullptr) +{ +} + +PhysicsBodyInfo::~PhysicsBodyInfo() +{ + if (body) cpBodyFree(body); + if (shape) cpShapeFree(shape); +} + +PhysicsBody::PhysicsBody() +{ +} + +PhysicsBody::~PhysicsBody() +{ + CC_SAFE_DELETE(_info); +} + +PhysicsBody* PhysicsBody::create() +{ + PhysicsBody * body = new PhysicsBody(); + if(body && body->init()) + { + return body; + } + + CC_SAFE_DELETE(body); + return nullptr; +} + +bool PhysicsBody::init() +{ + do + { + _info = new PhysicsBodyInfo(); + CC_BREAK_IF(_info == nullptr); + + _info->body = cpBodyNew(1.0, 1.0); + CC_BREAK_IF(_info->body == nullptr); + + return true; + } while (false); + + return false; +} + +PhysicsBody* PhysicsBody::createCircle(Point centre, float radius) +{ + PhysicsBody* body = PhysicsBody::create(); + + if (body == nullptr) + { + return nullptr; + } + + cpBodySetPos(body->_info->body, cpv(centre.x, centre.y)); + body->_info->shape = cpCircleShapeNew(body->_info->body, radius, cpvzero); + + if (body->_info->shape == nullptr) + { + return nullptr; + } + + return body; +} + +#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) + + +#endif + +NS_CC_END + +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsBody.h b/cocos2dx/physics/CCPhysicsBody.h index 1871565c3d..64df98ec3f 100644 --- a/cocos2dx/physics/CCPhysicsBody.h +++ b/cocos2dx/physics/CCPhysicsBody.h @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsSetting.h" -#ifdef CC_USE_PHYSICS_ENGINE +#ifdef CC_USE_PHYSICS #ifndef __CCPHYSICS_BODY_H__ #define __CCPHYSICS_BODY_H__ @@ -37,6 +37,7 @@ class Sprite; class PhysicsWorld; class PhysicsJoint; class PhysicsFixture; +class PhysicsBodyInfo; class PhysicsBody : public Object, public Clonable { @@ -63,7 +64,7 @@ public: void removeFixture(PhysicsFixture* fixture); void removeAllFixtures(); - inline PhysicsWorld* getWorld() const { return _physicsWorld; } + inline PhysicsWorld* getWorld() const { return _world; } inline const std::vector* getJoints() const { return &_joints; } inline Sprite* getOwner() const { return _owner; } @@ -78,13 +79,14 @@ public: virtual Clonable* clone() const override; protected: + static PhysicsBody* create(); bool init(); protected: PhysicsBody(); virtual ~PhysicsBody(); -private: +protected: float _mass; float _density; float _area; @@ -100,11 +102,12 @@ private: std::vector _joints; Array* _fixtures; - PhysicsWorld* _physicsWorld; + PhysicsWorld* _world; + PhysicsBodyInfo* _info; }; NS_CC_END #endif // __CCPHYSICS_BODY_H__ -#endif // CC_USE_PHYSICS_ENGINE +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsContactDelegate.h b/cocos2dx/physics/CCPhysicsContactDelegate.h index e96e563139..a371b6e044 100644 --- a/cocos2dx/physics/CCPhysicsContactDelegate.h +++ b/cocos2dx/physics/CCPhysicsContactDelegate.h @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsSetting.h" -#ifdef CC_USE_PHYSICS_ENGINE +#ifdef CC_USE_PHYSICS #ifndef __CCPHYSICS_CONTACTDELEGATE_H__ #define __CCPHYSICS_CONTACTDELEGATE_H__ @@ -49,4 +49,4 @@ public: NS_CC_END #endif //__CCPHYSICS_CONTACTDELEGATE_H__ -#endif // CC_USE_PHYSICS_ENGINE +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsFixture.h b/cocos2dx/physics/CCPhysicsFixture.h index 210f58472d..e743ab3c44 100644 --- a/cocos2dx/physics/CCPhysicsFixture.h +++ b/cocos2dx/physics/CCPhysicsFixture.h @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsSetting.h" -#ifdef CC_USE_PHYSICS_ENGINE +#ifdef CC_USE_PHYSICS #ifndef __CCPHYSICS_FIXTURE_H__ #define __CCPHYSICS_FIXTURE_H__ @@ -60,4 +60,4 @@ protected: NS_CC_END #endif // __CCPHYSICS_FIXTURE_H__ -#endif // CC_USE_PHYSICS_ENGINE +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsJoint.h b/cocos2dx/physics/CCPhysicsJoint.h index 03e0515336..c7e659ab75 100644 --- a/cocos2dx/physics/CCPhysicsJoint.h +++ b/cocos2dx/physics/CCPhysicsJoint.h @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsSetting.h" -#ifdef CC_USE_PHYSICS_ENGINE +#ifdef CC_USE_PHYSICS #ifndef __CCPHYSICS_JOINT_H__ #define __CCPHYSICS_JOINT_H__ @@ -115,4 +115,4 @@ NS_CC_END #endif // __CCPHYSICS_JOINT_H__ -#endif // CC_USE_PHYSICS_ENGINE +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsSetting.h b/cocos2dx/physics/CCPhysicsSetting.h index 4edd004e11..b68da7cf93 100644 --- a/cocos2dx/physics/CCPhysicsSetting.h +++ b/cocos2dx/physics/CCPhysicsSetting.h @@ -32,7 +32,7 @@ #define CC_PHYSICS_ENGINE CC_PHYSICS_CHIPMUNK #if (CC_PHYSICS_ENGINE != CC_PHYSICS_UNKNOWN) -#define CC_USE_PHYSICS_ENGINE +#define CC_USE_PHYSICS #endif #if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) diff --git a/cocos2dx/physics/CCPhysicsWorld.cpp b/cocos2dx/physics/CCPhysicsWorld.cpp index 7ca586a2b1..ccfc1ea788 100644 --- a/cocos2dx/physics/CCPhysicsWorld.cpp +++ b/cocos2dx/physics/CCPhysicsWorld.cpp @@ -57,6 +57,11 @@ bool PhysicsWorld::init() return true; } +void PhysicsWorld::addChild(PhysicsBody* body) +{ + +} + #elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) struct PhysicsInfo @@ -67,19 +72,20 @@ struct PhysicsInfo PhysicsWorld* PhysicsWorld::create() { - PhysicsWorld * physicsWorld = new PhysicsWorld(); - if(physicsWorld && physicsWorld->init()) + PhysicsWorld * world = new PhysicsWorld(); + if(world && world->init()) { - return physicsWorld; + return world; } - CC_SAFE_DELETE(physicsWorld); - return NULL; + CC_SAFE_DELETE(world); + return nullptr; } -PhysicsWorld::PhysicsWorld() : -_gravity(Point(0, -9.8)), -_speed(1.0) +PhysicsWorld::PhysicsWorld() +: _gravity(Point(0, -9.8)) +, _speed(1.0) +, _worldInfo(nullptr) { } diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index 2b81983f77..5bf807c159 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -23,7 +23,7 @@ ****************************************************************************/ #include "CCPhysicsSetting.h" -#ifdef CC_USE_PHYSICS_ENGINE +#ifdef CC_USE_PHYSICS #ifndef __CCPHYSICS_WORLD_H__ #define __CCPHYSICS_WORLD_H__ @@ -55,6 +55,9 @@ public: void registerContactDelegate(PhysicsContactDelegate* delegate); + inline Point getGravity() { return _gravity; } + inline void setGravity(Point gravity) { _gravity = gravity; } + protected: static PhysicsWorld* create(); bool init(); @@ -78,4 +81,4 @@ NS_CC_END #endif // __CCPHYSICS_WORLD_H__ -#endif // CC_USE_PHYSICS_ENGINE +#endif // CC_USE_PHYSICS From 7bba5f1b01e275d64d7bd66def2a3d0c393de3fe Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 10 Sep 2013 17:38:47 +0800 Subject: [PATCH 10/34] issue #2771: Add method Scene::createWithPhysics() end Scene::initWithPhysics() --- cocos2dx/base_nodes/CCNode.h | 2 - .../CCScene.cpp | 76 ++++++++++++++----- .../layers_scenes_transitions_nodes/CCScene.h | 15 +++- cocos2dx/sprite_nodes/CCSprite.h | 5 ++ 4 files changed, 75 insertions(+), 23 deletions(-) diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index d3ea08952d..dd6384e724 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -52,8 +52,6 @@ class ActionManager; class Component; class Dictionary; class ComponentContainer; -class Scene; -class PhysicsBody; /** * @addtogroup base_nodes diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp index a2bc6bb4ed..589a77d60b 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp @@ -33,6 +33,9 @@ THE SOFTWARE. NS_CC_BEGIN Scene::Scene() +#ifdef _physicsWorld +: _physicsWorld(nullptr) +#endif { _ignoreAnchorPointForPosition = true; setAnchorPoint(Point(0.5f, 0.5f)); @@ -56,7 +59,7 @@ bool Scene::init() return bRet; } -Scene *Scene::create(bool usePhysics/* = false*/) +Scene *Scene::create() { Scene *pRet = new Scene(); if (pRet && pRet->init()) @@ -71,6 +74,38 @@ Scene *Scene::create(bool usePhysics/* = false*/) } } +#ifdef CC_USE_PHYSICS +Scene *Scene::createWithPhysics() +{ + Scene *pRet = new Scene(); + if (pRet && pRet->initWithPhysics()) + { + pRet->autorelease(); + return pRet; + } + else + { + CC_SAFE_DELETE(pRet); + return NULL; + } +} + +bool Scene::initWithPhysics() +{ + bool bRet = false; + do + { + Director * pDirector; + CC_BREAK_IF( ! (pDirector = Director::getInstance()) ); + this->setContentSize(pDirector->getWinSize()); + CC_BREAK_IF(! (_physicsWorld = PhysicsWorld::create())); + // success + bRet = true; + } while (0); + return bRet; +} +#endif + void Scene::addChild(Node* child) { Node::addChild(child); @@ -85,30 +120,35 @@ void Scene::addChild(Node* child, int zOrder, int tag) { Node::addChild(child, zOrder, tag); - auto addToPhysicsWorldFunc = [this](Object* node) -> void +#ifdef CC_USE_PHYSICS + if (_physicsWorld) { - if (typeid(Sprite).hash_code() == typeid(node).hash_code()) + auto addToPhysicsWorldFunc = [this](Object* node) -> void { - Sprite* sp = dynamic_cast(node); - - if (sp && sp->getPhysicsBody()) + if (typeid(Sprite).hash_code() == typeid(node).hash_code()) { - _physicsWorld->addChild(sp->getPhysicsBody()); + Sprite* sp = dynamic_cast(node); + + if (sp && sp->getPhysicsBody()) + { + _physicsWorld->addChild(sp->getPhysicsBody()); + } } - } - }; - - if(typeid(Layer).hash_code() == typeid(child).hash_code()) - { - Object* subChild = nullptr; - CCARRAY_FOREACH(child->getChildren(), subChild) + }; + + if(typeid(Layer).hash_code() == typeid(child).hash_code()) { - addToPhysicsWorldFunc(subChild); + Object* subChild = nullptr; + CCARRAY_FOREACH(child->getChildren(), subChild) + { + addToPhysicsWorldFunc(subChild); + } + }else + { + addToPhysicsWorldFunc(child); } - }else - { - addToPhysicsWorldFunc(child); } +#endif } diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.h b/cocos2dx/layers_scenes_transitions_nodes/CCScene.h index c084852513..4b5b27f4a4 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.h +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.h @@ -28,11 +28,10 @@ THE SOFTWARE. #define __CCSCENE_H__ #include "base_nodes/CCNode.h" +#include "physics/CCPhysicsWorld.h" NS_CC_BEGIN -class PhysicsWorld; - /** * @addtogroup scene * @{ @@ -52,21 +51,31 @@ class CC_DLL Scene : public Node { public: /** creates a new Scene object */ - static Scene *create(bool usePhysics = false); + static Scene *create(); +#ifdef CC_USE_PHYSICS + static Scene *createWithPhysics(); +#endif Scene(); virtual ~Scene(); bool init(); +#ifdef CC_USE_PHYSICS + bool initWithPhysics(); +#endif virtual void addChild(Node* child) override; virtual void addChild(Node* child, int zOrder) override; virtual void addChild(Node* child, int zOrder, int tag) override; +#ifdef CC_USE_PHYSICS inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; } +#endif protected: +#ifdef CC_USE_PHYSICS PhysicsWorld* _physicsWorld; +#endif }; // end of scene group diff --git a/cocos2dx/sprite_nodes/CCSprite.h b/cocos2dx/sprite_nodes/CCSprite.h index 16162b810b..4d4d0e7bdf 100644 --- a/cocos2dx/sprite_nodes/CCSprite.h +++ b/cocos2dx/sprite_nodes/CCSprite.h @@ -36,6 +36,7 @@ THE SOFTWARE. #ifdef EMSCRIPTEN #include "base_nodes/CCGLBufferedNode.h" #endif // EMSCRIPTEN +#include "physics/CCPhysicsBody.h" NS_CC_BEGIN @@ -443,6 +444,7 @@ public: */ void setFlipY(bool bFlipY); +#ifdef CC_USE_PHYSICS /** * set the PhysicsBody that let the sprite effect with physics */ @@ -452,6 +454,7 @@ public: * get the PhysicsBody the sprite have */ PhysicsBody* getPhysicsBody() const; +#endif /// @} End of Sprite properties getter/setters @@ -550,7 +553,9 @@ protected: bool _flipX; /// Whether the sprite is flipped horizaontally or not. bool _flipY; /// Whether the sprite is flipped vertically or not. +#ifdef CC_USE_PHYSICS PhysicsBody* _physicsBody; ///< the physicsBody the node have +#endif }; From d161c6a5760a3f254a3155e6cb548ac34d709886 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 10 Sep 2013 17:41:06 +0800 Subject: [PATCH 11/34] issue #2771: Add PhysicsTest to TestCpp. Add initTest to TestScene, move Scene::init() from constructor to TestScene::initTest() --- .../Classes/PhysicsTest/PhysicsTest.cpp | 108 ++++++++++++++++++ .../TestCpp/Classes/PhysicsTest/PhysicsTest.h | 29 +++++ samples/Cpp/TestCpp/Classes/controller.cpp | 3 +- samples/Cpp/TestCpp/Classes/testBasic.cpp | 7 +- samples/Cpp/TestCpp/Classes/testBasic.h | 1 + samples/Cpp/TestCpp/Classes/tests.h | 1 + .../project.pbxproj.REMOVED.git-id | 2 +- 7 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp create mode 100644 samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp new file mode 100644 index 0000000000..a1d9180b72 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -0,0 +1,108 @@ +#include "PhysicsTest.h" +#include "../testResource.h" +#include "cocos-ext.h" +USING_NS_CC_EXT; + +PhysicsTestLayer::PhysicsTestLayer() +: _spriteTexture(NULL) +{ +#ifdef CC_USE_PHYSICS + //Set up sprite +#if 1 + // Use batch node. Faster + auto parent = SpriteBatchNode::create("Images/blocks.png", 100); + _spriteTexture = parent->getTexture(); +#else + // doesn't use batch node. Slower + _spriteTexture = TextureCache::getInstance()->addImage("Images/blocks.png"); + auto parent = Node::create(); +#endif + +#else + auto label = LabelTTF::create("Should define CC_ENABLE_BOX2D_INTEGRATION=1\n to run this test case", + "Arial", + 18); + auto size = Director::getInstance()->getWinSize(); + label->setPosition(Point(size.width/2, size.height/2)); + + addChild(label); +#endif +} + +PhysicsTestLayer::~PhysicsTestLayer() +{ +} + +void PhysicsTestLayer::initPhysics() +{ +} + +void PhysicsTestLayer::createResetButton() +{ + auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", [](Object *sender) { + auto s = new PhysicsTestScene(); + auto child = new PhysicsTestLayer(); + s->addChild(child); + child->release(); + Director::getInstance()->replaceScene(s); + s->release(); + }); + + auto menu = Menu::create(reset, NULL); + + menu->setPosition(Point(VisibleRect::bottom().x, VisibleRect::bottom().y + 30)); + this->addChild(menu, -1); + +} + +void PhysicsTestLayer::addNewSpriteAtPosition(Point p) +{ + CCLOG("Add sprite %0.2f x %02.f",p.x,p.y); + +#if CC_ENABLE_BOX2D_INTEGRATION + auto parent = this->getChildByTag(kTagParentNode); + + //We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is + //just randomly picking one of the images + int idx = (CCRANDOM_0_1() > .5 ? 0:1); + int idy = (CCRANDOM_0_1() > .5 ? 0:1); + auto sprite = PhysicsSprite::createWithTexture(_spriteTexture,Rect(32 * idx,32 * idy,32,32)); + parent->addChild(sprite); + sprite->setB2Body(body); + sprite->setPTMRatio(PTM_RATIO); + sprite->setPosition( Point( p.x, p.y) ); +#endif +} + +void PhysicsTestLayer::ccTouchesEnded(Set* touches, Event* event) +{ + //Add a new body/atlas sprite at the touched location + SetIterator it; + Touch* touch; + + for( it = touches->begin(); it != touches->end(); it++) + { + touch = static_cast(*it); + + if(!touch) + break; + + auto location = touch->getLocation(); + + addNewSpriteAtPosition( location ); + } +} + +bool PhysicsTestScene::initTest() +{ + return TestScene::initWithPhysics(); +} + +void PhysicsTestScene::runThisTest() +{ + auto layer = new PhysicsTestLayer(); + addChild(layer); + layer->release(); + + Director::getInstance()->replaceScene(this); +} diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h new file mode 100644 index 0000000000..8140015488 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h @@ -0,0 +1,29 @@ +#ifndef _PHYSICS_TEST_H_ +#define _PHYSICS_TEST_H_ + +#include "cocos2d.h" +#include "../testBasic.h" + +class PhysicsTestLayer : public Layer +{ + Texture2D* _spriteTexture; // weak ref + +public: + PhysicsTestLayer(); + ~PhysicsTestLayer(); + + void initPhysics(); + void createResetButton(); + + void addNewSpriteAtPosition(Point p); + virtual void ccTouchesEnded(Set* touches, Event* event); +} ; + +class PhysicsTestScene : public TestScene +{ +public: + virtual bool initTest() override; + virtual void runThisTest(); +}; + +#endif diff --git a/samples/Cpp/TestCpp/Classes/controller.cpp b/samples/Cpp/TestCpp/Classes/controller.cpp index 26971f6452..946458bb57 100644 --- a/samples/Cpp/TestCpp/Classes/controller.cpp +++ b/samples/Cpp/TestCpp/Classes/controller.cpp @@ -65,6 +65,7 @@ struct { { "ParallaxTest", [](){return new ParallaxTestScene(); } }, { "ParticleTest", [](){return new ParticleTestScene(); } }, { "PerformanceTest", []() { return new PerformanceTestScene(); } }, + { "PhysicsTest", []() { return new PhysicsTestScene(); } }, { "RenderTextureTest", [](){return new RenderTextureScene(); } }, { "RotateWorldTest", [](){return new RotateWorldTestScene(); } }, { "SceneTest", [](){return new SceneTestScene();} }, @@ -142,7 +143,7 @@ void TestController::menuCallback(Object * sender) // create the test scene and run it auto scene = g_aTestNames[idx].callback(); - if (scene) + if (scene && scene->initTest()) { scene->runThisTest(); scene->release(); diff --git a/samples/Cpp/TestCpp/Classes/testBasic.cpp b/samples/Cpp/TestCpp/Classes/testBasic.cpp index c1c7b22bad..9600d3b067 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.cpp +++ b/samples/Cpp/TestCpp/Classes/testBasic.cpp @@ -3,8 +3,11 @@ TestScene::TestScene(bool bPortrait) { - - Scene::init(); +} + +bool TestScene::initTest() +{ + return Scene::init(); } void TestScene::onEnter() diff --git a/samples/Cpp/TestCpp/Classes/testBasic.h b/samples/Cpp/TestCpp/Classes/testBasic.h index f4be332a7d..7bc95ab05c 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.h +++ b/samples/Cpp/TestCpp/Classes/testBasic.h @@ -11,6 +11,7 @@ class TestScene : public Scene { public: TestScene(bool bPortrait = false); + virtual bool initTest(); virtual void onEnter(); virtual void runThisTest() = 0; diff --git a/samples/Cpp/TestCpp/Classes/tests.h b/samples/Cpp/TestCpp/Classes/tests.h index ea26d0223c..455caf02b8 100644 --- a/samples/Cpp/TestCpp/Classes/tests.h +++ b/samples/Cpp/TestCpp/Classes/tests.h @@ -63,5 +63,6 @@ #include "TexturePackerEncryptionTest/TextureAtlasEncryptionTest.h" #include "DataVisitorTest/DataVisitorTest.h" #include "ConfigurationTest/ConfigurationTest.h" +#include "PhysicsTest/PhysicsTest.h" #endif diff --git a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id index 42c17a6004..c276a3fc9e 100644 --- a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -d36d2542f8c085962b01d856a008b085589e62e6 \ No newline at end of file +aa2d7f7606e4895b0fa0d8aa4031609822b30eaf \ No newline at end of file From 2c66f1b95e25d4bc787a9f83a16cba77127c7ff7 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 16 Sep 2013 21:22:22 +0800 Subject: [PATCH 12/34] issue #2771: Implement the minimum set of physical API. Improve the PhysicsTest --- .../project.pbxproj.REMOVED.git-id | 2 +- cocos2dx/include/cocos2d.h | 4 +- .../CCLayer.cpp | 25 + .../layers_scenes_transitions_nodes/CCLayer.h | 7 + .../CCScene.cpp | 25 +- .../layers_scenes_transitions_nodes/CCScene.h | 18 +- .../CCPhysicsBodyInfo.cpp} | 16 + cocos2dx/physics/Box2D/CCPhysicsBodyInfo.h | 43 ++ .../physics/Box2D/CCPhysicsContactInfo.cpp | 39 ++ cocos2dx/physics/Box2D/CCPhysicsContactInfo.h | 43 ++ .../CCPhysicsHelper.h} | 36 +- .../CCPhysicsJointInfo.cpp} | 16 + cocos2dx/physics/Box2D/CCPhysicsJointInfo.h | 43 ++ cocos2dx/physics/Box2D/CCPhysicsShapeInfo.cpp | 39 ++ cocos2dx/physics/Box2D/CCPhysicsShapeInfo.h | 43 ++ cocos2dx/physics/Box2D/CCPhysicsWorldInfo.cpp | 39 ++ cocos2dx/physics/Box2D/CCPhysicsWorldInfo.h | 43 ++ cocos2dx/physics/CCPhysicsBody.cpp | 346 ++++++++++++-- cocos2dx/physics/CCPhysicsBody.h | 96 ++-- cocos2dx/physics/CCPhysicsContact.cpp | 137 ++++++ cocos2dx/physics/CCPhysicsContact.h | 136 ++++++ cocos2dx/physics/CCPhysicsJoint.cpp | 195 ++++++++ cocos2dx/physics/CCPhysicsJoint.h | 49 +- cocos2dx/physics/CCPhysicsSetting.h | 8 + cocos2dx/physics/CCPhysicsShape.cpp | 426 +++++++++++++++++ cocos2dx/physics/CCPhysicsShape.h | 182 +++++++ cocos2dx/physics/CCPhysicsWorld.cpp | 275 ++++++++++- cocos2dx/physics/CCPhysicsWorld.h | 53 ++- .../physics/chipmunk/CCPhysicsBodyInfo.cpp | 45 ++ .../CCPhysicsBodyInfo.h} | 32 +- .../physics/chipmunk/CCPhysicsContactInfo.cpp | 39 ++ .../physics/chipmunk/CCPhysicsContactInfo.h | 49 ++ cocos2dx/physics/chipmunk/CCPhysicsHelper.h | 68 +++ .../physics/chipmunk/CCPhysicsJointInfo.cpp | 43 ++ .../physics/chipmunk/CCPhysicsJointInfo.h | 50 ++ .../physics/chipmunk/CCPhysicsShapeInfo.cpp | 70 +++ .../physics/chipmunk/CCPhysicsShapeInfo.h | 61 +++ .../physics/chipmunk/CCPhysicsWorldInfo.cpp | 40 ++ .../physics/chipmunk/CCPhysicsWorldInfo.h | 48 ++ cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c | 446 ++++++++++++++++++ cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h | 50 ++ cocos2dx/sprite_nodes/CCSprite.cpp | 61 ++- cocos2dx/sprite_nodes/CCSprite.h | 2 + .../Classes/PhysicsTest/PhysicsTest.cpp | 114 +++-- .../TestCpp/Classes/PhysicsTest/PhysicsTest.h | 4 +- 45 files changed, 3379 insertions(+), 227 deletions(-) rename cocos2dx/physics/{CCPhysicsContactDelegate.cpp => Box2D/CCPhysicsBodyInfo.cpp} (84%) create mode 100644 cocos2dx/physics/Box2D/CCPhysicsBodyInfo.h create mode 100644 cocos2dx/physics/Box2D/CCPhysicsContactInfo.cpp create mode 100644 cocos2dx/physics/Box2D/CCPhysicsContactInfo.h rename cocos2dx/physics/{CCPhysicsFixture.h => Box2D/CCPhysicsHelper.h} (60%) rename cocos2dx/physics/{CCPhysicsFixture.cpp => Box2D/CCPhysicsJointInfo.cpp} (84%) create mode 100644 cocos2dx/physics/Box2D/CCPhysicsJointInfo.h create mode 100644 cocos2dx/physics/Box2D/CCPhysicsShapeInfo.cpp create mode 100644 cocos2dx/physics/Box2D/CCPhysicsShapeInfo.h create mode 100644 cocos2dx/physics/Box2D/CCPhysicsWorldInfo.cpp create mode 100644 cocos2dx/physics/Box2D/CCPhysicsWorldInfo.h create mode 100644 cocos2dx/physics/CCPhysicsContact.cpp create mode 100644 cocos2dx/physics/CCPhysicsContact.h create mode 100644 cocos2dx/physics/CCPhysicsShape.cpp create mode 100644 cocos2dx/physics/CCPhysicsShape.h create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.cpp rename cocos2dx/physics/{CCPhysicsContactDelegate.h => chipmunk/CCPhysicsBodyInfo.h} (69%) create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsContactInfo.cpp create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsContactInfo.h create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsHelper.h create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsJointInfo.cpp create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsJointInfo.h create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.cpp create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.h create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.cpp create mode 100644 cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.h create mode 100644 cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c create mode 100644 cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 1eaf467207..ac85a298cf 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -cbb5290ea17f6020e0249818c08c9d94a17dd073 \ No newline at end of file +f64b17366179be63ab250b6a65922b95efbd9712 \ No newline at end of file diff --git a/cocos2dx/include/cocos2d.h b/cocos2dx/include/cocos2d.h index d8ee1e9099..a841f7fa5c 100755 --- a/cocos2dx/include/cocos2d.h +++ b/cocos2dx/include/cocos2d.h @@ -126,8 +126,8 @@ THE SOFTWARE. // physics #include "physics/CCPhysicsBody.h" -#include "physics/CCPhysicsContactDelegate.h" -#include "physics/CCPhysicsFixture.h" +#include "physics/CCPhysicsContact.h" +#include "physics/CCPhysicsShape.h" #include "physics/CCPhysicsJoint.h" #include "physics/CCPhysicsWorld.h" diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index c00cf03903..04043c332e 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -38,6 +38,7 @@ THE SOFTWARE. // extern #include "kazmath/GL/matrix.h" #include "keyboard_dispatcher/CCKeyboardDispatcher.h" +#include "CCScene.h" NS_CC_BEGIN @@ -499,6 +500,30 @@ void Layer::ccTouchesCancelled(Set *pTouches, Event *pEvent) CC_UNUSED_PARAM(pEvent); } + +#ifdef CC_USE_PHYSICS +void Layer::addChild(Node* child) +{ + Node::addChild(child); +} + +void Layer::addChild(Node* child, int zOrder) +{ + Node::addChild(child, zOrder); +} + +void Layer::addChild(Node* child, int zOrder, int tag) +{ + Node::addChild(child, zOrder, tag); + + if (this->getParent() && + dynamic_cast(this->getParent()) != nullptr) + { + dynamic_cast(this->getParent())->addChildToPhysicsWorld(child); + } +} +#endif + // LayerRGBA LayerRGBA::LayerRGBA() : _displayedOpacity(255) diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h index 32e8991b75..1c7792a29a 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h @@ -36,6 +36,7 @@ THE SOFTWARE. #ifdef EMSCRIPTEN #include "base_nodes/CCGLBufferedNode.h" #endif // EMSCRIPTEN +#include "physics/CCPhysicsSetting.h" NS_CC_BEGIN @@ -138,6 +139,12 @@ public: virtual void onEnter() override; virtual void onExit() override; virtual void onEnterTransitionDidFinish() override; + +#ifdef CC_USE_PHYSICS + virtual void addChild(Node* child) override; + virtual void addChild(Node* child, int zOrder) override; + virtual void addChild(Node* child, int zOrder, int tag) override; +#endif // CC_USE_PHYSICS protected: bool _touchEnabled; diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp index 589a77d60b..36f2947dc6 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp @@ -99,12 +99,14 @@ bool Scene::initWithPhysics() CC_BREAK_IF( ! (pDirector = Director::getInstance()) ); this->setContentSize(pDirector->getWinSize()); CC_BREAK_IF(! (_physicsWorld = PhysicsWorld::create())); + _physicsWorld->setScene(this); + + this->scheduleUpdate(); // success bRet = true; } while (0); return bRet; } -#endif void Scene::addChild(Node* child) { @@ -120,23 +122,27 @@ void Scene::addChild(Node* child, int zOrder, int tag) { Node::addChild(child, zOrder, tag); -#ifdef CC_USE_PHYSICS + addChildToPhysicsWorld(child); +} + +void Scene::addChildToPhysicsWorld(Node* child) +{ if (_physicsWorld) { auto addToPhysicsWorldFunc = [this](Object* node) -> void { - if (typeid(Sprite).hash_code() == typeid(node).hash_code()) + if (dynamic_cast(node) != nullptr) { Sprite* sp = dynamic_cast(node); - if (sp && sp->getPhysicsBody()) + if (sp->getPhysicsBody()) { _physicsWorld->addChild(sp->getPhysicsBody()); } } }; - if(typeid(Layer).hash_code() == typeid(child).hash_code()) + if(dynamic_cast(child) != nullptr) { Object* subChild = nullptr; CCARRAY_FOREACH(child->getChildren(), subChild) @@ -148,8 +154,15 @@ void Scene::addChild(Node* child, int zOrder, int tag) addToPhysicsWorldFunc(child); } } -#endif } +void Scene::update(float delta) +{ + Node::update(delta); + + _physicsWorld->update(delta); +} +#endif + NS_CC_END diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.h b/cocos2dx/layers_scenes_transitions_nodes/CCScene.h index 4b5b27f4a4..217d01c756 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.h +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.h @@ -60,22 +60,30 @@ public: virtual ~Scene(); bool init(); + #ifdef CC_USE_PHYSICS +public: bool initWithPhysics(); -#endif virtual void addChild(Node* child) override; virtual void addChild(Node* child, int zOrder) override; virtual void addChild(Node* child, int zOrder, int tag) override; -#ifdef CC_USE_PHYSICS + /* + * Update method will be called automatically every frame if "scheduleUpdate" is called, and the node is "live" + */ + virtual void update(float delta) override; + inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; } -#endif protected: -#ifdef CC_USE_PHYSICS + virtual void addChildToPhysicsWorld(Node* child); + +protected: PhysicsWorld* _physicsWorld; -#endif +#endif // CC_USE_PHYSICS + + friend class Layer; }; // end of scene group diff --git a/cocos2dx/physics/CCPhysicsContactDelegate.cpp b/cocos2dx/physics/Box2D/CCPhysicsBodyInfo.cpp similarity index 84% rename from cocos2dx/physics/CCPhysicsContactDelegate.cpp rename to cocos2dx/physics/Box2D/CCPhysicsBodyInfo.cpp index 39b3eedbc5..bfa20b616a 100644 --- a/cocos2dx/physics/CCPhysicsContactDelegate.cpp +++ b/cocos2dx/physics/Box2D/CCPhysicsBodyInfo.cpp @@ -21,3 +21,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ + +#include "CCPhysicsBodyInfo.h" + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) +NS_CC_BEGIN + +PhysicsBodyInfo::PhysicsBodyInfo() +{ +} + +PhysicsBodyInfo::~PhysicsBodyInfo() +{ +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/Box2D/CCPhysicsBodyInfo.h b/cocos2dx/physics/Box2D/CCPhysicsBodyInfo.h new file mode 100644 index 0000000000..730837ed9d --- /dev/null +++ b/cocos2dx/physics/Box2D/CCPhysicsBodyInfo.h @@ -0,0 +1,43 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) + +#ifndef __CCPHYSICS_BODY_INFO_H__ +#define __CCPHYSICS_BODY_INFO_H__ +#include "platform/CCPlatformMacros.h" +NS_CC_BEGIN + +class PhysicsBodyInfo +{ +public: + PhysicsBodyInfo(); + ~PhysicsBodyInfo(); +}; + +NS_CC_END +#endif // __CCPHYSICS_BODY_INFO_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/Box2D/CCPhysicsContactInfo.cpp b/cocos2dx/physics/Box2D/CCPhysicsContactInfo.cpp new file mode 100644 index 0000000000..41eaa4f831 --- /dev/null +++ b/cocos2dx/physics/Box2D/CCPhysicsContactInfo.cpp @@ -0,0 +1,39 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsContactInfo.h" + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) +NS_CC_BEGIN + +PhysicsContactInfo::PhysicsContactInfo() +{ +} + +PhysicsContactInfo::~PhysicsContactInfo() +{ +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/Box2D/CCPhysicsContactInfo.h b/cocos2dx/physics/Box2D/CCPhysicsContactInfo.h new file mode 100644 index 0000000000..b592caa0af --- /dev/null +++ b/cocos2dx/physics/Box2D/CCPhysicsContactInfo.h @@ -0,0 +1,43 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) + +#ifndef __CCPHYSICS_CONTACT_INFO_H__ +#define __CCPHYSICS_CONTACT_INFO_H__ +#include "platform/CCPlatformMacros.h" +NS_CC_BEGIN + +class PhysicsContactInfo +{ +public: + PhysicsContactInfo(); + ~PhysicsContactInfo(); +}; + +NS_CC_END +#endif // __CCPHYSICS_CONTACT_INFO_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/CCPhysicsFixture.h b/cocos2dx/physics/Box2D/CCPhysicsHelper.h similarity index 60% rename from cocos2dx/physics/CCPhysicsFixture.h rename to cocos2dx/physics/Box2D/CCPhysicsHelper.h index e743ab3c44..86ef7d74ee 100644 --- a/cocos2dx/physics/CCPhysicsFixture.h +++ b/cocos2dx/physics/Box2D/CCPhysicsHelper.h @@ -22,42 +22,22 @@ THE SOFTWARE. ****************************************************************************/ -#include "CCPhysicsSetting.h" -#ifdef CC_USE_PHYSICS +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) -#ifndef __CCPHYSICS_FIXTURE_H__ -#define __CCPHYSICS_FIXTURE_H__ +#ifndef __CCPHYSICS_HELPER_H__ +#define __CCPHYSICS_HELPER_H__ -#include "cocoa/CCObject.h" +#include "platform/CCPlatformMacros.h" #include "cocoa/CCGeometry.h" NS_CC_BEGIN -class PhysicsFixture : public Object +class PhysicsHelper { -public: - static PhysicsFixture* createCircle(Point centre, float radius); - static PhysicsFixture* createRectangle(Rect rect); - static PhysicsFixture* createPolygon(Array* points); - - static PhysicsFixture* createEdgeSegment(Point x, Point y); - static PhysicsFixture* createEdgeCircle(Point centre, float radius); - static PhysicsFixture* createEdgeRectangle(Rect rect); - static PhysicsFixture* createEdgePolygon(Array* points); - -protected: - bool init(); - -protected: - PhysicsFixture(); - virtual ~PhysicsFixture(); - -protected: - float _density; - float _friction; }; NS_CC_END -#endif // __CCPHYSICS_FIXTURE_H__ +#endif // __CCPHYSICS_HELPER_H__ -#endif // CC_USE_PHYSICS +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/CCPhysicsFixture.cpp b/cocos2dx/physics/Box2D/CCPhysicsJointInfo.cpp similarity index 84% rename from cocos2dx/physics/CCPhysicsFixture.cpp rename to cocos2dx/physics/Box2D/CCPhysicsJointInfo.cpp index 39b3eedbc5..753ba41534 100644 --- a/cocos2dx/physics/CCPhysicsFixture.cpp +++ b/cocos2dx/physics/Box2D/CCPhysicsJointInfo.cpp @@ -21,3 +21,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ + +#include "CCPhysicsJointInfo.h" + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) +NS_CC_BEGIN + +PhysicsJointInfo::PhysicsJointInfo() +{ +} + +PhysicsJointInfo::~PhysicsJointInfo() +{ +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/Box2D/CCPhysicsJointInfo.h b/cocos2dx/physics/Box2D/CCPhysicsJointInfo.h new file mode 100644 index 0000000000..abcf089387 --- /dev/null +++ b/cocos2dx/physics/Box2D/CCPhysicsJointInfo.h @@ -0,0 +1,43 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) + +#ifndef __CCPHYSICS_JOINT_INFO_H__ +#define __CCPHYSICS_JOINT_INFO_H__ +#include "platform/CCPlatformMacros.h" +NS_CC_BEGIN + +class PhysicsJointInfo +{ +public: + PhysicsJointInfo(); + ~PhysicsJointInfo(); +}; + +NS_CC_END +#endif // __CCPHYSICS_JOINT_INFO_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/Box2D/CCPhysicsShapeInfo.cpp b/cocos2dx/physics/Box2D/CCPhysicsShapeInfo.cpp new file mode 100644 index 0000000000..a89ba7dae7 --- /dev/null +++ b/cocos2dx/physics/Box2D/CCPhysicsShapeInfo.cpp @@ -0,0 +1,39 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsShapeInfo.h" + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) +NS_CC_BEGIN + +PhysicsShapeInfo::PhysicsShapeInfo() +{ +} + +PhysicsShapeInfo::~PhysicsShapeInfo() +{ +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/Box2D/CCPhysicsShapeInfo.h b/cocos2dx/physics/Box2D/CCPhysicsShapeInfo.h new file mode 100644 index 0000000000..9091001887 --- /dev/null +++ b/cocos2dx/physics/Box2D/CCPhysicsShapeInfo.h @@ -0,0 +1,43 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) + +#ifndef __CCPHYSICS_SHAPE_INFO_H__ +#define __CCPHYSICS_SHAPE_INFO_H__ +#include "platform/CCPlatformMacros.h" +NS_CC_BEGIN + +class PhysicsShapeInfo +{ +public: + PhysicsShapeInfo(); + ~PhysicsShapeInfo(); +}; + +NS_CC_END +#endif // __CCPHYSICS_SHAPE_INFO_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/Box2D/CCPhysicsWorldInfo.cpp b/cocos2dx/physics/Box2D/CCPhysicsWorldInfo.cpp new file mode 100644 index 0000000000..0de6c00d82 --- /dev/null +++ b/cocos2dx/physics/Box2D/CCPhysicsWorldInfo.cpp @@ -0,0 +1,39 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsWorldInfo.h" + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) +NS_CC_BEGIN + +PhysicsWorldInfo::PhysicsWorldInfo() +{ +} + +PhysicsWorldInfo::~PhysicsWorldInfo() +{ +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/Box2D/CCPhysicsWorldInfo.h b/cocos2dx/physics/Box2D/CCPhysicsWorldInfo.h new file mode 100644 index 0000000000..bcc09124db --- /dev/null +++ b/cocos2dx/physics/Box2D/CCPhysicsWorldInfo.h @@ -0,0 +1,43 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) + +#ifndef __CCPHYSICS_WORLD_INFO_H__ +#define __CCPHYSICS_WORLD_INFO_H__ +#include "platform/CCPlatformMacros.h" +NS_CC_BEGIN + +class PhysicsWorldInfo +{ +public: + PhysicsWorldInfo(); + ~PhysicsWorldInfo(); +}; + +NS_CC_END +#endif // __CCPHYSICS_WORLD_INFO_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D diff --git a/cocos2dx/physics/CCPhysicsBody.cpp b/cocos2dx/physics/CCPhysicsBody.cpp index 0b2309a1c1..588586dded 100644 --- a/cocos2dx/physics/CCPhysicsBody.cpp +++ b/cocos2dx/physics/CCPhysicsBody.cpp @@ -22,51 +22,74 @@ THE SOFTWARE. ****************************************************************************/ #include "CCPhysicsBody.h" - #ifdef CC_USE_PHYSICS +#include "CCPhysicsShape.h" +#include "CCPhysicsJoint.h" +#include "CCPhysicsWorld.h" + +#include "chipmunk/CCPhysicsBodyInfo.h" +#include "Box2D/CCPhysicsBodyInfo.h" +#include "chipmunk/CCPhysicsJointInfo.h" +#include "Box2D/CCPhysicsJointInfo.h" +#include "chipmunk/CCPhysicsWorldInfo.h" +#include "Box2D/CCPhysicsWorldInfo.h" + +#include "chipmunk/CCPhysicsHelper.h" +#include "Box2D/CCPhysicsHelper.h" + NS_CC_BEGIN #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) -class PhysicsBodyInfo +namespace { -public: - PhysicsBodyInfo(); - ~PhysicsBodyInfo(); - -public: - cpBody* body; - cpShape* shape; -}; - -PhysicsBodyInfo::PhysicsBodyInfo() -: body(nullptr) -, shape(nullptr) -{ -} - -PhysicsBodyInfo::~PhysicsBodyInfo() -{ - if (body) cpBodyFree(body); - if (shape) cpShapeFree(shape); + static const float MASS_DEFAULT = 1.0; + static const float DENSITY_DEFAULT = 1.0; + static const float ANGULARDAMPING_DEFAULT = 200; } PhysicsBody::PhysicsBody() +: _owner(nullptr) +, _world(nullptr) +, _info(nullptr) +, _dynamic(false) +, _massDefault(true) +, _angularDampingDefault(true) +, _mass(MASS_DEFAULT) +, _area(0.0) +, _density(DENSITY_DEFAULT) +, _angularDamping(ANGULARDAMPING_DEFAULT) { } PhysicsBody::~PhysicsBody() { CC_SAFE_DELETE(_info); + + for (auto it = _shapes.begin(); it != _shapes.end(); ++it) + { + delete *it; + } + + for (auto it = _joints.begin(); it != _joints.end(); ++it) + { + PhysicsJoint* joint = *it; + PhysicsBody* other = joint->getBodyA() == this ? joint->getBodyA() : joint->getBodyB(); + + other->_joints.erase(std::find(other->_joints.begin(), other->_joints.end(), joint)); + delete joint; + } } -PhysicsBody* PhysicsBody::create() +PhysicsBody* PhysicsBody::createCircle(float radius) { - PhysicsBody * body = new PhysicsBody(); - if(body && body->init()) + PhysicsBody* body = new PhysicsBody(); + if (body && body->init()) { + body->addCircle(radius); + body->autorelease(); return body; } @@ -74,6 +97,156 @@ PhysicsBody* PhysicsBody::create() return nullptr; } +PhysicsBody* PhysicsBody::createBox(Size size) +{ + PhysicsBody* body = new PhysicsBody(); + if (body && body->init()) + { + body->addBox(size); + body->autorelease(); + return body; + } + + CC_SAFE_DELETE(body); + return nullptr; +} + +PhysicsBody* PhysicsBody::createPolygon(Point* points, int count) +{ + PhysicsBody* body = new PhysicsBody(); + if (body && body->init()) + { + body->addPolygon(points, count); + body->autorelease(); + return body; + } + + CC_SAFE_DELETE(body); + return nullptr; +} + +PhysicsBody* PhysicsBody::createEdgeSegment(Point a, Point b, float border/* = 1*/) +{ + PhysicsBody* body = new PhysicsBody(); + if (body && body->initStatic()) + { + body->addEdgeSegment(a, b, border); + body->autorelease(); + return body; + } + + CC_SAFE_DELETE(body); + return nullptr; +} + +PhysicsBody* PhysicsBody::createEdgeBox(Size size, float border/* = 1*/) +{ + PhysicsBody* body = new PhysicsBody(); + if (body && body->initStatic()) + { + body->addEdgeBox(size, border); + body->autorelease(); + return body; + } + + CC_SAFE_DELETE(body); + + return nullptr; +} + +PhysicsBody* PhysicsBody::createEdgePolygon(Point* points, int count, float border/* = 1*/) +{ + PhysicsBody* body = new PhysicsBody(); + if (body && body->initStatic()) + { + body->addEdgePolygon(points, count, border); + body->autorelease(); + return body; + } + + CC_SAFE_DELETE(body); + + return nullptr; +} + +PhysicsBody* PhysicsBody::createEdgeChain(Point* points, int count, float border/* = 1*/) +{ + PhysicsBody* body = new PhysicsBody(); + if (body && body->initStatic()) + { + body->addEdgeChain(points, count); + body->autorelease(); + return body; + } + + CC_SAFE_DELETE(body); + + return nullptr; +} + +PhysicsShapeCircle* PhysicsBody::addCircle(float radius, Point offset/* = Point(0, 0)*/) +{ + _area = PhysicsHelper::cpfloat2float(cpAreaForCircle(0, radius)); + setMass((_massDefault ? 0 : getMass()) + _area * _density); + + setAngularDamping((_angularDampingDefault ? 0 : getAngularDamping()) + + PhysicsHelper::cpfloat2float(cpMomentForCircle(getMass(), 0, radius, PhysicsHelper::point2cpv(offset)))); + + return PhysicsShapeCircle::create(this, radius, offset); +} + +PhysicsShapeBox* PhysicsBody::addBox(Size size, Point offset/* = Point(0, 0)*/) +{ + cpVect cpOffset = PhysicsHelper::size2cpv(size); + cpVect vec[4] = {}; + vec[0] = cpv(0, 0); + vec[1] = cpv(0, cpOffset.y); + vec[2] = cpv(cpOffset.x, cpOffset.y); + vec[3] = cpv(cpOffset.x, 0); + + _area = PhysicsHelper::cpfloat2float(cpAreaForPoly(4, vec)); + setMass((_massDefault ? 0 : getMass()) + _area * _density); + + setAngularDamping((_angularDampingDefault ? 0 : getAngularDamping()) + + PhysicsHelper::cpfloat2float(cpMomentForBox(getMass(), PhysicsHelper::float2cpfloat(size.width), PhysicsHelper::float2cpfloat(size.height)))); + + return PhysicsShapeBox::create(this, size, offset); +} + +PhysicsShapePolygon* PhysicsBody::addPolygon(Point* points, int count, Point offset/* = Point(0, 0)*/) +{ + cpVect* vec = new cpVect[count]; + PhysicsHelper::points2cpvs(points, vec, count); + _area = PhysicsHelper::cpfloat2float(cpAreaForPoly(count, vec)); + + setAngularDamping((_angularDampingDefault ? 0 : getAngularDamping()) + + PhysicsHelper::cpfloat2float(cpMomentForPoly(getMass(), count, vec, PhysicsHelper::point2cpv(offset)))); + + delete[] vec; + + return PhysicsShapePolygon::create(this, points, count, offset); +} + +PhysicsShapeEdgeSegment* PhysicsBody::addEdgeSegment(Point a, Point b, float border/* = 1*/) +{ + return PhysicsShapeEdgeSegment::create(this, a, b, border); +} + +PhysicsShapeEdgeBox* PhysicsBody::addEdgeBox(Size size, float border/* = 1*/, Point offset/* = Point(0, 0)*/) +{ + return PhysicsShapeEdgeBox::create(this, size, border, offset); +} + +PhysicsShapeEdgePolygon* PhysicsBody::addEdgePolygon(Point* points, int count, float border/* = 1*/) +{ + return PhysicsShapeEdgePolygon::create(this, points, count); +} + +PhysicsShapeEdgeChain* PhysicsBody::addEdgeChain(Point* points, int count, float border/* = 1*/) +{ + return PhysicsShapeEdgeChain::create(this, points, count, border); +} + bool PhysicsBody::init() { do @@ -81,8 +254,9 @@ bool PhysicsBody::init() _info = new PhysicsBodyInfo(); CC_BREAK_IF(_info == nullptr); - _info->body = cpBodyNew(1.0, 1.0); + _info->body = cpBodyNew(PhysicsHelper::float2cpfloat(_mass), PhysicsHelper::float2cpfloat(_angularDamping)); CC_BREAK_IF(_info->body == nullptr); + _dynamic = true; return true; } while (false); @@ -90,26 +264,118 @@ bool PhysicsBody::init() return false; } -PhysicsBody* PhysicsBody::createCircle(Point centre, float radius) +void PhysicsBody::setDynamic(bool dynamic) { - PhysicsBody* body = PhysicsBody::create(); - - if (body == nullptr) + _dynamic = dynamic; + if (_world != nullptr && cpBodyIsStatic(_info->body) == (cpBool)_dynamic) { - return nullptr; + if (dynamic) + { + cpSpaceConvertBodyToDynamic(_world->_info->space, _info->body, _mass, _angularDamping); + }else + { + cpSpaceConvertBodyToStatic(_world->_info->space, _info->body); + } } - - cpBodySetPos(body->_info->body, cpv(centre.x, centre.y)); - body->_info->shape = cpCircleShapeNew(body->_info->body, radius, cpvzero); - - if (body->_info->shape == nullptr) - { - return nullptr; - } - - return body; } +bool PhysicsBody::initStatic() +{ + do + { + _info = new PhysicsBodyInfo(); + CC_BREAK_IF(_info == nullptr); + + _info->body = cpBodyNewStatic(); + CC_BREAK_IF(_info->body == nullptr); + _dynamic = false; + + return true; + } while (false); + + return false; +} + +void PhysicsBody::setPosition(Point position) +{ + cpBodySetPos(_info->body, PhysicsHelper::point2cpv(position)); +} + +void PhysicsBody::setRotation(float rotation) +{ + cpBodySetAngle(_info->body, PhysicsHelper::float2cpfloat(rotation)); +} + +Point PhysicsBody::getPosition() const +{ + cpVect vec = cpBodyGetPos(_info->body); + return PhysicsHelper::cpv2point(vec); +} + +float PhysicsBody::getRotation() const +{ + return -PhysicsHelper::cpfloat2float(cpBodyGetAngle(_info->body) / 3.14f * 180.0f); +} + +void PhysicsBody::addShape(PhysicsShape* shape) +{ + if (shape == nullptr) return; + + _shapes.push_back(shape); + + if (_world != nullptr) _world->addShape(shape); +} + +void PhysicsBody::applyForce(Point force) +{ + applyForce(force, Point()); +} + +void PhysicsBody::applyForce(Point force, Point offset) +{ + cpBodyApplyForce(_info->body, PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset)); +} + +void PhysicsBody::applyImpulse(Point impulse) +{ + applyImpulse(impulse, Point()); +} + +void PhysicsBody::applyImpulse(Point impulse, Point offset) +{ + cpBodyApplyImpulse(_info->body, PhysicsHelper::point2cpv(impulse), PhysicsHelper::point2cpv(offset)); +} + +void PhysicsBody::applyTorque(float torque) +{ + cpBodySetTorque(_info->body, PhysicsHelper::float2cpfloat(torque)); +} + +void PhysicsBody::setMass(float mass) +{ + _mass = mass; + _massDefault = false; + + cpBodySetMass(_info->body, PhysicsHelper::float2cpfloat(_mass)); +} + +void PhysicsBody::setAngularDamping(float angularDamping) +{ + _angularDamping = angularDamping; + _angularDampingDefault = false; + + cpBodySetMoment(_info->body, _angularDamping); +} + +//Clonable* PhysicsBody::clone() const +//{ +// PhysicsBody* body = new PhysicsBody(); +// +// body->autorelease(); +// +// return body; +//} + #elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) diff --git a/cocos2dx/physics/CCPhysicsBody.h b/cocos2dx/physics/CCPhysicsBody.h index 64df98ec3f..08fffb8722 100644 --- a/cocos2dx/physics/CCPhysicsBody.h +++ b/cocos2dx/physics/CCPhysicsBody.h @@ -36,33 +36,48 @@ NS_CC_BEGIN class Sprite; class PhysicsWorld; class PhysicsJoint; -class PhysicsFixture; +class PhysicsShape; +class PhysicsShapeCircle; +class PhysicsShapeBox; +class PhysicsShapePolygon; +class PhysicsShapeEdgeSegment; +class PhysicsShapeEdgeBox; +class PhysicsShapeEdgePolygon; +class PhysicsShapeEdgeChain; + class PhysicsBodyInfo; -class PhysicsBody : public Object, public Clonable +class PhysicsBody : public Object//, public Clonable { public: - static PhysicsBody* createCircle(Point centre, float radius); - static PhysicsBody* createRectangle(Rect rect); - static PhysicsBody* createPolygon(Array* points); + static PhysicsBody* createCircle(float radius); + static PhysicsBody* createBox(Size size); + static PhysicsBody* createPolygon(Point* points, int count); - static PhysicsBody* createEdgeSegment(Point x, Point y); - static PhysicsBody* createEdgeCircle(Point centre, float radius); - static PhysicsBody* createEdgeRectangle(Rect rect); - static PhysicsBody* createEdgePolygon(Array* points); - static PhysicsBody* createEdgeChain(Array* points); + static PhysicsBody* createEdgeSegment(Point a, Point b, float border = 1); + static PhysicsBody* createEdgeBox(Size size, float border = 1); + static PhysicsBody* createEdgePolygon(Point* points, int count, float border = 1); + static PhysicsBody* createEdgeChain(Point* points, int count, float border = 1); + + virtual PhysicsShapeCircle* addCircle(float radius, Point offset = Point(0, 0)); + virtual PhysicsShapeBox* addBox(Size size, Point offset = Point(0, 0)); + virtual PhysicsShapePolygon* addPolygon(Point* points, int count, Point offset = Point(0, 0)); + + virtual PhysicsShapeEdgeSegment* addEdgeSegment(Point a, Point b, float border = 1); + virtual PhysicsShapeEdgeBox* addEdgeBox(Size size, float border = 1, Point offset = Point(0, 0)); + virtual PhysicsShapeEdgePolygon* addEdgePolygon(Point* points, int count, float border = 1); + virtual PhysicsShapeEdgeChain* addEdgeChain(Point* points, int count, float border = 1); virtual void applyForce(Point force); - virtual void applyForce(Point force, Point point); + virtual void applyForce(Point force, Point offset); virtual void applyImpulse(Point impulse); - virtual void applyImpulse(Point impulse, Point point); + virtual void applyImpulse(Point impulse, Point offset); virtual void applyTorque(float torque); - virtual void applyAngularImpulse(float impulse); - void addFixture(PhysicsFixture* fixture); - inline Array* getFixtures() const { return _fixtures; } - void removeFixture(PhysicsFixture* fixture); - void removeAllFixtures(); + inline std::vector& getShapes() { return _shapes; } + inline PhysicsShape* getShape() { return _shapes.size() >= 1 ? _shapes.front() : nullptr; } + void removeShape(PhysicsShape* shape); + void removeAllShapes(); inline PhysicsWorld* getWorld() const { return _world; } inline const std::vector* getJoints() const { return &_joints; } @@ -76,34 +91,55 @@ public: void setCollisionBitmask(int bitmask); inline int getCollisionBitmask() const { return _collisionBitmask; } - virtual Clonable* clone() const override; + Point getPosition() const; + float getRotation() const; + + inline bool isDynamic() { return _dynamic; } + void setDynamic(bool dynamic); + + void setMass(float mass); + inline float getMass() { return _mass; } + + void setAngularDamping(float angularDamping); + inline float getAngularDamping() { return _angularDamping; } + + //virtual Clonable* clone() const override; protected: - static PhysicsBody* create(); + bool init(); + bool initStatic(); + + virtual void setPosition(Point position); + virtual void setRotation(float rotation); + virtual void addShape(PhysicsShape* shape); protected: PhysicsBody(); virtual ~PhysicsBody(); protected: - float _mass; - float _density; - float _area; - float _friction; Sprite* _owner; - Point _velocity; - float _angularVelocity; - bool _resting; + std::vector _joints; + std::vector _shapes; + PhysicsWorld* _world; + PhysicsBodyInfo* _info; + bool _dynamic; + bool _massDefault; + bool _angularDampingDefault; + float _mass; + float _area; + float _density; + float _angularDamping; int _categoryBitmask; int _contactTestBitmask; int _collisionBitmask; - std::vector _joints; - Array* _fixtures; - PhysicsWorld* _world; - PhysicsBodyInfo* _info; + friend class PhysicsWorld; + friend class PhysicsShape; + friend class PhysicsJoint; + friend class Sprite; }; NS_CC_END diff --git a/cocos2dx/physics/CCPhysicsContact.cpp b/cocos2dx/physics/CCPhysicsContact.cpp new file mode 100644 index 0000000000..d76b93f9d8 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsContact.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#include "CCPhysicsContact.h" +#ifdef CC_USE_PHYSICS +#include "chipmunk/CCPhysicsContactInfo.h" +#include "Box2D/CCPhysicsContactInfo.h" + +NS_CC_BEGIN + +PhysicsContact::PhysicsContact() +: _shapeA(nullptr) +, _shapeB(nullptr) +, _info(nullptr) +, _data(nullptr) +{ + +} + +PhysicsContact::~PhysicsContact() +{ + CC_SAFE_DELETE(_info); +} + +PhysicsContact* PhysicsContact::create(PhysicsShape* a, PhysicsShape* b) +{ + PhysicsContact * contact = new PhysicsContact(); + if(contact && contact->init(a, b)) + { + return contact; + } + + CC_SAFE_DELETE(contact); + return nullptr; +} + +bool PhysicsContact::init(PhysicsShape* a, PhysicsShape* b) +{ + do + { + CC_BREAK_IF(a == nullptr || b == nullptr); + + CC_BREAK_IF(!(_info = new PhysicsContactInfo(this))); + + _shapeA = a; + _shapeB = b; + + return true; + } while(false); + + return false; +} + +// PhysicsContactPreSolve implementation +PhysicsContactPreSolve::PhysicsContactPreSolve() +{ + +} + +PhysicsContactPreSolve::~PhysicsContactPreSolve() +{ + +} + +PhysicsContactPreSolve* PhysicsContactPreSolve::create() +{ + PhysicsContactPreSolve * solve = new PhysicsContactPreSolve(); + if(solve && solve->init()) + { + return solve; + } + + CC_SAFE_DELETE(solve); + return nullptr; +} + +bool PhysicsContactPreSolve::init() +{ + return true; +} + + +// PhysicsContactPostSolve implementation +PhysicsContactPostSolve::PhysicsContactPostSolve() +{ + +} + +PhysicsContactPostSolve::~PhysicsContactPostSolve() +{ + +} + +PhysicsContactPostSolve* PhysicsContactPostSolve::create() +{ + PhysicsContactPostSolve * solve = new PhysicsContactPostSolve(); + if(solve && solve->init()) + { + return solve; + } + + CC_SAFE_DELETE(solve); + return nullptr; +} + +bool PhysicsContactPostSolve::init() +{ + return true; +} + + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) +#endif + +NS_CC_END +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsContact.h b/cocos2dx/physics/CCPhysicsContact.h new file mode 100644 index 0000000000..6db1fd47f7 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsContact.h @@ -0,0 +1,136 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsSetting.h" +#ifdef CC_USE_PHYSICS + +#ifndef __CCPHYSICS_CONTACT_H__ +#define __CCPHYSICS_CONTACT_H__ + +#include "cocoa/CCObject.h" +#include "cocoa/CCGeometry.h" + +NS_CC_BEGIN + +class PhysicsShape; +class PhysicsWorld; + +namespace PhysicsInnerCallbackFunctions +{ +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + int collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); + int collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + void collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); +#endif +} + +class PhysicsContactInfo; + +class PhysicsContact +{ +public: + inline PhysicsShape* getShapeA() { return _shapeA; } + inline PhysicsShape* getShapeB() { return _shapeB; } + inline void* getData() { return _data; } + +private: + static PhysicsContact* create(PhysicsShape* a, PhysicsShape* b); + bool init(PhysicsShape* a, PhysicsShape* b); + +private: + PhysicsContact(); + ~PhysicsContact(); + +private: + PhysicsShape* _shapeA; + PhysicsShape* _shapeB; + PhysicsContactInfo* _info; + void* _data; + + friend class PhysicsWorld; + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + friend int PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); + friend int PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + friend void PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + friend void PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); +#endif +}; + +class PhysicsContactPreSolve +{ +private: + PhysicsContactPreSolve(); + ~PhysicsContactPreSolve(); + + static PhysicsContactPreSolve* create(); + bool init(); + + friend class PhysicsWorld; + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + friend int PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); + friend int PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + friend void PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + friend void PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); +#endif +}; + +class PhysicsContactPostSolve +{ +private: + PhysicsContactPostSolve(); + ~PhysicsContactPostSolve(); + + static PhysicsContactPostSolve* create(); + bool init(); + + friend class PhysicsWorld; + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + friend int PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); + friend int PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + friend void PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + friend void PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); +#endif +}; + +class PhysicsContactDelegate +{ +public: + PhysicsContactDelegate(); + virtual ~PhysicsContactDelegate(); + +public: + virtual bool onContactBegin(const PhysicsContact& contact) = 0; + virtual bool onContactPreSolve(const PhysicsContact& contact, const PhysicsContactPreSolve& solve) = 0; + virtual void onContactPostSove(const PhysicsContact& contact, const PhysicsContactPostSolve& solve)= 0; + virtual void onContactEnd(const PhysicsContact& contact) = 0; +}; + +NS_CC_END +#endif //__CCPHYSICS_CONTACT_H__ + +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsJoint.cpp b/cocos2dx/physics/CCPhysicsJoint.cpp index 39b3eedbc5..572e682fa8 100644 --- a/cocos2dx/physics/CCPhysicsJoint.cpp +++ b/cocos2dx/physics/CCPhysicsJoint.cpp @@ -21,3 +21,198 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ + +#include "CCPhysicsJoint.h" +#ifdef CC_USE_PHYSICS +#include "CCPhysicsBody.h" + +#include "chipmunk/CCPhysicsJointInfo.h" +#include "Box2D/CCPhysicsJointInfo.h" +#include "chipmunk/CCPhysicsBodyInfo.h" +#include "Box2D/CCPhysicsBodyInfo.h" +#include "chipmunk/CCPhysicsHelper.h" +#include "Box2D/CCPhysicsHelper.h" + +NS_CC_BEGIN + +PhysicsJoint::PhysicsJoint() +: _bodyA(nullptr) +, _bodyB(nullptr) +, _info(nullptr) +{ + +} + +PhysicsJoint::~PhysicsJoint() +{ + CC_SAFE_DELETE(_info); + + CC_SAFE_RELEASE(_bodyA); + CC_SAFE_RELEASE(_bodyB); +} + +bool PhysicsJoint::init(cocos2d::PhysicsBody *a, cocos2d::PhysicsBody *b) +{ + do + { + CC_BREAK_IF(a == nullptr || b == nullptr); + + CC_BREAK_IF(!(_info = new PhysicsJointInfo())); + + _bodyA = a; + _bodyA->retain(); + _bodyA->_joints.push_back(this); + _bodyB = b; + _bodyB->retain(); + _bodyB->_joints.push_back(this); + + return true; + } while (false); + + return false; +} + + +PhysicsJointPin::PhysicsJointPin() +{ + +} + +PhysicsJointPin::~PhysicsJointPin() +{ + +} + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +PhysicsBodyInfo* PhysicsJoint::bodyInfo(PhysicsBody* body) const +{ + return body->_info; +} + + + +PhysicsJointFixed* PhysicsJointFixed::create(PhysicsBody* a, PhysicsBody* b, const Point& anchr) +{ + PhysicsJointFixed* joint = new PhysicsJointFixed(); + + if (joint && joint->init(a, b, anchr)) + { + joint->autorelease(); + return joint; + } + + CC_SAFE_DELETE(joint); + return nullptr; +} + +bool PhysicsJointFixed::init(PhysicsBody* a, PhysicsBody* b, const Point& anchr) +{ + do + { + CC_BREAK_IF(!PhysicsJoint::init(a, b)); + + _info->joint = cpPivotJointNew(bodyInfo(a)->body, bodyInfo(b)->body, + PhysicsHelper::point2cpv(anchr)); + + return true; + } while (false); + + return false; +} + +PhysicsJointPin* PhysicsJointPin::create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2) +{ + PhysicsJointPin* joint = new PhysicsJointPin(); + + if (joint && joint->init(a, b, anchr1, anchr2)) + { + joint->autorelease(); + return joint; + } + + CC_SAFE_DELETE(joint); + return nullptr; +} + +bool PhysicsJointPin::init(PhysicsBody *a, PhysicsBody *b, const Point& anchr1, const Point& anchr2) +{ + do + { + CC_BREAK_IF(!PhysicsJoint::init(a, b)); + + _info->joint = cpPinJointNew(bodyInfo(a)->body, bodyInfo(b)->body, PhysicsHelper::point2cpv(anchr1), PhysicsHelper::point2cpv(anchr2)); + + return true; + } while (false); + + return false; +} + +PhysicsJointSliding* PhysicsJointSliding::create(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr) +{ + PhysicsJointSliding* joint = new PhysicsJointSliding(); + + if (joint && joint->init(a, b, grooveA, grooveB, anchr)) + { + return joint; + } + + CC_SAFE_DELETE(joint); + return nullptr; +} + +bool PhysicsJointSliding::init(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr) +{ + do + { + CC_BREAK_IF(!PhysicsJoint::init(a, b)); + + _info->joint = cpGrooveJointNew(bodyInfo(a)->body, bodyInfo(b)->body, + PhysicsHelper::point2cpv(grooveA), + PhysicsHelper::point2cpv(grooveB), + PhysicsHelper::point2cpv(anchr)); + + return true; + } while (false); + + return false; +} + + +PhysicsJointLimit* PhysicsJointLimit::create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max) +{ + PhysicsJointLimit* joint = new PhysicsJointLimit(); + + if (joint && joint->init(a, b, anchr1, anchr2, min, max)) + { + return joint; + } + + CC_SAFE_DELETE(joint); + return nullptr; +} + +bool PhysicsJointLimit::init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max) +{ + do + { + CC_BREAK_IF(!PhysicsJoint::init(a, b)); + + _info->joint = cpSlideJointNew(bodyInfo(a)->body, bodyInfo(b)->body, + PhysicsHelper::point2cpv(anchr1), + PhysicsHelper::point2cpv(anchr2), + PhysicsHelper::float2cpfloat(min), + PhysicsHelper::float2cpfloat(max)); + + return true; + } while (false); + + return false; +} + +#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) + +#endif + +NS_CC_END +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsJoint.h b/cocos2dx/physics/CCPhysicsJoint.h index c7e659ab75..ab0315d690 100644 --- a/cocos2dx/physics/CCPhysicsJoint.h +++ b/cocos2dx/physics/CCPhysicsJoint.h @@ -34,42 +34,59 @@ NS_CC_BEGIN class PhysicsBody; +class PhysicsJointInfo; +class PhysicsBodyInfo; -class PhysicsJoint +class PhysicsJoint : public Object { protected: PhysicsJoint(); - virtual ~PhysicsJoint(); + virtual ~PhysicsJoint() = 0; + +public: + PhysicsBody* getBodyA() { return _bodyA; } + PhysicsBody* getBodyB() { return _bodyB; } -private: +protected: + bool init(PhysicsBody* a, PhysicsBody* b); + + /** + * PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody. + */ + PhysicsBodyInfo* bodyInfo(PhysicsBody* body) const; + +protected: PhysicsBody* _bodyA; PhysicsBody* _bodyB; + PhysicsJointInfo* _info; + + friend class PhysicsBody; }; class PhysicsJointFixed : public PhysicsJoint { public: - PhysicsJointFixed* create(); + PhysicsJointFixed* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr); protected: - bool init(); + bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr); protected: PhysicsJointFixed(); - ~PhysicsJointFixed(); + virtual ~PhysicsJointFixed(); }; class PhysicsJointSliding : public PhysicsJoint { public: - PhysicsJointSliding* create(); + PhysicsJointSliding* create(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr); protected: - bool init(); + bool init(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr); protected: PhysicsJointSliding(); - ~PhysicsJointSliding(); + virtual ~PhysicsJointSliding(); }; class PhysicsJointSpring : public PhysicsJoint @@ -82,33 +99,33 @@ protected: protected: PhysicsJointSpring(); - ~PhysicsJointSpring(); + virtual ~PhysicsJointSpring(); }; class PhysicsJointLimit : public PhysicsJoint { public: - PhysicsJointLimit* create(); + PhysicsJointLimit* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max); protected: - bool init(); + bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max); protected: PhysicsJointLimit(); - ~PhysicsJointLimit(); + virtual ~PhysicsJointLimit(); }; class PhysicsJointPin : public PhysicsJoint { public: - PhysicsJointPin* create(); + static PhysicsJointPin* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2); protected: - bool init(); + bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2); protected: PhysicsJointPin(); - ~PhysicsJointPin(); + virtual ~PhysicsJointPin(); }; NS_CC_END diff --git a/cocos2dx/physics/CCPhysicsSetting.h b/cocos2dx/physics/CCPhysicsSetting.h index b68da7cf93..3d3aaaaf55 100644 --- a/cocos2dx/physics/CCPhysicsSetting.h +++ b/cocos2dx/physics/CCPhysicsSetting.h @@ -29,7 +29,15 @@ #define CC_PHYSICS_BOX2D 1 #define CC_PHYSICS_CHIPMUNK 2 +#define CC_USE_CHIPMUNK + +#ifdef CC_USE_BOX2D +#define CC_PHYSICS_ENGINE CC_PHYSICS_BOX2D +#elif defined(CC_USE_CHIPMUNK) #define CC_PHYSICS_ENGINE CC_PHYSICS_CHIPMUNK +#else +#define CC_PHYSICS_ENGINE CC_PHYSICS_UNKNOWN +#endif #if (CC_PHYSICS_ENGINE != CC_PHYSICS_UNKNOWN) #define CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsShape.cpp b/cocos2dx/physics/CCPhysicsShape.cpp new file mode 100644 index 0000000000..002c848eff --- /dev/null +++ b/cocos2dx/physics/CCPhysicsShape.cpp @@ -0,0 +1,426 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsShape.h" +#ifdef CC_USE_PHYSICS + +#include "CCPhysicsBody.h" + +#include "chipmunk/CCPhysicsBodyInfo.h" +#include "Box2D/CCPhysicsBodyInfo.h" +#include "chipmunk/CCPhysicsShapeInfo.h" +#include "Box2D/CCPhysicsShapeInfo.h" +#include "chipmunk/CCPhysicsHelper.h" + +NS_CC_BEGIN + +PhysicsShape::PhysicsShape() +: _body(nullptr) +, _info(nullptr) +, _type(Type::UNKNOWN) +{ + +} + +PhysicsShape::~PhysicsShape() +{ + CC_SAFE_DELETE(_info); +} + +bool PhysicsShape::init(PhysicsBody* body, Type type) +{ + if (body == nullptr) return false; + + _body = body; + + _info = new PhysicsShapeInfo(this); + if (_info == nullptr) return false; + + _type = type; + + return true; +} + +void PhysicsShape::addToBody() +{ + if(_body != nullptr) _body->addShape(this); +} + +PhysicsBodyInfo* PhysicsShape::bodyInfo() const +{ + return _body->_info; +} + +PhysicsShapeCircle::PhysicsShapeCircle() +{ + +} + +PhysicsShapeCircle::~PhysicsShapeCircle() +{ + +} + +PhysicsShapeBox::PhysicsShapeBox() +{ + +} + +PhysicsShapeBox::~PhysicsShapeBox() +{ + +} + +PhysicsShapePolygon::PhysicsShapePolygon() +{ + +} + +PhysicsShapePolygon::~PhysicsShapePolygon() +{ + +} + +PhysicsShapeEdgeBox::PhysicsShapeEdgeBox() +{ + +} + +PhysicsShapeEdgeBox::~PhysicsShapeEdgeBox() +{ + +} + +PhysicsShapeEdgeChain::PhysicsShapeEdgeChain() +{ + +} + +PhysicsShapeEdgeChain::~PhysicsShapeEdgeChain() +{ + +} + +PhysicsShapeEdgePolygon::PhysicsShapeEdgePolygon() +{ + +} + +PhysicsShapeEdgePolygon::~PhysicsShapeEdgePolygon() +{ + +} + +PhysicsShapeEdgeSegment::PhysicsShapeEdgeSegment() +{ + +} + +PhysicsShapeEdgeSegment::~PhysicsShapeEdgeSegment() +{ + +} + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + +// PhysicsShapeCircle +PhysicsShapeCircle* PhysicsShapeCircle::create(PhysicsBody* body, float radius, Point offset/* = Point(0, 0)*/) +{ + PhysicsShapeCircle* shape = new PhysicsShapeCircle(); + if (shape && shape->init(body, radius, offset)) + { + return shape; + } + + CC_SAFE_DELETE(shape); + return nullptr; +} + +bool PhysicsShapeCircle::init(PhysicsBody* body, float radius, Point offset /*= Point(0, 0)*/) +{ + do + { + CC_BREAK_IF(!PhysicsShape::init(body, Type::CIRCLE)); + + cpShape* shape = cpCircleShapeNew(bodyInfo()->body, radius, PhysicsHelper::point2cpv(offset)); + + CC_BREAK_IF(shape == nullptr); + + _info->add(shape); + addToBody(); + + return true; + } while (false); + + return false; +} + +// PhysicsShapeEdgeSegment +PhysicsShapeEdgeSegment* PhysicsShapeEdgeSegment::create(PhysicsBody* body, Point a, Point b, float border/* = 1*/) +{ + PhysicsShapeEdgeSegment* shape = new PhysicsShapeEdgeSegment(); + if (shape && shape->init(body, a, b, border)) + { + return shape; + } + + CC_SAFE_DELETE(shape); + return nullptr; +} + +bool PhysicsShapeEdgeSegment::init(PhysicsBody* body, Point a, Point b, float border/* = 1*/) +{ + do + { + CC_BREAK_IF(!PhysicsShape::init(body, Type::EDGESEGMENT)); + + cpShape* shape = cpSegmentShapeNew(bodyInfo()->body, + PhysicsHelper::point2cpv(a), + PhysicsHelper::point2cpv(b), + PhysicsHelper::float2cpfloat(border)); + + CC_BREAK_IF(shape == nullptr); + + _info->add(shape); + addToBody(); + + return true; + } while (false); + + return false; +} + +// PhysicsShapeBox +PhysicsShapeBox* PhysicsShapeBox::create(PhysicsBody* body, Size size, Point offset/* = Point(0, 0)*/) +{ + PhysicsShapeBox* shape = new PhysicsShapeBox(); + if (shape && shape->init(body, size, offset)) + { + return shape; + } + + CC_SAFE_DELETE(shape); + return nullptr; +} + +bool PhysicsShapeBox::init(PhysicsBody* body, Size size, Point offset /*= Point(0, 0)*/) +{ + do + { + CC_BREAK_IF(!PhysicsShape::init(body, Type::BOX)); + + cpShape* shape = cpBoxShapeNew(bodyInfo()->body, PhysicsHelper::float2cpfloat(size.width), PhysicsHelper::float2cpfloat(size.height)); + + CC_BREAK_IF(shape == nullptr); + + _info->add(shape); + addToBody(); + + return true; + } while (false); + + return false; +} + +// PhysicsShapeCircle +PhysicsShapePolygon* PhysicsShapePolygon::create(PhysicsBody* body, Point* points, int count, Point offset/* = Point(0, 0)*/) +{ + PhysicsShapePolygon* shape = new PhysicsShapePolygon(); + if (shape && shape->init(body, points, count, offset)) + { + return shape; + } + + CC_SAFE_DELETE(shape); + return nullptr; +} + +bool PhysicsShapePolygon::init(PhysicsBody* body, Point* points, int count, Point offset /*= Point(0, 0)*/) +{ + do + { + CC_BREAK_IF(!PhysicsShape::init(body, Type::POLYGEN)); + + cpVect* vecs = new cpVect[count]; + PhysicsHelper::points2cpvs(points, vecs, count); + cpShape* shape = cpPolyShapeNew(bodyInfo()->body, count, vecs, PhysicsHelper::point2cpv(offset)); + + CC_BREAK_IF(shape == nullptr); + + _info->add(shape); + addToBody(); + + return true; + } while (false); + + return false; +} + +// PhysicsShapeEdgeBox +PhysicsShapeEdgeBox* PhysicsShapeEdgeBox::create(PhysicsBody* body, Size size, float border/* = 1*/, Point offset/* = Point(0, 0)*/) +{ + PhysicsShapeEdgeBox* shape = new PhysicsShapeEdgeBox(); + if (shape && shape->init(body, size, border, offset)) + { + return shape; + } + + CC_SAFE_DELETE(shape); + return nullptr; +} + +bool PhysicsShapeEdgeBox::init(PhysicsBody* body, Size size, float border/* = 1*/, Point offset/*= Point(0, 0)*/) +{ + do + { + CC_BREAK_IF(!PhysicsShape::init(body, Type::EDGEBOX)); + + Point bodyPos = body->getPosition(); + + cpVect vec[4] = {}; + vec[0] = PhysicsHelper::point2cpv(Point(bodyPos.x-size.width/2+offset.x, bodyPos.y-size.height/2+offset.y)); + vec[1] = PhysicsHelper::point2cpv(Point(bodyPos.x+size.width/2+offset.x, bodyPos.y-size.height/2+offset.y)); + vec[2] = PhysicsHelper::point2cpv(Point(bodyPos.x+size.width/2+offset.x, bodyPos.y+size.height/2+offset.y)); + vec[3] = PhysicsHelper::point2cpv(Point(bodyPos.x-size.width/2+offset.x, bodyPos.y+size.height/2+offset.y)); + + int i = 0; + for (; i < 4; ++i) + { + cpShape* shape = cpSegmentShapeNew(bodyInfo()->body, vec[i], vec[(i+1)%4], + PhysicsHelper::float2cpfloat(border)); + CC_BREAK_IF(shape == nullptr); + cpShapeSetElasticity(shape, 1.0f); + cpShapeSetFriction(shape, 1.0f); + _info->add(shape); + } + CC_BREAK_IF(i < 4); + + addToBody(); + + return true; + } while (false); + + return false; +} + +// PhysicsShapeEdgeBox +PhysicsShapeEdgePolygon* PhysicsShapeEdgePolygon::create(PhysicsBody* body, Point* points, int count, float border/* = 1*/) +{ + PhysicsShapeEdgePolygon* shape = new PhysicsShapeEdgePolygon(); + if (shape && shape->init(body, points, count, border)) + { + return shape; + } + + CC_SAFE_DELETE(shape); + return nullptr; +} + +bool PhysicsShapeEdgePolygon::init(PhysicsBody* body, Point* points, int count, float border/* = 1*/) +{ + cpVect* vec = nullptr; + do + { + CC_BREAK_IF(!PhysicsShape::init(body, Type::EDGEPOLYGEN)); + + vec = new cpVect[count]; + PhysicsHelper::points2cpvs(points, vec, count); + + int i = 0; + for (; i < count; ++i) + { + cpShape* shape = cpSegmentShapeNew(bodyInfo()->body, vec[i], vec[(i+1)%count], + PhysicsHelper::float2cpfloat(border)); + CC_BREAK_IF(shape == nullptr); + cpShapeSetElasticity(shape, 1.0f); + cpShapeSetFriction(shape, 1.0f); + _info->add(shape); + } + CC_BREAK_IF(i < count); + + addToBody(); + + if (vec != nullptr) delete[] vec; + return true; + } while (false); + + if (vec != nullptr) delete[] vec; + + return false; +} + +// PhysicsShapeEdgeChain +PhysicsShapeEdgeChain* PhysicsShapeEdgeChain::create(PhysicsBody* body, Point* points, int count, float border/* = 1*/) +{ + PhysicsShapeEdgeChain* shape = new PhysicsShapeEdgeChain(); + if (shape && shape->init(body, points, count, border)) + { + return shape; + } + + CC_SAFE_DELETE(shape); + return nullptr; +} + +bool PhysicsShapeEdgeChain::init(PhysicsBody* body, Point* points, int count, float border/* = 1*/) +{ + cpVect* vec = nullptr; + do + { + CC_BREAK_IF(!PhysicsShape::init(body, Type::EDGECHAIN)); + + vec = new cpVect[count]; + PhysicsHelper::points2cpvs(points, vec, count); + + int i = 0; + for (; i < count - 1; ++i) + { + cpShape* shape = cpSegmentShapeNew(bodyInfo()->body, vec[i], vec[i+1], + PhysicsHelper::float2cpfloat(border)); + CC_BREAK_IF(shape == nullptr); + cpShapeSetElasticity(shape, 1.0f); + cpShapeSetFriction(shape, 1.0f); + _info->add(shape); + } + CC_BREAK_IF(i < count); + + addToBody(); + + if (vec != nullptr) delete[] vec; + return true; + } while (false); + + if (vec != nullptr) delete[] vec; + + return false; +} + + +#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) + +#endif + +NS_CC_END + +#endif // CC_USE_PHYSICS \ No newline at end of file diff --git a/cocos2dx/physics/CCPhysicsShape.h b/cocos2dx/physics/CCPhysicsShape.h new file mode 100644 index 0000000000..64049c2947 --- /dev/null +++ b/cocos2dx/physics/CCPhysicsShape.h @@ -0,0 +1,182 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsSetting.h" +#ifdef CC_USE_PHYSICS + +#ifndef __CCPHYSICS_SHAPE_H__ +#define __CCPHYSICS_SHAPE_H__ + +#include "cocoa/CCObject.h" +#include "cocoa/CCGeometry.h" + +NS_CC_BEGIN + +class PhysicsShapeInfo; +class PhysicsBody; +class PhysicsBodyInfo; + +class PhysicsShape : public Object +{ +public: + enum class Type + { + UNKNOWN, + CIRCLE, + BOX, + POLYGEN, + EDGESEGMENT, + EDGEBOX, + EDGEPOLYGEN, + EDGECHAIN, + }; + +public: + inline PhysicsBody* getBody(){ return _body; } + inline Type getType() { return _type; } + +protected: + bool init(PhysicsBody* body, Type type); + + /** + * PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody. + */ + PhysicsBodyInfo* bodyInfo() const; + + void addToBody(); + +protected: + PhysicsShape(); + virtual ~PhysicsShape(); + +protected: + PhysicsBody* _body; + PhysicsShapeInfo* _info; + Type _type; + + friend class PhysicsWorld; + friend class PhysicsBody; +}; + +class PhysicsShapeCircle : public PhysicsShape +{ +protected: + static PhysicsShapeCircle* create(PhysicsBody* body, float radius, Point offset = Point(0, 0)); + bool init(PhysicsBody* body, float radius, Point offset = Point(0, 0)); + +protected: + PhysicsShapeCircle(); + virtual ~PhysicsShapeCircle(); + + friend class PhysicsBody; +}; + +class PhysicsShapeBox : public PhysicsShape +{ +protected: + static PhysicsShapeBox* create(PhysicsBody* body, Size size, Point offset = Point(0, 0)); + bool init(PhysicsBody* body, Size size, Point offset = Point(0, 0)); + +protected: + PhysicsShapeBox(); + virtual ~PhysicsShapeBox(); + + friend class PhysicsBody; +}; + +class PhysicsShapePolygon : public PhysicsShape +{ +protected: + static PhysicsShapePolygon* create(PhysicsBody* body, Point* points, int count, Point offset = Point(0, 0)); + bool init(PhysicsBody* body, Point* points, int count, Point offset = Point(0, 0)); + +protected: + PhysicsShapePolygon(); + virtual ~PhysicsShapePolygon(); + + friend class PhysicsBody; +}; + +class PhysicsShapeEdgeSegment : public PhysicsShape +{ +protected: + static PhysicsShapeEdgeSegment* create(PhysicsBody* body, Point a, Point b, float border = 1); + bool init(PhysicsBody* body, Point a, Point b, float border = 1); + +protected: + PhysicsShapeEdgeSegment(); + virtual ~PhysicsShapeEdgeSegment(); + + friend class PhysicsBody; +}; + +class PhysicsShapeEdgeBox : public PhysicsShape +{ +public: + static PhysicsShapeEdgeBox* create(PhysicsBody* body, Size size, float border = 0, Point offset = Point(0, 0)); + +protected: + bool init(PhysicsBody* body, Size size, float border = 1, Point offset = Point(0, 0)); + +protected: + PhysicsShapeEdgeBox(); + virtual ~PhysicsShapeEdgeBox(); + + friend class PhysicsBody; +}; + +class PhysicsShapeEdgePolygon : public PhysicsShape +{ +public: + static PhysicsShapeEdgePolygon* create(PhysicsBody* body, Point* points, int count, float border = 1); + +protected: + bool init(PhysicsBody* body, Point* points, int count, float border = 1); + +protected: + PhysicsShapeEdgePolygon(); + virtual ~PhysicsShapeEdgePolygon(); + + friend class PhysicsBody; +}; + +class PhysicsShapeEdgeChain : public PhysicsShape +{ +public: + static PhysicsShapeEdgeChain* create(PhysicsBody* body, Point* points, int count, float border = 1); + +protected: + bool init(PhysicsBody* body, Point* points, int count, float border = 1); + +protected: + PhysicsShapeEdgeChain(); + virtual ~PhysicsShapeEdgeChain(); + + friend class PhysicsBody; +}; + +NS_CC_END +#endif // __CCPHYSICS_FIXTURE_H__ + +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsWorld.cpp b/cocos2dx/physics/CCPhysicsWorld.cpp index ccfc1ea788..78a6f3b806 100644 --- a/cocos2dx/physics/CCPhysicsWorld.cpp +++ b/cocos2dx/physics/CCPhysicsWorld.cpp @@ -23,51 +23,265 @@ ****************************************************************************/ #include "CCPhysicsWorld.h" +#ifdef CC_USE_PHYSICS + +#include "CCPhysicsBody.h" +#include "CCPhysicsShape.h" +#include "CCPhysicsContact.h" + +#include "chipmunk/CCPhysicsWorldInfo.h" +#include "Box2D/CCPhysicsWorldInfo.h" +#include "chipmunk/CCPhysicsBodyInfo.h" +#include "Box2D/CCPhysicsBodyInfo.h" +#include "chipmunk/CCPhysicsShapeInfo.h" +#include "Box2D/CCPhysicsShapeInfo.h" +#include "chipmunk/CCPhysicsContactInfo.h" +#include "Box2D/CCPhysicsContactInfo.h" +#include "chipmunk/CCPhysicsHelper.h" + +#include "draw_nodes/CCDrawNode.h" +#include "cocoa/CCArray.h" +#include "layers_scenes_transitions_nodes/CCScene.h" +#include "CCDirector.h" NS_CC_BEGIN #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) -class PhysicsWorldInfo +namespace PhysicsInnerCallbackFunctions { -public: - cpSpace* space; + int collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data) + { + PhysicsWorld* world = static_cast(data); + + CP_ARBITER_GET_SHAPES(arb, a, b); + + auto ita = PhysicsShapeInfo::map.find(a); + auto itb = PhysicsShapeInfo::map.find(b); + CC_ASSERT(ita != PhysicsShapeInfo::map.end() && itb != PhysicsShapeInfo::map.end()); + + PhysicsContact* contact = PhysicsContact::create(ita->second->shape, itb->second->shape); + arb->data = contact; + + return world->collisionBeginCallback(*static_cast(arb->data)); + } -public: - PhysicsWorldInfo(); - ~PhysicsWorldInfo(); -}; - -PhysicsWorldInfo::PhysicsWorldInfo() -{ - space = cpSpaceNew(); -} - -PhysicsWorldInfo::~PhysicsWorldInfo() -{ - cpSpaceFree(space); + int collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data) + { + PhysicsWorld* world = static_cast(data); + return world->collisionPreSolveCallback(*static_cast(arb->data), + PhysicsContactPreSolve()); + } + + void collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data) + { + PhysicsWorld* world = static_cast(data); + world->collisionPostSolveCallback(*static_cast(arb->data), + PhysicsContactPostSolve()); + } + + void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data) + { + PhysicsWorld* world = static_cast(data); + PhysicsContact* contact = static_cast(arb->data); + + world->collisionSeparateCallback(*contact); + + delete contact; + } } bool PhysicsWorld::init() { - _worldInfo = new PhysicsWorldInfo(); + _info = new PhysicsWorldInfo(); - cpSpaceSetGravity(_worldInfo->space, cpv(_gravity.x, _gravity.y)); + cpSpaceSetGravity(_info->space, PhysicsHelper::point2cpv(_gravity)); + + cpSpaceSetDefaultCollisionHandler(_info->space, + PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc, + PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc, + PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc, + PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc, + this); return true; } +void PhysicsWorld::addShape(PhysicsShape* shape) +{ + for (auto it = shape->_info->shapes.begin(); it != shape->_info->shapes.end(); it++) + { + if (cpBodyIsStatic(shape->getBody()->_info->body)) + { + cpSpaceAddStaticShape(_info->space, *it); + }else + { + cpSpaceAddShape(_info->space, *it); + } + } +} + void PhysicsWorld::addChild(PhysicsBody* body) { + auto shapes = body->getShapes(); + // add body to space + if (body->isDynamic()) + { + cpSpaceAddBody(_info->space, body->_info->body); + } + + // add shapes to space + for (auto it = shapes.begin(); it != shapes.end(); it++) + { + addShape(*it); + } + + if (_bodys == nullptr) + { + _bodys = Array::create(body, NULL); + _bodys->retain(); + }else + { + _bodys->addObject(body); + } +} + +void PhysicsWorld::update(float delta) +{ + cpSpaceStep(_info->space, delta); + + if (_drawNode) + { + _drawNode->removeFromParent(); + _drawNode = nullptr; + } + + if (_debugDraw) + { + debugDraw(); + } +} + +void PhysicsWorld::debugDraw() +{ + if (_debugDraw && _bodys != nullptr) + { + _drawNode= DrawNode::create(); + + Object* child = nullptr; + CCARRAY_FOREACH(_bodys, child) + { + PhysicsBody* body = dynamic_cast(child); + + std::vector shapes = body->getShapes(); + + for (auto it = shapes.begin(); it != shapes.end(); ++it) + { + drawWithShape(_drawNode, *it); + } + } + + if (_scene) + { + _scene->addChild(_drawNode); + } + } +} + +void PhysicsWorld::setScene(Scene *scene) +{ + _scene = scene; + scene->retain(); +} + +void PhysicsWorld::drawWithShape(DrawNode* node, PhysicsShape* shape) +{ + for (auto it = shape->_info->shapes.begin(); it != shape->_info->shapes.end(); ++it) + { + cpShape *shape = *it; + + switch ((*it)->klass_private->type) + { + case CP_CIRCLE_SHAPE: + { + float radius = PhysicsHelper::cpfloat2float(cpCircleShapeGetRadius(shape)); + Point centre = PhysicsHelper::cpv2point(cpBodyGetPos(cpShapeGetBody(shape))) + + PhysicsHelper::cpv2point(cpCircleShapeGetOffset(shape)); + + Point seg[4] = {}; + seg[0] = Point(centre.x - radius, centre.y - radius); + seg[1] = Point(centre.x - radius, centre.y + radius); + seg[2] = Point(centre.x + radius, centre.y + radius); + seg[3] = Point(centre.x + radius, centre.y - radius); + node->drawPolygon(seg, 4, Color4F(), 1, Color4F(1, 0, 0, 1)); + break; + } + case CP_SEGMENT_SHAPE: + { + cpSegmentShape *seg = (cpSegmentShape *)shape; + node->drawSegment(PhysicsHelper::cpv2point(seg->ta), + PhysicsHelper::cpv2point(seg->tb), + PhysicsHelper::cpfloat2float(seg->r==0 ? 1 : seg->r), Color4F(1, 0, 0, 1)); + break; + } + case CP_POLY_SHAPE: + { + cpPolyShape* poly = (cpPolyShape*)shape; + int num = poly->numVerts; + Point* seg = new Point[num]; + + PhysicsHelper::cpvs2points(poly->tVerts, seg, num); + + node->drawPolygon(seg, num, Color4F(1, 0, 0, 0.3), 1, Color4F(1, 0, 0, 1)); + + delete[] seg; + break; + } + default: + break; + } + } +} + +int PhysicsWorld::collisionBeginCallback(const PhysicsContact& contact) +{ + if (_delegate) + { + return _delegate->onContactBegin(contact); + } + + return true; +} + +int PhysicsWorld::collisionPreSolveCallback(const PhysicsContact& contact, const PhysicsContactPreSolve& solve) +{ + if (_delegate) + { + return _delegate->onContactPreSolve(contact, solve); + } + + return true; +} + +void PhysicsWorld::collisionPostSolveCallback(const PhysicsContact& contact, const PhysicsContactPostSolve& solve) +{ + if (_delegate) + { + _delegate->onContactPostSove(contact, solve); + } +} + +void PhysicsWorld::collisionSeparateCallback(const PhysicsContact& contact) +{ + if (_delegate) + { + _delegate->onContactEnd(contact); + } } #elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) -struct PhysicsInfo -{ - -}; #endif PhysicsWorld* PhysicsWorld::create() @@ -83,16 +297,25 @@ PhysicsWorld* PhysicsWorld::create() } PhysicsWorld::PhysicsWorld() -: _gravity(Point(0, -9.8)) -, _speed(1.0) -, _worldInfo(nullptr) +: _gravity(Point(0.0f, -98.0f)) +, _speed(1.0f) +, _info(nullptr) +, _delegate(nullptr) +, _bodys(nullptr) +, _scene(nullptr) +, _debugDraw(false) +, _drawNode(nullptr) { } PhysicsWorld::~PhysicsWorld() { - CC_SAFE_DELETE(_worldInfo); + CC_SAFE_DELETE(_info); + CC_SAFE_RELEASE(_bodys); + CC_SAFE_RELEASE(_scene); } NS_CC_END + +#endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index 5bf807c159..1cb2530351 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -36,10 +36,26 @@ NS_CC_BEGIN class PhysicsBody; class PhysicsJoint; class PhysicsWorldInfo; +class PhysicsShape; +class PhysicsContact; +class PhysicsContactPreSolve; +class PhysicsContactPostSolve; class PhysicsContactDelegate; +class Array; class Sprite; class Scene; +class DrawNode; + +namespace PhysicsInnerCallbackFunctions +{ +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + int collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); + int collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + void collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); +#endif +} class PhysicsWorld { @@ -53,21 +69,46 @@ public: Array* getBodysInRect(Rect rect) const; Array* getAllBody() const; - void registerContactDelegate(PhysicsContactDelegate* delegate); + inline void registerContactDelegate(PhysicsContactDelegate* delegate) { _delegate = delegate; } + inline void unregisterContactDelegate() { _delegate = nullptr; } inline Point getGravity() { return _gravity; } inline void setGravity(Point gravity) { _gravity = gravity; } + inline bool getDebugDraw() { return _debugDraw; } + inline void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; } + protected: static PhysicsWorld* create(); bool init(); + + void setScene(Scene* scene); + virtual void addChild(PhysicsBody* body); + virtual void addShape(PhysicsShape* shape); + virtual void update(float delta); + + virtual void debugDraw(); + virtual void drawWithShape(DrawNode* node, PhysicsShape* shape); + + + virtual int collisionBeginCallback(const PhysicsContact& contact); + virtual int collisionPreSolveCallback(const PhysicsContact& contact, const PhysicsContactPreSolve& solve); + virtual void collisionPostSolveCallback(const PhysicsContact& contact, const PhysicsContactPostSolve& solve); + virtual void collisionSeparateCallback(const PhysicsContact& contact); protected: Point _gravity; float _speed; + PhysicsWorldInfo* _info; + PhysicsContactDelegate* _delegate; - PhysicsWorldInfo* _worldInfo; + + Array* _bodys; + Scene* _scene; + + bool _debugDraw; + DrawNode* _drawNode; protected: PhysicsWorld(); @@ -75,6 +116,14 @@ protected: friend class Sprite; friend class Scene; + friend class PhysicsBody; + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + friend int PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); + friend int PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + friend void PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + friend void PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); +#endif }; NS_CC_END diff --git a/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.cpp b/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.cpp new file mode 100644 index 0000000000..4627c02499 --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsBodyInfo.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +NS_CC_BEGIN + +PhysicsBodyInfo::PhysicsBodyInfo() +: body(nullptr) +{ +} + +PhysicsBodyInfo::~PhysicsBodyInfo() +{ + if (body) cpBodyFree(body); +} + +Clonable* PhysicsBodyInfo::clone() const +{ + +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/CCPhysicsContactDelegate.h b/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.h similarity index 69% rename from cocos2dx/physics/CCPhysicsContactDelegate.h rename to cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.h index a371b6e044..796f384584 100644 --- a/cocos2dx/physics/CCPhysicsContactDelegate.h +++ b/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.h @@ -22,31 +22,31 @@ THE SOFTWARE. ****************************************************************************/ -#include "CCPhysicsSetting.h" -#ifdef CC_USE_PHYSICS - -#ifndef __CCPHYSICS_CONTACTDELEGATE_H__ -#define __CCPHYSICS_CONTACTDELEGATE_H__ +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +#ifndef __CCPHYSICS_BODY_INFO_H__ +#define __CCPHYSICS_BODY_INFO_H__ +#include "platform/CCPlatformMacros.h" #include "cocoa/CCObject.h" -#include "cocoa/CCGeometry.h" NS_CC_BEGIN -class PhysicsBody; - -class PhysicsContactDelegate +class PhysicsBodyInfo : public Clonable { public: - PhysicsContactDelegate(); - virtual ~PhysicsContactDelegate(); + cpBody* body; -public: - virtual void onContactBegin(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint) = 0; - virtual void onContactEnd(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint) = 0; +private: + PhysicsBodyInfo(); + ~PhysicsBodyInfo(); + + Clonable* clone() const override; + + friend class PhysicsBody; }; NS_CC_END -#endif //__CCPHYSICS_CONTACTDELEGATE_H__ +#endif // __CCPHYSICS_BODY_INFO_H__ -#endif // CC_USE_PHYSICS +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.cpp b/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.cpp new file mode 100644 index 0000000000..53b4f29b14 --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.cpp @@ -0,0 +1,39 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsContactInfo.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +NS_CC_BEGIN + +PhysicsContactInfo::PhysicsContactInfo(PhysicsContact* contact) +: contact(contact) +{ +} + +PhysicsContactInfo::~PhysicsContactInfo() +{ +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.h b/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.h new file mode 100644 index 0000000000..b0d123ae21 --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.h @@ -0,0 +1,49 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + +#ifndef __CCPHYSICS_CONTACT_INFO_H__ +#define __CCPHYSICS_CONTACT_INFO_H__ +#include "platform/CCPlatformMacros.h" +NS_CC_BEGIN + +class PhysicsContact; +class PhysicsContactInfo +{ +public: + PhysicsContact* contact; + +private: + PhysicsContactInfo(PhysicsContact* contact); + ~PhysicsContactInfo(); + + friend class PhysicsContact; +}; + +NS_CC_END +#endif // __CCPHYSICS_WORLD_INFO_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/CCPhysicsHelper.h b/cocos2dx/physics/chipmunk/CCPhysicsHelper.h new file mode 100644 index 0000000000..07508e9b13 --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsHelper.h @@ -0,0 +1,68 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + +#ifndef __CCPHYSICS_HELPER_H__ +#define __CCPHYSICS_HELPER_H__ + +#include "platform/CCPlatformMacros.h" +#include "cocoa/CCGeometry.h" + +NS_CC_BEGIN + +class PhysicsHelper +{ +public: + static Point cpv2point(const cpVect& vec) { return Point(vec.x, vec.y); } + static cpVect point2cpv(const Point& point) { return cpv(point.x, point.y); } + static Size cpv2size(const cpVect& vec) { return Size(vec.x, vec.y); } + static cpVect size2cpv(const Size& size) { return cpv(size.width, size.height); } + static float cpfloat2float(cpFloat f) { return f; } + static cpFloat float2cpfloat(float f) { return f; } + + static void cpvs2points(const cpVect* cpvs, Point* points, int count) + { + for (int i = 0; i < count; ++i) + { + points[i] = cpv2point(cpvs[i]); + } + } + + static cpVect* points2cpvs(const Point* points, cpVect* cpvs, int count) + { + for (int i = 0; i < count; ++i) + { + cpvs[i] = point2cpv(points[i]); + } + + return cpvs; + } +}; + +NS_CC_END +#endif // __CCPHYSICS_HELPER_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.cpp b/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.cpp new file mode 100644 index 0000000000..aca28aa0fb --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsJointInfo.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +NS_CC_BEGIN + +PhysicsJointInfo::PhysicsJointInfo() +: joint(nullptr) +{ +} + +PhysicsJointInfo::~PhysicsJointInfo() +{ + if (joint) + { + cpConstraintFree(joint); + } +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.h b/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.h new file mode 100644 index 0000000000..4174c866f6 --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.h @@ -0,0 +1,50 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + +#ifndef __CCPHYSICS_JOINT_INFO_H__ +#define __CCPHYSICS_JOINT_INFO_H__ + +#include "platform/CCPlatformMacros.h" + +NS_CC_BEGIN + +class PhysicsJointInfo +{ +public: + cpConstraint* joint; + +private: + PhysicsJointInfo(); + ~PhysicsJointInfo(); + + friend class PhysicsJoint; +}; + +NS_CC_END +#endif // __CCPHYSICS_SHAPE_INFO_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.cpp b/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.cpp new file mode 100644 index 0000000000..f22d7a3267 --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsShapeInfo.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +NS_CC_BEGIN + +std::map PhysicsShapeInfo::map; + +PhysicsShapeInfo::PhysicsShapeInfo(PhysicsShape* shape) +: shape(shape) +{ +} + +PhysicsShapeInfo::~PhysicsShapeInfo() +{ + for (auto it = shapes.begin(); it != shapes.end(); it++) + { + cpShapeFree(*it); + + auto mit = map.find(*it); + if (mit != map.end()) map.erase(*it); + } +} + +void PhysicsShapeInfo::add(cpShape* shape) +{ + if (shape == nullptr) return; + + shapes.push_back(shape); + map.insert(std::pair(shape, this)); +} + +void PhysicsShapeInfo::remove(cpShape* shape) +{ + if (shape == nullptr) return; + + auto it = find(shapes.begin(), shapes.end(), shape); + if (it != shapes.end()) + { + shapes.erase(it); + + auto mit = map.find(shape); + if (mit != map.end()) map.erase(mit); + } +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.h b/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.h new file mode 100644 index 0000000000..7114bd3961 --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.h @@ -0,0 +1,61 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + +#ifndef __CCPHYSICS_SHAPE_INFO_H__ +#define __CCPHYSICS_SHAPE_INFO_H__ +#include + +#include "platform/CCPlatformMacros.h" +#include + +NS_CC_BEGIN + +class PhysicsShape; + +class PhysicsShapeInfo +{ +public: + void add(cpShape* shape); + void remove(cpShape* shape); + void removeall(); + +public: + std::vector shapes; + static std::map map; + PhysicsShape* shape; + +private: + PhysicsShapeInfo(PhysicsShape* shape); + ~PhysicsShapeInfo(); + + friend class PhysicsShape; +}; + +NS_CC_END +#endif // __CCPHYSICS_SHAPE_INFO_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.cpp b/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.cpp new file mode 100644 index 0000000000..57f601ead7 --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.cpp @@ -0,0 +1,40 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsWorldInfo.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +NS_CC_BEGIN + +PhysicsWorldInfo::PhysicsWorldInfo() +{ + space = cpSpaceNew(); +} + +PhysicsWorldInfo::~PhysicsWorldInfo() +{ + cpSpaceFree(space); +} + +NS_CC_END +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.h b/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.h new file mode 100644 index 0000000000..a1f1e66342 --- /dev/null +++ b/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.h @@ -0,0 +1,48 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "../CCPhysicsSetting.h" +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + +#ifndef __CCPHYSICS_WORLD_INFO_H__ +#define __CCPHYSICS_WORLD_INFO_H__ +#include "platform/CCPlatformMacros.h" +NS_CC_BEGIN + +class PhysicsWorldInfo +{ +public: + cpSpace* space; + +private: + PhysicsWorldInfo(); + ~PhysicsWorldInfo(); + + friend class PhysicsWorld; +}; + +NS_CC_END +#endif // __CCPHYSICS_WORLD_INFO_H__ + +#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK diff --git a/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c b/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c new file mode 100644 index 0000000000..38b06af1a0 --- /dev/null +++ b/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c @@ -0,0 +1,446 @@ +/* Copyright (c) 2007 Scott Lembcke + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +#ifdef __APPLE__ + #include "OpenGL/gl.h" + #include "OpenGL/glu.h" + #include +#else + #ifdef WIN32 + #include + #endif + + #include + #include + #include +#endif + +#include "chipmunk_private.h" +#include "ChipmunkDebugDraw.h" + +/* + IMPORTANT - READ ME! + + This file sets up a simple interface that the individual demos can use to get + a Chipmunk space running and draw what's in it. In order to keep the Chipmunk + examples clean and simple, they contain no graphics code. All drawing is done + by accessing the Chipmunk structures at a very low level. It is NOT + recommended to write a game or application this way as it does not scale + beyond simple shape drawing and is very dependent on implementation details + about Chipmunk which may change with little to no warning. +*/ + +const Color LINE_COLOR = {200.0/255.0, 210.0/255.0, 230.0/255.0, 1.0}; +const Color CONSTRAINT_COLOR = {0.0, 0.75, 0.0, 1.0}; +const float SHAPE_ALPHA = 1.0; + +float ChipmunkDebugDrawPointLineScale = 1.0; + +static Color +ColorFromHash(cpHashValue hash, float alpha) +{ + unsigned long val = (unsigned long)hash; + + // scramble the bits up using Robert Jenkins' 32 bit integer hash function + val = (val+0x7ed55d16) + (val<<12); + val = (val^0xc761c23c) ^ (val>>19); + val = (val+0x165667b1) + (val<<5); + val = (val+0xd3a2646c) ^ (val<<9); + val = (val+0xfd7046c5) + (val<<3); + val = (val^0xb55a4f09) ^ (val>>16); + + GLfloat r = (val>>0) & 0xFF; + GLfloat g = (val>>8) & 0xFF; + GLfloat b = (val>>16) & 0xFF; + + GLfloat max = cpfmax(cpfmax(r, g), b); + GLfloat min = cpfmin(cpfmin(r, g), b); + GLfloat intensity = 0.75; + + // Saturate and scale the color + if(min == max){ + return RGBAColor(intensity, 0.0, 0.0, alpha); + } else { + GLfloat coef = alpha*intensity/(max - min); + return RGBAColor( + (r - min)*coef, + (g - min)*coef, + (b - min)*coef, + alpha + ); + } +} + +static inline void +glColor_from_color(Color color){ + glColor4fv((GLfloat *)&color); +} + +static Color +ColorForShape(cpShape *shape) +{ + if(cpShapeGetSensor(shape)){ + return LAColor(1, 0); + } else { + cpBody *body = shape->body; + + if(cpBodyIsSleeping(body)){ + return LAColor(0.2, 1); + } else if(body->node.idleTime > shape->space->sleepTimeThreshold) { + return LAColor(0.66, 1); + } else { + return ColorFromHash(shape->hashid, SHAPE_ALPHA); + } + } +} + +static const GLfloat circleVAR[] = { + 0.0000f, 1.0000f, + 0.2588f, 0.9659f, + 0.5000f, 0.8660f, + 0.7071f, 0.7071f, + 0.8660f, 0.5000f, + 0.9659f, 0.2588f, + 1.0000f, 0.0000f, + 0.9659f, -0.2588f, + 0.8660f, -0.5000f, + 0.7071f, -0.7071f, + 0.5000f, -0.8660f, + 0.2588f, -0.9659f, + 0.0000f, -1.0000f, + -0.2588f, -0.9659f, + -0.5000f, -0.8660f, + -0.7071f, -0.7071f, + -0.8660f, -0.5000f, + -0.9659f, -0.2588f, + -1.0000f, -0.0000f, + -0.9659f, 0.2588f, + -0.8660f, 0.5000f, + -0.7071f, 0.7071f, + -0.5000f, 0.8660f, + -0.2588f, 0.9659f, + 0.0000f, 1.0000f, + 0.0f, 0.0f, // For an extra line to see the rotation. +}; +static const int circleVAR_count = sizeof(circleVAR)/sizeof(GLfloat)/2; + +void ChipmunkDebugDrawCircle(cpVect center, cpFloat angle, cpFloat radius, Color lineColor, Color fillColor) +{ + glVertexPointer(2, GL_FLOAT, 0, circleVAR); + + glPushMatrix(); { + glTranslatef(center.x, center.y, 0.0f); + glRotatef(angle*180.0f/M_PI, 0.0f, 0.0f, 1.0f); + glScalef(radius, radius, 1.0f); + + if(fillColor.a > 0){ + glColor_from_color(fillColor); + glDrawArrays(GL_TRIANGLE_FAN, 0, circleVAR_count - 1); + } + + if(lineColor.a > 0){ + glColor_from_color(lineColor); + glDrawArrays(GL_LINE_STRIP, 0, circleVAR_count); + } + } glPopMatrix(); +} + +static const GLfloat pillVAR[] = { + 0.0000f, 1.0000f, 1.0f, + 0.2588f, 0.9659f, 1.0f, + 0.5000f, 0.8660f, 1.0f, + 0.7071f, 0.7071f, 1.0f, + 0.8660f, 0.5000f, 1.0f, + 0.9659f, 0.2588f, 1.0f, + 1.0000f, 0.0000f, 1.0f, + 0.9659f, -0.2588f, 1.0f, + 0.8660f, -0.5000f, 1.0f, + 0.7071f, -0.7071f, 1.0f, + 0.5000f, -0.8660f, 1.0f, + 0.2588f, -0.9659f, 1.0f, + 0.0000f, -1.0000f, 1.0f, + + 0.0000f, -1.0000f, 0.0f, + -0.2588f, -0.9659f, 0.0f, + -0.5000f, -0.8660f, 0.0f, + -0.7071f, -0.7071f, 0.0f, + -0.8660f, -0.5000f, 0.0f, + -0.9659f, -0.2588f, 0.0f, + -1.0000f, -0.0000f, 0.0f, + -0.9659f, 0.2588f, 0.0f, + -0.8660f, 0.5000f, 0.0f, + -0.7071f, 0.7071f, 0.0f, + -0.5000f, 0.8660f, 0.0f, + -0.2588f, 0.9659f, 0.0f, + 0.0000f, 1.0000f, 0.0f, +}; +static const int pillVAR_count = sizeof(pillVAR)/sizeof(GLfloat)/3; + +void ChipmunkDebugDrawSegment(cpVect a, cpVect b, Color color) +{ + GLfloat verts[] = { + a.x, a.y, + b.x, b.y, + }; + + glVertexPointer(2, GL_FLOAT, 0, verts); + glColor_from_color(color); + glDrawArrays(GL_LINES, 0, 2); +} + +void ChipmunkDebugDrawFatSegment(cpVect a, cpVect b, cpFloat radius, Color lineColor, Color fillColor) +{ + if(radius){ + glVertexPointer(3, GL_FLOAT, 0, pillVAR); + glPushMatrix(); { + cpVect d = cpvsub(b, a); + cpVect r = cpvmult(d, radius/cpvlength(d)); + + const GLfloat matrix[] = { + r.x, r.y, 0.0f, 0.0f, + -r.y, r.x, 0.0f, 0.0f, + d.x, d.y, 0.0f, 0.0f, + a.x, a.y, 0.0f, 1.0f, + }; + glMultMatrixf(matrix); + + if(fillColor.a > 0){ + glColor_from_color(fillColor); + glDrawArrays(GL_TRIANGLE_FAN, 0, pillVAR_count); + } + + if(lineColor.a > 0){ + glColor_from_color(lineColor); + glDrawArrays(GL_LINE_LOOP, 0, pillVAR_count); + } + } glPopMatrix(); + } else { + ChipmunkDebugDrawSegment(a, b, lineColor); + } +} + +void ChipmunkDebugDrawPolygon(int count, cpVect *verts, Color lineColor, Color fillColor) +{ +#if CP_USE_DOUBLES + glVertexPointer(2, GL_DOUBLE, 0, verts); +#else + glVertexPointer(2, GL_FLOAT, 0, verts); +#endif + + if(fillColor.a > 0){ + glColor_from_color(fillColor); + glDrawArrays(GL_TRIANGLE_FAN, 0, count); + } + + if(lineColor.a > 0){ + glColor_from_color(lineColor); + glDrawArrays(GL_LINE_LOOP, 0, count); + } +} + +void ChipmunkDebugDrawPoints(cpFloat size, int count, cpVect *verts, Color color) +{ +#if CP_USE_DOUBLES + glVertexPointer(2, GL_DOUBLE, 0, verts); +#else + glVertexPointer(2, GL_FLOAT, 0, verts); +#endif + + glPointSize(size*ChipmunkDebugDrawPointLineScale); + glColor_from_color(color); + glDrawArrays(GL_POINTS, 0, count); +} + +void ChipmunkDebugDrawBB(cpBB bb, Color color) +{ + cpVect verts[] = { + cpv(bb.l, bb.b), + cpv(bb.l, bb.t), + cpv(bb.r, bb.t), + cpv(bb.r, bb.b), + }; + ChipmunkDebugDrawPolygon(4, verts, color, LAColor(0, 0)); +} + +static void +drawShape(cpShape *shape, void *unused) +{ + cpBody *body = shape->body; + Color color = ColorForShape(shape); + + switch(shape->klass->type){ + case CP_CIRCLE_SHAPE: { + cpCircleShape *circle = (cpCircleShape *)shape; + ChipmunkDebugDrawCircle(circle->tc, body->a, circle->r, LINE_COLOR, color); + break; + } + case CP_SEGMENT_SHAPE: { + cpSegmentShape *seg = (cpSegmentShape *)shape; + ChipmunkDebugDrawFatSegment(seg->ta, seg->tb, seg->r, LINE_COLOR, color); + break; + } + case CP_POLY_SHAPE: { + cpPolyShape *poly = (cpPolyShape *)shape; + ChipmunkDebugDrawPolygon(poly->numVerts, poly->tVerts, LINE_COLOR, color); + break; + } + default: break; + } +} + +void ChipmunkDebugDrawShape(cpShape *shape) +{ + drawShape(shape, NULL); +} + +void ChipmunkDebugDrawShapes(cpSpace *space) +{ + cpSpaceEachShape(space, drawShape, NULL); +} + +static const GLfloat springVAR[] = { + 0.00f, 0.0f, + 0.20f, 0.0f, + 0.25f, 3.0f, + 0.30f,-6.0f, + 0.35f, 6.0f, + 0.40f,-6.0f, + 0.45f, 6.0f, + 0.50f,-6.0f, + 0.55f, 6.0f, + 0.60f,-6.0f, + 0.65f, 6.0f, + 0.70f,-3.0f, + 0.75f, 6.0f, + 0.80f, 0.0f, + 1.00f, 0.0f, +}; +static const int springVAR_count = sizeof(springVAR)/sizeof(GLfloat)/2; + +static void +drawSpring(cpDampedSpring *spring, cpBody *body_a, cpBody *body_b) +{ + cpVect a = cpvadd(body_a->p, cpvrotate(spring->anchr1, body_a->rot)); + cpVect b = cpvadd(body_b->p, cpvrotate(spring->anchr2, body_b->rot)); + + cpVect points[] = {a, b}; + ChipmunkDebugDrawPoints(5, 2, points, CONSTRAINT_COLOR); + + cpVect delta = cpvsub(b, a); + + glVertexPointer(2, GL_FLOAT, 0, springVAR); + glPushMatrix(); { + GLfloat x = a.x; + GLfloat y = a.y; + GLfloat cos = delta.x; + GLfloat sin = delta.y; + GLfloat s = 1.0f/cpvlength(delta); + + const GLfloat matrix[] = { + cos, sin, 0.0f, 0.0f, + -sin*s, cos*s, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + x, y, 0.0f, 1.0f, + }; + + glMultMatrixf(matrix); + glDrawArrays(GL_LINE_STRIP, 0, springVAR_count); + } glPopMatrix(); +} + +static void +drawConstraint(cpConstraint *constraint, void *unused) +{ + cpBody *body_a = constraint->a; + cpBody *body_b = constraint->b; + + const cpConstraintClass *klass = constraint->klass; + if(klass == cpPinJointGetClass()){ + cpPinJoint *joint = (cpPinJoint *)constraint; + + cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot)); + cpVect b = cpvadd(body_b->p, cpvrotate(joint->anchr2, body_b->rot)); + + cpVect points[] = {a, b}; + ChipmunkDebugDrawPoints(5, 2, points, CONSTRAINT_COLOR); + ChipmunkDebugDrawSegment(a, b, CONSTRAINT_COLOR); + } else if(klass == cpSlideJointGetClass()){ + cpSlideJoint *joint = (cpSlideJoint *)constraint; + + cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot)); + cpVect b = cpvadd(body_b->p, cpvrotate(joint->anchr2, body_b->rot)); + + cpVect points[] = {a, b}; + ChipmunkDebugDrawPoints(5, 2, points, CONSTRAINT_COLOR); + ChipmunkDebugDrawSegment(a, b, CONSTRAINT_COLOR); + } else if(klass == cpPivotJointGetClass()){ + cpPivotJoint *joint = (cpPivotJoint *)constraint; + + cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot)); + cpVect b = cpvadd(body_b->p, cpvrotate(joint->anchr2, body_b->rot)); + + cpVect points[] = {a, b}; + ChipmunkDebugDrawPoints(10, 2, points, CONSTRAINT_COLOR); + } else if(klass == cpGrooveJointGetClass()){ + cpGrooveJoint *joint = (cpGrooveJoint *)constraint; + + cpVect a = cpvadd(body_a->p, cpvrotate(joint->grv_a, body_a->rot)); + cpVect b = cpvadd(body_a->p, cpvrotate(joint->grv_b, body_a->rot)); + cpVect c = cpvadd(body_b->p, cpvrotate(joint->anchr2, body_b->rot)); + + ChipmunkDebugDrawPoints(5, 1, &c, CONSTRAINT_COLOR); + ChipmunkDebugDrawSegment(a, b, CONSTRAINT_COLOR); + } else if(klass == cpDampedSpringGetClass()){ + drawSpring((cpDampedSpring *)constraint, body_a, body_b); + } +} + +void ChipmunkDebugDrawConstraint(cpConstraint *constraint) +{ + drawConstraint(constraint, NULL); +} + +void ChipmunkDebugDrawConstraints(cpSpace *space) +{ + cpSpaceEachConstraint(space, drawConstraint, NULL); +} + +void ChipmunkDebugDrawCollisionPoints(cpSpace *space) +{ + cpArray *arbiters = space->arbiters; + + glColor3f(1.0f, 0.0f, 0.0f); + glPointSize(4.0f*ChipmunkDebugDrawPointLineScale); + + glBegin(GL_POINTS); { + for(int i=0; inum; i++){ + cpArbiter *arb = (cpArbiter*)arbiters->arr[i]; + + for(int j=0; jnumContacts; j++){ + cpVect v = arb->contacts[j].p; + glVertex2f(v.x, v.y); + } + } + } glEnd(); +} diff --git a/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h b/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h new file mode 100644 index 0000000000..9cc0a722fd --- /dev/null +++ b/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2007 Scott Lembcke + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +typedef struct Color { + float r, g, b, a; +} Color; + +static inline Color RGBAColor(float r, float g, float b, float a){ + Color color = {r, g, b, a}; + return color; +} + +static inline Color LAColor(float l, float a){ + Color color = {l, l, l, a}; + return color; +} + +extern float ChipmunkDebugDrawPointLineScale; + +void ChipmunkDebugDrawCircle(cpVect center, cpFloat angle, cpFloat radius, Color lineColor, Color fillColor); +void ChipmunkDebugDrawSegment(cpVect a, cpVect b, Color color); +void ChipmunkDebugDrawFatSegment(cpVect a, cpVect b, cpFloat radius, Color lineColor, Color fillColor); +void ChipmunkDebugDrawPolygon(int count, cpVect *verts, Color lineColor, Color fillColor); +void ChipmunkDebugDrawPoints(cpFloat size, int count, cpVect *verts, Color color); +void ChipmunkDebugDrawBB(cpBB bb, Color color); + +void ChipmunkDebugDrawConstraint(cpConstraint *constraint); +void ChipmunkDebugDrawShape(cpShape *shape); + +void ChipmunkDebugDrawShapes(cpSpace *space); +void ChipmunkDebugDrawConstraints(cpSpace *space); +void ChipmunkDebugDrawCollisionPoints(cpSpace *space); diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index ed8f0460c3..80c6fd696c 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -296,13 +296,18 @@ Sprite* Sprite::initWithCGImage(CGImageRef pImage, const char *pszKey) Sprite::Sprite(void) : _shouldBeHidden(false) , _texture(nullptr) +#ifdef CC_USE_PHYSICS , _physicsBody(nullptr) +#endif { } Sprite::~Sprite(void) { CC_SAFE_RELEASE(_texture); +#ifdef CC_USE_PHYSICS + CC_SAFE_RELEASE(_physicsBody); +#endif } void Sprite::setTextureRect(const Rect& rect) @@ -447,16 +452,6 @@ void Sprite::setTextureCoords(Rect rect) } } -void Sprite::setPhysicsBody(PhysicsBody* body) -{ - _physicsBody = body; -} - -PhysicsBody* Sprite::getPhysicsBody() const -{ - return _physicsBody; -} - void Sprite::updateTransform(void) { CCASSERT(_batchNode, "updateTransform is only valid when Sprite is being rendered using an SpriteBatchNode"); @@ -795,12 +790,27 @@ void Sprite::setPosition(const Point& pos) { Node::setPosition(pos); SET_DIRTY_RECURSIVELY(); + +#ifdef CC_USE_PHYSICS + if (_physicsBody) + { + _physicsBody->setPosition(pos); + } +#endif } -void Sprite::setRotation(float fRotation) +void Sprite::setRotation(float rotation) { - Node::setRotation(fRotation); + Node::setRotation(rotation); + SET_DIRTY_RECURSIVELY(); + +#ifdef CC_USE_PHYSICS + if (_physicsBody) + { + _physicsBody->setRotation(rotation); + } +#endif } void Sprite::setRotationX(float fRotationX) @@ -897,6 +907,33 @@ bool Sprite::isFlipY(void) const return _flipY; } +#ifdef CC_USE_PHYSICS +void Sprite::setPhysicsBody(PhysicsBody* body) +{ + _physicsBody = body; + _physicsBody->retain(); + _physicsBody->setPosition(getPosition()); + _physicsBody->setRotation(getRotation()); +} + +PhysicsBody* Sprite::getPhysicsBody() const +{ + return _physicsBody; +} + +void Sprite::visit() +{ + if (_physicsBody) + { + Node::setPosition(_physicsBody->getPosition()); + Node::setRotation(_physicsBody->getRotation()); + SET_DIRTY_RECURSIVELY(); + } + + Node::visit(); +} +#endif //CC_USE_PHYSICS + // // RGBA protocol // diff --git a/cocos2dx/sprite_nodes/CCSprite.h b/cocos2dx/sprite_nodes/CCSprite.h index 4d4d0e7bdf..6f66e630f6 100644 --- a/cocos2dx/sprite_nodes/CCSprite.h +++ b/cocos2dx/sprite_nodes/CCSprite.h @@ -454,6 +454,8 @@ public: * get the PhysicsBody the sprite have */ PhysicsBody* getPhysicsBody() const; + + virtual void visit() override; #endif /// @} End of Sprite properties getter/setters diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp index a1d9180b72..a95e864344 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -1,25 +1,42 @@ #include "PhysicsTest.h" #include "../testResource.h" -#include "cocos-ext.h" -USING_NS_CC_EXT; +USING_NS_CC; PhysicsTestLayer::PhysicsTestLayer() : _spriteTexture(NULL) { #ifdef CC_USE_PHYSICS - //Set up sprite -#if 1 - // Use batch node. Faster - auto parent = SpriteBatchNode::create("Images/blocks.png", 100); + setTouchEnabled(true); + setAccelerometerEnabled(true); + + // title + auto label = LabelTTF::create("Multi touch the screen", "Marker Felt", 36); + label->setPosition(Point( VisibleRect::center().x, VisibleRect::top().y - 30)); + this->addChild(label, -1); + + // menu for debug layer + MenuItemFont::setFontSize(18); + auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(PhysicsTestLayer::toggleDebugCallback, this)); + + auto menu = Menu::create(item, NULL); + this->addChild(menu); + menu->setPosition(Point(VisibleRect::right().x-100, VisibleRect::top().y-60)); + + auto sp = Sprite::create(); + auto body = PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size); + sp->setPhysicsBody(body); + this->addChild(sp); + sp->setPosition(VisibleRect::center()); + + auto parent = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100); _spriteTexture = parent->getTexture(); -#else - // doesn't use batch node. Slower - _spriteTexture = TextureCache::getInstance()->addImage("Images/blocks.png"); - auto parent = Node::create(); -#endif + + addNewSpriteAtPosition(VisibleRect::center()); + + createResetButton(); #else - auto label = LabelTTF::create("Should define CC_ENABLE_BOX2D_INTEGRATION=1\n to run this test case", + auto label = LabelTTF::create("Should define CC_USE_BOX2D or CC_USE_CHIPMUNK\n to run this test case", "Arial", 18); auto size = Director::getInstance()->getWinSize(); @@ -29,11 +46,18 @@ PhysicsTestLayer::PhysicsTestLayer() #endif } -PhysicsTestLayer::~PhysicsTestLayer() +void PhysicsTestLayer::toggleDebugCallback(Object* sender) { +#ifdef CC_USE_PHYSICS + if (dynamic_cast(this->getParent()) != nullptr) + { + PhysicsWorld* world = dynamic_cast(this->getParent())->getPhysicsWorld(); + world->setDebugDraw(!world->getDebugDraw()); + } +#endif } -void PhysicsTestLayer::initPhysics() +PhysicsTestLayer::~PhysicsTestLayer() { } @@ -41,6 +65,7 @@ void PhysicsTestLayer::createResetButton() { auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", [](Object *sender) { auto s = new PhysicsTestScene(); + s->initTest(); auto child = new PhysicsTestLayer(); s->addChild(child); child->release(); @@ -55,37 +80,13 @@ void PhysicsTestLayer::createResetButton() } -void PhysicsTestLayer::addNewSpriteAtPosition(Point p) -{ - CCLOG("Add sprite %0.2f x %02.f",p.x,p.y); - -#if CC_ENABLE_BOX2D_INTEGRATION - auto parent = this->getChildByTag(kTagParentNode); - - //We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is - //just randomly picking one of the images - int idx = (CCRANDOM_0_1() > .5 ? 0:1); - int idy = (CCRANDOM_0_1() > .5 ? 0:1); - auto sprite = PhysicsSprite::createWithTexture(_spriteTexture,Rect(32 * idx,32 * idy,32,32)); - parent->addChild(sprite); - sprite->setB2Body(body); - sprite->setPTMRatio(PTM_RATIO); - sprite->setPosition( Point( p.x, p.y) ); -#endif -} - void PhysicsTestLayer::ccTouchesEnded(Set* touches, Event* event) { //Add a new body/atlas sprite at the touched location - SetIterator it; - Touch* touch; - for( it = touches->begin(); it != touches->end(); it++) + for( auto &item: *touches) { - touch = static_cast(*it); - - if(!touch) - break; + auto touch = static_cast(item); auto location = touch->getLocation(); @@ -93,9 +94,40 @@ void PhysicsTestLayer::ccTouchesEnded(Set* touches, Event* event) } } +void PhysicsTestLayer::addNewSpriteAtPosition(Point p) +{ +#ifdef CC_USE_PHYSICS + CCLOG("Add sprite %0.2f x %02.f",p.x,p.y); + + int posx, posy; + + posx = CCRANDOM_0_1() * 200.0f; + posy = CCRANDOM_0_1() * 200.0f; + + posx = (posx % 4) * 85; + posy = (posy % 3) * 121; + + auto sp = Sprite::createWithTexture(_spriteTexture, Rect(posx, posy, 85, 121)); + auto body = PhysicsBody::createBox(Size(48, 108)); + sp->setPhysicsBody(body); + sp->setPosition(p); + this->addChild(sp); +#endif +} + bool PhysicsTestScene::initTest() { - return TestScene::initWithPhysics(); +#ifdef CC_USE_PHYSICS + if (TestScene::initWithPhysics()) + { + this->getPhysicsWorld()->setDebugDraw(true); + return true; + } +#else + return TestScene::init(); +#endif + + return false; } void PhysicsTestScene::runThisTest() diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h index 8140015488..73cfb56935 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h @@ -11,10 +11,10 @@ class PhysicsTestLayer : public Layer public: PhysicsTestLayer(); ~PhysicsTestLayer(); - - void initPhysics(); + void createResetButton(); + void toggleDebugCallback(Object* sender); void addNewSpriteAtPosition(Point p); virtual void ccTouchesEnded(Set* touches, Event* event); } ; From 8ec7996dcd99424e60459902fd1a1d559f2bf357 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 16 Sep 2013 22:51:48 +0800 Subject: [PATCH 13/34] issue #2771: Edit delegate to listener. --- cocos2dx/physics/CCPhysicsContact.cpp | 15 ++++- cocos2dx/physics/CCPhysicsContact.h | 46 +++---------- cocos2dx/physics/CCPhysicsWorld.cpp | 97 +++++++++++++-------------- cocos2dx/physics/CCPhysicsWorld.h | 32 +++------ 4 files changed, 78 insertions(+), 112 deletions(-) diff --git a/cocos2dx/physics/CCPhysicsContact.cpp b/cocos2dx/physics/CCPhysicsContact.cpp index d76b93f9d8..e7c5a8555a 100644 --- a/cocos2dx/physics/CCPhysicsContact.cpp +++ b/cocos2dx/physics/CCPhysicsContact.cpp @@ -128,10 +128,19 @@ bool PhysicsContactPostSolve::init() return true; } +PhysicsContactListener::PhysicsContactListener() +: onContactBegin(nullptr) +, onContactPreSolve(nullptr) +, onContactPostSolve(nullptr) +, onContactEnd(nullptr) +{ + +} -#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) -#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) -#endif +PhysicsContactListener::~PhysicsContactListener() +{ + +} NS_CC_END #endif // CC_USE_PHYSICS diff --git a/cocos2dx/physics/CCPhysicsContact.h b/cocos2dx/physics/CCPhysicsContact.h index 6db1fd47f7..4b40fadf4a 100644 --- a/cocos2dx/physics/CCPhysicsContact.h +++ b/cocos2dx/physics/CCPhysicsContact.h @@ -36,16 +36,6 @@ NS_CC_BEGIN class PhysicsShape; class PhysicsWorld; -namespace PhysicsInnerCallbackFunctions -{ -#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) - int collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); - int collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - void collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); -#endif -} - class PhysicsContactInfo; class PhysicsContact @@ -70,13 +60,6 @@ private: void* _data; friend class PhysicsWorld; - -#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) - friend int PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); - friend int PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - friend void PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - friend void PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); -#endif }; class PhysicsContactPreSolve @@ -89,13 +72,6 @@ private: bool init(); friend class PhysicsWorld; - -#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) - friend int PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); - friend int PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - friend void PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - friend void PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); -#endif }; class PhysicsContactPostSolve @@ -108,26 +84,20 @@ private: bool init(); friend class PhysicsWorld; - -#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) - friend int PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); - friend int PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - friend void PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - friend void PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); -#endif }; -class PhysicsContactDelegate +class PhysicsContactListener { public: - PhysicsContactDelegate(); - virtual ~PhysicsContactDelegate(); + PhysicsContactListener(); + virtual ~PhysicsContactListener(); public: - virtual bool onContactBegin(const PhysicsContact& contact) = 0; - virtual bool onContactPreSolve(const PhysicsContact& contact, const PhysicsContactPreSolve& solve) = 0; - virtual void onContactPostSove(const PhysicsContact& contact, const PhysicsContactPostSolve& solve)= 0; - virtual void onContactEnd(const PhysicsContact& contact) = 0; + std::function onContactBegin; + std::function onContactPreSolve; + + std::function onContactPostSolve; + std::function onContactEnd; }; NS_CC_END diff --git a/cocos2dx/physics/CCPhysicsWorld.cpp b/cocos2dx/physics/CCPhysicsWorld.cpp index 78a6f3b806..e880f72f65 100644 --- a/cocos2dx/physics/CCPhysicsWorld.cpp +++ b/cocos2dx/physics/CCPhysicsWorld.cpp @@ -48,47 +48,44 @@ NS_CC_BEGIN #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) -namespace PhysicsInnerCallbackFunctions +int PhysicsWorld::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data) { - int collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data) - { - PhysicsWorld* world = static_cast(data); - - CP_ARBITER_GET_SHAPES(arb, a, b); - - auto ita = PhysicsShapeInfo::map.find(a); - auto itb = PhysicsShapeInfo::map.find(b); - CC_ASSERT(ita != PhysicsShapeInfo::map.end() && itb != PhysicsShapeInfo::map.end()); - - PhysicsContact* contact = PhysicsContact::create(ita->second->shape, itb->second->shape); - arb->data = contact; - - return world->collisionBeginCallback(*static_cast(arb->data)); - } + PhysicsWorld* world = static_cast(data); - int collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data) - { - PhysicsWorld* world = static_cast(data); - return world->collisionPreSolveCallback(*static_cast(arb->data), - PhysicsContactPreSolve()); - } + CP_ARBITER_GET_SHAPES(arb, a, b); - void collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data) - { - PhysicsWorld* world = static_cast(data); - world->collisionPostSolveCallback(*static_cast(arb->data), - PhysicsContactPostSolve()); - } + auto ita = PhysicsShapeInfo::map.find(a); + auto itb = PhysicsShapeInfo::map.find(b); + CC_ASSERT(ita != PhysicsShapeInfo::map.end() && itb != PhysicsShapeInfo::map.end()); - void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data) - { - PhysicsWorld* world = static_cast(data); - PhysicsContact* contact = static_cast(arb->data); - - world->collisionSeparateCallback(*contact); - - delete contact; - } + PhysicsContact* contact = PhysicsContact::create(ita->second->shape, itb->second->shape); + arb->data = contact; + + return world->collisionBeginCallback(*static_cast(arb->data)); +} + +int PhysicsWorld::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data) +{ + PhysicsWorld* world = static_cast(data); + return world->collisionPreSolveCallback(*static_cast(arb->data), + PhysicsContactPreSolve()); +} + +void PhysicsWorld::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data) +{ + PhysicsWorld* world = static_cast(data); + world->collisionPostSolveCallback(*static_cast(arb->data), + PhysicsContactPostSolve()); +} + +void PhysicsWorld::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data) +{ + PhysicsWorld* world = static_cast(data); + PhysicsContact* contact = static_cast(arb->data); + + world->collisionSeparateCallback(*contact); + + delete contact; } bool PhysicsWorld::init() @@ -98,10 +95,10 @@ bool PhysicsWorld::init() cpSpaceSetGravity(_info->space, PhysicsHelper::point2cpv(_gravity)); cpSpaceSetDefaultCollisionHandler(_info->space, - PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc, - PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc, - PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc, - PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc, + PhysicsWorld::collisionBeginCallbackFunc, + PhysicsWorld::collisionPreSolveCallbackFunc, + PhysicsWorld::collisionPostSolveCallbackFunc, + PhysicsWorld::collisionSeparateCallbackFunc, this); return true; @@ -246,9 +243,9 @@ void PhysicsWorld::drawWithShape(DrawNode* node, PhysicsShape* shape) int PhysicsWorld::collisionBeginCallback(const PhysicsContact& contact) { - if (_delegate) + if (_listener && _listener->onContactBegin) { - return _delegate->onContactBegin(contact); + return _listener->onContactBegin(contact); } return true; @@ -256,9 +253,9 @@ int PhysicsWorld::collisionBeginCallback(const PhysicsContact& contact) int PhysicsWorld::collisionPreSolveCallback(const PhysicsContact& contact, const PhysicsContactPreSolve& solve) { - if (_delegate) + if (_listener && _listener->onContactPreSolve) { - return _delegate->onContactPreSolve(contact, solve); + return _listener->onContactPreSolve(contact, solve); } return true; @@ -266,17 +263,17 @@ int PhysicsWorld::collisionPreSolveCallback(const PhysicsContact& contact, const void PhysicsWorld::collisionPostSolveCallback(const PhysicsContact& contact, const PhysicsContactPostSolve& solve) { - if (_delegate) + if (_listener && _listener->onContactPreSolve) { - _delegate->onContactPostSove(contact, solve); + _listener->onContactPostSolve(contact, solve); } } void PhysicsWorld::collisionSeparateCallback(const PhysicsContact& contact) { - if (_delegate) + if (_listener && _listener->onContactEnd) { - _delegate->onContactEnd(contact); + _listener->onContactEnd(contact); } } @@ -300,7 +297,7 @@ PhysicsWorld::PhysicsWorld() : _gravity(Point(0.0f, -98.0f)) , _speed(1.0f) , _info(nullptr) -, _delegate(nullptr) +, _listener(nullptr) , _bodys(nullptr) , _scene(nullptr) , _debugDraw(false) diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index 1cb2530351..625ba9c065 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -40,23 +40,13 @@ class PhysicsShape; class PhysicsContact; class PhysicsContactPreSolve; class PhysicsContactPostSolve; -class PhysicsContactDelegate; +class PhysicsContactListener; class Array; class Sprite; class Scene; class DrawNode; -namespace PhysicsInnerCallbackFunctions -{ -#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) - int collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); - int collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - void collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); -#endif -} - class PhysicsWorld { public: @@ -69,8 +59,8 @@ public: Array* getBodysInRect(Rect rect) const; Array* getAllBody() const; - inline void registerContactDelegate(PhysicsContactDelegate* delegate) { _delegate = delegate; } - inline void unregisterContactDelegate() { _delegate = nullptr; } + inline void registerContactListener(PhysicsContactListener* delegate) { _listener = delegate; } + inline void unregisterContactListener() { _listener = nullptr; } inline Point getGravity() { return _gravity; } inline void setGravity(Point gravity) { _gravity = gravity; } @@ -97,11 +87,18 @@ protected: virtual void collisionPostSolveCallback(const PhysicsContact& contact, const PhysicsContactPostSolve& solve); virtual void collisionSeparateCallback(const PhysicsContact& contact); +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) + static int collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); + static int collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + static void collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); + static void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); +#endif + protected: Point _gravity; float _speed; PhysicsWorldInfo* _info; - PhysicsContactDelegate* _delegate; + PhysicsContactListener* _listener; Array* _bodys; @@ -117,13 +114,6 @@ protected: friend class Sprite; friend class Scene; friend class PhysicsBody; - -#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) - friend int PhysicsInnerCallbackFunctions::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); - friend int PhysicsInnerCallbackFunctions::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - friend void PhysicsInnerCallbackFunctions::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); - friend void PhysicsInnerCallbackFunctions::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); -#endif }; NS_CC_END From f96bc2355a043baa8f363a66a4a126779d2269d1 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 16 Sep 2013 22:56:20 +0800 Subject: [PATCH 14/34] issue #2771: update android.mk --- cocos2dx/Android.mk | 16 ++++++++++++++++ samples/Cpp/TestCpp/Android.mk | 2 ++ 2 files changed, 18 insertions(+) diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index 0c54f17697..c03343e1b1 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -96,6 +96,22 @@ particle_nodes/CCParticleBatchNode.cpp \ particle_nodes/CCParticleExamples.cpp \ particle_nodes/CCParticleSystem.cpp \ particle_nodes/CCParticleSystemQuad.cpp \ +physics/CCPhysicsBody.cpp \ +physics/CCPhysicsContact.cpp \ +physics/CCPhysicsJoint.cpp \ +physics/CCPhysicsShape.cpp \ +physics/CCPhysicsWorld.cpp \ +physics/Box2D/CCPhysicsBodyInfo.cpp \ +physics/Box2D/CCPhysicsContactInfo.cpp \ +physics/Box2D/CCPhysicsJointInfo.cpp \ +physics/Box2D/CCPhysicsShapeInfo.cpp \ +physics/Box2D/CCPhysicsWorldInfo.cpp \ +physics/chipmunk/CCPhysicsBodyInfo.cpp \ +physics/chipmunk/CCPhysicsContactInfo.cpp \ +physics/chipmunk/CCPhysicsJointInfo.cpp \ +physics/chipmunk/CCPhysicsShapeInfo.cpp \ +physics/chipmunk/CCPhysicsWorldInfo.cpp \ +physics/chipmunk/ChipmunkDebugDraw.c \ platform/CCEGLViewProtocol.cpp \ platform/CCFileUtils.cpp \ platform/CCSAXParser.cpp \ diff --git a/samples/Cpp/TestCpp/Android.mk b/samples/Cpp/TestCpp/Android.mk index 339a50a3d8..f96922a9e7 100644 --- a/samples/Cpp/TestCpp/Android.mk +++ b/samples/Cpp/TestCpp/Android.mk @@ -45,6 +45,7 @@ Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp \ Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp \ Classes/EffectsTest/EffectsTest.cpp \ Classes/ExtensionsTest/ExtensionsTest.cpp \ +Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp \ Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.cpp \ Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.cpp \ Classes/ExtensionsTest/CocosBuilderTest/ButtonTest/ButtonTestLayer.cpp \ @@ -98,6 +99,7 @@ Classes/PerformanceTest/PerformanceSpriteTest.cpp \ Classes/PerformanceTest/PerformanceTest.cpp \ Classes/PerformanceTest/PerformanceTextureTest.cpp \ Classes/PerformanceTest/PerformanceTouchesTest.cpp \ +Classes/PhysicsTest/PhysicsTest.cpp \ Classes/RenderTextureTest/RenderTextureTest.cpp \ Classes/RotateWorldTest/RotateWorldTest.cpp \ Classes/SceneTest/SceneTest.cpp \ From 365419a8b20db5a8e848614325926fc1c4c9997b Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 16 Sep 2013 23:35:16 +0800 Subject: [PATCH 15/34] issue #2087: [dispatcher] Fix box2d_test crash. --- .../CCLayer.cpp | 18 ++++++++++++------ .../layers_scenes_transitions_nodes/CCLayer.h | 3 ++- .../TestCpp/Classes/Box2DTestBed/Box2dView.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index fc8dd27d63..6179bfd934 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -98,8 +98,13 @@ Layer *Layer::create() /// Touch and Accelerometer related -void Layer::onRegisterTouchListener() -{ +void Layer::addTouchListener() +{ + if (_touchListener != nullptr) + return; + + auto dispatcher = EventDispatcher::getInstance(); + if( _touchMode == Touch::DispatchMode::ALL_AT_ONCE ) { // Register Touch Event @@ -110,7 +115,7 @@ void Layer::onRegisterTouchListener() listener->onTouchesEnded = CC_CALLBACK_2(Layer::onTouchesEnded, this); listener->onTouchesCancelled = CC_CALLBACK_2(Layer::onTouchesCancelled, this); - EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, this); + dispatcher->addEventListenerWithSceneGraphPriority(listener, this); _touchListener = listener; } else @@ -124,7 +129,7 @@ void Layer::onRegisterTouchListener() listener->onTouchEnded = CC_CALLBACK_2(Layer::onTouchEnded, this); listener->onTouchCancelled = CC_CALLBACK_2(Layer::onTouchCancelled, this); - EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, this); + dispatcher->addEventListenerWithSceneGraphPriority(listener, this); _touchListener = listener; } } @@ -170,7 +175,7 @@ void Layer::setTouchEnabled(bool enabled) { if (enabled) { - this->onRegisterTouchListener(); + this->addTouchListener(); } else { @@ -309,7 +314,7 @@ void Layer::onEnter() // since events are propagated in reverse order if (_touchEnabled) { - this->onRegisterTouchListener(); + this->addTouchListener(); } // then iterate over all the children @@ -348,6 +353,7 @@ void Layer::onEnterTransitionDidFinish() if (_accelerometerEnabled) { auto dispatcher = EventDispatcher::getInstance(); + dispatcher->removeEventListener(_accelerationListener); _accelerationListener = AccelerationEventListener::create(CC_CALLBACK_2(Layer::onAcceleration, this)); dispatcher->addEventListenerWithSceneGraphPriority(_accelerationListener, this); } diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h index ca75eb3dd0..ffd4eafe2c 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h @@ -113,7 +113,6 @@ public: @since v0.8.0 */ CC_DEPRECATED_ATTRIBUTE virtual void registerWithTouchDispatcher() final {}; - virtual void onRegisterTouchListener(); /** whether or not it will receive Touch events. You can enable / disable touch events with this property. @@ -180,6 +179,8 @@ public: virtual void onEnterTransitionDidFinish() override; protected: + void addTouchListener(); + bool _touchEnabled; bool _accelerometerEnabled; bool _keyboardEnabled; diff --git a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp index b35b38048e..d99f5e6f3c 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp @@ -53,6 +53,7 @@ bool MenuLayer::initWithEntryID(int entryId) m_entryID = entryId; setTouchEnabled( true ); + setTouchMode(Touch::DispatchMode::ONE_BY_ONE); Box2DView* view = Box2DView::viewWithEntryID( entryId ); addChild(view, 0, kTagBox2DNode); @@ -90,7 +91,7 @@ bool MenuLayer::initWithEntryID(int entryId) listener->onTouchBegan = CC_CALLBACK_2(MenuLayer::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(MenuLayer::onTouchMoved, this); - EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, 0); + EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, 1); _touchListener = listener; return true; } @@ -185,6 +186,7 @@ bool Box2DView::initWithEntryID(int entryId) m_entry = g_testEntries + entryId; m_test = m_entry->createFcn(); + setTouchMode(Touch::DispatchMode::ONE_BY_ONE); // Removes Touch Event Listener EventDispatcher::getInstance()->removeEventListener(_touchListener); @@ -197,7 +199,7 @@ bool Box2DView::initWithEntryID(int entryId) listener->onTouchMoved = CC_CALLBACK_2(Box2DView::onTouchMoved, this); listener->onTouchEnded = CC_CALLBACK_2(Box2DView::onTouchEnded, this); - EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, 10); + EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, -10); _touchListener = listener; return true; @@ -268,8 +270,6 @@ void Box2DView::onTouchEnded(Touch* touch, Event* event) log("Box2DView::onTouchEnded, pos: %f,%f -> %f,%f", touchLocation.x, touchLocation.y, nodePosition.x, nodePosition.y); m_test->MouseUp(b2Vec2(nodePosition.x,nodePosition.y)); - -// EventDispatcher::getInstance()->setPriorityWithFixedValue(_touchEventId, -1); } // void Box2DView::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration) From 481ad7ef125ea5262af23b9850d08a0dac71bc83 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 17 Sep 2013 10:41:08 +0800 Subject: [PATCH 16/34] issue #2771: update project setting --- .../proj.win32/CocosDenshion.vcxproj | 2 +- .../project.pbxproj.REMOVED.git-id | 2 +- .../physics/chipmunk/CCPhysicsBodyInfo.cpp | 2 +- cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c | 446 ------------------ cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h | 50 -- cocos2dx/proj.linux/cocos2dx.mk | 3 +- cocos2dx/proj.win32/cocos2d.vcxproj | 35 +- cocos2dx/proj.win32/cocos2d.vcxproj.filters | 108 +++++ extensions/Android.mk | 2 +- .../Cpp/HelloCpp/proj.android/jni/Android.mk | 3 +- .../Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj | 2 +- .../SimpleGame/proj.android/jni/Android.mk | 3 +- samples/Cpp/TestCpp/proj.emscripten/Makefile | 1 + samples/Cpp/TestCpp/proj.linux/Makefile | 1 + .../Cpp/TestCpp/proj.win32/TestCpp.vcxproj | 2 + .../proj.win32/TestCpp.vcxproj.filters | 9 + .../Lua/HelloLua/proj.win32/HelloLua.vcxproj | 2 +- scripting/lua/proj.win32/liblua.vcxproj | 2 +- 18 files changed, 168 insertions(+), 507 deletions(-) delete mode 100644 cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c delete mode 100644 cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h diff --git a/CocosDenshion/proj.win32/CocosDenshion.vcxproj b/CocosDenshion/proj.win32/CocosDenshion.vcxproj index c5738cf5a2..7a91634027 100644 --- a/CocosDenshion/proj.win32/CocosDenshion.vcxproj +++ b/CocosDenshion/proj.win32/CocosDenshion.vcxproj @@ -65,7 +65,7 @@ Disabled - $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;..\Include;"$(ProjectDir)..\..\cocos2dx";"$(ProjectDir)..\..\cocos2dx\include";"$(ProjectDir)..\..\cocos2dx\kazmath\include";"$(ProjectDir)..\..\cocos2dx\platform\win32";"$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES";%(AdditionalIncludeDirectories) + $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;..\Include;$(ProjectDir)..\..\cocos2dx;$(ProjectDir)..\..\cocos2dx\include;$(ProjectDir)..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) false EnableFastChecks diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 1436cd2cc4..1e9cc1e16a 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -3f1cfaf06d95973aa8f2a629582705eb65bb24f6 \ No newline at end of file +29c3c2dfd8b683a800709d085839444c3a304a0d \ No newline at end of file diff --git a/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.cpp b/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.cpp index 4627c02499..5fd8ceb171 100644 --- a/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.cpp +++ b/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.cpp @@ -38,7 +38,7 @@ PhysicsBodyInfo::~PhysicsBodyInfo() Clonable* PhysicsBodyInfo::clone() const { - + return nullptr; } NS_CC_END diff --git a/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c b/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c deleted file mode 100644 index 38b06af1a0..0000000000 --- a/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.c +++ /dev/null @@ -1,446 +0,0 @@ -/* Copyright (c) 2007 Scott Lembcke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include - -#ifdef __APPLE__ - #include "OpenGL/gl.h" - #include "OpenGL/glu.h" - #include -#else - #ifdef WIN32 - #include - #endif - - #include - #include - #include -#endif - -#include "chipmunk_private.h" -#include "ChipmunkDebugDraw.h" - -/* - IMPORTANT - READ ME! - - This file sets up a simple interface that the individual demos can use to get - a Chipmunk space running and draw what's in it. In order to keep the Chipmunk - examples clean and simple, they contain no graphics code. All drawing is done - by accessing the Chipmunk structures at a very low level. It is NOT - recommended to write a game or application this way as it does not scale - beyond simple shape drawing and is very dependent on implementation details - about Chipmunk which may change with little to no warning. -*/ - -const Color LINE_COLOR = {200.0/255.0, 210.0/255.0, 230.0/255.0, 1.0}; -const Color CONSTRAINT_COLOR = {0.0, 0.75, 0.0, 1.0}; -const float SHAPE_ALPHA = 1.0; - -float ChipmunkDebugDrawPointLineScale = 1.0; - -static Color -ColorFromHash(cpHashValue hash, float alpha) -{ - unsigned long val = (unsigned long)hash; - - // scramble the bits up using Robert Jenkins' 32 bit integer hash function - val = (val+0x7ed55d16) + (val<<12); - val = (val^0xc761c23c) ^ (val>>19); - val = (val+0x165667b1) + (val<<5); - val = (val+0xd3a2646c) ^ (val<<9); - val = (val+0xfd7046c5) + (val<<3); - val = (val^0xb55a4f09) ^ (val>>16); - - GLfloat r = (val>>0) & 0xFF; - GLfloat g = (val>>8) & 0xFF; - GLfloat b = (val>>16) & 0xFF; - - GLfloat max = cpfmax(cpfmax(r, g), b); - GLfloat min = cpfmin(cpfmin(r, g), b); - GLfloat intensity = 0.75; - - // Saturate and scale the color - if(min == max){ - return RGBAColor(intensity, 0.0, 0.0, alpha); - } else { - GLfloat coef = alpha*intensity/(max - min); - return RGBAColor( - (r - min)*coef, - (g - min)*coef, - (b - min)*coef, - alpha - ); - } -} - -static inline void -glColor_from_color(Color color){ - glColor4fv((GLfloat *)&color); -} - -static Color -ColorForShape(cpShape *shape) -{ - if(cpShapeGetSensor(shape)){ - return LAColor(1, 0); - } else { - cpBody *body = shape->body; - - if(cpBodyIsSleeping(body)){ - return LAColor(0.2, 1); - } else if(body->node.idleTime > shape->space->sleepTimeThreshold) { - return LAColor(0.66, 1); - } else { - return ColorFromHash(shape->hashid, SHAPE_ALPHA); - } - } -} - -static const GLfloat circleVAR[] = { - 0.0000f, 1.0000f, - 0.2588f, 0.9659f, - 0.5000f, 0.8660f, - 0.7071f, 0.7071f, - 0.8660f, 0.5000f, - 0.9659f, 0.2588f, - 1.0000f, 0.0000f, - 0.9659f, -0.2588f, - 0.8660f, -0.5000f, - 0.7071f, -0.7071f, - 0.5000f, -0.8660f, - 0.2588f, -0.9659f, - 0.0000f, -1.0000f, - -0.2588f, -0.9659f, - -0.5000f, -0.8660f, - -0.7071f, -0.7071f, - -0.8660f, -0.5000f, - -0.9659f, -0.2588f, - -1.0000f, -0.0000f, - -0.9659f, 0.2588f, - -0.8660f, 0.5000f, - -0.7071f, 0.7071f, - -0.5000f, 0.8660f, - -0.2588f, 0.9659f, - 0.0000f, 1.0000f, - 0.0f, 0.0f, // For an extra line to see the rotation. -}; -static const int circleVAR_count = sizeof(circleVAR)/sizeof(GLfloat)/2; - -void ChipmunkDebugDrawCircle(cpVect center, cpFloat angle, cpFloat radius, Color lineColor, Color fillColor) -{ - glVertexPointer(2, GL_FLOAT, 0, circleVAR); - - glPushMatrix(); { - glTranslatef(center.x, center.y, 0.0f); - glRotatef(angle*180.0f/M_PI, 0.0f, 0.0f, 1.0f); - glScalef(radius, radius, 1.0f); - - if(fillColor.a > 0){ - glColor_from_color(fillColor); - glDrawArrays(GL_TRIANGLE_FAN, 0, circleVAR_count - 1); - } - - if(lineColor.a > 0){ - glColor_from_color(lineColor); - glDrawArrays(GL_LINE_STRIP, 0, circleVAR_count); - } - } glPopMatrix(); -} - -static const GLfloat pillVAR[] = { - 0.0000f, 1.0000f, 1.0f, - 0.2588f, 0.9659f, 1.0f, - 0.5000f, 0.8660f, 1.0f, - 0.7071f, 0.7071f, 1.0f, - 0.8660f, 0.5000f, 1.0f, - 0.9659f, 0.2588f, 1.0f, - 1.0000f, 0.0000f, 1.0f, - 0.9659f, -0.2588f, 1.0f, - 0.8660f, -0.5000f, 1.0f, - 0.7071f, -0.7071f, 1.0f, - 0.5000f, -0.8660f, 1.0f, - 0.2588f, -0.9659f, 1.0f, - 0.0000f, -1.0000f, 1.0f, - - 0.0000f, -1.0000f, 0.0f, - -0.2588f, -0.9659f, 0.0f, - -0.5000f, -0.8660f, 0.0f, - -0.7071f, -0.7071f, 0.0f, - -0.8660f, -0.5000f, 0.0f, - -0.9659f, -0.2588f, 0.0f, - -1.0000f, -0.0000f, 0.0f, - -0.9659f, 0.2588f, 0.0f, - -0.8660f, 0.5000f, 0.0f, - -0.7071f, 0.7071f, 0.0f, - -0.5000f, 0.8660f, 0.0f, - -0.2588f, 0.9659f, 0.0f, - 0.0000f, 1.0000f, 0.0f, -}; -static const int pillVAR_count = sizeof(pillVAR)/sizeof(GLfloat)/3; - -void ChipmunkDebugDrawSegment(cpVect a, cpVect b, Color color) -{ - GLfloat verts[] = { - a.x, a.y, - b.x, b.y, - }; - - glVertexPointer(2, GL_FLOAT, 0, verts); - glColor_from_color(color); - glDrawArrays(GL_LINES, 0, 2); -} - -void ChipmunkDebugDrawFatSegment(cpVect a, cpVect b, cpFloat radius, Color lineColor, Color fillColor) -{ - if(radius){ - glVertexPointer(3, GL_FLOAT, 0, pillVAR); - glPushMatrix(); { - cpVect d = cpvsub(b, a); - cpVect r = cpvmult(d, radius/cpvlength(d)); - - const GLfloat matrix[] = { - r.x, r.y, 0.0f, 0.0f, - -r.y, r.x, 0.0f, 0.0f, - d.x, d.y, 0.0f, 0.0f, - a.x, a.y, 0.0f, 1.0f, - }; - glMultMatrixf(matrix); - - if(fillColor.a > 0){ - glColor_from_color(fillColor); - glDrawArrays(GL_TRIANGLE_FAN, 0, pillVAR_count); - } - - if(lineColor.a > 0){ - glColor_from_color(lineColor); - glDrawArrays(GL_LINE_LOOP, 0, pillVAR_count); - } - } glPopMatrix(); - } else { - ChipmunkDebugDrawSegment(a, b, lineColor); - } -} - -void ChipmunkDebugDrawPolygon(int count, cpVect *verts, Color lineColor, Color fillColor) -{ -#if CP_USE_DOUBLES - glVertexPointer(2, GL_DOUBLE, 0, verts); -#else - glVertexPointer(2, GL_FLOAT, 0, verts); -#endif - - if(fillColor.a > 0){ - glColor_from_color(fillColor); - glDrawArrays(GL_TRIANGLE_FAN, 0, count); - } - - if(lineColor.a > 0){ - glColor_from_color(lineColor); - glDrawArrays(GL_LINE_LOOP, 0, count); - } -} - -void ChipmunkDebugDrawPoints(cpFloat size, int count, cpVect *verts, Color color) -{ -#if CP_USE_DOUBLES - glVertexPointer(2, GL_DOUBLE, 0, verts); -#else - glVertexPointer(2, GL_FLOAT, 0, verts); -#endif - - glPointSize(size*ChipmunkDebugDrawPointLineScale); - glColor_from_color(color); - glDrawArrays(GL_POINTS, 0, count); -} - -void ChipmunkDebugDrawBB(cpBB bb, Color color) -{ - cpVect verts[] = { - cpv(bb.l, bb.b), - cpv(bb.l, bb.t), - cpv(bb.r, bb.t), - cpv(bb.r, bb.b), - }; - ChipmunkDebugDrawPolygon(4, verts, color, LAColor(0, 0)); -} - -static void -drawShape(cpShape *shape, void *unused) -{ - cpBody *body = shape->body; - Color color = ColorForShape(shape); - - switch(shape->klass->type){ - case CP_CIRCLE_SHAPE: { - cpCircleShape *circle = (cpCircleShape *)shape; - ChipmunkDebugDrawCircle(circle->tc, body->a, circle->r, LINE_COLOR, color); - break; - } - case CP_SEGMENT_SHAPE: { - cpSegmentShape *seg = (cpSegmentShape *)shape; - ChipmunkDebugDrawFatSegment(seg->ta, seg->tb, seg->r, LINE_COLOR, color); - break; - } - case CP_POLY_SHAPE: { - cpPolyShape *poly = (cpPolyShape *)shape; - ChipmunkDebugDrawPolygon(poly->numVerts, poly->tVerts, LINE_COLOR, color); - break; - } - default: break; - } -} - -void ChipmunkDebugDrawShape(cpShape *shape) -{ - drawShape(shape, NULL); -} - -void ChipmunkDebugDrawShapes(cpSpace *space) -{ - cpSpaceEachShape(space, drawShape, NULL); -} - -static const GLfloat springVAR[] = { - 0.00f, 0.0f, - 0.20f, 0.0f, - 0.25f, 3.0f, - 0.30f,-6.0f, - 0.35f, 6.0f, - 0.40f,-6.0f, - 0.45f, 6.0f, - 0.50f,-6.0f, - 0.55f, 6.0f, - 0.60f,-6.0f, - 0.65f, 6.0f, - 0.70f,-3.0f, - 0.75f, 6.0f, - 0.80f, 0.0f, - 1.00f, 0.0f, -}; -static const int springVAR_count = sizeof(springVAR)/sizeof(GLfloat)/2; - -static void -drawSpring(cpDampedSpring *spring, cpBody *body_a, cpBody *body_b) -{ - cpVect a = cpvadd(body_a->p, cpvrotate(spring->anchr1, body_a->rot)); - cpVect b = cpvadd(body_b->p, cpvrotate(spring->anchr2, body_b->rot)); - - cpVect points[] = {a, b}; - ChipmunkDebugDrawPoints(5, 2, points, CONSTRAINT_COLOR); - - cpVect delta = cpvsub(b, a); - - glVertexPointer(2, GL_FLOAT, 0, springVAR); - glPushMatrix(); { - GLfloat x = a.x; - GLfloat y = a.y; - GLfloat cos = delta.x; - GLfloat sin = delta.y; - GLfloat s = 1.0f/cpvlength(delta); - - const GLfloat matrix[] = { - cos, sin, 0.0f, 0.0f, - -sin*s, cos*s, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - x, y, 0.0f, 1.0f, - }; - - glMultMatrixf(matrix); - glDrawArrays(GL_LINE_STRIP, 0, springVAR_count); - } glPopMatrix(); -} - -static void -drawConstraint(cpConstraint *constraint, void *unused) -{ - cpBody *body_a = constraint->a; - cpBody *body_b = constraint->b; - - const cpConstraintClass *klass = constraint->klass; - if(klass == cpPinJointGetClass()){ - cpPinJoint *joint = (cpPinJoint *)constraint; - - cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot)); - cpVect b = cpvadd(body_b->p, cpvrotate(joint->anchr2, body_b->rot)); - - cpVect points[] = {a, b}; - ChipmunkDebugDrawPoints(5, 2, points, CONSTRAINT_COLOR); - ChipmunkDebugDrawSegment(a, b, CONSTRAINT_COLOR); - } else if(klass == cpSlideJointGetClass()){ - cpSlideJoint *joint = (cpSlideJoint *)constraint; - - cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot)); - cpVect b = cpvadd(body_b->p, cpvrotate(joint->anchr2, body_b->rot)); - - cpVect points[] = {a, b}; - ChipmunkDebugDrawPoints(5, 2, points, CONSTRAINT_COLOR); - ChipmunkDebugDrawSegment(a, b, CONSTRAINT_COLOR); - } else if(klass == cpPivotJointGetClass()){ - cpPivotJoint *joint = (cpPivotJoint *)constraint; - - cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot)); - cpVect b = cpvadd(body_b->p, cpvrotate(joint->anchr2, body_b->rot)); - - cpVect points[] = {a, b}; - ChipmunkDebugDrawPoints(10, 2, points, CONSTRAINT_COLOR); - } else if(klass == cpGrooveJointGetClass()){ - cpGrooveJoint *joint = (cpGrooveJoint *)constraint; - - cpVect a = cpvadd(body_a->p, cpvrotate(joint->grv_a, body_a->rot)); - cpVect b = cpvadd(body_a->p, cpvrotate(joint->grv_b, body_a->rot)); - cpVect c = cpvadd(body_b->p, cpvrotate(joint->anchr2, body_b->rot)); - - ChipmunkDebugDrawPoints(5, 1, &c, CONSTRAINT_COLOR); - ChipmunkDebugDrawSegment(a, b, CONSTRAINT_COLOR); - } else if(klass == cpDampedSpringGetClass()){ - drawSpring((cpDampedSpring *)constraint, body_a, body_b); - } -} - -void ChipmunkDebugDrawConstraint(cpConstraint *constraint) -{ - drawConstraint(constraint, NULL); -} - -void ChipmunkDebugDrawConstraints(cpSpace *space) -{ - cpSpaceEachConstraint(space, drawConstraint, NULL); -} - -void ChipmunkDebugDrawCollisionPoints(cpSpace *space) -{ - cpArray *arbiters = space->arbiters; - - glColor3f(1.0f, 0.0f, 0.0f); - glPointSize(4.0f*ChipmunkDebugDrawPointLineScale); - - glBegin(GL_POINTS); { - for(int i=0; inum; i++){ - cpArbiter *arb = (cpArbiter*)arbiters->arr[i]; - - for(int j=0; jnumContacts; j++){ - cpVect v = arb->contacts[j].p; - glVertex2f(v.x, v.y); - } - } - } glEnd(); -} diff --git a/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h b/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h deleted file mode 100644 index 9cc0a722fd..0000000000 --- a/cocos2dx/physics/chipmunk/ChipmunkDebugDraw.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (c) 2007 Scott Lembcke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -typedef struct Color { - float r, g, b, a; -} Color; - -static inline Color RGBAColor(float r, float g, float b, float a){ - Color color = {r, g, b, a}; - return color; -} - -static inline Color LAColor(float l, float a){ - Color color = {l, l, l, a}; - return color; -} - -extern float ChipmunkDebugDrawPointLineScale; - -void ChipmunkDebugDrawCircle(cpVect center, cpFloat angle, cpFloat radius, Color lineColor, Color fillColor); -void ChipmunkDebugDrawSegment(cpVect a, cpVect b, Color color); -void ChipmunkDebugDrawFatSegment(cpVect a, cpVect b, cpFloat radius, Color lineColor, Color fillColor); -void ChipmunkDebugDrawPolygon(int count, cpVect *verts, Color lineColor, Color fillColor); -void ChipmunkDebugDrawPoints(cpFloat size, int count, cpVect *verts, Color color); -void ChipmunkDebugDrawBB(cpBB bb, Color color); - -void ChipmunkDebugDrawConstraint(cpConstraint *constraint); -void ChipmunkDebugDrawShape(cpShape *shape); - -void ChipmunkDebugDrawShapes(cpSpace *space); -void ChipmunkDebugDrawConstraints(cpSpace *space); -void ChipmunkDebugDrawCollisionPoints(cpSpace *space); diff --git a/cocos2dx/proj.linux/cocos2dx.mk b/cocos2dx/proj.linux/cocos2dx.mk index 3269129024..35955f2990 100644 --- a/cocos2dx/proj.linux/cocos2dx.mk +++ b/cocos2dx/proj.linux/cocos2dx.mk @@ -59,7 +59,8 @@ INCLUDES += \ -I$(COCOS_SRC)/platform/linux \ -I$(COCOS_SRC)/platform/third_party/linux/libjpeg \ -I$(COCOS_SRC)/platform/third_party/linux/libtiff \ - -I$(COCOS_SRC)/platform/third_party/linux/libwebp + -I$(COCOS_SRC)/platform/third_party/linux/libwebp \ + -I$(COCOS_ROOT/external/chipmunk/include/chipmunk LBITS := $(shell getconf LONG_BIT) ifeq ($(LBITS),64) diff --git a/cocos2dx/proj.win32/cocos2d.vcxproj b/cocos2dx/proj.win32/cocos2d.vcxproj index d6efeb7168..a37adf2788 100644 --- a/cocos2dx/proj.win32/cocos2d.vcxproj +++ b/cocos2dx/proj.win32/cocos2d.vcxproj @@ -69,7 +69,7 @@ Disabled - $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\libfreetype2;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;$(ProjectDir)..\platform\third_party\common\etc;%(AdditionalIncludeDirectories) + $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\libfreetype2;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;$(ProjectDir)..\platform\third_party\common\etc;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) false EnableFastChecks @@ -211,6 +211,21 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir + + + + + + + + + + + + + + + @@ -365,6 +380,24 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir + + + + + + + + + + + + + + + + + + diff --git a/cocos2dx/proj.win32/cocos2d.vcxproj.filters b/cocos2dx/proj.win32/cocos2d.vcxproj.filters index dcd9961e74..81e2e2a3d0 100644 --- a/cocos2dx/proj.win32/cocos2d.vcxproj.filters +++ b/cocos2dx/proj.win32/cocos2d.vcxproj.filters @@ -103,6 +103,15 @@ {3ff2746c-a91b-4b86-93b7-43a9ec14825b} + + {08593631-5bf5-46aa-9436-62595c4f7bf6} + + + {aeadfa95-9c89-4212-98ae-89ad57db596a} + + + {b9880458-36e5-4f28-a34b-d01d9512a395} + @@ -512,6 +521,51 @@ event_dispatcher + + physics + + + physics + + + physics + + + physics + + + physics + + + physics\chipmunk + + + physics\chipmunk + + + physics\chipmunk + + + physics\chipmunk + + + physics\chipmunk + + + physics\Box2D + + + physics\Box2D + + + physics\Box2D + + + physics\Box2D + + + physics\Box2D + @@ -1035,5 +1089,59 @@ event_dispatcher + + physics + + + physics + + + physics + + + physics + + + physics + + + physics + + + physics\chipmunk + + + physics\chipmunk + + + physics\chipmunk + + + physics\chipmunk + + + physics\chipmunk + + + physics\chipmunk + + + physics\Box2D + + + physics\Box2D + + + physics\Box2D + + + physics\Box2D + + + physics\Box2D + + + physics\Box2D + \ No newline at end of file diff --git a/extensions/Android.mk b/extensions/Android.mk index e5f7924e84..0a1877b23e 100644 --- a/extensions/Android.mk +++ b/extensions/Android.mk @@ -43,8 +43,8 @@ CocoStudio/Armature/display/CCDisplayFactory.cpp \ CocoStudio/Armature/display/CCDisplayManager.cpp \ CocoStudio/Armature/display/CCSkin.cpp \ CocoStudio/Armature/physics/CCColliderDetector.cpp \ -CocoStudio/Armature/utils/CCArmatureDefine.cpp \ CocoStudio/Armature/utils/CCArmatureDataManager.cpp \ +CocoStudio/Armature/utils/CCArmatureDefine.cpp \ CocoStudio/Armature/utils/CCDataReaderHelper.cpp \ CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp \ CocoStudio/Armature/utils/CCTransformHelp.cpp \ diff --git a/samples/Cpp/HelloCpp/proj.android/jni/Android.mk b/samples/Cpp/HelloCpp/proj.android/jni/Android.mk index 13989f3cf1..a59a21c7dd 100644 --- a/samples/Cpp/HelloCpp/proj.android/jni/Android.mk +++ b/samples/Cpp/HelloCpp/proj.android/jni/Android.mk @@ -12,10 +12,11 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes -LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocos2dxandroid_static cocosdenshion_static +LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocos2dxandroid_static cocosdenshion_static chipmunk_static include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) $(call import-module,cocos2dx/platform/android) +$(call import-module,external/chipmunk) diff --git a/samples/Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj b/samples/Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj index 616d9f442d..cc87373ff7 100644 --- a/samples/Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj +++ b/samples/Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj @@ -67,7 +67,7 @@ Disabled - $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;..\Classes;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;..\Classes;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks diff --git a/samples/Cpp/SimpleGame/proj.android/jni/Android.mk b/samples/Cpp/SimpleGame/proj.android/jni/Android.mk index e3f5b5c1ef..d50779e5c4 100644 --- a/samples/Cpp/SimpleGame/proj.android/jni/Android.mk +++ b/samples/Cpp/SimpleGame/proj.android/jni/Android.mk @@ -13,7 +13,7 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes -LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocos2dxandroid_static cocosdenshion_static +LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocos2dxandroid_static cocosdenshion_static chipmunk_static include $(BUILD_SHARED_LIBRARY) @@ -21,3 +21,4 @@ $(call import-module,CocosDenshion/android) $(call import-module,cocos2dx) $(call import-module,extensions) $(call import-module,cocos2dx/platform/android) +$(call import-module,external/chipmunk) diff --git a/samples/Cpp/TestCpp/proj.emscripten/Makefile b/samples/Cpp/TestCpp/proj.emscripten/Makefile index 426cb385e8..e2088a2ab4 100644 --- a/samples/Cpp/TestCpp/proj.emscripten/Makefile +++ b/samples/Cpp/TestCpp/proj.emscripten/Makefile @@ -76,6 +76,7 @@ SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \ ../Classes/PerformanceTest/PerformanceTest.cpp \ ../Classes/PerformanceTest/PerformanceTextureTest.cpp \ ../Classes/PerformanceTest/PerformanceTouchesTest.cpp \ + ../Classes/PhysicsTest/PhysicsTest.cpp \ ../Classes/RenderTextureTest/RenderTextureTest.cpp \ ../Classes/RotateWorldTest/RotateWorldTest.cpp \ ../Classes/SceneTest/SceneTest.cpp \ diff --git a/samples/Cpp/TestCpp/proj.linux/Makefile b/samples/Cpp/TestCpp/proj.linux/Makefile index aa64af3764..a10cab6883 100644 --- a/samples/Cpp/TestCpp/proj.linux/Makefile +++ b/samples/Cpp/TestCpp/proj.linux/Makefile @@ -82,6 +82,7 @@ SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \ ../Classes/PerformanceTest/PerformanceTest.cpp \ ../Classes/PerformanceTest/PerformanceTextureTest.cpp \ ../Classes/PerformanceTest/PerformanceTouchesTest.cpp \ + ../Classes/PhysicsTest/PhysicsTest.cpp \ ../Classes/RenderTextureTest/RenderTextureTest.cpp \ ../Classes/RotateWorldTest/RotateWorldTest.cpp \ ../Classes/SceneTest/SceneTest.cpp \ diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index e38cc2fe68..af1e2fa4cc 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -160,6 +160,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + @@ -273,6 +274,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index f6dac52c63..bf4d74d5c1 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -241,6 +241,9 @@ {0b414789-7971-4a4c-86e3-40cc00936684} + + {a83cb042-e3d6-4d3b-a4f6-30a4b3fcb3e9} + @@ -571,6 +574,9 @@ Classes\NewEventDispatcherTest + + Classes\PhysicsTest + @@ -1078,5 +1084,8 @@ Classes\NewEventDispatcherTest + + Classes\PhysicsTest + \ No newline at end of file diff --git a/samples/Lua/HelloLua/proj.win32/HelloLua.vcxproj b/samples/Lua/HelloLua/proj.win32/HelloLua.vcxproj index 7ab70c4ea1..6cc69ba5c8 100644 --- a/samples/Lua/HelloLua/proj.win32/HelloLua.vcxproj +++ b/samples/Lua/HelloLua/proj.win32/HelloLua.vcxproj @@ -77,7 +77,7 @@ Disabled - $(ProjectDir)..\Classes;$(ProjectDir)..\..\..\..\scripting\auto-generated\lua-bindings;$(ProjectDir)..\..\..\..\scripting\lua\cocos2dx_support;$(ProjectDir)..\..\..\..\scripting\lua\lua;$(ProjectDir)..\..\..\..\scripting\lua\tolua;$(ProjectDir)..\..\..\..\scripting\lua\src;$(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\..\extensions;%(AdditionalIncludeDirectories) + $(ProjectDir)..\Classes;$(ProjectDir)..\..\..\..\scripting\auto-generated\lua-bindings;$(ProjectDir)..\..\..\..\scripting\lua\cocos2dx_support;$(ProjectDir)..\..\..\..\scripting\lua\lua;$(ProjectDir)..\..\..\..\scripting\lua\tolua;$(ProjectDir)..\..\..\..\scripting\lua\src;$(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\..\extensions;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;STRICT;_DEBUG;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) false EnableFastChecks diff --git a/scripting/lua/proj.win32/liblua.vcxproj b/scripting/lua/proj.win32/liblua.vcxproj index cc6539600d..a890c7e2dc 100644 --- a/scripting/lua/proj.win32/liblua.vcxproj +++ b/scripting/lua/proj.win32/liblua.vcxproj @@ -62,7 +62,7 @@ Disabled - $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\extensions;$(ProjectDir)..\..\..\extensions\network;$(ProjectDir)..\..\..\external\libwebsockets\win32\include;$(ProjectDir)..\tolua;$(ProjectDir)..\luajit\include;$(ProjectDir)..\..\auto-generated\lua-bindings;$(ProjectDir)..\cocos2dx_support;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\extensions;$(ProjectDir)..\..\..\extensions\network;$(ProjectDir)..\..\..\external\libwebsockets\win32\include;$(ProjectDir)..\tolua;$(ProjectDir)..\luajit\include;$(ProjectDir)..\..\auto-generated\lua-bindings;$(ProjectDir)..\cocos2dx_support;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;_DEBUG;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) false EnableFastChecks From 650e6ad6fcca01f1371521f84ec509633deed937 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 17 Sep 2013 10:46:31 +0800 Subject: [PATCH 17/34] issue #2087: [dispatcher] Updating MenuTest. --- .../Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp | 17 +++++++---------- samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.h | 2 -- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp b/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp index 8b0e698c47..e8081a2563 100644 --- a/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp +++ b/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp @@ -573,19 +573,16 @@ RemoveMenuItemWhenMove::RemoveMenuItemWhenMove() setTouchEnabled(true); setTouchMode(Touch::DispatchMode::ONE_BY_ONE); -} - -void RemoveMenuItemWhenMove::onRegisterTouchListener() -{ + // Register Touch Event - auto listener = TouchEventListener::create(Touch::DispatchMode::ONE_BY_ONE); - listener->setSwallowTouches(false); + _touchListener = TouchEventListener::create(Touch::DispatchMode::ONE_BY_ONE); + _touchListener->setSwallowTouches(false); - listener->onTouchBegan = CC_CALLBACK_2(RemoveMenuItemWhenMove::onTouchBegan, this); - listener->onTouchMoved = CC_CALLBACK_2(RemoveMenuItemWhenMove::onTouchMoved, this); + _touchListener->onTouchBegan = CC_CALLBACK_2(RemoveMenuItemWhenMove::onTouchBegan, this); + _touchListener->onTouchMoved = CC_CALLBACK_2(RemoveMenuItemWhenMove::onTouchMoved, this); + + EventDispatcher::getInstance()->addEventListenerWithFixedPriority(_touchListener, -100); - EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, -100); - _touchListener = listener; } void RemoveMenuItemWhenMove::goBack(Object *pSender) diff --git a/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.h b/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.h index af97bf66aa..a6384d0195 100644 --- a/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.h +++ b/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.h @@ -107,8 +107,6 @@ public: RemoveMenuItemWhenMove(); ~RemoveMenuItemWhenMove(); - virtual void onRegisterTouchListener() override; -// virtual void registerWithTouchDispatcher(void); virtual bool onTouchBegan(Touch *touch, Event *event); virtual void onTouchMoved(Touch *touch, Event *event); From 54f7146d5f7401e39f704af73bada2e9812350b6 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 17 Sep 2013 11:18:53 +0800 Subject: [PATCH 18/34] issue #2771: update vs project setting --- samples/Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj | 2 +- samples/Lua/HelloLua/proj.win32/HelloLua.vcxproj | 2 +- scripting/lua/proj.win32/liblua.vcxproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj b/samples/Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj index cc87373ff7..2e747d142d 100644 --- a/samples/Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj +++ b/samples/Cpp/HelloCpp/proj.win32/HelloCpp.vcxproj @@ -84,7 +84,7 @@ true Windows MachineX86 - libcocos2d.lib;%(AdditionalDependencies) + libcocos2d.lib;libchipmunk.lib;%(AdditionalDependencies) diff --git a/samples/Lua/HelloLua/proj.win32/HelloLua.vcxproj b/samples/Lua/HelloLua/proj.win32/HelloLua.vcxproj index 6cc69ba5c8..b8fd26308f 100644 --- a/samples/Lua/HelloLua/proj.win32/HelloLua.vcxproj +++ b/samples/Lua/HelloLua/proj.win32/HelloLua.vcxproj @@ -95,7 +95,7 @@ $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(IntDir);%(AdditionalIncludeDirectories) - libcocos2d.lib;libCocosDenshion.lib;liblua.lib;lua51.lib;libExtensions.lib;websockets.lib;%(AdditionalDependencies) + libcocos2d.lib;libCocosDenshion.lib;liblua.lib;lua51.lib;libExtensions.lib;websockets.lib;libchipmunk.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) true Windows diff --git a/scripting/lua/proj.win32/liblua.vcxproj b/scripting/lua/proj.win32/liblua.vcxproj index a890c7e2dc..1c646b774c 100644 --- a/scripting/lua/proj.win32/liblua.vcxproj +++ b/scripting/lua/proj.win32/liblua.vcxproj @@ -62,7 +62,7 @@ Disabled - $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\extensions;$(ProjectDir)..\..\..\extensions\network;$(ProjectDir)..\..\..\external\libwebsockets\win32\include;$(ProjectDir)..\tolua;$(ProjectDir)..\luajit\include;$(ProjectDir)..\..\auto-generated\lua-bindings;$(ProjectDir)..\cocos2dx_support;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\extensions;$(ProjectDir)..\..\..\extensions\network;$(ProjectDir)..\..\..\external\libwebsockets\win32\include;$(ProjectDir)..\tolua;$(ProjectDir)..\luajit\include;$(ProjectDir)..\..\auto-generated\lua-bindings;$(ProjectDir)..\cocos2dx_support;$(ProjectDir)..\..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;_DEBUG;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) false EnableFastChecks From 40ed7bc326c8a3194ed0217fb00ce52582fea124 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 17 Sep 2013 12:59:38 +0800 Subject: [PATCH 19/34] Add a deprecated function --- scripting/lua/script/Deprecated.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripting/lua/script/Deprecated.lua b/scripting/lua/script/Deprecated.lua index a2d6ac9878..82be56c5c6 100644 --- a/scripting/lua/script/Deprecated.lua +++ b/scripting/lua/script/Deprecated.lua @@ -28,6 +28,12 @@ function CCTextureCacheDeprecated.purgeSharedTextureCache() return cc.TextureCache:destroyInstance() end rawset(CCTextureCache,"purgeSharedTextureCache",CCTextureCacheDeprecated.purgeSharedTextureCache) + +function CCTextureCacheDeprecated.addUIImage(self, image, key) + deprecatedTip("CCTextureCache:addUIImage","CCTextureCache:addImage") + return self:addImage(image,key) +end +rawset(CCTextureCache,"addUIImage",CCTextureCacheDeprecated.addUIImage) --functions of CCTextureCache will be deprecated end --functions of CCAnimation will be deprecated begin From a25c2cabf8b9b51c742b4109ab36173d72407237 Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Tue, 17 Sep 2013 13:25:15 +0800 Subject: [PATCH 20/34] 1. Fixes failed to build windows. 2. Upload CocoGUI Resources. --- extensions/CocoStudio/GUI/Layouts/Layout.cpp | 4 +- .../cocosgui/Hello.png.REMOVED.git-id | 1 + .../UITest/background.png.REMOVED.git-id | 1 + .../Resources/cocosgui/b11.png.REMOVED.git-id | 1 + .../bitmapFontTest2.png.REMOVED.git-id | 1 + .../examples/examples.json.REMOVED.git-id | 1 + .../equip_1/equip_1.json.REMOVED.git-id | 1 + .../map_1/map_pve.png.REMOVED.git-id | 1 + .../page_1/background.png.REMOVED.git-id | 1 + .../hd/cocosgui/Hello.png.REMOVED.git-id | 1 + .../UITest/background.png.REMOVED.git-id | 1 + .../hd/cocosgui/b11.png.REMOVED.git-id | 1 + .../bitmapFontTest2.png.REMOVED.git-id | 1 + .../examples/examples.json.REMOVED.git-id | 1 + .../equip_1/equip_1.json.REMOVED.git-id | 1 + .../map_1/map_pve.png.REMOVED.git-id | 1 + .../page_1/background.png.REMOVED.git-id | 1 + .../Cpp/TestCpp/proj.win32/TestCpp.vcxproj | 40 ++++ .../proj.win32/TestCpp.vcxproj.filters | 174 ++++++++++++++++++ 19 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 samples/Cpp/TestCpp/Resources/cocosgui/Hello.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/cocosgui/UITest/background.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/cocosgui/b11.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/cocosgui/examples/examples.json.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/equip_1/equip_1.json.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/hd/cocosgui/Hello.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/hd/cocosgui/UITest/background.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/hd/cocosgui/b11.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/hd/cocosgui/bitmapFontTest2.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/hd/cocosgui/examples/examples.json.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/equip_1/equip_1.json.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id diff --git a/extensions/CocoStudio/GUI/Layouts/Layout.cpp b/extensions/CocoStudio/GUI/Layouts/Layout.cpp index 779ff73616..17e90a2108 100644 --- a/extensions/CocoStudio/GUI/Layouts/Layout.cpp +++ b/extensions/CocoStudio/GUI/Layouts/Layout.cpp @@ -462,7 +462,7 @@ bool RectClippingNode::init() rect[2] = Point(_clippingSize.width, _clippingSize.height); rect[3] = Point(0, _clippingSize.height); - Color4F green = {0, 1, 0, 1}; + Color4F green(0, 1, 0, 1); m_pInnerStencil->drawPolygon(rect, 4, green, 0, green); if (CCClippingNode::init(m_pInnerStencil)) { @@ -480,7 +480,7 @@ void RectClippingNode::setClippingSize(const Size &size) rect[1] = Point(_clippingSize.width, 0); rect[2] = Point(_clippingSize.width, _clippingSize.height); rect[3] = Point(0, _clippingSize.height); - Color4F green = {0, 1, 0, 1}; + Color4F green(0, 1, 0, 1); m_pInnerStencil->clear(); m_pInnerStencil->drawPolygon(rect, 4, green, 0, green); } diff --git a/samples/Cpp/TestCpp/Resources/cocosgui/Hello.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/cocosgui/Hello.png.REMOVED.git-id new file mode 100644 index 0000000000..f02d84fd8f --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/cocosgui/Hello.png.REMOVED.git-id @@ -0,0 +1 @@ +5fe89fb5bd58cedf13b0363f97b20e3ea7ff255d \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/cocosgui/UITest/background.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/cocosgui/UITest/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/cocosgui/UITest/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/cocosgui/b11.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/cocosgui/b11.png.REMOVED.git-id new file mode 100644 index 0000000000..0b4502562c --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/cocosgui/b11.png.REMOVED.git-id @@ -0,0 +1 @@ +39179659c7b94b213b6ab7b24372c96378f61062 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id new file mode 100644 index 0000000000..d025022480 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id @@ -0,0 +1 @@ +9975e4961272d5bda6d5f3bbd61ea0fc02222199 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/cocosgui/examples/examples.json.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/cocosgui/examples/examples.json.REMOVED.git-id new file mode 100644 index 0000000000..f28818a9af --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/cocosgui/examples/examples.json.REMOVED.git-id @@ -0,0 +1 @@ +0a4ce85782909e964aa0e95e89bab8272d0c3d4e \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/equip_1/equip_1.json.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/equip_1/equip_1.json.REMOVED.git-id new file mode 100644 index 0000000000..596d52b27c --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/equip_1/equip_1.json.REMOVED.git-id @@ -0,0 +1 @@ +0a77108d377ceb5f084f1aab1877159df9499428 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id new file mode 100644 index 0000000000..6f99243a26 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id @@ -0,0 +1 @@ +39d29cbeb700598c3e4ad6d3ee0ac273a3385fcd \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/cocosgui/Hello.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/cocosgui/Hello.png.REMOVED.git-id new file mode 100644 index 0000000000..bf03af4205 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/cocosgui/Hello.png.REMOVED.git-id @@ -0,0 +1 @@ +a6e5d948d0c85ecc42b7a2ebf5751e3990002bac \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/cocosgui/UITest/background.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/cocosgui/UITest/background.png.REMOVED.git-id new file mode 100644 index 0000000000..1f73829609 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/cocosgui/UITest/background.png.REMOVED.git-id @@ -0,0 +1 @@ +eff519b0334eaeb486f302ec2581771950b7cca2 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/cocosgui/b11.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/cocosgui/b11.png.REMOVED.git-id new file mode 100644 index 0000000000..7ad21adacb --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/cocosgui/b11.png.REMOVED.git-id @@ -0,0 +1 @@ +021493cabd2489bf2c20c657e5523e24608df86c \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/cocosgui/bitmapFontTest2.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/cocosgui/bitmapFontTest2.png.REMOVED.git-id new file mode 100644 index 0000000000..d025022480 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/cocosgui/bitmapFontTest2.png.REMOVED.git-id @@ -0,0 +1 @@ +9975e4961272d5bda6d5f3bbd61ea0fc02222199 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/cocosgui/examples/examples.json.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/cocosgui/examples/examples.json.REMOVED.git-id new file mode 100644 index 0000000000..f28818a9af --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/cocosgui/examples/examples.json.REMOVED.git-id @@ -0,0 +1 @@ +0a4ce85782909e964aa0e95e89bab8272d0c3d4e \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/equip_1/equip_1.json.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/equip_1/equip_1.json.REMOVED.git-id new file mode 100644 index 0000000000..596d52b27c --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/equip_1/equip_1.json.REMOVED.git-id @@ -0,0 +1 @@ +0a77108d377ceb5f084f1aab1877159df9499428 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id new file mode 100644 index 0000000000..7e87ef6cb4 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id @@ -0,0 +1 @@ +1a6a5a2f571c692a962e9159fca8ea5d6879a748 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id new file mode 100644 index 0000000000..1f73829609 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id @@ -0,0 +1 @@ +eff519b0334eaeb486f302ec2581771950b7cca2 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index e38cc2fe68..d8c38569e3 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -146,6 +146,26 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + + + + + + + + + + + + + + + + + + + + @@ -260,6 +280,26 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + + + + + + + + + + + + + + + + + + + + diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index f6dac52c63..cf47e0d936 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -241,6 +241,60 @@ {0b414789-7971-4a4c-86e3-40cc00936684} + + {9daecd38-37c6-4216-a999-86077af83beb} + + + {493fcd85-c749-482d-9404-905e99aa0103} + + + {5c1960de-24ba-4b72-be18-cc160dd2a50d} + + + {175b363b-a41a-4b1d-bde1-970e77e64cff} + + + {2e08949f-bf73-4fdc-85e8-34b8c69aa978} + + + {c57c0453-a096-44d7-830b-1cf24c712cfd} + + + {c4dbbfb3-0e91-492f-bbbf-f03fb26f3f54} + + + {01097388-e538-4081-8e16-d1ff3a86292a} + + + {160da6f0-a0f1-4a53-8e5e-cf0a63ee82a3} + + + {fadff96e-c19a-41f5-a755-547cf1f8a5fb} + + + {73c268e8-3872-49d6-9204-1e679ff72a42} + + + {6e7f1d2a-c8c1-4f48-826f-930bc8a0556e} + + + {305e1c54-9321-49f7-8672-46d1286dbe83} + + + {df6e9468-93f7-472d-be1d-d274d7de677e} + + + {dedcabba-959c-40e3-9959-7ccf4e31c792} + + + {cfc87c30-a7b4-4b6f-bc5d-da45360466b6} + + + {5caf2179-ae22-4040-8bac-17e9f22efbf7} + + + {24f044ee-09a6-406b-98d7-8d5d759e5bb1} + @@ -571,6 +625,66 @@ Classes\NewEventDispatcherTest + + Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UICheckBoxTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIDragPanelTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIImageViewTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UILabelAtlasTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UILabelBMFontTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UILabelTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIListViewTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UILoadingBarTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UINodeContainerTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIPageViewTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIPanelTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIScrollViewTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UISliderTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UITextAreaTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UITextButtonTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UITextFieldTest + + + Classes\ExtensionsTest\CocoStudioGUITest + + + Classes\ExtensionsTest\CocoStudioGUITest + + + Classes\ExtensionsTest\CocoStudioGUITest + @@ -1078,5 +1192,65 @@ Classes\NewEventDispatcherTest + + Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UICheckBoxTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIDragPanelTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIImageViewTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UILabelAtlasTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UILabelBMFontTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UILabelTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIListViewTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UILoadingBarTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UINodeContainerTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIPageViewTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIPanelTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UIScrollViewTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UISliderTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UITextAreaTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UITextButtonTest + + + Classes\ExtensionsTest\CocoStudioGUITest\UITextFieldTest + + + Classes\ExtensionsTest\CocoStudioGUITest + + + Classes\ExtensionsTest\CocoStudioGUITest + + + Classes\ExtensionsTest\CocoStudioGUITest + \ No newline at end of file From 3809a6feed508be682e1b7cb1df885cefa3f0b51 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 17 Sep 2013 13:59:48 +0800 Subject: [PATCH 21/34] Repair some lua test samples bug and del tool/tolua++ folders --- .../ClickAndMoveTest/ClickAndMoveTest.lua | 4 +- .../Resources/luaScript/MenuTest/MenuTest.lua | 1 - tools/tolua++/CCAction.pkg | 298 ----------- tools/tolua++/CCActionCamera.pkg | 13 - tools/tolua++/CCActionCatmullRom.pkg | 44 -- tools/tolua++/CCActionEase.pkg | 149 ------ tools/tolua++/CCActionGrid.pkg | 65 --- tools/tolua++/CCActionGrid3D.pkg | 79 --- tools/tolua++/CCActionManager.pkg | 25 - tools/tolua++/CCActionPageTurn3D.pkg | 5 - tools/tolua++/CCActionProgressTimer.pkg | 10 - tools/tolua++/CCActionTiledGrid.pkg | 85 --- tools/tolua++/CCAffineTransform.pkg | 24 - tools/tolua++/CCAnimation.pkg | 50 -- tools/tolua++/CCAnimationCache.pkg | 13 - tools/tolua++/CCApplication.pkg | 35 -- tools/tolua++/CCArray.pkg | 56 -- tools/tolua++/CCAtlasNode.pkg | 24 - tools/tolua++/CCCamera.pkg | 22 - tools/tolua++/CCCommon.pkg | 3 - tools/tolua++/CCControl.pkg | 62 --- tools/tolua++/CCControlButton.pkg | 111 ---- tools/tolua++/CCControlColourPicker.pkg | 23 - tools/tolua++/CCControlPotentiometer.pkg | 42 -- tools/tolua++/CCControlSlider.pkg | 39 -- tools/tolua++/CCControlStepper.pkg | 47 -- tools/tolua++/CCControlSwitch.pkg | 26 - tools/tolua++/CCDictionary.pkg | 26 - tools/tolua++/CCDirector.pkg | 61 --- tools/tolua++/CCDrawNode.pkg | 22 - tools/tolua++/CCEGLViewProtocol.pkg | 91 ---- tools/tolua++/CCEditBox.pkg | 103 ---- tools/tolua++/CCFileUtils.pkg | 19 - tools/tolua++/CCGeometry.pkg | 63 --- tools/tolua++/CCImage.pkg | 60 --- tools/tolua++/CCInteger.pkg | 7 - tools/tolua++/CCKeypadDispatcher.pkg | 6 - tools/tolua++/CCLabelAtlas.pkg | 14 - tools/tolua++/CCLabelBMFont.pkg | 39 -- tools/tolua++/CCLabelTTF.pkg | 29 - tools/tolua++/CCLayer.pkg | 104 ---- tools/tolua++/CCMenu.pkg | 38 -- tools/tolua++/CCMenuItem.pkg | 130 ----- tools/tolua++/CCMotionStreak.pkg | 25 - tools/tolua++/CCNode.pkg | 146 ----- tools/tolua++/CCNotificationCenter.pkg | 24 - tools/tolua++/CCObject.pkg | 10 - tools/tolua++/CCParallaxNode.pkg | 16 - tools/tolua++/CCParticleBatchNode.pkg | 23 - tools/tolua++/CCParticleExamples.pkg | 55 -- tools/tolua++/CCParticleSystem.pkg | 152 ------ tools/tolua++/CCPointExtension.pkg | 1 - tools/tolua++/CCProgressTimer.pkg | 36 -- tools/tolua++/CCProtocols.pkg | 18 - tools/tolua++/CCRenderTexture.pkg | 30 -- tools/tolua++/CCRibbon.pkg | 20 - tools/tolua++/CCScale9Sprite.pkg | 92 ---- tools/tolua++/CCScene.pkg | 5 - tools/tolua++/CCScheduler.pkg | 19 - tools/tolua++/CCSet.pkg | 10 - tools/tolua++/CCSprite.pkg | 96 ---- tools/tolua++/CCSpriteBatchNode.pkg | 38 -- tools/tolua++/CCSpriteFrame.pkg | 32 -- tools/tolua++/CCSpriteFrameCache.pkg | 21 - tools/tolua++/CCString.pkg | 19 - tools/tolua++/CCTMXLayer.pkg | 37 -- tools/tolua++/CCTMXObjectGroup.pkg | 19 - tools/tolua++/CCTMXTiledMap.pkg | 36 -- tools/tolua++/CCTMXXMLParser.pkg | 76 --- tools/tolua++/CCTextFieldTTF.pkg | 18 - tools/tolua++/CCTexture2D.pkg | 505 ------------------ tools/tolua++/CCTextureAtlas.pkg | 30 -- tools/tolua++/CCTextureCache.pkg | 18 - tools/tolua++/CCTileMapAtlas.pkg | 16 - tools/tolua++/CCTouch.pkg | 16 - tools/tolua++/CCTouchDispatcher.pkg | 6 - tools/tolua++/CCTransition.pkg | 168 ------ tools/tolua++/CCTransitionProgress.pkg | 35 -- tools/tolua++/CCUserDefault.pkg | 24 - tools/tolua++/Cocos2d.pkg | 88 --- tools/tolua++/Makefile | 2 - tools/tolua++/README | 23 - tools/tolua++/SimpleAudioEngine.pkg | 25 - tools/tolua++/basic.lua | 359 ------------- tools/tolua++/build.bat | 1 - tools/tolua++/build.sh | 17 - tools/tolua++/ccTypes.pkg | 263 --------- tools/tolua++/matrix.pkg | 18 - tools/tolua++/tolua++.Mac.zip.REMOVED.git-id | 1 - tools/tolua++/tolua++.rar.REMOVED.git-id | 1 - 90 files changed, 2 insertions(+), 4855 deletions(-) delete mode 100644 tools/tolua++/CCAction.pkg delete mode 100644 tools/tolua++/CCActionCamera.pkg delete mode 100644 tools/tolua++/CCActionCatmullRom.pkg delete mode 100644 tools/tolua++/CCActionEase.pkg delete mode 100644 tools/tolua++/CCActionGrid.pkg delete mode 100644 tools/tolua++/CCActionGrid3D.pkg delete mode 100644 tools/tolua++/CCActionManager.pkg delete mode 100644 tools/tolua++/CCActionPageTurn3D.pkg delete mode 100644 tools/tolua++/CCActionProgressTimer.pkg delete mode 100644 tools/tolua++/CCActionTiledGrid.pkg delete mode 100644 tools/tolua++/CCAffineTransform.pkg delete mode 100644 tools/tolua++/CCAnimation.pkg delete mode 100644 tools/tolua++/CCAnimationCache.pkg delete mode 100644 tools/tolua++/CCApplication.pkg delete mode 100644 tools/tolua++/CCArray.pkg delete mode 100644 tools/tolua++/CCAtlasNode.pkg delete mode 100644 tools/tolua++/CCCamera.pkg delete mode 100644 tools/tolua++/CCCommon.pkg delete mode 100644 tools/tolua++/CCControl.pkg delete mode 100644 tools/tolua++/CCControlButton.pkg delete mode 100644 tools/tolua++/CCControlColourPicker.pkg delete mode 100644 tools/tolua++/CCControlPotentiometer.pkg delete mode 100644 tools/tolua++/CCControlSlider.pkg delete mode 100644 tools/tolua++/CCControlStepper.pkg delete mode 100644 tools/tolua++/CCControlSwitch.pkg delete mode 100644 tools/tolua++/CCDictionary.pkg delete mode 100644 tools/tolua++/CCDirector.pkg delete mode 100644 tools/tolua++/CCDrawNode.pkg delete mode 100644 tools/tolua++/CCEGLViewProtocol.pkg delete mode 100644 tools/tolua++/CCEditBox.pkg delete mode 100644 tools/tolua++/CCFileUtils.pkg delete mode 100644 tools/tolua++/CCGeometry.pkg delete mode 100644 tools/tolua++/CCImage.pkg delete mode 100644 tools/tolua++/CCInteger.pkg delete mode 100644 tools/tolua++/CCKeypadDispatcher.pkg delete mode 100644 tools/tolua++/CCLabelAtlas.pkg delete mode 100644 tools/tolua++/CCLabelBMFont.pkg delete mode 100644 tools/tolua++/CCLabelTTF.pkg delete mode 100644 tools/tolua++/CCLayer.pkg delete mode 100644 tools/tolua++/CCMenu.pkg delete mode 100644 tools/tolua++/CCMenuItem.pkg delete mode 100644 tools/tolua++/CCMotionStreak.pkg delete mode 100644 tools/tolua++/CCNode.pkg delete mode 100644 tools/tolua++/CCNotificationCenter.pkg delete mode 100644 tools/tolua++/CCObject.pkg delete mode 100644 tools/tolua++/CCParallaxNode.pkg delete mode 100644 tools/tolua++/CCParticleBatchNode.pkg delete mode 100644 tools/tolua++/CCParticleExamples.pkg delete mode 100644 tools/tolua++/CCParticleSystem.pkg delete mode 100644 tools/tolua++/CCPointExtension.pkg delete mode 100644 tools/tolua++/CCProgressTimer.pkg delete mode 100644 tools/tolua++/CCProtocols.pkg delete mode 100644 tools/tolua++/CCRenderTexture.pkg delete mode 100644 tools/tolua++/CCRibbon.pkg delete mode 100644 tools/tolua++/CCScale9Sprite.pkg delete mode 100644 tools/tolua++/CCScene.pkg delete mode 100644 tools/tolua++/CCScheduler.pkg delete mode 100644 tools/tolua++/CCSet.pkg delete mode 100644 tools/tolua++/CCSprite.pkg delete mode 100644 tools/tolua++/CCSpriteBatchNode.pkg delete mode 100644 tools/tolua++/CCSpriteFrame.pkg delete mode 100644 tools/tolua++/CCSpriteFrameCache.pkg delete mode 100644 tools/tolua++/CCString.pkg delete mode 100644 tools/tolua++/CCTMXLayer.pkg delete mode 100644 tools/tolua++/CCTMXObjectGroup.pkg delete mode 100644 tools/tolua++/CCTMXTiledMap.pkg delete mode 100644 tools/tolua++/CCTMXXMLParser.pkg delete mode 100644 tools/tolua++/CCTextFieldTTF.pkg delete mode 100644 tools/tolua++/CCTexture2D.pkg delete mode 100644 tools/tolua++/CCTextureAtlas.pkg delete mode 100644 tools/tolua++/CCTextureCache.pkg delete mode 100644 tools/tolua++/CCTileMapAtlas.pkg delete mode 100644 tools/tolua++/CCTouch.pkg delete mode 100644 tools/tolua++/CCTouchDispatcher.pkg delete mode 100644 tools/tolua++/CCTransition.pkg delete mode 100644 tools/tolua++/CCTransitionProgress.pkg delete mode 100644 tools/tolua++/CCUserDefault.pkg delete mode 100644 tools/tolua++/Cocos2d.pkg delete mode 100644 tools/tolua++/Makefile delete mode 100644 tools/tolua++/README delete mode 100644 tools/tolua++/SimpleAudioEngine.pkg delete mode 100644 tools/tolua++/basic.lua delete mode 100644 tools/tolua++/build.bat delete mode 100755 tools/tolua++/build.sh delete mode 100644 tools/tolua++/ccTypes.pkg delete mode 100644 tools/tolua++/matrix.pkg delete mode 100644 tools/tolua++/tolua++.Mac.zip.REMOVED.git-id delete mode 100644 tools/tolua++/tolua++.rar.REMOVED.git-id diff --git a/samples/Lua/TestLua/Resources/luaScript/ClickAndMoveTest/ClickAndMoveTest.lua b/samples/Lua/TestLua/Resources/luaScript/ClickAndMoveTest/ClickAndMoveTest.lua index 781a8824e6..ee13a9c390 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ClickAndMoveTest/ClickAndMoveTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ClickAndMoveTest/ClickAndMoveTest.lua @@ -59,9 +59,9 @@ function ClickAndMoveTest() layer = cc.Layer:create() initWithLayer() - - scene:addChild(CreateBackMenuItem()) scene:addChild(layer) + scene:addChild(CreateBackMenuItem()) + return scene end diff --git a/samples/Lua/TestLua/Resources/luaScript/MenuTest/MenuTest.lua b/samples/Lua/TestLua/Resources/luaScript/MenuTest/MenuTest.lua index 0e8d723b25..25588d87eb 100644 --- a/samples/Lua/TestLua/Resources/luaScript/MenuTest/MenuTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/MenuTest/MenuTest.lua @@ -23,7 +23,6 @@ local function MenuLayerMainMenu() local ret = cc.Layer:create() ret:setTouchEnabled(true) - ret:setTouchPriority(cc.MENU_HANDLER_PRIORITY + 1) ret:setTouchMode(cc.TOUCHES_ONE_BY_ONE ) -- Font Item diff --git a/tools/tolua++/CCAction.pkg b/tools/tolua++/CCAction.pkg deleted file mode 100644 index 043e16809d..0000000000 --- a/tools/tolua++/CCAction.pkg +++ /dev/null @@ -1,298 +0,0 @@ - -enum { - kCCActionTagInvalid = -1, -}; - -class CCAction : public CCObject -{ - bool isDone(void); - CCNode* getTarget(void); - // void setTarget(CCNode *pTarget); - CCNode* getOriginalTarget(void); - // void setOriginalTarget(CCNode *pOriginalTarget); - int getTag(void); - void setTag(int nTag); - CCAction* clone(); - CCObject* copy(); -}; - -class CCFiniteTimeAction : public CCAction -{ - float getDuration(void); - void setDuration(float duration); - CCFiniteTimeAction* reverse(void); -}; - -class CCActionInterval : public CCFiniteTimeAction -{ - float getElapsed(void); - bool isDone(void); - void setAmplitudeRate(float amp); - float getAmplitudeRate(void); - CCActionInterval* reverse(void); -}; - -// CCActionInterval -class CCSpeed : public CCAction -{ - float getSpeed(void); - void setSpeed(float fSpeed); - CCActionInterval* reverse(void); - bool isDone(void); - - static CCSpeed* create(CCActionInterval *pAction, float fRate); -}; - -class CCFollow : public CCAction -{ - bool isBoundarySet(void); - void setBoudarySet(bool bValue); - bool isDone(void); - - static CCFollow* create(CCNode *pFollowedNode, CCRect rect); - static CCFollow* create(CCNode *pFollowedNode); -}; - -class CCSequence : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCSequence* createWithTwoActions(CCFiniteTimeAction *pActionOne, CCFiniteTimeAction *pActionTwo); - static CCSequence* create(CCArray *actions); -}; - -class CCRepeat : public CCActionInterval -{ - bool isDone(void); - CCActionInterval* reverse(void); - - static CCRepeat* create(CCFiniteTimeAction *pAction, unsigned int times); -}; - -class CCRepeatForever : public CCActionInterval -{ - bool isDone(void); - CCActionInterval* reverse(void); - - static CCRepeatForever* create(CCActionInterval *pAction); -}; - -class CCSpawn : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCSpawn* createWithTwoActions(CCFiniteTimeAction *pAction1, CCFiniteTimeAction *pAction2); - static CCSpawn* create(CCArray *actions); -}; - -class CCRotateTo : public CCActionInterval -{ - - static CCRotateTo* create(float duration, float fDeltaAngle); -}; - -class CCRotateBy : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCRotateBy* create(float duration, float fDeltaAngle); - static CCRotateBy* create(float duration, float fDeltaAngleX, float DeltaAngleY); -}; - -class CCMoveTo : public CCActionInterval -{ - - static CCMoveTo* create(float duration, CCPoint position); -}; - -class CCMoveBy : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCMoveBy* create(float duration, CCPoint deltaPosition); -}; - -class CCSkewTo : public CCActionInterval -{ - - static CCSkewTo* create(float t, float sx, float sy); -}; - -class CCSkewBy : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCSkewBy* create(float t, float deltaSkewX, float deltaSkewY); -}; - -class CCJumpBy : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCJumpBy* create(float duration, CCPoint position, float height, int jumps); -}; - -class CCJumpTo : public CCActionInterval -{ - - static CCJumpTo* create(float duration, CCPoint position, float height, int jumps); -}; - -/* - There's a bug in tolua++ - Can't use struct in lua after binding struct - So use class instead. -*/ -class ccBezierConfig { - ccBezierConfig(void); - CCPoint endPosition; - CCPoint controlPoint_1; - CCPoint controlPoint_2; -}; - -class CCBezierBy : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCBezierBy* create(float t, ccBezierConfig c); -}; - -class CCBezierTo : public CCActionInterval -{ - - static CCBezierTo* create(float t, ccBezierConfig c); -}; - -class CCScaleTo : public CCActionInterval -{ - - static CCScaleTo* create(float duration, float sx, float sy); - static CCScaleTo* create(float duration, float s); -}; - -class CCScaleBy : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCScaleBy* create(float duration, float s); - static CCScaleBy* create(float duration, float sx, float sy); -}; - -class CCBlink : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCBlink* create(float duration, unsigned int uBlinks); -}; - -class CCFadeIn : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCFadeIn* create(float d); -}; - -class CCFadeOut : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCFadeOut* create(float d); -}; - -class CCFadeTo : public CCActionInterval -{ - - static CCFadeTo* create(float duration, GLubyte opacity); -}; - -class CCTintTo : public CCActionInterval -{ - - static CCTintTo* create(float duration, GLubyte red, GLubyte green, GLubyte blue); -}; - -class CCTintBy : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCTintBy* create(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue); -}; - -class CCDelayTime : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCDelayTime* create(float d); -}; - -class CCReverseTime : public CCActionInterval -{ - CCActionInterval* reverse(void); - - static CCReverseTime* create(CCFiniteTimeAction *pAction); -}; - -class CCAnimate : public CCActionInterval -{ - CCActionInterval* reverse(void); - - CCAnimation* getAnimation(void); - void setAnimation(CCAnimation *pAnimation); - - static CCAnimate* create(CCAnimation *pAnimation); -}; - -class CCTargetedAction : public CCActionInterval -{ - CCNode* getForcedTarget(void); - void setForcedTarget(CCNode* target); - - static CCTargetedAction* create(CCNode* pTarget, CCFiniteTimeAction* pAction); -}; - - -// CCActionInstant -class CCActionInstant : public CCFiniteTimeAction -{ - CCFiniteTimeAction* reverse(void); - bool isDone(void); -}; - -class CCShow : public CCActionInstant -{ - CCFiniteTimeAction* reverse(void); - - static CCShow* create(); -}; - -class CCHide : public CCActionInstant -{ - CCFiniteTimeAction* reverse(void); - - static CCHide* create(); -}; - -class CCToggleVisibility : public CCActionInstant -{ - - static CCToggleVisibility* create(); -}; - -class CCFlipX : public CCActionInstant -{ - CCFiniteTimeAction* reverse(void); - - static CCFlipX* create(bool x); -}; - -class CCFlipY : public CCActionInstant -{ - CCFiniteTimeAction* reverse(void); - - static CCFlipY* create(bool y); -}; - -class CCPlace : public CCActionInstant // -{ - static CCPlace* create(CCPoint pos); -}; diff --git a/tools/tolua++/CCActionCamera.pkg b/tools/tolua++/CCActionCamera.pkg deleted file mode 100644 index 0063c75a73..0000000000 --- a/tools/tolua++/CCActionCamera.pkg +++ /dev/null @@ -1,13 +0,0 @@ - -class CCActionCamera : public CCActionInterval -{ - void startWithTarget(CCNode *pTarget); - CCActionInterval* reverse(); -}; - -class CCOrbitCamera : public CCActionCamera -{ - void sphericalRadius(float *r, float *zenith, float *azimuth); - - static CCOrbitCamera * create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX); -}; diff --git a/tools/tolua++/CCActionCatmullRom.pkg b/tools/tolua++/CCActionCatmullRom.pkg deleted file mode 100644 index d26651c2a1..0000000000 --- a/tools/tolua++/CCActionCatmullRom.pkg +++ /dev/null @@ -1,44 +0,0 @@ - -class CCPointArray : public CCNode -{ - bool initWithCapacity(unsigned int capacity); - void addControlPoint(CCPoint controlPoint); - void insertControlPoint(CCPoint &controlPoint, unsigned int index); - void replaceControlPoint(CCPoint &controlPoint, unsigned int index); - CCPoint getControlPointAtIndex(unsigned int index); - void removeControlPointAtIndex(unsigned int index); - unsigned int count(); - CCPointArray* reverse(); - void reverseInline(); - const std::vector* getControlPoints(); - void setControlPoints(std::vector *controlPoints); - - static CCPointArray* create(unsigned int capacity); -}; - -class CCCardinalSplineTo : public CCActionInterval -{ - CCActionInterval* reverse(); - CCPointArray* getPoints(); - void setPoints(CCPointArray* points); - - static CCCardinalSplineTo* create(float duration, CCPointArray* points, float tension); -}; - - -class CCCardinalSplineBy : public CCCardinalSplineTo -{ - CCActionInterval* reverse(); - - static CCCardinalSplineBy* create(float duration, CCPointArray* points, float tension); -}; - -class CCCatmullRomTo : public CCCardinalSplineTo -{ - static CCCatmullRomTo* create(float dt, CCPointArray* points); -}; - -class CCCatmullRomBy : public CCCardinalSplineBy -{ - static CCCatmullRomBy* create(float dt, CCPointArray* points); -}; diff --git a/tools/tolua++/CCActionEase.pkg b/tools/tolua++/CCActionEase.pkg deleted file mode 100644 index 00409506a1..0000000000 --- a/tools/tolua++/CCActionEase.pkg +++ /dev/null @@ -1,149 +0,0 @@ - -class CCActionEase : public CCActionInterval -{ - CCActionInterval* reverse(void); -}; - -class CCEaseRateAction : public CCActionEase -{ - CCActionInterval* reverse(void); -}; - -class CCEaseIn : public CCEaseRateAction -{ - CCActionInterval* reverse(void); - - static CCEaseIn* create(CCActionInterval* pAction, float fRate); -}; - -class CCEaseOut : public CCEaseRateAction -{ - CCActionInterval* reverse(void); - - static CCEaseOut* create(CCActionInterval* pAction, float fRate); -}; - -class CCEaseInOut : public CCEaseRateAction -{ - CCActionInterval* reverse(void); - - static CCEaseInOut* create(CCActionInterval* pAction, float fRate); -}; - -class CCEaseExponentialIn : public CCActionEase -{ - CCActionInterval* reverse(void); - - static CCEaseExponentialIn* create(CCActionInterval* pAction); -}; - -class CCEaseExponentialOut : public CCActionEase -{ - CCActionInterval* reverse(void); - - static CCEaseExponentialOut* create(CCActionInterval* pAction); -}; - -class CCEaseExponentialInOut : public CCActionEase -{ - CCActionInterval* reverse(void); - - static CCEaseExponentialInOut* create(CCActionInterval* pAction); -}; - -class CCEaseSineIn : public CCActionEase -{ - CCActionInterval* reverse(void); - - static CCEaseSineIn* create(CCActionInterval* pAction); -}; - -class CCEaseSineOut : public CCActionEase -{ - CCActionInterval* reverse(void); - - static CCEaseSineOut* create(CCActionInterval* pAction); -}; - -class CCEaseSineInOut : public CCActionEase -{ - CCActionInterval* reverse(void); - - static CCEaseSineInOut* create(CCActionInterval* pAction); -}; - -class CCEaseElastic : public CCActionEase -{ - CCActionInterval* reverse(void); - - float getPeriod(void); - void setPeriod(float fPeriod); -}; - -class CCEaseElasticIn : public CCEaseElastic -{ - CCActionInterval* reverse(void); - - static CCEaseElasticIn* create(CCActionInterval *pAction, float fPeriod = 0.3); -}; - -class CCEaseElasticOut : public CCEaseElastic -{ - CCActionInterval* reverse(void); - - static CCEaseElasticOut* create(CCActionInterval *pAction, float fPeriod = 0.3); -}; - -class CCEaseElasticInOut : public CCEaseElastic -{ - CCActionInterval* reverse(void); - - static CCEaseElasticInOut* create(CCActionInterval *pAction, float fPeriod = 0.3); -}; - -class CCEaseBounce : public CCActionEase -{ - CCActionInterval* reverse(void); -}; - -class CCEaseBounceIn : public CCEaseBounce -{ - CCActionInterval* reverse(void); - - static CCEaseBounceIn* create(CCActionInterval* pAction); -}; - -class CCEaseBounceOut : public CCEaseBounce -{ - CCActionInterval* reverse(void); - - static CCEaseBounceOut* create(CCActionInterval* pAction); -}; - -class CCEaseBounceInOut : public CCEaseBounce -{ - CCActionInterval* reverse(void); - - static CCEaseBounceInOut* create(CCActionInterval* pAction); -}; - -class CCEaseBackIn : public CCActionEase -{ - CCActionInterval* reverse(void); - - static CCEaseBackIn* create(CCActionInterval* pAction); -}; - -class CCEaseBackOut : public CCActionEase -{ - CCActionInterval* reverse(void); - - static CCEaseBackOut* create(CCActionInterval* pAction); -}; - -class CCEaseBackInOut : public CCActionEase -{ - CCActionInterval* reverse(void); - - static CCEaseBackInOut* create(CCActionInterval* pAction); -}; diff --git a/tools/tolua++/CCActionGrid.pkg b/tools/tolua++/CCActionGrid.pkg deleted file mode 100644 index bcd89597b5..0000000000 --- a/tools/tolua++/CCActionGrid.pkg +++ /dev/null @@ -1,65 +0,0 @@ - -class CCGridAction : public CCActionInterval -{ - CCActionInterval* reverse(void); - - CCGridBase* getGrid(void); -}; - -class CCAccelDeccelAmplitude : public CCActionInterval -{ - CCActionInterval* reverse(void); - - float getRate(void); - void setRate(float fRate); - - static CCAccelDeccelAmplitude* create(CCAction *pAction, float duration); -}; - -class CCGrid3DAction : public CCGridAction -{ - virtual CCGridBase* getGrid(void); - void setVertex(const CCPoint& pos, const Vertex3F& vertex); - Vertex3F getVertex(const CCPoint& position); - Vertex3F getOriginalVertex(const CCPoint& position); -}; - -class CCTiledGrid3DAction : public CCGridAction -{ - void setTile(CCPoint pos, Quad3 coords); - CCGridBase* getGrid(void); - Quad3 getTile(const CCPoint& position); - Quad3 getOriginalTile(const CCPoint& position); - - //static CCTiledGrid3DAction* create(float duration, const CCSize& gridSize); -}; - -class CCAccelAmplitude : public CCActionInterval -{ - CCActionInterval* reverse(void); - - float getRate(void); - void setRate(float fRate); - - static CCAccelAmplitude* create(CCAction *pAction, float duration); -}; - -class CCDeccelAmplitude : public CCActionInterval -{ - CCActionInterval* reverse(void); - - float getRate(void); - void setRate(float fRate); - - static CCDeccelAmplitude* create(CCAction *pAction, float duration); -}; - -class CCStopGrid : public CCActionInstant -{ - static CCStopGrid* create(void); -}; - -class CCReuseGrid : public CCActionInstant -{ - static CCReuseGrid* create(int times); -}; diff --git a/tools/tolua++/CCActionGrid3D.pkg b/tools/tolua++/CCActionGrid3D.pkg deleted file mode 100644 index 99cf5e6c6d..0000000000 --- a/tools/tolua++/CCActionGrid3D.pkg +++ /dev/null @@ -1,79 +0,0 @@ - -class CCWaves3D : public CCGrid3DAction -{ - float getAmplitude(void); - void setAmplitude(float fAmplitude); - float getAmplitudeRate(void); - void setAmplitudeRate(float fAmplitudeRate); - - static CCWaves3D* create(float duration, CCSize gridSize, unsigned int waves, float amplitude); -}; - -class CCFlipX3D : public CCGrid3DAction -{ - static CCFlipX3D* create(float duration); -}; - -class CCFlipY3D : public CCFlipX3D -{ - static CCFlipY3D* create(float duration); -}; - -class CCLens3D : public CCGrid3DAction -{ - float getLensEffect(void); - void setLensEffect(float fLensEffect); - CCPoint getPosition(void); - void setPosition(CCPoint position); - - static CCLens3D* create(float duration, CCSize gridSize, CCPoint position, float radius); -}; - -class CCRipple3D : public CCGrid3DAction -{ - CCPoint getPosition(void); - void setPosition(CCPoint position); - float getAmplitude(void); - void setAmplitude(float fAmplitude); - float getAmplitudeRate(void); - void setAmplitudeRate(float fAmplitudeRate); - - static CCRipple3D* create(float duration, CCSize gridSize, CCPoint position, float radius, unsigned int waves, float amplitude); -}; - -class CCShaky3D : public CCGrid3DAction -{ - static CCShaky3D* create(float duration, CCSize gridSize, int range, bool shakeZ); -}; - -class CCLiquid : public CCGrid3DAction -{ - float getAmplitude(void); - void setAmplitude(float fAmplitude); - float getAmplitudeRate(void); - void setAmplitudeRate(float fAmplitudeRate); - - static CCLiquid* create(float duration, CCSize gridSize, unsigned int waves, float amplitude); -}; - -class CCWaves : public CCGrid3DAction -{ - float getAmplitude(void); - void setAmplitude(float fAmplitude); - float getAmplitudeRate(void); - void setAmplitudeRate(float fAmplitudeRate); - - static CCWaves* create(float duration, CCSize gridSize, unsigned int waves, float amplitude, bool horizontal, bool vertical); -}; - -class CCTwirl : public CCGrid3DAction -{ - CCPoint getPosition(void); - void setPosition(CCPoint position); - float getAmplitude(void); - void setAmplitude(float fAmplitude); - float getAmplitudeRate(void); - void setAmplitudeRate(float fAmplitudeRate); - - static CCTwirl* create(float duration, CCSize gridSize, CCPoint position, unsigned int twirls, float amplitude); -}; diff --git a/tools/tolua++/CCActionManager.pkg b/tools/tolua++/CCActionManager.pkg deleted file mode 100644 index 8eb3890da9..0000000000 --- a/tools/tolua++/CCActionManager.pkg +++ /dev/null @@ -1,25 +0,0 @@ - -class CCActionManager : public CCObject -{ - void addAction(CCAction *pAction, CCNode *pTarget, bool paused); - - void removeAllActions(void); - - void removeAllActionsFromTarget(CCObject *pTarget); - - void removeAction(CCAction *pAction); - - void removeActionByTag(unsigned int tag, CCObject *pTarget); - - CCAction* getActionByTag(unsigned int tag, CCObject *pTarget); - - unsigned int getNumberOfRunningActionsInTarget(CCObject *pTarget); - - void pauseTarget(CCObject *pTarget); - - void resumeTarget(CCObject *pTarget); - - CCSet* pauseAllRunningActions(); - - void resumeTargets(CCSet* targetsToResume); -}; diff --git a/tools/tolua++/CCActionPageTurn3D.pkg b/tools/tolua++/CCActionPageTurn3D.pkg deleted file mode 100644 index 40e5b2eb3d..0000000000 --- a/tools/tolua++/CCActionPageTurn3D.pkg +++ /dev/null @@ -1,5 +0,0 @@ - -class CCPageTurn3D : public CCGrid3DAction -{ - static CCPageTurn3D* create(float duration, CCSize gridSize); -}; diff --git a/tools/tolua++/CCActionProgressTimer.pkg b/tools/tolua++/CCActionProgressTimer.pkg deleted file mode 100644 index 6e3c911fd8..0000000000 --- a/tools/tolua++/CCActionProgressTimer.pkg +++ /dev/null @@ -1,10 +0,0 @@ - -class CCProgressTo : public CCActionInterval -{ - static CCProgressTo* create(float duration, float fPercent); -}; - -class CCProgressFromTo : public CCActionInterval -{ - static CCProgressFromTo* create(float duration, float fFromPercentage, float fToPercentage); -}; diff --git a/tools/tolua++/CCActionTiledGrid.pkg b/tools/tolua++/CCActionTiledGrid.pkg deleted file mode 100644 index 6baa15906d..0000000000 --- a/tools/tolua++/CCActionTiledGrid.pkg +++ /dev/null @@ -1,85 +0,0 @@ - -class CCShakyTiles3D : public CCTiledGrid3DAction -{ - static CCShakyTiles3D* create(float duration, CCSize gridSize, int nRange, bool bShakeZ); -}; - -class CCShatteredTiles3D : public CCTiledGrid3DAction -{ - static CCShatteredTiles3D* create(float duration, CCSize gridSize, int nRange, bool bShatterZ); -}; - -class CCShuffleTiles : public CCTiledGrid3DAction -{ - void shuffle(unsigned int *pArray, int nLen); - CCSize getDelta(CCSize pos); - void placeTile(CCPoint pos, Tile *t); - - static CCShuffleTiles* create(float duration, CCSize gridSize, unsigned int seed); -}; - -class CCFadeOutTRTiles : public CCTiledGrid3DAction -{ - void turnOnTile(CCPoint pos); - void turnOffTile(CCPoint pos); - void transformTile(CCPoint pos, float distance); - - static CCFadeOutTRTiles* create(float duration, CCSize gridSize); -}; - -class CCFadeOutBLTiles : public CCFadeOutTRTiles -{ - static CCFadeOutBLTiles* create(float duration, CCSize gridSize); -}; - -class CCFadeOutUpTiles : public CCFadeOutTRTiles -{ - void transformTile(CCPoint pos, float distance); - - static CCFadeOutUpTiles* create(float duration, CCSize gridSize); -}; - -class CCFadeOutDownTiles : public CCFadeOutUpTiles -{ - static CCFadeOutDownTiles* create(float duration, CCSize gridSize); -}; - -class CCTurnOffTiles : public CCTiledGrid3DAction -{ - void shuffle(unsigned int *pArray, int nLen); - void turnOnTile(CCPoint pos); - void turnOffTile(CCPoint pos); - - static CCTurnOffTiles* create(float duration, CCSize gridSize); - static CCTurnOffTiles* create(float duration, CCSize gridSize, unsigned int seed); -}; - -class CCWavesTiles3D : public CCTiledGrid3DAction -{ - float getAmplitude(void); - void setAmplitude(float fAmplitude); - float getAmplitudeRate(void); - void setAmplitudeRate(float fAmplitudeRate); - - static CCWavesTiles3D* create(float duration, CCSize gridSize, unsigned int waves, float amplitude); -}; - -class CCJumpTiles3D : public CCTiledGrid3DAction -{ - float getAmplitude(void); - void setAmplitude(float fAmplitude); - float getAmplitudeRate(void); - void setAmplitudeRate(float fAmplitudeRate); - - static CCJumpTiles3D* create(float duration, CCSize gridSize, unsigned int numberOfJumps, float amplitude); -}; - -class CCSplitRows : public CCTiledGrid3DAction -{ - static CCSplitRows* create(float duration, unsigned int nRows); -}; - -class CCSplitCols : public CCTiledGrid3DAction -{ - static CCSplitCols* create(float duration, unsigned int nCols); -}; diff --git a/tools/tolua++/CCAffineTransform.pkg b/tools/tolua++/CCAffineTransform.pkg deleted file mode 100644 index b7a98840c6..0000000000 --- a/tools/tolua++/CCAffineTransform.pkg +++ /dev/null @@ -1,24 +0,0 @@ - -class CCAffineTransform { - float a, b, c, d; - float tx, ty; -}; - -CCAffineTransform __CCAffineTransformMake(float a, float b, float c, float d, float tx, float ty); -CCAffineTransform CCAffineTransformMake(float a, float b, float c, float d, float tx, float ty); - -CCPoint __CCPointApplyAffineTransform(CCPoint point, CCAffineTransform t); -CCPoint CCPointApplyAffineTransform(CCPoint point, CCAffineTransform t); - -CCSize CCSizeApplyAffineTransform(CCSize size, CCAffineTransform t); -CCSize __CCSizeApplyAffineTransform(CCSize size, CCAffineTransform t); - -CCAffineTransform CCAffineTransformMakeIdentity(); -CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform); - -CCAffineTransform CCAffineTransformTranslate(CCAffineTransform t, float tx, float ty); -CCAffineTransform CCAffineTransformRotate(CCAffineTransform aTransform, float anAngle); -CCAffineTransform CCAffineTransformScale(CCAffineTransform t, float sx, float sy); -CCAffineTransform CCAffineTransformConcat(CCAffineTransform t1,CCAffineTransform t2); -bool CCAffineTransformEqualToTransform(CCAffineTransform t1,CCAffineTransform t2); -CCAffineTransform CCAffineTransformInvert(CCAffineTransform t); diff --git a/tools/tolua++/CCAnimation.pkg b/tools/tolua++/CCAnimation.pkg deleted file mode 100644 index 83a7d82071..0000000000 --- a/tools/tolua++/CCAnimation.pkg +++ /dev/null @@ -1,50 +0,0 @@ - -class CCAnimationFrame : public CCObject -{ - CCAnimationFrame(); - ~CCAnimationFrame(); - - bool initWithSpriteFrame(CCSpriteFrame* spriteFrame, float delayUnits, CCDictionary* userInfo); - - CCSpriteFrame* getSpriteFrame(); - void setSpriteFrame(CCSpriteFrame* pSpFrame); - - float getDelayUnits(); - void setDelayUnits(float fDelayUnits); - - CCDictionary* getUserInfo(); - void setUserInfo(CCDictionary* pDict); -}; - - -class CCAnimation : public CCObject -{ - static CCAnimation* create(CCArray *arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops); - static CCAnimation* create(void); - static CCAnimation* createWithSpriteFrames(CCArray* arrayOfSpriteFrameNames, float delay); - static CCAnimation* createWithSpriteFrames(CCArray* arrayOfSpriteFrameNames); - - void addSpriteFrame(CCSpriteFrame *pFrame); - void addSpriteFrameWithFileName(const char *pszFileName); - void addSpriteFrameWithTexture(CCTexture2D* pobTexture, const CCRect& rect); - - float getTotalDelayUnits(); - - float getDelayPerUnit(); - void setDelayPerUnit(float fDelayPerUnits); - - float getDuration(); - - CCAnimation* clone(); - CCObject* copy(); - - CCArray* getFrames(); - void setFrames(CCArray* pFrames); - - - bool getRestoreOriginalFrame(); - void setRestoreOriginalFrame(bool bRestoreFrame); - - unsigned int getLoops(); - void setLoops(unsigned int uLoops); -}; diff --git a/tools/tolua++/CCAnimationCache.pkg b/tools/tolua++/CCAnimationCache.pkg deleted file mode 100644 index c4da10ccd9..0000000000 --- a/tools/tolua++/CCAnimationCache.pkg +++ /dev/null @@ -1,13 +0,0 @@ - -class CCAnimationCache : public CCObject -{ - void addAnimation(CCAnimation *animation, const char * name); - void removeAnimationByName(const char* name); - CCAnimation* animationByName(const char* name); - - static CCAnimationCache* getInstance(); - static void destroyInstance(); - - void addAnimationsWithDictionary(CCDictionary* dictionary); - void addAnimationsWithFile(const char* plist); -}; diff --git a/tools/tolua++/CCApplication.pkg b/tools/tolua++/CCApplication.pkg deleted file mode 100644 index 8bf80c8895..0000000000 --- a/tools/tolua++/CCApplication.pkg +++ /dev/null @@ -1,35 +0,0 @@ -typedef enum LanguageType -{ - kLanguageEnglish = 0, - kLanguageChinese, - kLanguageFrench, - kLanguageItalian, - kLanguageGerman, - kLanguageSpanish, - kLanguageRussian, - kLanguageKorean, - kLanguageJapanese, - kLanguageHungarian, - kLanguagePortuguese, - kLanguageArabic -} ccLanguageType; - -enum TargetPlatform -{ - kTargetWindows, - kTargetLinux, - kTargetMacOS, - kTargetAndroid, - kTargetIphone, - kTargetIpad, - kTargetBlackBerry, -}; - -class CCApplication -{ - ~CCApplication(); - - static CCApplication* getInstance(); - ccLanguageType getCurrentLanguage(); - TargetPlatform getTargetPlatform(); -}; diff --git a/tools/tolua++/CCArray.pkg b/tools/tolua++/CCArray.pkg deleted file mode 100644 index 194f5e932f..0000000000 --- a/tools/tolua++/CCArray.pkg +++ /dev/null @@ -1,56 +0,0 @@ -class CCArray : public CCObject -{ - static CCArray* create(); - - static CCArray* createWithObject(CCObject* pObject); - static CCArray* createWithArray(CCArray* otherArray); - static CCArray* createWithCapacity(unsigned int capacity); - static CCArray* createWithContentsOfFile(const char* pFileName); - - unsigned int count(); - - unsigned int capacity(); - - unsigned int indexOfObject(CCObject* object); - - CCObject* objectAtIndex(unsigned int index); - - CCObject* lastObject(); - - CCObject* randomObject(); - - bool isEqualToArray(CCArray* pOtherArray); - - bool containsObject(CCObject* object); - - void addObject(CCObject* object); - - void addObjectsFromArray(CCArray* otherArray); - - void insertObject(CCObject* object, unsigned int index); - - void removeLastObject(bool bReleaseObj = true); - - void removeObject(CCObject* object, bool bReleaseObj = true); - - void removeObjectAtIndex(unsigned int index, bool bReleaseObj = true); - - void removeObjectsInArray(CCArray* otherArray); - - void removeAllObjects(); - - void fastRemoveObject(CCObject* object); - - void fastRemoveObjectAtIndex(unsigned int index); - - void exchangeObject(CCObject* object1, CCObject* object2); - - void exchangeObjectAtIndex(unsigned int index1, unsigned int index2); - - void reverseObjects(); - - void reduceMemoryFootprint(); - - void replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool bReleaseObject = true); - -}; diff --git a/tools/tolua++/CCAtlasNode.pkg b/tools/tolua++/CCAtlasNode.pkg deleted file mode 100644 index ff5d3a1e6d..0000000000 --- a/tools/tolua++/CCAtlasNode.pkg +++ /dev/null @@ -1,24 +0,0 @@ - -class CCAtlasNode : public CCNodeRGBA -{ - CCTextureAtlas* getTextureAtlas(); - void setTextureAtlas(CCTextureAtlas* atlas); - - CCTexture2D* getTexture(void); - void setTexture(CCTexture2D *texture); - - Color3B getColor(); - void setColor(Color3B color); - - unsigned int getQuadsToDraw(); - void setQuadsToDraw(unsigned int quadsToDraw); - - GLubyte getOpacity(); - void setOpacity(GLubyte opacity); - - void updateAtlasValues(); - bool isOpacityModifyRGB(); - void setOpacityModifyRGB(bool isOpacityModifyRGB); - - static CCAtlasNode * create(const char* tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender); -}; diff --git a/tools/tolua++/CCCamera.pkg b/tools/tolua++/CCCamera.pkg deleted file mode 100644 index 5d69c3b860..0000000000 --- a/tools/tolua++/CCCamera.pkg +++ /dev/null @@ -1,22 +0,0 @@ - -class CCCamera : public CCObject -{ - CCCamera(void); - - void init(void); - char * description(void); - - void setDirty(bool bValue); - bool isDirty(void); - void restore(void); - void locate(void); - void setEyeXYZ(float fEyeX, float fEyeY, float fEyeZ); - void setCenterXYZ(float fCenterX, float fCenterY, float fCenterZ); - void setUpXYZ(float fUpX, float fUpY, float fUpZ); - - void getEyeXYZ(float *pEyeX, float *pEyeY, float *pEyeZ); - void getCenterXYZ(float *pCenterX, float *pCenterY, float *pCenterZ); - void getUpXYZ(float *pUpX, float *pUpY, float *pUpZ); - - static float getZEye(); -}; diff --git a/tools/tolua++/CCCommon.pkg b/tools/tolua++/CCCommon.pkg deleted file mode 100644 index 5f01e967be..0000000000 --- a/tools/tolua++/CCCommon.pkg +++ /dev/null @@ -1,3 +0,0 @@ - -void CCLuaLog(const char * pszFormat); -void CCMessageBox(const char * pszMsg, const char * pszTitle); diff --git a/tools/tolua++/CCControl.pkg b/tools/tolua++/CCControl.pkg deleted file mode 100644 index bb749d8334..0000000000 --- a/tools/tolua++/CCControl.pkg +++ /dev/null @@ -1,62 +0,0 @@ -enum CCControlEvent -{ - CCControlEventTouchDown = 1 << 0, - CCControlEventTouchDragInside = 1 << 1, - CCControlEventTouchDragOutside = 1 << 2, - CCControlEventTouchDragEnter = 1 << 3, - CCControlEventTouchDragExit = 1 << 4, - CCControlEventTouchUpInside = 1 << 5, - CCControlEventTouchUpOutside = 1 << 6, - CCControlEventTouchCancel = 1 << 7, - CCControlEventValueChanged = 1 << 8 -}; - -typedef unsigned int CCControlEvent; - -enum CCControlState -{ - CCControlStateNormal = 1 << 0, - CCControlStateHighlighted = 1 << 1, - CCControlStateDisabled = 1 << 2, - CCControlStateSelected = 1 << 3 -}; - -typedef unsigned int CCControlState; - -class CCControl:public CCLayerRGBA -{ - virtual CCControlState getState() const; - - virtual void setEnabled(bool bEnabled); - virtual bool isEnabled(); - - virtual void setSelected(bool bSelected); - virtual bool isSelected(); - - virtual void setHighlighted(bool bHighlighted); - virtual bool isHighlighted(); - bool hasVisibleParents(); - - virtual void needsLayout(); - - virtual bool isOpacityModifyRGB(); - virtual void setOpacityModifyRGB(bool bOpacityModifyRGB); - - CCControl(); - virtual bool init(void); - virtual ~CCControl(); - - - virtual void onEnter(); - virtual void onExit(); - virtual void registerWithTouchDispatcher(); - - virtual void sendActionsForControlEvents(CCControlEvent controlEvents); - - virtual void addTargetWithActionForControlEvents(CCObject* target, SEL_CCControlHandler action, CCControlEvent controlEvents); - - virtual void removeTargetWithActionForControlEvents(CCObject* target, SEL_CCControlHandler action, CCControlEvent controlEvents); - - virtual CCPoint getTouchLocation(CCTouch* touch); - virtual bool isTouchInside(CCTouch * touch); -}; diff --git a/tools/tolua++/CCControlButton.pkg b/tools/tolua++/CCControlButton.pkg deleted file mode 100644 index 849e28b9d8..0000000000 --- a/tools/tolua++/CCControlButton.pkg +++ /dev/null @@ -1,111 +0,0 @@ - -#define CCControlButtonMarginLR 8 - -#define CCControlButtonMarginTB 2 - -class CCControlButton : public CCControl -{ - CCControlButton(); - virtual ~CCControlButton(); - virtual void needsLayout(void); - - virtual void setEnabled(bool enabled); - virtual void setSelected(bool enabled); - virtual void setHighlighted(bool enabled); - - virtual CCString* getCurrentTitle(); - virtual const Color3B& getCurrentTitleColor() const; - - bool doesAdjustBackgroundImage(); - void setAdjustBackgroundImage(bool adjustBackgroundImage); - - virtual CCNode* getTitleLabel(); - virtual void setTitleLabel(CCNode* var); - - virtual CCScale9Sprite* getBackgroundSprite(); - virtual void setBackgroundSprite(CCScale9Sprite* var); - - virtual CCSize getPreferredSize(); - virtual void setPreferredSize(CCSize var); - - virtual bool getZoomOnTouchDown(); - virtual void setZoomOnTouchDown(bool var); - - virtual CCPoint getLabelAnchorPoint(); - virtual void setLabelAnchorPoint(CCPoint var); - - virtual GLubyte getOpacity(void); - virtual void setOpacity(GLubyte var); - - bool isPushed(); - - virtual CCDictionary* getTitleDispatchTable(); - virtual void setTitleDispatchTable(CCDictionary* var); - - virtual CCDictionary* getTitleColorDispatchTable(); - virtual void setTitleColorDispatchTable(CCDictionary* var); - - virtual CCDictionary* getTitleLabelDispatchTable(); - virtual void setTitleLabelDispatchTable(CCDictionary* var); - - virtual CCDictionary* getBackgroundSpriteDispatchTable(); - virtual void setBackgroundSpriteDispatchTable(CCDictionary* var); - - virtual int getVerticalMargin() const; - virtual int getHorizontalOrigin() const; - - virtual void setMargins(int marginH, int marginV); - - virtual bool init(); - virtual bool initWithLabelAndBackgroundSprite(CCNode* label, CCScale9Sprite* backgroundSprite); - - static CCControlButton* create(CCNode* label, CCScale9Sprite* backgroundSprite); - - virtual bool initWithTitleAndFontNameAndFontSize(std::string title, const char * fontName, float fontSize); - - static CCControlButton* create(std::string title, const char * fontName, float fontSize); - - virtual bool initWithBackgroundSprite(CCScale9Sprite* sprite); - - static CCControlButton* create(CCScale9Sprite* sprite); - - virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent); - - virtual CCString* getTitleForState(CCControlState state); - - virtual void setTitleForState(CCString* title, CCControlState state); - - - virtual const Color3B getTitleColorForState(CCControlState state); - - - virtual void setTitleColorForState(Color3B color, CCControlState state); - - - virtual CCNode* getTitleLabelForState(CCControlState state); - - virtual void setTitleLabelForState(CCNode* label, CCControlState state); - - virtual void setTitleTTFForState(const char * fntFile, CCControlState state); - virtual const char * getTitleTTFForState(CCControlState state); - - virtual void setTitleTTFSizeForState(float size, CCControlState state); - virtual float getTitleTTFSizeForState(CCControlState state); - - virtual void setTitleBMFontForState(const char * fntFile, CCControlState state); - virtual const char * getTitleBMFontForState(CCControlState state); - - virtual CCScale9Sprite* getBackgroundSpriteForState(CCControlState state); - - - virtual void setBackgroundSpriteForState(CCScale9Sprite* sprite, CCControlState state); - - - virtual void setBackgroundSpriteFrameForState(CCSpriteFrame * spriteFrame, CCControlState state); - - static CCControlButton* create(); - -}; diff --git a/tools/tolua++/CCControlColourPicker.pkg b/tools/tolua++/CCControlColourPicker.pkg deleted file mode 100644 index bbe40ba62d..0000000000 --- a/tools/tolua++/CCControlColourPicker.pkg +++ /dev/null @@ -1,23 +0,0 @@ -class CCControlColourPicker : public CCControl -{ - CCControlColourPicker(); - virtual ~CCControlColourPicker(); - virtual void setColor(const Color3B& colorValue); - virtual void setEnabled(bool bEnabled); - - virtual CCControlSaturationBrightnessPicker* getcolourPicker() const; - virtual void setcolourPicker(CCControlSaturationBrightnessPicker* var); - - virtual CCControlHuePicker* getHuePicker() const; - virtual void setHuePicker(CCControlHuePicker* var); - - virtual CCSprite* getBackground() const; - virtual void setBackground(CCSprite* var); - - static CCControlColourPicker* create(); - - virtual bool init(); - - void hueSliderValueChanged(CCObject * sender, CCControlEvent controlEvent); - void colourSliderValueChanged(CCObject * sender, CCControlEvent controlEvent); -}; diff --git a/tools/tolua++/CCControlPotentiometer.pkg b/tools/tolua++/CCControlPotentiometer.pkg deleted file mode 100644 index 85f83cf056..0000000000 --- a/tools/tolua++/CCControlPotentiometer.pkg +++ /dev/null @@ -1,42 +0,0 @@ -class CCControlPotentiometer : public CCControl -{ - CCControlPotentiometer(); - virtual ~CCControlPotentiometer(); - - static CCControlPotentiometer* create(const char* backgroundFile, const char* progressFile, const char* thumbFile); - - bool initWithTrackSprite_ProgressTimer_ThumbSprite(CCSprite* trackSprite, CCProgressTimer* progressTimer, CCSprite* thumbSprite); - void setValue(float value); - float getValue(); - - void setMinimumValue(float minimumValue); - float getMinimumValue(); - - void setMaximumValue(float maximumValue); - float getMaximumValue(); - - void setEnabled(bool enabled); - - virtual bool isTouchInside(CCTouch * touch); - - virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); - - virtual CCSprite* getThumbSprite() const; - virtual void setThumbSprite(CCSprite* var); - - virtual CCProgressTimer* getProgressTimer() const; - virtual void setProgressTimer(CCProgressTimer* var); - - virtual CCPoint getPreviousLocation() const; - virtual void setPreviousLocation(CCPoint var); - - void potentiometerBegan(CCPoint location); - void potentiometerMoved(CCPoint location); - void potentiometerEnded(CCPoint location); - - float distanceBetweenPointAndPoint(CCPoint point1, CCPoint point2); - - float angleInDegreesBetweenLineFromPoint_toPoint_toLineFromPoint_toPoint(CCPoint beginLineA, CCPoint endLineA,CCPoint beginLineB,CCPoint endLineB); -}; diff --git a/tools/tolua++/CCControlSlider.pkg b/tools/tolua++/CCControlSlider.pkg deleted file mode 100644 index ee17566768..0000000000 --- a/tools/tolua++/CCControlSlider.pkg +++ /dev/null @@ -1,39 +0,0 @@ -class CCControlSlider : public CCControl -{ - virtual float getValue() const; - virtual void setValue(float val); - - virtual float getMinimumValue() const; - virtual void setMinimumValue(float val); - - virtual float getMaximumValue() const; - virtual void setMaximumValue(float val); - - virtual void setMaximumValue(float val); - virtual void setEnabled(bool enabled); - virtual bool isTouchInside(CCTouch * touch); - CCPoint locationFromTouch(CCTouch* touch); - - virtual float getMinimumAllowedValue() const; - virtual void setMinimumAllowedValue(float val); - - virtual float getMaximumAllowedValue() const; - virtual void setMaximumAllowedValue(float val); - - virtual CCSprite* getThumbSprite() const; - virtual void setThumbSprite(CCSprite* val); - - virtual CCSprite* getProgressSprite() const; - virtual void setProgressSprite(CCSprite* val); - - virtual CCSprite* getBackgroundSprite() const; - virtual void setBackgroundSprite(CCSprite* val); - - CCControlSlider(); - virtual ~CCControlSlider(); - - virtual bool initWithSprites(CCSprite * backgroundSprite, CCSprite* progressSprite, CCSprite* thumbSprite); - static CCControlSlider* create(const char* bgFile, const char* progressFile, const char* thumbFile); - static CCControlSlider* create(CCSprite * backgroundSprite, CCSprite* pogressSprite, CCSprite* thumbSprite); - virtual void needsLayout(); -}; diff --git a/tools/tolua++/CCControlStepper.pkg b/tools/tolua++/CCControlStepper.pkg deleted file mode 100644 index 66fcc45cb0..0000000000 --- a/tools/tolua++/CCControlStepper.pkg +++ /dev/null @@ -1,47 +0,0 @@ -enum CCControlStepperPart -{ - kCCControlStepperPartMinus, - kCCControlStepperPartPlus, - kCCControlStepperPartNone, -}; - - -class CCControlStepper : public CCControl -{ - CCControlStepper(); - virtual ~CCControlStepper(); - - bool initWithMinusSpriteAndPlusSprite(CCSprite *minusSprite, CCSprite *plusSprite); - static CCControlStepper* create(CCSprite *minusSprite, CCSprite *plusSprite); - virtual void setWraps(bool wraps); - virtual void setMinimumValue(double minimumValue); - virtual void setMaximumValue(double maximumValue); - virtual void setValue(double value); - virtual double getValue(); - virtual void setStepValue(double stepValue); - virtual void setValueWithSendingEvent(double value, bool send); - virtual bool isContinuous(); - void update(float dt); - - virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); - - virtual CCSprite* getMinusSprite() const; - virtual void setMinusSprite(CCSprite* var); - - virtual CCSprite* getPlusSprite() const; - virtual void setPlusSprite(CCSprite* var); - - virtual CCLabelTTF* getMinusLabel() const; - virtual void setMinusLabel(CCLabelTTF* var); - - virtual CCLabelTTF* getPlusLabel() const; - virtual void setPlusLabel(CCLabelTTF* var); - - void updateLayoutUsingTouchLocation(CCPoint location); - - void startAutorepeat(); - - void stopAutorepeat(); -}; diff --git a/tools/tolua++/CCControlSwitch.pkg b/tools/tolua++/CCControlSwitch.pkg deleted file mode 100644 index a73dd5ca77..0000000000 --- a/tools/tolua++/CCControlSwitch.pkg +++ /dev/null @@ -1,26 +0,0 @@ -class CCControlSwitch : public CCControl -{ - CCControlSwitch(); - virtual ~CCControlSwitch(); - - bool initWithMaskSprite(CCSprite *maskSprite, CCSprite * onSprite, CCSprite * offSprite, CCSprite * thumbSprite); - - static CCControlSwitch* create(CCSprite *maskSprite, CCSprite * onSprite, CCSprite * offSprite, CCSprite * thumbSprite); - - bool initWithMaskSprite(CCSprite *maskSprite, CCSprite * onSprite, CCSprite * offSprite, CCSprite * thumbSprite, CCLabelTTF* onLabel, CCLabelTTF* offLabel); - - static CCControlSwitch* create(CCSprite *maskSprite, CCSprite * onSprite, CCSprite * offSprite, CCSprite * thumbSprite, CCLabelTTF* onLabel, CCLabelTTF* offLabel); - - void setOn(bool isOn, bool animated); - void setOn(bool isOn); - bool isOn(void) { return m_bOn; } - bool hasMoved() { return m_bMoved; } - virtual void setEnabled(bool enabled); - - CCPoint locationFromTouch(CCTouch* touch); - - virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); - virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent); -}; diff --git a/tools/tolua++/CCDictionary.pkg b/tools/tolua++/CCDictionary.pkg deleted file mode 100644 index 3c87553265..0000000000 --- a/tools/tolua++/CCDictionary.pkg +++ /dev/null @@ -1,26 +0,0 @@ -class CCDictionary : public CCObject -{ - unsigned int count(); - CCArray* allKeys(); - CCArray* allKeysForObject(CCObject* object); - - CCObject* objectForKey(const std::string& key); - CCObject* objectForKey(int key); - const CCString* valueForKey(const std::string& key); - const CCString* valueForKey(int key); - - - void setObject(CCObject* pObject, const std::string& key); - void setObject(CCObject* pObject, int key); - - void removeObjectForKey(const std::string& key); - void removeObjectForKey(int key); - void removeObjectsForKeys(CCArray* pKeyArray); - void removeAllObjects(); - - static CCDictionary* create(); - static CCDictionary* createWithDictionary(CCDictionary* srcDict); - static CCDictionary* createWithContentsOfFile(const char *pFileName); - -}; - diff --git a/tools/tolua++/CCDirector.pkg b/tools/tolua++/CCDirector.pkg deleted file mode 100644 index e63fda7c94..0000000000 --- a/tools/tolua++/CCDirector.pkg +++ /dev/null @@ -1,61 +0,0 @@ - -typedef enum { - kCCDirectorProjection2D, - kCCDirectorProjection3D, - kCCDirectorProjectionCustom, - kCCDirectorProjectionDefault = kCCDirectorProjection3D, -} ccDirectorProjection; - -class CCDirector : public CCObject -{ - CCScene* getRunningScene(void); - - double getAnimationInterval(void); - - bool isDisplayStats(void); - void setDisplayStats(bool bDisplayStats); - - bool isPaused(void); - unsigned int getTotalFrames(void); - - CCEGLViewProtocol* getOpenGLView(void); - - CCSize getWinSize(void); - CCSize getWinSizeInPixels(void); - - CCPoint convertToGL(CCPoint obPoint); - CCPoint convertToUI(CCPoint obPoint); - - void pause(); - void resume(); - void purgeCachedData(void); - - void runWithScene(CCScene *pScene); - void pushScene(CCScene *pScene); - void popScene(void); - void popToRootScene(); - void replaceScene(CCScene *pScene); - void end @ endToLua (); - - float getContentScaleFactor(void); - void setContentScaleFactor(float scaleFactor); - - CCScheduler* getScheduler(); - CCActionManager* getActionManager(); - CCTouchDispatcher* getTouchDispatcher(); - // CCKeypadDispatcher* getKeypadDispatcher(); - // CCAccelerometer* getAccelerometer(); - - void setDepthTest(bool var); - void setProjection(ccDirectorProjection kProjection); - ccDirectorProjection getProjection(void); - - CCNode* getNotificationNode(); - void setNotificationNode(CCNode *node); - - float getZEye(void); - CCSize getVisibleSize(); - CCPoint getVisibleOrigin(); - - static CCDirector* getInstance(); -}; diff --git a/tools/tolua++/CCDrawNode.pkg b/tools/tolua++/CCDrawNode.pkg deleted file mode 100644 index f8a28cef5e..0000000000 --- a/tools/tolua++/CCDrawNode.pkg +++ /dev/null @@ -1,22 +0,0 @@ -class CCDrawNode : public CCNode -{ - static CCDrawNode* create(); - - CCDrawNode(); - - virtual ~CCDrawNode(); - - virtual bool init(); - - void drawDot(const CCPoint &pos, float radius, const Color4F &color); - - void drawSegment(const CCPoint &from, const CCPoint &to, float radius, const Color4F &color); - - void clear(); - - const BlendFunc& getBlendFunc() const; - - void setBlendFunc(const BlendFunc &blendFunc); - - virtual void draw(); -}; diff --git a/tools/tolua++/CCEGLViewProtocol.pkg b/tools/tolua++/CCEGLViewProtocol.pkg deleted file mode 100644 index ff01580f8b..0000000000 --- a/tools/tolua++/CCEGLViewProtocol.pkg +++ /dev/null @@ -1,91 +0,0 @@ - -enum ResolutionPolicy -{ - // The entire application is visible in the specified area without trying to preserve the original aspect ratio. - // Distortion can occur, and the application may appear stretched or compressed. - kResolutionExactFit, - // The entire application fills the specified area, without distortion but possibly with some cropping, - // while maintaining the original aspect ratio of the application. - kResolutionNoBorder, - // The entire application is visible in the specified area without distortion while maintaining the original - // aspect ratio of the application. Borders can appear on two sides of the application. - kResolutionShowAll, - - kResolutionUnKnown, -}; - -class CCEGLViewProtocol -{ - /** - * Get the frame size of EGL view. - * In general, it returns the screen size since the EGL view is a fullscreen view. - */ - const CCSize& getFrameSize() const; - - /** - * Set the frame size of EGL view. - */ - void setFrameSize(float width, float height); - - /** - * Get the visible area size of opengl viewport. - */ - CCSize getVisibleSize() const; - - /** - * Get the visible origin point of opengl viewport. - */ - CCPoint getVisibleOrigin() const; - - /** - * Set the design resolutin size. - * You can't use it with enableRetina together. - * @param width Design resolution width. - * @param height Design resolution height. - * @param resolutionPolicy The resolution policy you need, there are: - * [1] kResolutionExactFit Fill screen, if the design resolution ratio of width and height is different from the screen resolution ratio, your game view will be stretched. - * [2] kResolutionNoBorder Full screen without black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two areas of your game view will be cut. - * [3] kResolutionShowAll Full screen with black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two black border will be shown on the screen; - */ - void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy); - - /** Get design resolution size. - * Default resolution size is the same as 'getFrameSize'. - */ - virtual const CCSize& getDesignResolutionSize() const; - - /** Set touch delegate */ - void setTouchDelegate(EGLTouchDelegate * pDelegate); - - /** - * Set opengl view port rectangle with points. - */ - void setViewPortInPoints(float x , float y , float w , float h); - - /** - * Set Scissor rectangle with points. - */ - void setScissorInPoints(float x , float y , float w , float h); - - /** - * Get opengl view port rectangle. - */ - const CCRect& getViewPortRect() const; - - /** - * Get the scale factor of horizontal direction. - * - */ - float getScaleX() const; - - /** - * Get the scale factor of vertical direction. - */ - float getScaleY() const; -}; - -class CCEGLView : public CCEGLViewProtocol -{ - static CCEGLView* getInstance(); -}; - diff --git a/tools/tolua++/CCEditBox.pkg b/tools/tolua++/CCEditBox.pkg deleted file mode 100644 index bbb9b33626..0000000000 --- a/tools/tolua++/CCEditBox.pkg +++ /dev/null @@ -1,103 +0,0 @@ -enum KeyboardReturnType { - kKeyboardReturnTypeDefault = 0, - kKeyboardReturnTypeDone, - kKeyboardReturnTypeSend, - kKeyboardReturnTypeSearch, - kKeyboardReturnTypeGo -}; - -enum EditBoxInputMode -{ - kEditBoxInputModeAny = 0, - - kEditBoxInputModeEmailAddr, - - kEditBoxInputModeNumeric, - - kEditBoxInputModePhoneNumber, - - kEditBoxInputModeUrl, - - kEditBoxInputModeDecimal, - - kEditBoxInputModeSingleLine -}; - -enum EditBoxInputFlag -{ - - kEditBoxInputFlagPassword = 0, - - kEditBoxInputFlagSensitive, - - kEditBoxInputFlagInitialCapsWord, - - kEditBoxInputFlagInitialCapsSentence, - - kEditBoxInputFlagInitialCapsAllCharacters -}; - -class CCEditBox: public CCControlButton -{ -public: - - CCEditBox(void); - - - virtual ~CCEditBox(void); - - - static CCEditBox* create(const CCSize& size, CCScale9Sprite* pNormal9SpriteBg, CCScale9Sprite* pPressed9SpriteBg = NULL, CCScale9Sprite* pDisabled9SpriteBg = NULL); - - bool initWithSizeAndBackgroundSprite(const CCSize& size, CCScale9Sprite* pNormal9SpriteBg); - - void registerScriptEditBoxHandler(LUA_FUNCTION handler); - - void unregisterScriptEditBoxHandler(void); - - int getScriptEditBoxHandler(void); - - void setText(const char* pText); - - const char* getText(void); - - void setFont(const char* pFontName, int fontSize); - - void setFontName(const char* pFontName); - - void setFontSize(int fontSize); - - void setFontColor(const Color3B& color); - - void setPlaceholderFont(const char* pFontName, int fontSize); - - void setPlaceholderFontName(const char* pFontName); - - void setPlaceholderFontSize(int fontSize); - - void setPlaceholderFontColor(const Color3B& color); - - void setPlaceHolder(const char* pText); - - const char* getPlaceHolder(void); - - void setInputMode(EditBoxInputMode inputMode); - - void setMaxLength(int maxLength); - - int getMaxLength(); - - void setInputFlag(EditBoxInputFlag inputFlag); - - void setReturnType(KeyboardReturnType returnType); - - virtual void setPosition(const CCPoint& pos); - virtual void setVisible(bool visible); - virtual void setContentSize(const CCSize& size); - virtual void setAnchorPoint(const CCPoint& anchorPoint); - virtual void visit(void); - virtual void onEnter(void); - virtual void onExit(void); - - void touchDownAction(CCObject *sender, CCControlEvent controlEvent); -}; diff --git a/tools/tolua++/CCFileUtils.pkg b/tools/tolua++/CCFileUtils.pkg deleted file mode 100644 index 558bbc3394..0000000000 --- a/tools/tolua++/CCFileUtils.pkg +++ /dev/null @@ -1,19 +0,0 @@ - -class CCFileUtils -{ - static CCFileUtils* getInstance(); - static void destroyInstance(); - - void purgeCachedEntries(); - - std::string fullPathForFilename(const char *pszFileName); - void loadFilenameLookupDictionaryFromFile(const char* filename); - const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile); - void addSearchResolutionsOrder(const char* order); - void addSearchPath(const char* path); - - std::string getWritablePath(); - - void setPopupNotify(bool bNotify); - bool isPopupNotify(); -}; diff --git a/tools/tolua++/CCGeometry.pkg b/tools/tolua++/CCGeometry.pkg deleted file mode 100644 index 917f83079a..0000000000 --- a/tools/tolua++/CCGeometry.pkg +++ /dev/null @@ -1,63 +0,0 @@ - -class CCPoint -{ - float x; - float y; - CCPoint(); - CCPoint(float x, float y); - CCPoint(const CCSize& size); - CCPoint operator-(const CCPoint& right) const; - CCPoint operator+(const CCPoint& right) const; - CCPoint operator*(float a) const; - CCPoint getMidpoint(const CCPoint& other) const; - float dot(const CCPoint& other) const; - float cross(const CCPoint& other) const; - CCPoint getPerp() const; - CCPoint getRPerp() const; - CCPoint project(const CCPoint& other) const; - CCPoint rotate(const CCPoint& other) const; - CCPoint unrotate(const CCPoint& other) const; - float getLengthSq() const; - float getLength() const; - float getDistance(const CCPoint& other) const; - CCPoint normalize() const; - float getAngle() const; - CCPoint getClampPoint(const CCPoint& min_inclusive, const CCPoint& max_inclusive) const; - CCPoint lerp(const CCPoint& other, float alpha) const; - bool fuzzyEquals(const CCPoint& target, float variance) const; - CCPoint rotateByAngle(const CCPoint& pivot, float angle) const; - - bool equals(const CCPoint & target) const ; - static bool isLineIntersect(const CCPoint& A, const CCPoint& B,const CCPoint& C, const CCPoint& D,float* S, float* T); - static bool isSegmentIntersect(const CCPoint& A, const CCPoint& B, const CCPoint& C, const CCPoint& D); - static CCPoint getIntersectPoint(const CCPoint& A, const CCPoint& B, const CCPoint& C, const CCPoint& D); - static CCPoint forAngle(const float a); -}; - -class CCSize -{ - float width; - float height; - CCSize(); - CCSize(float width, float height); - - bool equals(const CCSize & target) const; -}; - -class CCRect -{ - CCPoint origin; - CCSize size; - CCRect(); - CCRect(float x, float y, float width, float height); - - float getMinX(); - float getMidX(); - float getMaxX(); - float getMinY(); - float getMidY(); - float getMaxY(); - bool equals(const CCRect & rect) const; - bool containsPoint(const CCPoint & point) const; - bool intersectsRect(const CCRect & rect) const; -}; diff --git a/tools/tolua++/CCImage.pkg b/tools/tolua++/CCImage.pkg deleted file mode 100644 index 87638721a9..0000000000 --- a/tools/tolua++/CCImage.pkg +++ /dev/null @@ -1,60 +0,0 @@ -class CCImage : public CCObject -{ - CCImage(); - ~CCImage(); - -/* - typedef enum - { - kFmtJpg = 0, - kFmtPng, - kFmtTiff, - kFmtWebp, - kFmtRawData, - kFmtUnKnown - }EImageFormat; - - typedef enum - { - kAlignCenter = 0x33, ///< Horizontal center and vertical center. - kAlignTop = 0x13, ///< Horizontal center and vertical top. - kAlignTopRight = 0x12, ///< Horizontal right and vertical top. - kAlignRight = 0x32, ///< Horizontal right and vertical center. - kAlignBottomRight = 0x22, ///< Horizontal right and vertical bottom. - kAlignBottom = 0x23, ///< Horizontal center and vertical bottom. - kAlignBottomLeft = 0x21, ///< Horizontal left and vertical bottom. - kAlignLeft = 0x31, ///< Horizontal left and vertical center. - kAlignTopLeft = 0x11, ///< Horizontal left and vertical top. - }ETextAlign; - - typedef enum - { - kColorGray = 0, - kColorRGB, - }EColorType; - - bool initWithImageFile(const char * strPath); - bool initWithImageData(void * pData, - int nDataLen, - int nWidth = 0, - int nHeight = 0, - int nBitsPerComponent = 8); - bool initWithString( - const char * pText, - int nWidth = 0, - int nHeight = 0, - ETextAlign eAlignMask = kAlignCenter, - const char * pFontName = 0, - int nSize = 0); - -*/ - unsigned char * getData(); - int getDataLen(); - - bool hasAlpha(); - bool isPremultipliedAlpha(); - bool saveToFile(const char *pszFilePath, bool bIsToRGB = true); - int getWidth(); - int getHeight(); - int getBitPerPixel(); -}; diff --git a/tools/tolua++/CCInteger.pkg b/tools/tolua++/CCInteger.pkg deleted file mode 100644 index c506637fb4..0000000000 --- a/tools/tolua++/CCInteger.pkg +++ /dev/null @@ -1,7 +0,0 @@ -class CCInteger : public CCObject -{ - CCInteger(int v); - int getValue() const; - - static CCInteger* create(int v); -}; diff --git a/tools/tolua++/CCKeypadDispatcher.pkg b/tools/tolua++/CCKeypadDispatcher.pkg deleted file mode 100644 index 868e390bec..0000000000 --- a/tools/tolua++/CCKeypadDispatcher.pkg +++ /dev/null @@ -1,6 +0,0 @@ - -typedef enum { - // the back key clicked msg - kTypeBackClicked = 1, - kTypeMenuClicked, -} ccKeypadMSGType; diff --git a/tools/tolua++/CCLabelAtlas.pkg b/tools/tolua++/CCLabelAtlas.pkg deleted file mode 100644 index f14d41c84e..0000000000 --- a/tools/tolua++/CCLabelAtlas.pkg +++ /dev/null @@ -1,14 +0,0 @@ - -class CCLabelAtlas : public CCAtlasNode -{ - void updateAtlasValues(); - - void setString(const char *label); - const char* getString(void) const; - - CCTexture2D* getTexture(void); - void setTexture(CCTexture2D *texture); - - static CCLabelAtlas* create(const char *label, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap); - static CCLabelAtlas* create(const char *sring, const char *fntFile); -}; diff --git a/tools/tolua++/CCLabelBMFont.pkg b/tools/tolua++/CCLabelBMFont.pkg deleted file mode 100644 index 358f2fdab4..0000000000 --- a/tools/tolua++/CCLabelBMFont.pkg +++ /dev/null @@ -1,39 +0,0 @@ - -enum { - kCCLabelAutomaticWidth = -1, -}; - -class CCLabelBMFont : public CCSpriteBatchNode -{ - CCLabelBMFont(); - ~CCLabelBMFont(); - bool init(); - void setString(const char *label); - void setString(const char *label, bool fromUpdate); - void setCString(const char *label); - const char* getString(void) const; - - void setAnchorPoint(const CCPoint & var); - void setAlignment(CCTextAlignment alignment); - void setWidth(float width); - void setLineBreakWithoutSpace(bool breakWithoutSpace); - void setScale(float scale); - void setScaleX(float scaleX); - void setScaleY(float scaleY); - - void setFntFile(const char* fntFile); - const char* getFntFile(); - - void setColor(const Color3B& color); - const Color3B& getColor(void) const; - - GLubyte getOpacity(void) const; - void setOpacity(GLubyte opacity); - - bool isOpacityModifyRGB() const; - void setOpacityModifyRGB(bool isOpacityModifyRGB); - - static void purgeCachedData(); - static CCLabelBMFont * create(const char *str, const char *fntFile, float width = kCCLabelAutomaticWidth, CCTextAlignment alignment = kCCTextAlignmentLeft, CCPoint imageOffset = CCPointMake(0, 0)); - static CCLabelBMFont * create(); -}; diff --git a/tools/tolua++/CCLabelTTF.pkg b/tools/tolua++/CCLabelTTF.pkg deleted file mode 100644 index 5fe337dbe5..0000000000 --- a/tools/tolua++/CCLabelTTF.pkg +++ /dev/null @@ -1,29 +0,0 @@ - -class CCLabelTTF : public CCSprite -{ - CCLabelTTF(); - ~CCLabelTTF(); - bool init(); - void setString(const char *label); - const char* getString(void) const; - - CCTextAlignment getHorizontalAlignment() const; - void setHorizontalAlignment(CCTextAlignment alignment); - - CCVerticalTextAlignment getVerticalAlignment() const; - void setVerticalAlignment(CCVerticalTextAlignment verticalAlignment); - - CCSize getDimensions() const; - void setDimensions(CCSize &dim); - - float getFontSize() const; - void setFontSize(float fontSize); - - const char* getFontName() const; - void setFontName(const char *fontName); - - static CCLabelTTF * create(const char *str, const char *fontName, float fontSize, const CCSize& dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment); - static CCLabelTTF * create(const char *str, const char *fontName, float fontSize, const CCSize& dimensions, CCTextAlignment hAlignment); - static CCLabelTTF * create(const char *str, const char *fontName, float fontSize); - static CCLabelTTF * create(); -}; diff --git a/tools/tolua++/CCLayer.pkg b/tools/tolua++/CCLayer.pkg deleted file mode 100644 index 5d7f85ddf7..0000000000 --- a/tools/tolua++/CCLayer.pkg +++ /dev/null @@ -1,104 +0,0 @@ -typedef enum { - kCCTouchesAllAtOnce, - kCCTouchesOneByOne, -} ccTouchesMode; - -class CCLayer : public CCNode -{ - void setTouchEnabled(bool bValue); - bool isTouchEnabled() const; - - void setAccelerometerEnabled(bool bValue); - bool isAccelerometerEnabled() const; - - void setKeypadEnabled(bool bValue); - bool isKeypadEnabled() const; - - virtual void setTouchMode(ccTouchesMode mode); - virtual int getTouchMode() const; - virtual void setTouchPriority(int priority); - virtual int getTouchPriority() const; - virtual void setSwallowsTouches(bool swallowsTouches); - virtual bool isSwallowsTouches() const; - - static CCLayer *create(void); -}; - -class CCLayerRGBA : public CCLayer, public CCRGBAProtocol -{ - static CCLayerRGBA* create(); - - CCLayerRGBA(); - virtual ~CCLayerRGBA(); - - virtual bool init(); - - virtual GLubyte getOpacity() const; - virtual GLubyte getDisplayedOpacity() const; - virtual void setOpacity(GLubyte opacity); - virtual void updateDisplayedOpacity(GLubyte parentOpacity); - virtual bool isCascadeOpacityEnabled() const; - virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled); - - virtual const Color3B& getColor() const; - virtual const Color3B& getDisplayedColor() const; - virtual void setColor(const Color3B& color); - virtual void updateDisplayedColor(const Color3B& parentColor); - virtual bool isCascadeColorEnabled() const; - virtual void setCascadeColorEnabled(bool cascadeColorEnabled); - - virtual void setOpacityModifyRGB(bool bValue); - virtual bool isOpacityModifyRGB() const; -}; - -class CCLayerColor : public CCLayerRGBA -{ - void changeWidth(GLfloat w); - void changeHeight(GLfloat h); - void changeWidthAndHeight(GLfloat w ,GLfloat h); - - void setContentSize(const CCSize & var); - - void setOpacity(GLubyte var); - void setColor(Color3B Value); - void setBlendFunc(BlendFunc Value); - BlendFunc getBlendFunc(void) const; - - void setOpacityModifyRGB(bool bValue); - bool isOpacityModifyRGB(void) const; - - static CCLayerColor * create(Color4B color, GLfloat width, GLfloat height); - static CCLayerColor * create(Color4B color); -}; - -class CCLayerGradient : public CCLayerColor -{ - void setStartColor(Color3B colors); - Color3B getStartColor() const; - void setEndColor(Color3B Value); - Color3B getEndColor(void) const; - void setStartOpacity(GLubyte Value); - GLubyte getStartOpacity(void); - void setEndOpacity(GLubyte Value); - GLubyte getEndOpacity(void); - void setVector(CCPoint Value); - CCPoint getVector(void); - - void setCompressedInterpolation(bool Value); - bool isCompressedInterpolation(void) const; - - static CCLayerGradient* create(Color4B start, Color4B end, CCPoint v); - static CCLayerGradient* create(Color4B start, Color4B end); - static CCLayerGradient* create(); -}; - -class CCLayerMultiplex : public CCLayer -{ - void addLayer(CCLayer* layer); - void switchTo(unsigned int n); - void switchToAndReleaseMe(unsigned int n); - - static CCLayerMultiplex* createWithArray(CCArray* arrayOfLayers); - static CCLayerMultiplex * create(); - static CCLayerMultiplex * createWithLayer(CCLayer* layer); -}; diff --git a/tools/tolua++/CCMenu.pkg b/tools/tolua++/CCMenu.pkg deleted file mode 100644 index efc9b6daaa..0000000000 --- a/tools/tolua++/CCMenu.pkg +++ /dev/null @@ -1,38 +0,0 @@ -enum -{ - kCCMenuStateWaiting, - kCCMenuStateTrackingTouch -}; - -enum { - kCCMenuHandlerPriority = -128 -}; - -class CCMenu : public CCLayerRGBA -{ - void alignItemsVertically(); - void alignItemsVerticallyWithPadding(float padding); - void alignItemsHorizontally(); - void alignItemsHorizontallyWithPadding(float padding); - void alignItemsInColumnsWithArray(CCArray* rows); - void alignItemsInRowsWithArray(CCArray* columns); - - void setHandlerPriority(int newPriority); - - void addChild(CCMenuItem* child, int zOrder = 0, int tag = -1); - - void setOpacity(GLubyte opacity); - GLubyte getOpacity(void); - void setColor(Color3B color); - Color3B getColor(void); - - void setOpacityModifyRGB(bool bValue); - bool isOpacityModifyRGB(void); - - bool isEnabled(); - void setEnabled(bool value); - - static CCMenu* create(); - static CCMenu* createWithItem(CCMenuItem* item); - static CCMenu* createWithArray(CCArray* pArrayOfItems); -}; diff --git a/tools/tolua++/CCMenuItem.pkg b/tools/tolua++/CCMenuItem.pkg deleted file mode 100644 index 7f0dd8414a..0000000000 --- a/tools/tolua++/CCMenuItem.pkg +++ /dev/null @@ -1,130 +0,0 @@ - -class CCMenuItem : public CCNodeRGBA -{ - CCRect rect(); - void activate(); - void selected(); - void unselected(); - void setEnabled(bool enabled); - bool isEnabled() const; - bool isSelected() const; -}; - -class CCMenuItemLabel : public CCMenuItem -{ - void setString(const char* label); - - void setOpacity(GLubyte opacity); - GLubyte getOpacity(); - void setColor(Color3B color); - Color3B getColor(); - void setDisabledColor(const Color3B & color); - const Color3B & getDisabledColor(); - void setLabel(CCNode* pLabel); - CCNode* getLabel(); - - void activate(); - void selected(); - void unselected(); - void setEnabled(bool enabled); - - void setOpacityModifyRGB(bool bValue); - bool isOpacityModifyRGB(void); - - static CCMenuItemLabel* create(CCNode* label); -}; - -class CCMenuItemAtlasFont : public CCMenuItemLabel -{ - static CCMenuItemAtlasFont* create(const char* value, - const char* charMapFile, - int itemWidth, - int itemHeight, - char startCharMap); -}; - -class CCMenuItemFont : public CCMenuItemLabel -{ - static void setFontSize(int s); - static unsigned int getFontSize(); - static void setFontName(const char* name); - static const char* getFontName(); - void setFontSizeObj(unsigned int s); - unsigned int getFontSizeObj(); - void setFontNameObj(const char* name); - const char* getFontNameObj() const; - - static CCMenuItemFont * create(const char* value); -}; - -class CCMenuItemSprite : public CCMenuItem -{ - void setColor(Color3B color); - Color3B getColor(); - void setOpacity(GLubyte opacity); - GLubyte getOpacity(); - - void setNormalImage(CCNode* pImage); - CCNode* getNormalImage(); - void setSelectedImage(CCNode* pImage); - CCNode* getSelectedImage(); - void setDisabledImage(CCNode* pImage); - CCNode* getDisabledImage(); - - void selected(); - void unselected(); - void setEnabled(bool bEnabled); - - void setOpacityModifyRGB(bool bValue); - bool isOpacityModifyRGB(void); - - static CCMenuItemSprite * create(CCNode* normalSprite, - CCNode* selectedSprite, - CCNode* disabledSprite); - static CCMenuItemSprite * create(CCNode* normalSprite, - CCNode* selectedSprite); -}; - -class CCMenuItemImage : public CCMenuItemSprite -{ - void setColor(Color3B color); - Color3B getColor(); - void setOpacity(GLubyte opacity); - GLubyte getOpacity(); - - void setNormalSpriteFrame(CCSpriteFrame* frame); - void setSelectedSpriteFrame(CCSpriteFrame* frame); - void setDisabledSpriteFrame(CCSpriteFrame* frame); - - static CCMenuItemImage* create(const char* normalImage, - const char* selectedImage, - const char* disabledImage); - static CCMenuItemImage* create(const char* normalImage, - const char* selectedImage); - static CCMenuItemImage* create(); -}; - -class CCMenuItemToggle : public CCMenuItem -{ - void setColor(Color3B color); - Color3B getColor(); - void setOpacity(GLubyte opacity); - GLubyte getOpacity(); - void setSelectedIndex(unsigned int index); - unsigned int getSelectedIndex(); - void setSubItems(CCArray* pArrayOfItems); - CCArray* getSubItems(); - - void addSubItem(CCMenuItem *item); - CCMenuItem* getSelectedItem(); - - void activate(); - void selected(); - void unselected(); - void setEnabled(bool var); - - void setOpacityModifyRGB(bool bValue); - bool isOpacityModifyRGB(void); - - static CCMenuItemToggle* create(CCMenuItem *item); -}; diff --git a/tools/tolua++/CCMotionStreak.pkg b/tools/tolua++/CCMotionStreak.pkg deleted file mode 100644 index 2945d3d18e..0000000000 --- a/tools/tolua++/CCMotionStreak.pkg +++ /dev/null @@ -1,25 +0,0 @@ -class CCMotionStreak : public CCNodeRGBA -{ - static CCMotionStreak* create(float fade, float minSeg, float stroke, Color3B color, const char* path); - static CCMotionStreak* create(float fade, float minSeg, float stroke, Color3B color, CCTexture2D* texture); - - void tintWithColor(Color3B colors); - void reset(); - - void setPosition(CCPoint& position); - - CCTexture2D* getTexture(void); - void setTexture(CCTexture2D *texture); - void setBlendFunc(BlendFunc blendFunc); - BlendFunc getBlendFunc(void); - void setColor(const Color3B& color); - const Color3B& getColor(void); - GLubyte getOpacity(void); - void setOpacity(GLubyte opacity); - void setOpacityModifyRGB(bool bValue); - bool isOpacityModifyRGB(void); - bool isFastMode(); - void setFastMode(bool bFastMode); - bool isStartingPositionInitialized(); - void setStartingPositionInitialized(bool bStartingPositionInitialized); -}; diff --git a/tools/tolua++/CCNode.pkg b/tools/tolua++/CCNode.pkg deleted file mode 100644 index 249461610f..0000000000 --- a/tools/tolua++/CCNode.pkg +++ /dev/null @@ -1,146 +0,0 @@ -enum { - kCCNodeTagInvalid = -1, -}; - -enum { - kCCNodeOnEnter, - kCCNodeOnExit -}; - -typedef enum { -// CC_GL_ALL = 0, -} ccGLServerState; - - -class CCNode : public CCObject -{ - int getZOrder() const; - float getVertexZ() const; - void setVertexZ(float var); - float getRotation() const; - float getRotationX() const; - float getRotationY() const; - void setRotation(float newRotation); - float getScale() const; - void setScale(float scale); - float getScaleX() const; - void setScaleX(float newScaleX); - float getScaleY() const; - void setScaleY(float newScaleY); - void getPosition(float* x = 0, float* y = 0) const; - float getPositionX() const; - float getPositionY() const; - void setPosition(float x, float y); - void setPosition(CCPoint pos); - void setPositionX(float x); - void setPositionY(float y); - float getSkewX() const; - void setSkewX(float skewX); - float getSkewY() const; - void setSkewY(float skewY); - bool isVisible() const; - void setVisible(bool var); - CCPoint getAnchorPoint() const; - void setAnchorPoint(CCPoint point); - CCSize getContentSize(); - void setContentSize(const CCSize & size); - int getTag(); - void setTag(int var); - - CCArray* getChildren(); - unsigned int getChildrenCount(void); - - CCCamera* getCamera(); - CCGridBase* getGrid(); - void setGrid(CCGridBase* pGrid); - CCPoint getAnchorPointInPoints(); - bool isRunning() const; - CCNode* getParent(); - void setParent(CCNode * var); - bool isIgnoreAnchorPointForPosition(); - void ignoreAnchorPointForPosition(bool newValue); - void* getUserData(); - void setUserData(void *var); - CCObject* getUserObject(); - void setUserObject(CCObject* pObject); - CCGLProgram* getShaderProgram(); - void setShaderProgram(CCGLProgram* pShaderProgram); - int getOrderOfArrival() const; - void setOrderOfArrival(int order); - ccGLServerState getGLServerState() const; - void setGLServerState(ccGLServerState state); - CCActionManager* getActionManager(); - void setActionManager(CCActionManager* pActionMgr); - ccGLServerState getGLServerState(void); - void setGLServerState(ccGLServerState state); - CCScheduler* getScheduler(); - void setScheduler(CCScheduler* pScheduler); - void addChild(CCNode * child); - void addChild(CCNode * child, int zOrder); - void addChild(CCNode * child, int zOrder, int tag); - void removeChild(CCNode* child, bool cleanup); - void removeAllChildrenWithCleanup(bool cleanup); - void reorderChild(CCNode * child, int zOrder); - void cleanup(void); - void draw(void); - void visit(void); - void transform(void); - void transformAncestors(void); - CCRect getBoundingBox(void) const; - - CCAction* runAction(CCAction* action); - void stopAllActions(void); - void stopAction(CCAction* action); - - void stopActionByTag(int tag); - CCAction* getActionByTag(int tag); - const char * description(void) const; - CCNode* getChildByTag(int tag); - - unsigned int getNumberOfRunningActions(void) const; - - CCAffineTransform nodeToParentTransform(void); - CCAffineTransform parentToNodeTransform(void); - CCAffineTransform nodeToWorldTransform(void); - CCAffineTransform worldToNodeTransform(void); - - CCPoint convertToNodeSpace(CCPoint worldPoint); - CCPoint convertToWorldSpace(CCPoint nodePoint); - CCPoint convertToNodeSpaceAR(CCPoint worldPoint); - CCPoint convertToWorldSpaceAR(CCPoint nodePoint); - CCPoint convertTouchToNodeSpace(CCTouch * touch); - CCPoint convertTouchToNodeSpaceAR(CCTouch * touch); - - void removeFromParentAndCleanup(bool cleanup); - void removeChildByTag(int tag, bool cleanup); - - void scheduleUpdateWithPriorityLua(LUA_FUNCTION nHandler, int priority); - void unscheduleUpdate(void); - - static CCNode * create(void); -}; - -class CCNodeRGBA : public CCNode, public CCRGBAProtocol -{ - CCNodeRGBA(); - virtual ~CCNodeRGBA(); - - virtual bool init(); - - virtual GLubyte getOpacity() const; - virtual GLubyte getDisplayedOpacity() const; - virtual void setOpacity(GLubyte opacity); - virtual void updateDisplayedOpacity(GLubyte parentOpacity); - virtual bool isCascadeOpacityEnabled() const; - virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled); - - virtual const Color3B& getColor(void) const; - virtual const Color3B& getDisplayedColor() const; - virtual void setColor(const Color3B& color); - virtual void updateDisplayedColor(const Color3B& parentColor); - virtual bool isCascadeColorEnabled() const; - virtual void setCascadeColorEnabled(bool cascadeColorEnabled); - - virtual void setOpacityModifyRGB(bool bValue); - virtual bool isOpacityModifyRGB() const; -}; diff --git a/tools/tolua++/CCNotificationCenter.pkg b/tools/tolua++/CCNotificationCenter.pkg deleted file mode 100644 index d6598d1076..0000000000 --- a/tools/tolua++/CCNotificationCenter.pkg +++ /dev/null @@ -1,24 +0,0 @@ - -class CCNotificationCenter : public CCObject -{ - CCNotificationCenter(); - - ~CCNotificationCenter(); - - static CCNotificationCenter* getInstance(); - static void destroyInstance(); - - int removeAllObservers(CCObject *target); - - void registerScriptObserver(CCObject *target,LUA_FUNCTION funcID,const char* name); - - void unregisterScriptObserver(CCObject *target,const char* name); - - void postNotification(const char *name); - - void postNotification(const char *name, CCObject *object); - - int getScriptHandler(); - - int getObserverHandlerByName(const char* name); -}; diff --git a/tools/tolua++/CCObject.pkg b/tools/tolua++/CCObject.pkg deleted file mode 100644 index 12883a0b74..0000000000 --- a/tools/tolua++/CCObject.pkg +++ /dev/null @@ -1,10 +0,0 @@ - -class CCObject -{ - void release(void); - void retain(void); - bool isSingleReference(void); - unsigned int retainCount(void); - bool isEqual(const CCObject* pObject); - CCObject* autorelease(); -}; diff --git a/tools/tolua++/CCParallaxNode.pkg b/tools/tolua++/CCParallaxNode.pkg deleted file mode 100644 index 998fb6d4a1..0000000000 --- a/tools/tolua++/CCParallaxNode.pkg +++ /dev/null @@ -1,16 +0,0 @@ - -class CCParallaxNode : public CCNode -{ - // struct _ccArray* getParallaxArray(); - // void setParallaxArray(struct _ccArray * pval); - - void addChild(CCNode * child, unsigned int z, CCPoint parallaxRatio, CCPoint positionOffset); - void addChild(CCNode * child, unsigned int zOrder, int tag); - - void removeChild(CCNode* child, bool cleanup); - void removeAllChildrenWithCleanup(bool cleanup); - - void visit(void); - - static CCParallaxNode* create(); -}; diff --git a/tools/tolua++/CCParticleBatchNode.pkg b/tools/tolua++/CCParticleBatchNode.pkg deleted file mode 100644 index b76da61785..0000000000 --- a/tools/tolua++/CCParticleBatchNode.pkg +++ /dev/null @@ -1,23 +0,0 @@ -class CCParticleBatchNode : public CCNode, public CCTextureProtocol -{ -public: - void addChild(CCNode * child); - void addChild(CCNode * child, int zOrder); - void addChild(CCNode * child, int zOrder, int tag); - - void insertChild(CCParticleSystem* pSystem, unsigned int index); - - void removeChild(CCNode* child, bool cleanup); - void reorderChild(CCNode * child, int zOrder); - void removeChildAtIndex(unsigned int index, bool doCleanup); - void removeAllChildrenWithCleanup(bool doCleanup); - void disableParticle(unsigned int particleIndex); - - CCTexture2D* getTexture(void); - void setTexture(CCTexture2D *texture); - void setBlendFunc(const BlendFunc &blendFunc); - const BlendFunc& getBlendFunc(void); - - static CCParticleBatchNode* create(const char* fileImage, unsigned int capacity = kCCParticleDefaultCapacity); - static CCParticleBatchNode* createWithTexture(CCTexture2D *tex, unsigned int capacity = kCCParticleDefaultCapacity); -}; diff --git a/tools/tolua++/CCParticleExamples.pkg b/tools/tolua++/CCParticleExamples.pkg deleted file mode 100644 index 6b6571010b..0000000000 --- a/tools/tolua++/CCParticleExamples.pkg +++ /dev/null @@ -1,55 +0,0 @@ - -class CCParticleFire : public CCParticleSystemQuad -{ - static CCParticleFire * create(); -}; - -class CCParticleFireworks : public CCParticleSystemQuad -{ - static CCParticleFireworks * create(); -}; - -class CCParticleSun : public CCParticleSystemQuad -{ - static CCParticleSun * create(); -}; - -class CCParticleGalaxy : public CCParticleSystemQuad -{ - static CCParticleGalaxy * create(); -}; - -class CCParticleFlower : public CCParticleSystemQuad -{ - static CCParticleFlower * create(); -}; - -class CCParticleMeteor : public CCParticleSystemQuad -{ - static CCParticleMeteor * create(); -}; - -class CCParticleSpiral : public CCParticleSystemQuad -{ - static CCParticleSpiral * create(); -}; - -class CCParticleExplosion : public CCParticleSystemQuad -{ - static CCParticleExplosion * create(); -}; - -class CCParticleSmoke : public CCParticleSystemQuad -{ - static CCParticleSmoke * create(); -}; - -class CCParticleSnow : public CCParticleSystemQuad -{ - static CCParticleSnow * create(); -}; - -class CCParticleRain : public CCParticleSystemQuad -{ - static CCParticleRain * create(); -}; diff --git a/tools/tolua++/CCParticleSystem.pkg b/tools/tolua++/CCParticleSystem.pkg deleted file mode 100644 index 66f7174530..0000000000 --- a/tools/tolua++/CCParticleSystem.pkg +++ /dev/null @@ -1,152 +0,0 @@ -enum { - kCCParticleDurationInfinity = -1, - kCCParticleStartSizeEqualToEndSize = -1, - kCCParticleStartRadiusEqualToEndRadius = -1, -}; - -enum { - kCCParticleModeGravity, - kCCParticleModeRadius, -}; - -typedef enum { - kCCPositionTypeFree, - kCCPositionTypeRelative, - kCCPositionTypeGrouped, -}tCCPositionType; - - -class CCParticleSystem : public CCNode -{ - // mode A - const CCPoint& getGravity(); - void setGravity(const CCPoint& g); - float getSpeed(); - void setSpeed(float speed); - float getSpeedVar(); - void setSpeedVar(float speed); - float getTangentialAccel(); - void setTangentialAccel(float t); - float getTangentialAccelVar(); - void setTangentialAccelVar(float t); - float getRadialAccel(); - void setRadialAccel(float t); - float getRadialAccelVar(); - void setRadialAccelVar(float t); - - // mode B - float getStartRadius(); - void setStartRadius(float startRadius); - float getStartRadiusVar(); - void setStartRadiusVar(float startRadiusVar); - float getEndRadius(); - void setEndRadius(float endRadius); - float getEndRadiusVar(); - void setEndRadiusVar(float endRadiusVar); - float getRotatePerSecond(); - void setRotatePerSecond(float degrees); - float getRotatePerSecondVar(); - void setRotatePerSecondVar(float degrees); - - bool addParticle(); - void initParticle(tCCParticle* particle); - void stopSystem(); - void resetSystem(); - bool isFull(); - void updateQuadWithParticle(tCCParticle* particle, const CCPoint& newPosition); - void postStep(); - - unsigned int getParticleCount(); - float getDuration(); - void setDuration(float d); - CCPoint getSourcePosition(); - void setSourcePosition(CCPoint pos); - CCPoint getPosVar(); - void setPosVar(CCPoint pos); - float getLife(); - void setLife(float life); - float getLifeVar(); - void setLifeVar(float lifeVar); - float getAngle(); - void setAngle(float angle); - float getAngleVar(); - void setAngleVar(float angle); - - float getStartSize(); - void setStartSize(float size); - float getStartSizeVar(); - void setStartSizeVar(float size); - float getEndSize(); - void setEndSize(float size); - float getEndSizeVar(); - void setEndSizeVar(float size); - - void setStartColor(const Color4F var); - const Color4F & getStartColor(); - void setStartColorVar(const Color4F var); - const Color4F & getStartColorVar(); - void setEndColor(const Color4F var); - const Color4F & getEndColor(); - void setEndColorVar(const Color4F var); - const Color4F & getEndColorVar(); - void setStartSpin(float var); - float getStartSpin(); - void setStartSpinVar(float var); - float getStartSpinVar(); - void setEndSpin(float var); - float getEndSpin(); - void setEndSpinVar(float var); - float getEndSpinVar(); - void setEmissionRate(float rate); - float getEmissionRate(); - unsigned int getTotalParticles(); - - bool isAutoRemoveOnFinish(); - void setAutoRemoveOnFinish(bool var); - int getEmitterMode(); - void setEmitterMode(int mode); - - CCTexture2D* getTexture(void); - void setTexture(CCTexture2D* var); - - BlendFunc getBlendFunc(void); - void setBlendFunc(BlendFunc var); - - void setScale(float s); - void setRotation(float newRotation); - void setScaleX(float newScaleX); - void setScaleY(float newScaleY); - - bool isActive(); - bool isBlendAdditive(); - void setBlendAdditive(bool value); - - CCParticleBatchNode* getBatchNode(void); - void setBatchNode(CCParticleBatchNode* node); - tCCPositionType getPositionType(void); - void setPositionType(tCCPositionType type); - - bool initWithFile(const char* plistFile); - bool initWithTotalParticles(unsigned int number); - - static CCParticleSystem * create(const char *plistFile); -}; - -class CCParticleSystemQuad : public CCParticleSystem -{ - CCParticleSystemQuad(void); - void postStep(); - void setDisplayFrame(CCSpriteFrame* spriteFrame); - void setTexture(CCTexture2D* texture); - void setTextureWithRect(CCTexture2D *texture, const CCRect& rect); - void setBatchNode(CCParticleBatchNode* batchNode); - void setTotalParticles(unsigned int tp); - - void updateQuadWithParticle(tCCParticle* particle, const CCPoint& newPosition); - void postStep(); - void setTotalParticles(unsigned int tp); - - static CCParticleSystemQuad * create(const char *plistFile); - static CCParticleSystemQuad * create(); -}; - diff --git a/tools/tolua++/CCPointExtension.pkg b/tools/tolua++/CCPointExtension.pkg deleted file mode 100644 index 1af9739089..0000000000 --- a/tools/tolua++/CCPointExtension.pkg +++ /dev/null @@ -1 +0,0 @@ -float clampf(float value, float min_inclusive, float max_inclusive); diff --git a/tools/tolua++/CCProgressTimer.pkg b/tools/tolua++/CCProgressTimer.pkg deleted file mode 100644 index 6eba68fd82..0000000000 --- a/tools/tolua++/CCProgressTimer.pkg +++ /dev/null @@ -1,36 +0,0 @@ -typedef enum { - kCCProgressTimerTypeRadial, - kCCProgressTimerTypeBar, -} CCProgressTimerType; - -class CCProgressTimer : public CCNodeRGBA -{ - CCProgressTimerType getType(void); - - float getPercentage(void); - - CCSprite* getSprite(void) { return m_pSprite; } - - void setPercentage(float fPercentage); - void setSprite(CCSprite *pSprite); - void setType(CCProgressTimerType type); - void setReverseProgress(bool reverse); - void setAnchorPoint(CCPoint anchorPoint); - - void setColor(const Color3B& color); - const Color3B& getColor(void); - GLubyte getOpacity(void); - void setOpacity(GLubyte opacity); - void setOpacityModifyRGB(bool bValue); - bool isOpacityModifyRGB(void); - - static CCProgressTimer* create(CCSprite* sp); - - CCPoint getMidpoint(); - void setMidpoint(CCPoint pt); - CCPoint getBarChangeRate(); - void setBarChangeRate(CCPoint rate); - - bool isReverseDirection(); - void setReverseDirection(bool bReverseDir); -}; diff --git a/tools/tolua++/CCProtocols.pkg b/tools/tolua++/CCProtocols.pkg deleted file mode 100644 index 05d48bb5bc..0000000000 --- a/tools/tolua++/CCProtocols.pkg +++ /dev/null @@ -1,18 +0,0 @@ -class CCRGBAProtocol -{ -public: - virtual void setColor(const Color3B& color); - virtual const Color3B& getColor(void); - virtual const Color3B& getDisplayedColor(void); - virtual GLubyte getDisplayedOpacity(void); - virtual GLubyte getOpacity(void); - virtual void setOpacity(GLubyte opacity); - virtual void setOpacityModifyRGB(bool bValue); - virtual bool isOpacityModifyRGB(void); - virtual bool isCascadeColorEnabled(void); - virtual void setCascadeColorEnabled(bool cascadeColorEnabled); - virtual void updateDisplayedColor(const Color3B& color); - virtual bool isCascadeOpacityEnabled(void); - virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled); - virtual void updateDisplayedOpacity(GLubyte opacity); -}; diff --git a/tools/tolua++/CCRenderTexture.pkg b/tools/tolua++/CCRenderTexture.pkg deleted file mode 100644 index 2e038456ff..0000000000 --- a/tools/tolua++/CCRenderTexture.pkg +++ /dev/null @@ -1,30 +0,0 @@ -enum tCCImageFormat -{ - kCCImageFormatJPEG = 0, - kCCImageFormatPNG = 1, -}; - -class CCRenderTexture : public CCNode -{ - CCSprite* getSprite(); - void setSprite(CCSprite* psprite); - - void begin(); - void endToLua (); - void beginWithClear(float r, float g, float b, float a); - void beginWithClear(float r, float g, float b, float a, float depthValue); - void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue); - - void clear(float r, float g, float b, float a); - void clearDepth(float depthValue); - void clearStencil(int stencilValue); - - CCImage* newCCImage(); - - bool saveToFile(const char *szFilePath); - bool saveToFile(const char *name, tCCImageFormat format); - - static CCRenderTexture * create(int w ,int h, CCTexture2DPixelFormat eFormat, GLuint uDepthStencilFormat); - static CCRenderTexture * create(int w, int h, CCTexture2DPixelFormat eFormat); - static CCRenderTexture * create(int w, int h); -}; diff --git a/tools/tolua++/CCRibbon.pkg b/tools/tolua++/CCRibbon.pkg deleted file mode 100644 index e97e84598a..0000000000 --- a/tools/tolua++/CCRibbon.pkg +++ /dev/null @@ -1,20 +0,0 @@ - -class CCRibbon: public CCNode -{ - void setTexture(CCTexture2D* val); - CCTexture2D* getTexture(); - - void setTextureLength(float val); - float getTextureLength(); - - void setBlendFunc(BlendFunc val); - BlendFunc getBlendFunc(); - - void setColor(Color4B val); - Color4B getColor(); - - void addPointAt(CCPoint location, float width); - float sideOfLine(CCPoint p, CCPoint l1, CCPoint l2); - - static CCRibbon * create(float w, const char *path, float length, Color4B color, float fade); -}; diff --git a/tools/tolua++/CCScale9Sprite.pkg b/tools/tolua++/CCScale9Sprite.pkg deleted file mode 100644 index 2baeb3218c..0000000000 --- a/tools/tolua++/CCScale9Sprite.pkg +++ /dev/null @@ -1,92 +0,0 @@ - -class CCScale9Sprite : public CCNodeRGBA -{ - - CCScale9Sprite(); - virtual ~CCScale9Sprite(); - - CCSize getOriginalSize(void) const; - - CCSize getPreferredSize(); - void setPreferredSize(CCSize sz); - - CCRect getCapInsets(); - void setCapInsets(CCRect rt); - - float getInsetLeft(); - void setInsetLeft(float fLeft); - - float getInsetTop(); - void setInsetTop(float fTop); - - float getInsetRight(); - void setInsetRight(float fRight); - - float getInsetBottom(); - void setInsetBottom(float fBottom); - - virtual void setContentSize(const CCSize & size); - virtual void visit(); - - virtual bool init(); - - virtual bool initWithBatchNode(CCSpriteBatchNode* batchnode, CCRect rect, bool rotated, CCRect capInsets); - virtual bool initWithBatchNode(CCSpriteBatchNode* batchnode, CCRect rect, CCRect capInsets); - - virtual bool initWithFile(const char* file, CCRect rect, CCRect capInsets); - - - static CCScale9Sprite* create(const char* file, CCRect rect, CCRect capInsets); - - - virtual bool initWithFile(const char* file, CCRect rect); - - - static CCScale9Sprite* create(const char* file, CCRect rect); - - - virtual bool initWithFile(CCRect capInsets, const char* file); - - - static CCScale9Sprite* create(CCRect capInsets, const char* file); - - virtual bool initWithFile(const char* file); - - static CCScale9Sprite* create(const char* file); - - virtual bool initWithSpriteFrame(CCSpriteFrame* spriteFrame, CCRect capInsets); - - static CCScale9Sprite* createWithSpriteFrame(CCSpriteFrame* spriteFrame, CCRect capInsets); - - virtual bool initWithSpriteFrame(CCSpriteFrame* spriteFrame); - - - static CCScale9Sprite* createWithSpriteFrame(CCSpriteFrame* spriteFrame); - - - virtual bool initWithSpriteFrameName(const char*spriteFrameName, CCRect capInsets); - - - static CCScale9Sprite* createWithSpriteFrameName(const char*spriteFrameName, CCRect capInsets); - - - virtual bool initWithSpriteFrameName(const char*spriteFrameName); - - - static CCScale9Sprite* createWithSpriteFrameName(const char*spriteFrameName); - - - CCScale9Sprite* resizableSpriteWithCapInsets(CCRect capInsets); - - static CCScale9Sprite* create(); - - virtual void setOpacityModifyRGB(bool bValue); - - virtual bool isOpacityModifyRGB(void); - virtual void setOpacity(GLubyte opacity); - virtual void setColor(const Color3B& color); - - virtual bool updateWithBatchNode(CCSpriteBatchNode* batchnode, CCRect rect, bool rotated, CCRect capInsets); - - virtual void setSpriteFrame(CCSpriteFrame * spriteFrame); -}; diff --git a/tools/tolua++/CCScene.pkg b/tools/tolua++/CCScene.pkg deleted file mode 100644 index 350672772d..0000000000 --- a/tools/tolua++/CCScene.pkg +++ /dev/null @@ -1,5 +0,0 @@ - -class CCScene : public CCNode -{ - static CCScene *create(void); -}; diff --git a/tools/tolua++/CCScheduler.pkg b/tools/tolua++/CCScheduler.pkg deleted file mode 100644 index 1bb53bb84f..0000000000 --- a/tools/tolua++/CCScheduler.pkg +++ /dev/null @@ -1,19 +0,0 @@ - -class CCTimer : public CCObject -{ - float getInterval(void); - void setInterval(float fInterval); - void update(float dt); - - static CCTimer* createWithScriptHandler(LUA_FUNCTION funcID, float fSeconds); -}; - -class CCScheduler : public CCObject -{ - float getTimeScale(void); - void setTimeScale(float fTimeScale); - - - unsigned int scheduleScriptFunc(LUA_FUNCTION funcID, float fInterval, bool bPaused); - void unscheduleScriptEntry(unsigned int uScheduleScriptEntryID); -}; diff --git a/tools/tolua++/CCSet.pkg b/tools/tolua++/CCSet.pkg deleted file mode 100644 index 529ca53368..0000000000 --- a/tools/tolua++/CCSet.pkg +++ /dev/null @@ -1,10 +0,0 @@ -class CCSet : public CCObject -{ - CCSet* copy(); - int count(); - void addObject(CCObject *pObject); - void removeObject(CCObject *pObject); - void removeAllObjects(); - bool containsObject(CCObject *pObject); - CCObject* anyObject(); -}; \ No newline at end of file diff --git a/tools/tolua++/CCSprite.pkg b/tools/tolua++/CCSprite.pkg deleted file mode 100644 index f54f72becd..0000000000 --- a/tools/tolua++/CCSprite.pkg +++ /dev/null @@ -1,96 +0,0 @@ -/* -typedef enum { - //! Translate with it's parent - CC_HONOR_PARENT_TRANSFORM_TRANSLATE = 1 << 0, - //! Rotate with it's parent - CC_HONOR_PARENT_TRANSFORM_ROTATE = 1 << 1, - //! Scale with it's parent - CC_HONOR_PARENT_TRANSFORM_SCALE = 1 << 2, - //! Skew with it's parent - CC_HONOR_PARENT_TRANSFORM_SKEW = 1 << 3, - - //! All possible transformation enabled. Default value. - CC_HONOR_PARENT_TRANSFORM_ALL = CC_HONOR_PARENT_TRANSFORM_TRANSLATE | CC_HONOR_PARENT_TRANSFORM_ROTATE | CC_HONOR_PARENT_TRANSFORM_SCALE | CC_HONOR_PARENT_TRANSFORM_SKEW, - -} ccHonorParentTransform; -*/ -class CCSprite : public CCNodeRGBA -{ - void setDirty(bool bDirty); - bool isDirty(void) const; - - V3F_C4B_T2F_Quad getQuad(void); - - CCRect getTextureRect(void); - //bool isUsesBatchNode(void); - bool isTextureRectRotated(void); - - void setAtlasIndex(unsigned int uAtlasIndex); - unsigned int getAtlasIndex(void) const; - //void setUsesSpriteBatchNode(bool bUsesSpriteBatchNode); - void setTextureAtlas(CCTextureAtlas *pobTextureAtlas); - CCTextureAtlas* getTextureAtlas(void); - //void setSpriteBatchNode(CCSpriteBatchNode *pobSpriteBatchNode); - //CCSpriteBatchNode* getSpriteBatchNode(void); - //void setHonorParentTransform(ccHonorParentTransform eHonorParentTransform); - //ccHonorParentTransform getHonorParentTransform(void); - void setBlendFunc(const BlendFunc &blendFunc); - const BlendFunc& getBlendFunc(void); - - const CCPoint& getOffsetPosition(void) const; - - void ignoreAnchorPointForPosition(bool newValue); - void setFlipX(bool bFlipX); - void setFlipY(bool bFlipY); - bool isFlipX(void) const; - bool isFlipY(void) const; - - void removeChild(CCNode* pChild, bool bCleanUp); - void removeAllChildrenWithCleanup(bool bCleanup); - void reorderChild(CCNode* pChild, int zOrder); - void addChild(CCNode* pChild); - void addChild(CCNode* pChild, int zOrder); - void addChild(CCNode* pChild, int zOrder, int tag); - void sortAllChildren(); - //void setPosition(CCPoint pos); - void setRotation(float rotation); - void setSkewX(float sx); - void setSkewY(float sy); - void setScale(float fScale); - void setScaleX(float fScaleX); - void setScaleY(float fScaleY); - void setVertexZ(float fVertexZ); - void setAnchorPoint(const CCPoint & anchor); - void setVisible(bool bVisible); - - void setOpacity(GLubyte opacity); - - void setColor(Color3B color3); - Color3B getColor(void); - void setOpacityModifyRGB(bool bValue); - bool isOpacityModifyRGB(void) const; - - void setTexture(CCTexture2D *texture); - CCTexture2D* getTexture(void); - - void updateTransform(void); - //void useSelfRender(void); - void setTextureRect(CCRect rect); - void setTextureRect(CCRect rect, bool rotated, CCSize size); - void setVertexRect(CCRect rect); - //void useBatchNode(CCSpriteBatchNode *batchNode); - void setDisplayFrame(CCSpriteFrame *pNewFrame); - bool isFrameDisplayed(CCSpriteFrame *pFrame) const; - CCSpriteFrame* displayFrame(void); - void setBatchNode(CCSpriteBatchNode* pBatchNode); - CCSpriteBatchNode* getBatchNode(); - void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex); - - static CCSprite* createWithTexture(CCTexture2D *pTexture); - static CCSprite* createWithTexture(CCTexture2D *pTexture, CCRect rect); - static CCSprite* createWithSpriteFrame(CCSpriteFrame *pSpriteFrame); - static CCSprite* createWithSpriteFrameName(const char *pszSpriteFrameName); - static CCSprite* create(const char *pszFileName, CCRect rect); - static CCSprite* create(const char *pszFileName); - static CCSprite* create(); -}; diff --git a/tools/tolua++/CCSpriteBatchNode.pkg b/tools/tolua++/CCSpriteBatchNode.pkg deleted file mode 100644 index ecfb47e511..0000000000 --- a/tools/tolua++/CCSpriteBatchNode.pkg +++ /dev/null @@ -1,38 +0,0 @@ - -class CCSpriteBatchNode : public CCNode -{ - CCTextureAtlas* getTextureAtlas(void); - void setTextureAtlas(CCTextureAtlas* textureAtlas); - CCArray* getDescendants(void); - - void increaseAtlasCapacity(); - void removeChildAtIndex(unsigned int index, bool doCleanup); - void insertChild(CCSprite *child, unsigned int index); - void appendChild(CCSprite *child); - void removeSpriteFromAtlas(CCSprite *sprite); - - unsigned int rebuildIndexInOrder(CCSprite *parent, unsigned int index); - unsigned int highestAtlasIndexInChild(CCSprite *sprite); - unsigned int lowestAtlasIndexInChild(CCSprite *sprite); - unsigned int atlasIndexForChild(CCSprite *sprite, int z); - - void reorderBatch(bool reorder); - void setTexture(CCTexture2D *texture); - CCTexture2D* getTexture(void); - void setBlendFunc(const BlendFunc &blendFunc); - const BlendFunc& getBlendFunc(void); - - void addChild(CCNode * child); - void addChild(CCNode * child, int zOrder); - void addChild(CCNode * child, int zOrder, int tag); - void reorderChild(CCNode * child, int zOrder); - - void removeChild(CCNode* child, bool cleanup); - void removeAllChildrenWithCleanup(bool cleanup); - void sortAllChildren(); - - static CCSpriteBatchNode* createWithTexture(CCTexture2D *tex); - static CCSpriteBatchNode* createWithTexture(CCTexture2D* tex, unsigned int capacity); - static CCSpriteBatchNode* create(const char* fileImage, unsigned int capacity); - static CCSpriteBatchNode* create(const char* fileImage); -}; diff --git a/tools/tolua++/CCSpriteFrame.pkg b/tools/tolua++/CCSpriteFrame.pkg deleted file mode 100644 index d57db04172..0000000000 --- a/tools/tolua++/CCSpriteFrame.pkg +++ /dev/null @@ -1,32 +0,0 @@ - -class CCSpriteFrame : public CCObject -{ - CCRect getRectInPixels(void); - void setRectInPixels(CCRect rectInPixels); - - bool isRotated(void); - void setRotated(bool bRotated); - - CCRect getRect(void) const; - void setRect(CCRect rect); - - CCPoint getOffsetInPixels(void); - void setOffsetInPixels(CCPoint offsetInPixels); - - CCSize getOriginalSizeInPixels(void); - void setOriginalSizeInPixels(CCSize sizeInPixels); - - const CCSize & getOriginalSize(); - void setOriginalSize(const CCSize & size); - - CCTexture2D* getTexture(void); - void setTexture(CCTexture2D* pobTexture); - - const CCPoint & getOffset(); - void setOffset(const CCPoint & offsets); - - static CCSpriteFrame* create(const char* filename, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize); - static CCSpriteFrame* create(const char* filename, CCRect rect); - static CCSpriteFrame* createWithTexture(CCTexture2D* pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize); - static CCSpriteFrame* createWithTexture(CCTexture2D* pobTexture, CCRect rect); -}; diff --git a/tools/tolua++/CCSpriteFrameCache.pkg b/tools/tolua++/CCSpriteFrameCache.pkg deleted file mode 100644 index 207042b654..0000000000 --- a/tools/tolua++/CCSpriteFrameCache.pkg +++ /dev/null @@ -1,21 +0,0 @@ - -class CCSpriteFrameCache : public CCObject -{ - //void addSpriteFramesWithDictionary(CCDictionary *pobDictionary, CCTexture2D *pobTexture); - void addSpriteFramesWithFile(const char *pszPlist); - void addSpriteFramesWithFile(const char* plist, const char* textureFileName); - void addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture); - void addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName); - - void removeSpriteFrames(void); - void removeUnusedSpriteFrames(void); - void removeSpriteFrameByName(const char *pszName); - void removeSpriteFramesFromFile(const char* plist); - //void removeSpriteFramesFromDictionary(CCDictionary *dictionary); - void removeSpriteFramesFromTexture(CCTexture2D* texture); - - CCSpriteFrame* getSpriteFrameByName(const char *pszName); - - static CCSpriteFrameCache* getInstance(); - static void destroyInstance(); -}; diff --git a/tools/tolua++/CCString.pkg b/tools/tolua++/CCString.pkg deleted file mode 100644 index 1950324a13..0000000000 --- a/tools/tolua++/CCString.pkg +++ /dev/null @@ -1,19 +0,0 @@ - -class CCString : public CCObject -{ - int intValue() const; - unsigned int uintValue() const; - float floatValue() const; - double doubleValue() const; - bool boolValue() const; - const char* getCString() const; - unsigned int length() const; - - int compare(const char* str) const; - bool isEqual(const CCObject* pObject); - - static CCString* create(const char* pStr); - static CCString* createWithData(unsigned char* pData, unsigned long nLen); - static CCString* createWithContentsOfFile(const char* pszFileName); -}; - diff --git a/tools/tolua++/CCTMXLayer.pkg b/tools/tolua++/CCTMXLayer.pkg deleted file mode 100644 index b968c515fc..0000000000 --- a/tools/tolua++/CCTMXLayer.pkg +++ /dev/null @@ -1,37 +0,0 @@ - -class CCTMXLayer : public CCSpriteBatchNode -{ - void setLayerSize(CCSize val); - CCSize getLayerSize(); - - void setMapTileSize(CCSize val); - CCSize getMapTileSize(); - - void setTiles(unsigned int* pval); - unsigned int* getTiles(); - - void setTileSet(CCTMXTilesetInfo* pval); - CCTMXTilesetInfo* getTileSet(); - - void setLayerOrientation(unsigned int val); - unsigned int getLayerOrientation(); - - void setProperties(CCDictionary* pval); - CCDictionary* getProperties(); - - void releaseMap(); - - CCSprite* getTileAt(const CCPoint& tileCoordinate); - unsigned int getTileGIDAt(const CCPoint& tileCoordinate); - void setTileGID(unsigned int gid, const CCPoint& tileCoordinate); - void setTileGID(unsigned int gid, const CCPoint& tileCoordinate, ccTMXTileFlags flags); - void removeTileAt(CCPoint tileCoordinate); - CCPoint getPositionAt(CCPoint tileCoordinate); - CCString* getProperty(const char *propertyName) const; - void setupTiles(); - - void setLayerName(const char *layerName); - const char* getLayerName(); - - static CCTMXLayer * create(CCTMXTilesetInfo *tilesetInfo, CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo); -}; diff --git a/tools/tolua++/CCTMXObjectGroup.pkg b/tools/tolua++/CCTMXObjectGroup.pkg deleted file mode 100644 index f38bfd3c66..0000000000 --- a/tools/tolua++/CCTMXObjectGroup.pkg +++ /dev/null @@ -1,19 +0,0 @@ - -class CCTMXObjectGroup : public CCObject -{ - void setPositionOffset(CCPoint pt); - CCPoint getPositionOffset(); - - void setProperties(CCDictionary* pval); - CCDictionary* getProperties(); - - void setObjects(CCArray* val); - CCArray* getObjects(); - - void setGroupName(const char *groupName); - const char* getGroupName(); - - CCString* getProperty(const char* propertyName); - - CCDictionary* getObject(const char *objectName); -}; diff --git a/tools/tolua++/CCTMXTiledMap.pkg b/tools/tolua++/CCTMXTiledMap.pkg deleted file mode 100644 index 937d99ba4c..0000000000 --- a/tools/tolua++/CCTMXTiledMap.pkg +++ /dev/null @@ -1,36 +0,0 @@ - -enum -{ - /** Orthogonal orientation */ - CCTMXOrientationOrtho, - /** Hexagonal orientation */ - CCTMXOrientationHex, - /** Isometric orientation */ - CCTMXOrientationIso, -}; - -class CCTMXTiledMap : public CCNode -{ - void setMapSize(CCSize sz); - CCSize getMapSize(); - - void setTileSize(CCSize sz); - CCSize getTileSize(); - - void setMapOrientation(int val); - int getMapOrientation(); - - void setObjectGroups(CCArray* pval); - CCArray* getObjectGroups(); - - void setProperties(CCDictionary* pval); - CCDictionary* getProperties(); - - CCTMXLayer* getLayer(const char *layerName); - CCTMXObjectGroup* getObjectGroup(const char *groupName); - CCString* getProperty(const char *propertyName); - CCDictionary* getPropertiesForGID(int GID); - - static CCTMXTiledMap * create(const char *tmxFile); - static CCTMXTiledMap* createWithXML(const char* tmxString, const char* resourcePath); -}; diff --git a/tools/tolua++/CCTMXXMLParser.pkg b/tools/tolua++/CCTMXXMLParser.pkg deleted file mode 100644 index 4ddbf5b1ca..0000000000 --- a/tools/tolua++/CCTMXXMLParser.pkg +++ /dev/null @@ -1,76 +0,0 @@ - -enum { - TMXLayerAttribNone = 1 << 0, - TMXLayerAttribBase64 = 1 << 1, - TMXLayerAttribGzip = 1 << 2, - TMXLayerAttribZlib = 1 << 3, -}; - -enum { - TMXPropertyNone, - TMXPropertyMap, - TMXPropertyLayer, - TMXPropertyObjectGroup, - TMXPropertyObject, - TMXPropertyTile -}; - -typedef enum ccTMXTileFlags_ { - kCCTMXTileHorizontalFlag = 0x80000000, - kCCTMXTileVerticalFlag = 0x40000000, - kCCTMXTileDiagonalFlag = 0x20000000, - kCCFlipedAll = (kCCTMXTileHorizontalFlag|kCCTMXTileVerticalFlag|kCCTMXTileDiagonalFlag), - kCCFlippedMask = ~(kCCFlipedAll) -} ccTMXTileFlags; - -class CCTMXLayerInfo : public CCObject -{ - CCDictionary* getProperties(); - void setProperties(CCDictionary* pval); -}; - -class CCTMXTilesetInfo : public CCObject -{ - CCRect rectForGID(unsigned int gid); -}; - -class CCTMXMapInfo : public CCObject -{ - void setOrientation(int val); - int getOrientation(); - void setMapSize(CCSize sz); - CCSize getMapSize(); - void setTileSize(CCSize sz); - CCSize getTileSize(); - void setLayers(CCArray* pval); - CCArray* getLayers(); - void setTilesets(CCArray* pval); - CCArray* getTilesets(); - void setObjectGroups(CCArray* val); - CCArray* getObjectGroups(); - void setParentElement(int val); - int getParentElement(); - void setParentGID(unsigned int val); - unsigned int getParentGID(); - void setLayerAttribs(int val); - int getLayerAttribs(); - void setStoringCharacters(bool val); - bool isStoringCharacters() const; - void setProperties(CCDictionary* pval); - CCDictionary* getProperties(); - void setTileProperties(CCDictionary* tileProperties); - CCDictionary* getTileProperties(); - void setCurrentString(const char *currentString); - const char* getCurrentString(); - void setTMXFileName(const char *fileName); - const char* getTMXFileName(); - - void startElement(void *ctx, const char *name, const char **atts); - void endElement(void *ctx, const char *name); - void textHandler(void *ctx, const char *ch, int len); - bool parseXMLFile(const char *xmlFilename); - bool parseXMLString(const char *xmlString); - - static CCTMXMapInfo* create(const char *tmxFile); - static CCTMXMapInfo* createWithXML(const char* tmxString, const char* resourcePath); -}; diff --git a/tools/tolua++/CCTextFieldTTF.pkg b/tools/tolua++/CCTextFieldTTF.pkg deleted file mode 100644 index 8087596648..0000000000 --- a/tools/tolua++/CCTextFieldTTF.pkg +++ /dev/null @@ -1,18 +0,0 @@ - -class CCTextFieldTTF : public CCLabelTTF -{ - bool attachWithIME(); - bool detachWithIME(); - - int getCharCount(); - void setColorSpaceHolder(Color3B val); - Color3B getColorSpaceHolder(); - void setString(const char *text); - const char* getString(void) const; - - void setPlaceHolder(const char * text); - const char * getPlaceHolder(void); - - static CCTextFieldTTF * textFieldWithPlaceHolder(const char *placeholder, CCSize dimensions, CCTextAlignment alignment, const char *fontName, float fontSize); - static CCTextFieldTTF * textFieldWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize); -}; diff --git a/tools/tolua++/CCTexture2D.pkg b/tools/tolua++/CCTexture2D.pkg deleted file mode 100644 index e7ea419776..0000000000 --- a/tools/tolua++/CCTexture2D.pkg +++ /dev/null @@ -1,505 +0,0 @@ -/* ClearBufferMask */ -#define GL_DEPTH_BUFFER_BIT 0x00000100 -#define GL_STENCIL_BUFFER_BIT 0x00000400 -#define GL_COLOR_BUFFER_BIT 0x00004000 - -/* Boolean */ -#define GL_FALSE 0 -#define GL_TRUE 1 - -/* BeginMode */ -#define GL_POINTS 0x0000 -#define GL_LINES 0x0001 -#define GL_LINE_LOOP 0x0002 -#define GL_LINE_STRIP 0x0003 -#define GL_TRIANGLES 0x0004 -#define GL_TRIANGLE_STRIP 0x0005 -#define GL_TRIANGLE_FAN 0x0006 - -/* AlphaFunction (not supported in ES20) */ -/* GL_NEVER */ -/* GL_LESS */ -/* GL_EQUAL */ -/* GL_LEQUAL */ -/* GL_GREATER */ -/* GL_NOTEQUAL */ -/* GL_GEQUAL */ -/* GL_ALWAYS */ - -/* BlendingFactorDest */ -#define GL_ZERO 0 -#define GL_ONE 1 -#define GL_SRC_COLOR 0x0300 -#define GL_ONE_MINUS_SRC_COLOR 0x0301 -#define GL_SRC_ALPHA 0x0302 -#define GL_ONE_MINUS_SRC_ALPHA 0x0303 -#define GL_DST_ALPHA 0x0304 -#define GL_ONE_MINUS_DST_ALPHA 0x0305 - -/* BlendingFactorSrc */ -/* GL_ZERO */ -/* GL_ONE */ -#define GL_DST_COLOR 0x0306 -#define GL_ONE_MINUS_DST_COLOR 0x0307 -#define GL_SRC_ALPHA_SATURATE 0x0308 -/* GL_SRC_ALPHA */ -/* GL_ONE_MINUS_SRC_ALPHA */ -/* GL_DST_ALPHA */ -/* GL_ONE_MINUS_DST_ALPHA */ - -/* BlendEquationSeparate */ -#define GL_FUNC_ADD 0x8006 -#define GL_BLEND_EQUATION 0x8009 -#define GL_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */ -#define GL_BLEND_EQUATION_ALPHA 0x883D - -/* BlendSubtract */ -#define GL_FUNC_SUBTRACT 0x800A -#define GL_FUNC_REVERSE_SUBTRACT 0x800B - -/* Separate Blend Functions */ -#define GL_BLEND_DST_RGB 0x80C8 -#define GL_BLEND_SRC_RGB 0x80C9 -#define GL_BLEND_DST_ALPHA 0x80CA -#define GL_BLEND_SRC_ALPHA 0x80CB -#define GL_CONSTANT_COLOR 0x8001 -#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 -#define GL_CONSTANT_ALPHA 0x8003 -#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 -#define GL_BLEND_COLOR 0x8005 - -/* Buffer Objects */ -#define GL_ARRAY_BUFFER 0x8892 -#define GL_ELEMENT_ARRAY_BUFFER 0x8893 -#define GL_ARRAY_BUFFER_BINDING 0x8894 -#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 - -#define GL_STREAM_DRAW 0x88E0 -#define GL_STATIC_DRAW 0x88E4 -#define GL_DYNAMIC_DRAW 0x88E8 - -#define GL_BUFFER_SIZE 0x8764 -#define GL_BUFFER_USAGE 0x8765 - -#define GL_CURRENT_VERTEX_ATTRIB 0x8626 - -/* CullFaceMode */ -#define GL_FRONT 0x0404 -#define GL_BACK 0x0405 -#define GL_FRONT_AND_BACK 0x0408 - -/* DepthFunction */ -/* GL_NEVER */ -/* GL_LESS */ -/* GL_EQUAL */ -/* GL_LEQUAL */ -/* GL_GREATER */ -/* GL_NOTEQUAL */ -/* GL_GEQUAL */ -/* GL_ALWAYS */ - -/* EnableCap */ -#define GL_TEXTURE_2D 0x0DE1 -#define GL_CULL_FACE 0x0B44 -#define GL_BLEND 0x0BE2 -#define GL_DITHER 0x0BD0 -#define GL_STENCIL_TEST 0x0B90 -#define GL_DEPTH_TEST 0x0B71 -#define GL_SCISSOR_TEST 0x0C11 -#define GL_POLYGON_OFFSET_FILL 0x8037 -#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E -#define GL_SAMPLE_COVERAGE 0x80A0 - -/* ErrorCode */ -#define GL_NO_ERROR 0 -#define GL_INVALID_ENUM 0x0500 -#define GL_INVALID_VALUE 0x0501 -#define GL_INVALID_OPERATION 0x0502 -#define GL_OUT_OF_MEMORY 0x0505 - -/* FrontFaceDirection */ -#define GL_CW 0x0900 -#define GL_CCW 0x0901 - -/* GetPName */ -#define GL_LINE_WIDTH 0x0B21 -#define GL_ALIASED_POINT_SIZE_RANGE 0x846D -#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E -#define GL_CULL_FACE_MODE 0x0B45 -#define GL_FRONT_FACE 0x0B46 -#define GL_DEPTH_RANGE 0x0B70 -#define GL_DEPTH_WRITEMASK 0x0B72 -#define GL_DEPTH_CLEAR_VALUE 0x0B73 -#define GL_DEPTH_FUNC 0x0B74 -#define GL_STENCIL_CLEAR_VALUE 0x0B91 -#define GL_STENCIL_FUNC 0x0B92 -#define GL_STENCIL_FAIL 0x0B94 -#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 -#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 -#define GL_STENCIL_REF 0x0B97 -#define GL_STENCIL_VALUE_MASK 0x0B93 -#define GL_STENCIL_WRITEMASK 0x0B98 -#define GL_STENCIL_BACK_FUNC 0x8800 -#define GL_STENCIL_BACK_FAIL 0x8801 -#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 -#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 -#define GL_STENCIL_BACK_REF 0x8CA3 -#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 -#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 -#define GL_VIEWPORT 0x0BA2 -#define GL_SCISSOR_BOX 0x0C10 -/* GL_SCISSOR_TEST */ -#define GL_COLOR_CLEAR_VALUE 0x0C22 -#define GL_COLOR_WRITEMASK 0x0C23 -#define GL_UNPACK_ALIGNMENT 0x0CF5 -#define GL_PACK_ALIGNMENT 0x0D05 -#define GL_MAX_TEXTURE_SIZE 0x0D33 -#define GL_MAX_VIEWPORT_DIMS 0x0D3A -#define GL_SUBPIXEL_BITS 0x0D50 -#define GL_RED_BITS 0x0D52 -#define GL_GREEN_BITS 0x0D53 -#define GL_BLUE_BITS 0x0D54 -#define GL_ALPHA_BITS 0x0D55 -#define GL_DEPTH_BITS 0x0D56 -#define GL_STENCIL_BITS 0x0D57 -#define GL_POLYGON_OFFSET_UNITS 0x2A00 -/* GL_POLYGON_OFFSET_FILL */ -#define GL_POLYGON_OFFSET_FACTOR 0x8038 -#define GL_TEXTURE_BINDING_2D 0x8069 -#define GL_SAMPLE_BUFFERS 0x80A8 -#define GL_SAMPLES 0x80A9 -#define GL_SAMPLE_COVERAGE_VALUE 0x80AA -#define GL_SAMPLE_COVERAGE_INVERT 0x80AB - -/* GetTextureParameter */ -/* GL_TEXTURE_MAG_FILTER */ -/* GL_TEXTURE_MIN_FILTER */ -/* GL_TEXTURE_WRAP_S */ -/* GL_TEXTURE_WRAP_T */ - -#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 -#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 - -/* HintMode */ -#define GL_DONT_CARE 0x1100 -#define GL_FASTEST 0x1101 -#define GL_NICEST 0x1102 - -/* HintTarget */ -#define GL_GENERATE_MIPMAP_HINT 0x8192 - -/* DataType */ -#define GL_BYTE 0x1400 -#define GL_UNSIGNED_BYTE 0x1401 -#define GL_SHORT 0x1402 -#define GL_UNSIGNED_SHORT 0x1403 -#define GL_INT 0x1404 -#define GL_UNSIGNED_INT 0x1405 -#define GL_FLOAT 0x1406 -// #define GL_FIXED 0x140C - -/* PixelFormat */ -#define GL_DEPTH_COMPONENT 0x1902 -#define GL_ALPHA 0x1906 -#define GL_RGB 0x1907 -#define GL_RGBA 0x1908 -#define GL_LUMINANCE 0x1909 -#define GL_LUMINANCE_ALPHA 0x190A - -/* PixelType */ -/* GL_UNSIGNED_BYTE */ -#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 -#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 -#define GL_UNSIGNED_SHORT_5_6_5 0x8363 - -/* Shaders */ -#define GL_FRAGMENT_SHADER 0x8B30 -#define GL_VERTEX_SHADER 0x8B31 -#define GL_MAX_VERTEX_ATTRIBS 0x8869 -// #define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB -// #define GL_MAX_VARYING_VECTORS 0x8DFC -#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D -#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C -#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 -// #define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD -#define GL_SHADER_TYPE 0x8B4F -#define GL_DELETE_STATUS 0x8B80 -#define GL_LINK_STATUS 0x8B82 -#define GL_VALIDATE_STATUS 0x8B83 -#define GL_ATTACHED_SHADERS 0x8B85 -#define GL_ACTIVE_UNIFORMS 0x8B86 -#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 -#define GL_ACTIVE_ATTRIBUTES 0x8B89 -#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A -#define GL_SHADING_LANGUAGE_VERSION 0x8B8C -#define GL_CURRENT_PROGRAM 0x8B8D - -/* StencilFunction */ -#define GL_NEVER 0x0200 -#define GL_LESS 0x0201 -#define GL_EQUAL 0x0202 -#define GL_LEQUAL 0x0203 -#define GL_GREATER 0x0204 -#define GL_NOTEQUAL 0x0205 -#define GL_GEQUAL 0x0206 -#define GL_ALWAYS 0x0207 - -/* StencilOp */ -/* GL_ZERO */ -#define GL_KEEP 0x1E00 -#define GL_REPLACE 0x1E01 -#define GL_INCR 0x1E02 -#define GL_DECR 0x1E03 -#define GL_INVERT 0x150A -#define GL_INCR_WRAP 0x8507 -#define GL_DECR_WRAP 0x8508 - -/* StringName */ -#define GL_VENDOR 0x1F00 -#define GL_RENDERER 0x1F01 -#define GL_VERSION 0x1F02 -#define GL_EXTENSIONS 0x1F03 - -/* TextureMagFilter */ -#define GL_NEAREST 0x2600 -#define GL_LINEAR 0x2601 - -/* TextureMinFilter */ -/* GL_NEAREST */ -/* GL_LINEAR */ -#define GL_NEAREST_MIPMAP_NEAREST 0x2700 -#define GL_LINEAR_MIPMAP_NEAREST 0x2701 -#define GL_NEAREST_MIPMAP_LINEAR 0x2702 -#define GL_LINEAR_MIPMAP_LINEAR 0x2703 - -/* TextureParameterName */ -#define GL_TEXTURE_MAG_FILTER 0x2800 -#define GL_TEXTURE_MIN_FILTER 0x2801 -#define GL_TEXTURE_WRAP_S 0x2802 -#define GL_TEXTURE_WRAP_T 0x2803 - -/* TextureTarget */ -/* GL_TEXTURE_2D */ -#define GL_TEXTURE 0x1702 - -#define GL_TEXTURE_CUBE_MAP 0x8513 -#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A -#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C - -/* TextureUnit */ -#define GL_TEXTURE0 0x84C0 -#define GL_TEXTURE1 0x84C1 -#define GL_TEXTURE2 0x84C2 -#define GL_TEXTURE3 0x84C3 -#define GL_TEXTURE4 0x84C4 -#define GL_TEXTURE5 0x84C5 -#define GL_TEXTURE6 0x84C6 -#define GL_TEXTURE7 0x84C7 -#define GL_TEXTURE8 0x84C8 -#define GL_TEXTURE9 0x84C9 -#define GL_TEXTURE10 0x84CA -#define GL_TEXTURE11 0x84CB -#define GL_TEXTURE12 0x84CC -#define GL_TEXTURE13 0x84CD -#define GL_TEXTURE14 0x84CE -#define GL_TEXTURE15 0x84CF -#define GL_TEXTURE16 0x84D0 -#define GL_TEXTURE17 0x84D1 -#define GL_TEXTURE18 0x84D2 -#define GL_TEXTURE19 0x84D3 -#define GL_TEXTURE20 0x84D4 -#define GL_TEXTURE21 0x84D5 -#define GL_TEXTURE22 0x84D6 -#define GL_TEXTURE23 0x84D7 -#define GL_TEXTURE24 0x84D8 -#define GL_TEXTURE25 0x84D9 -#define GL_TEXTURE26 0x84DA -#define GL_TEXTURE27 0x84DB -#define GL_TEXTURE28 0x84DC -#define GL_TEXTURE29 0x84DD -#define GL_TEXTURE30 0x84DE -#define GL_TEXTURE31 0x84DF -#define GL_ACTIVE_TEXTURE 0x84E0 - -/* TextureWrapMode */ -#define GL_REPEAT 0x2901 -#define GL_CLAMP_TO_EDGE 0x812F -#define GL_MIRRORED_REPEAT 0x8370 - -/* Uniform Types */ -#define GL_FLOAT_VEC2 0x8B50 -#define GL_FLOAT_VEC3 0x8B51 -#define GL_FLOAT_VEC4 0x8B52 -#define GL_INT_VEC2 0x8B53 -#define GL_INT_VEC3 0x8B54 -#define GL_INT_VEC4 0x8B55 -#define GL_BOOL 0x8B56 -#define GL_BOOL_VEC2 0x8B57 -#define GL_BOOL_VEC3 0x8B58 -#define GL_BOOL_VEC4 0x8B59 -#define GL_FLOAT_MAT2 0x8B5A -#define GL_FLOAT_MAT3 0x8B5B -#define GL_FLOAT_MAT4 0x8B5C -#define GL_SAMPLER_2D 0x8B5E -#define GL_SAMPLER_CUBE 0x8B60 - -/* Vertex Arrays */ -#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 -#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 -#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 -#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 -#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A -#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 -#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F - -/* Read Format */ -// #define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A -// #define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B - -/* Shader Source */ -#define GL_COMPILE_STATUS 0x8B81 -#define GL_INFO_LOG_LENGTH 0x8B84 -#define GL_SHADER_SOURCE_LENGTH 0x8B88 -// #define GL_SHADER_COMPILER 0x8DFA - -/* Shader Binary */ -// #define GL_SHADER_BINARY_FORMATS 0x8DF8 -// #define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 - -/* Shader Precision-Specified Types */ -// #define GL_LOW_FLOAT 0x8DF0 -// #define GL_MEDIUM_FLOAT 0x8DF1 -// #define GL_HIGH_FLOAT 0x8DF2 -// #define GL_LOW_INT 0x8DF3 -// #define GL_MEDIUM_INT 0x8DF4 -// #define GL_HIGH_INT 0x8DF5 - -/* Framebuffer Object. */ -#define GL_FRAMEBUFFER 0x8D40 -#define GL_RENDERBUFFER 0x8D41 - -#define GL_RGBA4 0x8056 -#define GL_RGB5_A1 0x8057 -//comment nextline since it wasn't defined in glew.h of windows -// #define GL_RGB565 0x8D62 -#define GL_DEPTH_COMPONENT16 0x81A5 -//comment nextline since it wasn't defined in gl.h of IOS7 sdk -//#define GL_STENCIL_INDEX 0x1901 -#define GL_STENCIL_INDEX8 0x8D48 - -#define GL_RENDERBUFFER_WIDTH 0x8D42 -#define GL_RENDERBUFFER_HEIGHT 0x8D43 -#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 -#define GL_RENDERBUFFER_RED_SIZE 0x8D50 -#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 -#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 -#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 -#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 -#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 - -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 - -#define GL_COLOR_ATTACHMENT0 0x8CE0 -#define GL_DEPTH_ATTACHMENT 0x8D00 -#define GL_STENCIL_ATTACHMENT 0x8D20 - -#define GL_NONE 0 - -#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 -//#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 -#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD - -#define GL_FRAMEBUFFER_BINDING 0x8CA6 -#define GL_RENDERBUFFER_BINDING 0x8CA7 -#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 - -#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 - - -typedef enum { -// kCCTexture2DPixelFormat_Automatic = 0, - //! 32-bit texture: RGBA8888 - kCCTexture2DPixelFormat_RGBA8888, - //! 24-bit texture: RGBA888 - kCCTexture2DPixelFormat_RGB888, - //! 16-bit texture without Alpha channel - kCCTexture2DPixelFormat_RGB565, - //! 8-bit textures used as masks - kCCTexture2DPixelFormat_A8, - //! 8-bit intensity texture - kCCTexture2DPixelFormat_I8, - //! 16-bit textures used as masks - kCCTexture2DPixelFormat_AI88, - //! 16-bit textures: RGBA4444 - kCCTexture2DPixelFormat_RGBA4444, - //! 16-bit textures: RGB5A1 - kCCTexture2DPixelFormat_RGB5A1, - //! 4-bit PVRTC-compressed texture: PVRTC4 - kCCTexture2DPixelFormat_PVRTC4, - //! 2-bit PVRTC-compressed texture: PVRTC2 - kCCTexture2DPixelFormat_PVRTC2, - - //! Default texture format: RGBA8888 - kCCTexture2DPixelFormat_Default = kCCTexture2DPixelFormat_RGBA8888, -} CCTexture2DPixelFormat; - - -class CCTexture2D : public CCObject -{ - -class TexParams { - TexParams(void); - GLuint minFilter; - GLuint magFilter; - GLuint wrapS; - GLuint wrapT; -}; - void releaseData(void* data); - void* keepData(void* data, unsigned int length); - - CCTexture2DPixelFormat getPixelFormat(); - - unsigned int getPixelsWide(); - unsigned int getPixelsHigh(); - - GLuint getName(); - - CCSize getContentSizeInPixels(); - - void setMaxS(GLfloat val); - GLfloat getMaxS(); - - GLfloat getMaxT(); - void setMaxT(GLfloat val); - - bool hasPremultipliedAlpha() const; - bool hasMipmaps() const; - - void drawAtPoint(CCPoint point); - void drawInRect(CCRect rect); - - CCSize getContentSize(void); - - void setTexParameters(const TexParams& texParams); - void setAntiAliasTexParameters(); - void setAliasTexParameters(); - void generateMipmap(); - - const char* getStringForFormat() const; - unsigned int getBitsPerPixelForFormat() const; - unsigned int getBitsPerPixelForFormat(CCTexture2DPixelFormat format) const; - - static void setDefaultAlphaPixelFormat(CCTexture2DPixelFormat format); - static CCTexture2DPixelFormat getDefaultAlphaPixelFormat(); -}; diff --git a/tools/tolua++/CCTextureAtlas.pkg b/tools/tolua++/CCTextureAtlas.pkg deleted file mode 100644 index 4d550ab5c0..0000000000 --- a/tools/tolua++/CCTextureAtlas.pkg +++ /dev/null @@ -1,30 +0,0 @@ - -class CCTextureAtlas : public CCObject -{ - unsigned int getTotalQuads(); - unsigned int getCapacity(); - - void setTexture(CCTexture2D* val); - CCTexture2D* getTexture(); - - void setQuads(V3F_C4B_T2F_Quad* val); - V3F_C4B_T2F_Quad* getQuads(); - - void updateQuad(V3F_C4B_T2F_Quad* quad, unsigned int index); - void insertQuad(V3F_C4B_T2F_Quad* quad, unsigned int index); - void insertQuadFromIndex(unsigned int fromIndex, unsigned int newIndex); - void removeQuadAtIndex(unsigned int index); - void removeAllQuads(); - bool resizeCapacity(unsigned int n); - void drawNumberOfQuads(unsigned int n); - void drawNumberOfQuads(unsigned int n, unsigned int start); - - void increaseTotalQuadsWith(unsigned int amount); - void moveQuadsFromIndex(unsigned int oldIndex, unsigned int amount, unsigned int newIndex); - void moveQuadsFromIndex(unsigned int index, unsigned int newIndex); - void fillWithEmptyQuadsFromIndex(unsigned int index, unsigned int amount); - void drawQuads(); - - static CCTextureAtlas* create(const char* file , unsigned int capacity); - static CCTextureAtlas* createWithTexture(CCTexture2D *texture, unsigned int capacity); -}; diff --git a/tools/tolua++/CCTextureCache.pkg b/tools/tolua++/CCTextureCache.pkg deleted file mode 100644 index b0dfa15d3d..0000000000 --- a/tools/tolua++/CCTextureCache.pkg +++ /dev/null @@ -1,18 +0,0 @@ - -class CCTextureCache : public CCObject -{ - CCTexture2D* addImage(const char* fileimage); - CCTexture2D* addUIImage(CCImage *image, const char *key); - CCTexture2D* textureForKey(const char* key); - - void removeAllTextures(); - void removeUnusedTextures(); - void removeTexture(CCTexture2D* texture); - void removeTextureForKey(const char *textureKeyName); - void dumpCachedTextureInfo(); - - static void reloadAllTextures(); - - static CCTextureCache * getInstance(); - static void destroyInstance(); -}; diff --git a/tools/tolua++/CCTileMapAtlas.pkg b/tools/tolua++/CCTileMapAtlas.pkg deleted file mode 100644 index 2e913f2aa4..0000000000 --- a/tools/tolua++/CCTileMapAtlas.pkg +++ /dev/null @@ -1,16 +0,0 @@ - - -// struct sImageTGA; - -class CCTileMapAtlas : public CCAtlasNode -{ - // struct sImageTGA* getTGAInfo(); - // void setTGAInfo(struct sImageTGA* val); - - void setTile(Color3B tile, CCPoint position); - void releaseMap(); - - Color3B getTileAt(const CCPoint & pos) const; - - static CCTileMapAtlas * create(const char *tile, const char *mapFile, int tileWidth, int tileHeight); -}; diff --git a/tools/tolua++/CCTouch.pkg b/tools/tolua++/CCTouch.pkg deleted file mode 100644 index a12fa53ea3..0000000000 --- a/tools/tolua++/CCTouch.pkg +++ /dev/null @@ -1,16 +0,0 @@ - -class CCTouch : public CCObject -{ - CCPoint getLocation() const; - CCPoint getPreviousLocation() const; - CCPoint getDelta() const; - CCPoint getLocationInView() const; - CCPoint getPreviousLocationInView() const; - - void setTouchInfo(int id, float x, float y); - int getID(); -}; - -class CCEvent : public CCObject -{ -}; diff --git a/tools/tolua++/CCTouchDispatcher.pkg b/tools/tolua++/CCTouchDispatcher.pkg deleted file mode 100644 index 8ef8227d07..0000000000 --- a/tools/tolua++/CCTouchDispatcher.pkg +++ /dev/null @@ -1,6 +0,0 @@ - -class CCTouchDispatcher : public CCObject -{ - bool isDispatchEvents(void); - void setDispatchEvents(bool bDispatchEvents); -}; diff --git a/tools/tolua++/CCTransition.pkg b/tools/tolua++/CCTransition.pkg deleted file mode 100644 index dcfb56e39e..0000000000 --- a/tools/tolua++/CCTransition.pkg +++ /dev/null @@ -1,168 +0,0 @@ - -typedef enum { - /// An horizontal orientation where the Left is nearer - kCCTransitionOrientationLeftOver = 0, - /// An horizontal orientation where the Right is nearer - kCCTransitionOrientationRightOver = 1, - /// A vertical orientation where the Up is nearer - kCCTransitionOrientationUpOver = 0, - /// A vertical orientation where the Bottom is nearer - kCCTransitionOrientationDownOver = 1, -} tOrientation; - -class CCTransitionScene : public CCScene -{ - static CCTransitionScene* create(float t, CCScene* scene); -}; - -class CCTransitionSceneOriented : public CCScene -{ - static CCTransitionSceneOriented* create(float t, CCScene* scene, tOrientation o); -}; - -class CCTransitionRotoZoom : public CCScene -{ - static CCTransitionRotoZoom* create(float t, CCScene* scene); -}; - -class CCTransitionJumpZoom : public CCScene -{ - static CCTransitionJumpZoom* create(float t, CCScene* scene); -}; - -class CCTransitionMoveInL : public CCScene -{ - static CCTransitionMoveInL* create(float t, CCScene* scene); -}; - -class CCTransitionMoveInR : public CCScene -{ - static CCTransitionMoveInR* create(float t, CCScene* scene); -}; - -class CCTransitionMoveInT : public CCScene -{ - static CCTransitionMoveInT* create(float t, CCScene* scene); -}; - -class CCTransitionMoveInB : public CCScene -{ - static CCTransitionMoveInB* create(float t, CCScene* scene); -}; - -class CCTransitionSlideInL : public CCScene -{ - static CCTransitionSlideInL* create(float t, CCScene* scene); -}; - -class CCTransitionSlideInR : public CCScene -{ - static CCTransitionSlideInR* create(float t, CCScene* scene); -}; - -class CCTransitionSlideInB : public CCScene -{ - static CCTransitionSlideInB* create(float t, CCScene* scene); -}; - -class CCTransitionSlideInT : public CCScene -{ - static CCTransitionSlideInT* create(float t, CCScene* scene); -}; - -class CCTransitionShrinkGrow : public CCScene -{ - static CCTransitionShrinkGrow* create(float t, CCScene* scene); -}; - -class CCTransitionFlipX : public CCScene -{ - static CCTransitionFlipX* create(float t, CCScene* s, tOrientation o = kCCTransitionOrientationRightOver); -}; - -class CCTransitionFlipY : public CCScene -{ - static CCTransitionFlipY* create(float t, CCScene* s, tOrientation o = kCCTransitionOrientationUpOver); -}; - -class CCTransitionFlipAngular : public CCScene -{ - static CCTransitionFlipAngular* create(float t, CCScene* s, tOrientation o = kCCTransitionOrientationRightOver); -}; - -class CCTransitionZoomFlipX : public CCScene -{ - static CCTransitionZoomFlipX* create(float t, CCScene* s, tOrientation o = kCCTransitionOrientationRightOver); -}; - -class CCTransitionZoomFlipY : public CCScene -{ - static CCTransitionZoomFlipY* create(float t, CCScene* s, tOrientation o = kCCTransitionOrientationUpOver); -}; - -class CCTransitionZoomFlipAngular : public CCScene -{ - static CCTransitionZoomFlipAngular* create(float t, CCScene* s, tOrientation o = kCCTransitionOrientationRightOver); -}; - -class CCTransitionFade : public CCScene -{ - static CCTransitionFade* create(float duration,CCScene* scene, Color3B color = ccBLACK); -}; - -class CCTransitionCrossFade : public CCScene -{ - static CCTransitionCrossFade* create(float t, CCScene* scene); -}; - -class CCTransitionTurnOffTiles : public CCScene -{ - static CCTransitionTurnOffTiles* create(float t, CCScene* scene); -}; - -class CCTransitionSplitCols : public CCScene -{ - static CCTransitionSplitCols* create(float t, CCScene* scene); -}; - -class CCTransitionSplitRows : public CCScene -{ - static CCTransitionSplitRows* create(float t, CCScene* scene); -}; - -class CCTransitionFadeTR : public CCScene -{ - static CCTransitionFadeTR* create(float t, CCScene* scene); -}; - -class CCTransitionFadeBL : public CCScene -{ - static CCTransitionFadeBL* create(float t, CCScene* scene); -}; - -class CCTransitionFadeUp : public CCScene -{ - static CCTransitionFadeUp* create(float t, CCScene* scene); -}; - -class CCTransitionFadeDown : public CCScene -{ - static CCTransitionFadeDown* create(float t, CCScene* scene); -}; - -class CCTransitionProgressRadialCCW : public CCScene -{ - static CCTransitionProgressRadialCCW* create(float t, CCScene* scene); -}; - -class CCTransitionProgressRadialCW : public CCScene -{ - static CCTransitionProgressRadialCW* create(float t, CCScene* scene); -}; - -class CCTransitionPageTurn : public CCScene -{ - CCActionInterval* actionWithSize(CCSize vector); - - static CCTransitionPageTurn* create(float t,CCScene* scene,bool backwards); -}; diff --git a/tools/tolua++/CCTransitionProgress.pkg b/tools/tolua++/CCTransitionProgress.pkg deleted file mode 100644 index d7a4f5cc89..0000000000 --- a/tools/tolua++/CCTransitionProgress.pkg +++ /dev/null @@ -1,35 +0,0 @@ -class CCTransitionProgress : public CCTransitionScene -{ - static CCTransitionProgress* create(float t, CCScene* scene); -}; - -class CCTransitionProgressRadialCCW : public CCTransitionProgress -{ - static CCTransitionProgressRadialCCW* create(float t, CCScene* scene); -}; - -class CCTransitionProgressRadialCW : public CCTransitionProgress -{ - static CCTransitionProgressRadialCW* create(float t, CCScene* scene); -}; - -class CCTransitionProgressHorizontal : public CCTransitionProgress -{ - static CCTransitionProgressHorizontal* create(float t, CCScene* scene); -}; - -class CCTransitionProgressVertical : public CCTransitionProgress -{ - static CCTransitionProgressVertical* create(float t, CCScene* scene); -}; - -class CCTransitionProgressInOut : public CCTransitionProgress -{ - static CCTransitionProgressInOut* create(float t, CCScene* scene); -}; - -class CCTransitionProgressOutIn : public CCTransitionProgress -{ - static CCTransitionProgressOutIn* create(float t, CCScene* scene); -}; - diff --git a/tools/tolua++/CCUserDefault.pkg b/tools/tolua++/CCUserDefault.pkg deleted file mode 100644 index 57d9cdb9be..0000000000 --- a/tools/tolua++/CCUserDefault.pkg +++ /dev/null @@ -1,24 +0,0 @@ - -class CCUserDefault -{ - // get value methods - bool getBoolForKey(const char* pKey); - int getIntegerForKey(const char* pKey); - float getFloatForKey(const char* pKey); - double getDoubleForKey(const char* pKey); - std::string getStringForKey(const char* pKey); - - // set value methods - void setBoolForKey(const char* pKey, bool value); - void setIntegerForKey(const char* pKey, int value); - void setFloatForKey(const char* pKey, float value); - void setDoubleForKey(const char* pKey, double value); - void setStringForKey(const char* pKey, std::string value); - - void flush(); - - static CCUserDefault* getInstance(); - static void destroyInstance(); - - const static std::string& getXMLFilePath(); -}; diff --git a/tools/tolua++/Cocos2d.pkg b/tools/tolua++/Cocos2d.pkg deleted file mode 100644 index d0ff69ca65..0000000000 --- a/tools/tolua++/Cocos2d.pkg +++ /dev/null @@ -1,88 +0,0 @@ -$#include "LuaCocos2d.h" - -$pfile "matrix.pkg" -$pfile "ccTypes.pkg" -$pfile "CCObject.pkg" -$pfile "CCCommon.pkg" -$pfile "CCGeometry.pkg" -$pfile "CCArray.pkg" -$pfile "CCDictionary.pkg" -$pfile "CCString.pkg" -$pfile "CCPointExtension.pkg" -$pfile "CCEGLViewProtocol.pkg" - -$pfile "CCProtocols.pkg" -$pfile "CCFileUtils.pkg" -$pfile "CCAffineTransform.pkg" -$pfile "CCApplication.pkg" -$pfile "CCTouchDispatcher.pkg" -$pfile "CCDirector.pkg" -$pfile "CCUserDefault.pkg" -$pfile "CCNotificationCenter.pkg" -$pfile "CCKeypadDispatcher.pkg" - -$pfile "CCImage.pkg" -$pfile "CCNode.pkg" -$pfile "CCTexture2D.pkg" -$pfile "CCTextureAtlas.pkg" -$pfile "CCTextureCache.pkg" -$pfile "CCRenderTexture.pkg" -$pfile "CCSprite.pkg" -$pfile "CCSpriteBatchNode.pkg" -$pfile "CCSpriteFrame.pkg" -$pfile "CCSpriteFrameCache.pkg" -$pfile "CCLayer.pkg" -$pfile "CCScene.pkg" -$pfile "CCTransition.pkg" -$pfile "CCTransitionProgress.pkg" - -$pfile "CCScheduler.pkg" - -$pfile "CCAction.pkg" -$pfile "CCActionCamera.pkg" -$pfile "CCActionCatmullRom.pkg" -$pfile "CCActionEase.pkg" -$pfile "CCActionGrid.pkg" -$pfile "CCActionGrid3D.pkg" -$pfile "CCActionPageTurn3D.pkg" -$pfile "CCActionProgressTimer.pkg" -$pfile "CCActionTiledGrid.pkg" -$pfile "CCActionManager.pkg" -$pfile "CCMotionStreak.pkg" - -$pfile "CCAnimation.pkg" -$pfile "CCAnimationCache.pkg" -$pfile "CCAtlasNode.pkg" -$pfile "CCCamera.pkg" -$pfile "CCLabelAtlas.pkg" -$pfile "CCLabelBMFont.pkg" -$pfile "CCLabelTTF.pkg" -$pfile "CCMenu.pkg" -$pfile "CCMenuItem.pkg" -$pfile "CCParallaxNode.pkg" -$pfile "CCParticleSystem.pkg" -$pfile "CCParticleExamples.pkg" -$pfile "CCParticleBatchNode.pkg" -$pfile "CCProgressTimer.pkg" -$pfile "CCTextFieldTTF.pkg" -$pfile "CCTileMapAtlas.pkg" -$pfile "CCTMXLayer.pkg" -$pfile "CCTMXObjectGroup.pkg" -$pfile "CCTMXTiledMap.pkg" -$pfile "CCTMXXMLParser.pkg" -$pfile "CCTouch.pkg" - -$pfile "CCSet.pkg" - -$pfile "SimpleAudioEngine.pkg" -$pfile "CCScale9Sprite.pkg" -$pfile "CCControl.pkg" -$pfile "CCControlButton.pkg" -$pfile "CCControlSlider.pkg" -$pfile "CCControlColourPicker.pkg" -$pfile "CCControlSwitch.pkg" -$pfile "CCControlPotentiometer.pkg" -$pfile "CCControlStepper.pkg" -$pfile "CCEditBox.pkg" -$pfile "CCInteger.pkg" -$pfile "CCDrawNode.pkg" diff --git a/tools/tolua++/Makefile b/tools/tolua++/Makefile deleted file mode 100644 index 55bfb2a403..0000000000 --- a/tools/tolua++/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -../../scripting/lua/cocos2dx_support/LuaCocos2d.cpp: basic.lua *.pkg - ./build.sh diff --git a/tools/tolua++/README b/tools/tolua++/README deleted file mode 100644 index 9c718ec267..0000000000 --- a/tools/tolua++/README +++ /dev/null @@ -1,23 +0,0 @@ -1. Generating the lua<-->C bindings with tolua++ - - Build scripts for windows (build.bat) and unix (build.sh) are provided - to generate the relevant files after modifying the .pkg files. These - scripts basically run the following command: - - tolua++.exe -L basic.lua -o LuaCocos2d.cpp Cocos2d.pkg - - This will generate the bindings file and patch it with come cocos2dx - specific modifications. - - On POSIX systems you can also just run "make" to build the bindings - if/when you change .pkg files. - -2. Writing .pkg files - - 1) enum keeps the same - 2) remove CC_DLL for the class defines, pay attention to multi inherites - 3) remove inline keyword for declaration and implementation - 4) remove public protect and private - 5) remove the decalration of class member variable - 6) keep static keyword - 7) remove memeber functions that declared as private or protected diff --git a/tools/tolua++/SimpleAudioEngine.pkg b/tools/tolua++/SimpleAudioEngine.pkg deleted file mode 100644 index b49e83ab5c..0000000000 --- a/tools/tolua++/SimpleAudioEngine.pkg +++ /dev/null @@ -1,25 +0,0 @@ -class SimpleAudioEngine -{ - static SimpleAudioEngine* getInstance(); - void preloadBackgroundMusic(const char* pszFilePath); - void playBackgroundMusic(const char* pszFilePath, bool bLoop = false); - void stopBackgroundMusic(bool bReleaseData = false); - void pauseBackgroundMusic(); - void resumeBackgroundMusic(); - void rewindBackgroundMusic(); - bool willPlayBackgroundMusic(); - bool isBackgroundMusicPlaying(); - float getBackgroundMusicVolume(); - void setBackgroundMusicVolume(float volume); - float getEffectsVolume(); - void setEffectsVolume(float volume); - unsigned int playEffect(const char* pszFilePath, bool bLoop = false); - void stopEffect(unsigned int nSoundId); - void preloadEffect(const char* pszFilePath); - void unloadEffect(const char* pszFilePath); - void pauseEffect(unsigned int nSoundId); - void resumeEffect(unsigned int nSoundId); - void pauseAllEffects(); - void resumeAllEffects(); - void stopAllEffects(); -}; diff --git a/tools/tolua++/basic.lua b/tools/tolua++/basic.lua deleted file mode 100644 index 110591b59c..0000000000 --- a/tools/tolua++/basic.lua +++ /dev/null @@ -1,359 +0,0 @@ --- usage: (use instead of ant) --- tolua++ "-L" "basic.lua" "-o" "../../scripting/lua/cocos2dx_support/LuaCocos2d.cpp" "Cocos2d.pkg" - -_is_functions = _is_functions or {} -_to_functions = _to_functions or {} -_push_functions = _push_functions or {} - -local CCObjectTypes = { - "CCObject", - "CCAction", - "CCImage", - "CCFiniteTimeAction", - "CCActionInstant", - "CCFlipX", - "CCFlipY", - "CCHide", - "CCPlace", - "CCReuseGrid", - "CCShow", - "CCStopGrid", - "CCToggleVisibility", - "CCActionInterval", - "CCAccelAmplitude", - "CCAccelDeccelAmplitude", - "CCActionCamera", - "CCOrbitCamera", - "CCCardinalSplineTo", - "CCCardinalSplineBy", - "CCCatmullRomTo", - "CCCatmullRomBy", - "CCActionEase", - "CCEaseBackIn", - "CCEaseBackInOut", - "CCEaseBackOut", - "CCEaseBounce", - "CCEaseElastic", - "CCEaseExponentialIn", - "CCEaseExponentialInOut", - "CCEaseExponentialOut", - "CCEaseRateAction", - "CCEaseSineIn", - "CCEaseSineInOut", - "CCEaseSineOut", - "CCAnimate", - "CCBezierBy", - "CCBezierTo", - "CCBlink", - "CCDeccelAmplitude", - "CCDelayTime", - "CCFadeIn", - "CCFadeOut", - "CCFadeTo", - "CCGridAction", - "CCJumpBy", - "CCJumpTo", - "CCMoveTo", - "CCMoveBy", - "CCProgressFromTo", - "CCProgressTo", - "CCRepeat", - "CCRepeatForever", - "CCReverseTime", - "CCRotateBy", - "CCRotateTo", - "CCScaleTo", - "CCScaleBy", - "CCSequence", - "CCSkewTo", - "CCSkewBy", - "CCSpawn", - "CCTintBy", - "CCTintTo", - "CCActionManager", - "CCAnimation", - "CCAnimationCache", - "CCArray", - "CCAsyncObject", - "CCAutoreleasePool", - "CCBMFontConfiguration", - "CCCamera", - "CCConfiguration", - "CCData", - "CCDirector", - "CCDisplayLinkDirector", - "CCEvent", - "CCGrabber", - "CCGrid3D", - "CCTiledGrid3D", - "CCKeypadDispatcher", - "CCKeypadHandler", - "CCDictionary", - "CCNode", - "CCAtlasNode", - "CCLabelAtlas", - "CCTileMapAtlas", - "CCLayer", - "CCLayerColor", - "CCLayerGradient", - "CCLayerMultiplex", - "CCMenu", - "CCMenuItem", - "CCMenuItemLabel", - "CCMenuItemAtlasFont", - "CCMenuItemFont", - "CCMenuItemSprite", - "CCMenuItemImage", - "CCMenuItemToggle", - "CCMotionStreak", - "CCParallaxNode", - "CCParticleSystem", - "CCParticleBatchNode", - "CCParticleSystemQuad", - "CCProgressTimer", - "CCRenderTexture", - "CCRibbon", - "CCScene", - "CCTransitionScene", - "CCTransitionCrossFade", - "CCTransitionFade", - "CCTransitionFadeTR", - "CCTransitionFadeBL", - "CCTransitionFadeDown", - "CCTransitionFadeUp", - "CCTransitionJumpZoom", - "CCTransitionMoveInL", - "CCTransitionMoveInB", - "CCTransitionMoveInR", - "CCTransitionMoveInT", - "CCTransitionPageTurn", - "CCTransitionRotoZoom", - "CCTransitionSceneOriented", - "CCTransitionFlipAngular", - "CCTransitionFlipX", - "CCTransitionFlipY", - "CCTransitionZoomFlipAngular", - "CCTransitionZoomFlipX", - "CCTransitionZoomFlipY", - "CCTransitionShrinkGrow", - "CCTransitionSlideInL", - "CCTransitionSlideInB", - "CCTransitionSlideInR", - "CCTransitionSlideInT", - "CCTransitionSplitCols", - "CCTransitionSplitRows", - "CCTransitionTurnOffTiles", - "CCTransitionProgress", - "CCTransitionProgressRadialCCW", - "CCTransitionProgressRadialCW", - "CCTransitionProgressHorizontal", - "CCTransitionProgressVertical", - "CCTransitionProgressInOut", - "CCTransitionProgressOutIn", - "CCSprite", - "CCLabelTTF", - "CCTextFieldTTF", - "CCSpriteBatchNode", - "CCLabelBMFont", - "CCTMXLayer", - "CCTMXTiledMap", - "CCPointObject", - "CCProjectionProtocol", - "CCRibbonSegment", - "CCScheduler", - "CCSet", - "CCSpriteFrame", - "CCSpriteFrameCache", - "CCString", - "CCTexture2D", - "CCTextureAtlas", - "CCTextureCache", - "CCTexturePVR", - "CCTimer", - "CCTMXLayerInfo", - "CCTMXMapInfo", - "CCTMXObjectGroup", - "CCTMXTilesetInfo", - "CCTouch", - "CCTouchDispatcher", - "CCTouchHandler", - "CCParticleFire", - "CCParticleFireworks", - "CCParticleSun", - "CCParticleGalaxy", - "CCParticleFlower", - "CCParticleMeteor", - "CCParticleSpiral", - "CCParticleExplosion", - "CCParticleSmoke", - "CCParticleSnow", - "CCParticleRain", - "CCScale9Sprite", - "CCControl", - "CCControlButton", - "CCControlColourPicker", - "CCControlPotentiometer", - "CCControlSlider", - "CCControlStepper", - "CCControlSwitch", - "CCEditBox", - "CCInteger", - "CCDrawNode", -} - --- register CCObject types -for i = 1, #CCObjectTypes do - _push_functions[CCObjectTypes[i]] = "toluafix_pushusertype_ccobject" -end - --- register LUA_FUNCTION, LUA_TABLE, LUA_HANDLE type -_to_functions["LUA_FUNCTION"] = "toluafix_ref_function" -_is_functions["LUA_FUNCTION"] = "toluafix_isfunction" -_to_functions["LUA_TABLE"] = "toluafix_totable" -_is_functions["LUA_TABLE"] = "toluafix_istable" - -local toWrite = {} -local currentString = '' -local out -local WRITE, OUTPUT = write, output - -function output(s) - out = _OUTPUT - output = OUTPUT -- restore - output(s) -end - -function write(a) - if out == _OUTPUT then - currentString = currentString .. a - if string.sub(currentString,-1) == '\n' then - toWrite[#toWrite+1] = currentString - currentString = '' - end - else - WRITE(a) - end -end - -function post_output_hook(package) - local result = table.concat(toWrite) - local function replace(pattern, replacement) - local k = 0 - local nxt, currentString = 1, '' - repeat - local s, e = string.find(result, pattern, nxt, true) - if e then - currentString = currentString .. string.sub(result, nxt, s-1) .. replacement - nxt = e + 1 - k = k + 1 - end - until not e - result = currentString..string.sub(result, nxt) - if k == 0 then print('Pattern not replaced', pattern) end - end - - replace([[#ifndef __cplusplus -#include "stdlib.h" -#endif -#include "string.h" - -#include "tolua++.h"]], - [[/**************************************************************************** - Copyright (c) 2011 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -extern "C" { -#include "tolua_fix.h" -} - -#include -#include -#include "cocos2d.h" -#include "CCLuaEngine.h" -#include "SimpleAudioEngine.h" -#include "cocos-ext.h" - -using namespace cocos2d; -using namespace cocos2d::extension; -using namespace CocosDenshion;]]) - - replace([[/* Exported function */ -TOLUA_API int tolua_Cocos2d_open (lua_State* tolua_S);]], [[]]) - - replace([[*((LUA_FUNCTION*)]], [[(]]) - - replace([[unsigned void* tolua_ret = (unsigned void*) self->getTiles();]], - [[unsigned int* tolua_ret = (unsigned int*) self->getTiles();]]) - - replace([[Color3B color = *((Color3B*) tolua_tousertype(tolua_S,4,(void*)&(const Color3B)ccBLACK));]], - [[const Color3B clr = Color3B::BLACK; - Color3B color = *((Color3B*) tolua_tousertype(tolua_S,4,(void*)&clr));]]) - - replace([[tolua_usertype(tolua_S,"LUA_FUNCTION");]], [[]]) - - replace([[toluafix_pushusertype_ccobject(tolua_S,(void*)tolua_ret]], - [[int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret]]) - - replace('\t', ' ') - - - result = string.gsub(result, '(\"const )(CC%u%w*)', '%1_%2') - - local skip_contents = { "CCPointMake", "CCSizeMake", "CCRectMake", "CCLOG", "CCLog", "CCAssert", "CCTexture2DPixelFormat", "CCTextAlignment", "CCVerticalTextAlignment", "CCControlState", "CCControlEvent" } - - local function remove_prefix() - result = string.gsub(result, '[^_\"k]CC%u%w+', function(m) - local s, e - local count = table.getn(skip_contents) - local i = 1 - - for i = 1, count do - s, e = string.find(m, skip_contents[i]) - if s ~= nil then - return m - end - end - - return string.gsub(m, 'CC(%u%w+)', '%1') - end) - end - remove_prefix() - - - result = string.gsub(result, '(tolua_tonumber%(tolua_S,%d,)(kCC)', '%1(int)%2') - result = string.gsub(result, '(tolua_constant%(tolua_S,"k%w*",)(k)', '%1(int)%2') - result = string.gsub(result, '(tolua_constant%(tolua_S,"CCControl%w*",)(CCControl)', '%1(int)%2') - - result = string.gsub(result, "(self%->setEmitterMode%()", "%1(ParticleSystem::Mode)") - - result = string.gsub(result, '(tolua_constant%(tolua_S,"kCC[%w_]*",)(kCC)', '%1(int)%2') - - replace("Animation*", "cocos2d::Animation*") - replace("Animation::create", "cocos2d::Animation::create") - - result = string.gsub(result, '(\"const )_(CC%u%w*)', '%1%2') - - WRITE(result) -end diff --git a/tools/tolua++/build.bat b/tools/tolua++/build.bat deleted file mode 100644 index 84490f5188..0000000000 --- a/tools/tolua++/build.bat +++ /dev/null @@ -1 +0,0 @@ -tolua++ -L basic.lua -o "../../scripting/lua/cocos2dx_support/LuaCocos2d.cpp" Cocos2d.pkg diff --git a/tools/tolua++/build.sh b/tools/tolua++/build.sh deleted file mode 100755 index af219ef0c1..0000000000 --- a/tools/tolua++/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# -# Invoked build.xml, overriding the lolua++ property - -SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -TOLUA=`which tolua++` -if [ -z "${TOLUA}" ]; then - TOLUA=`which tolua++5.1` -fi - -if [ -z "${TOLUA}" ]; then - echo "Unable to find tolua++ (or tolua++5.1) in your PATH." - exit 1 -fi - -cd ${SCRIPT_DIR} -${TOLUA} -L basic.lua -o ../../scripting/lua/cocos2dx_support/LuaCocos2d.cpp Cocos2d.pkg diff --git a/tools/tolua++/ccTypes.pkg b/tools/tolua++/ccTypes.pkg deleted file mode 100644 index ddf54509c6..0000000000 --- a/tools/tolua++/ccTypes.pkg +++ /dev/null @@ -1,263 +0,0 @@ - -#define GL_ZERO 0 -#define GL_ONE 1 -#define GL_SRC_COLOR 0x0300 -#define GL_ONE_MINUS_SRC_COLOR 0x0301 -#define GL_SRC_ALPHA 0x0302 -#define GL_ONE_MINUS_SRC_ALPHA 0x0303 -#define GL_DST_ALPHA 0x0304 -#define GL_ONE_MINUS_DST_ALPHA 0x0305 -#define GL_DST_COLOR 0x0306 -#define GL_ONE_MINUS_DST_COLOR 0x0307 - -typedef unsigned char GLubyte; -typedef int GLint; -typedef int GLsizei; -typedef unsigned char GLubyte; -typedef unsigned short GLushort; -typedef unsigned int GLuint; -typedef float GLfloat; -typedef short GLshort; -typedef unsigned int GLenum; - -struct Color3B -{ - Color3B(void); - Color3B(GLubyte _r, GLubyte _g, GLubyte _b); - bool equals(const Color3B &other); - GLubyte r; - GLubyte g; - GLubyte b; -}; - - -/** RGBA color composed of 4 bytes -@since v0.8 -*/ -struct Color4B -{ - Color4B(void); - Color4B(GLubyte _r, GLubyte _g, GLubyte _b, GLubyte _a); - Color4B(const Color4F &color4F); - GLubyte r; - GLubyte g; - GLubyte b; - GLubyte a; -}; - - -/** RGBA color composed of 4 floats -@since v0.8 -*/ -struct Color4F -{ - Color4F(void); - Color4F(GLfloat _r, GLfloat _g, GLfloat _b, GLfloat _a); - Color4F(const Color3B &color3B); - Color4F(const Color4B &color4B); - bool equals(const Color4F &other); - GLfloat r; - GLfloat g; - GLfloat b; - GLfloat a; -}; - - -/** A vertex composed of 2 floats: x, y - @since v0.8 - */ -class Vertex2F -{ - Vertex2F(void); - Vertex2F(float _x, float _y); - GLfloat x; - GLfloat y; -}; - - -/** A vertex composed of 2 floats: x, y - @since v0.8 - */ -class Vertex3F -{ - Vertex3F(void); - Vertex3F(float _x, float _y, float _z); - GLfloat x; - GLfloat y; - GLfloat z; -}; - -/** A texcoord composed of 2 floats: u, y - @since v0.8 - */ -class Tex2F -{ - Tex2F(void); - Tex2F(float _u, float _v); - GLfloat u; - GLfloat v; -}; - - -//! Point Sprite component -class PointSprite -{ - PointSprite(void); - Vertex2F pos; // 8 bytes - Color4B color; // 4 bytes - GLfloat size; // 4 bytes -}; - -//! A 2D Quad. 4 * 2 floats -class Quad2 -{ - Quad2(void); - Vertex2F tl; - Vertex2F tr; - Vertex2F bl; - Vertex2F br; -}; - - -//! A 3D Quad. 4 * 3 floats -class Quad3 -{ - Quad3(void); - Vertex3F bl; - Vertex3F br; - Vertex3F tl; - Vertex3F tr; -}; - -//! a Point with a vertex point, a tex coord point and a color 4B -class V2F_C4B_T2F -{ - V2F_C4B_T2F(void); - //! vertices (2F) - Vertex2F vertices; - //! colors (4B) - Color4B colors; - //! tex coords (2F) - Tex2F texCoords; -}; - -//! a Point with a vertex point, a tex coord point and a color 4F -class V2F_C4F_T2F -{ - V2F_C4F_T2F(void); - //! vertices (2F) - Vertex2F vertices; - //! colors (4F) - Color4F colors; - //! tex coords (2F) - Tex2F texCoords; -}; - -//! a Point with a vertex point, a tex coord point and a color 4B -class V3F_C4B_T2F -{ - V3F_C4B_T2F(void); - //! vertices (3F) - Vertex3F vertices; // 12 bytes -// char __padding__[4]; - - //! colors (4B) - Color4B colors; // 4 bytes -// char __padding2__[4]; - - // tex coords (2F) - Tex2F texCoords; // 8 byts -}; - -//! 4 Vertex2FTex2FColor4B Quad -class V2F_C4B_T2F_Quad -{ - V2F_C4B_T2F_Quad(void); - //! bottom left - V2F_C4B_T2F bl; - //! bottom right - V2F_C4B_T2F br; - //! top left - V2F_C4B_T2F tl; - //! top right - V2F_C4B_T2F tr; -}; - -//! 4 Vertex3FTex2FColor4B -class V3F_C4B_T2F_Quad -{ - V3F_C4B_T2F_Quad(void); - //! top left - V3F_C4B_T2F tl; - //! bottom left - V3F_C4B_T2F bl; - //! top right - V3F_C4B_T2F tr; - //! bottom right - V3F_C4B_T2F br; -}; - -//! 4 Vertex2FTex2FColor4F Quad -class V2F_C4F_T2F_Quad -{ - V2F_C4F_T2F_Quad(void); - //! bottom left - V2F_C4F_T2F bl; - //! bottom right - V2F_C4F_T2F br; - //! top left - V2F_C4F_T2F tl; - //! top right - V2F_C4F_T2F tr; -}; - -//! Blend Function used for textures -class BlendFunc -{ - BlendFunc(void); - GLenum src; - GLenum dst; -}; - -// XXX: If any of these enums are edited and/or reordered, udpate CCTexture2D.m -//! Vertical text alignment type -typedef enum -{ - kCCVerticalTextAlignmentTop, - kCCVerticalTextAlignmentCenter, - kCCVerticalTextAlignmentBottom, -} CCVerticalTextAlignment; - -// XXX: If any of these enums are edited and/or reordered, udpate CCTexture2D.m -//! Horizontal text alignment type -typedef enum -{ - kCCTextAlignmentLeft, - kCCTextAlignmentCenter, - kCCTextAlignmentRight, -} CCTextAlignment; - -// types for animation in particle systems - -// texture coordinates for a quad -class T2F_Quad -{ - T2F_Quad(void); - //! bottom left - Tex2F bl; - //! bottom right - Tex2F br; - //! top left - Tex2F tl; - //! top right - Tex2F tr; -}; - -// struct that holds the size in pixels, texture coordinates and delays for animated CCParticleSystemQuad -class AnimationFrameData -{ - AnimationFrameData(void); - T2F_Quad texCoords; - float delay; - CCSize size; -}; diff --git a/tools/tolua++/matrix.pkg b/tools/tolua++/matrix.pkg deleted file mode 100644 index 1bd3c67933..0000000000 --- a/tools/tolua++/matrix.pkg +++ /dev/null @@ -1,18 +0,0 @@ - -typedef unsigned int kmGLEnum; - -class kmMat4 { - float mat[16]; -}; - -void kmGLFreeAll(void); -void kmGLPushMatrix(void); -void kmGLPopMatrix(void); -void kmGLMatrixMode(kmGLEnum mode); -void kmGLLoadIdentity(void); -void kmGLLoadMatrix(const kmMat4* pIn); -void kmGLMultMatrix(const kmMat4* pIn); -void kmGLTranslatef(float x, float y, float z); -void kmGLRotatef(float angle, float x, float y, float z); -void kmGLScalef(float x, float y, float z); -void kmGLGetMatrix(kmGLEnum mode, kmMat4* pOut); diff --git a/tools/tolua++/tolua++.Mac.zip.REMOVED.git-id b/tools/tolua++/tolua++.Mac.zip.REMOVED.git-id deleted file mode 100644 index 52d16d82cb..0000000000 --- a/tools/tolua++/tolua++.Mac.zip.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -12a58290deb3c79169fcb192e45b92d7229da0b3 \ No newline at end of file diff --git a/tools/tolua++/tolua++.rar.REMOVED.git-id b/tools/tolua++/tolua++.rar.REMOVED.git-id deleted file mode 100644 index 6be0fb75bc..0000000000 --- a/tools/tolua++/tolua++.rar.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -eea7ee6d1eab766660efb216ab5fb16640957e75 \ No newline at end of file From 0a53a12f514575282d7392aa7ee22e66e550a2ab Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 17 Sep 2013 14:31:43 +0800 Subject: [PATCH 22/34] issue #2771: update project setting --- CocosDenshion/android/Android.mk | 3 +- cocos2dx/Android.mk | 7 +- cocos2dx/physics/CCPhysicsBody.cpp | 2 + cocos2dx/physics/CCPhysicsJoint.cpp | 30 + cocos2dx/physics/CCPhysicsWorld.cpp | 6 + cocos2dx/physics/CCPhysicsWorld.h | 2 +- .../physics/chipmunk/CCPhysicsShapeInfo.cpp | 3 +- samples/Cpp/TestCpp/Android.mk | 22 +- .../ArmatureTest/ArmatureScene.cpp | 873 ------------------ .../ArmatureTest/ArmatureScene.h | 217 ----- .../CocoStudioGUITest/CocosGUIScene.cpp | 2 +- 11 files changed, 68 insertions(+), 1099 deletions(-) delete mode 100644 samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp delete mode 100644 samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.h diff --git a/CocosDenshion/android/Android.mk b/CocosDenshion/android/Android.mk index 2d59a7e79b..996a07f321 100644 --- a/CocosDenshion/android/Android.mk +++ b/CocosDenshion/android/Android.mk @@ -16,7 +16,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \ $(LOCAL_PATH)/../../cocos2dx \ $(LOCAL_PATH)/../../cocos2dx/include \ $(LOCAL_PATH)/../../cocos2dx/kazmath/include \ - $(LOCAL_PATH)/../../cocos2dx/platform/android + $(LOCAL_PATH)/../../cocos2dx/platform/android \ + $(LOCAL_PATH)/../../external/chipmunk/include/chipmunk LOCAL_CFLAGS += -Wno-psabi LOCAL_EXPORT_CFLAGS += -Wno-psabi diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index c03343e1b1..9dddcde603 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -111,7 +111,6 @@ physics/chipmunk/CCPhysicsContactInfo.cpp \ physics/chipmunk/CCPhysicsJointInfo.cpp \ physics/chipmunk/CCPhysicsShapeInfo.cpp \ physics/chipmunk/CCPhysicsWorldInfo.cpp \ -physics/chipmunk/ChipmunkDebugDraw.c \ platform/CCEGLViewProtocol.cpp \ platform/CCFileUtils.cpp \ platform/CCSAXParser.cpp \ @@ -165,7 +164,8 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/platform/android \ $(LOCAL_PATH)/platform/third_party/common/etc \ $(LOCAL_PATH)/platform/third_party/common/s3tc \ - $(LOCAL_PATH)/platform/third_party/common/atitc + $(LOCAL_PATH)/platform/third_party/common/atitc \ + $(LOCAL_PATH)/../external/chipmunk/include/chipmunk LOCAL_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/include \ @@ -173,7 +173,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/platform/android \ $(LOCAL_PATH)/platform/third_party/common/etc \ $(LOCAL_PATH)/platform/third_party/common/s3tc \ - $(LOCAL_PATH)/platform/third_party/common/atitc + $(LOCAL_PATH)/platform/third_party/common/atitc \ + $(LOCAL_PATH)/../external/chipmunk/include/chipmunk LOCAL_LDLIBS := -lGLESv2 \ diff --git a/cocos2dx/physics/CCPhysicsBody.cpp b/cocos2dx/physics/CCPhysicsBody.cpp index 588586dded..655a57eb89 100644 --- a/cocos2dx/physics/CCPhysicsBody.cpp +++ b/cocos2dx/physics/CCPhysicsBody.cpp @@ -24,6 +24,8 @@ #include "CCPhysicsBody.h" #ifdef CC_USE_PHYSICS +#include + #include "CCPhysicsShape.h" #include "CCPhysicsJoint.h" #include "CCPhysicsWorld.h" diff --git a/cocos2dx/physics/CCPhysicsJoint.cpp b/cocos2dx/physics/CCPhysicsJoint.cpp index 572e682fa8..6b57ee2351 100644 --- a/cocos2dx/physics/CCPhysicsJoint.cpp +++ b/cocos2dx/physics/CCPhysicsJoint.cpp @@ -83,6 +83,36 @@ PhysicsJointPin::~PhysicsJointPin() } +PhysicsJointFixed::PhysicsJointFixed() +{ + +} + +PhysicsJointFixed::~PhysicsJointFixed() +{ + +} + +PhysicsJointSliding::PhysicsJointSliding() +{ + +} + +PhysicsJointSliding::~PhysicsJointSliding() +{ + +} + +PhysicsJointLimit::PhysicsJointLimit() +{ + +} + +PhysicsJointLimit::~PhysicsJointLimit() +{ + +} + #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) PhysicsBodyInfo* PhysicsJoint::bodyInfo(PhysicsBody* body) const { diff --git a/cocos2dx/physics/CCPhysicsWorld.cpp b/cocos2dx/physics/CCPhysicsWorld.cpp index e880f72f65..d35260d4cb 100644 --- a/cocos2dx/physics/CCPhysicsWorld.cpp +++ b/cocos2dx/physics/CCPhysicsWorld.cpp @@ -277,6 +277,12 @@ void PhysicsWorld::collisionSeparateCallback(const PhysicsContact& contact) } } +void PhysicsWorld::setGravity(Point gravity) +{ + _gravity = gravity; + cpSpaceSetGravity(_info->space, PhysicsHelper::point2cpv(_gravity)); +} + #elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) #endif diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index 625ba9c065..6c4bed8b16 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -63,7 +63,7 @@ public: inline void unregisterContactListener() { _listener = nullptr; } inline Point getGravity() { return _gravity; } - inline void setGravity(Point gravity) { _gravity = gravity; } + void setGravity(Point gravity); inline bool getDebugDraw() { return _debugDraw; } inline void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; } diff --git a/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.cpp b/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.cpp index f22d7a3267..0734bf6e49 100644 --- a/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.cpp +++ b/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.cpp @@ -24,6 +24,7 @@ #include "CCPhysicsShapeInfo.h" #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +#include NS_CC_BEGIN std::map PhysicsShapeInfo::map; @@ -56,7 +57,7 @@ void PhysicsShapeInfo::remove(cpShape* shape) { if (shape == nullptr) return; - auto it = find(shapes.begin(), shapes.end(), shape); + auto it = std::find(shapes.begin(), shapes.end(), shape); if (it != shapes.end()) { shapes.erase(it); diff --git a/samples/Cpp/TestCpp/Android.mk b/samples/Cpp/TestCpp/Android.mk index b52c6db179..87d662be3a 100644 --- a/samples/Cpp/TestCpp/Android.mk +++ b/samples/Cpp/TestCpp/Android.mk @@ -45,7 +45,6 @@ Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp \ Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp \ Classes/EffectsTest/EffectsTest.cpp \ Classes/ExtensionsTest/ExtensionsTest.cpp \ -Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp \ Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.cpp \ Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.cpp \ Classes/ExtensionsTest/CocosBuilderTest/ButtonTest/ButtonTestLayer.cpp \ @@ -60,8 +59,27 @@ Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp \ Classes/ExtensionsTest/CocoStudioComponentsTest/PlayerController.cpp \ Classes/ExtensionsTest/CocoStudioComponentsTest/ProjectileController.cpp \ Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp \ -Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp \ Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UIScene.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UIDragPanelTest/UIDragPanelTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UILabelAtlasTest/UILabelAtlasTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UILabelBMFontTest/UILabelBMFontTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UILabelTest/UILabelTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UINodeContainerTest/UINodeContainerTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UIPanelTest/UIPanelTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UITextAreaTest/UITextAreaTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UITextButtonTest/UITextButtonTest.cpp \ +Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp \ +Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp \ Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp \ Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp \ Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp \ diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp deleted file mode 100644 index 0e62769a95..0000000000 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp +++ /dev/null @@ -1,873 +0,0 @@ -#include "ArmatureScene.h" -#include "../../testResource.h" - - -using namespace cocos2d; -using namespace cocos2d::extension; - -CCLayer* NextTest(); -CCLayer* BackTest(); -CCLayer* RestartTest(); - -static int s_nActionIdx = -1; - - -CCLayer *CreateLayer(int index) -{ - CCLayer *pLayer = NULL; - switch(index) - { - case TEST_DRAGON_BONES_2_0: - pLayer = new TestDragonBones20(); break; - case TEST_COCOSTUDIO_WITH_SKELETON: - pLayer = new TestCSWithSkeleton(); break; - case TEST_COCOSTUDIO_WITHOUT_SKELETON: - pLayer = new TestCSWithoutSkeleton(); break; - case TEST_PERFORMANCE: - pLayer = new TestPerformance(); break; - case TEST_CHANGE_ZORDER: - pLayer = new TestChangeZorder(); break; - case TEST_ANIMATION_EVENT: - pLayer = new TestAnimationEvent(); break; - case TEST_PARTICLE_DISPLAY: - pLayer = new TestParticleDisplay(); break; - case TEST_USE_DIFFERENT_PICTURE: - pLayer = new TestUseMutiplePicture(); break; - case TEST_BCOLLIDER_DETECTOR: - pLayer = new TestColliderDetector(); break; - case TEST_BOUDINGBOX: - pLayer = new TestBoundingBox(); break; - case TEST_ANCHORPOINT: - pLayer = new TestAnchorPoint(); break; - case TEST_ARMATURE_NESTING: - pLayer = new TestArmatureNesting(); break; - default: - break; - } - - return pLayer; -} - - -CCLayer* NextTest() -{ - ++s_nActionIdx; - s_nActionIdx = s_nActionIdx % TEST_LAYER_COUNT; - - CCLayer* pLayer = CreateLayer(s_nActionIdx); - pLayer->autorelease(); - - return pLayer; -} - -CCLayer* BackTest() -{ - --s_nActionIdx; - if( s_nActionIdx < 0 ) - s_nActionIdx += TEST_LAYER_COUNT; - - CCLayer* pLayer = CreateLayer(s_nActionIdx); - pLayer->autorelease(); - - return pLayer; -} - -CCLayer* RestartTest() -{ - CCLayer* pLayer = CreateLayer(s_nActionIdx); - pLayer->autorelease(); - - return pLayer; -} - - -ArmatureTestScene::ArmatureTestScene(bool bPortrait) -{ - TestScene::init(); - - CCSprite *bg = CCSprite::create("armature/bg.jpg"); - bg->setPosition(VisibleRect::center()); - - float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width; - float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height; - - bg->setScaleX(scaleX); - bg->setScaleY(scaleY); - - addChild(bg); -} -void ArmatureTestScene::runThisTest() -{ - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/TestBone0.png", "armature/TestBone0.plist", "armature/TestBone.json"); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy0.png", "armature/Cowboy0.plist", "armature/Cowboy.ExportJson"); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml"); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml"); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml"); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml"); - - s_nActionIdx = -1; - addChild(NextTest()); - - CCDirector::sharedDirector()->replaceScene(this); -} -void ArmatureTestScene::MainMenuCallback(CCObject* pSender) -{ - TestScene::MainMenuCallback(pSender); - - removeAllChildren(); - CCArmatureDataManager::sharedArmatureDataManager()->purgeArmatureSystem(); -} - - - -void ArmatureTestLayer::onEnter() -{ - - CCLayer::onEnter(); - - // add title and subtitle - std::string str = title(); - const char * pTitle = str.c_str(); - CCLabelTTF* label = CCLabelTTF::create(pTitle, "Arial", 18); - label->setColor(ccc3(0, 0, 0)); - addChild(label, 1, 10000); - label->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 30) ); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Arial", 18); - l->setColor(ccc3(0, 0, 0)); - addChild(l, 1, 10001); - l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 60) ); - } - - // add menu - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(ArmatureTestLayer::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(ArmatureTestLayer::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(ArmatureTestLayer::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 100); - - setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); - -} -void ArmatureTestLayer::onExit() -{ -} - -std::string ArmatureTestLayer::title() -{ - return "CSArmature Test Bed"; -} -std::string ArmatureTestLayer::subtitle() -{ - return ""; -} - -void ArmatureTestLayer::restartCallback(CCObject* pSender) -{ - CCScene* s = new ArmatureTestScene(); - s->addChild( RestartTest() ); - CCDirector::sharedDirector()->replaceScene(s); - s->release(); -} -void ArmatureTestLayer::nextCallback(CCObject* pSender) -{ - CCScene* s = new ArmatureTestScene(); - s->addChild( NextTest() ); - CCDirector::sharedDirector()->replaceScene(s); - s->release(); -} -void ArmatureTestLayer::backCallback(CCObject* pSender) -{ - CCScene* s = new ArmatureTestScene(); - s->addChild( BackTest() ); - CCDirector::sharedDirector()->replaceScene(s); - s->release(); -} -void ArmatureTestLayer::draw() -{ - CCLayer::draw(); -} - - - -void TestDragonBones20::onEnter() -{ - ArmatureTestLayer::onEnter(); - - cocos2d::extension::CCArmature *armature = NULL; - armature = cocos2d::extension::CCArmature::create("Dragon"); - armature->getAnimation()->playByIndex(1); - armature->getAnimation()->setAnimationScale(0.4f); - armature->setPosition(VisibleRect::center().x, VisibleRect::center().y * 0.3f); - armature->setScale(0.6f); - addChild(armature); -} - -std::string TestDragonBones20::title() -{ - return "Test Export From DragonBones version 2.0"; -} - - -void TestCSWithSkeleton::onEnter() -{ - ArmatureTestLayer::onEnter(); - cocos2d::extension::CCArmature *armature = NULL; - armature = cocos2d::extension::CCArmature::create("Cowboy"); - armature->getAnimation()->playByIndex(0); - armature->setScale(0.2f); - armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y/*-100*/)); - addChild(armature); -} - -std::string TestCSWithSkeleton::title() -{ - return "Test Export From CocoStudio With Skeleton Effect"; -} - - - -void TestCSWithoutSkeleton::onEnter() -{ - ArmatureTestLayer::onEnter(); - cocos2d::extension::CCArmature *armature = NULL; - armature = cocos2d::extension::CCArmature::create("TestBone"); - armature->getAnimation()->playByIndex(0); - armature->setAnchorPoint(ccp(0.5, -0.1)); - armature->setScale(0.2f); - armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y-100)); - addChild(armature); -} - -std::string TestCSWithoutSkeleton::title() -{ - return "Test Export From CocoStudio Without Skeleton Effect"; -} - - - - -TestPerformance::~TestPerformance() -{ -} -void TestPerformance::onEnter() -{ - ArmatureTestLayer::onEnter(); - - armatureCount = frames = times = lastTimes = 0; - generated = false; - - scheduleUpdate(); -} - -std::string TestPerformance::title() -{ - return "Test Performance"; -} -std::string TestPerformance::subtitle() -{ - return "Current CCArmature Count : "; -} -void TestPerformance::addArmature(cocos2d::extension::CCArmature *armature) -{ - armatureCount++; - addChild(armature, armatureCount); -} -void TestPerformance::update(float delta) -{ - frames ++; - times += delta; - - if (frames/times > 58) - { - cocos2d::extension::CCArmature *armature = NULL; - armature = new cocos2d::extension::CCArmature(); - armature->init("Knight_f/Knight"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(50 + armatureCount * 2, 150); - armature->setScale(0.6f); - addArmature(armature); - armature->release(); - - char pszCount[255]; - sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount); - CCLabelTTF *label = (CCLabelTTF*)getChildByTag(10001); - label->setString(pszCount); - } -} - - - - - - -void TestChangeZorder::onEnter() -{ - ArmatureTestLayer::onEnter(); - - cocos2d::extension::CCArmature *armature = NULL; - currentTag = -1; - - armature = cocos2d::extension::CCArmature::create("Knight_f/Knight"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y-100)); - ++currentTag; - armature->setScale(0.6f); - addChild(armature, currentTag, currentTag); - - armature = cocos2d::extension::CCArmature::create("TestBone"); - armature->getAnimation()->playByIndex(0); - armature->setScale(0.24f); - armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y-100)); - ++currentTag; - addChild(armature, currentTag, currentTag); - - armature = cocos2d::extension::CCArmature::create("Dragon"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(ccp(VisibleRect::center().x , VisibleRect::center().y-100)); - ++currentTag; - armature->setScale(0.6f); - addChild(armature, currentTag, currentTag); - - schedule( schedule_selector(TestChangeZorder::changeZorder), 1); - - currentTag = 0; -} -std::string TestChangeZorder::title() -{ - return "Test Change ZOrder Of Different CCArmature"; -} -void TestChangeZorder::changeZorder(float dt) -{ - - CCNode *node = getChildByTag(currentTag); - - node->setZOrder(CCRANDOM_0_1() * 3); - - currentTag ++; - currentTag = currentTag % 3; -} - - - - -void TestAnimationEvent::onEnter() -{ - ArmatureTestLayer::onEnter(); - armature = cocos2d::extension::CCArmature::create("Cowboy"); - armature->getAnimation()->play("Fire"); - armature->setScaleX(-0.24f); - armature->setScaleY(0.24f); - armature->setPosition(ccp(VisibleRect::left().x + 50, VisibleRect::left().y)); - armature->getAnimation()->MovementEventSignal.connect(this, &TestAnimationEvent::animationEvent); - addChild(armature); -} -std::string TestAnimationEvent::title() -{ - return "Test CCArmature Animation Event"; -} -void TestAnimationEvent::animationEvent(cocos2d::extension::CCArmature *armature, MovementEventType movementType, const char *movementID) -{ - std::string id = movementID; - - if (movementType == LOOP_COMPLETE) - { - if (id.compare("Fire") == 0) - { - CCActionInterval *actionToRight = CCMoveTo::create(2, ccp(VisibleRect::right().x - 50, VisibleRect::right().y)); - armature->stopAllActions(); - armature->runAction(CCSequence::create(actionToRight, CCCallFunc::create(this, callfunc_selector(TestAnimationEvent::callback1)), NULL)); - armature->getAnimation()->play("Walk"); - } - else if (id.compare("FireMax") == 0) - { - CCActionInterval *actionToLeft = CCMoveTo::create(2, ccp(VisibleRect::left().x + 50, VisibleRect::left().y)); - armature->stopAllActions(); - armature->runAction(CCSequence::create(actionToLeft, CCCallFunc::create(this, callfunc_selector(TestAnimationEvent::callback2)), NULL)); - armature->getAnimation()->play("Walk"); - } - } -} -void TestAnimationEvent::callback1() -{ - armature->runAction(CCScaleTo::create(0.3f, 0.3f, 0.3f)); - armature->getAnimation()->play("FireMax", 10); -} -void TestAnimationEvent::callback2() -{ - armature->runAction(CCScaleTo::create(0.3f, -0.3f, 0.3f)); - armature->getAnimation()->play("Fire", 10); -} - - - - -void TestParticleDisplay::onEnter() -{ - ArmatureTestLayer::onEnter(); - setTouchEnabled(true); - - animationID = 0; - - armature = cocos2d::extension::CCArmature::create("robot"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(VisibleRect::center()); - armature->setScale(0.48f); - armature->getAnimation()->setAnimationScale(0.5f); - addChild(armature); - - - CCParticleSystem *p1 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); - CCParticleSystem *p2 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); - - cocos2d::extension::CCBone *bone = cocos2d::extension::CCBone::create("p1"); - bone->addDisplay(p1, 0); - bone->changeDisplayByIndex(0, true); - bone->setIgnoreMovementBoneData(true); - bone->setZOrder(100); - bone->setScale(1.2f); - armature->addBone(bone, "bady-a3"); - - bone = cocos2d::extension::CCBone::create("p2"); - bone->addDisplay(p2, 0); - bone->changeDisplayByIndex(0, true); - bone->setIgnoreMovementBoneData(true); - bone->setZOrder(100); - bone->setScale(1.2f); - armature->addBone(bone, "bady-a30"); -} -std::string TestParticleDisplay::title() -{ - return "Test Particle Display"; -} -std::string TestParticleDisplay::subtitle() -{ - return "Touch to change animation"; -} -bool TestParticleDisplay::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) -{ - ++animationID; - animationID = animationID % armature->getAnimation()->getMovementCount(); - armature->getAnimation()->playByIndex(animationID); - return false; -} - -void TestParticleDisplay::registerWithTouchDispatcher() -{ - CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true); -} - - - - -void TestUseMutiplePicture::onEnter() -{ - ArmatureTestLayer::onEnter(); - setTouchEnabled(true); - - displayIndex = 0; - - armature = cocos2d::extension::CCArmature::create("Knight_f/Knight"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(ccp(VisibleRect::left().x+70, VisibleRect::left().y)); - armature->setScale(1.2f); - addChild(armature); - - std::string weapon[] = {"weapon_f-sword.png", "weapon_f-sword2.png", "weapon_f-sword3.png", "weapon_f-sword4.png", "weapon_f-sword5.png", "weapon_f-knife.png", "weapon_f-hammer.png"}; - - CCSpriteDisplayData displayData; - for (int i = 0; i < 7; i++) - { - displayData.setParam(weapon[i].c_str()); - armature->getBone("weapon")->addDisplay(&displayData, i); - } -} -std::string TestUseMutiplePicture::title() -{ - return "Test One CCArmature Use Different Picture"; -} -std::string TestUseMutiplePicture::subtitle() -{ - return "weapon and armature are in different picture"; -} -bool TestUseMutiplePicture::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) -{ - ++displayIndex; - displayIndex = (displayIndex) % 6; - armature->getBone("weapon")->changeDisplayByIndex(displayIndex, true); - return false; -} -void TestUseMutiplePicture::registerWithTouchDispatcher() -{ - CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true); -} - - - - - - -#if ENABLE_PHYSICS_BOX2D_DETECT - -class Contact -{ -public: - b2Fixture *fixtureA; - b2Fixture *fixtureB; -}; - -class ContactListener : public b2ContactListener -{ - //! Callbacks for derived classes. - virtual void BeginContact(b2Contact *contact) - { - if (contact) - { - Contact c; - c.fixtureA = contact->GetFixtureA(); - c.fixtureB = contact->GetFixtureB(); - - contact_list.push_back(c); - } - B2_NOT_USED(contact); - } - virtual void EndContact(b2Contact *contact) - { - contact_list.clear(); - B2_NOT_USED(contact); - } - virtual void PreSolve(b2Contact *contact, const b2Manifold *oldManifold) - { - B2_NOT_USED(contact); - B2_NOT_USED(oldManifold); - } - virtual void PostSolve(const b2Contact *contact, const b2ContactImpulse *impulse) - { - B2_NOT_USED(contact); - B2_NOT_USED(impulse); - } - -public: - std::list contact_list; -}; - -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - -enum ColliderType -{ - eBulletTag, - eEnemyTag -}; - - -int TestColliderDetector::beginHit(cpArbiter *arb, cpSpace *space, void *unused) -{ - CP_ARBITER_GET_SHAPES(arb, a, b); - - CCBone *bone = (CCBone*)a->data; - bone->getArmature()->setVisible(false); - - return 0; -} - -void TestColliderDetector::endHit(cpArbiter *arb, cpSpace *space, void *unused) -{ - CP_ARBITER_GET_SHAPES(arb, a, b); - - CCBone *bone = (CCBone*)a->data; - bone->getArmature()->setVisible(true); -} - -void TestColliderDetector::destroyCPBody(cpBody *body) -{ - cpShape *shape = body->shapeList_private; - while(shape) - { - cpShape *temp = shape->next_private; - - cpSpaceRemoveShape(space, shape); - cpShapeFree(shape); - - shape = temp; - } - - cpSpaceRemoveBody(space, body); - cpBodyFree(body); -} -#endif - -TestColliderDetector::~TestColliderDetector() -{ -#if ENABLE_PHYSICS_BOX2D_DETECT - CC_SAFE_DELETE(world); - CC_SAFE_DELETE(listener); - CC_SAFE_DELETE(debugDraw); -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - destroyCPBody(armature2->getCPBody()); - destroyCPBody(bullet->getCPBody()); - - cpSpaceFree(space); -#endif -} - -void TestColliderDetector::onEnter() -{ - ArmatureTestLayer::onEnter(); - - scheduleUpdate(); - - armature = cocos2d::extension::CCArmature::create("Cowboy"); - armature->getAnimation()->play("FireWithoutBullet"); - armature->getAnimation()->setAnimationScale(0.2f); - armature->setScaleX(-0.2f); - armature->setScaleY(0.2f); - armature->setPosition(ccp(VisibleRect::left().x + 70, VisibleRect::left().y)); - addChild(armature); - - armature2 = cocos2d::extension::CCArmature::create("Cowboy"); - armature2->getAnimation()->play("Walk"); - armature2->setScaleX(-0.2f); - armature2->setScaleY(0.2f); - armature2->setPosition(ccp(VisibleRect::right().x - 30, VisibleRect::left().y)); - addChild(armature2); - - bullet = CCPhysicsSprite::createWithSpriteFrameName("25.png"); - addChild(bullet); - - initWorld(); -} -std::string TestColliderDetector::title() -{ - return "Test Collider Detector"; -} -void TestColliderDetector::draw() -{ -#if ENABLE_PHYSICS_BOX2D_DETECT - ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position ); - kmGLPushMatrix(); - world->DrawDebugData(); - kmGLPopMatrix(); -#endif -} -void TestColliderDetector::update(float delta) -{ -#if ENABLE_PHYSICS_BOX2D_DETECT - armature2->setVisible(true); -#endif - - if (armature->getAnimation()->getCurrentFrameIndex() == 9) - { - CCPoint p = armature->getBone("Layer126")->getDisplayRenderNode()->convertToWorldSpaceAR(ccp(0, 0)); - bullet->setPosition(ccp(p.x + 60, p.y)); - - bullet->stopAllActions(); - bullet->runAction(CCMoveBy::create(1.5f, ccp(350, 0))); - } - -#if ENABLE_PHYSICS_BOX2D_DETECT - world->Step(delta, 0, 0); - - for (std::list::iterator it = listener->contact_list.begin(); it != listener->contact_list.end(); ++it) - { - Contact &contact = *it; - - b2Body *b2a = contact.fixtureA->GetBody(); - b2Body *b2b = contact.fixtureB->GetBody(); - - CCBone *ba = (CCBone *)b2a->GetUserData(); - CCBone *bb = (CCBone *)b2b->GetUserData(); - - bb->getArmature()->setVisible(false); - } -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - cpSpaceStep(space, delta); -#endif -} -void TestColliderDetector::initWorld() -{ -#if ENABLE_PHYSICS_BOX2D_DETECT - b2Vec2 noGravity(0, 0); - - world = new b2World(noGravity); - world->SetAllowSleeping(true); - - listener = new ContactListener(); - world->SetContactListener(listener); - - debugDraw = new GLESDebugDraw( PT_RATIO ); - world->SetDebugDraw(debugDraw); - - uint32 flags = 0; - flags += b2Draw::e_shapeBit; - // flags += b2Draw::e_jointBit; - // flags += b2Draw::e_aabbBit; - // flags += b2Draw::e_pairBit; - // flags += b2Draw::e_centerOfMassBit; - debugDraw->SetFlags(flags); - - - // Define the dynamic body. - //Set up a 1m squared box in the physics world - b2BodyDef bodyDef; - bodyDef.type = b2_dynamicBody; - - b2Body *body = world->CreateBody(&bodyDef); - - // Define another box shape for our dynamic body. - b2PolygonShape dynamicBox; - dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box - - // Define the dynamic body fixture. - b2FixtureDef fixtureDef; - fixtureDef.shape = &dynamicBox; - fixtureDef.isSensor = true; - body->CreateFixture(&fixtureDef); - - - bullet->setB2Body(body); - bullet->setPTMRatio(PT_RATIO); - bullet->setPosition( ccp( -100, -100) ); - - body = world->CreateBody(&bodyDef); - armature2->setB2Body(body); - -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - space = cpSpaceNew(); - space->gravity = cpv(0, 0); - - // Physics debug layer - CCPhysicsDebugNode *debugLayer = CCPhysicsDebugNode::create(space); - this->addChild(debugLayer, INT_MAX); - - CCSize size = bullet->getContentSize(); - - int num = 4; - cpVect verts[] = { - cpv(-size.width/2,-size.height/2), - cpv(-size.width/2,size.height/2), - cpv(size.width/2,size.height/2), - cpv(size.width/2,-size.height/2), - }; - - cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero)); - cpSpaceAddBody(space, body); - - cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero); - shape->collision_type = eBulletTag; - cpSpaceAddShape(space, shape); - - bullet->setCPBody(body); - - body = cpBodyNew(INFINITY, INFINITY); - cpSpaceAddBody(space, body); - armature2->setCPBody(body); - - shape = body->shapeList_private; - while(shape){ - cpShape *next = shape->next_private; - shape->collision_type = eEnemyTag; - shape = next; - } - - cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, NULL, NULL, endHit, NULL); -#endif -} - - - - - -void TestBoundingBox::onEnter() -{ - ArmatureTestLayer::onEnter(); - - armature = cocos2d::extension::CCArmature::create("Cowboy"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(VisibleRect::center()); - armature->setScale(0.2f); - addChild(armature); -} -std::string TestBoundingBox::title() -{ - return "Test BoundingBox"; -} -void TestBoundingBox::draw() -{ - CC_NODE_DRAW_SETUP(); - - rect = CCRectApplyAffineTransform(armature->boundingBox(), armature->nodeToParentTransform()); - - ccDrawColor4B(100, 100, 100, 255); - ccDrawRect(rect.origin, ccp(rect.getMaxX(), rect.getMaxY())); -} - - - -void TestAnchorPoint::onEnter() -{ - ArmatureTestLayer::onEnter(); - - for (int i = 0; i<5; i++) - { - cocos2d::extension::CCArmature *armature = cocos2d::extension::CCArmature::create("Cowboy"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(VisibleRect::center()); - armature->setScale(0.2f); - addChild(armature, 0, i); - } - - getChildByTag(0)->setAnchorPoint(ccp(0,0)); - getChildByTag(1)->setAnchorPoint(ccp(0,1)); - getChildByTag(2)->setAnchorPoint(ccp(1,0)); - getChildByTag(3)->setAnchorPoint(ccp(1,1)); - getChildByTag(4)->setAnchorPoint(ccp(0.5,0.5)); - -} -std::string TestAnchorPoint::title() -{ - return "Test Set AnchorPoint"; -} - - -void TestArmatureNesting::onEnter() -{ - ArmatureTestLayer::onEnter(); - setTouchEnabled(true); - - armature = cocos2d::extension::CCArmature::create("cyborg"); - armature->getAnimation()->playByIndex(1); - armature->setPosition(VisibleRect::center()); - armature->setScale(1.2f); - armature->getAnimation()->setAnimationScale(0.4f); - addChild(armature); - - weaponIndex = 0; -} -std::string TestArmatureNesting::title() -{ - return "Test CCArmature Nesting"; -} -bool TestArmatureNesting::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) -{ - ++weaponIndex; - weaponIndex = weaponIndex % 4; - - armature->getBone("armInside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); - armature->getBone("armOutside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); - return false; -} -void TestArmatureNesting::registerWithTouchDispatcher() -{ - CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true); -} \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.h deleted file mode 100644 index 67576a3746..0000000000 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.h +++ /dev/null @@ -1,217 +0,0 @@ -#ifndef __HELLOWORLD_SCENE_H__ -#define __HELLOWORLD_SCENE_H__ - -#include "cocos2d.h" -#include "cocos-ext.h" -#include "../../VisibleRect.h" -#include "../../testBasic.h" - -#if ENABLE_PHYSICS_BOX2D_DETECT -#include "../../Box2DTestBed/GLES-Render.h" -#include "Box2D/Box2D.h" -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT -#include "chipmunk.h" -#endif - -class ArmatureTestScene : public TestScene -{ -public: - ArmatureTestScene(bool bPortrait = false); - - virtual void runThisTest(); - - // The CallBack for back to the main menu scene - virtual void MainMenuCallback(CCObject* pSender); -}; - -enum { - TEST_COCOSTUDIO_WITH_SKELETON = 0, - TEST_COCOSTUDIO_WITHOUT_SKELETON, - TEST_DRAGON_BONES_2_0, - TEST_PERFORMANCE, - TEST_CHANGE_ZORDER, - TEST_ANIMATION_EVENT, - TEST_PARTICLE_DISPLAY, - TEST_USE_DIFFERENT_PICTURE, - TEST_BCOLLIDER_DETECTOR, - TEST_BOUDINGBOX, - TEST_ANCHORPOINT, - TEST_ARMATURE_NESTING, - - TEST_LAYER_COUNT -}; - -class ArmatureTestLayer : public CCLayer -{ -public: - virtual void onEnter(); - virtual void onExit(); - - virtual std::string title(); - virtual std::string subtitle(); - - void restartCallback(CCObject* pSender); - void nextCallback(CCObject* pSender); - void backCallback(CCObject* pSender); - - virtual void draw(); -}; - - - -class TestDragonBones20 : public ArmatureTestLayer -{ -public: - virtual void onEnter(); - virtual std::string title(); -}; - - - -class TestCSWithSkeleton : public ArmatureTestLayer -{ - virtual void onEnter(); - virtual std::string title(); -}; - -class TestCSWithoutSkeleton : public ArmatureTestLayer -{ - virtual void onEnter(); - virtual std::string title(); -}; - - -class TestPerformance : public ArmatureTestLayer -{ -public: - ~TestPerformance(); - - virtual void onEnter(); - virtual std::string title(); - virtual std::string subtitle(); - virtual void addArmature(cocos2d::extension::CCArmature *armature); - void update(float delta); - - int armatureCount; - - int frames; - float times; - float lastTimes; - bool generated; -}; - - -class TestChangeZorder : public ArmatureTestLayer -{ - virtual void onEnter(); - virtual std::string title(); - void changeZorder(float dt); - - int currentTag; -}; - - -class TestAnimationEvent : public ArmatureTestLayer, public sigslot::has_slots<> -{ -public: - - virtual void onEnter(); - virtual std::string title(); - void animationEvent(cocos2d::extension::CCArmature *armature, cocos2d::extension::MovementEventType movementType, const char *movementID); - void callback1(); - void callback2(); - - cocos2d::extension::CCArmature *armature; -}; - -class TestUseMutiplePicture : public ArmatureTestLayer -{ - virtual void onEnter(); - virtual std::string title(); - virtual std::string subtitle(); - virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); - virtual void registerWithTouchDispatcher(); - - int displayIndex; - cocos2d::extension::CCArmature *armature; -}; - -class TestParticleDisplay : public ArmatureTestLayer -{ - virtual void onEnter(); - virtual std::string title(); - virtual std::string subtitle(); - virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); - virtual void registerWithTouchDispatcher(); - - int animationID; - cocos2d::extension::CCArmature *armature; -}; - -#if ENABLE_PHYSICS_BOX2D_DETECT -class ContactListener; -#endif - -class TestColliderDetector : public ArmatureTestLayer, public sigslot::has_slots<> -{ -public: - ~TestColliderDetector(); - - virtual void onEnter(); - virtual std::string title(); - virtual void draw(); - virtual void update(float delta); - - void initWorld(); - - cocos2d::extension::CCArmature *armature; - cocos2d::extension::CCArmature *armature2; - - cocos2d::extension::CCPhysicsSprite *bullet; - -#if ENABLE_PHYSICS_BOX2D_DETECT - b2World *world; - ContactListener *listener; - GLESDebugDraw *debugDraw; -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - cpSpace *space; - - static int beginHit(cpArbiter *arb, cpSpace *space, void *unused); - static void endHit(cpArbiter *arb, cpSpace *space, void *unused); - - void destroyCPBody(cpBody *body); -#endif -}; - - - -class TestBoundingBox : public ArmatureTestLayer -{ -public: - virtual void onEnter(); - virtual std::string title(); - virtual void draw(); - - cocos2d::extension::CCArmature *armature; - CCRect rect; -}; - -class TestAnchorPoint : public ArmatureTestLayer -{ -public: - virtual void onEnter(); - virtual std::string title(); -}; - -class TestArmatureNesting : public ArmatureTestLayer -{ -public: - virtual void onEnter(); - virtual std::string title(); - virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); - virtual void registerWithTouchDispatcher(); - - cocos2d::extension::CCArmature *armature; - int weaponIndex; -}; -#endif // __HELLOWORLD_SCENE_H__ \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp index 6514e7e2cf..4d17896184 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp @@ -1,7 +1,7 @@ #include "CocosGUIScene.h" #include "UISceneManager.h" //#include "CocosGUIExamplesRegisterScene.h" -#include "ExtensionsTest.h" +#include "../ExtensionsTest.h" const char* gui_scene_names[2] = { From 5040ae33a17a7e5e88aed1f28a335e7d5b39487a Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 17 Sep 2013 16:27:43 +0800 Subject: [PATCH 23/34] issue #2771: add comments --- cocos2dx/physics/CCPhysicsBody.h | 112 +++++++++++++++++- cocos2dx/physics/CCPhysicsContact.h | 39 +++++- cocos2dx/physics/CCPhysicsJoint.h | 18 +++ cocos2dx/physics/CCPhysicsShape.h | 14 ++- cocos2dx/physics/CCPhysicsWorld.h | 14 ++- .../Classes/PhysicsTest/PhysicsTest.cpp | 2 +- 6 files changed, 193 insertions(+), 6 deletions(-) diff --git a/cocos2dx/physics/CCPhysicsBody.h b/cocos2dx/physics/CCPhysicsBody.h index 08fffb8722..515366e64e 100644 --- a/cocos2dx/physics/CCPhysicsBody.h +++ b/cocos2dx/physics/CCPhysicsBody.h @@ -46,42 +46,126 @@ class PhysicsShapeEdgePolygon; class PhysicsShapeEdgeChain; class PhysicsBodyInfo; - +/** + * A body affect by physics. + * it can attach one or more shapes. + */ class PhysicsBody : public Object//, public Clonable { public: + /** + * @brief Create a body contains a circle shape. + */ static PhysicsBody* createCircle(float radius); + /** + * @brief Create a body contains a box shape. + */ static PhysicsBody* createBox(Size size); + /** + * @brief Create a body contains a polygon shape. + * points is an array of Point structs defining a convex hull with a clockwise winding. + */ static PhysicsBody* createPolygon(Point* points, int count); + /** + * @brief Create a body contains a EdgeSegment shape. + */ static PhysicsBody* createEdgeSegment(Point a, Point b, float border = 1); + /** + * @brief Create a body contains a EdgeBox shape. + */ static PhysicsBody* createEdgeBox(Size size, float border = 1); + /** + * @brief Create a body contains a EdgePolygon shape. + */ static PhysicsBody* createEdgePolygon(Point* points, int count, float border = 1); + /** + * @brief Create a body contains a EdgeChain shape. + */ static PhysicsBody* createEdgeChain(Point* points, int count, float border = 1); + /** + * @brief Attach a circle shape with body + */ virtual PhysicsShapeCircle* addCircle(float radius, Point offset = Point(0, 0)); + /** + * @brief Attach a box shape with body + */ virtual PhysicsShapeBox* addBox(Size size, Point offset = Point(0, 0)); + /** + * @brief Attach a polygon shape with body + */ virtual PhysicsShapePolygon* addPolygon(Point* points, int count, Point offset = Point(0, 0)); + /** + * @brief Attach a edge segment shape with body + */ virtual PhysicsShapeEdgeSegment* addEdgeSegment(Point a, Point b, float border = 1); + /** + * @brief Attach a edge box shape with body + */ virtual PhysicsShapeEdgeBox* addEdgeBox(Size size, float border = 1, Point offset = Point(0, 0)); + /** + * @brief Attach a edge polygon shape with body + * points is an array of Point structs defining a convex hull with a clockwise winding. + */ virtual PhysicsShapeEdgePolygon* addEdgePolygon(Point* points, int count, float border = 1); + /** + * @brief Attach a edge chain shape with body + * points is an array of Point structs defining a convex hull with a clockwise winding. + */ virtual PhysicsShapeEdgeChain* addEdgeChain(Point* points, int count, float border = 1); + /** + * @brief Applies a immediate force to body. + */ virtual void applyForce(Point force); + /** + * @brief Applies a immediate force to body. + */ virtual void applyForce(Point force, Point offset); + /** + * @brief Applies a continuous force to body. + */ virtual void applyImpulse(Point impulse); + /** + * @brief Applies a continuous force to body. + */ virtual void applyImpulse(Point impulse, Point offset); + /** + * @brief Applies a torque force to body. + */ virtual void applyTorque(float torque); + /* + * @brief get the body shapes. + */ inline std::vector& getShapes() { return _shapes; } + /* + * @brief get the first body shapes. + */ inline PhysicsShape* getShape() { return _shapes.size() >= 1 ? _shapes.front() : nullptr; } + /* + * @brief remove a shape from body + */ void removeShape(PhysicsShape* shape); + /* + * @brief remove all shapes + */ void removeAllShapes(); + /* + * @brief get the world body added to. + */ inline PhysicsWorld* getWorld() const { return _world; } + /* + * @brief get all joints the body have + */ inline const std::vector* getJoints() const { return &_joints; } + /* + * @brief get the sprite the body set to. + */ inline Sprite* getOwner() const { return _owner; } void setCategoryBitmask(int bitmask); @@ -91,16 +175,42 @@ public: void setCollisionBitmask(int bitmask); inline int getCollisionBitmask() const { return _collisionBitmask; } + /* + * @brief get the body position. + */ Point getPosition() const; + /* + * @brief get the body rotation. + */ float getRotation() const; + /* + * @brief test the body is dynamic or not. + * a dynamic body will effect with gravity. + */ inline bool isDynamic() { return _dynamic; } + /* + * @brief set dynamic to body. + * a dynamic body will effect with gravity. + */ void setDynamic(bool dynamic); + /* + * @brief set the body mass. + */ void setMass(float mass); + /* + * @brief get the body mass. + */ inline float getMass() { return _mass; } + /* + * @brief set angular damping. + */ void setAngularDamping(float angularDamping); + /* + * @brief get angular damping. + */ inline float getAngularDamping() { return _angularDamping; } //virtual Clonable* clone() const override; diff --git a/cocos2dx/physics/CCPhysicsContact.h b/cocos2dx/physics/CCPhysicsContact.h index 4b40fadf4a..605a6dcf80 100644 --- a/cocos2dx/physics/CCPhysicsContact.h +++ b/cocos2dx/physics/CCPhysicsContact.h @@ -38,12 +38,28 @@ class PhysicsWorld; class PhysicsContactInfo; +/** + * @brief Contact infomation. it will created automatically when two shape contact with each other. and it will destoried automatically when two shape separated. + */ class PhysicsContact { public: + /* + * @brief get contact shape A. + */ inline PhysicsShape* getShapeA() { return _shapeA; } + /* + * @brief get contact shape B. + */ inline PhysicsShape* getShapeB() { return _shapeB; } + /* + * @brief get data. + */ inline void* getData() { return _data; } + /* + * @brief set data to contact. you must manage the memory yourself, Generally you can set data at contact begin, and distory it at contact end. + */ + inline void setData(void* data) { _data = data; } private: static PhysicsContact* create(PhysicsShape* a, PhysicsShape* b); @@ -62,6 +78,9 @@ private: friend class PhysicsWorld; }; +/* + * @brief presolve value generated when onContactPreSolve called. + */ class PhysicsContactPreSolve { private: @@ -74,6 +93,9 @@ private: friend class PhysicsWorld; }; +/* + * @brief postsolve value generated when onContactPostSolve called. + */ class PhysicsContactPostSolve { private: @@ -86,6 +108,9 @@ private: friend class PhysicsWorld; }; +/* + * @brief contact listener. + */ class PhysicsContactListener { public: @@ -93,10 +118,22 @@ public: virtual ~PhysicsContactListener(); public: + /* + * @brief it will called at two shapes start to contact, and only call it once. + */ std::function onContactBegin; + /* + * @brief Two shapes are touching during this step. Return false from the callback to make world ignore the collision this step or true to process it normally. Additionally, you may override collision values, elasticity, or surface velocity values. + */ std::function onContactPreSolve; - + /* + * @brief Two shapes are touching and their collision response has been processed. You can retrieve the collision impulse or kinetic energy at this time if you want to use it to calculate sound volumes or damage amounts. See cpArbiter for more info + */ std::function onContactPostSolve; + /* + * @brief it will called at two shapes separated, and only call it once. + * onContactBegin and onContactEnd will called in pairs. + */ std::function onContactEnd; }; diff --git a/cocos2dx/physics/CCPhysicsJoint.h b/cocos2dx/physics/CCPhysicsJoint.h index ab0315d690..854963049d 100644 --- a/cocos2dx/physics/CCPhysicsJoint.h +++ b/cocos2dx/physics/CCPhysicsJoint.h @@ -37,6 +37,9 @@ class PhysicsBody; class PhysicsJointInfo; class PhysicsBodyInfo; +/* + * @brief An PhysicsJoint object connects two physics bodies together. + */ class PhysicsJoint : public Object { protected: @@ -63,6 +66,9 @@ protected: friend class PhysicsBody; }; +/* + * @brief A fixed joint fuses the two bodies together at a reference point. Fixed joints are useful for creating complex shapes that can be broken apart later. + */ class PhysicsJointFixed : public PhysicsJoint { public: @@ -76,6 +82,9 @@ protected: virtual ~PhysicsJointFixed(); }; +/* + * @brief A sliding joint allows the two bodies to slide along a chosen axis. + */ class PhysicsJointSliding : public PhysicsJoint { public: @@ -89,6 +98,9 @@ protected: virtual ~PhysicsJointSliding(); }; +/* + * @brief A spring joint connects the two bodies with a spring whose length is the initial distance between the two bodies. + */ class PhysicsJointSpring : public PhysicsJoint { public: @@ -102,6 +114,9 @@ protected: virtual ~PhysicsJointSpring(); }; +/* + * @brief A limit joint imposes a maximum distance between the two bodies, as if they were connected by a rope. + */ class PhysicsJointLimit : public PhysicsJoint { public: @@ -115,6 +130,9 @@ protected: virtual ~PhysicsJointLimit(); }; +/* + * @brief A pin joint allows the two bodies to independently rotate around the anchor point as if pinned together. + */ class PhysicsJointPin : public PhysicsJoint { public: diff --git a/cocos2dx/physics/CCPhysicsShape.h b/cocos2dx/physics/CCPhysicsShape.h index 64049c2947..79cda68e6d 100644 --- a/cocos2dx/physics/CCPhysicsShape.h +++ b/cocos2dx/physics/CCPhysicsShape.h @@ -37,6 +37,9 @@ class PhysicsShapeInfo; class PhysicsBody; class PhysicsBodyInfo; +/** + * @brief A shape for body. You do not create PhysicsWorld objects directly, instead, you can view PhysicsBody to see how to create it. + */ class PhysicsShape : public Object { public: @@ -60,7 +63,7 @@ protected: bool init(PhysicsBody* body, Type type); /** - * PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody. + * @brief PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody. */ PhysicsBodyInfo* bodyInfo() const; @@ -68,7 +71,7 @@ protected: protected: PhysicsShape(); - virtual ~PhysicsShape(); + virtual ~PhysicsShape() = 0; protected: PhysicsBody* _body; @@ -79,6 +82,7 @@ protected: friend class PhysicsBody; }; +/** A circle shape */ class PhysicsShapeCircle : public PhysicsShape { protected: @@ -92,6 +96,7 @@ protected: friend class PhysicsBody; }; +/** A box shape */ class PhysicsShapeBox : public PhysicsShape { protected: @@ -105,6 +110,7 @@ protected: friend class PhysicsBody; }; +/** A polygon shape */ class PhysicsShapePolygon : public PhysicsShape { protected: @@ -118,6 +124,7 @@ protected: friend class PhysicsBody; }; +/** A segment shape */ class PhysicsShapeEdgeSegment : public PhysicsShape { protected: @@ -131,6 +138,7 @@ protected: friend class PhysicsBody; }; +/** An edge box shape */ class PhysicsShapeEdgeBox : public PhysicsShape { public: @@ -146,6 +154,7 @@ protected: friend class PhysicsBody; }; +/** An edge polygon shape */ class PhysicsShapeEdgePolygon : public PhysicsShape { public: @@ -161,6 +170,7 @@ protected: friend class PhysicsBody; }; +/** a chain shape */ class PhysicsShapeEdgeChain : public PhysicsShape { public: diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index 6c4bed8b16..425a831442 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -47,11 +47,17 @@ class Sprite; class Scene; class DrawNode; +/** + * @brief An PhysicsWorld object simulates collisions and other physical properties. You do not create PhysicsWorld objects directly; instead, you can get it from an Scene object. + */ class PhysicsWorld { public: + /** Adds a joint to the physics world.*/ void addJoint(PhysicsJoint* joint); + /** Removes a joint from the physics world.*/ void removeJoint(PhysicsJoint* joint); + /** Remove all joints from the physics world.*/ void removeAllJoints(); Array* getBodysAlongRay(Point start, Point end) const; @@ -59,13 +65,19 @@ public: Array* getBodysInRect(Rect rect) const; Array* getAllBody() const; + /** Register a listener to receive contact callbacks*/ inline void registerContactListener(PhysicsContactListener* delegate) { _listener = delegate; } + /** Unregister a listener. */ inline void unregisterContactListener() { _listener = nullptr; } + /** get the gravity value */ inline Point getGravity() { return _gravity; } + /** set the gravity value */ void setGravity(Point gravity); - inline bool getDebugDraw() { return _debugDraw; } + /** test the debug draw is enabled */ + inline bool isDebugDraw() { return _debugDraw; } + /** set the debug draw */ inline void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; } protected: diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp index e3b1b271a8..94f63e7f59 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -52,7 +52,7 @@ void PhysicsTestLayer::toggleDebugCallback(Object* sender) #ifdef CC_USE_PHYSICS if (_scene != nullptr) { - _scene->getPhysicsWorld()->setDebugDraw(!_scene->getPhysicsWorld()->getDebugDraw()); + _scene->getPhysicsWorld()->setDebugDraw(!_scene->getPhysicsWorld()->isDebugDraw()); } #endif } From acbb50b5436c46b2461b4f24883e340be2f3137e Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 17 Sep 2013 16:28:32 +0800 Subject: [PATCH 24/34] issue #2771: edit Xcode project setting. --- samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id index 2fabb28142..a9525c1ccd 100644 --- a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -60e85f9caa5b49a958f331723b961bdfcd0baed9 \ No newline at end of file +6d8e6b3004ee535bfb88fdd9148eb337bb67a3aa \ No newline at end of file From 89ec5edf78c9c49833290c5dfd4b962476c9aeb4 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 17 Sep 2013 16:42:24 +0800 Subject: [PATCH 25/34] issue #2771: edit compile setting. --- tools/tojs/cocos2dx.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index 84d3d8ebc9..82440540cd 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -13,7 +13,7 @@ android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c++ -std=c++11 -cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include +cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/external/chipmunk/include/chipmunk cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common From cdcfda1f2c21771ca158b96bd5df92d100dc7aca Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 17 Sep 2013 12:01:22 +0800 Subject: [PATCH 26/34] issue #2087: [dispatcher] Removing unused codes. --- cocos2dx/platform/CCAccelerometerDelegate.h | 51 ---------------- cocos2dx/platform/android/CCAccelerometer.h | 58 ------------------- .../platform/emscripten/CCAccelerometer.h | 39 ------------- cocos2dx/platform/ios/CCAccelerometer.h | 52 ----------------- cocos2dx/platform/linux/CCAccelerometer.h | 39 ------------- cocos2dx/platform/mac/CCAccelerometer.h | 49 ---------------- cocos2dx/platform/nacl/CCAccelerometer.h | 56 ------------------ cocos2dx/platform/win32/CCAccelerometer.h | 56 ------------------ 8 files changed, 400 deletions(-) delete mode 100644 cocos2dx/platform/CCAccelerometerDelegate.h delete mode 100644 cocos2dx/platform/android/CCAccelerometer.h delete mode 100644 cocos2dx/platform/emscripten/CCAccelerometer.h delete mode 100644 cocos2dx/platform/ios/CCAccelerometer.h delete mode 100644 cocos2dx/platform/linux/CCAccelerometer.h delete mode 100644 cocos2dx/platform/mac/CCAccelerometer.h delete mode 100644 cocos2dx/platform/nacl/CCAccelerometer.h delete mode 100644 cocos2dx/platform/win32/CCAccelerometer.h diff --git a/cocos2dx/platform/CCAccelerometerDelegate.h b/cocos2dx/platform/CCAccelerometerDelegate.h deleted file mode 100644 index 2cb0dafac9..0000000000 --- a/cocos2dx/platform/CCAccelerometerDelegate.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __CCACCELEROMETER_DELEGATE_H__ -#define __CCACCELEROMETER_DELEGATE_H__ - -#include "platform/CCCommon.h" - -NS_CC_BEGIN -/** -@brief The device accelerometer reports values for each axis in units of g-force -*/ -class Acceleration -{ -public: - double x; - double y; - double z; - - double timestamp; - /** - * @js NA - * @lua NA - */ - Acceleration(): x(0), y(0), z(0), timestamp(0) {} -}; - -NS_CC_END - -#endif diff --git a/cocos2dx/platform/android/CCAccelerometer.h b/cocos2dx/platform/android/CCAccelerometer.h deleted file mode 100644 index df6569cb3b..0000000000 --- a/cocos2dx/platform/android/CCAccelerometer.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __PLATFORM_ANDROID_CCACCELEROMETER_H__ -#define __PLATFORM_ANDROID_CCACCELEROMETER_H__ - -#include "platform/CCCommon.h" -#include "platform/CCAccelerometerDelegate.h" -#include - -namespace cocos2d { - -class Accelerometer -{ -public: - /** - * @js ctor - */ - Accelerometer(); - /** - * @js NA - * @lua NA - */ - ~Accelerometer(); - - void setDelegate(std::function function); - void setAccelerometerInterval(float interval); - void update(float x, float y, float z, long sensorTimeStamp); - -private: - std::function _function; - Acceleration _accelerationValue; -}; - -}//namespace cocos2d - -#endif diff --git a/cocos2dx/platform/emscripten/CCAccelerometer.h b/cocos2dx/platform/emscripten/CCAccelerometer.h deleted file mode 100644 index 576b496590..0000000000 --- a/cocos2dx/platform/emscripten/CCAccelerometer.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Accelerometer.h - * - * Created on: Aug 9, 2011 - * Author: laschweinski - */ - -#ifndef CCACCELEROMETER_H_ -#define CCACCELEROMETER_H_ - -#include "platform/CCAccelerometerDelegate.h" -#include - -namespace cocos2d { - -class Accelerometer -{ -public: - /** - * @js ctor - */ - Accelerometer(){} - /** - * @js NA - * @lua NA - */ - ~Accelerometer(){} - - static Accelerometer* sharedAccelerometer() { return NULL; }; - - void removeDelegate(std::function function) {CC_UNUSED_PARAM(function);}; - void addDelegate(std::function function) {CC_UNUSED_PARAM(function);}; - void setDelegate(std::function function) {CC_UNUSED_PARAM(function);}; - void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);}; -}; - -}//namespace cocos2d - -#endif /* CCACCELEROMETER_H_ */ diff --git a/cocos2dx/platform/ios/CCAccelerometer.h b/cocos2dx/platform/ios/CCAccelerometer.h deleted file mode 100644 index f218da6d36..0000000000 --- a/cocos2dx/platform/ios/CCAccelerometer.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __PLATFORM_IPHONE_CCACCELEROMETER_H__ -#define __PLATFORM_IPHONE_CCACCELEROMETER_H__ - -#include -#include "platform/CCAccelerometerDelegate.h" - -NS_CC_BEGIN - -class Accelerometer -{ -public: - /** - * @js ctor - */ - Accelerometer(); - /** - * @js NA - * @lua NA - */ - ~Accelerometer(); - - void setDelegate(std::function function); - void setAccelerometerInterval(float interval); -}; - -NS_CC_END - -#endif diff --git a/cocos2dx/platform/linux/CCAccelerometer.h b/cocos2dx/platform/linux/CCAccelerometer.h deleted file mode 100644 index 576b496590..0000000000 --- a/cocos2dx/platform/linux/CCAccelerometer.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Accelerometer.h - * - * Created on: Aug 9, 2011 - * Author: laschweinski - */ - -#ifndef CCACCELEROMETER_H_ -#define CCACCELEROMETER_H_ - -#include "platform/CCAccelerometerDelegate.h" -#include - -namespace cocos2d { - -class Accelerometer -{ -public: - /** - * @js ctor - */ - Accelerometer(){} - /** - * @js NA - * @lua NA - */ - ~Accelerometer(){} - - static Accelerometer* sharedAccelerometer() { return NULL; }; - - void removeDelegate(std::function function) {CC_UNUSED_PARAM(function);}; - void addDelegate(std::function function) {CC_UNUSED_PARAM(function);}; - void setDelegate(std::function function) {CC_UNUSED_PARAM(function);}; - void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);}; -}; - -}//namespace cocos2d - -#endif /* CCACCELEROMETER_H_ */ diff --git a/cocos2dx/platform/mac/CCAccelerometer.h b/cocos2dx/platform/mac/CCAccelerometer.h deleted file mode 100644 index cf3f9ca945..0000000000 --- a/cocos2dx/platform/mac/CCAccelerometer.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __PLATFORM_MAC_CCACCELEROMETER_H__ -#define __PLATFORM_MAC_CCACCELEROMETER_H__ - -#include -#include "platform/CCAccelerometerDelegate.h" - -NS_CC_BEGIN - -class CC_DLL Accelerometer -{ -public: - Accelerometer() {} - /** - * @js NA - * @lua NA - */ - ~Accelerometer() {} - - void setDelegate(std::function function) { CC_UNUSED_PARAM(function); } - void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);}; -}; - -NS_CC_END - -#endif diff --git a/cocos2dx/platform/nacl/CCAccelerometer.h b/cocos2dx/platform/nacl/CCAccelerometer.h deleted file mode 100644 index a56075c8e3..0000000000 --- a/cocos2dx/platform/nacl/CCAccelerometer.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013 The Chromium Authors - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __CCACCELEROMETER_H__ -#define __CCACCELEROMETER_H__ - -#include "platform/CCAccelerometerDelegate.h" -#include - -namespace cocos2d { - -class Accelerometer -{ -public: - /** - * @js ctor - */ - Accelerometer(){} - /** - * @js NA - * @lua NA - */ - ~Accelerometer(){} - - static Accelerometer* sharedAccelerometer() { return NULL; }; - - void removeDelegate(std::function function) {CC_UNUSED_PARAM(function);}; - void addDelegate(std::function function) {CC_UNUSED_PARAM(function);}; - void setDelegate(std::function function) {CC_UNUSED_PARAM(function);}; - void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);}; -}; - -} - -#endif /* __CCACCELEROMETER_H__ */ diff --git a/cocos2dx/platform/win32/CCAccelerometer.h b/cocos2dx/platform/win32/CCAccelerometer.h deleted file mode 100644 index babb2c284d..0000000000 --- a/cocos2dx/platform/win32/CCAccelerometer.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __PLATFORM_WIN32_UIACCELEROMETER_H__ -#define __PLATFORM_WIN32_UIACCELEROMETER_H__ - -#include "platform/CCAccelerometerDelegate.h" -#include - -NS_CC_BEGIN - -class CC_DLL Accelerometer -{ -public: - /** - * @js ctor - */ - Accelerometer(); - /** - * @js NA - * @lua NA - */ - ~Accelerometer(); - - void setDelegate(std::function function); - void setAccelerometerInterval(float interval); - void update( double x,double y,double z,double timestamp ); -private: - Acceleration _accelerationValue; - std::function _function; -}; - -NS_CC_END - -#endif From 81d8558c3cb0a12eec98e4a5dd4163244d383d36 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 17 Sep 2013 16:35:35 +0800 Subject: [PATCH 27/34] issue #2087: [dispatcher] Removing HANDLE_PRIORITY. --- cocos2dx/include/CCDeprecated.h | 1 - cocos2dx/menu_nodes/CCMenu.h | 5 ----- 2 files changed, 6 deletions(-) diff --git a/cocos2dx/include/CCDeprecated.h b/cocos2dx/include/CCDeprecated.h index 28aae5f779..0e201a9668 100644 --- a/cocos2dx/include/CCDeprecated.h +++ b/cocos2dx/include/CCDeprecated.h @@ -909,7 +909,6 @@ CC_DEPRECATED_ATTRIBUTE typedef ParticleSystem::PositionType tPositionType; #define kCCLabelAutomaticWidth kLabelAutomaticWidth -CC_DEPRECATED_ATTRIBUTE const int kCCMenuHandlerPriority = Menu::HANDLER_PRIORITY; CC_DEPRECATED_ATTRIBUTE const Menu::State kCCMenuStateWaiting = Menu::State::WAITING; CC_DEPRECATED_ATTRIBUTE const Menu::State kCCMenuStateTrackingTouch = Menu::State::TRACKING_TOUCH; diff --git a/cocos2dx/menu_nodes/CCMenu.h b/cocos2dx/menu_nodes/CCMenu.h index 3fc1781baa..966d5ad4f6 100644 --- a/cocos2dx/menu_nodes/CCMenu.h +++ b/cocos2dx/menu_nodes/CCMenu.h @@ -50,11 +50,6 @@ NS_CC_BEGIN class CC_DLL Menu : public LayerRGBA { public: - enum - { - HANDLER_PRIORITY = -128, - }; - enum class State { WAITING, From 111a2ef4dec81415da73754a988640df91d36bee Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 17 Sep 2013 16:59:54 +0800 Subject: [PATCH 28/34] issue #2087: [dispatcher] Fixing BugTest/Bug422 crashes. --- .../event_dispatcher/CCEventDispatcher.cpp | 156 +++++++++++++----- cocos2dx/event_dispatcher/CCEventDispatcher.h | 11 +- 2 files changed, 124 insertions(+), 43 deletions(-) diff --git a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp index cb796bb0a7..c9b6f8718f 100644 --- a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp +++ b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp @@ -58,11 +58,17 @@ private: NS_CC_BEGIN +EventDispatcher::EventListenerItem::~EventListenerItem() +{ + CC_SAFE_RELEASE(this->node); +} + EventDispatcher::EventDispatcher() : _inDispatch(0) , _listeners(nullptr) , _isEnabled(true) { + _toAddedListeners.reserve(50); } EventDispatcher::~EventDispatcher() @@ -82,25 +88,33 @@ void EventDispatcher::addEventListenerWithItem(EventListenerItem* item) _listeners = new std::map*>(); } - std::vector* listenerList = nullptr; - - auto itr = _listeners->find(item->listener->type); - if (itr == _listeners->end()) + if (_inDispatch == 0) { - listenerList = new std::vector(); - listenerList->reserve(100); - _listeners->insert(std::make_pair(item->listener->type, listenerList)); + std::vector* listenerList = nullptr; + + auto itr = _listeners->find(item->listener->type); + if (itr == _listeners->end()) + { + listenerList = new std::vector(); + listenerList->reserve(100); + _listeners->insert(std::make_pair(item->listener->type, listenerList)); + } + else + { + listenerList = itr->second; + } + + listenerList->insert(listenerList->begin(), item); } else { - listenerList = itr->second; + _toAddedListeners.push_back(item); } - - listenerList->insert(listenerList->begin(), item); } void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* listener, Node* node) { + CCASSERT(listener && node, "Invalid parameters."); CCASSERT(!listener->_isRegistered, "The listener has been registered."); if (!listener->checkAvaiable()) @@ -108,6 +122,7 @@ void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* list auto item = new EventListenerItem(); item->node = node; + item->node->retain(); item->fixedPriority = 0; item->listener = listener; item->listener->retain(); @@ -120,6 +135,7 @@ void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* list void EventDispatcher::addEventListenerWithFixedPriority(EventListener* listener, int fixedPriority) { + CCASSERT(listener, "Invalid parameters."); CCASSERT(!listener->_isRegistered, "The listener has been registered."); CCASSERT(fixedPriority != 0, "0 priority is forbidden for fixed priority since it's used for scene graph based priority."); @@ -141,6 +157,8 @@ void EventDispatcher::removeEventListener(EventListener* listener) if (_listeners == nullptr || listener == nullptr) return; + bool isFound = false; + for (auto iter = _listeners->begin(); iter != _listeners->end();) { for (auto itemIter = iter->second->begin(); itemIter != iter->second->end(); ++itemIter) @@ -158,6 +176,7 @@ void EventDispatcher::removeEventListener(EventListener* listener) (*itemIter)->listener = nullptr; } + isFound = true; break; } } @@ -172,6 +191,9 @@ void EventDispatcher::removeEventListener(EventListener* listener) { ++iter; } + + if (isFound) + break; } if (_listeners->empty()) @@ -193,6 +215,9 @@ void EventDispatcher::setPriorityWithSceneGraph(EventListener* listener, Node* n if (item->listener == listener) { item->fixedPriority = 0; + + CC_SAFE_RETAIN(node); + CC_SAFE_RELEASE(item->node); item->node = node; return; } @@ -216,7 +241,7 @@ void EventDispatcher::setPriorityWithFixedValue(EventListener* listener, int fix if (item->node != nullptr) { item->node->dissociateEventListener(listener); - item->node = nullptr; + CC_SAFE_RELEASE_NULL(item->node); } return; } @@ -259,7 +284,7 @@ void EventDispatcher::dispatchEvent(Event* event, bool toSortListeners) } } - removeUnregisteredListeners(); + updateListenerItems(); } void EventDispatcher::dispatchTouchEvent(TouchEvent* event) @@ -331,7 +356,7 @@ void EventDispatcher::dispatchTouchEvent(TouchEvent* event) if (touchEventListener->onTouchBegan) { isClaimed = touchEventListener->onTouchBegan(*touchesIter, event); - if (isClaimed) + if (isClaimed && item->listener) { touchEventListener->_claimedTouches.push_back(*touchesIter); } @@ -355,14 +380,20 @@ void EventDispatcher::dispatchTouchEvent(TouchEvent* event) { touchEventListener->onTouchEnded(*touchesIter, event); } - touchEventListener->_claimedTouches.erase(removedIter); + if (item->listener) + { + touchEventListener->_claimedTouches.erase(removedIter); + } break; case TouchEvent::EventCode::CANCELLED: if (touchEventListener->onTouchCancelled) { touchEventListener->onTouchCancelled(*touchesIter, event); } - touchEventListener->_claimedTouches.erase(removedIter); + if (item->listener) + { + touchEventListener->_claimedTouches.erase(removedIter); + } break; default: CCASSERT(false, "The eventcode is invalid."); @@ -373,13 +404,13 @@ void EventDispatcher::dispatchTouchEvent(TouchEvent* event) // If the event was stopped, return directly. if (event->isStopped()) { - removeUnregisteredListeners(); + updateListenerItems(); return; } CCASSERT((*touchesIter)->getID() == (*mutableTouchesIter)->getID(), ""); - if (isClaimed && touchEventListener->_needSwallow) + if (isClaimed && item->listener && touchEventListener->_needSwallow) { if (isNeedsMutableSet) { @@ -444,16 +475,16 @@ void EventDispatcher::dispatchTouchEvent(TouchEvent* event) // If the event was stopped, return directly. if (event->isStopped()) { - removeUnregisteredListeners(); + updateListenerItems(); return; } } } - removeUnregisteredListeners(); + updateListenerItems(); } -void EventDispatcher::removeUnregisteredListeners() +void EventDispatcher::updateListenerItems() { if (!_listeners) return; @@ -461,17 +492,19 @@ void EventDispatcher::removeUnregisteredListeners() auto listenerItemIter = _listeners->begin(); while (listenerItemIter != _listeners->end()) { - auto removeIterBegin = std::remove_if(listenerItemIter->second->begin(), listenerItemIter->second->end(), [](const EventListenerItem* item){ - return item->listener == nullptr; - }); - - for (auto iter = removeIterBegin; iter != listenerItemIter->second->end(); ++iter) + for (auto iter = listenerItemIter->second->begin(); iter != listenerItemIter->second->end();) { - delete (*iter); + if ((*iter)->listener == nullptr) + { + delete (*iter); + iter = listenerItemIter->second->erase(iter); + } + else + { + ++iter; + } } - listenerItemIter->second->erase(removeIterBegin, listenerItemIter->second->end()); - if (listenerItemIter->second->empty()) { delete listenerItemIter->second; @@ -483,6 +516,29 @@ void EventDispatcher::removeUnregisteredListeners() } } + if (!_toAddedListeners.empty()) + { + std::vector* listenerList = nullptr; + + for (auto& item : _toAddedListeners) + { + auto itr = _listeners->find(item->listener->type); + if (itr == _listeners->end()) + { + listenerList = new std::vector(); + listenerList->reserve(100); + _listeners->insert(std::make_pair(item->listener->type, listenerList)); + } + else + { + listenerList = itr->second; + } + + listenerList->push_back(item); + } + _toAddedListeners.clear(); + } + if (_listeners->empty()) { delete _listeners; @@ -563,14 +619,22 @@ void EventDispatcher::removeListenersForEventType(const std::string& eventType) for (auto iter = listenerItemIter->second->begin(); iter != listenerItemIter->second->end(); ++iter) { (*iter)->listener->release(); - delete (*iter); + if (_inDispatch) + { + (*iter)->listener = nullptr; + } + else + { + delete (*iter); + } } - listenerItemIter->second->clear(); - - delete listenerItemIter->second; - - _listeners->erase(listenerItemIter); + if (!_inDispatch) + { + listenerItemIter->second->clear(); + delete listenerItemIter->second; + _listeners->erase(listenerItemIter); + } } } @@ -584,16 +648,28 @@ void EventDispatcher::removeAllListeners() for (auto iter = listenerItemIter->second->begin(); iter != listenerItemIter->second->end(); ++iter) { (*iter)->listener->release(); - delete (*iter); + if (_inDispatch) + { + (*iter)->listener = nullptr; + } + else + { + delete (*iter); + } } - listenerItemIter->second->clear(); - - delete listenerItemIter->second; + if (!_inDispatch) + { + listenerItemIter->second->clear(); + delete listenerItemIter->second; + } } - delete _listeners; - _listeners = nullptr; + if (!_inDispatch) + { + delete _listeners; + _listeners = nullptr; + } } void EventDispatcher::setEnabled(bool isEnabled) diff --git a/cocos2dx/event_dispatcher/CCEventDispatcher.h b/cocos2dx/event_dispatcher/CCEventDispatcher.h index 621262272b..51aff99973 100644 --- a/cocos2dx/event_dispatcher/CCEventDispatcher.h +++ b/cocos2dx/event_dispatcher/CCEventDispatcher.h @@ -110,6 +110,7 @@ private: int fixedPriority; // The higher the number, the higher the priority Node* node; // Weak reference. EventListener* listener; + ~EventListenerItem(); }; /** Constructor of EventDispatcher */ @@ -127,15 +128,19 @@ private: /** Sorts the listeners of specified type by priority */ void sortAllEventListenerItemsForType(const std::string& eventType); - /** Removes all listeners that have been unregistered. */ - void removeUnregisteredListeners(); + /** Updates all listener items + * 1) Removes all listener items that have been marked as 'removed' when dispatching event. + * 2) Adds all listener items that have been marked as 'added' when dispatching event. + */ + void updateListenerItems(); private: /** * Listeners map. */ std::map*>* _listeners; - + std::vector _toAddedListeners; + int _inDispatch; bool _isEnabled; }; From b5b6406976d5ccaa76db574eb07ec7107667c7ad Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 17 Sep 2013 17:09:07 +0800 Subject: [PATCH 29/34] issue #2771: edit compile setting. --- tools/tojs/cocos2dx_extension.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tojs/cocos2dx_extension.ini b/tools/tojs/cocos2dx_extension.ini index d0554f5314..9056fafb16 100644 --- a/tools/tojs/cocos2dx_extension.ini +++ b/tools/tojs/cocos2dx_extension.ini @@ -13,7 +13,7 @@ android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c++ -std=c++11 -cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/extensions +cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external/chipmunk/include/chipmunk cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common From a454e373c79f9e18030f1d2e20f934ec96ef42fa Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 17 Sep 2013 17:39:08 +0800 Subject: [PATCH 30/34] issue #2771: move include chipmunk and box2d to cpp --- cocos2dx/physics/CCPhysicsBody.cpp | 6 ++++++ cocos2dx/physics/CCPhysicsContact.cpp | 7 +++++++ cocos2dx/physics/CCPhysicsJoint.cpp | 7 +++++++ cocos2dx/physics/CCPhysicsSetting.h | 6 ------ cocos2dx/physics/CCPhysicsShape.cpp | 6 ++++++ cocos2dx/physics/CCPhysicsWorld.cpp | 6 ++++++ cocos2dx/physics/CCPhysicsWorld.h | 6 ++++++ cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.h | 1 + cocos2dx/physics/chipmunk/CCPhysicsContactInfo.h | 1 + cocos2dx/physics/chipmunk/CCPhysicsHelper.h | 1 + cocos2dx/physics/chipmunk/CCPhysicsJointInfo.h | 3 +-- cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.h | 5 +++-- cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.h | 1 + tools/tojs/cocos2dx.ini | 2 +- tools/tojs/cocos2dx_extension.ini | 2 +- 15 files changed, 48 insertions(+), 12 deletions(-) diff --git a/cocos2dx/physics/CCPhysicsBody.cpp b/cocos2dx/physics/CCPhysicsBody.cpp index 655a57eb89..3fb5d485b1 100644 --- a/cocos2dx/physics/CCPhysicsBody.cpp +++ b/cocos2dx/physics/CCPhysicsBody.cpp @@ -26,6 +26,12 @@ #include +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +#include "chipmunk.h" +#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D) +#include "Box2D.h" +#endif + #include "CCPhysicsShape.h" #include "CCPhysicsJoint.h" #include "CCPhysicsWorld.h" diff --git a/cocos2dx/physics/CCPhysicsContact.cpp b/cocos2dx/physics/CCPhysicsContact.cpp index e7c5a8555a..928c8c9e59 100644 --- a/cocos2dx/physics/CCPhysicsContact.cpp +++ b/cocos2dx/physics/CCPhysicsContact.cpp @@ -23,6 +23,13 @@ ****************************************************************************/ #include "CCPhysicsContact.h" #ifdef CC_USE_PHYSICS + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +#include "chipmunk.h" +#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D) +#include "Box2D.h" +#endif + #include "chipmunk/CCPhysicsContactInfo.h" #include "Box2D/CCPhysicsContactInfo.h" diff --git a/cocos2dx/physics/CCPhysicsJoint.cpp b/cocos2dx/physics/CCPhysicsJoint.cpp index 6b57ee2351..3e60d246ab 100644 --- a/cocos2dx/physics/CCPhysicsJoint.cpp +++ b/cocos2dx/physics/CCPhysicsJoint.cpp @@ -24,6 +24,13 @@ #include "CCPhysicsJoint.h" #ifdef CC_USE_PHYSICS + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +#include "chipmunk.h" +#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D) +#include "Box2D.h" +#endif + #include "CCPhysicsBody.h" #include "chipmunk/CCPhysicsJointInfo.h" diff --git a/cocos2dx/physics/CCPhysicsSetting.h b/cocos2dx/physics/CCPhysicsSetting.h index 3d3aaaaf55..98b39f8f66 100644 --- a/cocos2dx/physics/CCPhysicsSetting.h +++ b/cocos2dx/physics/CCPhysicsSetting.h @@ -43,10 +43,4 @@ #define CC_USE_PHYSICS #endif -#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D) -#include "Box2D.h" -#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) -#include "chipmunk.h" -#endif - #endif // __CCPHYSICS_SETTING_H__ diff --git a/cocos2dx/physics/CCPhysicsShape.cpp b/cocos2dx/physics/CCPhysicsShape.cpp index 002c848eff..e98dff0b5c 100644 --- a/cocos2dx/physics/CCPhysicsShape.cpp +++ b/cocos2dx/physics/CCPhysicsShape.cpp @@ -25,6 +25,12 @@ #include "CCPhysicsShape.h" #ifdef CC_USE_PHYSICS +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +#include "chipmunk.h" +#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D) +#include "Box2D.h" +#endif + #include "CCPhysicsBody.h" #include "chipmunk/CCPhysicsBodyInfo.h" diff --git a/cocos2dx/physics/CCPhysicsWorld.cpp b/cocos2dx/physics/CCPhysicsWorld.cpp index d35260d4cb..08857de24b 100644 --- a/cocos2dx/physics/CCPhysicsWorld.cpp +++ b/cocos2dx/physics/CCPhysicsWorld.cpp @@ -25,6 +25,12 @@ #include "CCPhysicsWorld.h" #ifdef CC_USE_PHYSICS +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +#include "chipmunk.h" +#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D) +#include "Box2D.h" +#endif + #include "CCPhysicsBody.h" #include "CCPhysicsShape.h" #include "CCPhysicsContact.h" diff --git a/cocos2dx/physics/CCPhysicsWorld.h b/cocos2dx/physics/CCPhysicsWorld.h index 425a831442..bd06fdf661 100644 --- a/cocos2dx/physics/CCPhysicsWorld.h +++ b/cocos2dx/physics/CCPhysicsWorld.h @@ -31,6 +31,12 @@ #include "cocoa/CCObject.h" #include "cocoa/CCGeometry.h" + +#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) +typedef struct cpArbiter cpArbiter; +typedef struct cpSpace cpSpace; +#endif + NS_CC_BEGIN class PhysicsBody; diff --git a/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.h b/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.h index 796f384584..0faef2eb49 100644 --- a/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.h +++ b/cocos2dx/physics/chipmunk/CCPhysicsBodyInfo.h @@ -27,6 +27,7 @@ #ifndef __CCPHYSICS_BODY_INFO_H__ #define __CCPHYSICS_BODY_INFO_H__ +#include "chipmunk.h" #include "platform/CCPlatformMacros.h" #include "cocoa/CCObject.h" diff --git a/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.h b/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.h index b0d123ae21..5033a2181d 100644 --- a/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.h +++ b/cocos2dx/physics/chipmunk/CCPhysicsContactInfo.h @@ -27,6 +27,7 @@ #ifndef __CCPHYSICS_CONTACT_INFO_H__ #define __CCPHYSICS_CONTACT_INFO_H__ +#include "chipmunk.h" #include "platform/CCPlatformMacros.h" NS_CC_BEGIN diff --git a/cocos2dx/physics/chipmunk/CCPhysicsHelper.h b/cocos2dx/physics/chipmunk/CCPhysicsHelper.h index 07508e9b13..a026d632b7 100644 --- a/cocos2dx/physics/chipmunk/CCPhysicsHelper.h +++ b/cocos2dx/physics/chipmunk/CCPhysicsHelper.h @@ -28,6 +28,7 @@ #ifndef __CCPHYSICS_HELPER_H__ #define __CCPHYSICS_HELPER_H__ +#include "chipmunk.h" #include "platform/CCPlatformMacros.h" #include "cocoa/CCGeometry.h" diff --git a/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.h b/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.h index 4174c866f6..47b1fc6141 100644 --- a/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.h +++ b/cocos2dx/physics/chipmunk/CCPhysicsJointInfo.h @@ -27,9 +27,8 @@ #ifndef __CCPHYSICS_JOINT_INFO_H__ #define __CCPHYSICS_JOINT_INFO_H__ - +#include "chipmunk.h" #include "platform/CCPlatformMacros.h" - NS_CC_BEGIN class PhysicsJointInfo diff --git a/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.h b/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.h index 7114bd3961..7e0be63747 100644 --- a/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.h +++ b/cocos2dx/physics/chipmunk/CCPhysicsShapeInfo.h @@ -27,10 +27,11 @@ #ifndef __CCPHYSICS_SHAPE_INFO_H__ #define __CCPHYSICS_SHAPE_INFO_H__ -#include -#include "platform/CCPlatformMacros.h" +#include #include +#include "chipmunk.h" +#include "platform/CCPlatformMacros.h" NS_CC_BEGIN diff --git a/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.h b/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.h index a1f1e66342..3bc0cf2bc4 100644 --- a/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.h +++ b/cocos2dx/physics/chipmunk/CCPhysicsWorldInfo.h @@ -27,6 +27,7 @@ #ifndef __CCPHYSICS_WORLD_INFO_H__ #define __CCPHYSICS_WORLD_INFO_H__ +#include "chipmunk.h" #include "platform/CCPlatformMacros.h" NS_CC_BEGIN diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index 82440540cd..87551f1c09 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -13,7 +13,7 @@ android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c++ -std=c++11 -cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/external/chipmunk/include/chipmunk +cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common diff --git a/tools/tojs/cocos2dx_extension.ini b/tools/tojs/cocos2dx_extension.ini index 9056fafb16..41ecc9e5a6 100644 --- a/tools/tojs/cocos2dx_extension.ini +++ b/tools/tojs/cocos2dx_extension.ini @@ -13,7 +13,7 @@ android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c++ -std=c++11 -cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external/chipmunk/include/chipmunk +cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/extensions cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common From c0a0dc580abb0bc98cab70ddca1cc2201a5b17e8 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 17 Sep 2013 09:40:09 +0000 Subject: [PATCH 31/34] [AUTO] : updating submodule reference to latest autogenerated bindings --- scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripting/auto-generated b/scripting/auto-generated index f0a368c0f8..558b0d0b08 160000 --- a/scripting/auto-generated +++ b/scripting/auto-generated @@ -1 +1 @@ -Subproject commit f0a368c0f8f9f460ff1ad3d7d876fa6ad29213a0 +Subproject commit 558b0d0b086fc2b5011b49237fa5f49b6d6537f4 From 068d0140d9f5273ed6d201302f8e0d826cb4ef05 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 17 Sep 2013 17:41:53 +0800 Subject: [PATCH 32/34] Manual bind the getDescendants function of the SpriteBatchNode class --- .../cocos2dx_support/LuaBasicConversions.cpp | 22 ------ .../cocos2dx_support/LuaBasicConversions.h | 1 - .../cocos2dx_support/lua_cocos2dx_manual.cpp | 78 ++++++++++++++++++- tools/bindings-generator | 2 +- tools/tolua/cocos2dx.ini | 2 +- 5 files changed, 79 insertions(+), 26 deletions(-) diff --git a/scripting/lua/cocos2dx_support/LuaBasicConversions.cpp b/scripting/lua/cocos2dx_support/LuaBasicConversions.cpp index adc06cea35..1914d3a930 100644 --- a/scripting/lua/cocos2dx_support/LuaBasicConversions.cpp +++ b/scripting/lua/cocos2dx_support/LuaBasicConversions.cpp @@ -1328,25 +1328,3 @@ void dictionary_to_luaval(lua_State* L, Dictionary* dict) } } } - -void std_vector_to_luaval(lua_State* L,const std::vector& inValue) -{ - lua_newtable(L); - - if (inValue.empty()) - return; - - auto iter = inValue.begin(); - int indexTable = 1; - for (; iter != inValue.end(); ++iter) - { - if (nullptr == *iter) - continue; - - lua_pushnumber(L, (lua_Number)indexTable); - toluafix_pushusertype_ccobject(L, (*iter)->_ID, &((*iter)->_luaID), (void*)(*iter),"Sprite"); - lua_rawset(L, -3); - (*iter)->retain(); - ++indexTable; - } -} diff --git a/scripting/lua/cocos2dx_support/LuaBasicConversions.h b/scripting/lua/cocos2dx_support/LuaBasicConversions.h index ace2f0643e..20167170df 100644 --- a/scripting/lua/cocos2dx_support/LuaBasicConversions.h +++ b/scripting/lua/cocos2dx_support/LuaBasicConversions.h @@ -55,5 +55,4 @@ extern void affinetransform_to_luaval(lua_State* L,const AffineTransform& inValu extern void fontdefinition_to_luaval(lua_State* L,const FontDefinition& inValue); extern void array_to_luaval(lua_State* L,Array* inValue); extern void dictionary_to_luaval(lua_State* L, Dictionary* dict); -extern void std_vector_to_luaval(lua_State* L,const std::vector& inValue); #endif //__COCOS2DX_SCRIPTING_LUA_COCOS2DXSUPPORT_LUABAISCCONVERSIONS_H__ diff --git a/scripting/lua/cocos2dx_support/lua_cocos2dx_manual.cpp b/scripting/lua/cocos2dx_support/lua_cocos2dx_manual.cpp index 14dab59467..cb3ab58888 100644 --- a/scripting/lua/cocos2dx_support/lua_cocos2dx_manual.cpp +++ b/scripting/lua/cocos2dx_support/lua_cocos2dx_manual.cpp @@ -2286,6 +2286,70 @@ tolua_lerror: #endif } +static int tolua_cocos2dx_SpriteBatchNode_getDescendants(lua_State* tolua_S) +{ + if (NULL == tolua_S) + return 0; + + int argc = 0; + cocos2d::SpriteBatchNode* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"SpriteBatchNode",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::SpriteBatchNode*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'tolua_cocos2dx_SpriteBatchNode_getDescendants'", NULL); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + return 0; + std::vector ret = cobj->getDescendants(); + + lua_newtable(tolua_S); + + if (ret.empty()) + return 1; + + auto iter = ret.begin(); + int indexTable = 1; + for (; iter != ret.end(); ++iter) + { + if (nullptr == *iter) + continue; + + lua_pushnumber(tolua_S, (lua_Number)indexTable); + toluafix_pushusertype_ccobject(tolua_S, (*iter)->_ID, &((*iter)->_luaID), (void*)(*iter),"Sprite"); + lua_rawset(tolua_S, -3); + (*iter)->retain(); + ++indexTable; + } + + return 1; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getDescendants",argc, 0); + return 0; +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_SpriteBatchNode_getDescendants'.",&tolua_err); +#endif + return 0; +} + static void extendTexture2D(lua_State* tolua_S) { lua_pushstring(tolua_S, "Texture2D"); @@ -2657,6 +2721,18 @@ static void extendUserDefault(lua_State* tolua_S) } } +static void extendSpriteBatchNode(lua_State* tolua_S) +{ + lua_pushstring(tolua_S, "SpriteBatchNode"); + lua_rawget(tolua_S, LUA_REGISTRYINDEX); + if (lua_istable(tolua_S,-1)) + { + lua_pushstring(tolua_S,"getDescendants"); + lua_pushcfunction(tolua_S,tolua_cocos2dx_SpriteBatchNode_getDescendants ); + lua_rawset(tolua_S,-3); + } +} + int register_all_cocos2dx_manual(lua_State* tolua_S) { @@ -2691,6 +2767,6 @@ int register_all_cocos2dx_manual(lua_State* tolua_S) extendUserDefault(tolua_S); extendGLProgram(tolua_S); extendTexture2D(tolua_S); - + extendSpriteBatchNode(tolua_S); return 0; } \ No newline at end of file diff --git a/tools/bindings-generator b/tools/bindings-generator index 9d98b45fcd..2ee36ff842 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit 9d98b45fcdebff58bfe4372266f883cd1a6ce476 +Subproject commit 2ee36ff8423fb0a30817c5278891e4d1667ec68f diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 2a89e7e837..4cff3e48da 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -37,7 +37,7 @@ classes = Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* skip = Node::[setGLServerState description getUserObject .*UserData getGLServerState .*schedule getPosition$], Sprite::[getQuad getBlendFunc ^setPosition$ setBlendFunc], - SpriteBatchNode::[getBlendFunc setBlendFunc], + SpriteBatchNode::[getBlendFunc setBlendFunc getDescendants], MotionStreak::[getBlendFunc setBlendFunc draw update], AtlasNode::[getBlendFunc setBlendFunc], ParticleBatchNode::[getBlendFunc setBlendFunc], From 43e98be8b775709e0e93c33b3240acc772ba5b3d Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 17 Sep 2013 17:46:40 +0800 Subject: [PATCH 33/34] Adding resources of CocoStudio GUI Test. --- samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id index 3206968761..7cc40dd941 100644 --- a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -0859c6e193e305efaec33c21d373b65637f5544e \ No newline at end of file +ff8fe7ad5d9802d094d57853c10fe706d467e0b3 \ No newline at end of file From ddaff9cce6cd63de3c9d5099ecc54f43cc3dd175 Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 17 Sep 2013 19:24:30 +0800 Subject: [PATCH 34/34] make cocos2dx depend chipmunk --- CocosDenshion/android/Android.mk | 3 +-- cocos2dx/Android.mk | 2 ++ samples/Cpp/AssetsManagerTest/proj.android/jni/Android.mk | 2 -- samples/Cpp/HelloCpp/proj.android/jni/Android.mk | 3 +-- samples/Cpp/SimpleGame/proj.android/jni/Android.mk | 3 +-- samples/Cpp/TestCpp/proj.android/jni/Android.mk | 2 -- samples/Javascript/CocosDragonJS/proj.android/jni/Android.mk | 2 -- samples/Javascript/CrystalCraze/proj.android/jni/Android.mk | 2 -- samples/Javascript/MoonWarriors/proj.android/jni/Android.mk | 2 -- samples/Javascript/TestJavascript/proj.android/jni/Android.mk | 2 -- .../Javascript/WatermelonWithMe/proj.android/jni/Android.mk | 2 -- samples/Lua/TestLua/proj.android/jni/Android.mk | 2 -- template/multi-platform-cpp/proj.android/jni/Android.mk | 2 -- template/multi-platform-js/proj.android/jni/Android.mk | 2 -- template/multi-platform-lua/proj.android/jni/Android.mk | 2 -- 15 files changed, 5 insertions(+), 28 deletions(-) diff --git a/CocosDenshion/android/Android.mk b/CocosDenshion/android/Android.mk index 996a07f321..2704964c93 100644 --- a/CocosDenshion/android/Android.mk +++ b/CocosDenshion/android/Android.mk @@ -16,8 +16,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \ $(LOCAL_PATH)/../../cocos2dx \ $(LOCAL_PATH)/../../cocos2dx/include \ $(LOCAL_PATH)/../../cocos2dx/kazmath/include \ - $(LOCAL_PATH)/../../cocos2dx/platform/android \ - $(LOCAL_PATH)/../../external/chipmunk/include/chipmunk + $(LOCAL_PATH)/../../cocos2dx/platform/android LOCAL_CFLAGS += -Wno-psabi LOCAL_EXPORT_CFLAGS += -Wno-psabi diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index 9dddcde603..0033dd4975 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -193,6 +193,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libxml2_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libtiff_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libwebp_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_freetype2_static +LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static # define the macro to compile through support/zip_support/ioapi.c LOCAL_CFLAGS := -Wno-psabi -DUSE_FILE32API @@ -205,3 +206,4 @@ $(call import-module,libpng) $(call import-module,libtiff) $(call import-module,libwebp) $(call import-module,libfreetype2) +$(call import-module,external/chipmunk) diff --git a/samples/Cpp/AssetsManagerTest/proj.android/jni/Android.mk b/samples/Cpp/AssetsManagerTest/proj.android/jni/Android.mk index 5ffbbfbf2f..a85ad02ade 100644 --- a/samples/Cpp/AssetsManagerTest/proj.android/jni/Android.mk +++ b/samples/Cpp/AssetsManagerTest/proj.android/jni/Android.mk @@ -13,7 +13,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += spidermonkey_static LOCAL_WHOLE_STATIC_LIBRARIES += scriptingcore-spidermonkey LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -24,7 +23,6 @@ include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) -$(call import-module,external/chipmunk) $(call import-module,scripting/javascript/spidermonkey-android) $(call import-module,scripting/javascript/bindings) $(call import-module,cocos2dx/platform/android) diff --git a/samples/Cpp/HelloCpp/proj.android/jni/Android.mk b/samples/Cpp/HelloCpp/proj.android/jni/Android.mk index a59a21c7dd..13989f3cf1 100644 --- a/samples/Cpp/HelloCpp/proj.android/jni/Android.mk +++ b/samples/Cpp/HelloCpp/proj.android/jni/Android.mk @@ -12,11 +12,10 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes -LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocos2dxandroid_static cocosdenshion_static chipmunk_static +LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocos2dxandroid_static cocosdenshion_static include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) $(call import-module,cocos2dx/platform/android) -$(call import-module,external/chipmunk) diff --git a/samples/Cpp/SimpleGame/proj.android/jni/Android.mk b/samples/Cpp/SimpleGame/proj.android/jni/Android.mk index d50779e5c4..e3f5b5c1ef 100644 --- a/samples/Cpp/SimpleGame/proj.android/jni/Android.mk +++ b/samples/Cpp/SimpleGame/proj.android/jni/Android.mk @@ -13,7 +13,7 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes -LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocos2dxandroid_static cocosdenshion_static chipmunk_static +LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocos2dxandroid_static cocosdenshion_static include $(BUILD_SHARED_LIBRARY) @@ -21,4 +21,3 @@ $(call import-module,CocosDenshion/android) $(call import-module,cocos2dx) $(call import-module,extensions) $(call import-module,cocos2dx/platform/android) -$(call import-module,external/chipmunk) diff --git a/samples/Cpp/TestCpp/proj.android/jni/Android.mk b/samples/Cpp/TestCpp/proj.android/jni/Android.mk index 210fef8fa1..98de0c8956 100644 --- a/samples/Cpp/TestCpp/proj.android/jni/Android.mk +++ b/samples/Cpp/TestCpp/proj.android/jni/Android.mk @@ -14,7 +14,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := cocos_testcpp_common LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -26,5 +25,4 @@ $(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl) $(call import-module,CocosDenshion/android) $(call import-module,extensions) $(call import-module,external/Box2D) -$(call import-module,external/chipmunk) $(call import-module,cocos2dx/platform/android) diff --git a/samples/Javascript/CocosDragonJS/proj.android/jni/Android.mk b/samples/Javascript/CocosDragonJS/proj.android/jni/Android.mk index d2615a756b..0ab251941c 100644 --- a/samples/Javascript/CocosDragonJS/proj.android/jni/Android.mk +++ b/samples/Javascript/CocosDragonJS/proj.android/jni/Android.mk @@ -13,7 +13,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += spidermonkey_static LOCAL_WHOLE_STATIC_LIBRARIES += scriptingcore-spidermonkey LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -24,7 +23,6 @@ include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) -$(call import-module,external/chipmunk) $(call import-module,scripting/javascript/spidermonkey-android) $(call import-module,scripting/javascript/bindings) $(call import-module,cocos2dx/platform/android) diff --git a/samples/Javascript/CrystalCraze/proj.android/jni/Android.mk b/samples/Javascript/CrystalCraze/proj.android/jni/Android.mk index de9f96689d..12575cad7a 100644 --- a/samples/Javascript/CrystalCraze/proj.android/jni/Android.mk +++ b/samples/Javascript/CrystalCraze/proj.android/jni/Android.mk @@ -13,7 +13,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += spidermonkey_static LOCAL_WHOLE_STATIC_LIBRARIES += scriptingcore-spidermonkey LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -24,7 +23,6 @@ include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) -$(call import-module,external/chipmunk) $(call import-module,scripting/javascript/spidermonkey-android) $(call import-module,scripting/javascript/bindings) $(call import-module,cocos2dx/platform/android) diff --git a/samples/Javascript/MoonWarriors/proj.android/jni/Android.mk b/samples/Javascript/MoonWarriors/proj.android/jni/Android.mk index 5567a3879c..1cdcb62cd6 100644 --- a/samples/Javascript/MoonWarriors/proj.android/jni/Android.mk +++ b/samples/Javascript/MoonWarriors/proj.android/jni/Android.mk @@ -13,7 +13,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += spidermonkey_static LOCAL_WHOLE_STATIC_LIBRARIES += scriptingcore-spidermonkey LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -24,7 +23,6 @@ include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) -$(call import-module,external/chipmunk) $(call import-module,scripting/javascript/spidermonkey-android) $(call import-module,scripting/javascript/bindings) $(call import-module,cocos2dx/platform/android) diff --git a/samples/Javascript/TestJavascript/proj.android/jni/Android.mk b/samples/Javascript/TestJavascript/proj.android/jni/Android.mk index a5e5f60ec0..88ce0ac197 100644 --- a/samples/Javascript/TestJavascript/proj.android/jni/Android.mk +++ b/samples/Javascript/TestJavascript/proj.android/jni/Android.mk @@ -14,7 +14,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += spidermonkey_static LOCAL_WHOLE_STATIC_LIBRARIES += scriptingcore-spidermonkey LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -25,7 +24,6 @@ include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) -$(call import-module,external/chipmunk) $(call import-module,extensions) $(call import-module,scripting/javascript/spidermonkey-android) $(call import-module,scripting/javascript/bindings) diff --git a/samples/Javascript/WatermelonWithMe/proj.android/jni/Android.mk b/samples/Javascript/WatermelonWithMe/proj.android/jni/Android.mk index 33fdf59cf3..76b8e7fd1e 100644 --- a/samples/Javascript/WatermelonWithMe/proj.android/jni/Android.mk +++ b/samples/Javascript/WatermelonWithMe/proj.android/jni/Android.mk @@ -13,7 +13,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += spidermonkey_static LOCAL_WHOLE_STATIC_LIBRARIES += scriptingcore-spidermonkey LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -24,7 +23,6 @@ include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) -$(call import-module,external/chipmunk) $(call import-module,scripting/javascript/spidermonkey-android) $(call import-module,scripting/javascript/bindings) $(call import-module,cocos2dx/platform/android) diff --git a/samples/Lua/TestLua/proj.android/jni/Android.mk b/samples/Lua/TestLua/proj.android/jni/Android.mk index 306ca7e320..189dd81468 100644 --- a/samples/Lua/TestLua/proj.android/jni/Android.mk +++ b/samples/Lua/TestLua/proj.android/jni/Android.mk @@ -18,7 +18,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_lua_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -30,5 +29,4 @@ $(call import-module,scripting/lua/proj.android) $(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl) $(call import-module,extensions) $(call import-module,external/Box2D) -$(call import-module,external/chipmunk) $(call import-module,cocos2dx/platform/android) diff --git a/template/multi-platform-cpp/proj.android/jni/Android.mk b/template/multi-platform-cpp/proj.android/jni/Android.mk index 329ebc0e4f..5430a288ba 100644 --- a/template/multi-platform-cpp/proj.android/jni/Android.mk +++ b/template/multi-platform-cpp/proj.android/jni/Android.mk @@ -15,7 +15,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -26,5 +25,4 @@ $(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl) $(call import-module,CocosDenshion/android) $(call import-module,extensions) $(call import-module,external/Box2D) -$(call import-module,external/chipmunk) $(call import-module,cocos2dx/platform/android) diff --git a/template/multi-platform-js/proj.android/jni/Android.mk b/template/multi-platform-js/proj.android/jni/Android.mk index 2b70298a7c..09cabaea59 100644 --- a/template/multi-platform-js/proj.android/jni/Android.mk +++ b/template/multi-platform-js/proj.android/jni/Android.mk @@ -13,7 +13,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += spidermonkey_static LOCAL_WHOLE_STATIC_LIBRARIES += scriptingcore-spidermonkey LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -24,7 +23,6 @@ include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) -$(call import-module,external/chipmunk) $(call import-module,scripting/javascript/spidermonkey-android) $(call import-module,scripting/javascript/bindings) $(call import-module,cocos2dx/platform/android) diff --git a/template/multi-platform-lua/proj.android/jni/Android.mk b/template/multi-platform-lua/proj.android/jni/Android.mk index 3cab251681..05362699b5 100644 --- a/template/multi-platform-lua/proj.android/jni/Android.mk +++ b/template/multi-platform-lua/proj.android/jni/Android.mk @@ -19,7 +19,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_lua_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static -LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static @@ -31,5 +30,4 @@ $(call import-module,scripting/lua/proj.android) $(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl) $(call import-module,extensions) $(call import-module,external/Box2D) -$(call import-module,external/chipmunk) $(call import-module,cocos2dx/platform/android)