From f5795c25b6d8f1c6f30b0fe127c9575ee0c1beff Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 24 Mar 2014 10:12:40 +0800 Subject: [PATCH 01/18] remove warnings under win32 --- cocos/2d/CCEventDispatcher.cpp | 2 +- cocos/2d/CCFontFreeType.cpp | 2 +- cocos/2d/CCTMXLayer.cpp | 2 +- cocos/2d/cocos2d.vcxproj | 4 ++- .../cocostudio/CCActionNode.cpp | 6 ++-- cocos/editor-support/cocostudio/CCSkin.cpp | 4 +-- cocos/ui/UIRichText.cpp | 6 ++-- .../CocoStudioArmatureTest/ArmatureScene.cpp | 2 +- .../CustomWidget/CustomImageView.cpp | 2 +- .../CustomWidget/CustomParticleWidget.cpp | 2 +- .../UILayoutTest/UILayoutTest_Editor.cpp | 36 +++++++++---------- .../UIListViewTest/UIListViewTest_Editor.cpp | 8 ++--- .../UIPageViewTest/UIPageViewTest_Editor.cpp | 4 +-- .../UIRichTextTest/UIRichTextTest.cpp | 4 +-- .../UIScrollViewTest_Editor.cpp | 12 +++---- .../UITextFieldTest/UITextFieldTest.cpp | 4 +-- .../UIWidgetAddNodeTest_Editor.cpp | 2 +- .../CocoStudioSceneTest/TriggerCode/acts.cpp | 8 ++--- .../CocoStudioSceneTest/TriggerCode/cons.cpp | 2 +- .../Classes/PhysicsTest/PhysicsTest.cpp | 18 +++++----- .../RenderTextureTest/RenderTextureTest.cpp | 24 ++++++------- .../SpriteTest/SpriteTest.cpp.REMOVED.git-id | 2 +- .../Classes/TileMapTest/TileMapTest.cpp | 8 ++--- .../Classes/ZwoptexTest/ZwoptexTest.cpp | 4 +-- tests/cpp-tests/proj.win32/cpp-tests.vcxproj | 14 +++++--- 25 files changed, 95 insertions(+), 87 deletions(-) mode change 100755 => 100644 tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp mode change 100755 => 100644 tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp diff --git a/cocos/2d/CCEventDispatcher.cpp b/cocos/2d/CCEventDispatcher.cpp index 6dedb2f3cb..6b12aa58e1 100644 --- a/cocos/2d/CCEventDispatcher.cpp +++ b/cocos/2d/CCEventDispatcher.cpp @@ -590,7 +590,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, c // priority < 0 if (fixedPriorityListeners) { - CCASSERT(listeners->getGt0Index() <= fixedPriorityListeners->size(), "Out of range exception!"); + CCASSERT(listeners->getGt0Index() <= static_cast(fixedPriorityListeners->size()), "Out of range exception!"); if (!fixedPriorityListeners->empty()) { diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index caaf2eb6ba..19aace6e9c 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -388,7 +388,7 @@ unsigned char * makeDistanceMap( unsigned char *img, long width, long height) double * data = (double *) calloc( pixelAmount, sizeof(double) ); double * outside = (double *) calloc( pixelAmount, sizeof(double) ); double * inside = (double *) calloc( pixelAmount, sizeof(double) ); - unsigned int i,j; + long i,j; // Convert img into double (data) rescale image levels between 0 and 1 long outWidth = width + 2 * FontFreeType::DistanceMapSpread; diff --git a/cocos/2d/CCTMXLayer.cpp b/cocos/2d/CCTMXLayer.cpp index 1007dd9585..983d7e9d14 100644 --- a/cocos/2d/CCTMXLayer.cpp +++ b/cocos/2d/CCTMXLayer.cpp @@ -492,7 +492,7 @@ void TMXLayer::setTileGID(uint32_t gid, const Point& pos, TMXTileFlags flags) { CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position"); CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released"); - CCASSERT(gid == 0 || gid >= _tileSet->_firstGid, "TMXLayer: invalid gid" ); + CCASSERT(gid == 0 || (int)gid >= _tileSet->_firstGid, "TMXLayer: invalid gid" ); TMXTileFlags currentFlags; uint32_t currentGID = getTileGIDAt(pos, ¤tFlags); diff --git a/cocos/2d/cocos2d.vcxproj b/cocos/2d/cocos2d.vcxproj index b491f0fd9d..7f9a6fb1ff 100644 --- a/cocos/2d/cocos2d.vcxproj +++ b/cocos/2d/cocos2d.vcxproj @@ -317,7 +317,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou - + + 4267;4996;4251;4244;%(DisableSpecificWarnings) + diff --git a/cocos/editor-support/cocostudio/CCActionNode.cpp b/cocos/editor-support/cocostudio/CCActionNode.cpp index d615b11c46..2ef5097230 100644 --- a/cocos/editor-support/cocostudio/CCActionNode.cpp +++ b/cocos/editor-support/cocostudio/CCActionNode.cpp @@ -241,7 +241,7 @@ void ActionNode::insertFrame(int index, ActionFrame* frame) return; } int frameType = frame->getFrameType(); - if(frameType < _frameArray.size()) + if(frameType < (int)_frameArray.size()) { auto cArray = _frameArray.at(frameType); cArray->insert(index, frame); @@ -256,7 +256,7 @@ void ActionNode::addFrame(ActionFrame* frame) } int frameType = frame->getFrameType(); - if(frameType < _frameArray.size()) + if(frameType < (int)_frameArray.size()) { auto cArray = _frameArray.at(frameType); cArray->pushBack(frame); @@ -270,7 +270,7 @@ void ActionNode::deleteFrame(ActionFrame* frame) return; } int frameType = frame->getFrameType(); - if(frameType < _frameArray.size()) + if(frameType < (int)_frameArray.size()) { auto cArray = _frameArray.at(frameType); cArray->eraseObject(frame); diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index 4d153f5baf..259eb4af6d 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -126,8 +126,8 @@ void Skin::setSkinData(const BaseData &var) setScaleX(_skinData.scaleX); setScaleY(_skinData.scaleY); - setRotationX(CC_RADIANS_TO_DEGREES(_skinData.skewX)); - setRotationY(CC_RADIANS_TO_DEGREES(-_skinData.skewY)); + setRotationSkewX(CC_RADIANS_TO_DEGREES(_skinData.skewX)); + setRotationSkewY(CC_RADIANS_TO_DEGREES(-_skinData.skewY)); setPosition(Point(_skinData.x, _skinData.y)); _skinTransform = getNodeToParentTransform(); diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index 3c33e33beb..c1684259a4 100644 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -340,7 +340,7 @@ void RichText::formarRenderers() float newContentSizeHeight = 0.0f; float *maxHeights = new float[_elementRenders.size()]; - for (ssize_t i=0; i<_elementRenders.size(); i++) + for (size_t i=0; i<_elementRenders.size(); i++) { Vector* row = (_elementRenders[i]); float maxHeight = 0.0f; @@ -355,7 +355,7 @@ void RichText::formarRenderers() float nextPosY = _customSize.height; - for (ssize_t i=0; i<_elementRenders.size(); i++) + for (size_t i=0; i<_elementRenders.size(); i++) { Vector* row = (_elementRenders[i]); float nextPosX = 0.0f; @@ -375,7 +375,7 @@ void RichText::formarRenderers() } size_t length = _elementRenders.size(); - for (ssize_t i = 0; i* l = _elementRenders[i]; l->clear(); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index e1043b8dc5..32f624d1ab 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -1040,7 +1040,7 @@ void TestColliderDetector::update(float delta) float minx = 0, miny = 0, maxx = 0, maxy = 0; size_t length = vertexList.size(); - for (int i = 0; iremoveFromParent(); _emitter = ParticleSystemQuad::create(plist); } - Node::addChild(_emitter , getZOrder() + 1, -1); + Node::addChild(_emitter , getLocalZOrder() + 1, -1); _emitterPlist = plist; } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp index 5780b30a08..9c78795fe5 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp @@ -39,7 +39,7 @@ bool UILayoutTest_Editor::init() left_button->getSize().height)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -47,7 +47,7 @@ bool UILayoutTest_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -94,7 +94,7 @@ bool UILayoutTest_Color_Editor::init() left_button->getSize().height)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -102,7 +102,7 @@ bool UILayoutTest_Color_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -149,7 +149,7 @@ bool UILayoutTest_Gradient_Editor::init() left_button->getSize().height)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -157,7 +157,7 @@ bool UILayoutTest_Gradient_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -204,7 +204,7 @@ bool UILayoutTest_BackGroundImage_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -212,7 +212,7 @@ bool UILayoutTest_BackGroundImage_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -259,7 +259,7 @@ bool UILayoutTest_BackGroundImage_Scale9_Editor::init() left_button->getSize().height)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -267,7 +267,7 @@ bool UILayoutTest_BackGroundImage_Scale9_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -314,7 +314,7 @@ bool UILayoutTest_Layout_Linear_Vertical_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -322,7 +322,7 @@ bool UILayoutTest_Layout_Linear_Vertical_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -369,7 +369,7 @@ bool UILayoutTest_Layout_Linear_Horizontal_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -377,7 +377,7 @@ bool UILayoutTest_Layout_Linear_Horizontal_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -425,7 +425,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -433,7 +433,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -480,7 +480,7 @@ bool UILayoutTest_Layout_Relative_Location_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -488,7 +488,7 @@ bool UILayoutTest_Layout_Relative_Location_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp index 83cfeccd19..89c2954979 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp @@ -42,7 +42,7 @@ bool UIListViewTest_Vertical_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -50,7 +50,7 @@ bool UIListViewTest_Vertical_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -98,7 +98,7 @@ bool UIListViewTest_Horizontal_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -106,7 +106,7 @@ bool UIListViewTest_Horizontal_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); return true; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp index 743b5fc1f7..427b847820 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp @@ -40,7 +40,7 @@ bool UIPageViewTest_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -48,7 +48,7 @@ bool UIPageViewTest_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index afd0e47ba8..f0f33e7afd 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -36,7 +36,7 @@ bool UIRichTextTest::init() button->setTitleText("switch"); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getSize().height * 2.5)); button->addTouchEventListener(this, toucheventselector(UIRichTextTest::touchEvent)); - button->setZOrder(10); + button->setLocalZOrder(10); _widget->addChild(button); @@ -69,7 +69,7 @@ bool UIRichTextTest::init() _richText->pushBackElement(re6); _richText->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2)); - _richText->setZOrder(10); + _richText->setLocalZOrder(10); _widget->addChild(_richText); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp index d9a0d53e55..d3d7077f2d 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp @@ -39,7 +39,7 @@ bool UIScrollViewTest_Vertical_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -47,7 +47,7 @@ bool UIScrollViewTest_Vertical_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -94,7 +94,7 @@ bool UIScrollViewTest_Horizontal_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -102,7 +102,7 @@ bool UIScrollViewTest_Horizontal_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); @@ -149,7 +149,7 @@ bool UIScrollViewTest_Both_Editor::init() left_button->getSize().height * 0.625)); left_button->setTouchEnabled(true); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); - left_button->setZOrder(_layout->getZOrder() + 1); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(left_button); Button* right_button = Button::create(); @@ -157,7 +157,7 @@ bool UIScrollViewTest_Both_Editor::init() right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->getSize().height * 0.625)); right_button->setTouchEnabled(true); - right_button->setZOrder(_layout->getZOrder() + 1); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); _layout->addChild(right_button); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp index b65d499f76..d50b5afc9b 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp @@ -336,7 +336,7 @@ void UITextFieldTest_LineWrap::textFieldEvent(Ref *pSender, TextFiledEventType t { TextField* textField = dynamic_cast(pSender); Size widgetSize = _widget->getSize(); - textField->runAction(CCMoveTo::create(0.225, + textField->runAction(CCMoveTo::create(0.225f, Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + textField->getContentSize().height / 2))); textField->setTextHorizontalAlignment(TextHAlignment::LEFT); textField->setTextVerticalAlignment(TextVAlignment::TOP); @@ -349,7 +349,7 @@ void UITextFieldTest_LineWrap::textFieldEvent(Ref *pSender, TextFiledEventType t { TextField* textField = dynamic_cast(pSender); Size widgetSize = _widget->getSize(); - textField->runAction(CCMoveTo::create(0.175, Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f))); + textField->runAction(CCMoveTo::create(0.175f, Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f))); textField->setTextHorizontalAlignment(TextHAlignment::CENTER); textField->setTextVerticalAlignment(TextVAlignment::CENTER); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp index 6bc4101250..ba0ae2baf1 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp @@ -37,7 +37,7 @@ bool UIWidgetAddNodeTest_Editor::init() // Create the ui widget Widget* widget = Widget::create(); widget->setPosition(Point(rootSize.width / 2.0f, rootSize.height / 2.0f)); - widget->setZOrder(_layout->getZOrder() + 1); + widget->setLocalZOrder(_layout->getLocalZOrder() + 1); _layout->addChild(widget); Sprite* sprite = Sprite::create("cocosui/ccicon.png"); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp old mode 100755 new mode 100644 index 4449d2cd9d..4e29ed3236 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp @@ -199,7 +199,7 @@ void TMoveBy::serialize(const rapidjson::Value &val) } else if (key == "IsReverse") { - _reverse = (bool)(DICTOOL->getIntValue_json(subDict, "value")); + _reverse = DICTOOL->getIntValue_json(subDict, "value") ? true : false; continue; } } @@ -337,7 +337,7 @@ void TRotateBy::serialize(const rapidjson::Value &val) } else if (key == "IsReverse") { - _reverse = (int)(DICTOOL->getIntValue_json(subDict, "value")); + _reverse = (DICTOOL->getIntValue_json(subDict, "value")) ? true : false; continue; } } @@ -483,7 +483,7 @@ void TScaleBy::serialize(const rapidjson::Value &val) } else if (key == "IsReverse") { - _reverse = (bool)(DICTOOL->getIntValue_json(subDict, "value")); + _reverse = (DICTOOL->getIntValue_json(subDict, "value")) ? true : false; continue; } } @@ -629,7 +629,7 @@ void TSkewBy::serialize(const rapidjson::Value &val) } else if (key == "IsReverse") { - _reverse = (bool)(DICTOOL->getIntValue_json(subDict, "value")); + _reverse = DICTOOL->getIntValue_json(subDict, "value") ? true : false; } } } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp old mode 100755 new mode 100644 index ea2f3a3971..e0f402d587 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp @@ -255,7 +255,7 @@ void NodeVisible::serialize(const rapidjson::Value &val) } else if (key == "Visible") { - _visible = DICTOOL->getIntValue_json(subDict, "value"); + _visible = DICTOOL->getIntValue_json(subDict, "value") ? true : false; continue; } } diff --git a/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.cpp b/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.cpp index 013718db01..a94052cac4 100644 --- a/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.cpp +++ b/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.cpp @@ -844,7 +844,7 @@ void PhysicsDemoJoints::onEnter() _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); - PhysicsJointRotaryLimit* joint = PhysicsJointRotaryLimit::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f, M_PI_2); + PhysicsJointRotaryLimit* joint = PhysicsJointRotaryLimit::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f,(float) M_PI_2); _scene->getPhysicsWorld()->addJoint(joint); this->addChild(sp1); @@ -860,7 +860,7 @@ void PhysicsDemoJoints::onEnter() _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); - PhysicsJointRatchet* joint = PhysicsJointRatchet::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f, M_PI_2); + PhysicsJointRatchet* joint = PhysicsJointRatchet::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f, (float)M_PI_2); _scene->getPhysicsWorld()->addJoint(joint); this->addChild(sp1); @@ -892,7 +892,7 @@ void PhysicsDemoJoints::onEnter() _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); - PhysicsJointMotor* joint = PhysicsJointMotor::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), M_PI_2); + PhysicsJointMotor* joint = PhysicsJointMotor::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), (float)M_PI_2); _scene->getPhysicsWorld()->addJoint(joint); this->addChild(sp1); @@ -1444,7 +1444,7 @@ void PhysicsContactTest::resetTest() label->setPosition(Point(s.width/2, s.height-170)); auto wall = Node::create(); - wall->setPhysicsBody(PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size, PhysicsMaterial(0.1, 1, 0.0))); + wall->setPhysicsBody(PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size, PhysicsMaterial(0.1f, 1, 0.0f))); wall->setPosition(VisibleRect::center()); root->addChild(wall); @@ -1462,7 +1462,7 @@ void PhysicsContactTest::resetTest() position.y = position.y * CCRANDOM_0_1(); position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2); Vect velocity((CCRANDOM_0_1() - 0.5)*200, (CCRANDOM_0_1() - 0.5)*200); - auto box = makeBox(position, size, 1, PhysicsMaterial(0.1, 1, 0.0)); + auto box = makeBox(position, size, 1, PhysicsMaterial(0.1f, 1, 0.0f)); box->getPhysicsBody()->setVelocity(velocity); box->getPhysicsBody()->setCategoryBitmask(0x01); // 0001 box->getPhysicsBody()->setContactTestBitmask(0x04); // 0100 @@ -1480,7 +1480,7 @@ void PhysicsContactTest::resetTest() position.y = position.y * CCRANDOM_0_1(); position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2); Vect velocity((CCRANDOM_0_1() - 0.5)*200, (CCRANDOM_0_1() - 0.5)*200); - auto box = makeBox(position, size, 2, PhysicsMaterial(0.1, 1, 0.0)); + auto box = makeBox(position, size, 2, PhysicsMaterial(0.1f, 1, 0.0f)); box->getPhysicsBody()->setVelocity(velocity); box->getPhysicsBody()->setCategoryBitmask(0x02); // 0010 box->getPhysicsBody()->setContactTestBitmask(0x08); // 1000 @@ -1498,7 +1498,7 @@ void PhysicsContactTest::resetTest() position.y = position.y * CCRANDOM_0_1(); position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2); Vect velocity((CCRANDOM_0_1() - 0.5)*300, (CCRANDOM_0_1() - 0.5)*300); - auto triangle = makeTriangle(position, size, 1, PhysicsMaterial(0.1, 1, 0.0)); + auto triangle = makeTriangle(position, size, 1, PhysicsMaterial(0.1f, 1, 0.0f)); triangle->getPhysicsBody()->setVelocity(velocity); triangle->getPhysicsBody()->setCategoryBitmask(0x04); // 0100 triangle->getPhysicsBody()->setContactTestBitmask(0x01); // 0001 @@ -1516,7 +1516,7 @@ void PhysicsContactTest::resetTest() position.y = position.y * CCRANDOM_0_1(); position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2); Vect velocity((CCRANDOM_0_1() - 0.5)*300, (CCRANDOM_0_1() - 0.5)*300); - auto triangle = makeTriangle(position, size, 2, PhysicsMaterial(0.1, 1, 0.0)); + auto triangle = makeTriangle(position, size, 2, PhysicsMaterial(0.1f, 1, 0.0f)); triangle->getPhysicsBody()->setVelocity(velocity); triangle->getPhysicsBody()->setCategoryBitmask(0x08); // 1000 triangle->getPhysicsBody()->setContactTestBitmask(0x02); // 0010 @@ -1565,7 +1565,7 @@ void PhysicsPositionRotationTest::onEnter() // anchor test auto anchorNode = Sprite::create("Images/YellowSquare.png"); - anchorNode->setAnchorPoint(Point(0.1, 0.9)); + anchorNode->setAnchorPoint(Point(0.1f, 0.9f)); anchorNode->setPosition(100, 100); anchorNode->setScale(0.25); anchorNode->setPhysicsBody(PhysicsBody::createBox(anchorNode->getContentSize()*anchorNode->getScale())); diff --git a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp index b817ed6701..49e5848a08 100644 --- a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -314,9 +314,9 @@ RenderTextureZbuffer::RenderTextureZbuffer() label3->setPosition(Point(size.width / 2, size.height * 0.75f)); this->addChild(label3); - label->setVertexZ(50); - label2->setVertexZ(0); - label3->setVertexZ(-50); + label->setPositionZ(50); + label2->setPositionZ(0); + label3->setPositionZ(-50); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/bugs/circle.plist"); mgr = SpriteBatchNode::create("Images/bugs/circle.png", 9); @@ -341,15 +341,15 @@ RenderTextureZbuffer::RenderTextureZbuffer() mgr->addChild(sp8, 2); mgr->addChild(sp9, 1); - sp1->setVertexZ(400); - sp2->setVertexZ(300); - sp3->setVertexZ(200); - sp4->setVertexZ(100); - sp5->setVertexZ(0); - sp6->setVertexZ(-100); - sp7->setVertexZ(-200); - sp8->setVertexZ(-300); - sp9->setVertexZ(-400); + sp1->setPositionZ(400); + sp2->setPositionZ(300); + sp3->setPositionZ(200); + sp4->setPositionZ(100); + sp5->setPositionZ(0); + sp6->setPositionZ(-100); + sp7->setPositionZ(-200); + sp8->setPositionZ(-300); + sp9->setPositionZ(-400); sp9->setScale(2); sp9->setColor(Color3B::YELLOW); diff --git a/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id b/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id index b98c1b9d46..ac73085b6b 100644 --- a/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id +++ b/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id @@ -1 +1 @@ -4bb0b2a6151e4910ea662bedd91a5be655ec05d1 \ No newline at end of file +4d17613c96e30631ec5da21b2629fa3d0fc39f2d \ No newline at end of file diff --git a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp index ecad3ef353..4b26ddbe49 100644 --- a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp +++ b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp @@ -285,7 +285,7 @@ TMXOrthoTest::TMXOrthoTest() Size CC_UNUSED s = map->getContentSize(); CCLOG("ContentSize: %f, %f", s.width,s.height); - auto scale = ScaleBy::create(10, 0.1); + auto scale = ScaleBy::create(10, 0.1f); auto back = scale->reverse(); auto seq = Sequence::create(scale, back, NULL); auto repeat = RepeatForever::create(seq); @@ -1086,7 +1086,7 @@ void TMXIsoVertexZ::repositionSprite(float dt) auto p = _tamara->getPosition(); p = CC_POINT_POINTS_TO_PIXELS(p); float newZ = -(p.y+32) /16; - _tamara->setVertexZ( newZ ); + _tamara->setPositionZ( newZ ); } void TMXIsoVertexZ::onEnter() @@ -1132,7 +1132,7 @@ TMXOrthoVertexZ::TMXOrthoVertexZ() // can use any Sprite and it will work OK. auto layer = map->getLayer("trees"); _tamara = layer->getTileAt(Point(0,11)); - CCLOG("%p vertexZ: %f", _tamara, _tamara->getVertexZ()); + CCLOG("%p vertexZ: %f", _tamara, _tamara->getPositionZ()); _tamara->retain(); auto move = MoveBy::create(10, Point(400,450) * (1/CC_CONTENT_SCALE_FACTOR())); @@ -1155,7 +1155,7 @@ void TMXOrthoVertexZ::repositionSprite(float dt) // map size: 12x12 auto p = _tamara->getPosition(); p = CC_POINT_POINTS_TO_PIXELS(p); - _tamara->setVertexZ( -( (p.y+81) /81) ); + _tamara->setPositionZ( -( (p.y+81) /81) ); } void TMXOrthoVertexZ::onEnter() diff --git a/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.cpp b/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.cpp index 6687de06da..25a44638ed 100644 --- a/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.cpp +++ b/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.cpp @@ -185,8 +185,8 @@ void ZwoptexGenericTest::flipSprites(float dt) char str2[32] = {0}; sprintf(str1, "grossini_dance_%02d.png", spriteFrameIndex); sprintf(str2, "grossini_dance_generic_%02d.png", spriteFrameIndex); - sprite1->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str1)); - sprite2->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str2)); + sprite1->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str1)); + sprite2->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str2)); } ZwoptexGenericTest::~ZwoptexGenericTest() diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index 172ef28da3..12c78bf5ff 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -153,8 +153,12 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou - - + + 4267;4251;4068;4244;%(DisableSpecificWarnings) + + + 4267;4251;4244;4068;%(DisableSpecificWarnings) + @@ -209,7 +213,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou - + + 4267;4251;4244;4819;%(DisableSpecificWarnings) + @@ -583,4 +589,4 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou - + \ No newline at end of file From 4a974e24df252e2fb00266681cf6f03a7ccccb6b Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 24 Mar 2014 10:50:48 +0800 Subject: [PATCH 02/18] revert vcxproj files --- cocos/2d/cocos2d.vcxproj | 4 +--- tests/cpp-tests/proj.win32/cpp-tests.vcxproj | 14 ++++---------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/cocos/2d/cocos2d.vcxproj b/cocos/2d/cocos2d.vcxproj index 7f9a6fb1ff..b491f0fd9d 100644 --- a/cocos/2d/cocos2d.vcxproj +++ b/cocos/2d/cocos2d.vcxproj @@ -317,9 +317,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou - - 4267;4996;4251;4244;%(DisableSpecificWarnings) - + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index 12c78bf5ff..172ef28da3 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -153,12 +153,8 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou - - 4267;4251;4068;4244;%(DisableSpecificWarnings) - - - 4267;4251;4244;4068;%(DisableSpecificWarnings) - + + @@ -213,9 +209,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou - - 4267;4251;4244;4819;%(DisableSpecificWarnings) - + @@ -589,4 +583,4 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou - \ No newline at end of file + From 538c01e76ee8035a1183a95493ea3fcd1e79fdc5 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 24 Mar 2014 14:16:27 +0800 Subject: [PATCH 03/18] label:support clip blank of upper and lower margin. --- cocos/2d/CCFontAtlas.cpp | 4 +++ cocos/2d/CCFontAtlas.h | 2 ++ cocos/2d/CCLabel.cpp | 2 ++ cocos/2d/CCLabel.h | 6 ++++ cocos/2d/CCLabelTextFormatter.cpp | 50 ++++++++++++++++++++++++++++++- 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 3e40e41419..11f9998d6c 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -231,6 +231,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) auto pixelFormat = fontTTf->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8; bool existNewLetter = false; + int bottomHeight = _commonLineHeight - _fontAscender; + for (int i = 0; i < length; ++i) { auto outIterator = _fontLetterDefinitions.find(utf16String[i]); @@ -248,6 +250,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) tempDef.height = tempRect.size.height + _letterPadding; tempDef.offsetX = tempRect.origin.x + offsetAdjust; tempDef.offsetY = _fontAscender + tempRect.origin.y - offsetAdjust; + tempDef.clipBottom = bottomHeight - (tempDef.height + tempRect.origin.y + offsetAdjust); if (_currentPageOrigX + tempDef.width > CacheTextureWidth) { @@ -290,6 +293,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) tempDef.offsetX = 0; tempDef.offsetY = 0; tempDef.textureID = 0; + tempDef.clipBottom = 0; _currentPageOrigX += 1; } diff --git a/cocos/2d/CCFontAtlas.h b/cocos/2d/CCFontAtlas.h index 2d3eb615a3..a10fe9eb9f 100644 --- a/cocos/2d/CCFontAtlas.h +++ b/cocos/2d/CCFontAtlas.h @@ -50,6 +50,8 @@ struct FontLetterDefinition int textureID; bool validDefinition; int xAdvance; + + int clipBottom; }; class CC_DLL FontAtlas : public Ref diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 3d6bc68508..644ceeec06 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -339,6 +339,8 @@ void Label::reset() _textColor = Color4B::WHITE; _textColorF = Color4F::WHITE; setColor(Color3B::WHITE); + + _clipEnabled = false; } void Label::updateShaderProgram() diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 93130c4e10..dc9271d8ab 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -217,6 +217,10 @@ public: virtual Sprite * getLetter(int lettetIndex); + /** clip upper and lower margin for reduce height of label. + */ + void setClipMarginEnabled(bool clipEnabled) { _clipEnabled = clipEnabled; } + // font related stuff int getCommonLineHeight() const; @@ -365,6 +369,8 @@ protected: Color4B _textColor; Color4F _textColorF; + bool _clipEnabled; + private: CC_DISALLOW_COPY_AND_ASSIGN(Label); diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index 9f0efe1eaa..119456caa6 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -321,6 +321,16 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) FontLetterDefinition tempDefinition; Point letterPosition; const auto& kernings = theLabel->_horizontalKernings; + + float clipTop = 0; + float clipBottom = 0; + int lineIndex = 0; + bool lineStart = true; + bool clip = false; + if (theLabel->_currentLabelType == Label::LabelType::TTF && theLabel->_clipEnabled) + { + clip = true; + } for (unsigned int i = 0; i < stringLen; i++) { @@ -337,9 +347,10 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) charYOffset = -1; charAdvance = -1; } - + if (c == '\n') { + lineIndex++; nextFontPositionX = 0; nextFontPositionY -= theLabel->_commonLineHeight; @@ -347,8 +358,30 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) if(nextFontPositionY < theLabel->_commonLineHeight) break; + lineStart = true; continue; } + else if (clip && tempDefinition.height > 0.0f) + { + if (lineStart) + { + if (lineIndex == 0) + { + clipTop = charYOffset; + } + lineStart = false; + clipBottom = tempDefinition.clipBottom; + } + else if(tempDefinition.clipBottom < clipBottom) + { + clipBottom = tempDefinition.clipBottom; + } + + if (lineIndex == 0 && charYOffset < clipTop) + { + clipTop = charYOffset; + } + } letterPosition.x = (nextFontPositionX + charXOffset + kernings[i]) / contentScaleFactor; letterPosition.y = (nextFontPositionY - charYOffset) / contentScaleFactor; @@ -382,11 +415,26 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) } tmpSize.height = totalHeight; + if (theLabel->_labelHeight > 0) { tmpSize.height = theLabel->_labelHeight * contentScaleFactor; } + + if (clip) + { + int clipTotal = (clipTop + clipBottom) / contentScaleFactor; + tmpSize.height -= clipTotal * contentScaleFactor; + clipBottom /= contentScaleFactor; + + for (int i = 0; i < theLabel->_limitShowCount; i++) + { + theLabel->_lettersInfo[i].position.y -= clipBottom; + } + } + theLabel->setContentSize(CC_SIZE_PIXELS_TO_POINTS(tmpSize)); + return true; } From 19341ceaf42fe3bbb8fed7e9ca8a6f08d58bab8c Mon Sep 17 00:00:00 2001 From: LinWenhai Date: Tue, 25 Mar 2014 14:54:42 +0800 Subject: [PATCH 04/18] add getter of ClipMarginEnabled. --- cocos/2d/CCLabel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index dc9271d8ab..c453112cb4 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -220,7 +220,7 @@ public: /** clip upper and lower margin for reduce height of label. */ void setClipMarginEnabled(bool clipEnabled) { _clipEnabled = clipEnabled; } - + bool getClipMarginEnabled() const { return _clipEnabled; } // font related stuff int getCommonLineHeight() const; From bdcd6ea198117700d6183bc1593896fcd62bbc4f Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 25 Mar 2014 08:13:42 +0000 Subject: [PATCH 05/18] [AUTO]: updating luabinding automatically --- .../lua-bindings/auto/api/RichText.lua | 5 + .../lua-bindings/auto/api/ScrollView.lua | 86 +++------- .../lua-bindings/auto/api/Widget.lua | 159 +++--------------- .../lua_cocos2dx_ui_auto.cpp.REMOVED.git-id | 2 +- .../auto/lua_cocos2dx_ui_auto.hpp | 6 - 5 files changed, 57 insertions(+), 201 deletions(-) diff --git a/cocos/scripting/lua-bindings/auto/api/RichText.lua b/cocos/scripting/lua-bindings/auto/api/RichText.lua index 3c181b3a2d..b14dcddf9e 100644 --- a/cocos/scripting/lua-bindings/auto/api/RichText.lua +++ b/cocos/scripting/lua-bindings/auto/api/RichText.lua @@ -52,6 +52,11 @@ -- @param self -- @return RichText#RichText ret (return value: ccui.RichText) +-------------------------------- +-- @function [parent=#RichText] getDescription +-- @param self +-- @return string#string ret (return value: string) + -------------------------------- -- @function [parent=#RichText] RichText -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua index 66b3f739f6..b5532e0192 100644 --- a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua +++ b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua @@ -187,58 +187,22 @@ -- @param #int int -- @param #int int +-------------------------------- +-- @function [parent=#ScrollView] getChildByName +-- @param self +-- @param #char char +-- @return Widget#Widget ret (return value: ccui.Widget) + -------------------------------- -- @function [parent=#ScrollView] getDescription -- @param self -- @return string#string ret (return value: string) -------------------------------- --- @function [parent=#ScrollView] removeAllChildren +-- @function [parent=#ScrollView] update -- @param self +-- @param #float float --------------------------------- --- overload function: getChildren() --- --- overload function: getChildren() --- --- @function [parent=#ScrollView] getChildren --- @param self --- @return array_table#array_table ret (retunr value: array_table) - --------------------------------- --- @function [parent=#ScrollView] getNodes --- @param self --- @return array_table#array_table ret (return value: array_table) - --------------------------------- --- @function [parent=#ScrollView] getChildByTag --- @param self --- @param #int int --- @return Node#Node ret (return value: cc.Node) - --------------------------------- --- @function [parent=#ScrollView] removeNode --- @param self --- @param #cc.Node node - --------------------------------- --- @function [parent=#ScrollView] removeNodeByTag --- @param self --- @param #int int - --------------------------------- --- overload function: addNode(cc.Node, int) --- --- overload function: addNode(cc.Node) --- --- overload function: addNode(cc.Node, int, int) --- --- @function [parent=#ScrollView] addNode --- @param self --- @param #cc.Node node --- @param #int int --- @param #int int - -------------------------------- -- @function [parent=#ScrollView] getLayoutType -- @param self @@ -250,24 +214,7 @@ -- @param #bool bool -------------------------------- --- @function [parent=#ScrollView] update --- @param self --- @param #float float - --------------------------------- --- @function [parent=#ScrollView] getNodeByTag --- @param self --- @param #int int --- @return Node#Node ret (return value: cc.Node) - --------------------------------- --- @function [parent=#ScrollView] getChildByName --- @param self --- @param #char char --- @return Widget#Widget ret (return value: ccui.Widget) - --------------------------------- --- @function [parent=#ScrollView] removeAllNodes +-- @function [parent=#ScrollView] removeAllChildren -- @param self -------------------------------- @@ -276,6 +223,21 @@ -- @param #cc.Node node -- @param #bool bool +-------------------------------- +-- overload function: getChildren() +-- +-- overload function: getChildren() +-- +-- @function [parent=#ScrollView] getChildren +-- @param self +-- @return array_table#array_table ret (retunr value: array_table) + +-------------------------------- +-- @function [parent=#ScrollView] getChildByTag +-- @param self +-- @param #int int +-- @return Node#Node ret (return value: cc.Node) + -------------------------------- -- @function [parent=#ScrollView] getChildrenCount -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/Widget.lua b/cocos/scripting/lua-bindings/auto/api/Widget.lua index 5bea038c34..1f97832c9f 100644 --- a/cocos/scripting/lua-bindings/auto/api/Widget.lua +++ b/cocos/scripting/lua-bindings/auto/api/Widget.lua @@ -1,18 +1,13 @@ -------------------------------- -- @module Widget --- @extend Node +-- @extend ProtectedNode -------------------------------- -- @function [parent=#Widget] setSizePercent -- @param self -- @param #point_table point --------------------------------- --- @function [parent=#Widget] isFlippedX --- @param self --- @return bool#bool ret (return value: bool) - -------------------------------- -- @function [parent=#Widget] getCustomSize -- @param self @@ -29,10 +24,9 @@ -- @param #bool bool -------------------------------- --- @function [parent=#Widget] getNodeByTag +-- @function [parent=#Widget] getLeftInParent -- @param self --- @param #int int --- @return Node#Node ret (return value: cc.Node) +-- @return float#float ret (return value: float) -------------------------------- -- @function [parent=#Widget] getTouchEndPos @@ -44,11 +38,6 @@ -- @param self -- @param #point_table point --------------------------------- --- @function [parent=#Widget] getNodes --- @param self --- @return array_table#array_table ret (return value: array_table) - -------------------------------- -- @function [parent=#Widget] getLayoutSize -- @param self @@ -69,15 +58,6 @@ -- @param self -- @return bool#bool ret (return value: bool) --------------------------------- --- overload function: updateSizeAndPosition(size_table) --- --- overload function: updateSizeAndPosition() --- --- @function [parent=#Widget] updateSizeAndPosition --- @param self --- @param #size_table size - -------------------------------- -- @function [parent=#Widget] getBottomInParent -- @param self @@ -100,9 +80,9 @@ -- @return PositionType#PositionType ret (return value: ccui.PositionType) -------------------------------- --- @function [parent=#Widget] setName +-- @function [parent=#Widget] getWidgetType -- @param self --- @param #char char +-- @return WidgetType#WidgetType ret (return value: ccui.WidgetType) -------------------------------- -- @function [parent=#Widget] getChildByName @@ -116,9 +96,9 @@ -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#Widget] removeNodeByTag +-- @function [parent=#Widget] isFocused -- @param self --- @param #int int +-- @return bool#bool ret (return value: bool) -------------------------------- -- @function [parent=#Widget] isTouchEnabled @@ -175,18 +155,10 @@ -- @param #ccui.BrightStyle brightstyle -------------------------------- --- overload function: addNode(cc.Node, int) --- --- overload function: addNode(cc.Node) --- --- overload function: addNode(cc.Node, int, int) --- --- @function [parent=#Widget] addNode +-- @function [parent=#Widget] setName -- @param self --- @param #cc.Node node --- @param #int int --- @param #int int - +-- @param #char char + -------------------------------- -- @function [parent=#Widget] setLayoutParameter -- @param self @@ -202,21 +174,11 @@ -- @param self -- @return point_table#point_table ret (return value: point_table) --------------------------------- --- @function [parent=#Widget] getLeftInParent --- @param self --- @return float#float ret (return value: float) - -------------------------------- -- @function [parent=#Widget] setActionTag -- @param self -- @param #int int --------------------------------- --- @function [parent=#Widget] ignoreContentAdaptWithSize --- @param self --- @param #bool bool - -------------------------------- -- @function [parent=#Widget] isBright -- @param self @@ -234,10 +196,14 @@ -- @return float#float ret (return value: float) -------------------------------- --- @function [parent=#Widget] getWidgetType +-- overload function: updateSizeAndPosition(size_table) +-- +-- overload function: updateSizeAndPosition() +-- +-- @function [parent=#Widget] updateSizeAndPosition -- @param self --- @return WidgetType#WidgetType ret (return value: ccui.WidgetType) - +-- @param #size_table size + -------------------------------- -- @function [parent=#Widget] getSize -- @param self @@ -254,13 +220,9 @@ -- @return SizeType#SizeType ret (return value: ccui.SizeType) -------------------------------- --- @function [parent=#Widget] removeNode --- @param self --- @param #cc.Node node - --------------------------------- --- @function [parent=#Widget] removeAllNodes +-- @function [parent=#Widget] ignoreContentAdaptWithSize -- @param self +-- @param #bool bool -------------------------------- -- @function [parent=#Widget] getPositionPercent @@ -274,7 +236,7 @@ -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#Widget] isFocused +-- @function [parent=#Widget] isFlippedX -- @param self -- @return bool#bool ret (return value: bool) @@ -310,72 +272,11 @@ -- @param self -- @return Widget#Widget ret (return value: ccui.Widget) --------------------------------- --- overload function: addChild(cc.Node, int) --- --- overload function: addChild(cc.Node) --- --- overload function: addChild(cc.Node, int, int) --- --- @function [parent=#Widget] addChild --- @param self --- @param #cc.Node node --- @param #int int --- @param #int int - -------------------------------- -- @function [parent=#Widget] setColor -- @param self -- @param #color3B_table color3b --------------------------------- --- @function [parent=#Widget] removeFromParent --- @param self - --------------------------------- --- @function [parent=#Widget] removeAllChildrenWithCleanup --- @param self --- @param #bool bool - --------------------------------- --- @function [parent=#Widget] removeAllChildren --- @param self - --------------------------------- --- @function [parent=#Widget] sortAllChildren --- @param self - --------------------------------- --- @function [parent=#Widget] removeChild --- @param self --- @param #cc.Node node --- @param #bool bool - --------------------------------- --- overload function: getChildren() --- --- overload function: getChildren() --- --- @function [parent=#Widget] getChildren --- @param self --- @return array_table#array_table ret (retunr value: array_table) - --------------------------------- --- @function [parent=#Widget] getDescription --- @param self --- @return string#string ret (return value: string) - --------------------------------- --- @function [parent=#Widget] getChildByTag --- @param self --- @param #int int --- @return Node#Node ret (return value: cc.Node) - --------------------------------- --- @function [parent=#Widget] removeFromParentAndCleanup --- @param self --- @param #bool bool - -------------------------------- -- @function [parent=#Widget] getColor -- @param self @@ -386,26 +287,20 @@ -- @param self -- @param #unsigned char char --------------------------------- --- @function [parent=#Widget] setPosition --- @param self --- @param #point_table point - --------------------------------- --- @function [parent=#Widget] removeChildByTag --- @param self --- @param #int int --- @param #bool bool - -------------------------------- -- @function [parent=#Widget] getOpacity -- @param self -- @return unsigned char#unsigned char ret (return value: unsigned char) -------------------------------- --- @function [parent=#Widget] getChildrenCount +-- @function [parent=#Widget] setPosition -- @param self --- @return long#long ret (return value: long) +-- @param #point_table point + +-------------------------------- +-- @function [parent=#Widget] getDescription +-- @param self +-- @return string#string ret (return value: string) -------------------------------- -- @function [parent=#Widget] Widget diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id index 104c65729e..e024e99b59 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id @@ -1 +1 @@ -11bba6be0cebc89eb4c7195a61d021e51719468f \ No newline at end of file +19adb2eb5a08b20b670b77975f7e30c08bbac2d6 \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp index 1e576402ce..3a1b0bb858 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp @@ -362,12 +362,6 @@ int register_all_cocos2dx_ui(lua_State* tolua_S); - - - - - - From c37584ee5c4b568598f5ff11298a7019399d887b Mon Sep 17 00:00:00 2001 From: koowolf <450928375@qq.com> Date: Tue, 25 Mar 2014 16:14:21 +0800 Subject: [PATCH 06/18] closed #4542: fix crash in win32(delete mutex while still lock) --- cocos/network/WebSocket.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cocos/network/WebSocket.cpp b/cocos/network/WebSocket.cpp index 4ba4b708a0..4e98591d24 100644 --- a/cocos/network/WebSocket.cpp +++ b/cocos/network/WebSocket.cpp @@ -187,16 +187,19 @@ void WsThreadHelper::update(float dt) WsMessage *msg = nullptr; // Returns quickly if no message - std::lock_guard lk(_UIWsMessageQueueMutex); + _UIWsMessageQueueMutex.lock(); if (0 == _UIWsMessageQueue->size()) { + _UIWsMessageQueueMutex.unlock(); return; } // Gets message msg = *(_UIWsMessageQueue->begin()); _UIWsMessageQueue->pop_front(); + + _UIWsMessageQueueMutex.unlock(); if (_ws) { From d6ad9274c4341fac0f7581cfd10853dca026b3f7 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Tue, 25 Mar 2014 16:19:34 +0800 Subject: [PATCH 07/18] closed #2880, Generate mipmap for the texture has mipmaps when reload textures. --- cocos/2d/CCTexture2D.cpp | 3 +++ cocos/2d/CCTextureCache.cpp | 9 +++++++++ cocos/2d/CCTextureCache.h | 2 ++ tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp | 1 + 4 files changed, 15 insertions(+) diff --git a/cocos/2d/CCTexture2D.cpp b/cocos/2d/CCTexture2D.cpp index a43563d862..564298eca3 100644 --- a/cocos/2d/CCTexture2D.cpp +++ b/cocos/2d/CCTexture2D.cpp @@ -1199,6 +1199,9 @@ void Texture2D::generateMipmap() GL::bindTexture2D( _name ); glGenerateMipmap(GL_TEXTURE_2D); _hasMipmaps = true; +#if CC_ENABLE_CACHE_TEXTURE_DATA + VolatileTextureMgr::setHasMipmaps(this, _hasMipmaps); +#endif } bool Texture2D::hasMipmaps() const diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index 0e7bd4f647..38ef71f31a 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -635,6 +635,12 @@ void VolatileTextureMgr::addStringTexture(Texture2D *tt, const char* text, const vt->_fontDefinition = fontDefinition; } +void VolatileTextureMgr::setHasMipmaps(Texture2D *t, bool hasMipmaps) +{ + VolatileTexture *vt = findVolotileTexture(t); + vt->_hasMipmaps = hasMipmaps; +} + void VolatileTextureMgr::setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams) { VolatileTexture *vt = findVolotileTexture(t); @@ -717,6 +723,9 @@ void VolatileTextureMgr::reloadAllTextures() default: break; } + if (vt->_hasMipmaps) { + vt->_texture->generateMipmap(); + } vt->_texture->setTexParameters(vt->_texParams); } diff --git a/cocos/2d/CCTextureCache.h b/cocos/2d/CCTextureCache.h index 8ebd4821b5..39b1a8e957 100644 --- a/cocos/2d/CCTextureCache.h +++ b/cocos/2d/CCTextureCache.h @@ -251,6 +251,7 @@ protected: std::string _fileName; + bool _hasMipmaps; Texture2D::TexParams _texParams; std::string _text; FontDefinition _fontDefinition; @@ -264,6 +265,7 @@ public: static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize); static void addImage(Texture2D *tt, Image *image); + static void setHasMipmaps(Texture2D *t, bool hasMipmaps); static void setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams); static void removeTexture(Texture2D *t); static void reloadAllTextures(); diff --git a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp index 4f80334657..05e2fc128a 100644 --- a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp +++ b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp @@ -38,6 +38,7 @@ static std::function createFunctions[] = { CL(TexturePVRv3Premult), + CL(TextureMipMap), CL(TextureMemoryAlloc), CL(TextureAlias), CL(TexturePVRMipMap), From e65315d01e2617653afb177dfe61ba3a4c7ab004 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 25 Mar 2014 08:22:13 +0000 Subject: [PATCH 08/18] [AUTO][ci skip]: updating cocos2dx_files.json --- templates/cocos2dx_files.json.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/cocos2dx_files.json.REMOVED.git-id b/templates/cocos2dx_files.json.REMOVED.git-id index 1c31d78c7e..089a8e7561 100644 --- a/templates/cocos2dx_files.json.REMOVED.git-id +++ b/templates/cocos2dx_files.json.REMOVED.git-id @@ -1 +1 @@ -9be9de64b36c123c9aba99c3149937136749b712 \ No newline at end of file +d53bc7d6e68a49984c5971344f59bba8414d142b \ No newline at end of file From bb190fe78ac2fdb7343f0cadfe7dcfcda9d92724 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 Mar 2014 16:24:08 +0800 Subject: [PATCH 09/18] [ci] Updates travis scripts. --- tools/travis-scripts/generate-bindings.sh | 7 +++++-- tools/travis-scripts/generate-cocosfiles.sh | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/travis-scripts/generate-bindings.sh b/tools/travis-scripts/generate-bindings.sh index 19978804e3..d586e61d09 100755 --- a/tools/travis-scripts/generate-bindings.sh +++ b/tools/travis-scripts/generate-bindings.sh @@ -23,6 +23,7 @@ ELAPSEDSECS=`date +%s` COCOS_BRANCH="update_lua_bindings_$ELAPSEDSECS" COCOS_ROBOT_REMOTE="https://${GH_USER}:${GH_PASSWORD}@github.com/${GH_USER}/cocos2d-x.git" PULL_REQUEST_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" +FETCH_REMOTE_BRANCH="develop" # Exit on error set -e @@ -88,12 +89,14 @@ pushd "$PROJECT_ROOT" git status echo -echo Comparing with HEAD ... +echo Comparing with origin HEAD ... echo +git fetch origin ${FETCH_REMOTE_BRANCH} + # Don't exit on non-zero return value set +e -git diff --stat --exit-code +git diff FETCH_HEAD --stat --exit-code DIFF_RETVAL=$? if [ $DIFF_RETVAL -eq 0 ] diff --git a/tools/travis-scripts/generate-cocosfiles.sh b/tools/travis-scripts/generate-cocosfiles.sh index 1014bc303e..ec43dc8300 100755 --- a/tools/travis-scripts/generate-cocosfiles.sh +++ b/tools/travis-scripts/generate-cocosfiles.sh @@ -6,6 +6,7 @@ PROJECT_ROOT="$DIR"/../.. COMMITTAG="[AUTO][ci skip]: updating cocos2dx_files.json" PUSH_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" OUTPUT_FILE_PATH="${PROJECT_ROOT}/templates/cocos2dx_files.json" +FETCH_REMOTE_BRANCH="develop" # Exit on error set -e @@ -51,12 +52,14 @@ pushd "$PROJECT_ROOT" git status echo -echo Comparing with HEAD ... +echo Comparing with origin HEAD ... echo +git fetch origin ${FETCH_REMOTE_BRANCH} + # Don't exit on non-zero return value set +e -git diff --stat --exit-code +git diff FETCH_HEAD --stat --exit-code DIFF_RETVAL=$? if [ $DIFF_RETVAL -eq 0 ] From 81cc05729c28eb492c58f1b28a4624efbc0b704c Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 25 Mar 2014 08:26:13 +0000 Subject: [PATCH 10/18] [AUTO]: updating luabinding automatically --- .../lua-bindings/auto/api/RichText.lua | 5 + .../lua-bindings/auto/api/ScrollView.lua | 86 +++------- .../lua-bindings/auto/api/Widget.lua | 159 +++--------------- .../lua_cocos2dx_ui_auto.cpp.REMOVED.git-id | 2 +- .../auto/lua_cocos2dx_ui_auto.hpp | 6 - 5 files changed, 57 insertions(+), 201 deletions(-) diff --git a/cocos/scripting/lua-bindings/auto/api/RichText.lua b/cocos/scripting/lua-bindings/auto/api/RichText.lua index 3c181b3a2d..b14dcddf9e 100644 --- a/cocos/scripting/lua-bindings/auto/api/RichText.lua +++ b/cocos/scripting/lua-bindings/auto/api/RichText.lua @@ -52,6 +52,11 @@ -- @param self -- @return RichText#RichText ret (return value: ccui.RichText) +-------------------------------- +-- @function [parent=#RichText] getDescription +-- @param self +-- @return string#string ret (return value: string) + -------------------------------- -- @function [parent=#RichText] RichText -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua index 66b3f739f6..b5532e0192 100644 --- a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua +++ b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua @@ -187,58 +187,22 @@ -- @param #int int -- @param #int int +-------------------------------- +-- @function [parent=#ScrollView] getChildByName +-- @param self +-- @param #char char +-- @return Widget#Widget ret (return value: ccui.Widget) + -------------------------------- -- @function [parent=#ScrollView] getDescription -- @param self -- @return string#string ret (return value: string) -------------------------------- --- @function [parent=#ScrollView] removeAllChildren +-- @function [parent=#ScrollView] update -- @param self +-- @param #float float --------------------------------- --- overload function: getChildren() --- --- overload function: getChildren() --- --- @function [parent=#ScrollView] getChildren --- @param self --- @return array_table#array_table ret (retunr value: array_table) - --------------------------------- --- @function [parent=#ScrollView] getNodes --- @param self --- @return array_table#array_table ret (return value: array_table) - --------------------------------- --- @function [parent=#ScrollView] getChildByTag --- @param self --- @param #int int --- @return Node#Node ret (return value: cc.Node) - --------------------------------- --- @function [parent=#ScrollView] removeNode --- @param self --- @param #cc.Node node - --------------------------------- --- @function [parent=#ScrollView] removeNodeByTag --- @param self --- @param #int int - --------------------------------- --- overload function: addNode(cc.Node, int) --- --- overload function: addNode(cc.Node) --- --- overload function: addNode(cc.Node, int, int) --- --- @function [parent=#ScrollView] addNode --- @param self --- @param #cc.Node node --- @param #int int --- @param #int int - -------------------------------- -- @function [parent=#ScrollView] getLayoutType -- @param self @@ -250,24 +214,7 @@ -- @param #bool bool -------------------------------- --- @function [parent=#ScrollView] update --- @param self --- @param #float float - --------------------------------- --- @function [parent=#ScrollView] getNodeByTag --- @param self --- @param #int int --- @return Node#Node ret (return value: cc.Node) - --------------------------------- --- @function [parent=#ScrollView] getChildByName --- @param self --- @param #char char --- @return Widget#Widget ret (return value: ccui.Widget) - --------------------------------- --- @function [parent=#ScrollView] removeAllNodes +-- @function [parent=#ScrollView] removeAllChildren -- @param self -------------------------------- @@ -276,6 +223,21 @@ -- @param #cc.Node node -- @param #bool bool +-------------------------------- +-- overload function: getChildren() +-- +-- overload function: getChildren() +-- +-- @function [parent=#ScrollView] getChildren +-- @param self +-- @return array_table#array_table ret (retunr value: array_table) + +-------------------------------- +-- @function [parent=#ScrollView] getChildByTag +-- @param self +-- @param #int int +-- @return Node#Node ret (return value: cc.Node) + -------------------------------- -- @function [parent=#ScrollView] getChildrenCount -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/Widget.lua b/cocos/scripting/lua-bindings/auto/api/Widget.lua index 5bea038c34..1f97832c9f 100644 --- a/cocos/scripting/lua-bindings/auto/api/Widget.lua +++ b/cocos/scripting/lua-bindings/auto/api/Widget.lua @@ -1,18 +1,13 @@ -------------------------------- -- @module Widget --- @extend Node +-- @extend ProtectedNode -------------------------------- -- @function [parent=#Widget] setSizePercent -- @param self -- @param #point_table point --------------------------------- --- @function [parent=#Widget] isFlippedX --- @param self --- @return bool#bool ret (return value: bool) - -------------------------------- -- @function [parent=#Widget] getCustomSize -- @param self @@ -29,10 +24,9 @@ -- @param #bool bool -------------------------------- --- @function [parent=#Widget] getNodeByTag +-- @function [parent=#Widget] getLeftInParent -- @param self --- @param #int int --- @return Node#Node ret (return value: cc.Node) +-- @return float#float ret (return value: float) -------------------------------- -- @function [parent=#Widget] getTouchEndPos @@ -44,11 +38,6 @@ -- @param self -- @param #point_table point --------------------------------- --- @function [parent=#Widget] getNodes --- @param self --- @return array_table#array_table ret (return value: array_table) - -------------------------------- -- @function [parent=#Widget] getLayoutSize -- @param self @@ -69,15 +58,6 @@ -- @param self -- @return bool#bool ret (return value: bool) --------------------------------- --- overload function: updateSizeAndPosition(size_table) --- --- overload function: updateSizeAndPosition() --- --- @function [parent=#Widget] updateSizeAndPosition --- @param self --- @param #size_table size - -------------------------------- -- @function [parent=#Widget] getBottomInParent -- @param self @@ -100,9 +80,9 @@ -- @return PositionType#PositionType ret (return value: ccui.PositionType) -------------------------------- --- @function [parent=#Widget] setName +-- @function [parent=#Widget] getWidgetType -- @param self --- @param #char char +-- @return WidgetType#WidgetType ret (return value: ccui.WidgetType) -------------------------------- -- @function [parent=#Widget] getChildByName @@ -116,9 +96,9 @@ -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#Widget] removeNodeByTag +-- @function [parent=#Widget] isFocused -- @param self --- @param #int int +-- @return bool#bool ret (return value: bool) -------------------------------- -- @function [parent=#Widget] isTouchEnabled @@ -175,18 +155,10 @@ -- @param #ccui.BrightStyle brightstyle -------------------------------- --- overload function: addNode(cc.Node, int) --- --- overload function: addNode(cc.Node) --- --- overload function: addNode(cc.Node, int, int) --- --- @function [parent=#Widget] addNode +-- @function [parent=#Widget] setName -- @param self --- @param #cc.Node node --- @param #int int --- @param #int int - +-- @param #char char + -------------------------------- -- @function [parent=#Widget] setLayoutParameter -- @param self @@ -202,21 +174,11 @@ -- @param self -- @return point_table#point_table ret (return value: point_table) --------------------------------- --- @function [parent=#Widget] getLeftInParent --- @param self --- @return float#float ret (return value: float) - -------------------------------- -- @function [parent=#Widget] setActionTag -- @param self -- @param #int int --------------------------------- --- @function [parent=#Widget] ignoreContentAdaptWithSize --- @param self --- @param #bool bool - -------------------------------- -- @function [parent=#Widget] isBright -- @param self @@ -234,10 +196,14 @@ -- @return float#float ret (return value: float) -------------------------------- --- @function [parent=#Widget] getWidgetType +-- overload function: updateSizeAndPosition(size_table) +-- +-- overload function: updateSizeAndPosition() +-- +-- @function [parent=#Widget] updateSizeAndPosition -- @param self --- @return WidgetType#WidgetType ret (return value: ccui.WidgetType) - +-- @param #size_table size + -------------------------------- -- @function [parent=#Widget] getSize -- @param self @@ -254,13 +220,9 @@ -- @return SizeType#SizeType ret (return value: ccui.SizeType) -------------------------------- --- @function [parent=#Widget] removeNode --- @param self --- @param #cc.Node node - --------------------------------- --- @function [parent=#Widget] removeAllNodes +-- @function [parent=#Widget] ignoreContentAdaptWithSize -- @param self +-- @param #bool bool -------------------------------- -- @function [parent=#Widget] getPositionPercent @@ -274,7 +236,7 @@ -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#Widget] isFocused +-- @function [parent=#Widget] isFlippedX -- @param self -- @return bool#bool ret (return value: bool) @@ -310,72 +272,11 @@ -- @param self -- @return Widget#Widget ret (return value: ccui.Widget) --------------------------------- --- overload function: addChild(cc.Node, int) --- --- overload function: addChild(cc.Node) --- --- overload function: addChild(cc.Node, int, int) --- --- @function [parent=#Widget] addChild --- @param self --- @param #cc.Node node --- @param #int int --- @param #int int - -------------------------------- -- @function [parent=#Widget] setColor -- @param self -- @param #color3B_table color3b --------------------------------- --- @function [parent=#Widget] removeFromParent --- @param self - --------------------------------- --- @function [parent=#Widget] removeAllChildrenWithCleanup --- @param self --- @param #bool bool - --------------------------------- --- @function [parent=#Widget] removeAllChildren --- @param self - --------------------------------- --- @function [parent=#Widget] sortAllChildren --- @param self - --------------------------------- --- @function [parent=#Widget] removeChild --- @param self --- @param #cc.Node node --- @param #bool bool - --------------------------------- --- overload function: getChildren() --- --- overload function: getChildren() --- --- @function [parent=#Widget] getChildren --- @param self --- @return array_table#array_table ret (retunr value: array_table) - --------------------------------- --- @function [parent=#Widget] getDescription --- @param self --- @return string#string ret (return value: string) - --------------------------------- --- @function [parent=#Widget] getChildByTag --- @param self --- @param #int int --- @return Node#Node ret (return value: cc.Node) - --------------------------------- --- @function [parent=#Widget] removeFromParentAndCleanup --- @param self --- @param #bool bool - -------------------------------- -- @function [parent=#Widget] getColor -- @param self @@ -386,26 +287,20 @@ -- @param self -- @param #unsigned char char --------------------------------- --- @function [parent=#Widget] setPosition --- @param self --- @param #point_table point - --------------------------------- --- @function [parent=#Widget] removeChildByTag --- @param self --- @param #int int --- @param #bool bool - -------------------------------- -- @function [parent=#Widget] getOpacity -- @param self -- @return unsigned char#unsigned char ret (return value: unsigned char) -------------------------------- --- @function [parent=#Widget] getChildrenCount +-- @function [parent=#Widget] setPosition -- @param self --- @return long#long ret (return value: long) +-- @param #point_table point + +-------------------------------- +-- @function [parent=#Widget] getDescription +-- @param self +-- @return string#string ret (return value: string) -------------------------------- -- @function [parent=#Widget] Widget diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id index 104c65729e..e024e99b59 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id @@ -1 +1 @@ -11bba6be0cebc89eb4c7195a61d021e51719468f \ No newline at end of file +19adb2eb5a08b20b670b77975f7e30c08bbac2d6 \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp index 1e576402ce..3a1b0bb858 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp @@ -362,12 +362,6 @@ int register_all_cocos2dx_ui(lua_State* tolua_S); - - - - - - From f672f3153ec3ef93aa8f2ad16ae32ce2a579e6ab Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 Mar 2014 16:30:00 +0800 Subject: [PATCH 11/18] Update CHANGELOG [ci skip] --- CHANGELOG.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.REMOVED.git-id b/CHANGELOG.REMOVED.git-id index af31d79c6e..f99513ccea 100644 --- a/CHANGELOG.REMOVED.git-id +++ b/CHANGELOG.REMOVED.git-id @@ -1 +1 @@ -819b72559f8be48c41958b0afb4c6513207b453a \ No newline at end of file +f25c155ba7b72acabb5314391df45df00f582ca3 \ No newline at end of file From 4b454fe7bbb5a067dda9d4305912d4d8a078d183 Mon Sep 17 00:00:00 2001 From: LinWenhai Date: Tue, 25 Mar 2014 16:37:34 +0800 Subject: [PATCH 12/18] Update getter of ClipMarginEnabled. --- cocos/2d/CCLabel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index c453112cb4..c2e2be23b8 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -220,7 +220,7 @@ public: /** clip upper and lower margin for reduce height of label. */ void setClipMarginEnabled(bool clipEnabled) { _clipEnabled = clipEnabled; } - bool getClipMarginEnabled() const { return _clipEnabled; } + bool isClipMarginEnabled() const { return _clipEnabled; } // font related stuff int getCommonLineHeight() const; From fe89291be64450e24ec1956956bac3a854c574c1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 Mar 2014 16:47:59 +0800 Subject: [PATCH 13/18] Update CHANGELOG [ci skip] --- CHANGELOG.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.REMOVED.git-id b/CHANGELOG.REMOVED.git-id index f99513ccea..04713d44d3 100644 --- a/CHANGELOG.REMOVED.git-id +++ b/CHANGELOG.REMOVED.git-id @@ -1 +1 @@ -f25c155ba7b72acabb5314391df45df00f582ca3 \ No newline at end of file +185679986c46f4ecc4cb98f4fc014a8e9a42a88f \ No newline at end of file From dda53f26d487e4621594cac51a5f58fe31137800 Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 25 Mar 2014 16:50:36 +0800 Subject: [PATCH 14/18] [ci skip] --- CHANGELOG.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.REMOVED.git-id b/CHANGELOG.REMOVED.git-id index 04713d44d3..73a33eb03f 100644 --- a/CHANGELOG.REMOVED.git-id +++ b/CHANGELOG.REMOVED.git-id @@ -1 +1 @@ -185679986c46f4ecc4cb98f4fc014a8e9a42a88f \ No newline at end of file +5b8d2ae9f19e1ca958245cf11e144d18d6ee3f89 \ No newline at end of file From b8eee8e1a4a2b26d312070e408a1096f7e511b86 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 Mar 2014 17:07:15 +0800 Subject: [PATCH 15/18] [ci] Updates travis scripts. only commit relevant folder. --- tools/travis-scripts/generate-bindings.sh | 3 ++- tools/travis-scripts/generate-cocosfiles.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/travis-scripts/generate-bindings.sh b/tools/travis-scripts/generate-bindings.sh index d586e61d09..0a2b428b57 100755 --- a/tools/travis-scripts/generate-bindings.sh +++ b/tools/travis-scripts/generate-bindings.sh @@ -24,6 +24,7 @@ COCOS_BRANCH="update_lua_bindings_$ELAPSEDSECS" COCOS_ROBOT_REMOTE="https://${GH_USER}:${GH_PASSWORD}@github.com/${GH_USER}/cocos2d-x.git" PULL_REQUEST_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" FETCH_REMOTE_BRANCH="develop" +COMMIT_PATH="cocos/scripting/lua-bindings/auto" # Exit on error set -e @@ -96,7 +97,7 @@ git fetch origin ${FETCH_REMOTE_BRANCH} # Don't exit on non-zero return value set +e -git diff FETCH_HEAD --stat --exit-code +git diff FETCH_HEAD --stat --exit-code ${COMMIT_PATH} DIFF_RETVAL=$? if [ $DIFF_RETVAL -eq 0 ] diff --git a/tools/travis-scripts/generate-cocosfiles.sh b/tools/travis-scripts/generate-cocosfiles.sh index ec43dc8300..82837b2a6d 100755 --- a/tools/travis-scripts/generate-cocosfiles.sh +++ b/tools/travis-scripts/generate-cocosfiles.sh @@ -7,6 +7,7 @@ COMMITTAG="[AUTO][ci skip]: updating cocos2dx_files.json" PUSH_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" OUTPUT_FILE_PATH="${PROJECT_ROOT}/templates/cocos2dx_files.json" FETCH_REMOTE_BRANCH="develop" +COMMIT_PATH="templates/cocos2dx_files.json" # Exit on error set -e @@ -59,7 +60,7 @@ git fetch origin ${FETCH_REMOTE_BRANCH} # Don't exit on non-zero return value set +e -git diff FETCH_HEAD --stat --exit-code +git diff FETCH_HEAD --stat --exit-code ${COMMIT_PATH} DIFF_RETVAL=$? if [ $DIFF_RETVAL -eq 0 ] From c5d6e83673e9d729fdcf754877eeab90691d7714 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 25 Mar 2014 09:30:11 +0000 Subject: [PATCH 16/18] [AUTO]: updating luabinding automatically --- cocos/scripting/lua-bindings/auto/api/Label.lua | 10 ++++++++++ .../auto/lua_cocos2dx_auto.cpp.REMOVED.git-id | 2 +- .../scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/auto/api/Label.lua b/cocos/scripting/lua-bindings/auto/api/Label.lua index cd439ef1bf..f46a580dc0 100644 --- a/cocos/scripting/lua-bindings/auto/api/Label.lua +++ b/cocos/scripting/lua-bindings/auto/api/Label.lua @@ -3,6 +3,11 @@ -- @module Label -- @extend SpriteBatchNode,LabelProtocol, +-------------------------------- +-- @function [parent=#Label] isClipMarginEnabled +-- @param self +-- @return bool#bool ret (return value: bool) + -------------------------------- -- @function [parent=#Label] enableShadow -- @param self @@ -57,6 +62,11 @@ -- @param self -- @return TextHAlignment#TextHAlignment ret (return value: cc.TextHAlignment) +-------------------------------- +-- @function [parent=#Label] setClipMarginEnabled +-- @param self +-- @param #bool bool + -------------------------------- -- @function [parent=#Label] setString -- @param self diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp.REMOVED.git-id index 4131e54b6b..ce6e4ecd48 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp.REMOVED.git-id @@ -1 +1 @@ -83d9fece450a67211518c287e9ecf99ce122c142 \ No newline at end of file +bb331bf4e55b4ca2f5b12c75e6c3e638ae3367d0 \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index b7ba04e76c..5eeff5ebfd 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -1544,6 +1544,8 @@ int register_all_cocos2dx(lua_State* tolua_S); + + From 473a6b19ee1cffdd5caa6f8b8126318fd3f58ed1 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Tue, 25 Mar 2014 10:37:35 -0700 Subject: [PATCH 17/18] Upgrades to Chipmunk 6.2.1 --- CHANGELOG.REMOVED.git-id | 2 +- external/chipmunk/include/chipmunk/chipmunk.h | 10 +- .../include/chipmunk/chipmunk_private.h | 73 +- .../include/chipmunk/chipmunk_types.h | 7 + .../include/chipmunk/chipmunk_unsafe.h | 2 + .../chipmunk/include/chipmunk/cpArbiter.h | 2 +- external/chipmunk/include/chipmunk/cpBB.h | 7 + .../chipmunk/include/chipmunk/cpPolyShape.h | 20 +- external/chipmunk/include/chipmunk/cpShape.h | 4 + .../include/chipmunk/cpSpatialIndex.h | 2 +- external/chipmunk/include/chipmunk/cpVect.h | 7 +- external/chipmunk/src/CMakeLists.txt | 18 +- external/chipmunk/src/chipmunk.c | 2 + .../src/constraints/cpRotaryLimitJoint.c | 2 +- external/chipmunk/src/cpBBTree.c | 37 +- external/chipmunk/src/cpCollision.c | 999 ++++++++++++------ external/chipmunk/src/cpPolyShape.c | 89 +- external/chipmunk/src/cpShape.c | 41 +- external/chipmunk/src/cpSpaceHash.c | 2 +- external/chipmunk/src/cpSpaceQuery.c | 38 +- external/chipmunk/src/cpSpaceStep.c | 16 +- external/chipmunk/src/cpSweep1D.c | 4 +- .../Classes/ChipmunkTest/ChipmunkTest.cpp | 14 +- .../Classes/ChipmunkTest/ChipmunkTest.h | 2 +- tests/cpp-tests/Classes/VisibleRect.cpp | 2 + tests/cpp-tests/Classes/VisibleRect.h | 23 +- 26 files changed, 914 insertions(+), 511 deletions(-) diff --git a/CHANGELOG.REMOVED.git-id b/CHANGELOG.REMOVED.git-id index 73a33eb03f..1703c79ebf 100644 --- a/CHANGELOG.REMOVED.git-id +++ b/CHANGELOG.REMOVED.git-id @@ -1 +1 @@ -5b8d2ae9f19e1ca958245cf11e144d18d6ee3f89 \ No newline at end of file +8141cfdd7d973fa5a4c189a72c2fd6cac8eb95ae \ No newline at end of file diff --git a/external/chipmunk/include/chipmunk/chipmunk.h b/external/chipmunk/include/chipmunk/chipmunk.h index f0e4282f7e..6337fb1a13 100644 --- a/external/chipmunk/include/chipmunk/chipmunk.h +++ b/external/chipmunk/include/chipmunk/chipmunk.h @@ -23,9 +23,7 @@ #define CHIPMUNK_HEADER #ifdef _MSC_VER - #ifndef _USE_MATH_DEFINES - #define _USE_MATH_DEFINES - #endif + #define _USE_MATH_DEFINES #endif #include @@ -112,10 +110,10 @@ typedef struct cpSpace cpSpace; #include "cpSpace.h" -// Chipmunk 6.1.5 +// Chipmunk 6.2.1 #define CP_VERSION_MAJOR 6 -#define CP_VERSION_MINOR 1 -#define CP_VERSION_RELEASE 5 +#define CP_VERSION_MINOR 2 +#define CP_VERSION_RELEASE 1 /// Version string. extern const char *cpVersionString; diff --git a/external/chipmunk/include/chipmunk/chipmunk_private.h b/external/chipmunk/include/chipmunk/chipmunk_private.h index 3353292262..f676345bc9 100644 --- a/external/chipmunk/include/chipmunk/chipmunk_private.h +++ b/external/chipmunk/include/chipmunk/chipmunk_private.h @@ -25,6 +25,9 @@ #define CP_HASH_COEF (3344921057ul) #define CP_HASH_PAIR(A, B) ((cpHashValue)(A)*CP_HASH_COEF ^ (cpHashValue)(B)*CP_HASH_COEF) +// TODO: Eww. Magic numbers. +#define MAGIC_EPSILON 1e-5 + //MARK: cpArray struct cpArray { @@ -43,6 +46,7 @@ cpBool cpArrayContains(cpArray *arr, void *ptr); void cpArrayFreeEach(cpArray *arr, void (freeFunc)(void*)); + //MARK: Foreach loops static inline cpConstraint * @@ -69,6 +73,7 @@ cpArbiterNext(cpArbiter *node, cpBody *body) #define CP_BODY_FOREACH_COMPONENT(root, var)\ for(cpBody *var = root; var; var = var->node.next) + //MARK: cpHashSet typedef cpBool (*cpHashSetEqlFunc)(void *ptr, void *elt); @@ -90,6 +95,7 @@ void cpHashSetEach(cpHashSet *set, cpHashSetIteratorFunc func, void *data); typedef cpBool (*cpHashSetFilterFunc)(void *elt, void *data); void cpHashSetFilter(cpHashSet *set, cpHashSetFilterFunc func, void *data); + //MARK: Body Functions void cpBodyAddShape(cpBody *body, cpShape *shape); @@ -116,7 +122,29 @@ cpShapeActive(cpShape *shape) return shape->prev || (shape->body && shape->body->shapeList == shape); } -int cpCollideShapes(const cpShape *a, const cpShape *b, cpContact *arr); +int cpCollideShapes(const cpShape *a, const cpShape *b, cpCollisionID *id, cpContact *arr); + +static inline void +CircleSegmentQuery(cpShape *shape, cpVect center, cpFloat r, cpVect a, cpVect b, cpSegmentQueryInfo *info) +{ + cpVect da = cpvsub(a, center); + cpVect db = cpvsub(b, center); + + cpFloat qa = cpvdot(da, da) - 2.0f*cpvdot(da, db) + cpvdot(db, db); + cpFloat qb = -2.0f*cpvdot(da, da) + 2.0f*cpvdot(da, db); + cpFloat qc = cpvdot(da, da) - r*r; + + cpFloat det = qb*qb - 4.0f*qa*qc; + + if(det >= 0.0f){ + cpFloat t = (-qb - cpfsqrt(det))/(2.0f*qa); + if(0.0f<= t && t <= 1.0f){ + info->shape = shape; + info->t = t; + info->n = cpvnormalize(cpvlerp(da, db, t)); + } + } +} // TODO doesn't really need to be inline, but need a better place to put this function static inline cpSplittingPlane @@ -135,50 +163,12 @@ cpSplittingPlaneCompare(cpSplittingPlane plane, cpVect v) void cpLoopIndexes(cpVect *verts, int count, int *start, int *end); -static inline cpFloat -cpPolyShapeValueOnAxis(const cpPolyShape *poly, const cpVect n, const cpFloat d) -{ - cpVect *verts = poly->tVerts; - cpFloat min = cpvdot(n, verts[0]); - - for(int i=1; inumVerts; i++){ - min = cpfmin(min, cpvdot(n, verts[i])); - } - - return min - d; -} - -static inline cpBool -cpPolyShapeContainsVert(const cpPolyShape *poly, const cpVect v) -{ - cpSplittingPlane *planes = poly->tPlanes; - - for(int i=0; inumVerts; i++){ - cpFloat dist = cpSplittingPlaneCompare(planes[i], v); - if(dist > 0.0f) return cpFalse; - } - - return cpTrue; -} - -static inline cpBool -cpPolyShapeContainsVertPartial(const cpPolyShape *poly, const cpVect v, const cpVect n) -{ - cpSplittingPlane *planes = poly->tPlanes; - - for(int i=0; inumVerts; i++){ - if(cpvdot(planes[i].n, n) < 0.0f) continue; - cpFloat dist = cpSplittingPlaneCompare(planes[i], v); - if(dist > 0.0f) return cpFalse; - } - - return cpTrue; -} //MARK: Spatial Index Functions cpSpatialIndex *cpSpatialIndexInit(cpSpatialIndex *index, cpSpatialIndexClass *klass, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex); + //MARK: Space Functions extern cpCollisionHandler cpDefaultCollisionHandler; @@ -221,8 +211,7 @@ cpSpaceUncacheArbiter(cpSpace *space, cpArbiter *arb) } void cpShapeUpdateFunc(cpShape *shape, void *unused); -void cpSpaceCollideShapes(cpShape *a, cpShape *b, cpSpace *space); - +cpCollisionID cpSpaceCollideShapes(cpShape *a, cpShape *b, cpCollisionID id, cpSpace *space); //MARK: Arbiters diff --git a/external/chipmunk/include/chipmunk/chipmunk_types.h b/external/chipmunk/include/chipmunk/chipmunk_types.h index a4c21899db..fdfb6d1eef 100644 --- a/external/chipmunk/include/chipmunk/chipmunk_types.h +++ b/external/chipmunk/include/chipmunk/chipmunk_types.h @@ -1,4 +1,5 @@ #include +#include #ifdef __APPLE__ #include "TargetConditionals.h" @@ -45,6 +46,7 @@ #define cpfpow pow #define cpffloor floor #define cpfceil ceil + #define CPFLOAT_MIN DBL_MIN #else typedef float cpFloat; #define cpfsqrt sqrtf @@ -57,6 +59,7 @@ #define cpfpow powf #define cpffloor floorf #define cpfceil ceilf + #define CPFLOAT_MIN FLT_MIN #endif #ifndef INFINITY @@ -135,6 +138,10 @@ static inline cpFloat cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d) /// Hash value type. typedef uintptr_t cpHashValue; +/// Type used internally to cache colliding object info for cpCollideShapes(). +/// Should be at least 32 bits. +typedef uint32_t cpCollisionID; + // Oh C, how we love to define our own boolean types to get compiler compatibility /// Chipmunk's boolean type. #ifdef CP_BOOL_TYPE diff --git a/external/chipmunk/include/chipmunk/chipmunk_unsafe.h b/external/chipmunk/include/chipmunk/chipmunk_unsafe.h index 637e33670c..4428814c07 100644 --- a/external/chipmunk/include/chipmunk/chipmunk_unsafe.h +++ b/external/chipmunk/include/chipmunk/chipmunk_unsafe.h @@ -55,6 +55,8 @@ void cpSegmentShapeSetRadius(cpShape *shape, cpFloat radius); /// Set the vertexes of a poly shape. void cpPolyShapeSetVerts(cpShape *shape, int numVerts, cpVect *verts, cpVect offset); +/// Set the radius of a poly shape. +void cpPolyShapeSetRadius(cpShape *shape, cpFloat radius); #ifdef __cplusplus } diff --git a/external/chipmunk/include/chipmunk/cpArbiter.h b/external/chipmunk/include/chipmunk/cpArbiter.h index 4891948184..1ccb693d3a 100644 --- a/external/chipmunk/include/chipmunk/cpArbiter.h +++ b/external/chipmunk/include/chipmunk/cpArbiter.h @@ -50,7 +50,7 @@ struct cpCollisionHandler { typedef struct cpContact cpContact; -#define CP_MAX_CONTACTS_PER_ARBITER 4 +#define CP_MAX_CONTACTS_PER_ARBITER 2 /// @private typedef enum cpArbiterState { diff --git a/external/chipmunk/include/chipmunk/cpBB.h b/external/chipmunk/include/chipmunk/cpBB.h index 320a1af358..4e59c2d495 100644 --- a/external/chipmunk/include/chipmunk/cpBB.h +++ b/external/chipmunk/include/chipmunk/cpBB.h @@ -79,6 +79,13 @@ static inline cpBB cpBBExpand(const cpBB bb, const cpVect v){ ); } +/// Returns the center of a bounding box. +static inline cpVect +cpBBCenter(cpBB bb) +{ + return cpvlerp(cpv(bb.l, bb.b), cpv(bb.r, bb.t), 0.5f); +} + /// Returns the area of the bounding box. static inline cpFloat cpBBArea(cpBB bb) { diff --git a/external/chipmunk/include/chipmunk/cpPolyShape.h b/external/chipmunk/include/chipmunk/cpPolyShape.h index 40ecd8b472..a5587ba250 100644 --- a/external/chipmunk/include/chipmunk/cpPolyShape.h +++ b/external/chipmunk/include/chipmunk/cpPolyShape.h @@ -35,6 +35,8 @@ typedef struct cpPolyShape { int numVerts; cpVect *verts, *tVerts; cpSplittingPlane *planes, *tPlanes; + + cpFloat r; } cpPolyShape; /// Allocate a polygon shape. @@ -42,26 +44,38 @@ cpPolyShape* cpPolyShapeAlloc(void); /// Initialize a polygon shape. /// A convex hull will be created from the vertexes. cpPolyShape* cpPolyShapeInit(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset); +/// Initialize a polygon shape. +/// A convex hull will be created from the vertexes. +cpPolyShape* cpPolyShapeInit2(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset, cpFloat radius); /// Allocate and initialize a polygon shape. /// A convex hull will be created from the vertexes. -cpShape* cpPolyShapeNew(cpBody *body, int numVerts, cpVect *verts, cpVect offset); +cpShape* cpPolyShapeNew(cpBody *body, int numVerts, const cpVect *verts, cpVect offset); +/// Allocate and initialize a polygon shape. +/// A convex hull will be created from the vertexes. +cpShape* cpPolyShapeNew2(cpBody *body, int numVerts, const cpVect *verts, cpVect offset, cpFloat radius); /// Initialize a box shaped polygon shape. cpPolyShape* cpBoxShapeInit(cpPolyShape *poly, cpBody *body, cpFloat width, cpFloat height); /// Initialize an offset box shaped polygon shape. cpPolyShape* cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box); +/// Initialize an offset box shaped polygon shape. +cpPolyShape* cpBoxShapeInit3(cpPolyShape *poly, cpBody *body, cpBB box, cpFloat radius); /// Allocate and initialize a box shaped polygon shape. cpShape* cpBoxShapeNew(cpBody *body, cpFloat width, cpFloat height); /// Allocate and initialize an offset box shaped polygon shape. cpShape* cpBoxShapeNew2(cpBody *body, cpBB box); +/// Allocate and initialize an offset box shaped polygon shape. +cpShape* cpBoxShapeNew3(cpBody *body, cpBB box, cpFloat radius); /// Check that a set of vertexes is convex and has a clockwise winding. /// NOTE: Due to floating point precision issues, hulls created with cpQuickHull() are not guaranteed to validate! cpBool cpPolyValidate(const cpVect *verts, const int numVerts); /// Get the number of verts in a polygon shape. -int cpPolyShapeGetNumVerts(cpShape *shape); +int cpPolyShapeGetNumVerts(const cpShape *shape); /// Get the @c ith vertex of a polygon shape. -cpVect cpPolyShapeGetVert(cpShape *shape, int idx); +cpVect cpPolyShapeGetVert(const cpShape *shape, int idx); +/// Get the radius of a polygon shape. +cpFloat cpPolyShapeGetRadius(const cpShape *shape); /// @} diff --git a/external/chipmunk/include/chipmunk/cpShape.h b/external/chipmunk/include/chipmunk/cpShape.h index 0d927a69b6..62920c371c 100644 --- a/external/chipmunk/include/chipmunk/cpShape.h +++ b/external/chipmunk/include/chipmunk/cpShape.h @@ -33,6 +33,9 @@ typedef struct cpNearestPointQueryInfo { cpVect p; /// The distance to the point. The distance is negative if the point is inside the shape. cpFloat d; + /// The gradient of the signed distance function. + /// The same as info.p/info.d, but accurate even for very small values of info.d. + cpVect g; } cpNearestPointQueryInfo; /// Segment query info struct. @@ -218,6 +221,7 @@ cpSegmentShape* cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a, /// Allocate and initialize a segment shape. cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius); +/// Let Chipmunk know about the geometry of adjacent segments to avoid colliding with endcaps. void cpSegmentShapeSetNeighbors(cpShape *shape, cpVect prev, cpVect next); CP_DeclareShapeGetter(cpSegmentShape, cpVect, A); diff --git a/external/chipmunk/include/chipmunk/cpSpatialIndex.h b/external/chipmunk/include/chipmunk/cpSpatialIndex.h index bf3d0da397..c279cad063 100644 --- a/external/chipmunk/include/chipmunk/cpSpatialIndex.h +++ b/external/chipmunk/include/chipmunk/cpSpatialIndex.h @@ -46,7 +46,7 @@ typedef cpBB (*cpSpatialIndexBBFunc)(void *obj); /// Spatial index/object iterator callback function type. typedef void (*cpSpatialIndexIteratorFunc)(void *obj, void *data); /// Spatial query callback function type. -typedef void (*cpSpatialIndexQueryFunc)(void *obj1, void *obj2, void *data); +typedef cpCollisionID (*cpSpatialIndexQueryFunc)(void *obj1, void *obj2, cpCollisionID id, void *data); /// Spatial segment query callback function type. typedef cpFloat (*cpSpatialIndexSegmentQueryFunc)(void *obj1, void *obj2, void *data); diff --git a/external/chipmunk/include/chipmunk/cpVect.h b/external/chipmunk/include/chipmunk/cpVect.h index a59a361e84..90855e56e2 100644 --- a/external/chipmunk/include/chipmunk/cpVect.h +++ b/external/chipmunk/include/chipmunk/cpVect.h @@ -151,13 +151,14 @@ static inline cpVect cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t) /// Returns a normalized copy of v. static inline cpVect cpvnormalize(const cpVect v) { - return cpvmult(v, 1.0f/cpvlength(v)); + // Neat trick I saw somewhere to avoid div/0. + return cpvmult(v, 1.0f/(cpvlength(v) + CPFLOAT_MIN)); } -/// Returns a normalized copy of v or cpvzero if v was already cpvzero. Protects against divide by zero errors. +/// @deprecated Just an alias for cpvnormalize() now. static inline cpVect cpvnormalize_safe(const cpVect v) { - return (v.x == 0.0f && v.y == 0.0f ? cpvzero : cpvnormalize(v)); + return cpvnormalize(v); } /// Clamp v to length len. diff --git a/external/chipmunk/src/CMakeLists.txt b/external/chipmunk/src/CMakeLists.txt index 45c855e838..2e817ea717 100644 --- a/external/chipmunk/src/CMakeLists.txt +++ b/external/chipmunk/src/CMakeLists.txt @@ -1,5 +1,3 @@ -set(BUILD_STATIC 1) - file(GLOB chipmunk_source_files "*.c" "constraints/*.c") file(GLOB chipmunk_public_header "${chipmunk_SOURCE_DIR}/include/chipmunk/*.h") file(GLOB chipmunk_constraint_header "${chipmunk_SOURCE_DIR}/include/chipmunk/constraints/*.h") @@ -16,7 +14,14 @@ if(BUILD_SHARED) set_target_properties(chipmunk PROPERTIES LINKER_LANGUAGE CXX) endif(MSVC) # set the lib's version number - set_target_properties(chipmunk PROPERTIES VERSION 6.1.5) + # But avoid on Android because symlinks to version numbered .so's don't work with Android's Java-side loadLibrary. + if(NOT ANDROID) + set_target_properties(chipmunk PROPERTIES VERSION 6.2.1) + endif(NOT ANDROID) + if(ANDROID) + # need to explicitly link to the math library because the CMake/Android toolchains may not do it automatically + target_link_libraries(chipmunk m) + endif(ANDROID) install(TARGETS chipmunk RUNTIME DESTINATION lib LIBRARY DESTINATION lib) endif(BUILD_SHARED) @@ -41,10 +46,3 @@ if(BUILD_SHARED OR INSTALL_STATIC) install(FILES ${chipmunk_public_header} DESTINATION include/chipmunk) install(FILES ${chipmunk_constraint_header} DESTINATION include/chipmunk/constraints) endif(BUILD_SHARED OR INSTALL_STATIC) - -set_target_properties(chipmunk_static - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" -) - diff --git a/external/chipmunk/src/chipmunk.c b/external/chipmunk/src/chipmunk.c index 8487dd0b7f..2c098df4f6 100644 --- a/external/chipmunk/src/chipmunk.c +++ b/external/chipmunk/src/chipmunk.c @@ -83,6 +83,8 @@ cpAreaForSegment(cpVect a, cpVect b, cpFloat r) cpFloat cpMomentForPoly(cpFloat m, const int numVerts, const cpVect *verts, cpVect offset) { + if(numVerts == 2) return cpMomentForSegment(m, verts[0], verts[1]); + cpFloat sum1 = 0.0f; cpFloat sum2 = 0.0f; for(int i=0; iiSum = 1.0f/(1.0f/a->i + 1.0f/b->i); + joint->iSum = 1.0f/(a->i_inv + b->i_inv); // calculate bias velocity cpFloat maxBias = joint->constraint.maxBias; diff --git a/external/chipmunk/src/cpBBTree.c b/external/chipmunk/src/cpBBTree.c index 757606e797..6d347e4d60 100644 --- a/external/chipmunk/src/cpBBTree.c +++ b/external/chipmunk/src/cpBBTree.c @@ -72,7 +72,10 @@ typedef struct Thread { Pair *next; } Thread; -struct Pair { Thread a, b; }; +struct Pair { + Thread a, b; + cpCollisionID id; +}; //MARK: Misc Functions @@ -205,7 +208,7 @@ PairInsert(Node *a, Node *b, cpBBTree *tree) { Pair *nextA = a->PAIRS, *nextB = b->PAIRS; Pair *pair = PairFromPool(tree); - Pair temp = {{NULL, a, nextA},{NULL, b, nextB}}; + Pair temp = {{NULL, a, nextA},{NULL, b, nextB}, 0}; a->PAIRS = b->PAIRS = pair; *pair = temp; @@ -351,7 +354,7 @@ SubtreeQuery(Node *subtree, void *obj, cpBB bb, cpSpatialIndexQueryFunc func, vo { if(cpBBIntersects(subtree->bb, bb)){ if(NodeIsLeaf(subtree)){ - func(obj, subtree->obj, data); + func(obj, subtree->obj, 0, data); } else { SubtreeQuery(subtree->A, obj, bb, func, data); SubtreeQuery(subtree->B, obj, bb, func, data); @@ -428,7 +431,7 @@ MarkLeafQuery(Node *subtree, Node *leaf, cpBool left, MarkContext *context) PairInsert(leaf, subtree, context->tree); } else { if(subtree->STAMP < leaf->STAMP) PairInsert(subtree, leaf, context->tree); - context->func(leaf->obj, subtree->obj, context->data); + context->func(leaf->obj, subtree->obj, 0, context->data); } } else { MarkLeafQuery(subtree->A, leaf, left, context); @@ -456,7 +459,7 @@ MarkLeaf(Node *leaf, MarkContext *context) Pair *pair = leaf->PAIRS; while(pair){ if(leaf == pair->b.leaf){ - context->func(pair->a.leaf->obj, leaf->obj, context->data); + pair->id = context->func(pair->a.leaf->obj, leaf->obj, pair->id, context->data); pair = pair->b.next; } else { pair = pair->a.next; @@ -472,7 +475,7 @@ MarkSubtree(Node *subtree, MarkContext *context) MarkLeaf(subtree, context); } else { MarkSubtree(subtree->A, context); - MarkSubtree(subtree->B, context); + MarkSubtree(subtree->B, context); // TODO Force TCO here? } } @@ -508,12 +511,12 @@ LeafUpdate(Node *leaf, cpBBTree *tree) leaf->STAMP = GetMasterTree(tree)->stamp; return cpTrue; + } else { + return cpFalse; } - - return cpFalse; } -static void VoidQueryFunc(void *obj1, void *obj2, void *data){} +static cpCollisionID VoidQueryFunc(void *obj1, void *obj2, cpCollisionID id, void *data){return id;} static void LeafAddPairs(Node *leaf, cpBBTree *tree) @@ -864,17 +867,17 @@ NodeRender(Node *node, int depth) // glColor3f(1.0f - v, v, 0.0f); glLineWidth(cpfmax(5.0f - depth, 1.0f)); glBegin(GL_LINES); { - glVertex2F(bb.l, bb.b); - glVertex2F(bb.l, bb.t); + glVertex2f(bb.l, bb.b); + glVertex2f(bb.l, bb.t); - glVertex2F(bb.l, bb.t); - glVertex2F(bb.r, bb.t); + glVertex2f(bb.l, bb.t); + glVertex2f(bb.r, bb.t); - glVertex2F(bb.r, bb.t); - glVertex2F(bb.r, bb.b); + glVertex2f(bb.r, bb.t); + glVertex2f(bb.r, bb.b); - glVertex2F(bb.r, bb.b); - glVertex2F(bb.l, bb.b); + glVertex2f(bb.r, bb.b); + glVertex2f(bb.l, bb.b); }; glEnd(); } diff --git a/external/chipmunk/src/cpCollision.c b/external/chipmunk/src/cpCollision.c index 78798116a9..e29e4bf82e 100644 --- a/external/chipmunk/src/cpCollision.c +++ b/external/chipmunk/src/cpCollision.c @@ -18,47 +18,538 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + +#include +#include + #include "chipmunk_private.h" -typedef int (*collisionFunc)(const cpShape *, const cpShape *, cpContact *); +#if DEBUG && 0 +#include "ChipmunkDemo.h" +#define DRAW_ALL 0 +#define DRAW_GJK (0 || DRAW_ALL) +#define DRAW_EPA (0 || DRAW_ALL) +#define DRAW_CLOSEST (0 || DRAW_ALL) +#define DRAW_CLIP (0 || DRAW_ALL) + +#define PRINT_LOG 0 +#endif + +#define ENABLE_CACHING 1 + +#define MAX_GJK_ITERATIONS 30 +#define MAX_EPA_ITERATIONS 30 +#define WARN_GJK_ITERATIONS 20 +#define WARN_EPA_ITERATIONS 20 // Add contact points for circle to circle collisions. // Used by several collision tests. +// TODO should accept hash parameter static int -circle2circleQuery(const cpVect p1, const cpVect p2, const cpFloat r1, const cpFloat r2, cpContact *con) +CircleToCircleQuery(const cpVect p1, const cpVect p2, const cpFloat r1, const cpFloat r2, cpHashValue hash, cpContact *con) { cpFloat mindist = r1 + r2; cpVect delta = cpvsub(p2, p1); cpFloat distsq = cpvlengthsq(delta); - if(distsq >= mindist*mindist) return 0; - cpFloat dist = cpfsqrt(distsq); - - // Allocate and initialize the contact. - cpContactInit( - con, - cpvadd(p1, cpvmult(delta, 0.5f + (r1 - 0.5f*mindist)/(dist ? dist : INFINITY))), - (dist ? cpvmult(delta, 1.0f/dist) : cpv(1.0f, 0.0f)), - dist - mindist, - 0 - ); - - return 1; + if(distsq < mindist*mindist){ + cpFloat dist = cpfsqrt(distsq); + cpVect n = (dist ? cpvmult(delta, 1.0f/dist) : cpv(1.0f, 0.0f)); + cpContactInit(con, cpvlerp(p1, p2, r1/(r1 + r2)), n, dist - mindist, hash); + + return 1; + } else { + return 0; + } } +//MARK: Support Points and Edges: + +static inline int +PolySupportPointIndex(const int count, const cpVect *verts, const cpVect n) +{ + cpFloat max = -INFINITY; + int index = 0; + + for(int i=0; i max){ + max = d; + index = i; + } + } + + return index; +} + +struct SupportPoint { + cpVect p; + cpCollisionID id; +}; + +static inline struct SupportPoint +SupportPointNew(cpVect p, cpCollisionID id) +{ + struct SupportPoint point = {p, id}; + return point; +} + +typedef struct SupportPoint (*SupportPointFunc)(const cpShape *shape, const cpVect n); + +static inline struct SupportPoint +CircleSupportPoint(const cpCircleShape *circle, const cpVect n) +{ + return SupportPointNew(circle->tc, 0); +} + +static inline struct SupportPoint +SegmentSupportPoint(const cpSegmentShape *seg, const cpVect n) +{ + if(cpvdot(seg->ta, n) > cpvdot(seg->tb, n)){ + return SupportPointNew(seg->ta, 0); + } else { + return SupportPointNew(seg->tb, 1); + } +} + +static inline struct SupportPoint +PolySupportPoint(const cpPolyShape *poly, const cpVect n) +{ + const cpVect *verts = poly->tVerts; + int i = PolySupportPointIndex(poly->numVerts, verts, n); + return SupportPointNew(verts[i], i); +} + +struct MinkowskiPoint { + cpVect a, b; + cpVect ab; + cpCollisionID id; +}; + +static inline struct MinkowskiPoint +MinkowskiPointNew(const struct SupportPoint a, const struct SupportPoint b) +{ + struct MinkowskiPoint point = {a.p, b.p, cpvsub(b.p, a.p), (a.id & 0xFF)<<8 | (b.id & 0xFF)}; + return point; +} + +struct SupportContext { + const cpShape *shape1, *shape2; + SupportPointFunc func1, func2; +}; + +static inline struct MinkowskiPoint +Support(const struct SupportContext *ctx, const cpVect n) +{ + struct SupportPoint a = ctx->func1(ctx->shape1, cpvneg(n)); + struct SupportPoint b = ctx->func2(ctx->shape2, n); + return MinkowskiPointNew(a, b); +} + +struct EdgePoint { + cpVect p; + cpHashValue hash; +}; + +struct Edge { + struct EdgePoint a, b; + cpFloat r; + cpVect n; +}; + +static inline struct Edge +EdgeNew(cpVect va, cpVect vb, cpHashValue ha, cpHashValue hb, cpFloat r) +{ + struct Edge edge = {{va, ha}, {vb, hb}, r, cpvnormalize(cpvperp(cpvsub(vb, va)))}; + return edge; +} + +static struct Edge +SupportEdgeForPoly(const cpPolyShape *poly, const cpVect n) +{ + int numVerts = poly->numVerts; + int i1 = PolySupportPointIndex(poly->numVerts, poly->tVerts, n); + + // TODO get rid of mod eventually, very expensive on ARM + int i0 = (i1 - 1 + numVerts)%numVerts; + int i2 = (i1 + 1)%numVerts; + + cpVect *verts = poly->tVerts; + if(cpvdot(n, poly->tPlanes[i1].n) > cpvdot(n, poly->tPlanes[i2].n)){ + struct Edge edge = {{verts[i0], CP_HASH_PAIR(poly, i0)}, {verts[i1], CP_HASH_PAIR(poly, i1)}, poly->r, poly->tPlanes[i1].n}; + return edge; + } else { + struct Edge edge = {{verts[i1], CP_HASH_PAIR(poly, i1)}, {verts[i2], CP_HASH_PAIR(poly, i2)}, poly->r, poly->tPlanes[i2].n}; + return edge; + } +} + +static struct Edge +SupportEdgeForSegment(const cpSegmentShape *seg, const cpVect n) +{ + if(cpvdot(seg->tn, n) > 0.0){ + struct Edge edge = {{seg->ta, CP_HASH_PAIR(seg, 0)}, {seg->tb, CP_HASH_PAIR(seg, 1)}, seg->r, seg->tn}; + return edge; + } else { + struct Edge edge = {{seg->tb, CP_HASH_PAIR(seg, 1)}, {seg->ta, CP_HASH_PAIR(seg, 0)}, seg->r, cpvneg(seg->tn)}; + return edge; + } +} + +static inline cpFloat +ClosestT(const cpVect a, const cpVect b) +{ + cpVect delta = cpvsub(b, a); + return -cpfclamp(cpvdot(delta, cpvadd(a, b))/cpvlengthsq(delta), -1.0f, 1.0f); +} + +static inline cpVect +LerpT(const cpVect a, const cpVect b, const cpFloat t) +{ + cpFloat ht = 0.5f*t; + return cpvadd(cpvmult(a, 0.5f - ht), cpvmult(b, 0.5f + ht)); +} + +struct ClosestPoints { + cpVect a, b; + cpVect n; + cpFloat d; + cpCollisionID id; +}; + +static inline struct ClosestPoints +ClosestPointsNew(const struct MinkowskiPoint v0, const struct MinkowskiPoint v1) +{ + cpFloat t = ClosestT(v0.ab, v1.ab); + cpVect p = LerpT(v0.ab, v1.ab, t); + + cpVect pa = LerpT(v0.a, v1.a, t); + cpVect pb = LerpT(v0.b, v1.b, t); + cpCollisionID id = (v0.id & 0xFFFF)<<16 | (v1.id & 0xFFFF); + + cpVect delta = cpvsub(v1.ab, v0.ab); + cpVect n = cpvnormalize(cpvperp(delta)); + cpFloat d = -cpvdot(n, p); + + if(d <= 0.0f || (0.0f < t && t < 1.0f)){ + struct ClosestPoints points = {pa, pb, cpvneg(n), d, id}; + return points; + } else { + cpFloat d2 = cpvlength(p); + cpVect n = cpvmult(p, 1.0f/(d2 + CPFLOAT_MIN)); + + struct ClosestPoints points = {pa, pb, n, d2, id}; + return points; + } +} + +//MARK: EPA Functions + +static inline cpFloat +ClosestDist(const cpVect v0,const cpVect v1) +{ + return cpvlengthsq(LerpT(v0, v1, ClosestT(v0, v1))); +} + +static struct ClosestPoints +EPARecurse(const struct SupportContext *ctx, const int count, const struct MinkowskiPoint *hull, const int iteration) +{ + int mini = 0; + cpFloat minDist = INFINITY; + + // TODO: precalculate this when building the hull and save a step. + for(int j=0, i=count-1; j 0.0f && iteration < MAX_EPA_ITERATIONS){ + int count2 = 1; + struct MinkowskiPoint *hull2 = (struct MinkowskiPoint *)alloca((count + 1)*sizeof(struct MinkowskiPoint)); + hull2[0] = p; + + for(int i=0; i 0.0f){ + hull2[count2] = hull[index]; + count2++; + } + } + + return EPARecurse(ctx, count2, hull2, iteration + 1); + } else { + cpAssertWarn(iteration < WARN_EPA_ITERATIONS, "High EPA iterations: %d", iteration); + return ClosestPointsNew(v0, v1); + } +} + +static struct ClosestPoints +EPA(const struct SupportContext *ctx, const struct MinkowskiPoint v0, const struct MinkowskiPoint v1, const struct MinkowskiPoint v2) +{ + // TODO: allocate a NxM array here and do an in place convex hull reduction in EPARecurse + struct MinkowskiPoint hull[3] = {v0, v1, v2}; + return EPARecurse(ctx, 3, hull, 1); +} + +//MARK: GJK Functions. + +static inline struct ClosestPoints +GJKRecurse(const struct SupportContext *ctx, const struct MinkowskiPoint v0, const struct MinkowskiPoint v1, const int iteration) +{ + if(iteration > MAX_GJK_ITERATIONS){ + cpAssertWarn(iteration < WARN_GJK_ITERATIONS, "High GJK iterations: %d", iteration); + return ClosestPointsNew(v0, v1); + } + + cpVect delta = cpvsub(v1.ab, v0.ab); + if(cpvcross(delta, cpvadd(v0.ab, v1.ab)) > 0.0f){ + // Origin is behind axis. Flip and try again. + return GJKRecurse(ctx, v1, v0, iteration + 1); + } else { + cpFloat t = ClosestT(v0.ab, v1.ab); + cpVect n = (-1.0f < t && t < 1.0f ? cpvperp(delta) : cpvneg(LerpT(v0.ab, v1.ab, t))); + struct MinkowskiPoint p = Support(ctx, n); + +#if DRAW_GJK + ChipmunkDebugDrawSegment(v0.ab, v1.ab, RGBAColor(1, 1, 1, 1)); + cpVect c = cpvlerp(v0.ab, v1.ab, 0.5); + ChipmunkDebugDrawSegment(c, cpvadd(c, cpvmult(cpvnormalize(n), 5.0)), RGBAColor(1, 0, 0, 1)); + + ChipmunkDebugDrawPoints(5.0, 1, &p.ab, RGBAColor(1, 1, 1, 1)); +#endif + + if( + cpvcross(cpvsub(v1.ab, p.ab), cpvadd(v1.ab, p.ab)) > 0.0f && + cpvcross(cpvsub(v0.ab, p.ab), cpvadd(v0.ab, p.ab)) < 0.0f + ){ + cpAssertWarn(iteration < WARN_GJK_ITERATIONS, "High GJK->EPA iterations: %d", iteration); + // The triangle v0, p, v1 contains the origin. Use EPA to find the MSA. + return EPA(ctx, v0, p, v1); + } else { + // The new point must be farther along the normal than the existing points. + if(cpvdot(p.ab, n) <= cpfmax(cpvdot(v0.ab, n), cpvdot(v1.ab, n))){ + cpAssertWarn(iteration < WARN_GJK_ITERATIONS, "High GJK iterations: %d", iteration); + return ClosestPointsNew(v0, v1); + } else { + if(ClosestDist(v0.ab, p.ab) < ClosestDist(p.ab, v1.ab)){ + return GJKRecurse(ctx, v0, p, iteration + 1); + } else { + return GJKRecurse(ctx, p, v1, iteration + 1); + } + } + } + } +} + +static struct SupportPoint +ShapePoint(const cpShape *shape, const int i) +{ + switch(shape->klass->type){ + case CP_CIRCLE_SHAPE: { + return SupportPointNew(((cpCircleShape *)shape)->tc, 0); + } case CP_SEGMENT_SHAPE: { + cpSegmentShape *seg = (cpSegmentShape *)shape; + return SupportPointNew(i == 0 ? seg->ta : seg->tb, i); + } case CP_POLY_SHAPE: { + cpPolyShape *poly = (cpPolyShape *)shape; + // Poly shapes may change vertex count. + int index = (i < poly->numVerts ? i : 0); + return SupportPointNew(poly->tVerts[index], index); + } default: { + return SupportPointNew(cpvzero, 0); + } + } +} + +static struct ClosestPoints +GJK(const struct SupportContext *ctx, cpCollisionID *id) +{ +#if DRAW_GJK || DRAW_EPA + // draw the minkowski difference origin + cpVect origin = cpvzero; + ChipmunkDebugDrawPoints(5.0, 1, &origin, RGBAColor(1,0,0,1)); + + int mdiffCount = ctx->count1*ctx->count2; + cpVect *mdiffVerts = alloca(mdiffCount*sizeof(cpVect)); + + for(int i=0; icount1; i++){ + for(int j=0; jcount2; j++){ + cpVect v1 = ShapePoint(ctx->count1, ctx->verts1, i).p; + cpVect v2 = ShapePoint(ctx->count2, ctx->verts2, j).p; + mdiffVerts[i*ctx->count2 + j] = cpvsub(v2, v1); + } + } + + cpVect *hullVerts = alloca(mdiffCount*sizeof(cpVect)); + int hullCount = cpConvexHull(mdiffCount, mdiffVerts, hullVerts, NULL, 0.0); + + ChipmunkDebugDrawPolygon(hullCount, hullVerts, RGBAColor(1, 0, 0, 1), RGBAColor(1, 0, 0, 0.25)); + ChipmunkDebugDrawPoints(2.0, mdiffCount, mdiffVerts, RGBAColor(1, 0, 0, 1)); +#endif + + struct MinkowskiPoint v0, v1; + if(*id && ENABLE_CACHING){ + v0 = MinkowskiPointNew(ShapePoint(ctx->shape1, (*id>>24)&0xFF), ShapePoint(ctx->shape2, (*id>>16)&0xFF)); + v1 = MinkowskiPointNew(ShapePoint(ctx->shape1, (*id>> 8)&0xFF), ShapePoint(ctx->shape2, (*id )&0xFF)); + } else { + cpVect axis = cpvperp(cpvsub(cpBBCenter(ctx->shape1->bb), cpBBCenter(ctx->shape2->bb))); + v0 = Support(ctx, axis); + v1 = Support(ctx, cpvneg(axis)); + } + + struct ClosestPoints points = GJKRecurse(ctx, v0, v1, 1); + *id = points.id; + return points; +} + +//MARK: Contact Clipping + +static inline void +Contact1(cpFloat dist, cpVect a, cpVect b, cpFloat refr, cpFloat incr, cpVect n, cpHashValue hash, cpContact *arr) +{ + cpFloat rsum = refr + incr; + cpFloat alpha = (rsum > 0.0f ? refr/rsum : 0.5f); + cpVect point = cpvlerp(a, b, alpha); + + cpContactInit(arr, point, n, dist - rsum, hash); +} + +static inline int +Contact2(cpVect refp, cpVect inca, cpVect incb, cpFloat refr, cpFloat incr, cpVect refn, cpVect n, cpHashValue hash, cpContact *arr) +{ + cpFloat cian = cpvcross(inca, refn); + cpFloat cibn = cpvcross(incb, refn); + cpFloat crpn = cpvcross(refp, refn); + cpFloat t = 1.0f - cpfclamp01((cibn - crpn)/(cibn - cian)); + + cpVect point = cpvlerp(inca, incb, t); + cpFloat pd = cpvdot(cpvsub(point, refp), refn); + + if(t > 0.0f && pd <= 0.0f){ + cpFloat rsum = refr + incr; + cpFloat alpha = (rsum > 0.0f ? incr*(1.0f - (rsum + pd)/rsum) : -0.5f*pd); + + cpContactInit(arr, cpvadd(point, cpvmult(refn, alpha)), n, pd, hash); + return 1; + } else { + return 0; + } +} + +static inline int +ClipContacts(const struct Edge ref, const struct Edge inc, const struct ClosestPoints points, const cpFloat nflip, cpContact *arr) +{ + cpVect inc_offs = cpvmult(inc.n, inc.r); + cpVect ref_offs = cpvmult(ref.n, ref.r); + + cpVect inca = cpvadd(inc.a.p, inc_offs); + cpVect incb = cpvadd(inc.b.p, inc_offs); + + cpVect closest_inca = cpClosetPointOnSegment(inc.a.p, ref.a.p, ref.b.p); + cpVect closest_incb = cpClosetPointOnSegment(inc.b.p, ref.a.p, ref.b.p); + + cpVect msa = cpvmult(points.n, nflip*points.d); + cpFloat cost_a = cpvdistsq(cpvsub(inc.a.p, closest_inca), msa); + cpFloat cost_b = cpvdistsq(cpvsub(inc.b.p, closest_incb), msa); + +#if DRAW_CLIP + ChipmunkDebugDrawSegment(ref.a.p, ref.b.p, RGBAColor(1, 0, 0, 1)); + ChipmunkDebugDrawSegment(inc.a.p, inc.b.p, RGBAColor(0, 1, 0, 1)); + ChipmunkDebugDrawSegment(inca, incb, RGBAColor(0, 1, 0, 1)); + + cpVect cref = cpvlerp(ref.a.p, ref.b.p, 0.5); + ChipmunkDebugDrawSegment(cref, cpvadd(cref, cpvmult(ref.n, 5.0)), RGBAColor(1, 0, 0, 1)); + + cpVect cinc = cpvlerp(inc.a.p, inc.b.p, 0.5); + ChipmunkDebugDrawSegment(cinc, cpvadd(cinc, cpvmult(inc.n, 5.0)), RGBAColor(1, 0, 0, 1)); + + ChipmunkDebugDrawPoints(5.0, 2, (cpVect[]){ref.a.p, inc.a.p}, RGBAColor(1, 1, 0, 1)); + ChipmunkDebugDrawPoints(5.0, 2, (cpVect[]){ref.b.p, inc.b.p}, RGBAColor(0, 1, 1, 1)); + + if(cost_a < cost_b){ + ChipmunkDebugDrawSegment(closest_inca, inc.a.p, RGBAColor(1, 0, 1, 1)); + } else { + ChipmunkDebugDrawSegment(closest_incb, inc.b.p, RGBAColor(1, 0, 1, 1)); + } +#endif + + cpHashValue hash_iarb = CP_HASH_PAIR(inc.a.hash, ref.b.hash); + cpHashValue hash_ibra = CP_HASH_PAIR(inc.b.hash, ref.a.hash); + + if(cost_a < cost_b){ + cpVect refp = cpvadd(ref.a.p, ref_offs); + Contact1(points.d, closest_inca, inc.a.p, ref.r, inc.r, points.n, hash_iarb, arr); + return Contact2(refp, inca, incb, ref.r, inc.r, ref.n, points.n, hash_ibra, arr + 1) + 1; + } else { + cpVect refp = cpvadd(ref.b.p, ref_offs); + Contact1(points.d, closest_incb, inc.b.p, ref.r, inc.r, points.n, hash_ibra, arr); + return Contact2(refp, incb, inca, ref.r, inc.r, ref.n, points.n, hash_iarb, arr + 1) + 1; + } +} + +static inline int +ContactPoints(const struct Edge e1, const struct Edge e2, const struct ClosestPoints points, cpContact *arr) +{ + cpFloat mindist = e1.r + e2.r; + if(points.d <= mindist){ + cpFloat pick = cpvdot(e1.n, points.n) + cpvdot(e2.n, points.n); + + if( + (pick != 0.0f && pick > 0.0f) || + // If the edges are both perfectly aligned weird things happen. + // This is *very* common at the start of a simulation. + // Pick the longest edge as the reference to break the tie. + (pick == 0.0f && (cpvdistsq(e1.a.p, e1.b.p) > cpvdistsq(e2.a.p, e2.b.p))) + ){ + return ClipContacts(e1, e2, points, 1.0f, arr); + } else { + return ClipContacts(e2, e1, points, -1.0f, arr); + } + } else { + return 0; + } +} + +//MARK: Collision Functions + +typedef int (*CollisionFunc)(const cpShape *a, const cpShape *b, cpCollisionID *id, cpContact *arr); + // Collide circle shapes. static int -circle2circle(const cpShape *shape1, const cpShape *shape2, cpContact *arr) +CircleToCircle(const cpCircleShape *c1, const cpCircleShape *c2, cpCollisionID *id, cpContact *arr) { - cpCircleShape *circ1 = (cpCircleShape *)shape1; //TODO - cpCircleShape *circ2 = (cpCircleShape *)shape2; - - return circle2circleQuery(circ1->tc, circ2->tc, circ1->r, circ2->r, arr); + return CircleToCircleQuery(c1->tc, c2->tc, c1->r, c2->r, 0, arr); } static int -circle2segment(const cpCircleShape *circleShape, const cpSegmentShape *segmentShape, cpContact *con) +CircleToSegment(const cpCircleShape *circleShape, const cpSegmentShape *segmentShape, cpCollisionID *id, cpContact *con) { cpVect seg_a = segmentShape->ta; cpVect seg_b = segmentShape->tb; @@ -68,341 +559,161 @@ circle2segment(const cpCircleShape *circleShape, const cpSegmentShape *segmentSh cpFloat closest_t = cpfclamp01(cpvdot(seg_delta, cpvsub(center, seg_a))/cpvlengthsq(seg_delta)); cpVect closest = cpvadd(seg_a, cpvmult(seg_delta, closest_t)); - if(circle2circleQuery(center, closest, circleShape->r, segmentShape->r, con)){ + if(CircleToCircleQuery(center, closest, circleShape->r, segmentShape->r, 0, con)){ cpVect n = con[0].n; // Reject endcap collisions if tangents are provided. if( - (closest_t == 0.0f && cpvdot(n, segmentShape->a_tangent) < 0.0) || - (closest_t == 1.0f && cpvdot(n, segmentShape->b_tangent) < 0.0) - ) return 0; - + (closest_t != 0.0f || cpvdot(n, cpvrotate(segmentShape->a_tangent, segmentShape->shape.body->rot)) >= 0.0) && + (closest_t != 1.0f || cpvdot(n, cpvrotate(segmentShape->b_tangent, segmentShape->shape.body->rot)) >= 0.0) + ){ + return 1; + } + } + + return 0; +} + +static int +SegmentToSegment(const cpSegmentShape *seg1, const cpSegmentShape *seg2, cpCollisionID *id, cpContact *arr) +{ + struct SupportContext context = {(cpShape *)seg1, (cpShape *)seg2, (SupportPointFunc)SegmentSupportPoint, (SupportPointFunc)SegmentSupportPoint}; + struct ClosestPoints points = GJK(&context, id); + +#if DRAW_CLOSEST +#if PRINT_LOG +// ChipmunkDemoPrintString("Distance: %.2f\n", points.d); +#endif + + ChipmunkDebugDrawDot(6.0, points.a, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawDot(6.0, points.b, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawSegment(points.a, points.b, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawSegment(points.a, cpvadd(points.a, cpvmult(points.n, 10.0)), RGBAColor(1, 0, 0, 1)); +#endif + + cpVect n = points.n; + cpVect rot1 = seg1->shape.body->rot; + cpVect rot2 = seg2->shape.body->rot; + if( + points.d <= (seg1->r + seg2->r) && + ( + (!cpveql(points.a, seg1->ta) || cpvdot(n, cpvrotate(seg1->a_tangent, rot1)) <= 0.0) && + (!cpveql(points.a, seg1->tb) || cpvdot(n, cpvrotate(seg1->b_tangent, rot1)) <= 0.0) && + (!cpveql(points.b, seg2->ta) || cpvdot(n, cpvrotate(seg2->a_tangent, rot2)) >= 0.0) && + (!cpveql(points.b, seg2->tb) || cpvdot(n, cpvrotate(seg2->b_tangent, rot2)) >= 0.0) + ) + ){ + return ContactPoints(SupportEdgeForSegment(seg1, n), SupportEdgeForSegment(seg2, cpvneg(n)), points, arr); + } else { + return 0; + } +} + +static int +PolyToPoly(const cpPolyShape *poly1, const cpPolyShape *poly2, cpCollisionID *id, cpContact *arr) +{ + struct SupportContext context = {(cpShape *)poly1, (cpShape *)poly2, (SupportPointFunc)PolySupportPoint, (SupportPointFunc)PolySupportPoint}; + struct ClosestPoints points = GJK(&context, id); + +#if DRAW_CLOSEST +#if PRINT_LOG +// ChipmunkDemoPrintString("Distance: %.2f\n", points.d); +#endif + + ChipmunkDebugDrawDot(3.0, points.a, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawDot(3.0, points.b, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawSegment(points.a, points.b, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawSegment(points.a, cpvadd(points.a, cpvmult(points.n, 10.0)), RGBAColor(1, 0, 0, 1)); +#endif + + if(points.d - poly1->r - poly2->r <= 0.0){ + return ContactPoints(SupportEdgeForPoly(poly1, points.n), SupportEdgeForPoly(poly2, cpvneg(points.n)), points, arr); + } else { + return 0; + } +} + +static int +SegmentToPoly(const cpSegmentShape *seg, const cpPolyShape *poly, cpCollisionID *id, cpContact *arr) +{ + struct SupportContext context = {(cpShape *)seg, (cpShape *)poly, (SupportPointFunc)SegmentSupportPoint, (SupportPointFunc)PolySupportPoint}; + struct ClosestPoints points = GJK(&context, id); + +#if DRAW_CLOSEST +#if PRINT_LOG +// ChipmunkDemoPrintString("Distance: %.2f\n", points.d); +#endif + + ChipmunkDebugDrawDot(3.0, points.a, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawDot(3.0, points.b, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawSegment(points.a, points.b, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawSegment(points.a, cpvadd(points.a, cpvmult(points.n, 10.0)), RGBAColor(1, 0, 0, 1)); +#endif + + // Reject endcap collisions if tangents are provided. + cpVect n = points.n; + cpVect rot = seg->shape.body->rot; + if( + points.d - seg->r - poly->r <= 0.0 && + ( + (!cpveql(points.a, seg->ta) || cpvdot(n, cpvrotate(seg->a_tangent, rot)) <= 0.0) && + (!cpveql(points.a, seg->tb) || cpvdot(n, cpvrotate(seg->b_tangent, rot)) <= 0.0) + ) + ){ + return ContactPoints(SupportEdgeForSegment(seg, n), SupportEdgeForPoly(poly, cpvneg(n)), points, arr); + } else { + return 0; + } +} + +// This one is less gross, but still gross. +// TODO: Comment me! +static int +CircleToPoly(const cpCircleShape *circle, const cpPolyShape *poly, cpCollisionID *id, cpContact *con) +{ + struct SupportContext context = {(cpShape *)circle, (cpShape *)poly, (SupportPointFunc)CircleSupportPoint, (SupportPointFunc)PolySupportPoint}; + struct ClosestPoints points = GJK(&context, id); + +#if DRAW_CLOSEST + ChipmunkDebugDrawDot(3.0, points.a, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawDot(3.0, points.b, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawSegment(points.a, points.b, RGBAColor(1, 1, 1, 1)); + ChipmunkDebugDrawSegment(points.a, cpvadd(points.a, cpvmult(points.n, 10.0)), RGBAColor(1, 0, 0, 1)); +#endif + + cpFloat mindist = circle->r + poly->r; + if(points.d - mindist <= 0.0){ + cpVect p = cpvlerp(points.a, points.b, circle->r/(mindist)); + cpContactInit(con, p, points.n, points.d - mindist, 0); return 1; } else { return 0; } } -// Helper function for working with contact buffers -// This used to malloc/realloc memory on the fly but was repurposed. -static cpContact * -nextContactPoint(cpContact *arr, int *numPtr) -{ - int index = *numPtr; - - if(index < CP_MAX_CONTACTS_PER_ARBITER){ - (*numPtr) = index + 1; - return &arr[index]; - } else { - return &arr[CP_MAX_CONTACTS_PER_ARBITER - 1]; - } -} - -// Find the minimum separating axis for the give poly and axis list. -static inline int -findMSA(const cpPolyShape *poly, const cpSplittingPlane *planes, const int num, cpFloat *min_out) -{ - int min_index = 0; - cpFloat min = cpPolyShapeValueOnAxis(poly, planes->n, planes->d); - if(min > 0.0f) return -1; - - for(int i=1; i 0.0f) { - return -1; - } else if(dist > min){ - min = dist; - min_index = i; - } - } - - (*min_out) = min; - return min_index; -} - -// Add contacts for probably penetrating vertexes. -// This handles the degenerate case where an overlap was detected, but no vertexes fall inside -// the opposing polygon. (like a star of david) -static inline int -findVertsFallback(cpContact *arr, const cpPolyShape *poly1, const cpPolyShape *poly2, const cpVect n, const cpFloat dist) -{ - int num = 0; - - for(int i=0; inumVerts; i++){ - cpVect v = poly1->tVerts[i]; - if(cpPolyShapeContainsVertPartial(poly2, v, cpvneg(n))) - cpContactInit(nextContactPoint(arr, &num), v, n, dist, CP_HASH_PAIR(poly1->shape.hashid, i)); - } - - for(int i=0; inumVerts; i++){ - cpVect v = poly2->tVerts[i]; - if(cpPolyShapeContainsVertPartial(poly1, v, n)) - cpContactInit(nextContactPoint(arr, &num), v, n, dist, CP_HASH_PAIR(poly2->shape.hashid, i)); - } - - return num; -} - -// Add contacts for penetrating vertexes. -static inline int -findVerts(cpContact *arr, const cpPolyShape *poly1, const cpPolyShape *poly2, const cpVect n, const cpFloat dist) -{ - int num = 0; - - for(int i=0; inumVerts; i++){ - cpVect v = poly1->tVerts[i]; - if(cpPolyShapeContainsVert(poly2, v)) - cpContactInit(nextContactPoint(arr, &num), v, n, dist, CP_HASH_PAIR(poly1->shape.hashid, i)); - } - - for(int i=0; inumVerts; i++){ - cpVect v = poly2->tVerts[i]; - if(cpPolyShapeContainsVert(poly1, v)) - cpContactInit(nextContactPoint(arr, &num), v, n, dist, CP_HASH_PAIR(poly2->shape.hashid, i)); - } - - return (num ? num : findVertsFallback(arr, poly1, poly2, n, dist)); -} - -// Collide poly shapes together. -static int -poly2poly(const cpShape *shape1, const cpShape *shape2, cpContact *arr) -{ - cpPolyShape *poly1 = (cpPolyShape *)shape1; - cpPolyShape *poly2 = (cpPolyShape *)shape2; - - cpFloat min1; - int mini1 = findMSA(poly2, poly1->tPlanes, poly1->numVerts, &min1); - if(mini1 == -1) return 0; - - cpFloat min2; - int mini2 = findMSA(poly1, poly2->tPlanes, poly2->numVerts, &min2); - if(mini2 == -1) return 0; - - // There is overlap, find the penetrating verts - if(min1 > min2) - return findVerts(arr, poly1, poly2, poly1->tPlanes[mini1].n, min1); - else - return findVerts(arr, poly1, poly2, cpvneg(poly2->tPlanes[mini2].n), min2); -} - -// Like cpPolyValueOnAxis(), but for segments. -static inline cpFloat -segValueOnAxis(const cpSegmentShape *seg, const cpVect n, const cpFloat d) -{ - cpFloat a = cpvdot(n, seg->ta) - seg->r; - cpFloat b = cpvdot(n, seg->tb) - seg->r; - return cpfmin(a, b) - d; -} - -// Identify vertexes that have penetrated the segment. -static inline void -findPointsBehindSeg(cpContact *arr, int *num, const cpSegmentShape *seg, const cpPolyShape *poly, const cpFloat pDist, const cpFloat coef) -{ - cpFloat dta = cpvcross(seg->tn, seg->ta); - cpFloat dtb = cpvcross(seg->tn, seg->tb); - cpVect n = cpvmult(seg->tn, coef); - - for(int i=0; inumVerts; i++){ - cpVect v = poly->tVerts[i]; - if(cpvdot(v, n) < cpvdot(seg->tn, seg->ta)*coef + seg->r){ - cpFloat dt = cpvcross(seg->tn, v); - if(dta >= dt && dt >= dtb){ - cpContactInit(nextContactPoint(arr, num), v, n, pDist, CP_HASH_PAIR(poly->shape.hashid, i)); - } - } - } -} - -// This one is complicated and gross. Just don't go there... -// TODO: Comment me! -static int -seg2poly(const cpShape *shape1, const cpShape *shape2, cpContact *arr) -{ - cpSegmentShape *seg = (cpSegmentShape *)shape1; - cpPolyShape *poly = (cpPolyShape *)shape2; - cpSplittingPlane *planes = poly->tPlanes; - - cpFloat segD = cpvdot(seg->tn, seg->ta); - cpFloat minNorm = cpPolyShapeValueOnAxis(poly, seg->tn, segD) - seg->r; - cpFloat minNeg = cpPolyShapeValueOnAxis(poly, cpvneg(seg->tn), -segD) - seg->r; - if(minNeg > 0.0f || minNorm > 0.0f) return 0; - - int mini = 0; - cpFloat poly_min = segValueOnAxis(seg, planes->n, planes->d); - if(poly_min > 0.0f) return 0; - for(int i=0; inumVerts; i++){ - cpFloat dist = segValueOnAxis(seg, planes[i].n, planes[i].d); - if(dist > 0.0f){ - return 0; - } else if(dist > poly_min){ - poly_min = dist; - mini = i; - } - } - - int num = 0; - - cpVect poly_n = cpvneg(planes[mini].n); - - cpVect va = cpvadd(seg->ta, cpvmult(poly_n, seg->r)); - cpVect vb = cpvadd(seg->tb, cpvmult(poly_n, seg->r)); - if(cpPolyShapeContainsVert(poly, va)) - cpContactInit(nextContactPoint(arr, &num), va, poly_n, poly_min, CP_HASH_PAIR(seg->shape.hashid, 0)); - if(cpPolyShapeContainsVert(poly, vb)) - cpContactInit(nextContactPoint(arr, &num), vb, poly_n, poly_min, CP_HASH_PAIR(seg->shape.hashid, 1)); - - // Floating point precision problems here. - // This will have to do for now. -// poly_min -= cp_collision_slop; // TODO is this needed anymore? - - if(minNorm >= poly_min || minNeg >= poly_min) { - if(minNorm > minNeg) - findPointsBehindSeg(arr, &num, seg, poly, minNorm, 1.0f); - else - findPointsBehindSeg(arr, &num, seg, poly, minNeg, -1.0f); - } - - // If no other collision points are found, try colliding endpoints. - if(num == 0){ - cpVect poly_a = poly->tVerts[mini]; - cpVect poly_b = poly->tVerts[(mini + 1)%poly->numVerts]; - - if(circle2circleQuery(seg->ta, poly_a, seg->r, 0.0f, arr)) return 1; - if(circle2circleQuery(seg->tb, poly_a, seg->r, 0.0f, arr)) return 1; - if(circle2circleQuery(seg->ta, poly_b, seg->r, 0.0f, arr)) return 1; - if(circle2circleQuery(seg->tb, poly_b, seg->r, 0.0f, arr)) return 1; - } - - return num; -} - -// This one is less gross, but still gross. -// TODO: Comment me! -static int -circle2poly(const cpShape *shape1, const cpShape *shape2, cpContact *con) -{ - cpCircleShape *circ = (cpCircleShape *)shape1; - cpPolyShape *poly = (cpPolyShape *)shape2; - cpSplittingPlane *planes = poly->tPlanes; - - int mini = 0; - cpFloat min = cpSplittingPlaneCompare(planes[0], circ->tc) - circ->r; - for(int i=0; inumVerts; i++){ - cpFloat dist = cpSplittingPlaneCompare(planes[i], circ->tc) - circ->r; - if(dist > 0.0f){ - return 0; - } else if(dist > min) { - min = dist; - mini = i; - } - } - - cpVect n = planes[mini].n; - cpVect a = poly->tVerts[mini]; - cpVect b = poly->tVerts[(mini + 1)%poly->numVerts]; - cpFloat dta = cpvcross(n, a); - cpFloat dtb = cpvcross(n, b); - cpFloat dt = cpvcross(n, circ->tc); - - if(dt < dtb){ - return circle2circleQuery(circ->tc, b, circ->r, 0.0f, con); - } else if(dt < dta) { - cpContactInit( - con, - cpvsub(circ->tc, cpvmult(n, circ->r + min/2.0f)), - cpvneg(n), - min, - 0 - ); - - return 1; - } else { - return circle2circleQuery(circ->tc, a, circ->r, 0.0f, con); - } -} - -// Submitted by LegoCyclon -static int -seg2seg(const cpShape* shape1, const cpShape* shape2, cpContact* con) -{ - cpSegmentShape* seg1 = (cpSegmentShape *)shape1; - cpSegmentShape* seg2 = (cpSegmentShape *)shape2; - - cpVect v1 = cpvsub(seg1->tb, seg1->ta); - cpVect v2 = cpvsub(seg2->tb, seg2->ta); - cpFloat v1lsq = cpvlengthsq(v1); - cpFloat v2lsq = cpvlengthsq(v2); - // project seg2 onto seg1 - cpVect p1a = cpvproject(cpvsub(seg2->ta, seg1->ta), v1); - cpVect p1b = cpvproject(cpvsub(seg2->tb, seg1->ta), v1); - // project seg1 onto seg2 - cpVect p2a = cpvproject(cpvsub(seg1->ta, seg2->ta), v2); - cpVect p2b = cpvproject(cpvsub(seg1->tb, seg2->ta), v2); - - // clamp projections to segment endcaps - if (cpvdot(p1a, v1) < 0.0f) - p1a = cpvzero; - else if (cpvdot(p1a, v1) > 0.0f && cpvlengthsq(p1a) > v1lsq) - p1a = v1; - if (cpvdot(p1b, v1) < 0.0f) - p1b = cpvzero; - else if (cpvdot(p1b, v1) > 0.0f && cpvlengthsq(p1b) > v1lsq) - p1b = v1; - if (cpvdot(p2a, v2) < 0.0f) - p2a = cpvzero; - else if (cpvdot(p2a, v2) > 0.0f && cpvlengthsq(p2a) > v2lsq) - p2a = v2; - if (cpvdot(p2b, v2) < 0.0f) - p2b = cpvzero; - else if (cpvdot(p2b, v2) > 0.0f && cpvlengthsq(p2b) > v2lsq) - p2b = v2; - - p1a = cpvadd(p1a, seg1->ta); - p1b = cpvadd(p1b, seg1->ta); - p2a = cpvadd(p2a, seg2->ta); - p2b = cpvadd(p2b, seg2->ta); - - int num = 0; - - if (!circle2circleQuery(p1a, p2a, seg1->r, seg2->r, nextContactPoint(con, &num))) - --num; - - if (!circle2circleQuery(p1b, p2b, seg1->r, seg2->r, nextContactPoint(con, &num))) - --num; - - if (!circle2circleQuery(p1a, p2b, seg1->r, seg2->r, nextContactPoint(con, &num))) - --num; - - if (!circle2circleQuery(p1b, p2a, seg1->r, seg2->r, nextContactPoint(con, &num))) - --num; - - return num; -} - -static const collisionFunc builtinCollisionFuncs[9] = { - circle2circle, +static const CollisionFunc builtinCollisionFuncs[9] = { + (CollisionFunc)CircleToCircle, NULL, NULL, - (collisionFunc)circle2segment, + (CollisionFunc)CircleToSegment, NULL, NULL, - circle2poly, - seg2poly, - poly2poly, + (CollisionFunc)CircleToPoly, + (CollisionFunc)SegmentToPoly, + (CollisionFunc)PolyToPoly, }; -static const collisionFunc *colfuncs = builtinCollisionFuncs; +static const CollisionFunc *colfuncs = builtinCollisionFuncs; -static const collisionFunc segmentCollisions[9] = { - circle2circle, +static const CollisionFunc segmentCollisions[9] = { + (CollisionFunc)CircleToCircle, NULL, NULL, - (collisionFunc)circle2segment, - seg2seg, + (CollisionFunc)CircleToSegment, + (CollisionFunc)SegmentToSegment, NULL, - circle2poly, - seg2poly, - poly2poly, + (CollisionFunc)CircleToPoly, + (CollisionFunc)SegmentToPoly, + (CollisionFunc)PolyToPoly, }; void @@ -412,11 +723,15 @@ cpEnableSegmentToSegmentCollisions(void) } int -cpCollideShapes(const cpShape *a, const cpShape *b, cpContact *arr) +cpCollideShapes(const cpShape *a, const cpShape *b, cpCollisionID *id, cpContact *arr) { // Their shape types must be in order. - cpAssertSoft(a->klass->type <= b->klass->type, "Collision shapes passed to cpCollideShapes() are not sorted."); + cpAssertSoft(a->klass->type <= b->klass->type, "Internal Error: Collision shapes passed to cpCollideShapes() are not sorted."); - collisionFunc cfunc = colfuncs[a->klass->type + b->klass->type*CP_NUM_SHAPES]; - return (cfunc) ? cfunc(a, b, arr) : 0; + CollisionFunc cfunc = colfuncs[a->klass->type + b->klass->type*CP_NUM_SHAPES]; + + int numContacts = (cfunc? cfunc(a, b, id, arr) : 0); + cpAssertSoft(numContacts <= CP_MAX_CONTACTS_PER_ARBITER, "Internal error: Too many contact points returned."); + + return numContacts; } diff --git a/external/chipmunk/src/cpPolyShape.c b/external/chipmunk/src/cpPolyShape.c index 8250cbd514..12f2168c9a 100644 --- a/external/chipmunk/src/cpPolyShape.c +++ b/external/chipmunk/src/cpPolyShape.c @@ -47,7 +47,8 @@ cpPolyShapeTransformVerts(cpPolyShape *poly, cpVect p, cpVect rot) t = cpfmax(t, v.y); } - return cpBBNew(l, b, r, t); + cpFloat radius = poly->r; + return cpBBNew(l - radius, b - radius, r + radius, t + radius); } static void @@ -84,10 +85,12 @@ cpPolyShapeNearestPointQuery(cpPolyShape *poly, cpVect p, cpNearestPointQueryInf int count = poly->numVerts; cpSplittingPlane *planes = poly->tPlanes; cpVect *verts = poly->tVerts; + cpFloat r = poly->r; cpVect v0 = verts[count - 1]; cpFloat minDist = INFINITY; cpVect closestPoint = cpvzero; + cpVect closestNormal = cpvzero; cpBool outside = cpFalse; for(int i=0; ishape = (cpShape *)poly; - info->p = closestPoint; // TODO div/0 - info->d = (outside ? minDist : -minDist); + info->p = cpvadd(closestPoint, cpvmult(g, r)); + info->d = dist - r; + + // Use the normal of the closest segment if the distance is small. + info->g = (minDist > MAGIC_EPSILON ? g : closestNormal); } static void @@ -116,20 +126,22 @@ cpPolyShapeSegmentQuery(cpPolyShape *poly, cpVect a, cpVect b, cpSegmentQueryInf cpSplittingPlane *axes = poly->tPlanes; cpVect *verts = poly->tVerts; int numVerts = poly->numVerts; + cpFloat r = poly->r; for(int i=0; i an) continue; + cpFloat d = axes[i].d + r - an; + if(d > 0.0f) continue; cpFloat bn = cpvdot(b, n); - cpFloat t = (axes[i].d - an)/(bn - an); + cpFloat t = d/(bn - an); if(t < 0.0f || 1.0f < t) continue; cpVect point = cpvlerp(a, b, t); cpFloat dt = -cpvcross(n, point); - cpFloat dtMin = -cpvcross(n, verts[i]); - cpFloat dtMax = -cpvcross(n, verts[(i+1)%numVerts]); + cpFloat dtMin = -cpvcross(n, verts[(i - 1 + numVerts)%numVerts]); + cpFloat dtMax = -cpvcross(n, verts[i]); if(dtMin <= dt && dt <= dtMax){ info->shape = (cpShape *)poly; @@ -137,6 +149,15 @@ cpPolyShapeSegmentQuery(cpPolyShape *poly, cpVect a, cpVect b, cpSegmentQueryInf info->n = n; } } + + // Also check against the beveled vertexes. + if(r > 0.0f){ + for(int i=0; ishape, verts[i], r, a, b, &circle_info); + if(circle_info.t < info->t) (*info) = circle_info; + } + } } static const cpShapeClass polyClass = { @@ -164,14 +185,14 @@ cpPolyValidate(const cpVect *verts, const int numVerts) } int -cpPolyShapeGetNumVerts(cpShape *shape) +cpPolyShapeGetNumVerts(const cpShape *shape) { cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape."); return ((cpPolyShape *)shape)->numVerts; } cpVect -cpPolyShapeGetVert(cpShape *shape, int idx) +cpPolyShapeGetVert(const cpShape *shape, int idx) { cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape."); cpAssertHard(0 <= idx && idx < cpPolyShapeGetNumVerts(shape), "Index out of range."); @@ -179,6 +200,13 @@ cpPolyShapeGetVert(cpShape *shape, int idx) return ((cpPolyShape *)shape)->verts[idx]; } +cpFloat +cpPolyShapeGetRadius(const cpShape *shape) +{ + cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape."); + return ((cpPolyShape *)shape)->r; +} + static void setUpVerts(cpPolyShape *poly, int numVerts, const cpVect *verts, cpVect offset) @@ -202,21 +230,39 @@ setUpVerts(cpPolyShape *poly, int numVerts, const cpVect *verts, cpVect offset) poly->planes[i].d = cpvdot(n, a); } + // TODO: Why did I add this? It duplicates work from above. + for(int i=0; iplanes[i] = cpSplittingPlaneNew(poly->verts[(i - 1 + numVerts)%numVerts], poly->verts[i]); + } } cpPolyShape * cpPolyShapeInit(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset) +{ + return cpPolyShapeInit2(poly, body, numVerts, verts, offset, 0.0f); +} + +cpPolyShape * +cpPolyShapeInit2(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset, cpFloat radius) { setUpVerts(poly, numVerts, verts, offset); cpShapeInit((cpShape *)poly, &polyClass, body); + poly->r = radius; return poly; } + cpShape * -cpPolyShapeNew(cpBody *body, int numVerts, cpVect *verts, cpVect offset) +cpPolyShapeNew(cpBody *body, int numVerts, const cpVect *verts, cpVect offset) { - return (cpShape *)cpPolyShapeInit(cpPolyShapeAlloc(), body, numVerts, verts, offset); + return cpPolyShapeNew2(body, numVerts, verts, offset, 0.0f); +} + +cpShape * +cpPolyShapeNew2(cpBody *body, int numVerts, const cpVect *verts, cpVect offset, cpFloat radius) +{ + return (cpShape *)cpPolyShapeInit2(cpPolyShapeAlloc(), body, numVerts, verts, offset, radius); } cpPolyShape * @@ -230,6 +276,12 @@ cpBoxShapeInit(cpPolyShape *poly, cpBody *body, cpFloat width, cpFloat height) cpPolyShape * cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box) +{ + return cpBoxShapeInit3(poly, body, box, 0.0f); +} + +cpPolyShape * +cpBoxShapeInit3(cpPolyShape *poly, cpBody *body, cpBB box, cpFloat radius) { cpVect verts[] = { cpv(box.l, box.b), @@ -238,7 +290,7 @@ cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box) cpv(box.r, box.b), }; - return cpPolyShapeInit(poly, body, 4, verts, cpvzero); + return cpPolyShapeInit2(poly, body, 4, verts, cpvzero, radius); } cpShape * @@ -253,6 +305,12 @@ cpBoxShapeNew2(cpBody *body, cpBB box) return (cpShape *)cpBoxShapeInit2(cpPolyShapeAlloc(), body, box); } +cpShape * +cpBoxShapeNew3(cpBody *body, cpBB box, cpFloat radius) +{ + return (cpShape *)cpBoxShapeInit3(cpPolyShapeAlloc(), body, box, radius); +} + // Unsafe API (chipmunk_unsafe.h) void @@ -262,3 +320,10 @@ cpPolyShapeSetVerts(cpShape *shape, int numVerts, cpVect *verts, cpVect offset) cpPolyShapeDestroy((cpPolyShape *)shape); setUpVerts((cpPolyShape *)shape, numVerts, verts, offset); } + +void +cpPolyShapeSetRadius(cpShape *shape, cpFloat radius) +{ + cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape."); + ((cpPolyShape *)shape)->r = radius; +} diff --git a/external/chipmunk/src/cpShape.c b/external/chipmunk/src/cpShape.c index a07cc5da75..56f00b066a 100644 --- a/external/chipmunk/src/cpShape.c +++ b/external/chipmunk/src/cpShape.c @@ -103,7 +103,7 @@ cpShapeUpdate(cpShape *shape, cpVect pos, cpVect rot) cpBool cpShapePointQuery(cpShape *shape, cpVect p){ - cpNearestPointQueryInfo info = {NULL, cpvzero, INFINITY}; + cpNearestPointQueryInfo info = {NULL, cpvzero, INFINITY, cpvzero}; cpShapeNearestPointQuery(shape, p, &info); return (info.d < 0.0f); @@ -112,7 +112,7 @@ cpShapePointQuery(cpShape *shape, cpVect p){ cpFloat cpShapeNearestPointQuery(cpShape *shape, cpVect p, cpNearestPointQueryInfo *info) { - cpNearestPointQueryInfo blank = {NULL, cpvzero, INFINITY}; + cpNearestPointQueryInfo blank = {NULL, cpvzero, INFINITY, cpvzero}; if(info){ (*info) = blank; } else { @@ -126,7 +126,7 @@ cpShapeNearestPointQuery(cpShape *shape, cpVect p, cpNearestPointQueryInfo *info cpBool cpShapeSegmentQuery(cpShape *shape, cpVect a, cpVect b, cpSegmentQueryInfo *info){ - cpSegmentQueryInfo blank = {NULL, 0.0f, cpvzero}; + cpSegmentQueryInfo blank = {NULL, 1.0f, cpvzero}; if(info){ (*info) = blank; } else { @@ -169,34 +169,15 @@ cpCicleShapeNearestPointQuery(cpCircleShape *circle, cpVect p, cpNearestPointQue info->shape = (cpShape *)circle; info->p = cpvadd(circle->tc, cpvmult(delta, r/d)); // TODO div/0 info->d = d - r; -} - -static void -circleSegmentQuery(cpShape *shape, cpVect center, cpFloat r, cpVect a, cpVect b, cpSegmentQueryInfo *info) -{ - cpVect da = cpvsub(a, center); - cpVect db = cpvsub(b, center); - cpFloat qa = cpvdot(da, da) - 2.0f*cpvdot(da, db) + cpvdot(db, db); - cpFloat qb = -2.0f*cpvdot(da, da) + 2.0f*cpvdot(da, db); - cpFloat qc = cpvdot(da, da) - r*r; - - cpFloat det = qb*qb - 4.0f*qa*qc; - - if(det >= 0.0f){ - cpFloat t = (-qb - cpfsqrt(det))/(2.0f*qa); - if(0.0f<= t && t <= 1.0f){ - info->shape = shape; - info->t = t; - info->n = cpvnormalize(cpvlerp(da, db, t)); - } - } + // Use up for the gradient if the distance is very small. + info->g = (d > MAGIC_EPSILON ? cpvmult(delta, 1.0f/d) : cpv(0.0f, 1.0f)); } static void cpCircleShapeSegmentQuery(cpCircleShape *circle, cpVect a, cpVect b, cpSegmentQueryInfo *info) { - circleSegmentQuery((cpShape *)circle, circle->tc, circle->r, a, b, info); + CircleSegmentQuery((cpShape *)circle, circle->tc, circle->r, a, b, info); } static const cpShapeClass cpCircleShapeClass = { @@ -270,10 +251,14 @@ cpSegmentShapeNearestPointQuery(cpSegmentShape *seg, cpVect p, cpNearestPointQue cpVect delta = cpvsub(p, closest); cpFloat d = cpvlength(delta); cpFloat r = seg->r; + cpVect g = cpvmult(delta, 1.0f/d); info->shape = (cpShape *)seg; - info->p = (d ? cpvadd(closest, cpvmult(delta, r/d)) : closest); + info->p = (d ? cpvadd(closest, cpvmult(g, r)) : closest); info->d = d - r; + + // Use the segment's normal if the distance is very small. + info->g = (d > MAGIC_EPSILON ? g : seg->n); } static void @@ -304,8 +289,8 @@ cpSegmentShapeSegmentQuery(cpSegmentShape *seg, cpVect a, cpVect b, cpSegmentQue } else if(r != 0.0f){ cpSegmentQueryInfo info1 = {NULL, 1.0f, cpvzero}; cpSegmentQueryInfo info2 = {NULL, 1.0f, cpvzero}; - circleSegmentQuery((cpShape *)seg, seg->ta, seg->r, a, b, &info1); - circleSegmentQuery((cpShape *)seg, seg->tb, seg->r, a, b, &info2); + CircleSegmentQuery((cpShape *)seg, seg->ta, seg->r, a, b, &info1); + CircleSegmentQuery((cpShape *)seg, seg->tb, seg->r, a, b, &info2); if(info1.t < info2.t){ (*info) = info1; diff --git a/external/chipmunk/src/cpSpaceHash.c b/external/chipmunk/src/cpSpaceHash.c index 7479e9d3b1..9e20715e69 100644 --- a/external/chipmunk/src/cpSpaceHash.c +++ b/external/chipmunk/src/cpSpaceHash.c @@ -362,7 +362,7 @@ query_helper(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSpatialIn if(hand->stamp == hash->stamp || obj == other){ continue; } else if(other){ - func(obj, other, data); + func(obj, other, 0, data); hand->stamp = hash->stamp; } else { // The object for this handle has been removed diff --git a/external/chipmunk/src/cpSpaceQuery.c b/external/chipmunk/src/cpSpaceQuery.c index bf977dc28a..944bc4cec1 100644 --- a/external/chipmunk/src/cpSpaceQuery.c +++ b/external/chipmunk/src/cpSpaceQuery.c @@ -31,8 +31,8 @@ struct PointQueryContext { void *data; }; -static void -PointQuery(struct PointQueryContext *context, cpShape *shape, void *data) +static cpCollisionID +PointQuery(struct PointQueryContext *context, cpShape *shape, cpCollisionID id, void *data) { if( !(shape->group && context->group == shape->group) && (context->layers&shape->layers) && @@ -40,6 +40,8 @@ PointQuery(struct PointQueryContext *context, cpShape *shape, void *data) ){ context->func(shape, context->data); } + + return id; } void @@ -79,8 +81,8 @@ struct NearestPointQueryContext { cpSpaceNearestPointQueryFunc func; }; -static void -NearestPointQuery(struct NearestPointQueryContext *context, cpShape *shape, void *data) +static cpCollisionID +NearestPointQuery(struct NearestPointQueryContext *context, cpShape *shape, cpCollisionID id, void *data) { if( !(shape->group && context->group == shape->group) && (context->layers&shape->layers) @@ -90,6 +92,8 @@ NearestPointQuery(struct NearestPointQueryContext *context, cpShape *shape, void if(info.shape && info.d < context->maxDistance) context->func(shape, info.d, info.p, data); } + + return id; } void @@ -104,8 +108,8 @@ cpSpaceNearestPointQuery(cpSpace *space, cpVect point, cpFloat maxDistance, cpLa } cpSpaceUnlock(space, cpTrue); } -static void -NearestPointQueryNearest(struct NearestPointQueryContext *context, cpShape *shape, cpNearestPointQueryInfo *out) +static cpCollisionID +NearestPointQueryNearest(struct NearestPointQueryContext *context, cpShape *shape, cpCollisionID id, cpNearestPointQueryInfo *out) { if( !(shape->group && context->group == shape->group) && (context->layers&shape->layers) && !shape->sensor @@ -115,12 +119,14 @@ NearestPointQueryNearest(struct NearestPointQueryContext *context, cpShape *shap if(info.d < out->d) (*out) = info; } + + return id; } cpShape * cpSpaceNearestPointQueryNearest(cpSpace *space, cpVect point, cpFloat maxDistance, cpLayers layers, cpGroup group, cpNearestPointQueryInfo *out) { - cpNearestPointQueryInfo info = {NULL, cpvzero, maxDistance}; + cpNearestPointQueryInfo info = {NULL, cpvzero, maxDistance, cpvzero}; if(out){ (*out) = info; } else { @@ -228,8 +234,8 @@ struct BBQueryContext { cpSpaceBBQueryFunc func; }; -static void -BBQuery(struct BBQueryContext *context, cpShape *shape, void *data) +static cpCollisionID +BBQuery(struct BBQueryContext *context, cpShape *shape, cpCollisionID id, void *data) { if( !(shape->group && context->group == shape->group) && (context->layers&shape->layers) && @@ -237,6 +243,8 @@ BBQuery(struct BBQueryContext *context, cpShape *shape, void *data) ){ context->func(shape, data); } + + return id; } void @@ -259,24 +267,24 @@ struct ShapeQueryContext { }; // Callback from the spatial hash. -static void -ShapeQuery(cpShape *a, cpShape *b, struct ShapeQueryContext *context) +static cpCollisionID +ShapeQuery(cpShape *a, cpShape *b, cpCollisionID id, struct ShapeQueryContext *context) { // Reject any of the simple cases if( (a->group && a->group == b->group) || !(a->layers & b->layers) || a == b - ) return; + ) return id; cpContact contacts[CP_MAX_CONTACTS_PER_ARBITER]; int numContacts = 0; // Shape 'a' should have the lower shape type. (required by cpCollideShapes() ) if(a->klass->type <= b->klass->type){ - numContacts = cpCollideShapes(a, b, contacts); + numContacts = cpCollideShapes(a, b, &id, contacts); } else { - numContacts = cpCollideShapes(b, a, contacts); + numContacts = cpCollideShapes(b, a, &id, contacts); for(int i=0; ifunc(b, &set, context->data); } } + + return id; } cpBool diff --git a/external/chipmunk/src/cpSpaceStep.c b/external/chipmunk/src/cpSpaceStep.c index f80b8d0e6a..f6f6d050f0 100644 --- a/external/chipmunk/src/cpSpaceStep.c +++ b/external/chipmunk/src/cpSpaceStep.c @@ -219,19 +219,20 @@ queryReject(cpShape *a, cpShape *b) } // Callback from the spatial hash. -void -cpSpaceCollideShapes(cpShape *a, cpShape *b, cpSpace *space) +cpCollisionID +cpSpaceCollideShapes(cpShape *a, cpShape *b, cpCollisionID id, cpSpace *space) { // Reject any of the simple cases - if(queryReject(a,b)) return; + if(queryReject(a,b)) return id; cpCollisionHandler *handler = cpSpaceLookupHandler(space, a->collision_type, b->collision_type); cpBool sensor = a->sensor || b->sensor; - if(sensor && handler == &cpDefaultCollisionHandler) return; + if(sensor && handler == &cpDefaultCollisionHandler) return id; // Shape 'a' should have the lower shape type. (required by cpCollideShapes() ) - if(a->klass->type > b->klass->type){ + // TODO remove me: a < b comparison is for debugging collisions + if(a->klass->type > b->klass->type || (a->klass->type == b->klass->type && a < b)){ cpShape *temp = a; a = b; b = temp; @@ -239,8 +240,8 @@ cpSpaceCollideShapes(cpShape *a, cpShape *b, cpSpace *space) // Narrow-phase collision detection. cpContact *contacts = cpContactBufferGetArray(space); - int numContacts = cpCollideShapes(a, b, contacts); - if(!numContacts) return; // Shapes are not colliding. + int numContacts = cpCollideShapes(a, b, &id, contacts); + if(!numContacts) return id; // Shapes are not colliding. cpSpacePushContacts(space, numContacts); // Get an arbiter from space->arbiterSet for the two shapes. @@ -277,6 +278,7 @@ cpSpaceCollideShapes(cpShape *a, cpShape *b, cpSpace *space) // Time stamp the arbiter so we know it was used recently. arb->stamp = space->stamp; + return id; } // Hashset filter func to throw away old arbiters. diff --git a/external/chipmunk/src/cpSweep1D.c b/external/chipmunk/src/cpSweep1D.c index f617bce021..80b9a4ac53 100644 --- a/external/chipmunk/src/cpSweep1D.c +++ b/external/chipmunk/src/cpSweep1D.c @@ -183,7 +183,7 @@ cpSweep1DQuery(cpSweep1D *sweep, void *obj, cpBB bb, cpSpatialIndexQueryFunc fun TableCell *table = sweep->table; for(int i=0, count=sweep->num; isetPosition(Point( VisibleRect::center().x, VisibleRect::top().y - 30)); + label->setPosition(cocos2d::Point( VisibleRect::center().x, VisibleRect::top().y - 30)); this->addChild(label, -1); // reset button @@ -52,7 +52,7 @@ ChipmunkTestLayer::ChipmunkTestLayer() #endif addChild(parent, 0, kTagParentNode); - addNewSpriteAtPosition(Point(200,200)); + addNewSpriteAtPosition(cocos2d::Point(200,200)); // menu for debug layer MenuItemFont::setFontSize(18); @@ -60,7 +60,7 @@ ChipmunkTestLayer::ChipmunkTestLayer() auto menu = Menu::create(item, NULL); this->addChild(menu); - menu->setPosition(Point(VisibleRect::right().x-100, VisibleRect::top().y-60)); + menu->setPosition(cocos2d::Point(VisibleRect::right().x-100, VisibleRect::top().y-60)); scheduleUpdate(); #else @@ -160,7 +160,7 @@ void ChipmunkTestLayer::createResetButton() auto menu = Menu::create(reset, NULL); - menu->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y + 30)); + menu->setPosition(cocos2d::Point(VisibleRect::center().x, VisibleRect::bottom().y + 30)); this->addChild(menu, -1); } @@ -174,7 +174,7 @@ void ChipmunkTestLayer::reset(Ref* sender) s->release(); } -void ChipmunkTestLayer::addNewSpriteAtPosition(Point pos) +void ChipmunkTestLayer::addNewSpriteAtPosition(cocos2d::Point pos) { #if CC_ENABLE_CHIPMUNK_INTEGRATION int posx, posy; @@ -205,7 +205,7 @@ void ChipmunkTestLayer::addNewSpriteAtPosition(Point pos) shape->e = 0.5f; shape->u = 0.5f; cpSpaceAddShape(_space, shape); - auto sprite = PhysicsSprite::createWithTexture(_spriteTexture, Rect(posx, posy, 85, 121)); + auto sprite = PhysicsSprite::createWithTexture(_spriteTexture, cocos2d::Rect(posx, posy, 85, 121)); parent->addChild(sprite); sprite->setCPBody(body); @@ -242,7 +242,7 @@ void ChipmunkTestLayer::onAcceleration(Acceleration* acc, Event* event) prevX = accelX; prevY = accelY; - auto v = Point( accelX, accelY); + auto v = cocos2d::Point( accelX, accelY); v = v * 200; _space->gravity = cpv(v.x, v.y); } diff --git a/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.h b/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.h index 13d216c359..52f7295ee4 100644 --- a/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.h +++ b/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.h @@ -21,7 +21,7 @@ public: void createResetButton(); void reset(Ref* sender); - void addNewSpriteAtPosition(Point p); + void addNewSpriteAtPosition(cocos2d::Point p); void update(float dt); void toggleDebugCallback(Ref* sender); void onTouchesEnded(const std::vector& touches, Event* event); diff --git a/tests/cpp-tests/Classes/VisibleRect.cpp b/tests/cpp-tests/Classes/VisibleRect.cpp index 917de81d73..06d185695c 100644 --- a/tests/cpp-tests/Classes/VisibleRect.cpp +++ b/tests/cpp-tests/Classes/VisibleRect.cpp @@ -24,6 +24,8 @@ #include "VisibleRect.h" +USING_NS_CC; + Rect VisibleRect::s_visibleRect; void VisibleRect::lazyInit() diff --git a/tests/cpp-tests/Classes/VisibleRect.h b/tests/cpp-tests/Classes/VisibleRect.h index 67b7e1fa1b..e88b91bf23 100644 --- a/tests/cpp-tests/Classes/VisibleRect.h +++ b/tests/cpp-tests/Classes/VisibleRect.h @@ -2,25 +2,24 @@ #define __VISIBLERECT_H__ #include "cocos2d.h" -USING_NS_CC; class VisibleRect { public: - static Rect getVisibleRect(); + static cocos2d::Rect getVisibleRect(); - static Point left(); - static Point right(); - static Point top(); - static Point bottom(); - static Point center(); - static Point leftTop(); - static Point rightTop(); - static Point leftBottom(); - static Point rightBottom(); + static cocos2d::Point left(); + static cocos2d::Point right(); + static cocos2d::Point top(); + static cocos2d::Point bottom(); + static cocos2d::Point center(); + static cocos2d::Point leftTop(); + static cocos2d::Point rightTop(); + static cocos2d::Point leftBottom(); + static cocos2d::Point rightBottom(); private: static void lazyInit(); - static Rect s_visibleRect; + static cocos2d::Rect s_visibleRect; }; #endif /* __VISIBLERECT_H__ */ From c82933e3c45e64fae3291e753419b57c951323b7 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Tue, 25 Mar 2014 16:46:10 -0700 Subject: [PATCH 18/18] chipmunk fixes for Linux --- external/chipmunk/src/CMakeLists.txt | 9 +++++++++ external/chipmunk/src/cpCollision.c | 1 + 2 files changed, 10 insertions(+) diff --git a/external/chipmunk/src/CMakeLists.txt b/external/chipmunk/src/CMakeLists.txt index 2e817ea717..4005c750f4 100644 --- a/external/chipmunk/src/CMakeLists.txt +++ b/external/chipmunk/src/CMakeLists.txt @@ -1,3 +1,5 @@ +set(BUILD_STATIC 1) + file(GLOB chipmunk_source_files "*.c" "constraints/*.c") file(GLOB chipmunk_public_header "${chipmunk_SOURCE_DIR}/include/chipmunk/*.h") file(GLOB chipmunk_constraint_header "${chipmunk_SOURCE_DIR}/include/chipmunk/constraints/*.h") @@ -46,3 +48,10 @@ if(BUILD_SHARED OR INSTALL_STATIC) install(FILES ${chipmunk_public_header} DESTINATION include/chipmunk) install(FILES ${chipmunk_constraint_header} DESTINATION include/chipmunk/constraints) endif(BUILD_SHARED OR INSTALL_STATIC) + +set_target_properties(chipmunk_static + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" +) + diff --git a/external/chipmunk/src/cpCollision.c b/external/chipmunk/src/cpCollision.c index e29e4bf82e..e96738808b 100644 --- a/external/chipmunk/src/cpCollision.c +++ b/external/chipmunk/src/cpCollision.c @@ -21,6 +21,7 @@ #include #include +#include #include "chipmunk_private.h"