From 567f75c31b49bba84c5c54497c8df268562bcaaa Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Sat, 14 Sep 2013 15:52:41 +0800 Subject: [PATCH 01/39] upload CCArmatureDefine.cpp --- extensions/Android.mk | 4 --- .../Armature/utils/CCArmatureDefine.cpp | 34 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 extensions/CocoStudio/Armature/utils/CCArmatureDefine.cpp diff --git a/extensions/Android.mk b/extensions/Android.mk index b0c6196ec7..34af4f3a73 100644 --- a/extensions/Android.mk +++ b/extensions/Android.mk @@ -69,12 +69,8 @@ CocoStudio/Armature/display/CCBatchNode.cpp \ CocoStudio/Armature/display/CCDecorativeDisplay.cpp \ CocoStudio/Armature/display/CCDisplayFactory.cpp \ CocoStudio/Armature/display/CCDisplayManager.cpp \ -CocoStudio/Armature/display/CCShaderNode.cpp \ CocoStudio/Armature/display/CCSkin.cpp \ -CocoStudio/Armature/external_tool/CCTexture2DMutable.cpp \ -CocoStudio/Armature/external_tool/GLES-Render.cpp \ CocoStudio/Armature/physics/CCColliderDetector.cpp \ -CocoStudio/Armature/physics/CCPhysicsWorld.cpp \ CocoStudio/Armature/utils/CCArmatureDataManager.cpp \ CocoStudio/Armature/utils/CCDataReaderHelper.cpp \ CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp \ diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDefine.cpp b/extensions/CocoStudio/Armature/utils/CCArmatureDefine.cpp new file mode 100644 index 0000000000..cbd53fe1e0 --- /dev/null +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDefine.cpp @@ -0,0 +1,34 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#include "CCArmatureDefine.h" + +NS_CC_EXT_ARMATURE_BEGIN + +const char *armatureVersion() +{ + return "0.4.0.0"; +} + +NS_CC_EXT_ARMATURE_END From e1acbb6af4098417e4862c9c015088619ba07027 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Sun, 22 Sep 2013 13:53:25 +0800 Subject: [PATCH 02/39] fix setcolor --- extensions/CocoStudio/Armature/CCArmature.cpp | 4 +--- extensions/CocoStudio/Armature/CCBone.cpp | 11 +++++++++++ extensions/CocoStudio/Armature/CCBone.h | 15 +++++++++------ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/extensions/CocoStudio/Armature/CCArmature.cpp b/extensions/CocoStudio/Armature/CCArmature.cpp index d7817b16b1..8486000dc1 100644 --- a/extensions/CocoStudio/Armature/CCArmature.cpp +++ b/extensions/CocoStudio/Armature/CCArmature.cpp @@ -128,9 +128,7 @@ bool Armature::init(const char *name) _topBoneList = new Array(); _topBoneList->init(); - - _blendFunc.src = CC_BLEND_SRC; - _blendFunc.dst = CC_BLEND_DST; + _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; _name = name == NULL ? "" : name; diff --git a/extensions/CocoStudio/Armature/CCBone.cpp b/extensions/CocoStudio/Armature/CCBone.cpp index e6063e51c3..a5f59d7a16 100644 --- a/extensions/CocoStudio/Armature/CCBone.cpp +++ b/extensions/CocoStudio/Armature/CCBone.cpp @@ -211,6 +211,17 @@ void Bone::updateDisplayedOpacity(GLubyte parentOpacity) updateColor(); } +void Bone::setColor(const Color3B& color) +{ + CCNodeRGBA::setColor(color); + updateColor(); +} +void Bone::setOpacity(GLubyte opacity) +{ + CCNodeRGBA::setOpacity(opacity); + updateColor(); +} + void Bone::updateColor() { Node *display = _displayManager->getDisplayRenderNode(); diff --git a/extensions/CocoStudio/Armature/CCBone.h b/extensions/CocoStudio/Armature/CCBone.h index 9f979e616a..1aecfcb099 100644 --- a/extensions/CocoStudio/Armature/CCBone.h +++ b/extensions/CocoStudio/Armature/CCBone.h @@ -122,18 +122,21 @@ public: */ void removeChildBone(Bone *bone, bool recursion); - void update(float delta); + void update(float delta) override; - void updateDisplayedColor(const Color3B &parentColor); - void updateDisplayedOpacity(GLubyte parentOpacity); + virtual void updateDisplayedColor(const Color3B &parentColor) override; + virtual void updateDisplayedOpacity(GLubyte parentOpacity) override; + + virtual void setColor(const Color3B& color) override; + virtual void setOpacity(GLubyte opacity) override; //! Update color to render display - void updateColor(); + virtual void updateColor(); //! Update zorder - void updateZOrder(); + virtual void updateZOrder(); - virtual void setZOrder(int zOrder); + virtual void setZOrder(int zOrder) override; Tween *getTween(); From 90d7abb3ca77d0e927c412098d4a23116380237c Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Mon, 23 Sep 2013 16:48:09 +0800 Subject: [PATCH 03/39] fix add display --- extensions/CocoStudio/Armature/CCArmature.cpp | 26 ++-- extensions/CocoStudio/Armature/CCBone.cpp | 20 ++- .../Armature/display/CCDisplayManager.cpp | 5 +- .../CocoStudio/Armature/display/CCSkin.cpp | 13 +- .../Armature/utils/CCDataReaderHelper.cpp | 114 +++++++++--------- 5 files changed, 95 insertions(+), 83 deletions(-) diff --git a/extensions/CocoStudio/Armature/CCArmature.cpp b/extensions/CocoStudio/Armature/CCArmature.cpp index 8486000dc1..c5709b0418 100644 --- a/extensions/CocoStudio/Armature/CCArmature.cpp +++ b/extensions/CocoStudio/Armature/CCArmature.cpp @@ -261,18 +261,12 @@ void Armature::addBone(Bone *bone, const char *parentName) } else { - if (_parentBone) - _parentBone->addChildBone(bone); - else - _topBoneList->addObject(bone); + _topBoneList->addObject(bone); } } else { - if (_parentBone) - _parentBone->addChildBone(bone); - else - _topBoneList->addObject(bone); + _topBoneList->addObject(bone); } bone->setArmature(this); @@ -338,7 +332,7 @@ Dictionary *Armature::getBoneDic() return _boneDic; } -const AffineTransform& Armature::getNodeToParentTransform() const +const AffineTransform &Armature::getNodeToParentTransform() const { if (_transformDirty) { @@ -387,16 +381,16 @@ const AffineTransform& Armature::getNodeToParentTransform() const // Build Transform Matrix // Adjusted transform calculation for rotational skew _transform = AffineTransformMake( cy * _scaleX, sy * _scaleX, - -sx * _scaleY, cx * _scaleY, - x, y ); + -sx * _scaleY, cx * _scaleY, + x, y ); // XXX: Try to inline skew // If skew is needed, apply skew and then anchor point if (needsSkewMatrix) { AffineTransform skewMatrix = AffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(_skewY)), - tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1.0f, - 0.0f, 0.0f ); + tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1.0f, + 0.0f, 0.0f ); _transform = AffineTransformConcat(skewMatrix, _transform); // adjust anchor point @@ -452,7 +446,7 @@ void Armature::update(float dt) Object *object = NULL; CCARRAY_FOREACH(_topBoneList, object) { - static_cast(object)->update(dt); + static_cast(object)->update(dt); } _armatureTransformDirty = false; @@ -523,6 +517,8 @@ void Armature::draw() } } armature->draw(); + + _atlas = armature->getTextureAtlas(); } break; default: @@ -679,7 +675,7 @@ Bone *Armature::getBoneAtPoint(float x, float y) for(int i = length - 1; i >= 0; i--) { - bs = static_cast( _children->getObjectAtIndex(i) ); + bs = static_cast( _children->getObjectAtIndex(i) ); if(bs->getDisplayManager()->containPoint(x, y)) { return bs; diff --git a/extensions/CocoStudio/Armature/CCBone.cpp b/extensions/CocoStudio/Armature/CCBone.cpp index a5f59d7a16..d9ad2bfdc7 100644 --- a/extensions/CocoStudio/Armature/CCBone.cpp +++ b/extensions/CocoStudio/Armature/CCBone.cpp @@ -165,6 +165,13 @@ void Bone::update(float delta) if (_parentBone) _boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty(); + CCBone *armatureParentBone = _armature->getParentBone(); + if (armatureParentBone && !_boneTransformDirty) + { + _boneTransformDirty = armatureParentBone->isTransformDirty(); + } + + if (_boneTransformDirty) { if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) @@ -182,6 +189,13 @@ void Bone::update(float delta) { _worldTransform = AffineTransformConcat(_worldTransform, _parentBone->_worldTransform); } + else + { + if (armatureParentBone) + { + _worldTransform = CCAffineTransformConcat(_worldTransform, armatureParentBone->getNodeToArmatureTransform()); + } + } } DisplayFactory::updateDisplay(this, _displayManager->getCurrentDecorativeDisplay(), delta, _boneTransformDirty || _armature->getArmatureTransformDirty()); @@ -211,15 +225,15 @@ void Bone::updateDisplayedOpacity(GLubyte parentOpacity) updateColor(); } -void Bone::setColor(const Color3B& color) +void Bone::setColor(const Color3B &color) { CCNodeRGBA::setColor(color); - updateColor(); + updateColor(); } void Bone::setOpacity(GLubyte opacity) { CCNodeRGBA::setOpacity(opacity); - updateColor(); + updateColor(); } void Bone::updateColor() diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp index 01103f392d..ae69ea8230 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp +++ b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp @@ -135,6 +135,7 @@ void DisplayManager::addDisplay(Node *display, int index) if (SpriteDisplayData *spriteDisplayData = (SpriteDisplayData *)decoDisplay->getDisplayData()) { skin->setSkinData(spriteDisplayData->skinData); + ((CCSpriteDisplayData *)displayData)->skinData = spriteDisplayData->skinData; } else { @@ -256,8 +257,8 @@ void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay) if (RGBAProtocol *rgbaProtocaol = dynamic_cast(_displayRenderNode)) { - rgbaProtocaol->setColor(_bone->getDisplayedColor()); - rgbaProtocaol->setOpacity(_bone->getDisplayedOpacity()); + rgbaProtocaol->setColor(_bone->getDisplayedColor()); + rgbaProtocaol->setOpacity(_bone->getDisplayedOpacity()); } _displayRenderNode->retain(); diff --git a/extensions/CocoStudio/Armature/display/CCSkin.cpp b/extensions/CocoStudio/Armature/display/CCSkin.cpp index 2fdf2b24af..a35bbffcbe 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.cpp +++ b/extensions/CocoStudio/Armature/display/CCSkin.cpp @@ -84,10 +84,10 @@ bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) if (ret) { - TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); - setTextureAtlas(atlas); + TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); + setTextureAtlas(atlas); - _displayName = pszSpriteFrameName; + _displayName = pszSpriteFrameName; } return ret; @@ -99,10 +99,10 @@ bool Skin::initWithFile(const char *pszFilename) if (ret) { - TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); - setTextureAtlas(atlas); + TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); + setTextureAtlas(atlas); - _displayName = pszFilename; + _displayName = pszFilename; } return ret; @@ -118,6 +118,7 @@ void Skin::setSkinData(const BaseData &var) setPosition(Point(_skinData.x, _skinData.y)); _skinTransform = getNodeToParentTransform(); + updateArmatureTransform(); } const BaseData &Skin::getSkinData() const diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp index 76d56a4b8d..a053e4f490 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp @@ -136,7 +136,7 @@ static const char *CONFIG_FILE_PATH = "config_file_path"; NS_CC_EXT_ARMATURE_BEGIN - std::vector s_arrConfigFileList; +std::vector s_arrConfigFileList; float s_PositionReadScale = 1; static float s_FlashToolVersion = VERSION_2_0; static float s_CocoStudioVersion = VERSION_COMBINED; @@ -169,8 +169,8 @@ void DataReaderHelper::loadData() } else { - std::unique_lock lk(_sleepMutex); - _sleepCondition.wait(lk); + std::unique_lock lk(_sleepMutex); + _sleepCondition.wait(lk); continue; } } @@ -243,12 +243,12 @@ void DataReaderHelper::clear() } DataReaderHelper::DataReaderHelper() - : _loadingThread(nullptr) - , _asyncStructQueue(nullptr) - , _dataQueue(nullptr) - , need_quit(false) - , _asyncRefCount(0) - , _asyncRefTotalCount(0) + : _loadingThread(nullptr) + , _asyncStructQueue(nullptr) + , _dataQueue(nullptr) + , need_quit(false) + , _asyncRefCount(0) + , _asyncRefTotalCount(0) { } @@ -257,11 +257,11 @@ DataReaderHelper::~DataReaderHelper() { need_quit = true; - _sleepCondition.notify_one(); - if (_loadingThread) _loadingThread->join(); + _sleepCondition.notify_one(); + if (_loadingThread) _loadingThread->join(); - CC_SAFE_DELETE(_loadingThread); - _dataReaderHelper = NULL; + CC_SAFE_DELETE(_loadingThread); + _dataReaderHelper = NULL; } void DataReaderHelper::addDataFromFile(const char *filePath) @@ -354,15 +354,15 @@ void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target _asyncStructQueue = new std::queue(); _dataQueue = new std::queue(); - // create a new thread to load images - _loadingThread = new std::thread(&DataReaderHelper::loadData, this); + // create a new thread to load images + _loadingThread = new std::thread(&DataReaderHelper::loadData, this); need_quit = false; } if (0 == _asyncRefCount) { - Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this, 0, false); + Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this, 0, false); } ++_asyncRefCount; @@ -854,26 +854,26 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov } - //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) - CCFrameData **frames = (CCFrameData **)movBoneData->frameList.data->arr; - for (int i = movBoneData->frameList.count() - 1; i >= 0; i--) - { - if (i > 0) - { - float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; - float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; + //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) + CCFrameData **frames = (CCFrameData **)movBoneData->frameList.data->arr; + for (int i = movBoneData->frameList.count() - 1; i >= 0; i--) + { + if (i > 0) + { + float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; + float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; - if (difSkewX < -M_PI || difSkewX > M_PI) - { - frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; - } + if (difSkewX < -M_PI || difSkewX > M_PI) + { + frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; + } - if (difSkewY < -M_PI || difSkewY > M_PI) - { - frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; - } - } - } + if (difSkewY < -M_PI || difSkewY > M_PI) + { + frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; + } + } + } // @@ -1429,29 +1429,29 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(cs::JsonDictionary &json) } - if (s_CocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE) - { - //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) - CCFrameData **frames = (CCFrameData **)movementBoneData->frameList.data->arr; - for (int i = movementBoneData->frameList.count() - 1; i >= 0; i--) - { - if (i > 0) - { - float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; - float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; + if (s_CocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE) + { + //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) + CCFrameData **frames = (CCFrameData **)movementBoneData->frameList.data->arr; + for (int i = movementBoneData->frameList.count() - 1; i >= 0; i--) + { + if (i > 0) + { + float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; + float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; - if (difSkewX < -M_PI || difSkewX > M_PI) - { - frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; - } + if (difSkewX < -M_PI || difSkewX > M_PI) + { + frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; + } - if (difSkewY < -M_PI || difSkewY > M_PI) - { - frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; - } - } - } - } + if (difSkewY < -M_PI || difSkewY > M_PI) + { + frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; + } + } + } + } if (s_CocoStudioVersion < VERSION_COMBINED) { @@ -1478,7 +1478,7 @@ FrameData *DataReaderHelper::decodeFrame(cs::JsonDictionary &json) frameData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0); frameData->blendType = (BlendType)json.getItemIntValue(A_BLEND_TYPE, 0); - frameData->isTween = (bool)json.getItemBoolvalue(A_TWEEN_FRAME, true); + frameData->isTween = (bool)json.getItemBoolvalue(A_TWEEN_FRAME, true); const char *event = json.getItemStringValue(A_EVENT); if (event != NULL) @@ -1531,7 +1531,7 @@ TextureData *DataReaderHelper::decodeTexture(cs::JsonDictionary &json) ContourData *DataReaderHelper::decodeContour(cs::JsonDictionary &json) { ContourData *contourData = new ContourData(); - contourData->init(); + contourData->init(); int length = json.getArrayItemCount(VERTEX_POINT); for (int i = length - 1; i >= 0; i--) From 6f5e7d540e7039e1ddc818ea997259ac4e2c0b65 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Tue, 24 Sep 2013 23:22:07 +0800 Subject: [PATCH 04/39] remove cc --- extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp index a053e4f490..45b63c4db5 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp @@ -855,7 +855,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) - CCFrameData **frames = (CCFrameData **)movBoneData->frameList.data->arr; + FrameData **frames = (FrameData **)movBoneData->frameList.data->arr; for (int i = movBoneData->frameList.count() - 1; i >= 0; i--) { if (i > 0) From 2d3df6998257661005294c1303602f4c8e318448 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Tue, 29 Oct 2013 16:57:06 +0800 Subject: [PATCH 05/39] fix add display --- cocos/editor-support/cocostudio/CCArmature.cpp | 11 +++-------- cocos/editor-support/cocostudio/CCBone.cpp | 13 +++++++++++++ .../editor-support/cocostudio/CCDisplayManager.cpp | 1 + cocos/editor-support/cocostudio/CCSkin.cpp | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index 5c3b54e3df..ca935722c8 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -265,18 +265,12 @@ void Armature::addBone(Bone *bone, const char *parentName) } else { - if (_parentBone) - _parentBone->addChildBone(bone); - else - _topBoneList->addObject(bone); + _topBoneList->addObject(bone); } } else { - if (_parentBone) - _parentBone->addChildBone(bone); - else - _topBoneList->addObject(bone); + _topBoneList->addObject(bone); } bone->setArmature(this); @@ -527,6 +521,7 @@ void Armature::draw() } } armature->draw(); + _atlas = armature->getTextureAtlas(); } break; default: diff --git a/cocos/editor-support/cocostudio/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index abd0cb85a5..574a66e1b0 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -167,6 +167,12 @@ void Bone::update(float delta) if (_parentBone) _boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty(); + CCBone *armatureParentBone = _armature->getParentBone(); + if (armatureParentBone && !_boneTransformDirty) + { + _boneTransformDirty = armatureParentBone->isTransformDirty(); + } + if (_boneTransformDirty) { if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) @@ -184,6 +190,13 @@ void Bone::update(float delta) { _worldTransform = AffineTransformConcat(_worldTransform, _parentBone->_worldTransform); } + else + { + if (armatureParentBone) + { + _worldTransform = CCAffineTransformConcat(_worldTransform, armatureParentBone->getNodeToArmatureTransform()); + } + } } DisplayFactory::updateDisplay(this, _displayManager->getCurrentDecorativeDisplay(), delta, _boneTransformDirty || _armature->getArmatureTransformDirty()); diff --git a/cocos/editor-support/cocostudio/CCDisplayManager.cpp b/cocos/editor-support/cocostudio/CCDisplayManager.cpp index b7d337e3a9..ae1ed19781 100644 --- a/cocos/editor-support/cocostudio/CCDisplayManager.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayManager.cpp @@ -137,6 +137,7 @@ void DisplayManager::addDisplay(Node *display, int index) if (SpriteDisplayData *spriteDisplayData = (SpriteDisplayData *)decoDisplay->getDisplayData()) { skin->setSkinData(spriteDisplayData->skinData); + ((CCSpriteDisplayData *)displayData)->skinData = spriteDisplayData->skinData; } else { diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index afd6f5fc51..d1c66ddc3e 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -120,6 +120,7 @@ void Skin::setSkinData(const BaseData &var) setPosition(Point(_skinData.x, _skinData.y)); _skinTransform = getNodeToParentTransform(); + updateArmatureTransform(); } const BaseData &Skin::getSkinData() const From 8fa8b9f844ac723f1d9a38699f1d62206c1f8ced Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Wed, 30 Oct 2013 09:41:40 +0800 Subject: [PATCH 06/39] update develop --- .../editor-support/cocostudio/CCArmature.cpp | 52 +++- cocos/editor-support/cocostudio/CCArmature.h | 6 +- .../cocostudio/CCArmatureAnimation.cpp | 57 +++- .../cocostudio/CCArmatureAnimation.h | 37 ++- .../cocostudio/CCArmatureDataManager.cpp | 4 +- .../cocostudio/CCArmatureDefine.cpp | 2 +- .../editor-support/cocostudio/CCBatchNode.cpp | 83 ++++++ cocos/editor-support/cocostudio/CCBatchNode.h | 8 +- cocos/editor-support/cocostudio/CCBone.cpp | 95 ++++-- cocos/editor-support/cocostudio/CCBone.h | 21 +- .../cocostudio/CCColliderDetector.cpp | 10 +- .../cocostudio/CCDataReaderHelper.cpp | 107 +++++-- .../cocostudio/CCDataReaderHelper.h | 24 +- .../cocostudio/CCDisplayFactory.cpp | 51 ++-- .../cocostudio/CCDisplayFactory.h | 7 +- .../cocostudio/CCDisplayManager.cpp | 20 +- .../cocostudio/CCDisplayManager.h | 3 + .../cocostudio/CCProcessBase.cpp | 12 +- .../editor-support/cocostudio/CCProcessBase.h | 3 +- cocos/editor-support/cocostudio/CCSkin.cpp | 61 ++-- cocos/editor-support/cocostudio/CCSkin.h | 3 +- .../cocostudio/CCSpriteFrameCacheHelper.cpp | 14 - .../cocostudio/CCSpriteFrameCacheHelper.h | 4 - .../cocostudio/CCTransformHelp.cpp | 21 +- cocos/editor-support/cocostudio/CCTween.cpp | 63 ++-- cocos/editor-support/cocostudio/CCTween.h | 13 +- .../CocoStudioArmatureTest/ArmatureScene.cpp | 276 +++++++++++++++++- .../CocoStudioArmatureTest/ArmatureScene.h | 54 +++- 28 files changed, 907 insertions(+), 204 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index ca935722c8..ac04de1af5 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -86,6 +86,7 @@ Armature::Armature() , _boneDic(NULL) , _topBoneList(NULL) , _animation(NULL) + , _textureAtlasDic(NULL) { } @@ -103,6 +104,7 @@ Armature::~Armature(void) CC_SAFE_DELETE(_topBoneList); } CC_SAFE_DELETE(_animation); + CC_SAFE_RELEASE_NULL(_textureAtlasDic); } @@ -130,6 +132,8 @@ bool Armature::init(const char *name) _topBoneList = new Array(); _topBoneList->init(); + CC_SAFE_DELETE(_textureAtlasDic); + _textureAtlasDic = new Dictionary(); _blendFunc.src = CC_BLEND_SRC; _blendFunc.dst = CC_BLEND_DST; @@ -458,7 +462,7 @@ void Armature::update(float dt) void Armature::draw() { - if (_parentBone == NULL) + if (_parentBone == NULL && _batchNode == NULL) { CC_NODE_DRAW_SETUP(); GL::blendFunc(_blendFunc.src, _blendFunc.dst); @@ -469,13 +473,12 @@ void Armature::draw() { if (Bone *bone = dynamic_cast(object)) { - DisplayManager *displayManager = bone->getDisplayManager(); - Node *node = displayManager->getDisplayRenderNode(); + Node *node = bone->getDisplayRenderNode(); if (NULL == node) continue; - switch (displayManager->getCurrentDecorativeDisplay()->getDisplayData()->displayType) + switch (bone->getDisplayRenderNodeType()) { case CS_DISPLAY_SPRITE: { @@ -667,7 +670,7 @@ Rect Armature::getBoundingBox() const } } - return boundingBox; + return RectApplyAffineTransform(boundingBox, getNodeToParentTransform()); } Bone *Armature::getBoneAtPoint(float x, float y) @@ -686,6 +689,45 @@ Bone *Armature::getBoneAtPoint(float x, float y) return NULL; } +TextureAtlas *Armature::getTexureAtlasWithTexture(Texture2D *texture) +{ + int key = texture->getName(); + + if (_parentBone && _parentBone->getArmature()) + { + return _parentBone->getArmature()->getTexureAtlasWithTexture(texture); + } + else if (_batchNode) + { + _batchNode->getTexureAtlasWithTexture(texture); + } + + TextureAtlas *atlas = static_cast(_textureAtlasDic->objectForKey(key)); + if (atlas == NULL) + { + atlas = TextureAtlas::createWithTexture(texture, 4); + _textureAtlasDic->setObject(atlas, key); + } + return atlas; +} + +void Armature::setParentBone(Bone *parentBone) +{ + _parentBone = parentBone; + + DictElement *element = NULL; + CCDICT_FOREACH(_boneDic, element) + { + Bone *bone = static_cast(element->getObject()); + bone->setArmature(this); + } +} + +Bone *Armature::getParentBone() +{ + return _parentBone; +} + #if ENABLE_PHYSICS_BOX2D_DETECT b2Body *Armature::getBody() { diff --git a/cocos/editor-support/cocostudio/CCArmature.h b/cocos/editor-support/cocostudio/CCArmature.h index 3e8c521011..15abe96079 100644 --- a/cocos/editor-support/cocostudio/CCArmature.h +++ b/cocos/editor-support/cocostudio/CCArmature.h @@ -173,6 +173,8 @@ public: virtual bool getArmatureTransformDirty(); + virtual cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture); + #if ENABLE_PHYSICS_BOX2D_DETECT virtual b2Fixture *getShapeList(); #elif ENABLE_PHYSICS_CHIPMUNK_DETECT @@ -197,7 +199,7 @@ protected: CC_SYNTHESIZE(cocos2d::TextureAtlas *, _atlas, TextureAtlas); - CC_SYNTHESIZE(Bone *, _parentBone, ParentBone); + CC_PROPERTY(Bone *, _parentBone, ParentBone); CC_SYNTHESIZE(float, _version, Version); @@ -214,6 +216,8 @@ protected: ArmatureAnimation *_animation; + cocos2d::Dictionary *_textureAtlasDic; + #if ENABLE_PHYSICS_BOX2D_DETECT CC_PROPERTY(b2Body *, _body, Body); #elif ENABLE_PHYSICS_CHIPMUNK_DETECT diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp index a026fc33c9..ed6e383751 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp @@ -54,6 +54,8 @@ ArmatureAnimation::ArmatureAnimation() , _armature(NULL) , _movementID("") , _toIndex(0) + , _tweenList(NULL) + , _ignoreFrameEvent(false) , _movementEventCallFunc(NULL) , _frameEventCallFunc(NULL) @@ -268,6 +270,8 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura } } + + _armature->update(0); } @@ -280,7 +284,40 @@ void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int dura play(animationName.c_str(), durationTo, durationTween, loop, tweenEasing); } +void ArmatureAnimation::gotoAndPlay(int frameIndex) +{ + if (!_movementData || frameIndex < 0 || frameIndex >= _movementData->duration) + { + CCLOG("Please ensure you have played a movement, and the frameIndex is in the range."); + return; + } + bool ignoreFrameEvent = _ignoreFrameEvent; + _ignoreFrameEvent = true; + + _isPlaying = true; + _isComplete = _isPause = false; + + ProcessBase::gotoFrame(frameIndex); + _currentPercent = (float)_curFrameIndex / (float)_movementData->duration; + _currentFrame = _nextFrameIndex * _currentPercent; + + Object *object = NULL; + CCARRAY_FOREACH(_tweenList, object) + { + static_cast(object)->gotoAndPlay(frameIndex); + } + + _armature->update(0); + + _ignoreFrameEvent = ignoreFrameEvent; +} + +void ArmatureAnimation::gotoAndPause(int frameIndex) +{ + gotoAndPlay(frameIndex); + pause(); +} int ArmatureAnimation::getMovementCount() { @@ -295,6 +332,18 @@ void ArmatureAnimation::update(float dt) { static_cast(object)->update(dt); } + + while (_frameEventQueue.size() > 0) + { + FrameEvent *frameEvent = _frameEventQueue.front(); + _frameEventQueue.pop(); + + _ignoreFrameEvent = true; + (_frameEventTarget->*_frameEventCallFunc)(frameEvent->bone, frameEvent->frameEventName, frameEvent->originFrameIndex, frameEvent->currentFrameIndex); + _ignoreFrameEvent = false; + + CC_SAFE_DELETE(frameEvent); + } } void ArmatureAnimation::updateHandler() @@ -402,7 +451,13 @@ void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int o { if (_frameEventTarget && _frameEventCallFunc) { - (_frameEventTarget->*_frameEventCallFunc)(bone, frameEventName, originFrameIndex, currentFrameIndex); + FrameEvent *frameEvent = new FrameEvent(); + frameEvent->bone = bone; + frameEvent->frameEventName = frameEventName; + frameEvent->originFrameIndex = originFrameIndex; + frameEvent->currentFrameIndex = currentFrameIndex; + + _frameEventQueue.push(frameEvent); } } } diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.h b/cocos/editor-support/cocostudio/CCArmatureAnimation.h index 9551f97ff9..5fe23543bf 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.h +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.h @@ -27,6 +27,7 @@ THE SOFTWARE. #define __CCANIMATION_H__ #include "cocostudio/CCProcessBase.h" +#include namespace cocostudio { @@ -48,6 +49,13 @@ typedef void (cocos2d::Object::*SEL_FrameEventCallFunc)(Bone *, const char *, in #define movementEvent_selector(_SELECTOR) (cocostudio::SEL_MovementEventCallFunc)(&_SELECTOR) #define frameEvent_selector(_SELECTOR) (cocostudio::SEL_FrameEventCallFunc)(&_SELECTOR) +struct FrameEvent +{ + Bone *bone; + const char *frameEventName; + int originFrameIndex; + int currentFrameIndex; +}; class ArmatureAnimation : public ProcessBase { @@ -76,10 +84,11 @@ public: /** * Scale animation play speed. + * This method is deprecated, please use setSpeedScale. * @param animationScale Scale value */ - virtual void setAnimationScale(float animationScale); - virtual float getAnimationScale() const; + CC_DEPRECATED_ATTRIBUTE virtual void setAnimationScale(float animationScale); + CC_DEPRECATED_ATTRIBUTE virtual float getAnimationScale() const; /** * Scale animation play speed. @@ -123,10 +132,27 @@ public: /** * Play animation by index, the other param is the same to play. - * @param _animationIndex the animation index you want to play + * @param animationIndex the animation index you want to play */ void playByIndex(int animationIndex, int durationTo = -1, int durationTween = -1, int loop = -1, int tweenEasing = TWEEN_EASING_MAX); + /** + * Go to specified frame and play current movement. + * You need first switch to the movement you want to play, then call this function. + * + * example : playByIndex(0); + * gotoAndPlay(0); + * playByIndex(1); + * gotoAndPlay(0); + * gotoAndPlay(15); + */ + virtual void gotoAndPlay(int frameIndex); + + /** + * Go to specified frame and pause current movement. + */ + virtual void gotoAndPause(int frameIndex); + /** * Pause the Process */ @@ -183,6 +209,8 @@ protected: */ void frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex); + inline bool isIgnoreFrameEvent() { return _ignoreFrameEvent; } + friend class Tween; protected: //! AnimationData save all MovementDatas this animation used. @@ -201,6 +229,9 @@ protected: cocos2d::Array *_tweenList; + bool _ignoreFrameEvent; + + std::queue _frameEventQueue; protected: /** * MovementEvent CallFunc. diff --git a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp index 113ff33202..13ca184768 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp @@ -186,7 +186,7 @@ void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath) void ArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector) { _autoLoadSpriteFile = true; - DataReaderHelper::getInstance()->addDataFromFileAsync(configFilePath, target, selector); + DataReaderHelper::getInstance()->addDataFromFileAsync("", "", configFilePath, target, selector); } void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) @@ -199,7 +199,7 @@ void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char void ArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector) { _autoLoadSpriteFile = false; - DataReaderHelper::getInstance()->addDataFromFileAsync(configFilePath, target, selector); + DataReaderHelper::getInstance()->addDataFromFileAsync(imagePath, plistPath, configFilePath, target, selector); addSpriteFrameFromFile(plistPath, imagePath); } diff --git a/cocos/editor-support/cocostudio/CCArmatureDefine.cpp b/cocos/editor-support/cocostudio/CCArmatureDefine.cpp index 3672943778..4f48e0024e 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDefine.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureDefine.cpp @@ -28,7 +28,7 @@ namespace cocostudio { const char *armatureVersion() { - return "0.4.0.0"; + return "1.0.0.0"; } } diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index 7ef2188fb8..bb84576d66 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. #include "cocostudio/CCBatchNode.h" #include "cocostudio/CCArmatureDefine.h" #include "cocostudio/CCArmature.h" +#include "cocostudio/CCSkin.h" using namespace cocos2d; @@ -44,16 +45,36 @@ BatchNode *BatchNode::create() BatchNode::BatchNode() : _atlas(NULL) + , _textureAtlasDic(NULL) { } +BatchNode::~BatchNode() +{ + CC_SAFE_RELEASE_NULL(_textureAtlasDic); +} + bool BatchNode::init() { bool ret = Node::init(); setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + + CC_SAFE_DELETE(_textureAtlasDic); + _textureAtlasDic = new Dictionary(); + return ret; } +void BatchNode::addChild(Node *pChild) +{ + Node::addChild(pChild); +} + +void BatchNode::addChild(Node *child, int zOrder) +{ + Node::addChild(child, zOrder); +} + void BatchNode::addChild(Node *child, int zOrder, int tag) { Node::addChild(child, zOrder, tag); @@ -61,9 +82,58 @@ void BatchNode::addChild(Node *child, int zOrder, int tag) if (armature != NULL) { armature->setBatchNode(this); + + Dictionary *dict = armature->getBoneDic(); + DictElement *element = NULL; + CCDICT_FOREACH(dict, element) + { + Bone *bone = static_cast(element->getObject()); + + Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); + Object *object = NULL; + CCARRAY_FOREACH(displayList, object) + { + DecorativeDisplay *display = static_cast(object); + + if (Skin *skin = dynamic_cast(display->getDisplay())) + { + skin->setTextureAtlas(getTexureAtlasWithTexture(skin->getTexture())); + } + } + } } } +void BatchNode::removeChild(Node* child, bool cleanup) +{ + Armature *armature = dynamic_cast(child); + if (armature != NULL) + { + armature->setBatchNode(NULL); + + Dictionary *dict = armature->getBoneDic(); + DictElement *element = NULL; + CCDICT_FOREACH(dict, element) + { + Bone *bone = static_cast(element->getObject()); + + Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); + Object *object = NULL; + CCARRAY_FOREACH(displayList, object) + { + DecorativeDisplay *display = static_cast(object); + + if (Skin *skin = dynamic_cast(display->getDisplay())) + { + skin->setTextureAtlas(armature->getTexureAtlasWithTexture(skin->getTexture())); + } + } + } + } + + Node::removeChild(child, cleanup); +} + void BatchNode::visit() { // quick return if not visible. children won't be drawn. @@ -118,4 +188,17 @@ void BatchNode::draw() } } +TextureAtlas *BatchNode::getTexureAtlasWithTexture(Texture2D *texture) +{ + int key = texture->getName(); + + TextureAtlas *atlas = static_cast(_textureAtlasDic->objectForKey(key)); + if (atlas == NULL) + { + atlas = CCTextureAtlas::createWithTexture(texture, 4); + _textureAtlasDic->setObject(atlas, key); + } + return atlas; +} + } diff --git a/cocos/editor-support/cocostudio/CCBatchNode.h b/cocos/editor-support/cocostudio/CCBatchNode.h index df33e44e0b..44f10872c2 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.h +++ b/cocos/editor-support/cocostudio/CCBatchNode.h @@ -38,14 +38,20 @@ public: * @js ctor */ BatchNode(); + ~BatchNode(); virtual bool init(); - virtual void addChild(cocos2d::Node *child, int zOrder, int tag); + virtual void addChild(cocos2d::Node *pChild); + virtual void addChild(cocos2d::Node *pChild, int zOrder); + virtual void addChild(cocos2d::Node *pChild, int zOrder, int tag); + virtual void removeChild(cocos2d::Node* child, bool cleanup); virtual void visit(); void draw(); + virtual cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture); protected: cocos2d::TextureAtlas *_atlas; + cocos2d::Dictionary *_textureAtlasDic; }; } diff --git a/cocos/editor-support/cocostudio/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index 574a66e1b0..804ea5d65a 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -75,6 +75,10 @@ Bone::Bone() _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0); _boneTransformDirty = true; _blendType = BLEND_NORMAL; + _worldInfo = NULL; + + _armatureParentBone = NULL; + _dataVersion = 0; } @@ -84,6 +88,7 @@ Bone::~Bone(void) CC_SAFE_DELETE(_children); CC_SAFE_DELETE(_tween); CC_SAFE_DELETE(_displayManager); + CC_SAFE_DELETE(_worldInfo); if(_boneData) { @@ -121,6 +126,8 @@ bool Bone::init(const char *name) _displayManager = new DisplayManager(); _displayManager->init(this); + CC_SAFE_DELETE(_worldInfo); + _worldInfo = new BaseData(); bRet = true; } @@ -153,6 +160,12 @@ void Bone::setArmature(Armature *armature) if (_armature) { _tween->setAnimation(_armature->getAnimation()); + _dataVersion = _armature->getArmatureData()->dataVersion; + _armatureParentBone = _armature->getParentBone(); + } + else + { + _armatureParentBone = NULL; } } @@ -167,39 +180,50 @@ void Bone::update(float delta) if (_parentBone) _boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty(); - CCBone *armatureParentBone = _armature->getParentBone(); - if (armatureParentBone && !_boneTransformDirty) + if (_armatureParentBone && !_boneTransformDirty) { - _boneTransformDirty = armatureParentBone->isTransformDirty(); + _boneTransformDirty = _armatureParentBone->isTransformDirty(); } if (_boneTransformDirty) { - if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) + if (_dataVersion >= VERSION_COMBINED) { TransformHelp::nodeConcat(*_tweenData, *_boneData); _tweenData->scaleX -= 1; _tweenData->scaleY -= 1; } - TransformHelp::nodeToMatrix(*_tweenData, _worldTransform); + _worldInfo->copy(_tweenData); - _worldTransform = AffineTransformConcat(getNodeToParentTransform(), _worldTransform); + _worldInfo->x = _tweenData->x + _position.x; + _worldInfo->y = _tweenData->y + _position.y; + _worldInfo->scaleX = _tweenData->scaleX * _scaleX; + _worldInfo->scaleY = _tweenData->scaleY * _scaleY; + _worldInfo->skewX = _tweenData->skewX + _skewX + _rotationX; + _worldInfo->skewY = _tweenData->skewY + _skewY - _rotationY; if(_parentBone) { - _worldTransform = AffineTransformConcat(_worldTransform, _parentBone->_worldTransform); + applyParentTransform(_parentBone); } else { - if (armatureParentBone) + if (_armatureParentBone) { - _worldTransform = CCAffineTransformConcat(_worldTransform, armatureParentBone->getNodeToArmatureTransform()); + applyParentTransform(_armatureParentBone); } } + + TransformHelp::nodeToMatrix(*_worldInfo, _worldTransform); + + if (_armatureParentBone) + { + _worldTransform = AffineTransformConcat(_worldTransform, _armature->getNodeToParentTransform()); + } } - DisplayFactory::updateDisplay(this, _displayManager->getCurrentDecorativeDisplay(), delta, _boneTransformDirty || _armature->getArmatureTransformDirty()); + DisplayFactory::updateDisplay(this, delta, _boneTransformDirty || _armature->getArmatureTransformDirty()); Object *object = NULL; CCARRAY_FOREACH(_children, object) @@ -211,6 +235,18 @@ void Bone::update(float delta) _boneTransformDirty = false; } +void Bone::applyParentTransform(Bone *parent) +{ + float x = _worldInfo->x; + float y = _worldInfo->y; + _worldInfo->x = x * parent->_worldTransform.a + y * parent->_worldTransform.c + parent->_worldInfo->x; + _worldInfo->y = x * parent->_worldTransform.b + y * parent->_worldTransform.d + parent->_worldInfo->y; + _worldInfo->scaleX = _worldInfo->scaleX * parent->_worldInfo->scaleX; + _worldInfo->scaleY = _worldInfo->scaleY * parent->_worldInfo->scaleY; + _worldInfo->skewX = _worldInfo->skewX + parent->_worldInfo->skewX; + _worldInfo->skewY = _worldInfo->skewY + parent->_worldInfo->skewY; +} + void Bone::updateDisplayedColor(const Color3B &parentColor) { @@ -226,6 +262,18 @@ void Bone::updateDisplayedOpacity(GLubyte parentOpacity) updateColor(); } +void Bone::setColor(const Color3B& color) +{ + NodeRGBA::setColor(color); + updateColor(); +} + +void Bone::setOpacity(GLubyte opacity) +{ + NodeRGBA::setOpacity(opacity); + updateColor(); +} + void Bone::updateColor() { Node *display = _displayManager->getDisplayRenderNode(); @@ -239,7 +287,7 @@ void Bone::updateColor() void Bone::updateZOrder() { - if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) + if (_dataVersion >= VERSION_COMBINED) { int zorder = _tweenData->zOrder + _boneData->zOrder; setZOrder(zorder); @@ -313,6 +361,11 @@ void Bone::setChildArmature(Armature *armature) { if (_childArmature != armature) { + if (armature == NULL && _childArmature) + { + _childArmature->setParentBone(NULL); + } + CC_SAFE_RETAIN(armature); CC_SAFE_RELEASE(_childArmature); _childArmature = armature; @@ -335,16 +388,6 @@ void Bone::setZOrder(int zOrder) Node::setZOrder(zOrder); } -void Bone::setTransformDirty(bool dirty) -{ - _boneTransformDirty = dirty; -} - -bool Bone::isTransformDirty() -{ - return _boneTransformDirty; -} - AffineTransform Bone::getNodeToArmatureTransform() const { return _worldTransform; @@ -360,6 +403,11 @@ Node *Bone::getDisplayRenderNode() return _displayManager->getDisplayRenderNode(); } +DisplayType Bone::getDisplayRenderNodeType() +{ + return _displayManager->getDisplayRenderNodeType(); +} + void Bone::addDisplay(DisplayData *displayData, int index) { _displayManager->addDisplay(displayData, index); @@ -370,6 +418,11 @@ void Bone::addDisplay(Node *display, int index) _displayManager->addDisplay(display, index); } +void Bone::removeDisplay(int index) +{ + _displayManager->removeDisplay(index); +} + void Bone::changeDisplayByIndex(int index, bool force) { _displayManager->changeDisplayByIndex(index, force); diff --git a/cocos/editor-support/cocostudio/CCBone.h b/cocos/editor-support/cocostudio/CCBone.h index 1163738515..1a1d3c26d6 100644 --- a/cocos/editor-support/cocostudio/CCBone.h +++ b/cocos/editor-support/cocostudio/CCBone.h @@ -86,6 +86,8 @@ public: void addDisplay(cocos2d::Node *display, int index); + void removeDisplay(int index); + void changeDisplayByIndex(int index, bool force); /** @@ -127,6 +129,9 @@ public: void updateDisplayedColor(const cocos2d::Color3B &parentColor); void updateDisplayedOpacity(GLubyte parentOpacity); + virtual void setColor(const cocos2d::Color3B& color) override; + virtual void setOpacity(GLubyte opacity) override; + //! Update color to render display void updateColor(); @@ -140,14 +145,14 @@ public: /* * Whether or not the bone's transform property changed. if true, the bone will update the transform. */ - virtual void setTransformDirty(bool dirty); - - virtual bool isTransformDirty(); + virtual inline void setTransformDirty(bool dirty) { _boneTransformDirty = dirty; } + virtual inline bool isTransformDirty() { return _boneTransformDirty; } virtual cocos2d::AffineTransform getNodeToArmatureTransform() const; virtual cocos2d::AffineTransform getNodeToWorldTransform() const override; Node *getDisplayRenderNode(); + DisplayType getDisplayRenderNodeType(); /* * Get the ColliderBody list in this bone. The object in the Array is ColliderBody. @@ -177,6 +182,8 @@ public: CC_SYNTHESIZE(BlendType, _blendType, BlendType) protected: + void applyParentTransform(Bone *parent); + Tween *_tween; //! Calculate tween effect //! Used for making tween effect in every frame @@ -189,6 +196,14 @@ protected: //! self Transform, use this to change display's state cocos2d::AffineTransform _worldTransform; + + CC_SYNTHESIZE_READONLY(BaseData*, _worldInfo, WorldInfo); + + //! Armature's parent bone + Bone *_armatureParentBone; + + //! Data version + float _dataVersion; }; } diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.cpp b/cocos/editor-support/cocostudio/CCColliderDetector.cpp index 0839a30d7a..341bf503e6 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.cpp +++ b/cocos/editor-support/cocostudio/CCColliderDetector.cpp @@ -197,7 +197,10 @@ void ColliderDetector::setActive(bool active) { ColliderBody *colliderBody = (ColliderBody *)object; cpShape *shape = colliderBody->getShape(); - cpSpaceAddShape(_body->space_private, shape); + if(shape->space_private == NULL) + { + cpSpaceAddShape(_body->space_private, shape); + } } } else @@ -206,7 +209,10 @@ void ColliderDetector::setActive(bool active) { ColliderBody *colliderBody = (ColliderBody *)object; cpShape *shape = colliderBody->getShape(); - cpSpaceRemoveShape(_body->space_private, shape); + if (shape->space_private != NULL) + { + cpSpaceRemoveShape(_body->space_private, shape); + } } } } diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 4749f5eaf9..83151322c5 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -133,13 +133,14 @@ static const char *VERTEX_POINT = "vertex"; static const char *COLOR_INFO = "color"; static const char *CONFIG_FILE_PATH = "config_file_path"; - +static const char *CONTENT_SCALE = "content_scale"; namespace cocostudio { - std::vector s_arrConfigFileList; +std::vector s_arrConfigFileList; float s_PositionReadScale = 1; +float s_ContentScale = 1; static float s_FlashToolVersion = VERSION_2_0; static float s_CocoStudioVersion = VERSION_COMBINED; @@ -312,7 +313,7 @@ void DataReaderHelper::addDataFromFile(const char *filePath) } } -void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target, SEL_SCHEDULE selector) +void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *plistPath, const char *filePath, Object *target, SEL_SCHEDULE selector) { /* * Check if file is already added to ArmatureDataManager, if then return. @@ -338,15 +339,16 @@ void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target s_arrConfigFileList.push_back(filePath); //! find the base file path - s_BasefilePath = filePath; - size_t pos = s_BasefilePath.find_last_of("/"); + std::string basefilePath = filePath; + size_t pos = basefilePath.find_last_of("/"); + if (pos != std::string::npos) { - s_BasefilePath = s_BasefilePath.substr(0, pos + 1); + basefilePath = s_BasefilePath.substr(0, pos + 1); } else { - s_BasefilePath = ""; + basefilePath = ""; } @@ -378,11 +380,13 @@ void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target // generate async struct AsyncStruct *data = new AsyncStruct(); data->filename = filePath; - data->baseFilePath = s_BasefilePath; + data->baseFilePath = basefilePath; data->target = target; data->selector = selector; data->autoLoadSpriteFile = ArmatureDataManager::getInstance()->isAutoLoadSpriteFile(); + data->imagePath = imagePath; + data->plistPath = plistPath; std::string filePathStr = filePath; size_t startPos = filePathStr.find_last_of("."); @@ -428,10 +432,20 @@ void DataReaderHelper::addDataAsyncCallBack(float dt) AsyncStruct *pAsyncStruct = pDataInfo->asyncStruct; + + if (pAsyncStruct->imagePath != "" && pAsyncStruct->plistPath != "") + { + _getFileMutex.lock(); + ArmatureDataManager::getInstance()->addSpriteFrameFromFile(pAsyncStruct->plistPath.c_str(), pAsyncStruct->imagePath.c_str()); + _getFileMutex.unlock(); + } + while (!pDataInfo->configFileQueue.empty()) { std::string configPath = pDataInfo->configFileQueue.front(); + _getFileMutex.lock(); ArmatureDataManager::getInstance()->addSpriteFrameFromFile((pAsyncStruct->baseFilePath + configPath + ".plist").c_str(), (pAsyncStruct->baseFilePath + configPath + ".png").c_str()); + _getFileMutex.unlock(); pDataInfo->configFileQueue.pop(); } @@ -1123,12 +1137,21 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d JsonDictionary json; json.initWithDescription(fileContent); + if (dataInfo) + { + dataInfo->contentScale = json.getItemFloatValue(CONTENT_SCALE, 1); + } + else + { + s_ContentScale = json.getItemFloatValue(CONTENT_SCALE, 1); + } + // Decode armatures int length = json.getArrayItemCount(ARMATURE_DATA); for (int i = 0; i < length; i++) { JsonDictionary *armatureDic = json.getSubItemFromArray(ARMATURE_DATA, i); - ArmatureData *armatureData = decodeArmature(*armatureDic); + ArmatureData *armatureData = decodeArmature(*armatureDic, dataInfo); if (dataInfo) { @@ -1148,7 +1171,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d for (int i = 0; i < length; i++) { JsonDictionary *animationDic = json.getSubItemFromArray(ANIMATION_DATA, i); - AnimationData *animationData = decodeAnimation(*animationDic); + AnimationData *animationData = decodeAnimation(*animationDic, dataInfo); if (dataInfo) { @@ -1215,7 +1238,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d } } -ArmatureData *DataReaderHelper::decodeArmature(JsonDictionary &json) +ArmatureData *DataReaderHelper::decodeArmature(JsonDictionary &json, DataInfo *dataInfo) { ArmatureData *armatureData = new ArmatureData(); armatureData->init(); @@ -1232,7 +1255,7 @@ ArmatureData *DataReaderHelper::decodeArmature(JsonDictionary &json) for (int i = 0; i < length; i++) { JsonDictionary *dic = json.getSubItemFromArray(BONE_DATA, i); - BoneData *boneData = decodeBone(*dic); + BoneData *boneData = decodeBone(*dic, dataInfo); armatureData->addBoneData(boneData); boneData->release(); @@ -1242,12 +1265,12 @@ ArmatureData *DataReaderHelper::decodeArmature(JsonDictionary &json) return armatureData; } -BoneData *DataReaderHelper::decodeBone(JsonDictionary &json) +BoneData *DataReaderHelper::decodeBone(JsonDictionary &json, DataInfo *dataInfo) { BoneData *boneData = new BoneData(); boneData->init(); - decodeNode(boneData, json); + decodeNode(boneData, json, dataInfo); const char *str = json.getItemStringValue(A_NAME); if(str != NULL) @@ -1266,7 +1289,7 @@ BoneData *DataReaderHelper::decodeBone(JsonDictionary &json) for (int i = 0; i < length; i++) { JsonDictionary *dic = json.getSubItemFromArray(DISPLAY_DATA, i); - DisplayData *displayData = decodeBoneDisplay(*dic); + DisplayData *displayData = decodeBoneDisplay(*dic, dataInfo); boneData->addDisplayData(displayData); displayData->release(); @@ -1276,7 +1299,7 @@ BoneData *DataReaderHelper::decodeBone(JsonDictionary &json) return boneData; } -DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json) +DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo *dataInfo) { DisplayType displayType = (DisplayType)json.getItemIntValue(A_DISPLAY_TYPE, CS_DISPLAY_SPRITE); @@ -1304,6 +1327,18 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json) sdd->skinData.scaleY = dic->getItemFloatValue(A_SCALE_Y, 1); sdd->skinData.skewX = dic->getItemFloatValue(A_SKEW_X, 0); sdd->skinData.skewY = dic->getItemFloatValue(A_SKEW_Y, 0); + + if (dataInfo) + { + sdd->skinData.x *= dataInfo->contentScale; + sdd->skinData.y *= dataInfo->contentScale; + } + else + { + sdd->skinData.x *= s_ContentScale; + sdd->skinData.y *= s_ContentScale; + } + delete dic; } } @@ -1327,7 +1362,14 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json) const char *plist = json.getItemStringValue(A_PLIST); if(plist != NULL) { - ((ParticleDisplayData *)displayData)->plist = s_BasefilePath + plist; + if (dataInfo != NULL) + { + static_cast(displayData)->plist = dataInfo->asyncStruct->baseFilePath + plist; + } + else + { + static_cast(displayData)->plist = s_BasefilePath + plist; + } } } break; @@ -1343,7 +1385,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json) return displayData; } -AnimationData *DataReaderHelper::decodeAnimation(JsonDictionary &json) +AnimationData *DataReaderHelper::decodeAnimation(JsonDictionary &json, DataInfo *dataInfo) { AnimationData *aniData = new AnimationData(); @@ -1358,7 +1400,7 @@ AnimationData *DataReaderHelper::decodeAnimation(JsonDictionary &json) for (int i = 0; i < length; i++) { JsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_DATA, i); - MovementData *movementData = decodeMovement(*dic); + MovementData *movementData = decodeMovement(*dic, dataInfo); aniData->addMovement(movementData); movementData->release(); @@ -1368,7 +1410,7 @@ AnimationData *DataReaderHelper::decodeAnimation(JsonDictionary &json) return aniData; } -MovementData *DataReaderHelper::decodeMovement(JsonDictionary &json) +MovementData *DataReaderHelper::decodeMovement(JsonDictionary &json, DataInfo *dataInfo) { MovementData *movementData = new MovementData(); @@ -1389,7 +1431,7 @@ MovementData *DataReaderHelper::decodeMovement(JsonDictionary &json) for (int i = 0; i < length; i++) { JsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_BONE_DATA, i); - MovementBoneData *movementBoneData = decodeMovementBone(*dic); + MovementBoneData *movementBoneData = decodeMovementBone(*dic, dataInfo); movementData->addMovementBoneData(movementBoneData); movementBoneData->release(); @@ -1399,7 +1441,7 @@ MovementData *DataReaderHelper::decodeMovement(JsonDictionary &json) return movementData; } -MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json) +MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json, DataInfo *dataInfo) { MovementBoneData *movementBoneData = new MovementBoneData(); movementBoneData->init(); @@ -1416,7 +1458,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json) for (int i = 0; i < length; i++) { JsonDictionary *dic = json.getSubItemFromArray(FRAME_DATA, i); - FrameData *frameData = decodeFrame(*dic); + FrameData *frameData = decodeFrame(*dic, dataInfo); movementBoneData->addFrameData(frameData); frameData->release(); @@ -1471,11 +1513,11 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json) return movementBoneData; } -FrameData *DataReaderHelper::decodeFrame(JsonDictionary &json) +FrameData *DataReaderHelper::decodeFrame(JsonDictionary &json, DataInfo *dataInfo) { FrameData *frameData = new FrameData(); - decodeNode(frameData, json); + decodeNode(frameData, json, dataInfo); frameData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0); @@ -1554,10 +1596,23 @@ ContourData *DataReaderHelper::decodeContour(JsonDictionary &json) return contourData; } -void DataReaderHelper::decodeNode(BaseData *node, JsonDictionary &json) +void DataReaderHelper::decodeNode(BaseData *node, JsonDictionary &json, DataInfo *dataInfo) { node->x = json.getItemFloatValue(A_X, 0) * s_PositionReadScale; node->y = json.getItemFloatValue(A_Y, 0) * s_PositionReadScale; + + if (dataInfo) + { + node->x *= dataInfo->contentScale; + node->y *= dataInfo->contentScale; + } + else + { + node->x *= s_ContentScale; + node->y *= s_ContentScale; + } + + node->zOrder = json.getItemIntValue(A_Z, 0); node->skewX = json.getItemFloatValue(A_SKEW_X, 0); diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.h b/cocos/editor-support/cocostudio/CCDataReaderHelper.h index d5c8a0d6f5..a9159ef39e 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.h +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.h @@ -63,12 +63,16 @@ protected: cocos2d::Object *target; cocos2d::SEL_SCHEDULE selector; bool autoLoadSpriteFile; + + std::string imagePath; + std::string plistPath; } AsyncStruct; typedef struct _DataInfo { AsyncStruct *asyncStruct; std::queue configFileQueue; + float contentScale; } DataInfo; public: @@ -99,7 +103,7 @@ public: ~DataReaderHelper(); void addDataFromFile(const char *filePath); - void addDataFromFileAsync(const char *filePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector); + void addDataFromFileAsync(const char *imagePath, const char *plistPath, const char *filePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector); void addDataAsyncCallBack(float dt); @@ -145,20 +149,20 @@ public: public: static void addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo = NULL); - static ArmatureData *decodeArmature(JsonDictionary &json); - static BoneData *decodeBone(JsonDictionary &json); - static DisplayData *decodeBoneDisplay(JsonDictionary &json); + static ArmatureData *decodeArmature(JsonDictionary &json, DataInfo *dataInfo); + static BoneData *decodeBone(JsonDictionary &json, DataInfo *dataInfo); + static DisplayData *decodeBoneDisplay(JsonDictionary &json, DataInfo *dataInfo); - static AnimationData *decodeAnimation(JsonDictionary &json); - static MovementData *decodeMovement(JsonDictionary &json); - static MovementBoneData *decodeMovementBone(JsonDictionary &json); - static FrameData *decodeFrame(JsonDictionary &json); + static AnimationData *decodeAnimation(JsonDictionary &json, DataInfo *dataInfo); + static MovementData *decodeMovement(JsonDictionary &json, DataInfo *dataInfo); + static MovementBoneData *decodeMovementBone(JsonDictionary &json, DataInfo *dataInfo); + static FrameData *decodeFrame(JsonDictionary &json, DataInfo *dataInfo); static TextureData *decodeTexture(JsonDictionary &json); static ContourData *decodeContour(JsonDictionary &json); - static void decodeNode(BaseData *node, JsonDictionary &json); + static void decodeNode(BaseData *node, JsonDictionary &json, DataInfo *dataInfo); protected: void loadData(); @@ -177,6 +181,8 @@ protected: std::mutex _addDataMutex; + std::mutex _getFileMutex; + unsigned long _asyncRefCount; unsigned long _asyncRefTotalCount; diff --git a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp index 034f115481..b130428ab1 100644 --- a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp @@ -70,13 +70,15 @@ void DisplayFactory::createDisplay(Bone *bone, DecorativeDisplay *decoDisplay) } } -void DisplayFactory::updateDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty) +void DisplayFactory::updateDisplay(Bone *bone, float dt, bool dirty) { - CS_RETURN_IF(!decoDisplay); + Node *display = bone->getDisplayRenderNode(); + CS_RETURN_IF(!display); #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT if (dirty) { + DecorativeDisplay *decoDisplay = bone->getDisplayManager()->getCurrentDecorativeDisplay(); ColliderDetector *detector = decoDisplay->getColliderDetector(); if (detector) { @@ -84,9 +86,8 @@ void DisplayFactory::updateDisplay(Bone *bone, DecorativeDisplay *decoDisplay, f { CC_BREAK_IF(!detector->getBody()); - Node *node = decoDisplay->getDisplay(); - AffineTransform displayTransform = node->getNodeToParentTransform(); - Point anchorPoint = node->getAnchorPointInPoints(); + AffineTransform displayTransform = display->getNodeToParentTransform(); + Point anchorPoint = display->getAnchorPointInPoints(); anchorPoint = PointApplyAffineTransform(anchorPoint, displayTransform); displayTransform.tx = anchorPoint.x; displayTransform.ty = anchorPoint.y; @@ -98,18 +99,19 @@ void DisplayFactory::updateDisplay(Bone *bone, DecorativeDisplay *decoDisplay, f } #endif - Node *display = decoDisplay->getDisplay(); - - switch(decoDisplay->getDisplayData()->displayType) + switch(bone->getDisplayRenderNodeType()) { case CS_DISPLAY_SPRITE: - updateSpriteDisplay(bone, display, dt, dirty); + if (dirty) + { + static_cast(display)->updateArmatureTransform(); + } break; case CS_DISPLAY_PARTICLE: - updateParticleDisplay(bone, display, dt, dirty); + updateParticleDisplay(bone, display, dt); break; case CS_DISPLAY_ARMATURE: - updateArmatureDisplay(bone, display, dt, dirty); + updateArmatureDisplay(bone, display, dt); break; default: { @@ -153,6 +155,13 @@ void DisplayFactory::createSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisp skin = Skin::createWithSpriteFrameName((textureName + ".png").c_str()); } + decoDisplay->setDisplay(skin); + + if (skin == NULL) + { + return; + } + skin->setBone(bone); initSpriteDisplay(bone, decoDisplay, displayData->displayName.c_str(), skin); @@ -170,8 +179,6 @@ void DisplayFactory::createSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisp } } - decoDisplay->setDisplay(skin); - } void DisplayFactory::initSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, const char *displayName, Skin *skin) @@ -206,17 +213,11 @@ void DisplayFactory::initSpriteDisplay(Bone *bone, DecorativeDisplay *decoDispla #endif } -void DisplayFactory::updateSpriteDisplay(Bone *bone, Node *display, float dt, bool dirty) -{ - CS_RETURN_IF(!dirty); - Skin *skin = (Skin *)display; - skin->updateArmatureTransform(); -} void DisplayFactory::addArmatureDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) { - ArmatureDisplayData *adp = ArmatureDisplayData::create(); ; + ArmatureDisplayData *adp = ArmatureDisplayData::create(); adp->copy((ArmatureDisplayData *)displayData); decoDisplay->setDisplayData(adp); @@ -228,15 +229,9 @@ void DisplayFactory::createArmatureDisplay(Bone *bone, DecorativeDisplay *decoDi Armature *armature = Armature::create(displayData->displayName.c_str(), bone); - /* - * because this bone have called this name, so armature should change it's name, or it can't add to - * Armature's bone children. - */ - armature->setName((bone->getName() + "_armatureChild").c_str()); - decoDisplay->setDisplay(armature); } -void DisplayFactory::updateArmatureDisplay(Bone *bone, Node *display, float dt, bool dirty) +void DisplayFactory::updateArmatureDisplay(Bone *bone, Node *display, float dt) { Armature *armature = (Armature *)display; if(armature) @@ -262,7 +257,7 @@ void DisplayFactory::createParticleDisplay(Bone *bone, DecorativeDisplay *decoDi ParticleSystem *system = ParticleSystemQuad::create(displayData->plist.c_str()); decoDisplay->setDisplay(system); } -void DisplayFactory::updateParticleDisplay(Bone *bone, Node *display, float dt, bool dirty) +void DisplayFactory::updateParticleDisplay(Bone *bone, Node *display, float dt) { ParticleSystem *system = (ParticleSystem *)display; BaseData node; diff --git a/cocos/editor-support/cocostudio/CCDisplayFactory.h b/cocos/editor-support/cocostudio/CCDisplayFactory.h index 3ef0725ff0..a62329d548 100644 --- a/cocos/editor-support/cocostudio/CCDisplayFactory.h +++ b/cocos/editor-support/cocostudio/CCDisplayFactory.h @@ -40,21 +40,20 @@ class DisplayFactory public: static void addDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData); static void createDisplay(Bone *bone, DecorativeDisplay *decoDisplay); - static void updateDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty); + static void updateDisplay(Bone *bone, float dt, bool dirty); static void addSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData); static void createSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay); static void initSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, const char *displayName, Skin *skin); - static void updateSpriteDisplay(Bone *bone, cocos2d::Node *display, float dt, bool dirty); static void addArmatureDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData); static void createArmatureDisplay(Bone *bone, DecorativeDisplay *decoDisplay); - static void updateArmatureDisplay(Bone *bone, cocos2d::Node *display, float dt, bool dirty); + static void updateArmatureDisplay(Bone *bone, cocos2d::Node *display, float dt); static void addParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData); static void createParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay); - static void updateParticleDisplay(Bone *bone, cocos2d::Node *display, float dt, bool dirty); + static void updateParticleDisplay(Bone *bone, cocos2d::Node *display, float dt); }; diff --git a/cocos/editor-support/cocostudio/CCDisplayManager.cpp b/cocos/editor-support/cocostudio/CCDisplayManager.cpp index ae1ed19781..bffcf80c64 100644 --- a/cocos/editor-support/cocostudio/CCDisplayManager.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayManager.cpp @@ -48,6 +48,7 @@ DisplayManager *DisplayManager::create(Bone *bone) DisplayManager::DisplayManager() : _decoDisplayList(NULL) , _displayRenderNode(NULL) + , _displayType(CS_DISPLAY_MAX) , _currentDecoDisplay(NULL) , _displayIndex(-1) , _forceChangeDisplay(false) @@ -137,7 +138,7 @@ void DisplayManager::addDisplay(Node *display, int index) if (SpriteDisplayData *spriteDisplayData = (SpriteDisplayData *)decoDisplay->getDisplayData()) { skin->setSkinData(spriteDisplayData->skinData); - ((CCSpriteDisplayData *)displayData)->skinData = spriteDisplayData->skinData; + ((SpriteDisplayData *)displayData)->skinData = spriteDisplayData->skinData; } else { @@ -172,12 +173,13 @@ void DisplayManager::addDisplay(Node *display, int index) void DisplayManager::removeDisplay(int index) { - _decoDisplayList->removeObjectAtIndex(index); - if(index == _displayIndex) { setCurrentDecorativeDisplay(NULL); + _displayIndex = -1; } + + _decoDisplayList->removeObjectAtIndex(index); } Array *DisplayManager::getDecorativeDisplayList() @@ -265,6 +267,12 @@ void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay) _displayRenderNode->retain(); _displayRenderNode->setVisible(_visible); + + _displayType = _currentDecoDisplay->getDisplayData()->displayType; + } + else + { + _displayType = CS_DISPLAY_MAX; } } @@ -273,6 +281,12 @@ Node *DisplayManager::getDisplayRenderNode() return _displayRenderNode; } + +DisplayType DisplayManager::getDisplayRenderNodeType() +{ + return _displayType; +} + int DisplayManager::getCurrentDisplayIndex() { return _displayIndex; diff --git a/cocos/editor-support/cocostudio/CCDisplayManager.h b/cocos/editor-support/cocostudio/CCDisplayManager.h index 9953d77995..0856886c57 100644 --- a/cocos/editor-support/cocostudio/CCDisplayManager.h +++ b/cocos/editor-support/cocostudio/CCDisplayManager.h @@ -91,6 +91,7 @@ public: cocos2d::Node *getDisplayRenderNode(); + DisplayType getDisplayRenderNodeType(); int getCurrentDisplayIndex(); @@ -133,6 +134,8 @@ protected: cocos2d::Array *_decoDisplayList; //! Display render node. cocos2d::Node *_displayRenderNode; + //! Display render node type + DisplayType _displayType; //! Include current display information, like contour sprite, etc. DecorativeDisplay *_currentDecoDisplay; //! Current display index diff --git a/cocos/editor-support/cocostudio/CCProcessBase.cpp b/cocos/editor-support/cocostudio/CCProcessBase.cpp index c3e1bfbc20..1c9bd8965e 100644 --- a/cocos/editor-support/cocostudio/CCProcessBase.cpp +++ b/cocos/editor-support/cocostudio/CCProcessBase.cpp @@ -141,8 +141,18 @@ void ProcessBase::update(float dt) void ProcessBase::gotoFrame(int frameIndex) { + if (_loopType == ANIMATION_NO_LOOP) + { + _loopType = ANIMATION_MAX; + } + else if (_loopType == ANIMATION_TO_LOOP_FRONT) + { + _loopType = ANIMATION_LOOP_FRONT; + } + _curFrameIndex = frameIndex; - pause(); + + _nextFrameIndex = _durationTween; } int ProcessBase::getCurrentFrameIndex() diff --git a/cocos/editor-support/cocostudio/CCProcessBase.h b/cocos/editor-support/cocostudio/CCProcessBase.h index 9f80fb2ea7..77c5da4ebb 100644 --- a/cocos/editor-support/cocostudio/CCProcessBase.h +++ b/cocos/editor-support/cocostudio/CCProcessBase.h @@ -104,8 +104,6 @@ public: virtual void stop(); - virtual void gotoFrame(int frameIndex); - /** * You should never call this function, unless you know what you do * Update the Process, include current process, current frame and son on @@ -118,6 +116,7 @@ public: protected: + virtual void gotoFrame(int frameIndex); /** * Update(float dt) will call this handler, you can handle your logic here diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index d1c66ddc3e..5cb8483a95 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -37,6 +37,8 @@ namespace cocostudio { #define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__)) #endif +#define SET_VERTEX3F(_v_, _x_, _y_, _z_) (_v_).x = (_x_); (_v_).y = (_y_); (_v_).z = (_z_); + Skin *Skin::create() { Skin *skin = new Skin(); @@ -75,6 +77,7 @@ Skin *Skin::create(const char *pszFileName) Skin::Skin() : _bone(NULL) + , _armature(NULL) , _displayName("") { _skinTransform = AffineTransformIdentity; @@ -82,15 +85,22 @@ Skin::Skin() bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) { - bool ret = Sprite::initWithSpriteFrameName(pszSpriteFrameName); + CCAssert(pszSpriteFrameName != NULL, ""); - if (ret) + SpriteFrame *pFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(pszSpriteFrameName); + bool ret = true; + + if (pFrame != NULL) { - TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); - setTextureAtlas(atlas); - - _displayName = pszSpriteFrameName; + ret = initWithSpriteFrame(pFrame); } + else + { + CCLOG("Cann't find CCSpriteFrame with %s. Please check your .plist file", pszSpriteFrameName); + ret = false; + } + + _displayName = pszSpriteFrameName; return ret; } @@ -99,13 +109,7 @@ bool Skin::initWithFile(const char *pszFilename) { bool ret = Sprite::initWithFile(pszFilename); - if (ret) - { - TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); - setTextureAtlas(atlas); - - _displayName = pszFilename; - } + _displayName = pszFilename; return ret; } @@ -116,7 +120,8 @@ void Skin::setSkinData(const BaseData &var) setScaleX(_skinData.scaleX); setScaleY(_skinData.scaleY); - setRotation(CC_RADIANS_TO_DEGREES(_skinData.skewX)); + setRotationX(CC_RADIANS_TO_DEGREES(_skinData.skewX)); + setRotationY(CC_RADIANS_TO_DEGREES(-_skinData.skewY)); setPosition(Point(_skinData.x, _skinData.y)); _skinTransform = getNodeToParentTransform(); @@ -131,6 +136,10 @@ const BaseData &Skin::getSkinData() const void Skin::updateArmatureTransform() { _transform = AffineTransformConcat(_skinTransform, _bone->getNodeToArmatureTransform()); + if(_armature && _armature->getBatchNode()) + { + _transform = AffineTransformConcat(_transform, _armature->getNodeToParentTransform()); + } } void Skin::updateTransform() @@ -173,10 +182,10 @@ void Skin::updateTransform() float dx = x1 * cr - y2 * sr2 + x; float dy = x1 * sr + y2 * cr2 + y; - _quad.bl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), _vertexZ ); - _quad.br.vertices = Vertex3F( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), _vertexZ ); - _quad.tl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), _vertexZ ); - _quad.tr.vertices = Vertex3F( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _vertexZ ); + SET_VERTEX3F( _quad.bl.vertices, RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), _vertexZ ); + SET_VERTEX3F( _quad.br.vertices, RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), _vertexZ ); + SET_VERTEX3F( _quad.tl.vertices, RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), _vertexZ ); + SET_VERTEX3F( _quad.tr.vertices, RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _vertexZ ); } // MARMALADE CHANGE: ADDED CHECK FOR NULL, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS @@ -204,4 +213,20 @@ AffineTransform Skin::getNodeToWorldTransformAR() const return AffineTransformConcat(displayTransform, _bone->getArmature()->getNodeToWorldTransform()); } +void Skin::setBone(Bone *bone) +{ + _bone = bone; + if(Armature *armature = _bone->getArmature()) + { + _armature = armature; + TextureAtlas *atlas = armature->getTexureAtlasWithTexture(_texture); + setTextureAtlas(atlas); + } +} + +Bone *Skin::getBone() +{ + return _bone; +} + } diff --git a/cocos/editor-support/cocostudio/CCSkin.h b/cocos/editor-support/cocostudio/CCSkin.h index 3494c48436..2d934b8e4b 100644 --- a/cocos/editor-support/cocostudio/CCSkin.h +++ b/cocos/editor-support/cocostudio/CCSkin.h @@ -49,9 +49,10 @@ public: cocos2d::AffineTransform getNodeToWorldTransformAR() const; CC_PROPERTY_PASS_BY_REF(BaseData, _skinData, SkinData); - CC_SYNTHESIZE(Bone *, _bone, Bone); + CC_PROPERTY(Bone *, _bone, Bone); protected: + Armature *_armature; cocos2d::AffineTransform _skinTransform; CC_SYNTHESIZE_READONLY(std::string, _displayName, DisplayName) }; diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp index d783c4ba4e..68fa7ebfb5 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp @@ -52,26 +52,12 @@ void SpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath, imagePath); } -TextureAtlas *SpriteFrameCacheHelper::getTexureAtlasWithTexture(Texture2D *texture) -{ - int key = texture->getName(); - TextureAtlas *atlas = (TextureAtlas *)_textureAtlasDic->objectForKey(key); - if (atlas == NULL) - { - atlas = TextureAtlas::createWithTexture(texture, 4); - _textureAtlasDic->setObject(atlas, key); - } - return atlas; -} - SpriteFrameCacheHelper::SpriteFrameCacheHelper() { - _textureAtlasDic = new Dictionary(); } SpriteFrameCacheHelper::~SpriteFrameCacheHelper() { - CC_SAFE_RELEASE_NULL(_textureAtlasDic); } } diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h index 150fe96aaa..81ccf1b1f9 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h @@ -47,8 +47,6 @@ public: */ void addSpriteFrameFromFile(const char *plistPath, const char *imagePath); - cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture); - private: /** * @js ctor @@ -60,8 +58,6 @@ private: */ ~SpriteFrameCacheHelper(); - cocos2d::Dictionary *_textureAtlasDic; - static SpriteFrameCacheHelper *_spriteFrameCacheHelper; }; diff --git a/cocos/editor-support/cocostudio/CCTransformHelp.cpp b/cocos/editor-support/cocostudio/CCTransformHelp.cpp index a836055c16..0107760a3b 100644 --- a/cocos/editor-support/cocostudio/CCTransformHelp.cpp +++ b/cocos/editor-support/cocostudio/CCTransformHelp.cpp @@ -96,10 +96,23 @@ void TransformHelp::transformToParentWithoutScale(BaseData &node, const BaseData void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix) { - matrix.a = node.scaleX * cos(node.skewY); - matrix.b = node.scaleX * sin(node.skewY); - matrix.c = node.scaleY * sin(node.skewX); - matrix.d = node.scaleY * cos(node.skewX); + if (node.skewX == -node.skewY) + { + double sine = sin(node.skewX); + double cosine = cos(node.skewX); + + matrix.a = node.scaleX * cosine; + matrix.b = node.scaleX * -sine; + matrix.c = node.scaleY * sine; + matrix.d = node.scaleY * cosine; + } + else + { + matrix.a = node.scaleX * cos(node.skewY); + matrix.b = node.scaleX * sin(node.skewY); + matrix.c = node.scaleY * sin(node.skewX); + matrix.d = node.scaleY * cos(node.skewX); + } matrix.tx = node.x; matrix.ty = node.y; diff --git a/cocos/editor-support/cocostudio/CCTween.cpp b/cocos/editor-support/cocostudio/CCTween.cpp index 8fec95b2a0..5704867a61 100644 --- a/cocos/editor-support/cocostudio/CCTween.cpp +++ b/cocos/editor-support/cocostudio/CCTween.cpp @@ -99,7 +99,14 @@ void Tween::play(MovementBoneData *movementBoneData, int durationTo, int duratio { ProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing); - _loopType = (AnimationType)loop; + if (loop) + { + _loopType = ANIMATION_TO_LOOP_FRONT; + } + else + { + _loopType = ANIMATION_NO_LOOP; + } _totalDuration = 0; _betweenDuration = 0; @@ -135,15 +142,6 @@ void Tween::play(MovementBoneData *movementBoneData, int durationTo, int duratio } else if (_movementBoneData->frameList.count() > 1) { - if (loop) - { - _loopType = ANIMATION_TO_LOOP_BACK; - } - else - { - _loopType = ANIMATION_NO_LOOP; - } - _durationTween = durationTween * _movementBoneData->scale; if (loop && _movementBoneData->delay != 0) @@ -166,6 +164,27 @@ void Tween::play(MovementBoneData *movementBoneData, int durationTo, int duratio tweenNodeTo(0); } +void Tween::gotoAndPlay(int frameIndex) +{ + ProcessBase::gotoFrame(frameIndex); + + _totalDuration = 0; + _betweenDuration = 0; + _fromIndex = _toIndex = 0; + + _isPlaying = true; + _isComplete = _isPause = false; + + _currentPercent = (float)_curFrameIndex / (float)_rawDuration; + _currentFrame = _nextFrameIndex * _currentPercent; +} + +void Tween::gotoAndPause(int frameIndex) +{ + gotoAndPlay(frameIndex); + pause(); +} + void Tween::updateHandler() { if (_currentPercent >= 1) @@ -211,9 +230,9 @@ void Tween::updateHandler() } } break; - case ANIMATION_TO_LOOP_BACK: + case ANIMATION_TO_LOOP_FRONT: { - _loopType = ANIMATION_LOOP_BACK; + _loopType = ANIMATION_LOOP_FRONT; _nextFrameIndex = _durationTween > 0 ? _durationTween : 1; @@ -244,10 +263,6 @@ void Tween::updateHandler() default: { _currentFrame = fmodf(_currentFrame, _nextFrameIndex); - - _totalDuration = 0; - _betweenDuration = 0; - _fromIndex = _toIndex = 0; } break; } @@ -342,7 +357,7 @@ FrameData *Tween::tweenNodeTo(float percent, FrameData *node) if (!_from->isTween) { - return _from; + percent = 0; } node->x = _from->x + percent * _between->x; @@ -393,6 +408,7 @@ float Tween::updateFrameData(float currentPercent) FrameData *from = NULL; FrameData *to = NULL; + bool passLastFrame = false; if (playedTime < frames[0]->frameID) { @@ -402,32 +418,31 @@ float Tween::updateFrameData(float currentPercent) } else if(playedTime >= frames[length - 1]->frameID) { - from = to = frames[length - 1]; - setBetween(from, to); - return currentPercent; + passLastFrame = true; } do { + _fromIndex = _toIndex; from = frames[_fromIndex]; _totalDuration = from->frameID; - if (++_toIndex >= length) + _toIndex = _fromIndex + 1; + if (_toIndex >= length) { _toIndex = 0; } - _fromIndex = _toIndex; to = frames[_toIndex]; //! Guaranteed to trigger frame event - if(from->strEvent.length() != 0) + if(from->strEvent.length() != 0 && !_animation->isIgnoreFrameEvent()) { _animation->frameEvent(_bone, from->strEvent.c_str(), from->frameID, playedTime); } - if (playedTime == from->frameID) + if (playedTime == from->frameID || (passLastFrame && _fromIndex == length-1)) { break; } diff --git a/cocos/editor-support/cocostudio/CCTween.h b/cocos/editor-support/cocostudio/CCTween.h index 80b6c6d7e9..5e5bea6356 100644 --- a/cocos/editor-support/cocostudio/CCTween.h +++ b/cocos/editor-support/cocostudio/CCTween.h @@ -83,14 +83,11 @@ public: */ virtual void play(MovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing); - inline void setAnimation(ArmatureAnimation *animation) - { - _animation = animation; - } - inline ArmatureAnimation *getAnimation() const - { - return _animation; - } + inline void setAnimation(ArmatureAnimation *animation) { _animation = animation; } + inline ArmatureAnimation *getAnimation() const { return _animation; } + + virtual void gotoAndPlay(int frameIndex); + virtual void gotoAndPause(int frameIndex); protected: /** diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 1cd233ffd2..4421be8ccb 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -30,6 +30,9 @@ Layer *CreateLayer(int index) case TEST_PERFORMANCE: pLayer = new TestPerformance(); break; + case TEST_PERFORMANCE_BATCHNODE: + pLayer = new TestPerformanceBatchNode(); + break; case TEST_CHANGE_ZORDER: pLayer = new TestChangeZorder(); break; @@ -54,6 +57,9 @@ Layer *CreateLayer(int index) case TEST_ARMATURE_NESTING: pLayer = new TestArmatureNesting(); break; + case TEST_ARMATURE_NESTING_2: + pLayer = new TestArmatureNesting2(); + break; default: break; } @@ -235,6 +241,9 @@ void TestAsynchronousLoading::onEnter() ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/Cowboy.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/hero.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/horse.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/bear.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); //! load data directly // ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); @@ -314,6 +323,8 @@ std::string TestDragonBones20::title() +#define ArmaturePerformanceTag 20000 + TestPerformance::~TestPerformance() { } @@ -321,10 +332,22 @@ void TestPerformance::onEnter() { ArmatureTestLayer::onEnter(); + + MenuItemFont::setFontSize(65); + MenuItemFont *decrease = MenuItemFont::create(" - ", this, menu_selector(TestPerformance::onDecrease)); + decrease->setColor(ccc3(0,200,20)); + MenuItemFont *increase = MenuItemFont::create(" + ", this, menu_selector(TestPerformance::onIncrease)); + increase->setColor(ccc3(0,200,20)); + + Menu *menu = Menu::create(decrease, increase, NULL); + menu->alignItemsHorizontally(); + menu->setPosition(ccp(VisibleRect::getVisibleRect().size.width/2, VisibleRect::getVisibleRect().size.height-100)); + addChild(menu, 10000); + armatureCount = frames = times = lastTimes = 0; generated = false; - scheduleUpdate(); + addArmature(100); } std::string TestPerformance::title() @@ -335,37 +358,76 @@ std::string TestPerformance::subtitle() { return "Current Armature Count : "; } -void TestPerformance::addArmature(Armature *armature) +void TestPerformance::onIncrease(Object* pSender) { - armatureCount++; - addChild(armature, armatureCount); + addArmature(20); } -void TestPerformance::update(float delta) +void TestPerformance::onDecrease(Object* pSender) { - frames ++; - times += delta; + if (armatureCount == 0) + return; - if (frames / times > 58) + for (int i = 0; i<20; i++) { + removeArmatureFromParent(ArmaturePerformanceTag + armatureCount); + armatureCount --; + refreshTitile(); + } +} +void TestPerformance::addArmature(int number) +{ + for (int i = 0; iinit("Knight_f/Knight"); armature->getAnimation()->playByIndex(0); armature->setPosition(50 + armatureCount * 2, 150); armature->setScale(0.6f); - addArmature(armature); + addArmatureToParent(armature); armature->release(); - - char pszCount[255]; - sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount); - LabelTTF *label = (LabelTTF *)getChildByTag(10001); - label->setString(pszCount); } + + refreshTitile(); +} +void TestPerformance::addArmatureToParent(cocostudio::Armature *armature) +{ + addChild(armature, 0, ArmaturePerformanceTag + armatureCount); +} +void TestPerformance::removeArmatureFromParent(int tag) +{ + removeChildByTag(ArmaturePerformanceTag + armatureCount); +} +void TestPerformance::refreshTitile() +{ + char pszCount[255]; + sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount); + LabelTTF *label = (LabelTTF *)getChildByTag(10001); + label->setString(pszCount); } +void TestPerformanceBatchNode::onEnter() +{ + batchNode = BatchNode::create(); + addChild(batchNode); - + TestPerformance::onEnter(); +} +std::string TestPerformanceBatchNode::title() +{ + return "Test Performance of using BatchNode"; +} +void TestPerformanceBatchNode::addArmatureToParent(cocostudio::Armature *armature) +{ + batchNode->addChild(armature, 0, ArmaturePerformanceTag + armatureCount); +} +void TestPerformanceBatchNode::removeArmatureFromParent(int tag) +{ + batchNode->removeChildByTag(ArmaturePerformanceTag + armatureCount); +} void TestChangeZorder::onEnter() @@ -905,7 +967,7 @@ void TestBoundingBox::draw() { CC_NODE_DRAW_SETUP(); - rect = RectApplyAffineTransform(armature->getBoundingBox(), armature->getNodeToParentTransform()); + rect = armature->getBoundingBox(); DrawPrimitives::setDrawColor4B(100, 100, 100, 255); DrawPrimitives::drawRect(rect.origin, Point(rect.getMaxX(), rect.getMaxY())); @@ -977,3 +1039,185 @@ void TestArmatureNesting::onTouchesEnded(const std::vector& touches, Eve armature->getBone("armOutside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); } } + + + + +Hero *Hero::create(const char *name) +{ + Hero *hero = new Hero(); + if (hero && hero->init(name)) + { + hero->autorelease(); + return hero; + } + CC_SAFE_DELETE(hero); + return NULL; +} + +Hero::Hero() + : m_pMount(NULL) + , m_pLayer(NULL) +{ +} + +void Hero::changeMount(Armature *armature) +{ + if (armature == NULL) + { + retain(); + + playByIndex(0); + //Remove hero from display list + m_pMount->getBone("hero")->removeDisplay(0); + m_pMount->stopAllActions(); + + //Set position to current position + setPosition(m_pMount->getPosition()); + //Add to layer + m_pLayer->addChild(this); + + release(); + + setMount(armature); + } + else + { + setMount(armature); + + retain(); + //Remove from layer + removeFromParentAndCleanup(false); + + //Get the hero bone + Bone *bone = armature->getBone("hero"); + //Add hero as a display to this bone + bone->addDisplay(this, 0); + //Change this bone's display + bone->changeDisplayByIndex(0, true); + bone->setIgnoreMovementBoneData(true); + + setPosition(ccp(0,0)); + //Change animation + playByIndex(1); + + setScale(1); + + release(); + } + +} + +void Hero::playByIndex(int index) +{ + _animation->playByIndex(index); + if (m_pMount) + { + m_pMount->getAnimation()->playByIndex(index); + } +} + +void TestArmatureNesting2::onEnter() +{ + ArmatureTestLayer::onEnter(); + + auto listener = EventListenerTouchAllAtOnce::create(); + listener->onTouchesEnded = CC_CALLBACK_2(TestArmatureNesting2::onTouchesEnded, this); + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + + + touchedMenu = false; + + LabelTTF* label = CCLabelTTF::create("Change Mount", "Arial", 20); + MenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(TestArmatureNesting2::ChangeMountCallback)); + + Menu* pMenu =Menu::create(pMenuItem, NULL); + + pMenu->setPosition( CCPointZero ); + pMenuItem->setPosition( ccp( VisibleRect::right().x - 67, VisibleRect::bottom().y + 50) ); + + addChild(pMenu, 2); + + //Create a hero + hero = Hero::create("hero"); + hero->setLayer(this); + hero->playByIndex(0); + hero->setPosition(ccp(VisibleRect::left().x + 20, VisibleRect::left().y)); + addChild(hero); + + //Create 3 mount + horse = createMount("horse", VisibleRect::center()); + + horse2 = createMount("horse", ccp(120, 200)); + horse2->setOpacity(200); + + bear = createMount("bear", ccp(300,70)); +} +void TestArmatureNesting2::onExit() +{ + ArmatureTestLayer::onExit(); +} +std::string TestArmatureNesting2::title() +{ + return "Test CCArmature Nesting 2"; +} +std::string TestArmatureNesting2::subtitle() +{ + return "Move to a mount and press the ChangeMount Button."; +} +void TestArmatureNesting2::onTouchesEnded(const std::vector& touches, Event* event) +{ + Point point = touches[0]->getLocation(); + + Armature *armature = hero->getMount() == NULL ? hero : hero->getMount(); + + //Set armature direction + if (point.x < armature->getPositionX()) + { + armature->setScaleX(-1); + } + else + { + armature->setScaleX(1); + } + + ActionInterval *move = CCMoveTo::create(2, point); + armature->stopAllActions(); + armature->runAction(Sequence::create(move, CallFunc::create(this, NULL), NULL)); +} + +void TestArmatureNesting2::ChangeMountCallback(Object* pSender) +{ + hero->stopAllActions(); + + if (hero->getMount()) + { + hero->changeMount(NULL); + } + else + { + if (ccpDistance(hero->getPosition(), horse->getPosition()) < 20) + { + hero->changeMount(horse); + } + else if (ccpDistance(hero->getPosition(), horse2->getPosition()) < 20) + { + hero->changeMount(horse2); + } + else if (ccpDistance(hero->getPosition(), bear->getPosition()) < 30) + { + hero->changeMount(bear); + } + } +} + +Armature * TestArmatureNesting2::createMount(const char *name, Point position) +{ + Armature *armature = Armature::create(name); + armature->getAnimation()->playByIndex(0); + armature->setPosition(position); + addChild(armature); + + return armature; +} + diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index 51b47085b5..f5a7787168 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -30,6 +30,7 @@ enum { TEST_COCOSTUDIO_WITH_SKELETON, TEST_DRAGON_BONES_2_0, TEST_PERFORMANCE, + TEST_PERFORMANCE_BATCHNODE, TEST_CHANGE_ZORDER, TEST_ANIMATION_EVENT, TEST_PARTICLE_DISPLAY, @@ -38,6 +39,7 @@ enum { TEST_BOUDINGBOX, TEST_ANCHORPOINT, TEST_ARMATURE_NESTING, + TEST_ARMATURE_NESTING_2, TEST_LAYER_COUNT }; @@ -97,8 +99,12 @@ public: virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); - virtual void addArmature(cocostudio::Armature *armature); - void update(float delta); + virtual void onIncrease(Object* pSender); + virtual void onDecrease(Object* pSender); + virtual void addArmature(int number); + virtual void addArmatureToParent(cocostudio::Armature *armature); + virtual void removeArmatureFromParent(int tag); + virtual void refreshTitile(); int armatureCount; @@ -108,6 +114,15 @@ public: bool generated; }; +class TestPerformanceBatchNode : public TestPerformance +{ + virtual void onEnter(); + virtual std::string title(); + virtual void addArmatureToParent(cocostudio::Armature *armature); + virtual void removeArmatureFromParent(int tag); + + cocostudio::BatchNode *batchNode; +}; class TestChangeZorder : public ArmatureTestLayer { @@ -256,4 +271,39 @@ public: cocostudio::Armature *armature; int weaponIndex; }; + +class Hero : public cocostudio::Armature +{ +public: + static Hero *create(const char *name); + Hero(); + + virtual void changeMount(cocostudio::Armature *armature); + virtual void playByIndex(int index); + + CC_SYNTHESIZE(cocostudio::Armature*, m_pMount, Mount); + CC_SYNTHESIZE(cocos2d::Layer*, m_pLayer, Layer); +}; + +class TestArmatureNesting2 : public ArmatureTestLayer +{ +public: + virtual void onEnter(); + virtual void onExit(); + virtual std::string title(); + virtual std::string subtitle(); + void onTouchesEnded(const std::vector& touches, Event* event); + + virtual void ChangeMountCallback(Object* pSender); + virtual cocostudio::Armature *createMount(const char *name, Point position); + + Hero *hero; + + cocostudio::Armature *horse; + cocostudio::Armature *horse2; + cocostudio::Armature *bear; + + + bool touchedMenu; +}; #endif // __HELLOWORLD_SCENE_H__ \ No newline at end of file From ef973b5737f8d441f3333c2470e97aae9a91d5eb Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Wed, 30 Oct 2013 09:54:05 +0800 Subject: [PATCH 07/39] upload resource --- .../Cpp/TestCpp/Resources/armature/Dragon.xml | 354 ++++++++++++------ 1 file changed, 241 insertions(+), 113 deletions(-) diff --git a/samples/Cpp/TestCpp/Resources/armature/Dragon.xml b/samples/Cpp/TestCpp/Resources/armature/Dragon.xml index 0b4f52cf06..f531349f7c 100644 --- a/samples/Cpp/TestCpp/Resources/armature/Dragon.xml +++ b/samples/Cpp/TestCpp/Resources/armature/Dragon.xml @@ -1,56 +1,56 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + @@ -58,158 +58,286 @@ - - - + + + - + - + - + - - - + + + - - - + + + - + - - - + + + - - - + + + - - - + + + - + - + - + - + - + - - - + + + - + - - - + + + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - - + + + - - - + + + - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 80b97be6f4378a2bc0b1b58ead232b98f53ad280 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Wed, 30 Oct 2013 11:34:16 +0800 Subject: [PATCH 08/39] update develop --- .../cocostudio/CCDataReaderHelper.cpp | 2 +- .../CocoStudioArmatureTest/ArmatureScene.cpp | 33 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 83151322c5..3fb1b69fb8 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -344,7 +344,7 @@ void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *p if (pos != std::string::npos) { - basefilePath = s_BasefilePath.substr(0, pos + 1); + basefilePath = basefilePath.substr(0, pos + 1); } else { diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 4421be8ccb..625308dd01 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -334,14 +334,14 @@ void TestPerformance::onEnter() MenuItemFont::setFontSize(65); - MenuItemFont *decrease = MenuItemFont::create(" - ", this, menu_selector(TestPerformance::onDecrease)); - decrease->setColor(ccc3(0,200,20)); - MenuItemFont *increase = MenuItemFont::create(" + ", this, menu_selector(TestPerformance::onIncrease)); - increase->setColor(ccc3(0,200,20)); + MenuItemFont *decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(TestPerformance::onDecrease, this)); + decrease->setColor(Color3B(0,200,20)); + MenuItemFont *increase = MenuItemFont::create(" + ", CC_CALLBACK_1(TestPerformance::onIncrease, this)); + increase->setColor(Color3B(0,200,20)); Menu *menu = Menu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); - menu->setPosition(ccp(VisibleRect::getVisibleRect().size.width/2, VisibleRect::getVisibleRect().size.height-100)); + menu->setPosition(Point(VisibleRect::getVisibleRect().size.width/2, VisibleRect::getVisibleRect().size.height-100)); addChild(menu, 10000); armatureCount = frames = times = lastTimes = 0; @@ -1097,7 +1097,7 @@ void Hero::changeMount(Armature *armature) bone->changeDisplayByIndex(0, true); bone->setIgnoreMovementBoneData(true); - setPosition(ccp(0,0)); + setPosition(Point(0,0)); //Change animation playByIndex(1); @@ -1125,16 +1125,15 @@ void TestArmatureNesting2::onEnter() listener->onTouchesEnded = CC_CALLBACK_2(TestArmatureNesting2::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - touchedMenu = false; LabelTTF* label = CCLabelTTF::create("Change Mount", "Arial", 20); - MenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(TestArmatureNesting2::ChangeMountCallback)); + MenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, CC_CALLBACK_1(TestArmatureNesting2::ChangeMountCallback, this)); Menu* pMenu =Menu::create(pMenuItem, NULL); - pMenu->setPosition( CCPointZero ); - pMenuItem->setPosition( ccp( VisibleRect::right().x - 67, VisibleRect::bottom().y + 50) ); + pMenu->setPosition( Point() ); + pMenuItem->setPosition( Point( VisibleRect::right().x - 67, VisibleRect::bottom().y + 50) ); addChild(pMenu, 2); @@ -1142,16 +1141,16 @@ void TestArmatureNesting2::onEnter() hero = Hero::create("hero"); hero->setLayer(this); hero->playByIndex(0); - hero->setPosition(ccp(VisibleRect::left().x + 20, VisibleRect::left().y)); + hero->setPosition(Point(VisibleRect::left().x + 20, VisibleRect::left().y)); addChild(hero); //Create 3 mount horse = createMount("horse", VisibleRect::center()); - horse2 = createMount("horse", ccp(120, 200)); + horse2 = createMount("horse", Point(120, 200)); horse2->setOpacity(200); - bear = createMount("bear", ccp(300,70)); + bear = createMount("bear", Point(300,70)); } void TestArmatureNesting2::onExit() { @@ -1183,7 +1182,7 @@ void TestArmatureNesting2::onTouchesEnded(const std::vector& touches, Ev ActionInterval *move = CCMoveTo::create(2, point); armature->stopAllActions(); - armature->runAction(Sequence::create(move, CallFunc::create(this, NULL), NULL)); + armature->runAction(Sequence::create(move, NULL)); } void TestArmatureNesting2::ChangeMountCallback(Object* pSender) @@ -1196,15 +1195,15 @@ void TestArmatureNesting2::ChangeMountCallback(Object* pSender) } else { - if (ccpDistance(hero->getPosition(), horse->getPosition()) < 20) + if (hero->getPosition().getDistance(horse->getPosition()) < 20) { hero->changeMount(horse); } - else if (ccpDistance(hero->getPosition(), horse2->getPosition()) < 20) + else if (hero->getPosition().getDistance(horse2->getPosition()) < 20) { hero->changeMount(horse2); } - else if (ccpDistance(hero->getPosition(), bear->getPosition()) < 30) + else if (hero->getPosition().getDistance(bear->getPosition()) < 30) { hero->changeMount(bear); } From 005d3c012103ddb31a2867251ae24276695825c4 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Thu, 31 Oct 2013 17:28:14 +0800 Subject: [PATCH 10/39] 1. fix if frame event is at the last frame, it may emit event several times 2. add method for removing single data info 3. add test TEST_DIRECT_LOADING 4. add test TEST_FRAME_EVENT 5. add method for getting calculated collider vertex --- .../cocostudio/CCArmatureDataManager.cpp | 113 ++++++++++++++---- .../cocostudio/CCArmatureDataManager.h | 27 +++-- .../cocostudio/CCArmatureDefine.h | 4 + .../cocostudio/CCColliderDetector.cpp | 36 ++++++ .../cocostudio/CCColliderDetector.h | 4 + .../cocostudio/CCDataReaderHelper.cpp | 102 +++++++++------- .../cocostudio/CCDataReaderHelper.h | 5 +- cocos/editor-support/cocostudio/CCTween.cpp | 18 ++- cocos/editor-support/cocostudio/CCTween.h | 19 +-- .../CocoStudioArmatureTest/ArmatureScene.cpp | 80 ++++++++++++- .../CocoStudioArmatureTest/ArmatureScene.h | 21 ++++ 11 files changed, 339 insertions(+), 90 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp index 13ca184768..ca1945b418 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp @@ -65,7 +65,21 @@ ArmatureDataManager::ArmatureDataManager(void) ArmatureDataManager::~ArmatureDataManager(void) { - removeAll(); + if( _animationDatas ) + { + _animationDatas->removeAllObjects(); + } + if( _armarureDatas ) + { + _armarureDatas->removeAllObjects(); + } + + if( _textureDatas ) + { + _textureDatas->removeAllObjects(); + } + + _relativeDatas.clear(); CC_SAFE_DELETE(_animationDatas); CC_SAFE_DELETE(_armarureDatas); @@ -97,10 +111,45 @@ bool ArmatureDataManager::init() return bRet; } -void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData) +void ArmatureDataManager::removeArmatureFileInfo(const char *configFilePath) +{ + if (RelativeData *data = getRelativeData(configFilePath)) + { + for (std::vector::iterator i = data->armatures.begin(); i != data->armatures.end(); i++) + { + removeArmatureData(i->c_str()); + } + + for (std::vector::iterator i = data->animations.begin(); i != data->animations.end(); i++) + { + removeAnimationData(i->c_str()); + } + + for (std::vector::iterator i = data->textures.begin(); i != data->textures.end(); i++) + { + removeTextureData(i->c_str()); + } + + for (std::vector::iterator i = data->plistFiles.begin(); i != data->plistFiles.end(); i++) + { + SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(i->c_str()); + } + + _relativeDatas.erase(configFilePath); + DataReaderHelper::sharedDataReaderHelper()->removeConfigFile(configFilePath); + } +} + + +void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData, const char *configFilePath) { if(_armarureDatas) { + if (RelativeData *data = getRelativeData(configFilePath)) + { + data->armatures.push_back(id); + } + _armarureDatas->setObject(armatureData, id); } } @@ -123,10 +172,15 @@ void ArmatureDataManager::removeArmatureData(const char *id) } } -void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData) +void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData, const char *configFilePath) { if(_animationDatas) { + if (RelativeData *data = getRelativeData(configFilePath)) + { + data->animations.push_back(id); + } + _animationDatas->setObject(animationData, id); } } @@ -149,10 +203,15 @@ void ArmatureDataManager::removeAnimationData(const char *id) } } -void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData) +void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData, const char *configFilePath) { if(_textureDatas) { + if (RelativeData *data = getRelativeData(configFilePath)) + { + data->textures.push_back(id); + } + _textureDatas->setObject(textureData, id); } } @@ -179,18 +238,24 @@ void ArmatureDataManager::removeTextureData(const char *id) void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath) { + addRelativeData(configFilePath); + _autoLoadSpriteFile = true; DataReaderHelper::getInstance()->addDataFromFile(configFilePath); } void ArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector) { + addRelativeData(configFilePath); + _autoLoadSpriteFile = true; DataReaderHelper::getInstance()->addDataFromFileAsync("", "", configFilePath, target, selector); } void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) { + addRelativeData(configFilePath); + _autoLoadSpriteFile = false; DataReaderHelper::getInstance()->addDataFromFile(configFilePath); addSpriteFrameFromFile(plistPath, imagePath); @@ -198,36 +263,23 @@ void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char void ArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector) { + addRelativeData(configFilePath); + _autoLoadSpriteFile = false; DataReaderHelper::getInstance()->addDataFromFileAsync(imagePath, plistPath, configFilePath, target, selector); addSpriteFrameFromFile(plistPath, imagePath); } -void ArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) +void ArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath, const char *configFilePath) { + if (RelativeData *data = getRelativeData(configFilePath)) + { + data->plistFiles.push_back(plistPath); + } SpriteFrameCacheHelper::getInstance()->addSpriteFrameFromFile(plistPath, imagePath); } -void ArmatureDataManager::removeAll() -{ - if( _animationDatas ) - { - _animationDatas->removeAllObjects(); - } - if( _armarureDatas ) - { - _armarureDatas->removeAllObjects(); - } - - if( _textureDatas ) - { - _textureDatas->removeAllObjects(); - } - - DataReaderHelper::clear(); -} - bool ArmatureDataManager::isAutoLoadSpriteFile() { return _autoLoadSpriteFile; @@ -246,4 +298,17 @@ Dictionary *ArmatureDataManager::getTextureDatas() const return _textureDatas; } +void CCArmatureDataManager::addRelativeData(const char *configFilePath) +{ + if (_relativeDatas.find(configFilePath) == _relativeDatas.end()) + { + _relativeDatas[configFilePath] = RelativeData(); + } +} + +RelativeData *CCArmatureDataManager::getRelativeData(const char* configFilePath) +{ + return &_relativeDatas[configFilePath]; +} + } diff --git a/cocos/editor-support/cocostudio/CCArmatureDataManager.h b/cocos/editor-support/cocostudio/CCArmatureDataManager.h index 1bd426784d..b73dc99ef9 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDataManager.h +++ b/cocos/editor-support/cocostudio/CCArmatureDataManager.h @@ -31,6 +31,14 @@ THE SOFTWARE. namespace cocostudio { +struct RelativeData +{ + std::vector plistFiles; + std::vector armatures; + std::vector animations; + std::vector textures; +}; + /** * @brief format and manage armature configuration and armature animation */ @@ -69,7 +77,7 @@ public: * @param id The id of the armature data * @param armatureData ArmatureData * */ - void addArmatureData(const char *id, ArmatureData *armatureData); + void addArmatureData(const char *id, ArmatureData *armatureData, const char *configFilePath = ""); /** * @brief get armature data @@ -89,7 +97,7 @@ public: * @param id the id of the animation data * @return AnimationData * */ - void addAnimationData(const char *id, AnimationData *animationData); + void addAnimationData(const char *id, AnimationData *animationData, const char *configFilePath = ""); /** * @brief get animation data from _animationDatas(Dictionary) @@ -109,7 +117,7 @@ public: * @param id the id of the texture data * @return TextureData * */ - void addTextureData(const char *id, TextureData *textureData); + void addTextureData(const char *id, TextureData *textureData, const char *configFilePath = ""); /** * @brief get texture data @@ -149,13 +157,10 @@ public: /** * @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name */ - void addSpriteFrameFromFile(const char *plistPath, const char *imagePath); + void addSpriteFrameFromFile(const char *plistPath, const char *imagePath, const char *configFilePath = ""); + virtual void removeArmatureFileInfo(const char *configFilePath); - /** - * @brief Clear the data in the _armarureDatas and _animationDatas, and set _armarureDatas and _animationDatas to NULL - */ - void removeAll(); /** * @brief Juge whether or not need auto load sprite file @@ -166,6 +171,10 @@ public: cocos2d::Dictionary *getArmatureDatas() const; cocos2d::Dictionary *getAnimationDatas() const; cocos2d::Dictionary *getTextureDatas() const; + +protected: + void addRelativeData(const char* configFilePath); + RelativeData *getRelativeData(const char* configFilePath); private: /** * @brief save amature datas @@ -189,6 +198,8 @@ private: cocos2d::Dictionary *_textureDatas; bool _autoLoadSpriteFile; + + std::map _relativeDatas; }; diff --git a/cocos/editor-support/cocostudio/CCArmatureDefine.h b/cocos/editor-support/cocostudio/CCArmatureDefine.h index 8b7cb42312..b3fca84e01 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDefine.h +++ b/cocos/editor-support/cocostudio/CCArmatureDefine.h @@ -44,6 +44,10 @@ THE SOFTWARE. #define ENABLE_PHYSICS_CHIPMUNK_DETECT 1 #endif +#ifndef ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX +#define ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX 0 +#endif + #define CS_RETURN_IF(cond) if (cond) return #define CS_RETURN_NULL_IF(cond) if (cond) return NULL; diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.cpp b/cocos/editor-support/cocostudio/CCColliderDetector.cpp index 341bf503e6..8857832c99 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.cpp +++ b/cocos/editor-support/cocostudio/CCColliderDetector.cpp @@ -44,6 +44,11 @@ ColliderBody::ColliderBody(ContourData *contourData) , _contourData(contourData) { CC_SAFE_RETAIN(_contourData); + +#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX + _calculatedVertexList = Array::create(); + CC_SAFE_RETAIN(_calculatedVertexList); +#endif } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT @@ -52,6 +57,11 @@ ColliderBody::ColliderBody(ContourData *contourData) , _contourData(contourData) { CC_SAFE_RETAIN(_contourData); + +#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX + _calculatedVertexList = Array::create(); + CC_SAFE_RETAIN(_calculatedVertexList); +#endif } #endif @@ -59,6 +69,10 @@ ColliderBody::~ColliderBody() { CC_SAFE_RELEASE(_contourData); +#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX + CC_SAFE_RELEASE(_calculatedVertexList); +#endif + #if ENABLE_PHYSICS_BOX2D_DETECT CC_SAFE_DELETE(_filter); #endif @@ -125,6 +139,19 @@ void ColliderDetector::addContourData(ContourData *contourData) ColliderBody *colliderBody = new ColliderBody(contourData); _colliderBodyList->addObject(colliderBody); colliderBody->release(); + + +#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX + CCArray *calculatedVertexList = colliderBody->getCalculatedVertexList(); + + int num = contourData->vertexList.count(); + for (int i = 0; i < num; i++) + { + ContourVertex2 *newVertex = new ContourVertex2(0, 0); + calculatedVertexList->addObject(newVertex); + newVertex->release(); + } +#endif } void ColliderDetector::addContourDataList(Array *contourDataList) @@ -262,12 +289,21 @@ void ColliderDetector::updateTransform(AffineTransform &t) int num = contourData->vertexList.count(); ContourVertex2 **vs = (ContourVertex2 **)contourData->vertexList.data->arr; +#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX + ContourVertex2 **cvs = (ContourVertex2 **)colliderBody->getCalculatedVertexList()->data->arr; +#endif + for (int i = 0; i < num; i++) { helpPoint.setPoint( vs[i]->x, vs[i]->y); helpPoint = PointApplyAffineTransform(helpPoint, t); +#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX + cvs[i]->x = helpPoint.x; + cvs[i]->y = helpPoint.y; +#endif + #if ENABLE_PHYSICS_BOX2D_DETECT if (shape != NULL) { diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.h b/cocos/editor-support/cocostudio/CCColliderDetector.h index 4f6fbeebfe..9e8b7246c6 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.h +++ b/cocos/editor-support/cocostudio/CCColliderDetector.h @@ -65,6 +65,10 @@ public: } private: ContourData *_contourData; + +#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX + CC_SYNTHESIZE_READONLY(CCArray *, _calculatedVertexList, CalculatedVertexList); +#endif }; /* diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 3fb1b69fb8..c64a469c71 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -138,13 +138,14 @@ static const char *CONTENT_SCALE = "content_scale"; namespace cocostudio { -std::vector s_arrConfigFileList; + float s_PositionReadScale = 1; float s_ContentScale = 1; static float s_FlashToolVersion = VERSION_2_0; static float s_CocoStudioVersion = VERSION_COMBINED; -static std::string s_BasefilePath = ""; +std::vector DataReaderHelper::_configFileList; +std::string DataReaderHelper::_basefilePath = ""; DataReaderHelper *DataReaderHelper::_dataReaderHelper = NULL; @@ -184,7 +185,7 @@ void DataReaderHelper::loadData() _asyncStructQueueMutex.unlock(); } - // generate image info + // generate data info DataInfo *pDataInfo = new DataInfo(); pDataInfo->asyncStruct = pAsyncStruct; @@ -236,14 +237,10 @@ float DataReaderHelper::getPositionReadScale() void DataReaderHelper::purge() { - DataReaderHelper::clear(); + _configFileList.clear(); CC_SAFE_RELEASE_NULL(_dataReaderHelper); } -void DataReaderHelper::clear() -{ - s_arrConfigFileList.clear(); -} DataReaderHelper::DataReaderHelper() : _loadingThread(nullptr) @@ -272,26 +269,26 @@ void DataReaderHelper::addDataFromFile(const char *filePath) /* * Check if file is already added to ArmatureDataManager, if then return. */ - for(unsigned int i = 0; i < s_arrConfigFileList.size(); i++) + for(unsigned int i = 0; i < _configFileList.size(); i++) { - if (s_arrConfigFileList[i].compare(filePath) == 0) + if (_configFileList[i].compare(filePath) == 0) { return; } } - s_arrConfigFileList.push_back(filePath); + _configFileList.push_back(filePath); //! find the base file path - s_BasefilePath = filePath; - size_t pos = s_BasefilePath.find_last_of("/"); + _basefilePath = filePath; + size_t pos = _basefilePath.find_last_of("/"); if (pos != std::string::npos) { - s_BasefilePath = s_BasefilePath.substr(0, pos + 1); + _basefilePath = _basefilePath.substr(0, pos + 1); } else { - s_BasefilePath = ""; + _basefilePath = ""; } @@ -303,13 +300,17 @@ void DataReaderHelper::addDataFromFile(const char *filePath) std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); const char *pFileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); + DataInfo dataInfo; + dataInfo.filename = filePathStr; + dataInfo.asyncStruct = NULL; + if (str.compare(".xml") == 0) { - DataReaderHelper::addDataFromCache(pFileContent); + DataReaderHelper::addDataFromCache(pFileContent, &dataInfo); } else if(str.compare(".json") == 0 || str.compare(".ExportJson") == 0) { - DataReaderHelper::addDataFromJsonCache(pFileContent); + DataReaderHelper::addDataFromJsonCache(pFileContent, &dataInfo); } } @@ -318,9 +319,9 @@ void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *p /* * Check if file is already added to ArmatureDataManager, if then return. */ - for(unsigned int i = 0; i < s_arrConfigFileList.size(); i++) + for(unsigned int i = 0; i < _configFileList.size(); i++) { - if (s_arrConfigFileList[i].compare(filePath) == 0) + if (_configFileList[i].compare(filePath) == 0) { if (target && selector) { @@ -336,7 +337,7 @@ void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *p return; } } - s_arrConfigFileList.push_back(filePath); + _configFileList.push_back(filePath); //! find the base file path std::string basefilePath = filePath; @@ -474,7 +475,22 @@ void DataReaderHelper::addDataAsyncCallBack(float dt) } +void DataReaderHelper::removeConfigFile(const char *configFile) +{ + std::vector::iterator it = _configFileList.end(); + for (std::vector::iterator i = _configFileList.begin(); i != _configFileList.end(); i++) + { + if (*i == configFile) + { + it = i; + } + } + if (it != _configFileList.end()) + { + _configFileList.erase(it); + } +} @@ -498,13 +514,13 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data { ArmatureData *armatureData = DataReaderHelper::decodeArmature(armatureXML); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.lock(); } - ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData); + ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData, dataInfo->filename.c_str()); armatureData->release(); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.unlock(); } @@ -521,13 +537,13 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data while(animationXML) { AnimationData *animationData = DataReaderHelper::decodeAnimation(animationXML); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.lock(); } - ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData); + ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData, dataInfo->filename.c_str()); animationData->release(); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.unlock(); } @@ -544,13 +560,13 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data { TextureData *textureData = DataReaderHelper::decodeTexture(textureXML); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.lock(); } - ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData); + ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData, dataInfo->filename.c_str()); textureData->release(); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.unlock(); } @@ -1137,7 +1153,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d JsonDictionary json; json.initWithDescription(fileContent); - if (dataInfo) + if (dataInfo->asyncStruct) { dataInfo->contentScale = json.getItemFloatValue(CONTENT_SCALE, 1); } @@ -1153,13 +1169,13 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d JsonDictionary *armatureDic = json.getSubItemFromArray(ARMATURE_DATA, i); ArmatureData *armatureData = decodeArmature(*armatureDic, dataInfo); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.lock(); } ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData); armatureData->release(); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.unlock(); } @@ -1173,13 +1189,13 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d JsonDictionary *animationDic = json.getSubItemFromArray(ANIMATION_DATA, i); AnimationData *animationData = decodeAnimation(*animationDic, dataInfo); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.lock(); } ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData); animationData->release(); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.unlock(); } @@ -1193,13 +1209,13 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d JsonDictionary *textureDic = json.getSubItemFromArray(TEXTURE_DATA, i); TextureData *textureData = decodeTexture(*textureDic); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.lock(); } ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData); textureData->release(); - if (dataInfo) + if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.unlock(); } @@ -1207,7 +1223,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d } // Auto load sprite file - bool autoLoad = dataInfo == NULL ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; + bool autoLoad = dataInfo->asyncStruct == NULL ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; if (autoLoad) { length = json.getArrayItemCount(CONFIG_FILE_PATH); @@ -1223,7 +1239,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d std::string filePath = path; filePath = filePath.erase(filePath.find_last_of(".")); - if (dataInfo != NULL) + if (dataInfo->asyncStruct) { dataInfo->configFileQueue.push(filePath); } @@ -1232,7 +1248,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d std::string plistPath = filePath + ".plist"; std::string pngPath = filePath + ".png"; - ArmatureDataManager::getInstance()->addSpriteFrameFromFile((s_BasefilePath + plistPath).c_str(), (s_BasefilePath + pngPath).c_str()); + ArmatureDataManager::getInstance()->addSpriteFrameFromFile((_basefilePath + plistPath).c_str(), (_basefilePath + pngPath).c_str()); } } } @@ -1328,7 +1344,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo sdd->skinData.skewX = dic->getItemFloatValue(A_SKEW_X, 0); sdd->skinData.skewY = dic->getItemFloatValue(A_SKEW_Y, 0); - if (dataInfo) + if (dataInfo->asyncStruct) { sdd->skinData.x *= dataInfo->contentScale; sdd->skinData.y *= dataInfo->contentScale; @@ -1362,13 +1378,13 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo const char *plist = json.getItemStringValue(A_PLIST); if(plist != NULL) { - if (dataInfo != NULL) + if (dataInfo->asyncStruct) { static_cast(displayData)->plist = dataInfo->asyncStruct->baseFilePath + plist; } else { - static_cast(displayData)->plist = s_BasefilePath + plist; + static_cast(displayData)->plist = _basefilePath + plist; } } } @@ -1601,7 +1617,7 @@ void DataReaderHelper::decodeNode(BaseData *node, JsonDictionary &json, DataInfo node->x = json.getItemFloatValue(A_X, 0) * s_PositionReadScale; node->y = json.getItemFloatValue(A_Y, 0) * s_PositionReadScale; - if (dataInfo) + if (dataInfo->asyncStruct) { node->x *= dataInfo->contentScale; node->y *= dataInfo->contentScale; diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.h b/cocos/editor-support/cocostudio/CCDataReaderHelper.h index a9159ef39e..c2df44b512 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.h +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.h @@ -73,6 +73,7 @@ protected: AsyncStruct *asyncStruct; std::queue configFileQueue; float contentScale; + std::string filename; } DataInfo; public: @@ -90,7 +91,6 @@ public: static float getPositionReadScale(); static void purge(); - static void clear(); public: /** * @js ctor @@ -107,6 +107,7 @@ public: void addDataAsyncCallBack(float dt); + void removeConfigFile(const char *configFile); public: /** @@ -192,6 +193,8 @@ protected: std::queue *_asyncStructQueue; std::queue *_dataQueue; + static std::string _basefilePath; + static std::vector _configFileList; static DataReaderHelper *_dataReaderHelper; }; diff --git a/cocos/editor-support/cocostudio/CCTween.cpp b/cocos/editor-support/cocostudio/CCTween.cpp index 5704867a61..77f9a3b2ff 100644 --- a/cocos/editor-support/cocostudio/CCTween.cpp +++ b/cocos/editor-support/cocostudio/CCTween.cpp @@ -61,6 +61,7 @@ Tween::Tween() , _fromIndex(0) , _toIndex(0) , _animation(NULL) + , _passLastFrame(false) { } @@ -408,7 +409,6 @@ float Tween::updateFrameData(float currentPercent) FrameData *from = NULL; FrameData *to = NULL; - bool passLastFrame = false; if (playedTime < frames[0]->frameID) { @@ -416,9 +416,19 @@ float Tween::updateFrameData(float currentPercent) setBetween(from, to); return currentPercent; } - else if(playedTime >= frames[length - 1]->frameID) + + if(playedTime >= frames[length - 1]->frameID) { - passLastFrame = true; + // If _passLastFrame is true and playedTime >= frames[length - 1]->frameID, then do not need to go on. + if (_passLastFrame) + { + return _currentPercent; + } + _passLastFrame = true; + } + else + { + _passLastFrame = false; } @@ -442,7 +452,7 @@ float Tween::updateFrameData(float currentPercent) _animation->frameEvent(_bone, from->strEvent.c_str(), from->frameID, playedTime); } - if (playedTime == from->frameID || (passLastFrame && _fromIndex == length-1)) + if (playedTime == from->frameID || (_passLastFrame && _fromIndex == length-1)) { break; } diff --git a/cocos/editor-support/cocostudio/CCTween.h b/cocos/editor-support/cocostudio/CCTween.h index 5e5bea6356..61213371e8 100644 --- a/cocos/editor-support/cocostudio/CCTween.h +++ b/cocos/editor-support/cocostudio/CCTween.h @@ -123,25 +123,26 @@ protected: //! A weak reference to the current MovementBoneData. The data is in the data pool CC_SYNTHESIZE(MovementBoneData *, _movementBoneData, MovementBoneData) - FrameData *_tweenData; //! The computational tween frame data, //! A weak reference to the Bone's tweenData - FrameData *_from; //! From frame data, used for calculate between value - FrameData *_to; //! To frame data, used for calculate between value - FrameData *_between; //! Between frame data, used for calculate current FrameData(m_pNode) value + FrameData *_tweenData; //! The computational tween frame data, //! A weak reference to the Bone's tweenData + FrameData *_from; //! From frame data, used for calculate between value + FrameData *_to; //! To frame data, used for calculate between value + FrameData *_between; //! Between frame data, used for calculate current FrameData(m_pNode) value - Bone *_bone; //! A weak reference to the Bone + Bone *_bone; //! A weak reference to the Bone - CCTweenType _frameTweenEasing; //! Dedermine which tween effect current frame use + CCTweenType _frameTweenEasing; //! Dedermine which tween effect current frame use - int _betweenDuration; //! Current key frame will last _betweenDuration frames + int _betweenDuration; //! Current key frame will last _betweenDuration frames int _totalDuration; - int _fromIndex; //! The current frame index in FrameList of MovementBoneData, it's different from m_iFrameIndex - int _toIndex; //! The next frame index in FrameList of MovementBoneData, it's different from m_iFrameIndex + int _fromIndex; //! The current frame index in FrameList of MovementBoneData, it's different from m_iFrameIndex + int _toIndex; //! The next frame index in FrameList of MovementBoneData, it's different from m_iFrameIndex ArmatureAnimation *_animation; + bool _passLastFrame; //! If current frame index is more than the last frame's index }; } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 625308dd01..35db4c129b 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -21,6 +21,9 @@ Layer *CreateLayer(int index) case TEST_ASYNCHRONOUS_LOADING: pLayer = new TestAsynchronousLoading(); break; + case TEST_DIRECT_LOADING: + pLayer = new TestDirectLoading(); + break; case TEST_DRAGON_BONES_2_0: pLayer = new TestDragonBones20(); break; @@ -39,6 +42,9 @@ Layer *CreateLayer(int index) case TEST_ANIMATION_EVENT: pLayer = new TestAnimationEvent(); break; + case TEST_FRAME_EVENT: + pLayer = new TestFrameEvent(); + break; case TEST_PARTICLE_DISPLAY: pLayer = new TestParticleDisplay(); break; @@ -244,6 +250,7 @@ void TestAsynchronousLoading::onEnter() ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/hero.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/horse.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/bear.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/HeroAnimation.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); //! load data directly // ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); @@ -263,6 +270,12 @@ std::string TestAsynchronousLoading::subtitle() { return "current percent : "; } + +void TestAsynchronousLoading::restartCallback(CCObject* pSender) +{ + ArmatureDataManager::getInstance()->purge(); + ArmatureTestLayer::restartCallback(pSender); +} void TestAsynchronousLoading::dataLoaded(float percent) { LabelTTF *label = (LabelTTF *)getChildByTag(10001); @@ -282,6 +295,26 @@ void TestAsynchronousLoading::dataLoaded(float percent) } +void TestDirectLoading::onEnter() +{ + ArmatureTestLayer::onEnter(); + + // remove sigle resource + ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/bear.ExportJson"); + + // load resource directly + ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/bear.ExportJson"); + + Armature *armature = Armature::create("bear"); + armature->getAnimation()->playByIndex(0); + armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y)); + addChild(armature); +} +std::string TestDirectLoading::title() +{ + return "Test Direct Loading"; +} + void TestCSWithSkeleton::onEnter() { @@ -535,6 +568,51 @@ void TestAnimationEvent::callback2() +#define FRAME_EVENT_ACTION_TAG 10000 + +void TestFrameEvent::onEnter() +{ + ArmatureTestLayer::onEnter(); + Armature *armature = Armature::create("HeroAnimation"); + armature->getAnimation()->play("attack"); + armature->getAnimation()->setSpeedScale(0.5); + armature->setPosition(Point(VisibleRect::center().x - 50, VisibleRect::center().y -100)); + + /* + * Set armature's frame event callback function + * To disconnect this event, just setFrameEventCallFunc(NULL, NULL); + */ + armature->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(TestFrameEvent::onFrameEvent)); + + addChild(armature); + + schedule( schedule_selector(TestFrameEvent::checkAction) ); +} +std::string TestFrameEvent::title() +{ + return "Test Frame Event"; +} +void TestFrameEvent::onFrameEvent(Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex) +{ + CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt, currentFrameIndex); + + + if (!this->getActionByTag(FRAME_EVENT_ACTION_TAG) || this->getActionByTag(FRAME_EVENT_ACTION_TAG)->isDone()) + { + this->stopAllActions(); + + ActionInterval *action = ShatteredTiles3D::create(0.2f, Size(16,12), 5, false); + action->setTag(FRAME_EVENT_ACTION_TAG); + this->runAction(action); + } +} +void TestFrameEvent::checkAction(float dt) +{ + if ( this->numberOfRunningActions() == 0 && this->getGrid() != NULL) + this->setGrid(NULL); +} + + void TestParticleDisplay::onEnter() { @@ -926,7 +1004,7 @@ void TestColliderDetector::initWorld() bullet->setCPBody(body); - body = cpBodyNew(INFINITY, INFINITY); + body = cpBodyNew(1.0f, INFINITY); cpSpaceAddBody(space, body); armature2->setBody(body); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index f5a7787168..f8429fc595 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -27,12 +27,14 @@ public: enum { TEST_ASYNCHRONOUS_LOADING = 0, + TEST_DIRECT_LOADING, TEST_COCOSTUDIO_WITH_SKELETON, TEST_DRAGON_BONES_2_0, TEST_PERFORMANCE, TEST_PERFORMANCE_BATCHNODE, TEST_CHANGE_ZORDER, TEST_ANIMATION_EVENT, + TEST_FRAME_EVENT, TEST_PARTICLE_DISPLAY, TEST_USE_DIFFERENT_PICTURE, TEST_BCOLLIDER_DETECTOR, @@ -72,10 +74,18 @@ public: virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); + virtual void restartCallback(CCObject* pSender); void dataLoaded(float percent); }; +class TestDirectLoading : public ArmatureTestLayer +{ +public: + virtual void onEnter(); + virtual std::string title(); +}; + class TestCSWithSkeleton : public ArmatureTestLayer { virtual void onEnter(); @@ -147,6 +157,17 @@ public: cocostudio::Armature *armature; }; + +class TestFrameEvent : public ArmatureTestLayer +{ +public: + virtual void onEnter(); + virtual std::string title(); + void onFrameEvent(cocostudio::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); + void checkAction(float dt); +}; + + class TestUseMutiplePicture : public ArmatureTestLayer { virtual void onEnter(); From 4eaaaddc3405cef7d3274a8af7b530abd1b52193 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Thu, 31 Oct 2013 17:29:03 +0800 Subject: [PATCH 11/39] upload resource --- .../Resources/armature/HeroAnimation.ExportJson.REMOVED.git-id | 1 + .../Resources/hd/armature/HeroAnimation0.png.REMOVED.git-id | 1 + 2 files changed, 2 insertions(+) create mode 100644 samples/Cpp/TestCpp/Resources/armature/HeroAnimation.ExportJson.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/hd/armature/HeroAnimation0.png.REMOVED.git-id diff --git a/samples/Cpp/TestCpp/Resources/armature/HeroAnimation.ExportJson.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/armature/HeroAnimation.ExportJson.REMOVED.git-id new file mode 100644 index 0000000000..43ba518703 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/armature/HeroAnimation.ExportJson.REMOVED.git-id @@ -0,0 +1 @@ +d73c3774258671e491d1579a4991bba7c4b4c24c \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/armature/HeroAnimation0.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/armature/HeroAnimation0.png.REMOVED.git-id new file mode 100644 index 0000000000..f92a9b8f72 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/armature/HeroAnimation0.png.REMOVED.git-id @@ -0,0 +1 @@ +ac19b290421fc75a284f603891442ab9796c132a \ No newline at end of file From a9054ba14abd41c836d3f8de177ede612e2d0fb7 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Fri, 1 Nov 2013 14:36:44 +0800 Subject: [PATCH 12/39] 1.add method to set collider filter --- .../editor-support/cocostudio/CCArmature.cpp | 10 ++ cocos/editor-support/cocostudio/CCArmature.h | 2 + cocos/editor-support/cocostudio/CCBone.cpp | 27 +++++ cocos/editor-support/cocostudio/CCBone.h | 2 + .../cocostudio/CCColliderDetector.cpp | 98 +++++++++++++++---- .../cocostudio/CCColliderDetector.h | 47 +++++++-- .../CocoStudioArmatureTest/ArmatureScene.cpp | 8 +- 7 files changed, 161 insertions(+), 33 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index ac04de1af5..baa56ddfb7 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -728,6 +728,16 @@ Bone *Armature::getParentBone() return _parentBone; } +void CCArmature::setColliderFilter(ColliderFilter *filter) +{ + DictElement *element = NULL; + CCDICT_FOREACH(_boneDic, element) + { + Bone *bone = static_cast(element->getObject()); + bone->setColliderFilter(filter); + } +} + #if ENABLE_PHYSICS_BOX2D_DETECT b2Body *Armature::getBody() { diff --git a/cocos/editor-support/cocostudio/CCArmature.h b/cocos/editor-support/cocostudio/CCArmature.h index 15abe96079..bf11841f7e 100644 --- a/cocos/editor-support/cocostudio/CCArmature.h +++ b/cocos/editor-support/cocostudio/CCArmature.h @@ -175,6 +175,8 @@ public: virtual cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture); + virtual void setColliderFilter(ColliderFilter *filter); + #if ENABLE_PHYSICS_BOX2D_DETECT virtual b2Fixture *getShapeList(); #elif ENABLE_PHYSICS_CHIPMUNK_DETECT diff --git a/cocos/editor-support/cocostudio/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index 804ea5d65a..3132acec79 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -441,4 +441,31 @@ Array *Bone::getColliderBodyList() } + +void Bone::setColliderFilter(ColliderFilter *filter) +{ + Array *array = _displayManager->getDecorativeDisplayList(); + Object *object = NULL; + CCARRAY_FOREACH(array, object) + { + DecorativeDisplay *decoDisplay = static_cast(object); + if (ColliderDetector *detector = decoDisplay->getColliderDetector()) + { + detector->setColliderFilter(filter); + } + } +} +ColliderFilter *Bone::getColliderFilter() +{ + if (DecorativeDisplay *decoDisplay = _displayManager->getCurrentDecorativeDisplay()) + { + if (ColliderDetector *detector = decoDisplay->getColliderDetector()) + { + return detector->getColliderFilter(); + } + } + return NULL; +} + + } diff --git a/cocos/editor-support/cocostudio/CCBone.h b/cocos/editor-support/cocostudio/CCBone.h index 1a1d3c26d6..6edd3fe8cb 100644 --- a/cocos/editor-support/cocostudio/CCBone.h +++ b/cocos/editor-support/cocostudio/CCBone.h @@ -159,6 +159,8 @@ public: */ virtual cocos2d::Array *getColliderBodyList(); + virtual void setColliderFilter(ColliderFilter *filter); + virtual ColliderFilter *getColliderFilter(); public: /* * The origin state of the Bone. Display's state is effected by _boneData, m_pNode, _tweenData diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.cpp b/cocos/editor-support/cocostudio/CCColliderDetector.cpp index 8857832c99..cceb1a9b72 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.cpp +++ b/cocos/editor-support/cocostudio/CCColliderDetector.cpp @@ -37,13 +37,44 @@ using namespace cocos2d; namespace cocostudio { +#if ENABLE_PHYSICS_BOX2D_DETECT +ColliderFilter::ColliderFilter(unsigned short categoryBits, unsigned short maskBits, signed short groupIndex) + : _categoryBits(categoryBits) + , _maskBits(maskBits) + , _groupIndex(groupIndex) +{ +} + +void ColliderFilter::updateShape(b2Fixture *fixture) +{ + b2Filter filter; + filter.categoryBits = _categoryBits; + filter.groupIndex = _groupIndex; + filter.maskBits = _maskBits; + + fixture->SetFilterData(filter); +} + +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +ColliderFilter::ColliderFilter(cpCollisionType collisionType, cpGroup group) + : _collisionType(collisionType) + , _group(group) +{ +} +void ColliderFilter::updateShape(cpShape *shape) +{ + shape->collision_type = _collisionType; + shape->group = _group; +} +#endif + #if ENABLE_PHYSICS_BOX2D_DETECT ColliderBody::ColliderBody(ContourData *contourData) : _fixture(NULL) - , _filter(NULL) , _contourData(contourData) { CC_SAFE_RETAIN(_contourData); + _filter = new ColliderFilter(); #if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX _calculatedVertexList = Array::create(); @@ -57,6 +88,7 @@ ColliderBody::ColliderBody(ContourData *contourData) , _contourData(contourData) { CC_SAFE_RETAIN(_contourData); + _filter = new ColliderFilter(); #if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX _calculatedVertexList = Array::create(); @@ -68,14 +100,20 @@ ColliderBody::ColliderBody(ContourData *contourData) ColliderBody::~ColliderBody() { CC_SAFE_RELEASE(_contourData); + CC_SAFE_DELETE(_filter); #if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX CC_SAFE_RELEASE(_calculatedVertexList); #endif +} -#if ENABLE_PHYSICS_BOX2D_DETECT - CC_SAFE_DELETE(_filter); -#endif +void ColliderBody::setColliderFilter(ColliderFilter *filter) +{ + *_filter = *filter; +} +ColliderFilter *ColliderBody::getColliderFilter() +{ + return _filter; } @@ -106,6 +144,7 @@ ColliderDetector *ColliderDetector::create(Bone *bone) ColliderDetector::ColliderDetector() : _colliderBodyList(NULL) + , _filter(NULL) , _active(false) { _body = NULL; @@ -115,6 +154,7 @@ ColliderDetector::~ColliderDetector() { _colliderBodyList->removeAllObjects(); CC_SAFE_DELETE(_colliderBodyList); + CC_SAFE_DELETE(_filter); } bool ColliderDetector::init() @@ -123,6 +163,8 @@ bool ColliderDetector::init() CCASSERT(_colliderBodyList, "create _colliderBodyList failed!"); _colliderBodyList->retain(); + _filter = new ColliderFilter(); + return true; } @@ -206,9 +248,6 @@ void ColliderDetector::setActive(bool active) ColliderBody *colliderBody = (ColliderBody *)object; b2Fixture *fixture = colliderBody->getB2Fixture(); - b2Filter *filter = colliderBody->getB2Filter(); - *filter = fixture->GetFilterData(); - _body->DestroyFixture(fixture); colliderBody->setB2Fixture(NULL); } @@ -256,6 +295,34 @@ Array *ColliderDetector::getColliderBodyList() return _colliderBodyList; } +void ColliderDetector::setColliderFilter(ColliderFilter *filter) +{ + *_filter = *filter; + + Object *object = NULL; + CCARRAY_FOREACH(_colliderBodyList, object) + { + ColliderBody *colliderBody = (ColliderBody *)object; + colliderBody->setColliderFilter(filter); + +#if ENABLE_PHYSICS_BOX2D_DETECT + if (colliderBody->getB2Fixture()) + { + colliderBody->getColliderFilter()->updateShape(colliderBody->getB2Fixture()); + } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + if (colliderBody->getShape()) + { + colliderBody->getColliderFilter()->updateShape(colliderBody->getShape()); + } +#endif + } +} +ColliderFilter *ColliderDetector::getColliderFilter() +{ + return _filter; +} + Point helpPoint; @@ -378,15 +445,7 @@ void ColliderDetector::setBody(b2Body *pBody) } colliderBody->setB2Fixture(fixture); - if (colliderBody->getB2Filter() == NULL) - { - b2Filter *filter = new b2Filter; - colliderBody->setB2Filter(filter); - } - else - { - fixture->SetFilterData(*colliderBody->getB2Filter()); - } + colliderBody->getColliderFilter()->updateShape(fixture); } } @@ -420,9 +479,14 @@ void ColliderDetector::setBody(cpBody *pBody) shape->sensor = true; shape->data = _bone; - cpSpaceAddShape(_body->space_private, shape); + + if (_active) + { + cpSpaceAddShape(_body->space_private, shape); + } colliderBody->setShape(shape); + colliderBody->getColliderFilter()->updateShape(shape); delete []verts; } diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.h b/cocos/editor-support/cocostudio/CCColliderDetector.h index 9e8b7246c6..e2da724c80 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.h +++ b/cocos/editor-support/cocostudio/CCColliderDetector.h @@ -33,24 +33,48 @@ THE SOFTWARE. #endif +#if ENABLE_PHYSICS_CHIPMUNK_DETECT +#include "chipmunk.h" +struct cpBody; +struct cpShape; +#elif ENABLE_PHYSICS_BOX2D_DETECT class b2Body; class b2Fixture; struct b2Filter; - -struct cpBody; -struct cpShape; +#endif namespace cocostudio { class Bone; + +class ColliderFilter +{ +public: + ~ColliderFilter() { } +#if ENABLE_PHYSICS_BOX2D_DETECT +public: + ColliderFilter(unsigned short categoryBits = 0x0001, unsigned short maskBits = 0xFFFF, signed short groupIndex = 0); + void updateShape(b2Fixture *fixture); +protected: + CC_SYNTHESIZE(unsigned short, _categoryBits, CategoryBits); + CC_SYNTHESIZE(unsigned short, _maskBits, MaskBits); + CC_SYNTHESIZE(signed short, _groupIndex, GroupIndex); +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +public: + ColliderFilter(cpCollisionType collisionType = 0, cpGroup group = 0); + void updateShape(cpShape *shape); +protected: + CC_SYNTHESIZE(cpCollisionType, _collisionType, CollisionType); + CC_SYNTHESIZE(cpGroup, _group, Group); +#endif +}; + class ColliderBody : public cocos2d::Object { public: #if ENABLE_PHYSICS_BOX2D_DETECT CC_SYNTHESIZE(b2Fixture *, _fixture, B2Fixture) - CC_SYNTHESIZE(b2Filter *, _filter, B2Filter) - #elif ENABLE_PHYSICS_CHIPMUNK_DETECT CC_SYNTHESIZE(cpShape *, _shape, Shape) #endif @@ -59,12 +83,13 @@ public: ColliderBody(ContourData *contourData); ~ColliderBody(); - inline ContourData *getContourData() - { - return _contourData; - } + inline ContourData *getContourData() { return _contourData; } + + void setColliderFilter(ColliderFilter *filter); + ColliderFilter *getColliderFilter(); private: ContourData *_contourData; + ColliderFilter *_filter; #if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX CC_SYNTHESIZE_READONLY(CCArray *, _calculatedVertexList, CalculatedVertexList); @@ -106,8 +131,12 @@ public: cocos2d::Array *getColliderBodyList(); + virtual void setColliderFilter(ColliderFilter *filter); + virtual ColliderFilter *getColliderFilter(); protected: cocos2d::Array *_colliderBodyList; + ColliderFilter *_filter; + CC_SYNTHESIZE(Bone *, _bone, Bone); #if ENABLE_PHYSICS_BOX2D_DETECT diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 35db4c129b..a6dfd04092 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -1008,13 +1008,7 @@ void TestColliderDetector::initWorld() cpSpaceAddBody(space, body); armature2->setBody(body); - shape = armature2->getShapeList(); - while(shape) - { - cpShape *next = shape->next_private; - shape->collision_type = eEnemyTag; - shape = next; - } + armature2->setColliderFilter(&ColliderFilter(eEnemyTag)); cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, NULL, NULL, endHit, NULL); } From 25196072f264d6d85d46830c10708b739ded5819 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Tue, 5 Nov 2013 11:57:20 +0800 Subject: [PATCH 13/39] 1. change color json format 2. fix tween easing 3. fix CCBone crate bug --- cocos/editor-support/cocostudio/CCArmature.h | 1 + .../cocostudio/CCArmatureDefine.h | 1 + cocos/editor-support/cocostudio/CCBone.cpp | 16 ++- .../cocostudio/CCDataReaderHelper.cpp | 130 ++++++++---------- .../cocostudio/CCDataReaderHelper.h | 22 +-- cocos/editor-support/cocostudio/CCDatas.h | 4 +- .../cocostudio/CCProcessBase.cpp | 2 +- .../editor-support/cocostudio/CCProcessBase.h | 2 +- cocos/editor-support/cocostudio/CCTween.cpp | 16 +-- cocos/editor-support/cocostudio/CCTween.h | 2 +- .../cocostudio/CCTweenFunction.cpp | 26 ++-- .../cocostudio/CCTweenFunction.h | 7 +- 12 files changed, 108 insertions(+), 121 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmature.h b/cocos/editor-support/cocostudio/CCArmature.h index bf11841f7e..b58591ae19 100644 --- a/cocos/editor-support/cocostudio/CCArmature.h +++ b/cocos/editor-support/cocostudio/CCArmature.h @@ -65,6 +65,7 @@ CC_DEPRECATED_ATTRIBUTE typedef Bone CCBone; CC_DEPRECATED_ATTRIBUTE typedef ArmatureAnimation CCArmatureAnimation; CC_DEPRECATED_ATTRIBUTE typedef Armature CCArmature; CC_DEPRECATED_ATTRIBUTE typedef ArmatureDataManager CCArmatureDataManager; +CC_DEPRECATED_ATTRIBUTE typedef TweenType CCTweenType; class Armature : public cocos2d::NodeRGBA, public cocos2d::BlendProtocol { diff --git a/cocos/editor-support/cocostudio/CCArmatureDefine.h b/cocos/editor-support/cocostudio/CCArmatureDefine.h index b3fca84e01..0691058417 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDefine.h +++ b/cocos/editor-support/cocostudio/CCArmatureDefine.h @@ -30,6 +30,7 @@ THE SOFTWARE. #define VERSION_COMBINED 0.30f #define VERSION_CHANGE_ROTATION_RANGE 1.0f +#define VERSION_COLOR_READING 1.1f #ifndef AUTO_ADD_SPRITE_FRAME_NAME_PREFIX #define AUTO_ADD_SPRITE_FRAME_NAME_PREFIX 0 diff --git a/cocos/editor-support/cocostudio/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index 3132acec79..faf4b0ee94 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -90,10 +90,7 @@ Bone::~Bone(void) CC_SAFE_DELETE(_displayManager); CC_SAFE_DELETE(_worldInfo); - if(_boneData) - { - _boneData->release(); - } + CC_SAFE_RELEASE_NULL(_boneData); CC_SAFE_RELEASE(_childArmature); } @@ -129,6 +126,9 @@ bool Bone::init(const char *name) CC_SAFE_DELETE(_worldInfo); _worldInfo = new BaseData(); + CC_SAFE_DELETE(_boneData); + _boneData = new CCBoneData(); + bRet = true; } while (0); @@ -140,8 +140,12 @@ void Bone::setBoneData(BoneData *boneData) { CCASSERT(NULL != boneData, "_boneData must not be NULL"); - _boneData = boneData; - _boneData->retain(); + if (_boneData != boneData) + { + CC_SAFE_RETAIN(boneData); + CC_SAFE_RELEASE(_boneData); + _boneData = boneData; + } _name = _boneData->name; _ZOrder = _boneData->zOrder; diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index c64a469c71..7ff2117b41 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -140,12 +140,8 @@ namespace cocostudio { float s_PositionReadScale = 1; -float s_ContentScale = 1; -static float s_FlashToolVersion = VERSION_2_0; -static float s_CocoStudioVersion = VERSION_COMBINED; std::vector DataReaderHelper::_configFileList; -std::string DataReaderHelper::_basefilePath = ""; DataReaderHelper *DataReaderHelper::_dataReaderHelper = NULL; @@ -188,6 +184,8 @@ void DataReaderHelper::loadData() // generate data info DataInfo *pDataInfo = new DataInfo(); pDataInfo->asyncStruct = pAsyncStruct; + pDataInfo->filename = pAsyncStruct->filename; + pDataInfo->baseFilePath = pAsyncStruct->baseFilePath; if (pAsyncStruct->configType == DragonBone_XML) { @@ -280,15 +278,16 @@ void DataReaderHelper::addDataFromFile(const char *filePath) //! find the base file path - _basefilePath = filePath; - size_t pos = _basefilePath.find_last_of("/"); + std::string basefilePath = filePath; + size_t pos = basefilePath.find_last_of("/"); + if (pos != std::string::npos) { - _basefilePath = _basefilePath.substr(0, pos + 1); + basefilePath = basefilePath.substr(0, pos + 1); } else { - _basefilePath = ""; + basefilePath = ""; } @@ -303,6 +302,7 @@ void DataReaderHelper::addDataFromFile(const char *filePath) DataInfo dataInfo; dataInfo.filename = filePathStr; dataInfo.asyncStruct = NULL; + dataInfo.baseFilePath = basefilePath; if (str.compare(".xml") == 0) { @@ -502,7 +502,7 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data tinyxml2::XMLElement *root = document.RootElement(); CCASSERT(root, "XML error or XML is empty."); - root->QueryFloatAttribute(VERSION, &s_FlashToolVersion); + root->QueryFloatAttribute(VERSION, &dataInfo->flashToolVersion); /* @@ -512,7 +512,7 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data tinyxml2::XMLElement *armatureXML = armaturesXML->FirstChildElement(ARMATURE); while(armatureXML) { - ArmatureData *armatureData = DataReaderHelper::decodeArmature(armatureXML); + ArmatureData *armatureData = DataReaderHelper::decodeArmature(armatureXML, dataInfo); if (dataInfo->asyncStruct) { @@ -536,7 +536,7 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data tinyxml2::XMLElement *animationXML = animationsXML->FirstChildElement(ANIMATION); while(animationXML) { - AnimationData *animationData = DataReaderHelper::decodeAnimation(animationXML); + AnimationData *animationData = DataReaderHelper::decodeAnimation(animationXML, dataInfo); if (dataInfo->asyncStruct) { _dataReaderHelper->_addDataMutex.lock(); @@ -558,7 +558,7 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data tinyxml2::XMLElement *textureXML = texturesXML->FirstChildElement(SUB_TEXTURE); while(textureXML) { - TextureData *textureData = DataReaderHelper::decodeTexture(textureXML); + TextureData *textureData = DataReaderHelper::decodeTexture(textureXML, dataInfo); if (dataInfo->asyncStruct) { @@ -574,7 +574,7 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data } } -ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML) +ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML, DataInfo *dataInfo) { ArmatureData *armatureData = new ArmatureData(); armatureData->init(); @@ -606,7 +606,7 @@ ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML } } - BoneData *boneData = decodeBone(boneXML, parentXML); + BoneData *boneData = decodeBone(boneXML, parentXML, dataInfo); armatureData->addBoneData(boneData); boneData->release(); @@ -616,7 +616,7 @@ ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML return armatureData; } -BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXml) +BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXml, DataInfo *dataInfo) { BoneData *boneData = new BoneData(); boneData->init(); @@ -634,7 +634,7 @@ BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2:: tinyxml2::XMLElement *displayXML = boneXML->FirstChildElement(DISPLAY); while(displayXML) { - DisplayData *displayData = decodeBoneDisplay(displayXML); + DisplayData *displayData = decodeBoneDisplay(displayXML, dataInfo); boneData->addDisplayData(displayData); displayData->release(); @@ -644,7 +644,7 @@ BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2:: return boneData; } -DisplayData *DataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXML) +DisplayData *DataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXML, DataInfo *dataInfo) { int _isArmature = 0; @@ -687,7 +687,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXM return displayData; } -AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animationXML) +AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animationXML, DataInfo *dataInfo) { AnimationData *aniData = new AnimationData(); @@ -701,7 +701,7 @@ AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animation while( movementXML ) { - MovementData *movementData = decodeMovement(movementXML, armatureData); + MovementData *movementData = decodeMovement(movementXML, armatureData, dataInfo); aniData->addMovement(movementData); movementData->release(); @@ -712,7 +712,7 @@ AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animation return aniData; } -MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, ArmatureData *armatureData) +MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, ArmatureData *armatureData, DataInfo *dataInfo) { MovementData *movementData = new MovementData(); @@ -747,12 +747,12 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML { if( movementXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS) { - movementData->tweenEasing = (CCTweenType)tweenEasing; + movementData->tweenEasing = tweenEasing == 2 ? Sine_EaseInOut : (TweenType)tweenEasing; } } else { - movementData->tweenEasing = TWEEN_EASING_MAX; + movementData->tweenEasing = Linear; } } @@ -788,7 +788,7 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML } } - MovementBoneData *moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData); + MovementBoneData *moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData, dataInfo); movementData->addMovementBoneData(moveBoneData); moveBoneData->release(); @@ -799,7 +799,7 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML } -MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, BoneData *boneData) +MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, BoneData *boneData, DataInfo *dataInfo) { MovementBoneData *movBoneData = new MovementBoneData(); movBoneData->init(); @@ -874,7 +874,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov } } - FrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData); + FrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData, dataInfo); movBoneData->addFrameData(frameData); frameData->release(); @@ -918,7 +918,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov return movBoneData; } -FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, BoneData *boneData) +FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, BoneData *boneData, DataInfo *dataInfo) { float x, y, scale_x, scale_y, skew_x, skew_y = 0; int duration, displayIndex, zOrder, tweenEasing, blendType = 0; @@ -944,7 +944,7 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm - if (s_FlashToolVersion >= VERSION_2_0) + if (dataInfo->flashToolVersion >= VERSION_2_0) { if(frameXML->QueryFloatAttribute(A_COCOS2DX_X, &x) == tinyxml2::XML_SUCCESS) { @@ -1037,12 +1037,12 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm { if( frameXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS) { - frameData->tweenEasing = (CCTweenType)tweenEasing; + frameData->tweenEasing = tweenEasing == 2 ? Sine_EaseInOut : (TweenType)tweenEasing; } } else { - frameData->tweenEasing = TWEEN_EASING_MAX; + frameData->tweenEasing = Linear; } } @@ -1052,7 +1052,7 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm * recalculate frame data from parent frame data, use for translate matrix */ BaseData helpNode; - if (s_FlashToolVersion >= VERSION_2_0) + if (dataInfo->flashToolVersion >= VERSION_2_0) { parentFrameXml->QueryFloatAttribute(A_COCOS2DX_X, &helpNode.x); parentFrameXml->QueryFloatAttribute(A_COCOS2DX_Y, &helpNode.y); @@ -1076,7 +1076,7 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm return frameData; } -TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) +TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML, DataInfo *dataInfo) { TextureData *textureData = new TextureData(); textureData->init(); @@ -1088,7 +1088,7 @@ TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) float px, py, width, height = 0; - if(s_FlashToolVersion >= VERSION_2_0) + if(dataInfo->flashToolVersion >= VERSION_2_0) { textureXML->QueryFloatAttribute(A_COCOS2D_PIVOT_X, &px); textureXML->QueryFloatAttribute(A_COCOS2D_PIVOT_Y, &py); @@ -1112,7 +1112,7 @@ TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) while (contourXML) { - ContourData *contourData = decodeContour(contourXML); + ContourData *contourData = decodeContour(contourXML, dataInfo); textureData->addContourData(contourData); contourData->release(); @@ -1122,7 +1122,7 @@ TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) return textureData; } -ContourData *DataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML) +ContourData *DataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML, DataInfo *dataInfo) { ContourData *contourData = new ContourData(); contourData->init(); @@ -1153,14 +1153,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d JsonDictionary json; json.initWithDescription(fileContent); - if (dataInfo->asyncStruct) - { - dataInfo->contentScale = json.getItemFloatValue(CONTENT_SCALE, 1); - } - else - { - s_ContentScale = json.getItemFloatValue(CONTENT_SCALE, 1); - } + dataInfo->contentScale = json.getItemFloatValue(CONTENT_SCALE, 1); // Decode armatures int length = json.getArrayItemCount(ARMATURE_DATA); @@ -1248,7 +1241,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d std::string plistPath = filePath + ".plist"; std::string pngPath = filePath + ".png"; - ArmatureDataManager::getInstance()->addSpriteFrameFromFile((_basefilePath + plistPath).c_str(), (_basefilePath + pngPath).c_str()); + ArmatureDataManager::getInstance()->addSpriteFrameFromFile((dataInfo->baseFilePath + plistPath).c_str(), (dataInfo->baseFilePath + pngPath).c_str()); } } } @@ -1265,7 +1258,7 @@ ArmatureData *DataReaderHelper::decodeArmature(JsonDictionary &json, DataInfo *d armatureData->name = name; } - s_CocoStudioVersion = armatureData->dataVersion = json.getItemFloatValue(VERSION, 0.1f); + dataInfo->cocoStudioVersion = armatureData->dataVersion = json.getItemFloatValue(VERSION, 0.1f); int length = json.getArrayItemCount(BONE_DATA); for (int i = 0; i < length; i++) @@ -1344,16 +1337,8 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo sdd->skinData.skewX = dic->getItemFloatValue(A_SKEW_X, 0); sdd->skinData.skewY = dic->getItemFloatValue(A_SKEW_Y, 0); - if (dataInfo->asyncStruct) - { - sdd->skinData.x *= dataInfo->contentScale; - sdd->skinData.y *= dataInfo->contentScale; - } - else - { - sdd->skinData.x *= s_ContentScale; - sdd->skinData.y *= s_ContentScale; - } + sdd->skinData.x *= dataInfo->contentScale; + sdd->skinData.y *= dataInfo->contentScale; delete dic; } @@ -1384,7 +1369,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo } else { - static_cast(displayData)->plist = _basefilePath + plist; + static_cast(displayData)->plist = dataInfo->baseFilePath + plist; } } } @@ -1435,7 +1420,7 @@ MovementData *DataReaderHelper::decodeMovement(JsonDictionary &json, DataInfo *d movementData->durationTo = json.getItemIntValue(A_DURATION_TO, 0); movementData->duration = json.getItemIntValue(A_DURATION, 0); movementData->scale = json.getItemFloatValue(A_MOVEMENT_SCALE, 1); - movementData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); + movementData->tweenEasing = (TweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); const char *name = json.getItemStringValue(A_NAME); if(name != NULL) @@ -1479,7 +1464,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json, Dat movementBoneData->addFrameData(frameData); frameData->release(); - if (s_CocoStudioVersion < VERSION_COMBINED) + if (dataInfo->cocoStudioVersion < VERSION_COMBINED) { frameData->frameID = movementBoneData->duration; movementBoneData->duration += frameData->duration; @@ -1489,7 +1474,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json, Dat } - if (s_CocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE) + if (dataInfo->cocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE) { //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) FrameData **frames = (FrameData **)movementBoneData->frameList.data->arr; @@ -1513,7 +1498,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json, Dat } } - if (s_CocoStudioVersion < VERSION_COMBINED) + if (dataInfo->cocoStudioVersion < VERSION_COMBINED) { if (movementBoneData->frameList.count() > 0) { @@ -1535,7 +1520,7 @@ FrameData *DataReaderHelper::decodeFrame(JsonDictionary &json, DataInfo *dataInf decodeNode(frameData, json, dataInfo); - frameData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); + frameData->tweenEasing = (TweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0); frameData->blendType = (BlendType)json.getItemIntValue(A_BLEND_TYPE, 0); frameData->isTween = (bool)json.getItemBoolvalue(A_TWEEN_FRAME, true); @@ -1546,7 +1531,7 @@ FrameData *DataReaderHelper::decodeFrame(JsonDictionary &json, DataInfo *dataInf frameData->strEvent = event; } - if (s_CocoStudioVersion < VERSION_COMBINED) + if (dataInfo->cocoStudioVersion < VERSION_COMBINED) { frameData->duration = json.getItemIntValue(A_DURATION, 1); } @@ -1617,17 +1602,8 @@ void DataReaderHelper::decodeNode(BaseData *node, JsonDictionary &json, DataInfo node->x = json.getItemFloatValue(A_X, 0) * s_PositionReadScale; node->y = json.getItemFloatValue(A_Y, 0) * s_PositionReadScale; - if (dataInfo->asyncStruct) - { - node->x *= dataInfo->contentScale; - node->y *= dataInfo->contentScale; - } - else - { - node->x *= s_ContentScale; - node->y *= s_ContentScale; - } - + node->x *= dataInfo->contentScale; + node->y *= dataInfo->contentScale; node->zOrder = json.getItemIntValue(A_Z, 0); @@ -1636,7 +1612,15 @@ void DataReaderHelper::decodeNode(BaseData *node, JsonDictionary &json, DataInfo node->scaleX = json.getItemFloatValue(A_SCALE_X, 1); node->scaleY = json.getItemFloatValue(A_SCALE_Y, 1); - JsonDictionary *colorDic = json.getSubItemFromArray(COLOR_INFO, 0); + JsonDictionary *colorDic = NULL; + if (dataInfo->cocoStudioVersion < VERSION_COLOR_READING) + { + colorDic = json.getSubItemFromArray(COLOR_INFO, 0); + } + else + { + colorDic = json.getSubDictionary(COLOR_INFO); + } if (colorDic) { diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.h b/cocos/editor-support/cocostudio/CCDataReaderHelper.h index c2df44b512..82f551e52f 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.h +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.h @@ -74,6 +74,9 @@ protected: std::queue configFileQueue; float contentScale; std::string filename; + std::string baseFilePath; + float flashToolVersion; + float cocoStudioVersion; } DataInfo; public: @@ -123,29 +126,29 @@ public: /** * Decode Armature Datas from xml export from Dragon Bone flash tool */ - static ArmatureData *decodeArmature(tinyxml2::XMLElement *armatureXML); - static BoneData *decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXML); - static DisplayData *decodeBoneDisplay(tinyxml2::XMLElement *displayXML); + static ArmatureData *decodeArmature(tinyxml2::XMLElement *armatureXML, DataInfo *dataInfo); + static BoneData *decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXML, DataInfo *dataInfo); + static DisplayData *decodeBoneDisplay(tinyxml2::XMLElement *displayXML, DataInfo *dataInfo); /** * Decode ArmatureAnimation Datas from xml export from Dragon Bone flash tool */ - static AnimationData *decodeAnimation(tinyxml2::XMLElement *animationXML); - static MovementData *decodeMovement(tinyxml2::XMLElement *movementXML, ArmatureData *armatureData); - static MovementBoneData *decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, BoneData *boneData); - static FrameData *decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, BoneData *boneData); + static AnimationData *decodeAnimation(tinyxml2::XMLElement *animationXML, DataInfo *dataInfo); + static MovementData *decodeMovement(tinyxml2::XMLElement *movementXML, ArmatureData *armatureData, DataInfo *dataInfo); + static MovementBoneData *decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, BoneData *boneData, DataInfo *dataInfo); + static FrameData *decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, BoneData *boneData, DataInfo *dataInfo); /** * Decode Texture Datas from xml export from Dragon Bone flash tool */ - static TextureData *decodeTexture(tinyxml2::XMLElement *textureXML); + static TextureData *decodeTexture(tinyxml2::XMLElement *textureXML, DataInfo *dataInfo); /** * Decode Contour Datas from xml export from Dragon Bone flash tool */ - static ContourData *decodeContour(tinyxml2::XMLElement *contourXML); + static ContourData *decodeContour(tinyxml2::XMLElement *contourXML, DataInfo *dataInfo); public: static void addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo = NULL); @@ -193,7 +196,6 @@ protected: std::queue *_asyncStructQueue; std::queue *_dataQueue; - static std::string _basefilePath; static std::vector _configFileList; static DataReaderHelper *_dataReaderHelper; diff --git a/cocos/editor-support/cocostudio/CCDatas.h b/cocos/editor-support/cocostudio/CCDatas.h index 26128020cf..5f08757d13 100644 --- a/cocos/editor-support/cocostudio/CCDatas.h +++ b/cocos/editor-support/cocostudio/CCDatas.h @@ -341,7 +341,7 @@ public: public: int frameID; int duration; //! The frame will last duration frames - CCTweenType tweenEasing; //! Every frame's tween easing effect + TweenType tweenEasing; //! Every frame's tween easing effect bool isTween; //! Whether it's a tween key frame /** @@ -435,7 +435,7 @@ public: * Which tween easing effect the movement use * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel */ - CCTweenType tweenEasing; + TweenType tweenEasing; /** * @brief save movment bone data diff --git a/cocos/editor-support/cocostudio/CCProcessBase.cpp b/cocos/editor-support/cocostudio/CCProcessBase.cpp index 1c9bd8965e..62bac419b6 100644 --- a/cocos/editor-support/cocostudio/CCProcessBase.cpp +++ b/cocos/editor-support/cocostudio/CCProcessBase.cpp @@ -89,7 +89,7 @@ void ProcessBase::play(void *animation, int durationTo, int durationTween, int * When changing end, m_iTotalFrames will be setted to _durationTween */ _nextFrameIndex = durationTo; - _tweenEasing = (CCTweenType)tweenEasing; + _tweenEasing = (TweenType)tweenEasing; } diff --git a/cocos/editor-support/cocostudio/CCProcessBase.h b/cocos/editor-support/cocostudio/CCProcessBase.h index 77c5da4ebb..e59244433e 100644 --- a/cocos/editor-support/cocostudio/CCProcessBase.h +++ b/cocos/editor-support/cocostudio/CCProcessBase.h @@ -146,7 +146,7 @@ protected: CC_SYNTHESIZE(AnimationType, _loopType, LoopType); //! The tween easing effect - CC_SYNTHESIZE(CCTweenType, _tweenEasing, TweenEasing); + CC_SYNTHESIZE(TweenType, _tweenEasing, TweenEasing); //! The animation update speed CC_SYNTHESIZE(float, _animationInternal, AnimationInternal); diff --git a/cocos/editor-support/cocostudio/CCTween.cpp b/cocos/editor-support/cocostudio/CCTween.cpp index 77f9a3b2ff..ce55cb4189 100644 --- a/cocos/editor-support/cocostudio/CCTween.cpp +++ b/cocos/editor-support/cocostudio/CCTween.cpp @@ -414,7 +414,7 @@ float Tween::updateFrameData(float currentPercent) { from = to = frames[0]; setBetween(from, to); - return currentPercent; + return _currentPercent; } if(playedTime >= frames[length - 1]->frameID) @@ -422,6 +422,8 @@ float Tween::updateFrameData(float currentPercent) // If _passLastFrame is true and playedTime >= frames[length - 1]->frameID, then do not need to go on. if (_passLastFrame) { + from = to = frames[length - 1]; + setBetween(from, to); return _currentPercent; } _passLastFrame = true; @@ -472,16 +474,10 @@ float Tween::updateFrameData(float currentPercent) /* * If frame tween easing equal to TWEEN_EASING_MAX, then it will not do tween. */ - - CCTweenType tweenType; - - if ( _frameTweenEasing != TWEEN_EASING_MAX) + TweenType tweenType = (_frameTweenEasing != Linear) ? _frameTweenEasing : _tweenEasing; + if (tweenType != TWEEN_EASING_MAX && tweenType != Linear) { - tweenType = (_tweenEasing == TWEEN_EASING_MAX) ? _frameTweenEasing : _tweenEasing; - if (tweenType != TWEEN_EASING_MAX && tweenType != Linear) - { - currentPercent = TweenFunction::tweenTo(0, 1, currentPercent, 1, tweenType); - } + currentPercent = TweenFunction::tweenTo(0, 1, currentPercent, 1, tweenType); } return currentPercent; diff --git a/cocos/editor-support/cocostudio/CCTween.h b/cocos/editor-support/cocostudio/CCTween.h index 61213371e8..c4fc110334 100644 --- a/cocos/editor-support/cocostudio/CCTween.h +++ b/cocos/editor-support/cocostudio/CCTween.h @@ -131,7 +131,7 @@ protected: Bone *_bone; //! A weak reference to the Bone - CCTweenType _frameTweenEasing; //! Dedermine which tween effect current frame use + TweenType _frameTweenEasing; //! Dedermine which tween effect current frame use int _betweenDuration; //! Current key frame will last _betweenDuration frames int _totalDuration; diff --git a/cocos/editor-support/cocostudio/CCTweenFunction.cpp b/cocos/editor-support/cocostudio/CCTweenFunction.cpp index 37b523fc79..74e4471768 100644 --- a/cocos/editor-support/cocostudio/CCTweenFunction.cpp +++ b/cocos/editor-support/cocostudio/CCTweenFunction.cpp @@ -27,7 +27,7 @@ THE SOFTWARE. namespace cocostudio { -float TweenFunction::tweenTo(float from, float change, float time, float duration, CCTweenType tweenType) +float TweenFunction::tweenTo(float from, float change, float time, float duration, TweenType tweenType) { float delta = 0; @@ -163,8 +163,8 @@ float TweenFunction::quadEaseOut(float t, float b, float c, float d) } float TweenFunction::quadEaseInOut(float t, float b, float c, float d) { - t /= d; - if ((t / 2) < 1) + t = t/d*2; + if ((t) < 1) return c / 2 * t * t + b; --t; return -c / 2 * (t * (t - 2) - 1) + b; @@ -182,8 +182,8 @@ float TweenFunction::cubicEaseOut(float t, float b, float c, float d) } float TweenFunction::cubicEaseInOut(float t, float b, float c, float d) { - t /= d; - if ((t / 2) < 1) + t = t/d*2; + if ((t) < 1) return c / 2 * t * t * t + b; t -= 2; return c / 2 * (t * t * t + 2) + b; @@ -201,8 +201,8 @@ float TweenFunction::quartEaseOut(float t, float b, float c, float d) } float TweenFunction::quartEaseInOut(float t, float b, float c, float d) { - t /= d; - if ((t / 2) < 1) + t = t/d*2; + if ((t) < 1) return c / 2 * t * t * t * t + b; t -= 2; return -c / 2 * (t * t * t * t - 2) + b; @@ -220,8 +220,8 @@ float TweenFunction::quintEaseOut(float t, float b, float c, float d) } float TweenFunction::quintEaseInOut(float t, float b, float c, float d) { - t /= d; - if ((t / 2) < 1) + t = t/d*2; + if ((t) < 1) return c / 2 * t * t * t * t * t + b; t -= 2; return c / 2 * (t * t * t * t * t + 2) + b; @@ -272,8 +272,8 @@ float TweenFunction::circEaseOut(float t, float b, float c, float d) } float TweenFunction::circEaseInOut(float t, float b, float c, float d) { - t /= d; - if ((t / 2) < 1) + t = t/d*2; + if ((t) < 1) return -c / 2 * (sqrt(1 - t * t) - 1) + b; t -= 2; return c / 2 * (sqrt(1 - t * t) + 1) + b; @@ -323,8 +323,8 @@ float TweenFunction::elasticEaseInOut(float t, float b, float c, float d, float float s = 0; if (t == 0) return b; - t /= d; - if ((t / 2) == 2) + t = t/d*2; + if ((t) == 2) return b + c; if (!p) p = d * (.3 * 1.5); diff --git a/cocos/editor-support/cocostudio/CCTweenFunction.h b/cocos/editor-support/cocostudio/CCTweenFunction.h index 255d19d58e..ff7ad6016d 100644 --- a/cocos/editor-support/cocostudio/CCTweenFunction.h +++ b/cocos/editor-support/cocostudio/CCTweenFunction.h @@ -31,16 +31,15 @@ THE SOFTWARE. namespace cocostudio { -enum CCTweenType +enum TweenType { TWEEN_EASING_MIN = -1, Linear, Sine_EaseIn, - Sine_EaseInOut, Sine_EaseOut, - + Sine_EaseInOut, Quad_EaseIn, Quad_EaseOut, @@ -85,7 +84,7 @@ class TweenFunction { public: - static float tweenTo(float from, float change, float time, float duration, CCTweenType tweenType); + static float tweenTo(float from, float change, float time, float duration, TweenType tweenType); static float linear(float t, float b, float c, float d); From b076711b699b3b37ec44f014e017a3af440e670e Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Tue, 5 Nov 2013 13:42:27 +0800 Subject: [PATCH 14/39] fix compile error --- cocos/editor-support/cocostudio/CCColliderDetector.cpp | 2 +- cocos/editor-support/cocostudio/CCColliderDetector.h | 7 +++---- .../CocoStudioArmatureTest/ArmatureScene.cpp | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.cpp b/cocos/editor-support/cocostudio/CCColliderDetector.cpp index cceb1a9b72..21cf39e486 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.cpp +++ b/cocos/editor-support/cocostudio/CCColliderDetector.cpp @@ -56,7 +56,7 @@ void ColliderFilter::updateShape(b2Fixture *fixture) } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT -ColliderFilter::ColliderFilter(cpCollisionType collisionType, cpGroup group) +ColliderFilter::ColliderFilter(uintptr_t collisionType, uintptr_t group) : _collisionType(collisionType) , _group(group) { diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.h b/cocos/editor-support/cocostudio/CCColliderDetector.h index e2da724c80..0b9c058aa8 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.h +++ b/cocos/editor-support/cocostudio/CCColliderDetector.h @@ -34,7 +34,6 @@ THE SOFTWARE. #if ENABLE_PHYSICS_CHIPMUNK_DETECT -#include "chipmunk.h" struct cpBody; struct cpShape; #elif ENABLE_PHYSICS_BOX2D_DETECT @@ -62,11 +61,11 @@ protected: CC_SYNTHESIZE(signed short, _groupIndex, GroupIndex); #elif ENABLE_PHYSICS_CHIPMUNK_DETECT public: - ColliderFilter(cpCollisionType collisionType = 0, cpGroup group = 0); + ColliderFilter(uintptr_t collisionType = 0, uintptr_t group = 0); void updateShape(cpShape *shape); protected: - CC_SYNTHESIZE(cpCollisionType, _collisionType, CollisionType); - CC_SYNTHESIZE(cpGroup, _group, Group); + CC_SYNTHESIZE(uintptr_t, _collisionType, CollisionType); + CC_SYNTHESIZE(uintptr_t, _group, Group); #endif }; diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index a6dfd04092..0b662d9c15 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -1008,7 +1008,8 @@ void TestColliderDetector::initWorld() cpSpaceAddBody(space, body); armature2->setBody(body); - armature2->setColliderFilter(&ColliderFilter(eEnemyTag)); + ColliderFilter filter = ColliderFilter(eEnemyTag); + armature2->setColliderFilter(&filter); cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, NULL, NULL, endHit, NULL); } From 3eef64c3b8d44adc58688c8a86921a2440983bd1 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Tue, 5 Nov 2013 15:32:13 +0800 Subject: [PATCH 15/39] 1. Change NULL to null 2. Remove CocoStudio/Armature files --- .../editor-support/cocostudio/CCArmature.cpp | 88 +- cocos/editor-support/cocostudio/CCArmature.h | 2 +- .../cocostudio/CCArmatureAnimation.cpp | 36 +- .../cocostudio/CCArmatureAnimation.h | 4 +- .../cocostudio/CCArmatureDataManager.cpp | 16 +- .../cocostudio/CCArmatureDefine.h | 2 +- .../editor-support/cocostudio/CCBatchNode.cpp | 24 +- cocos/editor-support/cocostudio/CCBone.cpp | 60 +- cocos/editor-support/cocostudio/CCBone.h | 2 +- .../cocostudio/CCColliderDetector.cpp | 54 +- .../cocostudio/CCDataReaderHelper.cpp | 76 +- .../cocostudio/CCDataReaderHelper.h | 4 +- cocos/editor-support/cocostudio/CCDatas.h | 4 +- .../cocostudio/CCDecorativeDisplay.cpp | 8 +- .../cocostudio/CCDisplayFactory.cpp | 4 +- .../cocostudio/CCDisplayManager.cpp | 28 +- cocos/editor-support/cocostudio/CCSkin.cpp | 16 +- .../cocostudio/CCSpriteFrameCacheHelper.cpp | 4 +- cocos/editor-support/cocostudio/CCTween.cpp | 26 +- cocos/editor-support/cocostudio/CCTween.h | 2 +- extensions/CocoStudio/Armature/CCArmature.cpp | 785 -------- extensions/CocoStudio/Armature/CCBone.cpp | 401 ----- extensions/CocoStudio/Armature/CCBone.h | 199 --- .../Armature/display/CCDisplayManager.cpp | 396 ----- .../CocoStudio/Armature/display/CCSkin.cpp | 205 --- .../Armature/utils/CCArmatureDefine.cpp | 34 - .../Armature/utils/CCDataReaderHelper.cpp | 1582 ----------------- .../CocoStudioArmatureTest/ArmatureScene.cpp | 50 +- 28 files changed, 255 insertions(+), 3857 deletions(-) delete mode 100644 extensions/CocoStudio/Armature/CCArmature.cpp delete mode 100644 extensions/CocoStudio/Armature/CCBone.cpp delete mode 100644 extensions/CocoStudio/Armature/CCBone.h delete mode 100644 extensions/CocoStudio/Armature/display/CCDisplayManager.cpp delete mode 100644 extensions/CocoStudio/Armature/display/CCSkin.cpp delete mode 100644 extensions/CocoStudio/Armature/utils/CCArmatureDefine.cpp delete mode 100644 extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index baa56ddfb7..be5c9d0c33 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -49,7 +49,7 @@ Armature *Armature::create() return armature; } CC_SAFE_DELETE(armature); - return NULL; + return nullptr; } @@ -62,7 +62,7 @@ Armature *Armature::create(const char *name) return armature; } CC_SAFE_DELETE(armature); - return NULL; + return nullptr; } Armature *Armature::create(const char *name, Bone *parentBone) @@ -74,31 +74,31 @@ Armature *Armature::create(const char *name, Bone *parentBone) return armature; } CC_SAFE_DELETE(armature); - return NULL; + return nullptr; } Armature::Armature() - : _armatureData(NULL) - , _batchNode(NULL) - , _atlas(NULL) - , _parentBone(NULL) + : _armatureData(nullptr) + , _batchNode(nullptr) + , _atlas(nullptr) + , _parentBone(nullptr) , _armatureTransformDirty(true) - , _boneDic(NULL) - , _topBoneList(NULL) - , _animation(NULL) - , _textureAtlasDic(NULL) + , _boneDic(nullptr) + , _topBoneList(nullptr) + , _animation(nullptr) + , _textureAtlasDic(nullptr) { } Armature::~Armature(void) { - if(NULL != _boneDic) + if(nullptr != _boneDic) { _boneDic->removeAllObjects(); CC_SAFE_DELETE(_boneDic); } - if (NULL != _topBoneList) + if (nullptr != _topBoneList) { _topBoneList->removeAllObjects(); CC_SAFE_DELETE(_topBoneList); @@ -110,7 +110,7 @@ Armature::~Armature(void) bool Armature::init() { - return init(NULL); + return init(nullptr); } @@ -139,7 +139,7 @@ bool Armature::init(const char *name) _blendFunc.dst = CC_BLEND_DST; - _name = name == NULL ? "" : name; + _name = name == nullptr ? "" : name; ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance(); @@ -159,7 +159,7 @@ bool Armature::init(const char *name) _armatureData = armatureData; - DictElement *_element = NULL; + DictElement *_element = nullptr; Dictionary *boneDataDic = &armatureData->boneDataDic; CCDICT_FOREACH(boneDataDic, _element) { @@ -228,13 +228,13 @@ bool Armature::init(const char *name, Bone *parentBone) Bone *Armature::createBone(const char *boneName) { Bone *existedBone = getBone(boneName); - if(existedBone != NULL) + if(existedBone != nullptr) return existedBone; BoneData *boneData = (BoneData *)_armatureData->getBoneData(boneName); std::string parentName = boneData->parentName; - Bone *bone = NULL; + Bone *bone = nullptr; if( parentName.length() != 0 ) { @@ -257,10 +257,10 @@ Bone *Armature::createBone(const char *boneName) void Armature::addBone(Bone *bone, const char *parentName) { - CCASSERT( bone != NULL, "Argument must be non-nil"); - CCASSERT(_boneDic->objectForKey(bone->getName()) == NULL, "bone already added. It can't be added again"); + CCASSERT( bone != nullptr, "Argument must be non-nil"); + CCASSERT(_boneDic->objectForKey(bone->getName()) == nullptr, "bone already added. It can't be added again"); - if (NULL != parentName) + if (nullptr != parentName) { Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName); if (boneParent) @@ -286,9 +286,9 @@ void Armature::addBone(Bone *bone, const char *parentName) void Armature::removeBone(Bone *bone, bool recursion) { - CCASSERT(bone != NULL, "bone must be added to the bone dictionary!"); + CCASSERT(bone != nullptr, "bone must be added to the bone dictionary!"); - bone->setArmature(NULL); + bone->setArmature(nullptr); bone->removeFromParent(recursion); if (_topBoneList->containsObject(bone)) @@ -308,15 +308,15 @@ Bone *Armature::getBone(const char *name) const void Armature::changeBoneParent(Bone *bone, const char *parentName) { - CCASSERT(bone != NULL, "bone must be added to the bone dictionary!"); + CCASSERT(bone != nullptr, "bone must be added to the bone dictionary!"); if(bone->getParentBone()) { bone->getParentBone()->getChildren()->removeObject(bone); - bone->setParentBone(NULL); + bone->setParentBone(nullptr); } - if (parentName != NULL) + if (parentName != nullptr) { Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName); @@ -451,7 +451,7 @@ void Armature::update(float dt) { _animation->update(dt); - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_topBoneList, object) { static_cast(object)->update(dt); @@ -462,20 +462,20 @@ void Armature::update(float dt) void Armature::draw() { - if (_parentBone == NULL && _batchNode == NULL) + if (_parentBone == nullptr && _batchNode == nullptr) { CC_NODE_DRAW_SETUP(); GL::blendFunc(_blendFunc.src, _blendFunc.dst); } - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_children, object) { if (Bone *bone = dynamic_cast(object)) { Node *node = bone->getDisplayRenderNode(); - if (NULL == node) + if (nullptr == node) continue; switch (bone->getDisplayRenderNodeType()) @@ -556,7 +556,7 @@ void Armature::draw() } } - if(_atlas && !_batchNode && _parentBone == NULL) + if(_atlas && !_batchNode && _parentBone == nullptr) { _atlas->drawQuads(); _atlas->removeAllQuads(); @@ -642,7 +642,7 @@ Rect Armature::getBoundingBox() const Rect boundingBox = Rect(0, 0, 0, 0); - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_children, object) { if (Bone *bone = dynamic_cast(object)) @@ -686,7 +686,7 @@ Bone *Armature::getBoneAtPoint(float x, float y) return bs; } } - return NULL; + return nullptr; } TextureAtlas *Armature::getTexureAtlasWithTexture(Texture2D *texture) @@ -703,7 +703,7 @@ TextureAtlas *Armature::getTexureAtlasWithTexture(Texture2D *texture) } TextureAtlas *atlas = static_cast(_textureAtlasDic->objectForKey(key)); - if (atlas == NULL) + if (atlas == nullptr) { atlas = TextureAtlas::createWithTexture(texture, 4); _textureAtlasDic->setObject(atlas, key); @@ -715,7 +715,7 @@ void Armature::setParentBone(Bone *parentBone) { _parentBone = parentBone; - DictElement *element = NULL; + DictElement *element = nullptr; CCDICT_FOREACH(_boneDic, element) { Bone *bone = static_cast(element->getObject()); @@ -730,7 +730,7 @@ Bone *Armature::getParentBone() void CCArmature::setColliderFilter(ColliderFilter *filter) { - DictElement *element = NULL; + DictElement *element = nullptr; CCDICT_FOREACH(_boneDic, element) { Bone *bone = static_cast(element->getObject()); @@ -754,18 +754,18 @@ void Armature::setBody(b2Body *body) _body = body; _body->SetUserData(this); - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_children, object) { if (Bone *bone = dynamic_cast(object)) { Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - Object *displayObject = NULL; + Object *displayObject = nullptr; CCARRAY_FOREACH(displayList, displayObject) { ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); - if (detector != NULL) + if (detector != nullptr) { detector->setBody(_body); } @@ -782,7 +782,7 @@ b2Fixture *Armature::getShapeList() } else { - return NULL; + return nullptr; } } @@ -802,18 +802,18 @@ void Armature::setBody(cpBody *body) _body = body; _body->data = this; - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_children, object) { if (Bone *bone = dynamic_cast(object)) { Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - Object *displayObject = NULL; + Object *displayObject = nullptr; CCARRAY_FOREACH(displayList, displayObject) { ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); - if (detector != NULL) + if (detector != nullptr) { detector->setBody(_body); } @@ -830,7 +830,7 @@ cpShape *Armature::getShapeList() } else { - return NULL; + return nullptr; } } #endif diff --git a/cocos/editor-support/cocostudio/CCArmature.h b/cocos/editor-support/cocostudio/CCArmature.h index b58591ae19..9f6fc3331b 100644 --- a/cocos/editor-support/cocostudio/CCArmature.h +++ b/cocos/editor-support/cocostudio/CCArmature.h @@ -112,7 +112,7 @@ public: * Add a Bone to this Armature, * * @param bone The Bone you want to add to Armature - * @param parentName The parent Bone's name you want to add to . If it's NULL, then set Armature to its parent + * @param parentName The parent Bone's name you want to add to . If it's nullptr, then set Armature to its parent */ virtual void addBone(Bone *bone, const char *parentName); /** diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp index ed6e383751..8f9c9252bd 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp @@ -43,24 +43,24 @@ ArmatureAnimation *ArmatureAnimation::create(Armature *armature) return pArmatureAnimation; } CC_SAFE_DELETE(pArmatureAnimation); - return NULL; + return nullptr; } ArmatureAnimation::ArmatureAnimation() - : _animationData(NULL) + : _animationData(nullptr) , _speedScale(1) - , _movementData(NULL) - , _armature(NULL) + , _movementData(nullptr) + , _armature(nullptr) , _movementID("") , _toIndex(0) - , _tweenList(NULL) + , _tweenList(nullptr) , _ignoreFrameEvent(false) - , _movementEventCallFunc(NULL) - , _frameEventCallFunc(NULL) - , _movementEventTarget(NULL) - , _frameEventTarget(NULL) + , _movementEventCallFunc(nullptr) + , _frameEventCallFunc(nullptr) + , _movementEventTarget(nullptr) + , _frameEventTarget(nullptr) { } @@ -94,7 +94,7 @@ bool ArmatureAnimation::init(Armature *armature) void ArmatureAnimation:: pause() { - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_tweenList, object) { static_cast(object)->pause(); @@ -104,7 +104,7 @@ void ArmatureAnimation:: pause() void ArmatureAnimation::resume() { - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_tweenList, object) { static_cast(object)->resume(); @@ -114,7 +114,7 @@ void ArmatureAnimation::resume() void ArmatureAnimation::stop() { - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_tweenList, object) { static_cast(object)->stop(); @@ -145,7 +145,7 @@ void ArmatureAnimation::setSpeedScale(float speedScale) _processScale = !_movementData ? _speedScale : _speedScale * _movementData->scale; - DictElement *element = NULL; + DictElement *element = nullptr; Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { @@ -173,7 +173,7 @@ void ArmatureAnimation::setAnimationInternal(float animationInternal) _animationInternal = animationInternal; - DictElement *element = NULL; + DictElement *element = nullptr; Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { @@ -232,10 +232,10 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura _durationTween = durationTween; } - MovementBoneData *movementBoneData = NULL; + MovementBoneData *movementBoneData = nullptr; _tweenList->removeAllObjects(); - DictElement *element = NULL; + DictElement *element = nullptr; Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) @@ -302,7 +302,7 @@ void ArmatureAnimation::gotoAndPlay(int frameIndex) _currentPercent = (float)_curFrameIndex / (float)_movementData->duration; _currentFrame = _nextFrameIndex * _currentPercent; - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_tweenList, object) { static_cast(object)->gotoAndPlay(frameIndex); @@ -327,7 +327,7 @@ int ArmatureAnimation::getMovementCount() void ArmatureAnimation::update(float dt) { ProcessBase::update(dt); - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_tweenList, object) { static_cast(object)->update(dt); diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.h b/cocos/editor-support/cocostudio/CCArmatureAnimation.h index 5fe23543bf..3c6e7e5a2c 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.h +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.h @@ -182,13 +182,13 @@ public: /** * Set armature's movement event callback function - * To disconnect this event, just setMovementEventCallFunc(NULL, NULL); + * To disconnect this event, just setMovementEventCallFunc(nullptr, nullptr); */ void setMovementEventCallFunc(cocos2d::Object *target, SEL_MovementEventCallFunc callFunc); /** * Set armature's frame event callback function - * To disconnect this event, just setFrameEventCallFunc(NULL, NULL); + * To disconnect this event, just setFrameEventCallFunc(nullptr, nullptr); */ void setFrameEventCallFunc(cocos2d::Object *target, SEL_FrameEventCallFunc callFunc); diff --git a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp index ca1945b418..c8278387ce 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp @@ -32,11 +32,11 @@ using namespace cocos2d; namespace cocostudio { -static ArmatureDataManager *s_sharedArmatureDataManager = NULL; +static ArmatureDataManager *s_sharedArmatureDataManager = nullptr; ArmatureDataManager *ArmatureDataManager::getInstance() { - if (s_sharedArmatureDataManager == NULL) + if (s_sharedArmatureDataManager == nullptr) { s_sharedArmatureDataManager = new ArmatureDataManager(); if (!s_sharedArmatureDataManager || !s_sharedArmatureDataManager->init()) @@ -56,9 +56,9 @@ void ArmatureDataManager::destoryInstance() ArmatureDataManager::ArmatureDataManager(void) { - _armarureDatas = NULL; - _animationDatas = NULL; - _textureDatas = NULL; + _armarureDatas = nullptr; + _animationDatas = nullptr; + _textureDatas = nullptr; _autoLoadSpriteFile = false; } @@ -156,7 +156,7 @@ void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armature ArmatureData *ArmatureDataManager::getArmatureData(const char *id) { - ArmatureData *armatureData = NULL; + ArmatureData *armatureData = nullptr; if (_armarureDatas) { armatureData = (ArmatureData *)_armarureDatas->objectForKey(id); @@ -187,7 +187,7 @@ void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animat AnimationData *ArmatureDataManager::getAnimationData(const char *id) { - AnimationData *animationData = NULL; + AnimationData *animationData = nullptr; if (_animationDatas) { animationData = (AnimationData *)_animationDatas->objectForKey(id); @@ -219,7 +219,7 @@ void ArmatureDataManager::addTextureData(const char *id, TextureData *textureDat TextureData *ArmatureDataManager::getTextureData(const char *id) { - TextureData *textureData = NULL; + TextureData *textureData = nullptr; if (_textureDatas) { textureData = (TextureData *)_textureDatas->objectForKey(id); diff --git a/cocos/editor-support/cocostudio/CCArmatureDefine.h b/cocos/editor-support/cocostudio/CCArmatureDefine.h index 0691058417..c79b58ff81 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDefine.h +++ b/cocos/editor-support/cocostudio/CCArmatureDefine.h @@ -50,7 +50,7 @@ THE SOFTWARE. #endif #define CS_RETURN_IF(cond) if (cond) return -#define CS_RETURN_NULL_IF(cond) if (cond) return NULL; +#define CS_RETURN_NULL_IF(cond) if (cond) return nullptr; namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index bb84576d66..d674d8487b 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -40,12 +40,12 @@ BatchNode *BatchNode::create() return batchNode; } CC_SAFE_DELETE(batchNode); - return NULL; + return nullptr; } BatchNode::BatchNode() - : _atlas(NULL) - , _textureAtlasDic(NULL) + : _atlas(nullptr) + , _textureAtlasDic(nullptr) { } @@ -79,18 +79,18 @@ void BatchNode::addChild(Node *child, int zOrder, int tag) { Node::addChild(child, zOrder, tag); Armature *armature = dynamic_cast(child); - if (armature != NULL) + if (armature != nullptr) { armature->setBatchNode(this); Dictionary *dict = armature->getBoneDic(); - DictElement *element = NULL; + DictElement *element = nullptr; CCDICT_FOREACH(dict, element) { Bone *bone = static_cast(element->getObject()); Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(displayList, object) { DecorativeDisplay *display = static_cast(object); @@ -107,18 +107,18 @@ void BatchNode::addChild(Node *child, int zOrder, int tag) void BatchNode::removeChild(Node* child, bool cleanup) { Armature *armature = dynamic_cast(child); - if (armature != NULL) + if (armature != nullptr) { - armature->setBatchNode(NULL); + armature->setBatchNode(nullptr); Dictionary *dict = armature->getBoneDic(); - DictElement *element = NULL; + DictElement *element = nullptr; CCDICT_FOREACH(dict, element) { Bone *bone = static_cast(element->getObject()); Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(displayList, object) { DecorativeDisplay *display = static_cast(object); @@ -166,7 +166,7 @@ void BatchNode::visit() void BatchNode::draw() { CC_NODE_DRAW_SETUP(); - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_children, object) { Armature *armature = dynamic_cast(object); @@ -193,7 +193,7 @@ TextureAtlas *BatchNode::getTexureAtlasWithTexture(Texture2D *texture) int key = texture->getName(); TextureAtlas *atlas = static_cast(_textureAtlasDic->objectForKey(key)); - if (atlas == NULL) + if (atlas == nullptr) { atlas = CCTextureAtlas::createWithTexture(texture, 4); _textureAtlasDic->setObject(atlas, key); diff --git a/cocos/editor-support/cocostudio/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index faf4b0ee94..45562f898e 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -43,7 +43,7 @@ Bone *Bone::create() return pBone; } CC_SAFE_DELETE(pBone); - return NULL; + return nullptr; } @@ -57,27 +57,27 @@ Bone *Bone::create(const char *name) return pBone; } CC_SAFE_DELETE(pBone); - return NULL; + return nullptr; } Bone::Bone() { - _tweenData = NULL; - _parentBone = NULL; - _armature = NULL; - _childArmature = NULL; - _boneData = NULL; - _tween = NULL; - _tween = NULL; - _children = NULL; - _displayManager = NULL; + _tweenData = nullptr; + _parentBone = nullptr; + _armature = nullptr; + _childArmature = nullptr; + _boneData = nullptr; + _tween = nullptr; + _tween = nullptr; + _children = nullptr; + _displayManager = nullptr; _ignoreMovementBoneData = false; _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0); _boneTransformDirty = true; _blendType = BLEND_NORMAL; - _worldInfo = NULL; + _worldInfo = nullptr; - _armatureParentBone = NULL; + _armatureParentBone = nullptr; _dataVersion = 0; } @@ -97,7 +97,7 @@ Bone::~Bone(void) bool Bone::init() { - return Bone::init(NULL); + return Bone::init(nullptr); } @@ -107,7 +107,7 @@ bool Bone::init(const char *name) do { - if(NULL != name) + if(nullptr != name) { _name = name; } @@ -138,7 +138,7 @@ bool Bone::init(const char *name) void Bone::setBoneData(BoneData *boneData) { - CCASSERT(NULL != boneData, "_boneData must not be NULL"); + CCASSERT(nullptr != boneData, "_boneData must not be nullptr"); if (_boneData != boneData) { @@ -169,7 +169,7 @@ void Bone::setArmature(Armature *armature) } else { - _armatureParentBone = NULL; + _armatureParentBone = nullptr; } } @@ -229,7 +229,7 @@ void Bone::update(float delta) DisplayFactory::updateDisplay(this, delta, _boneTransformDirty || _armature->getArmatureTransformDirty()); - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_children, object) { Bone *childBone = (Bone *)object; @@ -282,7 +282,7 @@ void Bone::updateColor() { Node *display = _displayManager->getDisplayRenderNode(); RGBAProtocol *protocol = dynamic_cast(display); - if(protocol != NULL) + if(protocol != nullptr) { protocol->setColor(Color3B(_displayedColor.r * _tweenData->r / 255, _displayedColor.g * _tweenData->g / 255, _displayedColor.b * _tweenData->b / 255)); protocol->setOpacity(_displayedOpacity * _tweenData->a / 255); @@ -304,8 +304,8 @@ void Bone::updateZOrder() void Bone::addChildBone(Bone *child) { - CCASSERT( NULL != child, "Argument must be non-nil"); - CCASSERT( NULL == child->_parentBone, "child already added. It can't be added again"); + CCASSERT( nullptr != child, "Argument must be non-nil"); + CCASSERT( nullptr == child->_parentBone, "child already added. It can't be added again"); if(!_children) { @@ -327,7 +327,7 @@ void Bone::removeChildBone(Bone *bone, bool recursion) if(recursion) { Array *_ccbones = bone->_children; - Object *_object = NULL; + Object *_object = nullptr; CCARRAY_FOREACH(_ccbones, _object) { Bone *_ccBone = (Bone *)_object; @@ -335,9 +335,9 @@ void Bone::removeChildBone(Bone *bone, bool recursion) } } - bone->setParentBone(NULL); + bone->setParentBone(nullptr); - bone->getDisplayManager()->setCurrentDecorativeDisplay(NULL); + bone->getDisplayManager()->setCurrentDecorativeDisplay(nullptr); _children->removeObject(bone); } @@ -345,7 +345,7 @@ void Bone::removeChildBone(Bone *bone, bool recursion) void Bone::removeFromParent(bool recursion) { - if (NULL != _parentBone) + if (nullptr != _parentBone) { _parentBone->removeChildBone(this, recursion); } @@ -365,9 +365,9 @@ void Bone::setChildArmature(Armature *armature) { if (_childArmature != armature) { - if (armature == NULL && _childArmature) + if (armature == nullptr && _childArmature) { - _childArmature->setParentBone(NULL); + _childArmature->setParentBone(nullptr); } CC_SAFE_RETAIN(armature); @@ -441,7 +441,7 @@ Array *Bone::getColliderBodyList() return detector->getColliderBodyList(); } } - return NULL; + return nullptr; } @@ -449,7 +449,7 @@ Array *Bone::getColliderBodyList() void Bone::setColliderFilter(ColliderFilter *filter) { Array *array = _displayManager->getDecorativeDisplayList(); - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(array, object) { DecorativeDisplay *decoDisplay = static_cast(object); @@ -468,7 +468,7 @@ ColliderFilter *Bone::getColliderFilter() return detector->getColliderFilter(); } } - return NULL; + return nullptr; } diff --git a/cocos/editor-support/cocostudio/CCBone.h b/cocos/editor-support/cocostudio/CCBone.h index 6edd3fe8cb..58a15c3987 100644 --- a/cocos/editor-support/cocostudio/CCBone.h +++ b/cocos/editor-support/cocostudio/CCBone.h @@ -102,7 +102,7 @@ public: * It will not set the Armature, if you want to add the bone to a Armature, you should use Armature::addBone(Bone *bone, const char* parentName). * * @param parent the parent bone. - * NULL : remove this bone from armature + * nullptr : remove this bone from armature */ void setParentBone(Bone *parent); diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.cpp b/cocos/editor-support/cocostudio/CCColliderDetector.cpp index 21cf39e486..be587ecefb 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.cpp +++ b/cocos/editor-support/cocostudio/CCColliderDetector.cpp @@ -70,7 +70,7 @@ void ColliderFilter::updateShape(cpShape *shape) #if ENABLE_PHYSICS_BOX2D_DETECT ColliderBody::ColliderBody(ContourData *contourData) - : _fixture(NULL) + : _fixture(nullptr) , _contourData(contourData) { CC_SAFE_RETAIN(_contourData); @@ -84,7 +84,7 @@ ColliderBody::ColliderBody(ContourData *contourData) #elif ENABLE_PHYSICS_CHIPMUNK_DETECT ColliderBody::ColliderBody(ContourData *contourData) - : _shape(NULL) + : _shape(nullptr) , _contourData(contourData) { CC_SAFE_RETAIN(_contourData); @@ -127,7 +127,7 @@ ColliderDetector *ColliderDetector::create() return pColliderDetector; } CC_SAFE_DELETE(pColliderDetector); - return NULL; + return nullptr; } ColliderDetector *ColliderDetector::create(Bone *bone) @@ -139,15 +139,15 @@ ColliderDetector *ColliderDetector::create(Bone *bone) return pColliderDetector; } CC_SAFE_DELETE(pColliderDetector); - return NULL; + return nullptr; } ColliderDetector::ColliderDetector() - : _colliderBodyList(NULL) - , _filter(NULL) + : _colliderBodyList(nullptr) + , _filter(nullptr) , _active(false) { - _body = NULL; + _body = nullptr; } ColliderDetector::~ColliderDetector() @@ -198,7 +198,7 @@ void ColliderDetector::addContourData(ContourData *contourData) void ColliderDetector::addContourDataList(Array *contourDataList) { - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(contourDataList, object) { addContourData((ContourData *)object); @@ -207,7 +207,7 @@ void ColliderDetector::addContourDataList(Array *contourDataList) void ColliderDetector::removeContourData(ContourData *contourData) { - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *body = (ColliderBody*)object; @@ -242,28 +242,28 @@ void ColliderDetector::setActive(bool active) } else { - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; b2Fixture *fixture = colliderBody->getB2Fixture(); _body->DestroyFixture(fixture); - colliderBody->setB2Fixture(NULL); + colliderBody->setB2Fixture(nullptr); } } } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT if (_body) { - Object *object = NULL; + Object *object = nullptr; if (_active) { CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; cpShape *shape = colliderBody->getShape(); - if(shape->space_private == NULL) + if(shape->space_private == nullptr) { cpSpaceAddShape(_body->space_private, shape); } @@ -275,7 +275,7 @@ void ColliderDetector::setActive(bool active) { ColliderBody *colliderBody = (ColliderBody *)object; cpShape *shape = colliderBody->getShape(); - if (shape->space_private != NULL) + if (shape->space_private != nullptr) { cpSpaceRemoveShape(_body->space_private, shape); } @@ -299,7 +299,7 @@ void ColliderDetector::setColliderFilter(ColliderFilter *filter) { *_filter = *filter; - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; @@ -333,21 +333,21 @@ void ColliderDetector::updateTransform(AffineTransform &t) return; } - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; ContourData *contourData = colliderBody->getContourData(); #if ENABLE_PHYSICS_BOX2D_DETECT - b2PolygonShape *shape = NULL; - if (_body != NULL) + b2PolygonShape *shape = nullptr; + if (_body != nullptr) { shape = (b2PolygonShape *)colliderBody->getB2Fixture()->GetShape(); } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT - cpPolyShape *shape = NULL; - if (_body != NULL) + cpPolyShape *shape = nullptr; + if (_body != nullptr) { shape = (cpPolyShape *)colliderBody->getShape(); } @@ -372,13 +372,13 @@ void ColliderDetector::updateTransform(AffineTransform &t) #endif #if ENABLE_PHYSICS_BOX2D_DETECT - if (shape != NULL) + if (shape != nullptr) { b2Vec2 &bv = shape->m_vertices[i]; bv.Set(helpPoint.x / PT_RATIO, helpPoint.y / PT_RATIO); } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT - if (shape != NULL) + if (shape != nullptr) { cpVect v ; v.x = helpPoint.x; @@ -389,7 +389,7 @@ void ColliderDetector::updateTransform(AffineTransform &t) } #if ENABLE_PHYSICS_CHIPMUNK_DETECT - cpConvexHull(num, shape->verts, NULL, NULL, 0); + cpConvexHull(num, shape->verts, nullptr, nullptr, 0); for (int i = 0; i < num; i++) { cpVect b = shape->verts[(i + 1) % shape->numVerts]; @@ -408,14 +408,14 @@ void ColliderDetector::setBody(b2Body *pBody) { _body = pBody; - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; ContourData *contourData = colliderBody->getContourData(); const Array *array = &contourData->vertexList; - Object *object = NULL; + Object *object = nullptr; b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.count()]; @@ -439,7 +439,7 @@ void ColliderDetector::setBody(b2Body *pBody) b2Fixture *fixture = _body->CreateFixture(&fixtureDef); fixture->SetUserData(_bone); - if (colliderBody->getB2Fixture() != NULL) + if (colliderBody->getB2Fixture() != nullptr) { _body->DestroyFixture(colliderBody->getB2Fixture()); } @@ -459,7 +459,7 @@ void ColliderDetector::setBody(cpBody *pBody) { _body = pBody; - Object *object = NULL; + Object *object = nullptr; CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 7ff2117b41..50b59715c7 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -143,14 +143,14 @@ float s_PositionReadScale = 1; std::vector DataReaderHelper::_configFileList; -DataReaderHelper *DataReaderHelper::_dataReaderHelper = NULL; +DataReaderHelper *DataReaderHelper::_dataReaderHelper = nullptr; //! Async load void DataReaderHelper::loadData() { - AsyncStruct *pAsyncStruct = NULL; + AsyncStruct *pAsyncStruct = nullptr; while (true) { @@ -202,12 +202,12 @@ void DataReaderHelper::loadData() _dataInfoMutex.unlock(); } - if( _asyncStructQueue != NULL ) + if( _asyncStructQueue != nullptr ) { delete _asyncStructQueue; - _asyncStructQueue = NULL; + _asyncStructQueue = nullptr; delete _dataQueue; - _dataQueue = NULL; + _dataQueue = nullptr; } } @@ -259,7 +259,7 @@ DataReaderHelper::~DataReaderHelper() if (_loadingThread) _loadingThread->join(); CC_SAFE_DELETE(_loadingThread); - _dataReaderHelper = NULL; + _dataReaderHelper = nullptr; } void DataReaderHelper::addDataFromFile(const char *filePath) @@ -301,7 +301,7 @@ void DataReaderHelper::addDataFromFile(const char *filePath) DataInfo dataInfo; dataInfo.filename = filePathStr; - dataInfo.asyncStruct = NULL; + dataInfo.asyncStruct = nullptr; dataInfo.baseFilePath = basefilePath; if (str.compare(".xml") == 0) @@ -354,7 +354,7 @@ void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *p // lazy init - if (_asyncStructQueue == NULL) + if (_asyncStructQueue == nullptr) { _asyncStructQueue = new std::queue(); _dataQueue = new std::queue(); @@ -591,7 +591,7 @@ ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML * If this bone have parent, then get the parent bone xml */ const char *parentName = boneXML->Attribute(A_PARENT); - tinyxml2::XMLElement *parentXML = NULL; + tinyxml2::XMLElement *parentXML = nullptr; if (parentName) { parentXML = armatureXML->FirstChildElement(BONE); @@ -624,7 +624,7 @@ BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2:: std::string name = boneXML->Attribute(A_NAME); boneData->name = name; - if( boneXML->Attribute(A_PARENT) != NULL ) + if( boneXML->Attribute(A_PARENT) != nullptr ) { boneData->parentName = boneXML->Attribute(A_PARENT); } @@ -671,7 +671,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXM } - if(displayXML->Attribute(A_NAME) != NULL ) + if(displayXML->Attribute(A_NAME) != nullptr ) { if(!_isArmature) { @@ -740,7 +740,7 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML } const char *_easing = movementXML->Attribute(A_TWEEN_EASING); - if(_easing != NULL) + if(_easing != nullptr) { std::string str = _easing; if(str.compare(FL_NAN) != 0) @@ -773,7 +773,7 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML std::string parentName = boneData->parentName; - tinyxml2::XMLElement *parentXml = NULL; + tinyxml2::XMLElement *parentXml = nullptr; if (parentName.length() != 0) { parentXml = movementXML->FirstChildElement(BONE); @@ -827,14 +827,14 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov int parentTotalDuration = 0; int currentDuration = 0; - tinyxml2::XMLElement *parentFrameXML = NULL; + tinyxml2::XMLElement *parentFrameXML = nullptr; std::vector parentXmlList; /* * get the parent frame xml list, we need get the origin data */ - if( parentXml != NULL ) + if( parentXml != nullptr ) { parentFrameXML = parentXml->FirstChildElement(FRAME); while (parentFrameXML) @@ -843,7 +843,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov parentFrameXML = parentFrameXML->NextSiblingElement(FRAME); } - parentFrameXML = NULL; + parentFrameXML = nullptr; length = parentXmlList.size(); } @@ -925,19 +925,19 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm FrameData *frameData = new FrameData(); - if(frameXML->Attribute(A_MOVEMENT) != NULL) + if(frameXML->Attribute(A_MOVEMENT) != nullptr) { frameData->strMovement = frameXML->Attribute(A_MOVEMENT); } - if(frameXML->Attribute(A_EVENT) != NULL) + if(frameXML->Attribute(A_EVENT) != nullptr) { frameData->strEvent = frameXML->Attribute(A_EVENT); } - if(frameXML->Attribute(A_SOUND) != NULL) + if(frameXML->Attribute(A_SOUND) != nullptr) { frameData->strSound = frameXML->Attribute(A_SOUND); } - if(frameXML->Attribute(A_SOUND_EFFECT) != NULL) + if(frameXML->Attribute(A_SOUND_EFFECT) != nullptr) { frameData->strSoundEffect = frameXML->Attribute(A_SOUND_EFFECT); } @@ -1030,7 +1030,7 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm const char *_easing = frameXML->Attribute(A_TWEEN_EASING); - if(_easing != NULL) + if(_easing != nullptr) { std::string str = _easing; if(str.compare(FL_NAN) != 0) @@ -1081,7 +1081,7 @@ TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML, D TextureData *textureData = new TextureData(); textureData->init(); - if( textureXML->Attribute(A_NAME) != NULL) + if( textureXML->Attribute(A_NAME) != nullptr) { textureData->name = textureXML->Attribute(A_NAME); } @@ -1216,14 +1216,14 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d } // Auto load sprite file - bool autoLoad = dataInfo->asyncStruct == NULL ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; + bool autoLoad = dataInfo->asyncStruct == nullptr ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; if (autoLoad) { length = json.getArrayItemCount(CONFIG_FILE_PATH); for (int i = 0; i < length; i++) { const char *path = json.getStringValueFromArray(CONFIG_FILE_PATH, i); - if (path == NULL) + if (path == nullptr) { CCLOG("load CONFIG_FILE_PATH error."); return; @@ -1253,7 +1253,7 @@ ArmatureData *DataReaderHelper::decodeArmature(JsonDictionary &json, DataInfo *d armatureData->init(); const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) + if(name != nullptr) { armatureData->name = name; } @@ -1282,13 +1282,13 @@ BoneData *DataReaderHelper::decodeBone(JsonDictionary &json, DataInfo *dataInfo) decodeNode(boneData, json, dataInfo); const char *str = json.getItemStringValue(A_NAME); - if(str != NULL) + if(str != nullptr) { boneData->name = str; } str = json.getItemStringValue(A_PARENT); - if(str != NULL) + if(str != nullptr) { boneData->parentName = str; } @@ -1312,7 +1312,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo { DisplayType displayType = (DisplayType)json.getItemIntValue(A_DISPLAY_TYPE, CS_DISPLAY_SPRITE); - DisplayData *displayData = NULL; + DisplayData *displayData = nullptr; switch (displayType) { @@ -1321,13 +1321,13 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo displayData = new SpriteDisplayData(); const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) + if(name != nullptr) { ((SpriteDisplayData *)displayData)->displayName = name; } JsonDictionary *dic = json.getSubItemFromArray(SKIN_DATA, 0); - if (dic != NULL) + if (dic != nullptr) { SpriteDisplayData *sdd = (SpriteDisplayData *)displayData; sdd->skinData.x = dic->getItemFloatValue(A_X, 0) * s_PositionReadScale; @@ -1350,7 +1350,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo displayData = new ArmatureDisplayData(); const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) + if(name != nullptr) { ((ArmatureDisplayData *)displayData)->displayName = name; } @@ -1361,7 +1361,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo displayData = new ParticleDisplayData(); const char *plist = json.getItemStringValue(A_PLIST); - if(plist != NULL) + if(plist != nullptr) { if (dataInfo->asyncStruct) { @@ -1391,7 +1391,7 @@ AnimationData *DataReaderHelper::decodeAnimation(JsonDictionary &json, DataInfo AnimationData *aniData = new AnimationData(); const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) + if(name != nullptr) { aniData->name = name; } @@ -1423,7 +1423,7 @@ MovementData *DataReaderHelper::decodeMovement(JsonDictionary &json, DataInfo *d movementData->tweenEasing = (TweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) + if(name != nullptr) { movementData->name = name; } @@ -1450,7 +1450,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json, Dat movementBoneData->delay = json.getItemFloatValue(A_MOVEMENT_DELAY, 0); const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) + if(name != nullptr) { movementBoneData->name = name; } @@ -1526,7 +1526,7 @@ FrameData *DataReaderHelper::decodeFrame(JsonDictionary &json, DataInfo *dataInf frameData->isTween = (bool)json.getItemBoolvalue(A_TWEEN_FRAME, true); const char *event = json.getItemStringValue(A_EVENT); - if (event != NULL) + if (event != nullptr) { frameData->strEvent = event; } @@ -1549,7 +1549,7 @@ TextureData *DataReaderHelper::decodeTexture(JsonDictionary &json) textureData->init(); const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) + if(name != nullptr) { textureData->name = name; } @@ -1612,7 +1612,7 @@ void DataReaderHelper::decodeNode(BaseData *node, JsonDictionary &json, DataInfo node->scaleX = json.getItemFloatValue(A_SCALE_X, 1); node->scaleY = json.getItemFloatValue(A_SCALE_Y, 1); - JsonDictionary *colorDic = NULL; + JsonDictionary *colorDic = nullptr; if (dataInfo->cocoStudioVersion < VERSION_COLOR_READING) { colorDic = json.getSubItemFromArray(COLOR_INFO, 0); diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.h b/cocos/editor-support/cocostudio/CCDataReaderHelper.h index 82f551e52f..33088e0043 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.h +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.h @@ -119,7 +119,7 @@ public: * * @param xmlPath The cache of the xml */ - static void addDataFromCache(const char *pFileContent, DataInfo *dataInfo = NULL); + static void addDataFromCache(const char *pFileContent, DataInfo *dataInfo = nullptr); @@ -151,7 +151,7 @@ public: static ContourData *decodeContour(tinyxml2::XMLElement *contourXML, DataInfo *dataInfo); public: - static void addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo = NULL); + static void addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo = nullptr); static ArmatureData *decodeArmature(JsonDictionary &json, DataInfo *dataInfo); static BoneData *decodeBone(JsonDictionary &json, DataInfo *dataInfo); diff --git a/cocos/editor-support/cocostudio/CCDatas.h b/cocos/editor-support/cocostudio/CCDatas.h index 5f08757d13..4b9c2feca6 100644 --- a/cocos/editor-support/cocostudio/CCDatas.h +++ b/cocos/editor-support/cocostudio/CCDatas.h @@ -39,7 +39,7 @@ public: \ return var;\ }\ CC_SAFE_DELETE(var);\ - return NULL;\ + return nullptr;\ } #define CC_CREATE_NO_PARAM(varType)\ @@ -52,7 +52,7 @@ public: \ return var;\ }\ CC_SAFE_DELETE(var);\ - return NULL;\ + return nullptr;\ } namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCDecorativeDisplay.cpp b/cocos/editor-support/cocostudio/CCDecorativeDisplay.cpp index e595ecbe0c..81cc4bc751 100644 --- a/cocos/editor-support/cocostudio/CCDecorativeDisplay.cpp +++ b/cocos/editor-support/cocostudio/CCDecorativeDisplay.cpp @@ -37,16 +37,16 @@ DecorativeDisplay *DecorativeDisplay::create() return pDisplay; } CC_SAFE_DELETE(pDisplay); - return NULL; + return nullptr; } DecorativeDisplay::DecorativeDisplay() - : _display(NULL) - , _displayData(NULL) + : _display(nullptr) + , _displayData(nullptr) { #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - _colliderDetector = NULL; + _colliderDetector = nullptr; #endif } diff --git a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp index b130428ab1..7f329ff3cc 100644 --- a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp @@ -133,7 +133,7 @@ void DisplayFactory::addSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay void DisplayFactory::createSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay) { - Skin *skin = NULL; + Skin *skin = nullptr; SpriteDisplayData *displayData = (SpriteDisplayData *)decoDisplay->getDisplayData(); @@ -157,7 +157,7 @@ void DisplayFactory::createSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisp decoDisplay->setDisplay(skin); - if (skin == NULL) + if (skin == nullptr) { return; } diff --git a/cocos/editor-support/cocostudio/CCDisplayManager.cpp b/cocos/editor-support/cocostudio/CCDisplayManager.cpp index bffcf80c64..5efa5510c7 100644 --- a/cocos/editor-support/cocostudio/CCDisplayManager.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayManager.cpp @@ -41,19 +41,19 @@ DisplayManager *DisplayManager::create(Bone *bone) return pDisplayManager; } CC_SAFE_DELETE(pDisplayManager); - return NULL; + return nullptr; } DisplayManager::DisplayManager() - : _decoDisplayList(NULL) - , _displayRenderNode(NULL) + : _decoDisplayList(nullptr) + , _displayRenderNode(nullptr) , _displayType(CS_DISPLAY_MAX) - , _currentDecoDisplay(NULL) + , _currentDecoDisplay(nullptr) , _displayIndex(-1) , _forceChangeDisplay(false) , _visible(true) - , _bone(NULL) + , _bone(nullptr) { } @@ -91,7 +91,7 @@ bool DisplayManager::init(Bone *bone) void DisplayManager::addDisplay(DisplayData *displayData, int index) { - DecorativeDisplay *decoDisplay = NULL; + DecorativeDisplay *decoDisplay = nullptr; if( (index >= 0) && (index < _decoDisplayList->count()) ) { @@ -115,7 +115,7 @@ void DisplayManager::addDisplay(DisplayData *displayData, int index) void DisplayManager::addDisplay(Node *display, int index) { - DecorativeDisplay *decoDisplay = NULL; + DecorativeDisplay *decoDisplay = nullptr; if( (index >= 0) && (index < _decoDisplayList->count()) ) { @@ -127,7 +127,7 @@ void DisplayManager::addDisplay(Node *display, int index) _decoDisplayList->addObject(decoDisplay); } - DisplayData *displayData = NULL; + DisplayData *displayData = nullptr; if (Skin *skin = dynamic_cast(display)) { skin->setBone(_bone); @@ -175,7 +175,7 @@ void DisplayManager::removeDisplay(int index) { if(index == _displayIndex) { - setCurrentDecorativeDisplay(NULL); + setCurrentDecorativeDisplay(nullptr); _displayIndex = -1; } @@ -206,7 +206,7 @@ void DisplayManager::changeDisplayByIndex(int index, bool force) if(_displayRenderNode) { _displayRenderNode->removeFromParentAndCleanup(true); - setCurrentDecorativeDisplay(NULL); + setCurrentDecorativeDisplay(nullptr); } return; } @@ -235,12 +235,12 @@ void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay) } #endif - Node *displayRenderNode = _currentDecoDisplay == NULL ? NULL : _currentDecoDisplay->getDisplay(); + Node *displayRenderNode = _currentDecoDisplay == nullptr ? nullptr : _currentDecoDisplay->getDisplay(); if (_displayRenderNode) { - if (dynamic_cast(_displayRenderNode) != NULL) + if (dynamic_cast(_displayRenderNode) != nullptr) { - _bone->setChildArmature(NULL); + _bone->setChildArmature(nullptr); } _displayRenderNode->removeFromParentAndCleanup(true); _displayRenderNode->release(); @@ -310,7 +310,7 @@ void DisplayManager::initDisplayList(BoneData *boneData) CS_RETURN_IF(!boneData); - Object *object = NULL; + Object *object = nullptr; Array *displayDataList = &boneData->displayDataList; CCARRAY_FOREACH(displayDataList, object) { diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index 5cb8483a95..b0496729f4 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -48,7 +48,7 @@ Skin *Skin::create() return skin; } CC_SAFE_DELETE(skin); - return NULL; + return nullptr; } Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName) @@ -60,7 +60,7 @@ Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName) return skin; } CC_SAFE_DELETE(skin); - return NULL; + return nullptr; } Skin *Skin::create(const char *pszFileName) @@ -72,12 +72,12 @@ Skin *Skin::create(const char *pszFileName) return skin; } CC_SAFE_DELETE(skin); - return NULL; + return nullptr; } Skin::Skin() - : _bone(NULL) - , _armature(NULL) + : _bone(nullptr) + , _armature(nullptr) , _displayName("") { _skinTransform = AffineTransformIdentity; @@ -85,12 +85,12 @@ Skin::Skin() bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) { - CCAssert(pszSpriteFrameName != NULL, ""); + CCAssert(pszSpriteFrameName != nullptr, ""); SpriteFrame *pFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(pszSpriteFrameName); bool ret = true; - if (pFrame != NULL) + if (pFrame != nullptr) { ret = initWithSpriteFrame(pFrame); } @@ -188,7 +188,7 @@ void Skin::updateTransform() SET_VERTEX3F( _quad.tr.vertices, RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _vertexZ ); } - // MARMALADE CHANGE: ADDED CHECK FOR NULL, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS + // MARMALADE CHANGE: ADDED CHECK FOR nullptr, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS if (_textureAtlas) { _textureAtlas->updateQuad(&_quad, _textureAtlas->getTotalQuads()); diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp index 68fa7ebfb5..d3e2b620fd 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp @@ -29,7 +29,7 @@ using namespace cocos2d; namespace cocostudio { -SpriteFrameCacheHelper *SpriteFrameCacheHelper::_spriteFrameCacheHelper = NULL; +SpriteFrameCacheHelper *SpriteFrameCacheHelper::_spriteFrameCacheHelper = nullptr; SpriteFrameCacheHelper *SpriteFrameCacheHelper::getInstance() { @@ -44,7 +44,7 @@ SpriteFrameCacheHelper *SpriteFrameCacheHelper::getInstance() void SpriteFrameCacheHelper::purge() { delete _spriteFrameCacheHelper; - _spriteFrameCacheHelper = NULL; + _spriteFrameCacheHelper = nullptr; } void SpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) diff --git a/cocos/editor-support/cocostudio/CCTween.cpp b/cocos/editor-support/cocostudio/CCTween.cpp index ce55cb4189..75ff8bbb7e 100644 --- a/cocos/editor-support/cocostudio/CCTween.cpp +++ b/cocos/editor-support/cocostudio/CCTween.cpp @@ -43,24 +43,24 @@ Tween *Tween::create(Bone *bone) return pTween; } CC_SAFE_DELETE(pTween); - return NULL; + return nullptr; } Tween::Tween() - : _movementBoneData(NULL) - , _tweenData(NULL) - , _from(NULL) - , _to(NULL) - , _between(NULL) - , _bone(NULL) + : _movementBoneData(nullptr) + , _tweenData(nullptr) + , _from(nullptr) + , _to(nullptr) + , _between(nullptr) + , _bone(nullptr) , _frameTweenEasing(Linear) , _fromIndex(0) , _toIndex(0) - , _animation(NULL) + , _animation(nullptr) , _passLastFrame(false) { @@ -86,7 +86,7 @@ bool Tween::init(Bone *bone) _tweenData = _bone->getTweenData(); _tweenData->displayIndex = -1; - _animation = _bone->getArmature() != NULL ? _bone->getArmature()->getAnimation() : NULL; + _animation = _bone->getArmature() != nullptr ? _bone->getArmature()->getAnimation() : nullptr; bRet = true; } @@ -98,7 +98,7 @@ bool Tween::init(Bone *bone) void Tween::play(MovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing) { - ProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing); + ProcessBase::play(nullptr, durationTo, durationTween, loop, tweenEasing); if (loop) { @@ -354,7 +354,7 @@ void Tween::arriveKeyFrame(FrameData *keyFrameData) FrameData *Tween::tweenNodeTo(float percent, FrameData *node) { - node = node == NULL ? _tweenData : node; + node = node == nullptr ? _tweenData : node; if (!_from->isTween) { @@ -407,8 +407,8 @@ float Tween::updateFrameData(float currentPercent) int length = _movementBoneData->frameList.count(); FrameData **frames = (FrameData **)_movementBoneData->frameList.data->arr; - FrameData *from = NULL; - FrameData *to = NULL; + FrameData *from = nullptr; + FrameData *to = nullptr; if (playedTime < frames[0]->frameID) { diff --git a/cocos/editor-support/cocostudio/CCTween.h b/cocos/editor-support/cocostudio/CCTween.h index c4fc110334..ce08f2264e 100644 --- a/cocos/editor-support/cocostudio/CCTween.h +++ b/cocos/editor-support/cocostudio/CCTween.h @@ -108,7 +108,7 @@ protected: /** * According to the percent to calculate current FrameData with tween effect */ - virtual FrameData *tweenNodeTo(float percent, FrameData *node = NULL); + virtual FrameData *tweenNodeTo(float percent, FrameData *node = nullptr); /** * According to the percent to calculate current color with tween effect diff --git a/extensions/CocoStudio/Armature/CCArmature.cpp b/extensions/CocoStudio/Armature/CCArmature.cpp deleted file mode 100644 index c5709b0418..0000000000 --- a/extensions/CocoStudio/Armature/CCArmature.cpp +++ /dev/null @@ -1,785 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "CCArmature.h" -#include "utils/CCArmatureDataManager.h" -#include "utils/CCArmatureDefine.h" -#include "utils/CCDataReaderHelper.h" -#include "datas/CCDatas.h" -#include "display/CCSkin.h" - -#if ENABLE_PHYSICS_BOX2D_DETECT -#include "Box2D/Box2D.h" -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT -#include "chipmunk.h" -#endif - - -NS_CC_EXT_ARMATURE_BEGIN - -Armature *Armature::create() -{ - Armature *armature = new Armature(); - if (armature && armature->init()) - { - armature->autorelease(); - return armature; - } - CC_SAFE_DELETE(armature); - return NULL; -} - - -Armature *Armature::create(const char *name) -{ - Armature *armature = new Armature(); - if (armature && armature->init(name)) - { - armature->autorelease(); - return armature; - } - CC_SAFE_DELETE(armature); - return NULL; -} - -Armature *Armature::create(const char *name, Bone *parentBone) -{ - Armature *armature = new Armature(); - if (armature && armature->init(name, parentBone)) - { - armature->autorelease(); - return armature; - } - CC_SAFE_DELETE(armature); - return NULL; -} - -Armature::Armature() - : _armatureData(NULL) - , _batchNode(NULL) - , _atlas(NULL) - , _parentBone(NULL) - , _armatureTransformDirty(true) - , _boneDic(NULL) - , _topBoneList(NULL) - , _animation(NULL) -{ -} - - -Armature::~Armature(void) -{ - if(NULL != _boneDic) - { - _boneDic->removeAllObjects(); - CC_SAFE_DELETE(_boneDic); - } - if (NULL != _topBoneList) - { - _topBoneList->removeAllObjects(); - CC_SAFE_DELETE(_topBoneList); - } - CC_SAFE_DELETE(_animation); -} - - -bool Armature::init() -{ - return init(NULL); -} - - -bool Armature::init(const char *name) -{ - bool bRet = false; - do - { - removeAllChildren(); - - CC_SAFE_DELETE(_animation); - _animation = new ArmatureAnimation(); - _animation->init(this); - - CC_SAFE_DELETE(_boneDic); - _boneDic = new Dictionary(); - - CC_SAFE_DELETE(_topBoneList); - _topBoneList = new Array(); - _topBoneList->init(); - - _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; - - - _name = name == NULL ? "" : name; - - ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance(); - - if(_name.length() != 0) - { - _name = name; - - AnimationData *animationData = armatureDataManager->getAnimationData(name); - CCASSERT(animationData, "AnimationData not exist! "); - - _animation->setAnimationData(animationData); - - - ArmatureData *armatureData = armatureDataManager->getArmatureData(name); - CCASSERT(armatureData, ""); - - _armatureData = armatureData; - - - DictElement *_element = NULL; - Dictionary *boneDataDic = &armatureData->boneDataDic; - CCDICT_FOREACH(boneDataDic, _element) - { - Bone *bone = createBone(_element->getStrKey()); - - //! init bone's Tween to 1st movement's 1st frame - do - { - - MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str()); - CC_BREAK_IF(!movData); - - MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str()); - CC_BREAK_IF(!movBoneData || movBoneData->frameList.count() <= 0); - - FrameData *frameData = movBoneData->getFrameData(0); - CC_BREAK_IF(!frameData); - - bone->getTweenData()->copy(frameData); - bone->changeDisplayByIndex(frameData->displayIndex, false); - } - while (0); - } - - update(0); - updateOffsetPoint(); - } - else - { - _name = "new_armature"; - _armatureData = ArmatureData::create(); - _armatureData->name = _name; - - AnimationData *animationData = AnimationData::create(); - animationData->name = _name; - - armatureDataManager->addArmatureData(_name.c_str(), _armatureData); - armatureDataManager->addAnimationData(_name.c_str(), animationData); - - _animation->setAnimationData(animationData); - - } - - setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); - - unscheduleUpdate(); - scheduleUpdate(); - - setCascadeOpacityEnabled(true); - setCascadeColorEnabled(true); - - bRet = true; - } - while (0); - - return bRet; -} - -bool Armature::init(const char *name, Bone *parentBone) -{ - _parentBone = parentBone; - return init(name); -} - - -Bone *Armature::createBone(const char *boneName) -{ - Bone *existedBone = getBone(boneName); - if(existedBone != NULL) - return existedBone; - - BoneData *boneData = (BoneData *)_armatureData->getBoneData(boneName); - std::string parentName = boneData->parentName; - - Bone *bone = NULL; - - if( parentName.length() != 0 ) - { - createBone(parentName.c_str()); - bone = Bone::create(boneName); - addBone(bone, parentName.c_str()); - } - else - { - bone = Bone::create(boneName); - addBone(bone, ""); - } - - bone->setBoneData(boneData); - bone->getDisplayManager()->changeDisplayByIndex(-1, false); - - return bone; -} - - -void Armature::addBone(Bone *bone, const char *parentName) -{ - CCASSERT( bone != NULL, "Argument must be non-nil"); - CCASSERT(_boneDic->objectForKey(bone->getName()) == NULL, "bone already added. It can't be added again"); - - if (NULL != parentName) - { - Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName); - if (boneParent) - { - boneParent->addChildBone(bone); - } - else - { - _topBoneList->addObject(bone); - } - } - else - { - _topBoneList->addObject(bone); - } - - bone->setArmature(this); - - _boneDic->setObject(bone, bone->getName()); - addChild(bone); -} - - -void Armature::removeBone(Bone *bone, bool recursion) -{ - CCASSERT(bone != NULL, "bone must be added to the bone dictionary!"); - - bone->setArmature(NULL); - bone->removeFromParent(recursion); - - if (_topBoneList->containsObject(bone)) - { - _topBoneList->removeObject(bone); - } - _boneDic->removeObjectForKey(bone->getName()); - removeChild(bone, true); -} - - -Bone *Armature::getBone(const char *name) const -{ - return (Bone *)_boneDic->objectForKey(name); -} - - -void Armature::changeBoneParent(Bone *bone, const char *parentName) -{ - CCASSERT(bone != NULL, "bone must be added to the bone dictionary!"); - - if(bone->getParentBone()) - { - bone->getParentBone()->getChildren()->removeObject(bone); - bone->setParentBone(NULL); - } - - if (parentName != NULL) - { - Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName); - - if (boneParent) - { - boneParent->addChildBone(bone); - if (_topBoneList->containsObject(bone)) - { - _topBoneList->removeObject(bone); - } - } - else - { - _topBoneList->addObject(bone); - } - } -} - -Dictionary *Armature::getBoneDic() -{ - return _boneDic; -} - -const AffineTransform &Armature::getNodeToParentTransform() const -{ - if (_transformDirty) - { - _armatureTransformDirty = true; - - // Translate values - float x = _position.x; - float y = _position.y; - - if (_ignoreAnchorPointForPosition) - { - x += _anchorPointInPoints.x; - y += _anchorPointInPoints.y; - } - - // Rotation values - // Change rotation code to handle X and Y - // If we skew with the exact same value for both x and y then we're simply just rotating - float cx = 1, sx = 0, cy = 1, sy = 0; - if (_rotationX || _rotationY) - { - float radiansX = -CC_DEGREES_TO_RADIANS(_rotationX); - float radiansY = -CC_DEGREES_TO_RADIANS(_rotationY); - cx = cosf(radiansX); - sx = sinf(radiansX); - cy = cosf(radiansY); - sy = sinf(radiansY); - } - - // Add offset point - x += cy * _offsetPoint.x * _scaleX + -sx * _offsetPoint.y * _scaleY; - y += sy * _offsetPoint.x * _scaleX + cx * _offsetPoint.y * _scaleY; - - bool needsSkewMatrix = ( _skewX || _skewY ); - - // optimization: - // inline anchor point calculation if skew is not needed - // Adjusted transform calculation for rotational skew - if (! needsSkewMatrix && !_anchorPointInPoints.equals(Point::ZERO)) - { - x += cy * -_anchorPointInPoints.x * _scaleX + -sx * -_anchorPointInPoints.y * _scaleY; - y += sy * -_anchorPointInPoints.x * _scaleX + cx * -_anchorPointInPoints.y * _scaleY; - } - - - // Build Transform Matrix - // Adjusted transform calculation for rotational skew - _transform = AffineTransformMake( cy * _scaleX, sy * _scaleX, - -sx * _scaleY, cx * _scaleY, - x, y ); - - // XXX: Try to inline skew - // If skew is needed, apply skew and then anchor point - if (needsSkewMatrix) - { - AffineTransform skewMatrix = AffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(_skewY)), - tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1.0f, - 0.0f, 0.0f ); - _transform = AffineTransformConcat(skewMatrix, _transform); - - // adjust anchor point - if (!_anchorPointInPoints.equals(Point::ZERO)) - { - _transform = AffineTransformTranslate(_transform, -_anchorPointInPoints.x, -_anchorPointInPoints.y); - } - } - - if (_additionalTransformDirty) - { - _transform = AffineTransformConcat(_transform, _additionalTransform); - _additionalTransformDirty = false; - } - - _transformDirty = false; - } - - return _transform; -} - -void Armature::updateOffsetPoint() -{ - // Set contentsize and Calculate anchor point. - Rect rect = getBoundingBox(); - setContentSize(rect.size); - _offsetPoint = Point(-rect.origin.x, -rect.origin.y); - if (rect.size.width != 0 && rect.size.height != 0) - { - setAnchorPoint(Point(_offsetPoint.x / rect.size.width, _offsetPoint.y / rect.size.height)); - } -} - -void Armature::setAnimation(ArmatureAnimation *animation) -{ - _animation = animation; -} - -ArmatureAnimation *Armature::getAnimation() -{ - return _animation; -} - -bool Armature::getArmatureTransformDirty() -{ - return _armatureTransformDirty; -} - -void Armature::update(float dt) -{ - _animation->update(dt); - - Object *object = NULL; - CCARRAY_FOREACH(_topBoneList, object) - { - static_cast(object)->update(dt); - } - - _armatureTransformDirty = false; -} - -void Armature::draw() -{ - if (_parentBone == NULL) - { - CC_NODE_DRAW_SETUP(); - GL::blendFunc(_blendFunc.src, _blendFunc.dst); - } - - Object *object = NULL; - CCARRAY_FOREACH(_children, object) - { - if (Bone *bone = dynamic_cast(object)) - { - DisplayManager *displayManager = bone->getDisplayManager(); - Node *node = displayManager->getDisplayRenderNode(); - - if (NULL == node) - continue; - - switch (displayManager->getCurrentDecorativeDisplay()->getDisplayData()->displayType) - { - case CS_DISPLAY_SPRITE: - { - Skin *skin = static_cast(node); - - TextureAtlas *textureAtlas = skin->getTextureAtlas(); - BlendType blendType = bone->getBlendType(); - if(_atlas != textureAtlas || blendType != BLEND_NORMAL) - { - if (_atlas) - { - _atlas->drawQuads(); - _atlas->removeAllQuads(); - } - } - - _atlas = textureAtlas; - if (_atlas->getCapacity() == _atlas->getTotalQuads() && !_atlas->resizeCapacity(_atlas->getCapacity() * 2)) - return; - - skin->updateTransform(); - - if (blendType != BLEND_NORMAL) - { - updateBlendType(blendType); - _atlas->drawQuads(); - _atlas->removeAllQuads(); - GL::blendFunc(_blendFunc.src, _blendFunc.dst); - } - } - break; - case CS_DISPLAY_ARMATURE: - { - Armature *armature = static_cast(node); - - TextureAtlas *textureAtlas = armature->getTextureAtlas(); - if(_atlas != textureAtlas) - { - if (_atlas) - { - _atlas->drawQuads(); - _atlas->removeAllQuads(); - } - } - armature->draw(); - - _atlas = armature->getTextureAtlas(); - } - break; - default: - { - if (_atlas) - { - _atlas->drawQuads(); - _atlas->removeAllQuads(); - } - node->visit(); - - CC_NODE_DRAW_SETUP(); - GL::blendFunc(_blendFunc.src, _blendFunc.dst); - } - break; - } - } - else if(Node *node = dynamic_cast(object)) - { - if (_atlas) - { - _atlas->drawQuads(); - _atlas->removeAllQuads(); - } - node->visit(); - - CC_NODE_DRAW_SETUP(); - GL::blendFunc(_blendFunc.src, _blendFunc.dst); - } - } - - if(_atlas && !_batchNode && _parentBone == NULL) - { - _atlas->drawQuads(); - _atlas->removeAllQuads(); - } -} - - -void Armature::updateBlendType(BlendType blendType) -{ - BlendFunc blendFunc; - switch (blendType) - { - case BLEND_NORMAL: - { - blendFunc.src = CC_BLEND_SRC; - blendFunc.dst = CC_BLEND_DST; - } - break; - case BLEND_ADD: - { - blendFunc.src = GL_SRC_ALPHA; - blendFunc.dst = GL_ONE; - } - break; - case BLEND_MULTIPLY: - { - blendFunc.src = GL_DST_COLOR; - blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA; - } - break; - case BLEND_SCREEN: - { - blendFunc.src = GL_ONE; - blendFunc.dst = GL_ONE_MINUS_SRC_COLOR; - } - break; - default: - { - blendFunc.src = CC_BLEND_SRC; - blendFunc.dst = CC_BLEND_DST; - } - break; - } - GL::blendFunc(blendFunc.src, blendFunc.dst); -} - - - -void Armature::visit() -{ - // quick return if not visible. children won't be drawn. - if (!_visible) - { - return; - } - kmGLPushMatrix(); - - if (_grid && _grid->isActive()) - { - _grid->beforeDraw(); - } - - transform(); - sortAllChildren(); - draw(); - updateEventPriorityIndex(); - - // reset for next frame - _orderOfArrival = 0; - - if (_grid && _grid->isActive()) - { - _grid->afterDraw(this); - } - - kmGLPopMatrix(); -} - -Rect Armature::getBoundingBox() const -{ - float minx, miny, maxx, maxy = 0; - - bool first = true; - - Rect boundingBox = Rect(0, 0, 0, 0); - - Object *object = NULL; - CCARRAY_FOREACH(_children, object) - { - if (Bone *bone = dynamic_cast(object)) - { - Rect r = bone->getDisplayManager()->getBoundingBox(); - - if(first) - { - minx = r.getMinX(); - miny = r.getMinY(); - maxx = r.getMaxX(); - maxy = r.getMaxY(); - - first = false; - } - else - { - minx = r.getMinX() < boundingBox.getMinX() ? r.getMinX() : boundingBox.getMinX(); - miny = r.getMinY() < boundingBox.getMinY() ? r.getMinY() : boundingBox.getMinY(); - maxx = r.getMaxX() > boundingBox.getMaxX() ? r.getMaxX() : boundingBox.getMaxX(); - maxy = r.getMaxY() > boundingBox.getMaxY() ? r.getMaxY() : boundingBox.getMaxY(); - } - - boundingBox.setRect(minx, miny, maxx - minx, maxy - miny); - } - } - - return boundingBox; -} - -Bone *Armature::getBoneAtPoint(float x, float y) -{ - int length = _children->count(); - Bone *bs; - - for(int i = length - 1; i >= 0; i--) - { - bs = static_cast( _children->getObjectAtIndex(i) ); - if(bs->getDisplayManager()->containPoint(x, y)) - { - return bs; - } - } - return NULL; -} - -#if ENABLE_PHYSICS_BOX2D_DETECT -b2Body *Armature::getBody() -{ - return _body; -} - -void Armature::setBody(b2Body *body) -{ - if (_body == body) - { - return; - } - - _body = body; - _body->SetUserData(this); - - Object *object = NULL; - CCARRAY_FOREACH(_children, object) - { - if (Bone *bone = dynamic_cast(object)) - { - Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - - Object *displayObject = NULL; - CCARRAY_FOREACH(displayList, displayObject) - { - ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); - if (detector != NULL) - { - detector->setBody(_body); - } - } - } - } -} - -b2Fixture *Armature::getShapeList() -{ - if (_body) - { - return _body->GetFixtureList(); - } - else - { - return NULL; - } -} - -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT -cpBody *Armature::getBody() -{ - return _body; -} - -void Armature::setBody(cpBody *body) -{ - if (_body == body) - { - return; - } - - _body = body; - _body->data = this; - - Object *object = NULL; - CCARRAY_FOREACH(_children, object) - { - if (Bone *bone = dynamic_cast(object)) - { - Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - - Object *displayObject = NULL; - CCARRAY_FOREACH(displayList, displayObject) - { - ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); - if (detector != NULL) - { - detector->setBody(_body); - } - } - } - } -} - -cpShape *Armature::getShapeList() -{ - if (_body) - { - return _body->shapeList_private; - } - else - { - return NULL; - } -} -#endif - - -NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/CCBone.cpp b/extensions/CocoStudio/Armature/CCBone.cpp deleted file mode 100644 index d9ad2bfdc7..0000000000 --- a/extensions/CocoStudio/Armature/CCBone.cpp +++ /dev/null @@ -1,401 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "CCBone.h" -#include "CCArmature.h" -#include "utils/CCUtilMath.h" -#include "utils/CCArmatureDataManager.h" -#include "utils/CCTransformHelp.h" -#include "display/CCDisplayManager.h" - -NS_CC_EXT_ARMATURE_BEGIN - -Bone *Bone::create() -{ - - Bone *pBone = new Bone(); - if (pBone && pBone->init()) - { - pBone->autorelease(); - return pBone; - } - CC_SAFE_DELETE(pBone); - return NULL; - -} - -Bone *Bone::create(const char *name) -{ - - Bone *pBone = new Bone(); - if (pBone && pBone->init(name)) - { - pBone->autorelease(); - return pBone; - } - CC_SAFE_DELETE(pBone); - return NULL; -} - -Bone::Bone() -{ - _tweenData = NULL; - _parentBone = NULL; - _armature = NULL; - _childArmature = NULL; - _boneData = NULL; - _tween = NULL; - _tween = NULL; - _children = NULL; - _displayManager = NULL; - _ignoreMovementBoneData = false; - _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0); - _boneTransformDirty = true; - _blendType = BLEND_NORMAL; -} - - -Bone::~Bone(void) -{ - CC_SAFE_DELETE(_tweenData); - CC_SAFE_DELETE(_children); - CC_SAFE_DELETE(_tween); - CC_SAFE_DELETE(_displayManager); - - if(_boneData) - { - _boneData->release(); - } - - CC_SAFE_RELEASE(_childArmature); -} - -bool Bone::init() -{ - return Bone::init(NULL); -} - - -bool Bone::init(const char *name) -{ - bool bRet = false; - do - { - - if(NULL != name) - { - _name = name; - } - - CC_SAFE_DELETE(_tweenData); - _tweenData = new FrameData(); - - CC_SAFE_DELETE(_tween); - _tween = new Tween(); - _tween->init(this); - - CC_SAFE_DELETE(_displayManager); - _displayManager = new DisplayManager(); - _displayManager->init(this); - - - bRet = true; - } - while (0); - - return bRet; -} - -void Bone::setBoneData(BoneData *boneData) -{ - CCASSERT(NULL != boneData, "_boneData must not be NULL"); - - _boneData = boneData; - _boneData->retain(); - - _name = _boneData->name; - _ZOrder = _boneData->zOrder; - - _displayManager->initDisplayList(boneData); -} - -BoneData *Bone::getBoneData() -{ - return _boneData; -} - -void Bone::setArmature(Armature *armature) -{ - _armature = armature; - if (_armature) - { - _tween->setAnimation(_armature->getAnimation()); - } -} - - -Armature *Bone::getArmature() -{ - return _armature; -} - -void Bone::update(float delta) -{ - if (_parentBone) - _boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty(); - - CCBone *armatureParentBone = _armature->getParentBone(); - if (armatureParentBone && !_boneTransformDirty) - { - _boneTransformDirty = armatureParentBone->isTransformDirty(); - } - - - if (_boneTransformDirty) - { - if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) - { - TransformHelp::nodeConcat(*_tweenData, *_boneData); - _tweenData->scaleX -= 1; - _tweenData->scaleY -= 1; - } - - TransformHelp::nodeToMatrix(*_tweenData, _worldTransform); - - _worldTransform = AffineTransformConcat(getNodeToParentTransform(), _worldTransform); - - if(_parentBone) - { - _worldTransform = AffineTransformConcat(_worldTransform, _parentBone->_worldTransform); - } - else - { - if (armatureParentBone) - { - _worldTransform = CCAffineTransformConcat(_worldTransform, armatureParentBone->getNodeToArmatureTransform()); - } - } - } - - DisplayFactory::updateDisplay(this, _displayManager->getCurrentDecorativeDisplay(), delta, _boneTransformDirty || _armature->getArmatureTransformDirty()); - - Object *object = NULL; - CCARRAY_FOREACH(_children, object) - { - Bone *childBone = (Bone *)object; - childBone->update(delta); - } - - _boneTransformDirty = false; -} - - -void Bone::updateDisplayedColor(const Color3B &parentColor) -{ - _realColor = Color3B(255, 255, 255); - NodeRGBA::updateDisplayedColor(parentColor); - updateColor(); -} - -void Bone::updateDisplayedOpacity(GLubyte parentOpacity) -{ - _realOpacity = 255; - NodeRGBA::updateDisplayedOpacity(parentOpacity); - updateColor(); -} - -void Bone::setColor(const Color3B &color) -{ - CCNodeRGBA::setColor(color); - updateColor(); -} -void Bone::setOpacity(GLubyte opacity) -{ - CCNodeRGBA::setOpacity(opacity); - updateColor(); -} - -void Bone::updateColor() -{ - Node *display = _displayManager->getDisplayRenderNode(); - RGBAProtocol *protocol = dynamic_cast(display); - if(protocol != NULL) - { - protocol->setColor(Color3B(_displayedColor.r * _tweenData->r / 255, _displayedColor.g * _tweenData->g / 255, _displayedColor.b * _tweenData->b / 255)); - protocol->setOpacity(_displayedOpacity * _tweenData->a / 255); - } -} - -void Bone::updateZOrder() -{ - if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) - { - int zorder = _tweenData->zOrder + _boneData->zOrder; - setZOrder(zorder); - } - else - { - setZOrder(_tweenData->zOrder); - } -} - -void Bone::addChildBone(Bone *child) -{ - CCASSERT( NULL != child, "Argument must be non-nil"); - CCASSERT( NULL == child->_parentBone, "child already added. It can't be added again"); - - if(!_children) - { - _children = Array::createWithCapacity(4); - _children->retain(); - } - - if (_children->getIndexOfObject(child) == UINT_MAX) - { - _children->addObject(child); - child->setParentBone(this); - } -} - -void Bone::removeChildBone(Bone *bone, bool recursion) -{ - if ( _children->getIndexOfObject(bone) != UINT_MAX ) - { - if(recursion) - { - Array *_ccbones = bone->_children; - Object *_object = NULL; - CCARRAY_FOREACH(_ccbones, _object) - { - Bone *_ccBone = (Bone *)_object; - bone->removeChildBone(_ccBone, recursion); - } - } - - bone->setParentBone(NULL); - - bone->getDisplayManager()->setCurrentDecorativeDisplay(NULL); - - _children->removeObject(bone); - } -} - -void Bone::removeFromParent(bool recursion) -{ - if (NULL != _parentBone) - { - _parentBone->removeChildBone(this, recursion); - } -} - -void Bone::setParentBone(Bone *parent) -{ - _parentBone = parent; -} - -Bone *Bone::getParentBone() -{ - return _parentBone; -} - -void Bone::setChildArmature(Armature *armature) -{ - if (_childArmature != armature) - { - CC_SAFE_RETAIN(armature); - CC_SAFE_RELEASE(_childArmature); - _childArmature = armature; - } -} - -Armature *Bone::getChildArmature() -{ - return _childArmature; -} - -Tween *Bone::getTween() -{ - return _tween; -} - -void Bone::setZOrder(int zOrder) -{ - if (_ZOrder != zOrder) - Node::setZOrder(zOrder); -} - -void Bone::setTransformDirty(bool dirty) -{ - _boneTransformDirty = dirty; -} - -bool Bone::isTransformDirty() -{ - return _boneTransformDirty; -} - -AffineTransform Bone::getNodeToArmatureTransform() const -{ - return _worldTransform; -} - -AffineTransform Bone::getNodeToWorldTransform() const -{ - return AffineTransformConcat(_worldTransform, _armature->getNodeToWorldTransform()); -} - -Node *Bone::getDisplayRenderNode() -{ - return _displayManager->getDisplayRenderNode(); -} - -void Bone::addDisplay(DisplayData *displayData, int index) -{ - _displayManager->addDisplay(displayData, index); -} - -void Bone::addDisplay(Node *display, int index) -{ - _displayManager->addDisplay(display, index); -} - -void Bone::changeDisplayByIndex(int index, bool force) -{ - _displayManager->changeDisplayByIndex(index, force); -} - -Array *Bone::getColliderBodyList() -{ - if (DecorativeDisplay *decoDisplay = _displayManager->getCurrentDecorativeDisplay()) - { - if (ColliderDetector *detector = decoDisplay->getColliderDetector()) - { - return detector->getColliderBodyList(); - } - } - return NULL; -} - - -NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/CCBone.h b/extensions/CocoStudio/Armature/CCBone.h deleted file mode 100644 index 1aecfcb099..0000000000 --- a/extensions/CocoStudio/Armature/CCBone.h +++ /dev/null @@ -1,199 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __CCBONE_H__ -#define __CCBONE_H__ - -#include "utils/CCArmatureDefine.h" -#include "datas/CCDatas.h" -#include "animation/CCTween.h" -#include "display/CCDecorativeDisplay.h" -#include "display/CCDisplayManager.h" - -NS_CC_EXT_ARMATURE_BEGIN - - -class Armature; - -class Bone : public NodeRGBA -{ -public: - /** - * Allocates and initializes a bone. - * @return A initialized bone which is marked as "autorelease". - */ - static Bone *create(); - /** - * Allocates and initializes a bone. - * - * @param name If name is not null, then set name to the bone's name - * @return A initialized bone which is marked as "autorelease". - */ - static Bone *create(const char *name); - -public: - Bone(); - /** - * @js NA - * @lua NA - */ - virtual ~Bone(void); - - /** - * Initializes an empty Bone with nothing init. - */ - virtual bool init(); - - /** - * Initializes a Bone with the specified name - * @param name Bone's name. - */ - virtual bool init(const char *name); - - /** - * Add display and use displayData to init the display. - * If index already have a display, then replace it. - * If index is current display index, then also change display to _index - * - * @param displayData it include the display information, like DisplayType. - * If you want to create a sprite display, then create a SpriteDisplayData param - * - * @param index the index of the display you want to replace or add to - * -1 : append display from back - */ - void addDisplay(DisplayData *displayData, int index); - - void addDisplay(Node *display, int index); - - void changeDisplayByIndex(int index, bool force); - - /** - * Add a child to this bone, and it will let this child call setParent(Bone *parent) function to set self to it's parent - * @param child the child you want to add - */ - void addChildBone(Bone *child); - - /** - * Set parent bone. - * If parent is NUll, then also remove this bone from armature. - * It will not set the Armature, if you want to add the bone to a Armature, you should use Armature::addBone(Bone *bone, const char* parentName). - * - * @param parent the parent bone. - * NULL : remove this bone from armature - */ - void setParentBone(Bone *parent); - - /** - * Get parent bone - * @return parent bone - */ - Bone *getParentBone(); - - /** - * Remove itself from its parent. - * @param recursion whether or not to remove childBone's display - */ - void removeFromParent(bool recursion); - - /** - * Removes a child Bone - * @param bone the bone you want to remove - */ - void removeChildBone(Bone *bone, bool recursion); - - void update(float delta) override; - - virtual void updateDisplayedColor(const Color3B &parentColor) override; - virtual void updateDisplayedOpacity(GLubyte parentOpacity) override; - - virtual void setColor(const Color3B& color) override; - virtual void setOpacity(GLubyte opacity) override; - - //! Update color to render display - virtual void updateColor(); - - //! Update zorder - virtual void updateZOrder(); - - virtual void setZOrder(int zOrder) override; - - Tween *getTween(); - - /* - * Whether or not the bone's transform property changed. if true, the bone will update the transform. - */ - virtual void setTransformDirty(bool dirty); - - virtual bool isTransformDirty(); - - virtual AffineTransform getNodeToArmatureTransform() const; - virtual AffineTransform getNodeToWorldTransform() const override; - - Node *getDisplayRenderNode(); - - /* - * Get the ColliderBody list in this bone. The object in the Array is ColliderBody. - */ - virtual Array *getColliderBodyList(); - -public: - /* - * The origin state of the Bone. Display's state is effected by _boneData, m_pNode, _tweenData - * when call setData function, it will copy from the BoneData. - */ - CC_PROPERTY(BoneData *, _boneData, BoneData); - - //! A weak reference to the Armature - CC_PROPERTY(Armature *, _armature, Armature); - - //! A weak reference to the child Armature - CC_PROPERTY(Armature *, _childArmature, ChildArmature); - - CC_SYNTHESIZE(DisplayManager *, _displayManager, DisplayManager) - - /* - * When Armature play an animation, if there is not a MovementBoneData of this bone in this MovementData, this bone will be hidden. - * Set IgnoreMovementBoneData to true, then this bone will also be shown. - */ - CC_SYNTHESIZE(bool, _ignoreMovementBoneData, IgnoreMovementBoneData) - - CC_SYNTHESIZE(BlendType, _blendType, BlendType) -protected: - Tween *_tween; //! Calculate tween effect - - //! Used for making tween effect in every frame - CC_SYNTHESIZE_READONLY(FrameData *, _tweenData, TweenData); - - CC_SYNTHESIZE(std::string, _name, Name); - - Bone *_parentBone; //! A weak reference to its parent - bool _boneTransformDirty; //! Whether or not transform dirty - - //! self Transform, use this to change display's state - AffineTransform _worldTransform; -}; - -NS_CC_EXT_ARMATURE_END - -#endif /*__CCBONE_H__*/ diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp deleted file mode 100644 index ae69ea8230..0000000000 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "CCDisplayManager.h" -#include "../CCBone.h" -#include "../CCArmature.h" -#include "../utils/CCUtilMath.h" -#include "../display/CCSkin.h" - -NS_CC_EXT_ARMATURE_BEGIN - -DisplayManager *DisplayManager::create(Bone *bone) -{ - DisplayManager *pDisplayManager = new DisplayManager(); - if (pDisplayManager && pDisplayManager->init(bone)) - { - pDisplayManager->autorelease(); - return pDisplayManager; - } - CC_SAFE_DELETE(pDisplayManager); - return NULL; -} - - -DisplayManager::DisplayManager() - : _decoDisplayList(NULL) - , _displayRenderNode(NULL) - , _currentDecoDisplay(NULL) - , _displayIndex(-1) - , _forceChangeDisplay(false) - , _visible(true) - , _bone(NULL) -{ -} - -DisplayManager::~DisplayManager() -{ - CC_SAFE_DELETE(_decoDisplayList); - - if( _displayRenderNode ) - { - _displayRenderNode->removeFromParentAndCleanup(true); - if(_displayRenderNode->retainCount() > 0) - CC_SAFE_RELEASE_NULL(_displayRenderNode); - } - -} - -bool DisplayManager::init(Bone *bone) -{ - bool ret = false; - - do - { - - _bone = bone; - - initDisplayList(bone->getBoneData()); - - ret = true; - } - while (0); - - return ret; -} - - -void DisplayManager::addDisplay(DisplayData *displayData, int index) -{ - DecorativeDisplay *decoDisplay = NULL; - - if(index >= 0 && (unsigned int)index < _decoDisplayList->count()) - { - decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index); - } - else - { - decoDisplay = DecorativeDisplay::create(); - _decoDisplayList->addObject(decoDisplay); - } - - DisplayFactory::addDisplay(_bone, decoDisplay, displayData); - - //! if changed display index is current display index, then change current display to the new display - if(index == _displayIndex) - { - _displayIndex = -1; - changeDisplayByIndex(index, false); - } -} - -void DisplayManager::addDisplay(Node *display, int index) -{ - DecorativeDisplay *decoDisplay = NULL; - - if(index >= 0 && (unsigned int)index < _decoDisplayList->count()) - { - decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index); - } - else - { - decoDisplay = DecorativeDisplay::create(); - _decoDisplayList->addObject(decoDisplay); - } - - DisplayData *displayData = NULL; - if (Skin *skin = dynamic_cast(display)) - { - skin->setBone(_bone); - displayData = SpriteDisplayData::create(); - - DisplayFactory::initSpriteDisplay(_bone, decoDisplay, skin->getDisplayName().c_str(), skin); - - if (SpriteDisplayData *spriteDisplayData = (SpriteDisplayData *)decoDisplay->getDisplayData()) - { - skin->setSkinData(spriteDisplayData->skinData); - ((CCSpriteDisplayData *)displayData)->skinData = spriteDisplayData->skinData; - } - else - { - BaseData baseData; - skin->setSkinData(baseData); - } - } - else if (dynamic_cast(display)) - { - displayData = ParticleDisplayData::create(); - } - else if(Armature *armature = dynamic_cast(display)) - { - displayData = ArmatureDisplayData::create(); - armature->setParentBone(_bone); - } - else - { - displayData = DisplayData::create(); - } - - decoDisplay->setDisplay(display); - decoDisplay->setDisplayData(displayData); - - //! if changed display index is current display index, then change current display to the new display - if(index == _displayIndex) - { - _displayIndex = -1; - changeDisplayByIndex(index, false); - } -} - -void DisplayManager::removeDisplay(int index) -{ - _decoDisplayList->removeObjectAtIndex(index); - - if(index == _displayIndex) - { - setCurrentDecorativeDisplay(NULL); - } -} - -Array *DisplayManager::getDecorativeDisplayList() -{ - return _decoDisplayList; -} - -void DisplayManager::changeDisplayByIndex(int index, bool force) -{ - CCASSERT( (_decoDisplayList ? index < (int)_decoDisplayList->count() : true), "the _index value is out of range"); - - _forceChangeDisplay = force; - - //! If index is equal to current display index,then do nothing - if ( _displayIndex == index) - return; - - - _displayIndex = index; - - //! If displayIndex < 0, it means you want to hide you display - if (_displayIndex < 0) - { - if(_displayRenderNode) - { - _displayRenderNode->removeFromParentAndCleanup(true); - setCurrentDecorativeDisplay(NULL); - } - return; - } - - - DecorativeDisplay *decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(_displayIndex); - - setCurrentDecorativeDisplay(decoDisplay); -} - -void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay) -{ -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector()) - { - _currentDecoDisplay->getColliderDetector()->setActive(false); - } -#endif - - _currentDecoDisplay = decoDisplay; - -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector()) - { - _currentDecoDisplay->getColliderDetector()->setActive(true); - } -#endif - - Node *displayRenderNode = _currentDecoDisplay == NULL ? NULL : _currentDecoDisplay->getDisplay(); - if (_displayRenderNode) - { - if (dynamic_cast(_displayRenderNode) != NULL) - { - _bone->setChildArmature(NULL); - } - _displayRenderNode->removeFromParentAndCleanup(true); - _displayRenderNode->release(); - } - - _displayRenderNode = displayRenderNode; - - if(_displayRenderNode) - { - if (Armature *armature = dynamic_cast(_displayRenderNode)) - { - _bone->setChildArmature(armature); - } - else if (ParticleSystemQuad *particle = dynamic_cast(_displayRenderNode)) - { - particle->resetSystem(); - } - - if (RGBAProtocol *rgbaProtocaol = dynamic_cast(_displayRenderNode)) - { - rgbaProtocaol->setColor(_bone->getDisplayedColor()); - rgbaProtocaol->setOpacity(_bone->getDisplayedOpacity()); - } - - _displayRenderNode->retain(); - _displayRenderNode->setVisible(_visible); - } -} - -Node *DisplayManager::getDisplayRenderNode() -{ - return _displayRenderNode; -} - -int DisplayManager::getCurrentDisplayIndex() -{ - return _displayIndex; -} - -DecorativeDisplay *DisplayManager::getCurrentDecorativeDisplay() -{ - return _currentDecoDisplay; -} - -DecorativeDisplay *DisplayManager::getDecorativeDisplayByIndex( int index) -{ - return (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index); -} - -void DisplayManager::initDisplayList(BoneData *boneData) -{ - CC_SAFE_DELETE(_decoDisplayList); - _decoDisplayList = Array::create(); - _decoDisplayList->retain(); - - CS_RETURN_IF(!boneData); - - Object *object = NULL; - Array *displayDataList = &boneData->displayDataList; - CCARRAY_FOREACH(displayDataList, object) - { - DisplayData *displayData = (DisplayData *)object; - - DecorativeDisplay *decoDisplay = DecorativeDisplay::create(); - decoDisplay->setDisplayData(displayData); - - DisplayFactory::createDisplay(_bone, decoDisplay); - - _decoDisplayList->addObject(decoDisplay); - } -} - - -bool DisplayManager::containPoint(Point &point) -{ - if(!_visible || _displayIndex < 0) - { - return false; - } - - bool ret = false; - - switch (_currentDecoDisplay->getDisplayData()->displayType) - { - case CS_DISPLAY_SPRITE: - { - /* - * First we first check if the point is in the sprite content rect. If false, then we continue to check - * the contour point. If this step is also false, then we can say the bone not contain this point. - * - */ - - Point outPoint = Point(0, 0); - - Sprite *sprite = (Sprite *)_currentDecoDisplay->getDisplay(); - sprite = (Sprite *)sprite->getChildByTag(0); - - ret = CC_SPRITE_CONTAIN_POINT_WITH_RETURN(sprite, point, outPoint); - - } - break; - - default: - break; - } - return ret; -} - -bool DisplayManager::containPoint(float x, float y) -{ - Point p = Point(x, y); - return containPoint(p); -} - - -void DisplayManager::setVisible(bool visible) -{ - if(!_displayRenderNode) - return; - - _visible = visible; - _displayRenderNode->setVisible(visible); -} - -bool DisplayManager::isVisible() -{ - return _visible; -} - - -Size DisplayManager::getContentSize() -{ - CS_RETURN_IF(!_displayRenderNode) Size(0, 0); - return _displayRenderNode->getContentSize(); -} - -Rect DisplayManager::getBoundingBox() -{ - CS_RETURN_IF(!_displayRenderNode) Rect(0, 0, 0, 0); - return _displayRenderNode->getBoundingBox(); -} - - -Point DisplayManager::getAnchorPoint() -{ - CS_RETURN_IF(!_displayRenderNode) Point(0, 0); - return _displayRenderNode->getAnchorPoint(); -} - -Point DisplayManager::getAnchorPointInPoints() -{ - CS_RETURN_IF(!_displayRenderNode) Point(0, 0); - return _displayRenderNode->getAnchorPointInPoints(); -} - - -NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCSkin.cpp b/extensions/CocoStudio/Armature/display/CCSkin.cpp deleted file mode 100644 index a35bbffcbe..0000000000 --- a/extensions/CocoStudio/Armature/display/CCSkin.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "CCSkin.h" -#include "../utils/CCTransformHelp.h" -#include "../utils/CCSpriteFrameCacheHelper.h" -#include "../CCArmature.h" - -NS_CC_EXT_ARMATURE_BEGIN - -#if CC_SPRITEBATCHNODE_RENDER_SUBPIXEL -#define RENDER_IN_SUBPIXEL -#else -#define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__)) -#endif - -Skin *Skin::create() -{ - Skin *skin = new Skin(); - if(skin && skin->init()) - { - skin->autorelease(); - return skin; - } - CC_SAFE_DELETE(skin); - return NULL; -} - -Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName) -{ - Skin *skin = new Skin(); - if(skin && skin->initWithSpriteFrameName(pszSpriteFrameName)) - { - skin->autorelease(); - return skin; - } - CC_SAFE_DELETE(skin); - return NULL; -} - -Skin *Skin::create(const char *pszFileName) -{ - Skin *skin = new Skin(); - if(skin && skin->initWithFile(pszFileName)) - { - skin->autorelease(); - return skin; - } - CC_SAFE_DELETE(skin); - return NULL; -} - -Skin::Skin() - : _bone(NULL) - , _displayName("") -{ - _skinTransform = AffineTransformIdentity; -} - -bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) -{ - bool ret = Sprite::initWithSpriteFrameName(pszSpriteFrameName); - - if (ret) - { - TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); - setTextureAtlas(atlas); - - _displayName = pszSpriteFrameName; - } - - return ret; -} - -bool Skin::initWithFile(const char *pszFilename) -{ - bool ret = Sprite::initWithFile(pszFilename); - - if (ret) - { - TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); - setTextureAtlas(atlas); - - _displayName = pszFilename; - } - - return ret; -} - -void Skin::setSkinData(const BaseData &var) -{ - _skinData = var; - - setScaleX(_skinData.scaleX); - setScaleY(_skinData.scaleY); - setRotation(CC_RADIANS_TO_DEGREES(_skinData.skewX)); - setPosition(Point(_skinData.x, _skinData.y)); - - _skinTransform = getNodeToParentTransform(); - updateArmatureTransform(); -} - -const BaseData &Skin::getSkinData() const -{ - return _skinData; -} - -void Skin::updateArmatureTransform() -{ - _transform = AffineTransformConcat(_skinTransform, _bone->getNodeToArmatureTransform()); -} - -void Skin::updateTransform() -{ - // If it is not visible, or one of its ancestors is not visible, then do nothing: - if( !_visible) - { - _quad.br.vertices = _quad.tl.vertices = _quad.tr.vertices = _quad.bl.vertices = Vertex3F(0, 0, 0); - } - else - { - // - // calculate the Quad based on the Affine Matrix - // - - Size &size = _rect.size; - - float x1 = _offsetPosition.x; - float y1 = _offsetPosition.y; - - float x2 = x1 + size.width; - float y2 = y1 + size.height; - - float x = _transform.tx; - float y = _transform.ty; - - float cr = _transform.a; - float sr = _transform.b; - float cr2 = _transform.d; - float sr2 = -_transform.c; - float ax = x1 * cr - y1 * sr2 + x; - float ay = x1 * sr + y1 * cr2 + y; - - float bx = x2 * cr - y1 * sr2 + x; - float by = x2 * sr + y1 * cr2 + y; - - float cx = x2 * cr - y2 * sr2 + x; - float cy = x2 * sr + y2 * cr2 + y; - - float dx = x1 * cr - y2 * sr2 + x; - float dy = x1 * sr + y2 * cr2 + y; - - _quad.bl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), _vertexZ ); - _quad.br.vertices = Vertex3F( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), _vertexZ ); - _quad.tl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), _vertexZ ); - _quad.tr.vertices = Vertex3F( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _vertexZ ); - } - - // MARMALADE CHANGE: ADDED CHECK FOR NULL, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS - if (_textureAtlas) - { - _textureAtlas->updateQuad(&_quad, _textureAtlas->getTotalQuads()); - } -} - -AffineTransform Skin::getNodeToWorldTransform() const -{ - return AffineTransformConcat(_transform, _bone->getArmature()->getNodeToWorldTransform()); -} - -AffineTransform Skin::getNodeToWorldTransformAR() const -{ - AffineTransform displayTransform = _transform; - Point anchorPoint = _anchorPointInPoints; - - anchorPoint = PointApplyAffineTransform(anchorPoint, displayTransform); - - displayTransform.tx = anchorPoint.x; - displayTransform.ty = anchorPoint.y; - - return AffineTransformConcat(displayTransform, _bone->getArmature()->getNodeToWorldTransform()); -} - -NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDefine.cpp b/extensions/CocoStudio/Armature/utils/CCArmatureDefine.cpp deleted file mode 100644 index cbd53fe1e0..0000000000 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDefine.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "CCArmatureDefine.h" - -NS_CC_EXT_ARMATURE_BEGIN - -const char *armatureVersion() -{ - return "0.4.0.0"; -} - -NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp deleted file mode 100644 index 45b63c4db5..0000000000 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp +++ /dev/null @@ -1,1582 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "support/tinyxml2/tinyxml2.h" -#include "CCDataReaderHelper.h" -#include "CCArmatureDataManager.h" -#include "CCTransformHelp.h" -#include "CCUtilMath.h" -#include "CCArmatureDefine.h" -#include "../datas/CCDatas.h" - - -static const char *VERSION = "version"; -static const float VERSION_2_0 = 2.0f; - -static const char *ARMATURES = "armatures"; -static const char *ARMATURE = "armature"; -static const char *BONE = "b"; -static const char *DISPLAY = "d"; - -static const char *ANIMATIONS = "animations"; -static const char *ANIMATION = "animation"; -static const char *MOVEMENT = "mov"; -static const char *FRAME = "f"; - -static const char *TEXTURE_ATLAS = "TextureAtlas"; -static const char *SUB_TEXTURE = "SubTexture"; - -static const char *A_NAME = "name"; -static const char *A_DURATION = "dr"; -static const char *A_FRAME_INDEX = "fi"; -static const char *A_DURATION_TO = "to"; -static const char *A_DURATION_TWEEN = "drTW"; -static const char *A_LOOP = "lp"; -static const char *A_MOVEMENT_SCALE = "sc"; -static const char *A_MOVEMENT_DELAY = "dl"; -static const char *A_DISPLAY_INDEX = "dI"; - -// static const char *A_VERT = "vert"; -// static const char *A_FRAG = "frag"; -static const char *A_PLIST = "plist"; - -static const char *A_PARENT = "parent"; -static const char *A_SKEW_X = "kX"; -static const char *A_SKEW_Y = "kY"; -static const char *A_SCALE_X = "cX"; -static const char *A_SCALE_Y = "cY"; -static const char *A_Z = "z"; -static const char *A_EVENT = "evt"; -static const char *A_SOUND = "sd"; -static const char *A_SOUND_EFFECT = "sdE"; -static const char *A_TWEEN_EASING = "twE"; -//static const char *A_TWEEN_ROTATE = "twR"; -static const char *A_IS_ARMATURE = "isArmature"; -static const char *A_DISPLAY_TYPE = "displayType"; -static const char *A_MOVEMENT = "mov"; - -static const char *A_X = "x"; -static const char *A_Y = "y"; - -static const char *A_COCOS2DX_X = "cocos2d_x"; -static const char *A_COCOS2DX_Y = "cocos2d_y"; - -static const char *A_WIDTH = "width"; -static const char *A_HEIGHT = "height"; -static const char *A_PIVOT_X = "pX"; -static const char *A_PIVOT_Y = "pY"; - -static const char *A_COCOS2D_PIVOT_X = "cocos2d_pX"; -static const char *A_COCOS2D_PIVOT_Y = "cocos2d_pY"; - -static const char *A_BLEND_TYPE = "bd"; - -static const char *A_ALPHA = "a"; -static const char *A_RED = "r"; -static const char *A_GREEN = "g"; -static const char *A_BLUE = "b"; -static const char *A_ALPHA_OFFSET = "aM"; -static const char *A_RED_OFFSET = "rM"; -static const char *A_GREEN_OFFSET = "gM"; -static const char *A_BLUE_OFFSET = "bM"; -static const char *A_COLOR_TRANSFORM = "colorTransform"; -static const char *A_TWEEN_FRAME = "tweenFrame"; -//static const char *A_ROTATION = "rotation"; -//static const char *A_USE_COLOR_INFO = "uci"; - - - -static const char *CONTOUR = "con"; -static const char *CONTOUR_VERTEX = "con_vt"; - -//static const char *MOVEMENT_EVENT_FRAME = "movementEventFrame"; -//static const char *SOUND_FRAME = "soundFrame"; - - -static const char *FL_NAN = "NaN"; - - -static const char *FRAME_DATA = "frame_data"; -static const char *MOVEMENT_BONE_DATA = "mov_bone_data"; -static const char *MOVEMENT_DATA = "mov_data"; -static const char *ANIMATION_DATA = "animation_data"; -static const char *DISPLAY_DATA = "display_data"; -static const char *SKIN_DATA = "skin_data"; -static const char *BONE_DATA = "bone_data"; -static const char *ARMATURE_DATA = "armature_data"; -static const char *CONTOUR_DATA = "contour_data"; -static const char *TEXTURE_DATA = "texture_data"; -static const char *VERTEX_POINT = "vertex"; -static const char *COLOR_INFO = "color"; - -static const char *CONFIG_FILE_PATH = "config_file_path"; - - -NS_CC_EXT_ARMATURE_BEGIN - - -std::vector s_arrConfigFileList; -float s_PositionReadScale = 1; -static float s_FlashToolVersion = VERSION_2_0; -static float s_CocoStudioVersion = VERSION_COMBINED; - -static std::string s_BasefilePath = ""; - -DataReaderHelper *DataReaderHelper::_dataReaderHelper = NULL; - - - -//! Async load -void DataReaderHelper::loadData() -{ - AsyncStruct *pAsyncStruct = NULL; - - while (true) - { - // create autorelease pool for iOS - Thread thread; - thread.createAutoreleasePool(); - - std::queue *pQueue = _asyncStructQueue; - _asyncStructQueueMutex.lock(); // get async struct from queue - if (pQueue->empty()) - { - _asyncStructQueueMutex.unlock(); - if (need_quit) - { - break; - } - else - { - std::unique_lock lk(_sleepMutex); - _sleepCondition.wait(lk); - continue; - } - } - else - { - pAsyncStruct = pQueue->front(); - pQueue->pop(); - _asyncStructQueueMutex.unlock(); - } - - // generate image info - DataInfo *pDataInfo = new DataInfo(); - pDataInfo->asyncStruct = pAsyncStruct; - - if (pAsyncStruct->configType == DragonBone_XML) - { - DataReaderHelper::addDataFromCache(pAsyncStruct->fileContent.c_str(), pDataInfo); - } - else if(pAsyncStruct->configType == CocoStudio_JSON) - { - DataReaderHelper::addDataFromJsonCache(pAsyncStruct->fileContent.c_str(), pDataInfo); - } - - // put the image info into the queue - _dataInfoMutex.lock(); - _dataQueue->push(pDataInfo); - _dataInfoMutex.unlock(); - } - - if( _asyncStructQueue != NULL ) - { - delete _asyncStructQueue; - _asyncStructQueue = NULL; - delete _dataQueue; - _dataQueue = NULL; - } -} - - -DataReaderHelper *DataReaderHelper::getInstance() -{ - if(!_dataReaderHelper) - { - _dataReaderHelper = new DataReaderHelper(); - } - - return _dataReaderHelper; -} - -void DataReaderHelper::setPositionReadScale(float scale) -{ - s_PositionReadScale = scale; -} - -float DataReaderHelper::getPositionReadScale() -{ - return s_PositionReadScale; -} - - -void DataReaderHelper::purge() -{ - DataReaderHelper::clear(); - CC_SAFE_RELEASE_NULL(_dataReaderHelper); -} - -void DataReaderHelper::clear() -{ - s_arrConfigFileList.clear(); -} - -DataReaderHelper::DataReaderHelper() - : _loadingThread(nullptr) - , _asyncStructQueue(nullptr) - , _dataQueue(nullptr) - , need_quit(false) - , _asyncRefCount(0) - , _asyncRefTotalCount(0) -{ - -} - -DataReaderHelper::~DataReaderHelper() -{ - need_quit = true; - - _sleepCondition.notify_one(); - if (_loadingThread) _loadingThread->join(); - - CC_SAFE_DELETE(_loadingThread); - _dataReaderHelper = NULL; -} - -void DataReaderHelper::addDataFromFile(const char *filePath) -{ - /* - * Check if file is already added to ArmatureDataManager, if then return. - */ - for(unsigned int i = 0; i < s_arrConfigFileList.size(); i++) - { - if (s_arrConfigFileList[i].compare(filePath) == 0) - { - return; - } - } - s_arrConfigFileList.push_back(filePath); - - - //! find the base file path - s_BasefilePath = filePath; - size_t pos = s_BasefilePath.find_last_of("/"); - if (pos != std::string::npos) - { - s_BasefilePath = s_BasefilePath.substr(0, pos + 1); - } - else - { - s_BasefilePath = ""; - } - - - std::string filePathStr = filePath; - size_t startPos = filePathStr.find_last_of("."); - std::string str = &filePathStr[startPos]; - - unsigned long size; - std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); - const char *pFileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); - - if (str.compare(".xml") == 0) - { - DataReaderHelper::addDataFromCache(pFileContent); - } - else if(str.compare(".json") == 0 || str.compare(".ExportJson") == 0) - { - DataReaderHelper::addDataFromJsonCache(pFileContent); - } -} - -void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target, SEL_SCHEDULE selector) -{ - /* - * Check if file is already added to ArmatureDataManager, if then return. - */ - for(unsigned int i = 0; i < s_arrConfigFileList.size(); i++) - { - if (s_arrConfigFileList[i].compare(filePath) == 0) - { - if (target && selector) - { - if (_asyncRefTotalCount == 0 && _asyncRefCount == 0) - { - (target->*selector)(1); - } - else - { - (target->*selector)((_asyncRefTotalCount - _asyncRefCount) / (float)_asyncRefTotalCount); - } - } - return; - } - } - s_arrConfigFileList.push_back(filePath); - - //! find the base file path - s_BasefilePath = filePath; - size_t pos = s_BasefilePath.find_last_of("/"); - if (pos != std::string::npos) - { - s_BasefilePath = s_BasefilePath.substr(0, pos + 1); - } - else - { - s_BasefilePath = ""; - } - - - // lazy init - if (_asyncStructQueue == NULL) - { - _asyncStructQueue = new std::queue(); - _dataQueue = new std::queue(); - - // create a new thread to load images - _loadingThread = new std::thread(&DataReaderHelper::loadData, this); - - need_quit = false; - } - - if (0 == _asyncRefCount) - { - Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this, 0, false); - } - - ++_asyncRefCount; - ++_asyncRefTotalCount; - - if (target) - { - target->retain(); - } - - // generate async struct - AsyncStruct *data = new AsyncStruct(); - data->filename = filePath; - data->baseFilePath = s_BasefilePath; - data->target = target; - data->selector = selector; - data->autoLoadSpriteFile = ArmatureDataManager::getInstance()->isAutoLoadSpriteFile(); - - - std::string filePathStr = filePath; - size_t startPos = filePathStr.find_last_of("."); - std::string str = &filePathStr[startPos]; - - std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); - unsigned long size; - data->fileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); - - if (str.compare(".xml") == 0) - { - data->configType = DragonBone_XML; - } - else if(str.compare(".json") == 0 || str.compare(".ExportJson") == 0) - { - data->configType = CocoStudio_JSON; - } - - - // add async struct into queue - _asyncStructQueueMutex.lock(); - _asyncStructQueue->push(data); - _asyncStructQueueMutex.unlock(); - - _sleepCondition.notify_one(); -} - -void DataReaderHelper::addDataAsyncCallBack(float dt) -{ - // the data is generated in loading thread - std::queue *dataQueue = _dataQueue; - - _dataInfoMutex.lock(); - if (dataQueue->empty()) - { - _dataInfoMutex.unlock(); - } - else - { - DataInfo *pDataInfo = dataQueue->front(); - dataQueue->pop(); - _dataInfoMutex.unlock(); - - AsyncStruct *pAsyncStruct = pDataInfo->asyncStruct; - - while (!pDataInfo->configFileQueue.empty()) - { - std::string configPath = pDataInfo->configFileQueue.front(); - ArmatureDataManager::getInstance()->addSpriteFrameFromFile((pAsyncStruct->baseFilePath + configPath + ".plist").c_str(), (pAsyncStruct->baseFilePath + configPath + ".png").c_str()); - pDataInfo->configFileQueue.pop(); - } - - - Object *target = pAsyncStruct->target; - SEL_SCHEDULE selector = pAsyncStruct->selector; - - --_asyncRefCount; - - if (target && selector) - { - (target->*selector)((_asyncRefTotalCount - _asyncRefCount) / (float)_asyncRefTotalCount); - target->release(); - } - - - delete pAsyncStruct; - delete pDataInfo; - - if (0 == _asyncRefCount) - { - _asyncRefTotalCount = 0; - CCDirector::getInstance()->getScheduler()->unscheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this); - } - } -} - - - - - - -void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *dataInfo) -{ - tinyxml2::XMLDocument document; - document.Parse(pFileContent); - - tinyxml2::XMLElement *root = document.RootElement(); - CCASSERT(root, "XML error or XML is empty."); - - root->QueryFloatAttribute(VERSION, &s_FlashToolVersion); - - - /* - * Begin decode armature data from xml - */ - tinyxml2::XMLElement *armaturesXML = root->FirstChildElement(ARMATURES); - tinyxml2::XMLElement *armatureXML = armaturesXML->FirstChildElement(ARMATURE); - while(armatureXML) - { - ArmatureData *armatureData = DataReaderHelper::decodeArmature(armatureXML); - - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.lock(); - } - ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData); - armatureData->release(); - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.unlock(); - } - - armatureXML = armatureXML->NextSiblingElement(ARMATURE); - } - - - /* - * Begin decode animation data from xml - */ - tinyxml2::XMLElement *animationsXML = root->FirstChildElement(ANIMATIONS); - tinyxml2::XMLElement *animationXML = animationsXML->FirstChildElement(ANIMATION); - while(animationXML) - { - AnimationData *animationData = DataReaderHelper::decodeAnimation(animationXML); - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.lock(); - } - ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData); - animationData->release(); - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.unlock(); - } - animationXML = animationXML->NextSiblingElement(ANIMATION); - } - - - /* - * Begin decode texture data from xml - */ - tinyxml2::XMLElement *texturesXML = root->FirstChildElement(TEXTURE_ATLAS); - tinyxml2::XMLElement *textureXML = texturesXML->FirstChildElement(SUB_TEXTURE); - while(textureXML) - { - TextureData *textureData = DataReaderHelper::decodeTexture(textureXML); - - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.lock(); - } - ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData); - textureData->release(); - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.unlock(); - } - textureXML = textureXML->NextSiblingElement(SUB_TEXTURE); - } -} - -ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML) -{ - ArmatureData *armatureData = new ArmatureData(); - armatureData->init(); - - const char *name = armatureXML->Attribute(A_NAME); - armatureData->name = name; - - - tinyxml2::XMLElement *boneXML = armatureXML->FirstChildElement(BONE); - - while( boneXML ) - { - /* - * If this bone have parent, then get the parent bone xml - */ - const char *parentName = boneXML->Attribute(A_PARENT); - tinyxml2::XMLElement *parentXML = NULL; - if (parentName) - { - parentXML = armatureXML->FirstChildElement(BONE); - std::string name = parentName; - while (parentXML) - { - if (name.compare(parentXML->Attribute(A_NAME)) == 0) - { - break; - } - parentXML = parentXML->NextSiblingElement(BONE); - } - } - - BoneData *boneData = decodeBone(boneXML, parentXML); - armatureData->addBoneData(boneData); - boneData->release(); - - boneXML = boneXML->NextSiblingElement(BONE); - } - - return armatureData; -} - -BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXml) -{ - BoneData *boneData = new BoneData(); - boneData->init(); - - std::string name = boneXML->Attribute(A_NAME); - boneData->name = name; - - if( boneXML->Attribute(A_PARENT) != NULL ) - { - boneData->parentName = boneXML->Attribute(A_PARENT); - } - - boneXML->QueryIntAttribute(A_Z, &boneData->zOrder); - - tinyxml2::XMLElement *displayXML = boneXML->FirstChildElement(DISPLAY); - while(displayXML) - { - DisplayData *displayData = decodeBoneDisplay(displayXML); - boneData->addDisplayData(displayData); - displayData->release(); - - displayXML = displayXML->NextSiblingElement(DISPLAY); - } - - return boneData; -} - -DisplayData *DataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXML) -{ - int _isArmature = 0; - - DisplayData *displayData; - - if( displayXML->QueryIntAttribute(A_IS_ARMATURE, &(_isArmature)) == tinyxml2::XML_SUCCESS ) - { - if(!_isArmature) - { - displayData = new SpriteDisplayData(); - displayData->displayType = CS_DISPLAY_SPRITE; - } - else - { - displayData = new ArmatureDisplayData(); - displayData->displayType = CS_DISPLAY_ARMATURE; - } - - } - else - { - displayData = new SpriteDisplayData(); - displayData->displayType = CS_DISPLAY_SPRITE; - } - - - if(displayXML->Attribute(A_NAME) != NULL ) - { - if(!_isArmature) - { - ((SpriteDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); - } - else - { - ((ArmatureDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); - } - - } - - return displayData; -} - -AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animationXML) -{ - AnimationData *aniData = new AnimationData(); - - const char *name = animationXML->Attribute(A_NAME); - - ArmatureData *armatureData = ArmatureDataManager::getInstance()->getArmatureData(name); - - aniData->name = name; - - tinyxml2::XMLElement *movementXML = animationXML->FirstChildElement(MOVEMENT); - - while( movementXML ) - { - MovementData *movementData = decodeMovement(movementXML, armatureData); - aniData->addMovement(movementData); - movementData->release(); - - movementXML = movementXML->NextSiblingElement(MOVEMENT); - - } - - return aniData; -} - -MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, ArmatureData *armatureData) -{ - MovementData *movementData = new MovementData(); - - const char *movName = movementXML->Attribute(A_NAME); - movementData->name = movName; - - - int duration, durationTo, durationTween, loop, tweenEasing = 0; - - if( movementXML->QueryIntAttribute(A_DURATION, &(duration)) == tinyxml2::XML_SUCCESS) - { - movementData->duration = duration; - } - if( movementXML->QueryIntAttribute(A_DURATION_TO, &(durationTo)) == tinyxml2::XML_SUCCESS) - { - movementData->durationTo = durationTo; - } - if( movementXML->QueryIntAttribute(A_DURATION_TWEEN, &(durationTween)) == tinyxml2::XML_SUCCESS) - { - movementData->durationTween = durationTween; - } - if( movementXML->QueryIntAttribute(A_LOOP, &(loop)) == tinyxml2::XML_SUCCESS) - { - movementData->loop = (bool)loop; - } - - const char *_easing = movementXML->Attribute(A_TWEEN_EASING); - if(_easing != NULL) - { - std::string str = _easing; - if(str.compare(FL_NAN) != 0) - { - if( movementXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS) - { - movementData->tweenEasing = (CCTweenType)tweenEasing; - } - } - else - { - movementData->tweenEasing = TWEEN_EASING_MAX; - } - } - - tinyxml2::XMLElement *movBoneXml = movementXML->FirstChildElement(BONE); - while(movBoneXml) - { - const char *boneName = movBoneXml->Attribute(A_NAME); - - if (movementData->getMovementBoneData(boneName)) - { - movBoneXml = movBoneXml->NextSiblingElement(); - continue; - } - - - BoneData *boneData = (BoneData *)armatureData->getBoneData(boneName); - - std::string parentName = boneData->parentName; - - - tinyxml2::XMLElement *parentXml = NULL; - if (parentName.length() != 0) - { - parentXml = movementXML->FirstChildElement(BONE); - - while (parentXml) - { - if (parentName.compare(parentXml->Attribute(A_NAME)) == 0) - { - break; - } - parentXml = parentXml->NextSiblingElement(BONE); - } - } - - MovementBoneData *moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData); - movementData->addMovementBoneData(moveBoneData); - moveBoneData->release(); - - movBoneXml = movBoneXml->NextSiblingElement(BONE); - } - - return movementData; -} - - -MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, BoneData *boneData) -{ - MovementBoneData *movBoneData = new MovementBoneData(); - movBoneData->init(); - - float scale, delay; - - if( movBoneXml ) - { - if( movBoneXml->QueryFloatAttribute(A_MOVEMENT_SCALE, &scale) == tinyxml2::XML_SUCCESS ) - { - movBoneData->scale = scale; - } - if( movBoneXml->QueryFloatAttribute(A_MOVEMENT_DELAY, &delay) == tinyxml2::XML_SUCCESS ) - { - if(delay > 0) - { - delay -= 1; - } - movBoneData->delay = delay; - } - } - - int length = 0; - int i = 0; - int parentTotalDuration = 0; - int currentDuration = 0; - - tinyxml2::XMLElement *parentFrameXML = NULL; - - std::vector parentXmlList; - - /* - * get the parent frame xml list, we need get the origin data - */ - if( parentXml != NULL ) - { - parentFrameXML = parentXml->FirstChildElement(FRAME); - while (parentFrameXML) - { - parentXmlList.push_back(parentFrameXML); - parentFrameXML = parentFrameXML->NextSiblingElement(FRAME); - } - - parentFrameXML = NULL; - - length = parentXmlList.size(); - } - - - int totalDuration = 0; - - std::string name = movBoneXml->Attribute(A_NAME); - - movBoneData->name = name; - - tinyxml2::XMLElement *frameXML = movBoneXml->FirstChildElement(FRAME); - - while( frameXML ) - { - if(parentXml) - { - /* - * in this loop we get the corresponding parent frame xml - */ - while(i < length && (parentFrameXML ? (totalDuration < parentTotalDuration || totalDuration >= parentTotalDuration + currentDuration) : true)) - { - parentFrameXML = parentXmlList[i]; - parentTotalDuration += currentDuration; - parentFrameXML->QueryIntAttribute(A_DURATION, ¤tDuration); - i++; - - } - } - - FrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData); - movBoneData->addFrameData(frameData); - frameData->release(); - - frameData->frameID = totalDuration; - totalDuration += frameData->duration; - movBoneData->duration = totalDuration; - - frameXML = frameXML->NextSiblingElement(FRAME); - } - - - //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) - FrameData **frames = (FrameData **)movBoneData->frameList.data->arr; - for (int i = movBoneData->frameList.count() - 1; i >= 0; i--) - { - if (i > 0) - { - float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; - float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; - - if (difSkewX < -M_PI || difSkewX > M_PI) - { - frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; - } - - if (difSkewY < -M_PI || difSkewY > M_PI) - { - frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; - } - } - } - - - // - FrameData *frameData = new FrameData(); - frameData->copy((FrameData *)movBoneData->frameList.getLastObject()); - frameData->frameID = movBoneData->duration; - movBoneData->addFrameData(frameData); - frameData->release(); - - return movBoneData; -} - -FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, BoneData *boneData) -{ - float x, y, scale_x, scale_y, skew_x, skew_y = 0; - int duration, displayIndex, zOrder, tweenEasing, blendType = 0; - - FrameData *frameData = new FrameData(); - - if(frameXML->Attribute(A_MOVEMENT) != NULL) - { - frameData->strMovement = frameXML->Attribute(A_MOVEMENT); - } - if(frameXML->Attribute(A_EVENT) != NULL) - { - frameData->strEvent = frameXML->Attribute(A_EVENT); - } - if(frameXML->Attribute(A_SOUND) != NULL) - { - frameData->strSound = frameXML->Attribute(A_SOUND); - } - if(frameXML->Attribute(A_SOUND_EFFECT) != NULL) - { - frameData->strSoundEffect = frameXML->Attribute(A_SOUND_EFFECT); - } - - - - if (s_FlashToolVersion >= VERSION_2_0) - { - if(frameXML->QueryFloatAttribute(A_COCOS2DX_X, &x) == tinyxml2::XML_SUCCESS) - { - frameData->x = x; - frameData->x *= s_PositionReadScale; - } - if(frameXML->QueryFloatAttribute(A_COCOS2DX_Y, &y) == tinyxml2::XML_SUCCESS) - { - frameData->y = -y; - frameData->y *= s_PositionReadScale; - } - } - else - { - if(frameXML->QueryFloatAttribute(A_X, &x) == tinyxml2::XML_SUCCESS) - { - frameData->x = x; - frameData->x *= s_PositionReadScale; - } - if(frameXML->QueryFloatAttribute(A_Y, &y) == tinyxml2::XML_SUCCESS) - { - frameData->y = -y; - frameData->y *= s_PositionReadScale; - } - } - - if( frameXML->QueryFloatAttribute(A_SCALE_X, &scale_x) == tinyxml2::XML_SUCCESS ) - { - frameData->scaleX = scale_x; - } - if( frameXML->QueryFloatAttribute(A_SCALE_Y, &scale_y) == tinyxml2::XML_SUCCESS ) - { - frameData->scaleY = scale_y; - } - if( frameXML->QueryFloatAttribute(A_SKEW_X, &skew_x) == tinyxml2::XML_SUCCESS ) - { - frameData->skewX = CC_DEGREES_TO_RADIANS(skew_x); - } - if( frameXML->QueryFloatAttribute(A_SKEW_Y, &skew_y) == tinyxml2::XML_SUCCESS ) - { - frameData->skewY = CC_DEGREES_TO_RADIANS(-skew_y); - } - if( frameXML->QueryIntAttribute(A_DURATION, &duration) == tinyxml2::XML_SUCCESS ) - { - frameData->duration = duration; - } - if( frameXML->QueryIntAttribute(A_DISPLAY_INDEX, &displayIndex) == tinyxml2::XML_SUCCESS ) - { - frameData->displayIndex = displayIndex; - } - if( frameXML->QueryIntAttribute(A_Z, &zOrder) == tinyxml2::XML_SUCCESS ) - { - frameData->zOrder = zOrder; - } - if ( frameXML->QueryIntAttribute(A_BLEND_TYPE, &blendType) == tinyxml2::XML_SUCCESS ) - { - frameData->blendType = (BlendType)blendType; - } - - tinyxml2::XMLElement *colorTransformXML = frameXML->FirstChildElement(A_COLOR_TRANSFORM); - if (colorTransformXML) - { - int alpha, red, green, blue = 100; - int alphaOffset, redOffset, greenOffset, blueOffset = 0; - - colorTransformXML->QueryIntAttribute(A_ALPHA, &alpha); - colorTransformXML->QueryIntAttribute(A_RED, &red); - colorTransformXML->QueryIntAttribute(A_GREEN, &green); - colorTransformXML->QueryIntAttribute(A_BLUE, &blue) ; - - colorTransformXML->QueryIntAttribute(A_ALPHA_OFFSET, &alphaOffset); - colorTransformXML->QueryIntAttribute(A_RED_OFFSET, &redOffset); - colorTransformXML->QueryIntAttribute(A_GREEN_OFFSET, &greenOffset); - colorTransformXML->QueryIntAttribute(A_BLUE_OFFSET, &blueOffset) ; - - frameData->a = 2.55 * alphaOffset + alpha; - frameData->r = 2.55 * redOffset + red; - frameData->g = 2.55 * greenOffset + green; - frameData->b = 2.55 * blueOffset + blue; - - frameData->isUseColorInfo = true; - } - - - const char *_easing = frameXML->Attribute(A_TWEEN_EASING); - if(_easing != NULL) - { - std::string str = _easing; - if(str.compare(FL_NAN) != 0) - { - if( frameXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS) - { - frameData->tweenEasing = (CCTweenType)tweenEasing; - } - } - else - { - frameData->tweenEasing = TWEEN_EASING_MAX; - } - } - - if(parentFrameXml) - { - /* - * recalculate frame data from parent frame data, use for translate matrix - */ - BaseData helpNode; - if (s_FlashToolVersion >= VERSION_2_0) - { - parentFrameXml->QueryFloatAttribute(A_COCOS2DX_X, &helpNode.x); - parentFrameXml->QueryFloatAttribute(A_COCOS2DX_Y, &helpNode.y); - } - else - { - parentFrameXml->QueryFloatAttribute(A_X, &helpNode.x); - parentFrameXml->QueryFloatAttribute(A_Y, &helpNode.y); - } - - - parentFrameXml->QueryFloatAttribute(A_SKEW_X, &helpNode.skewX); - parentFrameXml->QueryFloatAttribute(A_SKEW_Y, &helpNode.skewY); - - helpNode.y = -helpNode.y; - helpNode.skewX = CC_DEGREES_TO_RADIANS(helpNode.skewX); - helpNode.skewY = CC_DEGREES_TO_RADIANS(-helpNode.skewY); - - TransformHelp::transformFromParent(*frameData, helpNode); - } - return frameData; -} - -TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) -{ - TextureData *textureData = new TextureData(); - textureData->init(); - - if( textureXML->Attribute(A_NAME) != NULL) - { - textureData->name = textureXML->Attribute(A_NAME); - } - - float px, py, width, height = 0; - - if(s_FlashToolVersion >= VERSION_2_0) - { - textureXML->QueryFloatAttribute(A_COCOS2D_PIVOT_X, &px); - textureXML->QueryFloatAttribute(A_COCOS2D_PIVOT_Y, &py); - } - else - { - textureXML->QueryFloatAttribute(A_PIVOT_X, &px); - textureXML->QueryFloatAttribute(A_PIVOT_Y, &py); - } - - textureXML->QueryFloatAttribute(A_WIDTH, &width); - textureXML->QueryFloatAttribute(A_HEIGHT, &height); - - float anchorPointX = px / width; - float anchorPointY = (height - py) / height; - - textureData->pivotX = anchorPointX; - textureData->pivotY = anchorPointY; - - tinyxml2::XMLElement *contourXML = textureXML->FirstChildElement(CONTOUR); - - while (contourXML) - { - ContourData *contourData = decodeContour(contourXML); - textureData->addContourData(contourData); - contourData->release(); - - contourXML = contourXML->NextSiblingElement(CONTOUR); - } - - return textureData; -} - -ContourData *DataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML) -{ - ContourData *contourData = new ContourData(); - contourData->init(); - - tinyxml2::XMLElement *vertexDataXML = contourXML->FirstChildElement(CONTOUR_VERTEX); - - while (vertexDataXML) - { - ContourVertex2 *vertex = new ContourVertex2(0, 0); - vertex->release(); - - vertexDataXML->QueryFloatAttribute(A_X, &vertex->x); - vertexDataXML->QueryFloatAttribute(A_Y, &vertex->y); - - vertex->y = -vertex->y; - contourData->vertexList.addObject(vertex); - - vertexDataXML = vertexDataXML->NextSiblingElement(CONTOUR_VERTEX); - } - - return contourData; -} - - - -void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo) -{ - cs::JsonDictionary json; - json.initWithDescription(fileContent); - - // Decode armatures - int length = json.getArrayItemCount(ARMATURE_DATA); - for (int i = 0; i < length; i++) - { - cs::JsonDictionary *armatureDic = json.getSubItemFromArray(ARMATURE_DATA, i); - ArmatureData *armatureData = decodeArmature(*armatureDic); - - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.lock(); - } - ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData); - armatureData->release(); - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.unlock(); - } - delete armatureDic; - } - - // Decode animations - length = json.getArrayItemCount(ANIMATION_DATA); - for (int i = 0; i < length; i++) - { - cs::JsonDictionary *animationDic = json.getSubItemFromArray(ANIMATION_DATA, i); - AnimationData *animationData = decodeAnimation(*animationDic); - - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.lock(); - } - ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData); - animationData->release(); - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.unlock(); - } - delete animationDic; - } - - // Decode textures - length = json.getArrayItemCount(TEXTURE_DATA); - for (int i = 0; i < length; i++) - { - cs::JsonDictionary *textureDic = json.getSubItemFromArray(TEXTURE_DATA, i); - TextureData *textureData = decodeTexture(*textureDic); - - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.lock(); - } - ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData); - textureData->release(); - if (dataInfo) - { - _dataReaderHelper->_addDataMutex.unlock(); - } - delete textureDic; - } - - // Auto load sprite file - bool autoLoad = dataInfo == NULL ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; - if (autoLoad) - { - length = json.getArrayItemCount(CONFIG_FILE_PATH); - for (int i = 0; i < length; i++) - { - const char *path = json.getStringValueFromArray(CONFIG_FILE_PATH, i); - if (path == NULL) - { - CCLOG("load CONFIG_FILE_PATH error."); - return; - } - - std::string filePath = path; - filePath = filePath.erase(filePath.find_last_of(".")); - - if (dataInfo != NULL) - { - dataInfo->configFileQueue.push(filePath); - } - else - { - std::string plistPath = filePath + ".plist"; - std::string pngPath = filePath + ".png"; - - ArmatureDataManager::getInstance()->addSpriteFrameFromFile((s_BasefilePath + plistPath).c_str(), (s_BasefilePath + pngPath).c_str()); - } - } - } -} - -ArmatureData *DataReaderHelper::decodeArmature(cs::JsonDictionary &json) -{ - ArmatureData *armatureData = new ArmatureData(); - armatureData->init(); - - const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) - { - armatureData->name = name; - } - - s_CocoStudioVersion = armatureData->dataVersion = json.getItemFloatValue(VERSION, 0.1f); - - int length = json.getArrayItemCount(BONE_DATA); - for (int i = 0; i < length; i++) - { - cs::JsonDictionary *dic = json.getSubItemFromArray(BONE_DATA, i); - BoneData *boneData = decodeBone(*dic); - armatureData->addBoneData(boneData); - boneData->release(); - - delete dic; - } - - return armatureData; -} - -BoneData *DataReaderHelper::decodeBone(cs::JsonDictionary &json) -{ - BoneData *boneData = new BoneData(); - boneData->init(); - - decodeNode(boneData, json); - - const char *str = json.getItemStringValue(A_NAME); - if(str != NULL) - { - boneData->name = str; - } - - str = json.getItemStringValue(A_PARENT); - if(str != NULL) - { - boneData->parentName = str; - } - - int length = json.getArrayItemCount(DISPLAY_DATA); - - for (int i = 0; i < length; i++) - { - cs::JsonDictionary *dic = json.getSubItemFromArray(DISPLAY_DATA, i); - DisplayData *displayData = decodeBoneDisplay(*dic); - boneData->addDisplayData(displayData); - displayData->release(); - - delete dic; - } - - return boneData; -} - -DisplayData *DataReaderHelper::decodeBoneDisplay(cs::JsonDictionary &json) -{ - DisplayType displayType = (DisplayType)json.getItemIntValue(A_DISPLAY_TYPE, CS_DISPLAY_SPRITE); - - DisplayData *displayData = NULL; - - switch (displayType) - { - case CS_DISPLAY_SPRITE: - { - displayData = new SpriteDisplayData(); - - const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) - { - ((SpriteDisplayData *)displayData)->displayName = name; - } - - cs::JsonDictionary *dic = json.getSubItemFromArray(SKIN_DATA, 0); - if (dic != NULL) - { - SpriteDisplayData *sdd = (SpriteDisplayData *)displayData; - sdd->skinData.x = dic->getItemFloatValue(A_X, 0) * s_PositionReadScale; - sdd->skinData.y = dic->getItemFloatValue(A_Y, 0) * s_PositionReadScale; - sdd->skinData.scaleX = dic->getItemFloatValue(A_SCALE_X, 1); - sdd->skinData.scaleY = dic->getItemFloatValue(A_SCALE_Y, 1); - sdd->skinData.skewX = dic->getItemFloatValue(A_SKEW_X, 0); - sdd->skinData.skewY = dic->getItemFloatValue(A_SKEW_Y, 0); - delete dic; - } - } - - break; - case CS_DISPLAY_ARMATURE: - { - displayData = new ArmatureDisplayData(); - - const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) - { - ((ArmatureDisplayData *)displayData)->displayName = name; - } - } - break; - case CS_DISPLAY_PARTICLE: - { - displayData = new ParticleDisplayData(); - - const char *plist = json.getItemStringValue(A_PLIST); - if(plist != NULL) - { - ((ParticleDisplayData *)displayData)->plist = s_BasefilePath + plist; - } - } - break; - default: - displayData = new SpriteDisplayData(); - - break; - } - - - displayData->displayType = displayType; - - return displayData; -} - -AnimationData *DataReaderHelper::decodeAnimation(cs::JsonDictionary &json) -{ - AnimationData *aniData = new AnimationData(); - - const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) - { - aniData->name = name; - } - - int length = json.getArrayItemCount(MOVEMENT_DATA); - - for (int i = 0; i < length; i++) - { - cs::JsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_DATA, i); - MovementData *movementData = decodeMovement(*dic); - aniData->addMovement(movementData); - movementData->release(); - - delete dic; - } - - return aniData; -} - -MovementData *DataReaderHelper::decodeMovement(cs::JsonDictionary &json) -{ - MovementData *movementData = new MovementData(); - - movementData->loop = json.getItemBoolvalue(A_LOOP, true); - movementData->durationTween = json.getItemIntValue(A_DURATION_TWEEN, 0); - movementData->durationTo = json.getItemIntValue(A_DURATION_TO, 0); - movementData->duration = json.getItemIntValue(A_DURATION, 0); - movementData->scale = json.getItemFloatValue(A_MOVEMENT_SCALE, 1); - movementData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); - - const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) - { - movementData->name = name; - } - - int length = json.getArrayItemCount(MOVEMENT_BONE_DATA); - for (int i = 0; i < length; i++) - { - cs::JsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_BONE_DATA, i); - MovementBoneData *movementBoneData = decodeMovementBone(*dic); - movementData->addMovementBoneData(movementBoneData); - movementBoneData->release(); - - delete dic; - } - - return movementData; -} - -MovementBoneData *DataReaderHelper::decodeMovementBone(cs::JsonDictionary &json) -{ - MovementBoneData *movementBoneData = new MovementBoneData(); - movementBoneData->init(); - - movementBoneData->delay = json.getItemFloatValue(A_MOVEMENT_DELAY, 0); - - const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) - { - movementBoneData->name = name; - } - - int length = json.getArrayItemCount(FRAME_DATA); - for (int i = 0; i < length; i++) - { - cs::JsonDictionary *dic = json.getSubItemFromArray(FRAME_DATA, i); - FrameData *frameData = decodeFrame(*dic); - - movementBoneData->addFrameData(frameData); - frameData->release(); - - if (s_CocoStudioVersion < VERSION_COMBINED) - { - frameData->frameID = movementBoneData->duration; - movementBoneData->duration += frameData->duration; - } - - delete dic; - } - - - if (s_CocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE) - { - //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) - CCFrameData **frames = (CCFrameData **)movementBoneData->frameList.data->arr; - for (int i = movementBoneData->frameList.count() - 1; i >= 0; i--) - { - if (i > 0) - { - float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; - float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; - - if (difSkewX < -M_PI || difSkewX > M_PI) - { - frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; - } - - if (difSkewY < -M_PI || difSkewY > M_PI) - { - frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; - } - } - } - } - - if (s_CocoStudioVersion < VERSION_COMBINED) - { - if (movementBoneData->frameList.count() > 0) - { - FrameData *frameData = new FrameData(); - frameData->copy((FrameData *)movementBoneData->frameList.getLastObject()); - movementBoneData->addFrameData(frameData); - frameData->release(); - - frameData->frameID = movementBoneData->duration; - } - } - - return movementBoneData; -} - -FrameData *DataReaderHelper::decodeFrame(cs::JsonDictionary &json) -{ - FrameData *frameData = new FrameData(); - - decodeNode(frameData, json); - - frameData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); - frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0); - frameData->blendType = (BlendType)json.getItemIntValue(A_BLEND_TYPE, 0); - frameData->isTween = (bool)json.getItemBoolvalue(A_TWEEN_FRAME, true); - - const char *event = json.getItemStringValue(A_EVENT); - if (event != NULL) - { - frameData->strEvent = event; - } - - if (s_CocoStudioVersion < VERSION_COMBINED) - { - frameData->duration = json.getItemIntValue(A_DURATION, 1); - } - else - { - frameData->frameID = json.getItemIntValue(A_FRAME_INDEX, 0); - } - - return frameData; -} - -TextureData *DataReaderHelper::decodeTexture(cs::JsonDictionary &json) -{ - TextureData *textureData = new TextureData(); - textureData->init(); - - const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) - { - textureData->name = name; - } - - textureData->width = json.getItemFloatValue(A_WIDTH, 0); - textureData->height = json.getItemFloatValue(A_HEIGHT, 0); - textureData->pivotX = json.getItemFloatValue(A_PIVOT_X, 0); - textureData->pivotY = json.getItemFloatValue(A_PIVOT_Y, 0); - - int length = json.getArrayItemCount(CONTOUR_DATA); - for (int i = 0; i < length; i++) - { - cs::JsonDictionary *dic = json.getSubItemFromArray(CONTOUR_DATA, i); - ContourData *contourData = decodeContour(*dic); - textureData->contourDataList.addObject(contourData); - contourData->release(); - - delete dic; - } - - return textureData; -} - -ContourData *DataReaderHelper::decodeContour(cs::JsonDictionary &json) -{ - ContourData *contourData = new ContourData(); - contourData->init(); - - int length = json.getArrayItemCount(VERTEX_POINT); - for (int i = length - 1; i >= 0; i--) - { - cs::JsonDictionary *dic = json.getSubItemFromArray(VERTEX_POINT, i); - - ContourVertex2 *vertex = new ContourVertex2(0, 0); - - vertex->x = dic->getItemFloatValue(A_X, 0); - vertex->y = dic->getItemFloatValue(A_Y, 0); - - contourData->vertexList.addObject(vertex); - vertex->release(); - - delete dic; - } - - return contourData; -} - -void DataReaderHelper::decodeNode(BaseData *node, cs::JsonDictionary &json) -{ - node->x = json.getItemFloatValue(A_X, 0) * s_PositionReadScale; - node->y = json.getItemFloatValue(A_Y, 0) * s_PositionReadScale; - node->zOrder = json.getItemIntValue(A_Z, 0); - - node->skewX = json.getItemFloatValue(A_SKEW_X, 0); - node->skewY = json.getItemFloatValue(A_SKEW_Y, 0); - node->scaleX = json.getItemFloatValue(A_SCALE_X, 1); - node->scaleY = json.getItemFloatValue(A_SCALE_Y, 1); - - cs::JsonDictionary *colorDic = json.getSubItemFromArray(COLOR_INFO, 0); - - if (colorDic) - { - node->a = colorDic->getItemIntValue(A_ALPHA, 255); - node->r = colorDic->getItemIntValue(A_RED, 255); - node->g = colorDic->getItemIntValue(A_GREEN, 255); - node->b = colorDic->getItemIntValue(A_BLUE, 255); - - node->isUseColorInfo = true; - - delete colorDic; - } - -} - -NS_CC_EXT_ARMATURE_END diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 0b662d9c15..b571dfb808 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -15,7 +15,7 @@ static int s_nActionIdx = -1; Layer *CreateLayer(int index) { - Layer *pLayer = NULL; + Layer *pLayer = nullptr; switch(index) { case TEST_ASYNCHRONOUS_LOADING: @@ -167,7 +167,7 @@ void ArmatureTestLayer::onEnter() restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(ArmatureTestLayer::restartCallback, this) ); nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(ArmatureTestLayer::nextCallback, this) ); - Menu *menu = Menu::create(backItem, restartItem, nextItem, NULL); + Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr); menu->setPosition(Point::ZERO); backItem->setPosition(Point(VisibleRect::center().x - restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2)); @@ -183,7 +183,7 @@ void ArmatureTestLayer::onExit() { removeAllChildren(); - backItem = restartItem = nextItem = NULL; + backItem = restartItem = nextItem = nullptr; Layer::onExit(); } @@ -319,7 +319,7 @@ std::string TestDirectLoading::title() void TestCSWithSkeleton::onEnter() { ArmatureTestLayer::onEnter(); - Armature *armature = NULL; + Armature *armature = nullptr; armature = Armature::create("Cowboy"); armature->getAnimation()->playByIndex(0); armature->setScale(0.2f); @@ -340,7 +340,7 @@ void TestDragonBones20::onEnter() { ArmatureTestLayer::onEnter(); - Armature *armature = NULL; + Armature *armature = nullptr; armature = Armature::create("Dragon"); armature->getAnimation()->playByIndex(1); armature->getAnimation()->setSpeedScale(0.4f); @@ -372,7 +372,7 @@ void TestPerformance::onEnter() MenuItemFont *increase = MenuItemFont::create(" + ", CC_CALLBACK_1(TestPerformance::onIncrease, this)); increase->setColor(Color3B(0,200,20)); - Menu *menu = Menu::create(decrease, increase, NULL); + Menu *menu = Menu::create(decrease, increase, nullptr); menu->alignItemsHorizontally(); menu->setPosition(Point(VisibleRect::getVisibleRect().size.width/2, VisibleRect::getVisibleRect().size.height-100)); addChild(menu, 10000); @@ -413,7 +413,7 @@ void TestPerformance::addArmature(int number) { armatureCount++; - Armature *armature = NULL; + Armature *armature = nullptr; armature = new Armature(); armature->init("Knight_f/Knight"); armature->getAnimation()->playByIndex(0); @@ -467,7 +467,7 @@ void TestChangeZorder::onEnter() { ArmatureTestLayer::onEnter(); - Armature *armature = NULL; + Armature *armature = nullptr; currentTag = -1; armature = Armature::create("Knight_f/Knight"); @@ -524,7 +524,7 @@ void TestAnimationEvent::onEnter() /* * Set armature's movement event callback function - * To disconnect this event, just setMovementEventCallFunc(NULL, NULL); + * To disconnect this event, just setMovementEventCallFunc(nullptr, nullptr); */ armature->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(TestAnimationEvent::animationEvent)); addChild(armature); @@ -543,14 +543,14 @@ void TestAnimationEvent::animationEvent(Armature *armature, MovementEventType mo { ActionInterval *actionToRight = MoveTo::create(2, Point(VisibleRect::right().x - 50, VisibleRect::right().y)); armature->stopAllActions(); - armature->runAction(Sequence::create(actionToRight, CallFunc::create( CC_CALLBACK_0(TestAnimationEvent::callback1, this)), NULL)); + armature->runAction(Sequence::create(actionToRight, CallFunc::create( CC_CALLBACK_0(TestAnimationEvent::callback1, this)), nullptr)); armature->getAnimation()->play("Walk"); } else if (id.compare("FireMax") == 0) { ActionInterval *actionToLeft = MoveTo::create(2, Point(VisibleRect::left().x + 50, VisibleRect::left().y)); armature->stopAllActions(); - armature->runAction(Sequence::create(actionToLeft, CallFunc::create( CC_CALLBACK_0(TestAnimationEvent::callback2, this)), NULL)); + armature->runAction(Sequence::create(actionToLeft, CallFunc::create( CC_CALLBACK_0(TestAnimationEvent::callback2, this)), nullptr)); armature->getAnimation()->play("Walk"); } } @@ -580,7 +580,7 @@ void TestFrameEvent::onEnter() /* * Set armature's frame event callback function - * To disconnect this event, just setFrameEventCallFunc(NULL, NULL); + * To disconnect this event, just setFrameEventCallFunc(nullptr, nullptr); */ armature->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(TestFrameEvent::onFrameEvent)); @@ -608,8 +608,8 @@ void TestFrameEvent::onFrameEvent(Bone *bone, const char *evt, int originFrameIn } void TestFrameEvent::checkAction(float dt) { - if ( this->numberOfRunningActions() == 0 && this->getGrid() != NULL) - this->setGrid(NULL); + if ( this->numberOfRunningActions() == 0 && this->getGrid() != nullptr) + this->setGrid(nullptr); } @@ -750,7 +750,7 @@ void TestColliderDetector::onEnter() /* * Set armature's frame event callback function - * To disconnect this event, just setFrameEventCallFunc(NULL, NULL); + * To disconnect this event, just setFrameEventCallFunc(nullptr, nullptr); */ armature->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(TestColliderDetector::onFrameEvent)); @@ -1011,7 +1011,7 @@ void TestColliderDetector::initWorld() ColliderFilter filter = ColliderFilter(eEnemyTag); armature2->setColliderFilter(&filter); - cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, NULL, NULL, endHit, NULL); + cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, nullptr, nullptr, endHit, nullptr); } #endif @@ -1106,7 +1106,7 @@ void TestArmatureNesting::onTouchesEnded(const std::vector& touches, Eve ++weaponIndex; weaponIndex = weaponIndex % 4; - if(armature != NULL) + if(armature != nullptr) { armature->getBone("armInside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); armature->getBone("armOutside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); @@ -1125,18 +1125,18 @@ Hero *Hero::create(const char *name) return hero; } CC_SAFE_DELETE(hero); - return NULL; + return nullptr; } Hero::Hero() - : m_pMount(NULL) - , m_pLayer(NULL) + : m_pMount(nullptr) + , m_pLayer(nullptr) { } void Hero::changeMount(Armature *armature) { - if (armature == NULL) + if (armature == nullptr) { retain(); @@ -1203,7 +1203,7 @@ void TestArmatureNesting2::onEnter() LabelTTF* label = CCLabelTTF::create("Change Mount", "Arial", 20); MenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, CC_CALLBACK_1(TestArmatureNesting2::ChangeMountCallback, this)); - Menu* pMenu =Menu::create(pMenuItem, NULL); + Menu* pMenu =Menu::create(pMenuItem, nullptr); pMenu->setPosition( Point() ); pMenuItem->setPosition( Point( VisibleRect::right().x - 67, VisibleRect::bottom().y + 50) ); @@ -1241,7 +1241,7 @@ void TestArmatureNesting2::onTouchesEnded(const std::vector& touches, Ev { Point point = touches[0]->getLocation(); - Armature *armature = hero->getMount() == NULL ? hero : hero->getMount(); + Armature *armature = hero->getMount() == nullptr ? hero : hero->getMount(); //Set armature direction if (point.x < armature->getPositionX()) @@ -1255,7 +1255,7 @@ void TestArmatureNesting2::onTouchesEnded(const std::vector& touches, Ev ActionInterval *move = CCMoveTo::create(2, point); armature->stopAllActions(); - armature->runAction(Sequence::create(move, NULL)); + armature->runAction(Sequence::create(move, nullptr)); } void TestArmatureNesting2::ChangeMountCallback(Object* pSender) @@ -1264,7 +1264,7 @@ void TestArmatureNesting2::ChangeMountCallback(Object* pSender) if (hero->getMount()) { - hero->changeMount(NULL); + hero->changeMount(nullptr); } else { From 16c23d0ad3ca414b206232e0082222b40f65f97d Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Tue, 5 Nov 2013 19:53:38 +0800 Subject: [PATCH 16/39] remove CC_PROPERTY and CC_SYNTHESIZE. --- .../editor-support/cocostudio/CCArmature.cpp | 16 ++--- cocos/editor-support/cocostudio/CCArmature.h | 62 ++++++++++------ .../cocostudio/CCArmatureAnimation.cpp | 12 ++-- .../cocostudio/CCArmatureAnimation.h | 18 +++-- .../editor-support/cocostudio/CCBatchNode.cpp | 6 +- cocos/editor-support/cocostudio/CCBatchNode.h | 16 ++--- cocos/editor-support/cocostudio/CCBone.cpp | 8 +-- cocos/editor-support/cocostudio/CCBone.h | 64 +++++++++++------ .../cocostudio/CCColliderDetector.cpp | 4 +- .../cocostudio/CCColliderDetector.h | 72 ++++++++++++++----- .../cocostudio/CCDecorativeDisplay.h | 41 +++++++++-- .../cocostudio/CCDisplayManager.cpp | 22 +++--- .../cocostudio/CCDisplayManager.h | 26 +++---- .../editor-support/cocostudio/CCProcessBase.h | 35 ++++++--- cocos/editor-support/cocostudio/CCSkin.cpp | 2 +- cocos/editor-support/cocostudio/CCSkin.h | 20 ++++-- cocos/editor-support/cocostudio/CCTween.cpp | 2 +- cocos/editor-support/cocostudio/CCTween.h | 5 +- .../CocoStudioArmatureTest/ArmatureScene.cpp | 8 +-- .../CocoStudioArmatureTest/ArmatureScene.h | 2 +- 20 files changed, 297 insertions(+), 144 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index be5c9d0c33..7cd7ad9295 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -335,7 +335,7 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName) } } -Dictionary *Armature::getBoneDic() +const Dictionary *Armature::getBoneDic() const { return _boneDic; } @@ -437,12 +437,12 @@ void Armature::setAnimation(ArmatureAnimation *animation) _animation = animation; } -ArmatureAnimation *Armature::getAnimation() +ArmatureAnimation *Armature::getAnimation() const { return _animation; } -bool Armature::getArmatureTransformDirty() +bool Armature::getArmatureTransformDirty() const { return _armatureTransformDirty; } @@ -673,7 +673,7 @@ Rect Armature::getBoundingBox() const return RectApplyAffineTransform(boundingBox, getNodeToParentTransform()); } -Bone *Armature::getBoneAtPoint(float x, float y) +Bone *Armature::getBoneAtPoint(float x, float y) const { int length = _children->count(); Bone *bs; @@ -689,7 +689,7 @@ Bone *Armature::getBoneAtPoint(float x, float y) return nullptr; } -TextureAtlas *Armature::getTexureAtlasWithTexture(Texture2D *texture) +TextureAtlas *Armature::getTexureAtlasWithTexture(Texture2D *texture) const { int key = texture->getName(); @@ -723,7 +723,7 @@ void Armature::setParentBone(Bone *parentBone) } } -Bone *Armature::getParentBone() +Bone *Armature::getParentBone() const { return _parentBone; } @@ -739,7 +739,7 @@ void CCArmature::setColliderFilter(ColliderFilter *filter) } #if ENABLE_PHYSICS_BOX2D_DETECT -b2Body *Armature::getBody() +b2Body *Armature::getBody() const { return _body; } @@ -787,7 +787,7 @@ b2Fixture *Armature::getShapeList() } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT -cpBody *Armature::getBody() +cpBody *Armature::getBody() const { return _body; } diff --git a/cocos/editor-support/cocostudio/CCArmature.h b/cocos/editor-support/cocostudio/CCArmature.h index 9f6fc3331b..6182072265 100644 --- a/cocos/editor-support/cocostudio/CCArmature.h +++ b/cocos/editor-support/cocostudio/CCArmature.h @@ -99,7 +99,7 @@ public: /** * Init the empty armature */ - virtual bool init(); + virtual bool init() override; /** * Init an armature with specified name @@ -140,14 +140,14 @@ public: * Get Armature's bone dictionary * @return Armature's bone dictionary */ - cocos2d::Dictionary *getBoneDic(); + const cocos2d::Dictionary *getBoneDic() const; /** * This boundingBox will calculate all bones' boundingBox every time */ - virtual cocos2d::Rect getBoundingBox() const; + virtual cocos2d::Rect getBoundingBox() const override; - Bone *getBoneAtPoint(float x, float y); + Bone *getBoneAtPoint(float x, float y) const; // overrides /** @@ -170,18 +170,43 @@ public: virtual void updateOffsetPoint(); virtual void setAnimation(ArmatureAnimation *animation); - virtual ArmatureAnimation *getAnimation(); + virtual ArmatureAnimation *getAnimation() const; - virtual bool getArmatureTransformDirty(); + virtual bool getArmatureTransformDirty() const; - virtual cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture); + virtual cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture) const; virtual void setColliderFilter(ColliderFilter *filter); + + virtual void setArmatureData(ArmatureData *armatureData) { _armatureData = armatureData; } + virtual const ArmatureData *getArmatureData() const { return _armatureData; } + + virtual void setBatchNode(BatchNode *batchNode) { _batchNode = batchNode; } + virtual const BatchNode *getBatchNode() const { return _batchNode; } + + virtual void setName(const std::string &name) { _name = name; } + virtual const std::string &getName() const { return _name; } + + virtual void setTextureAtlas(cocos2d::TextureAtlas *atlas) { _atlas = atlas; } + virtual cocos2d::TextureAtlas *getTextureAtlas() const { return _atlas; } + + virtual void setParentBone(Bone *parentBone); + virtual Bone *getParentBone() const; + + virtual void setVersion(float version) { _version = version; } + virtual float getVersion() const { return _version; } + #if ENABLE_PHYSICS_BOX2D_DETECT virtual b2Fixture *getShapeList(); + + virtual void setBody(b2Body *body); + virtual b2Body *getBody() const; #elif ENABLE_PHYSICS_CHIPMUNK_DETECT virtual cpShape *getShapeList(); + + virtual void setBody(cpBody *body); + virtual cpBody *getBody() const; #endif protected: @@ -194,19 +219,14 @@ protected: //! Update blend function void updateBlendType(BlendType blendType); - CC_SYNTHESIZE(ArmatureData *, _armatureData, ArmatureData); - - CC_SYNTHESIZE(BatchNode *, _batchNode, BatchNode); - - CC_SYNTHESIZE(std::string, _name, Name); - - CC_SYNTHESIZE(cocos2d::TextureAtlas *, _atlas, TextureAtlas); - - CC_PROPERTY(Bone *, _parentBone, ParentBone); - - CC_SYNTHESIZE(float, _version, Version); - protected: + ArmatureData *_armatureData; + BatchNode *_batchNode; + std::string _name; + cocos2d::TextureAtlas *_atlas; + Bone *_parentBone; + float _version; + mutable bool _armatureTransformDirty; cocos2d::Dictionary *_boneDic; //! The dictionary of the bones, include all bones in the armature, no matter it is the direct bone or the indirect bone. It is different from m_pChindren. @@ -222,9 +242,9 @@ protected: cocos2d::Dictionary *_textureAtlasDic; #if ENABLE_PHYSICS_BOX2D_DETECT - CC_PROPERTY(b2Body *, _body, Body); + b2Body *_body; #elif ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_PROPERTY(cpBody *, _body, Body); + cpBody *_body; #endif }; diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp index 8f9c9252bd..6b234782bd 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp @@ -146,7 +146,7 @@ void ArmatureAnimation::setSpeedScale(float speedScale) _processScale = !_movementData ? _speedScale : _speedScale * _movementData->scale; DictElement *element = nullptr; - Dictionary *dict = _armature->getBoneDic(); + const Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { Bone *bone = static_cast(element->getObject()); @@ -174,7 +174,7 @@ void ArmatureAnimation::setAnimationInternal(float animationInternal) _animationInternal = animationInternal; DictElement *element = nullptr; - Dictionary *dict = _armature->getBoneDic(); + const Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { Bone *bone = static_cast(element->getObject()); @@ -236,7 +236,7 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura _tweenList->removeAllObjects(); DictElement *element = nullptr; - Dictionary *dict = _armature->getBoneDic(); + const Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { @@ -261,7 +261,7 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura } else { - if(!bone->getIgnoreMovementBoneData()) + if(!bone->isIgnoreMovementBoneData()) { //! this bone is not include in this movement, so hide it bone->getDisplayManager()->changeDisplayByIndex(-1, false); @@ -319,7 +319,7 @@ void ArmatureAnimation::gotoAndPause(int frameIndex) pause(); } -int ArmatureAnimation::getMovementCount() +int ArmatureAnimation::getMovementCount() const { return _animationData->getMovementCount(); } @@ -416,7 +416,7 @@ void ArmatureAnimation::updateHandler() } } -std::string ArmatureAnimation::getCurrentMovementID() +std::string ArmatureAnimation::getCurrentMovementID() const { if (_isComplete) { diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.h b/cocos/editor-support/cocostudio/CCArmatureAnimation.h index 3c6e7e5a2c..8d306398e9 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.h +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.h @@ -170,7 +170,7 @@ public: /** * Get movement count */ - int getMovementCount(); + int getMovementCount() const; void update(float dt); @@ -178,7 +178,7 @@ public: * Get current movementID * @return The name of current movement */ - std::string getCurrentMovementID(); + std::string getCurrentMovementID() const; /** * Set armature's movement event callback function @@ -192,6 +192,16 @@ public: */ void setFrameEventCallFunc(cocos2d::Object *target, SEL_FrameEventCallFunc callFunc); + virtual void setAnimationData(AnimationData *data) + { + if (_animationData != data) + { + CC_SAFE_RETAIN(data); + CC_SAFE_RELEASE(_animationData); + _animationData = data; + } + } + virtual AnimationData *getAnimationData() const { return _animationData; } protected: /** @@ -209,12 +219,12 @@ protected: */ void frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex); - inline bool isIgnoreFrameEvent() { return _ignoreFrameEvent; } + bool isIgnoreFrameEvent() const { return _ignoreFrameEvent; } friend class Tween; protected: //! AnimationData save all MovementDatas this animation used. - CC_SYNTHESIZE_RETAIN(AnimationData *, _animationData, AnimationData); + AnimationData *_animationData; //! Scale the animation speed float _speedScale; diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index d674d8487b..36158a12dd 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -83,7 +83,7 @@ void BatchNode::addChild(Node *child, int zOrder, int tag) { armature->setBatchNode(this); - Dictionary *dict = armature->getBoneDic(); + const Dictionary *dict = armature->getBoneDic(); DictElement *element = nullptr; CCDICT_FOREACH(dict, element) { @@ -111,7 +111,7 @@ void BatchNode::removeChild(Node* child, bool cleanup) { armature->setBatchNode(nullptr); - Dictionary *dict = armature->getBoneDic(); + const Dictionary *dict = armature->getBoneDic(); DictElement *element = nullptr; CCDICT_FOREACH(dict, element) { @@ -188,7 +188,7 @@ void BatchNode::draw() } } -TextureAtlas *BatchNode::getTexureAtlasWithTexture(Texture2D *texture) +TextureAtlas *BatchNode::getTexureAtlasWithTexture(Texture2D *texture) const { int key = texture->getName(); diff --git a/cocos/editor-support/cocostudio/CCBatchNode.h b/cocos/editor-support/cocostudio/CCBatchNode.h index 44f10872c2..fa654a19ba 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.h +++ b/cocos/editor-support/cocostudio/CCBatchNode.h @@ -40,15 +40,15 @@ public: BatchNode(); ~BatchNode(); - virtual bool init(); - virtual void addChild(cocos2d::Node *pChild); - virtual void addChild(cocos2d::Node *pChild, int zOrder); - virtual void addChild(cocos2d::Node *pChild, int zOrder, int tag); - virtual void removeChild(cocos2d::Node* child, bool cleanup); - virtual void visit(); - void draw(); + virtual bool init() override; + virtual void addChild(cocos2d::Node *pChild) override; + virtual void addChild(cocos2d::Node *pChild, int zOrder) override; + virtual void addChild(cocos2d::Node *pChild, int zOrder, int tag) override; + virtual void removeChild(cocos2d::Node* child, bool cleanup) override; + virtual void visit() override; + void draw() override; - virtual cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture); + virtual cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture) const; protected: cocos2d::TextureAtlas *_atlas; cocos2d::Dictionary *_textureAtlasDic; diff --git a/cocos/editor-support/cocostudio/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index 45562f898e..26c5653d58 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -127,7 +127,7 @@ bool Bone::init(const char *name) _worldInfo = new BaseData(); CC_SAFE_DELETE(_boneData); - _boneData = new CCBoneData(); + _boneData = new BoneData(); bRet = true; } @@ -153,7 +153,7 @@ void Bone::setBoneData(BoneData *boneData) _displayManager->initDisplayList(boneData); } -BoneData *Bone::getBoneData() +BoneData *Bone::getBoneData() const { return _boneData; } @@ -174,7 +174,7 @@ void Bone::setArmature(Armature *armature) } -Armature *Bone::getArmature() +Armature *Bone::getArmature() const { return _armature; } @@ -376,7 +376,7 @@ void Bone::setChildArmature(Armature *armature) } } -Armature *Bone::getChildArmature() +Armature *Bone::getChildArmature() const { return _childArmature; } diff --git a/cocos/editor-support/cocostudio/CCBone.h b/cocos/editor-support/cocostudio/CCBone.h index 58a15c3987..9082f1ebb3 100644 --- a/cocos/editor-support/cocostudio/CCBone.h +++ b/cocos/editor-support/cocostudio/CCBone.h @@ -63,7 +63,7 @@ public: /** * Initializes an empty Bone with nothing init. */ - virtual bool init(); + virtual bool init() override; /** * Initializes a Bone with the specified name @@ -124,10 +124,10 @@ public: */ void removeChildBone(Bone *bone, bool recursion); - void update(float delta); + void update(float delta) override; - void updateDisplayedColor(const cocos2d::Color3B &parentColor); - void updateDisplayedOpacity(GLubyte parentOpacity); + void updateDisplayedColor(const cocos2d::Color3B &parentColor) override; + void updateDisplayedOpacity(GLubyte parentOpacity) override; virtual void setColor(const cocos2d::Color3B& color) override; virtual void setOpacity(GLubyte opacity) override; @@ -138,15 +138,15 @@ public: //! Update zorder void updateZOrder(); - virtual void setZOrder(int zOrder); + virtual void setZOrder(int zOrder) override; Tween *getTween(); /* * Whether or not the bone's transform property changed. if true, the bone will update the transform. */ - virtual inline void setTransformDirty(bool dirty) { _boneTransformDirty = dirty; } - virtual inline bool isTransformDirty() { return _boneTransformDirty; } + virtual void setTransformDirty(bool dirty) { _boneTransformDirty = dirty; } + virtual bool isTransformDirty() { return _boneTransformDirty; } virtual cocos2d::AffineTransform getNodeToArmatureTransform() const; virtual cocos2d::AffineTransform getNodeToWorldTransform() const override; @@ -161,45 +161,69 @@ public: virtual void setColliderFilter(ColliderFilter *filter); virtual ColliderFilter *getColliderFilter(); -public: + + virtual void setBoneData(BoneData *boneData); + virtual BoneData *getBoneData() const; + + virtual void setArmature(Armature *armature); + virtual Armature *getArmature() const; + + virtual void setChildArmature(Armature *childArmature); + virtual Armature *getChildArmature() const; + + virtual DisplayManager *getDisplayManager() const { return _displayManager; } + + virtual void setIgnoreMovementBoneData(bool ignore) { _ignoreMovementBoneData = ignore; } + virtual bool isIgnoreMovementBoneData() const { return _ignoreMovementBoneData; } + + virtual void setBlendType(BlendType type) { _blendType = type; } + virtual BlendType getBlendType() const { return _blendType; } + + virtual FrameData *getTweenData() const { return _tweenData; } + + virtual void setName(const std::string &name) { _name = name; } + virtual const std::string getName() const { return _name; } + + virtual const BaseData *getWorldInfo() const { return _worldInfo; } +protected: + void applyParentTransform(Bone *parent); + /* * The origin state of the Bone. Display's state is effected by _boneData, m_pNode, _tweenData * when call setData function, it will copy from the BoneData. */ - CC_PROPERTY(BoneData *, _boneData, BoneData); + BoneData *_boneData; //! A weak reference to the Armature - CC_PROPERTY(Armature *, _armature, Armature); + Armature *_armature; //! A weak reference to the child Armature - CC_PROPERTY(Armature *, _childArmature, ChildArmature); + Armature *_childArmature; - CC_SYNTHESIZE(DisplayManager *, _displayManager, DisplayManager) + DisplayManager *_displayManager; /* * When Armature play an animation, if there is not a MovementBoneData of this bone in this MovementData, this bone will be hidden. * Set IgnoreMovementBoneData to true, then this bone will also be shown. */ - CC_SYNTHESIZE(bool, _ignoreMovementBoneData, IgnoreMovementBoneData) + bool _ignoreMovementBoneData; - CC_SYNTHESIZE(BlendType, _blendType, BlendType) -protected: - void applyParentTransform(Bone *parent); + BlendType _blendType; Tween *_tween; //! Calculate tween effect //! Used for making tween effect in every frame - CC_SYNTHESIZE_READONLY(FrameData *, _tweenData, TweenData); + FrameData *_tweenData; - CC_SYNTHESIZE(std::string, _name, Name); + std::string _name; - Bone *_parentBone; //! A weak reference to its parent + Bone *_parentBone; //! A weak reference to its parent bool _boneTransformDirty; //! Whether or not transform dirty //! self Transform, use this to change display's state cocos2d::AffineTransform _worldTransform; - CC_SYNTHESIZE_READONLY(BaseData*, _worldInfo, WorldInfo); + BaseData *_worldInfo; //! Armature's parent bone Bone *_armatureParentBone; diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.cpp b/cocos/editor-support/cocostudio/CCColliderDetector.cpp index be587ecefb..adbea59a31 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.cpp +++ b/cocos/editor-support/cocostudio/CCColliderDetector.cpp @@ -449,7 +449,7 @@ void ColliderDetector::setBody(b2Body *pBody) } } -b2Body *ColliderDetector::getBody() +b2Body *ColliderDetector::getBody() const { return _body; } @@ -492,7 +492,7 @@ void ColliderDetector::setBody(cpBody *pBody) } } -cpBody *ColliderDetector::getBody() +cpBody *ColliderDetector::getBody() const { return _body; } diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.h b/cocos/editor-support/cocostudio/CCColliderDetector.h index 0b9c058aa8..2737980f60 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.h +++ b/cocos/editor-support/cocostudio/CCColliderDetector.h @@ -55,29 +55,37 @@ public: public: ColliderFilter(unsigned short categoryBits = 0x0001, unsigned short maskBits = 0xFFFF, signed short groupIndex = 0); void updateShape(b2Fixture *fixture); + + virtual void setCategoryBits(unsigned short categoryBits) { _categoryBits = categoryBits; } + virtual unsigned short getCategoryBits() const { return _categoryBits; } + + virtual void setMaskBits(unsigned short maskBits) { _maskBits = maskBits; } + virtual unsigned short getMaskBits() const { return _maskBits; } + + virtual void setGroupIndex(signed short groupIndex) { _groupIndex = groupIndex; } + virtual signed short getGroupIndex() const { return _groupIndex; } protected: - CC_SYNTHESIZE(unsigned short, _categoryBits, CategoryBits); - CC_SYNTHESIZE(unsigned short, _maskBits, MaskBits); - CC_SYNTHESIZE(signed short, _groupIndex, GroupIndex); + unsigned short _categoryBits; + unsigned short _maskBits; + signed short _groupIndex; #elif ENABLE_PHYSICS_CHIPMUNK_DETECT public: ColliderFilter(uintptr_t collisionType = 0, uintptr_t group = 0); void updateShape(cpShape *shape); + + virtual void setCollisionType(uintptr_t collisionType) { _collisionType = collisionType; } + virtual uintptr_t getCollisionType() const { return _collisionType; } + + virtual void setGroup(uintptr_t group) { _group = group; } + virtual uintptr_t getGroup() const { return _group; } protected: - CC_SYNTHESIZE(uintptr_t, _collisionType, CollisionType); - CC_SYNTHESIZE(uintptr_t, _group, Group); + uintptr_t _collisionType; + uintptr_t _group; #endif }; class ColliderBody : public cocos2d::Object { -public: -#if ENABLE_PHYSICS_BOX2D_DETECT - CC_SYNTHESIZE(b2Fixture *, _fixture, B2Fixture) -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_SYNTHESIZE(cpShape *, _shape, Shape) -#endif - public: ColliderBody(ContourData *contourData); ~ColliderBody(); @@ -86,12 +94,31 @@ public: void setColliderFilter(ColliderFilter *filter); ColliderFilter *getColliderFilter(); + +#if ENABLE_PHYSICS_BOX2D_DETECT + virtual void setB2Fixture(b2Fixture *fixture) { _fixture = fixture; } + virtual b2Fixture *getB2Fixture() const { return _fixture; } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + virtual void setShape(cpShape *shape) { _shape = shape; } + virtual cpShape *getShape() const { return _shape; } +#endif + +#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX + virtual const cocos2d::Array *getCalculatedVertexList() const { return _calculatedVertexList; } +#endif private: + +#if ENABLE_PHYSICS_BOX2D_DETECT + b2Fixture *_fixture; +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + cpShape *_shape; +#endif + ContourData *_contourData; ColliderFilter *_filter; #if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX - CC_SYNTHESIZE_READONLY(CCArray *, _calculatedVertexList, CalculatedVertexList); + cocos2d::Array *_calculatedVertexList; #endif }; @@ -132,16 +159,27 @@ public: virtual void setColliderFilter(ColliderFilter *filter); virtual ColliderFilter *getColliderFilter(); -protected: + + virtual void setBone(Bone *bone) { _bone = bone; } + virtual Bone *getBone() const { return _bone; } + +#if ENABLE_PHYSICS_BOX2D_DETECT + virtual void setBody(b2Body *body); + virtual b2Body *getBody() const; +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + virtual void setBody(cpBody *body); + virtual cpBody *getBody() const; +#endif + protected: cocos2d::Array *_colliderBodyList; ColliderFilter *_filter; - CC_SYNTHESIZE(Bone *, _bone, Bone); + Bone *_bone; #if ENABLE_PHYSICS_BOX2D_DETECT - CC_PROPERTY(b2Body *, _body, Body); + b2Body *_body; #elif ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_PROPERTY(cpBody *, _body, Body); + cpBody *_body; #endif protected: diff --git a/cocos/editor-support/cocostudio/CCDecorativeDisplay.h b/cocos/editor-support/cocostudio/CCDecorativeDisplay.h index 7196d0e9ec..0444cae440 100644 --- a/cocos/editor-support/cocostudio/CCDecorativeDisplay.h +++ b/cocos/editor-support/cocostudio/CCDecorativeDisplay.h @@ -53,13 +53,46 @@ public: virtual bool init(); -protected: + virtual void setDisplay(cocos2d::Node *display) + { + if (_display != display) + { + CC_SAFE_RETAIN(display); + CC_SAFE_RELEASE(_display); + _display = display; + } + } + virtual cocos2d::Node *getDisplay() const { return _display; } - CC_SYNTHESIZE_RETAIN(cocos2d::Node *, _display, Display); - CC_SYNTHESIZE_RETAIN(DisplayData *, _displayData, DisplayData); + virtual void setDisplayData(DisplayData *data) + { + if (_displayData != data) + { + CC_SAFE_RETAIN(data); + CC_SAFE_RELEASE(_displayData); + _displayData = data; + } + } + virtual DisplayData *getDisplayData() const { return _displayData; } #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_SYNTHESIZE_RETAIN(ColliderDetector *, _colliderDetector, ColliderDetector); + virtual void setColliderDetector(ColliderDetector *detector) + { + if (_colliderDetector != detector) + { + CC_SAFE_RETAIN(detector); + CC_SAFE_RELEASE(_colliderDetector); + _colliderDetector = detector; + } + } + virtual ColliderDetector *getColliderDetector() const { return _colliderDetector; } +#endif +protected: + cocos2d::Node *_display; + DisplayData *_displayData; + +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT + ColliderDetector *_colliderDetector; #endif }; diff --git a/cocos/editor-support/cocostudio/CCDisplayManager.cpp b/cocos/editor-support/cocostudio/CCDisplayManager.cpp index 5efa5510c7..52af6b2d1d 100644 --- a/cocos/editor-support/cocostudio/CCDisplayManager.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayManager.cpp @@ -182,7 +182,7 @@ void DisplayManager::removeDisplay(int index) _decoDisplayList->removeObjectAtIndex(index); } -Array *DisplayManager::getDecorativeDisplayList() +Array *DisplayManager::getDecorativeDisplayList() const { return _decoDisplayList; } @@ -276,28 +276,28 @@ void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay) } } -Node *DisplayManager::getDisplayRenderNode() +Node *DisplayManager::getDisplayRenderNode() const { return _displayRenderNode; } -DisplayType DisplayManager::getDisplayRenderNodeType() +DisplayType DisplayManager::getDisplayRenderNodeType() const { return _displayType; } -int DisplayManager::getCurrentDisplayIndex() +int DisplayManager::getCurrentDisplayIndex() const { return _displayIndex; } -DecorativeDisplay *DisplayManager::getCurrentDecorativeDisplay() +DecorativeDisplay *DisplayManager::getCurrentDecorativeDisplay() const { return _currentDecoDisplay; } -DecorativeDisplay *DisplayManager::getDecorativeDisplayByIndex( int index) +DecorativeDisplay *DisplayManager::getDecorativeDisplayByIndex( int index) const { return (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index); } @@ -377,32 +377,32 @@ void DisplayManager::setVisible(bool visible) _displayRenderNode->setVisible(visible); } -bool DisplayManager::isVisible() +bool DisplayManager::isVisible() const { return _visible; } -Size DisplayManager::getContentSize() +Size DisplayManager::getContentSize() const { CS_RETURN_IF(!_displayRenderNode) Size(0, 0); return _displayRenderNode->getContentSize(); } -Rect DisplayManager::getBoundingBox() +Rect DisplayManager::getBoundingBox() const { CS_RETURN_IF(!_displayRenderNode) Rect(0, 0, 0, 0); return _displayRenderNode->getBoundingBox(); } -Point DisplayManager::getAnchorPoint() +Point DisplayManager::getAnchorPoint() const { CS_RETURN_IF(!_displayRenderNode) Point(0, 0); return _displayRenderNode->getAnchorPoint(); } -Point DisplayManager::getAnchorPointInPoints() +Point DisplayManager::getAnchorPointInPoints() const { CS_RETURN_IF(!_displayRenderNode) Point(0, 0); return _displayRenderNode->getAnchorPointInPoints(); diff --git a/cocos/editor-support/cocostudio/CCDisplayManager.h b/cocos/editor-support/cocostudio/CCDisplayManager.h index 0856886c57..1f1b4190ba 100644 --- a/cocos/editor-support/cocostudio/CCDisplayManager.h +++ b/cocos/editor-support/cocostudio/CCDisplayManager.h @@ -76,7 +76,7 @@ public: void removeDisplay(int index); - cocos2d::Array *getDecorativeDisplayList(); + cocos2d::Array *getDecorativeDisplayList() const; /** * Change display by index. You can just use this method to change display in the display list. @@ -90,14 +90,14 @@ public: void changeDisplayByIndex(int index, bool force); - cocos2d::Node *getDisplayRenderNode(); - DisplayType getDisplayRenderNodeType(); + cocos2d::Node *getDisplayRenderNode() const; + DisplayType getDisplayRenderNodeType() const; - int getCurrentDisplayIndex(); + int getCurrentDisplayIndex() const; virtual void setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay); - virtual DecorativeDisplay *getCurrentDecorativeDisplay(); - virtual DecorativeDisplay *getDecorativeDisplayByIndex( int index); + virtual DecorativeDisplay *getCurrentDecorativeDisplay() const; + virtual DecorativeDisplay *getDecorativeDisplayByIndex( int index) const; /** * Sets whether the display is visible @@ -112,13 +112,13 @@ public: * @see setVisible(bool) * @return true if the node is visible, false if the node is hidden. */ - virtual bool isVisible(); + virtual bool isVisible() const; - cocos2d::Size getContentSize(); - cocos2d::Rect getBoundingBox(); + cocos2d::Size getContentSize() const; + cocos2d::Rect getBoundingBox() const; - cocos2d::Point getAnchorPoint(); - cocos2d::Point getAnchorPointInPoints(); + cocos2d::Point getAnchorPoint() const; + cocos2d::Point getAnchorPointInPoints() const; /** * Check if the position is inside the bone. @@ -130,6 +130,8 @@ public: */ virtual bool containPoint(float x, float y); + virtual void setForceChangeDisplay(bool force) { _forceChangeDisplay = force; } + virtual bool isForceChangeDisplay() const { return _forceChangeDisplay; } protected: cocos2d::Array *_decoDisplayList; //! Display render node. @@ -141,7 +143,7 @@ protected: //! Current display index int _displayIndex; - CC_SYNTHESIZE(bool, _forceChangeDisplay, ForceChangeDisplay) + bool _forceChangeDisplay; //! Whether of not the bone is visible. Default is true bool _visible; diff --git a/cocos/editor-support/cocostudio/CCProcessBase.h b/cocos/editor-support/cocostudio/CCProcessBase.h index e59244433e..c6b62793b4 100644 --- a/cocos/editor-support/cocostudio/CCProcessBase.h +++ b/cocos/editor-support/cocostudio/CCProcessBase.h @@ -114,6 +114,23 @@ public: virtual int getCurrentFrameIndex(); + virtual void setProcessScale(float processScale) { _processScale = processScale; } + virtual float getProcessScale() const { return _processScale; } + + virtual void setIsPause(bool pause) { _isPause = pause; } + virtual bool isPause() const { return _isPause; } + + virtual void setIsComplete(bool complete) { _isComplete = complete; } + virtual bool isComplete() const { return _isComplete; } + + virtual void setIsPlaying(bool playing) { _isPlaying = playing; } + virtual bool isPlaying() const { return _isPlaying; } + + virtual float getCurrentPercent() const { return _currentPercent; } + virtual int getRawDuration() const { return _rawDuration; } + + virtual void setAnimationInternal(float animationInternal) { _animationInternal = animationInternal; } + virtual float getAnimationInternal() const { return _animationInternal; } protected: virtual void gotoFrame(int frameIndex); @@ -125,31 +142,31 @@ protected: protected: //! Scale the process speed - CC_SYNTHESIZE(float, _processScale, ProcessScale); + float _processScale; //! Set and get whether the aniamtion is pause - CC_SYNTHESIZE(bool, _isPause, IsPause); + bool _isPause; //! Set and get whether the aniamtion is complete - CC_SYNTHESIZE(bool, _isComplete, IsComplete); + bool _isComplete; //! Set and get whether the aniamtion is playing - CC_SYNTHESIZE(bool, _isPlaying, IsPlaying); + bool _isPlaying; //! Current percent this process arrived - CC_SYNTHESIZE(float, _currentPercent, CurrentPercent); + float _currentPercent; //! The raw duration - CC_SYNTHESIZE(int, _rawDuration, RawDuration); + int _rawDuration; //! The animation whether or not loop - CC_SYNTHESIZE(AnimationType, _loopType, LoopType); + AnimationType _loopType; //! The tween easing effect - CC_SYNTHESIZE(TweenType, _tweenEasing, TweenEasing); + TweenType _tweenEasing; //! The animation update speed - CC_SYNTHESIZE(float, _animationInternal, AnimationInternal); + float _animationInternal; protected: diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index b0496729f4..62710e561d 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -224,7 +224,7 @@ void Skin::setBone(Bone *bone) } } -Bone *Skin::getBone() +Bone *Skin::getBone() const { return _bone; } diff --git a/cocos/editor-support/cocostudio/CCSkin.h b/cocos/editor-support/cocostudio/CCSkin.h index 2d934b8e4b..6e62da7d22 100644 --- a/cocos/editor-support/cocostudio/CCSkin.h +++ b/cocos/editor-support/cocostudio/CCSkin.h @@ -39,22 +39,28 @@ public: public: Skin(); - bool initWithSpriteFrameName(const char *pszSpriteFrameName); - bool initWithFile(const char *pszFilename); + bool initWithSpriteFrameName(const char *pszSpriteFrameName) override; + bool initWithFile(const char *pszFilename) override; void updateArmatureTransform(); - void updateTransform(); + void updateTransform() override; - cocos2d::AffineTransform getNodeToWorldTransform() const; + cocos2d::AffineTransform getNodeToWorldTransform() const override; cocos2d::AffineTransform getNodeToWorldTransformAR() const; - CC_PROPERTY_PASS_BY_REF(BaseData, _skinData, SkinData); - CC_PROPERTY(Bone *, _bone, Bone); + virtual void setSkinData(const BaseData &data); + virtual const BaseData &getSkinData() const; + virtual void setBone(Bone *bone); + virtual Bone *getBone() const; + + virtual const std::string &getDisplayName() const { return _displayName; } protected: + BaseData _skinData; + Bone *_bone; Armature *_armature; cocos2d::AffineTransform _skinTransform; - CC_SYNTHESIZE_READONLY(std::string, _displayName, DisplayName) + std::string _displayName; }; } diff --git a/cocos/editor-support/cocostudio/CCTween.cpp b/cocos/editor-support/cocostudio/CCTween.cpp index 75ff8bbb7e..dec84bf295 100644 --- a/cocos/editor-support/cocostudio/CCTween.cpp +++ b/cocos/editor-support/cocostudio/CCTween.cpp @@ -328,7 +328,7 @@ void Tween::arriveKeyFrame(FrameData *keyFrameData) //! Change bone's display int displayIndex = keyFrameData->displayIndex; - if (!displayManager->getForceChangeDisplay()) + if (!displayManager->isForceChangeDisplay()) { displayManager->changeDisplayByIndex(displayIndex, false); } diff --git a/cocos/editor-support/cocostudio/CCTween.h b/cocos/editor-support/cocostudio/CCTween.h index ce08f2264e..8b4dcba9d2 100644 --- a/cocos/editor-support/cocostudio/CCTween.h +++ b/cocos/editor-support/cocostudio/CCTween.h @@ -88,6 +88,9 @@ public: virtual void gotoAndPlay(int frameIndex); virtual void gotoAndPause(int frameIndex); + + virtual void setMovementBoneData(MovementBoneData *data) { _movementBoneData = data; } + virtual const MovementBoneData *getMovementBoneData() const { return _movementBoneData; } protected: /** @@ -121,7 +124,7 @@ protected: virtual void arriveKeyFrame(FrameData *keyFrameData); protected: //! A weak reference to the current MovementBoneData. The data is in the data pool - CC_SYNTHESIZE(MovementBoneData *, _movementBoneData, MovementBoneData) + MovementBoneData *_movementBoneData; FrameData *_tweenData; //! The computational tween frame data, //! A weak reference to the Bone's tweenData FrameData *_from; //! From frame data, used for calculate between value diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index b571dfb808..65cd9044ef 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -271,9 +271,9 @@ std::string TestAsynchronousLoading::subtitle() return "current percent : "; } -void TestAsynchronousLoading::restartCallback(CCObject* pSender) +void TestAsynchronousLoading::restartCallback(Object* pSender) { - ArmatureDataManager::getInstance()->purge(); + ArmatureDataManager::getInstance()->destoryInstance(); ArmatureTestLayer::restartCallback(pSender); } void TestAsynchronousLoading::dataLoaded(float percent) @@ -307,7 +307,7 @@ void TestDirectLoading::onEnter() Armature *armature = Armature::create("bear"); armature->getAnimation()->playByIndex(0); - armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y)); + armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y)); addChild(armature); } std::string TestDirectLoading::title() @@ -608,7 +608,7 @@ void TestFrameEvent::onFrameEvent(Bone *bone, const char *evt, int originFrameIn } void TestFrameEvent::checkAction(float dt) { - if ( this->numberOfRunningActions() == 0 && this->getGrid() != nullptr) + if ( this->getNumberOfRunningActions() == 0 && this->getGrid() != nullptr) this->setGrid(nullptr); } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index f8429fc595..79e29b61dc 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -74,7 +74,7 @@ public: virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); - virtual void restartCallback(CCObject* pSender); + virtual void restartCallback(Object* pSender); void dataLoaded(float percent); }; From 8b86373b08ccc2126c8cb1eac4e6ae59331bc325 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Tue, 5 Nov 2013 20:33:29 +0800 Subject: [PATCH 17/39] 1.Change to range-based loop --- .../cocostudio/CCArmatureDataManager.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp index c8278387ce..0e139ef560 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp @@ -115,24 +115,24 @@ void ArmatureDataManager::removeArmatureFileInfo(const char *configFilePath) { if (RelativeData *data = getRelativeData(configFilePath)) { - for (std::vector::iterator i = data->armatures.begin(); i != data->armatures.end(); i++) + for (std::string str : data->armatures) { - removeArmatureData(i->c_str()); + removeArmatureData(str.c_str()); } - for (std::vector::iterator i = data->animations.begin(); i != data->animations.end(); i++) + for (std::string str : data->animations) { - removeAnimationData(i->c_str()); + removeAnimationData(str.c_str()); } - for (std::vector::iterator i = data->textures.begin(); i != data->textures.end(); i++) + for (std::string str : data->textures) { - removeTextureData(i->c_str()); + removeTextureData(str.c_str()); } - for (std::vector::iterator i = data->plistFiles.begin(); i != data->plistFiles.end(); i++) + for (std::string str : data->plistFiles) { - SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(i->c_str()); + SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(str.c_str()); } _relativeDatas.erase(configFilePath); From 471dd07f3b33074755807a3b95e29f0497523975 Mon Sep 17 00:00:00 2001 From: Chris Hannon Date: Tue, 5 Nov 2013 15:54:31 -0500 Subject: [PATCH 18/39] [android] update nativeactivity.cpp to work with changes made in commit 0220f27 (AMD support), changing int to long int for the second argument in most touch callbacks --- cocos/2d/platform/android/nativeactivity.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cocos/2d/platform/android/nativeactivity.cpp b/cocos/2d/platform/android/nativeactivity.cpp index 5ac17a5ee5..12e25d597d 100644 --- a/cocos/2d/platform/android/nativeactivity.cpp +++ b/cocos/2d/platform/android/nativeactivity.cpp @@ -292,7 +292,7 @@ static void engine_term_display(struct engine* engine) { /* * Get X, Y positions and ID's for all pointers */ -static void getTouchPos(AInputEvent *event, int ids[], float xs[], float ys[]) { +static void getTouchPos(AInputEvent *event, long ids[], float xs[], float ys[]) { int pointerCount = AMotionEvent_getPointerCount(event); for(int i = 0; i < pointerCount; ++i) { ids[i] = AMotionEvent_getPointerId(event, i); @@ -321,7 +321,7 @@ static int32_t handle_touch_input(AInputEvent *event) { LOG_EVENTS_DEBUG("Event: Action DOWN x=%f y=%f pointerID=%d\n", xP, yP, pointerId); - int pId = pointerId; + long pId = pointerId; float x = xP; float y = yP; @@ -340,7 +340,7 @@ static int32_t handle_touch_input(AInputEvent *event) { LOG_EVENTS_DEBUG("Event: Action POINTER DOWN x=%f y=%f pointerID=%d\n", xP, yP, pointerId); - int pId = pointerId; + long pId = pointerId; float x = xP; float y = yP; @@ -353,10 +353,10 @@ static int32_t handle_touch_input(AInputEvent *event) { { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_MOVE"); int pointerCount = AMotionEvent_getPointerCount(event); - int ids[pointerCount]; + long ids[pointerCount]; float xs[pointerCount], ys[pointerCount]; getTouchPos(event, ids, xs, ys); - cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(pointerCount, ids, xs, ys); + cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(pointerCount, ids, xs, ys); return 1; } break; @@ -369,7 +369,7 @@ static int32_t handle_touch_input(AInputEvent *event) { float yP = AMotionEvent_getY(event,0); LOG_EVENTS_DEBUG("Event: Action UP x=%f y=%f pointerID=%d\n", xP, yP, pointerId); - int pId = pointerId; + long pId = pointerId; float x = xP; float y = yP; @@ -387,7 +387,7 @@ static int32_t handle_touch_input(AInputEvent *event) { float yP = AMotionEvent_getY(event,pointerIndex); LOG_EVENTS_DEBUG("Event: Action POINTER UP x=%f y=%f pointerID=%d\n", xP, yP, pointerIndex); - int pId = pointerId; + long pId = pointerId; float x = xP; float y = yP; @@ -400,10 +400,10 @@ static int32_t handle_touch_input(AInputEvent *event) { { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_CANCEL"); int pointerCount = AMotionEvent_getPointerCount(event); - int ids[pointerCount]; + long ids[pointerCount]; float xs[pointerCount], ys[pointerCount]; getTouchPos(event, ids, xs, ys); - cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(pointerCount, ids, xs, ys); + cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(pointerCount, ids, xs, ys); return 1; } break; From 84a6aa29cd61e7624830f1461d6aa00047d0a934 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Tue, 5 Nov 2013 17:36:44 -0800 Subject: [PATCH 19/39] Adds more 64-bit fixes Replaces more `int` with `long` where it makes sense. Also , it repalces some `unsigned long` with `long` for "lenght" values as described in our c++ guideline --- cocos/2d/CCDirector.cpp | 4 +- cocos/2d/CCDirector.h | 2 +- cocos/2d/CCFontFreeType.cpp | 4 +- cocos/2d/CCTextureCache.cpp | 6 +-- cocos/2d/CCUserDefault.cpp | 2 +- cocos/2d/CCUserDefault.mm | 4 +- cocos/2d/TGAlib.cpp | 10 ++--- cocos/2d/ZipUtils.cpp | 28 +++++++------- cocos/2d/ZipUtils.h | 20 +++++----- cocos/2d/platform/CCFileUtils.cpp | 4 +- cocos/2d/platform/CCFileUtils.h | 4 +- cocos/2d/platform/CCImage.h | 4 +- cocos/2d/platform/CCImageCommon_cpp.h | 28 +++++++------- cocos/2d/platform/CCSAXParser.cpp | 8 ++-- cocos/base/CCString.cpp | 38 +++++++++---------- .../editor-support/cocosbuilder/CCBReader.cpp | 2 +- .../cocosbuilder/CCNodeLoader.cpp | 2 +- .../cocostudio/CCDataReaderHelper.cpp | 4 +- .../cocostudio/CCSGUIReader.cpp | 4 +- .../cocostudio/CCSSceneReader.cpp | 8 ++-- cocos/editor-support/spine/spine-cocos2dx.cpp | 2 +- .../javascript/bindings/ScriptingCore.cpp | 2 +- .../cocos2d_specifics.cpp.REMOVED.git-id | 2 +- 23 files changed, 96 insertions(+), 96 deletions(-) diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index 7255659d07..130d170d30 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -831,7 +831,7 @@ void Director::calculateMPF() } // returns the FPS image data pointer and len -void Director::getFPSImageData(unsigned char** datapointer, unsigned int* length) +void Director::getFPSImageData(unsigned char** datapointer, long* length) { // XXX fixed me if it should be used *datapointer = cc_fps_images_png; @@ -855,7 +855,7 @@ void Director::createStatsLabel() Texture2D::PixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat(); Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); unsigned char *data = nullptr; - unsigned int dataLength = 0; + long dataLength = 0; getFPSImageData(&data, &dataLength); Image* image = new Image(); diff --git a/cocos/2d/CCDirector.h b/cocos/2d/CCDirector.h index 5f0d6eb0a8..b01b0fe954 100644 --- a/cocos/2d/CCDirector.h +++ b/cocos/2d/CCDirector.h @@ -376,7 +376,7 @@ protected: void showStats(); void createStatsLabel(); void calculateMPF(); - void getFPSImageData(unsigned char** datapointer, unsigned int* length); + void getFPSImageData(unsigned char** datapointer, long* length); /** calculates delta time since last time it was called */ void calculateDeltaTime(); diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 0e4e49d96f..5e2173204f 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -99,8 +99,8 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize) { FT_Face face; - int len = 0; - _ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", (unsigned long *)(&len)); + long len = 0; + _ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", &len); if (!_ttfData) return false; diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index 95c02f8ff4..8f3fc6fe3a 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -614,10 +614,10 @@ void VolatileTexture::reloadAllTextures() case kImageFile: { Image* image = new Image(); - unsigned long nSize = 0; - unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &nSize); + long size = 0; + unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &size); - if (image && image->initWithImageData(pBuffer, nSize)) + if (image && image->initWithImageData(pBuffer, size)) { Texture2D::PixelFormat oldPixelFormat = Texture2D::getDefaultAlphaPixelFormat(); Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat); diff --git a/cocos/2d/CCUserDefault.cpp b/cocos/2d/CCUserDefault.cpp index 5a85d65b41..2104051f76 100644 --- a/cocos/2d/CCUserDefault.cpp +++ b/cocos/2d/CCUserDefault.cpp @@ -58,7 +58,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLEle tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); *doc = xmlDoc; //CCFileData data(UserDefault::getInstance()->getXMLFilePath().c_str(),"rt"); - unsigned long nSize; + long nSize; const char* pXmlBuffer = (const char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize); //const char* pXmlBuffer = (const char*)data.getBuffer(); if(NULL == pXmlBuffer) diff --git a/cocos/2d/CCUserDefault.mm b/cocos/2d/CCUserDefault.mm index b55acfcf24..da1c8827fd 100644 --- a/cocos/2d/CCUserDefault.mm +++ b/cocos/2d/CCUserDefault.mm @@ -73,8 +73,8 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc { tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); *doc = xmlDoc; - unsigned long nSize; - const char* pXmlBuffer = (const char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize); + long size; + const char* pXmlBuffer = (const char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size); //const char* pXmlBuffer = (const char*)data.getBuffer(); if(NULL == pXmlBuffer) { diff --git a/cocos/2d/TGAlib.cpp b/cocos/2d/TGAlib.cpp index ba4ca83b01..8725e765cb 100644 --- a/cocos/2d/TGAlib.cpp +++ b/cocos/2d/TGAlib.cpp @@ -198,8 +198,8 @@ tImageTGA * tgaLoad(const char *filename) int mode,total; tImageTGA *info = NULL; - unsigned long nSize = 0; - unsigned char* pBuffer = FileUtils::getInstance()->getFileData(filename, "rb", &nSize); + long size = 0; + unsigned char* pBuffer = FileUtils::getInstance()->getFileData(filename, "rb", &size); do { @@ -207,7 +207,7 @@ tImageTGA * tgaLoad(const char *filename) info = (tImageTGA *)malloc(sizeof(tImageTGA)); // get the file header info - if (! tgaLoadHeader(pBuffer, nSize, info)) + if (! tgaLoadHeader(pBuffer, size, info)) { info->status = TGA_ERROR_MEMORY; break; @@ -245,11 +245,11 @@ tImageTGA * tgaLoad(const char *filename) // finally load the image pixels if ( info->type == 10 ) { - bLoadImage = tgaLoadRLEImageData(pBuffer, nSize, info); + bLoadImage = tgaLoadRLEImageData(pBuffer, size, info); } else { - bLoadImage = tgaLoadImageData(pBuffer, nSize, info); + bLoadImage = tgaLoadImageData(pBuffer, size, info); } // check for errors when reading the pixels diff --git a/cocos/2d/ZipUtils.cpp b/cocos/2d/ZipUtils.cpp index db2fab18ce..2e5d9fe43f 100644 --- a/cocos/2d/ZipUtils.cpp +++ b/cocos/2d/ZipUtils.cpp @@ -39,7 +39,7 @@ bool ZipUtils::s_bEncryptionKeyIsValid = false; // --------------------- ZipUtils --------------------- -inline void ZipUtils::ccDecodeEncodedPvr(unsigned int *data, int len) +inline void ZipUtils::ccDecodeEncodedPvr(unsigned int *data, long len) { const int enclen = 1024; const int securelen = 512; @@ -108,7 +108,7 @@ inline void ZipUtils::ccDecodeEncodedPvr(unsigned int *data, int len) } } -inline unsigned int ZipUtils::ccChecksumPvr(const unsigned int *data, int len) +inline unsigned int ZipUtils::ccChecksumPvr(const unsigned int *data, long len) { unsigned int cs = 0; const int cslen = 128; @@ -127,12 +127,12 @@ inline unsigned int ZipUtils::ccChecksumPvr(const unsigned int *data, int len) // Should buffer factor be 1.5 instead of 2 ? #define BUFFER_INC_FACTOR (2) -int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength, unsigned int outLenghtHint) +int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long *outLength, long outLenghtHint) { /* ret value */ int err = Z_OK; - int bufferSize = outLenghtHint; + long bufferSize = outLenghtHint; *out = new unsigned char[bufferSize]; z_stream d_stream; /* decompression stream */ @@ -192,9 +192,9 @@ int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, return err; } -int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outLengthHint) +int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long outLengthHint) { - unsigned int outLength = 0; + long outLength = 0; int err = ccInflateMemoryWithHint(in, inLength, out, &outLength, outLengthHint); if (err != Z_OK || *out == NULL) { @@ -223,7 +223,7 @@ int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, return outLength; } -int ZipUtils::ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out) +int ZipUtils::ccInflateMemory(unsigned char *in, long inLength, unsigned char **out) { // 256k for hint return ccInflateMemoryWithHint(in, inLength, out, 256 * 1024); @@ -304,7 +304,7 @@ bool ZipUtils::ccIsCCZFile(const char *path) // load file into memory unsigned char* compressed = NULL; - unsigned long fileLen = 0; + long fileLen = 0; compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); if(NULL == compressed || 0 == fileLen) @@ -316,7 +316,7 @@ bool ZipUtils::ccIsCCZFile(const char *path) return ccIsCCZBuffer(compressed, fileLen); } -bool ZipUtils::ccIsCCZBuffer(const unsigned char *buffer, int len) +bool ZipUtils::ccIsCCZBuffer(const unsigned char *buffer, long len) { if (len < sizeof(struct CCZHeader)) { @@ -333,7 +333,7 @@ bool ZipUtils::ccIsGZipFile(const char *path) // load file into memory unsigned char* compressed = NULL; - unsigned long fileLen = 0; + long fileLen = 0; compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); if(NULL == compressed || 0 == fileLen) @@ -345,7 +345,7 @@ bool ZipUtils::ccIsGZipFile(const char *path) return ccIsGZipBuffer(compressed, fileLen); } -bool ZipUtils::ccIsGZipBuffer(const unsigned char *buffer, int len) +bool ZipUtils::ccIsGZipBuffer(const unsigned char *buffer, long len) { if (len < 2) { @@ -356,7 +356,7 @@ bool ZipUtils::ccIsGZipBuffer(const unsigned char *buffer, int len) } -int ZipUtils::ccInflateCCZBuffer(const unsigned char *buffer, int bufferLen, unsigned char **out) +int ZipUtils::ccInflateCCZBuffer(const unsigned char *buffer, long bufferLen, unsigned char **out) { struct CCZHeader *header = (struct CCZHeader*) buffer; @@ -454,7 +454,7 @@ int ZipUtils::ccInflateCCZFile(const char *path, unsigned char **out) // load file into memory unsigned char* compressed = NULL; - unsigned long fileLen = 0; + long fileLen = 0; compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); if(NULL == compressed || 0 == fileLen) @@ -582,7 +582,7 @@ bool ZipFile::fileExists(const std::string &fileName) const return ret; } -unsigned char *ZipFile::getFileData(const std::string &fileName, unsigned long *pSize) +unsigned char *ZipFile::getFileData(const std::string &fileName, long *pSize) { unsigned char * pBuffer = NULL; if (pSize) diff --git a/cocos/2d/ZipUtils.h b/cocos/2d/ZipUtils.h index 5564807540..48552502b4 100644 --- a/cocos/2d/ZipUtils.h +++ b/cocos/2d/ZipUtils.h @@ -64,7 +64,7 @@ namespace cocos2d * @since v0.8.1 */ - static int ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out); + static int ccInflateMemory(unsigned char *in, long inLength, unsigned char **out); /** * Inflates either zlib or gzip deflated memory. The inflated memory is @@ -76,7 +76,7 @@ namespace cocos2d * @since v1.0.0 */ - static int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outLenghtHint); + static int ccInflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long outLenghtHint); /** inflates a GZip file into memory * @@ -100,7 +100,7 @@ namespace cocos2d * * @since v3.0 */ - static bool ccIsGZipBuffer(const unsigned char *buffer, int len); + static bool ccIsGZipBuffer(const unsigned char *buffer, long len); /** inflates a CCZ file into memory * @@ -116,7 +116,7 @@ namespace cocos2d * * @since v3.0 */ - static int ccInflateCCZBuffer(const unsigned char *buffer, int len, unsigned char **out); + static int ccInflateCCZBuffer(const unsigned char *buffer, long len, unsigned char **out); /** test a file is a CCZ format file or not * @@ -132,7 +132,7 @@ namespace cocos2d * * @since v3.0 */ - static bool ccIsCCZBuffer(const unsigned char *buffer, int len); + static bool ccIsCCZBuffer(const unsigned char *buffer, long len); /** Sets the pvr.ccz encryption key parts separately for added * security. @@ -187,10 +187,10 @@ namespace cocos2d static void ccSetPvrEncryptionKey(unsigned int keyPart1, unsigned int keyPart2, unsigned int keyPart3, unsigned int keyPart4); private: - static int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength, - unsigned int outLenghtHint); - static inline void ccDecodeEncodedPvr (unsigned int *data, int len); - static inline unsigned int ccChecksumPvr(const unsigned int *data, int len); + static int ccInflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long *outLength, + long outLenghtHint); + static inline void ccDecodeEncodedPvr (unsigned int *data, long len); + static inline unsigned int ccChecksumPvr(const unsigned int *data, long len); static unsigned int s_uEncryptedPvrKeyParts[4]; static unsigned int s_uEncryptionKey[1024]; @@ -253,7 +253,7 @@ namespace cocos2d * * @since v2.0.5 */ - unsigned char *getFileData(const std::string &fileName, unsigned long *pSize); + unsigned char *getFileData(const std::string &fileName, long *size); private: /** Internal data like zip file pointer / file list array and so on */ diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index d7244ba6f0..6760432cad 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -488,7 +488,7 @@ void FileUtils::purgeCachedEntries() _fullPathCache.clear(); } -unsigned char* FileUtils::getFileData(const char* filename, const char* mode, unsigned long * size) +unsigned char* FileUtils::getFileData(const char* filename, const char* mode, long *size) { unsigned char * buffer = NULL; CCASSERT(filename != NULL && size != NULL && mode != NULL, "Invalid parameters."); @@ -518,7 +518,7 @@ unsigned char* FileUtils::getFileData(const char* filename, const char* mode, un return buffer; } -unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char* filename, unsigned long * size) +unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char* filename, long *size) { unsigned char * buffer = NULL; unzFile pFile = NULL; diff --git a/cocos/2d/platform/CCFileUtils.h b/cocos/2d/platform/CCFileUtils.h index 299807af01..855f016fe5 100644 --- a/cocos/2d/platform/CCFileUtils.h +++ b/cocos/2d/platform/CCFileUtils.h @@ -88,7 +88,7 @@ public: * @return Upon success, a pointer to the data is returned, otherwise NULL. * @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned. */ - virtual unsigned char* getFileData(const char* filename, const char* mode, unsigned long * size); + virtual unsigned char* getFileData(const char* filename, const char* mode, long *size); /** * Gets resource file data from a zip file. @@ -98,7 +98,7 @@ public: * @return Upon success, a pointer to the data is returned, otherwise NULL. * @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned. */ - virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, unsigned long *size); + virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, long *size); /** Returns the fullpath for a given filename. diff --git a/cocos/2d/platform/CCImage.h b/cocos/2d/platform/CCImage.h index 25f09dade2..1f2e04ced7 100644 --- a/cocos/2d/platform/CCImage.h +++ b/cocos/2d/platform/CCImage.h @@ -119,10 +119,10 @@ public: * @js NA * @lua NA */ - bool initWithImageData(const unsigned char * data, int dataLen); + bool initWithImageData(const unsigned char * data, long dataLen); // @warning kFmtRawData only support RGBA8888 - bool initWithRawData(const unsigned char * data, int dataLen, int width, int height, int bitsPerComponent, bool preMulti = false); + bool initWithRawData(const unsigned char * data, long dataLen, long width, long height, long bitsPerComponent, bool preMulti = false); /** @brief Create image with specified string. diff --git a/cocos/2d/platform/CCImageCommon_cpp.h b/cocos/2d/platform/CCImageCommon_cpp.h index be7480a0ae..f2fc7a9a08 100644 --- a/cocos/2d/platform/CCImageCommon_cpp.h +++ b/cocos/2d/platform/CCImageCommon_cpp.h @@ -416,7 +416,7 @@ bool Image::initWithImageFile(const char * strPath) SDL_FreeSurface(iSurf); #else - unsigned long bufferLen = 0; + long bufferLen = 0; unsigned char* buffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &bufferLen); if (buffer != nullptr && bufferLen > 0) @@ -432,23 +432,23 @@ bool Image::initWithImageFile(const char * strPath) bool Image::initWithImageFileThreadSafe(const char *fullpath) { - bool bRet = false; - unsigned long dataLen = 0; + bool ret = false; + long dataLen = 0; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) FileUtilsAndroid *fileUitls = (FileUtilsAndroid*)FileUtils::getInstance(); - unsigned char *pBuffer = fileUitls->getFileDataForAsync(fullpath, "rb", &dataLen); + unsigned char *buffer = fileUitls->getFileDataForAsync(fullpath, "rb", &dataLen); #else - unsigned char *pBuffer = FileUtils::getInstance()->getFileData(fullpath, "rb", &dataLen); + unsigned char *buffer = FileUtils::getInstance()->getFileData(fullpath, "rb", &dataLen); #endif - if (pBuffer != NULL && dataLen > 0) + if (buffer != NULL && dataLen > 0) { - bRet = initWithImageData(pBuffer, dataLen); + ret = initWithImageData(buffer, dataLen); } - CC_SAFE_DELETE_ARRAY(pBuffer); - return bRet; + CC_SAFE_DELETE_ARRAY(buffer); + return ret; } -bool Image::initWithImageData(const unsigned char * data, int dataLen) +bool Image::initWithImageData(const unsigned char * data, long dataLen) { bool ret = false; @@ -1190,13 +1190,13 @@ bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen) if (!testFormatForPvr2TCSupport(formatFlags)) { - CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", formatFlags); + CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", (int)formatFlags); return false; } if (v2_pixel_formathash.find(formatFlags) == v2_pixel_formathash.end()) { - CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", formatFlags); + CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", (int)formatFlags); return false; } @@ -1204,7 +1204,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen) if (it == Texture2D::getPixelFormatInfoMap().end()) { - CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", formatFlags); + CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", (int)formatFlags); return false; } @@ -1757,7 +1757,7 @@ bool Image::initWithWebpData(const unsigned char * data, int dataLen) return bRet; } -bool Image::initWithRawData(const unsigned char * data, int dataLen, int width, int height, int bitsPerComponent, bool preMulti) +bool Image::initWithRawData(const unsigned char * data, long dataLen, long width, long height, long bitsPerComponent, bool preMulti) { bool bRet = false; do diff --git a/cocos/2d/platform/CCSAXParser.cpp b/cocos/2d/platform/CCSAXParser.cpp index 0f823f938d..04201557c1 100644 --- a/cocos/2d/platform/CCSAXParser.cpp +++ b/cocos/2d/platform/CCSAXParser.cpp @@ -114,15 +114,15 @@ bool SAXParser::parse(const char* pXMLData, unsigned int uDataLength) bool SAXParser::parse(const char *pszFile) { - bool bRet = false; - unsigned long size = 0; + bool ret = false; + long size = 0; char* pBuffer = (char*)FileUtils::getInstance()->getFileData(pszFile, "rt", &size); if (pBuffer != NULL && size > 0) { - bRet = parse(pBuffer, size); + ret = parse(pBuffer, size); } CC_SAFE_DELETE_ARRAY(pBuffer); - return bRet; + return ret; } void SAXParser::startElement(void *ctx, const CC_XML_CHAR *name, const CC_XML_CHAR **atts) diff --git a/cocos/base/CCString.cpp b/cocos/base/CCString.cpp index f9962b1ba4..67193eb52c 100644 --- a/cocos/base/CCString.cpp +++ b/cocos/base/CCString.cpp @@ -216,15 +216,15 @@ bool String::isEqual(const Object* pObject) String* String::create(const std::string& str) { - String* pRet = new String(str); - pRet->autorelease(); - return pRet; + String* ret = new String(str); + ret->autorelease(); + return ret; } -String* String::createWithData(const unsigned char* pData, unsigned long nLen) +String* String::createWithData(const unsigned char* data, unsigned long nLen) { - String* pRet = NULL; - if (pData != NULL) + String* ret = NULL; + if (data != NULL) { char* pStr = (char*)malloc(nLen+1); if (pStr != NULL) @@ -232,36 +232,36 @@ String* String::createWithData(const unsigned char* pData, unsigned long nLen) pStr[nLen] = '\0'; if (nLen > 0) { - memcpy(pStr, pData, nLen); + memcpy(pStr, data, nLen); } - pRet = String::create(pStr); + ret = String::create(pStr); free(pStr); } } - return pRet; + return ret; } String* String::createWithFormat(const char* format, ...) { - String* pRet = String::create(""); + String* ret = String::create(""); va_list ap; va_start(ap, format); - pRet->initWithFormatAndValist(format, ap); + ret->initWithFormatAndValist(format, ap); va_end(ap); - return pRet; + return ret; } String* String::createWithContentsOfFile(const char* filename) { - unsigned long size = 0; - unsigned char* pData = 0; - String* pRet = NULL; - pData = FileUtils::getInstance()->getFileData(filename, "rb", &size); - pRet = String::createWithData(pData, size); - CC_SAFE_DELETE_ARRAY(pData); - return pRet; + long size = 0; + unsigned char* data = 0; + String* ret = NULL; + data = FileUtils::getInstance()->getFileData(filename, "rb", &size); + ret = String::createWithData(data, size); + CC_SAFE_DELETE_ARRAY(data); + return ret; } void String::acceptVisitor(DataVisitor &visitor) diff --git a/cocos/editor-support/cocosbuilder/CCBReader.cpp b/cocos/editor-support/cocosbuilder/CCBReader.cpp index 938c595f46..154d2b0b36 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.cpp +++ b/cocos/editor-support/cocosbuilder/CCBReader.cpp @@ -244,7 +244,7 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, } std::string strPath = FileUtils::getInstance()->fullPathForFilename(strCCBFileName.c_str()); - unsigned long size = 0; + long size = 0; unsigned char * pBytes = FileUtils::getInstance()->getFileData(strPath.c_str(), "rb", &size); Data *data = new Data(pBytes, size); diff --git a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp index f1aedc7104..e82764ce86 100644 --- a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp +++ b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp @@ -918,7 +918,7 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader // Load sub file std::string path = FileUtils::getInstance()->fullPathForFilename(ccbFileName.c_str()); - unsigned long size = 0; + long size = 0; unsigned char * pBytes = FileUtils::getInstance()->getFileData(path.c_str(), "rb", &size); CCBReader * reader = new CCBReader(pCCBReader); diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 4749f5eaf9..b03d2b1f1f 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -298,7 +298,7 @@ void DataReaderHelper::addDataFromFile(const char *filePath) size_t startPos = filePathStr.find_last_of("."); std::string str = &filePathStr[startPos]; - unsigned long size; + long size; std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); const char *pFileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); @@ -389,7 +389,7 @@ void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target std::string str = &filePathStr[startPos]; std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); - unsigned long size; + long size; data->fileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); if (str.compare(".xml") == 0) diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 77cb5d56de..5e199edbbc 100755 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -207,7 +207,7 @@ UIWidget* CCSGUIReader::widgetFromJsonFile(const char *fileName) JsonDictionary *jsonDict = NULL; jsonpath = FileUtils::getInstance()->fullPathForFilename(fileName); - unsigned long size = 0; + long size = 0; des = (char*)(FileUtils::getInstance()->getFileData(jsonpath.c_str(),"r" , &size)); if(NULL == des || strcmp(des, "") == 0) { @@ -225,7 +225,7 @@ UIWidget* CCSGUIReader::widgetFromJsonFile(const char *fileName) } int texturesCount = DICTOOL->getArrayCount_json(jsonDict, "textures"); - int pos = jsonpath.find_last_of('/'); + long pos = jsonpath.find_last_of('/'); m_strFilePath = jsonpath.substr(0,pos+1); for (int i=0; igetFileData(pPath.c_str(),"r" , &size)); JsonDictionary *jsonDict = new JsonDictionary(); jsonDict->initWithDescription(des); @@ -227,7 +227,7 @@ namespace cocostudio { const char *name = DICTOOL->getStringValue_json(subData, "name"); childrenCount = DICTOOL->getArrayCount_json(jsonDict, "config_file_path"); - for (int i = 0; i < childrenCount; ++i) + for (long i = 0; i < childrenCount; ++i) { const char* plist = DICTOOL->getStringValueFromArray_json(jsonDict, "config_file_path", i); std::string plistpath; @@ -283,7 +283,7 @@ namespace cocostudio { if (nResType == 0) { pAttribute = ComAttribute::create(); - unsigned long size = 0; + long size = 0; const char* pData = 0; pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(), "r", &size)); if(pData != NULL && strcmp(pData, "") != 0) diff --git a/cocos/editor-support/spine/spine-cocos2dx.cpp b/cocos/editor-support/spine/spine-cocos2dx.cpp index cd9ea67e30..dbc389db51 100644 --- a/cocos/editor-support/spine/spine-cocos2dx.cpp +++ b/cocos/editor-support/spine/spine-cocos2dx.cpp @@ -47,7 +47,7 @@ void _AtlasPage_disposeTexture (AtlasPage* self) { } char* _Util_readFile (const char* path, int* length) { - unsigned long size; + long size; char* data = reinterpret_cast(FileUtils::getInstance()->getFileData( FileUtils::getInstance()->fullPathForFilename(path).c_str(), "r", &size)); *length = size; diff --git a/cocos/scripting/javascript/bindings/ScriptingCore.cpp b/cocos/scripting/javascript/bindings/ScriptingCore.cpp index 5d902c1c23..1f7f01c566 100644 --- a/cocos/scripting/javascript/bindings/ScriptingCore.cpp +++ b/cocos/scripting/javascript/bindings/ScriptingCore.cpp @@ -527,7 +527,7 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c // a) check jsc file first std::string byteCodePath = RemoveFileExt(std::string(path)) + BYTE_CODE_FILE_EXT; - unsigned long length = 0; + long length = 0; unsigned char* data = futil->getFileData(byteCodePath.c_str(), "rb", &length); diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 39e01fd1ef..071cbc433d 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -c93df276adb92b5e076db49c4f9482b8eb37d45c \ No newline at end of file +827b30175daeeaa135581f3546d5458db6d9dcdf \ No newline at end of file From c364c4f083c815b133f7f5580e2345b8112b3f77 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 6 Nov 2013 10:55:39 +0800 Subject: [PATCH 20/39] issue #3113: Updating CMakeLists.txt, Improve Copying files. --- build/BuildHelpers.CMakeLists.txt | 60 +++++------------------------ samples/Cpp/HelloCpp/CMakeLists.txt | 5 ++- samples/Cpp/TestCpp/CMakeLists.txt | 5 ++- samples/Lua/HelloLua/CMakeLists.txt | 8 ++-- samples/Lua/TestLua/CMakeLists.txt | 11 +++--- 5 files changed, 27 insertions(+), 62 deletions(-) diff --git a/build/BuildHelpers.CMakeLists.txt b/build/BuildHelpers.CMakeLists.txt index 92d537dd7d..6e848d4f29 100644 --- a/build/BuildHelpers.CMakeLists.txt +++ b/build/BuildHelpers.CMakeLists.txt @@ -1,53 +1,13 @@ -# This file was copied from GamePlay -# Copies files for the given game into the target res directory -# GAME_NAME name of the game -# REL_DIR to which directory these files are relative -# SRC_FILES which files from the REL_DIR to copy (GLOB) -macro(COPY_RES_FILES GAME_NAME GAME_RES_TARGET REL_DIR SRC_FILES) - file( GLOB_RECURSE RES_FILES RELATIVE ${REL_DIR} ${SRC_FILES} ) +macro(pre_build TARGET_NAME) + add_custom_target( ${TARGET_NAME}_PRE_BUILD ALL ) - set(ALL_FILES) - foreach(SRC_FILE ${RES_FILES}) - IF(NOT (SRC_FILE MATCHES "(^\\.\\.)")) - add_custom_command( - OUTPUT "${APP_BIN_DIR}/${SRC_FILE}" - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${REL_DIR}/${SRC_FILE}" - "${APP_BIN_DIR}/Resources/${SRC_FILE}" - COMMENT "Copy ${SRC_FILE}" - ) - list(APPEND ALL_FILES "${APP_BIN_DIR}/${SRC_FILE}" ) - ENDIF(NOT (SRC_FILE MATCHES "(^\\.\\.)")) - endforeach() - # create target for copying these files - add_custom_target( ${GAME_RES_TARGET} DEPENDS ${ALL_FILES} ) -endmacro() + add_custom_command( + TARGET ${TARGET_NAME}_PRE_BUILD + ${ARGN} + PRE_BUILD + COMMENT "${TARGET_NAME}_PRE_BUILD ..." + ) -# convenience to call above with current directory and everything in "res" -macro(COPY_RES GAME_NAME) - # a target for all addition asserts (will be done in default compile, but if you target the executable - # it won't be done -- good for testing) - add_custom_target( ${GAME_NAME}_ASSETS ALL ) - - # copy entire "res" directory and "game.config" if there is one - set(CRG_PATTERN "*") - COPY_RES_FILES( ${GAME_NAME} ${GAME_NAME}_CORE_RES - ${CMAKE_CURRENT_SOURCE_DIR}/Resources - "${CRG_PATTERN}" - ) - add_dependencies( ${GAME_NAME}_ASSETS ${GAME_NAME}_CORE_RES ) -endmacro() - -# Copies resources from an additional directory -# GAME_NAME name of the game -# REL_DIR from which directory -# ARGN which patterns to copy (should include res/ in name if to be placed in the res/ output) -macro(COPY_RES_EXTRA GAME_NAME EXTRA_RES REL_DIR) - # convert src's to full paths (based on rel_dir) - set(SRC_FILES) - foreach(SRC_FILE ${ARGN} ) - list(APPEND SRC_FILES "${REL_DIR}/${SRC_FILE}") - endforeach() - COPY_RES_FILES( ${GAME_NAME} ${GAME_NAME}_${EXTRA_RES} ${REL_DIR} "${SRC_FILES}" ) - add_dependencies( ${GAME_NAME}_ASSETS ${GAME_NAME}_${EXTRA_RES} ) + add_custom_target( ${TARGET_NAME}_CORE_PRE_BUILD ) + add_dependencies( ${TARGET_NAME}_PRE_BUILD ${TARGET_NAME}_CORE_PRE_BUILD ) endmacro() diff --git a/samples/Cpp/HelloCpp/CMakeLists.txt b/samples/Cpp/HelloCpp/CMakeLists.txt index b335cf89fc..667bf7cd18 100644 --- a/samples/Cpp/HelloCpp/CMakeLists.txt +++ b/samples/Cpp/HelloCpp/CMakeLists.txt @@ -18,5 +18,8 @@ set(APP_BIN_DIR "${CMAKE_SOURCE_DIR}/bin/${APP_NAME}") set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") -COPY_RES( ${APP_NAME} ) +pre_build(${APP_NAME} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources + ) diff --git a/samples/Cpp/TestCpp/CMakeLists.txt b/samples/Cpp/TestCpp/CMakeLists.txt index a4237425f9..e5493d194c 100644 --- a/samples/Cpp/TestCpp/CMakeLists.txt +++ b/samples/Cpp/TestCpp/CMakeLists.txt @@ -159,5 +159,8 @@ set(APP_BIN_DIR "${CMAKE_SOURCE_DIR}/bin/${APP_NAME}") set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") -COPY_RES( ${APP_NAME} ) +pre_build(${APP_NAME} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources + ) diff --git a/samples/Lua/HelloLua/CMakeLists.txt b/samples/Lua/HelloLua/CMakeLists.txt index c048fae5c0..e0d1f3a753 100644 --- a/samples/Lua/HelloLua/CMakeLists.txt +++ b/samples/Lua/HelloLua/CMakeLists.txt @@ -33,8 +33,8 @@ set(APP_BIN_DIR "${CMAKE_SOURCE_DIR}/bin/${APP_NAME}") set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") -COPY_RES( ${APP_NAME} ) - -COPY_RES_EXTRA(${APP_NAME} copy_core_scripts ${CMAKE_SOURCE_DIR}/cocos/scripting/lua - script/* +pre_build(${APP_NAME} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua/script ${APP_BIN_DIR}/Resources ) diff --git a/samples/Lua/TestLua/CMakeLists.txt b/samples/Lua/TestLua/CMakeLists.txt index dc81be8941..743f3eeb3f 100644 --- a/samples/Lua/TestLua/CMakeLists.txt +++ b/samples/Lua/TestLua/CMakeLists.txt @@ -33,11 +33,10 @@ set(APP_BIN_DIR "${CMAKE_SOURCE_DIR}/bin/${APP_NAME}") set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") -COPY_RES(${APP_NAME}) -COPY_RES_EXTRA(${APP_NAME} copy_core_scripts ${CMAKE_SOURCE_DIR}/cocos/scripting/lua - script/* - ) -COPY_RES_EXTRA(${APP_NAME} copy_cpp_res ${CMAKE_SOURCE_DIR}/samples/Cpp/TestCpp/Resources - * +pre_build(${APP_NAME} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua/script ${APP_BIN_DIR}/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/samples/Cpp/TestCpp/Resources ${APP_BIN_DIR}/Resources ) From 555f3609c84c87c07f07c2c4172e0967e67f737a Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Tue, 5 Nov 2013 19:02:03 -0800 Subject: [PATCH 21/39] Uses `const std::string&` ... instead of const char* * Because it is more robust * and it is faster... yes faster. It is faster because internally some of our classes use std::string (like FileUtils and Dictionary) so converting back-and-forth from const char * to std::string is very expensive. It is faster to have everthing in std::string as soon as possible to prevent further conversions. There are still some parts of the code that require conversion, but most of the code was converted. --- cocos/2d/CCAnimationCache.cpp | 40 +++++++++---------- cocos/2d/CCAnimationCache.h | 12 +++--- cocos/2d/CCLabel.cpp | 14 +++---- cocos/2d/CCLabel.h | 8 ++-- cocos/2d/CCLabelAtlas.cpp | 4 +- cocos/2d/CCLabelAtlas.h | 2 +- cocos/2d/CCLabelBMFont.cpp | 45 +++++++++------------ cocos/2d/CCLabelBMFont.h | 28 ++++++------- cocos/2d/CCLabelTTF.cpp | 4 +- cocos/2d/CCLabelTTF.h | 2 +- cocos/2d/CCParticleSystem.cpp | 14 +++---- cocos/2d/CCParticleSystem.h | 6 +-- cocos/2d/CCProtocols.h | 2 +- cocos/2d/CCSprite.cpp | 24 +++++------ cocos/2d/CCSprite.h | 14 +++---- cocos/2d/CCSpriteFrame.cpp | 36 ++++++++--------- cocos/2d/CCSpriteFrame.h | 8 ++-- cocos/2d/CCSpriteFrameCache.cpp | 70 ++++++++++++++++----------------- cocos/2d/CCSpriteFrameCache.h | 18 ++++----- 19 files changed, 168 insertions(+), 183 deletions(-) diff --git a/cocos/2d/CCAnimationCache.cpp b/cocos/2d/CCAnimationCache.cpp index 37f516347a..a2c0fa9303 100644 --- a/cocos/2d/CCAnimationCache.cpp +++ b/cocos/2d/CCAnimationCache.cpp @@ -71,22 +71,20 @@ AnimationCache::~AnimationCache() CC_SAFE_RELEASE(_animations); } -void AnimationCache::addAnimation(Animation *animation, const char * name) +void AnimationCache::addAnimation(Animation *animation, const std::string& name) { _animations->setObject(animation, name); } -void AnimationCache::removeAnimation(const char* name) +void AnimationCache::removeAnimation(const std::string& name) { - if (! name) - { + if (name.size()==0) return; - } _animations->removeObjectForKey(name); } -Animation* AnimationCache::getAnimation(const char* name) +Animation* AnimationCache::getAnimation(const std::string& name) { return (Animation*)_animations->objectForKey(name); } @@ -95,17 +93,17 @@ void AnimationCache::parseVersion1(Dictionary* animations) { SpriteFrameCache *frameCache = SpriteFrameCache::getInstance(); - DictElement* pElement = NULL; - CCDICT_FOREACH(animations, pElement) + DictElement* element = NULL; + CCDICT_FOREACH(animations, element) { - Dictionary* animationDict = static_cast(pElement->getObject()); + Dictionary* animationDict = static_cast(element->getObject()); Array* frameNames = static_cast(animationDict->objectForKey("frames")); float delay = animationDict->valueForKey("delay")->floatValue(); Animation* animation = NULL; if ( frameNames == NULL ) { - CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", pElement->getStrKey()); + CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", element->getStrKey()); continue; } @@ -115,11 +113,11 @@ void AnimationCache::parseVersion1(Dictionary* animations) Object* pObj = NULL; CCARRAY_FOREACH(frameNames, pObj) { - const char* frameName = static_cast(pObj)->getCString(); + const std::string& frameName = static_cast(pObj)->getCString(); SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(frameName); if ( ! spriteFrame ) { - CCLOG("cocos2d: AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the SpriteFrameCache. This frame will not be added to the animation.", pElement->getStrKey(), frameName); + CCLOG("cocos2d: AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the SpriteFrameCache. This frame will not be added to the animation.", element->getStrKey(), frameName.c_str()); continue; } @@ -131,15 +129,15 @@ void AnimationCache::parseVersion1(Dictionary* animations) } if ( frames->count() == 0 ) { - CCLOG("cocos2d: AnimationCache: None of the frames for animation '%s' were found in the SpriteFrameCache. Animation is not being added to the Animation Cache.", pElement->getStrKey()); + CCLOG("cocos2d: AnimationCache: None of the frames for animation '%s' were found in the SpriteFrameCache. Animation is not being added to the Animation Cache.", element->getStrKey()); continue; } else if ( frames->count() != frameNames->count() ) { - CCLOG("cocos2d: AnimationCache: An animation in your dictionary refers to a frame which is not in the SpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", pElement->getStrKey()); + CCLOG("cocos2d: AnimationCache: An animation in your dictionary refers to a frame which is not in the SpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", element->getStrKey()); } animation = Animation::create(frames, delay, 1); - AnimationCache::getInstance()->addAnimation(animation, pElement->getStrKey()); + AnimationCache::getInstance()->addAnimation(animation, element->getStrKey()); frames->release(); } } @@ -148,11 +146,11 @@ void AnimationCache::parseVersion2(Dictionary* animations) { SpriteFrameCache *frameCache = SpriteFrameCache::getInstance(); - DictElement* pElement = NULL; - CCDICT_FOREACH(animations, pElement) + DictElement* element = NULL; + CCDICT_FOREACH(animations, element) { - const char* name = pElement->getStrKey(); - Dictionary* animationDict = static_cast(pElement->getObject()); + const char* name = element->getStrKey(); + Dictionary* animationDict = static_cast(element->getObject()); const String* loops = animationDict->valueForKey("loops"); bool restoreOriginalFrame = animationDict->valueForKey("restoreOriginalFrame")->boolValue(); @@ -241,9 +239,9 @@ void AnimationCache::addAnimationsWithDictionary(Dictionary* dictionary) } /** Read an NSDictionary from a plist file and parse it automatically for animations */ -void AnimationCache::addAnimationsWithFile(const char* plist) +void AnimationCache::addAnimationsWithFile(const std::string& plist) { - CCASSERT( plist, "Invalid texture file name"); + CCASSERT( plist.size()>0, "Invalid texture file name"); std::string path = FileUtils::getInstance()->fullPathForFilename(plist); Dictionary* dict = Dictionary::createWithContentsOfFile(path.c_str()); diff --git a/cocos/2d/CCAnimationCache.h b/cocos/2d/CCAnimationCache.h index f30d6ee94f..475c16ce87 100644 --- a/cocos/2d/CCAnimationCache.h +++ b/cocos/2d/CCAnimationCache.h @@ -76,29 +76,29 @@ public: /** Adds a Animation with a name. */ - void addAnimation(Animation *animation, const char * name); + void addAnimation(Animation *animation, const std::string& name); /** Deletes a Animation from the cache. */ - void removeAnimation(const char* name); + void removeAnimation(const std::string& name); /** @deprecated. Use removeAnimation() instead * @js NA * @lua NA */ - CC_DEPRECATED_ATTRIBUTE void removeAnimationByName(const char* name){ removeAnimation(name);} + CC_DEPRECATED_ATTRIBUTE void removeAnimationByName(const std::string& name){ removeAnimation(name);} /** Returns a Animation that was previously added. If the name is not found it will return nil. You should retain the returned copy if you are going to use it. */ - Animation* getAnimation(const char* name); + Animation* getAnimation(const std::string& name); /** @deprecated. Use getAnimation() instead * @js NA * @lua NA */ - CC_DEPRECATED_ATTRIBUTE Animation* animationByName(const char* name){ return getAnimation(name); } + CC_DEPRECATED_ATTRIBUTE Animation* animationByName(const std::string& name){ return getAnimation(name); } /** Adds an animation from an NSDictionary Make sure that the frames were previously loaded in the SpriteFrameCache. @@ -112,7 +112,7 @@ public: * @js addAnimations * @lua addAnimations */ - void addAnimationsWithFile(const char* plist); + void addAnimationsWithFile(const std::string& plist); private: void parseVersion1(Dictionary* animations); diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 68cc984636..0dc7fc5081 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -29,9 +29,9 @@ NS_CC_BEGIN -Label* Label::createWithTTF( const char* label, const char* fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs ) +Label* Label::createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs ) { - FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath, fontSize, glyphs, customGlyphs); + FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), fontSize, glyphs, customGlyphs); if (!tmpAtlas) return nullptr; @@ -48,10 +48,10 @@ Label* Label::createWithTTF( const char* label, const char* fontFilePath, int fo return nullptr; } -Label* Label::createWithBMFont( const char* label, const char* bmfontFilePath, TextHAlignment alignment, int lineSize) +Label* Label::createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment, int lineSize) { - FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath); + FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath.c_str()); if (!tmpAtlas) return 0; @@ -135,12 +135,12 @@ bool Label::init() return true; } -void Label::setString(const char *stringToRender) +void Label::setString(const std::string &stringToRender) { setText(stringToRender, _width, TextHAlignment::CENTER, false); } -bool Label::setText(const char *stringToRender, float lineWidth, TextHAlignment alignment, bool lineBreakWithoutSpaces) +bool Label::setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment, bool lineBreakWithoutSpaces) { if (!_fontAtlas) return false; @@ -159,7 +159,7 @@ bool Label::setText(const char *stringToRender, float lineWidth, TextHAlignment return false; // int numLetter = 0; - unsigned short* utf16String = cc_utf8_to_utf16(stringToRender); + unsigned short* utf16String = cc_utf8_to_utf16(stringToRender.c_str()); if(!utf16String) return false; diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 0d668256f2..a4c9a127e2 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -51,13 +51,13 @@ class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public RGBAPr public: // static create - static Label* createWithTTF(const char* label, const char* fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0); + static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0); - static Label* createWithBMFont(const char* label, const char* bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0); + static Label* createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0); - bool setText(const char *stringToRender, float lineWidth, TextHAlignment alignment = TextHAlignment::LEFT, bool lineBreakWithoutSpaces = false); + bool setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment = TextHAlignment::LEFT, bool lineBreakWithoutSpaces = false); - virtual void setString(const char *stringToRender) override; + virtual void setString(const std::string &stringToRender) override; virtual void setAlignment(TextHAlignment alignment); virtual void setWidth(float width); virtual void setLineBreakWithoutSpace(bool breakWithoutSpace); diff --git a/cocos/2d/CCLabelAtlas.cpp b/cocos/2d/CCLabelAtlas.cpp index ca28f930cb..f1a9126b54 100644 --- a/cocos/2d/CCLabelAtlas.cpp +++ b/cocos/2d/CCLabelAtlas.cpp @@ -186,9 +186,9 @@ void LabelAtlas::updateAtlasValues() } //CCLabelAtlas - LabelProtocol -void LabelAtlas::setString(const char *label) +void LabelAtlas::setString(const std::string &label) { - size_t len = strlen(label); + size_t len = label.size(); if (len > _textureAtlas->getTotalQuads()) { _textureAtlas->resizeCapacity(len); diff --git a/cocos/2d/CCLabelAtlas.h b/cocos/2d/CCLabelAtlas.h index 2c7d98ea5b..b8df38f62d 100644 --- a/cocos/2d/CCLabelAtlas.h +++ b/cocos/2d/CCLabelAtlas.h @@ -87,7 +87,7 @@ public: // super methods virtual void updateAtlasValues(); - virtual void setString(const char *label); + virtual void setString(const std::string &label); virtual const char* getString(void) const; #if CC_LABELATLAS_DEBUG_DRAW diff --git a/cocos/2d/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp index a9270757c7..1000889c62 100644 --- a/cocos/2d/CCLabelBMFont.cpp +++ b/cocos/2d/CCLabelBMFont.cpp @@ -62,7 +62,7 @@ static unsigned short* copyUTF16StringN(unsigned short* str) // static Dictionary* s_pConfigurations = NULL; -CCBMFontConfiguration* FNTConfigLoadFile( const char *fntFile) +CCBMFontConfiguration* FNTConfigLoadFile(const std::string& fntFile) { CCBMFontConfiguration* pRet = NULL; @@ -75,7 +75,7 @@ CCBMFontConfiguration* FNTConfigLoadFile( const char *fntFile) pRet = static_cast( s_pConfigurations->objectForKey(fntFile) ); if( pRet == NULL ) { - pRet = CCBMFontConfiguration::create(fntFile); + pRet = CCBMFontConfiguration::create(fntFile.c_str()); if (pRet) { s_pConfigurations->setObject(pRet, fntFile); @@ -180,7 +180,7 @@ void CCBMFontConfiguration::purgeFontDefDictionary() } } -std::set* CCBMFontConfiguration::parseConfigFile(const char *controlFile) +std::set* CCBMFontConfiguration::parseConfigFile(const std::string& controlFile) { std::string fullpath = FileUtils::getInstance()->fullPathForFilename(controlFile); String *contents = String::createWithContentsOfFile(fullpath.c_str()); @@ -191,7 +191,7 @@ std::set* CCBMFontConfiguration::parseConfigFile(const char *contr if (!contents) { - CCLOG("cocos2d: Error parsing FNTfile %s", controlFile); + CCLOG("cocos2d: Error parsing FNTfile %s", controlFile.c_str()); return NULL; } @@ -259,7 +259,7 @@ std::set* CCBMFontConfiguration::parseConfigFile(const char *contr return validCharsString; } -void CCBMFontConfiguration::parseImageFileName(std::string line, const char *fntFile) +void CCBMFontConfiguration::parseImageFileName(std::string line, const std::string& fntFile) { ////////////////////////////////////////////////////////////////////////// // line to parse: @@ -431,23 +431,23 @@ LabelBMFont * LabelBMFont::create() return NULL; } -LabelBMFont * LabelBMFont::create(const char *str, const char *fntFile, float width, TextHAlignment alignment) +LabelBMFont * LabelBMFont::create(const std::string& str, const std::string& fntFile, float width, TextHAlignment alignment) { return LabelBMFont::create(str, fntFile, width, alignment, Point::ZERO); } -LabelBMFont * LabelBMFont::create(const char *str, const char *fntFile, float width) +LabelBMFont * LabelBMFont::create(const std::string& str, const std::string& fntFile, float width) { return LabelBMFont::create(str, fntFile, width, TextHAlignment::LEFT, Point::ZERO); } -LabelBMFont * LabelBMFont::create(const char *str, const char *fntFile) +LabelBMFont * LabelBMFont::create(const std::string& str, const std::string& fntFile) { return LabelBMFont::create(str, fntFile, kLabelAutomaticWidth, TextHAlignment::LEFT, Point::ZERO); } //LabelBMFont - Creation & Init -LabelBMFont *LabelBMFont::create(const char *str, const char *fntFile, float width/* = kLabelAutomaticWidth*/, TextHAlignment alignment/* = TextHAlignment::LEFT*/, Point imageOffset/* = Point::ZERO*/) +LabelBMFont *LabelBMFont::create(const std::string& str, const std::string& fntFile, float width/* = kLabelAutomaticWidth*/, TextHAlignment alignment/* = TextHAlignment::LEFT*/, Point imageOffset/* = Point::ZERO*/) { LabelBMFont *pRet = new LabelBMFont(); if(pRet && pRet->initWithString(str, fntFile, width, alignment, imageOffset)) @@ -461,22 +461,21 @@ LabelBMFont *LabelBMFont::create(const char *str, const char *fntFile, float wid bool LabelBMFont::init() { - return initWithString(NULL, NULL, kLabelAutomaticWidth, TextHAlignment::LEFT, Point::ZERO); + return initWithString("", "", kLabelAutomaticWidth, TextHAlignment::LEFT, Point::ZERO); } -bool LabelBMFont::initWithString(const char *theString, const char *fntFile, float width/* = kLabelAutomaticWidth*/, TextHAlignment alignment/* = TextHAlignment::LEFT*/, Point imageOffset/* = Point::ZERO*/) +bool LabelBMFont::initWithString(const std::string& theString, const std::string& fntFile, float width/* = kLabelAutomaticWidth*/, TextHAlignment alignment/* = TextHAlignment::LEFT*/, Point imageOffset/* = Point::ZERO*/) { CCASSERT(!_configuration, "re-init is no longer supported"); - CCASSERT( (theString && fntFile) || (theString==NULL && fntFile==NULL), "Invalid params for LabelBMFont"); - + Texture2D *texture = NULL; - if (fntFile) + if (fntFile.size() > 0 ) { CCBMFontConfiguration *newConf = FNTConfigLoadFile(fntFile); if (!newConf) { - CCLOG("cocos2d: WARNING. LabelBMFont: Impossible to create font. Please check file: '%s'", fntFile); + CCLOG("cocos2d: WARNING. LabelBMFont: Impossible to create font. Please check file: '%s'", fntFile.c_str()); release(); return false; } @@ -495,12 +494,7 @@ bool LabelBMFont::initWithString(const char *theString, const char *fntFile, flo texture->autorelease(); } - if (theString == NULL) - { - theString = ""; - } - - if (SpriteBatchNode::initWithTexture(texture, strlen(theString))) + if (SpriteBatchNode::initWithTexture(texture, theString.size())) { _width = width; _alignment = alignment; @@ -724,20 +718,17 @@ void LabelBMFont::createFontChars() } //LabelBMFont - LabelProtocol protocol -void LabelBMFont::setString(const char *newString) +void LabelBMFont::setString(const std::string &newString) { this->setString(newString, true); } -void LabelBMFont::setString(const char *newString, bool needUpdateLabel) +void LabelBMFont::setString(const std::string &newString, bool needUpdateLabel) { - if (newString == NULL) { - newString = ""; - } if (needUpdateLabel) { _initialStringUTF8 = newString; } - unsigned short* utf16String = cc_utf8_to_utf16(newString); + unsigned short* utf16String = cc_utf8_to_utf16(newString.c_str()); setString(utf16String, needUpdateLabel); CC_SAFE_DELETE_ARRAY(utf16String); } diff --git a/cocos/2d/CCLabelBMFont.h b/cocos/2d/CCLabelBMFont.h index 11ff078ac5..0da1584387 100644 --- a/cocos/2d/CCLabelBMFont.h +++ b/cocos/2d/CCLabelBMFont.h @@ -145,16 +145,16 @@ public: /** initializes a BitmapFontConfiguration with a FNT file */ bool initWithFNTfile(const char *FNTfile); - inline const char* getAtlasName(){ return _atlasName.c_str(); } - inline void setAtlasName(const char* atlasName) { _atlasName = atlasName; } + inline const std::string& getAtlasName(){ return _atlasName; } + inline void setAtlasName(const std::string& atlasName) { _atlasName = atlasName; } std::set* getCharacterSet() const; private: - std::set* parseConfigFile(const char *controlFile); + std::set* parseConfigFile(const std::string& controlFile); void parseCharacterDefinition(std::string line, ccBMFontDef *characterDefinition); void parseInfoArguments(std::string line); void parseCommonArguments(std::string line); - void parseImageFileName(std::string line, const char *fntFile); + void parseImageFileName(std::string line, const std::string& fntFile); void parseKerningEntry(std::string line); void purgeKerningDictionary(); void purgeFontDefDictionary(); @@ -209,13 +209,13 @@ public: static void purgeCachedData(); /** creates a bitmap font atlas with an initial string and the FNT file */ - static LabelBMFont * create(const char *str, const char *fntFile, float width, TextHAlignment alignment, Point imageOffset); + static LabelBMFont * create(const std::string& str, const std::string& fntFile, float width, TextHAlignment alignment, Point imageOffset); - static LabelBMFont * create(const char *str, const char *fntFile, float width, TextHAlignment alignment); + static LabelBMFont * create(const std::string& str, const std::string& fntFile, float width, TextHAlignment alignment); - static LabelBMFont * create(const char *str, const char *fntFile, float width); + static LabelBMFont * create(const std::string& str, const std::string& fntFile, float width); - static LabelBMFont * create(const char *str, const char *fntFile); + static LabelBMFont * create(const std::string& str, const std::string& fntFile); /** Creates an label. */ @@ -223,15 +223,15 @@ public: bool init(); /** init a bitmap font atlas with an initial string and the FNT file */ - bool initWithString(const char *str, const char *fntFile, float width = kLabelAutomaticWidth, TextHAlignment alignment = TextHAlignment::LEFT, Point imageOffset = Point::ZERO); + bool initWithString(const std::string& str, const std::string& fntFile, float width = kLabelAutomaticWidth, TextHAlignment alignment = TextHAlignment::LEFT, Point imageOffset = Point::ZERO); /** updates the font chars based on the string to render */ void createFontChars(); // super method - virtual void setString(const char *newString); - virtual void setString(const char *newString, bool needUpdateLabel); + virtual void setString(const std::string& newString); + virtual void setString(const std::string& newString, bool needUpdateLabel); - virtual const char* getString(void) const; + virtual const char* getString() const; virtual void setCString(const char *label); virtual void setAnchorPoint(const Point& var); virtual void updateLabel(); @@ -264,7 +264,7 @@ public: virtual void draw(); #endif // CC_LABELBMFONT_DEBUG_DRAW private: - char * atlasNameFromFntFile(const char *fntFile); + char * atlasNameFromFntFile(const std::string& fntFile); int kerningAmountForFirst(unsigned short first, unsigned short second); float getLetterPosXLeft( Sprite* characterSprite ); float getLetterPosXRight( Sprite* characterSprite ); @@ -309,7 +309,7 @@ protected: /** Free function that parses a FNT file a place it on the cache */ -CC_DLL CCBMFontConfiguration * FNTConfigLoadFile( const char *file ); +CC_DLL CCBMFontConfiguration * FNTConfigLoadFile(const std::string &file); /** Purges the FNT config cache */ CC_DLL void FNTConfigRemoveCache( void ); diff --git a/cocos/2d/CCLabelTTF.cpp b/cocos/2d/CCLabelTTF.cpp index bead3ea020..051b07d9b7 100644 --- a/cocos/2d/CCLabelTTF.cpp +++ b/cocos/2d/CCLabelTTF.cpp @@ -171,10 +171,8 @@ bool LabelTTF::initWithStringAndTextDefinition(const char *string, FontDefinitio } -void LabelTTF::setString(const char *string) +void LabelTTF::setString(const std::string &string) { - CCASSERT(string != NULL, "Invalid string"); - if (_string.compare(string)) { _string = string; diff --git a/cocos/2d/CCLabelTTF.h b/cocos/2d/CCLabelTTF.h index 9243a50e1c..1f785028c4 100644 --- a/cocos/2d/CCLabelTTF.h +++ b/cocos/2d/CCLabelTTF.h @@ -144,7 +144,7 @@ public: /** changes the string to render * @warning Changing the string is as expensive as creating a new LabelTTF. To obtain better performance use LabelAtlas */ - virtual void setString(const char *label); + virtual void setString(const std::string &label); virtual const char* getString(void) const; TextHAlignment getHorizontalAlignment() const; diff --git a/cocos/2d/CCParticleSystem.cpp b/cocos/2d/CCParticleSystem.cpp index 785251ca7a..21c473f2f2 100644 --- a/cocos/2d/CCParticleSystem.cpp +++ b/cocos/2d/CCParticleSystem.cpp @@ -136,7 +136,7 @@ ParticleSystem::ParticleSystem() } // implementation ParticleSystem -ParticleSystem * ParticleSystem::create(const char *plistFile) +ParticleSystem * ParticleSystem::create(const std::string& plistFile) { ParticleSystem *pRet = new ParticleSystem(); if (pRet && pRet->initWithFile(plistFile)) @@ -165,7 +165,7 @@ bool ParticleSystem::init() return initWithTotalParticles(150); } -bool ParticleSystem::initWithFile(const char *plistFile) +bool ParticleSystem::initWithFile(const std::string& plistFile) { bool bRet = false; _plistFile = FileUtils::getInstance()->fullPathForFilename(plistFile); @@ -195,7 +195,7 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary) return initWithDictionary(dictionary, ""); } -bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const char *dirname) +bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::string& dirname) { bool bRet = false; unsigned char *buffer = NULL; @@ -353,17 +353,17 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const char *dirn { string textureDir = textureName.substr(0, rPos + 1); - if (dirname != NULL && textureDir != dirname) + if (dirname.size()>0 && textureDir != dirname) { textureName = textureName.substr(rPos+1); - textureName = string(dirname) + textureName; + textureName = dirname + textureName; } } else { - if (dirname != NULL) + if (dirname.size()>0) { - textureName = string(dirname) + textureName; + textureName = dirname + textureName; } } diff --git a/cocos/2d/CCParticleSystem.h b/cocos/2d/CCParticleSystem.h index ae22671c4c..1cd30b56c8 100644 --- a/cocos/2d/CCParticleSystem.h +++ b/cocos/2d/CCParticleSystem.h @@ -167,7 +167,7 @@ public: http://particledesigner.71squared.com/ @since v2.0 */ - static ParticleSystem * create(const char *plistFile); + static ParticleSystem * create(const std::string& plistFile); //! create a system with a fixed number of particles static ParticleSystem* createWithTotalParticles(unsigned int numberOfParticles); @@ -188,7 +188,7 @@ public: http://particledesigner.71squared.com/ @since v0.99.3 */ - bool initWithFile(const char *plistFile); + bool initWithFile(const std::string& plistFile); /** initializes a QuadParticleSystem from a Dictionary. @since v0.99.3 @@ -198,7 +198,7 @@ public: /** initializes a particle system from a NSDictionary and the path from where to load the png @since v2.1 */ - bool initWithDictionary(Dictionary *dictionary, const char *dirname); + bool initWithDictionary(Dictionary *dictionary, const std::string& dirname); //! Initializes a system with a fixed number of particles virtual bool initWithTotalParticles(unsigned int numberOfParticles); diff --git a/cocos/2d/CCProtocols.h b/cocos/2d/CCProtocols.h index 01b7ebc011..17249816c0 100644 --- a/cocos/2d/CCProtocols.h +++ b/cocos/2d/CCProtocols.h @@ -229,7 +229,7 @@ public: * @js NA * @lua NA */ - virtual void setString(const char *label) = 0; + virtual void setString(const std::string &label) = 0; /** * Returns the string that is currently being used in this label diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 676138d9b1..fa6f4878b0 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -82,7 +82,7 @@ Sprite* Sprite::createWithTexture(Texture2D *texture, const Rect& rect) return NULL; } -Sprite* Sprite::create(const char *filename) +Sprite* Sprite::create(const std::string& filename) { Sprite *sprite = new Sprite(); if (sprite && sprite->initWithFile(filename)) @@ -94,7 +94,7 @@ Sprite* Sprite::create(const char *filename) return NULL; } -Sprite* Sprite::create(const char *filename, const Rect& rect) +Sprite* Sprite::create(const std::string& filename, const Rect& rect) { Sprite *sprite = new Sprite(); if (sprite && sprite->initWithFile(filename, rect)) @@ -118,13 +118,13 @@ Sprite* Sprite::createWithSpriteFrame(SpriteFrame *spriteFrame) return NULL; } -Sprite* Sprite::createWithSpriteFrameName(const char *spriteFrameName) +Sprite* Sprite::createWithSpriteFrameName(const std::string& spriteFrameName) { SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName); #if COCOS2D_DEBUG > 0 char msg[256] = {0}; - sprintf(msg, "Invalid spriteFrameName: %s", spriteFrameName); + sprintf(msg, "Invalid spriteFrameName: %s", spriteFrameName.c_str()); CCASSERT(frame != NULL, msg); #endif @@ -215,9 +215,9 @@ bool Sprite::initWithTexture(Texture2D *texture) return initWithTexture(texture, rect); } -bool Sprite::initWithFile(const char *filename) +bool Sprite::initWithFile(const std::string& filename) { - CCASSERT(filename != NULL, "Invalid filename for sprite"); + CCASSERT(filename.size()>0, "Invalid filename for sprite"); Texture2D *texture = TextureCache::getInstance()->addImage(filename); if (texture) @@ -233,9 +233,9 @@ bool Sprite::initWithFile(const char *filename) return false; } -bool Sprite::initWithFile(const char *filename, const Rect& rect) +bool Sprite::initWithFile(const std::string &filename, const Rect& rect) { - CCASSERT(filename != NULL, ""); + CCASSERT(filename.size()>0, "Invalid filename"); Texture2D *texture = TextureCache::getInstance()->addImage(filename); if (texture) @@ -259,9 +259,9 @@ bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame) return bRet; } -bool Sprite::initWithSpriteFrameName(const char *spriteFrameName) +bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName) { - CCASSERT(spriteFrameName != NULL, ""); + CCASSERT(spriteFrameName.size() > 0, "Invalid spriteFrameName"); SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName); return initWithSpriteFrame(frame); @@ -992,9 +992,9 @@ void Sprite::setDisplayFrame(SpriteFrame *pNewFrame) setTextureRect(pNewFrame->getRect(), _rectRotated, pNewFrame->getOriginalSize()); } -void Sprite::setDisplayFrameWithAnimationName(const char *animationName, int frameIndex) +void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex) { - CCASSERT(animationName, "CCSprite#setDisplayFrameWithAnimationName. animationName must not be NULL"); + CCASSERT(animationName.size()>0, "CCSprite#setDisplayFrameWithAnimationName. animationName must not be NULL"); Animation *a = AnimationCache::getInstance()->getAnimation(animationName); diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index cc6470c7da..7ebf7ff616 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -105,7 +105,7 @@ public: * @param filename The string which indicates a path to image file, e.g., "scene1/monster.png". * @return A valid sprite object that is marked as autoreleased. */ - static Sprite* create(const char *filename); + static Sprite* create(const std::string& filename); /** * Creates a sprite with an image filename and a rect. @@ -114,7 +114,7 @@ public: * @param rect Only the contents inside rect of filename's texture will be applied for this sprite. * @return A valid sprite object that is marked as autoreleased. */ - static Sprite* create(const char *filename, const Rect& rect); + static Sprite* create(const std::string& filename, const Rect& rect); /** * Creates a sprite with an exsiting texture contained in a Texture2D object @@ -154,7 +154,7 @@ public: * @param spriteFrameName A null terminated string which indicates the sprite frame name. * @return A valid sprite object that is marked as autoreleased. */ - static Sprite* createWithSpriteFrameName(const char *spriteFrameName); + static Sprite* createWithSpriteFrameName(const std::string& spriteFrameName); /// @} end of creators group @@ -233,7 +233,7 @@ public: * @param spriteFrameName A key string that can fected a volid SpriteFrame from SpriteFrameCache * @return true if the sprite is initialized properly, false otherwise. */ - virtual bool initWithSpriteFrameName(const char *spriteFrameName); + virtual bool initWithSpriteFrameName(const std::string& spriteFrameName); /** * Initializes a sprite with an image filename. @@ -247,7 +247,7 @@ public: * @js init * @lua init */ - virtual bool initWithFile(const char *filename); + virtual bool initWithFile(const std::string& filename); /** * Initializes a sprite with an image filename, and a rect. @@ -262,7 +262,7 @@ public: * @js init * @lua init */ - virtual bool initWithFile(const char *filename, const Rect& rect); + virtual bool initWithFile(const std::string& filename, const Rect& rect); /// @} end of initializers @@ -354,7 +354,7 @@ public: * Changes the display frame with animation name and index. * The animation name will be get from the AnimationCache */ - virtual void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex); + virtual void setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex); /// @} diff --git a/cocos/2d/CCSpriteFrame.cpp b/cocos/2d/CCSpriteFrame.cpp index 8bc0bafa6d..d2fd2c2495 100644 --- a/cocos/2d/CCSpriteFrame.cpp +++ b/cocos/2d/CCSpriteFrame.cpp @@ -31,61 +31,61 @@ NS_CC_BEGIN // implementation of SpriteFrame -SpriteFrame* SpriteFrame::create(const char* filename, const Rect& rect) +SpriteFrame* SpriteFrame::create(const std::string& filename, const Rect& rect) { - SpriteFrame *pSpriteFrame = new SpriteFrame();; + SpriteFrame *pSpriteFrame = new SpriteFrame(); pSpriteFrame->initWithTextureFilename(filename, rect); pSpriteFrame->autorelease(); return pSpriteFrame; } -SpriteFrame* SpriteFrame::createWithTexture(Texture2D *pobTexture, const Rect& rect) +SpriteFrame* SpriteFrame::createWithTexture(Texture2D *texture, const Rect& rect) { - SpriteFrame *pSpriteFrame = new SpriteFrame();; - pSpriteFrame->initWithTexture(pobTexture, rect); + SpriteFrame *pSpriteFrame = new SpriteFrame(); + pSpriteFrame->initWithTexture(texture, rect); pSpriteFrame->autorelease(); return pSpriteFrame; } -SpriteFrame* SpriteFrame::createWithTexture(Texture2D* pobTexture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize) +SpriteFrame* SpriteFrame::createWithTexture(Texture2D* texture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize) { - SpriteFrame *pSpriteFrame = new SpriteFrame();; - pSpriteFrame->initWithTexture(pobTexture, rect, rotated, offset, originalSize); + SpriteFrame *pSpriteFrame = new SpriteFrame(); + pSpriteFrame->initWithTexture(texture, rect, rotated, offset, originalSize); pSpriteFrame->autorelease(); return pSpriteFrame; } -SpriteFrame* SpriteFrame::create(const char* filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize) +SpriteFrame* SpriteFrame::create(const std::string& filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize) { - SpriteFrame *pSpriteFrame = new SpriteFrame();; + SpriteFrame *pSpriteFrame = new SpriteFrame(); pSpriteFrame->initWithTextureFilename(filename, rect, rotated, offset, originalSize); pSpriteFrame->autorelease(); return pSpriteFrame; } -bool SpriteFrame::initWithTexture(Texture2D* pobTexture, const Rect& rect) +bool SpriteFrame::initWithTexture(Texture2D* texture, const Rect& rect) { Rect rectInPixels = CC_RECT_POINTS_TO_PIXELS(rect); - return initWithTexture(pobTexture, rectInPixels, false, Point::ZERO, rectInPixels.size); + return initWithTexture(texture, rectInPixels, false, Point::ZERO, rectInPixels.size); } -bool SpriteFrame::initWithTextureFilename(const char* filename, const Rect& rect) +bool SpriteFrame::initWithTextureFilename(const std::string& filename, const Rect& rect) { Rect rectInPixels = CC_RECT_POINTS_TO_PIXELS( rect ); return initWithTextureFilename(filename, rectInPixels, false, Point::ZERO, rectInPixels.size); } -bool SpriteFrame::initWithTexture(Texture2D* pobTexture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize) +bool SpriteFrame::initWithTexture(Texture2D* texture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize) { - _texture = pobTexture; + _texture = texture; - if (pobTexture) + if (texture) { - pobTexture->retain(); + texture->retain(); } _rectInPixels = rect; @@ -99,7 +99,7 @@ bool SpriteFrame::initWithTexture(Texture2D* pobTexture, const Rect& rect, bool return true; } -bool SpriteFrame::initWithTextureFilename(const char* filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize) +bool SpriteFrame::initWithTextureFilename(const std::string& filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize) { _texture = NULL; _textureFilename = filename; diff --git a/cocos/2d/CCSpriteFrame.h b/cocos/2d/CCSpriteFrame.h index f9b2d68c4a..4d205d0f8a 100644 --- a/cocos/2d/CCSpriteFrame.h +++ b/cocos/2d/CCSpriteFrame.h @@ -58,12 +58,12 @@ public: /** Create a SpriteFrame with a texture filename, rect in points. It is assumed that the frame was not trimmed. */ - static SpriteFrame* create(const char* filename, const Rect& rect); + static SpriteFrame* create(const std::string& filename, const Rect& rect); /** Create a SpriteFrame with a texture filename, rect, rotated, offset and originalSize in pixels. The originalSize is the size in pixels of the frame before being trimmed. */ - static SpriteFrame* create(const char* filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize); + static SpriteFrame* create(const std::string& filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize); /** Create a SpriteFrame with a texture, rect in points. It is assumed that the frame was not trimmed. @@ -88,7 +88,7 @@ public: /** Initializes a SpriteFrame with a texture filename, rect in points; It is assumed that the frame was not trimmed. */ - bool initWithTextureFilename(const char* filename, const Rect& rect); + bool initWithTextureFilename(const std::string& filename, const Rect& rect); /** Initializes a SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. The originalSize is the size in points of the frame before being trimmed. @@ -100,7 +100,7 @@ public: @since v1.1 */ - bool initWithTextureFilename(const char* filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize); + bool initWithTextureFilename(const std::string& filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize); // attributes diff --git a/cocos/2d/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp index 78fc2f8fa6..7ab33b85fe 100644 --- a/cocos/2d/CCSpriteFrameCache.cpp +++ b/cocos/2d/CCSpriteFrameCache.cpp @@ -102,11 +102,11 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex // check the format CCASSERT(format >=0 && format <= 3, "format is not supported for SpriteFrameCache addSpriteFramesWithDictionary:textureFilename:"); - DictElement* pElement = NULL; - CCDICT_FOREACH(framesDict, pElement) + DictElement* element = NULL; + CCDICT_FOREACH(framesDict, element) { - Dictionary* frameDict = static_cast(pElement->getObject()); - std::string spriteFrameName = pElement->getStrKey(); + Dictionary* frameDict = static_cast(element->getObject()); + std::string spriteFrameName = element->getStrKey(); SpriteFrame* spriteFrame = static_cast(_spriteFrames->objectForKey(spriteFrameName)); if (spriteFrame) { @@ -203,7 +203,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex } } -void SpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, Texture2D *pobTexture) +void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist, Texture2D *pobTexture) { std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszPlist); Dictionary *dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str()); @@ -212,9 +212,9 @@ void SpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, Texture2D * dict->release(); } -void SpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* textureFileName) +void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName) { - CCASSERT(textureFileName, "texture name should not be null"); + CCASSERT(textureFileName.size()>0, "texture name should not be null"); Texture2D *texture = TextureCache::getInstance()->addImage(textureFileName); if (texture) @@ -223,13 +223,13 @@ void SpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* te } else { - CCLOG("cocos2d: SpriteFrameCache: couldn't load texture file. File not found %s", textureFileName); + CCLOG("cocos2d: SpriteFrameCache: couldn't load texture file. File not found %s", textureFileName.c_str()); } } -void SpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist) +void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist) { - CCASSERT(pszPlist, "plist filename should not be NULL"); + CCASSERT(pszPlist.size()>0, "plist filename should not be NULL"); if (_loadedFileNames->find(pszPlist) == _loadedFileNames->end()) { @@ -280,7 +280,7 @@ void SpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist) } } -void SpriteFrameCache::addSpriteFrame(SpriteFrame *pobFrame, const char *pszFrameName) +void SpriteFrameCache::addSpriteFrame(SpriteFrame *pobFrame, const std::string& pszFrameName) { _spriteFrames->setObject(pobFrame, pszFrameName); } @@ -295,14 +295,14 @@ void SpriteFrameCache::removeSpriteFrames(void) void SpriteFrameCache::removeUnusedSpriteFrames(void) { bool bRemoved = false; - DictElement* pElement = NULL; - CCDICT_FOREACH(_spriteFrames, pElement) + DictElement* element = NULL; + CCDICT_FOREACH(_spriteFrames, element) { - SpriteFrame* spriteFrame = static_cast(pElement->getObject()); + SpriteFrame* spriteFrame = static_cast(element->getObject()); if( spriteFrame->retainCount() == 1 ) { - CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", pElement->getStrKey()); - _spriteFrames->removeObjectForElememt(pElement); + CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", element->getStrKey()); + _spriteFrames->removeObjectForElememt(element); bRemoved = true; } } @@ -315,16 +315,14 @@ void SpriteFrameCache::removeUnusedSpriteFrames(void) } -void SpriteFrameCache::removeSpriteFrameByName(const char *pszName) +void SpriteFrameCache::removeSpriteFrameByName(const std::string& name) { // explicit nil handling - if( ! pszName ) - { + if( ! name.size()>0 ) return; - } // Is this an alias ? - String* key = (String*)_spriteFramesAliases->objectForKey(pszName); + String* key = (String*)_spriteFramesAliases->objectForKey(name); if (key) { @@ -333,20 +331,20 @@ void SpriteFrameCache::removeSpriteFrameByName(const char *pszName) } else { - _spriteFrames->removeObjectForKey(pszName); + _spriteFrames->removeObjectForKey(name); } // XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache _loadedFileNames->clear(); } -void SpriteFrameCache::removeSpriteFramesFromFile(const char* plist) +void SpriteFrameCache::removeSpriteFramesFromFile(const std::string& plist) { std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist); Dictionary* dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str()); if (dict == nullptr) { - CCLOG("cocos2d:SpriteFrameCache:removeSpriteFramesFromFile: create dict by %s fail.",plist); + CCLOG("cocos2d:SpriteFrameCache:removeSpriteFramesFromFile: create dict by %s fail.",plist.c_str()); return; } removeSpriteFramesFromDictionary((Dictionary*)dict); @@ -365,12 +363,12 @@ void SpriteFrameCache::removeSpriteFramesFromDictionary(Dictionary* dictionary) Dictionary* framesDict = static_cast(dictionary->objectForKey("frames")); Array* keysToRemove = Array::create(); - DictElement* pElement = NULL; - CCDICT_FOREACH(framesDict, pElement) + DictElement* element = NULL; + CCDICT_FOREACH(framesDict, element) { - if (_spriteFrames->objectForKey(pElement->getStrKey())) + if (_spriteFrames->objectForKey(element->getStrKey())) { - keysToRemove->addObject(String::create(pElement->getStrKey())); + keysToRemove->addObject(String::create(element->getStrKey())); } } @@ -381,33 +379,33 @@ void SpriteFrameCache::removeSpriteFramesFromTexture(Texture2D* texture) { Array* keysToRemove = Array::create(); - DictElement* pElement = NULL; - CCDICT_FOREACH(_spriteFrames, pElement) + DictElement* element = NULL; + CCDICT_FOREACH(_spriteFrames, element) { - string key = pElement->getStrKey(); + string key = element->getStrKey(); SpriteFrame* frame = static_cast(_spriteFrames->objectForKey(key.c_str())); if (frame && (frame->getTexture() == texture)) { - keysToRemove->addObject(String::create(pElement->getStrKey())); + keysToRemove->addObject(String::create(element->getStrKey())); } } _spriteFrames->removeObjectsForKeys(keysToRemove); } -SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const char *pszName) +SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const std::string& name) { - SpriteFrame* frame = (SpriteFrame*)_spriteFrames->objectForKey(pszName); + SpriteFrame* frame = (SpriteFrame*)_spriteFrames->objectForKey(name); if (!frame) { // try alias dictionary - String *key = (String*)_spriteFramesAliases->objectForKey(pszName); + String *key = (String*)_spriteFramesAliases->objectForKey(name); if (key) { frame = (SpriteFrame*)_spriteFrames->objectForKey(key->getCString()); if (! frame) { - CCLOG("cocos2d: SpriteFrameCache: Frame '%s' not found", pszName); + CCLOG("cocos2d: SpriteFrameCache: Frame '%s' not found", name.c_str()); } } } diff --git a/cocos/2d/CCSpriteFrameCache.h b/cocos/2d/CCSpriteFrameCache.h index c7249d222c..11733fa0ff 100644 --- a/cocos/2d/CCSpriteFrameCache.h +++ b/cocos/2d/CCSpriteFrameCache.h @@ -85,29 +85,29 @@ public: public: /** Adds multiple Sprite Frames from a plist file. * A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png - * If you want to use another texture, you should use the addSpriteFramesWithFile(const char *plist, const char *textureFileName) method. + * If you want to use another texture, you should use the addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName) method. * @js addSpriteFrames * @lua addSpriteFrames */ - void addSpriteFramesWithFile(const char *plist); + void addSpriteFramesWithFile(const std::string& plist); /** Adds multiple Sprite Frames from a plist file. The texture will be associated with the created sprite frames. @since v0.99.5 * @js addSpriteFrames * @lua addSpriteFrames */ - void addSpriteFramesWithFile(const char* plist, const char* textureFileName); + void addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName); /** Adds multiple Sprite Frames from a plist file. The texture will be associated with the created sprite frames. * @js addSpriteFrames * @lua addSpriteFrames */ - void addSpriteFramesWithFile(const char *plist, Texture2D *texture); + void addSpriteFramesWithFile(const std::string&plist, Texture2D *texture); /** Adds an sprite frame with a given name. If the name already exists, then the contents of the old name will be replaced with the new one. */ - void addSpriteFrame(SpriteFrame *frame, const char *frameName); + void addSpriteFrame(SpriteFrame *frame, const std::string& frameName); /** Purges the dictionary of loaded sprite frames. * Call this method if you receive the "Memory Warning". @@ -124,14 +124,14 @@ public: void removeUnusedSpriteFrames(void); /** Deletes an sprite frame from the sprite frame cache. */ - void removeSpriteFrameByName(const char *name); + void removeSpriteFrameByName(const std::string& name); /** Removes multiple Sprite Frames from a plist file. * Sprite Frames stored in this file will be removed. * It is convenient to call this method when a specific texture needs to be removed. * @since v0.99.5 */ - void removeSpriteFramesFromFile(const char* plist); + void removeSpriteFramesFromFile(const std::string& plist); /** Removes all Sprite Frames associated with the specified textures. * It is convenient to call this method when a specific texture needs to be removed. @@ -145,10 +145,10 @@ public: * @js getSpriteFrame * @lua getSpriteFrame */ - SpriteFrame* getSpriteFrameByName(const char *name); + SpriteFrame* getSpriteFrameByName(const std::string& name); /** @deprecated use getSpriteFrameByName() instead */ - CC_DEPRECATED_ATTRIBUTE SpriteFrame* spriteFrameByName(const char *name) { return getSpriteFrameByName(name); } + CC_DEPRECATED_ATTRIBUTE SpriteFrame* spriteFrameByName(const std::string&name) { return getSpriteFrameByName(name); } private: /*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames. From f05c1590ae426078dc6af3d1bd1099f6b5f966c2 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Wed, 6 Nov 2013 11:20:16 +0800 Subject: [PATCH 22/39] 1.fix particle kCCPositionTypeFree state bug --- cocos/editor-support/cocostudio/CCArmature.h | 2 +- cocos/editor-support/cocostudio/CCDisplayFactory.cpp | 9 +++++++++ cocos/editor-support/cocostudio/CCDisplayManager.cpp | 8 ++++++++ cocos/editor-support/cocostudio/CCProcessBase.h | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmature.h b/cocos/editor-support/cocostudio/CCArmature.h index 6182072265..e29323ff86 100644 --- a/cocos/editor-support/cocostudio/CCArmature.h +++ b/cocos/editor-support/cocostudio/CCArmature.h @@ -94,7 +94,7 @@ public: * @js NA * @lua NA */ - ~Armature(void); + virtual ~Armature(void); /** * Init the empty armature diff --git a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp index 7f329ff3cc..a4f1432727 100644 --- a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp @@ -255,6 +255,15 @@ void DisplayFactory::createParticleDisplay(Bone *bone, DecorativeDisplay *decoDi { ParticleDisplayData *displayData = (ParticleDisplayData *)decoDisplay->getDisplayData(); ParticleSystem *system = ParticleSystemQuad::create(displayData->plist.c_str()); + + system->removeFromParent(); + + Armature *armature = bone->getArmature(); + if (armature) + { + system->setParent(armature); + } + decoDisplay->setDisplay(system); } void DisplayFactory::updateParticleDisplay(Bone *bone, Node *display, float dt) diff --git a/cocos/editor-support/cocostudio/CCDisplayManager.cpp b/cocos/editor-support/cocostudio/CCDisplayManager.cpp index 52af6b2d1d..ce808ca3b9 100644 --- a/cocos/editor-support/cocostudio/CCDisplayManager.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayManager.cpp @@ -149,6 +149,14 @@ void DisplayManager::addDisplay(Node *display, int index) else if (dynamic_cast(display)) { displayData = ParticleDisplayData::create(); + + display->removeFromParent(); + + Armature *armature = _bone->getArmature(); + if (armature) + { + display->setParent(armature); + } } else if(Armature *armature = dynamic_cast(display)) { diff --git a/cocos/editor-support/cocostudio/CCProcessBase.h b/cocos/editor-support/cocostudio/CCProcessBase.h index c6b62793b4..2b3ef4ab47 100644 --- a/cocos/editor-support/cocostudio/CCProcessBase.h +++ b/cocos/editor-support/cocostudio/CCProcessBase.h @@ -58,7 +58,7 @@ public: * @js NA * @lua NA */ - ~ProcessBase(void); + virtual ~ProcessBase(void); /** * Play animation by animation name. From c32628e93039f22a833e45ace1996018e62be46a Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 6 Nov 2013 14:19:08 +0800 Subject: [PATCH 23/39] [ci skip] --- CHANGELOG | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 797c52821d..e206d5cea7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,18 +10,19 @@ cocos2d-x-3.0alpha1 @??? 2013 [FIX] Could not set next animation in CCBAnimationCompleted callback. [FIX] The Node's anchor point was changed after being added to ScrollView. [FIX] Refactored and improved EventDispatcher. - [NEW] Added Mouse Support For Desktop Platforms. [FIX] EventListeners can't be removed sometimes. [FIX] When parsing XML using TinyXML, the data size has to be specified. + [FIX] Parameter type: const char* -> const string& [NEW] Arm64 support. + [NEW] Added Mouse Support For Desktop Platforms. [Android] [FIX] Added EGL_RENDERABLE_TYPE to OpenGL attributes - [NEW] Added Cocos2dxHelper.runOnGLThread(Runnable) again [FIX] Fixed application will crash when pause and resume. [FIX] Clear NoSuchMethodError Exception when JniHelper fails to find method id [NEW] Added xlargeScreens="true" to supports-screens [NEW] Added build/android-build.py to build all Android samples, and remove all build_native.sh/cmd [NEW] Added build_native.py to build template projects, and remove build_native.sh/cmd + [NEW] Added Cocos2dxHelper.runOnGLThread(Runnable) again [Mac] [FIX] Removed unused CCLOG() from GL initialization [iOS] From d7ed908818bc79139685dcbe734680183a6319aa Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Wed, 6 Nov 2013 06:20:17 +0000 Subject: [PATCH 24/39] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index c2b42be577..e150a74a02 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit c2b42be577425e4dd6c2501e8f0cd1520ca3d059 +Subproject commit e150a74a028e26cff0dac7d2238e2cd16fbaf370 From f3c40a3e7aea34bdd59b42d99dcc2b4f0d934cc9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 6 Nov 2013 14:54:35 +0800 Subject: [PATCH 25/39] issue #3113: 32Bit fix and 13.10 32bit complication is ok. --- cocos/2d/CMakeLists.txt | 2 ++ cocos/audio/CMakeLists.txt | 8 +++++++- cocos/network/CMakeLists.txt | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index f147d233b6..9446d95364 100644 --- a/cocos/2d/CMakeLists.txt +++ b/cocos/2d/CMakeLists.txt @@ -134,9 +134,11 @@ target_link_libraries(cocos2d freetype fontconfig png + pthread glfw GLEW GL + X11 rt z ) diff --git a/cocos/audio/CMakeLists.txt b/cocos/audio/CMakeLists.txt index 9e88293ddd..12fde54f25 100644 --- a/cocos/audio/CMakeLists.txt +++ b/cocos/audio/CMakeLists.txt @@ -7,8 +7,14 @@ add_library(audio STATIC ${AUDIO_SRC} ) +if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) +set(FMOD_LIB "fmodex64") +else() +set(FMOD_LIB "fmodex") +endif() + target_link_libraries(audio - fmodex64 + ${FMOD_LIB} ) set_target_properties(audio diff --git a/cocos/network/CMakeLists.txt b/cocos/network/CMakeLists.txt index 3bd130111b..f2deb9b365 100644 --- a/cocos/network/CMakeLists.txt +++ b/cocos/network/CMakeLists.txt @@ -9,6 +9,10 @@ add_library(network STATIC target_link_libraries(network curl + ldap + lber + idn + rtmp ) set_target_properties(network From 12d6bc1722d9b4cf35f433c5cd706a9c504a6ad0 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Wed, 6 Nov 2013 15:25:44 +0800 Subject: [PATCH 26/39] 1. change CCARRAY_FOREACH to range-based loop --- .../editor-support/cocostudio/CCArmature.cpp | 27 +++++++----------- cocos/editor-support/cocostudio/CCArmature.h | 6 ++-- .../cocostudio/CCArmatureAnimation.cpp | 16 ++++------- .../cocostudio/CCArmatureDataManager.cpp | 2 +- .../editor-support/cocostudio/CCBatchNode.cpp | 10 +++---- cocos/editor-support/cocostudio/CCBone.cpp | 27 ++++++++++-------- cocos/editor-support/cocostudio/CCBone.h | 7 ++++- .../cocostudio/CCColliderDetector.cpp | 28 +++++++------------ .../cocostudio/CCDisplayFactory.cpp | 2 +- .../cocostudio/CCDisplayManager.cpp | 6 ++-- 10 files changed, 58 insertions(+), 73 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index 7cd7ad9295..b09922ff70 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -335,7 +335,7 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName) } } -const Dictionary *Armature::getBoneDic() const +Dictionary *Armature::getBoneDic() const { return _boneDic; } @@ -451,8 +451,7 @@ void Armature::update(float dt) { _animation->update(dt); - Object *object = nullptr; - CCARRAY_FOREACH(_topBoneList, object) + for (auto object : *_topBoneList) { static_cast(object)->update(dt); } @@ -468,8 +467,7 @@ void Armature::draw() GL::blendFunc(_blendFunc.src, _blendFunc.dst); } - Object *object = nullptr; - CCARRAY_FOREACH(_children, object) + for (auto object : *_children) { if (Bone *bone = dynamic_cast(object)) { @@ -642,8 +640,7 @@ Rect Armature::getBoundingBox() const Rect boundingBox = Rect(0, 0, 0, 0); - Object *object = nullptr; - CCARRAY_FOREACH(_children, object) + for(auto object : *_children) { if (Bone *bone = dynamic_cast(object)) { @@ -754,17 +751,15 @@ void Armature::setBody(b2Body *body) _body = body; _body->SetUserData(this); - Object *object = nullptr; - CCARRAY_FOREACH(_children, object) + for(auto object : *_children) { if (Bone *bone = dynamic_cast(object)) { Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - Object *displayObject = nullptr; - CCARRAY_FOREACH(displayList, displayObject) + for(auto displayObject : displayList) { - ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); + ColliderDetector *detector = static_cast(displayObject)->getColliderDetector(); if (detector != nullptr) { detector->setBody(_body); @@ -802,17 +797,15 @@ void Armature::setBody(cpBody *body) _body = body; _body->data = this; - Object *object = nullptr; - CCARRAY_FOREACH(_children, object) + for(auto object: *_children) { if (Bone *bone = dynamic_cast(object)) { Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - Object *displayObject = nullptr; - CCARRAY_FOREACH(displayList, displayObject) + for(auto displayObject: *displayList) { - ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); + ColliderDetector *detector = static_cast(displayObject)->getColliderDetector(); if (detector != nullptr) { detector->setBody(_body); diff --git a/cocos/editor-support/cocostudio/CCArmature.h b/cocos/editor-support/cocostudio/CCArmature.h index e29323ff86..3ace91b05e 100644 --- a/cocos/editor-support/cocostudio/CCArmature.h +++ b/cocos/editor-support/cocostudio/CCArmature.h @@ -140,7 +140,7 @@ public: * Get Armature's bone dictionary * @return Armature's bone dictionary */ - const cocos2d::Dictionary *getBoneDic() const; + cocos2d::Dictionary *getBoneDic() const; /** * This boundingBox will calculate all bones' boundingBox every time @@ -180,10 +180,10 @@ public: virtual void setArmatureData(ArmatureData *armatureData) { _armatureData = armatureData; } - virtual const ArmatureData *getArmatureData() const { return _armatureData; } + virtual ArmatureData *getArmatureData() const { return _armatureData; } virtual void setBatchNode(BatchNode *batchNode) { _batchNode = batchNode; } - virtual const BatchNode *getBatchNode() const { return _batchNode; } + virtual BatchNode *getBatchNode() const { return _batchNode; } virtual void setName(const std::string &name) { _name = name; } virtual const std::string &getName() const { return _name; } diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp index 6b234782bd..49aa8e1c6f 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp @@ -94,8 +94,7 @@ bool ArmatureAnimation::init(Armature *armature) void ArmatureAnimation:: pause() { - Object *object = nullptr; - CCARRAY_FOREACH(_tweenList, object) + for(auto object : *_tweenList) { static_cast(object)->pause(); } @@ -104,8 +103,7 @@ void ArmatureAnimation:: pause() void ArmatureAnimation::resume() { - Object *object = nullptr; - CCARRAY_FOREACH(_tweenList, object) + for(auto object : *_tweenList) { static_cast(object)->resume(); } @@ -114,8 +112,7 @@ void ArmatureAnimation::resume() void ArmatureAnimation::stop() { - Object *object = nullptr; - CCARRAY_FOREACH(_tweenList, object) + for(auto object : *_tweenList) { static_cast(object)->stop(); } @@ -302,8 +299,7 @@ void ArmatureAnimation::gotoAndPlay(int frameIndex) _currentPercent = (float)_curFrameIndex / (float)_movementData->duration; _currentFrame = _nextFrameIndex * _currentPercent; - Object *object = nullptr; - CCARRAY_FOREACH(_tweenList, object) + for(auto object : *_tweenList) { static_cast(object)->gotoAndPlay(frameIndex); } @@ -327,8 +323,8 @@ int ArmatureAnimation::getMovementCount() const void ArmatureAnimation::update(float dt) { ProcessBase::update(dt); - Object *object = nullptr; - CCARRAY_FOREACH(_tweenList, object) + + for(auto object : *_tweenList) { static_cast(object)->update(dt); } diff --git a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp index 0e139ef560..57f9bf5cdc 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp @@ -136,7 +136,7 @@ void ArmatureDataManager::removeArmatureFileInfo(const char *configFilePath) } _relativeDatas.erase(configFilePath); - DataReaderHelper::sharedDataReaderHelper()->removeConfigFile(configFilePath); + DataReaderHelper::getInstance()->removeConfigFile(configFilePath); } } diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index 36158a12dd..7219969b57 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -90,8 +90,7 @@ void BatchNode::addChild(Node *child, int zOrder, int tag) Bone *bone = static_cast(element->getObject()); Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - Object *object = nullptr; - CCARRAY_FOREACH(displayList, object) + for(auto object : *displayList) { DecorativeDisplay *display = static_cast(object); @@ -118,8 +117,7 @@ void BatchNode::removeChild(Node* child, bool cleanup) Bone *bone = static_cast(element->getObject()); Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - Object *object = nullptr; - CCARRAY_FOREACH(displayList, object) + for(auto object : *displayList) { DecorativeDisplay *display = static_cast(object); @@ -166,8 +164,8 @@ void BatchNode::visit() void BatchNode::draw() { CC_NODE_DRAW_SETUP(); - Object *object = nullptr; - CCARRAY_FOREACH(_children, object) + + for(auto object : *_children) { Armature *armature = dynamic_cast(object); if (armature) diff --git a/cocos/editor-support/cocostudio/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index 26c5653d58..cbd4544120 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -229,11 +229,13 @@ void Bone::update(float delta) DisplayFactory::updateDisplay(this, delta, _boneTransformDirty || _armature->getArmatureTransformDirty()); - Object *object = nullptr; - CCARRAY_FOREACH(_children, object) + if (_children) { - Bone *childBone = (Bone *)object; - childBone->update(delta); + for(auto object : *_children) + { + Bone *childBone = (Bone *)object; + childBone->update(delta); + } } _boneTransformDirty = false; @@ -322,16 +324,16 @@ void Bone::addChildBone(Bone *child) void Bone::removeChildBone(Bone *bone, bool recursion) { - if ( _children->getIndexOfObject(bone) != UINT_MAX ) + if (_children && _children->getIndexOfObject(bone) != UINT_MAX ) { if(recursion) { - Array *_ccbones = bone->_children; - Object *_object = nullptr; - CCARRAY_FOREACH(_ccbones, _object) + Array *ccbones = bone->_children; + + for(auto object : *ccbones) { - Bone *_ccBone = (Bone *)_object; - bone->removeChildBone(_ccBone, recursion); + Bone *ccBone = (Bone *)object; + bone->removeChildBone(ccBone, recursion); } } @@ -412,6 +414,7 @@ DisplayType Bone::getDisplayRenderNodeType() return _displayManager->getDisplayRenderNodeType(); } + void Bone::addDisplay(DisplayData *displayData, int index) { _displayManager->addDisplay(displayData, index); @@ -449,8 +452,8 @@ Array *Bone::getColliderBodyList() void Bone::setColliderFilter(ColliderFilter *filter) { Array *array = _displayManager->getDecorativeDisplayList(); - Object *object = nullptr; - CCARRAY_FOREACH(array, object) + + for(auto object : *array) { DecorativeDisplay *decoDisplay = static_cast(object); if (ColliderDetector *detector = decoDisplay->getColliderDetector()) diff --git a/cocos/editor-support/cocostudio/CCBone.h b/cocos/editor-support/cocostudio/CCBone.h index 9082f1ebb3..4d67c41e2e 100644 --- a/cocos/editor-support/cocostudio/CCBone.h +++ b/cocos/editor-support/cocostudio/CCBone.h @@ -176,6 +176,11 @@ public: virtual void setIgnoreMovementBoneData(bool ignore) { _ignoreMovementBoneData = ignore; } virtual bool isIgnoreMovementBoneData() const { return _ignoreMovementBoneData; } + /* + * This function is deprecated, please use isIgnoreMovementBoneData() + */ + CC_DEPRECATED_ATTRIBUTE virtual bool getIgnoreMovementBoneData() const { return isIgnoreMovementBoneData(); } + virtual void setBlendType(BlendType type) { _blendType = type; } virtual BlendType getBlendType() const { return _blendType; } @@ -184,7 +189,7 @@ public: virtual void setName(const std::string &name) { _name = name; } virtual const std::string getName() const { return _name; } - virtual const BaseData *getWorldInfo() const { return _worldInfo; } + virtual BaseData *getWorldInfo() const { return _worldInfo; } protected: void applyParentTransform(Bone *parent); diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.cpp b/cocos/editor-support/cocostudio/CCColliderDetector.cpp index adbea59a31..35d1fe95f3 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.cpp +++ b/cocos/editor-support/cocostudio/CCColliderDetector.cpp @@ -198,8 +198,7 @@ void ColliderDetector::addContourData(ContourData *contourData) void ColliderDetector::addContourDataList(Array *contourDataList) { - Object *object = nullptr; - CCARRAY_FOREACH(contourDataList, object) + for(auto object : *contourDataList) { addContourData((ContourData *)object); } @@ -207,8 +206,7 @@ void ColliderDetector::addContourDataList(Array *contourDataList) void ColliderDetector::removeContourData(ContourData *contourData) { - Object *object = nullptr; - CCARRAY_FOREACH(_colliderBodyList, object) + for(auto object : *_colliderBodyList) { ColliderBody *body = (ColliderBody*)object; if (body && body->getContourData() == contourData) @@ -242,8 +240,7 @@ void ColliderDetector::setActive(bool active) } else { - Object *object = nullptr; - CCARRAY_FOREACH(_colliderBodyList, object) + for(auto object : *_colliderBodyList) { ColliderBody *colliderBody = (ColliderBody *)object; b2Fixture *fixture = colliderBody->getB2Fixture(); @@ -256,10 +253,9 @@ void ColliderDetector::setActive(bool active) #elif ENABLE_PHYSICS_CHIPMUNK_DETECT if (_body) { - Object *object = nullptr; if (_active) { - CCARRAY_FOREACH(_colliderBodyList, object) + for(auto object : *_colliderBodyList) { ColliderBody *colliderBody = (ColliderBody *)object; cpShape *shape = colliderBody->getShape(); @@ -271,7 +267,7 @@ void ColliderDetector::setActive(bool active) } else { - CCARRAY_FOREACH(_colliderBodyList, object) + for(auto object : *_colliderBodyList) { ColliderBody *colliderBody = (ColliderBody *)object; cpShape *shape = colliderBody->getShape(); @@ -299,8 +295,7 @@ void ColliderDetector::setColliderFilter(ColliderFilter *filter) { *_filter = *filter; - Object *object = nullptr; - CCARRAY_FOREACH(_colliderBodyList, object) + for(auto object : *_colliderBodyList) { ColliderBody *colliderBody = (ColliderBody *)object; colliderBody->setColliderFilter(filter); @@ -333,8 +328,7 @@ void ColliderDetector::updateTransform(AffineTransform &t) return; } - Object *object = nullptr; - CCARRAY_FOREACH(_colliderBodyList, object) + for(auto object : *_colliderBodyList) { ColliderBody *colliderBody = (ColliderBody *)object; ContourData *contourData = colliderBody->getContourData(); @@ -408,8 +402,7 @@ void ColliderDetector::setBody(b2Body *pBody) { _body = pBody; - Object *object = nullptr; - CCARRAY_FOREACH(_colliderBodyList, object) + for(auto object : *_colliderBodyList) { ColliderBody *colliderBody = (ColliderBody *)object; @@ -420,7 +413,7 @@ void ColliderDetector::setBody(b2Body *pBody) b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.count()]; int i = 0; - CCARRAY_FOREACH(array, object) + for(auto object : *array) { ContourVertex2 *v = (ContourVertex2 *)object; b2bv[i].Set(v->x / PT_RATIO, v->y / PT_RATIO); @@ -459,8 +452,7 @@ void ColliderDetector::setBody(cpBody *pBody) { _body = pBody; - Object *object = nullptr; - CCARRAY_FOREACH(_colliderBodyList, object) + for(auto object : *_colliderBodyList) { ColliderBody *colliderBody = (ColliderBody *)object; diff --git a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp index a4f1432727..46c7750d48 100644 --- a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp @@ -245,7 +245,7 @@ void DisplayFactory::updateArmatureDisplay(Bone *bone, Node *display, float dt) void DisplayFactory::addParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) { - ParticleDisplayData *adp = ParticleDisplayData::create(); ; + ParticleDisplayData *adp = ParticleDisplayData::create(); adp->copy((ParticleDisplayData *)displayData); decoDisplay->setDisplayData(adp); diff --git a/cocos/editor-support/cocostudio/CCDisplayManager.cpp b/cocos/editor-support/cocostudio/CCDisplayManager.cpp index ce808ca3b9..a8c8f5d760 100644 --- a/cocos/editor-support/cocostudio/CCDisplayManager.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayManager.cpp @@ -318,11 +318,9 @@ void DisplayManager::initDisplayList(BoneData *boneData) CS_RETURN_IF(!boneData); - Object *object = nullptr; - Array *displayDataList = &boneData->displayDataList; - CCARRAY_FOREACH(displayDataList, object) + for(auto object : boneData->displayDataList) { - DisplayData *displayData = (DisplayData *)object; + DisplayData *displayData = static_cast(object); DecorativeDisplay *decoDisplay = DecorativeDisplay::create(); decoDisplay->setDisplayData(displayData); From 2e80e95a37bb424d8cccc87ce7a3697d75b9b2fe Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 6 Nov 2013 15:26:33 +0800 Subject: [PATCH 27/39] [Linux] compilation fix for PR #4099 --- cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp b/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp index a3ae0474d8..69967031a8 100644 --- a/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp +++ b/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp @@ -46,7 +46,7 @@ extern "C" } filename.append(".lua"); - unsigned long codeBufferSize = 0; + long codeBufferSize = 0; unsigned char* codeBuffer = FileUtils::getInstance()->getFileData(filename.c_str(), "rb", &codeBufferSize); if (codeBuffer) From f6070406cd5ac2389392835fe101443554f4d343 Mon Sep 17 00:00:00 2001 From: garfield_ho Date: Wed, 6 Nov 2013 15:31:58 +0800 Subject: [PATCH 28/39] Missing add "JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET " before calling JS_CallFunctionValue --- cocos/scripting/javascript/bindings/ScriptingCore.cpp | 3 +++ cocos/scripting/javascript/bindings/ScriptingCore.h | 2 ++ .../bindings/chipmunk/js_bindings_chipmunk_manual.cpp | 8 ++++++++ .../bindings/cocos2d_specifics.cpp.REMOVED.git-id | 2 +- .../bindings/cocosbuilder/cocosbuilder_specifics.hpp | 2 ++ .../bindings/cocostudio/jsb_cocos2dx_studio_manual.cpp | 9 +++++++++ 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cocos/scripting/javascript/bindings/ScriptingCore.cpp b/cocos/scripting/javascript/bindings/ScriptingCore.cpp index 5d902c1c23..ab4afd4091 100644 --- a/cocos/scripting/javascript/bindings/ScriptingCore.cpp +++ b/cocos/scripting/javascript/bindings/ScriptingCore.cpp @@ -96,6 +96,9 @@ static void executeJSFunctionFromReservedSpot(JSContext *cx, JSObject *obj, if (func == JSVAL_VOID) { return; } jsval thisObj = JS_GetReservedSlot(obj, 1); JSAutoCompartment ac(cx, obj); + + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + if (thisObj == JSVAL_VOID) { JS_CallFunctionValue(cx, obj, func, 1, &dataVal, &retval); } else { diff --git a/cocos/scripting/javascript/bindings/ScriptingCore.h b/cocos/scripting/javascript/bindings/ScriptingCore.h index 8df12fddc6..992569afc9 100644 --- a/cocos/scripting/javascript/bindings/ScriptingCore.h +++ b/cocos/scripting/javascript/bindings/ScriptingCore.h @@ -320,6 +320,8 @@ public: JS_RemoveObjectRoot(this->_cx, &this->_jsthis); } JSBool invoke(unsigned int argc, jsval *argv, jsval &rval) { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + return JS_CallFunctionValue(this->_cx, this->_jsthis, this->_fval, argc, argv, &rval); } private: diff --git a/cocos/scripting/javascript/bindings/chipmunk/js_bindings_chipmunk_manual.cpp b/cocos/scripting/javascript/bindings/chipmunk/js_bindings_chipmunk_manual.cpp index 197a270e91..903b777fde 100644 --- a/cocos/scripting/javascript/bindings/chipmunk/js_bindings_chipmunk_manual.cpp +++ b/cocos/scripting/javascript/bindings/chipmunk/js_bindings_chipmunk_manual.cpp @@ -638,6 +638,8 @@ static cpBool myCollisionBegin(cpArbiter *arb, cpSpace *space, void *data) args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); } + + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval rval; JSBool ok = JS_CallFunctionValue( handler->cx, handler->jsthis, OBJECT_TO_JSVAL(handler->begin), 2, args, &rval); @@ -662,6 +664,8 @@ static cpBool myCollisionPre(cpArbiter *arb, cpSpace *space, void *data) args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); } + + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval rval; JSBool ok = JS_CallFunctionValue( handler->cx, handler->jsthis, OBJECT_TO_JSVAL(handler->pre), 2, args, &rval); @@ -687,6 +691,8 @@ static void myCollisionPost(cpArbiter *arb, cpSpace *space, void *data) args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); } + + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval ignore; JSBool ok = JS_CallFunctionValue( handler->cx, handler->jsthis, OBJECT_TO_JSVAL(handler->post), 2, args, &ignore); @@ -705,6 +711,8 @@ static void myCollisionSeparate(cpArbiter *arb, cpSpace *space, void *data) args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); } + + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval ignore; JSBool ok = JS_CallFunctionValue( handler->cx, handler->jsthis, OBJECT_TO_JSVAL(handler->separate), 2, args, &ignore); diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 39e01fd1ef..60a40d7ff2 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -c93df276adb92b5e076db49c4f9482b8eb37d45c \ No newline at end of file +d922b0cdce5f5f90c7feca934b43c294a9585ab1 \ No newline at end of file diff --git a/cocos/scripting/javascript/bindings/cocosbuilder/cocosbuilder_specifics.hpp b/cocos/scripting/javascript/bindings/cocosbuilder/cocosbuilder_specifics.hpp index f6b3252c57..774c75820b 100644 --- a/cocos/scripting/javascript/bindings/cocosbuilder/cocosbuilder_specifics.hpp +++ b/cocos/scripting/javascript/bindings/cocosbuilder/cocosbuilder_specifics.hpp @@ -14,6 +14,8 @@ public: jsval retval = JSVAL_NULL; if(!JSVAL_IS_VOID(_jsCallback) && !JSVAL_IS_VOID(_jsThisObj)) { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(_jsThisObj), _jsCallback, 0, NULL, &retval); } } diff --git a/cocos/scripting/javascript/bindings/cocostudio/jsb_cocos2dx_studio_manual.cpp b/cocos/scripting/javascript/bindings/cocostudio/jsb_cocos2dx_studio_manual.cpp index 34ecbca985..4838fbcab2 100644 --- a/cocos/scripting/javascript/bindings/cocostudio/jsb_cocos2dx_studio_manual.cpp +++ b/cocos/scripting/javascript/bindings/cocostudio/jsb_cocos2dx_studio_manual.cpp @@ -73,6 +73,9 @@ void JSArmatureWrapper::movementCallbackFunc(cocostudio::Armature *pArmature, co valArr[2] = idVal; JS_AddValueRoot(cx, valArr); + + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS_CallFunctionValue(cx, thisObj, _jsCallback, 3, valArr, &retval); JS_RemoveValueRoot(cx, valArr); } @@ -88,6 +91,9 @@ void JSArmatureWrapper::addArmatureFileInfoAsyncCallbackFunc(float percent) jsval percentVal = DOUBLE_TO_JSVAL(percent); JS_AddValueRoot(cx, &percentVal); + + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS_CallFunctionValue(cx, thisObj, _jsCallback, 1, &percentVal, &retval); JS_RemoveValueRoot(cx, &percentVal); } @@ -113,6 +119,9 @@ void JSArmatureWrapper::frameCallbackFunc(cocostudio::Bone *pBone, const char *f valArr[3] = currentIndexVal; JS_AddValueRoot(cx, valArr); + + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS_CallFunctionValue(cx, thisObj, _jsCallback, 4, valArr, &retval); JS_RemoveValueRoot(cx, valArr); } From efd8f629924e5cc71f2e7efca6ff52a5dd8db24d Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Wed, 6 Nov 2013 15:40:06 +0800 Subject: [PATCH 29/39] add virtual --- cocos/editor-support/cocostudio/CCSkin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCSkin.h b/cocos/editor-support/cocostudio/CCSkin.h index 6e62da7d22..3d937a76bb 100644 --- a/cocos/editor-support/cocostudio/CCSkin.h +++ b/cocos/editor-support/cocostudio/CCSkin.h @@ -39,8 +39,8 @@ public: public: Skin(); - bool initWithSpriteFrameName(const char *pszSpriteFrameName) override; - bool initWithFile(const char *pszFilename) override; + virtual bool initWithSpriteFrameName(const char *pszSpriteFrameName) override; + virtual bool initWithFile(const char *pszFilename) override; void updateArmatureTransform(); void updateTransform() override; From f36fd002cdff05a4a95bf0d35b4ba01534329eba Mon Sep 17 00:00:00 2001 From: garfield_ho Date: Wed, 6 Nov 2013 15:40:23 +0800 Subject: [PATCH 30/39] Remove duplicate --- cocos/scripting/javascript/bindings/ScriptingCore.cpp | 2 -- .../javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cocos/scripting/javascript/bindings/ScriptingCore.cpp b/cocos/scripting/javascript/bindings/ScriptingCore.cpp index ab4afd4091..dc3859eba1 100644 --- a/cocos/scripting/javascript/bindings/ScriptingCore.cpp +++ b/cocos/scripting/javascript/bindings/ScriptingCore.cpp @@ -97,8 +97,6 @@ static void executeJSFunctionFromReservedSpot(JSContext *cx, JSObject *obj, jsval thisObj = JS_GetReservedSlot(obj, 1); JSAutoCompartment ac(cx, obj); - JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - if (thisObj == JSVAL_VOID) { JS_CallFunctionValue(cx, obj, func, 1, &dataVal, &retval); } else { diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 60a40d7ff2..4bf97ac9a7 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -d922b0cdce5f5f90c7feca934b43c294a9585ab1 \ No newline at end of file +b29fccdfcc5201f7a53a2c7896310afd9884ed8f \ No newline at end of file From ba8b4866e289a89fae87b6fb456a7bdfbae820f1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 6 Nov 2013 15:57:57 +0800 Subject: [PATCH 31/39] Update AUTHORS [ci skip] --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 0c11df97d6..37e302de05 100644 --- a/AUTHORS +++ b/AUTHORS @@ -628,6 +628,7 @@ Developers: HoGarfield (garfield_ho) Fixed a bug that CCBReader can't play sequence automatically in JSB. Could not set next animation in CCBAnimationCompleted callback. + Fixed missing to add JSAutoCompartment when invoking JS functions from C++. lite3 Fixed a bug that Node's anchor point was changed after being added to ScrollView. From d990699417ac4a5dee2af27d84e132553a3c8a62 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Wed, 6 Nov 2013 08:00:35 +0000 Subject: [PATCH 32/39] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index e150a74a02..9b0b068f92 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit e150a74a028e26cff0dac7d2238e2cd16fbaf370 +Subproject commit 9b0b068f923249440b8a8c758b1c06d29f6cbdfe From 3ea0d2f12d4881413f99f0939ac053b7c91e237a Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Wed, 6 Nov 2013 16:37:30 +0800 Subject: [PATCH 33/39] change override function --- cocos/editor-support/cocostudio/CCSkin.cpp | 16 ++++++++-------- cocos/editor-support/cocostudio/CCSkin.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index 62710e561d..394dfb48ec 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -83,11 +83,11 @@ Skin::Skin() _skinTransform = AffineTransformIdentity; } -bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) +bool Skin::initWithSpriteFrameName(const std::string& spriteFrameName) { - CCAssert(pszSpriteFrameName != nullptr, ""); + CCAssert(spriteFrameName != "", ""); - SpriteFrame *pFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(pszSpriteFrameName); + SpriteFrame *pFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName); bool ret = true; if (pFrame != nullptr) @@ -96,20 +96,20 @@ bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) } else { - CCLOG("Cann't find CCSpriteFrame with %s. Please check your .plist file", pszSpriteFrameName); + CCLOG("Cann't find CCSpriteFrame with %s. Please check your .plist file", spriteFrameName.c_str()); ret = false; } - _displayName = pszSpriteFrameName; + _displayName = spriteFrameName; return ret; } -bool Skin::initWithFile(const char *pszFilename) +bool Skin::initWithFile(const std::string& filename) { - bool ret = Sprite::initWithFile(pszFilename); + bool ret = Sprite::initWithFile(filename); - _displayName = pszFilename; + _displayName = filename; return ret; } diff --git a/cocos/editor-support/cocostudio/CCSkin.h b/cocos/editor-support/cocostudio/CCSkin.h index 3d937a76bb..e740d1eb01 100644 --- a/cocos/editor-support/cocostudio/CCSkin.h +++ b/cocos/editor-support/cocostudio/CCSkin.h @@ -39,8 +39,8 @@ public: public: Skin(); - virtual bool initWithSpriteFrameName(const char *pszSpriteFrameName) override; - virtual bool initWithFile(const char *pszFilename) override; + virtual bool initWithSpriteFrameName(const std::string& spriteFrameName) override; + virtual bool initWithFile(const std::string& filename) override; void updateArmatureTransform(); void updateTransform() override; From 8a836dc4771f2ccb1037a769f71768a0382fa12d Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Wed, 6 Nov 2013 09:38:34 +0000 Subject: [PATCH 34/39] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index 9b0b068f92..f55eab57aa 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit 9b0b068f923249440b8a8c758b1c06d29f6cbdfe +Subproject commit f55eab57aa6b3ff20fd33bea986e4569ebd68c8e From 3deb3b4231eff1868d24961b8c65c39452e27237 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 6 Nov 2013 17:52:03 +0800 Subject: [PATCH 35/39] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index e206d5cea7..93e703edb1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ cocos2d-x-3.0alpha1 @??? 2013 [FIX] EventListeners can't be removed sometimes. [FIX] When parsing XML using TinyXML, the data size has to be specified. [FIX] Parameter type: const char* -> const string& + [FIX] Armature: many bug fixed, add more samples, add function to skip some frames when playing animation [NEW] Arm64 support. [NEW] Added Mouse Support For Desktop Platforms. [Android] From 8c0ab2d4895a392593bad1904eb4a111855abf08 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 6 Nov 2013 18:05:02 +0800 Subject: [PATCH 36/39] [ci skip] --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 217779827f..6d84c08926 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ How to start a new game Example: - $ cd cocos2d-x/tools/project-creator - $ ./create-multi-platform-projects.py -p mygame -k com.your_company.mygame -l cpp + $ cd cocos2d-x/tools/project-creator + $ ./create-multi-platform-projects.py -p mygame -k com.your_company.mygame -l cpp $ cd ../../projects/mygame @@ -97,8 +97,9 @@ $ open samples.xcodeproj * For Linux ``` -$ cd cocos2d-x/build -$ ./make-all-linux-projects.sh +$ cd cocos2d-x +$ cmake CMakeLists.txt +$ make ``` * For Windows From b30494cc4fa906a6995f1ba06b579d592aadc776 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 6 Nov 2013 18:07:03 +0800 Subject: [PATCH 37/39] [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d84c08926..1cfd3a014d 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Build Requirements ------------------ * Mac OS X 10.7+, Xcode 4.6+ -* or Ubuntu 13.04+ +* or Ubuntu 12.10+, CMake 2.6+ * or Windows 7+, VS 2012+ From d6d041f561b2677dc600cdb41407c784ba7b2c88 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 6 Nov 2013 19:15:20 +0800 Subject: [PATCH 38/39] issue #3113: [Linux] Adding options for modules. --- CMakeLists.txt | 73 ++++++++++++++++++++++++++++--- cocos/scripting/CMakeLists.txt | 6 +++ external/Box2D/CMakeLists.txt | 6 +++ external/lua/lua/CMakeLists.txt | 8 +++- external/lua/tolua/CMakeLists.txt | 5 +++ samples/CMakeLists.txt | 12 ++++- 6 files changed, 101 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e07f618e27..f75d56a708 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.6) -project (Cocos2dxSamples) +project (Cocos2dx) # The version number set(Cocos2dxSamples_VERSION_MAJOR 3) @@ -7,14 +7,45 @@ set(Cocos2dxSamples_VERSION_MINOR 0) include(build/BuildHelpers.CMakeLists.txt) -set(CMAKE_BUILE_TYPE DEBUG) +option(USE_CHIPMUNK "Use chipmunk for physics library" ON) +option(USE_BOX2D "Use box2d for physics library" OFF) +option(DEBUG_MODE "Debug or release?" ON) +option(BUILD_LIBS_LUA "Build lua libraries" ON) +option(BUILD_GUI "Build GUI library" ON) +option(BUILD_NETWORK "Build network library" ON) +option(BUILD_EXTENSIONS "Build extension library" ON) +option(BUILD_EDITOR_SPINE "Build editor support for spine" ON) +option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON) +option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON) + + +option(BUILD_HelloCpp "Only build HelloCpp sample" ON) +option(BUILD_TestCpp "Only build TestCpp sample" ON) +option(BUILD_HelloLua "Only build HelloLua sample" ON) +option(BUILD_TestLua "Only build TestLua sample" ON) + + +if(DEBUG_MODE) + set(CMAKE_BUILE_TYPE DEBUG) +else(DEBUG_MODE) + set(CMAKE_BUILE_TYPE RELEASE) +endif(DEBUG_MODE) + set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1") set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99") set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11") -add_definitions(-DLINUX -DCC_ENABLE_CHIPMUNK_INTEGRATION=1) +if(USE_CHIPMUNK) + message("Using chipmunk ...") + add_definitions(-DLINUX -DCC_ENABLE_CHIPMUNK_INTEGRATION=1) +elseif(USE_BOX2D) + message("Using box2d ...") + add_definitions(-DLINUX -DCC_ENABLE_BOX2D_INTEGRATION=1) +else(USE_CHIPMUNK) + message(FATAL_ERROR "Must choose a physics library.") +endif(USE_CHIPMUNK) # architecture if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) @@ -58,6 +89,7 @@ link_directories( ${CMAKE_SOURCE_DIR}/external/linux-specific/fmod/prebuilt/${ARCH_DIR} ) + # kazmath add_subdirectory(cocos/math/kazmath) @@ -73,8 +105,6 @@ add_subdirectory(external/unzip) # tinyxml2 library add_subdirectory(external/tinyxml2) -add_subdirectory(external/json) - # audio add_subdirectory(cocos/audio) @@ -84,22 +114,51 @@ add_subdirectory(cocos/base) # cocos 2d library add_subdirectory(cocos/2d) +if(BUILD_GUI) +# gui add_subdirectory(cocos/gui) +endif(BUILD_GUI) +if(BUILD_NETWORK) +# network add_subdirectory(cocos/network) +endif(BUILD_NETWORK) +if(BUILD_EXTENSIONS) +# extensions add_subdirectory(extensions) +endif(BUILD_EXTENSIONS) +## Editor Support + +if(BUILD_EDITOR_SPINE) +# spine add_subdirectory(cocos/editor-support/spine) +endif(BUILD_EDITOR_SPINE) + +if(BUILD_EDITOR_COCOSBUILDER) +# cocosbuilder add_subdirectory(cocos/editor-support/cocosbuilder) +endif(BUILD_EDITOR_COCOSBUILDER) + +if(BUILD_EDITOR_COCOSTUDIO) +# cocostudio add_subdirectory(cocos/editor-support/cocostudio) +# jsoncpp library, cocostuido depends on jsoncpp +add_subdirectory(external/json) +endif(BUILD_EDITOR_COCOSTUDIO) - +if(BUILD_LIBS_LUA) +## Scripting +# lua add_subdirectory(external/lua/lua) + +# tolua add_subdirectory(external/lua/tolua) +# luabinding add_subdirectory(cocos/scripting) +endif(BUILD_LIBS_LUA) # build samples add_subdirectory(samples) - diff --git a/cocos/scripting/CMakeLists.txt b/cocos/scripting/CMakeLists.txt index 478ae9a039..612d728162 100644 --- a/cocos/scripting/CMakeLists.txt +++ b/cocos/scripting/CMakeLists.txt @@ -36,3 +36,9 @@ target_link_libraries(luabinding tolua lua ) + +set_target_properties(luabinding + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib" +) diff --git a/external/Box2D/CMakeLists.txt b/external/Box2D/CMakeLists.txt index 94a1fffb50..fd1f63dc64 100644 --- a/external/Box2D/CMakeLists.txt +++ b/external/Box2D/CMakeLists.txt @@ -53,3 +53,9 @@ include_directories( add_library(box2d STATIC ${BOX2D_SRC} ) + +set_target_properties(box2d + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib" +) diff --git a/external/lua/lua/CMakeLists.txt b/external/lua/lua/CMakeLists.txt index faba14e849..c63d80a7b2 100644 --- a/external/lua/lua/CMakeLists.txt +++ b/external/lua/lua/CMakeLists.txt @@ -33,4 +33,10 @@ set(LUA_SRC add_library(lua STATIC ${LUA_SRC} -) \ No newline at end of file +) + +set_target_properties(lua + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib" +) diff --git a/external/lua/tolua/CMakeLists.txt b/external/lua/tolua/CMakeLists.txt index 481bdd1247..b12e144e75 100644 --- a/external/lua/tolua/CMakeLists.txt +++ b/external/lua/tolua/CMakeLists.txt @@ -15,3 +15,8 @@ add_library(tolua STATIC ${TOLUA_SRC} ) +set_target_properties(tolua + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib" +) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index d73334ce7e..198764a991 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,5 +1,15 @@ - +if(BUILD_HelloCpp) add_subdirectory(Cpp/HelloCpp) +endif(BUILD_HelloCpp) + +if(BUILD_TestCpp) add_subdirectory(Cpp/TestCpp) +endif(BUILD_TestCpp) + +if(BUILD_HelloLua) add_subdirectory(Lua/HelloLua) +endif(BUILD_HelloLua) + +if(BUILD_TestLua) add_subdirectory(Lua/TestLua) +endif(BUILD_TestLua) \ No newline at end of file From 6be59456a5c03d9bac50d0f7359a16e9a1ed0aa3 Mon Sep 17 00:00:00 2001 From: Oleg Loginov Date: Thu, 7 Nov 2013 01:24:33 +0400 Subject: [PATCH 39/39] correct type in root CMakeLists.txt --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f75d56a708..c03a1e9d87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,9 +26,9 @@ option(BUILD_TestLua "Only build TestLua sample" ON) if(DEBUG_MODE) - set(CMAKE_BUILE_TYPE DEBUG) + set(CMAKE_BUILD_TYPE DEBUG) else(DEBUG_MODE) - set(CMAKE_BUILE_TYPE RELEASE) + set(CMAKE_BUILD_TYPE RELEASE) endif(DEBUG_MODE) set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")