From 0470ce936bf073ea3f2a689f523056370d953029 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 19 Jul 2013 19:02:26 +0800 Subject: [PATCH] 1.Fix release CCTexture2DMutable.cpp crash 2.Change frame tween method --- extensions/CCArmature/CCArmature.cpp | 7 +- extensions/CCArmature/CCArmature.h | 2 + extensions/CCArmature/CCBone.cpp | 12 + extensions/CCArmature/CCBone.h | 6 +- .../animation/CCArmatureAnimation.cpp | 3 +- extensions/CCArmature/animation/CCTween.cpp | 100 +- extensions/CCArmature/animation/CCTween.h | 6 +- extensions/CCArmature/datas/CCDatas.cpp | 24 +- extensions/CCArmature/datas/CCDatas.h | 10 +- .../display/CCDecorativeDisplay.cpp | 5 - .../CCArmature/display/CCDecorativeDisplay.h | 5 +- .../CCArmature/display/CCDisplayFactory.cpp | 3 +- .../CCArmature/display/CCDisplayManager.h | 2 +- extensions/CCArmature/display/CCSkin.cpp | 13 + extensions/CCArmature/display/CCSkin.h | 1 + .../external_tool/CCTexture2DMutable.cpp | 12 +- .../Json/CSContentJsonDictionary.cpp | 13 + .../Json/CSContentJsonDictionary.h | 1 + .../Json/lib_json/json_reader.cpp | 2 + .../Json/lib_json/json_value.cpp | 30 +- .../external_tool/Json/lib_json/value.h | 2 +- .../CCArmature/utils/CCArmatureDefine.h | 1 + .../CCArmature/utils/CCDataReaderHelper.cpp | 45 +- extensions/CCArmature/utils/CCUtilMath.cpp | 8 +- .../ArmatureTest/ArmatureScene.cpp | 3 +- .../Cpp/TestCpp/Resources/armature/Dragon.xml | 581 ++++---- .../Cpp/TestCpp/Resources/armature/cyborg.xml | 280 ++-- .../Cpp/TestCpp/Resources/armature/knight.xml | 301 ++-- .../Cpp/TestCpp/Resources/armature/robot.xml | 1242 +++++++++-------- 29 files changed, 1313 insertions(+), 1407 deletions(-) diff --git a/extensions/CCArmature/CCArmature.cpp b/extensions/CCArmature/CCArmature.cpp index b5e659d76f..ca29548a10 100644 --- a/extensions/CCArmature/CCArmature.cpp +++ b/extensions/CCArmature/CCArmature.cpp @@ -304,8 +304,11 @@ void CCArmature::changeBoneParent(CCBone *bone, const char *parentName) { CCAssert(bone != NULL, "bone must be added to the bone dictionary!"); - bone->getParentBone()->getChildren()->removeObject(bone); - bone->setParentBone(NULL); + if(bone->getParentBone()) + { + bone->getParentBone()->getChildren()->removeObject(bone); + bone->setParentBone(NULL); + } if (parentName != NULL) { diff --git a/extensions/CCArmature/CCArmature.h b/extensions/CCArmature/CCArmature.h index 0ff843bcb1..42396f6e9b 100644 --- a/extensions/CCArmature/CCArmature.h +++ b/extensions/CCArmature/CCArmature.h @@ -145,6 +145,8 @@ protected: CC_SYNTHESIZE(CCTextureAtlas*, m_pAtlas, TextureAtlas); CC_SYNTHESIZE(CCBone*, m_pParentBone, ParentBone); + + CC_SYNTHESIZE(float, m_fVersion, Version); protected: CCDictionary *m_pBoneDic; //! 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. diff --git a/extensions/CCArmature/CCBone.cpp b/extensions/CCArmature/CCBone.cpp index e93c761eac..f4e4bf0d2f 100644 --- a/extensions/CCArmature/CCBone.cpp +++ b/extensions/CCArmature/CCBone.cpp @@ -219,6 +219,18 @@ void CCBone::updateColor() } } +void CCBone::updateZOrder() +{ + if (m_pArmature->getArmatureData()->dataVersion >= VERSION_COMBINED) + { + int zorder = m_pTweenData->zOrder + m_pBoneData->zOrder; + setZOrder(zorder); + } + else + { + setZOrder(m_pTweenData->zOrder); + } +} void CCBone::addChildBone(CCBone *child) { diff --git a/extensions/CCArmature/CCBone.h b/extensions/CCArmature/CCBone.h index 8cf83a2ace..46b1641d7b 100644 --- a/extensions/CCArmature/CCBone.h +++ b/extensions/CCArmature/CCBone.h @@ -126,9 +126,13 @@ public: //! Update color to render display void updateColor(); - CCTween *getTween(); + //! Update zorder + void updateZOrder(); virtual void setZOrder(int zOrder); + + CCTween *getTween(); + /* * Whether or not the bone's transform property changed. if true, the bone will update the transform. */ diff --git a/extensions/CCArmature/animation/CCArmatureAnimation.cpp b/extensions/CCArmature/animation/CCArmatureAnimation.cpp index 5f04151da1..031c2dc30d 100644 --- a/extensions/CCArmature/animation/CCArmatureAnimation.cpp +++ b/extensions/CCArmature/animation/CCArmatureAnimation.cpp @@ -158,7 +158,7 @@ void CCArmatureAnimation::play(const char *animationName, int durationTo, int du CCProcessBase::play((void *)animationName, durationTo, durationTween, loop, tweenEasing); - if (m_iRawDuration == 1) + if (m_iRawDuration == 0) { m_eLoopType = SINGLE_FRAME; } @@ -191,6 +191,7 @@ void CCArmatureAnimation::play(const char *animationName, int durationTo, int du if(movementBoneData && movementBoneData->frameList.count() > 0) { m_pTweenList->addObject(tween); + movementBoneData->duration = m_pMovementData->duration; tween->play(movementBoneData, durationTo, durationTween, loop, tweenEasing); tween->setAnimationScale(m_fAnimationScale); diff --git a/extensions/CCArmature/animation/CCTween.cpp b/extensions/CCArmature/animation/CCTween.cpp index 801fc14bb9..03742cba6d 100644 --- a/extensions/CCArmature/animation/CCTween.cpp +++ b/extensions/CCArmature/animation/CCTween.cpp @@ -101,17 +101,18 @@ void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int dur m_eLoopType = (AnimationType)loop; m_iTotalDuration = 0; - m_BetweenDuration = 0; + m_iBetweenDuration = 0; m_iFromIndex = m_iToIndex = 0; - + m_bNeedTweenTo = true; bool difMovement = movementBoneData != m_pMovementBoneData; setMovementBoneData(movementBoneData); + m_iRawDuration = m_pMovementBoneData->duration; CCFrameData *nextKeyFrame = m_pMovementBoneData->getFrameData(0); m_pTweenData->displayIndex = nextKeyFrame->displayIndex; - if (m_pMovementBoneData->frameList.count() == 1) + if (m_iRawDuration == 0 ) { m_eLoopType = SINGLE_FRAME; if(durationTo == 0) @@ -123,19 +124,16 @@ void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int dur setBetween(m_pTweenData, nextKeyFrame); } m_eFrameTweenEasing = Linear; - m_iRawDuration = m_pMovementBoneData->duration; } else if (m_pMovementBoneData->frameList.count() > 1) { if (loop) { m_eLoopType = ANIMATION_TO_LOOP_BACK; - m_iRawDuration = m_pMovementBoneData->duration; } else { m_eLoopType = ANIMATION_NO_LOOP; - m_iRawDuration = m_pMovementBoneData->duration - 1; } m_iDurationTween = durationTween * m_pMovementBoneData->scale; @@ -197,7 +195,7 @@ void CCTween::updateHandler() m_iNextFrameIndex = m_iDurationTween; m_fCurrentFrame = m_fCurrentPercent * m_iNextFrameIndex; m_iTotalDuration = 0; - m_BetweenDuration = 0; + m_iBetweenDuration = 0; m_iToIndex = 0; break; } @@ -222,7 +220,7 @@ void CCTween::updateHandler() } m_iTotalDuration = 0; - m_BetweenDuration = 0; + m_iBetweenDuration = 0; m_iToIndex = 0; } break; @@ -238,7 +236,7 @@ void CCTween::updateHandler() m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); m_iTotalDuration = 0; - m_BetweenDuration = 0; + m_iBetweenDuration = 0; m_iToIndex = 0; } break; @@ -254,7 +252,7 @@ void CCTween::updateHandler() if (m_eLoopType > ANIMATION_TO_LOOP_BACK) { - percent = updateFrameData(percent, true); + percent = updateFrameData(percent); } if(m_eFrameTweenEasing != TWEEN_EASING_MAX) @@ -293,6 +291,7 @@ void CCTween::arriveKeyFrame(CCFrameData *keyFrameData) { if(keyFrameData) { + //! Change bone's display int displayIndex = keyFrameData->displayIndex; if (!m_pBone->getDisplayManager()->getForceChangeDisplay()) @@ -300,24 +299,24 @@ void CCTween::arriveKeyFrame(CCFrameData *keyFrameData) m_pBone->getDisplayManager()->changeDisplayByIndex(displayIndex, false); } - - m_pBone->setZOrder(keyFrameData->zOrder); + //! Update bone zorder, bone's zorder is determined by frame zorder and bone zorder + m_pTweenData->zOrder = keyFrameData->zOrder; + m_pBone->updateZOrder(); CCArmature *childAramture = m_pBone->getChildArmature(); if(childAramture) { - if(keyFrameData->m_strMovement.length() != 0) + if(keyFrameData->strMovement.length() != 0) { - childAramture->getAnimation()->play(keyFrameData->m_strMovement.c_str()); + childAramture->getAnimation()->play(keyFrameData->strMovement.c_str()); } } - - // if(keyFrameData->m_strSound.length() != 0) - // { - // //soundManager.dispatchEventWith(Event.SOUND_FRAME, keyFrameData->sound); - // } + if(keyFrameData->strEvent.length() != 0) + { + m_pAnimation->FrameEventSignal.emit(m_pBone, keyFrameData->strEvent.c_str()); + } } } @@ -335,7 +334,7 @@ CCFrameData *CCTween::tweenNodeTo(float percent, CCFrameData *node) m_pBone->setTransformDirty(true); - tweenColorTo(percent, node, m_pTweenData->isUseColorInfo); + tweenColorTo(percent, node, m_pBetween->isUseColorInfo); return node; } @@ -352,7 +351,7 @@ void CCTween::tweenColorTo(float percent, CCFrameData *node, bool dirty) } } -float CCTween::updateFrameData(float currentPrecent, bool activeFrame) +float CCTween::updateFrameData(float currentPrecent) { if (currentPrecent > 1) { @@ -363,54 +362,65 @@ float CCTween::updateFrameData(float currentPrecent, bool activeFrame) //! If play to current frame's front or back, then find current frame again - if (playedTime < m_iTotalDuration || playedTime >= m_iTotalDuration + m_BetweenDuration) + if (playedTime < m_iTotalDuration || playedTime >= m_iTotalDuration + m_iBetweenDuration) { /* * Get frame length, if m_iToIndex >= _length, then set m_iToIndex to 0, start anew. * m_iToIndex is next index will play */ int length = m_pMovementBoneData->frameList.count(); + CCFrameData **frames = (CCFrameData**)m_pMovementBoneData->frameList.data->arr; + + if (playedTime < frames[0]->frameID || playedTime > frames[length-1]->frameID) + { + m_pBone->changeDisplayByIndex(-1, false); + m_bNeedTweenTo = false; + return currentPrecent; + } + else + { + m_bNeedTweenTo = true; + } CCFrameData *from = NULL; CCFrameData *to = NULL; bool isListEnd; - CCFrameData **frames = (CCFrameData**)m_pMovementBoneData->frameList.data->arr; - do - { + do + { from = frames[m_iFromIndex]; to = frames[m_iToIndex]; - m_iTotalDuration = from->frameID; - m_iFromIndex = m_iToIndex; - if (++m_iToIndex >= length) - { - m_iToIndex = 0; - } - } - while (playedTime < from->frameID || playedTime>=to->frameID); + m_iTotalDuration = from->frameID; + m_iFromIndex = m_iToIndex; - m_BetweenDuration = to->frameID - from->frameID; + if (++m_iToIndex >= length) + { + m_iToIndex = 0; + } + if (playedTime == from->frameID) + { + break; + } + } + while (playedTime < from->frameID || playedTime>=to->frameID); - isListEnd = m_eLoopType == ANIMATION_MAX && m_iToIndex == 0; + m_iBetweenDuration = to->frameID - from->frameID; - if(isListEnd) - { - to = from = frames[m_iFromIndex]; - } -// else -// { -// from = frames[m_iFromIndex]; -// to = frames[m_iToIndex]; -// } + isListEnd = m_eLoopType == ANIMATION_MAX && m_iToIndex == 0; + + if(isListEnd) + { + to = from = frames[m_iFromIndex]; + } m_eFrameTweenEasing = from->tweenEasing; setBetween(from, to); } - currentPrecent = (playedTime - m_iTotalDuration) / (float)m_BetweenDuration; + currentPrecent = m_iBetweenDuration == 0 ? 0 : (playedTime - m_iTotalDuration) / (float)m_iBetweenDuration; /* diff --git a/extensions/CCArmature/animation/CCTween.h b/extensions/CCArmature/animation/CCTween.h index bb27f2f111..4aade7c626 100644 --- a/extensions/CCArmature/animation/CCTween.h +++ b/extensions/CCArmature/animation/CCTween.h @@ -94,7 +94,7 @@ protected: /** * Calculate which frame arrived, and if current frame have event, then call the event listener */ - virtual float updateFrameData(float currentPrecent, bool activeFrame = false); + virtual float updateFrameData(float currentPrecent); /** * Calculate the between value of _from and _to, and give it to between frame data @@ -129,7 +129,7 @@ protected: CCTweenType m_eFrameTweenEasing; //! Dedermine which tween effect current frame use - int m_BetweenDuration; //! Current key frame will last m_BetweenDuration frames + int m_iBetweenDuration; //! Current key frame will last m_iBetweenDuration frames int m_iTotalDuration; @@ -137,6 +137,8 @@ protected: int m_iToIndex; //! The next frame index in FrameList of CCMovementBoneData, it's different from m_iFrameIndex CCArmatureAnimation *m_pAnimation; + + bool m_bNeedTweenTo; }; NS_CC_EXT_END diff --git a/extensions/CCArmature/datas/CCDatas.cpp b/extensions/CCArmature/datas/CCDatas.cpp index b525332248..358a68e226 100644 --- a/extensions/CCArmature/datas/CCDatas.cpp +++ b/extensions/CCArmature/datas/CCDatas.cpp @@ -23,12 +23,13 @@ THE SOFTWARE. ****************************************************************************/ #include "CCDatas.h" -#include "CCArmature/utils/CCUtilMath.h" +#include "../utils/CCUtilMath.h" +#include "../utils/CCTransformHelp.h" NS_CC_EXT_BEGIN - CCBaseData::CCBaseData() +CCBaseData::CCBaseData() : x(0.0f) , y(0.0f) , zOrder(0) @@ -135,7 +136,6 @@ ccColor4B CCBaseData::getColor() return ccc4(r, g, b, a); } - const char *CCDisplayData::changeDisplayToTexture(const char *displayName) { // remove .xxx @@ -173,6 +173,8 @@ void CCSpriteDisplayData::copy(CCSpriteDisplayData *displayData) { displayName = displayData->displayName; displayType = displayData->displayType; + + skinData = displayData->skinData; } CCArmatureDisplayData::CCArmatureDisplayData(void) @@ -243,6 +245,11 @@ CCDisplayData *CCBoneData::getDisplayData(int index) { return (CCDisplayData *)displayDataList.objectAtIndex(index); } +void CCBoneData::updateBoneDataTransform() +{ + CCTransformHelp::nodeToMatrix(*this, boneDataTransform); +} + CCArmatureData::CCArmatureData() :dataVersion(0.1f) @@ -274,10 +281,10 @@ CCFrameData::CCFrameData(void) , tweenEasing(Linear) , displayIndex(0) - , m_strMovement("") - , m_strEvent("") - , m_strSound("") - , m_strSoundEffect("") + , strMovement("") + , strEvent("") + , strSound("") + , strSoundEffect("") { } @@ -289,7 +296,6 @@ void CCFrameData::copy(CCFrameData *frameData) { CCBaseData::copy(frameData); - frameID = frameData->frameID; duration = frameData->duration; displayIndex = frameData->displayIndex; tweenEasing = frameData->tweenEasing; @@ -398,6 +404,7 @@ bool CCContourData::init() { return vertexList.init(); } + void CCContourData::addVertex(CCPoint *vertex) { CCContourVertex2 *vertex2 = new CCContourVertex2(vertex->x, vertex->y); @@ -406,7 +413,6 @@ void CCContourData::addVertex(CCPoint *vertex) vertexList.addObject(vertex2); } - CCTextureData::CCTextureData() : height(0.0f) , width(0.0f) diff --git a/extensions/CCArmature/datas/CCDatas.h b/extensions/CCArmature/datas/CCDatas.h index 9ecbc225be..b7ea23d1df 100644 --- a/extensions/CCArmature/datas/CCDatas.h +++ b/extensions/CCArmature/datas/CCDatas.h @@ -245,10 +245,12 @@ public: void addDisplayData(CCDisplayData *displayData); CCDisplayData *getDisplayData(int index); + void updateBoneDataTransform(); public: std::string name; //! the bone's name std::string parentName; //! the bone parent's name CCArray displayDataList; //! save CCDisplayData informations for the CCBone + CCAffineTransform boneDataTransform; }; @@ -298,10 +300,10 @@ public: /** * m_strMovement, m_strEvent, m_strSound, m_strSoundEffect do not support yet */ - std::string m_strMovement; - std::string m_strEvent; - std::string m_strSound; - std::string m_strSoundEffect; + std::string strMovement; + std::string strEvent; + std::string strSound; + std::string strSoundEffect; }; diff --git a/extensions/CCArmature/display/CCDecorativeDisplay.cpp b/extensions/CCArmature/display/CCDecorativeDisplay.cpp index 6783e84265..d58f1a713c 100644 --- a/extensions/CCArmature/display/CCDecorativeDisplay.cpp +++ b/extensions/CCArmature/display/CCDecorativeDisplay.cpp @@ -65,9 +65,4 @@ bool CCDecorativeDisplay::init() return true; } - -void CCDecorativeDisplay::anchorPointChanged(float pointX, float pointY) -{ -} - NS_CC_EXT_END diff --git a/extensions/CCArmature/display/CCDecorativeDisplay.h b/extensions/CCArmature/display/CCDecorativeDisplay.h index 19b558f141..b8b486f01e 100644 --- a/extensions/CCArmature/display/CCDecorativeDisplay.h +++ b/extensions/CCArmature/display/CCDecorativeDisplay.h @@ -28,7 +28,6 @@ THE SOFTWARE. #include "../utils/CCArmatureDefine.h" #include "CCDisplayFactory.h" #include "../datas/CCDatas.h" -#include "../external_tool/sigslot.h" #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT @@ -37,7 +36,7 @@ THE SOFTWARE. NS_CC_EXT_BEGIN -class CCDecorativeDisplay: public CCObject, public sigslot::has_slots<> +class CCDecorativeDisplay: public CCObject { public: static CCDecorativeDisplay *create(); @@ -55,8 +54,6 @@ protected: #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT CC_SYNTHESIZE_RETAIN(CCColliderDetector *, m_pColliderDetector, ColliderDetector); #endif -public: - void anchorPointChanged(float pointX, float pointY); }; NS_CC_EXT_END diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp index d92935e74c..530830b80e 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ b/extensions/CCArmature/display/CCDisplayFactory.cpp @@ -152,10 +152,11 @@ void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *de } skin->setBone(bone); + CCArmature *armature = bone->getArmature(); if (armature) { - if (armature->getArmatureData()->dataVersion >= 0.15f) + if (armature->getArmatureData()->dataVersion >= VERSION_COMBINED) { skin->setSkinData(displayData->skinData); } diff --git a/extensions/CCArmature/display/CCDisplayManager.h b/extensions/CCArmature/display/CCDisplayManager.h index 0b04d38055..15bdfa43a6 100644 --- a/extensions/CCArmature/display/CCDisplayManager.h +++ b/extensions/CCArmature/display/CCDisplayManager.h @@ -50,7 +50,7 @@ public: * If display is a sprite, and it have texture info in the TexutreData, then use TexutreData to init the display's anchor point * If the display is a CCArmature, then create a new CCArmature */ - void initDisplayList(CCBoneData *boneData); + virtual void initDisplayList(CCBoneData *boneData); /** * Add display and use _DisplayData init the display. diff --git a/extensions/CCArmature/display/CCSkin.cpp b/extensions/CCArmature/display/CCSkin.cpp index cba1d8bc92..11c924bac8 100644 --- a/extensions/CCArmature/display/CCSkin.cpp +++ b/extensions/CCArmature/display/CCSkin.cpp @@ -155,4 +155,17 @@ CCAffineTransform CCSkin::nodeToWorldTransform() return CCAffineTransformConcat(m_sTransform, m_pBone->getArmature()->nodeToWorldTransform()); } +CCAffineTransform CCSkin::nodeToWorldTransformAR() +{ + CCAffineTransform displayTransform = m_sTransform; + CCPoint anchorPoint = m_obAnchorPointInPoints; + + anchorPoint = CCPointApplyAffineTransform(anchorPoint, displayTransform); + + displayTransform.tx = anchorPoint.x; + displayTransform.ty = anchorPoint.y; + + return CCAffineTransformConcat(displayTransform, m_pBone->getArmature()->nodeToWorldTransform()); +} + NS_CC_EXT_END diff --git a/extensions/CCArmature/display/CCSkin.h b/extensions/CCArmature/display/CCSkin.h index 801201ebff..c2eeb76c2f 100644 --- a/extensions/CCArmature/display/CCSkin.h +++ b/extensions/CCArmature/display/CCSkin.h @@ -43,6 +43,7 @@ public: void updateTransform(); CCAffineTransform nodeToWorldTransform(); + CCAffineTransform nodeToWorldTransformAR(); CC_PROPERTY_PASS_BY_REF(CCBaseData, m_sSkinData, SkinData); CC_SYNTHESIZE(CCBone *, m_pBone, Bone); diff --git a/extensions/CCArmature/external_tool/CCTexture2DMutable.cpp b/extensions/CCArmature/external_tool/CCTexture2DMutable.cpp index 95e09cf82f..9a41db7fe8 100644 --- a/extensions/CCArmature/external_tool/CCTexture2DMutable.cpp +++ b/extensions/CCArmature/external_tool/CCTexture2DMutable.cpp @@ -118,7 +118,7 @@ ccColor4B CCTexture2DMutable::pixelAt(const CCPoint& pt) //! modified, texture origin point is left top, cocos2d origin point is left bottom //! unsigned int x = pt.x, y = pt.y - unsigned int x = pt.x, y = m_uPixelsHigh - pt.y; + unsigned int x = pt.x, y = m_uPixelsHigh - 1 - pt.y; if(m_ePixelFormat == kTexture2DPixelFormat_RGBA8888){ unsigned int *pixel = (unsigned int *)data_; @@ -301,9 +301,15 @@ CCTexture2DMutable::~CCTexture2DMutable(void) { CCLOGINFO("cocos2d: deallocing %p", this); - CC_SAFE_DELETE(image_); + if (image_) + { + CC_SAFE_DELETE(image_); + } + else + { + free(data_); + } - free(data_); #if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA free(originalData_); #endif diff --git a/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.cpp b/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.cpp index ea5f37d3be..c1b6cea44a 100644 --- a/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.cpp +++ b/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.cpp @@ -313,6 +313,19 @@ namespace cs { return fRet; } + bool CSJsonDictionary::getBoolValueFromArray(const char *pszArrayKey, int nIndex, bool bDefaultValue) + { + bool bRet = bDefaultValue; + CSJson::Value * arrayValue = validateArrayItem(pszArrayKey, nIndex); + if (arrayValue) + { + if ((*arrayValue)[nIndex].isNumeric()) + bRet = (*arrayValue)[nIndex].asBool(); + } + + return bRet; + } + const char * CSJsonDictionary::getStringValueFromArray(const char *pszArrayKey, int nIndex) { diff --git a/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.h b/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.h index 928658d0c9..4054b14f61 100644 --- a/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.h +++ b/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.h @@ -79,6 +79,7 @@ namespace cs { int getArrayItemCount(const char *pszArrayKey); int getIntValueFromArray(const char *pszArrayKey, int nIndex, int nDefaultValue); double getFloatValueFromArray(const char *pszArrayKey, int nIndex, double fDefaultValue); + bool getBoolValueFromArray(const char *pszArrayKey, int nIndex, bool bDefaultValue); const char * getStringValueFromArray(const char *pszArrayKey, int nIndex); CSJsonDictionary *getSubItemFromArray(const char *pszArrayKey, int nIndex); DicItemType getItemTypeFromArray(const char *pszArrayKey, int nIndex); diff --git a/extensions/CCArmature/external_tool/Json/lib_json/json_reader.cpp b/extensions/CCArmature/external_tool/Json/lib_json/json_reader.cpp index 7ba6a1f0bf..5d336cf2a7 100644 --- a/extensions/CCArmature/external_tool/Json/lib_json/json_reader.cpp +++ b/extensions/CCArmature/external_tool/Json/lib_json/json_reader.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #if _MSC_VER >= 1400 // VC++ 8.0 #pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. diff --git a/extensions/CCArmature/external_tool/Json/lib_json/json_value.cpp b/extensions/CCArmature/external_tool/Json/lib_json/json_value.cpp index 60ba5d22d6..0090a5279d 100644 --- a/extensions/CCArmature/external_tool/Json/lib_json/json_value.cpp +++ b/extensions/CCArmature/external_tool/Json/lib_json/json_value.cpp @@ -20,6 +20,8 @@ #endif #include // size_t +#include + #define JSON_ASSERT_UNREACHABLE assert( false ) #define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw #define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message ); @@ -27,7 +29,7 @@ namespace CSJson { -const Value Value::null; +const Value Value::jsonNull; const Int Value::minInt = Int( ~(UInt(-1)/2) ); const Int Value::maxInt = Int( UInt(-1)/2 ); const UInt Value::maxUInt = UInt(-1); @@ -1084,7 +1086,7 @@ Value::operator[]( ArrayIndex index ) if ( it != value_.map_->end() && (*it).first == key ) return (*it).second; - ObjectValues::value_type defaultValue( key, null ); + ObjectValues::value_type defaultValue( key, jsonNull ); it = value_.map_->insert( it, defaultValue ); return (*it).second; #else @@ -1106,12 +1108,12 @@ Value::operator[]( ArrayIndex index ) const { JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); if ( type_ == nullValue ) - return null; + return jsonNull; #ifndef JSON_VALUE_USE_INTERNAL_MAP CZString key( index ); ObjectValues::const_iterator it = value_.map_->find( key ); if ( it == value_.map_->end() ) - return null; + return jsonNull; return (*it).second; #else Value *value = value_.array_->find( index ); @@ -1149,7 +1151,7 @@ Value::resolveReference( const char *key, if ( it != value_.map_->end() && (*it).first == actualKey ) return (*it).second; - ObjectValues::value_type defaultValue( actualKey, null ); + ObjectValues::value_type defaultValue( actualKey, jsonNull ); it = value_.map_->insert( it, defaultValue ); Value &value = (*it).second; return value; @@ -1164,7 +1166,7 @@ Value::get( ArrayIndex index, const Value &defaultValue ) const { const Value *value = &((*this)[index]); - return value == &null ? defaultValue : *value; + return value == &jsonNull ? defaultValue : *value; } @@ -1181,12 +1183,12 @@ Value::operator[]( const char *key ) const { JSON_ASSERT( type_ == nullValue || type_ == objectValue ); if ( type_ == nullValue ) - return null; + return jsonNull; #ifndef JSON_VALUE_USE_INTERNAL_MAP CZString actualKey( key, CZString::noDuplication ); ObjectValues::const_iterator it = value_.map_->find( actualKey ); if ( it == value_.map_->end() ) - return null; + return jsonNull; return (*it).second; #else const Value *value = value_.map_->find( key ); @@ -1243,7 +1245,7 @@ Value::get( const char *key, const Value &defaultValue ) const { const Value *value = &((*this)[key]); - return value == &null ? defaultValue : *value; + return value == &jsonNull ? defaultValue : *value; } @@ -1259,12 +1261,12 @@ Value::removeMember( const char* key ) { JSON_ASSERT( type_ == nullValue || type_ == objectValue ); if ( type_ == nullValue ) - return null; + return jsonNull; #ifndef JSON_VALUE_USE_INTERNAL_MAP CZString actualKey( key, CZString::noDuplication ); ObjectValues::iterator it = value_.map_->find( actualKey ); if ( it == value_.map_->end() ) - return null; + return jsonNull; Value old(it->second); value_.map_->erase(it); return old; @@ -1299,7 +1301,7 @@ bool Value::isMember( const char *key ) const { const Value *value = &((*this)[key]); - return value != &null; + return value != &jsonNull; } @@ -1767,7 +1769,7 @@ Path::resolve( const Value &root ) const // Error: unable to resolve path (object value expected at position...) } node = &((*node)[arg.key_]); - if ( node == &Value::null ) + if ( node == &Value::jsonNull ) { // Error: unable to resolve path (object has no member named '' at position...) } @@ -1796,7 +1798,7 @@ Path::resolve( const Value &root, if ( !node->isObject() ) return defaultValue; node = &((*node)[arg.key_]); - if ( node == &Value::null ) + if ( node == &Value::jsonNull ) return defaultValue; } } diff --git a/extensions/CCArmature/external_tool/Json/lib_json/value.h b/extensions/CCArmature/external_tool/Json/lib_json/value.h index 0d4d97e715..73c612c94e 100644 --- a/extensions/CCArmature/external_tool/Json/lib_json/value.h +++ b/extensions/CCArmature/external_tool/Json/lib_json/value.h @@ -136,7 +136,7 @@ namespace CSJson { typedef CSJson::LargestUInt LargestUInt; typedef CSJson::ArrayIndex ArrayIndex; - static const Value null; + static const Value jsonNull; /// Minimum signed integer value that can be stored in a CSJson::Value. static const LargestInt minLargestInt; /// Maximum signed integer value that can be stored in a CSJson::Value. diff --git a/extensions/CCArmature/utils/CCArmatureDefine.h b/extensions/CCArmature/utils/CCArmatureDefine.h index 79812fc43a..aab765523c 100644 --- a/extensions/CCArmature/utils/CCArmatureDefine.h +++ b/extensions/CCArmature/utils/CCArmatureDefine.h @@ -30,6 +30,7 @@ THE SOFTWARE. #include "cocos2d.h" #include "ExtensionMacros.h" +#define VERSION_COMBINED 0.25f #ifndef ENABLE_PHYSICS_BOX2D_DETECT #define ENABLE_PHYSICS_BOX2D_DETECT 0 diff --git a/extensions/CCArmature/utils/CCDataReaderHelper.cpp b/extensions/CCArmature/utils/CCDataReaderHelper.cpp index 4fcc3b0019..8b6be9f72b 100644 --- a/extensions/CCArmature/utils/CCDataReaderHelper.cpp +++ b/extensions/CCArmature/utils/CCDataReaderHelper.cpp @@ -26,11 +26,11 @@ THE SOFTWARE. #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; @@ -49,6 +49,7 @@ 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"; @@ -132,6 +133,7 @@ NS_CC_EXT_BEGIN std::vector s_arrConfigFileList; float s_PositionReadScale = 1; static float s_FlashToolVersion = VERSION_2_0; +static float s_CocoStudioVersion = VERSION_COMBINED; void CCDataReaderHelper::setPositionReadScale(float scale) { @@ -590,19 +592,19 @@ CCFrameData *CCDataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, ti if(frameXML->Attribute(A_MOVEMENT) != NULL) { - frameData->m_strMovement = frameXML->Attribute(A_MOVEMENT); + frameData->strMovement = frameXML->Attribute(A_MOVEMENT); } if(frameXML->Attribute(A_EVENT) != NULL) { - frameData->m_strEvent = frameXML->Attribute(A_EVENT); + frameData->strEvent = frameXML->Attribute(A_EVENT); } if(frameXML->Attribute(A_SOUND) != NULL) { - frameData->m_strSound = frameXML->Attribute(A_SOUND); + frameData->strSound = frameXML->Attribute(A_SOUND); } if(frameXML->Attribute(A_SOUND_EFFECT) != NULL) { - frameData->m_strSoundEffect = frameXML->Attribute(A_SOUND_EFFECT); + frameData->strSoundEffect = frameXML->Attribute(A_SOUND_EFFECT); } @@ -864,7 +866,7 @@ CCArmatureData *CCDataReaderHelper::decodeArmature(cs::CSJsonDictionary &json) armatureData->name = name; } - armatureData->dataVersion = json.getItemFloatValue("data_version", 0.1f); + s_CocoStudioVersion = armatureData->dataVersion = json.getItemFloatValue(VERSION, 0.1f); int length = json.getArrayItemCount(BONE_DATA); for (int i = 0; i < length; i++) @@ -1061,18 +1063,23 @@ CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(cs::CSJsonDictionary movementBoneData->addFrameData(frameData); - frameData->frameID = movementBoneData->duration; - movementBoneData->duration += frameData->duration; + if (s_CocoStudioVersion < VERSION_COMBINED) + { + frameData->frameID = movementBoneData->duration; + movementBoneData->duration += frameData->duration; + } delete dic; } - // - CCFrameData *frameData = CCFrameData::create(); - frameData->copy((CCFrameData*)movementBoneData->frameList.lastObject()); - movementBoneData->addFrameData(frameData); + if (s_CocoStudioVersion < VERSION_COMBINED) + { + CCFrameData *frameData = CCFrameData::create(); + frameData->copy((CCFrameData*)movementBoneData->frameList.lastObject()); + movementBoneData->addFrameData(frameData); - frameData->frameID = movementBoneData->duration; + frameData->frameID = movementBoneData->duration; + } return movementBoneData; } @@ -1083,16 +1090,24 @@ CCFrameData *CCDataReaderHelper::decodeFrame(cs::CSJsonDictionary &json) decodeNode(frameData, json); - frameData->duration = json.getItemIntValue(A_DURATION, 1); frameData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0); const char *event = json.getItemStringValue(A_EVENT); if (event != NULL) { - frameData->m_strEvent = event; + 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; } diff --git a/extensions/CCArmature/utils/CCUtilMath.cpp b/extensions/CCArmature/utils/CCUtilMath.cpp index e964e17173..3bc4dcbe23 100644 --- a/extensions/CCArmature/utils/CCUtilMath.cpp +++ b/extensions/CCArmature/utils/CCUtilMath.cpp @@ -27,14 +27,14 @@ THE SOFTWARE. NS_CC_EXT_BEGIN -bool isSpriteContainPoint(CCSprite *_sprite, CCPoint _point, CCPoint &_outPoint) +bool isSpriteContainPoint(CCSprite *sprite, CCPoint _point, CCPoint &outPoint) { - _outPoint = _sprite->convertToNodeSpace(_point); + outPoint = sprite->convertToNodeSpace(_point); - CCSize _s = _sprite->getContentSize(); + CCSize _s = sprite->getContentSize(); CCRect _r(0, 0, _s.width, _s.height); - return _r.containsPoint(_outPoint); + return _r.containsPoint(outPoint); } bool isSpriteContainPoint(CCSprite *_sprite, CCPoint _point) diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp index 62ceaa0f07..0e62769a95 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp @@ -424,6 +424,7 @@ void TestParticleDisplay::onEnter() armature->getAnimation()->playByIndex(0); armature->setPosition(VisibleRect::center()); armature->setScale(0.48f); + armature->getAnimation()->setAnimationScale(0.5f); addChild(armature); @@ -648,7 +649,7 @@ void TestColliderDetector::onEnter() } std::string TestColliderDetector::title() { - return "Test Box2D Detector"; + return "Test Collider Detector"; } void TestColliderDetector::draw() { diff --git a/samples/Cpp/TestCpp/Resources/armature/Dragon.xml b/samples/Cpp/TestCpp/Resources/armature/Dragon.xml index 661b23009a..0b4f52cf06 100644 --- a/samples/Cpp/TestCpp/Resources/armature/Dragon.xml +++ b/samples/Cpp/TestCpp/Resources/armature/Dragon.xml @@ -1,347 +1,236 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/armature/cyborg.xml b/samples/Cpp/TestCpp/Resources/armature/cyborg.xml index 71ac8cb332..6c9a51fdf2 100644 --- a/samples/Cpp/TestCpp/Resources/armature/cyborg.xml +++ b/samples/Cpp/TestCpp/Resources/armature/cyborg.xml @@ -167,281 +167,181 @@ - + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - + + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + - - - - + - + \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/armature/knight.xml b/samples/Cpp/TestCpp/Resources/armature/knight.xml index 3da2e19f28..5cbc2b3f68 100644 --- a/samples/Cpp/TestCpp/Resources/armature/knight.xml +++ b/samples/Cpp/TestCpp/Resources/armature/knight.xml @@ -1,287 +1,194 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/armature/robot.xml b/samples/Cpp/TestCpp/Resources/armature/robot.xml index 3dda72b0fd..c5005d4cd2 100644 --- a/samples/Cpp/TestCpp/Resources/armature/robot.xml +++ b/samples/Cpp/TestCpp/Resources/armature/robot.xml @@ -1,562 +1,682 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file