diff --git a/AUTHORS b/AUTHORS index 4dff8c12b5..9357213fb6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -627,6 +627,9 @@ Developers: Fixed a bug that CCBReader can't play sequence automatically in JSB. Could not set next animation in CCBAnimationCompleted callback. + lite3 + Fixed a bug that Node's anchor point was changed after being added to ScrollView. + Retired Core Developers: WenSheng Yang Author of windows port, CCTextField, diff --git a/CHANGELOG b/CHANGELOG index 7b81c3c5f9..567b572bc1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ cocos2d-x-3.0alpha1 @??? 2013 [FIX] Avoid unnecessary object duplication for Scale9Sprite. [FIX] create_project.py does not rename/replace template projects completely. [FIX] Could not set next animation in CCBAnimationCompleted callback. + [FIX] The Node's anchor point was changed after being added to ScrollView. [Android] [FIX] Added EGL_RENDERABLE_TYPE to OpenGL attributes [NEW] Added Cocos2dxHelper.runOnGLThread(Runnable) again diff --git a/cocos/physics/CCPhysicsBody.h b/cocos/physics/CCPhysicsBody.h index 65d9f7318a..f1715b0f1a 100644 --- a/cocos/physics/CCPhysicsBody.h +++ b/cocos/physics/CCPhysicsBody.h @@ -43,7 +43,7 @@ class PhysicsJoint; class PhysicsBodyInfo; -const PhysicsMaterial PHYSICSBODY_MATERIAL_DEFAULT = {1.0f, 1.0f, 1.0f}; +const PhysicsMaterial PHYSICSBODY_MATERIAL_DEFAULT(1.0f, 1.0f, 1.0f); /** * A body affect by physics. diff --git a/cocos/physics/CCPhysicsJoint.cpp b/cocos/physics/CCPhysicsJoint.cpp index fff8665a3c..6cca90dd5b 100644 --- a/cocos/physics/CCPhysicsJoint.cpp +++ b/cocos/physics/CCPhysicsJoint.cpp @@ -70,16 +70,21 @@ bool PhysicsJoint::init(cocos2d::PhysicsBody *a, cocos2d::PhysicsBody *b) { do { - CC_BREAK_IF(a == nullptr || b == nullptr); - CC_BREAK_IF(!(_info = new PhysicsJointInfo(this))); - _bodyA = a; - _bodyA->retain(); - _bodyA->_joints.push_back(this); - _bodyB = b; - _bodyB->retain(); - _bodyB->_joints.push_back(this); + if (a != nullptr) + { + _bodyA = a; + _bodyA->retain(); + _bodyA->_joints.push_back(this); + } + + if (b != nullptr) + { + _bodyB = b; + _bodyB->retain(); + _bodyB->_joints.push_back(this); + } return true; } while (false); diff --git a/cocos/physics/CCPhysicsShape.h b/cocos/physics/CCPhysicsShape.h index ebbe646466..6cd5329f6d 100644 --- a/cocos/physics/CCPhysicsShape.h +++ b/cocos/physics/CCPhysicsShape.h @@ -44,14 +44,20 @@ typedef struct PhysicsMaterial float restitution; float friction; - static PhysicsMaterial make(float density, float restitution, float friction) - { - PhysicsMaterial var = {density, restitution, friction}; - return var; - } + PhysicsMaterial() + : density(0.0f) + , restitution(0.0f) + , friction(0.0f) + {} + + PhysicsMaterial(float density, float restitution, float friction) + : density(density) + , restitution(restitution) + , friction(friction) + {} }PhysicsMaterial; -const PhysicsMaterial PHYSICSSHAPE_MATERIAL_DEFAULT = {0.0f, 1.0f, 1.0f}; +const PhysicsMaterial PHYSICSSHAPE_MATERIAL_DEFAULT(0.0f, 1.0f, 1.0f); /** * @brief A shape for body. You do not create PhysicsWorld objects directly, instead, you can view PhysicsBody to see how to create it. diff --git a/cocos/physics/CCPhysicsWorld.cpp b/cocos/physics/CCPhysicsWorld.cpp index 03495edfb9..9085805e1d 100644 --- a/cocos/physics/CCPhysicsWorld.cpp +++ b/cocos/physics/CCPhysicsWorld.cpp @@ -88,6 +88,7 @@ public: static void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, PhysicsWorld *world); static void rayCastCallbackFunc(cpShape *shape, cpFloat t, cpVect n, RayCastCallbackInfo *info); static void rectQueryCallbackFunc(cpShape *shape, RectQueryCallbackInfo *info); + static void nearestPointQueryFunc(cpShape *shape, cpFloat distance, cpVect point, Array *arr); public: static bool continues; @@ -166,6 +167,15 @@ void PhysicsWorldCallback::rectQueryCallbackFunc(cpShape *shape, RectQueryCallba info->data); } +void PhysicsWorldCallback::nearestPointQueryFunc(cpShape *shape, cpFloat distance, cpVect point, Array *arr) +{ + auto it = PhysicsShapeInfo::map.find(shape); + + CC_ASSERT(it != PhysicsShapeInfo::map.end()); + + arr->addObject(it->second->shape); +} + bool PhysicsWorld::init() { _info = new PhysicsWorldInfo(); @@ -561,9 +571,30 @@ void PhysicsWorld::rectQuery(PhysicsRectQueryCallback& callback, Rect rect, void } } -Array* getShapesAtPoint(Point point) +Array* PhysicsWorld::getShapesAtPoint(Point point) { + Array* arr = Array::create(); + cpSpaceNearestPointQuery(this->_info->space, + PhysicsHelper::point2cpv(point), + 0, + CP_ALL_LAYERS, + CP_NO_GROUP, + (cpSpaceNearestPointQueryFunc)PhysicsWorldCallback::nearestPointQueryFunc, + arr); + return arr; +} + +PhysicsShape* PhysicsWorld::getShapeAtPoint(Point point) +{ + cpShape* shape = cpSpaceNearestPointQueryNearest(this->_info->space, + PhysicsHelper::point2cpv(point), + 0, + CP_ALL_LAYERS, + CP_NO_GROUP, + nullptr); + + return shape == nullptr ? nullptr : PhysicsShapeInfo::map.find(shape)->second->shape; } Array* PhysicsWorld::getAllBody() const diff --git a/cocos/physics/CCPhysicsWorld.h b/cocos/physics/CCPhysicsWorld.h index 868889b539..63c841cc93 100644 --- a/cocos/physics/CCPhysicsWorld.h +++ b/cocos/physics/CCPhysicsWorld.h @@ -98,6 +98,7 @@ public: void rayCast(PhysicsRayCastCallback& callback, Point point1, Point point2, void* data); void rectQuery(PhysicsRectQueryCallback& callback, Rect rect, void* data); Array* getShapesAtPoint(Point point); + PhysicsShape* getShapeAtPoint(Point point); Array* getAllBody() const; /** Register a listener to receive contact callbacks*/ diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index 95b9c48c51..ee6a416310 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -469,8 +469,6 @@ void ScrollView::updateInset() */ void ScrollView::addChild(Node * child, int zOrder, int tag) { - child->ignoreAnchorPointForPosition(false); - child->setAnchorPoint(Point(0.0f, 0.0f)); if (_container != child) { _container->addChild(child, zOrder, tag); } else { diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp index 907a0df83a..f0ceb3553c 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -50,7 +50,7 @@ namespace return layer; } - static const Color4F STATIC_COLOR = {1.0f, 0.0f, 0.0f, 1.0f}; + static const Color4F STATIC_COLOR(1.0f, 0.0f, 0.0f, 1.0f); } @@ -92,6 +92,7 @@ PhysicsDemo::PhysicsDemo() : _scene(nullptr) , _ball(nullptr) , _spriteTexture(nullptr) +, _mouse(nullptr) { } @@ -296,7 +297,8 @@ namespace -25,-8,0,63,-57,-29,-4,-1,-1,-13,-4,127,-64,31,-2,0,15,103,-1,-1,-57,-8,127, -97,-25,-8,0,63,-61,-61,-4,127,-1,-29,-4,127,-64,15,-8,0,0,55,-1,-1,-121,-8, 127,-97,-25,-8,0,63,-61,-61,-4,127,-1,-29,-4,63,-64,15,-32,0,0,23,-1,-2,3,-16, - 63,15,-61,-16,0,31,-127,-127,-8,31,-1,-127,-8,31,-128,7,-128,0,0}; + 63,15,-61,-16,0,31,-127,-127,-8,31,-1,-127,-8,31,-128,7,-128,0,0 + }; static inline int get_pixel(int x, int y) { @@ -365,6 +367,31 @@ Sprite* PhysicsDemo::makeTriangle(float x, float y, Size size, PhysicsMaterial m return triangle; } +void PhysicsDemo::onTouchesBegan(const std::vector& touches, Event* event) +{ + for( auto &touch: touches) + { + auto location = touch->getLocation(); + Array* arr = _scene->getPhysicsWorld()->getShapesAtPoint(location); + + PhysicsShape* shape = nullptr; + for (Object* obj : *arr) + { + + } + } +} + +void PhysicsDemo::onTouchesMoved(const std::vector& touches, Event* event) +{ + +} + +void PhysicsDemo::onTouchesEnded(const std::vector& touches, Event* event) +{ + +} + void PhysicsDemoLogoSmash::onEnter() { PhysicsDemo::onEnter(); @@ -384,7 +411,7 @@ void PhysicsDemoLogoSmash::onEnter() Node* ball = makeBall(2*(x - logo_width/2 + x_jitter) + VisibleRect::getVisibleRect().size.width/2, 2*(logo_height-y + y_jitter) + VisibleRect::getVisibleRect().size.height/2 - logo_height/2, - 0.95f, PhysicsMaterial::make(1.0f, 0.0f, 0.0f)); + 0.95f, PhysicsMaterial(1.0f, 0.0f, 0.0f)); ball->getPhysicsBody()->setMass(1.0); ball->getPhysicsBody()->setMoment(PHYSICS_INFINITY); @@ -396,7 +423,7 @@ void PhysicsDemoLogoSmash::onEnter() } - auto bullet = makeBall(400, 0, 10, PhysicsMaterial::make(PHYSICS_INFINITY, 0, 0)); + auto bullet = makeBall(400, 0, 10, PhysicsMaterial(PHYSICS_INFINITY, 0, 0)); bullet->getPhysicsBody()->setVelocity(Point(400, 0)); bullet->setPosition(Point(-1000, VisibleRect::getVisibleRect().size.height/2)); @@ -427,7 +454,7 @@ void PhysicsDemoPyramidStack::onEnter() { for(int j=0; j<=i; j++) { - addGrossiniAtPosition(VisibleRect::bottom() + Point((i/2 - j) * 11, (14 - i) * 23 + 100), 0.2); + addGrossiniAtPosition(VisibleRect::bottom() + Point((i/2 - j) * 11, (14 - i) * 23 + 100), 0.2f); } } } @@ -644,7 +671,7 @@ void PhysicsDemoRayCast::update(float delta) break; } - _angle += 0.25f * M_PI / 180.0f; + _angle += 0.25f * (float)M_PI / 180.0f; } void PhysicsDemoRayCast::onTouchesEnded(const std::vector& touches, Event* event) @@ -687,18 +714,6 @@ void PhysicsDemoJoints::onEnter() } -void PhysicsDemoJoints::onTouchesEnded(const std::vector& touches, Event* event) -{ - //Add a new body/atlas sprite at the touched location - - for( auto &touch: touches) - { - auto location = touch->getLocation(); - - - } -} - std::string PhysicsDemoJoints::title() { return "Joints"; diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h index 9df12624de..0c685ef98e 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h @@ -37,13 +37,18 @@ public: void toggleDebugCallback(Object* sender); void addGrossiniAtPosition(Point p, float scale = 1.0); - Sprite* makeBall(float x, float y, float radius, PhysicsMaterial material = {1.0f, 1.0f, 1.0f}); - Sprite* makeBox(float x, float y, Size size, PhysicsMaterial material = {1.0f, 1.0f, 1.0f}); - Sprite* makeTriangle(float x, float y, Size size, PhysicsMaterial material = {1.0f, 1.0f, 1.0f}); + Sprite* makeBall(float x, float y, float radius, PhysicsMaterial material = PhysicsMaterial(1.0f, 1.0f, 1.0f)); + Sprite* makeBox(float x, float y, Size size, PhysicsMaterial material = PhysicsMaterial(1.0f, 1.0f, 1.0f)); + Sprite* makeTriangle(float x, float y, Size size, PhysicsMaterial material = PhysicsMaterial(1.0f, 1.0f, 1.0f)); + + void onTouchesBegan(const std::vector& touches, Event* event) override; + void onTouchesMoved(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event) override; protected: Texture2D* _spriteTexture; // weak ref SpriteBatchNode* _ball; + DrawNode* _mouse; }; class PhysicsDemoClickAdd : public PhysicsDemo @@ -99,10 +104,15 @@ private: class PhysicsDemoJoints : public PhysicsDemo { +public: + PhysicsDemoJoints(); + public: void onEnter() override; std::string title() override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + +private: + PhysicsShape* _touchesShape; }; #endif diff --git a/tools/tojs/cocos2dx_builder.ini b/tools/tojs/cocos2dx_builder.ini new file mode 100644 index 0000000000..15de5f54d8 --- /dev/null +++ b/tools/tojs/cocos2dx_builder.ini @@ -0,0 +1,65 @@ +[cocos2dx_builder] +# the prefix to be added to the generated functions. You might or might not use this in your own +# templates +prefix = cocos2dx_builder + +# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) +# all classes will be embedded in that namespace +target_namespace = cc + +android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include +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/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s + +cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT + +cxxgenerator_headers = + +# extra arguments for clang +extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s + +# what headers to parse +headers = %(cocosdir)s/cocos/editor-support/cocosbuilder/CocosBuilder.h + +# what classes to produce code for. You can use regular expressions here. When testing the regular +# expression, it will be enclosed in "^$", like this: "^Menu*$". +classes = CCBReader.* CCBAnimationManager.* + +# what should we skip? in the format ClassName::[function function] +# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also +# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just +# add a single "*" as functions. See bellow for several examples. A special class name is "*", which +# will apply to all class names. This is a convenience wildcard to be able to skip similar named +# functions from all classes. + +skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getCCBMemberVariableAssigner readFloat getCCBSelectorResolver toLowerCase lastPathComponent deletePathExtension endsWith concat getResolutionScale getAnimatedProperties readBool readInt addOwnerCallbackNode addDocumentCallbackName readCachedString readNodeGraphFromData addDocumentCallbackNode getLoadedSpriteSheet initWithData readFileWithCleanUp getOwner$ readNodeGraphFromFile createSceneWithNodeGraphFromFile getAnimationManagers$ setAnimationManagers], + CCBAnimationManager::[setAnimationCompletedCallback], + .*Delegate::[*], + .*Loader.*::[*], + *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV onTouch.* onAcc.* onKey.* onRegisterTouchListener] + +rename_functions = + +rename_classes = CCBReader::_Reader, + CCBAnimationManager::BuilderAnimationManager + +# for all class names, should we remove something when registering in the target VM? +remove_prefix = + +# classes for which there will be no "parent" lookup +classes_have_no_parents = + +# base classes which will be skipped when their sub-classes found them. +base_classes_to_skip = Object + +# classes that create no constructor +# Set is special and we will use a hand-written constructor +abstract_classes = + +# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. +script_control_cpp = no + diff --git a/tools/tojs/cocos2dx_studio.ini b/tools/tojs/cocos2dx_studio.ini new file mode 100644 index 0000000000..47859dac3f --- /dev/null +++ b/tools/tojs/cocos2dx_studio.ini @@ -0,0 +1,65 @@ +[cocos2dx_studio] +# the prefix to be added to the generated functions. You might or might not use this in your own +# templates +prefix = cocos2dx_studio + +# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) +# all classes will be embedded in that namespace +target_namespace = cc + +android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include +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/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s + +cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT + +cxxgenerator_headers = + +# extra arguments for clang +extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s + +# what headers to parse +headers = %(cocosdir)s/cocos/editor-support/cocostudio/CocoStudio.h + +# what classes to produce code for. You can use regular expressions here. When testing the regular +# expression, it will be enclosed in "^$", like this: "^Menu*$". +classes = Armature ArmatureAnimation Skin Bone ArmatureDataManager + +# what should we skip? in the format ClassName::[function function] +# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also +# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just +# add a single "*" as functions. See bellow for several examples. A special class name is "*", which +# will apply to all class names. This is a convenience wildcard to be able to skip similar named +# functions from all classes. + +skip = .*Delegate::[*], + .*Loader.*::[*], + *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV onTouch.* onAcc.* onKey.* onRegisterTouchListener], + Armature::[createBone updateBlendType getBody setBody getShapeList .*BlendFunc], + Skin::[getSkinData setSkinData], + ArmatureAnimation::[updateHandler updateFrameData frameEvent] + +rename_functions = + +rename_classes = + +# for all class names, should we remove something when registering in the target VM? +remove_prefix = + +# classes for which there will be no "parent" lookup +classes_have_no_parents = + +# base classes which will be skipped when their sub-classes found them. +base_classes_to_skip = Object ProcessBase + +# classes that create no constructor +# Set is special and we will use a hand-written constructor +abstract_classes = ArmatureDataManager + +# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. +script_control_cpp = no +