From e7d5ac32119dd4352653906d401504c5fffd23d1 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Sun, 9 Jun 2013 13:34:48 +0800 Subject: [PATCH 01/28] Fix collider detection --- extensions/CCArmature/display/CCDisplayFactory.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp index c83c482386..c3dfb38345 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ b/extensions/CCArmature/display/CCDisplayFactory.cpp @@ -79,7 +79,13 @@ void CCDisplayFactory::updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisp CCColliderDetector *detector = decoDisplay->getColliderDetector(); if (detector) { - CCAffineTransform t = CCAffineTransformConcat(bone->nodeToArmatureTransform(), bone->getArmature()->nodeToWorldTransform()); + CCNode *node = decoDisplay->getDisplay(); + CCAffineTransform displayTransform = node->nodeToParentTransform(); + CCPoint anchorPoint = node->getAnchorPointInPoints(); + anchorPoint = CCPointApplyAffineTransform(anchorPoint, displayTransform); + displayTransform.tx = anchorPoint.x; + displayTransform.ty = anchorPoint.y; + CCAffineTransform t = CCAffineTransformConcat(displayTransform, bone->getArmature()->nodeToWorldTransform()); detector->updateTransform(t); } } From 57ada1fb36755fd8ab22093deedd1488efa87584 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Sat, 15 Jun 2013 10:16:32 +0800 Subject: [PATCH 02/28] 1.Fix when first frame have no key frame, the armature don't display. 2.Fix color change bug --- extensions/CCArmature/CCArmature.cpp | 5 ++++- extensions/CCArmature/CCArmature.h | 2 +- extensions/CCArmature/datas/CCDatas.cpp | 7 ++++++- extensions/CCArmature/datas/CCDatas.h | 2 ++ .../CCArmature/display/CCDisplayFactory.cpp | 13 ++++++++++++- .../CCArmature/utils/CCDataReaderHelper.cpp | 17 +++++++++++++++++ 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/extensions/CCArmature/CCArmature.cpp b/extensions/CCArmature/CCArmature.cpp index 133635f9ea..76055e7c3a 100644 --- a/extensions/CCArmature/CCArmature.cpp +++ b/extensions/CCArmature/CCArmature.cpp @@ -407,7 +407,10 @@ void CCArmature::updateOffsetPoint() CCRect rect = boundingBox(); setContentSize(rect.size); m_pOffsetPoint = ccp(-rect.origin.x, -rect.origin.y); - setAnchorPoint(ccp(m_pOffsetPoint.x / rect.size.width, m_pOffsetPoint.y / rect.size.height)); + if (rect.size.width != 0 && rect.size.height!= 0) + { + setAnchorPoint(ccp(m_pOffsetPoint.x / rect.size.width, m_pOffsetPoint.y / rect.size.height)); + } } diff --git a/extensions/CCArmature/CCArmature.h b/extensions/CCArmature/CCArmature.h index 1d661a21fb..997e1e63ed 100644 --- a/extensions/CCArmature/CCArmature.h +++ b/extensions/CCArmature/CCArmature.h @@ -133,7 +133,7 @@ protected: CC_SYNTHESIZE_RETAIN(CCArmatureAnimation *, m_pAnimation, Animation); - CC_SYNTHESIZE(CCArmatureData *, m_pArmatureData, CCArmatureData); + CC_SYNTHESIZE(CCArmatureData *, m_pArmatureData, ArmatureData); CC_SYNTHESIZE(CCBatchNode*, m_pBatchNode, BatchNode); diff --git a/extensions/CCArmature/datas/CCDatas.cpp b/extensions/CCArmature/datas/CCDatas.cpp index ee06cced58..54a6a533b8 100644 --- a/extensions/CCArmature/datas/CCDatas.cpp +++ b/extensions/CCArmature/datas/CCDatas.cpp @@ -91,7 +91,11 @@ void CCBaseData::subtract(CCBaseData *from, CCBaseData *to) isUseColorInfo = true; } - + else + { + a = r = g = b = 0; + isUseColorInfo = false; + } if (skewX > M_PI) { @@ -228,6 +232,7 @@ CCDisplayData *CCBoneData::getDisplayData(int index) } CCArmatureData::CCArmatureData() + :dataVersion(0.1f) { } diff --git a/extensions/CCArmature/datas/CCDatas.h b/extensions/CCArmature/datas/CCDatas.h index 5310b8bfe2..9af512f676 100644 --- a/extensions/CCArmature/datas/CCDatas.h +++ b/extensions/CCArmature/datas/CCDatas.h @@ -155,6 +155,7 @@ public: */ std::string displayName; + CCBaseData skinData; }; @@ -268,6 +269,7 @@ public: std::string name; CCDictionary boneDataDic; CCArray boneList; + float dataVersion; }; diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp index c3dfb38345..d8b48950a1 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ b/extensions/CCArmature/display/CCDisplayFactory.cpp @@ -154,7 +154,18 @@ void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *de } skin->setBone(bone); - skin->setSkinData(*bone->getBoneData()); + CCArmature *armature = bone->getArmature(); + if (armature) + { + if (armature->getArmatureData()->dataVersion >= 0.15f) + { + skin->setSkinData(displayData->skinData); + } + else + { + skin->setSkinData(*bone->getBoneData()); + } + } decoDisplay->setDisplay(skin); diff --git a/extensions/CCArmature/utils/CCDataReaderHelper.cpp b/extensions/CCArmature/utils/CCDataReaderHelper.cpp index 7e451b65ef..5ec773408a 100644 --- a/extensions/CCArmature/utils/CCDataReaderHelper.cpp +++ b/extensions/CCArmature/utils/CCDataReaderHelper.cpp @@ -118,6 +118,7 @@ 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"; @@ -854,6 +855,8 @@ CCArmatureData *CCDataReaderHelper::decodeArmature(cs::CSJsonDictionary &json) armatureData->name = name; } + armatureData->dataVersion = json.getItemFloatValue("data_version", 0.1f); + int length = json.getArrayItemCount(BONE_DATA); for (int i = 0; i < length; i++) { @@ -913,6 +916,20 @@ CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(cs::CSJsonDictionary &json) { ((CCSpriteDisplayData *)displayData)->displayName = name; } + + cs::CSJsonDictionary *dic = json.getSubItemFromArray(SKIN_DATA, 0); + if (dic != NULL) + { + CCSpriteDisplayData *sdd = (CCSpriteDisplayData *)displayData; + sdd->skinData.x = dic->getItemFloatValue(A_X, 0); + sdd->skinData.y = dic->getItemFloatValue(A_Y, 0); + 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; From 5d94a5594c5bb0884307a4a34f46cbf0bb33c1b5 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Tue, 25 Jun 2013 12:15:19 +0800 Subject: [PATCH 03/28] 1.Fix color tween bug --- extensions/CCArmature/CCBone.cpp | 48 +++++++------------ extensions/CCArmature/CCBone.h | 9 +--- extensions/CCArmature/animation/CCTween.cpp | 35 ++++++-------- extensions/CCArmature/animation/CCTween.h | 5 ++ .../utils/CCArmatureDataManager.cpp | 1 - 5 files changed, 40 insertions(+), 58 deletions(-) diff --git a/extensions/CCArmature/CCBone.cpp b/extensions/CCArmature/CCBone.cpp index 45252de07b..d03607dff0 100644 --- a/extensions/CCArmature/CCBone.cpp +++ b/extensions/CCArmature/CCBone.cpp @@ -61,7 +61,7 @@ CCBone *CCBone::create(const char *name) CCBone::CCBone() { m_pTweenData = NULL; - m_pParent = NULL; + m_pParentBone = NULL; m_pArmature = NULL; m_pChildArmature = NULL; m_pBoneData = NULL; @@ -71,7 +71,7 @@ CCBone::CCBone() m_pDisplayManager = NULL; m_bIgnoreMovementBoneData = false; m_tWorldTransform = CCAffineTransformMake(1, 0, 0, 1, 0, 0); - m_bTransformDirty = true; + m_bBoneTransformDirty = true; } @@ -158,10 +158,10 @@ CCArmature *CCBone::getArmature() void CCBone::update(float delta) { - if (m_pParent) - m_bTransformDirty = m_bTransformDirty || m_pParent->isTransformDirty(); + if (m_pParentBone) + m_bBoneTransformDirty = m_bBoneTransformDirty || m_pParentBone->isTransformDirty(); - if (m_bTransformDirty) + if (m_bBoneTransformDirty) { float cosX = cos(m_pTweenData->skewX); float cosY = cos(m_pTweenData->skewY); @@ -177,13 +177,13 @@ void CCBone::update(float delta) m_tWorldTransform = CCAffineTransformConcat(nodeToParentTransform(), m_tWorldTransform); - if(m_pParent) + if(m_pParentBone) { - m_tWorldTransform = CCAffineTransformConcat(m_tWorldTransform, m_pParent->m_tWorldTransform); + m_tWorldTransform = CCAffineTransformConcat(m_tWorldTransform, m_pParentBone->m_tWorldTransform); } } - CCDisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bTransformDirty); + CCDisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty); CCObject *object = NULL; CCARRAY_FOREACH(m_pChildren, object) @@ -192,7 +192,7 @@ void CCBone::update(float delta) childBone->update(delta); } - m_bTransformDirty = false; + m_bBoneTransformDirty = false; } @@ -223,11 +223,12 @@ void CCBone::updateColor() void CCBone::addChildBone(CCBone *child) { CCAssert( NULL != child, "Argument must be non-nil"); - CCAssert( NULL == child->m_pParent, "child already added. It can't be added again"); + CCAssert( NULL == child->m_pParentBone, "child already added. It can't be added again"); if(!m_pChildren) { - childrenAlloc(); + m_pChildren = CCArray::createWithCapacity(4); + m_pChildren->retain(); } if (m_pChildren->indexOfObject(child) == UINT_MAX) @@ -262,30 +263,22 @@ void CCBone::removeChildBone(CCBone *bone, bool recursion) void CCBone::removeFromParent(bool recursion) { - if (NULL != m_pParent) + if (NULL != m_pParentBone) { - m_pParent->removeChildBone(this, recursion); + m_pParentBone->removeChildBone(this, recursion); } } void CCBone::setParentBone(CCBone *parent) { - m_pParent = parent; + m_pParentBone = parent; } CCBone *CCBone::getParentBone() { - return m_pParent; + return m_pParentBone; } -void CCBone::childrenAlloc(void) -{ - CC_SAFE_DELETE(m_pChildren); - m_pChildren = CCArray::createWithCapacity(4); - m_pChildren->retain(); -} - - void CCBone::setChildArmature(CCArmature *armature) { if (m_pChildArmature != armature) @@ -301,11 +294,6 @@ CCArmature *CCBone::getChildArmature() return m_pChildArmature; } -CCArray *CCBone::getChildren() -{ - return m_pChildren; -} - CCTween *CCBone::getTween() { return m_pTween; @@ -319,12 +307,12 @@ void CCBone::setZOrder(int zOrder) void CCBone::setTransformDirty(bool dirty) { - m_bTransformDirty = dirty; + m_bBoneTransformDirty = dirty; } bool CCBone::isTransformDirty() { - return m_bTransformDirty; + return m_bBoneTransformDirty; } CCAffineTransform CCBone::nodeToArmatureTransform() diff --git a/extensions/CCArmature/CCBone.h b/extensions/CCArmature/CCBone.h index 564fdb7de9..c9e5adb872 100644 --- a/extensions/CCArmature/CCBone.h +++ b/extensions/CCArmature/CCBone.h @@ -124,7 +124,6 @@ public: //! Update color to render display void updateColor(); - CCArray *getChildren(); CCTween *getTween(); virtual void setZOrder(int zOrder); @@ -166,12 +165,8 @@ protected: CC_SYNTHESIZE_PASS_BY_REF(std::string, m_strName, Name); - //! Lazy allocs - void childrenAlloc(void); - CCArray *m_pChildren; - - CCBone *m_pParent; //! A weak reference to it's parent - bool m_bTransformDirty; //! Whether or not transform dirty + CCBone *m_pParentBone; //! A weak reference to it's parent + bool m_bBoneTransformDirty; //! Whether or not transform dirty //! self Transform, use this to change display's state CCAffineTransform m_tWorldTransform; diff --git a/extensions/CCArmature/animation/CCTween.cpp b/extensions/CCArmature/animation/CCTween.cpp index 6dde0248b9..59402f851e 100644 --- a/extensions/CCArmature/animation/CCTween.cpp +++ b/extensions/CCArmature/animation/CCTween.cpp @@ -155,12 +155,12 @@ void CCTween::play(CCMovementBoneData *_movementBoneData, int _durationTo, int _ m_bIsTweenKeyFrame = true; } } + + tweenColorTo(0, m_pTweenData, true); } void CCTween::updateHandler() { - - if (m_fCurrentPercent >= 1) { switch(m_eLoopType) @@ -246,7 +246,6 @@ void CCTween::updateHandler() } } - if (m_fCurrentPercent < 1 && m_eLoopType <= ANIMATION_TO_LOOP_BACK) { m_fCurrentPercent = sin(m_fCurrentPercent * CC_HALF_PI); @@ -344,27 +343,23 @@ CCFrameData *CCTween::tweenNodeTo(float percent, CCFrameData *node) m_pBone->setTransformDirty(true); - if(m_pBetween->isUseColorInfo) - { - node->a = m_pFrom->a + percent * m_pBetween->a; - node->r = m_pFrom->r + percent * m_pBetween->r; - node->g = m_pFrom->g + percent * m_pBetween->g; - node->b = m_pFrom->b + percent * m_pBetween->b; - m_pBone->updateColor(); - } - - // CCPoint p1 = ccp(m_pFrom->x, m_pFrom->y); - // CCPoint p2 = ccp(100, 0); - // CCPoint p3 = ccp(200, 400); - // CCPoint p4 = ccp(m_pFrom->x + m_pBetween->x, m_pFrom->y + m_pBetween->y); - // - // CCPoint p = bezierTo(percent, p1, p2, p3, p4); - // node->x = p.x; - // node->y = p.y; + tweenColorTo(percent, node, m_pTweenData->isUseColorInfo); return node; } +void CCTween::tweenColorTo(float percent, CCFrameData *node, bool dirty) +{ + if(node && dirty) + { + node->a = m_pFrom->a + percent * m_pBetween->a; + node->r = m_pFrom->r + percent * m_pBetween->r; + node->g = m_pFrom->g + percent * m_pBetween->g; + node->b = m_pFrom->b + percent * m_pBetween->b; + m_pBone->updateColor(); + } +} + float CCTween::updateFrameData(float currentPrecent, bool activeFrame) { diff --git a/extensions/CCArmature/animation/CCTween.h b/extensions/CCArmature/animation/CCTween.h index 3f81713965..c14605d59b 100644 --- a/extensions/CCArmature/animation/CCTween.h +++ b/extensions/CCArmature/animation/CCTween.h @@ -106,6 +106,11 @@ protected: */ virtual CCFrameData *tweenNodeTo(float percent, CCFrameData *node = NULL); + /** + * According to the percent to calculate current color with tween effect + */ + virtual void tweenColorTo(float percent, CCFrameData *node = NULL, bool dirty = false); + /** * Update display index and process the key frame event when arrived a key frame */ diff --git a/extensions/CCArmature/utils/CCArmatureDataManager.cpp b/extensions/CCArmature/utils/CCArmatureDataManager.cpp index c7ad29d983..cc12ad27d9 100644 --- a/extensions/CCArmature/utils/CCArmatureDataManager.cpp +++ b/extensions/CCArmature/utils/CCArmatureDataManager.cpp @@ -159,7 +159,6 @@ void CCArmatureDataManager::addArmatureFileInfo(const char *armatureName, const void CCArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) { - CCDataReaderHelper::addDataFromFile(configFilePath); addSpriteFrameFromFile(plistPath, imagePath); } From 58550a834c3ba3d5d940585628c824dd044550f3 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Tue, 2 Jul 2013 10:32:32 +0800 Subject: [PATCH 04/28] 1.Fix empty frame bug 2.Change Skin function interface name --- extensions/CCArmature/CCArmature.cpp | 2 +- extensions/CCArmature/animation/CCTween.cpp | 54 ++++++++++--------- extensions/CCArmature/animation/CCTween.h | 2 - .../CCArmature/display/CCDisplayFactory.cpp | 2 +- extensions/CCArmature/display/CCSkin.cpp | 4 +- extensions/CCArmature/display/CCSkin.h | 2 +- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/extensions/CCArmature/CCArmature.cpp b/extensions/CCArmature/CCArmature.cpp index 76055e7c3a..bfd0fcbf64 100644 --- a/extensions/CCArmature/CCArmature.cpp +++ b/extensions/CCArmature/CCArmature.cpp @@ -460,7 +460,7 @@ void CCArmature::draw() if (m_pAtlas->getCapacity() == m_pAtlas->getTotalQuads() && !m_pAtlas->resizeCapacity(m_pAtlas->getCapacity() * 2)) return; - skin->draw(); + skin->updateTransform(); } else if(CCArmature *armature = dynamic_cast(node)) { diff --git a/extensions/CCArmature/animation/CCTween.cpp b/extensions/CCArmature/animation/CCTween.cpp index 59402f851e..ec21561e9b 100644 --- a/extensions/CCArmature/animation/CCTween.cpp +++ b/extensions/CCArmature/animation/CCTween.cpp @@ -83,6 +83,7 @@ bool CCTween::init(CCBone *bone) m_pBone = bone; m_pTweenData = m_pBone->getTweenData(); + m_pTweenData->displayIndex = -1; m_pAnimation = m_pBone->getArmature() != NULL ? m_pBone->getArmature()->getAnimation() : NULL; @@ -94,43 +95,42 @@ bool CCTween::init(CCBone *bone) } -void CCTween::play(CCMovementBoneData *_movementBoneData, int _durationTo, int _durationTween, int _loop, int _tweenEasing) +void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing) { - CCProcessBase::play(NULL, _durationTo, _durationTween, _loop, _tweenEasing); + CCProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing); - m_eLoopType = (AnimationType)_loop; + m_eLoopType = (AnimationType)loop; m_pCurrentKeyFrame = NULL; - m_bIsTweenKeyFrame = false; m_iTotalDuration = 0; betweenDuration = 0; m_iToIndex = 0; - setMovementBoneData(_movementBoneData); + bool difMovement = movementBoneData != m_pMovementBoneData; + setMovementBoneData(movementBoneData); + CCFrameData *nextKeyFrame = m_pMovementBoneData->getFrameData(0); + m_pTweenData->displayIndex = nextKeyFrame->displayIndex; if (m_pMovementBoneData->frameList.count() == 1) { m_eLoopType = SINGLE_FRAME; - CCFrameData *_nextKeyFrame = m_pMovementBoneData->getFrameData(0); - if(_durationTo == 0) + if(durationTo == 0) { - setBetween(_nextKeyFrame, _nextKeyFrame); + setBetween(nextKeyFrame, nextKeyFrame); } else { - m_pTweenData->displayIndex = _nextKeyFrame->displayIndex; - setBetween(m_pTweenData, _nextKeyFrame); + setBetween(m_pTweenData, nextKeyFrame); } - m_bIsTweenKeyFrame = true; m_eFrameTweenEasing = Linear; m_iRawDuration = m_pMovementBoneData->duration; m_iFromIndex = m_iToIndex = 0; } else if (m_pMovementBoneData->frameList.count() > 1) { - if (_loop) + if (loop) { m_eLoopType = ANIMATION_TO_LOOP_BACK; m_iRawDuration = m_pMovementBoneData->duration; @@ -141,18 +141,22 @@ void CCTween::play(CCMovementBoneData *_movementBoneData, int _durationTo, int _ m_iRawDuration = m_pMovementBoneData->duration - 1; } - m_iDurationTween = _durationTween * m_pMovementBoneData->scale; + m_iDurationTween = durationTween * m_pMovementBoneData->scale; - if (_loop && m_pMovementBoneData->delay != 0) + if (loop && m_pMovementBoneData->delay != 0) { setBetween(m_pTweenData, tweenNodeTo(updateFrameData(1 - m_pMovementBoneData->delay), m_pBetween)); - } else { - CCFrameData *_nextKeyFrame = m_pMovementBoneData->getFrameData(0); - setBetween(m_pTweenData, _nextKeyFrame); - m_bIsTweenKeyFrame = true; + if (!difMovement) + { + setBetween(nextKeyFrame, nextKeyFrame); + } + else + { + setBetween(m_pTweenData, nextKeyFrame); + } } } @@ -272,18 +276,18 @@ void CCTween::setBetween(CCFrameData *from, CCFrameData *to) { do { - if(to->displayIndex < 0 && from->displayIndex > 0) + if(from->displayIndex < 0 && to->displayIndex >= 0) + { + m_pFrom->copy(to); + m_pBetween->subtract(to, to); + break; + } + else if(to->displayIndex < 0 && from->displayIndex >= 0) { m_pFrom->copy(from); m_pBetween->subtract(to, to); break; } - else if(from->displayIndex < 0 && to->displayIndex > 0) - { - m_pFrom->copy(to); - m_pBetween->subtract(to, to); - break; - } m_pFrom->copy(from); m_pBetween->subtract(from, to); diff --git a/extensions/CCArmature/animation/CCTween.h b/extensions/CCArmature/animation/CCTween.h index c14605d59b..328a8d250c 100644 --- a/extensions/CCArmature/animation/CCTween.h +++ b/extensions/CCArmature/animation/CCTween.h @@ -130,8 +130,6 @@ protected: CCTweenType m_eFrameTweenEasing; //! Dedermine which tween effect current frame use - bool m_bIsTweenKeyFrame; - int betweenDuration; //! Current key frame will last betweenDuration frames int m_iTotalDuration; diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp index d8b48950a1..efc9fc0334 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ b/extensions/CCArmature/display/CCDisplayFactory.cpp @@ -185,7 +185,7 @@ void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *de void CCDisplayFactory::updateSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty) { CCSkin *skin = (CCSkin *)decoDisplay->getDisplay(); - skin->updateTransform(); + skin->updateArmatureTransform(); } diff --git a/extensions/CCArmature/display/CCSkin.cpp b/extensions/CCArmature/display/CCSkin.cpp index 3b776a5c2e..2aeb12b83d 100644 --- a/extensions/CCArmature/display/CCSkin.cpp +++ b/extensions/CCArmature/display/CCSkin.cpp @@ -79,12 +79,12 @@ const CCBaseData &CCSkin::getSkinData() return m_sSkinData; } -void CCSkin::updateTransform() +void CCSkin::updateArmatureTransform() { m_sTransform = CCAffineTransformConcat(m_tSkinTransform, m_pBone->nodeToArmatureTransform()); } -void CCSkin::draw() +void CCSkin::updateTransform() { // If it is not visible, or one of its ancestors is not visible, then do nothing: if( !m_bVisible) diff --git a/extensions/CCArmature/display/CCSkin.h b/extensions/CCArmature/display/CCSkin.h index aa47224425..4c145f2ea6 100644 --- a/extensions/CCArmature/display/CCSkin.h +++ b/extensions/CCArmature/display/CCSkin.h @@ -38,8 +38,8 @@ public: public: CCSkin(); + void updateArmatureTransform(); void updateTransform(); - void draw(); CC_PROPERTY_PASS_BY_REF(CCBaseData, m_sSkinData, SkinData); CC_SYNTHESIZE(CCBone *, m_pBone, Bone); From 6fc0eaf5b1674f3b480f2e5a5675191c507cadb6 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Sun, 7 Jul 2013 17:27:42 +0800 Subject: [PATCH 05/28] update --- extensions/CCArmature/CCArmature.cpp | 9 +++++++ extensions/CCArmature/CCArmature.h | 6 +++-- extensions/CCArmature/animation/CCTween.cpp | 16 ++++++------- extensions/CCArmature/animation/CCTween.h | 2 +- extensions/CCArmature/datas/CCDatas.cpp | 24 +++++++++++++++++-- extensions/CCArmature/datas/CCDatas.h | 5 +++- .../CCArmature/display/CCDisplayFactory.cpp | 2 +- extensions/CCArmature/display/CCSkin.cpp | 12 ++++++++++ extensions/CCArmature/display/CCSkin.h | 1 + .../utils/CCSpriteFrameCacheHelper.cpp | 23 +++++++++++------- .../utils/CCSpriteFrameCacheHelper.h | 4 +++- 11 files changed, 79 insertions(+), 25 deletions(-) diff --git a/extensions/CCArmature/CCArmature.cpp b/extensions/CCArmature/CCArmature.cpp index bfd0fcbf64..20222afe01 100644 --- a/extensions/CCArmature/CCArmature.cpp +++ b/extensions/CCArmature/CCArmature.cpp @@ -413,6 +413,15 @@ void CCArmature::updateOffsetPoint() } } +void CCArmature::setAnimation(CCArmatureAnimation *animation) +{ + m_pAnimation = animation; +} + +CCArmatureAnimation *CCArmature::getAnimation() +{ + return m_pAnimation; +} void CCArmature::update(float dt) { diff --git a/extensions/CCArmature/CCArmature.h b/extensions/CCArmature/CCArmature.h index 997e1e63ed..b015f16ee8 100644 --- a/extensions/CCArmature/CCArmature.h +++ b/extensions/CCArmature/CCArmature.h @@ -123,6 +123,8 @@ public: inline void setBlendFunc(ccBlendFunc blendFunc) { m_sBlendFunc = blendFunc; } inline ccBlendFunc getBlendFunc(void) { return m_sBlendFunc; } + virtual void setAnimation(CCArmatureAnimation *animation); + virtual CCArmatureAnimation *getAnimation(); protected: /* @@ -130,8 +132,6 @@ protected: */ CCBone *createBone(const char *boneName ); - - CC_SYNTHESIZE_RETAIN(CCArmatureAnimation *, m_pAnimation, Animation); CC_SYNTHESIZE(CCArmatureData *, m_pArmatureData, ArmatureData); @@ -152,6 +152,8 @@ protected: ccBlendFunc m_sBlendFunc; //! It's required for CCTextureProtocol inheritance CCPoint m_pOffsetPoint; + + CCArmatureAnimation *m_pAnimation; }; NS_CC_EXT_END diff --git a/extensions/CCArmature/animation/CCTween.cpp b/extensions/CCArmature/animation/CCTween.cpp index ec21561e9b..a43ff4ad24 100644 --- a/extensions/CCArmature/animation/CCTween.cpp +++ b/extensions/CCArmature/animation/CCTween.cpp @@ -104,7 +104,7 @@ void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int dur m_pCurrentKeyFrame = NULL; m_iTotalDuration = 0; - betweenDuration = 0; + m_BetweenDuration = 0; m_iToIndex = 0; bool difMovement = movementBoneData != m_pMovementBoneData; @@ -200,7 +200,7 @@ void CCTween::updateHandler() m_iNextFrameIndex = m_iDurationTween; m_fCurrentFrame = m_fCurrentPercent * m_iNextFrameIndex; m_iTotalDuration = 0; - betweenDuration = 0; + m_BetweenDuration = 0; m_iToIndex = 0; break; } @@ -227,7 +227,7 @@ void CCTween::updateHandler() } m_iTotalDuration = 0; - betweenDuration = 0; + m_BetweenDuration = 0; m_iToIndex = 0; } break; @@ -243,7 +243,7 @@ void CCTween::updateHandler() m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); m_iTotalDuration = 0; - betweenDuration = 0; + m_BetweenDuration = 0; m_iToIndex = 0; } break; @@ -375,7 +375,7 @@ float CCTween::updateFrameData(float currentPrecent, bool activeFrame) bool isListEnd; //! If play to current frame's front or back, then find current frame again - if (playedTime >= m_iTotalDuration || playedTime < m_iTotalDuration - betweenDuration) + if (playedTime >= m_iTotalDuration || playedTime < m_iTotalDuration - m_BetweenDuration) { /* * Get frame length, if m_iToIndex >= _length, then set m_iToIndex to 0, start anew. @@ -384,8 +384,8 @@ float CCTween::updateFrameData(float currentPrecent, bool activeFrame) int length = m_pMovementBoneData->frameList.count(); do { - betweenDuration = m_pMovementBoneData->getFrameData(m_iToIndex)->duration; - m_iTotalDuration += betweenDuration; + m_BetweenDuration = m_pMovementBoneData->getFrameData(m_iToIndex)->duration; + m_iTotalDuration += m_BetweenDuration; m_iFromIndex = m_iToIndex; if (++m_iToIndex >= length) @@ -413,7 +413,7 @@ float CCTween::updateFrameData(float currentPrecent, bool activeFrame) setBetween(from, to); } - currentPrecent = 1 - (m_iTotalDuration - playedTime) / (float)betweenDuration; + currentPrecent = 1 - (m_iTotalDuration - playedTime) / (float)m_BetweenDuration; /* diff --git a/extensions/CCArmature/animation/CCTween.h b/extensions/CCArmature/animation/CCTween.h index 328a8d250c..b968fb6183 100644 --- a/extensions/CCArmature/animation/CCTween.h +++ b/extensions/CCArmature/animation/CCTween.h @@ -130,7 +130,7 @@ protected: CCTweenType m_eFrameTweenEasing; //! Dedermine which tween effect current frame use - int betweenDuration; //! Current key frame will last betweenDuration frames + int m_BetweenDuration; //! Current key frame will last m_BetweenDuration frames int m_iTotalDuration; diff --git a/extensions/CCArmature/datas/CCDatas.cpp b/extensions/CCArmature/datas/CCDatas.cpp index 54a6a533b8..e6ce61d295 100644 --- a/extensions/CCArmature/datas/CCDatas.cpp +++ b/extensions/CCArmature/datas/CCDatas.cpp @@ -122,6 +122,19 @@ void CCBaseData::subtract(CCBaseData *from, CCBaseData *to) } } +void CCBaseData::setColor(ccColor4B &color) +{ + r = color.r; + g = color.g; + b = color.b; + a = color.a; +} + +ccColor4B CCBaseData::getColor() +{ + return ccc4(r, g, b, a); +} + const char *CCDisplayData::changeDisplayToTexture(const char *displayName) { @@ -242,13 +255,12 @@ CCArmatureData::~CCArmatureData() bool CCArmatureData::init() { - return boneList.init(); + return true; } void CCArmatureData::addBoneData(CCBoneData *boneData) { boneDataDic.setObject(boneData, boneData->name); - boneList.addObject(boneData); } CCBoneData *CCArmatureData::getBoneData(const char *boneName) @@ -385,6 +397,14 @@ bool CCContourData::init() { return vertexList.init(); } +void CCContourData::addVertex(CCPoint *vertex) +{ + CCContourVertex2 *vertex2 = new CCContourVertex2(vertex->x, vertex->y); + vertex2->autorelease(); + + vertexList.addObject(vertex2); +} + CCTextureData::CCTextureData() : height(0.0f) diff --git a/extensions/CCArmature/datas/CCDatas.h b/extensions/CCArmature/datas/CCDatas.h index 9af512f676..81dcb29181 100644 --- a/extensions/CCArmature/datas/CCDatas.h +++ b/extensions/CCArmature/datas/CCDatas.h @@ -81,6 +81,9 @@ public: * @param to to CCBaseData */ virtual void subtract(CCBaseData *_from, CCBaseData *_to); + + virtual void setColor(ccColor4B &color); + virtual ccColor4B getColor(); public: float x; //! position x attribute float y; //! position y attribute @@ -268,7 +271,6 @@ public: public: std::string name; CCDictionary boneDataDic; - CCArray boneList; float dataVersion; }; @@ -420,6 +422,7 @@ public: ~CCContourData(void); virtual bool init(); + virtual void addVertex(CCPoint *vertex); public: CCArray vertexList; //! Save contour vertex info, vertex saved in a CCPoint }; diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp index efc9fc0334..d03fb2254d 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ b/extensions/CCArmature/display/CCDisplayFactory.cpp @@ -143,7 +143,7 @@ void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *de skin = CCSkin::createWithSpriteFrameName((textureName + ".png").c_str()); } - CCTextureAtlas *atlas = CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTextureAtlas((textureName + ".png").c_str()); + CCTextureAtlas *atlas = CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTextureAtlasWithDisplayName((textureName + ".png").c_str()); skin->setTextureAtlas(atlas); CCTextureData *textureData = CCArmatureDataManager::sharedArmatureDataManager()->getTextureData(textureName.c_str()); diff --git a/extensions/CCArmature/display/CCSkin.cpp b/extensions/CCArmature/display/CCSkin.cpp index 2aeb12b83d..967cbab6ae 100644 --- a/extensions/CCArmature/display/CCSkin.cpp +++ b/extensions/CCArmature/display/CCSkin.cpp @@ -57,6 +57,18 @@ CCSkin *CCSkin::createWithSpriteFrameName(const char *pszSpriteFrameName) return NULL; } +CCSkin *CCSkin::create(const char *pszFileName) +{ + CCSkin *skin = new CCSkin(); + if(skin && skin->initWithFile(pszFileName)) + { + skin->autorelease(); + return skin; + } + CC_SAFE_DELETE(skin); + return NULL; +} + CCSkin::CCSkin() : m_pBone(NULL) { diff --git a/extensions/CCArmature/display/CCSkin.h b/extensions/CCArmature/display/CCSkin.h index 4c145f2ea6..7dcbd112b2 100644 --- a/extensions/CCArmature/display/CCSkin.h +++ b/extensions/CCArmature/display/CCSkin.h @@ -35,6 +35,7 @@ class CCSkin : public CCSprite public: static CCSkin *create(); static CCSkin *createWithSpriteFrameName(const char *pszSpriteFrameName); + static CCSkin *create(const char *pszFileName); public: CCSkin(); diff --git a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp index d1fc75f41f..176a182e1b 100644 --- a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp +++ b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp @@ -157,17 +157,22 @@ const char *CCSpriteFrameCacheHelper::getDisplayImagePath(const char *displayNam } -CCTextureAtlas *CCSpriteFrameCacheHelper::getTextureAtlas(const char *displayName) +CCTextureAtlas *CCSpriteFrameCacheHelper::getTextureAtlasWithImageName(const char *imageName) { - const char *textureName = getDisplayImagePath(displayName); - CCTextureAtlas *atlas = (CCTextureAtlas *)m_pDisplay2TextureAtlas->objectForKey(textureName); - if (atlas == NULL) - { - atlas = CCTextureAtlas::createWithTexture(CCTextureCache::sharedTextureCache()->addImage(textureName), 4); - m_pDisplay2TextureAtlas->setObject(atlas, textureName); - } + CCTextureAtlas *atlas = (CCTextureAtlas*)m_pDisplay2TextureAtlas->objectForKey(imageName); + if (atlas == NULL) + { + atlas = CCTextureAtlas::createWithTexture(CCTextureCache::sharedTextureCache()->addImage(imageName), 4); + m_pDisplay2TextureAtlas->setObject(atlas, imageName); + } - return atlas; + return atlas; +} + +CCTextureAtlas *CCSpriteFrameCacheHelper::getTextureAtlasWithDisplayName(const char *displayName) +{ + const char *textureName = getDisplayImagePath(displayName); + return getTextureAtlasWithImageName(textureName); } CCSpriteFrameCacheHelper::CCSpriteFrameCacheHelper() diff --git a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h index b65976c8b6..66b47b9897 100644 --- a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h +++ b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h @@ -51,7 +51,9 @@ public: * Get this display in which image */ const char *getDisplayImagePath(const char *displayName); - CCTextureAtlas *getTextureAtlas(const char *displayName); + + cocos2d::CCTextureAtlas *getTextureAtlasWithImageName(const char *imageName); + cocos2d::CCTextureAtlas *getTextureAtlasWithDisplayName(const char *displayName); private: CCSpriteFrameCacheHelper(); From 4a8cde4dadedd2f8fbe2b15e81c44dd9a4af4817 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Mon, 8 Jul 2013 23:25:11 +0800 Subject: [PATCH 06/28] Change Tween Type to Frame Index --- extensions/CCArmature/animation/CCTween.cpp | 56 +++++++++---------- extensions/CCArmature/animation/CCTween.h | 1 - extensions/CCArmature/datas/CCDatas.cpp | 5 +- extensions/CCArmature/datas/CCDatas.h | 1 + .../CCArmature/utils/CCDataReaderHelper.cpp | 23 +++++++- 5 files changed, 53 insertions(+), 33 deletions(-) diff --git a/extensions/CCArmature/animation/CCTween.cpp b/extensions/CCArmature/animation/CCTween.cpp index a43ff4ad24..1717119bee 100644 --- a/extensions/CCArmature/animation/CCTween.cpp +++ b/extensions/CCArmature/animation/CCTween.cpp @@ -54,7 +54,6 @@ CCTween::CCTween() , m_pFrom(NULL) , m_pTo(NULL) , m_pBetween(NULL) - , m_pCurrentKeyFrame(NULL) , m_pBone(NULL) , m_eFrameTweenEasing(Linear) @@ -101,11 +100,10 @@ void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int dur m_eLoopType = (AnimationType)loop; - m_pCurrentKeyFrame = NULL; - m_iTotalDuration = 0; m_BetweenDuration = 0; - m_iToIndex = 0; + m_iFromIndex = m_iToIndex = 0; + bool difMovement = movementBoneData != m_pMovementBoneData; @@ -126,7 +124,6 @@ void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int dur } m_eFrameTweenEasing = Linear; m_iRawDuration = m_pMovementBoneData->duration; - m_iFromIndex = m_iToIndex = 0; } else if (m_pMovementBoneData->frameList.count() > 1) { @@ -217,8 +214,6 @@ void CCTween::updateHandler() // m_fCurrentFrame = (1 - m_pMovementBoneData->delay) * (float)m_iNextFrameIndex; m_fCurrentPercent = m_fCurrentFrame / m_iNextFrameIndex; - - } else { @@ -266,10 +261,6 @@ void CCTween::updateHandler() { tweenNodeTo(percent); } - else if(m_pCurrentKeyFrame) - { - tweenNodeTo(0); - } } void CCTween::setBetween(CCFrameData *from, CCFrameData *to) @@ -328,7 +319,7 @@ void CCTween::arriveKeyFrame(CCFrameData *keyFrameData) } // if(keyFrameData->m_strSound.length() != 0) // { - // //soundManager.dispatchEventWith(Event.SOUND_FRAME, m_pCurrentKeyFrame->sound); + // //soundManager.dispatchEventWith(Event.SOUND_FRAME, keyFrameData->sound); // } } } @@ -366,26 +357,33 @@ void CCTween::tweenColorTo(float percent, CCFrameData *node, bool dirty) float CCTween::updateFrameData(float currentPrecent, bool activeFrame) { - + if (currentPrecent > 1) + { + currentPrecent = fmodf(currentPrecent,1); + } + float playedTime = (float)m_iRawDuration * currentPrecent; - CCFrameData *from; - CCFrameData *to; - bool isListEnd; - //! 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_BetweenDuration) { /* * 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 *from = NULL; + CCFrameData *to = NULL; + bool isListEnd; + CCFrameData **frames = (CCFrameData**)m_pMovementBoneData->frameList.data->arr; + do { - m_BetweenDuration = m_pMovementBoneData->getFrameData(m_iToIndex)->duration; - m_iTotalDuration += m_BetweenDuration; + from = frames[m_iFromIndex]; + to = frames[m_iToIndex]; + m_iTotalDuration = from->frameID; m_iFromIndex = m_iToIndex; if (++m_iToIndex >= length) @@ -393,27 +391,29 @@ float CCTween::updateFrameData(float currentPrecent, bool activeFrame) m_iToIndex = 0; } } - while (playedTime >= m_iTotalDuration); + while (playedTime < from->frameID || playedTime>=to->frameID); + + m_BetweenDuration = to->frameID - from->frameID; isListEnd = m_eLoopType == ANIMATION_MAX && m_iToIndex == 0; if(isListEnd) { - to = from = m_pMovementBoneData->getFrameData(m_iFromIndex); - } - else - { - from = m_pMovementBoneData->getFrameData(m_iFromIndex); - to = m_pMovementBoneData->getFrameData(m_iToIndex); + to = from = frames[m_iFromIndex]; } +// else +// { +// from = frames[m_iFromIndex]; +// to = frames[m_iToIndex]; +// } m_eFrameTweenEasing = from->tweenEasing; setBetween(from, to); } - currentPrecent = 1 - (m_iTotalDuration - playedTime) / (float)m_BetweenDuration; + currentPrecent = (playedTime - m_iTotalDuration) / (float)m_BetweenDuration; /* diff --git a/extensions/CCArmature/animation/CCTween.h b/extensions/CCArmature/animation/CCTween.h index b968fb6183..bb27f2f111 100644 --- a/extensions/CCArmature/animation/CCTween.h +++ b/extensions/CCArmature/animation/CCTween.h @@ -124,7 +124,6 @@ protected: CCFrameData *m_pTo; //! To frame data, used for calculate between value CCFrameData *m_pBetween; //! Between frame data, used for calculate current CCFrameData(m_pNode) value - CCFrameData *m_pCurrentKeyFrame; //! A weak reference to the current CCFrameData. The data is in the data pool CCBone *m_pBone; //! A weak reference to the CCBone diff --git a/extensions/CCArmature/datas/CCDatas.cpp b/extensions/CCArmature/datas/CCDatas.cpp index e6ce61d295..b525332248 100644 --- a/extensions/CCArmature/datas/CCDatas.cpp +++ b/extensions/CCArmature/datas/CCDatas.cpp @@ -269,7 +269,8 @@ CCBoneData *CCArmatureData::getBoneData(const char *boneName) } CCFrameData::CCFrameData(void) - : duration(1) + : frameID(0) + , duration(1) , tweenEasing(Linear) , displayIndex(0) @@ -288,6 +289,7 @@ void CCFrameData::copy(CCFrameData *frameData) { CCBaseData::copy(frameData); + frameID = frameData->frameID; duration = frameData->duration; displayIndex = frameData->displayIndex; tweenEasing = frameData->tweenEasing; @@ -313,7 +315,6 @@ bool CCMovementBoneData::init() void CCMovementBoneData::addFrameData(CCFrameData *frameData) { frameList.addObject(frameData); - duration += frameData->duration; } CCFrameData *CCMovementBoneData::getFrameData(int index) diff --git a/extensions/CCArmature/datas/CCDatas.h b/extensions/CCArmature/datas/CCDatas.h index 81dcb29181..9ecbc225be 100644 --- a/extensions/CCArmature/datas/CCDatas.h +++ b/extensions/CCArmature/datas/CCDatas.h @@ -285,6 +285,7 @@ public: virtual void copy(CCFrameData *frameData); public: + int frameID; int duration; //! The frame will last m_iDuration frames CCTweenType tweenEasing; //! Every frame's tween easing effect diff --git a/extensions/CCArmature/utils/CCDataReaderHelper.cpp b/extensions/CCArmature/utils/CCDataReaderHelper.cpp index 5ec773408a..4fcc3b0019 100644 --- a/extensions/CCArmature/utils/CCDataReaderHelper.cpp +++ b/extensions/CCArmature/utils/CCDataReaderHelper.cpp @@ -562,11 +562,20 @@ CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(tinyxml2::XMLElement CCFrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData); movBoneData->addFrameData(frameData); + frameData->frameID = totalDuration; totalDuration += frameData->duration; + movBoneData->duration = totalDuration; frameXML = frameXML->NextSiblingElement(FRAME); } + + // + CCFrameData *frameData = CCFrameData::create(); + frameData->copy((CCFrameData*)movBoneData->frameList.lastObject()); + frameData->frameID = movBoneData->duration; + movBoneData->addFrameData(frameData); + return movBoneData; } @@ -1049,12 +1058,22 @@ CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(cs::CSJsonDictionary { cs::CSJsonDictionary *dic = json.getSubItemFromArray(FRAME_DATA, i); CCFrameData *frameData = decodeFrame(*dic); - movementBoneData->addFrameData(frameData); - //movementBoneData->duration += frameData->duration; + + movementBoneData->addFrameData(frameData); + + frameData->frameID = movementBoneData->duration; + movementBoneData->duration += frameData->duration; delete dic; } + // + CCFrameData *frameData = CCFrameData::create(); + frameData->copy((CCFrameData*)movementBoneData->frameList.lastObject()); + movementBoneData->addFrameData(frameData); + + frameData->frameID = movementBoneData->duration; + return movementBoneData; } From ac6d4e5cbbd92659749b773c8fb15aa933254d3a Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Tue, 9 Jul 2013 22:07:56 +0800 Subject: [PATCH 07/28] remove CCShaderNode --- extensions/CCArmature/CCBone.cpp | 9 +- extensions/CCArmature/CCBone.h | 2 + .../CCArmature/display/CCDisplayFactory.cpp | 17 --- .../CCArmature/display/CCDisplayFactory.h | 4 - .../CCArmature/display/CCDisplayManager.cpp | 5 + .../CCArmature/display/CCDisplayManager.h | 2 + .../CCArmature/display/CCShaderNode.cpp | 136 ------------------ extensions/CCArmature/display/CCShaderNode.h | 57 -------- extensions/proj.win32/libExtensions.vcxproj | 2 - .../proj.win32/libExtensions.vcxproj.filters | 6 - 10 files changed, 16 insertions(+), 224 deletions(-) delete mode 100644 extensions/CCArmature/display/CCShaderNode.cpp delete mode 100644 extensions/CCArmature/display/CCShaderNode.h diff --git a/extensions/CCArmature/CCBone.cpp b/extensions/CCArmature/CCBone.cpp index d03607dff0..aa2e11a1c6 100644 --- a/extensions/CCArmature/CCBone.cpp +++ b/extensions/CCArmature/CCBone.cpp @@ -320,9 +320,14 @@ CCAffineTransform CCBone::nodeToArmatureTransform() return m_tWorldTransform; } -void CCBone::addDisplay(CCDisplayData *_displayData, int _index) +void CCBone::addDisplay(CCDisplayData *displayData, int index) { - m_pDisplayManager->addDisplay(_displayData, _index); + m_pDisplayManager->addDisplay(displayData, index); +} + +void CCBone::addDisplay(CCNode *display, int index) +{ + m_pDisplayManager->addDisplay(display, index); } void CCBone::changeDisplayByIndex(int _index, bool _force) diff --git a/extensions/CCArmature/CCBone.h b/extensions/CCArmature/CCBone.h index c9e5adb872..719726ae05 100644 --- a/extensions/CCArmature/CCBone.h +++ b/extensions/CCArmature/CCBone.h @@ -80,6 +80,8 @@ public: */ void addDisplay(CCDisplayData *displayData, int index); + void addDisplay(CCNode *display, int index); + void changeDisplayByIndex(int index, bool force); /** diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp index d03fb2254d..3f2f6cab29 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ b/extensions/CCArmature/display/CCDisplayFactory.cpp @@ -26,7 +26,6 @@ THE SOFTWARE. #include "../CCBone.h" #include "../CCArmature.h" #include "../display/CCSkin.h" -#include "../display/CCShaderNode.h" #include "../utils/CCSpriteFrameCacheHelper.h" #include "../utils/CCArmatureDataManager.h" #include "../utils/CCTransformHelp.h" @@ -251,20 +250,4 @@ void CCDisplayFactory::updateParticleDisplay(CCBone *bone, CCDecorativeDisplay * } - -void CCDisplayFactory::addShaderDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) -{ - CCShaderDisplayData *sdp = CCShaderDisplayData::create(); - sdp->copy((CCShaderDisplayData *)displayData); - decoDisplay->setDisplayData(sdp); - - createShaderDisplay(bone, decoDisplay); -} -void CCDisplayFactory::createShaderDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) -{ - CCShaderDisplayData *displayData = (CCShaderDisplayData *)decoDisplay->getDisplayData(); - CCShaderNode *sn = CCShaderNode::shaderNodeWithVertex(displayData->vert.c_str(), displayData->frag.c_str()); - decoDisplay->setDisplay(sn); -} - NS_CC_EXT_END diff --git a/extensions/CCArmature/display/CCDisplayFactory.h b/extensions/CCArmature/display/CCDisplayFactory.h index 5c1cac7f91..705f2b3ac5 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.h +++ b/extensions/CCArmature/display/CCDisplayFactory.h @@ -53,10 +53,6 @@ public: static void addParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); static void createParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); static void updateParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty); - - static void addShaderDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); - static void createShaderDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - }; diff --git a/extensions/CCArmature/display/CCDisplayManager.cpp b/extensions/CCArmature/display/CCDisplayManager.cpp index c8b645faa4..50e9ee51c5 100644 --- a/extensions/CCArmature/display/CCDisplayManager.cpp +++ b/extensions/CCArmature/display/CCDisplayManager.cpp @@ -110,6 +110,11 @@ void CCDisplayManager::addDisplay(CCDisplayData *displayData, int index) } } +void CCDisplayManager::addDisplay(CCNode *display, int index) +{ + +} + void CCDisplayManager::removeDisplay(int index) { m_pDecoDisplayList->removeObjectAtIndex(index); diff --git a/extensions/CCArmature/display/CCDisplayManager.h b/extensions/CCArmature/display/CCDisplayManager.h index 20dffd987a..0b04d38055 100644 --- a/extensions/CCArmature/display/CCDisplayManager.h +++ b/extensions/CCArmature/display/CCDisplayManager.h @@ -65,6 +65,8 @@ public: */ void addDisplay(CCDisplayData *displayData, int index); + void addDisplay(CCNode *display, int index); + void removeDisplay(int index); CCArray *getDecorativeDisplayList(); diff --git a/extensions/CCArmature/display/CCShaderNode.cpp b/extensions/CCArmature/display/CCShaderNode.cpp deleted file mode 100644 index e89fd98ece..0000000000 --- a/extensions/CCArmature/display/CCShaderNode.cpp +++ /dev/null @@ -1,136 +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 "CCShaderNode.h" - -NS_CC_EXT_BEGIN - -enum -{ - SIZE_X = 128, - SIZE_Y = 128, -}; - -CCShaderNode::CCShaderNode() - : m_center(vertex2(0.0f, 0.0f)) - , m_resolution(vertex2(0.0f, 0.0f)) - , m_time(0.0f) - , m_uniformCenter(0) - , m_uniformResolution(0) - , m_uniformTime(0) -{ -} - -CCShaderNode *CCShaderNode::shaderNodeWithVertex(const char *vert, const char *frag) -{ - CCShaderNode *node = new CCShaderNode(); - node->initWithVertex(vert, frag); - node->autorelease(); - - return node; -} - -bool CCShaderNode::initWithVertex(const char *vert, const char *frag) -{ - - loadShaderVertex(vert, frag); - - m_time = 0; - m_resolution = vertex2(SIZE_X, SIZE_Y); - - scheduleUpdate(); - - setContentSize(CCSizeMake(SIZE_X, SIZE_Y)); - setAnchorPoint(ccp(0.5f, 0.5f)); - - return true; -} - -void CCShaderNode::loadShaderVertex(const char *vert, const char *frag) -{ - CCGLProgram *shader = new CCGLProgram(); - shader->initWithVertexShaderFilename(vert, frag); - - shader->addAttribute("aVertex", kCCVertexAttrib_Position); - shader->link(); - - shader->updateUniforms(); - - m_uniformCenter = glGetUniformLocation(shader->getProgram(), "center"); - m_uniformResolution = glGetUniformLocation(shader->getProgram(), "resolution"); - m_uniformTime = glGetUniformLocation(shader->getProgram(), "time"); - - this->setShaderProgram(shader); - - shader->release(); -} - -void CCShaderNode::update(float dt) -{ - m_time += dt; -} - -void CCShaderNode::translateFormOtherNode(CCAffineTransform &transform) -{ - CCNode::setAdditionalTransform(transform); - - m_center = vertex2(m_sAdditionalTransform.tx * CC_CONTENT_SCALE_FACTOR(), m_sAdditionalTransform.ty * CC_CONTENT_SCALE_FACTOR()); - m_resolution = vertex2( SIZE_X * m_sAdditionalTransform.a, SIZE_Y * m_sAdditionalTransform.d); -} - -void CCShaderNode::setPosition(const CCPoint &newPosition) -{ - CCNode::setPosition(newPosition); - CCPoint position = getPosition(); - m_center = vertex2(position.x * CC_CONTENT_SCALE_FACTOR(), position.y * CC_CONTENT_SCALE_FACTOR()); -} - -void CCShaderNode::draw() -{ - CC_NODE_DRAW_SETUP(); - - float w = SIZE_X, h = SIZE_Y; - GLfloat vertices[12] = {0, 0, w, 0, w, h, 0, 0, 0, h, w, h}; - - // - // Uniforms - // - getShaderProgram()->setUniformLocationWith2f(m_uniformCenter, m_center.x, m_center.y); - getShaderProgram()->setUniformLocationWith2f(m_uniformResolution, m_resolution.x, m_resolution.y); - - - // time changes all the time, so it is Ok to call OpenGL directly, and not the "cached" version - glUniform1f(m_uniformTime, m_time); - - ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position ); - - glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices); - - glDrawArrays(GL_TRIANGLES, 0, 6); - - CC_INCREMENT_GL_DRAWS(1); -} - - -NS_CC_EXT_END diff --git a/extensions/CCArmature/display/CCShaderNode.h b/extensions/CCArmature/display/CCShaderNode.h deleted file mode 100644 index 967ba08bfa..0000000000 --- a/extensions/CCArmature/display/CCShaderNode.h +++ /dev/null @@ -1,57 +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 __CCSHADERNODE_H__ -#define __CCSHADERNODE_H__ - -#include "../utils/CCArmatureDefine.h" - -NS_CC_EXT_BEGIN - -class CCShaderNode : public CCNode -{ -public: - CCShaderNode(); - - bool initWithVertex(const char *vert, const char *frag); - void loadShaderVertex(const char *vert, const char *frag); - - virtual void update(float dt); - virtual void setPosition(const CCPoint &newPosition); - virtual void translateFormOtherNode(CCAffineTransform &transform); - virtual void draw(); - - static CCShaderNode *shaderNodeWithVertex(const char *vert, const char *frag); - -private: - - ccVertex2F m_center; - ccVertex2F m_resolution; - float m_time; - GLuint m_uniformCenter, m_uniformResolution, m_uniformTime; -}; - -NS_CC_EXT_END - -#endif /*__CCSHADERNODE_H__*/ diff --git a/extensions/proj.win32/libExtensions.vcxproj b/extensions/proj.win32/libExtensions.vcxproj index 611280aa6a..03d8f2d893 100644 --- a/extensions/proj.win32/libExtensions.vcxproj +++ b/extensions/proj.win32/libExtensions.vcxproj @@ -102,7 +102,6 @@ - @@ -204,7 +203,6 @@ - diff --git a/extensions/proj.win32/libExtensions.vcxproj.filters b/extensions/proj.win32/libExtensions.vcxproj.filters index 14544b6d15..52b9d2b51e 100644 --- a/extensions/proj.win32/libExtensions.vcxproj.filters +++ b/extensions/proj.win32/libExtensions.vcxproj.filters @@ -228,9 +228,6 @@ CCArmature\display - - CCArmature\display - CCArmature\display @@ -556,9 +553,6 @@ CCArmature\display - - CCArmature\display - CCArmature\display From 54e5fca2aafe5a2b2e4f72b60fe562110a8b81cd Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Wed, 10 Jul 2013 10:00:51 +0800 Subject: [PATCH 08/28] Bone can add a particle display as a CCNode --- .../CCArmature/display/CCDisplayFactory.cpp | 39 +++++++++---------- .../CCArmature/display/CCDisplayFactory.h | 6 +-- .../CCArmature/display/CCDisplayManager.cpp | 20 ++++++++++ .../ArmatureTest/ArmatureScene.cpp | 9 +++-- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp index 3f2f6cab29..a8ce6d6336 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ b/extensions/CCArmature/display/CCDisplayFactory.cpp @@ -90,21 +90,20 @@ void CCDisplayFactory::updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisp } #endif + CCNode *display = decoDisplay->getDisplay(); - switch(decoDisplay->getDisplayData()->displayType) - { - case CS_DISPLAY_SPRITE: - updateSpriteDisplay(bone, decoDisplay, dt, dirty); - break; - case CS_DISPLAY_PARTICLE: - updateParticleDisplay(bone, decoDisplay, dt, dirty); - break; - case CS_DISPLAY_ARMATURE: - updateArmatureDisplay(bone, decoDisplay, dt, dirty); - break; - default: - break; - } + if (dynamic_cast(display) != NULL) + { + updateSpriteDisplay(bone, display, dt, dirty); + } + else if (dynamic_cast(display) != NULL) + { + updateParticleDisplay(bone, display, dt, dirty); + } + else if (dynamic_cast(display) != NULL) + { + updateArmatureDisplay(bone, display, dt, dirty); + } } @@ -181,9 +180,9 @@ void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *de #endif } -void CCDisplayFactory::updateSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty) +void CCDisplayFactory::updateSpriteDisplay(CCBone *bone, CCNode *display, float dt, bool dirty) { - CCSkin *skin = (CCSkin *)decoDisplay->getDisplay(); + CCSkin *skin = (CCSkin *)display; skin->updateArmatureTransform(); } @@ -210,11 +209,11 @@ void CCDisplayFactory::createArmatureDisplay(CCBone *bone, CCDecorativeDisplay * decoDisplay->setDisplay(armature); } -void CCDisplayFactory::updateArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty) +void CCDisplayFactory::updateArmatureDisplay(CCBone *bone, CCNode *display, float dt, bool dirty) { CS_RETURN_IF(!dirty); - CCArmature *armature = bone->getChildArmature(); + CCArmature *armature = (CCArmature*)display; if(armature) { armature->sortAllChildren(); @@ -238,9 +237,9 @@ void CCDisplayFactory::createParticleDisplay(CCBone *bone, CCDecorativeDisplay * CCParticleSystem *system = CCParticleSystemQuad::create(displayData->plist.c_str()); decoDisplay->setDisplay(system); } -void CCDisplayFactory::updateParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty) +void CCDisplayFactory::updateParticleDisplay(CCBone *bone, CCNode *display, float dt, bool dirty) { - CCParticleSystem *system = (CCParticleSystem *)decoDisplay->getDisplay(); + CCParticleSystem *system = (CCParticleSystem *)display; CCBaseData node; CCTransformHelp::matrixToNode(bone->nodeToArmatureTransform(), node); system->setPosition(node.x, node.y); diff --git a/extensions/CCArmature/display/CCDisplayFactory.h b/extensions/CCArmature/display/CCDisplayFactory.h index 705f2b3ac5..7e9c244ca8 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.h +++ b/extensions/CCArmature/display/CCDisplayFactory.h @@ -44,15 +44,15 @@ public: static void addSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); static void createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty); + static void updateSpriteDisplay(CCBone *bone, CCNode *display, float dt, bool dirty); static void addArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); static void createArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty); + static void updateArmatureDisplay(CCBone *bone, CCNode *display, float dt, bool dirty); static void addParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); static void createParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty); + static void updateParticleDisplay(CCBone *bone, CCNode *display, float dt, bool dirty); }; diff --git a/extensions/CCArmature/display/CCDisplayManager.cpp b/extensions/CCArmature/display/CCDisplayManager.cpp index 50e9ee51c5..09d37f8ae4 100644 --- a/extensions/CCArmature/display/CCDisplayManager.cpp +++ b/extensions/CCArmature/display/CCDisplayManager.cpp @@ -112,7 +112,27 @@ void CCDisplayManager::addDisplay(CCDisplayData *displayData, int index) void CCDisplayManager::addDisplay(CCNode *display, int index) { + CCDecorativeDisplay *decoDisplay = NULL; + if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) + { + decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->objectAtIndex(index); + } + else + { + decoDisplay = CCDecorativeDisplay::create(); + m_pDecoDisplayList->addObject(decoDisplay); + } + + /*CCDisplayFactory::addDisplay(m_pBone, decoDisplay, displayData);*/ + decoDisplay->setDisplay(display); + + //! if changed display index is current display index, then change current display to the new display + if(index == m_iDisplayIndex) + { + m_iDisplayIndex = -1; + changeDisplayByIndex(index, false); + } } void CCDisplayManager::removeDisplay(int index) diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp index aaac12e545..e32d4a6792 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp @@ -425,11 +425,12 @@ void TestParticleDisplay::onEnter() armature->setScale(0.48f); addChild(armature); - CCParticleDisplayData displayData; - displayData.setParam("Particles/SmallSun.plist"); + + CCParticleSystem *p1 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); + CCParticleSystem *p2 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); cocos2d::extension::CCBone *bone = cocos2d::extension::CCBone::create("p1"); - bone->addDisplay(&displayData, 0); + bone->addDisplay(p1, 0); bone->changeDisplayByIndex(0, true); bone->setIgnoreMovementBoneData(true); bone->setZOrder(100); @@ -437,7 +438,7 @@ void TestParticleDisplay::onEnter() armature->addBone(bone, "bady-a3"); bone = cocos2d::extension::CCBone::create("p2"); - bone->addDisplay(&displayData, 0); + bone->addDisplay(p2, 0); bone->changeDisplayByIndex(0, true); bone->setIgnoreMovementBoneData(true); bone->setZOrder(100); From 619a8810fe435024524f86cd3ae6475c317b4cdb Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Sat, 13 Jul 2013 19:14:30 +0800 Subject: [PATCH 09/28] Change Physics detector --- extensions/CCArmature/CCArmature.cpp | 61 ++++ extensions/CCArmature/CCArmature.h | 9 + extensions/CCArmature/CCBone.cpp | 10 + extensions/CCArmature/CCBone.h | 2 + extensions/CCArmature/animation/CCTween.cpp | 7 +- .../display/CCDecorativeDisplay.cpp | 4 +- .../CCArmature/display/CCDecorativeDisplay.h | 4 +- .../CCArmature/display/CCDisplayFactory.cpp | 4 +- .../CCArmature/display/CCDisplayManager.cpp | 9 +- extensions/CCArmature/display/CCSkin.cpp | 6 + extensions/CCArmature/display/CCSkin.h | 2 + .../CCArmature/external_tool/GLES-Render.cpp | 254 ----------------- .../CCArmature/external_tool/GLES-Render.h | 67 ----- .../CCArmature/physics/CCColliderDetector.cpp | 240 +++++++++++----- .../CCArmature/physics/CCColliderDetector.h | 56 ++-- .../CCArmature/physics/CCPhysicsWorld.cpp | 165 ----------- .../CCArmature/physics/CCPhysicsWorld.h | 80 ------ .../utils/CCArmatureDataManager.cpp | 3 - .../CCArmature/utils/CCArmatureDefine.h | 9 +- extensions/cocos-ext.h | 1 - extensions/proj.win32/libExtensions.vcxproj | 4 - .../proj.win32/libExtensions.vcxproj.filters | 12 - .../ArmatureTest/ArmatureScene.cpp | 262 ++++++++++++++++-- .../ArmatureTest/ArmatureScene.h | 36 ++- .../armature/Cowboy0.png.REMOVED.git-id | 2 +- 25 files changed, 591 insertions(+), 718 deletions(-) delete mode 100644 extensions/CCArmature/external_tool/GLES-Render.cpp delete mode 100644 extensions/CCArmature/external_tool/GLES-Render.h delete mode 100644 extensions/CCArmature/physics/CCPhysicsWorld.cpp delete mode 100644 extensions/CCArmature/physics/CCPhysicsWorld.h diff --git a/extensions/CCArmature/CCArmature.cpp b/extensions/CCArmature/CCArmature.cpp index 20222afe01..b5e659d76f 100644 --- a/extensions/CCArmature/CCArmature.cpp +++ b/extensions/CCArmature/CCArmature.cpp @@ -587,4 +587,65 @@ CCBone *CCArmature::getBoneAtPoint(float x, float y) return NULL; } +#if ENABLE_PHYSICS_BOX2D_DETECT +b2Body *CCArmature::getB2Body() +{ + return m_pB2Body; +} + +void CCArmature::setB2Body(b2Body *body) +{ + m_pB2Body = body; + + CCObject *object = NULL; + CCARRAY_FOREACH(m_pChildren, object) + { + if (CCBone *bone = dynamic_cast(object)) + { + CCArray *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); + + CCObject *displayObject = NULL; + CCARRAY_FOREACH(displayList, displayObject) + { + CCColliderDetector *detector = ((CCDecorativeDisplay*)displayObject)->getColliderDetector(); + if (detector != NULL) + { + detector->setB2Body(m_pB2Body); + } + } + } + } +} +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +cpBody *CCArmature::getCPBody() +{ + return m_pCPBody; +} + +void CCArmature::setCPBody(cpBody *body) +{ + m_pCPBody = body; + + CCObject *object = NULL; + CCARRAY_FOREACH(m_pChildren, object) + { + if (CCBone *bone = dynamic_cast(object)) + { + CCArray *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); + + CCObject *displayObject = NULL; + CCARRAY_FOREACH(displayList, displayObject) + { + CCColliderDetector *detector = ((CCDecorativeDisplay*)displayObject)->getColliderDetector(); + if (detector != NULL) + { + detector->setCPBody(m_pCPBody); + } + } + } + } +} +#endif + + NS_CC_EXT_END diff --git a/extensions/CCArmature/CCArmature.h b/extensions/CCArmature/CCArmature.h index b015f16ee8..0ff843bcb1 100644 --- a/extensions/CCArmature/CCArmature.h +++ b/extensions/CCArmature/CCArmature.h @@ -30,6 +30,9 @@ THE SOFTWARE. #include "display/CCBatchNode.h" #include "animation/CCArmatureAnimation.h" +class b2Body; +struct cpBody; + NS_CC_EXT_BEGIN class CCArmature : public CCNodeRGBA, public CCBlendProtocol @@ -154,6 +157,12 @@ protected: CCPoint m_pOffsetPoint; CCArmatureAnimation *m_pAnimation; + +#if ENABLE_PHYSICS_BOX2D_DETECT + CC_PROPERTY(b2Body*, m_pB2Body, B2Body); +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + CC_PROPERTY(cpBody*, m_pCPBody, CPBody); +#endif }; NS_CC_EXT_END diff --git a/extensions/CCArmature/CCBone.cpp b/extensions/CCArmature/CCBone.cpp index aa2e11a1c6..e93c761eac 100644 --- a/extensions/CCArmature/CCBone.cpp +++ b/extensions/CCArmature/CCBone.cpp @@ -320,6 +320,16 @@ CCAffineTransform CCBone::nodeToArmatureTransform() return m_tWorldTransform; } +CCAffineTransform CCBone::nodeToWorldTransform() +{ + return CCAffineTransformConcat(m_tWorldTransform, m_pArmature->nodeToWorldTransform()); +} + +CCNode *CCBone::getDisplayRenderNode() +{ + return m_pDisplayManager->getDisplayRenderNode(); +} + void CCBone::addDisplay(CCDisplayData *displayData, int index) { m_pDisplayManager->addDisplay(displayData, index); diff --git a/extensions/CCArmature/CCBone.h b/extensions/CCArmature/CCBone.h index 719726ae05..8cf83a2ace 100644 --- a/extensions/CCArmature/CCBone.h +++ b/extensions/CCArmature/CCBone.h @@ -137,7 +137,9 @@ public: virtual bool isTransformDirty(); virtual CCAffineTransform nodeToArmatureTransform(); + virtual CCAffineTransform nodeToWorldTransform(); + CCNode *getDisplayRenderNode(); public: /* * The origin state of the CCBone. Display's state is effected by m_pBoneData, m_pNode, m_pTweenData diff --git a/extensions/CCArmature/animation/CCTween.cpp b/extensions/CCArmature/animation/CCTween.cpp index a43ff4ad24..4fc59f8961 100644 --- a/extensions/CCArmature/animation/CCTween.cpp +++ b/extensions/CCArmature/animation/CCTween.cpp @@ -217,8 +217,6 @@ void CCTween::updateHandler() // m_fCurrentFrame = (1 - m_pMovementBoneData->delay) * (float)m_iNextFrameIndex; m_fCurrentPercent = m_fCurrentFrame / m_iNextFrameIndex; - - } else { @@ -322,10 +320,7 @@ void CCTween::arriveKeyFrame(CCFrameData *keyFrameData) } } - if(keyFrameData->m_strEvent.length() != 0) - { - m_pAnimation->FrameEventSignal.emit(m_pBone, keyFrameData->m_strEvent.c_str()); - } + // if(keyFrameData->m_strSound.length() != 0) // { // //soundManager.dispatchEventWith(Event.SOUND_FRAME, m_pCurrentKeyFrame->sound); diff --git a/extensions/CCArmature/display/CCDecorativeDisplay.cpp b/extensions/CCArmature/display/CCDecorativeDisplay.cpp index 6e9bfa3acf..6783e84265 100644 --- a/extensions/CCArmature/display/CCDecorativeDisplay.cpp +++ b/extensions/CCArmature/display/CCDecorativeDisplay.cpp @@ -44,7 +44,7 @@ CCDecorativeDisplay::CCDecorativeDisplay() , m_pDisplayData(NULL) { -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT m_pColliderDetector = NULL; #endif } @@ -55,7 +55,7 @@ CCDecorativeDisplay::~CCDecorativeDisplay(void) CC_SAFE_RELEASE_NULL(m_pDisplayData); CC_SAFE_RELEASE_NULL(m_pDisplay); -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT CC_SAFE_RELEASE_NULL(m_pColliderDetector); #endif } diff --git a/extensions/CCArmature/display/CCDecorativeDisplay.h b/extensions/CCArmature/display/CCDecorativeDisplay.h index c8ee8aecb6..19b558f141 100644 --- a/extensions/CCArmature/display/CCDecorativeDisplay.h +++ b/extensions/CCArmature/display/CCDecorativeDisplay.h @@ -31,7 +31,7 @@ THE SOFTWARE. #include "../external_tool/sigslot.h" -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT #include "../physics/CCColliderDetector.h" #endif @@ -52,7 +52,7 @@ protected: CC_SYNTHESIZE_RETAIN(CCNode *, m_pDisplay, Display); CC_SYNTHESIZE_RETAIN(CCDisplayData *, m_pDisplayData, DisplayData); -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT CC_SYNTHESIZE_RETAIN(CCColliderDetector *, m_pColliderDetector, ColliderDetector); #endif public: diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp index a8ce6d6336..d92935e74c 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ b/extensions/CCArmature/display/CCDisplayFactory.cpp @@ -72,7 +72,7 @@ void CCDisplayFactory::updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisp { CS_RETURN_IF(!decoDisplay); -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT if (dirty) { CCColliderDetector *detector = decoDisplay->getColliderDetector(); @@ -167,7 +167,7 @@ void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *de decoDisplay->setDisplay(skin); -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT if (textureData && textureData->contourDataList.count() > 0) { diff --git a/extensions/CCArmature/display/CCDisplayManager.cpp b/extensions/CCArmature/display/CCDisplayManager.cpp index 09d37f8ae4..d39d8e7b68 100644 --- a/extensions/CCArmature/display/CCDisplayManager.cpp +++ b/extensions/CCArmature/display/CCDisplayManager.cpp @@ -145,6 +145,11 @@ void CCDisplayManager::removeDisplay(int index) } } +CCArray *CCDisplayManager::getDecorativeDisplayList() +{ + return m_pDecoDisplayList; +} + void CCDisplayManager::changeDisplayByIndex(int index, bool force) { CCAssert( (m_pDecoDisplayList ? index < (int)m_pDecoDisplayList->count() : true), "the _index value is out of range"); @@ -177,7 +182,7 @@ void CCDisplayManager::changeDisplayByIndex(int index, bool force) void CCDisplayManager::setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisplay) { -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT if (m_pCurrentDecoDisplay && m_pCurrentDecoDisplay->getColliderDetector()) { m_pCurrentDecoDisplay->getColliderDetector()->setActive(false); @@ -186,7 +191,7 @@ void CCDisplayManager::setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisp m_pCurrentDecoDisplay = decoDisplay; -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT if (m_pCurrentDecoDisplay && m_pCurrentDecoDisplay->getColliderDetector()) { m_pCurrentDecoDisplay->getColliderDetector()->setActive(true); diff --git a/extensions/CCArmature/display/CCSkin.cpp b/extensions/CCArmature/display/CCSkin.cpp index 967cbab6ae..cba1d8bc92 100644 --- a/extensions/CCArmature/display/CCSkin.cpp +++ b/extensions/CCArmature/display/CCSkin.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. #include "CCSkin.h" #include "../utils/CCTransformHelp.h" +#include "../CCArmature.h" NS_CC_EXT_BEGIN @@ -149,4 +150,9 @@ void CCSkin::updateTransform() } } +CCAffineTransform CCSkin::nodeToWorldTransform() +{ + return CCAffineTransformConcat(m_sTransform, m_pBone->getArmature()->nodeToWorldTransform()); +} + NS_CC_EXT_END diff --git a/extensions/CCArmature/display/CCSkin.h b/extensions/CCArmature/display/CCSkin.h index 7dcbd112b2..801201ebff 100644 --- a/extensions/CCArmature/display/CCSkin.h +++ b/extensions/CCArmature/display/CCSkin.h @@ -42,6 +42,8 @@ public: void updateArmatureTransform(); void updateTransform(); + CCAffineTransform nodeToWorldTransform(); + CC_PROPERTY_PASS_BY_REF(CCBaseData, m_sSkinData, SkinData); CC_SYNTHESIZE(CCBone *, m_pBone, Bone); diff --git a/extensions/CCArmature/external_tool/GLES-Render.cpp b/extensions/CCArmature/external_tool/GLES-Render.cpp deleted file mode 100644 index 9d9989b7ba..0000000000 --- a/extensions/CCArmature/external_tool/GLES-Render.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#include "GLES-Render.h" -#include "cocos2d.h" -#include -#include -#include - -NS_CC_EXT_BEGIN - -USING_NS_CC; - -GLESDebugDraw::GLESDebugDraw() - : mRatio( 1.0f ) -{ - this->initShader(); -} - -GLESDebugDraw::GLESDebugDraw( float32 ratio ) - : mRatio( ratio ) -{ - this->initShader(); -} - -void GLESDebugDraw::initShader( void ) -{ - mShaderProgram = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_Position_uColor); - - mColorLocation = glGetUniformLocation( mShaderProgram->getProgram(), "u_color"); -} - -void GLESDebugDraw::DrawPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - b2Vec2* vertices = new b2Vec2[vertexCount]; - for( int i=0;isetUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - - glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices); - glDrawArrays(GL_LINE_LOOP, 0, vertexCount); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); - - delete[] vertices; -} - -void GLESDebugDraw::DrawSolidPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - b2Vec2* vertices = new b2Vec2[vertexCount]; - for( int i=0;isetUniformLocationWith4f(mColorLocation, color.r*0.5f, color.g*0.5f, color.b*0.5f, 0.5f); - - glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices); - - glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount); - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - glDrawArrays(GL_LINE_LOOP, 0, vertexCount); - - CC_INCREMENT_GL_DRAWS(2); - - CHECK_GL_ERROR_DEBUG(); - - delete[] vertices; -} - -void GLESDebugDraw::DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - const float32 k_segments = 16.0f; - int vertexCount=16; - const float32 k_increment = 2.0f * b2_pi / k_segments; - float32 theta = 0.0f; - - GLfloat* glVertices = new GLfloat[vertexCount*2]; - for (int i = 0; i < k_segments; ++i) - { - b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta)); - glVertices[i*2]=v.x * mRatio; - glVertices[i*2+1]=v.y * mRatio; - theta += k_increment; - } - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - - glDrawArrays(GL_LINE_LOOP, 0, vertexCount); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); - - delete[] glVertices; -} - -void GLESDebugDraw::DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - const float32 k_segments = 16.0f; - int vertexCount=16; - const float32 k_increment = 2.0f * b2_pi / k_segments; - float32 theta = 0.0f; - - GLfloat* glVertices = new GLfloat[vertexCount*2]; - for (int i = 0; i < k_segments; ++i) - { - b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta)); - glVertices[i*2]=v.x * mRatio; - glVertices[i*2+1]=v.y * mRatio; - theta += k_increment; - } - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r*0.5f, color.g*0.5f, color.b*0.5f, 0.5f); - glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount); - - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - glDrawArrays(GL_LINE_LOOP, 0, vertexCount); - - // Draw the axis line - DrawSegment(center,center+radius*axis,color); - - CC_INCREMENT_GL_DRAWS(2); - - CHECK_GL_ERROR_DEBUG(); - - delete[] glVertices; -} - -void GLESDebugDraw::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - - GLfloat glVertices[] = - { - p1.x * mRatio, p1.y * mRatio, - p2.x * mRatio, p2.y * mRatio - }; - glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - - glDrawArrays(GL_LINES, 0, 2); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); -} - -void GLESDebugDraw::DrawTransform(const b2Transform& xf) -{ - b2Vec2 p1 = xf.p, p2; - const float32 k_axisScale = 0.4f; - p2 = p1 + k_axisScale * xf.q.GetXAxis(); - DrawSegment(p1, p2, b2Color(1,0,0)); - - p2 = p1 + k_axisScale * xf.q.GetYAxis(); - DrawSegment(p1,p2,b2Color(0,1,0)); -} - -void GLESDebugDraw::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - - // glPointSize(size); - - GLfloat glVertices[] = { - p.x * mRatio, p.y * mRatio - }; - - glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - - glDrawArrays(GL_POINTS, 0, 1); - // glPointSize(1.0f); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); -} - -void GLESDebugDraw::DrawString(int x, int y, const char *string, ...) -{ -// NSLog(@"DrawString: unsupported: %s", string); - //printf(string); - /* Unsupported as yet. Could replace with bitmap font renderer at a later date */ -} - -void GLESDebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - - GLfloat glVertices[] = { - aabb->lowerBound.x * mRatio, aabb->lowerBound.y * mRatio, - aabb->upperBound.x * mRatio, aabb->lowerBound.y * mRatio, - aabb->upperBound.x * mRatio, aabb->upperBound.y * mRatio, - aabb->lowerBound.x * mRatio, aabb->upperBound.y * mRatio - }; - - glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - glDrawArrays(GL_LINE_LOOP, 0, 8); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); - -} - -NS_CC_EXT_END \ No newline at end of file diff --git a/extensions/CCArmature/external_tool/GLES-Render.h b/extensions/CCArmature/external_tool/GLES-Render.h deleted file mode 100644 index 5f65348b8c..0000000000 --- a/extensions/CCArmature/external_tool/GLES-Render.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com -* -* iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef RENDER_H -#define RENDER_H - -#include "Box2D/Box2D.h" -#include "cocos2d.h" -#include "ExtensionMacros.h" - -struct b2AABB; - -NS_CC_EXT_BEGIN - -// This class implements debug drawing callbacks that are invoked -// inside b2World::Step. -class GLESDebugDraw : public b2Draw -{ - float32 mRatio; - cocos2d::CCGLProgram* mShaderProgram; - GLint mColorLocation; - - void initShader( void ); -public: - GLESDebugDraw(); - - GLESDebugDraw( float32 ratio ); - - virtual void DrawPolygon(const b2Vec2* vertices, int vertexCount, const b2Color& color); - - virtual void DrawSolidPolygon(const b2Vec2* vertices, int vertexCount, const b2Color& color); - - virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color); - - virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color); - - virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color); - - virtual void DrawTransform(const b2Transform& xf); - - virtual void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color); - - virtual void DrawString(int x, int y, const char* string, ...); - - virtual void DrawAABB(b2AABB* aabb, const b2Color& color); -}; - -NS_CC_EXT_END - -#endif diff --git a/extensions/CCArmature/physics/CCColliderDetector.cpp b/extensions/CCArmature/physics/CCColliderDetector.cpp index b88ec65527..3b0c42d472 100644 --- a/extensions/CCArmature/physics/CCColliderDetector.cpp +++ b/extensions/CCArmature/physics/CCColliderDetector.cpp @@ -23,9 +23,15 @@ THE SOFTWARE. ****************************************************************************/ #include "CCColliderDetector.h" -#include "CCPhysicsWorld.h" #include "../CCBone.h" +#include "../utils/CCTransformHelp.h" + +#if ENABLE_PHYSICS_BOX2D_DETECT #include "Box2D/Box2D.h" +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +#include "chipmunk.h" +#endif + NS_CC_EXT_BEGIN @@ -56,20 +62,15 @@ CCColliderDetector *CCColliderDetector::create(CCBone *bone) CCColliderDetector::CCColliderDetector() : m_pColliderBodyList(NULL) { +#if ENABLE_PHYSICS_BOX2D_DETECT + m_pB2Body = NULL; +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + m_pCPBody = NULL; +#endif } CCColliderDetector::~CCColliderDetector() { - CCObject *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) - { - ColliderBody *colliderBody = (ColliderBody *)object; - - b2Body *body = colliderBody->getB2Body(); - CCPhysicsWorld::sharedPhysicsWorld()->getNoGravityWorld()->DestroyBody(body); - } - - m_pColliderBodyList->removeAllObjects(); CC_SAFE_DELETE(m_pColliderBodyList); } @@ -93,38 +94,7 @@ bool CCColliderDetector::init(CCBone *bone) void CCColliderDetector::addContourData(CCContourData *contourData) { - const CCArray *array = &contourData->vertexList; - CCObject *object = NULL; - - b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.count()]; - - int i = 0; - CCARRAY_FOREACH(array, object) - { - CCContourVertex2 *v = (CCContourVertex2 *)object; - b2bv[i].Set(v->x / PT_RATIO, v->y / PT_RATIO); - i++; - } - - b2PolygonShape polygon; - polygon.Set(b2bv, contourData->vertexList.count()); - - CC_SAFE_DELETE(b2bv); - - b2FixtureDef fixtureDef; - fixtureDef.shape = &polygon; - fixtureDef.density = 10.0f; - fixtureDef.isSensor = true; - - b2BodyDef bodyDef; - bodyDef.type = b2_dynamicBody; - bodyDef.position = b2Vec2(0.0f, 0.0f); - bodyDef.userData = m_pBone; - - b2Body *body = CCPhysicsWorld::sharedPhysicsWorld()->getNoGravityWorld()->CreateBody(&bodyDef); - body->CreateFixture(&fixtureDef); - - ColliderBody *colliderBody = new ColliderBody(body, contourData); + ColliderBody *colliderBody = new ColliderBody(contourData); m_pColliderBodyList->addObject(colliderBody); colliderBody->release(); } @@ -148,26 +118,35 @@ void CCColliderDetector::removeAll() m_pColliderBodyList->removeAllObjects(); } -void CCColliderDetector::setColliderFilter(b2Filter &filter) -{ - CCObject *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) - { - ColliderBody *colliderBody = (ColliderBody *)object; - colliderBody->getB2Body()->GetFixtureList()->SetFilterData(filter); - } -} void CCColliderDetector::setActive(bool active) { - CCObject *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) - { - ColliderBody *colliderBody = (ColliderBody *)object; - colliderBody->getB2Body()->SetActive(active); - } +#if ENABLE_PHYSICS_BOX2D_DETECT + if (m_pB2Body) + { + m_pB2Body->SetActive(active); + } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + if (m_pCPBody) + { + if (active) + { + cpBodyActivate(m_pCPBody); + } + else + { + cpBodySleep(m_pCPBody); + } + } +#endif } +CCArray *CCColliderDetector::getColliderBodyList() +{ + return m_pColliderBodyList; +} + + CCPoint helpPoint; void CCColliderDetector::updateTransform(CCAffineTransform &t) @@ -176,31 +155,144 @@ void CCColliderDetector::updateTransform(CCAffineTransform &t) CCARRAY_FOREACH(m_pColliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; - CCContourData *contourData = colliderBody->getContourData(); - b2Body *body = colliderBody->getB2Body(); - b2PolygonShape *shape = (b2PolygonShape *)body->GetFixtureList()->GetShape(); +#if ENABLE_PHYSICS_BOX2D_DETECT + b2PolygonShape *shape = NULL; + if (m_pB2Body != NULL) + { + shape = (b2PolygonShape *)colliderBody->getB2Fixture()->GetShape(); + } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + cpPolyShape *shape = NULL; + if (m_pCPBody != NULL) + { + shape = (cpPolyShape *)colliderBody->getShape(); + } +#endif - //! update every vertex - const CCArray *array = &contourData->vertexList; - CCObject *object = NULL; - int i = 0; - CCARRAY_FOREACH(array, object) - { - CCContourVertex2 *cv = (CCContourVertex2 *)object; - b2Vec2 &bv = shape->m_vertices[i]; + //! update every vertex + const CCArray *array = &contourData->vertexList; + CCObject *object = NULL; + int i = 0; + CCARRAY_FOREACH(array, object) + { + CCContourVertex2 *cv = (CCContourVertex2 *)object; - helpPoint.setPoint(cv->x, cv->y); - helpPoint = CCPointApplyAffineTransform(helpPoint, t); + helpPoint.setPoint(cv->x, cv->y); + helpPoint = CCPointApplyAffineTransform(helpPoint, t); - bv.Set(helpPoint.x / PT_RATIO, helpPoint.y / PT_RATIO); +#if ENABLE_PHYSICS_BOX2D_DETECT + if (shape != NULL) + { + b2Vec2 &bv = shape->m_vertices[i]; + bv.Set(helpPoint.x / PT_RATIO, helpPoint.y / PT_RATIO); + } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + if (shape != NULL) + { + cpVect v ; + v.x = helpPoint.x; + v.y = helpPoint.y; + shape->tVerts[i] = shape->verts[i] = v; - i++; - } + cpVect b = shape->verts[(i+1)%shape->numVerts]; + cpVect n = cpvnormalize(cpvperp(cpvsub(b, shape->verts[i]))); + + shape->planes[i].n = n; + shape->planes[i].d = cpvdot(n, shape->verts[i]); + } +#endif + i++; + } } } +#if ENABLE_PHYSICS_BOX2D_DETECT + +void CCColliderDetector::setB2Body(b2Body *pBody) +{ + m_pB2Body = pBody; + m_pB2Body->SetUserData(m_pBone); + + CCObject *object = NULL; + CCARRAY_FOREACH(m_pColliderBodyList, object) + { + ColliderBody *colliderBody = (ColliderBody *)object; + + CCContourData *contourData = colliderBody->getContourData(); + const CCArray *array = &contourData->vertexList; + CCObject *object = NULL; + + b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.count()]; + + int i = 0; + CCARRAY_FOREACH(array, object) + { + CCContourVertex2 *v = (CCContourVertex2 *)object; + b2bv[i].Set(v->x / PT_RATIO, v->y / PT_RATIO); + i++; + } + + b2PolygonShape polygon; + polygon.Set(b2bv, contourData->vertexList.count()); + + CC_SAFE_DELETE(b2bv); + + b2FixtureDef fixtureDef; + fixtureDef.shape = &polygon; + fixtureDef.isSensor = true; + + b2Fixture *fixture = m_pB2Body->CreateFixture(&fixtureDef); + colliderBody->setB2Fixture(fixture); + } +} + +b2Body *CCColliderDetector::getB2Body() +{ + return m_pB2Body; +} + +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +void CCColliderDetector::setCPBody(cpBody *pBody) +{ + m_pCPBody = pBody; + + CCObject *object = NULL; + CCARRAY_FOREACH(m_pColliderBodyList, object) + { + ColliderBody *colliderBody = (ColliderBody *)object; + + CCContourData *contourData = colliderBody->getContourData(); + const CCArray *array = &contourData->vertexList; + CCObject *object = NULL; + + int num = contourData->vertexList.count(); + CCContourVertex2 **vs = (CCContourVertex2 **)contourData->vertexList.data->arr; + cpVect *verts = new cpVect[num]; + for (int i=0; ix; + verts[num-1-i].y = vs[i]->y; + } + + cpShape* shape = cpPolyShapeNew(m_pCPBody, num, verts, cpvzero); + shape->sensor = true; + shape->data = m_pBone; + cpSpaceAddShape(m_pCPBody->space_private, shape); + + colliderBody->setShape(shape); + + delete []verts; + } +} + +cpBody *CCColliderDetector::getCPBody() +{ + return m_pCPBody; +} + +#endif NS_CC_EXT_END diff --git a/extensions/CCArmature/physics/CCColliderDetector.h b/extensions/CCArmature/physics/CCColliderDetector.h index eaff42ece5..3b66511c92 100644 --- a/extensions/CCArmature/physics/CCColliderDetector.h +++ b/extensions/CCArmature/physics/CCColliderDetector.h @@ -28,8 +28,16 @@ THE SOFTWARE. #include "../utils/CCArmatureDefine.h" #include "../datas/CCDatas.h" +#ifndef PT_RATIO +#define PT_RATIO 32 +#endif + + class b2Body; -struct b2Filter; +class b2Fixture; + +struct cpBody; +struct cpShape; NS_CC_EXT_BEGIN @@ -38,24 +46,36 @@ class CCBone; class ColliderBody : public CCObject { public: - ColliderBody(b2Body *b2b, CCContourData *contourData) - :m_pB2b(NULL) - ,m_pContourData(NULL) +#if ENABLE_PHYSICS_BOX2D_DETECT + ColliderBody(CCContourData *contourData) + : m_pFixture(NULL) + , m_pContourData(contourData) { - this->m_pB2b = b2b; - this->m_pContourData = contourData; CC_SAFE_RETAIN(m_pContourData); } +private: + CC_SYNTHESIZE(b2Fixture*, m_pFixture, B2Fixture) +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + + ColliderBody(CCContourData *contourData) + : m_pShape(NULL) + , m_pContourData(contourData) + { + CC_SAFE_RETAIN(m_pContourData); + } +private: + CC_SYNTHESIZE(cpShape*, m_pShape, Shape) + +#endif + + +public: ~ColliderBody() { CC_SAFE_RELEASE(m_pContourData); } - inline b2Body *getB2Body() - { - return m_pB2b; - } inline CCContourData *getContourData() { @@ -63,7 +83,6 @@ public: } private: - b2Body *m_pB2b; CCContourData *m_pContourData; }; @@ -90,14 +109,19 @@ public: void updateTransform(CCAffineTransform &t); - void setColliderFilter(b2Filter &filter); + void setActive(bool active); - void setActive(bool active); -private: - CCArray *m_pColliderBodyList; - + CCArray *getColliderBodyList(); + +protected: + CCArray *m_pColliderBodyList; CC_SYNTHESIZE(CCBone*, m_pBone, Bone); +#if ENABLE_PHYSICS_BOX2D_DETECT + CC_PROPERTY(b2Body*, m_pB2Body, B2Body); +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + CC_PROPERTY(cpBody*, m_pCPBody, CPBody); +#endif }; NS_CC_EXT_END diff --git a/extensions/CCArmature/physics/CCPhysicsWorld.cpp b/extensions/CCArmature/physics/CCPhysicsWorld.cpp deleted file mode 100644 index 8472f7130d..0000000000 --- a/extensions/CCArmature/physics/CCPhysicsWorld.cpp +++ /dev/null @@ -1,165 +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 "CCPhysicsWorld.h" -#include "../utils/CCArmatureDefine.h" -#include "Box2D/Box2D.h" -#include "../external_tool/GLES-Render.h" - -NS_CC_EXT_BEGIN - - -class Contact -{ -public: - b2Fixture *fixtureA; - b2Fixture *fixtureB; -}; - -class ContactListener : public b2ContactListener -{ - //! Callbacks for derived classes. - virtual void BeginContact(b2Contact *contact) - { - if (contact) - { - Contact c; - c.fixtureA = contact->GetFixtureA(); - c.fixtureB = contact->GetFixtureB(); - - contact_list.push_back(c); - } - B2_NOT_USED(contact); - } - virtual void EndContact(b2Contact *contact) - { - contact_list.clear(); - B2_NOT_USED(contact); - } - virtual void PreSolve(b2Contact *contact, const b2Manifold *oldManifold) - { - B2_NOT_USED(contact); - B2_NOT_USED(oldManifold); - } - virtual void PostSolve(const b2Contact *contact, const b2ContactImpulse *impulse) - { - B2_NOT_USED(contact); - B2_NOT_USED(impulse); - } - -public: - std::list contact_list; -}; - - - -CCPhysicsWorld *CCPhysicsWorld::s_PhysicsWorld = NULL; - - -CCPhysicsWorld *CCPhysicsWorld::sharedPhysicsWorld() -{ - if (s_PhysicsWorld == NULL) - { - s_PhysicsWorld = new CCPhysicsWorld(); - s_PhysicsWorld->initNoGravityWorld(); - } - - return s_PhysicsWorld; -} - -void CCPhysicsWorld::purgePhysicsWorld() -{ - delete s_PhysicsWorld; - s_PhysicsWorld = NULL; -} - -CCPhysicsWorld::CCPhysicsWorld() - : m_pNoGravityWorld(NULL) - , m_pDebugDraw(NULL) -{ -} - -CCPhysicsWorld::~CCPhysicsWorld() -{ - CC_SAFE_DELETE(m_pDebugDraw); - CC_SAFE_DELETE(m_pNoGravityWorld); - CC_SAFE_DELETE(m_pContactListener); -} - -void CCPhysicsWorld::initNoGravityWorld() -{ - b2Vec2 noGravity(0, 0); - - m_pNoGravityWorld = new b2World(noGravity); - m_pNoGravityWorld->SetAllowSleeping(true); - - m_pContactListener = new ContactListener(); - m_pNoGravityWorld->SetContactListener(m_pContactListener); - - -#if ENABLE_PHYSICS_DEBUG - m_pDebugDraw = new GLESDebugDraw( PT_RATIO ); - m_pNoGravityWorld->SetDebugDraw(m_pDebugDraw); - - uint32 flags = 0; - flags += b2Draw::e_shapeBit; - // flags += b2Draw::e_jointBit; - // flags += b2Draw::e_aabbBit; - // flags += b2Draw::e_pairBit; - // flags += b2Draw::e_centerOfMassBit; - m_pDebugDraw->SetFlags(flags); -#endif -} - -b2World *CCPhysicsWorld::getNoGravityWorld() -{ - return m_pNoGravityWorld; -} - -void CCPhysicsWorld::update(float dt) -{ - m_pNoGravityWorld->Step(dt, 0, 0); - - for (std::list::iterator it = m_pContactListener->contact_list.begin(); it != m_pContactListener->contact_list.end(); ++it) - { - Contact &contact = *it; - - b2Body *b2a = contact.fixtureA->GetBody(); - b2Body *b2b = contact.fixtureB->GetBody(); - - CCBone *ba = (CCBone *)b2a->GetUserData(); - CCBone *bb = (CCBone *)b2b->GetUserData(); - - BoneColliderSignal.emit(ba, bb); - } - -} - -void CCPhysicsWorld::drawDebug() -{ - m_pNoGravityWorld->DrawDebugData(); -} - -NS_CC_EXT_END diff --git a/extensions/CCArmature/physics/CCPhysicsWorld.h b/extensions/CCArmature/physics/CCPhysicsWorld.h deleted file mode 100644 index 60d94b7e04..0000000000 --- a/extensions/CCArmature/physics/CCPhysicsWorld.h +++ /dev/null @@ -1,80 +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 __CCPHYSICSWORLD_H__ -#define __CCPHYSICSWORLD_H__ - -#include "../utils/CCArmatureDefine.h" -#include "../CCBone.h" -#include "../external_tool/sigslot.h" - -#include -using std::list; - -#ifndef PT_RATIO -#define PT_RATIO 32 -#endif - -struct b2Manifold; -struct b2ContactImpulse; -class b2Fixture; -class b2Contact; -class b2World; - -NS_CC_EXT_BEGIN - -class ContactListener; -class GLESDebugDraw; - -class CCPhysicsWorld -{ -public: - static CCPhysicsWorld *sharedPhysicsWorld(); - static void purgePhysicsWorld(); - - void initNoGravityWorld(); -private: - CCPhysicsWorld(); - ~CCPhysicsWorld(); - -private: - static CCPhysicsWorld *s_PhysicsWorld; - - b2World *m_pNoGravityWorld; - - ContactListener *m_pContactListener; - - GLESDebugDraw *m_pDebugDraw; -public: - void update(float dt); - void drawDebug(); - - b2World *getNoGravityWorld(); - - sigslot::signal2 BoneColliderSignal; -}; - -NS_CC_EXT_END - -#endif/*__CCPHYSICSWORLD_H__*/ diff --git a/extensions/CCArmature/utils/CCArmatureDataManager.cpp b/extensions/CCArmature/utils/CCArmatureDataManager.cpp index cc12ad27d9..9d1bc62e5f 100644 --- a/extensions/CCArmature/utils/CCArmatureDataManager.cpp +++ b/extensions/CCArmature/utils/CCArmatureDataManager.cpp @@ -27,7 +27,6 @@ THE SOFTWARE. #include "CCTransformHelp.h" #include "CCDataReaderHelper.h" #include "CCSpriteFrameCacheHelper.h" -#include "../physics/CCPhysicsWorld.h" NS_CC_EXT_BEGIN @@ -67,8 +66,6 @@ CCArmatureDataManager::~CCArmatureDataManager(void) void CCArmatureDataManager::purgeArmatureSystem() { CCSpriteFrameCacheHelper::purgeSpriteFrameCacheHelper(); - CCPhysicsWorld::purgePhysicsWorld(); - CC_SAFE_RELEASE_NULL(s_sharedArmatureDataManager); } diff --git a/extensions/CCArmature/utils/CCArmatureDefine.h b/extensions/CCArmature/utils/CCArmatureDefine.h index 1e1eac7aff..79812fc43a 100644 --- a/extensions/CCArmature/utils/CCArmatureDefine.h +++ b/extensions/CCArmature/utils/CCArmatureDefine.h @@ -31,15 +31,14 @@ THE SOFTWARE. #include "ExtensionMacros.h" -#ifndef ENABLE_PHYSICS_DEBUG -#define ENABLE_PHYSICS_DEBUG 1 +#ifndef ENABLE_PHYSICS_BOX2D_DETECT +#define ENABLE_PHYSICS_BOX2D_DETECT 0 #endif -#ifndef ENABLE_PHYSICS_DETECT -#define ENABLE_PHYSICS_DETECT 1 +#ifndef ENABLE_PHYSICS_CHIPMUNK_DETECT +#define ENABLE_PHYSICS_CHIPMUNK_DETECT 1 #endif - #define MAX_VERTEXZ_VALUE 5000000.0f #define ARMATURE_MAX_CHILD 50.0f #define ARMATURE_MAX_ZORDER 100 diff --git a/extensions/cocos-ext.h b/extensions/cocos-ext.h index 8d6171d9c9..c8c2991fd8 100644 --- a/extensions/cocos-ext.h +++ b/extensions/cocos-ext.h @@ -50,7 +50,6 @@ #include "CCArmature/display/CCDisplayManager.h" #include "CCArmature/display/CCSkin.h" #include "CCArmature/physics/CCColliderDetector.h" -#include "CCArmature/physics/CCPhysicsWorld.h" #include "CCArmature/utils/CCArmatureDataManager.h" #include "CCArmature/utils/CCConstValue.h" #include "CCArmature/utils/CCDataReaderHelper.h" diff --git a/extensions/proj.win32/libExtensions.vcxproj b/extensions/proj.win32/libExtensions.vcxproj index 03d8f2d893..d92b44486a 100644 --- a/extensions/proj.win32/libExtensions.vcxproj +++ b/extensions/proj.win32/libExtensions.vcxproj @@ -104,13 +104,11 @@ - - @@ -205,7 +203,6 @@ - @@ -219,7 +216,6 @@ - diff --git a/extensions/proj.win32/libExtensions.vcxproj.filters b/extensions/proj.win32/libExtensions.vcxproj.filters index 52b9d2b51e..43f706349c 100644 --- a/extensions/proj.win32/libExtensions.vcxproj.filters +++ b/extensions/proj.win32/libExtensions.vcxproj.filters @@ -255,18 +255,12 @@ CCArmature\physics - - CCArmature\physics - CCArmature CCArmature - - CCArmature\external_tool - CCArmature\external_tool\Json @@ -589,18 +583,12 @@ CCArmature\physics - - CCArmature\physics - CCArmature CCArmature - - CCArmature\external_tool - CCArmature\external_tool\Json diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp index e32d4a6792..ad97c8da9b 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp @@ -1,5 +1,7 @@ #include "ArmatureScene.h" #include "../../testResource.h" +#include "D:/Program Files/Visual Leak Detector\include/vld.h" + using namespace cocos2d; using namespace cocos2d::extension; @@ -32,8 +34,8 @@ CCLayer *CreateLayer(int index) pLayer = new TestParticleDisplay(); break; case TEST_USE_DIFFERENT_PICTURE: pLayer = new TestUseMutiplePicture(); break; - case TEST_BOX2D_DETECTOR: - pLayer = new TestBox2DDetector(); break; + case TEST_BCOLLIDER_DETECTOR: + pLayer = new TestColliderDetector(); break; case TEST_BOUDINGBOX: pLayer = new TestBoundingBox(); break; case TEST_ANCHORPOINT: @@ -98,13 +100,13 @@ ArmatureTestScene::ArmatureTestScene(bool bPortrait) void ArmatureTestScene::runThisTest() { CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/TestBone0.png", "armature/TestBone0.plist", "armature/TestBone.json"); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy0.png", "armature/Cowboy0.plist", "armature/Cowboy.json"); + CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy0.png", "armature/Cowboy0.plist", "armature/Cowboy.ExportJson"); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml"); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml"); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml"); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml"); - + s_nActionIdx = -1; addChild(NextTest()); @@ -513,15 +515,121 @@ void TestUseMutiplePicture::registerWithTouchDispatcher() -void TestBox2DDetector::onEnter() + + + +#if ENABLE_PHYSICS_BOX2D_DETECT + +class Contact +{ +public: + b2Fixture *fixtureA; + b2Fixture *fixtureB; +}; + +class ContactListener : public b2ContactListener +{ + //! Callbacks for derived classes. + virtual void BeginContact(b2Contact *contact) + { + if (contact) + { + Contact c; + c.fixtureA = contact->GetFixtureA(); + c.fixtureB = contact->GetFixtureB(); + + contact_list.push_back(c); + } + B2_NOT_USED(contact); + } + virtual void EndContact(b2Contact *contact) + { + contact_list.clear(); + B2_NOT_USED(contact); + } + virtual void PreSolve(b2Contact *contact, const b2Manifold *oldManifold) + { + B2_NOT_USED(contact); + B2_NOT_USED(oldManifold); + } + virtual void PostSolve(const b2Contact *contact, const b2ContactImpulse *impulse) + { + B2_NOT_USED(contact); + B2_NOT_USED(impulse); + } + +public: + std::list contact_list; +}; + +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + +enum ColliderType +{ + eBulletTag, + eEnemyTag +}; + + +int TestColliderDetector::beginHit(cpArbiter *arb, cpSpace *space, void *unused) +{ + CP_ARBITER_GET_SHAPES(arb, a, b); + + CCBone *bone = (CCBone*)a->data; + bone->getArmature()->setVisible(false); + + return 0; +} + +void TestColliderDetector::endHit(cpArbiter *arb, cpSpace *space, void *unused) +{ + CP_ARBITER_GET_SHAPES(arb, a, b); + + CCBone *bone = (CCBone*)a->data; + bone->getArmature()->setVisible(true); +} + +void TestColliderDetector::destroyCPBody(cpBody *body) +{ + cpShape *shape = body->shapeList_private; + while(shape) + { + cpShape *temp = shape->next_private; + + cpSpaceRemoveShape(space, shape); + cpShapeFree(shape); + + shape = temp; + } + + cpSpaceRemoveBody(space, body); + cpBodyFree(body); +} +#endif + +TestColliderDetector::~TestColliderDetector() +{ +#if ENABLE_PHYSICS_BOX2D_DETECT + CC_SAFE_DELETE(world); + CC_SAFE_DELETE(listener); + CC_SAFE_DELETE(debugDraw); +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + destroyCPBody(armature2->getCPBody()); + destroyCPBody(bullet->getCPBody()); + + cpSpaceFree(space); +#endif +} + +void TestColliderDetector::onEnter() { ArmatureTestLayer::onEnter(); scheduleUpdate(); armature = cocos2d::extension::CCArmature::create("Cowboy"); - armature->getAnimation()->play("Fire"); - armature->getAnimation()->setAnimationScale(0.1f); + armature->getAnimation()->play("FireWithoutBullet"); + armature->getAnimation()->setAnimationScale(0.2f); armature->setScaleX(-0.2f); armature->setScaleY(0.2f); armature->setPosition(ccp(VisibleRect::left().x + 70, VisibleRect::left().y)); @@ -534,36 +642,152 @@ void TestBox2DDetector::onEnter() armature2->setPosition(ccp(VisibleRect::right().x - 30, VisibleRect::left().y)); addChild(armature2); - CCPhysicsWorld::sharedPhysicsWorld()->BoneColliderSignal.connect(this, &TestBox2DDetector::onHit); + bullet = CCPhysicsSprite::createWithSpriteFrameName("25.png"); + addChild(bullet); + + initWorld(); } -std::string TestBox2DDetector::title() +std::string TestColliderDetector::title() { return "Test Box2D Detector"; } -void TestBox2DDetector::draw() +void TestColliderDetector::draw() { +#if ENABLE_PHYSICS_BOX2D_DETECT ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position ); - kmGLPushMatrix(); - - CCPhysicsWorld::sharedPhysicsWorld()->drawDebug(); - + world->DrawDebugData(); kmGLPopMatrix(); - +#endif } -void TestBox2DDetector::update(float delta) +void TestColliderDetector::update(float delta) { +#if ENABLE_PHYSICS_BOX2D_DETECT armature2->setVisible(true); - CCPhysicsWorld::sharedPhysicsWorld()->update(delta); +#endif + + if (armature->getAnimation()->getCurrentFrameIndex() == 9) + { + CCPoint p = armature->getBone("Layer126")->getDisplayRenderNode()->convertToWorldSpaceAR(ccp(0, 0)); + bullet->setPosition(ccp(p.x + 60, p.y)); + + bullet->stopAllActions(); + bullet->runAction(CCMoveBy::create(1.5f, ccp(350, 0))); + } + +#if ENABLE_PHYSICS_BOX2D_DETECT + world->Step(delta, 0, 0); + + for (std::list::iterator it = listener->contact_list.begin(); it != listener->contact_list.end(); ++it) + { + Contact &contact = *it; + + b2Body *b2a = contact.fixtureA->GetBody(); + b2Body *b2b = contact.fixtureB->GetBody(); + + CCBone *ba = (CCBone *)b2a->GetUserData(); + CCBone *bb = (CCBone *)b2b->GetUserData(); + + bb->getArmature()->setVisible(false); + } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + cpSpaceStep(space, delta); +#endif } -void TestBox2DDetector::onHit(cocos2d::extension::CCBone *bone, cocos2d::extension::CCBone *bone2) +void TestColliderDetector::initWorld() { - armature2->setVisible(false); +#if ENABLE_PHYSICS_BOX2D_DETECT + b2Vec2 noGravity(0, 0); + + world = new b2World(noGravity); + world->SetAllowSleeping(true); + + listener = new ContactListener(); + world->SetContactListener(listener); + + debugDraw = new GLESDebugDraw( PT_RATIO ); + world->SetDebugDraw(debugDraw); + + uint32 flags = 0; + flags += b2Draw::e_shapeBit; + // flags += b2Draw::e_jointBit; + // flags += b2Draw::e_aabbBit; + // flags += b2Draw::e_pairBit; + // flags += b2Draw::e_centerOfMassBit; + debugDraw->SetFlags(flags); + + + // Define the dynamic body. + //Set up a 1m squared box in the physics world + b2BodyDef bodyDef; + bodyDef.type = b2_dynamicBody; + + b2Body *body = world->CreateBody(&bodyDef); + + // Define another box shape for our dynamic body. + b2PolygonShape dynamicBox; + dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box + + // Define the dynamic body fixture. + b2FixtureDef fixtureDef; + fixtureDef.shape = &dynamicBox; + fixtureDef.isSensor = true; + body->CreateFixture(&fixtureDef); + + + bullet->setB2Body(body); + bullet->setPTMRatio(PT_RATIO); + bullet->setPosition( ccp( -100, -100) ); + + body = world->CreateBody(&bodyDef); + armature2->setB2Body(body); + +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + space = cpSpaceNew(); + space->gravity = cpv(0, 0); + + // Physics debug layer + CCPhysicsDebugNode *debugLayer = CCPhysicsDebugNode::create(space); + this->addChild(debugLayer, INT_MAX); + + CCSize size = bullet->getContentSize(); + + int num = 4; + cpVect verts[] = { + cpv(-size.width/2,-size.height/2), + cpv(-size.width/2,size.height/2), + cpv(size.width/2,size.height/2), + cpv(size.width/2,-size.height/2), + }; + + cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero)); + cpSpaceAddBody(space, body); + + cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero); + shape->collision_type = eBulletTag; + cpSpaceAddShape(space, shape); + + bullet->setCPBody(body); + + body = cpBodyNew(INFINITY, INFINITY); + cpSpaceAddBody(space, body); + armature2->setCPBody(body); + + shape = body->shapeList_private; + while(shape){ + cpShape *next = shape->next_private; + shape->collision_type = eEnemyTag; + shape = next; + } + + cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, NULL, NULL, endHit, NULL); +#endif } + void TestBoundingBox::onEnter() { ArmatureTestLayer::onEnter(); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.h index a998d1f990..67576a3746 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.h @@ -6,6 +6,13 @@ #include "../../VisibleRect.h" #include "../../testBasic.h" +#if ENABLE_PHYSICS_BOX2D_DETECT +#include "../../Box2DTestBed/GLES-Render.h" +#include "Box2D/Box2D.h" +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +#include "chipmunk.h" +#endif + class ArmatureTestScene : public TestScene { public: @@ -26,7 +33,7 @@ enum { TEST_ANIMATION_EVENT, TEST_PARTICLE_DISPLAY, TEST_USE_DIFFERENT_PICTURE, - TEST_BOX2D_DETECTOR, + TEST_BCOLLIDER_DETECTOR, TEST_BOUDINGBOX, TEST_ANCHORPOINT, TEST_ARMATURE_NESTING, @@ -141,20 +148,43 @@ class TestParticleDisplay : public ArmatureTestLayer cocos2d::extension::CCArmature *armature; }; -class TestBox2DDetector : public ArmatureTestLayer, public sigslot::has_slots<> +#if ENABLE_PHYSICS_BOX2D_DETECT +class ContactListener; +#endif + +class TestColliderDetector : public ArmatureTestLayer, public sigslot::has_slots<> { public: + ~TestColliderDetector(); + virtual void onEnter(); virtual std::string title(); virtual void draw(); virtual void update(float delta); - void onHit(cocos2d::extension::CCBone *bone, cocos2d::extension::CCBone *bone2); + void initWorld(); cocos2d::extension::CCArmature *armature; cocos2d::extension::CCArmature *armature2; + + cocos2d::extension::CCPhysicsSprite *bullet; + +#if ENABLE_PHYSICS_BOX2D_DETECT + b2World *world; + ContactListener *listener; + GLESDebugDraw *debugDraw; +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + cpSpace *space; + + static int beginHit(cpArbiter *arb, cpSpace *space, void *unused); + static void endHit(cpArbiter *arb, cpSpace *space, void *unused); + + void destroyCPBody(cpBody *body); +#endif }; + + class TestBoundingBox : public ArmatureTestLayer { public: diff --git a/samples/Cpp/TestCpp/Resources/armature/Cowboy0.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/armature/Cowboy0.png.REMOVED.git-id index 9bac07216b..d2c12af0e0 100644 --- a/samples/Cpp/TestCpp/Resources/armature/Cowboy0.png.REMOVED.git-id +++ b/samples/Cpp/TestCpp/Resources/armature/Cowboy0.png.REMOVED.git-id @@ -1 +1 @@ -db891b84393bfe4b806f46bbf9c2879fa9438608 \ No newline at end of file +2b61d3b005b4076c5ff22a78a00822c0f0dc0875 \ No newline at end of file From 680b7f1cb01c45b69cc90f074d1c779c7b226882 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Sat, 13 Jul 2013 22:59:21 +0800 Subject: [PATCH 10/28] Remove vld.h --- .../Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp index ad97c8da9b..62ceaa0f07 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp @@ -1,6 +1,5 @@ #include "ArmatureScene.h" #include "../../testResource.h" -#include "D:/Program Files/Visual Leak Detector\include/vld.h" using namespace cocos2d; 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 11/28] 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 From 74bd8b09d6ddfa114f92b3276ea002d5d6526c61 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 13 Sep 2013 18:07:37 +0800 Subject: [PATCH 12/28] update armature --- extensions/CocoStudio/Armature/CCArmature.cpp | 583 +++++--- extensions/CocoStudio/Armature/CCArmature.h | 206 ++- extensions/CocoStudio/Armature/CCBone.cpp | 293 ++-- extensions/CocoStudio/Armature/CCBone.h | 114 +- .../animation/CCArmatureAnimation.cpp | 307 ++-- .../Armature/animation/CCArmatureAnimation.h | 143 +- .../Armature/animation/CCProcessBase.cpp | 125 +- .../Armature/animation/CCProcessBase.h | 54 +- .../CocoStudio/Armature/animation/CCTween.cpp | 399 +++--- .../CocoStudio/Armature/animation/CCTween.h | 107 +- .../CocoStudio/Armature/datas/CCDatas.cpp | 362 +++-- .../CocoStudio/Armature/datas/CCDatas.h | 408 +++--- .../Armature/display/CCBatchNode.cpp | 36 +- .../CocoStudio/Armature/display/CCBatchNode.h | 12 +- .../Armature/display/CCDecorativeDisplay.cpp | 36 +- .../Armature/display/CCDecorativeDisplay.h | 25 +- .../Armature/display/CCDisplayFactory.cpp | 171 ++- .../Armature/display/CCDisplayFactory.h | 42 +- .../Armature/display/CCDisplayManager.cpp | 276 ++-- .../Armature/display/CCDisplayManager.h | 52 +- .../Armature/display/CCShaderNode.cpp | 136 -- .../Armature/display/CCShaderNode.h | 57 - .../CocoStudio/Armature/display/CCSkin.cpp | 110 +- .../CocoStudio/Armature/display/CCSkin.h | 28 +- .../external_tool/CCTexture2DMutable.cpp | 312 ----- .../external_tool/CCTexture2DMutable.h | 86 -- .../Armature/external_tool/GLES-Render.cpp | 254 ---- .../Armature/external_tool/GLES-Render.h | 67 - .../Armature/external_tool/sigslot.h | 604 ++++---- .../Armature/physics/CCColliderDetector.cpp | 386 +++-- .../Armature/physics/CCColliderDetector.h | 101 +- .../Armature/physics/CCPhysicsWorld.cpp | 165 --- .../Armature/physics/CCPhysicsWorld.h | 80 -- .../Armature/utils/CCArmatureDataManager.cpp | 212 +-- .../Armature/utils/CCArmatureDataManager.h | 181 ++- .../Armature/utils/CCArmatureDefine.h | 32 +- .../CocoStudio/Armature/utils/CCConstValue.h | 29 - .../Armature/utils/CCDataReaderHelper.cpp | 805 ++++++++--- .../Armature/utils/CCDataReaderHelper.h | 199 ++- .../utils/CCSpriteFrameCacheHelper.cpp | 143 +- .../Armature/utils/CCSpriteFrameCacheHelper.h | 30 +- .../Armature/utils/CCTransformHelp.cpp | 40 +- .../Armature/utils/CCTransformHelp.h | 23 +- .../Armature/utils/CCTweenFunction.cpp | 154 +- .../Armature/utils/CCTweenFunction.h | 66 +- .../CocoStudio/Armature/utils/CCUtilMath.cpp | 20 +- .../CocoStudio/Armature/utils/CCUtilMath.h | 4 +- .../CocoStudio/Reader/CCSSceneReader.cpp | 2 +- extensions/cocos-ext.h | 2 - extensions/proj.win32/libExtensions.vcxproj | 7 +- .../proj.win32/libExtensions.vcxproj.filters | 19 +- samples/Cpp/TestCpp/Classes/AppDelegate.cpp | 2 +- .../CocoStudioArmatureTest/ArmatureScene.cpp | 1106 ++++++++++----- .../CocoStudioArmatureTest/ArmatureScene.h | 128 +- .../CocoStudioSceneTest/SceneEditorTest.cpp | 4 +- .../CocoStudioSceneTest/SceneEditorTest.h | 2 +- .../armature/Cowboy.ExportJson.REMOVED.git-id | 1 + .../armature/Cowboy0.png.REMOVED.git-id | 2 +- .../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 +++++++++-------- 62 files changed, 5982 insertions(+), 5772 deletions(-) delete mode 100644 extensions/CocoStudio/Armature/display/CCShaderNode.cpp delete mode 100644 extensions/CocoStudio/Armature/display/CCShaderNode.h delete mode 100644 extensions/CocoStudio/Armature/external_tool/CCTexture2DMutable.cpp delete mode 100644 extensions/CocoStudio/Armature/external_tool/CCTexture2DMutable.h delete mode 100644 extensions/CocoStudio/Armature/external_tool/GLES-Render.cpp delete mode 100644 extensions/CocoStudio/Armature/external_tool/GLES-Render.h delete mode 100644 extensions/CocoStudio/Armature/physics/CCPhysicsWorld.cpp delete mode 100644 extensions/CocoStudio/Armature/physics/CCPhysicsWorld.h delete mode 100644 extensions/CocoStudio/Armature/utils/CCConstValue.h create mode 100644 samples/Cpp/TestCpp/Resources/armature/Cowboy.ExportJson.REMOVED.git-id diff --git a/extensions/CocoStudio/Armature/CCArmature.cpp b/extensions/CocoStudio/Armature/CCArmature.cpp index f90f6f9258..529de6f68f 100644 --- a/extensions/CocoStudio/Armature/CCArmature.cpp +++ b/extensions/CocoStudio/Armature/CCArmature.cpp @@ -29,13 +29,20 @@ THE SOFTWARE. #include "datas/CCDatas.h" #include "display/CCSkin.h" -namespace cocos2d { namespace extension { namespace armature { +#if ENABLE_PHYSICS_BOX2D_DETECT +#include "Box2D/Box2D.h" +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +#include "chipmunk.h" +#endif -std::map Armature::_armatureIndexDic; -Armature *Armature::create() +NS_CC_EXT_ARMATURE_BEGIN + +std::map CCArmature::m_sArmatureIndexDic; + +CCArmature *CCArmature::create() { - Armature *armature = new Armature(); + CCArmature *armature = new CCArmature(); if (armature && armature->init()) { armature->autorelease(); @@ -46,10 +53,10 @@ Armature *Armature::create() } -Armature *Armature::create(const char *_name) +CCArmature *CCArmature::create(const char *name) { - Armature *armature = new Armature(); - if (armature && armature->init(_name)) + CCArmature *armature = new CCArmature(); + if (armature && armature->init(name)) { armature->autorelease(); return armature; @@ -58,9 +65,9 @@ Armature *Armature::create(const char *_name) return NULL; } -Armature *Armature::create(const char *name, Bone *parentBone) +CCArmature *CCArmature::create(const char *name, CCBone *parentBone) { - Armature *armature = new Armature(); + CCArmature *armature = new CCArmature(); if (armature && armature->init(name, parentBone)) { armature->autorelease(); @@ -70,100 +77,101 @@ Armature *Armature::create(const char *name, Bone *parentBone) return NULL; } -Armature::Armature() - : _animation(NULL) - , _armatureData(NULL) - , _batchNode(NULL) - , _atlas(NULL) - , _parentBone(NULL) - , _boneDic(NULL) - , _topBoneList(NULL) +CCArmature::CCArmature() + : m_pArmatureData(NULL) + , m_pBatchNode(NULL) + , m_pAtlas(NULL) + , m_pParentBone(NULL) + , m_bArmatureTransformDirty(true) + , m_pBoneDic(NULL) + , m_pTopBoneList(NULL) + , m_pAnimation(NULL) { } -Armature::~Armature(void) +CCArmature::~CCArmature(void) { - CCLOGINFO("deallocing Armature: %p", this); - - if(NULL != _boneDic) + if(NULL != m_pBoneDic) { - _boneDic->removeAllObjects(); - CC_SAFE_RELEASE(_boneDic); + m_pBoneDic->removeAllObjects(); + CC_SAFE_DELETE(m_pBoneDic); } - if (NULL != _topBoneList) + if (NULL != m_pTopBoneList) { - _topBoneList->removeAllObjects(); - CC_SAFE_DELETE(_topBoneList); + m_pTopBoneList->removeAllObjects(); + CC_SAFE_DELETE(m_pTopBoneList); } - CC_SAFE_DELETE(_animation); + CC_SAFE_DELETE(m_pAnimation); } -bool Armature::init() +bool CCArmature::init() { return init(NULL); } -bool Armature::init(const char *name) +bool CCArmature::init(const char *name) { bool bRet = false; do { removeAllChildren(); - CC_SAFE_DELETE(_animation); - _animation = new ArmatureAnimation(); - _animation->init(this); + CC_SAFE_DELETE(m_pAnimation); + m_pAnimation = new CCArmatureAnimation(); + m_pAnimation->init(this); - CC_SAFE_RELEASE(_boneDic); - _boneDic = new Dictionary(); - _boneDic->init(); + CC_SAFE_DELETE(m_pBoneDic); + m_pBoneDic = new Dictionary(); - CC_SAFE_DELETE(_topBoneList); - _topBoneList = Array::create(); - _topBoneList->retain(); + CC_SAFE_DELETE(m_pTopBoneList); + m_pTopBoneList = new Array(); + m_pTopBoneList->init(); - _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; - _name = name == NULL ? "" : name; + m_sBlendFunc.src = CC_BLEND_SRC; + m_sBlendFunc.dst = CC_BLEND_DST; - ArmatureDataManager *armatureDataManager = ArmatureDataManager::sharedArmatureDataManager(); - if(_name.length() != 0) + m_strName = name == NULL ? "" : name; + + CCArmatureDataManager *armatureDataManager = CCArmatureDataManager::sharedArmatureDataManager(); + + if(m_strName.length() != 0) { - _name = name; + m_strName = name; - AnimationData *animationData = armatureDataManager->getAnimationData(name); - CCASSERT(animationData, "CCAnimationData not exist! "); + CCAnimationData *animationData = armatureDataManager->getAnimationData(name); + CCAssert(animationData, "CCAnimationData not exist! "); - _animation->setAnimationData(animationData); + m_pAnimation->setAnimationData(animationData); - ArmatureData *armatureData = armatureDataManager->getArmatureData(name); - CCASSERT(armatureData, ""); + CCArmatureData *armatureData = armatureDataManager->getArmatureData(name); + CCAssert(armatureData, ""); - _armatureData = armatureData; + m_pArmatureData = armatureData; DictElement *_element = NULL; - Dictionary *boneDataDic = armatureData->boneDataDic; + Dictionary *boneDataDic = &armatureData->boneDataDic; CCDICT_FOREACH(boneDataDic, _element) { - Bone *bone = createBone(_element->getStrKey()); + CCBone *bone = createBone(_element->getStrKey()); - //! init bone's Tween to 1st movement's 1st frame + //! init bone's CCTween to 1st movement's 1st frame do { - MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str()); + CCMovementData *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); + CCMovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str()); + CC_BREAK_IF(!movBoneData || movBoneData->frameList.count() <= 0); - FrameData *frameData = movBoneData->getFrameData(0); + CCFrameData *frameData = movBoneData->getFrameData(0); CC_BREAK_IF(!frameData); bone->getTweenData()->copy(frameData); @@ -177,21 +185,21 @@ bool Armature::init(const char *name) } else { - _name = "new_armature"; - _armatureData = ArmatureData::create(); - _armatureData->name = _name; + m_strName = "new_armature"; + m_pArmatureData = CCArmatureData::create(); + m_pArmatureData->name = m_strName; - AnimationData *animationData = AnimationData::create(); - animationData->name = _name; + CCAnimationData *animationData = CCAnimationData::create(); + animationData->name = m_strName; - armatureDataManager->addArmatureData(_name.c_str(), _armatureData); - armatureDataManager->addAnimationData(_name.c_str(), animationData); + armatureDataManager->addArmatureData(m_strName.c_str(), m_pArmatureData); + armatureDataManager->addAnimationData(m_strName.c_str(), animationData); - _animation->setAnimationData(animationData); + m_pAnimation->setAnimationData(animationData); } - setShaderProgram(ShaderCache::getInstance()->programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setShaderProgram(CCShaderCache::getInstance()->programForKey(kCCShader_PositionTextureColor)); unscheduleUpdate(); scheduleUpdate(); @@ -206,33 +214,33 @@ bool Armature::init(const char *name) return bRet; } -bool Armature::init(const char *name, Bone *parentBone) +bool CCArmature::init(const char *name, CCBone *parentBone) { - _parentBone = parentBone; + m_pParentBone = parentBone; return init(name); } -Bone *Armature::createBone(const char *boneName) +CCBone *CCArmature::createBone(const char *boneName) { - Bone *existedBone = getBone(boneName); + CCBone *existedBone = getBone(boneName); if(existedBone != NULL) return existedBone; - BoneData *boneData = (BoneData *)_armatureData->getBoneData(boneName); + CCBoneData *boneData = (CCBoneData *)m_pArmatureData->getBoneData(boneName); std::string parentName = boneData->parentName; - Bone *bone = NULL; + CCBone *bone = NULL; if( parentName.length() != 0 ) { createBone(parentName.c_str()); - bone = Bone::create(boneName); + bone = CCBone::create(boneName); addBone(bone, parentName.c_str()); } else { - bone = Bone::create(boneName); + bone = CCBone::create(boneName); addBone(bone, ""); } @@ -243,90 +251,103 @@ Bone *Armature::createBone(const char *boneName) } -void Armature::addBone(Bone *bone, const char *parentName) +void CCArmature::addBone(CCBone *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 != NULL, "Argument must be non-nil"); + CCAssert(m_pBoneDic->objectForKey(bone->getName()) == NULL, "bone already added. It can't be added again"); if (NULL != parentName) { - Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName); + CCBone *boneParent = (CCBone *)m_pBoneDic->objectForKey(parentName); if (boneParent) { boneParent->addChildBone(bone); } else { - if (_parentBone) - _parentBone->addChildBone(bone); + if (m_pParentBone) + m_pParentBone->addChildBone(bone); else - _topBoneList->addObject(bone); + m_pTopBoneList->addObject(bone); } } else { - if (_parentBone) - _parentBone->addChildBone(bone); + if (m_pParentBone) + m_pParentBone->addChildBone(bone); else - _topBoneList->addObject(bone); + m_pTopBoneList->addObject(bone); } bone->setArmature(this); - _boneDic->setObject(bone, bone->getName()); + m_pBoneDic->setObject(bone, bone->getName()); addChild(bone); } -void Armature::removeBone(Bone *bone, bool recursion) +void CCArmature::removeBone(CCBone *bone, bool recursion) { - CCASSERT(bone != NULL, "bone must be added to the bone dictionary!"); + CCAssert(bone != NULL, "bone must be added to the bone dictionary!"); bone->setArmature(NULL); bone->removeFromParent(recursion); - if (_topBoneList->containsObject(bone)) + if (m_pTopBoneList->containsObject(bone)) { - _topBoneList->removeObject(bone); + m_pTopBoneList->removeObject(bone); } - _boneDic->removeObjectForKey(bone->getName()); + m_pBoneDic->removeObjectForKey(bone->getName()); removeChild(bone, true); } -Bone *Armature::getBone(const char *_name) const +CCBone *CCArmature::getBone(const char *name) const { - return (Bone *)_boneDic->objectForKey(_name); + return (CCBone *)m_pBoneDic->objectForKey(name); } -void Armature::changeBoneParent(Bone *bone, const char *parentName) +void CCArmature::changeBoneParent(CCBone *bone, const char *parentName) { - CCASSERT(bone != NULL, "bone must be added to the bone dictionary!"); + 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) { - Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName); + CCBone *boneParent = (CCBone *)m_pBoneDic->objectForKey(parentName); if (boneParent) { boneParent->addChildBone(bone); + if (m_pTopBoneList->containsObject(bone)) + { + m_pTopBoneList->removeObject(bone); + } + } + else + { + m_pTopBoneList->addObject(bone); } } } -Dictionary *Armature::getBoneDic() +Dictionary *CCArmature::getBoneDic() { - return _boneDic; + return m_pBoneDic; } -const AffineTransform& Armature::getNodeToParentTransform() const +AffineTransform CCArmature::getNodeToParentTransform() { if (_transformDirty) { + m_bArmatureTransformDirty = true; + // Translate values float x = _position.x; float y = _position.y; @@ -352,15 +373,15 @@ const AffineTransform& Armature::getNodeToParentTransform() const } // Add offset point - x += cy * _offsetPoint.x * _scaleX + -sx * _offsetPoint.y * _scaleY; - y += sy * _offsetPoint.x * _scaleX + cx * _offsetPoint.y * _scaleY; + x += cy * m_pOffsetPoint.x * _scaleX + -sx * m_pOffsetPoint.y * _scaleY; + y += sy * m_pOffsetPoint.x * _scaleX + cx * m_pOffsetPoint.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)) + if (! needsSkewMatrix && !_anchorPointInPoints.equals(CCPointZero)) { x += cy * -_anchorPointInPoints.x * _scaleX + -sx * -_anchorPointInPoints.y * _scaleY; y += sy * -_anchorPointInPoints.x * _scaleX + cx * -_anchorPointInPoints.y * _scaleY; @@ -383,9 +404,9 @@ const AffineTransform& Armature::getNodeToParentTransform() const _transform = AffineTransformConcat(skewMatrix, _transform); // adjust anchor point - if (!_anchorPointInPoints.equals(Point::ZERO)) + if (!_anchorPointInPoints.equals(CCPointZero)) { - _transform = AffineTransformTranslate(_transform, -_anchorPointInPoints.x, -_anchorPointInPoints.y); + _transform = CCAffineTransformTranslate(_transform, -_anchorPointInPoints.x, -_anchorPointInPoints.y); } } @@ -401,100 +422,187 @@ const AffineTransform& Armature::getNodeToParentTransform() const return _transform; } -void Armature::updateOffsetPoint() +void CCArmature::updateOffsetPoint() { // Set contentsize and Calculate anchor point. - Rect rect = getBoundingBox(); + Rect rect = boundingBox(); setContentSize(rect.size); - _offsetPoint = Point(-rect.origin.x, -rect.origin.y); - setAnchorPoint(Point(_offsetPoint.x / rect.size.width, _offsetPoint.y / rect.size.height)); -} - - -void Armature::update(float dt) -{ - _animation->update(dt); - - Object *object = NULL; - CCARRAY_FOREACH(_topBoneList, object) + m_pOffsetPoint = Point(-rect.origin.x, -rect.origin.y); + if (rect.size.width != 0 && rect.size.height != 0) { - static_cast(object)->update(dt); + setAnchorPoint(Point(m_pOffsetPoint.x / rect.size.width, m_pOffsetPoint.y / rect.size.height)); } } -void Armature::draw() +void CCArmature::setAnimation(CCArmatureAnimation *animation) { - if (_parentBone == NULL) + m_pAnimation = animation; +} + +CCArmatureAnimation *CCArmature::getAnimation() +{ + return m_pAnimation; +} + +void CCArmature::update(float dt) +{ + m_pAnimation->update(dt); + + Object *object = NULL; + CCARRAY_FOREACH(m_pTopBoneList, object) + { + ((CCBone *)object)->update(dt); + } + + m_bArmatureTransformDirty = false; +} + +void CCArmature::draw() +{ + if (m_pParentBone == NULL) { CC_NODE_DRAW_SETUP(); - GL::blendFunc(_blendFunc.src, _blendFunc.dst); + ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); } Object *object = NULL; CCARRAY_FOREACH(_children, object) { - Bone *bone = static_cast(object); - - DisplayManager *displayManager = bone->getDisplayManager(); - Node *node = displayManager->getDisplayRenderNode(); - - if (NULL == node) - continue; - - if(Skin *skin = dynamic_cast(node)) + if (CCBone *bone = dynamic_cast(object)) { - TextureAtlas *textureAtlas = skin->getTextureAtlas(); - if(_atlas != textureAtlas) + CCDisplayManager *displayManager = bone->getDisplayManager(); + Node *node = displayManager->getDisplayRenderNode(); + + if (NULL == node) + continue; + + switch (displayManager->getCurrentDecorativeDisplay()->getDisplayData()->displayType) { - if (_atlas) + case CS_DISPLAY_SPRITE: + { + CCSkin *skin = (CCSkin *)node; + + TextureAtlas *textureAtlas = skin->getTextureAtlas(); + CCBlendType blendType = bone->getBlendType(); + if(m_pAtlas != textureAtlas || blendType != BLEND_NORMAL) { - _atlas->drawQuads(); - _atlas->removeAllQuads(); + if (m_pAtlas) + { + m_pAtlas->drawQuads(); + m_pAtlas->removeAllQuads(); + } + } + + m_pAtlas = textureAtlas; + if (m_pAtlas->getCapacity() == m_pAtlas->getTotalQuads() && !m_pAtlas->resizeCapacity(m_pAtlas->getCapacity() * 2)) + return; + + skin->updateTransform(); + + if (blendType != BLEND_NORMAL) + { + updateBlendType(blendType); + m_pAtlas->drawQuads(); + m_pAtlas->removeAllQuads(); + ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); } } - - _atlas = textureAtlas; - if (_atlas->getCapacity() == _atlas->getTotalQuads() && !_atlas->resizeCapacity(_atlas->getCapacity() * 2)) - return; - - skin->draw(); - } - else if(Armature *armature = dynamic_cast(node)) - { - TextureAtlas *textureAtlas = armature->getTextureAtlas(); - - if(_atlas != textureAtlas) + break; + case CS_DISPLAY_ARMATURE: { - if (_atlas) + CCArmature *armature = (CCArmature *)(node); + + TextureAtlas *textureAtlas = armature->getTextureAtlas(); + if(m_pAtlas != textureAtlas) { - _atlas->drawQuads(); - _atlas->removeAllQuads(); + if (m_pAtlas) + { + m_pAtlas->drawQuads(); + m_pAtlas->removeAllQuads(); + } } + armature->draw(); } - armature->draw(); - } - else - { - if (_atlas) + break; + default: { - _atlas->drawQuads(); - _atlas->removeAllQuads(); + if (m_pAtlas) + { + m_pAtlas->drawQuads(); + m_pAtlas->removeAllQuads(); + } + node->visit(); + + CC_NODE_DRAW_SETUP(); + ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); + } + break; + } + } + else if(Node *node = dynamic_cast(object)) + { + if (m_pAtlas) + { + m_pAtlas->drawQuads(); + m_pAtlas->removeAllQuads(); } node->visit(); CC_NODE_DRAW_SETUP(); - GL::blendFunc(_blendFunc.src, _blendFunc.dst); + ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); } } - if(_atlas && !_batchNode && _parentBone == NULL) + if(m_pAtlas && !m_pBatchNode && m_pParentBone == NULL) { - _atlas->drawQuads(); - _atlas->removeAllQuads(); + m_pAtlas->drawQuads(); + m_pAtlas->removeAllQuads(); } } -void Armature::visit() + +void CCArmature::updateBlendType(CCBlendType 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; + } + ccGLBlendFunc(blendFunc.src, blendFunc.dst); +} + + + +void CCArmature::visit() { // quick return if not visible. children won't be drawn. if (!_visible) @@ -523,7 +631,7 @@ void Armature::visit() kmGLPopMatrix(); } -Rect Armature::getBoundingBox() const +Rect CCArmature::getBoundingBox() { float minx, miny, maxx, maxy = 0; @@ -534,46 +642,145 @@ Rect Armature::getBoundingBox() const Object *object = NULL; CCARRAY_FOREACH(_children, object) { - Bone *bone = static_cast(object); - Rect r = bone->getDisplayManager()->getBoundingBox(); - - if(first) + if (CCBone *bone = dynamic_cast(object)) { - minx = r.getMinX(); - miny = r.getMinY(); - maxx = r.getMaxX(); - maxy = r.getMaxY(); + Rect r = bone->getDisplayManager()->getBoundingBox(); - 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(); - } + if(first) + { + minx = r.getMinX(); + miny = r.getMinY(); + maxx = r.getMaxX(); + maxy = r.getMaxY(); - boundingBox.setRect(minx, miny, maxx - minx, maxy - miny); + 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) +CCBone *CCArmature::getBoneAtPoint(float x, float y) { - int length = _children->count(); - Bone *bs; + int length = _children->data->num; + CCBone **bs = (CCBone **)_children->data->arr; for(int i = length - 1; i >= 0; i--) { - bs = static_cast( _children->getObjectAtIndex(i) ); - if(bs->getDisplayManager()->containPoint(x, y)) + if(bs[i]->getDisplayManager()->containPoint(x, y)) { - return bs; + return bs[i]; } } return NULL; } -}}} // namespace cocos2d { namespace extension { namespace armature { +#if ENABLE_PHYSICS_BOX2D_DETECT +b2Body *CCArmature::getBody() +{ + return m_pBody; +} + +void CCArmature::setBody(b2Body *body) +{ + if (m_pBody == body) + { + return; + } + + m_pBody = body; + m_pBody->SetUserData(this); + + Object *object = NULL; + CCARRAY_FOREACH(_children, object) + { + if (CCBone *bone = dynamic_cast(object)) + { + Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); + + Object *displayObject = NULL; + CCARRAY_FOREACH(displayList, displayObject) + { + CCColliderDetector *detector = ((CCDecorativeDisplay *)displayObject)->getColliderDetector(); + if (detector != NULL) + { + detector->setBody(m_pBody); + } + } + } + } +} + +b2Fixture *CCArmature::getShapeList() +{ + if (m_pBody) + { + return m_pBody->GetFixtureList(); + } + else + { + return NULL; + } +} + +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +cpBody *CCArmature::getBody() +{ + return m_pBody; +} + +void CCArmature::setBody(cpBody *body) +{ + if (m_pBody == body) + { + return; + } + + m_pBody = body; + m_pBody->data = this; + + Object *object = NULL; + CCARRAY_FOREACH(_children, object) + { + if (CCBone *bone = dynamic_cast(object)) + { + Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); + + Object *displayObject = NULL; + CCARRAY_FOREACH(displayList, displayObject) + { + CCColliderDetector *detector = ((CCDecorativeDisplay *)displayObject)->getColliderDetector(); + if (detector != NULL) + { + detector->setBody(m_pBody); + } + } + } + } +} + +cpShape *CCArmature::getShapeList() +{ + if (m_pBody) + { + return m_pBody->shapeList_private; + } + else + { + return NULL; + } +} +#endif + + +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/CCArmature.h b/extensions/CocoStudio/Armature/CCArmature.h index 42befeba1d..b197152703 100644 --- a/extensions/CocoStudio/Armature/CCArmature.h +++ b/extensions/CocoStudio/Armature/CCArmature.h @@ -21,172 +21,170 @@ 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 __CCARMATURE_H__ #define __CCARMATURE_H__ #include "utils/CCArmatureDefine.h" #include "CCBone.h" #include "display/CCBatchNode.h" -#include "display/CCShaderNode.h" #include "animation/CCArmatureAnimation.h" -#include "physics/CCPhysicsWorld.h" -#include "utils/CCSpriteFrameCacheHelper.h" -#include "utils/CCArmatureDataManager.h" -namespace cocos2d { namespace extension { namespace armature { +class b2Body; +struct cpBody; -CC_DEPRECATED_ATTRIBUTE typedef ProcessBase CCProcessBase; -CC_DEPRECATED_ATTRIBUTE typedef BaseData CCBaseData; -CC_DEPRECATED_ATTRIBUTE typedef DisplayData CCDisplayData; -CC_DEPRECATED_ATTRIBUTE typedef SpriteDisplayData CCSpriteDisplayData; -CC_DEPRECATED_ATTRIBUTE typedef ArmatureDisplayData CCArmatureDisplayData; -CC_DEPRECATED_ATTRIBUTE typedef ParticleDisplayData CCParticleDisplayData; -CC_DEPRECATED_ATTRIBUTE typedef ShaderDisplayData CCShaderDisplayData; -CC_DEPRECATED_ATTRIBUTE typedef BoneData CCBoneData; -CC_DEPRECATED_ATTRIBUTE typedef FrameData CCFrameData; -CC_DEPRECATED_ATTRIBUTE typedef MovementBoneData CCMovementBoneData; -CC_DEPRECATED_ATTRIBUTE typedef MovementData CCMovementData; -CC_DEPRECATED_ATTRIBUTE typedef AnimationData CCAnimationData; -CC_DEPRECATED_ATTRIBUTE typedef ContourData CCContourData; -CC_DEPRECATED_ATTRIBUTE typedef TextureData CCTextureData; -CC_DEPRECATED_ATTRIBUTE typedef ShaderNode CCShaderNode; -CC_DEPRECATED_ATTRIBUTE typedef DecorativeDisplay CCDecorativeDisplay; -CC_DEPRECATED_ATTRIBUTE typedef DisplayData CCDisplayData; -CC_DEPRECATED_ATTRIBUTE typedef DisplayFactory CCDisplayFactory; -CC_DEPRECATED_ATTRIBUTE typedef BatchNode CCBatchNode; -CC_DEPRECATED_ATTRIBUTE typedef DecorativeDisplay CCDecorativeDisplay; -CC_DEPRECATED_ATTRIBUTE typedef DisplayManager CCDisplayManager; -CC_DEPRECATED_ATTRIBUTE typedef ColliderBody CCColliderBody; -CC_DEPRECATED_ATTRIBUTE typedef ColliderDetector CCColliderDetector; -CC_DEPRECATED_ATTRIBUTE typedef PhysicsWorld CCPhysicsWorld; -CC_DEPRECATED_ATTRIBUTE typedef SpriteFrameCacheHelper CCSpriteFrameCacheHelper; -CC_DEPRECATED_ATTRIBUTE typedef TweenFunction CCTweenFunction; -CC_DEPRECATED_ATTRIBUTE typedef ArmatureData CCArmatureData; -CC_DEPRECATED_ATTRIBUTE typedef Bone CCBone; -CC_DEPRECATED_ATTRIBUTE typedef ArmatureAnimation CCArmatureAnimation; -CC_DEPRECATED_ATTRIBUTE typedef Armature CCArmature; -CC_DEPRECATED_ATTRIBUTE typedef ArmatureDataManager CCArmatureDataManager; - -class Armature : public NodeRGBA, public BlendProtocol +NS_CC_EXT_ARMATURE_BEGIN + +class CCArmature : public NodeRGBA, public BlendProtocol { public: - /** - * Allocates and initializes a armature. - * @return A initialized armature which is marked as "autorelease". - */ - static Armature *create(); - - /** - * Allocates a armature, and use the ArmatureData named name in ArmatureDataManager to initializes the armature. - * - * @param name Armature will use the name to find to the ArmatureData to initializes it. - * @return A initialized armature which is marked as "autorelease". - */ - static Armature *create(const char *name); - static Armature *create(const char *name, Bone *parentBone); + /** + * Allocates and initializes an armature. + * @return An initialized armature which is marked as "autorelease". + */ + static CCArmature *create(); + + /** + * Allocates an armature, and use the CCArmatureData named name in CCArmatureDataManager to initializes the armature. + * + * @param name CCArmature will use the name to find the CCArmatureData to initializes it. + * @return A initialized armature which is marked as "autorelease". + */ + static CCArmature *create(const char *name); + + static CCArmature *create(const char *name, CCBone *parentBone); public: - Armature(); - virtual ~Armature(void); + CCArmature(); + ~CCArmature(void); /** * Init the empty armature */ virtual bool init(); - + /** - * Init a armature with specified name - * @param name Armature name + * Init an armature with specified name + * @param name CCArmature name */ virtual bool init(const char *name); - virtual bool init(const char *name, Bone *parentBone); + virtual bool init(const char *name, CCBone *parentBone); /** - * Add a Bone to this Armature, + * Add a CCBone to this CCArmature, * - * @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 it's parent + * @param bone The CCBone you want to add to CCArmature + * @param parentName The parent CCBone's name you want to add to . If it's NULL, then set CCArmature to its parent */ - virtual void addBone(Bone *bone, const char* parentName); + virtual void addBone(CCBone *bone, const char *parentName); /** * Get a bone with the specified name * * @param name The bone's name you want to get */ - virtual Bone *getBone(const char *name) const; + virtual CCBone *getBone(const char *name) const; /** * Change a bone's parent with the specified parent name. * * @param bone The bone you want to change parent - * @param parentName The new parent's name. + * @param parentName The new parent's name. */ - virtual void changeBoneParent(Bone *bone, const char *parentName); + virtual void changeBoneParent(CCBone *bone, const char *parentName); /** - * Remove a bone with the specified name. If recursion it will also remove child Bone recursionly. + * Remove a bone with the specified name. If recursion it will also remove child CCBone recursionly. * * @param bone The bone you want to remove - * @param recursion Determine whether remove the bone's child recursion. + * @param recursion Determine whether remove the bone's child recursion. */ - virtual void removeBone(Bone *bone, bool recursion); + virtual void removeBone(CCBone *bone, bool recursion); /** - * Get Armature's bone dictionary - * @return Armature's bone dictionary + * Get CCArmature's bone dictionary + * @return CCArmature's bone dictionary */ - Dictionary *getBoneDic(); - - Bone *getBoneAtPoint(float x, float y); - + Dictionary *getBoneDic(); - /** - * Set contentsize and Calculate anchor point. + /** + * This boundingBox will calculate all bones' boundingBox every time */ - virtual void updateOffsetPoint(); + virtual Rect getBoundingBox(); - // overrides - virtual void visit() override; - virtual void update(float dt) override; - virtual void draw() override; - virtual const AffineTransform& getNodeToParentTransform() const override; - /** This boundingBox will calculate all bones' boundingBox every time */ - virtual Rect getBoundingBox() const override; - inline void setBlendFunc(const BlendFunc& blendFunc) override { _blendFunc = blendFunc; } - inline const BlendFunc& getBlendFunc(void) const override { return _blendFunc; } + CCBone *getBoneAtPoint(float x, float y); + + virtual void visit(); + virtual void update(float dt); + virtual void draw(); + + virtual AffineTransform getNodeToParentTransform(); + + /** + * Set contentsize and Calculate anchor point. + */ + virtual void updateOffsetPoint(); + + inline void setBlendFunc(const BlendFunc &blendFunc) + { + m_sBlendFunc = blendFunc; + } + inline const BlendFunc &getBlendFunc(void) const + { + return m_sBlendFunc; + } + + virtual void setAnimation(CCArmatureAnimation *animation); + virtual CCArmatureAnimation *getAnimation(); + +#if ENABLE_PHYSICS_BOX2D_DETECT + virtual b2Fixture *getShapeList(); +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + virtual cpShape *getShapeList(); +#endif protected: - + /* - * Used to create Bone internal + * Used to create CCBone internal */ - Bone *createBone(const char *boneName ); - + CCBone *createBone(const char *boneName ); - CC_SYNTHESIZE_RETAIN(ArmatureAnimation *, _animation, Animation); - - CC_SYNTHESIZE(ArmatureData *, _armatureData, ArmatureData); + //! Update blend function + void updateBlendType(CCBlendType blendType); - CC_SYNTHESIZE(BatchNode*, _batchNode, BatchNode); + CC_SYNTHESIZE(CCArmatureData *, m_pArmatureData, ArmatureData); - CC_SYNTHESIZE_PASS_BY_REF(std::string, _name, Name); + CC_SYNTHESIZE(CCBatchNode *, m_pBatchNode, BatchNode); - CC_SYNTHESIZE(TextureAtlas*, _atlas, TextureAtlas); + CC_SYNTHESIZE(std::string, m_strName, Name); - CC_SYNTHESIZE(Bone*, _parentBone, ParentBone); + CC_SYNTHESIZE(TextureAtlas *, m_pAtlas, TextureAtlas); + + CC_SYNTHESIZE(CCBone *, m_pParentBone, ParentBone); + + CC_SYNTHESIZE(float, m_fVersion, Version); + + CC_SYNTHESIZE_READONLY(bool, m_bArmatureTransformDirty, ArmatureTransformDirty); protected: - 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 _chindren. + Dictionary *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. - Array *_topBoneList; + Array *m_pTopBoneList; - static std::map _armatureIndexDic; //! Use to save armature zorder info, + static std::map m_sArmatureIndexDic; //! Use to save armature zorder info, - BlendFunc _blendFunc; //! It's required for TextureProtocol inheritance + BlendFunc m_sBlendFunc; //! It's required for CCTextureProtocol inheritance - Point _offsetPoint; + Point m_pOffsetPoint; + + CCArmatureAnimation *m_pAnimation; + +#if ENABLE_PHYSICS_BOX2D_DETECT + CC_PROPERTY(b2Body *, m_pBody, Body); +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + CC_PROPERTY(cpBody *, m_pBody, Body); +#endif }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCARMATURE_H__*/ diff --git a/extensions/CocoStudio/Armature/CCBone.cpp b/extensions/CocoStudio/Armature/CCBone.cpp index 4361339ed9..d03ed67fe7 100644 --- a/extensions/CocoStudio/Armature/CCBone.cpp +++ b/extensions/CocoStudio/Armature/CCBone.cpp @@ -29,12 +29,12 @@ THE SOFTWARE. #include "utils/CCTransformHelp.h" #include "display/CCDisplayManager.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -Bone *Bone::create() +CCBone *CCBone::create() { - Bone *pBone = new Bone(); + CCBone *pBone = new CCBone(); if (pBone && pBone->init()) { pBone->autorelease(); @@ -45,10 +45,10 @@ Bone *Bone::create() } -Bone *Bone::create(const char *name) +CCBone *CCBone::create(const char *name) { - Bone *pBone = new Bone(); + CCBone *pBone = new CCBone(); if (pBone && pBone->init(name)) { pBone->autorelease(); @@ -58,45 +58,46 @@ Bone *Bone::create(const char *name) return NULL; } -Bone::Bone() +CCBone::CCBone() { - _tweenData = NULL; - _parent = NULL; - _armature = NULL; - _childArmature = NULL; - _boneData = NULL; - _tween = NULL; - _tween = NULL; + m_pTweenData = NULL; + m_pParentBone = NULL; + m_pArmature = NULL; + m_pChildArmature = NULL; + m_pBoneData = NULL; + m_pTween = NULL; + m_pTween = NULL; _children = NULL; - _displayManager = NULL; - _ignoreMovementBoneData = false; - _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0); - _transformDirty = true; + m_pDisplayManager = NULL; + m_bIgnoreMovementBoneData = false; + m_tWorldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0); + m_bBoneTransformDirty = true; + m_eBlendType = BLEND_NORMAL; } -Bone::~Bone(void) +CCBone::~CCBone(void) { - CC_SAFE_DELETE(_tweenData); + CC_SAFE_DELETE(m_pTweenData); CC_SAFE_DELETE(_children); - CC_SAFE_DELETE(_tween); - CC_SAFE_DELETE(_displayManager); + CC_SAFE_DELETE(m_pTween); + CC_SAFE_DELETE(m_pDisplayManager); - if(_boneData) + if(m_pBoneData) { - _boneData->release(); + m_pBoneData->release(); } - CC_SAFE_RELEASE(_childArmature); + CC_SAFE_RELEASE(m_pChildArmature); } -bool Bone::init() +bool CCBone::init() { - return Bone::init(NULL); + return CCBone::init(NULL); } -bool Bone::init(const char *name) +bool CCBone::init(const char *name) { bool bRet = false; do @@ -104,19 +105,19 @@ bool Bone::init(const char *name) if(NULL != name) { - _name = name; + m_strName = name; } - CC_SAFE_DELETE(_tweenData); - _tweenData = new FrameData(); + CC_SAFE_DELETE(m_pTweenData); + m_pTweenData = new CCFrameData(); - CC_SAFE_DELETE(_tween); - _tween = new Tween(); - _tween->init(this); + CC_SAFE_DELETE(m_pTween); + m_pTween = new CCTween(); + m_pTween->init(this); - CC_SAFE_DELETE(_displayManager); - _displayManager = new DisplayManager(); - _displayManager->init(this); + CC_SAFE_DELETE(m_pDisplayManager); + m_pDisplayManager = new CCDisplayManager(); + m_pDisplayManager->init(this); bRet = true; @@ -126,108 +127,123 @@ bool Bone::init(const char *name) return bRet; } -void Bone::setBoneData(BoneData *boneData) +void CCBone::setBoneData(CCBoneData *boneData) { - CCASSERT(NULL != boneData, "_boneData must not be NULL"); + CCAssert(NULL != boneData, "_boneData must not be NULL"); - _boneData = boneData; - _boneData->retain(); + m_pBoneData = boneData; + m_pBoneData->retain(); - _name = _boneData->name; - _ZOrder = _boneData->zOrder; + m_strName = m_pBoneData->name; + _ZOrder = m_pBoneData->zOrder; - _displayManager->initDisplayList(boneData); + m_pDisplayManager->initDisplayList(boneData); } -BoneData *Bone::getBoneData() +CCBoneData *CCBone::getBoneData() { - return _boneData; + return m_pBoneData; } -void Bone::setArmature(Armature *armature) +void CCBone::setArmature(CCArmature *armature) { - _armature = armature; - _tween->setAnimation(_armature->getAnimation()); -} - - -Armature *Bone::getArmature() -{ - return _armature; -} - -void Bone::update(float delta) -{ - if (_parent) - _transformDirty = _transformDirty || _parent->isTransformDirty(); - - if (_transformDirty) + m_pArmature = armature; + if (m_pArmature) { - float cosX = cos(_tweenData->skewX); - float cosY = cos(_tweenData->skewY); - float sinX = sin(_tweenData->skewX); - float sinY = sin(_tweenData->skewY); + m_pTween->setAnimation(m_pArmature->getAnimation()); + } +} - _worldTransform.a = _tweenData->scaleX * cosY; - _worldTransform.b = _tweenData->scaleX * sinY; - _worldTransform.c = _tweenData->scaleY * sinX; - _worldTransform.d = _tweenData->scaleY * cosX; - _worldTransform.tx = _tweenData->x; - _worldTransform.ty = _tweenData->y; - _worldTransform = AffineTransformConcat(getNodeToParentTransform(), _worldTransform); +CCArmature *CCBone::getArmature() +{ + return m_pArmature; +} - if(_parent) +void CCBone::update(float delta) +{ + if (m_pParentBone) + m_bBoneTransformDirty = m_bBoneTransformDirty || m_pParentBone->isTransformDirty(); + + if (m_bBoneTransformDirty) + { + if (m_pArmature->getArmatureData()->dataVersion >= VERSION_COMBINED) { - _worldTransform = AffineTransformConcat(_worldTransform, _parent->_worldTransform); + CCTransformHelp::nodeConcat(*m_pTweenData, *m_pBoneData); + m_pTweenData->scaleX -= 1; + m_pTweenData->scaleY -= 1; + } + + CCTransformHelp::nodeToMatrix(*m_pTweenData, m_tWorldTransform); + + m_tWorldTransform = AffineTransformConcat(getNodeToParentTransform(), m_tWorldTransform); + + if(m_pParentBone) + { + m_tWorldTransform = AffineTransformConcat(m_tWorldTransform, m_pParentBone->m_tWorldTransform); } } - DisplayFactory::updateDisplay(this, _displayManager->getCurrentDecorativeDisplay(), delta, _transformDirty); + CCDisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty || m_pArmature->getArmatureTransformDirty()); Object *object = NULL; CCARRAY_FOREACH(_children, object) { - Bone *childBone = static_cast(object); + CCBone *childBone = (CCBone *)object; childBone->update(delta); } - _transformDirty = false; + m_bBoneTransformDirty = false; } -void Bone::updateDisplayedColor(const Color3B &parentColor) +void CCBone::updateDisplayedColor(const Color3B &parentColor) { + _realColor = Color3B(255, 255, 255); NodeRGBA::updateDisplayedColor(parentColor); updateColor(); } -void Bone::updateDisplayedOpacity(GLubyte parentOpacity) +void CCBone::updateDisplayedOpacity(GLubyte parentOpacity) { + _realOpacity = 255; NodeRGBA::updateDisplayedOpacity(parentOpacity); updateColor(); } -void Bone::updateColor() +void CCBone::updateColor() { - Node *display = _displayManager->getDisplayRenderNode(); + Node *display = m_pDisplayManager->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); + protocol->setColor(Color3B(_displayedColor.r * m_pTweenData->r / 255, _displayedColor.g * m_pTweenData->g / 255, _displayedColor.b * m_pTweenData->b / 255)); + protocol->setOpacity(_displayedOpacity * m_pTweenData->a / 255); } } - -void Bone::addChildBone(Bone *child) +void CCBone::updateZOrder() { - CCASSERT( NULL != child, "Argument must be non-nil"); - CCASSERT( NULL == child->_parent, "child already added. It can't be added again"); + 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) +{ + CCAssert( NULL != child, "Argument must be non-nil"); + CCAssert( NULL == child->m_pParentBone, "child already added. It can't be added again"); if(!_children) { - childrenAlloc(); + _children = Array::createWithCapacity(4); + _children->retain(); } if (_children->getIndexOfObject(child) == UINT_MAX) @@ -237,7 +253,7 @@ void Bone::addChildBone(Bone *child) } } -void Bone::removeChildBone(Bone *bone, bool recursion) +void CCBone::removeChildBone(CCBone *bone, bool recursion) { if ( _children->getIndexOfObject(bone) != UINT_MAX ) { @@ -247,7 +263,7 @@ void Bone::removeChildBone(Bone *bone, bool recursion) Object *_object = NULL; CCARRAY_FOREACH(_ccbones, _object) { - Bone *_ccBone = static_cast(_object); + CCBone *_ccBone = (CCBone *)_object; bone->removeChildBone(_ccBone, recursion); } } @@ -260,86 +276,101 @@ void Bone::removeChildBone(Bone *bone, bool recursion) } } -void Bone::removeFromParent(bool recursion) +void CCBone::removeFromParent(bool recursion) { - if (NULL != _parent) + if (NULL != m_pParentBone) { - _parent->removeChildBone(this, recursion); + m_pParentBone->removeChildBone(this, recursion); } } -void Bone::setParentBone(Bone *parent) +void CCBone::setParentBone(CCBone *parent) { - _parent = parent; + m_pParentBone = parent; } -Bone *Bone::getParentBone() +CCBone *CCBone::getParentBone() { - return _parent; + return m_pParentBone; } -void Bone::childrenAlloc(void) +void CCBone::setChildArmature(CCArmature *armature) { - CC_SAFE_DELETE(_children); - _children = Array::createWithCapacity(4); - _children->retain(); -} - - -void Bone::setChildArmature(Armature *armature) -{ - if (_childArmature != armature) + if (m_pChildArmature != armature) { CC_SAFE_RETAIN(armature); - CC_SAFE_RELEASE(_childArmature); - _childArmature = armature; + CC_SAFE_RELEASE(m_pChildArmature); + m_pChildArmature = armature; } } -Armature *Bone::getChildArmature() +CCArmature *CCBone::getChildArmature() { - return _childArmature; + return m_pChildArmature; } -Array *Bone::getChildren() +CCTween *CCBone::getTween() { - return _children; + return m_pTween; } -Tween *Bone::getTween() -{ - return _tween; -} - -void Bone::setZOrder(int zOrder) +void CCBone::setZOrder(int zOrder) { if (_ZOrder != zOrder) Node::setZOrder(zOrder); } -void Bone::setTransformDirty(bool dirty) +void CCBone::setTransformDirty(bool dirty) { - _transformDirty = dirty; + m_bBoneTransformDirty = dirty; } -bool Bone::isTransformDirty() +bool CCBone::isTransformDirty() { - return _transformDirty; + return m_bBoneTransformDirty; } -AffineTransform Bone::nodeToArmatureTransform() +AffineTransform CCBone::getNodeToArmatureTransform() { - return _worldTransform; + return m_tWorldTransform; } -void Bone::addDisplay(DisplayData *_displayData, int _index) +AffineTransform CCBone::getNodeToWorldTransform() { - _displayManager->addDisplay(_displayData, _index); + return AffineTransformConcat(m_tWorldTransform, m_pArmature->getNodeToWorldTransform()); } -void Bone::changeDisplayByIndex(int _index, bool _force) +Node *CCBone::getDisplayRenderNode() { - _displayManager->changeDisplayByIndex(_index, _force); + return m_pDisplayManager->getDisplayRenderNode(); } -}}} // namespace cocos2d { namespace extension { namespace armature { +void CCBone::addDisplay(CCDisplayData *displayData, int index) +{ + m_pDisplayManager->addDisplay(displayData, index); +} + +void CCBone::addDisplay(Node *display, int index) +{ + m_pDisplayManager->addDisplay(display, index); +} + +void CCBone::changeDisplayByIndex(int index, bool force) +{ + m_pDisplayManager->changeDisplayByIndex(index, force); +} + +Array *CCBone::getColliderBodyList() +{ + if (CCDecorativeDisplay *decoDisplay = m_pDisplayManager->getCurrentDecorativeDisplay()) + { + if (CCColliderDetector *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 index 69aae2fc07..965a53b51d 100644 --- a/extensions/CocoStudio/Armature/CCBone.h +++ b/extensions/CocoStudio/Armature/CCBone.h @@ -28,93 +28,95 @@ THE SOFTWARE. #include "utils/CCArmatureDefine.h" #include "datas/CCDatas.h" #include "animation/CCTween.h" -#include "external_tool/CCTexture2DMutable.h" #include "display/CCDecorativeDisplay.h" #include "display/CCDisplayManager.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -class Armature; -class Bone : public NodeRGBA +class CCArmature; + +class CCBone : public NodeRGBA { public: /** * Allocates and initializes a bone. * @return A initialized bone which is marked as "autorelease". */ - static Bone *create(); + static CCBone *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); + static CCBone *create(const char *name); public: - Bone(); - virtual ~Bone(void); + CCBone(); + virtual ~CCBone(void); /** - * Initializes an empty Bone with nothing init. + * Initializes an empty CCBone with nothing init. */ virtual bool init(); /** - * Initializes a Bone with the specified name - * @param name Bone's name. + * Initializes a CCBone with the specified name + * @param name CCBone's name. */ virtual bool init(const char *name); /** - * Add display and use _DisplayData init the display. + * 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 + * If you want to create a sprite display, then create a CCSpriteDisplayData 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(CCDisplayData *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. + * Add a child to this bone, and it will let this child call setParent(CCBone *parent) function to set self to it's parent + * @param child the child you want to add */ - void addChildBone(Bone *child); + void addChildBone(CCBone *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). + * If parent is NUll, then also remove this bone from armature. + * It will not set the CCArmature, if you want to add the bone to a CCArmature, you should use CCArmature::addBone(CCBone *bone, const char* parentName). * * @param parent the parent bone. * NULL : remove this bone from armature */ - void setParentBone(Bone *parent); + void setParentBone(CCBone *parent); /** * Get parent bone * @return parent bone */ - Bone *getParentBone(); + CCBone *getParentBone(); /** - * Remove itself from its parent Bone. - * @param recursion Whether to remove Child display + * 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. + * Removes a child CCBone + * @param bone the bone you want to remove */ - void removeChildBone(Bone *bone, bool recursion); + void removeChildBone(CCBone *bone, bool recursion); void update(float delta); @@ -124,10 +126,13 @@ public: //! Update color to render display void updateColor(); - Array *getChildren(); - Tween *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. */ @@ -135,48 +140,53 @@ public: virtual bool isTransformDirty(); - virtual AffineTransform nodeToArmatureTransform(); + virtual AffineTransform getNodeToArmatureTransform(); + virtual AffineTransform getNodeToWorldTransform(); + + 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, _node, _tweenData - * when call setData function, it will copy from the BoneData. + * The origin state of the CCBone. Display's state is effected by m_pBoneData, m_pNode, m_pTweenData + * when call setData function, it will copy from the CCBoneData. */ - CC_PROPERTY(BoneData *, _boneData, BoneData); + CC_PROPERTY(CCBoneData *, m_pBoneData, BoneData); - //! A weak reference to the Armature - CC_PROPERTY(Armature *, _armature, Armature); + //! A weak reference to the CCArmature + CC_PROPERTY(CCArmature *, m_pArmature, Armature); - //! A weak reference to the child Armature - CC_PROPERTY(Armature *, _childArmature, ChildArmature); + //! A weak reference to the child CCArmature + CC_PROPERTY(CCArmature *, m_pChildArmature, ChildArmature); - CC_SYNTHESIZE(DisplayManager *, _displayManager, DisplayManager) + CC_SYNTHESIZE(CCDisplayManager *, m_pDisplayManager, DisplayManager) /* - * When Armature play a animation, if there is not a MovementBoneData of this bone in this MovementData, this bone will hide. - * Set IgnoreMovementBoneData to true, then this bone will also show. + * When CCArmature play an animation, if there is not a CCMovementBoneData of this bone in this CCMovementData, this bone will be hidden. + * Set IgnoreMovementBoneData to true, then this bone will also be shown. */ - CC_SYNTHESIZE_PASS_BY_REF(bool, _ignoreMovementBoneData, IgnoreMovementBoneData) + CC_SYNTHESIZE(bool, m_bIgnoreMovementBoneData, IgnoreMovementBoneData) + CC_SYNTHESIZE(CCBlendType, m_eBlendType, BlendType) protected: - Tween *_tween; //! Calculate tween effect + CCTween *m_pTween; //! Calculate tween effect - //! Used for make tween effect between every frame - CC_SYNTHESIZE_READONLY(FrameData *, _tweenData, TweenData); + //! Used for making tween effect in every frame + CC_SYNTHESIZE_READONLY(CCFrameData *, m_pTweenData, TweenData); - CC_SYNTHESIZE_PASS_BY_REF(std::string, _name, Name); + CC_SYNTHESIZE(std::string, m_strName, Name); - //! Lazy allocs - void childrenAlloc(void); - Array *_children; - - Bone *_parent; //! A weak reference to it's parent - bool _transformDirty; //! Whether or not transform dirty + CCBone *m_pParentBone; //! A weak reference to its parent + bool m_bBoneTransformDirty; //! Whether or not transform dirty //! self Transform, use this to change display's state - AffineTransform _worldTransform; + AffineTransform m_tWorldTransform; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCBONE_H__*/ diff --git a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp index c944a477eb..c2cd1c19c6 100644 --- a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp +++ b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp @@ -27,15 +27,14 @@ THE SOFTWARE. #include "../CCBone.h" #include "../utils/CCArmatureDefine.h" #include "../utils/CCUtilMath.h" -#include "../utils/CCConstValue.h" #include "../datas/CCDatas.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -ArmatureAnimation *ArmatureAnimation::create(Armature *armature) +CCArmatureAnimation *CCArmatureAnimation::create(CCArmature *armature) { - ArmatureAnimation *pArmatureAnimation = new ArmatureAnimation(); + CCArmatureAnimation *pArmatureAnimation = new CCArmatureAnimation(); if (pArmatureAnimation && pArmatureAnimation->init(armature)) { pArmatureAnimation->autorelease(); @@ -46,32 +45,40 @@ ArmatureAnimation *ArmatureAnimation::create(Armature *armature) } -ArmatureAnimation::ArmatureAnimation() - : _animationData(NULL) - , _armature(NULL) - , _movementID("") - , _toIndex(0) +CCArmatureAnimation::CCArmatureAnimation() + : m_pAnimationData(NULL) + , m_fSpeedScale(1) + , m_pMovementData(NULL) + , m_pArmature(NULL) + , m_strMovementID("") + , m_iToIndex(0) + + , m_sMovementEventCallFunc(NULL) + , m_sFrameEventCallFunc(NULL) + , m_sMovementEventTarget(NULL) + , m_sFrameEventTarget(NULL) { } -ArmatureAnimation::~ArmatureAnimation(void) +CCArmatureAnimation::~CCArmatureAnimation(void) { - CCLOGINFO("deallocing ArmatureAnimation: %p", this); + CC_SAFE_RELEASE_NULL(m_pTweenList); + CC_SAFE_RELEASE_NULL(m_pAnimationData); - CC_SAFE_RELEASE_NULL(_tweenList); - CC_SAFE_RELEASE_NULL(_animationData); + CC_SAFE_RELEASE_NULL(m_sMovementEventTarget); + CC_SAFE_RELEASE_NULL(m_sFrameEventTarget); } -bool ArmatureAnimation::init(Armature *armature) +bool CCArmatureAnimation::init(CCArmature *armature) { bool bRet = false; do { - _armature = armature; + m_pArmature = armature; - _tweenList = new Array(); - _tweenList->init(); + m_pTweenList = new Array(); + m_pTweenList->init(); bRet = true; } @@ -81,124 +88,171 @@ bool ArmatureAnimation::init(Armature *armature) } -void ArmatureAnimation:: pause() +void CCArmatureAnimation:: pause() { Object *object = NULL; - CCARRAY_FOREACH(_tweenList, object) + CCARRAY_FOREACH(m_pTweenList, object) { - static_cast(object)->pause(); + ((CCTween *)object)->pause(); } - ProcessBase::pause(); + CCProcessBase::pause(); } -void ArmatureAnimation::resume() +void CCArmatureAnimation::resume() { Object *object = NULL; - CCARRAY_FOREACH(_tweenList, object) + CCARRAY_FOREACH(m_pTweenList, object) { - static_cast(object)->resume(); + ((CCTween *)object)->resume(); } - ProcessBase::resume(); + CCProcessBase::resume(); } -void ArmatureAnimation::stop() +void CCArmatureAnimation::stop() { Object *object = NULL; - CCARRAY_FOREACH(_tweenList, object) + CCARRAY_FOREACH(m_pTweenList, object) { - static_cast(object)->stop(); + ((CCTween *)object)->stop(); } - _tweenList->removeAllObjects(); - ProcessBase::stop(); + m_pTweenList->removeAllObjects(); + CCProcessBase::stop(); } -void ArmatureAnimation::setAnimationScale(float animationScale ) +void CCArmatureAnimation::setAnimationScale(float animationScale ) { - if(animationScale == _animationScale) + setSpeedScale(animationScale); +} + +float CCArmatureAnimation::getAnimationScale() const +{ + return getSpeedScale(); +} + + +void CCArmatureAnimation::setSpeedScale(float speedScale) +{ + if(speedScale == m_fSpeedScale) { return; } - _animationScale = animationScale; + m_fSpeedScale = speedScale; + + m_fProcessScale = !m_pMovementData ? m_fSpeedScale : m_fSpeedScale * m_pMovementData->scale; DictElement *element = NULL; - Dictionary *dict = _armature->getBoneDic(); + Dictionary *dict = m_pArmature->getBoneDic(); CCDICT_FOREACH(dict, element) { - Bone *bone = (Bone *)element->getObject(); - bone->getTween()->setAnimationScale(_animationScale); + CCBone *bone = (CCBone *)element->getObject(); + + bone->getTween()->setProcessScale(m_fProcessScale); if (bone->getChildArmature()) { - bone->getChildArmature()->getAnimation()->setAnimationScale(_animationScale); + bone->getChildArmature()->getAnimation()->setProcessScale(m_fProcessScale); + } + } +} + +float CCArmatureAnimation::getSpeedScale() const +{ + return m_fSpeedScale; +} + +void CCArmatureAnimation::setAnimationInternal(float animationInternal) +{ + if(animationInternal == m_fAnimationInternal) + { + return; + } + + m_fAnimationInternal = animationInternal; + + DictElement *element = NULL; + Dictionary *dict = m_pArmature->getBoneDic(); + CCDICT_FOREACH(dict, element) + { + CCBone *bone = (CCBone *)element->getObject(); + bone->getTween()->setAnimationInternal(m_fAnimationInternal); + if (bone->getChildArmature()) + { + bone->getChildArmature()->getAnimation()->setAnimationInternal(m_fAnimationInternal); } } } -void ArmatureAnimation::play(const char *animationName, int durationTo, int durationTween, int loop, int tweenEasing) +void CCArmatureAnimation::play(const char *animationName, int durationTo, int durationTween, int loop, int tweenEasing) { - CCASSERT(_animationData, "_animationData can not be null"); + CCAssert(m_pAnimationData, "m_pAnimationData can not be null"); - _movementData = _animationData->getMovement(animationName); - CCASSERT(_movementData, "_movementData can not be null"); + m_pMovementData = m_pAnimationData->getMovement(animationName); + CCAssert(m_pMovementData, "m_pMovementData can not be null"); //! Get key frame count - _rawDuration = _movementData->duration; + m_iRawDuration = m_pMovementData->duration; - _movementID = animationName; + m_strMovementID = animationName; + + m_fProcessScale = m_fSpeedScale * m_pMovementData->scale; //! Further processing parameters - durationTo = (durationTo == -1) ? _movementData->durationTo : durationTo; + durationTo = (durationTo == -1) ? m_pMovementData->durationTo : durationTo; - durationTween = (durationTween == -1) ? _movementData->durationTween : durationTween; - durationTween = (durationTween == 0) ? _movementData->duration : durationTween; + durationTween = (durationTween == -1) ? m_pMovementData->durationTween : durationTween; + durationTween = (durationTween == 0) ? m_pMovementData->duration : durationTween; - tweenEasing = (tweenEasing == TWEEN_EASING_MAX) ? _movementData->tweenEasing : tweenEasing; - loop = (loop < 0) ? _movementData->loop : loop; + tweenEasing = (tweenEasing == TWEEN_EASING_MAX) ? m_pMovementData->tweenEasing : tweenEasing; + loop = (loop < 0) ? m_pMovementData->loop : loop; - ProcessBase::play((void *)animationName, durationTo, durationTween, loop, tweenEasing); + CCProcessBase::play((void *)animationName, durationTo, durationTween, loop, tweenEasing); - if (_rawDuration == 1) + if (m_iRawDuration == 0) { - _loopType = SINGLE_FRAME; + m_eLoopType = SINGLE_FRAME; } else { if (loop) { - _loopType = ANIMATION_TO_LOOP_FRONT; + m_eLoopType = ANIMATION_TO_LOOP_FRONT; } else { - _loopType = ANIMATION_NO_LOOP; - _rawDuration --; + m_eLoopType = ANIMATION_NO_LOOP; + m_iRawDuration --; } - _durationTween = durationTween; + m_iDurationTween = durationTween; } - MovementBoneData *movementBoneData = NULL; - _tweenList->removeAllObjects(); + CCMovementBoneData *movementBoneData = NULL; + m_pTweenList->removeAllObjects(); DictElement *element = NULL; - Dictionary *dict = _armature->getBoneDic(); + Dictionary *dict = m_pArmature->getBoneDic(); CCDICT_FOREACH(dict, element) { - Bone *bone = (Bone *)element->getObject(); - movementBoneData = (MovementBoneData *)_movementData->movBoneDataDic->objectForKey(bone->getName()); + CCBone *bone = (CCBone *)element->getObject(); + movementBoneData = (CCMovementBoneData *)m_pMovementData->movBoneDataDic.objectForKey(bone->getName()); - Tween *tween = bone->getTween(); - if(movementBoneData && movementBoneData->frameList->count() > 0) + CCTween *tween = bone->getTween(); + if(movementBoneData && movementBoneData->frameList.count() > 0) { - _tweenList->addObject(tween); + m_pTweenList->addObject(tween); + movementBoneData->duration = m_pMovementData->duration; tween->play(movementBoneData, durationTo, durationTween, loop, tweenEasing); - tween->setAnimationScale(_animationScale); + tween->setProcessScale(m_fProcessScale); + tween->setAnimationInternal(m_fAnimationInternal); + if (bone->getChildArmature()) { - bone->getChildArmature()->getAnimation()->setAnimationScale(_animationScale); + bone->getChildArmature()->getAnimation()->setProcessScale(m_fProcessScale); + bone->getChildArmature()->getAnimation()->setAnimationInternal(m_fAnimationInternal); } } else @@ -212,14 +266,12 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura } } - - //_armature->update(0); } -void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int durationTween, int loop, int tweenEasing) +void CCArmatureAnimation::playByIndex(int animationIndex, int durationTo, int durationTween, int loop, int tweenEasing) { - std::vector &movName = _animationData->movementNames; + std::vector &movName = m_pAnimationData->movementNames; CC_ASSERT((animationIndex > -1) && ((unsigned int)animationIndex < movName.size())); std::string animationName = movName.at(animationIndex); @@ -228,41 +280,44 @@ void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int dura -int ArmatureAnimation::getMovementCount() +int CCArmatureAnimation::getMovementCount() { - return _animationData->getMovementCount(); + return m_pAnimationData->getMovementCount(); } -void ArmatureAnimation::update(float dt) +void CCArmatureAnimation::update(float dt) { - ProcessBase::update(dt); + CCProcessBase::update(dt); Object *object = NULL; - CCARRAY_FOREACH(_tweenList, object) + CCARRAY_FOREACH(m_pTweenList, object) { - static_cast(object)->update(dt); + ((CCTween *)object)->update(dt); } } -void ArmatureAnimation::updateHandler() +void CCArmatureAnimation::updateHandler() { - if (_currentPercent >= 1) + if (m_fCurrentPercent >= 1) { - switch(_loopType) + switch(m_eLoopType) { case ANIMATION_NO_LOOP: { - _loopType = ANIMATION_MAX; - _currentFrame = (_currentPercent - 1) * _nextFrameIndex; - _currentPercent = _currentFrame / _durationTween; + m_eLoopType = ANIMATION_MAX; + m_fCurrentFrame = (m_fCurrentPercent - 1) * m_iNextFrameIndex; + m_fCurrentPercent = m_fCurrentFrame / m_iDurationTween; - if (_currentPercent >= 1.0f) + if (m_fCurrentPercent >= 1.0f) { } else { - _nextFrameIndex = _durationTween; + m_iNextFrameIndex = m_iDurationTween; - MovementEventSignal.emit(_armature, START, _movementID.c_str()); + if (m_sMovementEventTarget && m_sMovementEventCallFunc) + { + (m_sMovementEventTarget->*m_sMovementEventCallFunc)(m_pArmature, START, m_strMovementID.c_str()); + } break; } @@ -271,47 +326,81 @@ void ArmatureAnimation::updateHandler() case ANIMATION_MAX: case SINGLE_FRAME: { - _currentPercent = 1; - _isComplete = true; + m_fCurrentPercent = 1; + m_bIsComplete = true; + m_bIsPlaying = false; - MovementEventSignal.emit(_armature, COMPLETE, _movementID.c_str()); + if (m_sMovementEventTarget && m_sMovementEventCallFunc) + { + (m_sMovementEventTarget->*m_sMovementEventCallFunc)(m_pArmature, COMPLETE, m_strMovementID.c_str()); + } } break; case ANIMATION_TO_LOOP_FRONT: { - _loopType = ANIMATION_LOOP_FRONT; - _currentPercent = fmodf(_currentPercent, 1); - _currentFrame = fmodf(_currentFrame, _nextFrameIndex); - _nextFrameIndex = _durationTween > 0 ? _durationTween : 1; + m_eLoopType = ANIMATION_LOOP_FRONT; + m_fCurrentPercent = fmodf(m_fCurrentPercent, 1); + m_fCurrentFrame = m_iNextFrameIndex == 0 ? 0 : fmodf(m_fCurrentFrame, m_iNextFrameIndex); + m_iNextFrameIndex = m_iDurationTween > 0 ? m_iDurationTween : 1; - MovementEventSignal.emit(_armature, START, _movementID.c_str()); + if (m_sMovementEventTarget && m_sMovementEventCallFunc) + { + (m_sMovementEventTarget->*m_sMovementEventCallFunc)(m_pArmature, START, m_strMovementID.c_str()); + } } break; default: { - _currentPercent = fmodf(_currentPercent, 1); - _currentFrame = fmodf(_currentFrame, _nextFrameIndex); - _toIndex = 0; + //m_fCurrentPercent = fmodf(m_fCurrentPercent, 1); + m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); + m_iToIndex = 0; - MovementEventSignal.emit(_armature, LOOP_COMPLETE, _movementID.c_str()); + if (m_sMovementEventTarget && m_sMovementEventCallFunc) + { + (m_sMovementEventTarget->*m_sMovementEventCallFunc)(m_pArmature, LOOP_COMPLETE, m_strMovementID.c_str()); + } } break; } } +} - if (_loopType == ANIMATION_LOOP_FRONT || _loopType == ANIMATION_LOOP_BACK) +std::string CCArmatureAnimation::getCurrentMovementID() +{ + if (m_bIsComplete) { - updateFrameData(_currentPercent); + return ""; + } + return m_strMovementID; +} + +void CCArmatureAnimation::setMovementEventCallFunc(Object *target, SEL_MovementEventCallFunc callFunc) +{ + if (target != m_sMovementEventTarget) + { + CC_SAFE_RETAIN(target); + CC_SAFE_RELEASE_NULL(m_sMovementEventTarget); + m_sMovementEventTarget = target; + } + m_sMovementEventCallFunc = callFunc; +} + +void CCArmatureAnimation::setFrameEventCallFunc(Object *target, SEL_FrameEventCallFunc callFunc) +{ + if (target != m_sFrameEventTarget) + { + CC_SAFE_RETAIN(target); + CC_SAFE_RELEASE_NULL(m_sFrameEventTarget); + m_sFrameEventTarget = target; + } + m_sFrameEventCallFunc = callFunc; +} + +void CCArmatureAnimation::frameEvent(CCBone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex) +{ + if (m_sFrameEventTarget && m_sFrameEventCallFunc) + { + (m_sFrameEventTarget->*m_sFrameEventCallFunc)(bone, frameEventName, originFrameIndex, currentFrameIndex); } } - - -void ArmatureAnimation::updateFrameData(float currentPercent) -{ - _prevFrameIndex = _curFrameIndex; - _curFrameIndex = _rawDuration * currentPercent; - _curFrameIndex = _curFrameIndex % _rawDuration; -} - - -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h index dc4bbe47e6..842c7314e5 100644 --- a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h +++ b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h @@ -27,45 +27,62 @@ THE SOFTWARE. #define __CCANIMATION_H__ #include "CCProcessBase.h" -#include "../external_tool/sigslot.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN enum MovementEventType { - START, - COMPLETE, - LOOP_COMPLETE + START, + COMPLETE, + LOOP_COMPLETE }; -class Armature; -class Bone; +class CCArmature; +class CCBone; -class ArmatureAnimation : public ProcessBase +typedef void (Object::*SEL_MovementEventCallFunc)(CCArmature *, MovementEventType, const char *); +typedef void (Object::*SEL_FrameEventCallFunc)(CCBone *, const char *, int, int); + +#define movementEvent_selector(_SELECTOR) (SEL_MovementEventCallFunc)(&_SELECTOR) +#define frameEvent_selector(_SELECTOR) (SEL_FrameEventCallFunc)(&_SELECTOR) + + +class CCArmatureAnimation : public CCProcessBase { public: /** - * Create with a Armature - * @param armature The Armature ArmatureAnimation will bind to + * Create with a CCArmature + * @param armature The CCArmature CCArmatureAnimation will bind to */ - static ArmatureAnimation *create(Armature *armature); + static CCArmatureAnimation *create(CCArmature *armature); public: - ArmatureAnimation(); - virtual ~ArmatureAnimation(void); + CCArmatureAnimation(); + virtual ~CCArmatureAnimation(void); /** - * Init with a Armature - * @param armature The Armature ArmatureAnimation will bind to + * Init with a CCArmature + * @param armature The CCArmature CCArmatureAnimation will bind to */ - virtual bool init(Armature *armature); + virtual bool init(CCArmature *armature); /** * Scale animation play speed. * @param animationScale Scale value */ virtual void setAnimationScale(float animationScale); + virtual float getAnimationScale() const; + + /** + * Scale animation play speed. + * @param animationScale Scale value + */ + virtual void setSpeedScale(float speedScale); + virtual float getSpeedScale() const; + + //! The animation update speed + virtual void setAnimationInternal(float animationInternal); /** * Play animation by animation name. @@ -74,21 +91,21 @@ public: * @param durationTo The frames between two animation changing-over. * It's meaning is changing to this animation need how many frames * - * -1 : use the value from MovementData get from flash design panel + * -1 : use the value from CCMovementData get from flash design panel * @param durationTween The frame count you want to play in the game. * if _durationTween is 80, then the animation will played 80 frames in a loop * - * -1 : use the value from MovementData get from flash design panel + * -1 : use the value from CCMovementData get from flash design panel * * @param loop Whether the animation is loop * - * loop < 0 : use the value from MovementData get from flash design panel + * loop < 0 : use the value from CCMovementData get from flash design panel * loop = 0 : this animation is not loop * loop > 0 : this animation is loop * - * @param tweenEasing Tween easing is used for calculate easing effect + * @param tweenEasing CCTween easing is used for calculate easing effect * - * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel + * TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel * -1 : fade out * 0 : line * 1 : fade in @@ -99,7 +116,7 @@ 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); @@ -123,6 +140,25 @@ public: int getMovementCount(); void update(float dt); + + /** + * Get current movementID + * @return The name of current movement + */ + std::string getCurrentMovementID(); + + /** + * Set armature's movement event callback function + * To disconnect this event, just setMovementEventCallFunc(NULL, NULL); + */ + void setMovementEventCallFunc(Object *target, SEL_MovementEventCallFunc callFunc); + + /** + * Set armature's frame event callback function + * To disconnect this event, just setFrameEventCallFunc(NULL, NULL); + */ + void setFrameEventCallFunc(Object *target, SEL_FrameEventCallFunc callFunc); + protected: /** @@ -135,31 +171,52 @@ protected: */ void updateFrameData(float currentPercent); -protected: - //! AnimationData save all MovementDatas this animation used. - CC_SYNTHESIZE_RETAIN(AnimationData *, _animationData, AnimationData); - - - MovementData *_movementData; //! MovementData save all MovementFrameDatas this animation used. - - Armature *_armature; //! A weak reference of armature - - std::string _movementID; //! Current movment's name - - int _prevFrameIndex; //! Prev key frame index - int _toIndex; //! The frame index in MovementData->_movFrameDataArr, it's different from _frameIndex. - - Array *_tweenList; -public: /** - * MovementEvent signal. This will emit a signal when trigger a event. - * The 1st param is the Armature. The 2nd param is Event Type, like START, COMPLETE. The 3rd param is Movement ID, also called Movement Name. + * Emit a frame event */ - sigslot::signal3 MovementEventSignal; + void frameEvent(CCBone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex); - sigslot::signal2 FrameEventSignal; + friend class CCTween; +protected: + //! CCAnimationData save all MovementDatas this animation used. + CC_SYNTHESIZE_RETAIN(CCAnimationData *, m_pAnimationData, AnimationData); + + //! Scale the animation speed + float m_fSpeedScale; + + CCMovementData *m_pMovementData; //! CCMovementData save all MovementFrameDatas this animation used. + + CCArmature *m_pArmature; //! A weak reference of armature + + std::string m_strMovementID; //! Current movment's name + + int m_iToIndex; //! The frame index in CCMovementData->m_pMovFrameDataArr, it's different from m_iFrameIndex. + + Array *m_pTweenList; + +protected: + /** + * MovementEvent CallFunc. + * @param CCArmature* a CCArmature + * @param MovementEventType, Event Type, like START, COMPLETE. + * @param const char*, Movement ID, also called Movement Name + */ + SEL_MovementEventCallFunc m_sMovementEventCallFunc; + + /** + * FrameEvent CallFunc. + * @param CCBone*, a CCBone + * @param const char*, the name of this frame event + * @param int, origin frame index + * @param int, current frame index, animation may be delayed + */ + SEL_FrameEventCallFunc m_sFrameEventCallFunc; + + + Object *m_sMovementEventTarget; + Object *m_sFrameEventTarget; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCANIMATION_H__*/ diff --git a/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp b/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp index 46fe9032fd..8a00148fd1 100644 --- a/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp +++ b/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp @@ -25,121 +25,128 @@ THE SOFTWARE. #include "CCProcessBase.h" #include "../utils/CCUtilMath.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -ProcessBase::ProcessBase(void) - : _animationScale(1) - , _isPause(true) - , _isComplete(true) - , _isPlaying(false) - , _currentPercent(0.0f) - , _rawDuration(0) - , _loopType(ANIMATION_LOOP_BACK) - , _tweenEasing(Linear) - , _durationTween(0) - , _currentFrame(0) - , _curFrameIndex(0) - , _isLoopBack(false) +CCProcessBase::CCProcessBase(void) + : m_fProcessScale(1) + , m_bIsPause(true) + , m_bIsComplete(true) + , m_bIsPlaying(false) + , m_fCurrentPercent(0.0f) + , m_iRawDuration(0) + , m_eLoopType(ANIMATION_LOOP_BACK) + , m_eTweenEasing(Linear) + , m_iDurationTween(0) + , m_fCurrentFrame(0) + , m_iCurFrameIndex(0) + , m_bIsLoopBack(false) { /* - * set _animationInternal defualt value to Director::getInstance() + * set m_fAnimationInternal defualt value to CCDirector::sharedDirector() * ->getAnimationInterval(), in line with game update speed */ - _animationInternal = Director::getInstance()->getAnimationInterval(); + m_fAnimationInternal = CCDirector::sharedDirector()->getAnimationInterval(); } -ProcessBase::~ProcessBase(void) +CCProcessBase::~CCProcessBase(void) { } -void ProcessBase::pause() +void CCProcessBase::pause() { - _isPause = true; + m_bIsPause = true; + m_bIsPlaying = false; } -void ProcessBase::resume() +void CCProcessBase::resume() { - _isPause = false; + m_bIsPause = false; + m_bIsPlaying = true; } -void ProcessBase::stop() +void CCProcessBase::stop() { - _isComplete = true; - _currentFrame = 0; - _currentPercent = 0; + m_bIsComplete = true; + m_bIsPlaying = false; + m_fCurrentFrame = 0; + m_fCurrentPercent = 0; } -void ProcessBase::play(void *animation, int durationTo, int durationTween, int loop, int tweenEasing) +void CCProcessBase::play(void *animation, int durationTo, int durationTween, int loop, int tweenEasing) { - _isComplete = false; - _isPause = false; - _isPlaying = true; - _currentFrame = 0; + m_bIsComplete = false; + m_bIsPause = false; + m_bIsPlaying = true; + m_fCurrentFrame = 0; /* - * Set _totalFrames to durationTo, it is used for change tween between two animation. - * When changing end, _totalFrames will be setted to _durationTween + * Set m_iTotalFrames to durationTo, it is used for change tween between two animation. + * When changing end, m_iTotalFrames will be setted to _durationTween */ - _nextFrameIndex = durationTo; - _tweenEasing = (TweenType)tweenEasing; + m_iNextFrameIndex = durationTo; + m_eTweenEasing = (CCTweenType)tweenEasing; } -void ProcessBase::update(float dt) +void CCProcessBase::update(float dt) { - if (_isComplete || _isPause) + if (m_bIsComplete || m_bIsPause) { return; } /* - * Fileter the _duration <=0 and dt >1 + * Fileter the m_iDuration <=0 and dt >1 * If dt>1, generally speaking the reason is the device is stuck. */ - if(_rawDuration <= 0 || dt > 1) + if(m_iRawDuration <= 0 || dt > 1) { return; } - if (_nextFrameIndex <= 0) + if (m_iNextFrameIndex <= 0) { - _currentFrame = _nextFrameIndex = 1; + m_fCurrentPercent = 1; + m_fCurrentFrame = 0; } - - /* - * update _currentFrame, every update add the frame passed. - * dt/_animationInternal determine it is not a frame animation. If frame speed changed, it will not make our - * animation speed slower or quicker. - */ - _currentFrame += _animationScale * (dt / _animationInternal); + else + { + /* + * update m_fCurrentFrame, every update add the frame passed. + * dt/m_fAnimationInternal determine it is not a frame animation. If frame speed changed, it will not make our + * animation speed slower or quicker. + */ + m_fCurrentFrame += m_fProcessScale * (dt / m_fAnimationInternal); - _currentPercent = _currentFrame / _nextFrameIndex; + m_fCurrentPercent = m_fCurrentFrame / m_iNextFrameIndex; - /* - * if _currentFrame is bigger or equal than _totalFrames, then reduce it util _currentFrame is - * smaller than _totalFrames - */ - _currentFrame = fmodf(_currentFrame, _nextFrameIndex); + /* + * if m_fCurrentFrame is bigger or equal than m_iTotalFrames, then reduce it util m_fCurrentFrame is + * smaller than m_iTotalFrames + */ + m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); + } updateHandler(); } -void ProcessBase::gotoFrame(int frameIndex) +void CCProcessBase::gotoFrame(int frameIndex) { - _curFrameIndex = frameIndex; - stop(); + m_iCurFrameIndex = frameIndex; + pause(); } -int ProcessBase::getCurrentFrameIndex() +int CCProcessBase::getCurrentFrameIndex() { - return _curFrameIndex; + m_iCurFrameIndex = m_iRawDuration * m_fCurrentPercent; + return m_iCurFrameIndex; } -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/animation/CCProcessBase.h b/extensions/CocoStudio/Armature/animation/CCProcessBase.h index c0fabb7e1e..c9cf08b8cc 100644 --- a/extensions/CocoStudio/Armature/animation/CCProcessBase.h +++ b/extensions/CocoStudio/Armature/animation/CCProcessBase.h @@ -29,7 +29,7 @@ THE SOFTWARE. #include "../utils/CCArmatureDefine.h" #include "../datas/CCDatas.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN enum AnimationType { @@ -47,34 +47,34 @@ enum AnimationType }; -class ProcessBase : public Object +class CCProcessBase : public Object { public: - ProcessBase(void); - ~ProcessBase(void); + CCProcessBase(void); + ~CCProcessBase(void); /** * Play animation by animation name. * - * @param animation It will not used in the ProcessBase Class + * @param animation It will not used in the CCProcessBase Class * @param durationTo The frames between two animation changing-over. * It's meaning is changing to this animation need how many frames * - * -1 : use the value from MovementData get from flash design panel + * -1 : use the value from CCMovementData get from flash design panel * @param durationTween The frame count you want to play in the game. * if _durationTween is 80, then the animation will played 80 frames in a loop * - * -1 : use the value from MovementData get from flash design panel + * -1 : use the value from CCMovementData get from flash design panel * * @param loop Whether the animation is loop * - * loop < 0 : use the value from MovementData get from flash design panel + * loop < 0 : use the value from CCMovementData get from flash design panel * loop = 0 : this animation is not loop * loop > 0 : this animation is loop * - * @param tweenEasing Tween easing is used for calculate easing effect + * @param tweenEasing CCTween easing is used for calculate easing effect * - * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel + * TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel * -1 : fade out * 0 : line * 1 : fade in @@ -103,7 +103,7 @@ public: * You should never call this function, unless you know what you do * Update the Process, include current process, current frame and son on * - * @param dt The duration since last update + * @param The duration since last update */ virtual void update(float dt); @@ -118,50 +118,50 @@ protected: virtual void updateHandler() {}; protected: - //! Scale the animation speed - CC_SYNTHESIZE_PASS_BY_REF(float, _animationScale, AnimationScale); + //! Scale the process speed + CC_SYNTHESIZE(float, m_fProcessScale, ProcessScale); //! Set and get whether the aniamtion is pause - CC_SYNTHESIZE_PASS_BY_REF(bool, _isPause, IsPause); + CC_SYNTHESIZE(bool, m_bIsPause, IsPause); //! Set and get whether the aniamtion is complete - CC_SYNTHESIZE_PASS_BY_REF(bool, _isComplete, IsComplete); + CC_SYNTHESIZE(bool, m_bIsComplete, IsComplete); //! Set and get whether the aniamtion is playing - CC_SYNTHESIZE_PASS_BY_REF(bool, _isPlaying, IsPlaying); + CC_SYNTHESIZE(bool, m_bIsPlaying, IsPlaying); //! Current percent this process arrived - CC_SYNTHESIZE_PASS_BY_REF(float, _currentPercent, CurrentPercent); + CC_SYNTHESIZE(float, m_fCurrentPercent, CurrentPercent); //! The raw duration - CC_SYNTHESIZE_PASS_BY_REF(int, _rawDuration, RawDuration); + CC_SYNTHESIZE(int, m_iRawDuration, RawDuration); //! The animation whether or not loop - CC_SYNTHESIZE_PASS_BY_REF(AnimationType, _loopType, LoopType); + CC_SYNTHESIZE(AnimationType, m_eLoopType, LoopType); //! The tween easing effect - CC_SYNTHESIZE_PASS_BY_REF(TweenType, _tweenEasing, TweenEasing); + CC_SYNTHESIZE(CCTweenType, m_eTweenEasing, TweenEasing); //! The animation update speed - CC_SYNTHESIZE_PASS_BY_REF(float, _animationInternal, AnimationInternal); + CC_SYNTHESIZE(float, m_fAnimationInternal, AnimationInternal); protected: //! The durantion frame count will run - int _durationTween; + int m_iDurationTween; //! Current frame this process arrived, this frame is tween frame - float _currentFrame; + float m_fCurrentFrame; //! Frame index it the time line - int _curFrameIndex; + int m_iCurFrameIndex; //! Next frame this process need run to - int _nextFrameIndex; + int m_iNextFrameIndex; - bool _isLoopBack; + bool m_bIsLoopBack; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCPROCESSBASE_H__*/ diff --git a/extensions/CocoStudio/Armature/animation/CCTween.cpp b/extensions/CocoStudio/Armature/animation/CCTween.cpp index 07ae27dded..bd0c09ba89 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.cpp +++ b/extensions/CocoStudio/Armature/animation/CCTween.cpp @@ -29,13 +29,14 @@ THE SOFTWARE. #include "../CCArmature.h" #include "../utils/CCUtilMath.h" #include "../utils/CCTweenFunction.h" +#include "../utils/CCTransformHelp.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -Tween *Tween::create(Bone *bone) +CCTween *CCTween::create(CCBone *bone) { - Tween *pTween = new Tween(); + CCTween *pTween = new CCTween(); if (pTween && pTween->init(bone)) { pTween->autorelease(); @@ -48,43 +49,43 @@ Tween *Tween::create(Bone *bone) -Tween::Tween() - : _movementBoneData(NULL) - , _tweenData(NULL) - , _from(NULL) - , _to(NULL) - , _between(NULL) - , _currentKeyFrame(NULL) - , _bone(NULL) - - , _frameTweenEasing(Linear) - , _fromIndex(0) - , _toIndex(0) - , _animation(NULL) +CCTween::CCTween() + : m_pMovementBoneData(NULL) + , m_pTweenData(NULL) + , m_pFrom(NULL) + , m_pTo(NULL) + , m_pBetween(NULL) + , m_pBone(NULL) + + , m_eFrameTweenEasing(Linear) + , m_iFromIndex(0) + , m_iToIndex(0) + , m_pAnimation(NULL) { } -Tween::~Tween(void) +CCTween::~CCTween(void) { - CC_SAFE_DELETE( _from ); - CC_SAFE_DELETE( _between ); + CC_SAFE_DELETE( m_pFrom ); + CC_SAFE_DELETE( m_pBetween ); } -bool Tween::init(Bone *bone) +bool CCTween::init(CCBone *bone) { bool bRet = false; do { - _from = new FrameData(); - _between = new FrameData(); + m_pFrom = new CCFrameData(); + m_pBetween = new CCFrameData(); - _bone = bone; - _tweenData = _bone->getTweenData(); + m_pBone = bone; + m_pTweenData = m_pBone->getTweenData(); + m_pTweenData->displayIndex = -1; - _animation = _bone->getArmature() != NULL ? _bone->getArmature()->getAnimation() : NULL; + m_pAnimation = m_pBone->getArmature() != NULL ? m_pBone->getArmature()->getAnimation() : NULL; bRet = true; } @@ -94,200 +95,201 @@ bool Tween::init(Bone *bone) } -void Tween::play(MovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing) +void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing) { - ProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing); + CCProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing); - _loopType = (AnimationType)loop; + m_eLoopType = (AnimationType)loop; - _currentKeyFrame = NULL; - _isTweenKeyFrame = false; + m_iTotalDuration = 0; + m_iBetweenDuration = 0; + m_iFromIndex = m_iToIndex = 0; - _totalDuration = 0; - betweenDuration = 0; - _toIndex = 0; + bool difMovement = movementBoneData != m_pMovementBoneData; setMovementBoneData(movementBoneData); + m_iRawDuration = m_pMovementBoneData->duration; + CCFrameData *nextKeyFrame = m_pMovementBoneData->getFrameData(0); + m_pTweenData->displayIndex = nextKeyFrame->displayIndex; - if (_movementBoneData->frameList->count() == 1) + if (m_pBone->getArmature()->getArmatureData()->dataVersion >= VERSION_COMBINED) { - _loopType = SINGLE_FRAME; - FrameData *_nextKeyFrame = _movementBoneData->getFrameData(0); + CCTransformHelp::nodeSub(*m_pTweenData, *m_pBone->getBoneData()); + m_pTweenData->scaleX += 1; + m_pTweenData->scaleY += 1; + } + + if (m_iRawDuration == 0 ) + { + m_eLoopType = SINGLE_FRAME; if(durationTo == 0) { - setBetween(_nextKeyFrame, _nextKeyFrame); + setBetween(nextKeyFrame, nextKeyFrame); } else { - _tweenData->displayIndex = _nextKeyFrame->displayIndex; - setBetween(_tweenData, _nextKeyFrame); + setBetween(m_pTweenData, nextKeyFrame); } - _isTweenKeyFrame = true; - _frameTweenEasing = Linear; - _rawDuration = _movementBoneData->duration; - _fromIndex = _toIndex = 0; + m_eFrameTweenEasing = Linear; } - else if (_movementBoneData->frameList->count() > 1) + else if (m_pMovementBoneData->frameList.count() > 1) { if (loop) { - _loopType = ANIMATION_TO_LOOP_BACK; - _rawDuration = _movementBoneData->duration; + m_eLoopType = ANIMATION_TO_LOOP_BACK; } else { - _loopType = ANIMATION_NO_LOOP; - _rawDuration = _movementBoneData->duration - 1; + m_eLoopType = ANIMATION_NO_LOOP; } - _durationTween = durationTween * _movementBoneData->scale; + m_iDurationTween = durationTween * m_pMovementBoneData->scale; - if (loop && _movementBoneData->delay != 0) + if (loop && m_pMovementBoneData->delay != 0) { - setBetween(_tweenData, tweenNodeTo(updateFrameData(1 - _movementBoneData->delay), _between)); - + setBetween(m_pTweenData, tweenNodeTo(updateFrameData(1 - m_pMovementBoneData->delay), m_pBetween)); } else { - FrameData *_nextKeyFrame = _movementBoneData->getFrameData(0); - setBetween(_tweenData, _nextKeyFrame); - _isTweenKeyFrame = true; + if (!difMovement || durationTo == 0) + { + setBetween(nextKeyFrame, nextKeyFrame); + } + else + { + setBetween(m_pTweenData, nextKeyFrame); + } } } + + tweenNodeTo(0); } -void Tween::updateHandler() +void CCTween::updateHandler() { - - - if (_currentPercent >= 1) + if (m_fCurrentPercent >= 1) { - switch(_loopType) + switch(m_eLoopType) { case SINGLE_FRAME: { - _currentPercent = 1; - _isComplete = true; + m_fCurrentPercent = 1; + m_bIsComplete = true; + m_bIsPlaying = false; } break; case ANIMATION_NO_LOOP: { - _loopType = ANIMATION_MAX; + m_eLoopType = ANIMATION_MAX; - if (_durationTween <= 0) + if (m_iDurationTween <= 0) { - _currentPercent = 1; + m_fCurrentPercent = 1; } else { - _currentPercent = (_currentPercent - 1) * _nextFrameIndex / _durationTween; + m_fCurrentPercent = (m_fCurrentPercent - 1) * m_iNextFrameIndex / m_iDurationTween; } - if (_currentPercent >= 1) + if (m_fCurrentPercent >= 1) { - _currentPercent = 1; - _isComplete = true; + m_fCurrentPercent = 1; + m_bIsComplete = true; + m_bIsPlaying = false; break; } else { - _nextFrameIndex = _durationTween; - _currentFrame = _currentPercent * _nextFrameIndex; - _totalDuration = 0; - betweenDuration = 0; - _toIndex = 0; + m_iNextFrameIndex = m_iDurationTween; + m_fCurrentFrame = m_fCurrentPercent * m_iNextFrameIndex; + m_iTotalDuration = 0; + m_iBetweenDuration = 0; + m_iFromIndex = m_iToIndex = 0; break; } } break; case ANIMATION_TO_LOOP_BACK: { - _loopType = ANIMATION_LOOP_BACK; + m_eLoopType = ANIMATION_LOOP_BACK; - _nextFrameIndex = _durationTween > 0 ? _durationTween : 1; + m_iNextFrameIndex = m_iDurationTween > 0 ? m_iDurationTween : 1; - if (_movementBoneData->delay != 0) + if (m_pMovementBoneData->delay != 0) { // - _currentFrame = (1 - _movementBoneData->delay) * (float)_nextFrameIndex; - _currentPercent = _currentFrame / _nextFrameIndex; - - + m_fCurrentFrame = (1 - m_pMovementBoneData->delay) * (float)m_iNextFrameIndex; + m_fCurrentPercent = m_fCurrentFrame / m_iNextFrameIndex; } else { - _currentPercent = 0; - _currentFrame = 0; + m_fCurrentPercent = 0; + m_fCurrentFrame = 0; } - _totalDuration = 0; - betweenDuration = 0; - _toIndex = 0; + m_iTotalDuration = 0; + m_iBetweenDuration = 0; + m_iFromIndex = m_iToIndex = 0; } break; case ANIMATION_MAX: { - _currentPercent = 1; - _isComplete = true; + m_fCurrentPercent = 1; + m_bIsComplete = true; + m_bIsPlaying = false; } break; default: { - _currentPercent = fmodf(_currentPercent, 1); - _currentFrame = fmodf(_currentFrame, _nextFrameIndex); + m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); - _totalDuration = 0; - betweenDuration = 0; - _toIndex = 0; + m_iTotalDuration = 0; + m_iBetweenDuration = 0; + m_iFromIndex = m_iToIndex = 0; } break; } } - - if (_currentPercent < 1 && _loopType <= ANIMATION_TO_LOOP_BACK) + if (m_fCurrentPercent < 1 && m_eLoopType <= ANIMATION_TO_LOOP_BACK) { - _currentPercent = sin(_currentPercent * CC_HALF_PI); + m_fCurrentPercent = sin(m_fCurrentPercent * CC_HALF_PI); } - float percent = _currentPercent; + float percent = m_fCurrentPercent; - if (_loopType > ANIMATION_TO_LOOP_BACK) + if (m_eLoopType > ANIMATION_TO_LOOP_BACK) { - percent = updateFrameData(percent, true); + percent = updateFrameData(percent); } - if(_frameTweenEasing != TWEEN_EASING_MAX) + if(m_eFrameTweenEasing != TWEEN_EASING_MAX) { tweenNodeTo(percent); } - else if(_currentKeyFrame) - { - tweenNodeTo(0); - } } -void Tween::setBetween(FrameData *from, FrameData *to) +void CCTween::setBetween(CCFrameData *from, CCFrameData *to) { do { - if(to->displayIndex < 0 && from->displayIndex > 0) + if(from->displayIndex < 0 && to->displayIndex >= 0) { - _from->copy(from); - _between->subtract(to, to); + m_pFrom->copy(to); + m_pBetween->subtract(to, to); break; } - else if(from->displayIndex < 0 && to->displayIndex > 0) + else if(to->displayIndex < 0 && from->displayIndex >= 0) { - _from->copy(to); - _between->subtract(to, to); + m_pFrom->copy(from); + m_pBetween->subtract(to, to); break; } - _from->copy(from); - _between->subtract(from, to); + m_pFrom->copy(from); + m_pBetween->subtract(from, to); } while (0); @@ -295,145 +297,158 @@ void Tween::setBetween(FrameData *from, FrameData *to) } -void Tween::arriveKeyFrame(FrameData *keyFrameData) +void CCTween::arriveKeyFrame(CCFrameData *keyFrameData) { if(keyFrameData) { + CCDisplayManager *displayManager = m_pBone->getDisplayManager(); + + //! Change bone's display int displayIndex = keyFrameData->displayIndex; - if (!_bone->getDisplayManager()->getForceChangeDisplay()) + if (!displayManager->getForceChangeDisplay()) { - _bone->getDisplayManager()->changeDisplayByIndex(displayIndex, false); + displayManager->changeDisplayByIndex(displayIndex, false); } + //! Update bone zorder, bone's zorder is determined by frame zorder and bone zorder + m_pTweenData->zOrder = keyFrameData->zOrder; + m_pBone->updateZOrder(); - _bone->setZOrder(keyFrameData->zOrder); - - Armature *childAramture = _bone->getChildArmature(); + //! Update blend type + m_pBone->setBlendType(keyFrameData->blendType); + //! Update child armature's movement + CCArmature *childAramture = m_pBone->getChildArmature(); if(childAramture) { - if(keyFrameData->_movement.length() != 0) + if(keyFrameData->strMovement.length() != 0) { - childAramture->getAnimation()->play(keyFrameData->_movement.c_str()); + childAramture->getAnimation()->play(keyFrameData->strMovement.c_str()); } } - - if(keyFrameData->_event.length() != 0) - { - _animation->FrameEventSignal.emit(_bone, keyFrameData->_event.c_str()); - } - // if(keyFrameData->_sound.length() != 0) - // { - // //soundManager.dispatchEventWith(Event.SOUND_FRAME, _currentKeyFrame->sound); - // } } } - -FrameData *Tween::tweenNodeTo(float percent, FrameData *node) +CCFrameData *CCTween::tweenNodeTo(float percent, CCFrameData *node) { + node = node == NULL ? m_pTweenData : node; - node = node == NULL ? _tweenData : node; + node->x = m_pFrom->x + percent * m_pBetween->x; + node->y = m_pFrom->y + percent * m_pBetween->y; + node->scaleX = m_pFrom->scaleX + percent * m_pBetween->scaleX; + node->scaleY = m_pFrom->scaleY + percent * m_pBetween->scaleY; + node->skewX = m_pFrom->skewX + percent * m_pBetween->skewX; + node->skewY = m_pFrom->skewY + percent * m_pBetween->skewY; - node->x = _from->x + percent * _between->x; - node->y = _from->y + percent * _between->y; - node->scaleX = _from->scaleX + percent * _between->scaleX; - node->scaleY = _from->scaleY + percent * _between->scaleY; - node->skewX = _from->skewX + percent * _between->skewX; - node->skewY = _from->skewY + percent * _between->skewY; + m_pBone->setTransformDirty(true); - _bone->setTransformDirty(true); - - if(_between->isUseColorInfo) + if (node && m_pBetween->isUseColorInfo) { - node->a = _from->a + percent * _between->a; - node->r = _from->r + percent * _between->r; - node->g = _from->g + percent * _between->g; - node->b = _from->b + percent * _between->b; - _bone->updateColor(); + tweenColorTo(percent, node); } - // Point p1 = Point(_from->x, _from->y); - // Point p2 = Point(100, 0); - // Point p3 = Point(200, 400); - // Point p4 = Point(_from->x + _between->x, _from->y + _between->y); - // - // Point p = bezierTo(percent, p1, p2, p3, p4); - // node->x = p.x; - // node->y = p.y; - return node; } -float Tween::updateFrameData(float currentPrecent, bool activeFrame) +void CCTween::tweenColorTo(float percent, CCFrameData *node) { + node->a = m_pFrom->a + percent * m_pBetween->a; + node->r = m_pFrom->r + percent * m_pBetween->r; + node->g = m_pFrom->g + percent * m_pBetween->g; + node->b = m_pFrom->b + percent * m_pBetween->b; + m_pBone->updateColor(); +} - float playedTime = (float)_rawDuration * currentPrecent; +float CCTween::updateFrameData(float currentPercent) +{ + if (currentPercent > 1 && m_pMovementBoneData->delay != 0) + { + currentPercent = fmodf(currentPercent, 1); + } + float playedTime = (float)m_iRawDuration * currentPercent; - FrameData *from; - FrameData *to; - bool isListEnd; //! If play to current frame's front or back, then find current frame again - if (playedTime >= _totalDuration || playedTime < _totalDuration - betweenDuration) + if (playedTime < m_iTotalDuration || playedTime >= m_iTotalDuration + m_iBetweenDuration) { /* - * Get frame length, if _toIndex >= _length, then set _toIndex to 0, start anew. - * _toIndex is next index will play + * Get frame length, if m_iToIndex >= _length, then set m_iToIndex to 0, start anew. + * m_iToIndex is next index will play */ - int length = _movementBoneData->frameList->count(); + int length = m_pMovementBoneData->frameList.count(); + CCFrameData **frames = (CCFrameData **)m_pMovementBoneData->frameList.data->arr; + + CCFrameData *from = NULL; + CCFrameData *to = NULL; + + if (playedTime < frames[0]->frameID) + { + from = to = frames[0]; + setBetween(from, to); + return currentPercent; + } + else if(playedTime >= frames[length - 1]->frameID) + { + from = to = frames[length - 1]; + setBetween(from, to); + return currentPercent; + } + + do { - betweenDuration = _movementBoneData->getFrameData(_toIndex)->duration; - _totalDuration += betweenDuration; - _fromIndex = _toIndex; + from = frames[m_iFromIndex]; + m_iTotalDuration = from->frameID; - if (++_toIndex >= length) + if (++m_iToIndex >= length) { - _toIndex = 0; + m_iToIndex = 0; + } + + m_iFromIndex = m_iToIndex; + to = frames[m_iToIndex]; + + //! Guaranteed to trigger frame event + if(from->strEvent.length() != 0) + { + m_pAnimation->frameEvent(m_pBone, from->strEvent.c_str(), from->frameID, playedTime); + } + + if (playedTime == from->frameID) + { + break; } } - while (playedTime >= _totalDuration); + while (playedTime < from->frameID || playedTime >= to->frameID); + m_iBetweenDuration = to->frameID - from->frameID; - isListEnd = _loopType == ANIMATION_MAX && _toIndex == 0; - - if(isListEnd) - { - to = from = _movementBoneData->getFrameData(_fromIndex); - } - else - { - from = _movementBoneData->getFrameData(_fromIndex); - to = _movementBoneData->getFrameData(_toIndex); - } - - _frameTweenEasing = from->tweenEasing; + m_eFrameTweenEasing = from->tweenEasing; setBetween(from, to); } - currentPrecent = 1 - (_totalDuration - playedTime) / (float)betweenDuration; + currentPercent = m_iBetweenDuration == 0 ? 0 : (playedTime - m_iTotalDuration) / (float)m_iBetweenDuration; /* * If frame tween easing equal to TWEEN_EASING_MAX, then it will not do tween. */ - TweenType tweenType; + CCTweenType tweenType; - if ( _frameTweenEasing != TWEEN_EASING_MAX) + if ( m_eFrameTweenEasing != TWEEN_EASING_MAX) { - tweenType = (_tweenEasing == TWEEN_EASING_MAX) ? _frameTweenEasing : _tweenEasing; - if (tweenType != TWEEN_EASING_MAX) + tweenType = (m_eTweenEasing == TWEEN_EASING_MAX) ? m_eFrameTweenEasing : m_eTweenEasing; + if (tweenType != TWEEN_EASING_MAX && tweenType != Linear) { - currentPrecent = TweenFunction::tweenTo(0, 1, currentPrecent, 1, tweenType); + currentPercent = CCTweenFunction::tweenTo(0, 1, currentPercent, 1, tweenType); } } - return currentPrecent; + return currentPercent; } -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/animation/CCTween.h b/extensions/CocoStudio/Armature/animation/CCTween.h index abe37b82ed..5570410bb0 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.h +++ b/extensions/CocoStudio/Armature/animation/CCTween.h @@ -29,61 +29,61 @@ THE SOFTWARE. #include "CCProcessBase.h" #include "../utils/CCTweenFunction.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -class Bone; -class ArmatureAnimation; +class CCBone; +class CCArmatureAnimation; -class Tween : public ProcessBase +class CCTween : public CCProcessBase { public: /** - * Create with a Bone - * @param bone the Bone Tween will bind to + * Create with a CCBone + * @param bone the CCBone CCTween will bind to */ - static Tween *create(Bone *bone); + static CCTween *create(CCBone *bone); public: - Tween(void); - virtual ~Tween(void); + CCTween(void); + virtual ~CCTween(void); /** - * Init with a Bone - * @param bone the Bone Tween will bind to + * Init with a CCBone + * @param bone the CCBone CCTween will bind to */ - virtual bool init(Bone *bone); + virtual bool init(CCBone *bone); /** * Start the Process * - * @param movementBoneData the MovementBoneData include all frame datas - * @param durationTo the frames between two animation changing-over. - * It's meaning is changing to this animation need how many frames - * - * -1 : use the value from MovementData get from flash design panel - * @param durationTween the frame count you want to play in the game. - * if _durationTween is 80, then the animation will played 80 frames in a loop - * - * -1 : use the value from MovementData get from flash design panel + * @param movementBoneData the CCMovementBoneData include all CCFrameData + * @param durationTo the number of frames changing to this animation needs. + * @param durationTween the number of frames this animation actual last. * * @param loop whether the animation is loop * - * loop < 0 : use the value from MovementData get from flash design panel + * loop < 0 : use the value from CCMovementData get from Action Editor * loop = 0 : this animation is not loop * loop > 0 : this animation is loop * * @param tweenEasing tween easing is used for calculate easing effect * - * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel + * TWEEN_EASING_MAX : use the value from CCMovementData get from Action Editor * -1 : fade out * 0 : line * 1 : fade in * 2 : fade in and out * */ - virtual void play(MovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing); + virtual void play(CCMovementBoneData *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(CCArmatureAnimation *animation) + { + m_pAnimation = animation; + } + inline CCArmatureAnimation *getAnimation() const + { + return m_pAnimation; + } protected: /** @@ -94,49 +94,52 @@ 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 currentPercent); /** * Calculate the between value of _from and _to, and give it to between frame data */ - virtual void setBetween(FrameData *from, FrameData *to); + virtual void setBetween(CCFrameData *from, CCFrameData *to); /** - * According to the percent to calculate current FrameData with tween effect + * According to the percent to calculate current CCFrameData with tween effect */ - virtual FrameData *tweenNodeTo(float percent, FrameData *node = NULL); + virtual CCFrameData *tweenNodeTo(float percent, CCFrameData *node = NULL); + + /** + * According to the percent to calculate current color with tween effect + */ + virtual void tweenColorTo(float percent, CCFrameData *node); /** * Update display index and process the key frame event when arrived a key frame */ - virtual void arriveKeyFrame(FrameData *keyFrameData); + virtual void arriveKeyFrame(CCFrameData *keyFrameData); protected: - //! A weak reference to the current MovementBoneData. The data is in the data pool - CC_SYNTHESIZE(MovementBoneData *, _movementBoneData, MovementBoneData) + //! A weak reference to the current CCMovementBoneData. The data is in the data pool + CC_SYNTHESIZE(CCMovementBoneData *, m_pMovementBoneData, 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(_node) value - - FrameData *_currentKeyFrame; //! A weak reference to the current FrameData. The data is in the data pool - - Bone *_bone; //! A weak reference to the Bone - - TweenType _frameTweenEasing; //! Dedermine which tween effect current frame use - - bool _isTweenKeyFrame; - - int betweenDuration; //! Current key frame will last betweenDuration frames - int _totalDuration; + CCFrameData *m_pTweenData; //! The computational tween frame data, //! A weak reference to the CCBone's tweenData + CCFrameData *m_pFrom; //! From frame data, used for calculate between value + CCFrameData *m_pTo; //! To frame data, used for calculate between value + CCFrameData *m_pBetween; //! Between frame data, used for calculate current CCFrameData(m_pNode) value - int _fromIndex; //! The current frame index in FrameList of MovementBoneData, it's different from _frameIndex - int _toIndex; //! The next frame index in FrameList of MovementBoneData, it's different from _frameIndex + CCBone *m_pBone; //! A weak reference to the CCBone + + CCTweenType m_eFrameTweenEasing; //! Dedermine which tween effect current frame use + + int m_iBetweenDuration; //! Current key frame will last m_iBetweenDuration frames + int m_iTotalDuration; + + + int m_iFromIndex; //! The current frame index in FrameList of CCMovementBoneData, it's different from m_iFrameIndex + int m_iToIndex; //! The next frame index in FrameList of CCMovementBoneData, it's different from m_iFrameIndex + + CCArmatureAnimation *m_pAnimation; - ArmatureAnimation *_animation; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCTWEEN_H__*/ diff --git a/extensions/CocoStudio/Armature/datas/CCDatas.cpp b/extensions/CocoStudio/Armature/datas/CCDatas.cpp index 95863980db..964c8ccbdd 100644 --- a/extensions/CocoStudio/Armature/datas/CCDatas.cpp +++ b/extensions/CocoStudio/Armature/datas/CCDatas.cpp @@ -24,102 +24,119 @@ THE SOFTWARE. #include "CCDatas.h" #include "../utils/CCUtilMath.h" +#include "../utils/CCTransformHelp.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN - BaseData::BaseData() - : x(0.0f) - , y(0.0f) - , zOrder(0) +CCBaseData::CCBaseData() + : x(0.0f) + , y(0.0f) + , zOrder(0) - , skewX(0.0f) - , skewY(0.0f) - , scaleX(1.0f) - , scaleY(1.0f) + , skewX(0.0f) + , skewY(0.0f) + , scaleX(1.0f) + , scaleY(1.0f) - , tweenRotate(0.0f) + , tweenRotate(0.0f) - , isUseColorInfo(false) - , a(255) - , r(255) - , g(255) - , b(255) + , isUseColorInfo(false) + , a(255) + , r(255) + , g(255) + , b(255) { } -BaseData::~BaseData() +CCBaseData::~CCBaseData() { } -void BaseData::copy(const BaseData *node ) +void CCBaseData::copy(const CCBaseData *node ) { - x = node->x; - y = node->y; - zOrder = node->zOrder; + x = node->x; + y = node->y; + zOrder = node->zOrder; - scaleX = node->scaleX; - scaleY = node->scaleY; - skewX = node->skewX; - skewY = node->skewY; + scaleX = node->scaleX; + scaleY = node->scaleY; + skewX = node->skewX; + skewY = node->skewY; - tweenRotate = node->tweenRotate; + tweenRotate = node->tweenRotate; - isUseColorInfo = node->isUseColorInfo; - r = node->r; - g = node->g; - b = node->b; - a = node->a; + isUseColorInfo = node->isUseColorInfo; + r = node->r; + g = node->g; + b = node->b; + a = node->a; } -void BaseData::subtract(BaseData *from, BaseData *to) +void CCBaseData::subtract(CCBaseData *from, CCBaseData *to) { - x = to->x - from->x; - y = to->y - from->y; - scaleX = to->scaleX - from->scaleX; - scaleY = to->scaleY - from->scaleY; - skewX = to->skewX - from->skewX; - skewY = to->skewY - from->skewY; + x = to->x - from->x; + y = to->y - from->y; + scaleX = to->scaleX - from->scaleX; + scaleY = to->scaleY - from->scaleY; + skewX = to->skewX - from->skewX; + skewY = to->skewY - from->skewY; - if(from->isUseColorInfo || to->isUseColorInfo) - { - a = to->a - from->a; - r = to->r - from->r; - g = to->g - from->g; - b = to->b - from->b; + if(isUseColorInfo || from->isUseColorInfo || to->isUseColorInfo) + { + a = to->a - from->a; + r = to->r - from->r; + g = to->g - from->g; + b = to->b - from->b; - isUseColorInfo = true; - } + isUseColorInfo = true; + } + else + { + a = r = g = b = 0; + isUseColorInfo = false; + } + if (skewX > M_PI) + { + skewX -= (float)CC_DOUBLE_PI; + } + if (skewX < -M_PI) + { + skewX += (float)CC_DOUBLE_PI; + } - if (skewX > M_PI) - { - skewX -= (float)CC_DOUBLE_PI; - } - if (skewX < -M_PI) - { - skewX += (float)CC_DOUBLE_PI; - } + if (skewY > M_PI) + { + skewY -= (float)CC_DOUBLE_PI; + } + if (skewY < -M_PI) + { + skewY += (float)CC_DOUBLE_PI; + } - if (skewY > M_PI) - { - skewY -= (float)CC_DOUBLE_PI; - } - if (skewY < -M_PI) - { - skewY += (float)CC_DOUBLE_PI; - } - - if (to->tweenRotate) - { - skewX += to->tweenRotate; - skewY -= to->tweenRotate; - } + if (to->tweenRotate) + { + skewX += to->tweenRotate; + skewY -= to->tweenRotate; + } } +void CCBaseData::setColor(const Color4B &color) +{ + r = color.r; + g = color.g; + b = color.b; + a = color.a; +} -const char *DisplayData::changeDisplayToTexture(const char *displayName) +Color4B CCBaseData::getColor() +{ + return ccc4(r, g, b, a); +} + +const char *CCDisplayData::changeDisplayToTexture(const char *displayName) { // remove .xxx std::string textureName = displayName; @@ -133,304 +150,271 @@ const char *DisplayData::changeDisplayToTexture(const char *displayName) return textureName.c_str(); } -DisplayData::DisplayData(void) - : displayType(CS_DISPLAY_SPRITE) +CCDisplayData::CCDisplayData(void) + : displayType(CS_DISPLAY_MAX) { } -DisplayData::~DisplayData(void) +CCDisplayData::~CCDisplayData(void) { } -SpriteDisplayData::SpriteDisplayData(void) +CCSpriteDisplayData::CCSpriteDisplayData(void) : displayName("") { displayType = CS_DISPLAY_SPRITE; } -SpriteDisplayData::~SpriteDisplayData() +CCSpriteDisplayData::~CCSpriteDisplayData() { } -void SpriteDisplayData::copy(SpriteDisplayData *displayData) +void CCSpriteDisplayData::copy(CCSpriteDisplayData *displayData) { displayName = displayData->displayName; displayType = displayData->displayType; + + skinData = displayData->skinData; } -ArmatureDisplayData::ArmatureDisplayData(void) +CCArmatureDisplayData::CCArmatureDisplayData(void) : displayName("") { displayType = CS_DISPLAY_ARMATURE; } -ArmatureDisplayData::~ArmatureDisplayData() +CCArmatureDisplayData::~CCArmatureDisplayData() { } -void ArmatureDisplayData::copy(ArmatureDisplayData *displayData) +void CCArmatureDisplayData::copy(CCArmatureDisplayData *displayData) { displayName = displayData->displayName; displayType = displayData->displayType; } -ParticleDisplayData::ParticleDisplayData(void) +CCParticleDisplayData::CCParticleDisplayData(void) : plist("") { displayType = CS_DISPLAY_PARTICLE; } -void ParticleDisplayData::copy(ParticleDisplayData *displayData) +void CCParticleDisplayData::copy(CCParticleDisplayData *displayData) { plist = displayData->plist; displayType = displayData->displayType; } -ShaderDisplayData::ShaderDisplayData(void) - : vert("") - , frag("") -{ - displayType = CS_DISPLAY_SHADER; -} -void ShaderDisplayData::copy(ShaderDisplayData *displayData) -{ - vert = displayData->vert; - frag = displayData->frag; - displayType = displayData->displayType; -} - - -BoneData::BoneData(void) +CCBoneData::CCBoneData(void) : name("") , parentName("") { } -BoneData::~BoneData(void) +CCBoneData::~CCBoneData(void) { - CC_SAFE_RELEASE(displayDataList); } -bool BoneData::init() +bool CCBoneData::init() { - displayDataList = new Array; - displayDataList->init(); + displayDataList.init(); return true; } -void BoneData::addDisplayData(DisplayData *displayData) +void CCBoneData::addDisplayData(CCDisplayData *displayData) { - displayDataList->addObject(displayData); + displayDataList.addObject(displayData); } -DisplayData *BoneData::getDisplayData(int index) +CCDisplayData *CCBoneData::getDisplayData(int index) { - return static_cast( displayDataList->getObjectAtIndex(index) ); + return (CCDisplayData *)displayDataList.getObjectAtIndex(index); } -ArmatureData::ArmatureData() + +CCArmatureData::CCArmatureData() + : dataVersion(0.1f) { } -ArmatureData::~ArmatureData() +CCArmatureData::~CCArmatureData() { - CC_SAFE_RELEASE(boneList); - CC_SAFE_RELEASE(boneDataDic); } -bool ArmatureData::init() +bool CCArmatureData::init() { - boneList = new Array; - boneList->init(); - - boneDataDic = new Dictionary; - boneDataDic->init(); - return true; } -void ArmatureData::addBoneData(BoneData *boneData) +void CCArmatureData::addBoneData(CCBoneData *boneData) { - boneDataDic->setObject(boneData, boneData->name); - boneList->addObject(boneData); + boneDataDic.setObject(boneData, boneData->name); } -BoneData *ArmatureData::getBoneData(const char *boneName) +CCBoneData *CCArmatureData::getBoneData(const char *boneName) { - return static_cast( boneDataDic->objectForKey(boneName) ); + return (CCBoneData *)boneDataDic.objectForKey(boneName); } -FrameData::FrameData(void) - : duration(1) +CCFrameData::CCFrameData(void) + : frameID(0) + , duration(1) , tweenEasing(Linear) , displayIndex(0) + , blendType(BLEND_NORMAL) - , _movement("") - , _event("") - , _sound("") - , _soundEffect("") + , strEvent("") + , strMovement("") + , strSound("") + , strSoundEffect("") { } -FrameData::~FrameData(void) +CCFrameData::~CCFrameData(void) { } -void FrameData::copy(FrameData *frameData) +void CCFrameData::copy(CCFrameData *frameData) { - BaseData::copy(frameData); + CCBaseData::copy(frameData); duration = frameData->duration; displayIndex = frameData->displayIndex; tweenEasing = frameData->tweenEasing; + blendType = frameData->blendType; } -MovementBoneData::MovementBoneData() +CCMovementBoneData::CCMovementBoneData() : delay(0.0f) , scale(1.0f) , duration(0) , name("") { - frameList = new Array; - frameList->init(); } -MovementBoneData::~MovementBoneData(void) +CCMovementBoneData::~CCMovementBoneData(void) { - CC_SAFE_RELEASE(frameList); } -bool MovementBoneData::init() +bool CCMovementBoneData::init() { - return true; + return frameList.init(); } -void MovementBoneData::addFrameData(FrameData *frameData) +void CCMovementBoneData::addFrameData(CCFrameData *frameData) { - frameList->addObject(frameData); - duration += frameData->duration; + frameList.addObject(frameData); } -FrameData *MovementBoneData::getFrameData(int index) +CCFrameData *CCMovementBoneData::getFrameData(int index) { - return static_cast( frameList->getObjectAtIndex(index) ); + return (CCFrameData *)frameList.getObjectAtIndex(index); } -MovementData::MovementData(void) + + +CCMovementData::CCMovementData(void) : name("") , duration(0) + , scale(1.0f) , durationTo(0) , durationTween(0) , loop(true) , tweenEasing(Linear) { - movBoneDataDic = new Dictionary; - movBoneDataDic->init(); } -MovementData::~MovementData(void) +CCMovementData::~CCMovementData(void) { - CC_SAFE_RELEASE(movBoneDataDic); } -void MovementData::addMovementBoneData(MovementBoneData *movBoneData) +void CCMovementData::addMovementBoneData(CCMovementBoneData *movBoneData) { - movBoneDataDic->setObject(movBoneData, movBoneData->name); + movBoneDataDic.setObject(movBoneData, movBoneData->name); } -MovementBoneData *MovementData::getMovementBoneData(const char *boneName) +CCMovementBoneData *CCMovementData::getMovementBoneData(const char *boneName) { - return static_cast( movBoneDataDic->objectForKey(boneName) ); + return (CCMovementBoneData *)movBoneDataDic.objectForKey(boneName); } -AnimationData::AnimationData(void) +CCAnimationData::CCAnimationData(void) { - movementDataDic = new Dictionary; - movementDataDic->init(); } -AnimationData::~AnimationData(void) +CCAnimationData::~CCAnimationData(void) { - CC_SAFE_RELEASE(movementDataDic); } -void AnimationData::release() +void CCAnimationData::addMovement(CCMovementData *movData) { - Object::release(); -} - -void AnimationData::retain() -{ - Object::retain(); -} - -void AnimationData::addMovement(MovementData *movData) -{ - movementDataDic->setObject(movData, movData->name); + movementDataDic.setObject(movData, movData->name); movementNames.push_back(movData->name); } -MovementData *AnimationData::getMovement(const char *movementName) +CCMovementData *CCAnimationData::getMovement(const char *movementName) { - return (MovementData *)movementDataDic->objectForKey(movementName); + return (CCMovementData *)movementDataDic.objectForKey(movementName); } -int AnimationData::getMovementCount() +int CCAnimationData::getMovementCount() { - return movementDataDic->count(); + return movementDataDic.count(); } -ContourData::ContourData() +CCContourData::CCContourData() { - vertexList = new Array; - vertexList->init(); } -ContourData::~ContourData() +CCContourData::~CCContourData() { - CC_SAFE_RELEASE(vertexList); } -bool ContourData::init() +bool CCContourData::init() { - return true; + return vertexList.init(); } -TextureData::TextureData() +void CCContourData::addVertex(Point *vertex) +{ + CCContourVertex2 *vertex2 = new CCContourVertex2(vertex->x, vertex->y); + vertex2->autorelease(); + + vertexList.addObject(vertex2); +} + +CCTextureData::CCTextureData() : height(0.0f) , width(0.0f) , pivotX(0.5f) , pivotY(0.5f) , name("") { - contourDataList = new Array; - contourDataList->init(); } -TextureData::~TextureData() +CCTextureData::~CCTextureData() { - CC_SAFE_RELEASE(contourDataList); } -bool TextureData::init() +bool CCTextureData::init() { - return true; + return contourDataList.init(); } -void TextureData::addContourData(ContourData *contourData) +void CCTextureData::addContourData(CCContourData *contourData) { - contourDataList->addObject(contourData); + contourDataList.addObject(contourData); } -ContourData *TextureData::getContourData(int index) +CCContourData *CCTextureData::getContourData(int index) { - return static_cast( contourDataList->getObjectAtIndex(index) ); + return (CCContourData *)contourDataList.getObjectAtIndex(index); } -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/datas/CCDatas.h b/extensions/CocoStudio/Armature/datas/CCDatas.h index 5a2055ab1b..b5f1e181b8 100644 --- a/extensions/CocoStudio/Armature/datas/CCDatas.h +++ b/extensions/CocoStudio/Armature/datas/CCDatas.h @@ -29,62 +29,65 @@ THE SOFTWARE. #include "../utils/CCTweenFunction.h" -#define CS_CREATE_NO_PARAM_NO_INIT(varType)\ +#define CC_CREATE_NO_PARAM_NO_INIT(varType)\ public: \ - static inline varType *create(void){ \ - varType *var = new varType();\ - if (var)\ + static inline varType *create(void){ \ + varType *var = new varType();\ + if (var)\ {\ - var->autorelease();\ - return var;\ + var->autorelease();\ + return var;\ }\ - CC_SAFE_DELETE(var);\ - return NULL;\ + CC_SAFE_DELETE(var);\ + return NULL;\ } -#define CS_CREATE_NO_PARAM(varType)\ +#define CC_CREATE_NO_PARAM(varType)\ public: \ - static inline varType *create(void){ \ - varType *var = new varType();\ - if (var && var->init())\ + static inline varType *create(void){ \ + varType *var = new varType();\ + if (var && var->init())\ {\ - var->autorelease();\ - return var;\ + var->autorelease();\ + return var;\ }\ - CC_SAFE_DELETE(var);\ - return NULL;\ + CC_SAFE_DELETE(var);\ + return NULL;\ } -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN /** -* the base node include a lot of attribute. +* The base node include a lot of attributes. */ -class BaseData : public Object +class CCBaseData : public Object { public: - CS_CREATE_NO_PARAM_NO_INIT(BaseData) + CC_CREATE_NO_PARAM_NO_INIT(CCBaseData) public: - BaseData(); - ~BaseData(void); + CCBaseData(); + ~CCBaseData(void); /* - * Copy datas from node - * @param node A BaseData to copy datas + * Copy data from node + * @param node A CCBaseData to copy data */ - virtual void copy(const BaseData *node); + virtual void copy(const CCBaseData *node); /* - * Calculate two BaseData's between value(to - from) and set to self + * Calculate two CCBaseData's between value(to - from) and set to self * - * @param from from BaseData - * @param to to BaseData + * @param from from CCBaseData + * @param to to CCBaseData */ - virtual void subtract(BaseData *from, BaseData *to); + virtual void subtract(CCBaseData *from, CCBaseData *to); + + virtual void setColor(const Color4B &color); + virtual Color4B getColor(); public: - float x; //! position x attribute - float y; //! position y attribute - int zOrder; //! zorder attribute, used to order the Bone's depth order + float x; //! position x attribute + float y; //! position y attribute + int zOrder; //! zorder attribute, used to order the CCBone's depth order /** * x y skewX skewY scaleX scaleY used to calculate transform matrix @@ -96,306 +99,308 @@ public: float scaleX; float scaleY; - float tweenRotate; //! SkewX, SkewY, and TweenRotate effect the rotation + float tweenRotate; //! SkewX, SkewY, and TweenRotate effect the rotation - bool isUseColorInfo; //! Whether or not this frame have the color changed Info + bool isUseColorInfo; //! Whether or not this frame have the color changed Info int a, r, g, b; }; /** -* DisplayType distinguish which type you display is. +* DisplayType distinguish which type your display is. */ enum DisplayType { - CS_DISPLAY_SPRITE, //! display is a single Sprite - CS_DISPLAY_ARMATURE, //! display is a Armature - CS_DISPLAY_PARTICLE, //! display is a Particle. - CS_DISPLAY_SHADER, //! display is a shader + CS_DISPLAY_SPRITE, //! display is a single Sprite + CS_DISPLAY_ARMATURE, //! display is a CCArmature + CS_DISPLAY_PARTICLE, //! display is a CCParticle. CS_DISPLAY_MAX }; -class DisplayData : public Object +class CCDisplayData : public Object { public: - CS_CREATE_NO_PARAM_NO_INIT(DisplayData) + CC_CREATE_NO_PARAM_NO_INIT(CCDisplayData) - static const char *changeDisplayToTexture(const char *); + static const char *changeDisplayToTexture(const char *displayName); public: - DisplayData(); - virtual ~DisplayData(void); + CCDisplayData(); + virtual ~CCDisplayData(void); DisplayType displayType; //! mark which type your display is }; -class SpriteDisplayData : public DisplayData +class CCSpriteDisplayData : public CCDisplayData { public: - CS_CREATE_NO_PARAM_NO_INIT(SpriteDisplayData) + CC_CREATE_NO_PARAM_NO_INIT(CCSpriteDisplayData) public: - SpriteDisplayData(); - virtual ~SpriteDisplayData(); + CCSpriteDisplayData(); + virtual ~CCSpriteDisplayData(); inline void setParam(const char *displayName) { this->displayName = displayName; } - void copy(SpriteDisplayData *displayData); + void copy(CCSpriteDisplayData *displayData); public: /** - * If DisplayType is CS_DISPLAY_SPRITE, then Bone will use this image name to create a Sprite from SpriteFrameCache. - * It should note that when use this name to create Sprite from SpriteFrameCache, you should use _displayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". + * If DisplayType is CS_DISPLAY_SPRITE, then CCBone will use this image name to create a Sprite from CCSpriteFrameCache. + * It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use m_strDisplayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". * - * If DisplayType is CS_DISPLAY_ARMATURE, the name is the Armature's name. When Bone init display and type is CS_DISPLAY_ARMATURE, - * then Bone will create a Armature. + * If DisplayType is CS_DISPLAY_ARMATURE, the name is the CCArmature's name. When CCBone init display and type is CS_DISPLAY_ARMATURE, + * then CCBone will create a CCArmature. + */ + std::string displayName; + + CCBaseData skinData; +}; + + +class CCArmatureDisplayData : public CCDisplayData +{ +public: + CC_CREATE_NO_PARAM_NO_INIT(CCArmatureDisplayData) +public: + CCArmatureDisplayData(); + virtual ~CCArmatureDisplayData(); + + inline void setParam(const char *displayName) + { + this->displayName = displayName; + } + void copy(CCArmatureDisplayData *displayData); +public: + /** + * If DisplayType is CS_DISPLAY_SPRITE, then CCBone will use this image name to create a Sprite from CCSpriteFrameCache. + * It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use m_strDisplayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". + * + * If DisplayType is CS_DISPLAY_ARMATURE, the name is the CCArmature's name. When CCBone init display and type is CS_DISPLAY_ARMATURE, + * then CCBone will create a CCArmature. */ std::string displayName; }; -class ArmatureDisplayData : public DisplayData +class CCParticleDisplayData : public CCDisplayData { public: - CS_CREATE_NO_PARAM_NO_INIT(ArmatureDisplayData) + CC_CREATE_NO_PARAM_NO_INIT(CCParticleDisplayData) public: - ArmatureDisplayData(); - virtual ~ArmatureDisplayData(); - - inline void setParam(const char *displayName) - { - this->displayName = displayName; - } - void copy(ArmatureDisplayData *displayData); -public: - /** - * If DisplayType is CS_DISPLAY_SPRITE, then Bone will use this image name to create a Sprite from SpriteFrameCache. - * It should note that when use this name to create Sprite from SpriteFrameCache, you should use _displayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". - * - * If DisplayType is CS_DISPLAY_ARMATURE, the name is the Armature's name. When Bone init display and type is CS_DISPLAY_ARMATURE, - * then Bone will create a Armature. - */ - std::string displayName; - -}; - - -class ParticleDisplayData : public DisplayData -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(ParticleDisplayData) -public: - ParticleDisplayData(); - virtual ~ParticleDisplayData() {}; + CCParticleDisplayData(); + virtual ~CCParticleDisplayData() {}; void setParam(const char *plist) { this->plist = plist; } - void copy(ParticleDisplayData *displayData); + void copy(CCParticleDisplayData *displayData); public: std::string plist; }; -class ShaderDisplayData : public DisplayData -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(ShaderDisplayData) -public: - ShaderDisplayData(); - virtual ~ShaderDisplayData() {}; - - inline void setParam(const char *vert, const char *frag) - { - this->vert = vert; - this->frag = frag; - } - - void copy(ShaderDisplayData *displayData); -public: - std::string vert; - std::string frag; -}; - /** -* BoneData used to init a Bone. -* BoneData keeps a DisplayData list, a Bone can have many display to change. -* The display information saved in the DisplayData +* CCBoneData used to init a CCBone. +* CCBoneData keeps a CCDisplayData list, a CCBone can have many display to change. +* The display information saved in the CCDisplayData */ -class BoneData : public BaseData +class CCBoneData : public CCBaseData { public: - CS_CREATE_NO_PARAM(BoneData) + CC_CREATE_NO_PARAM(CCBoneData) public: - BoneData(void); - ~BoneData(void); + CCBoneData(void); + ~CCBoneData(void); virtual bool init(); - void addDisplayData(DisplayData *displayData); - DisplayData *getDisplayData(int index); + void addDisplayData(CCDisplayData *displayData); + CCDisplayData *getDisplayData(int index); public: - std::string name; //! the bone's name - std::string parentName; //! the bone parent's name - Array *displayDataList; //! save DisplayData informations for the Bone + std::string name; //! the bone's name + std::string parentName; //! the bone parent's name + Array displayDataList; //! save CCDisplayData informations for the CCBone + AffineTransform boneDataTransform; }; /** -* ArmatureData saved the Armature name and Bonedatas needed for the Bones in this Armature -* When we create a Armature, we need to get each Bone's BoneData as it's init information. -* So we can get a BoneData from the Dictionary saved in the ArmatureData. +* CCArmatureData saved the CCArmature name and Bonedata needed for the CCBones in this CCArmature +* When we create a CCArmature, we need to get each CCBone's CCBoneData as it's init information. +* So we can get a CCBoneData from the Dictionary saved in the CCArmatureData. */ -class ArmatureData : public Object +class CCArmatureData : public Object { public: - CS_CREATE_NO_PARAM(ArmatureData) + CC_CREATE_NO_PARAM(CCArmatureData) public: - ArmatureData(); - ~ArmatureData(); + CCArmatureData(); + ~CCArmatureData(); bool init(); - void addBoneData(BoneData *boneData); - BoneData *getBoneData(const char *boneName); + void addBoneData(CCBoneData *boneData); + CCBoneData *getBoneData(const char *boneName); public: std::string name; - Dictionary *boneDataDic; - Array *boneList; + Dictionary boneDataDic; + float dataVersion; +}; + +enum CCBlendType +{ + BLEND_NORMAL, + BLEND_LAYER, + BLEND_DARKEN, + BLEND_MULTIPLY, + BLEND_LIGHTEN, + BLEND_SCREEN, + BLEND_OVERLAY, + BLEND_HARD_LIGHT, + BLEND_ADD, + BLEND_SUBSTRACT, + BLEND_DIFFERENCE, + BLEND_INVERT, + BLEND_ALPHA, + BLEND_ERASE }; -class FrameData : public BaseData +class CCFrameData : public CCBaseData { public: - CS_CREATE_NO_PARAM_NO_INIT(FrameData) + CC_CREATE_NO_PARAM_NO_INIT(CCFrameData) public: - FrameData(); - ~FrameData(); + CCFrameData(); + ~CCFrameData(); - virtual void copy(FrameData *frameData); + virtual void copy(CCFrameData *frameData); public: - int duration; //! The frame will last _duration frames - TweenType tweenEasing; //! Every frame's tween easing effect + int frameID; + int duration; //! The frame will last duration frames + CCTweenType tweenEasing; //! Every frame's tween easing effect /** * The current display index when change to this frame. - * If value is -1, then display will not show. + * If value is -1, then display will not be shown. */ int displayIndex; + CCBlendType blendType; + + std::string strEvent; /** - * _movement, _event, _sound, _soundEffect do not support yet + * strMovement, strEvent, strSound, strSoundEffect do not support yet */ - std::string _movement; - std::string _event; - std::string _sound; - std::string _soundEffect; + std::string strMovement; + std::string strSound; + std::string strSoundEffect; }; -class MovementBoneData : public Object +class CCMovementBoneData : public Object { public: - CS_CREATE_NO_PARAM(MovementBoneData) + CC_CREATE_NO_PARAM(CCMovementBoneData) public: - MovementBoneData(); - ~MovementBoneData(void); + CCMovementBoneData(); + ~CCMovementBoneData(void); virtual bool init(); - void addFrameData(FrameData *frameData); - FrameData *getFrameData(int index); + void addFrameData(CCFrameData *frameData); + CCFrameData *getFrameData(int index); public: - float delay; //! movement delay percent, this value can produce a delay effect - float scale; //! scale this movement - float duration; //! this Bone in this movement will last _duration frames - std::string name; //! bone name + float delay; //! movement delay percent, this value can produce a delay effect + float scale; //! scale this movement + float duration; //! this CCBone in this movement will last m_iDuration frames + std::string name; //! bone name - Array *frameList; + Array frameList; }; -class MovementData : public Object +class CCMovementData : public Object { public: - CS_CREATE_NO_PARAM_NO_INIT(MovementData) + CC_CREATE_NO_PARAM_NO_INIT(CCMovementData) public: - MovementData(void); - ~MovementData(void); + CCMovementData(void); + ~CCMovementData(void); - void addMovementBoneData(MovementBoneData *movBoneData); - MovementBoneData *getMovementBoneData(const char *boneName); + void addMovementBoneData(CCMovementBoneData *movBoneData); + CCMovementBoneData *getMovementBoneData(const char *boneName); public: std::string name; int duration; //! the frames this movement will last + float scale; //! scale this movement /** - * Change to this movement will last _durationTo frames. Use this effect can avoid too suddenly changing. + * Change to this movement will last durationTo frames. Use this effect can avoid too suddenly changing. * - * Example : current movement is "stand", we want to change to "run", then we fill _durationTo frames before + * Example : current movement is "stand", we want to change to "run", then we fill durationTo frames before * change to "run" instead of changing to "run" directly. */ int durationTo; /* - * This is different from _duration, _durationTween contain tween effect. - * - * Example : If we edit 10 frames in the flash, then _duration is 10. When we set _durationTween to 50, the movement will last 50 frames, the extra 40 frames will auto filled with tween effect + * This is different from duration, durationTween contain tween effect. + * duration is the raw time that the animation will last, it's the same with the time you edit in the Action Editor. + * durationTween is the actual time you want this animation last. + * Example : If we edit 10 frames in the flash, then duration is 10. When we set durationTween to 50, the movement will last 50 frames, the extra 40 frames will auto filled with tween effect */ int durationTween; - bool loop; //! whether the movement is looped + bool loop; //! whether the movement was looped /** * Which tween easing effect the movement use - * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel + * TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel */ - TweenType tweenEasing; + CCTweenType tweenEasing; /** - * Dictionary to save movment bone data. - * Key type is std::string, value type is MovementBoneData *. - */ - Dictionary *movBoneDataDic; + * @brief save movment bone data + * @key const char * + * @value CCMovementBoneData * + */ + Dictionary movBoneDataDic; }; /** -* AnimationData include all movement infomation for the Armature -* The struct is AnimationData -> MovementData -> MovementBoneData -> FrameData +* CCAnimationData include all movement infomation for the CCArmature +* The struct is CCAnimationData -> CCMovementData -> CCMovementBoneData -> CCFrameData * -> MovementFrameData */ -class AnimationData : public Object +class CCAnimationData : public Object { public: - CS_CREATE_NO_PARAM_NO_INIT(AnimationData) + CC_CREATE_NO_PARAM_NO_INIT(CCAnimationData) public: - AnimationData(void); - ~AnimationData(void); + CCAnimationData(void); + ~CCAnimationData(void); - void release(); - void retain(); - - void addMovement(MovementData *movData); - MovementData *getMovement(const char *movementName); + void addMovement(CCMovementData *movData); + CCMovementData *getMovement(const char *movementName); int getMovementCount(); public: std::string name; - Dictionary *movementDataDic; + Dictionary movementDataDic; std::vector movementNames; }; -struct ContourVertex2F : public Object +struct CCContourVertex2 : public Object { - ContourVertex2F(float x, float y) + CCContourVertex2(float x, float y) { this->x = x; this->y = y; @@ -406,53 +411,54 @@ struct ContourVertex2F : public Object }; /* -* ContourData include a contour vertex information +* CCContourData include a contour vertex information */ -class ContourData : public Object +class CCContourData : public Object { public: - CS_CREATE_NO_PARAM(ContourData) + CC_CREATE_NO_PARAM(CCContourData) public: - ContourData(); - ~ContourData(void); + CCContourData(); + ~CCContourData(void); virtual bool init(); + virtual void addVertex(Point *vertex); public: - Array *vertexList; //! Save contour vertex info, vertex saved in a Point + Array vertexList; //! Save contour vertex info, vertex saved in a Point }; /* -* TextureData include a texture's information +* CCTextureData include a texture's information */ -class TextureData : public Object +class CCTextureData : public Object { public: - CS_CREATE_NO_PARAM(TextureData) + CC_CREATE_NO_PARAM(CCTextureData) public: - TextureData(); - ~TextureData(void); + CCTextureData(); + ~CCTextureData(void); virtual bool init(); - void addContourData(ContourData *contourData); - ContourData *getContourData(int index); + void addContourData(CCContourData *contourData); + CCContourData *getContourData(int index); public: - float height; //! The texture's width, height + float height; //! The texture's width, height float width; - float pivotX; //! The texture's anchor point + float pivotX; //! The texture's anchor point float pivotY; - std::string name; //! The texture's name + std::string name; //! The texture's name - Array *contourDataList; + Array contourDataList; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCARMATURE_DATAS_H__*/ diff --git a/extensions/CocoStudio/Armature/display/CCBatchNode.cpp b/extensions/CocoStudio/Armature/display/CCBatchNode.cpp index 09d10dc41c..20e52348ee 100644 --- a/extensions/CocoStudio/Armature/display/CCBatchNode.cpp +++ b/extensions/CocoStudio/Armature/display/CCBatchNode.cpp @@ -26,11 +26,11 @@ THE SOFTWARE. #include "../utils/CCArmatureDefine.h" #include "../CCArmature.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -BatchNode *BatchNode::create() +CCBatchNode *CCBatchNode::create() { - BatchNode *batchNode = new BatchNode(); + CCBatchNode *batchNode = new CCBatchNode(); if (batchNode && batchNode->init()) { batchNode->autorelease(); @@ -40,29 +40,29 @@ BatchNode *BatchNode::create() return NULL; } -BatchNode::BatchNode() - : _atlas(NULL) +CCBatchNode::CCBatchNode() + : m_pAtlas(NULL) { } -bool BatchNode::init() +bool CCBatchNode::init() { bool ret = Node::init(); - setShaderProgram(ShaderCache::getInstance()->programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setShaderProgram(CCShaderCache::getInstance()->programForKey(kCCShader_PositionTextureColor)); return ret; } -void BatchNode::addChild(Node *child, int zOrder, int tag) +void CCBatchNode::addChild(Node *child, int zOrder, int tag) { Node::addChild(child, zOrder, tag); - Armature *armature = dynamic_cast(child); + CCArmature *armature = dynamic_cast(child); if (armature != NULL) { armature->setBatchNode(this); } } -void BatchNode::visit() +void CCBatchNode::visit() { // quick return if not visible. children won't be drawn. if (!_visible) @@ -91,29 +91,29 @@ void BatchNode::visit() kmGLPopMatrix(); } -void BatchNode::draw() +void CCBatchNode::draw() { CC_NODE_DRAW_SETUP(); Object *object = NULL; CCARRAY_FOREACH(_children, object) { - Armature *armature = dynamic_cast(object); + CCArmature *armature = dynamic_cast(object); if (armature) { armature->visit(); - _atlas = armature->getTextureAtlas(); + m_pAtlas = armature->getTextureAtlas(); } else { - static_cast(object)->visit(); + ((Node *)object)->visit(); } } - if (_atlas) + if (m_pAtlas) { - _atlas->drawQuads(); - _atlas->removeAllQuads(); + m_pAtlas->drawQuads(); + m_pAtlas->removeAllQuads(); } } -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCBatchNode.h b/extensions/CocoStudio/Armature/display/CCBatchNode.h index 442afd026b..375472e988 100644 --- a/extensions/CocoStudio/Armature/display/CCBatchNode.h +++ b/extensions/CocoStudio/Armature/display/CCBatchNode.h @@ -27,14 +27,14 @@ THE SOFTWARE. #include "../utils/CCArmatureDefine.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -class BatchNode : public Node +class CCBatchNode : public Node { public: - static BatchNode *create(); + static CCBatchNode *create(); public: - BatchNode(); + CCBatchNode(); virtual bool init(); virtual void addChild(Node *child, int zOrder, int tag); @@ -42,9 +42,9 @@ public: void draw(); protected: - TextureAtlas *_atlas; + TextureAtlas *m_pAtlas; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCBATCHNODE_H__*/ diff --git a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp index 35eb653e8e..bb65f5fc83 100644 --- a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp +++ b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp @@ -23,13 +23,12 @@ THE SOFTWARE. ****************************************************************************/ #include "CCDecorativeDisplay.h" -#include "../utils/CCConstValue.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -DecorativeDisplay *DecorativeDisplay::create() +CCDecorativeDisplay *CCDecorativeDisplay::create() { - DecorativeDisplay *pDisplay = new DecorativeDisplay(); + CCDecorativeDisplay *pDisplay = new CCDecorativeDisplay(); if (pDisplay && pDisplay->init()) { pDisplay->autorelease(); @@ -39,35 +38,30 @@ DecorativeDisplay *DecorativeDisplay::create() return NULL; } -DecorativeDisplay::DecorativeDisplay() - : _display(NULL) - , _displayData(NULL) +CCDecorativeDisplay::CCDecorativeDisplay() + : m_pDisplay(NULL) + , m_pDisplayData(NULL) { -#if ENABLE_PHYSICS_DETECT - _colliderDetector = NULL; +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT + m_pColliderDetector = NULL; #endif } -DecorativeDisplay::~DecorativeDisplay(void) +CCDecorativeDisplay::~CCDecorativeDisplay(void) { - CC_SAFE_RELEASE_NULL(_displayData); - CC_SAFE_RELEASE_NULL(_display); + CC_SAFE_RELEASE_NULL(m_pDisplayData); + CC_SAFE_RELEASE_NULL(m_pDisplay); -#if ENABLE_PHYSICS_DETECT - CC_SAFE_RELEASE_NULL(_colliderDetector); +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT + CC_SAFE_RELEASE_NULL(m_pColliderDetector); #endif } -bool DecorativeDisplay::init() +bool CCDecorativeDisplay::init() { return true; } - -void DecorativeDisplay::anchorPointChanged(float pointX, float pointY) -{ -} - -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h index 3ebd737ec0..e66de887fa 100644 --- a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h +++ b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h @@ -28,37 +28,34 @@ THE SOFTWARE. #include "../utils/CCArmatureDefine.h" #include "CCDisplayFactory.h" #include "../datas/CCDatas.h" -#include "../external_tool/sigslot.h" -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT #include "../physics/CCColliderDetector.h" #endif -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -class DecorativeDisplay: public Object, public sigslot::has_slots<> +class CCDecorativeDisplay: public Object { public: - static DecorativeDisplay *create(); + static CCDecorativeDisplay *create(); public: - DecorativeDisplay(void); - ~DecorativeDisplay(void); + CCDecorativeDisplay(void); + ~CCDecorativeDisplay(void); virtual bool init(); protected: - CC_SYNTHESIZE_RETAIN(Node *, _display, Display); - CC_SYNTHESIZE_RETAIN(DisplayData *, _displayData, DisplayData); + CC_SYNTHESIZE_RETAIN(Node *, m_pDisplay, Display); + CC_SYNTHESIZE_RETAIN(CCDisplayData *, m_pDisplayData, DisplayData); -#if ENABLE_PHYSICS_DETECT - CC_SYNTHESIZE_RETAIN(ColliderDetector *, _colliderDetector, ColliderDetector); +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT + CC_SYNTHESIZE_RETAIN(CCColliderDetector *, m_pColliderDetector, ColliderDetector); #endif -public: - void anchorPointChanged(float pointX, float pointY); }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCDECORATIVEDISPLAY_H__*/ diff --git a/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp b/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp index 923c0dff2f..451f79d4e8 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp +++ b/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp @@ -26,14 +26,13 @@ THE SOFTWARE. #include "../CCBone.h" #include "../CCArmature.h" #include "../display/CCSkin.h" -#include "../display/CCShaderNode.h" #include "../utils/CCSpriteFrameCacheHelper.h" #include "../utils/CCArmatureDataManager.h" #include "../utils/CCTransformHelp.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -void DisplayFactory::addDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) +void CCDisplayFactory::addDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) { switch(displayData->displayType) { @@ -51,7 +50,7 @@ void DisplayFactory::addDisplay(Bone *bone, DecorativeDisplay *decoDisplay, Disp } } -void DisplayFactory::createDisplay(Bone *bone, DecorativeDisplay *decoDisplay) +void CCDisplayFactory::createDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) { switch(decoDisplay->getDisplayData()->displayType) { @@ -69,56 +68,74 @@ void DisplayFactory::createDisplay(Bone *bone, DecorativeDisplay *decoDisplay) } } -void DisplayFactory::updateDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty) +void CCDisplayFactory::updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty) { CS_RETURN_IF(!decoDisplay); -#if ENABLE_PHYSICS_DETECT +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT if (dirty) { - ColliderDetector *detector = decoDisplay->getColliderDetector(); + CCColliderDetector *detector = decoDisplay->getColliderDetector(); if (detector) { - AffineTransform t = AffineTransformConcat(bone->nodeToArmatureTransform(), bone->getArmature()->getNodeToWorldTransform()); - detector->updateTransform(t); + do + { +#if ENABLE_PHYSICS_BOX2D_DETECT + CC_BREAK_IF(!detector->getBody()); +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + CC_BREAK_IF(!detector->getBody()); +#endif + Node *node = decoDisplay->getDisplay(); + AffineTransform displayTransform = node->getNodeToParentTransform(); + Point anchorPoint = node->getAnchorPointInPoints(); + anchorPoint = PointApplyAffineTransform(anchorPoint, displayTransform); + displayTransform.tx = anchorPoint.x; + displayTransform.ty = anchorPoint.y; + AffineTransform t = AffineTransformConcat(displayTransform, bone->getArmature()->getNodeToParentTransform()); + detector->updateTransform(t); + } + while (0); } } #endif + Node *display = decoDisplay->getDisplay(); switch(decoDisplay->getDisplayData()->displayType) { case CS_DISPLAY_SPRITE: - updateSpriteDisplay(bone, decoDisplay, dt, dirty); + updateSpriteDisplay(bone, display, dt, dirty); break; case CS_DISPLAY_PARTICLE: - updateParticleDisplay(bone, decoDisplay, dt, dirty); + updateParticleDisplay(bone, display, dt, dirty); break; case CS_DISPLAY_ARMATURE: - updateArmatureDisplay(bone, decoDisplay, dt, dirty); + updateArmatureDisplay(bone, display, dt, dirty); break; default: - break; + { + display->setAdditionalTransform(bone->getNodeToArmatureTransform()); + } + break; } } -void DisplayFactory::addSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) +void CCDisplayFactory::addSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) { - SpriteDisplayData *sdp = SpriteDisplayData::create(); - sdp->copy((SpriteDisplayData *)displayData); + CCSpriteDisplayData *sdp = CCSpriteDisplayData::create(); + sdp->copy((CCSpriteDisplayData *)displayData); decoDisplay->setDisplayData(sdp); createSpriteDisplay(bone, decoDisplay); } -void DisplayFactory::createSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay) +void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) { - Skin *skin = NULL; + CCSkin *skin = NULL; - SpriteDisplayData *displayData = (SpriteDisplayData *)decoDisplay->getDisplayData(); + CCSpriteDisplayData *displayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData(); - //! remove .xxx std::string textureName = displayData->displayName; size_t startPos = textureName.find_last_of("."); @@ -130,75 +147,99 @@ void DisplayFactory::createSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisp //! create display if(textureName.length() == 0) { - skin = Skin::create(); + skin = CCSkin::create(); } else { - skin = Skin::createWithSpriteFrameName((textureName + ".png").c_str()); + skin = CCSkin::createWithSpriteFrameName((textureName + ".png").c_str()); } - TextureAtlas *atlas = SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTextureAtlas((textureName + ".png").c_str()); - skin->setTextureAtlas(atlas); + skin->setBone(bone); - TextureData *textureData = ArmatureDataManager::sharedArmatureDataManager()->getTextureData(textureName.c_str()); + initSpriteDisplay(bone, decoDisplay, displayData->displayName.c_str(), skin); + + CCArmature *armature = bone->getArmature(); + if (armature) + { + if (armature->getArmatureData()->dataVersion >= VERSION_COMBINED) + { + skin->setSkinData(displayData->skinData); + } + else + { + skin->setSkinData(*bone->getBoneData()); + } + } + + decoDisplay->setDisplay(skin); + +} + +void CCDisplayFactory::initSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, const char *displayName, CCSkin *skin) +{ + //! remove .xxx + std::string textureName = displayName; + size_t startPos = textureName.find_last_of("."); + + if(startPos != std::string::npos) + { + textureName = textureName.erase(startPos); + } + + CCTextureData *textureData = CCArmatureDataManager::sharedArmatureDataManager()->getTextureData(textureName.c_str()); if(textureData) { //! Init display anchorPoint, every Texture have a anchor point skin->setAnchorPoint(Point( textureData->pivotX, textureData->pivotY)); } - skin->setBone(bone); - skin->setSkinData(*bone->getBoneData()); - decoDisplay->setDisplay(skin); - -#if ENABLE_PHYSICS_DETECT - if (textureData && textureData->contourDataList->count() > 0) +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT + if (textureData && textureData->contourDataList.count() > 0) { //! create ContourSprite - ColliderDetector *colliderDetector = ColliderDetector::create(bone); - colliderDetector->addContourDataList(textureData->contourDataList); + CCColliderDetector *colliderDetector = CCColliderDetector::create(bone); + colliderDetector->addContourDataList(&textureData->contourDataList); decoDisplay->setColliderDetector(colliderDetector); } #endif } -void DisplayFactory::updateSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty) +void CCDisplayFactory::updateSpriteDisplay(CCBone *bone, Node *display, float dt, bool dirty) { - Skin *skin = (Skin *)decoDisplay->getDisplay(); - skin->updateTransform(); + CS_RETURN_IF(!dirty); + CCSkin *skin = (CCSkin *)display; + skin->updateArmatureTransform(); } -void DisplayFactory::addArmatureDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) +void CCDisplayFactory::addArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) { - ArmatureDisplayData *adp = ArmatureDisplayData::create(); ; - adp->copy((ArmatureDisplayData *)displayData); + CCArmatureDisplayData *adp = CCArmatureDisplayData::create(); ; + adp->copy((CCArmatureDisplayData *)displayData); decoDisplay->setDisplayData(adp); createArmatureDisplay(bone, decoDisplay); } -void DisplayFactory::createArmatureDisplay(Bone *bone, DecorativeDisplay *decoDisplay) +void CCDisplayFactory::createArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) { - ArmatureDisplayData *displayData = (ArmatureDisplayData *)decoDisplay->getDisplayData(); + CCArmatureDisplayData *displayData = (CCArmatureDisplayData *)decoDisplay->getDisplayData(); - Armature *armature = Armature::create(displayData->displayName.c_str(), bone); + CCArmature *armature = CCArmature::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. + * CCArmature's bone children. */ armature->setName((bone->getName() + "_armatureChild").c_str()); decoDisplay->setDisplay(armature); } -void DisplayFactory::updateArmatureDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty) +void CCDisplayFactory::updateArmatureDisplay(CCBone *bone, Node *display, float dt, bool dirty) { - CS_RETURN_IF(!dirty); - - Armature *armature = bone->getChildArmature(); + CCArmature *armature = (CCArmature *)display; if(armature) { armature->sortAllChildren(); @@ -208,25 +249,25 @@ void DisplayFactory::updateArmatureDisplay(Bone *bone, DecorativeDisplay *decoDi -void DisplayFactory::addParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) +void CCDisplayFactory::addParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) { - ParticleDisplayData *adp = ParticleDisplayData::create(); ; - adp->copy((ParticleDisplayData *)displayData); + CCParticleDisplayData *adp = CCParticleDisplayData::create(); ; + adp->copy((CCParticleDisplayData *)displayData); decoDisplay->setDisplayData(adp); createParticleDisplay(bone, decoDisplay); } -void DisplayFactory::createParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay) +void CCDisplayFactory::createParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) { - ParticleDisplayData *displayData = (ParticleDisplayData *)decoDisplay->getDisplayData(); + CCParticleDisplayData *displayData = (CCParticleDisplayData *)decoDisplay->getDisplayData(); ParticleSystem *system = ParticleSystemQuad::create(displayData->plist.c_str()); decoDisplay->setDisplay(system); } -void DisplayFactory::updateParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty) +void CCDisplayFactory::updateParticleDisplay(CCBone *bone, Node *display, float dt, bool dirty) { - ParticleSystem *system = (ParticleSystem *)decoDisplay->getDisplay(); - BaseData node; - TransformHelp::matrixToNode(bone->nodeToArmatureTransform(), node); + ParticleSystem *system = (ParticleSystem *)display; + CCBaseData node; + CCTransformHelp::matrixToNode(bone->getNodeToArmatureTransform(), node); system->setPosition(node.x, node.y); system->setScaleX(node.scaleX); system->setScaleY(node.scaleY); @@ -234,20 +275,4 @@ void DisplayFactory::updateParticleDisplay(Bone *bone, DecorativeDisplay *decoDi } - -void DisplayFactory::addShaderDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) -{ - ShaderDisplayData *sdp = ShaderDisplayData::create(); - sdp->copy((ShaderDisplayData *)displayData); - decoDisplay->setDisplayData(sdp); - - createShaderDisplay(bone, decoDisplay); -} -void DisplayFactory::createShaderDisplay(Bone *bone, DecorativeDisplay *decoDisplay) -{ - ShaderDisplayData *displayData = (ShaderDisplayData *)decoDisplay->getDisplayData(); - ShaderNode *sn = ShaderNode::shaderNodeWithVertex(displayData->vert.c_str(), displayData->frag.c_str()); - decoDisplay->setDisplay(sn); -} - -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCDisplayFactory.h b/extensions/CocoStudio/Armature/display/CCDisplayFactory.h index 6ad29ed030..bd3430344e 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayFactory.h +++ b/extensions/CocoStudio/Armature/display/CCDisplayFactory.h @@ -28,38 +28,36 @@ THE SOFTWARE. #include "../utils/CCArmatureDefine.h" #include "../datas/CCDatas.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -class Skin; -class Bone; -class DecorativeDisplay; -class DisplayData; +class CCSkin; +class CCBone; +class CCDecorativeDisplay; +class CCDisplayData; -class DisplayFactory +class CCDisplayFactory { 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 addDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); + static void createDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); + static void updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty); - static void addSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData); - static void createSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay); - static void updateSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty); + static void addSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); + static void createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); + static void initSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, const char *displayName, CCSkin *skin); + static void updateSpriteDisplay(CCBone *bone, 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, DecorativeDisplay *decoDisplay, float dt, bool dirty); - static void addParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData); - static void createParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay); - static void updateParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty); - - static void addShaderDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData); - static void createShaderDisplay(Bone *bone, DecorativeDisplay *decoDisplay); + static void addArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); + static void createArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); + static void updateArmatureDisplay(CCBone *bone, Node *display, float dt, bool dirty); + static void addParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); + static void createParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); + static void updateParticleDisplay(CCBone *bone, Node *display, float dt, bool dirty); }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCDISPLAYFACTORY_H__*/ diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp index b8fbbc5064..10e70ad288 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp +++ b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp @@ -28,11 +28,11 @@ THE SOFTWARE. #include "../utils/CCUtilMath.h" #include "../display/CCSkin.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -DisplayManager *DisplayManager::create(Bone *bone) +CCDisplayManager *CCDisplayManager::create(CCBone *bone) { - DisplayManager *pDisplayManager = new DisplayManager(); + CCDisplayManager *pDisplayManager = new CCDisplayManager(); if (pDisplayManager && pDisplayManager->init(bone)) { pDisplayManager->autorelease(); @@ -43,38 +43,38 @@ DisplayManager *DisplayManager::create(Bone *bone) } -DisplayManager::DisplayManager() - : _decoDisplayList(NULL) - , _displayRenderNode(NULL) - , _currentDecoDisplay(NULL) - , _displayIndex(-1) - , _forceChangeDisplay(false) - , _visible(true) - , _bone(NULL) +CCDisplayManager::CCDisplayManager() + : m_pDecoDisplayList(NULL) + , m_pDisplayRenderNode(NULL) + , m_pCurrentDecoDisplay(NULL) + , m_iDisplayIndex(-1) + , m_bForceChangeDisplay(false) + , m_bVisible(true) + , m_pBone(NULL) { } -DisplayManager::~DisplayManager() +CCDisplayManager::~CCDisplayManager() { - CC_SAFE_DELETE(_decoDisplayList); + CC_SAFE_DELETE(m_pDecoDisplayList); - if( _displayRenderNode ) + if( m_pDisplayRenderNode ) { - _displayRenderNode->removeFromParentAndCleanup(true); - if(_displayRenderNode->retainCount() > 0) - CC_SAFE_RELEASE_NULL(_displayRenderNode); + m_pDisplayRenderNode->removeFromParentAndCleanup(true); + if(m_pDisplayRenderNode->retainCount() > 0) + CC_SAFE_RELEASE_NULL(m_pDisplayRenderNode); } } -bool DisplayManager::init(Bone *bone) +bool CCDisplayManager::init(CCBone *bone) { bool ret = false; do { - _bone = bone; + m_pBone = bone; initDisplayList(bone->getBoneData()); @@ -86,167 +86,239 @@ bool DisplayManager::init(Bone *bone) } -void DisplayManager::addDisplay(DisplayData *displayData, int index) +void CCDisplayManager::addDisplay(CCDisplayData *displayData, int index) { - DecorativeDisplay *decoDisplay = NULL; + CCDecorativeDisplay *decoDisplay = NULL; - if(index >= 0 && (unsigned int)index < _decoDisplayList->count()) + if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) { - decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index); + decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); } else { - decoDisplay = DecorativeDisplay::create(); - _decoDisplayList->addObject(decoDisplay); + decoDisplay = CCDecorativeDisplay::create(); + m_pDecoDisplayList->addObject(decoDisplay); } - DisplayFactory::addDisplay(_bone, decoDisplay, displayData); + CCDisplayFactory::addDisplay(m_pBone, decoDisplay, displayData); //! if changed display index is current display index, then change current display to the new display - if(index == _displayIndex) + if(index == m_iDisplayIndex) { - _displayIndex = -1; + m_iDisplayIndex = -1; changeDisplayByIndex(index, false); } } -void DisplayManager::removeDisplay(int index) +void CCDisplayManager::addDisplay(Node *display, int index) { - _decoDisplayList->removeObjectAtIndex(index); + CCDecorativeDisplay *decoDisplay = NULL; - if(index == _displayIndex) + if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) + { + decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); + } + else + { + decoDisplay = CCDecorativeDisplay::create(); + m_pDecoDisplayList->addObject(decoDisplay); + } + + CCDisplayData *displayData = NULL; + if (CCSkin *skin = dynamic_cast(display)) + { + skin->setBone(m_pBone); + displayData = CCSpriteDisplayData::create(); + + CCDisplayFactory::initSpriteDisplay(m_pBone, decoDisplay, skin->getDisplayName().c_str(), skin); + + if (CCSpriteDisplayData *spriteDisplayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData()) + { + skin->setSkinData(spriteDisplayData->skinData); + } + else + { + CCBaseData baseData; + skin->setSkinData(baseData); + } + } + else if (dynamic_cast(display)) + { + displayData = CCParticleDisplayData::create(); + } + else if(CCArmature *armature = dynamic_cast(display)) + { + displayData = CCArmatureDisplayData::create(); + armature->setParentBone(m_pBone); + } + else + { + displayData = CCDisplayData::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 == m_iDisplayIndex) + { + m_iDisplayIndex = -1; + changeDisplayByIndex(index, false); + } +} + +void CCDisplayManager::removeDisplay(int index) +{ + m_pDecoDisplayList->removeObjectAtIndex(index); + + if(index == m_iDisplayIndex) { setCurrentDecorativeDisplay(NULL); } } -void DisplayManager::changeDisplayByIndex(int index, bool force) +Array *CCDisplayManager::getDecorativeDisplayList() { - CCASSERT( (_decoDisplayList ? index < (int)_decoDisplayList->count() : true), "the _index value is out of range"); + return m_pDecoDisplayList; +} - _forceChangeDisplay = force; +void CCDisplayManager::changeDisplayByIndex(int index, bool force) +{ + CCAssert( (m_pDecoDisplayList ? index < (int)m_pDecoDisplayList->count() : true), "the _index value is out of range"); + + m_bForceChangeDisplay = force; //! If index is equal to current display index,then do nothing - if ( _displayIndex == index) + if ( m_iDisplayIndex == index) return; - _displayIndex = index; + m_iDisplayIndex = index; //! If displayIndex < 0, it means you want to hide you display - if (_displayIndex < 0) + if (m_iDisplayIndex < 0) { - if(_displayRenderNode) + if(m_pDisplayRenderNode) { - _displayRenderNode->removeFromParentAndCleanup(true); + m_pDisplayRenderNode->removeFromParentAndCleanup(true); setCurrentDecorativeDisplay(NULL); } return; } - DecorativeDisplay *decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(_displayIndex); + CCDecorativeDisplay *decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(m_iDisplayIndex); setCurrentDecorativeDisplay(decoDisplay); } -void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay) +void CCDisplayManager::setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisplay) { -#if ENABLE_PHYSICS_DETECT - if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector()) +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT + if (m_pCurrentDecoDisplay && m_pCurrentDecoDisplay->getColliderDetector()) { - _currentDecoDisplay->getColliderDetector()->setActive(false); + m_pCurrentDecoDisplay->getColliderDetector()->setActive(false); } #endif - _currentDecoDisplay = decoDisplay; + m_pCurrentDecoDisplay = decoDisplay; -#if ENABLE_PHYSICS_DETECT - if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector()) +#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT + if (m_pCurrentDecoDisplay && m_pCurrentDecoDisplay->getColliderDetector()) { - _currentDecoDisplay->getColliderDetector()->setActive(true); + m_pCurrentDecoDisplay->getColliderDetector()->setActive(true); } #endif - Node *displayRenderNode = _currentDecoDisplay == NULL ? NULL : _currentDecoDisplay->getDisplay(); - if (_displayRenderNode) + Node *displayRenderNode = m_pCurrentDecoDisplay == NULL ? NULL : m_pCurrentDecoDisplay->getDisplay(); + if (m_pDisplayRenderNode) { - if (dynamic_cast(_displayRenderNode) != NULL) + if (dynamic_cast(m_pDisplayRenderNode) != NULL) { - _bone->setChildArmature(NULL); + m_pBone->setChildArmature(NULL); } - - _displayRenderNode->removeFromParentAndCleanup(true); - _displayRenderNode->release(); + m_pDisplayRenderNode->removeFromParentAndCleanup(true); + m_pDisplayRenderNode->release(); } - _displayRenderNode = displayRenderNode; + m_pDisplayRenderNode = displayRenderNode; - if(_displayRenderNode) + if(m_pDisplayRenderNode) { - if (dynamic_cast(_displayRenderNode) != NULL) + if (CCArmature *armature = dynamic_cast(m_pDisplayRenderNode)) { - _bone->setChildArmature((Armature *)_displayRenderNode); + m_pBone->setChildArmature(armature); } - _displayRenderNode->retain(); - _displayRenderNode->setVisible(_visible); + else if (ParticleSystemQuad *particle = dynamic_cast(m_pDisplayRenderNode)) + { + particle->resetSystem(); + } + + if (RGBAProtocol *rgbaProtocaol = dynamic_cast(m_pDisplayRenderNode)) + { + rgbaProtocaol->setColor(m_pBone->getDisplayedColor()); + rgbaProtocaol->setOpacity(m_pBone->getDisplayedOpacity()); + } + + m_pDisplayRenderNode->retain(); + m_pDisplayRenderNode->setVisible(m_bVisible); } } -Node *DisplayManager::getDisplayRenderNode() +Node *CCDisplayManager::getDisplayRenderNode() { - return _displayRenderNode; + return m_pDisplayRenderNode; } -int DisplayManager::getCurrentDisplayIndex() +int CCDisplayManager::getCurrentDisplayIndex() { - return _displayIndex; + return m_iDisplayIndex; } -DecorativeDisplay *DisplayManager::getCurrentDecorativeDisplay() +CCDecorativeDisplay *CCDisplayManager::getCurrentDecorativeDisplay() { - return _currentDecoDisplay; + return m_pCurrentDecoDisplay; } -DecorativeDisplay *DisplayManager::getDecorativeDisplayByIndex( int index) +CCDecorativeDisplay *CCDisplayManager::getDecorativeDisplayByIndex( int index) { - return static_cast( _decoDisplayList->getObjectAtIndex(index) ); + return (CCDecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); } -void DisplayManager::initDisplayList(BoneData *boneData) +void CCDisplayManager::initDisplayList(CCBoneData *boneData) { - CC_SAFE_DELETE(_decoDisplayList); - _decoDisplayList = Array::create(); - _decoDisplayList->retain(); + CC_SAFE_DELETE(m_pDecoDisplayList); + m_pDecoDisplayList = Array::create(); + m_pDecoDisplayList->retain(); CS_RETURN_IF(!boneData); Object *object = NULL; - Array *displayDataList = boneData->displayDataList; + Array *displayDataList = &boneData->displayDataList; CCARRAY_FOREACH(displayDataList, object) { - DisplayData *displayData = static_cast(object); + CCDisplayData *displayData = (CCDisplayData *)object; - DecorativeDisplay *decoDisplay = DecorativeDisplay::create(); + CCDecorativeDisplay *decoDisplay = CCDecorativeDisplay::create(); decoDisplay->setDisplayData(displayData); - DisplayFactory::createDisplay(_bone, decoDisplay); + CCDisplayFactory::createDisplay(m_pBone, decoDisplay); - _decoDisplayList->addObject(decoDisplay); + m_pDecoDisplayList->addObject(decoDisplay); } } -bool DisplayManager::containPoint(Point &point) +bool CCDisplayManager::containPoint(Point &point) { - if(!_visible || _displayIndex < 0) + if(!m_bVisible || m_iDisplayIndex < 0) { return false; } bool ret = false; - switch (_currentDecoDisplay->getDisplayData()->displayType) + switch (m_pCurrentDecoDisplay->getDisplayData()->displayType) { case CS_DISPLAY_SPRITE: { @@ -258,7 +330,7 @@ bool DisplayManager::containPoint(Point &point) Point outPoint = Point(0, 0); - Sprite *sprite = (Sprite *)_currentDecoDisplay->getDisplay(); + Sprite *sprite = (Sprite *)m_pCurrentDecoDisplay->getDisplay(); sprite = (Sprite *)sprite->getChildByTag(0); ret = CC_SPRITE_CONTAIN_POINT_WITH_RETURN(sprite, point, outPoint); @@ -272,52 +344,52 @@ bool DisplayManager::containPoint(Point &point) return ret; } -bool DisplayManager::containPoint(float x, float y) +bool CCDisplayManager::containPoint(float x, float y) { Point p = Point(x, y); return containPoint(p); } -void DisplayManager::setVisible(bool visible) +void CCDisplayManager::setVisible(bool visible) { - if(!_displayRenderNode) + if(!m_pDisplayRenderNode) return; - _visible = visible; - _displayRenderNode->setVisible(visible); + m_bVisible = visible; + m_pDisplayRenderNode->setVisible(visible); } -bool DisplayManager::isVisible() +bool CCDisplayManager::isVisible() { - return _visible; + return m_bVisible; } -Size DisplayManager::getContentSize() +Size CCDisplayManager::getContentSize() { - CS_RETURN_IF(!_displayRenderNode) Size(0, 0); - return _displayRenderNode->getContentSize(); + CS_RETURN_IF(!m_pDisplayRenderNode) Size(0, 0); + return m_pDisplayRenderNode->getContentSize(); } -Rect DisplayManager::getBoundingBox() +Rect CCDisplayManager::getBoundingBox() { - CS_RETURN_IF(!_displayRenderNode) Rect(0, 0, 0, 0); - return _displayRenderNode->getBoundingBox(); + CS_RETURN_IF(!m_pDisplayRenderNode) Rect(0, 0, 0, 0); + return m_pDisplayRenderNode->getBoundingBox(); } -Point DisplayManager::getAnchorPoint() +Point CCDisplayManager::getAnchorPoint() { - CS_RETURN_IF(!_displayRenderNode) Point(0, 0); - return _displayRenderNode->getAnchorPoint(); + CS_RETURN_IF(!m_pDisplayRenderNode) Point(0, 0); + return m_pDisplayRenderNode->getAnchorPoint(); } -Point DisplayManager::getAnchorPointInPoints() +Point CCDisplayManager::getAnchorPointInPoints() { - CS_RETURN_IF(!_displayRenderNode) Point(0, 0); - return _displayRenderNode->getAnchorPointInPoints(); + CS_RETURN_IF(!m_pDisplayRenderNode) Point(0, 0); + return m_pDisplayRenderNode->getAnchorPointInPoints(); } -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.h b/extensions/CocoStudio/Armature/display/CCDisplayManager.h index c439327db1..46da715c45 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.h +++ b/extensions/CocoStudio/Armature/display/CCDisplayManager.h @@ -29,28 +29,28 @@ THE SOFTWARE. #include "../display/CCDecorativeDisplay.h" #include "../datas/CCDatas.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -class Bone; +class CCBone; -//! DisplayManager manages Bone's display -class DisplayManager : public Object +//! CCDisplayManager manages CCBone's display +class CCDisplayManager : public Object { public: - static DisplayManager *create(Bone *bone); + static CCDisplayManager *create(CCBone *bone); public: - DisplayManager(); - ~DisplayManager(); + CCDisplayManager(); + ~CCDisplayManager(); - bool init(Bone *bone); + bool init(CCBone *bone); /** - * Use BoneData to init the display list. + * Use CCBoneData to init the display list. * 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 Armature, then create a new Armature + * If the display is a CCArmature, then create a new CCArmature */ - void initDisplayList(BoneData *boneData); + virtual void initDisplayList(CCBoneData *boneData); /** * Add display and use _DisplayData init the display. @@ -58,12 +58,14 @@ public: * 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 + * If you want to create a sprite display, then create a CCSpriteDisplayData 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(CCDisplayData *displayData, int index); + + void addDisplay(Node *display, int index); void removeDisplay(int index); @@ -85,9 +87,9 @@ public: int getCurrentDisplayIndex(); - void setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay); - DecorativeDisplay *getCurrentDecorativeDisplay(); - DecorativeDisplay *getDecorativeDisplayByIndex( int index); + virtual void setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisplay); + virtual CCDecorativeDisplay *getCurrentDecorativeDisplay(); + virtual CCDecorativeDisplay *getDecorativeDisplayByIndex( int index); /** * Sets whether the display is visible @@ -121,22 +123,22 @@ public: virtual bool containPoint(float x, float y); protected: - Array *_decoDisplayList; - //! Display render node. - Node *_displayRenderNode; + Array *m_pDecoDisplayList; + //! Display render node. + Node *m_pDisplayRenderNode; //! Include current display information, like contour sprite, etc. - DecorativeDisplay *_currentDecoDisplay; + CCDecorativeDisplay *m_pCurrentDecoDisplay; //! Current display index - int _displayIndex; + int m_iDisplayIndex; - CC_SYNTHESIZE_PASS_BY_REF(bool, _forceChangeDisplay, ForceChangeDisplay) + CC_SYNTHESIZE(bool, m_bForceChangeDisplay, ForceChangeDisplay) //! Whether of not the bone is visible. Default is true - bool _visible; + bool m_bVisible; - Bone *_bone; + CCBone *m_pBone; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCDISPLAYMANAGER_H__*/ diff --git a/extensions/CocoStudio/Armature/display/CCShaderNode.cpp b/extensions/CocoStudio/Armature/display/CCShaderNode.cpp deleted file mode 100644 index b45f649d23..0000000000 --- a/extensions/CocoStudio/Armature/display/CCShaderNode.cpp +++ /dev/null @@ -1,136 +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 "CCShaderNode.h" - -namespace cocos2d { namespace extension { namespace armature { - -enum -{ - SIZE_X = 128, - SIZE_Y = 128, -}; - -ShaderNode::ShaderNode() - : _center(Vertex2F(0.0f, 0.0f)) - , _resolution(Vertex2F(0.0f, 0.0f)) - , _time(0.0f) - , _uniformCenter(0) - , _uniformResolution(0) - , _uniformTime(0) -{ -} - -ShaderNode *ShaderNode::shaderNodeWithVertex(const char *vert, const char *frag) -{ - ShaderNode *node = new ShaderNode(); - node->initWithVertex(vert, frag); - node->autorelease(); - - return node; -} - -bool ShaderNode::initWithVertex(const char *vert, const char *frag) -{ - - loadShaderVertex(vert, frag); - - _time = 0; - _resolution = Vertex2F(SIZE_X, SIZE_Y); - - scheduleUpdate(); - - setContentSize(Size(SIZE_X, SIZE_Y)); - setAnchorPoint(Point(0.5f, 0.5f)); - - return true; -} - -void ShaderNode::loadShaderVertex(const char *vert, const char *frag) -{ - GLProgram *shader = new GLProgram(); - shader->initWithVertexShaderFilename(vert, frag); - - shader->addAttribute("aVertex", GLProgram::VERTEX_ATTRIB_POSITION); - shader->link(); - - shader->updateUniforms(); - - _uniformCenter = glGetUniformLocation(shader->getProgram(), "center"); - _uniformResolution = glGetUniformLocation(shader->getProgram(), "resolution"); - _uniformTime = glGetUniformLocation(shader->getProgram(), "time"); - - this->setShaderProgram(shader); - - shader->release(); -} - -void ShaderNode::update(float dt) -{ - _time += dt; -} - -void ShaderNode::translateFormOtherNode(AffineTransform &transform) -{ - Node::setAdditionalTransform(transform); - - _center = Vertex2F(_additionalTransform.tx * CC_CONTENT_SCALE_FACTOR(), _additionalTransform.ty * CC_CONTENT_SCALE_FACTOR()); - _resolution = Vertex2F( SIZE_X * _additionalTransform.a, SIZE_Y * _additionalTransform.d); -} - -void ShaderNode::setPosition(const Point &newPosition) -{ - Node::setPosition(newPosition); - Point position = getPosition(); - _center = Vertex2F(position.x * CC_CONTENT_SCALE_FACTOR(), position.y * CC_CONTENT_SCALE_FACTOR()); -} - -void ShaderNode::draw() -{ - CC_NODE_DRAW_SETUP(); - - float w = SIZE_X, h = SIZE_Y; - GLfloat vertices[12] = {0, 0, w, 0, w, h, 0, 0, 0, h, w, h}; - - // - // Uniforms - // - getShaderProgram()->setUniformLocationWith2f(_uniformCenter, _center.x, _center.y); - getShaderProgram()->setUniformLocationWith2f(_uniformResolution, _resolution.x, _resolution.y); - - - // time changes all the time, so it is Ok to call OpenGL directly, and not the "cached" version - glUniform1f(_uniformTime, _time); - - GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION); - - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); - - glDrawArrays(GL_TRIANGLES, 0, 6); - - CC_INCREMENT_GL_DRAWS(1); -} - - -}}} // namespace cocos2d { namespace extension { namespace armature { diff --git a/extensions/CocoStudio/Armature/display/CCShaderNode.h b/extensions/CocoStudio/Armature/display/CCShaderNode.h deleted file mode 100644 index 415c38585f..0000000000 --- a/extensions/CocoStudio/Armature/display/CCShaderNode.h +++ /dev/null @@ -1,57 +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 __CCSHADERNODE_H__ -#define __CCSHADERNODE_H__ - -#include "../utils/CCArmatureDefine.h" - -namespace cocos2d { namespace extension { namespace armature { - -class ShaderNode : public Node -{ -public: - ShaderNode(); - - bool initWithVertex(const char *vert, const char *frag); - void loadShaderVertex(const char *vert, const char *frag); - - virtual void update(float dt); - virtual void setPosition(const Point &newPosition); - virtual void translateFormOtherNode(AffineTransform &transform); - virtual void draw(); - - static ShaderNode *shaderNodeWithVertex(const char *vert, const char *frag); - -private: - - Vertex2F _center; - Vertex2F _resolution; - float _time; - GLuint _uniformCenter, _uniformResolution, _uniformTime; -}; - -}}} // namespace cocos2d { namespace extension { namespace armature { - -#endif /*__CCSHADERNODE_H__*/ diff --git a/extensions/CocoStudio/Armature/display/CCSkin.cpp b/extensions/CocoStudio/Armature/display/CCSkin.cpp index a1555bdb14..08cb7893ba 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.cpp +++ b/extensions/CocoStudio/Armature/display/CCSkin.cpp @@ -24,8 +24,10 @@ THE SOFTWARE. #include "CCSkin.h" #include "../utils/CCTransformHelp.h" +#include "../utils/CCSpriteFrameCacheHelper.h" +#include "../CCArmature.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN #if CC_SPRITEBATCHNODE_RENDER_SUBPIXEL #define RENDER_IN_SUBPIXEL @@ -33,9 +35,9 @@ namespace cocos2d { namespace extension { namespace armature { #define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__)) #endif -Skin *Skin::create() +CCSkin *CCSkin::create() { - Skin *skin = new Skin(); + CCSkin *skin = new CCSkin(); if(skin && skin->init()) { skin->autorelease(); @@ -45,9 +47,9 @@ Skin *Skin::create() return NULL; } -Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName) +CCSkin *CCSkin::createWithSpriteFrameName(const char *pszSpriteFrameName) { - Skin *skin = new Skin(); + CCSkin *skin = new CCSkin(); if(skin && skin->initWithSpriteFrameName(pszSpriteFrameName)) { skin->autorelease(); @@ -57,34 +59,78 @@ Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName) return NULL; } -Skin::Skin() - : _bone(NULL) +CCSkin *CCSkin::create(const char *pszFileName) { + CCSkin *skin = new CCSkin(); + if(skin && skin->initWithFile(pszFileName)) + { + skin->autorelease(); + return skin; + } + CC_SAFE_DELETE(skin); + return NULL; } -void Skin::setSkinData(const BaseData &var) +CCSkin::CCSkin() + : m_pBone(NULL) + , m_strDisplayName("") { - _skinData = var; - - setScaleX(_skinData.scaleX); - setScaleY(_skinData.scaleY); - setRotation(CC_RADIANS_TO_DEGREES(_skinData.skewX)); - setPosition(Point(_skinData.x, _skinData.y)); - - _skinTransform = getNodeToParentTransform(); + m_tSkinTransform = AffineTransformIdentity; } -const BaseData &Skin::getSkinData() const +bool CCSkin::initWithSpriteFrameName(const char *pszSpriteFrameName) { - return _skinData; + bool ret = Sprite::initWithSpriteFrameName(pszSpriteFrameName); + + if (ret) + { + TextureAtlas *atlas = CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); + setTextureAtlas(atlas); + + m_strDisplayName = pszSpriteFrameName; + } + + return ret; } -void Skin::updateTransform() +bool CCSkin::initWithFile(const char *pszFilename) { - _transform = AffineTransformConcat(_skinTransform, _bone->nodeToArmatureTransform()); + bool ret = Sprite::initWithFile(pszFilename); + + if (ret) + { + TextureAtlas *atlas = CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); + setTextureAtlas(atlas); + + m_strDisplayName = pszFilename; + } + + return ret; } -void Skin::draw() +void CCSkin::setSkinData(const CCBaseData &var) +{ + m_sSkinData = var; + + setScaleX(m_sSkinData.scaleX); + setScaleY(m_sSkinData.scaleY); + setRotation(CC_RADIANS_TO_DEGREES(m_sSkinData.skewX)); + setPosition(Point(m_sSkinData.x, m_sSkinData.y)); + + m_tSkinTransform = getNodeToParentTransform(); +} + +const CCBaseData &CCSkin::getSkinData() const +{ + return m_sSkinData; +} + +void CCSkin::updateArmatureTransform() +{ + _transform = AffineTransformConcat(m_tSkinTransform, m_pBone->getNodeToArmatureTransform()); +} + +void CCSkin::updateTransform() { // If it is not visible, or one of its ancestors is not visible, then do nothing: if( !_visible) @@ -97,7 +143,7 @@ void Skin::draw() // calculate the Quad based on the Affine Matrix // - Size size = _rect.size; + Size &size = _rect.size; float x1 = _offsetPosition.x; float y1 = _offsetPosition.y; @@ -137,4 +183,22 @@ void Skin::draw() } } -}}} // namespace cocos2d { namespace extension { namespace armature { +AffineTransform CCSkin::getNodeToWorldTransform() +{ + return AffineTransformConcat(_transform, m_pBone->getArmature()->getNodeToWorldTransform()); +} + +AffineTransform CCSkin::getNodeToWorldTransformAR() +{ + AffineTransform displayTransform = _transform; + Point anchorPoint = _anchorPointInPoints; + + anchorPoint = PointApplyAffineTransform(anchorPoint, displayTransform); + + displayTransform.tx = anchorPoint.x; + displayTransform.ty = anchorPoint.y; + + return AffineTransformConcat(displayTransform, m_pBone->getArmature()->getNodeToWorldTransform()); +} + +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCSkin.h b/extensions/CocoStudio/Armature/display/CCSkin.h index 5a37572c31..408ff647e5 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.h +++ b/extensions/CocoStudio/Armature/display/CCSkin.h @@ -28,26 +28,34 @@ THE SOFTWARE. #include "../utils/CCArmatureDefine.h" #include "../CCBone.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -class Skin : public Sprite +class CCSkin : public Sprite { public: - static Skin *create(); - static Skin *createWithSpriteFrameName(const char *pszSpriteFrameName); + static CCSkin *create(); + static CCSkin *createWithSpriteFrameName(const char *pszSpriteFrameName); + static CCSkin *create(const char *pszFileName); public: - Skin(); + CCSkin(); + bool initWithSpriteFrameName(const char *pszSpriteFrameName); + bool initWithFile(const char *pszFilename); + + void updateArmatureTransform(); void updateTransform(); - void draw(); - CC_PROPERTY_PASS_BY_REF(BaseData, _skinData, SkinData); - CC_SYNTHESIZE(Bone *, _bone, Bone); + AffineTransform getNodeToWorldTransform(); + AffineTransform getNodeToWorldTransformAR(); + + CC_PROPERTY_PASS_BY_REF(CCBaseData, m_sSkinData, SkinData); + CC_SYNTHESIZE(CCBone *, m_pBone, Bone); protected: - AffineTransform _skinTransform; + AffineTransform m_tSkinTransform; + CC_SYNTHESIZE_READONLY(std::string, m_strDisplayName, DisplayName) }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCSKIN_H__*/ diff --git a/extensions/CocoStudio/Armature/external_tool/CCTexture2DMutable.cpp b/extensions/CocoStudio/Armature/external_tool/CCTexture2DMutable.cpp deleted file mode 100644 index b9cf9084b2..0000000000 --- a/extensions/CocoStudio/Armature/external_tool/CCTexture2DMutable.cpp +++ /dev/null @@ -1,312 +0,0 @@ -// -// Texture2DMutable.cpp -// Ported to C++ by Dmitry Matyukhin -// -// MutableTexture.m -// Created by Lam Hoang Pham. -// Improved by Manuel Martinez-Almeida. -// - - -#include "CCTexture2DMutable.h" - - -using namespace cocos2d; - -#if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA -void* Texture2DMutable::getOriginalTexData() { - return originalData_; -} -#endif - -void* Texture2DMutable::getTexData() { - return data_; -} - -void Texture2DMutable::setTexData(void *var) { - data_ = var; -} - - -void Texture2DMutable::releaseData(void* data) -{ - //Don't free the data -} - -void* Texture2DMutable::keepData(void* data, unsigned int lenght) -{ - void *newData = malloc(lenght); - memmove(newData, data, lenght); - return newData; -} - -bool Texture2DMutable::initWithImageFile(const char *imageFile, cocos2d::Texture2D::PixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const cocos2d::Size& contentSize) -{ - image_ = new cocos2d::Image(); - image_->initWithImageFile(imageFile); - - - return initWithData(image_->getData(), image_->getDataLen(), pixelFormat, pixelsWide, pixelsHigh, contentSize); -} - -bool Texture2DMutable::initWithImageFile(const char *imageFile) -{ - image_ = new cocos2d::Image(); - image_->initWithImageFile(imageFile); - - bool hasAlpha = image_->hasAlpha(); - Size imageSize = Size((float)(image_->getWidth()), (float)(image_->getHeight())); - size_t bpp = image_->getBitPerPixel(); - cocos2d::Texture2D::PixelFormat pixelFormat; - - // compute pixel format - if(hasAlpha) - { - pixelFormat = Texture2D::PixelFormat::DEFAULT; - } - else - { - if (bpp >= 8) - { - pixelFormat = Texture2D::PixelFormat::RGB888; - } - else - { - pixelFormat = Texture2D::PixelFormat::RGB565; - } - - } - - return initWithData(image_->getData(), image_->getDataLen(), pixelFormat, imageSize.width, imageSize.height, imageSize); -} - -bool Texture2DMutable::initWithData(const void* data, int dataLen, Texture2D::PixelFormat pixelFormat, unsigned int width, unsigned int height, const Size& size) -{ - if(!Texture2D::initWithData(data, dataLen, pixelFormat, width, height, size)) { - return false; - } - - switch (pixelFormat) { - case Texture2D::PixelFormat::RGBA8888: bytesPerPixel_ = 4; break; - case Texture2D::PixelFormat::A8: bytesPerPixel_ = 1; break; - case Texture2D::PixelFormat::RGBA4444: - case Texture2D::PixelFormat::RGB565: - case Texture2D::PixelFormat::RGB5A1: - bytesPerPixel_ = 2; - break; - default:break; - } - - data_ = (void*) data; - -#if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA - unsigned int max = width * height * bytesPerPixel_; - originalData_ = malloc(max); - memcpy(originalData_, data_, max); -#endif - - return true; -} - -Color4B Texture2DMutable::pixelAt(const Point& pt) -{ - - Color4B c(0, 0, 0, 0); - if(!data_) return c; - if(pt.x < 0 || pt.y < 0) return c; - if(pt.x >= _contentSize.width || pt.y >= _contentSize.height) return c; - - //! 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 = _pixelsHigh - pt.y; - - if(_pixelFormat == Texture2D::PixelFormat::RGBA8888){ - unsigned int *pixel = (unsigned int *)data_; - pixel = pixel + (y * _pixelsWide) + x; - c.r = *pixel & 0xff; - c.g = (*pixel >> 8) & 0xff; - c.b = (*pixel >> 16) & 0xff; - c.a = (*pixel >> 24) & 0xff; - } else if(_pixelFormat == Texture2D::PixelFormat::RGBA4444){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * _pixelsWide) + x; - c.a = ((*pixel & 0xf) << 4) | (*pixel & 0xf); - c.b = (((*pixel >> 4) & 0xf) << 4) | ((*pixel >> 4) & 0xf); - c.g = (((*pixel >> 8) & 0xf) << 4) | ((*pixel >> 8) & 0xf); - c.r = (((*pixel >> 12) & 0xf) << 4) | ((*pixel >> 12) & 0xf); - } else if(_pixelFormat == Texture2D::PixelFormat::RGB5A1){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * _pixelsWide) + x; - c.r = ((*pixel >> 11) & 0x1f)<<3; - c.g = ((*pixel >> 6) & 0x1f)<<3; - c.b = ((*pixel >> 1) & 0x1f)<<3; - c.a = (*pixel & 0x1)*255; - } else if(_pixelFormat == Texture2D::PixelFormat::RGB565){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * _pixelsWide) + x; - c.b = (*pixel & 0x1f)<<3; - c.g = ((*pixel >> 5) & 0x3f)<<2; - c.r = ((*pixel >> 11) & 0x1f)<<3; - c.a = 255; - } else if(_pixelFormat == Texture2D::PixelFormat::A8){ - GLubyte *pixel = (GLubyte *)data_; - c.a = pixel[(y * _pixelsWide) + x]; - // Default white - c.r = 255; - c.g = 255; - c.b = 255; - } - - //log("color : %i, %i, %i, %i", c.r, c.g, c.b, c.a); - - return c; -} - -bool Texture2DMutable::setPixelAt(const Point& pt, Color4B c) -{ - if(!data_)return false; - if(pt.x < 0 || pt.y < 0) return false; - if(pt.x >= _contentSize.width || pt.y >= _contentSize.height) return false; - unsigned int x = pt.x, y = pt.y; - - dirty_ = true; - - // Shifted bit placement based on little-endian, let's make this more - // portable =/ - - if(_pixelFormat == Texture2D::PixelFormat::RGBA8888){ - unsigned int *pixel = (unsigned int *)data_; - pixel[(y * _pixelsWide) + x] = (c.a << 24) | (c.b << 16) | (c.g << 8) | c.r; - } else if(_pixelFormat == Texture2D::PixelFormat::RGBA4444){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * _pixelsWide) + x; - *pixel = ((c.r >> 4) << 12) | ((c.g >> 4) << 8) | ((c.b >> 4) << 4) | (c.a >> 4); - } else if(_pixelFormat == Texture2D::PixelFormat::RGB5A1){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * _pixelsWide) + x; - *pixel = ((c.r >> 3) << 11) | ((c.g >> 3) << 6) | ((c.b >> 3) << 1) | (c.a > 0); - } else if(_pixelFormat == Texture2D::PixelFormat::RGB565){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * _pixelsWide) + x; - *pixel = ((c.r >> 3) << 11) | ((c.g >> 2) << 5) | (c.b >> 3); - } else if(_pixelFormat == Texture2D::PixelFormat::A8){ - GLubyte *pixel = (GLubyte *)data_; - pixel[(y * _pixelsWide) + x] = c.a; - } else { - dirty_ = false; - return false; - } - return true; -} - -void Texture2DMutable::fill(Color4B p) -{ - for(int r = 0; r < _contentSize.height; ++r) - for(int c = 0; c < _contentSize.width; ++c) - this->setPixelAt(Point(c, r), p); -} - -Texture2D* Texture2DMutable::copyMutable(bool isMutable ) -{ - Texture2D* co; - if(isMutable) - { - int mem = _pixelsWide*_pixelsHigh*bytesPerPixel_; - void *newData = malloc(mem); - memcpy(newData, data_, mem); - co = new Texture2DMutable(); - if (!co->initWithData(newData, mem, _pixelFormat, _pixelsWide, _pixelsHigh, _contentSize)) { - delete co; - co = NULL; - } - }else { - - co = new Texture2D(); - if (!co->initWithData(data_, _pixelsWide*_pixelsHigh*bytesPerPixel_, _pixelFormat, _pixelsWide, _pixelsHigh, _contentSize)) { - delete co; - co = NULL; - } - } - - return co; -} - -Texture2DMutable* Texture2DMutable::copy() -{ - return (Texture2DMutable*)this->copyMutable( true ); -} - -void Texture2DMutable::copy(Texture2DMutable* textureToCopy, const Point& offset) -{ - for(int r = 0; r < _contentSize.height;++r){ - for(int c = 0; c < _contentSize.width; ++c){ - setPixelAt(Point(c + offset.x, r + offset.y), textureToCopy->pixelAt(Point(c, r))); - } - } -} - -void Texture2DMutable::restore() -{ -#if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA - memcpy(data_, originalData_, bytesPerPixel_*_pixelsWide*_pixelsHigh); - this->apply(); -#else - //You should set CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA 1 in Texture2DMutable.h - CCASSERT(false, "Exception: MutableTexture.restore was disabled by the user."); -#endif -} - -void Texture2DMutable::apply() -{ - if(!data_) return; - - glBindTexture(GL_TEXTURE_2D, _name); - - switch(_pixelFormat) - { - case Texture2D::PixelFormat::RGBA8888: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _pixelsWide, _pixelsHigh, 0, GL_RGBA, GL_UNSIGNED_BYTE, data_); - break; - case Texture2D::PixelFormat::RGBA4444: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _pixelsWide, _pixelsHigh, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, data_); - break; - case Texture2D::PixelFormat::RGB5A1: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _pixelsWide, _pixelsHigh, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, data_); - break; - case Texture2D::PixelFormat::RGB565: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _pixelsWide, _pixelsHigh, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data_); - break; - case Texture2D::PixelFormat::A8: - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, _pixelsWide, _pixelsHigh, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data_); - break; - default: - CCASSERT(false, "NSInternalInconsistencyException"); - - } - glBindTexture(GL_TEXTURE_2D, 0); - dirty_ = false; -} - -void *Texture2DMutable::getData() -{ - return data_; -} - -Texture2DMutable::Texture2DMutable(void) -{ - image_ = NULL; -} - -Texture2DMutable::~Texture2DMutable(void) -{ - CCLOGINFO("deallocing Texture2DMutable: %p", this); - - CC_SAFE_DELETE(image_); - - free(data_); -#if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA - free(originalData_); -#endif - -} - diff --git a/extensions/CocoStudio/Armature/external_tool/CCTexture2DMutable.h b/extensions/CocoStudio/Armature/external_tool/CCTexture2DMutable.h deleted file mode 100644 index 27d8c24560..0000000000 --- a/extensions/CocoStudio/Armature/external_tool/CCTexture2DMutable.h +++ /dev/null @@ -1,86 +0,0 @@ -// -// Texture2DMutable.h -// Ported to C++ by Dmitry Matyukhin -// -// MutableTexture.m -// Created by Lam Hoang Pham. -// Improved by Manuel Martinez-Almeida. -// - -#ifndef Texture2DMutable_cpp -#define Texture2DMutable_cpp - -#include "cocos2d.h" - -#define CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA 0 - -class Texture2DMutable : public cocos2d::Texture2D -{ -#if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA - - CC_PROPERTY_READONLY(void*, originalData_, OriginalTexData); - -#endif - - CC_PROPERTY(void*, data_, TexData); - - - unsigned int bytesPerPixel_; - bool dirty_; - - cocos2d::Image *image_; - -public: - Texture2DMutable(void); - ~Texture2DMutable(void); - - void restore(); - - /** These functions are needed to create mutable textures */ - void releaseData(void *data); - void* keepData(void *data, unsigned int length); - - bool initWithImageFile(const char *imageFile, cocos2d::Texture2D::PixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const cocos2d::Size& contentSize); - - bool initWithImageFile(const char *imageFilex); - - /** Intializes with a texture2d with data */ - bool initWithData(const void* data, int dataLen, cocos2d::Texture2D::PixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const cocos2d::Size& contentSize); - - - cocos2d::Color4B pixelAt(const cocos2d::Point& pt); - - /// - // @param pt is a point to get a pixel (0,0) is top-left to (width,height) bottom-right - // @param c is a Color4B which is a colour. - // @returns if a pixel was set - // Remember to call apply to actually update the texture canvas. - /// - bool setPixelAt(const cocos2d::Point& pt, cocos2d::Color4B c); - - /// - // Fill with specified colour - /// - void fill(cocos2d::Color4B c); - - /// - // @param textureToCopy is the texture image to copy over - // @param offset also offset's the texture image - /// - Texture2D* copyMutable(bool isMutable); - - Texture2DMutable* copy(); - - void copy(Texture2DMutable* textureToCopy, const cocos2d::Point& offset); - - /// - // apply actually updates the texture with any new data we added. - /// - void apply(); - - - void *getData(); - -}; - -#endif // Texture2DMutable_cpp diff --git a/extensions/CocoStudio/Armature/external_tool/GLES-Render.cpp b/extensions/CocoStudio/Armature/external_tool/GLES-Render.cpp deleted file mode 100644 index 3ccbee1040..0000000000 --- a/extensions/CocoStudio/Armature/external_tool/GLES-Render.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#include "GLES-Render.h" -#include "cocos2d.h" -#include -#include -#include - -namespace cocos2d { namespace extension { namespace armature { - -USING_NS_CC; - -GLESDebugDraw::GLESDebugDraw() - : mRatio( 1.0f ) -{ - this->initShader(); -} - -GLESDebugDraw::GLESDebugDraw( float32 ratio ) - : mRatio( ratio ) -{ - this->initShader(); -} - -void GLESDebugDraw::initShader( void ) -{ - mShaderProgram = ShaderCache::getInstance()->programForKey(GLProgram::SHADER_NAME_POSITION_U_COLOR); - - mColorLocation = glGetUniformLocation( mShaderProgram->getProgram(), "u_color"); -} - -void GLESDebugDraw::DrawPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - b2Vec2* vertices = new b2Vec2[vertexCount]; - for( int i=0;isetUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); - glDrawArrays(GL_LINE_LOOP, 0, vertexCount); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); - - delete[] vertices; -} - -void GLESDebugDraw::DrawSolidPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - b2Vec2* vertices = new b2Vec2[vertexCount]; - for( int i=0;isetUniformLocationWith4f(mColorLocation, color.r*0.5f, color.g*0.5f, color.b*0.5f, 0.5f); - - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); - - glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount); - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - glDrawArrays(GL_LINE_LOOP, 0, vertexCount); - - CC_INCREMENT_GL_DRAWS(2); - - CHECK_GL_ERROR_DEBUG(); - - delete[] vertices; -} - -void GLESDebugDraw::DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - const float32 k_segments = 16.0f; - int vertexCount=16; - const float32 k_increment = 2.0f * b2_pi / k_segments; - float32 theta = 0.0f; - - GLfloat* glVertices = new GLfloat[vertexCount*2]; - for (int i = 0; i < k_segments; ++i) - { - b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta)); - glVertices[i*2]=v.x * mRatio; - glVertices[i*2+1]=v.y * mRatio; - theta += k_increment; - } - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - - glDrawArrays(GL_LINE_LOOP, 0, vertexCount); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); - - delete[] glVertices; -} - -void GLESDebugDraw::DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - const float32 k_segments = 16.0f; - int vertexCount=16; - const float32 k_increment = 2.0f * b2_pi / k_segments; - float32 theta = 0.0f; - - GLfloat* glVertices = new GLfloat[vertexCount*2]; - for (int i = 0; i < k_segments; ++i) - { - b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta)); - glVertices[i*2]=v.x * mRatio; - glVertices[i*2+1]=v.y * mRatio; - theta += k_increment; - } - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r*0.5f, color.g*0.5f, color.b*0.5f, 0.5f); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount); - - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - glDrawArrays(GL_LINE_LOOP, 0, vertexCount); - - // Draw the axis line - DrawSegment(center,center+radius*axis,color); - - CC_INCREMENT_GL_DRAWS(2); - - CHECK_GL_ERROR_DEBUG(); - - delete[] glVertices; -} - -void GLESDebugDraw::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - - GLfloat glVertices[] = - { - p1.x * mRatio, p1.y * mRatio, - p2.x * mRatio, p2.y * mRatio - }; - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - - glDrawArrays(GL_LINES, 0, 2); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); -} - -void GLESDebugDraw::DrawTransform(const b2Transform& xf) -{ - b2Vec2 p1 = xf.p, p2; - const float32 k_axisScale = 0.4f; - p2 = p1 + k_axisScale * xf.q.GetXAxis(); - DrawSegment(p1, p2, b2Color(1,0,0)); - - p2 = p1 + k_axisScale * xf.q.GetYAxis(); - DrawSegment(p1,p2,b2Color(0,1,0)); -} - -void GLESDebugDraw::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - - // glPointSize(size); - - GLfloat glVertices[] = { - p.x * mRatio, p.y * mRatio - }; - - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - - glDrawArrays(GL_POINTS, 0, 1); - // glPointSize(1.0f); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); -} - -void GLESDebugDraw::DrawString(int x, int y, const char *string, ...) -{ -// NSLog(@"DrawString: unsupported: %s", string); - //printf(string); - /* Unsupported as yet. Could replace with bitmap font renderer at a later date */ -} - -void GLESDebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color) -{ - mShaderProgram->use(); - mShaderProgram->setUniformsForBuiltins(); - - mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, 1); - - GLfloat glVertices[] = { - aabb->lowerBound.x * mRatio, aabb->lowerBound.y * mRatio, - aabb->upperBound.x * mRatio, aabb->lowerBound.y * mRatio, - aabb->upperBound.x * mRatio, aabb->upperBound.y * mRatio, - aabb->lowerBound.x * mRatio, aabb->upperBound.y * mRatio - }; - - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - glDrawArrays(GL_LINE_LOOP, 0, 8); - - CC_INCREMENT_GL_DRAWS(1); - - CHECK_GL_ERROR_DEBUG(); - -} - -}}} // namespace cocos2d { namespace extension { namespace armature { \ No newline at end of file diff --git a/extensions/CocoStudio/Armature/external_tool/GLES-Render.h b/extensions/CocoStudio/Armature/external_tool/GLES-Render.h deleted file mode 100644 index c4acce8739..0000000000 --- a/extensions/CocoStudio/Armature/external_tool/GLES-Render.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com -* -* iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef CC_ARMATURE_GLES_RENDER_H -#define CC_ARMATURE_GLES_RENDER_H - -#include "Box2D/Box2D.h" -#include "cocos2d.h" -#include "ExtensionMacros.h" - -struct b2AABB; - -namespace cocos2d { namespace extension { namespace armature { - -// This class implements debug drawing callbacks that are invoked -// inside b2World::Step. -class GLESDebugDraw : public b2Draw -{ - float32 mRatio; - cocos2d::GLProgram* mShaderProgram; - GLint mColorLocation; - - void initShader( void ); -public: - GLESDebugDraw(); - - GLESDebugDraw( float32 ratio ); - - virtual void DrawPolygon(const b2Vec2* vertices, int vertexCount, const b2Color& color); - - virtual void DrawSolidPolygon(const b2Vec2* vertices, int vertexCount, const b2Color& color); - - virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color); - - virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color); - - virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color); - - virtual void DrawTransform(const b2Transform& xf); - - virtual void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color); - - virtual void DrawString(int x, int y, const char* string, ...); - - virtual void DrawAABB(b2AABB* aabb, const b2Color& color); -}; - -}}} // namespace cocos2d { namespace extension { namespace armature { - -#endif diff --git a/extensions/CocoStudio/Armature/external_tool/sigslot.h b/extensions/CocoStudio/Armature/external_tool/sigslot.h index ee6ea813b9..319bc29ae3 100644 --- a/extensions/CocoStudio/Armature/external_tool/sigslot.h +++ b/extensions/CocoStudio/Armature/external_tool/sigslot.h @@ -177,31 +177,31 @@ namespace sigslot { public: multi_threaded_local() { - InitializeCriticalSection(&_critsec); + InitializeCriticalSection(&m_critsec); } multi_threaded_local(const multi_threaded_local&) { - InitializeCriticalSection(&_critsec); + InitializeCriticalSection(&m_critsec); } virtual ~multi_threaded_local() { - DeleteCriticalSection(&_critsec); + DeleteCriticalSection(&m_critsec); } virtual void lock() { - EnterCriticalSection(&_critsec); + EnterCriticalSection(&m_critsec); } virtual void unlock() { - LeaveCriticalSection(&_critsec); + LeaveCriticalSection(&m_critsec); } private: - CRITICAL_SECTION _critsec; + CRITICAL_SECTION m_critsec; }; #endif // _SIGSLOT_HAS_WIN32_THREADS @@ -248,31 +248,31 @@ namespace sigslot { public: multi_threaded_local() { - pthread_mutex_init(&_mutex, NULL); + pthread_mutex_init(&m_mutex, NULL); } multi_threaded_local(const multi_threaded_local&) { - pthread_mutex_init(&_mutex, NULL); + pthread_mutex_init(&m_mutex, NULL); } virtual ~multi_threaded_local() { - pthread_mutex_destroy(&_mutex); + pthread_mutex_destroy(&m_mutex); } virtual void lock() { - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&m_mutex); } virtual void unlock() { - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&m_mutex); } private: - pthread_mutex_t _mutex; + pthread_mutex_t m_mutex; }; #endif // _SIGSLOT_HAS_POSIX_THREADS @@ -280,17 +280,17 @@ namespace sigslot { class lock_block { public: - mt_policy *_mutex; + mt_policy *m_mutex; lock_block(mt_policy *mtx) - : _mutex(mtx) + : m_mutex(mtx) { - _mutex->lock(); + m_mutex->lock(); } ~lock_block() { - _mutex->unlock(); + m_mutex->unlock(); } }; @@ -301,8 +301,6 @@ namespace sigslot { class _connection_base0 { public: - virtual ~_connection_base0() { } - virtual has_slots* getdest() const = 0; virtual void emit() = 0; virtual _connection_base0* clone() = 0; @@ -313,7 +311,6 @@ namespace sigslot { class _connection_base1 { public: - virtual ~_connection_base1() {}; virtual has_slots* getdest() const = 0; virtual void emit(arg1_type) = 0; virtual _connection_base1* clone() = 0; @@ -324,7 +321,6 @@ namespace sigslot { class _connection_base2 { public: - virtual ~_connection_base2() {}; virtual has_slots* getdest() const = 0; virtual void emit(arg1_type, arg2_type) = 0; virtual _connection_base2* clone() = 0; @@ -335,7 +331,6 @@ namespace sigslot { class _connection_base3 { public: - virtual ~_connection_base3() {}; virtual has_slots* getdest() const = 0; virtual void emit(arg1_type, arg2_type, arg3_type) = 0; virtual _connection_base3* clone() = 0; @@ -346,7 +341,6 @@ namespace sigslot { class _connection_base4 { public: - virtual ~_connection_base4() {}; virtual has_slots* getdest() const = 0; virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type) = 0; virtual _connection_base4* clone() = 0; @@ -358,7 +352,6 @@ namespace sigslot { class _connection_base5 { public: - virtual ~_connection_base5() {}; virtual has_slots* getdest() const = 0; virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type) = 0; @@ -373,7 +366,6 @@ namespace sigslot { class _connection_base6 { public: - virtual ~_connection_base6() {}; virtual has_slots* getdest() const = 0; virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type) = 0; @@ -388,8 +380,6 @@ namespace sigslot { class _connection_base7 { public: - virtual ~_connection_base7() { } - virtual has_slots* getdest() const = 0; virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type) = 0; @@ -404,8 +394,6 @@ namespace sigslot { class _connection_base8 { public: - virtual ~_connection_base8() { } - virtual has_slots* getdest() const = 0; virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, arg8_type) = 0; @@ -419,8 +407,6 @@ namespace sigslot { class _signal_base : public mt_policy { public: - virtual ~_signal_base() { } - virtual void slot_disconnect(has_slots* pslot) = 0; virtual void slot_duplicate(const has_slots* poldslot, has_slots* pnewslot) = 0; }; @@ -442,13 +428,13 @@ namespace sigslot { : mt_policy(hs) { lock_block lock(this); - const_iterator it = hs._senders.begin(); - const_iterator itEnd = hs._senders.end(); + const_iterator it = hs.m_senders.begin(); + const_iterator itEnd = hs.m_senders.end(); while(it != itEnd) { (*it)->slot_duplicate(&hs, this); - _senders.insert(*it); + m_senders.insert(*it); ++it; } } @@ -456,13 +442,13 @@ namespace sigslot { void signal_connect(_signal_base* sender) { lock_block lock(this); - _senders.insert(sender); + m_senders.insert(sender); } void signal_disconnect(_signal_base* sender) { lock_block lock(this); - _senders.erase(sender); + m_senders.erase(sender); } virtual ~has_slots() @@ -473,8 +459,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - const_iterator it = _senders.begin(); - const_iterator itEnd = _senders.end(); + const_iterator it = m_senders.begin(); + const_iterator itEnd = m_senders.end(); while(it != itEnd) { @@ -482,11 +468,11 @@ namespace sigslot { ++it; } - _senders.erase(_senders.begin(), _senders.end()); + m_senders.erase(m_senders.begin(), m_senders.end()); } private: - sender_set _senders; + sender_set m_senders; }; template @@ -504,13 +490,13 @@ namespace sigslot { : _signal_base(s) { lock_block lock(this); - typename connections_list::const_iterator it = s._connected_slots.begin(); - typename connections_list::const_iterator itEnd = s._connected_slots.end(); + typename connections_list::const_iterator it = s.m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); while(it != itEnd) { (*it)->getdest()->signal_connect(this); - _connected_slots.push_back((*it)->clone()); + m_connected_slots.push_back((*it)->clone()); ++it; } @@ -524,8 +510,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - typename connections_list::const_iterator it = _connected_slots.begin(); - typename connections_list::const_iterator itEnd = _connected_slots.end(); + typename connections_list::const_iterator it = m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -535,21 +521,21 @@ namespace sigslot { ++it; } - _connected_slots.erase(_connected_slots.begin(), _connected_slots.end()); + m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); } void disconnect(has_slots* pclass) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == pclass) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); pclass->signal_disconnect(this); return; } @@ -561,8 +547,8 @@ namespace sigslot { void slot_disconnect(has_slots* pslot) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -572,7 +558,7 @@ namespace sigslot { if((*it)->getdest() == pslot) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); } it = itNext; @@ -582,14 +568,14 @@ namespace sigslot { void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == oldtarget) { - _connected_slots.push_back((*it)->duplicate(newtarget)); + m_connected_slots.push_back((*it)->duplicate(newtarget)); } ++it; @@ -597,7 +583,7 @@ namespace sigslot { } protected: - connections_list _connected_slots; + connections_list m_connected_slots; }; template @@ -615,13 +601,13 @@ namespace sigslot { : _signal_base(s) { lock_block lock(this); - typename connections_list::const_iterator it = s._connected_slots.begin(); - typename connections_list::const_iterator itEnd = s._connected_slots.end(); + typename connections_list::const_iterator it = s.m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); while(it != itEnd) { (*it)->getdest()->signal_connect(this); - _connected_slots.push_back((*it)->clone()); + m_connected_slots.push_back((*it)->clone()); ++it; } @@ -630,14 +616,14 @@ namespace sigslot { void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == oldtarget) { - _connected_slots.push_back((*it)->duplicate(newtarget)); + m_connected_slots.push_back((*it)->duplicate(newtarget)); } ++it; @@ -652,8 +638,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - typename connections_list::const_iterator it = _connected_slots.begin(); - typename connections_list::const_iterator itEnd = _connected_slots.end(); + typename connections_list::const_iterator it = m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -663,21 +649,21 @@ namespace sigslot { ++it; } - _connected_slots.erase(_connected_slots.begin(), _connected_slots.end()); + m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); } void disconnect(has_slots* pclass) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == pclass) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); pclass->signal_disconnect(this); return; } @@ -689,8 +675,8 @@ namespace sigslot { void slot_disconnect(has_slots* pslot) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -700,7 +686,7 @@ namespace sigslot { if((*it)->getdest() == pslot) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); } it = itNext; @@ -709,7 +695,7 @@ namespace sigslot { protected: - connections_list _connected_slots; + connections_list m_connected_slots; }; template @@ -728,13 +714,13 @@ namespace sigslot { : _signal_base(s) { lock_block lock(this); - typename connections_list::const_iterator it = s._connected_slots.begin(); - typename connections_list::const_iterator itEnd = s._connected_slots.end(); + typename connections_list::const_iterator it = s.m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); while(it != itEnd) { (*it)->getdest()->signal_connect(this); - _connected_slots.push_back((*it)->clone()); + m_connected_slots.push_back((*it)->clone()); ++it; } @@ -743,14 +729,14 @@ namespace sigslot { void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == oldtarget) { - _connected_slots.push_back((*it)->duplicate(newtarget)); + m_connected_slots.push_back((*it)->duplicate(newtarget)); } ++it; @@ -765,8 +751,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - typename connections_list::const_iterator it = _connected_slots.begin(); - typename connections_list::const_iterator itEnd = _connected_slots.end(); + typename connections_list::const_iterator it = m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -776,21 +762,21 @@ namespace sigslot { ++it; } - _connected_slots.erase(_connected_slots.begin(), _connected_slots.end()); + m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); } void disconnect(has_slots* pclass) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == pclass) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); pclass->signal_disconnect(this); return; } @@ -802,8 +788,8 @@ namespace sigslot { void slot_disconnect(has_slots* pslot) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -813,7 +799,7 @@ namespace sigslot { if((*it)->getdest() == pslot) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); } it = itNext; @@ -821,7 +807,7 @@ namespace sigslot { } protected: - connections_list _connected_slots; + connections_list m_connected_slots; }; template @@ -840,13 +826,13 @@ namespace sigslot { : _signal_base(s) { lock_block lock(this); - typename connections_list::const_iterator it = s._connected_slots.begin(); - typename connections_list::const_iterator itEnd = s._connected_slots.end(); + typename connections_list::const_iterator it = s.m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); while(it != itEnd) { (*it)->getdest()->signal_connect(this); - _connected_slots.push_back((*it)->clone()); + m_connected_slots.push_back((*it)->clone()); ++it; } @@ -855,14 +841,14 @@ namespace sigslot { void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == oldtarget) { - _connected_slots.push_back((*it)->duplicate(newtarget)); + m_connected_slots.push_back((*it)->duplicate(newtarget)); } ++it; @@ -877,8 +863,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - typename connections_list::const_iterator it = _connected_slots.begin(); - typename connections_list::const_iterator itEnd = _connected_slots.end(); + typename connections_list::const_iterator it = m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -888,21 +874,21 @@ namespace sigslot { ++it; } - _connected_slots.erase(_connected_slots.begin(), _connected_slots.end()); + m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); } void disconnect(has_slots* pclass) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == pclass) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); pclass->signal_disconnect(this); return; } @@ -914,8 +900,8 @@ namespace sigslot { void slot_disconnect(has_slots* pslot) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -925,7 +911,7 @@ namespace sigslot { if((*it)->getdest() == pslot) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); } it = itNext; @@ -933,7 +919,7 @@ namespace sigslot { } protected: - connections_list _connected_slots; + connections_list m_connected_slots; }; template @@ -952,13 +938,13 @@ namespace sigslot { : _signal_base(s) { lock_block lock(this); - typename connections_list::const_iterator it = s._connected_slots.begin(); - typename connections_list::const_iterator itEnd = s._connected_slots.end(); + typename connections_list::const_iterator it = s.m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); while(it != itEnd) { (*it)->getdest()->signal_connect(this); - _connected_slots.push_back((*it)->clone()); + m_connected_slots.push_back((*it)->clone()); ++it; } @@ -967,14 +953,14 @@ namespace sigslot { void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == oldtarget) { - _connected_slots.push_back((*it)->duplicate(newtarget)); + m_connected_slots.push_back((*it)->duplicate(newtarget)); } ++it; @@ -989,8 +975,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - typename connections_list::const_iterator it = _connected_slots.begin(); - typename connections_list::const_iterator itEnd = _connected_slots.end(); + typename connections_list::const_iterator it = m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1000,21 +986,21 @@ namespace sigslot { ++it; } - _connected_slots.erase(_connected_slots.begin(), _connected_slots.end()); + m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); } void disconnect(has_slots* pclass) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == pclass) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); pclass->signal_disconnect(this); return; } @@ -1026,8 +1012,8 @@ namespace sigslot { void slot_disconnect(has_slots* pslot) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1037,7 +1023,7 @@ namespace sigslot { if((*it)->getdest() == pslot) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); } it = itNext; @@ -1045,7 +1031,7 @@ namespace sigslot { } protected: - connections_list _connected_slots; + connections_list m_connected_slots; }; template(s) { lock_block lock(this); - typename connections_list::const_iterator it = s._connected_slots.begin(); - typename connections_list::const_iterator itEnd = s._connected_slots.end(); + typename connections_list::const_iterator it = s.m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); while(it != itEnd) { (*it)->getdest()->signal_connect(this); - _connected_slots.push_back((*it)->clone()); + m_connected_slots.push_back((*it)->clone()); ++it; } @@ -1081,14 +1067,14 @@ namespace sigslot { void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == oldtarget) { - _connected_slots.push_back((*it)->duplicate(newtarget)); + m_connected_slots.push_back((*it)->duplicate(newtarget)); } ++it; @@ -1103,8 +1089,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - typename connections_list::const_iterator it = _connected_slots.begin(); - typename connections_list::const_iterator itEnd = _connected_slots.end(); + typename connections_list::const_iterator it = m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1114,21 +1100,21 @@ namespace sigslot { ++it; } - _connected_slots.erase(_connected_slots.begin(), _connected_slots.end()); + m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); } void disconnect(has_slots* pclass) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == pclass) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); pclass->signal_disconnect(this); return; } @@ -1140,8 +1126,8 @@ namespace sigslot { void slot_disconnect(has_slots* pslot) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1151,7 +1137,7 @@ namespace sigslot { if((*it)->getdest() == pslot) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); } it = itNext; @@ -1159,7 +1145,7 @@ namespace sigslot { } protected: - connections_list _connected_slots; + connections_list m_connected_slots; }; template(s) { lock_block lock(this); - typename connections_list::const_iterator it = s._connected_slots.begin(); - typename connections_list::const_iterator itEnd = s._connected_slots.end(); + typename connections_list::const_iterator it = s.m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); while(it != itEnd) { (*it)->getdest()->signal_connect(this); - _connected_slots.push_back((*it)->clone()); + m_connected_slots.push_back((*it)->clone()); ++it; } @@ -1195,14 +1181,14 @@ namespace sigslot { void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == oldtarget) { - _connected_slots.push_back((*it)->duplicate(newtarget)); + m_connected_slots.push_back((*it)->duplicate(newtarget)); } ++it; @@ -1217,8 +1203,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - typename connections_list::const_iterator it = _connected_slots.begin(); - typename connections_list::const_iterator itEnd = _connected_slots.end(); + typename connections_list::const_iterator it = m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1228,21 +1214,21 @@ namespace sigslot { ++it; } - _connected_slots.erase(_connected_slots.begin(), _connected_slots.end()); + m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); } void disconnect(has_slots* pclass) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == pclass) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); pclass->signal_disconnect(this); return; } @@ -1254,8 +1240,8 @@ namespace sigslot { void slot_disconnect(has_slots* pslot) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1265,7 +1251,7 @@ namespace sigslot { if((*it)->getdest() == pslot) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); } it = itNext; @@ -1273,7 +1259,7 @@ namespace sigslot { } protected: - connections_list _connected_slots; + connections_list m_connected_slots; }; template(s) { lock_block lock(this); - typename connections_list::const_iterator it = s._connected_slots.begin(); - typename connections_list::const_iterator itEnd = s._connected_slots.end(); + typename connections_list::const_iterator it = s.m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); while(it != itEnd) { (*it)->getdest()->signal_connect(this); - _connected_slots.push_back((*it)->clone()); + m_connected_slots.push_back((*it)->clone()); ++it; } @@ -1309,14 +1295,14 @@ namespace sigslot { void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == oldtarget) { - _connected_slots.push_back((*it)->duplicate(newtarget)); + m_connected_slots.push_back((*it)->duplicate(newtarget)); } ++it; @@ -1331,8 +1317,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - typename connections_list::const_iterator it = _connected_slots.begin(); - typename connections_list::const_iterator itEnd = _connected_slots.end(); + typename connections_list::const_iterator it = m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1342,21 +1328,21 @@ namespace sigslot { ++it; } - _connected_slots.erase(_connected_slots.begin(), _connected_slots.end()); + m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); } void disconnect(has_slots* pclass) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == pclass) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); pclass->signal_disconnect(this); return; } @@ -1368,8 +1354,8 @@ namespace sigslot { void slot_disconnect(has_slots* pslot) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1379,7 +1365,7 @@ namespace sigslot { if((*it)->getdest() == pslot) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); } it = itNext; @@ -1387,7 +1373,7 @@ namespace sigslot { } protected: - connections_list _connected_slots; + connections_list m_connected_slots; }; template(s) { lock_block lock(this); - typename connections_list::const_iterator it = s._connected_slots.begin(); - typename connections_list::const_iterator itEnd = s._connected_slots.end(); + typename connections_list::const_iterator it = s.m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); while(it != itEnd) { (*it)->getdest()->signal_connect(this); - _connected_slots.push_back((*it)->clone()); + m_connected_slots.push_back((*it)->clone()); ++it; } @@ -1424,14 +1410,14 @@ namespace sigslot { void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == oldtarget) { - _connected_slots.push_back((*it)->duplicate(newtarget)); + m_connected_slots.push_back((*it)->duplicate(newtarget)); } ++it; @@ -1446,8 +1432,8 @@ namespace sigslot { void disconnect_all() { lock_block lock(this); - typename connections_list::const_iterator it = _connected_slots.begin(); - typename connections_list::const_iterator itEnd = _connected_slots.end(); + typename connections_list::const_iterator it = m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1457,21 +1443,21 @@ namespace sigslot { ++it; } - _connected_slots.erase(_connected_slots.begin(), _connected_slots.end()); + m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); } void disconnect(has_slots* pclass) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { if((*it)->getdest() == pclass) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); pclass->signal_disconnect(this); return; } @@ -1483,8 +1469,8 @@ namespace sigslot { void slot_disconnect(has_slots* pslot) { lock_block lock(this); - typename connections_list::iterator it = _connected_slots.begin(); - typename connections_list::iterator itEnd = _connected_slots.end(); + typename connections_list::iterator it = m_connected_slots.begin(); + typename connections_list::iterator itEnd = m_connected_slots.end(); while(it != itEnd) { @@ -1494,7 +1480,7 @@ namespace sigslot { if((*it)->getdest() == pslot) { delete *it; - _connected_slots.erase(it); + m_connected_slots.erase(it); } it = itNext; @@ -1502,7 +1488,7 @@ namespace sigslot { } protected: - connections_list _connected_slots; + connections_list m_connected_slots; }; @@ -1512,14 +1498,14 @@ namespace sigslot { public: _connection0() { - _pobject = NULL; - _pmemfun = NULL; + m_pobject = NULL; + m_pmemfun = NULL; } _connection0(dest_type* pobject, void (dest_type::*pmemfun)()) { - _pobject = pobject; - _pmemfun = pmemfun; + m_pobject = pobject; + m_pmemfun = pmemfun; } virtual _connection_base0* clone() @@ -1529,22 +1515,22 @@ namespace sigslot { virtual _connection_base0* duplicate(has_slots* pnewdest) { - return new _connection0((dest_type *)pnewdest, _pmemfun); + return new _connection0((dest_type *)pnewdest, m_pmemfun); } virtual void emit() { - (_pobject->*_pmemfun)(); + (m_pobject->*m_pmemfun)(); } virtual has_slots* getdest() const { - return _pobject; + return m_pobject; } private: - dest_type* _pobject; - void (dest_type::* _pmemfun)(); + dest_type* m_pobject; + void (dest_type::* m_pmemfun)(); }; template @@ -1553,14 +1539,14 @@ namespace sigslot { public: _connection1() { - _pobject = NULL; - _pmemfun = NULL; + m_pobject = NULL; + m_pmemfun = NULL; } _connection1(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type)) { - _pobject = pobject; - _pmemfun = pmemfun; + m_pobject = pobject; + m_pmemfun = pmemfun; } virtual _connection_base1* clone() @@ -1570,22 +1556,22 @@ namespace sigslot { virtual _connection_base1* duplicate(has_slots* pnewdest) { - return new _connection1((dest_type *)pnewdest, _pmemfun); + return new _connection1((dest_type *)pnewdest, m_pmemfun); } virtual void emit(arg1_type a1) { - (_pobject->*_pmemfun)(a1); + (m_pobject->*m_pmemfun)(a1); } virtual has_slots* getdest() const { - return _pobject; + return m_pobject; } private: - dest_type* _pobject; - void (dest_type::* _pmemfun)(arg1_type); + dest_type* m_pobject; + void (dest_type::* m_pmemfun)(arg1_type); }; template @@ -1594,15 +1580,15 @@ namespace sigslot { public: _connection2() { - _pobject = NULL; - _pmemfun = NULL; + m_pobject = NULL; + m_pmemfun = NULL; } _connection2(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, arg2_type)) { - _pobject = pobject; - _pmemfun = pmemfun; + m_pobject = pobject; + m_pmemfun = pmemfun; } virtual _connection_base2* clone() @@ -1612,22 +1598,22 @@ namespace sigslot { virtual _connection_base2* duplicate(has_slots* pnewdest) { - return new _connection2((dest_type *)pnewdest, _pmemfun); + return new _connection2((dest_type *)pnewdest, m_pmemfun); } virtual void emit(arg1_type a1, arg2_type a2) { - (_pobject->*_pmemfun)(a1, a2); + (m_pobject->*m_pmemfun)(a1, a2); } virtual has_slots* getdest() const { - return _pobject; + return m_pobject; } private: - dest_type* _pobject; - void (dest_type::* _pmemfun)(arg1_type, arg2_type); + dest_type* m_pobject; + void (dest_type::* m_pmemfun)(arg1_type, arg2_type); }; template @@ -1636,15 +1622,15 @@ namespace sigslot { public: _connection3() { - _pobject = NULL; - _pmemfun = NULL; + m_pobject = NULL; + m_pmemfun = NULL; } _connection3(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, arg2_type, arg3_type)) { - _pobject = pobject; - _pmemfun = pmemfun; + m_pobject = pobject; + m_pmemfun = pmemfun; } virtual _connection_base3* clone() @@ -1654,22 +1640,22 @@ namespace sigslot { virtual _connection_base3* duplicate(has_slots* pnewdest) { - return new _connection3((dest_type *)pnewdest, _pmemfun); + return new _connection3((dest_type *)pnewdest, m_pmemfun); } virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3) { - (_pobject->*_pmemfun)(a1, a2, a3); + (m_pobject->*m_pmemfun)(a1, a2, a3); } virtual has_slots* getdest() const { - return _pobject; + return m_pobject; } private: - dest_type* _pobject; - void (dest_type::* _pmemfun)(arg1_type, arg2_type, arg3_type); + dest_type* m_pobject; + void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type); }; template* clone() @@ -1698,23 +1684,23 @@ namespace sigslot { virtual _connection_base4* duplicate(has_slots* pnewdest) { - return new _connection4((dest_type *)pnewdest, _pmemfun); + return new _connection4((dest_type *)pnewdest, m_pmemfun); } virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4) { - (_pobject->*_pmemfun)(a1, a2, a3, a4); + (m_pobject->*m_pmemfun)(a1, a2, a3, a4); } virtual has_slots* getdest() const { - return _pobject; + return m_pobject; } private: - dest_type* _pobject; - void (dest_type::* _pmemfun)(arg1_type, arg2_type, arg3_type, + dest_type* m_pobject; + void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type); }; @@ -1726,15 +1712,15 @@ namespace sigslot { public: _connection5() { - _pobject = NULL; - _pmemfun = NULL; + m_pobject = NULL; + m_pmemfun = NULL; } _connection5(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type)) { - _pobject = pobject; - _pmemfun = pmemfun; + m_pobject = pobject; + m_pmemfun = pmemfun; } virtual _connection_base5* duplicate(has_slots* pnewdest) { return new _connection5((dest_type *)pnewdest, _pmemfun); + arg5_type, mt_policy>((dest_type *)pnewdest, m_pmemfun); } virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5) { - (_pobject->*_pmemfun)(a1, a2, a3, a4, a5); + (m_pobject->*m_pmemfun)(a1, a2, a3, a4, a5); } virtual has_slots* getdest() const { - return _pobject; + return m_pobject; } private: - dest_type* _pobject; - void (dest_type::* _pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, + dest_type* m_pobject; + void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type); }; @@ -1776,15 +1762,15 @@ namespace sigslot { public: _connection6() { - _pobject = NULL; - _pmemfun = NULL; + m_pobject = NULL; + m_pmemfun = NULL; } _connection6(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type)) { - _pobject = pobject; - _pmemfun = pmemfun; + m_pobject = pobject; + m_pmemfun = pmemfun; } virtual _connection_base6* duplicate(has_slots* pnewdest) { return new _connection6((dest_type *)pnewdest, _pmemfun); + arg5_type, arg6_type, mt_policy>((dest_type *)pnewdest, m_pmemfun); } virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6) { - (_pobject->*_pmemfun)(a1, a2, a3, a4, a5, a6); + (m_pobject->*m_pmemfun)(a1, a2, a3, a4, a5, a6); } virtual has_slots* getdest() const { - return _pobject; + return m_pobject; } private: - dest_type* _pobject; - void (dest_type::* _pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, + dest_type* m_pobject; + void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type); }; @@ -1826,15 +1812,15 @@ namespace sigslot { public: _connection7() { - _pobject = NULL; - _pmemfun = NULL; + m_pobject = NULL; + m_pmemfun = NULL; } _connection7(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type)) { - _pobject = pobject; - _pmemfun = pmemfun; + m_pobject = pobject; + m_pmemfun = pmemfun; } virtual _connection_base7* duplicate(has_slots* pnewdest) { return new _connection7((dest_type *)pnewdest, _pmemfun); + arg5_type, arg6_type, arg7_type, mt_policy>((dest_type *)pnewdest, m_pmemfun); } virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6, arg7_type a7) { - (_pobject->*_pmemfun)(a1, a2, a3, a4, a5, a6, a7); + (m_pobject->*m_pmemfun)(a1, a2, a3, a4, a5, a6, a7); } virtual has_slots* getdest() const { - return _pobject; + return m_pobject; } private: - dest_type* _pobject; - void (dest_type::* _pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, + dest_type* m_pobject; + void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type); }; @@ -1877,16 +1863,16 @@ namespace sigslot { public: _connection8() { - _pobject = NULL; - _pmemfun = NULL; + m_pobject = NULL; + m_pmemfun = NULL; } _connection8(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, arg8_type)) { - _pobject = pobject; - _pmemfun = pmemfun; + m_pobject = pobject; + m_pmemfun = pmemfun; } virtual _connection_base8* duplicate(has_slots* pnewdest) { return new _connection8((dest_type *)pnewdest, _pmemfun); + arg5_type, arg6_type, arg7_type, arg8_type, mt_policy>((dest_type *)pnewdest, m_pmemfun); } virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6, arg7_type a7, arg8_type a8) { - (_pobject->*_pmemfun)(a1, a2, a3, a4, a5, a6, a7, a8); + (m_pobject->*m_pmemfun)(a1, a2, a3, a4, a5, a6, a7, a8); } virtual has_slots* getdest() const { - return _pobject; + return m_pobject; } private: - dest_type* _pobject; - void (dest_type::* _pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, + dest_type* m_pobject; + void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, arg8_type); }; @@ -1944,15 +1930,15 @@ namespace sigslot { _connection0* conn = new _connection0(pclass, pmemfun); - _signal_base0::_connected_slots.push_back(conn); + _signal_base0::m_connected_slots.push_back(conn); pclass->signal_connect(this); } void emit() { lock_block lock(this); - typename connections_list::const_iterator itNext, it = _signal_base0::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = _signal_base0::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = _signal_base0::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = _signal_base0::m_connected_slots.end(); while(it != itEnd) { @@ -1968,8 +1954,8 @@ namespace sigslot { void operator()() { lock_block lock(this); - typename connections_list::const_iterator itNext, it = _signal_base0::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = _signal_base0::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = _signal_base0::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = _signal_base0::m_connected_slots.end(); while(it != itEnd) { @@ -2007,15 +1993,15 @@ namespace sigslot { lock_block lock(this); _connection1* conn = new _connection1(pclass, pmemfun); - signal_base::_connected_slots.push_back(conn); + signal_base::m_connected_slots.push_back(conn); pclass->signal_connect(this); } void emit(arg1_type a1) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2031,8 +2017,8 @@ namespace sigslot { void operator()(arg1_type a1) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2071,15 +2057,15 @@ namespace sigslot { lock_block lock(this); _connection2* conn = new _connection2(pclass, pmemfun); - signal_base::_connected_slots.push_back(conn); + signal_base::m_connected_slots.push_back(conn); pclass->signal_connect(this); } void emit(arg1_type a1, arg2_type a2) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2095,8 +2081,8 @@ namespace sigslot { void operator()(arg1_type a1, arg2_type a2) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2141,15 +2127,15 @@ namespace sigslot { _connection3* conn = new _connection3(pclass, pmemfun); - signal_base::_connected_slots.push_back(conn); + signal_base::m_connected_slots.push_back(conn); pclass->signal_connect(this); } void emit(arg1_type a1, arg2_type a2, arg3_type a3) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2165,8 +2151,8 @@ namespace sigslot { void operator()(arg1_type a1, arg2_type a2, arg3_type a3) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2208,15 +2194,15 @@ namespace sigslot { _connection4* conn = new _connection4(pclass, pmemfun); - signal_base::_connected_slots.push_back(conn); + signal_base::m_connected_slots.push_back(conn); pclass->signal_connect(this); } void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2232,8 +2218,8 @@ namespace sigslot { void operator()(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2278,7 +2264,7 @@ namespace sigslot { _connection5* conn = new _connection5(pclass, pmemfun); - signal_base::_connected_slots.push_back(conn); + signal_base::m_connected_slots.push_back(conn); pclass->signal_connect(this); } @@ -2286,8 +2272,8 @@ namespace sigslot { arg5_type a5) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2304,8 +2290,8 @@ namespace sigslot { arg5_type a5) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2352,7 +2338,7 @@ namespace sigslot { arg5_type, arg6_type, mt_policy>* conn = new _connection6(pclass, pmemfun); - signal_base::_connected_slots.push_back(conn); + signal_base::m_connected_slots.push_back(conn); pclass->signal_connect(this); } @@ -2360,8 +2346,8 @@ namespace sigslot { arg5_type a5, arg6_type a6) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2378,8 +2364,8 @@ namespace sigslot { arg5_type a5, arg6_type a6) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2426,7 +2412,7 @@ namespace sigslot { arg5_type, arg6_type, arg7_type, mt_policy>* conn = new _connection7(pclass, pmemfun); - signal_base::_connected_slots.push_back(conn); + signal_base::m_connected_slots.push_back(conn); pclass->signal_connect(this); } @@ -2434,8 +2420,8 @@ namespace sigslot { arg5_type a5, arg6_type a6, arg7_type a7) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2452,8 +2438,8 @@ namespace sigslot { arg5_type a5, arg6_type a6, arg7_type a7) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2502,7 +2488,7 @@ namespace sigslot { new _connection8(pclass, pmemfun); - signal_base::_connected_slots.push_back(conn); + signal_base::m_connected_slots.push_back(conn); pclass->signal_connect(this); } @@ -2510,8 +2496,8 @@ namespace sigslot { arg5_type a5, arg6_type a6, arg7_type a7, arg8_type a8) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { @@ -2528,8 +2514,8 @@ namespace sigslot { arg5_type a5, arg6_type a6, arg7_type a7, arg8_type a8) { lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::_connected_slots.end(); + typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); + typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); while(it != itEnd) { diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp index d146650af6..459208a80a 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp @@ -23,15 +23,51 @@ THE SOFTWARE. ****************************************************************************/ #include "CCColliderDetector.h" -#include "CCPhysicsWorld.h" #include "../CCBone.h" +#include "../utils/CCTransformHelp.h" + +#if ENABLE_PHYSICS_BOX2D_DETECT #include "Box2D/Box2D.h" +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +#include "chipmunk.h" +#endif -namespace cocos2d { namespace extension { namespace armature { -ColliderDetector *ColliderDetector::create() +NS_CC_EXT_ARMATURE_BEGIN + + +#if ENABLE_PHYSICS_BOX2D_DETECT +ColliderBody::ColliderBody(CCContourData *contourData) + : m_pFixture(NULL) + , m_pFilter(NULL) + , m_pContourData(contourData) { - ColliderDetector *pColliderDetector = new ColliderDetector(); + CC_SAFE_RETAIN(m_pContourData); +} +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + +ColliderBody::ColliderBody(CCContourData *contourData) + : m_pShape(NULL) + , m_pContourData(contourData) +{ + CC_SAFE_RETAIN(m_pContourData); +} +#endif + +ColliderBody::~ColliderBody() +{ + CC_SAFE_RELEASE(m_pContourData); + +#if ENABLE_PHYSICS_BOX2D_DETECT + CC_SAFE_DELETE(m_pFilter); +#endif +} + + + +CCColliderDetector *CCColliderDetector::create() +{ + CCColliderDetector *pColliderDetector = new CCColliderDetector(); if (pColliderDetector && pColliderDetector->init()) { pColliderDetector->autorelease(); @@ -41,9 +77,9 @@ ColliderDetector *ColliderDetector::create() return NULL; } -ColliderDetector *ColliderDetector::create(Bone *bone) +CCColliderDetector *CCColliderDetector::create(CCBone *bone) { - ColliderDetector *pColliderDetector = new ColliderDetector(); + CCColliderDetector *pColliderDetector = new CCColliderDetector(); if (pColliderDetector && pColliderDetector->init(bone)) { pColliderDetector->autorelease(); @@ -53,37 +89,33 @@ ColliderDetector *ColliderDetector::create(Bone *bone) return NULL; } -ColliderDetector::ColliderDetector() - : _colliderBodyList(NULL) +CCColliderDetector::CCColliderDetector() + : m_pColliderBodyList(NULL) + , m_bActive(false) { +#if ENABLE_PHYSICS_BOX2D_DETECT + m_pBody = NULL; +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + m_pBody = NULL; +#endif } -ColliderDetector::~ColliderDetector() +CCColliderDetector::~CCColliderDetector() { - Object *object = NULL; - CCARRAY_FOREACH(_colliderBodyList, object) - { - ColliderBody *colliderBody = static_cast(object); - - b2Body *body = colliderBody->getB2Body(); - PhysicsWorld::sharedPhysicsWorld()->getNoGravityWorld()->DestroyBody(body); - } - - - _colliderBodyList->removeAllObjects(); - CC_SAFE_DELETE(_colliderBodyList); + m_pColliderBodyList->removeAllObjects(); + CC_SAFE_DELETE(m_pColliderBodyList); } -bool ColliderDetector::init() +bool CCColliderDetector::init() { - _colliderBodyList = Array::create(); - CCASSERT(_colliderBodyList, "create _colliderBodyList failed!"); - _colliderBodyList->retain(); + m_pColliderBodyList = Array::create(); + CCAssert(m_pColliderBodyList, "create m_pColliderBodyList failed!"); + m_pColliderBodyList->retain(); return true; } -bool ColliderDetector::init(Bone *bone) +bool CCColliderDetector::init(CCBone *bone) { init(); setBone(bone); @@ -91,116 +123,278 @@ bool ColliderDetector::init(Bone *bone) return true; } -void ColliderDetector::addContourData(ContourData *contourData) +void CCColliderDetector::addContourData(CCContourData *contourData) { - const Array *array = contourData->vertexList; - Object *object = NULL; - - b2Vec2 *b2bv = new b2Vec2[contourData->vertexList->count()]; - - int i = 0; - CCARRAY_FOREACH(array, object) - { - ContourVertex2F *v = static_cast(object); - b2bv[i].Set(v->x / PT_RATIO, v->y / PT_RATIO); - i++; - } - - b2PolygonShape polygon; - polygon.Set(b2bv, contourData->vertexList->count()); - - CC_SAFE_DELETE(b2bv); - - b2FixtureDef fixtureDef; - fixtureDef.shape = &polygon; - fixtureDef.density = 10.0f; - fixtureDef.isSensor = true; - - b2BodyDef bodyDef; - bodyDef.type = b2_dynamicBody; - bodyDef.position = b2Vec2(0.0f, 0.0f); - bodyDef.userData = _bone; - - b2Body *body = PhysicsWorld::sharedPhysicsWorld()->getNoGravityWorld()->CreateBody(&bodyDef); - body->CreateFixture(&fixtureDef); - - ColliderBody *colliderBody = new ColliderBody(body, contourData); - _colliderBodyList->addObject(colliderBody); + ColliderBody *colliderBody = new ColliderBody(contourData); + m_pColliderBodyList->addObject(colliderBody); colliderBody->release(); } -void ColliderDetector::addContourDataList(Array *contourDataList) +void CCColliderDetector::addContourDataList(Array *contourDataList) { Object *object = NULL; CCARRAY_FOREACH(contourDataList, object) { - addContourData(static_cast(object)); + addContourData((CCContourData *)object); } } -void ColliderDetector::removeContourData(ContourData *_contourData) +void CCColliderDetector::removeContourData(CCContourData *contourData) { - _colliderBodyList->removeObject(_contourData); + Object *object = NULL; + CCARRAY_FOREACH(m_pColliderBodyList, object) + { + ColliderBody *body = (ColliderBody*)object; + if (body && body->getContourData() == contourData) + { + m_pColliderBodyList->removeObject(body); + } + } } -void ColliderDetector::removeAll() +void CCColliderDetector::removeAll() { - _colliderBodyList->removeAllObjects(); + m_pColliderBodyList->removeAllObjects(); } -void ColliderDetector::setColliderFilter(b2Filter &filter) + +void CCColliderDetector::setActive(bool active) { - Object *object = NULL; - CCARRAY_FOREACH(_colliderBodyList, object) + if (m_bActive == active) { - ColliderBody *colliderBody = static_cast(object); - colliderBody->getB2Body()->GetFixtureList()->SetFilterData(filter); + return; } + + m_bActive = active; + +#if ENABLE_PHYSICS_BOX2D_DETECT + if (m_pBody) + { + if (active) + { + setBody(m_pBody); + } + else + { + Object *object = NULL; + CCARRAY_FOREACH(m_pColliderBodyList, object) + { + ColliderBody *colliderBody = (ColliderBody *)object; + b2Fixture *fixture = colliderBody->getB2Fixture(); + + b2Filter *filter = colliderBody->getB2Filter(); + *filter = fixture->GetFilterData(); + + m_pBody->DestroyFixture(fixture); + colliderBody->setB2Fixture(NULL); + } + } + } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + if (m_pBody) + { + Object *object = NULL; + if (m_bActive) + { + CCARRAY_FOREACH(m_pColliderBodyList, object) + { + ColliderBody *colliderBody = (ColliderBody *)object; + cpShape *shape = colliderBody->getShape(); + cpSpaceAddShape(m_pBody->space_private, shape); + } + } + else + { + CCARRAY_FOREACH(m_pColliderBodyList, object) + { + ColliderBody *colliderBody = (ColliderBody *)object; + cpShape *shape = colliderBody->getShape(); + cpSpaceRemoveShape(m_pBody->space_private, shape); + } + } + } +#endif } -void ColliderDetector::setActive(bool active) +bool CCColliderDetector::getActive() { - Object *object = NULL; - CCARRAY_FOREACH(_colliderBodyList, object) - { - ColliderBody *colliderBody = static_cast(object); - colliderBody->getB2Body()->SetActive(active); - } + return m_bActive; } +Array *CCColliderDetector::getColliderBodyList() +{ + return m_pColliderBodyList; +} + + Point helpPoint; -void ColliderDetector::updateTransform(AffineTransform &t) +void CCColliderDetector::updateTransform(AffineTransform &t) { - Object *object = NULL; - CCARRAY_FOREACH(_colliderBodyList, object) + if (!m_bActive) { - ColliderBody *colliderBody = static_cast(object); + return; + } - ContourData *contourData = colliderBody->getContourData(); - b2Body *body = colliderBody->getB2Body(); + Object *object = NULL; + CCARRAY_FOREACH(m_pColliderBodyList, object) + { + ColliderBody *colliderBody = (ColliderBody *)object; + CCContourData *contourData = colliderBody->getContourData(); - b2PolygonShape *shape = (b2PolygonShape *)body->GetFixtureList()->GetShape(); +#if ENABLE_PHYSICS_BOX2D_DETECT + b2PolygonShape *shape = NULL; + if (m_pBody != NULL) + { + shape = (b2PolygonShape *)colliderBody->getB2Fixture()->GetShape(); + } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + cpPolyShape *shape = NULL; + if (m_pBody != NULL) + { + shape = (cpPolyShape *)colliderBody->getShape(); + } +#endif - //! update every vertex - const Array *array = contourData->vertexList; + int num = contourData->vertexList.count(); + CCContourVertex2 **vs = (CCContourVertex2 **)contourData->vertexList.data->arr; + + for (int i = 0; i < num; i++) + { + helpPoint.setPoint( vs[i]->x, vs[i]->y); + helpPoint = PointApplyAffineTransform(helpPoint, t); + + +#if ENABLE_PHYSICS_BOX2D_DETECT + if (shape != NULL) + { + b2Vec2 &bv = shape->m_vertices[i]; + bv.Set(helpPoint.x / PT_RATIO, helpPoint.y / PT_RATIO); + } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + if (shape != NULL) + { + cpVect v ; + v.x = helpPoint.x; + v.y = helpPoint.y; + shape->verts[i] = v; + } +#endif + } + +#if ENABLE_PHYSICS_CHIPMUNK_DETECT + cpConvexHull(num, shape->verts, NULL, NULL, 0); + for (int i = 0; i < num; i++) + { + cpVect b = shape->verts[(i + 1) % shape->numVerts]; + cpVect n = cpvnormalize(cpvperp(cpvsub(b, shape->verts[i]))); + + shape->planes[i].n = n; + shape->planes[i].d = cpvdot(n, shape->verts[i]); + } +#endif + } +} + +#if ENABLE_PHYSICS_BOX2D_DETECT + +void CCColliderDetector::setBody(b2Body *pBody) +{ + m_pBody = pBody; + + Object *object = NULL; + CCARRAY_FOREACH(m_pColliderBodyList, object) + { + ColliderBody *colliderBody = (ColliderBody *)object; + + CCContourData *contourData = colliderBody->getContourData(); + const Array *array = &contourData->vertexList; Object *object = NULL; + + b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.count()]; + int i = 0; CCARRAY_FOREACH(array, object) { - ContourVertex2F *cv = static_cast(object); - b2Vec2 &bv = shape->m_vertices[i]; - - helpPoint.setPoint(cv->x, cv->y); - helpPoint = PointApplyAffineTransform(helpPoint, t); - - bv.Set(helpPoint.x / PT_RATIO, helpPoint.y / PT_RATIO); - + CCContourVertex2 *v = (CCContourVertex2 *)object; + b2bv[i].Set(v->x / PT_RATIO, v->y / PT_RATIO); i++; } + + b2PolygonShape polygon; + polygon.Set(b2bv, contourData->vertexList.count()); + + CC_SAFE_DELETE(b2bv); + + b2FixtureDef fixtureDef; + fixtureDef.shape = &polygon; + fixtureDef.isSensor = true; + + b2Fixture *fixture = m_pBody->CreateFixture(&fixtureDef); + fixture->SetUserData(m_pBone); + + if (colliderBody->getB2Fixture() != NULL) + { + m_pBody->DestroyFixture(colliderBody->getB2Fixture()); + } + colliderBody->setB2Fixture(fixture); + + if (colliderBody->getB2Filter() == NULL) + { + b2Filter *filter = new b2Filter; + colliderBody->setB2Filter(filter); + } + else + { + fixture->SetFilterData(*colliderBody->getB2Filter()); + } } } +b2Body *CCColliderDetector::getBody() +{ + return m_pBody; +} + +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +void CCColliderDetector::setBody(cpBody *pBody) +{ + m_pBody = pBody; + + Object *object = NULL; + CCARRAY_FOREACH(m_pColliderBodyList, object) + { + ColliderBody *colliderBody = (ColliderBody *)object; + + CCContourData *contourData = colliderBody->getContourData(); + + int num = contourData->vertexList.count(); + CCContourVertex2 **vs = (CCContourVertex2 **)contourData->vertexList.data->arr; + cpVect *verts = new cpVect[num]; + for (int i = 0; i < num; i++) + { + verts[num - 1 - i].x = vs[i]->x; + verts[num - 1 - i].y = vs[i]->y; + } + + cpShape *shape = cpPolyShapeNew(m_pBody, num, verts, cpvzero); + + shape->sensor = true; + shape->data = m_pBone; + cpSpaceAddShape(m_pBody->space_private, shape); + + colliderBody->setShape(shape); + + delete []verts; + } +} + +cpBody *CCColliderDetector::getBody() +{ + return m_pBody; +} + +#endif -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.h b/extensions/CocoStudio/Armature/physics/CCColliderDetector.h index 1aaaffea07..f97582069a 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.h +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.h @@ -28,78 +28,87 @@ THE SOFTWARE. #include "../utils/CCArmatureDefine.h" #include "../datas/CCDatas.h" +#ifndef PT_RATIO +#define PT_RATIO 32 +#endif + + class b2Body; +class b2Fixture; struct b2Filter; -namespace cocos2d { namespace extension { namespace armature { +struct cpBody; +struct cpShape; -class Bone; +NS_CC_EXT_ARMATURE_BEGIN + +class CCBone; class ColliderBody : public Object { public: - ColliderBody(b2Body *b2b, ContourData *contourData) - :_pB2b(NULL) - ,_contourData(NULL) - { - this->_pB2b = b2b; - this->_contourData = contourData; - CC_SAFE_RETAIN(_contourData); - } +#if ENABLE_PHYSICS_BOX2D_DETECT + CC_SYNTHESIZE(b2Fixture *, m_pFixture, B2Fixture) + CC_SYNTHESIZE(b2Filter *, m_pFilter, B2Filter) - ~ColliderBody() - { - CC_SAFE_RELEASE(_contourData); - } +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + CC_SYNTHESIZE(cpShape *, m_pShape, Shape) +#endif - inline b2Body *getB2Body() - { - return _pB2b; - } - - inline ContourData *getContourData() - { - return _contourData; - } +public: + ColliderBody(CCContourData *contourData); + ~ColliderBody(); + inline CCContourData *getContourData() + { + return m_pContourData; + } private: - b2Body *_pB2b; - ContourData *_contourData; + CCContourData *m_pContourData; }; /* * @brief ContourSprite used to draw the contour of the display */ -class ColliderDetector : public Object +class CCColliderDetector : public Object { public: - static ColliderDetector *create(); - static ColliderDetector *create(Bone *bone); + static CCColliderDetector *create(); + static CCColliderDetector *create(CCBone *bone); public: - ColliderDetector(); - ~ColliderDetector(void); - + CCColliderDetector(); + ~CCColliderDetector(void); + virtual bool init(); - virtual bool init(Bone *bone); - - void addContourData(ContourData *contourData); + virtual bool init(CCBone *bone); + + void addContourData(CCContourData *contourData); void addContourDataList(Array *contourDataList); - - void removeContourData(ContourData *contourData); - void removeAll(); - + + void removeContourData(CCContourData *contourData); + void removeAll(); + void updateTransform(AffineTransform &t); - void setColliderFilter(b2Filter &filter); - void setActive(bool active); -private: - Array *_colliderBodyList; - - CC_SYNTHESIZE(Bone*, _bone, Bone); + bool getActive(); + Array *getColliderBodyList(); + +protected: + Array *m_pColliderBodyList; + CC_SYNTHESIZE(CCBone *, m_pBone, Bone); + +#if ENABLE_PHYSICS_BOX2D_DETECT + CC_PROPERTY(b2Body *, m_pBody, Body); +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + CC_PROPERTY(cpBody *, m_pBody, Body); +#endif + +protected: + bool m_bActive; }; - -}}} // namespace cocos2d { namespace extension { namespace armature { + +NS_CC_EXT_ARMATURE_END #endif /*__CCCOLLIDERDETECTOR_H__*/ diff --git a/extensions/CocoStudio/Armature/physics/CCPhysicsWorld.cpp b/extensions/CocoStudio/Armature/physics/CCPhysicsWorld.cpp deleted file mode 100644 index 0ccf8eb617..0000000000 --- a/extensions/CocoStudio/Armature/physics/CCPhysicsWorld.cpp +++ /dev/null @@ -1,165 +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 "CCPhysicsWorld.h" -#include "../utils/CCArmatureDefine.h" -#include "Box2D/Box2D.h" -#include "../external_tool/GLES-Render.h" - -namespace cocos2d { namespace extension { namespace armature { - - -class Contact -{ -public: - b2Fixture *fixtureA; - b2Fixture *fixtureB; -}; - -class ContactListener : public b2ContactListener -{ - //! Callbacks for derived classes. - virtual void BeginContact(b2Contact *contact) override - { - if (contact) - { - Contact c; - c.fixtureA = contact->GetFixtureA(); - c.fixtureB = contact->GetFixtureB(); - - contact_list.push_back(c); - } - B2_NOT_USED(contact); - } - virtual void EndContact(b2Contact *contact) override - { - contact_list.clear(); - B2_NOT_USED(contact); - } - virtual void PreSolve(b2Contact *contact, const b2Manifold *oldManifold) override - { - B2_NOT_USED(contact); - B2_NOT_USED(oldManifold); - } - virtual void PostSolve(b2Contact *contact, const b2ContactImpulse *impulse) override - { - B2_NOT_USED(contact); - B2_NOT_USED(impulse); - } - -public: - std::list contact_list; -}; - - - -PhysicsWorld *PhysicsWorld::s_PhysicsWorld = NULL; - - -PhysicsWorld *PhysicsWorld::sharedPhysicsWorld() -{ - if (s_PhysicsWorld == NULL) - { - s_PhysicsWorld = new PhysicsWorld(); - s_PhysicsWorld->initNoGravityWorld(); - } - - return s_PhysicsWorld; -} - -void PhysicsWorld::purgePhysicsWorld() -{ - delete s_PhysicsWorld; - s_PhysicsWorld = NULL; -} - -PhysicsWorld::PhysicsWorld() - : _noGravityWorld(NULL) - , _debugDraw(NULL) -{ -} - -PhysicsWorld::~PhysicsWorld() -{ - CC_SAFE_DELETE(_debugDraw); - CC_SAFE_DELETE(_noGravityWorld); - CC_SAFE_DELETE(_contactListener); -} - -void PhysicsWorld::initNoGravityWorld() -{ - b2Vec2 noGravity(0, 0); - - _noGravityWorld = new b2World(noGravity); - _noGravityWorld->SetAllowSleeping(true); - - _contactListener = new ContactListener(); - _noGravityWorld->SetContactListener(_contactListener); - - -#if ENABLE_PHYSICS_DEBUG - _debugDraw = new GLESDebugDraw( PT_RATIO ); - _noGravityWorld->SetDebugDraw(_debugDraw); - - uint32 flags = 0; - flags += b2Draw::e_shapeBit; - // flags += b2Draw::e_jointBit; - // flags += b2Draw::e_aabbBit; - // flags += b2Draw::e_pairBit; - // flags += b2Draw::e_centerOfMassBit; - _debugDraw->SetFlags(flags); -#endif -} - -b2World *PhysicsWorld::getNoGravityWorld() -{ - return _noGravityWorld; -} - -void PhysicsWorld::update(float dt) -{ - _noGravityWorld->Step(dt, 0, 0); - - for (std::list::iterator it = _contactListener->contact_list.begin(); it != _contactListener->contact_list.end(); ++it) - { - Contact &contact = *it; - - b2Body *b2a = contact.fixtureA->GetBody(); - b2Body *b2b = contact.fixtureB->GetBody(); - - Bone *ba = (Bone *)b2a->GetUserData(); - Bone *bb = (Bone *)b2b->GetUserData(); - - BoneColliderSignal.emit(ba, bb); - } - -} - -void PhysicsWorld::drawDebug() -{ - _noGravityWorld->DrawDebugData(); -} - -}}} // namespace cocos2d { namespace extension { namespace armature { diff --git a/extensions/CocoStudio/Armature/physics/CCPhysicsWorld.h b/extensions/CocoStudio/Armature/physics/CCPhysicsWorld.h deleted file mode 100644 index ac60e609d0..0000000000 --- a/extensions/CocoStudio/Armature/physics/CCPhysicsWorld.h +++ /dev/null @@ -1,80 +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 __CCPHYSICSWORLD_H__ -#define __CCPHYSICSWORLD_H__ - -#include "../utils/CCArmatureDefine.h" -#include "../CCBone.h" -#include "../external_tool/sigslot.h" - -#include -using std::list; - -#ifndef PT_RATIO -#define PT_RATIO 32 -#endif - -struct b2Manifold; -struct b2ContactImpulse; -class b2Fixture; -class b2Contact; -class b2World; - -namespace cocos2d { namespace extension { namespace armature { - -class ContactListener; -class GLESDebugDraw; - -class PhysicsWorld -{ -public: - static PhysicsWorld *sharedPhysicsWorld(); - static void purgePhysicsWorld(); - - void initNoGravityWorld(); -private: - PhysicsWorld(); - ~PhysicsWorld(); - -private: - static PhysicsWorld *s_PhysicsWorld; - - b2World *_noGravityWorld; - - ContactListener *_contactListener; - - GLESDebugDraw *_debugDraw; -public: - void update(float dt); - void drawDebug(); - - b2World *getNoGravityWorld(); - - sigslot::signal2 BoneColliderSignal; -}; - -}}} // namespace cocos2d { namespace extension { namespace armature { - -#endif/*__CCPHYSICSWORLD_H__*/ diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp index 3153fe05f8..cda72df978 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp @@ -27,18 +27,17 @@ THE SOFTWARE. #include "CCTransformHelp.h" #include "CCDataReaderHelper.h" #include "CCSpriteFrameCacheHelper.h" -#include "../physics/CCPhysicsWorld.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -static ArmatureDataManager *s_sharedArmatureDataManager = NULL; +static CCArmatureDataManager *s_sharedArmatureDataManager = NULL; -ArmatureDataManager *ArmatureDataManager::sharedArmatureDataManager() +CCArmatureDataManager *CCArmatureDataManager::sharedArmatureDataManager() { if (s_sharedArmatureDataManager == NULL) { - s_sharedArmatureDataManager = new ArmatureDataManager(); + s_sharedArmatureDataManager = new CCArmatureDataManager(); if (!s_sharedArmatureDataManager || !s_sharedArmatureDataManager->init()) { CC_SAFE_DELETE(s_sharedArmatureDataManager); @@ -47,49 +46,48 @@ ArmatureDataManager *ArmatureDataManager::sharedArmatureDataManager() return s_sharedArmatureDataManager; } -ArmatureDataManager::ArmatureDataManager(void) +void CCArmatureDataManager::purge() { - _armarureDatas = NULL; - _animationDatas = NULL; - _textureDatas = NULL; -} - - -ArmatureDataManager::~ArmatureDataManager(void) -{ - CCLOGINFO("deallocing ArmatureDataManager: %p", this); - - removeAll(); - - CC_SAFE_RELEASE(_animationDatas); - CC_SAFE_RELEASE(_armarureDatas); - CC_SAFE_RELEASE(_textureDatas); -} - -void ArmatureDataManager::purgeArmatureSystem() -{ - SpriteFrameCacheHelper::purgeSpriteFrameCacheHelper(); - PhysicsWorld::purgePhysicsWorld(); - + CCSpriteFrameCacheHelper::purge(); + CCDataReaderHelper::purge(); CC_SAFE_RELEASE_NULL(s_sharedArmatureDataManager); } -bool ArmatureDataManager::init() +CCArmatureDataManager::CCArmatureDataManager(void) +{ + m_pArmarureDatas = NULL; + m_pAnimationDatas = NULL; + m_pTextureDatas = NULL; + m_bAutoLoadSpriteFile = false; +} + + +CCArmatureDataManager::~CCArmatureDataManager(void) +{ + removeAll(); + + CC_SAFE_DELETE(m_pAnimationDatas); + CC_SAFE_DELETE(m_pArmarureDatas); + CC_SAFE_DELETE(m_pTextureDatas); +} + + +bool CCArmatureDataManager::init() { bool bRet = false; do { - _armarureDatas = new Dictionary; - CCASSERT(_armarureDatas, "create ArmatureDataManager::_armarureDatas fail!"); - _armarureDatas->init(); + m_pArmarureDatas = Dictionary::create(); + CCAssert(m_pArmarureDatas, "create CCArmatureDataManager::m_pArmarureDatas fail!"); + m_pArmarureDatas->retain(); - _animationDatas = new Dictionary; - CCASSERT(_animationDatas, "create ArmatureDataManager::_animationDatas fail!"); - _animationDatas->init(); + m_pAnimationDatas = Dictionary::create(); + CCAssert(m_pAnimationDatas, "create CCArmatureDataManager::m_pAnimationDatas fail!"); + m_pAnimationDatas->retain(); - _textureDatas = new Dictionary; - CCASSERT(_textureDatas, "create ArmatureDataManager::_textureDatas fail!"); - _textureDatas->init(); + m_pTextureDatas = Dictionary::create(); + CCAssert(m_pTextureDatas, "create CCArmatureDataManager::m_pTextureDatas fail!"); + m_pTextureDatas->retain(); bRet = true; } @@ -98,105 +96,153 @@ bool ArmatureDataManager::init() return bRet; } -void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData) +void CCArmatureDataManager::addArmatureData(const char *id, CCArmatureData *armatureData) { - if(_armarureDatas) + if(m_pArmarureDatas) { - _armarureDatas->setObject(armatureData, id); + m_pArmarureDatas->setObject(armatureData, id); } } -ArmatureData *ArmatureDataManager::getArmatureData(const char *id) +CCArmatureData *CCArmatureDataManager::getArmatureData(const char *id) { - ArmatureData *armatureData = NULL; - if (_armarureDatas) + CCArmatureData *armatureData = NULL; + if (m_pArmarureDatas) { - armatureData = (ArmatureData *)_armarureDatas->objectForKey(id); + armatureData = (CCArmatureData *)m_pArmarureDatas->objectForKey(id); } return armatureData; } -void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData) +void CCArmatureDataManager::removeArmatureData(const char *id) { - if(_animationDatas) + if (m_pArmarureDatas) { - _animationDatas->setObject(animationData, id); + m_pArmarureDatas->removeObjectForKey(id); } } -void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData) +void CCArmatureDataManager::addAnimationData(const char *id, CCAnimationData *animationData) { - if(_textureDatas) + if(m_pAnimationDatas) { - _textureDatas->setObject(textureData, id); + m_pAnimationDatas->setObject(animationData, id); } } -AnimationData *ArmatureDataManager::getAnimationData(const char *id) +CCAnimationData *CCArmatureDataManager::getAnimationData(const char *id) { - AnimationData *animationData = NULL; - if (_animationDatas) + CCAnimationData *animationData = NULL; + if (m_pAnimationDatas) { - animationData = (AnimationData *)_animationDatas->objectForKey(id); + animationData = (CCAnimationData *)m_pAnimationDatas->objectForKey(id); } return animationData; } -TextureData *ArmatureDataManager::getTextureData(const char *id) +void CCArmatureDataManager::removeAnimationData(const char *id) { - TextureData *textureData = NULL; - if (_textureDatas) + if (m_pAnimationDatas) { - textureData = (TextureData *)_textureDatas->objectForKey(id); + m_pAnimationDatas->removeObjectForKey(id); + } +} + +void CCArmatureDataManager::addTextureData(const char *id, CCTextureData *textureData) +{ + if(m_pTextureDatas) + { + m_pTextureDatas->setObject(textureData, id); + } +} + + +CCTextureData *CCArmatureDataManager::getTextureData(const char *id) +{ + CCTextureData *textureData = NULL; + if (m_pTextureDatas) + { + textureData = (CCTextureData *)m_pTextureDatas->objectForKey(id); } return textureData; } - -void ArmatureDataManager::addArmatureFileInfo(const char *armatureName, const char *useExistFileInfo, const char *imagePath, const char *plistPath, const char *configFilePath) +void CCArmatureDataManager::removeTextureData(const char *id) { - addArmatureFileInfo(imagePath, plistPath, configFilePath); + if(m_pTextureDatas) + { + m_pTextureDatas->removeObjectForKey(id); + } } -void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) +void CCArmatureDataManager::addArmatureFileInfo(const char *configFilePath) { + m_bAutoLoadSpriteFile = true; + CCDataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); +} - DataReaderHelper::addDataFromFile(configFilePath); +void CCArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector) +{ + m_bAutoLoadSpriteFile = true; + CCDataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); +} + +void CCArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) +{ + m_bAutoLoadSpriteFile = false; + CCDataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); addSpriteFrameFromFile(plistPath, imagePath); } -void ArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) +void CCArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector) { - // if(Game::sharedGame()->isUsePackage()) - // { - // SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromPak(plistPath, imagePath); - // } - // else - // { - // SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath); - // } - SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath); + m_bAutoLoadSpriteFile = false; + CCDataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); + addSpriteFrameFromFile(plistPath, imagePath); +} + +void CCArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) +{ + CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath); } -void ArmatureDataManager::removeAll() +void CCArmatureDataManager::removeAll() { - if( _animationDatas ) + if( m_pAnimationDatas ) { - _animationDatas->removeAllObjects(); + m_pAnimationDatas->removeAllObjects(); } - if( _armarureDatas ) + if( m_pArmarureDatas ) { - _armarureDatas->removeAllObjects(); + m_pArmarureDatas->removeAllObjects(); } - if( _textureDatas ) + if( m_pTextureDatas ) { - _textureDatas->removeAllObjects(); + m_pTextureDatas->removeAllObjects(); } - DataReaderHelper::clear(); + CCDataReaderHelper::clear(); } -}}} // namespace cocos2d { namespace extension { namespace armature { +bool CCArmatureDataManager::isAutoLoadSpriteFile() +{ + return m_bAutoLoadSpriteFile; +} + +Dictionary *CCArmatureDataManager::getArmatureDatas() const +{ + return m_pArmarureDatas; +} +Dictionary *CCArmatureDataManager::getAnimationDatas() const +{ + return m_pAnimationDatas; +} +Dictionary *CCArmatureDataManager::getTextureDatas() const +{ + return m_pTextureDatas; +} + +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h index 58f089fc0d..62f9a558ae 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h @@ -26,124 +26,159 @@ THE SOFTWARE. #define __CCARMATUREDATAMANAGER_H__ #include "CCArmatureDefine.h" -#include "CCConstValue.h" #include "../datas/CCDatas.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN /** - * @brief format and manage armature configuration and armature animation + * @brief format and manage armature configuration and armature animation */ -class ArmatureDataManager : public Object +class CCArmatureDataManager : public Object { public: - static ArmatureDataManager *sharedArmatureDataManager(); - static void purgeArmatureSystem(); + static CCArmatureDataManager *sharedArmatureDataManager(); + + static void purge(); private: - ArmatureDataManager(void); - ~ArmatureDataManager(void); + CCArmatureDataManager(void); + ~CCArmatureDataManager(void); public: + /** - * Init ArmatureDataManager + * Init CCArmatureDataManager */ virtual bool init(); - - /** - * @brief Add armature data. - * - * @param id The id of the armature data. - * @param armatureData The armature data to be added. - */ - void addArmatureData(const char *id, ArmatureData *armatureData); - - /** - * @brief Get armature data. - * - * @param id The id of the armature data you want to get. - * - * @return The ArmatureData whose id is @p id. - */ - ArmatureData *getArmatureData(const char *id); /** - * @brief Add animation data. - * - * @param id The id of the animation data. - * @param animationData The animation data to be added. + * Add armature data + * @param id The id of the armature data + * @param armatureData CCArmatureData * */ - void addAnimationData(const char *id, AnimationData *animationData); - - /** - * @brief Get animation data. - * - * @param id The id of the animation data you want to get. - * - * @return The AnimationData whose id is @p id. - */ - AnimationData *getAnimationData(const char *id); + void addArmatureData(const char *id, CCArmatureData *armatureData); /** - * @brief Add texture data. - * - * @param id The id of the texture data. - * @param textureData The texture data to be added. + * @brief get armature data + * @param id the id of the armature data you want to get + * @return CCArmatureData * */ - void addTextureData(const char *id, TextureData *textureData); - - /** - * @brief Get texture data. - * - * @param id The id of the texture data you want to get. - * - * @return The TextureData whose id is @p id. - */ - TextureData *getTextureData(const char *id); - - /** - * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. - */ - void addArmatureFileInfo(const char *armatureName, const char *useExistFileInfo, const char *imagePath, const char *plistPath, const char *configFilePath); + CCArmatureData *getArmatureData(const char *id); /** - * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. + * @brief remove armature data + * @param id the id of the armature data you want to get + */ + void removeArmatureData(const char *id); + + /** + * @brief add animation data + * @param id the id of the animation data + * @return CCAnimationData * + */ + void addAnimationData(const char *id, CCAnimationData *animationData); + + /** + * @brief get animation data from m_pAnimationDatas(Dictionary) + * @param id the id of the animation data you want to get + * @return CCAnimationData * + */ + CCAnimationData *getAnimationData(const char *id); + + /** + * @brief remove animation data + * @param id the id of the animation data + */ + void removeAnimationData(const char *id); + + /** + * @brief add texture data + * @param id the id of the texture data + * @return CCTextureData * + */ + void addTextureData(const char *id, CCTextureData *textureData); + + /** + * @brief get texture data + * @param id the id of the texture data you want to get + * @return CCTextureData * + */ + CCTextureData *getTextureData(const char *id); + + /** + * @brief remove texture data + * @param id the id of the texture data you want to get + */ + void removeTextureData(const char *id); + + /** + * @brief Add ArmatureFileInfo, it is managed by CCArmatureDataManager. + */ + void addArmatureFileInfo(const char *configFilePath); + + /** + * @brief Add ArmatureFileInfo, it is managed by CCArmatureDataManager. + * It will load data in a new thread + */ + void addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector); + + /** + * @brief Add ArmatureFileInfo, it is managed by CCArmatureDataManager. */ void addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath); /** - * @brief Add sprite frame to SpriteFrameCache, it will save display name and it's relative image name + * @brief Add ArmatureFileInfo, it is managed by CCArmatureDataManager. + * It will load data in a new thread + */ + void addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector); + + /** + * @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); + /** - * @brief Clear the data in the _armarureDatas and _animationDatas, and set _armarureDatas and _animationDatas to NULL + * @brief Clear the data in the m_pArmarureDatas and m_pAnimationDatas, and set m_pArmarureDatas and m_pAnimationDatas to NULL */ void removeAll(); - + /** + * @brief Juge whether or not need auto load sprite file + */ + bool isAutoLoadSpriteFile(); + + + Dictionary *getArmatureDatas() const; + Dictionary *getAnimationDatas() const; + Dictionary *getTextureDatas() const; private: /** - * Dictionary to save amature data. - * Key type is std::string, value type is ArmatureData *. + * @brief save amature datas + * @key std::string + * @value CCArmatureData * */ - CC_SYNTHESIZE_READONLY(Dictionary *, _armarureDatas, ArmarureDatas); + Dictionary *m_pArmarureDatas; /** - * Dictionary to save animation data. - * Key type is std::string, value type is AnimationData *. + * @brief save animation datas + * @key std::string + * @value CCAnimationData * */ - CC_SYNTHESIZE_READONLY(Dictionary *, _animationDatas, AnimationDatas); + Dictionary *m_pAnimationDatas; /** - * Dictionary to save texture data. - * Key type is std::string, value type is TextureData *. + * @brief save texture datas + * @key std::string + * @value CCTextureData * */ - CC_SYNTHESIZE_READONLY(Dictionary *, _textureDatas, TextureDatas); + Dictionary *m_pTextureDatas; + bool m_bAutoLoadSpriteFile; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif/*__CCARMATUREDATAMANAGER_H__*/ diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDefine.h b/extensions/CocoStudio/Armature/utils/CCArmatureDefine.h index 1e1eac7aff..488bb0a1cc 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDefine.h +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDefine.h @@ -25,27 +25,37 @@ THE SOFTWARE. #ifndef __CCARMATUREDEFINE_H__ #define __CCARMATUREDEFINE_H__ -//#define _USRDLL 1 #include "cocos2d.h" #include "ExtensionMacros.h" +#define VERSION_COMBINED 0.30f -#ifndef ENABLE_PHYSICS_DEBUG -#define ENABLE_PHYSICS_DEBUG 1 + +#ifndef AUTO_ADD_SPRITE_FRAME_NAME_PREFIX +#define AUTO_ADD_SPRITE_FRAME_NAME_PREFIX 0 +#endif // !AUTO_ADD_SPRITE_FRAME_NAME_PREFIX + + +#ifndef ENABLE_PHYSICS_BOX2D_DETECT +#define ENABLE_PHYSICS_BOX2D_DETECT 0 #endif -#ifndef ENABLE_PHYSICS_DETECT -#define ENABLE_PHYSICS_DETECT 1 +#ifndef ENABLE_PHYSICS_CHIPMUNK_DETECT +#define ENABLE_PHYSICS_CHIPMUNK_DETECT 1 #endif - -#define MAX_VERTEXZ_VALUE 5000000.0f -#define ARMATURE_MAX_CHILD 50.0f -#define ARMATURE_MAX_ZORDER 100 -#define ARMATURE_MAX_COUNT ((MAX_VERTEXZ_VALUE) / (ARMATURE_MAX_CHILD) / ARMATURE_MAX_ZORDER) - #define CS_RETURN_IF(cond) if (cond) return #define CS_RETURN_NULL_IF(cond) if (cond) return NULL; +#define NS_CC_EXT_ARMATURE_BEGIN namespace cocos2d { namespace extension { namespace armature { +#define NS_CC_EXT_ARMATURE_END }}} +#define USING_NS_CC_EXT_ARMATURE using namespace cocos2d::extension::armature + +NS_CC_EXT_ARMATURE_BEGIN + +const char *armatureVersion(); + +NS_CC_EXT_ARMATURE_END + #endif /*__CCARMATUREDEFINE_H__*/ diff --git a/extensions/CocoStudio/Armature/utils/CCConstValue.h b/extensions/CocoStudio/Armature/utils/CCConstValue.h deleted file mode 100644 index 7aa611f716..0000000000 --- a/extensions/CocoStudio/Armature/utils/CCConstValue.h +++ /dev/null @@ -1,29 +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 __CCCONSTVALUE_H__ -#define __CCCONSTVALUE_H__ - - -#endif /*__CCCONSTVALUE_H__*/ diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp index 99442e5bb7..ef6941086a 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp +++ b/extensions/CocoStudio/Armature/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"; @@ -56,8 +57,8 @@ 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_VERT = "vert"; +// static const char *A_FRAG = "frag"; static const char *A_PLIST = "plist"; static const char *A_PARENT = "parent"; @@ -89,6 +90,8 @@ 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"; @@ -118,6 +121,7 @@ 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"; @@ -125,32 +129,144 @@ 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"; -namespace cocos2d { namespace extension { namespace armature { -std::vector s_arrConfigFileList; +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; -void DataReaderHelper::setPositionReadScale(float scale) +static std::string s_BasefilePath = ""; + +CCDataReaderHelper *CCDataReaderHelper::s_DataReaderHelper = NULL; + + + +//! Async load +void CCDataReaderHelper::loadData() +{ + AsyncStruct *pAsyncStruct = NULL; + + while (true) + { + // create autorelease pool for iOS + Thread thread; + thread.createAutoreleasePool(); + + std::queue *pQueue = s_pAsyncStructQueue; + s_AsyncStructQueueMutex.lock(); // get async struct from queue + if (pQueue->empty()) + { + s_AsyncStructQueueMutex.unlock(); + if (need_quit) + { + break; + } + else + { + std::unique_lock lk(s_SleepMutex); + s_SleepCondition.wait(lk); + continue; + } + } + else + { + pAsyncStruct = pQueue->front(); + pQueue->pop(); + s_AsyncStructQueueMutex.unlock(); + } + + // generate image info + DataInfo *pDataInfo = new DataInfo(); + pDataInfo->asyncStruct = pAsyncStruct; + + if (pAsyncStruct->configType == DragonBone_XML) + { + CCDataReaderHelper::addDataFromCache(pAsyncStruct->fileContent.c_str(), pDataInfo); + } + else if(pAsyncStruct->configType == CocoStudio_JSON) + { + CCDataReaderHelper::addDataFromJsonCache(pAsyncStruct->fileContent.c_str(), pDataInfo); + } + + // put the image info into the queue + s_DataInfoMutex.lock(); + s_pDataQueue->push(pDataInfo); + s_DataInfoMutex.unlock(); + } + + if( s_pAsyncStructQueue != NULL ) + { + delete s_pAsyncStructQueue; + s_pAsyncStructQueue = NULL; + delete s_pDataQueue; + s_pDataQueue = NULL; + } +} + + +CCDataReaderHelper *CCDataReaderHelper::sharedDataReaderHelper() +{ + if(!s_DataReaderHelper) + { + s_DataReaderHelper = new CCDataReaderHelper(); + } + + return s_DataReaderHelper; +} + +void CCDataReaderHelper::setPositionReadScale(float scale) { s_PositionReadScale = scale; } -float DataReaderHelper::getPositionReadScale() +float CCDataReaderHelper::getPositionReadScale() { return s_PositionReadScale; } -void DataReaderHelper::clear() + +void CCDataReaderHelper::purge() +{ + CCDataReaderHelper::clear(); + CC_SAFE_RELEASE_NULL(s_DataReaderHelper); +} + +void CCDataReaderHelper::clear() { s_arrConfigFileList.clear(); } -void DataReaderHelper::addDataFromFile(const char *filePath) +CCDataReaderHelper::CCDataReaderHelper() + : s_LoadingThread(nullptr) + , s_pAsyncStructQueue(nullptr) + , s_pDataQueue(nullptr) + , need_quit(false) + , s_nAsyncRefCount(0) + , s_nAsyncRefTotalCount(0) +{ + +} + +CCDataReaderHelper::~CCDataReaderHelper() +{ + need_quit = true; + + if (s_LoadingThread) s_LoadingThread->join(); + CC_SAFE_DELETE(s_LoadingThread); + + s_SleepCondition.notify_one(); + s_DataReaderHelper = NULL; +} + +void CCDataReaderHelper::addDataFromFile(const char *filePath) { /* - * Check if file is already added to ArmatureDataManager, if then return. + * Check if file is already added to CCArmatureDataManager, if then return. */ for(unsigned int i = 0; i < s_arrConfigFileList.size(); i++) { @@ -162,65 +278,200 @@ void DataReaderHelper::addDataFromFile(const char *filePath) s_arrConfigFileList.push_back(filePath); - std::string filePathStr = 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::addDataFromXML(filePathStr.c_str()); + CCDataReaderHelper::addDataFromCache(pFileContent); } else if(str.compare(".json") == 0 || str.compare(".ExportJson") == 0) { - DataReaderHelper::addDataFromJson(filePathStr.c_str()); + CCDataReaderHelper::addDataFromJsonCache(pFileContent); } } - - -void DataReaderHelper::addDataFromXML(const char *xmlPath) +void CCDataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target, SEL_SCHEDULE selector) { /* - * Need to get the full path of the xml file, or the Tiny XML can't find the xml at IOS + * Check if file is already added to CCArmatureDataManager, if then return. */ - std::string fullPath = FileUtils::getInstance()->fullPathForFilename(xmlPath); - - /* - * Need to read the tiny xml into memory first, or the Tiny XML can't find the xml at IOS - */ - unsigned long size; - const char *pFileContent = (char *)FileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); - - if (pFileContent) + for(unsigned int i = 0; i < s_arrConfigFileList.size(); i++) { - addDataFromCache(pFileContent); + if (s_arrConfigFileList[i].compare(filePath) == 0) + { + if (target && selector) + { + if (s_nAsyncRefTotalCount == 0 && s_nAsyncRefCount == 0) + { + (target->*selector)(1); + } + else + { + (target->*selector)((s_nAsyncRefTotalCount - s_nAsyncRefCount) / (float)s_nAsyncRefTotalCount); + } + } + 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 (s_pAsyncStructQueue == NULL) + { + s_pAsyncStructQueue = new std::queue(); + s_pDataQueue = new std::queue(); + + // create a new thread to load images + s_LoadingThread = new std::thread(&CCDataReaderHelper::loadData, this); + + need_quit = false; + } + + if (0 == s_nAsyncRefCount) + { + Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(CCDataReaderHelper::addDataAsyncCallBack), this, 0, false); + } + + ++s_nAsyncRefCount; + ++s_nAsyncRefTotalCount; + + 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 = CCArmatureDataManager::sharedArmatureDataManager()->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 + s_AsyncStructQueueMutex.lock(); + s_pAsyncStructQueue->push(data); + s_AsyncStructQueueMutex.unlock(); + + s_SleepCondition.notify_one(); +} + +void CCDataReaderHelper::addDataAsyncCallBack(float dt) +{ + // the data is generated in loading thread + std::queue *dataQueue = s_pDataQueue; + + s_DataInfoMutex.lock(); + if (dataQueue->empty()) + { + s_DataInfoMutex.unlock(); + } + else + { + DataInfo *pDataInfo = dataQueue->front(); + dataQueue->pop(); + s_DataInfoMutex.unlock(); + + AsyncStruct *pAsyncStruct = pDataInfo->asyncStruct; + + while (!pDataInfo->configFileQueue.empty()) + { + std::string configPath = pDataInfo->configFileQueue.front(); + CCArmatureDataManager::sharedArmatureDataManager()->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; + + --s_nAsyncRefCount; + + if (target && selector) + { + (target->*selector)((s_nAsyncRefTotalCount - s_nAsyncRefCount) / (float)s_nAsyncRefTotalCount); + target->release(); + } + + + delete pAsyncStruct; + delete pDataInfo; + + if (0 == s_nAsyncRefCount) + { + s_nAsyncRefTotalCount = 0; + CCDirector::getInstance()->getScheduler()->unscheduleSelector(schedule_selector(CCDataReaderHelper::addDataAsyncCallBack), this); + } } } -void DataReaderHelper::addDataFromXMLPak(const char *xmlPakPath) -{ - // #if CS_TOOL_PLATFORM - // - // char *_pFileContent = NULL; - // JsonReader::getFileBuffer(xmlPakPath, &_pFileContent); - // - // if (_pFileContent) - // { - // addDataFromCache(_pFileContent); - // } - // #endif -} -void DataReaderHelper::addDataFromCache(const char *pFileContent) + + + + +void CCDataReaderHelper::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."); + CCAssert(root, "XML error or XML is empty."); root->QueryFloatAttribute(VERSION, &s_FlashToolVersion); + /* * Begin decode armature data from xml */ @@ -228,12 +479,23 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent) tinyxml2::XMLElement *armatureXML = armaturesXML->FirstChildElement(ARMATURE); while(armatureXML) { - ArmatureData *armatureData = DataReaderHelper::decodeArmature(armatureXML); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); + CCArmatureData *armatureData = CCDataReaderHelper::decodeArmature(armatureXML); + + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.lock(); + } + CCArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); + armatureData->release(); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.unlock(); + } armatureXML = armatureXML->NextSiblingElement(ARMATURE); } + /* * Begin decode animation data from xml */ @@ -241,12 +503,21 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent) tinyxml2::XMLElement *animationXML = animationsXML->FirstChildElement(ANIMATION); while(animationXML) { - AnimationData *animationData = DataReaderHelper::decodeAnimation(animationXML); - ArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); - + CCAnimationData *animationData = CCDataReaderHelper::decodeAnimation(animationXML); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.lock(); + } + CCArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); + animationData->release(); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.unlock(); + } animationXML = animationXML->NextSiblingElement(ANIMATION); } + /* * Begin decode texture data from xml */ @@ -254,20 +525,28 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent) tinyxml2::XMLElement *textureXML = texturesXML->FirstChildElement(SUB_TEXTURE); while(textureXML) { - TextureData *textureData = DataReaderHelper::decodeTexture(textureXML); - ArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); + CCTextureData *textureData = CCDataReaderHelper::decodeTexture(textureXML); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.lock(); + } + CCArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); + textureData->release(); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.unlock(); + } textureXML = textureXML->NextSiblingElement(SUB_TEXTURE); } - } -ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML) +CCArmatureData *CCDataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML) { + CCArmatureData *armatureData = new CCArmatureData(); + armatureData->init(); + const char *name = armatureXML->Attribute(A_NAME); - - - ArmatureData *armatureData = ArmatureData::create(); armatureData->name = name; @@ -294,8 +573,9 @@ ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML } } - BoneData *boneData = decodeBone(boneXML, parentXML); + CCBoneData *boneData = decodeBone(boneXML, parentXML); armatureData->addBoneData(boneData); + boneData->release(); boneXML = boneXML->NextSiblingElement(BONE); } @@ -303,15 +583,12 @@ ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML return armatureData; } -BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXml) +CCBoneData *CCDataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXml) { + CCBoneData *boneData = new CCBoneData(); + boneData->init(); std::string name = boneXML->Attribute(A_NAME); - - CCASSERT(name.length() != 0, ""); - - BoneData *boneData = BoneData::create(); - boneData->name = name; if( boneXML->Attribute(A_PARENT) != NULL ) @@ -319,11 +596,14 @@ BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2:: boneData->parentName = boneXML->Attribute(A_PARENT); } + boneXML->QueryIntAttribute(A_Z, &boneData->zOrder); + tinyxml2::XMLElement *displayXML = boneXML->FirstChildElement(DISPLAY); while(displayXML) { - DisplayData *displayData = decodeBoneDisplay(displayXML); + CCDisplayData *displayData = decodeBoneDisplay(displayXML); boneData->addDisplayData(displayData); + displayData->release(); displayXML = displayXML->NextSiblingElement(DISPLAY); } @@ -331,41 +611,42 @@ BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2:: return boneData; } -DisplayData *DataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXML) +CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXML) { int _isArmature = 0; - DisplayData *displayData; + CCDisplayData *displayData; if( displayXML->QueryIntAttribute(A_IS_ARMATURE, &(_isArmature)) == tinyxml2::XML_SUCCESS ) { if(!_isArmature) { - displayData = SpriteDisplayData::create(); + displayData = new CCSpriteDisplayData(); displayData->displayType = CS_DISPLAY_SPRITE; } else { - displayData = ArmatureDisplayData::create(); + displayData = new CCArmatureDisplayData(); displayData->displayType = CS_DISPLAY_ARMATURE; } } else { - displayData = SpriteDisplayData::create(); + displayData = new CCSpriteDisplayData(); displayData->displayType = CS_DISPLAY_SPRITE; } + if(displayXML->Attribute(A_NAME) != NULL ) { if(!_isArmature) { - ((SpriteDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); + ((CCSpriteDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); } else { - ((ArmatureDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); + ((CCArmatureDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); } } @@ -373,14 +654,13 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXM return displayData; } -AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animationXML) +CCAnimationData *CCDataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animationXML) { + CCAnimationData *aniData = new CCAnimationData(); + const char *name = animationXML->Attribute(A_NAME); - - AnimationData *aniData = AnimationData::create(); - - ArmatureData *armatureData = ArmatureDataManager::sharedArmatureDataManager()->getArmatureData(name); + CCArmatureData *armatureData = CCArmatureDataManager::sharedArmatureDataManager()->getArmatureData(name); aniData->name = name; @@ -388,8 +668,9 @@ AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animation while( movementXML ) { - MovementData *movementData = decodeMovement(movementXML, armatureData); + CCMovementData *movementData = decodeMovement(movementXML, armatureData); aniData->addMovement(movementData); + movementData->release(); movementXML = movementXML->NextSiblingElement(MOVEMENT); @@ -398,12 +679,11 @@ AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animation return aniData; } -MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, ArmatureData *armatureData) +CCMovementData *CCDataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, CCArmatureData *armatureData) { + CCMovementData *movementData = new CCMovementData(); + const char *movName = movementXML->Attribute(A_NAME); - - MovementData *movementData = MovementData::create(); - movementData->name = movName; @@ -423,7 +703,7 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML } if( movementXML->QueryIntAttribute(A_LOOP, &(loop)) == tinyxml2::XML_SUCCESS) { - movementData->loop = loop != 0; + movementData->loop = (bool)loop; } const char *_easing = movementXML->Attribute(A_TWEEN_EASING); @@ -434,7 +714,7 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML { if( movementXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS) { - movementData->tweenEasing = (TweenType)tweenEasing; + movementData->tweenEasing = (CCTweenType)tweenEasing; } } else @@ -455,7 +735,7 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML } - BoneData *boneData = (BoneData *)armatureData->getBoneData(boneName); + CCBoneData *boneData = (CCBoneData *)armatureData->getBoneData(boneName); std::string parentName = boneData->parentName; @@ -475,8 +755,9 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML } } - MovementBoneData *_moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData); - movementData->addMovementBoneData(_moveBoneData); + CCMovementBoneData *moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData); + movementData->addMovementBoneData(moveBoneData); + moveBoneData->release(); movBoneXml = movBoneXml->NextSiblingElement(BONE); } @@ -485,9 +766,11 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML } -MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, BoneData *boneData) +CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, CCBoneData *boneData) { - MovementBoneData *movBoneData = MovementBoneData::create(); + CCMovementBoneData *movBoneData = new CCMovementBoneData(); + movBoneData->init(); + float scale, delay; if( movBoneXml ) @@ -558,101 +841,113 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov } } - FrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData); + CCFrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData); movBoneData->addFrameData(frameData); + frameData->release(); + frameData->frameID = totalDuration; totalDuration += frameData->duration; + movBoneData->duration = totalDuration; frameXML = frameXML->NextSiblingElement(FRAME); } + // + CCFrameData *frameData = new CCFrameData(); + frameData->copy((CCFrameData *)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) +CCFrameData *CCDataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, CCBoneData *boneData) { - float _x, _y, _scale_x, _scale_y, _skew_x, _skew_y = 0; - int _duration, _displayIndex, _zOrder, _tweenEasing = 0; - - FrameData *frameData = FrameData::create(); + float x, y, scale_x, scale_y, skew_x, skew_y = 0; + int duration, displayIndex, zOrder, tweenEasing, blendType = 0; + CCFrameData *frameData = new CCFrameData(); if(frameXML->Attribute(A_MOVEMENT) != NULL) { - frameData->_movement = frameXML->Attribute(A_MOVEMENT); + frameData->strMovement = frameXML->Attribute(A_MOVEMENT); } if(frameXML->Attribute(A_EVENT) != NULL) { - frameData->_event = frameXML->Attribute(A_EVENT); + frameData->strEvent = frameXML->Attribute(A_EVENT); } if(frameXML->Attribute(A_SOUND) != NULL) { - frameData->_sound = frameXML->Attribute(A_SOUND); + frameData->strSound = frameXML->Attribute(A_SOUND); } if(frameXML->Attribute(A_SOUND_EFFECT) != NULL) { - frameData->_soundEffect = frameXML->Attribute(A_SOUND_EFFECT); + frameData->strSoundEffect = frameXML->Attribute(A_SOUND_EFFECT); } if (s_FlashToolVersion >= VERSION_2_0) { - if(frameXML->QueryFloatAttribute(A_COCOS2DX_X, &_x) == tinyxml2::XML_SUCCESS) + if(frameXML->QueryFloatAttribute(A_COCOS2DX_X, &x) == tinyxml2::XML_SUCCESS) { - frameData->x = _x; + frameData->x = x; frameData->x *= s_PositionReadScale; } - if(frameXML->QueryFloatAttribute(A_COCOS2DX_Y, &_y) == tinyxml2::XML_SUCCESS) + if(frameXML->QueryFloatAttribute(A_COCOS2DX_Y, &y) == tinyxml2::XML_SUCCESS) { - frameData->y = -_y; + frameData->y = -y; frameData->y *= s_PositionReadScale; } } else { - if(frameXML->QueryFloatAttribute(A_X, &_x) == tinyxml2::XML_SUCCESS) + if(frameXML->QueryFloatAttribute(A_X, &x) == tinyxml2::XML_SUCCESS) { - frameData->x = _x; + frameData->x = x; frameData->x *= s_PositionReadScale; } - if(frameXML->QueryFloatAttribute(A_Y, &_y) == tinyxml2::XML_SUCCESS) + if(frameXML->QueryFloatAttribute(A_Y, &y) == tinyxml2::XML_SUCCESS) { - frameData->y = -_y; + frameData->y = -y; frameData->y *= s_PositionReadScale; } } - if( frameXML->QueryFloatAttribute(A_SCALE_X, &_scale_x) == tinyxml2::XML_SUCCESS ) + if( frameXML->QueryFloatAttribute(A_SCALE_X, &scale_x) == tinyxml2::XML_SUCCESS ) { - frameData->scaleX = _scale_x; + frameData->scaleX = scale_x; } - if( frameXML->QueryFloatAttribute(A_SCALE_Y, &_scale_y) == tinyxml2::XML_SUCCESS ) + if( frameXML->QueryFloatAttribute(A_SCALE_Y, &scale_y) == tinyxml2::XML_SUCCESS ) { - frameData->scaleY = _scale_y; + frameData->scaleY = scale_y; } - if( frameXML->QueryFloatAttribute(A_SKEW_X, &_skew_x) == tinyxml2::XML_SUCCESS ) + if( frameXML->QueryFloatAttribute(A_SKEW_X, &skew_x) == tinyxml2::XML_SUCCESS ) { - frameData->skewX = CC_DEGREES_TO_RADIANS(_skew_x); + frameData->skewX = CC_DEGREES_TO_RADIANS(skew_x); } - if( frameXML->QueryFloatAttribute(A_SKEW_Y, &_skew_y) == tinyxml2::XML_SUCCESS ) + if( frameXML->QueryFloatAttribute(A_SKEW_Y, &skew_y) == tinyxml2::XML_SUCCESS ) { - frameData->skewY = CC_DEGREES_TO_RADIANS(-_skew_y); + frameData->skewY = CC_DEGREES_TO_RADIANS(-skew_y); } - if( frameXML->QueryIntAttribute(A_DURATION, &_duration) == tinyxml2::XML_SUCCESS ) + if( frameXML->QueryIntAttribute(A_DURATION, &duration) == tinyxml2::XML_SUCCESS ) { - frameData->duration = _duration; + frameData->duration = duration; } - if( frameXML->QueryIntAttribute(A_DISPLAY_INDEX, &_displayIndex) == tinyxml2::XML_SUCCESS ) + if( frameXML->QueryIntAttribute(A_DISPLAY_INDEX, &displayIndex) == tinyxml2::XML_SUCCESS ) { - frameData->displayIndex = _displayIndex; + frameData->displayIndex = displayIndex; } - if( frameXML->QueryIntAttribute(A_Z, &_zOrder) == tinyxml2::XML_SUCCESS ) + if( frameXML->QueryIntAttribute(A_Z, &zOrder) == tinyxml2::XML_SUCCESS ) { - frameData->zOrder = _zOrder; + frameData->zOrder = zOrder; + } + if ( frameXML->QueryIntAttribute(A_BLEND_TYPE, &blendType) == tinyxml2::XML_SUCCESS ) + { + frameData->blendType = (CCBlendType)blendType; } - tinyxml2::XMLElement *colorTransformXML = frameXML->FirstChildElement(A_COLOR_TRANSFORM); if (colorTransformXML) @@ -685,9 +980,9 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm std::string str = _easing; if(str.compare(FL_NAN) != 0) { - if( frameXML->QueryIntAttribute(A_TWEEN_EASING, &(_tweenEasing)) == tinyxml2::XML_SUCCESS) + if( frameXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS) { - frameData->tweenEasing = (TweenType)_tweenEasing; + frameData->tweenEasing = (CCTweenType)tweenEasing; } } else @@ -701,7 +996,7 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm /* * recalculate frame data from parent frame data, use for translate matrix */ - BaseData helpNode; + CCBaseData helpNode; if (s_FlashToolVersion >= VERSION_2_0) { parentFrameXml->QueryFloatAttribute(A_COCOS2DX_X, &helpNode.x); @@ -721,14 +1016,15 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm helpNode.skewX = CC_DEGREES_TO_RADIANS(helpNode.skewX); helpNode.skewY = CC_DEGREES_TO_RADIANS(-helpNode.skewY); - TransformHelp::transformFromParent(*frameData, helpNode); + CCTransformHelp::transformFromParent(*frameData, helpNode); } return frameData; } -TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) +CCTextureData *CCDataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) { - TextureData *textureData = TextureData::create(); + CCTextureData *textureData = new CCTextureData(); + textureData->init(); if( textureXML->Attribute(A_NAME) != NULL) { @@ -761,8 +1057,9 @@ TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) while (contourXML) { - ContourData *contourData = decodeContour(contourXML); + CCContourData *contourData = decodeContour(contourXML); textureData->addContourData(contourData); + contourData->release(); contourXML = contourXML->NextSiblingElement(CONTOUR); } @@ -770,42 +1067,33 @@ TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) return textureData; } -ContourData *DataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML) +CCContourData *CCDataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML) { - ContourData *contourData = ContourData::create(); + CCContourData *contourData = new CCContourData(); + contourData->init(); tinyxml2::XMLElement *vertexDataXML = contourXML->FirstChildElement(CONTOUR_VERTEX); while (vertexDataXML) { - ContourVertex2F *vertex = new ContourVertex2F(0, 0); - vertex->autorelease(); + CCContourVertex2 *vertex = new CCContourVertex2(0, 0); + vertex->release(); vertexDataXML->QueryFloatAttribute(A_X, &vertex->x); vertexDataXML->QueryFloatAttribute(A_Y, &vertex->y); vertex->y = -vertex->y; - contourData->vertexList->addObject(vertex); + contourData->vertexList.addObject(vertex); vertexDataXML = vertexDataXML->NextSiblingElement(CONTOUR_VERTEX); } return contourData; - } -void DataReaderHelper::addDataFromJson(const char *filePath) -{ - unsigned long size; - std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath); - const char *pFileContent = (char *)FileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); - - addDataFromJsonCache(pFileContent); -} - -void DataReaderHelper::addDataFromJsonCache(const char *fileContent) +void CCDataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo) { cs::JsonDictionary json; json.initWithDescription(fileContent); @@ -815,9 +1103,18 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent) for (int i = 0; i < length; i++) { cs::JsonDictionary *armatureDic = json.getSubItemFromArray(ARMATURE_DATA, i); - ArmatureData *armatureData = decodeArmature(*armatureDic); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); + CCArmatureData *armatureData = decodeArmature(*armatureDic); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.lock(); + } + CCArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); + armatureData->release(); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.unlock(); + } delete armatureDic; } @@ -826,9 +1123,18 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent) for (int i = 0; i < length; i++) { cs::JsonDictionary *animationDic = json.getSubItemFromArray(ANIMATION_DATA, i); - AnimationData *animationData = decodeAnimation(*animationDic); - ArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); + CCAnimationData *animationData = decodeAnimation(*animationDic); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.lock(); + } + CCArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); + animationData->release(); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.unlock(); + } delete animationDic; } @@ -837,16 +1143,57 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent) for (int i = 0; i < length; i++) { cs::JsonDictionary *textureDic = json.getSubItemFromArray(TEXTURE_DATA, i); - TextureData *textureData = decodeTexture(*textureDic); - ArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); + CCTextureData *textureData = decodeTexture(*textureDic); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.lock(); + } + CCArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); + textureData->release(); + if (dataInfo) + { + s_DataReaderHelper->s_AddDataMutex.unlock(); + } delete textureDic; } + + // Auto load sprite file + bool autoLoad = dataInfo == NULL ? CCArmatureDataManager::sharedArmatureDataManager()->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"; + + CCArmatureDataManager::sharedArmatureDataManager()->addSpriteFrameFromFile((s_BasefilePath + plistPath).c_str(), (s_BasefilePath + pngPath).c_str()); + } + } + } } -ArmatureData *DataReaderHelper::decodeArmature(cs::JsonDictionary &json) +CCArmatureData *CCDataReaderHelper::decodeArmature(cs::JsonDictionary &json) { - ArmatureData *armatureData = ArmatureData::create(); + CCArmatureData *armatureData = new CCArmatureData(); + armatureData->init(); const char *name = json.getItemStringValue(A_NAME); if(name != NULL) @@ -854,11 +1201,15 @@ ArmatureData *DataReaderHelper::decodeArmature(cs::JsonDictionary &json) 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); - armatureData->addBoneData(decodeBone(*dic)); + CCBoneData *boneData = decodeBone(*dic); + armatureData->addBoneData(boneData); + boneData->release(); delete dic; } @@ -866,9 +1217,10 @@ ArmatureData *DataReaderHelper::decodeArmature(cs::JsonDictionary &json) return armatureData; } -BoneData *DataReaderHelper::decodeBone(cs::JsonDictionary &json) +CCBoneData *CCDataReaderHelper::decodeBone(cs::JsonDictionary &json) { - BoneData *boneData = BoneData::create(); + CCBoneData *boneData = new CCBoneData(); + boneData->init(); decodeNode(boneData, json); @@ -889,7 +1241,9 @@ BoneData *DataReaderHelper::decodeBone(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(DISPLAY_DATA, i); - boneData->addDisplayData(decodeBoneDisplay(*dic)); + CCDisplayData *displayData = decodeBoneDisplay(*dic); + boneData->addDisplayData(displayData); + displayData->release(); delete dic; } @@ -897,75 +1251,76 @@ BoneData *DataReaderHelper::decodeBone(cs::JsonDictionary &json) return boneData; } -DisplayData *DataReaderHelper::decodeBoneDisplay(cs::JsonDictionary &json) +CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(cs::JsonDictionary &json) { DisplayType displayType = (DisplayType)json.getItemIntValue(A_DISPLAY_TYPE, CS_DISPLAY_SPRITE); - DisplayData *displayData = NULL; + CCDisplayData *displayData = NULL; switch (displayType) { case CS_DISPLAY_SPRITE: { - displayData = SpriteDisplayData::create(); + displayData = new CCSpriteDisplayData(); + const char *name = json.getItemStringValue(A_NAME); if(name != NULL) { - ((SpriteDisplayData *)displayData)->displayName = name; + ((CCSpriteDisplayData *)displayData)->displayName = name; + } + + cs::JsonDictionary *dic = json.getSubItemFromArray(SKIN_DATA, 0); + if (dic != NULL) + { + CCSpriteDisplayData *sdd = (CCSpriteDisplayData *)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 = ArmatureDisplayData::create(); + displayData = new CCArmatureDisplayData(); + const char *name = json.getItemStringValue(A_NAME); if(name != NULL) { - ((ArmatureDisplayData *)displayData)->displayName = name; + ((CCArmatureDisplayData *)displayData)->displayName = name; } } break; case CS_DISPLAY_PARTICLE: { - displayData = ParticleDisplayData::create(); + displayData = new CCParticleDisplayData(); + const char *plist = json.getItemStringValue(A_PLIST); if(plist != NULL) { - ((ParticleDisplayData *)displayData)->plist = plist; + ((CCParticleDisplayData *)displayData)->plist = s_BasefilePath + plist; } } break; - case CS_DISPLAY_SHADER: - { - displayData = ShaderDisplayData::create(); - const char *vert = json.getItemStringValue(A_VERT); - if(vert != NULL) - { - ((ShaderDisplayData *)displayData)->vert = vert; - } - - const char *frag = json.getItemStringValue(A_FRAG); - if(frag != NULL) - { - ((ShaderDisplayData *)displayData)->frag = vert; - } - - } - break; default: - displayData = SpriteDisplayData::create(); + displayData = new CCSpriteDisplayData(); + break; } + displayData->displayType = displayType; return displayData; } -AnimationData *DataReaderHelper::decodeAnimation(cs::JsonDictionary &json) +CCAnimationData *CCDataReaderHelper::decodeAnimation(cs::JsonDictionary &json) { - AnimationData *aniData = AnimationData::create(); + CCAnimationData *aniData = new CCAnimationData(); const char *name = json.getItemStringValue(A_NAME); if(name != NULL) @@ -978,7 +1333,9 @@ AnimationData *DataReaderHelper::decodeAnimation(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_DATA, i); - aniData->addMovement(decodeMovement(*dic)); + CCMovementData *movementData = decodeMovement(*dic); + aniData->addMovement(movementData); + movementData->release(); delete dic; } @@ -986,15 +1343,16 @@ AnimationData *DataReaderHelper::decodeAnimation(cs::JsonDictionary &json) return aniData; } -MovementData *DataReaderHelper::decodeMovement(cs::JsonDictionary &json) +CCMovementData *CCDataReaderHelper::decodeMovement(cs::JsonDictionary &json) { - MovementData *movementData = MovementData::create(); + CCMovementData *movementData = new CCMovementData(); 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->tweenEasing = (TweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); + 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) @@ -1006,7 +1364,9 @@ MovementData *DataReaderHelper::decodeMovement(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_BONE_DATA, i); - movementData->addMovementBoneData(decodeMovementBone(*dic)); + CCMovementBoneData *movementBoneData = decodeMovementBone(*dic); + movementData->addMovementBoneData(movementBoneData); + movementBoneData->release(); delete dic; } @@ -1014,12 +1374,12 @@ MovementData *DataReaderHelper::decodeMovement(cs::JsonDictionary &json) return movementData; } -MovementBoneData *DataReaderHelper::decodeMovementBone(cs::JsonDictionary &json) +CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(cs::JsonDictionary &json) { - MovementBoneData *movementBoneData = MovementBoneData::create(); + CCMovementBoneData *movementBoneData = new CCMovementBoneData(); + movementBoneData->init(); movementBoneData->delay = json.getItemFloatValue(A_MOVEMENT_DELAY, 0); - movementBoneData->scale = json.getItemFloatValue(A_MOVEMENT_SCALE, 1); const char *name = json.getItemStringValue(A_NAME); if(name != NULL) @@ -1031,38 +1391,68 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(FRAME_DATA, i); - FrameData *frameData = decodeFrame(*dic); + CCFrameData *frameData = decodeFrame(*dic); + movementBoneData->addFrameData(frameData); - //movementBoneData->duration += frameData->duration; + frameData->release(); + + if (s_CocoStudioVersion < VERSION_COMBINED) + { + frameData->frameID = movementBoneData->duration; + movementBoneData->duration += frameData->duration; + } delete dic; } + if (s_CocoStudioVersion < VERSION_COMBINED) + { + if (movementBoneData->frameList.count() > 0) + { + CCFrameData *frameData = new CCFrameData(); + frameData->copy((CCFrameData *)movementBoneData->frameList.getLastObject()); + movementBoneData->addFrameData(frameData); + frameData->release(); + + frameData->frameID = movementBoneData->duration; + } + } + return movementBoneData; } -FrameData *DataReaderHelper::decodeFrame(cs::JsonDictionary &json) +CCFrameData *CCDataReaderHelper::decodeFrame(cs::JsonDictionary &json) { - FrameData *frameData = FrameData::create(); + CCFrameData *frameData = new CCFrameData(); decodeNode(frameData, json); - frameData->duration = json.getItemIntValue(A_DURATION, 1); - frameData->tweenEasing = (TweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); + frameData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0); + frameData->blendType = (CCBlendType)json.getItemIntValue(A_BLEND_TYPE, 0); const char *event = json.getItemStringValue(A_EVENT); if (event != NULL) { - frameData->_event = 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; } -TextureData *DataReaderHelper::decodeTexture(cs::JsonDictionary &json) +CCTextureData *CCDataReaderHelper::decodeTexture(cs::JsonDictionary &json) { - TextureData *textureData = TextureData::create(); + CCTextureData *textureData = new CCTextureData(); + textureData->init(); const char *name = json.getItemStringValue(A_NAME); if(name != NULL) @@ -1079,7 +1469,9 @@ TextureData *DataReaderHelper::decodeTexture(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(CONTOUR_DATA, i); - textureData->contourDataList->addObject(decodeContour(*dic)); + CCContourData *contourData = decodeContour(*dic); + textureData->contourDataList.addObject(contourData); + contourData->release(); delete dic; } @@ -1087,21 +1479,22 @@ TextureData *DataReaderHelper::decodeTexture(cs::JsonDictionary &json) return textureData; } -ContourData *DataReaderHelper::decodeContour(cs::JsonDictionary &json) +CCContourData *CCDataReaderHelper::decodeContour(cs::JsonDictionary &json) { - ContourData *contourData = ContourData::create(); + CCContourData *contourData = new CCContourData(); + contourData->init(); int length = json.getArrayItemCount(VERTEX_POINT); for (int i = length - 1; i >= 0; i--) { cs::JsonDictionary *dic = json.getSubItemFromArray(VERTEX_POINT, i); - ContourVertex2F *vertex = new ContourVertex2F(0, 0); + CCContourVertex2 *vertex = new CCContourVertex2(0, 0); vertex->x = dic->getItemFloatValue(A_X, 0); vertex->y = dic->getItemFloatValue(A_Y, 0); - contourData->vertexList->addObject(vertex); + contourData->vertexList.addObject(vertex); vertex->release(); delete dic; @@ -1110,7 +1503,7 @@ ContourData *DataReaderHelper::decodeContour(cs::JsonDictionary &json) return contourData; } -void DataReaderHelper::decodeNode(BaseData *node, cs::JsonDictionary &json) +void CCDataReaderHelper::decodeNode(CCBaseData *node, cs::JsonDictionary &json) { node->x = json.getItemFloatValue(A_X, 0) * s_PositionReadScale; node->y = json.getItemFloatValue(A_Y, 0) * s_PositionReadScale; @@ -1137,4 +1530,4 @@ void DataReaderHelper::decodeNode(BaseData *node, cs::JsonDictionary &json) } -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h index 69d310623b..5830f7ef9e 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h @@ -27,19 +27,54 @@ THE SOFTWARE. #include "CCArmatureDefine.h" #include "../datas/CCDatas.h" -#include "../utils/CCConstValue.h" #include "../CCArmature.h" #include "../../Json/CSContentJsonDictionary.h" -namespace tinyxml2 { class XMLElement; } +#include +#include +#include +#include +#include -namespace cocos2d { namespace extension { namespace armature { - - -class DataReaderHelper +namespace tinyxml2 { + class XMLElement; +} + +NS_CC_EXT_ARMATURE_BEGIN + + +class CCDataReaderHelper : Object +{ +protected: + + enum ConfigType + { + DragonBone_XML, + CocoStudio_JSON + }; + + typedef struct _AsyncStruct + { + std::string filename; + std::string fileContent; + ConfigType configType; + std::string baseFilePath; + Object *target; + SEL_SCHEDULE selector; + bool autoLoadSpriteFile; + } AsyncStruct; + + typedef struct _DataInfo + { + AsyncStruct *asyncStruct; + std::queue configFileQueue; + } DataInfo; public: + + static CCDataReaderHelper *sharedDataReaderHelper(); + /** * Scale the position data, used for multiresolution adapter * It won't effect the data already read. @@ -47,85 +82,105 @@ public: static void setPositionReadScale(float scale); static float getPositionReadScale(); - static void addDataFromFile(const char *filePath); - + static void purge(); static void clear(); public: + CCDataReaderHelper(); + ~CCDataReaderHelper(); - /** - * Translate XML export from Dragon Bone flash tool to datas, and save them. - * When you add a new xml, the data already saved will be keeped. - * - * @param xmlPath Path of xml file - */ - static void addDataFromXML(const char *xmlPath); + void addDataFromFile(const char *filePath); + void addDataFromFileAsync(const char *filePath, Object *target, SEL_SCHEDULE selector); - /** - * Translate XML export from Dragon Bone flash tool to datas, and save them. - * When you add a new xml, the data already saved will be keeped. - * - * @param xmlPakPath Path of pak file - */ - static void addDataFromXMLPak(const char *xmlPakPath); - - /** - * Translate XML export from Dragon Bone flash tool to datas, and save them. - * When you add a new xml, the data already saved will be keeped. - * - * @param fileContent The cache of the xml - */ - static void addDataFromCache(const char *fileContent); - - - - /** - * 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); - - - /** - * 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); - - - /** - * Decode Texture Datas from xml export from Dragon Bone flash tool - */ - static TextureData *decodeTexture(tinyxml2::XMLElement *textureXML); - - /** - * Decode Contour Datas from xml export from Dragon Bone flash tool - */ - static ContourData *decodeContour(tinyxml2::XMLElement *contourXML); + void addDataAsyncCallBack(float dt); public: - static void addDataFromJson(const char *filePath); - static void addDataFromJsonCache(const char *fileContent); + /** + * Translate XML export from Dragon CCBone flash tool to datas, and save them. + * When you add a new xml, the data already saved will be keeped. + * + * @param xmlPath The cache of the xml + */ + static void addDataFromCache(const char *pFileContent, DataInfo *dataInfo = NULL); - static ArmatureData *decodeArmature(cs::JsonDictionary &json); - static BoneData *decodeBone(cs::JsonDictionary &json); - static DisplayData *decodeBoneDisplay(cs::JsonDictionary &json); - static AnimationData *decodeAnimation(cs::JsonDictionary &json); - static MovementData *decodeMovement(cs::JsonDictionary &json); - static MovementBoneData *decodeMovementBone(cs::JsonDictionary &json); - static FrameData *decodeFrame(cs::JsonDictionary &json); - static TextureData *decodeTexture(cs::JsonDictionary &json); + /** + * Decode CCArmature Datas from xml export from Dragon CCBone flash tool + */ + static CCArmatureData *decodeArmature(tinyxml2::XMLElement *armatureXML); + static CCBoneData *decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXML); + static CCDisplayData *decodeBoneDisplay(tinyxml2::XMLElement *displayXML); - static ContourData *decodeContour(cs::JsonDictionary &json); - static void decodeNode(BaseData *node, cs::JsonDictionary &json); + /** + * Decode CCArmatureAnimation Datas from xml export from Dragon CCBone flash tool + */ + static CCAnimationData *decodeAnimation(tinyxml2::XMLElement *animationXML); + static CCMovementData *decodeMovement(tinyxml2::XMLElement *movementXML, CCArmatureData *armatureData); + static CCMovementBoneData *decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, CCBoneData *boneData); + static CCFrameData *decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, CCBoneData *boneData); + + + /** + * Decode Texture Datas from xml export from Dragon CCBone flash tool + */ + static CCTextureData *decodeTexture(tinyxml2::XMLElement *textureXML); + + /** + * Decode Contour Datas from xml export from Dragon CCBone flash tool + */ + static CCContourData *decodeContour(tinyxml2::XMLElement *contourXML); + +public: + static void addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo = NULL); + + static CCArmatureData *decodeArmature(cs::JsonDictionary &json); + static CCBoneData *decodeBone(cs::JsonDictionary &json); + static CCDisplayData *decodeBoneDisplay(cs::JsonDictionary &json); + + static CCAnimationData *decodeAnimation(cs::JsonDictionary &json); + static CCMovementData *decodeMovement(cs::JsonDictionary &json); + static CCMovementBoneData *decodeMovementBone(cs::JsonDictionary &json); + static CCFrameData *decodeFrame(cs::JsonDictionary &json); + + static CCTextureData *decodeTexture(cs::JsonDictionary &json); + + static CCContourData *decodeContour(cs::JsonDictionary &json); + + static void decodeNode(CCBaseData *node, cs::JsonDictionary &json); + +protected: + void loadData(); + + + + + std::condition_variable s_SleepCondition; + + std::thread *s_LoadingThread; + + std::mutex s_SleepMutex; + + std::mutex s_AsyncStructQueueMutex; + std::mutex s_DataInfoMutex; + + std::mutex s_AddDataMutex; + std::mutex s_ReadFileMutex; + + + unsigned long s_nAsyncRefCount; + unsigned long s_nAsyncRefTotalCount; + + bool need_quit; + + std::queue *s_pAsyncStructQueue; + std::queue *s_pDataQueue; + + + static CCDataReaderHelper *s_DataReaderHelper; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCDATAREADERHELPER_H__*/ diff --git a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp index 297cbd6046..fd5ad2694b 100644 --- a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp @@ -25,160 +25,51 @@ THE SOFTWARE. #include "CCSpriteFrameCacheHelper.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -SpriteFrameCacheHelper *SpriteFrameCacheHelper::s_SpriteFrameCacheHelper = NULL; +CCSpriteFrameCacheHelper *CCSpriteFrameCacheHelper::s_SpriteFrameCacheHelper = NULL; -SpriteFrameCacheHelper *SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper() +CCSpriteFrameCacheHelper *CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper() { if(!s_SpriteFrameCacheHelper) { - s_SpriteFrameCacheHelper = new SpriteFrameCacheHelper(); + s_SpriteFrameCacheHelper = new CCSpriteFrameCacheHelper(); } return s_SpriteFrameCacheHelper; } -void SpriteFrameCacheHelper::purgeSpriteFrameCacheHelper() +void CCSpriteFrameCacheHelper::purge() { delete s_SpriteFrameCacheHelper; s_SpriteFrameCacheHelper = NULL; } -void SpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) +void CCSpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) { - - std::string path = FileUtils::getInstance()->fullPathForFilename(plistPath); - Dictionary *dict = Dictionary::createWithContentsOfFileThreadSafe(path.c_str()); - - - Texture2D *pobTexture = TextureCache::getInstance()->addImage(imagePath); - - addSpriteFrameFromDict(dict, pobTexture, imagePath); - - dict->release(); - + CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plistPath, imagePath); } -void SpriteFrameCacheHelper::addSpriteFrameFromDict(Dictionary *dictionary, Texture2D *pobTexture, const char *imagePath) +TextureAtlas *CCSpriteFrameCacheHelper::getTexureAtlasWithTexture(Texture2D *texture) { - /* - Supported Zwoptex Formats: - - ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version - ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b - ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1 - ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+ - */ - - Dictionary *metadataDict = (Dictionary *)dictionary->objectForKey("metadata"); - Dictionary *framesDict = (Dictionary *)dictionary->objectForKey("frames"); - int format = 0; - - // get the format - if(metadataDict != NULL) - { - format = metadataDict->valueForKey("format")->intValue(); - } - - // check the format - CCASSERT(format >= 0 && format <= 3, "format is not supported for SpriteFrameCache addSpriteFramesWithDictionary:textureFilename:"); - - DictElement *pElement = NULL; - CCDICT_FOREACH(framesDict, pElement) - { - Dictionary *frameDict = static_cast(pElement->getObject()); - std::string spriteFrameName = pElement->getStrKey(); - - _display2ImageMap[spriteFrameName] = imagePath; - - //log("spriteFrameName : %s, imagePath : %s", spriteFrameName.c_str(), _imagePath); - - SpriteFrame *spriteFrame = (SpriteFrame *)SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName.c_str()); - if (spriteFrame) - { - continue; - } - - if(format == 0) - { - float x = frameDict->valueForKey("x")->floatValue(); - float y = frameDict->valueForKey("y")->floatValue(); - float w = frameDict->valueForKey("width")->floatValue(); - float h = frameDict->valueForKey("height")->floatValue(); - float ox = frameDict->valueForKey("offsetX")->floatValue(); - float oy = frameDict->valueForKey("offsetY")->floatValue(); - int ow = frameDict->valueForKey("originalWidth")->intValue(); - int oh = frameDict->valueForKey("originalHeight")->intValue(); - // check ow/oh - if(!ow || !oh) - { - CCLOG("cocos2d: WARNING: originalWidth/Height not found on the SpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist"); - } - // abs ow/oh - ow = abs(ow); - oh = abs(oh); - // create frame - spriteFrame = new SpriteFrame(); - spriteFrame->initWithTexture(pobTexture, Rect(x, y, w, h), false, Point(ox, oy), Size((float)ow, (float)oh)); - } - else if(format == 1 || format == 2) - { - Rect frame = RectFromString(frameDict->valueForKey("frame")->getCString()); - bool rotated = false; - - // rotation - if (format == 2) - { - rotated = frameDict->valueForKey("rotated")->boolValue(); - } - - Point offset = PointFromString(frameDict->valueForKey("offset")->getCString()); - Size sourceSize = SizeFromString(frameDict->valueForKey("sourceSize")->getCString()); - - // create frame - spriteFrame = new SpriteFrame(); - spriteFrame->initWithTexture(pobTexture, frame, rotated, offset, sourceSize ); - } - else if (format == 3) - { - - } - - // add sprite frame - SpriteFrameCache::getInstance()->addSpriteFrame(spriteFrame, spriteFrameName.c_str()); - spriteFrame->release(); - } -} - -const char *SpriteFrameCacheHelper::getDisplayImagePath(const char *displayName) -{ - return _display2ImageMap[displayName].c_str(); -} - - -TextureAtlas *SpriteFrameCacheHelper::getTextureAtlas(const char *displayName) -{ - const char *textureName = getDisplayImagePath(displayName); - TextureAtlas *atlas = (TextureAtlas *)_display2TextureAtlas->objectForKey(textureName); + int key = texture->getName(); + TextureAtlas *atlas = (TextureAtlas *)m_pTextureAtlasDic->objectForKey(key); if (atlas == NULL) { - atlas = TextureAtlas::createWithTexture(TextureCache::getInstance()->addImage(textureName), 4); - _display2TextureAtlas->setObject(atlas, textureName); + atlas = TextureAtlas::createWithTexture(texture, 4); + m_pTextureAtlasDic->setObject(atlas, key); } - return atlas; } -SpriteFrameCacheHelper::SpriteFrameCacheHelper() +CCSpriteFrameCacheHelper::CCSpriteFrameCacheHelper() { - _display2TextureAtlas = new Dictionary(); - _display2TextureAtlas->init(); + m_pTextureAtlasDic = new Dictionary(); } -SpriteFrameCacheHelper::~SpriteFrameCacheHelper() +CCSpriteFrameCacheHelper::~CCSpriteFrameCacheHelper() { - CC_SAFE_RELEASE_NULL(_display2TextureAtlas); + CC_SAFE_RELEASE_NULL(m_pTextureAtlasDic); } -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h index f92eeadaf0..bd7ce29978 100644 --- a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h @@ -29,40 +29,32 @@ THE SOFTWARE. using namespace std; -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -class SpriteFrameCacheHelper +class CCSpriteFrameCacheHelper { public: - static SpriteFrameCacheHelper *sharedSpriteFrameCacheHelper(); + static CCSpriteFrameCacheHelper *sharedSpriteFrameCacheHelper(); - static void purgeSpriteFrameCacheHelper(); + static void purge(); public: /** - * @brief Add sprite frame to SpriteFrameCache, it will save display name and it's relative image name - * + * @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 addSpriteFrameFromDict(Dictionary *dictionary, Texture2D *pobTexture, const char *imagePath); - - /** - * Get this display in which image - */ - const char *getDisplayImagePath(const char *displayName); - TextureAtlas *getTextureAtlas(const char *displayName); + TextureAtlas *getTexureAtlasWithTexture(Texture2D *texture); private: - SpriteFrameCacheHelper(); - ~SpriteFrameCacheHelper(); + CCSpriteFrameCacheHelper(); + ~CCSpriteFrameCacheHelper(); - std::map _display2ImageMap; - Dictionary *_display2TextureAtlas; + Dictionary *m_pTextureAtlasDic; - static SpriteFrameCacheHelper *s_SpriteFrameCacheHelper; + static CCSpriteFrameCacheHelper *s_SpriteFrameCacheHelper; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCSPRITEFRAMECACHEHELPER_H__*/ diff --git a/extensions/CocoStudio/Armature/utils/CCTransformHelp.cpp b/extensions/CocoStudio/Armature/utils/CCTransformHelp.cpp index dc635eb70a..dadbe909da 100644 --- a/extensions/CocoStudio/Armature/utils/CCTransformHelp.cpp +++ b/extensions/CocoStudio/Armature/utils/CCTransformHelp.cpp @@ -25,21 +25,21 @@ THE SOFTWARE. #include "CCTransformHelp.h" #include "CCUtilMath.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -AffineTransform TransformHelp::helpMatrix1; -AffineTransform TransformHelp::helpMatrix2; +AffineTransform CCTransformHelp::helpMatrix1; +AffineTransform CCTransformHelp::helpMatrix2; -Point TransformHelp::helpPoint1; -Point TransformHelp::helpPoint2; +Point CCTransformHelp::helpPoint1; +Point CCTransformHelp::helpPoint2; -BaseData helpParentNode; +CCBaseData helpParentNode; -TransformHelp::TransformHelp() +CCTransformHelp::CCTransformHelp() { } -void TransformHelp::transformFromParent(BaseData &node, const BaseData &parentNode) +void CCTransformHelp::transformFromParent(CCBaseData &node, const CCBaseData &parentNode) { nodeToMatrix(node, helpMatrix1); nodeToMatrix(parentNode, helpMatrix2); @@ -50,7 +50,7 @@ void TransformHelp::transformFromParent(BaseData &node, const BaseData &parentNo matrixToNode(helpMatrix1, node); } -void TransformHelp::transformToParent(BaseData &node, const BaseData &parentNode) +void CCTransformHelp::transformToParent(CCBaseData &node, const CCBaseData &parentNode) { nodeToMatrix(node, helpMatrix1); @@ -61,7 +61,7 @@ void TransformHelp::transformToParent(BaseData &node, const BaseData &parentNode matrixToNode(helpMatrix1, node); } -void TransformHelp::transformFromParentWithoutScale(BaseData &node, const BaseData &parentNode) +void CCTransformHelp::transformFromParentWithoutScale(CCBaseData &node, const CCBaseData &parentNode) { helpParentNode.copy(&parentNode); @@ -77,7 +77,7 @@ void TransformHelp::transformFromParentWithoutScale(BaseData &node, const BaseDa matrixToNode(helpMatrix1, node); } -void TransformHelp::transformToParentWithoutScale(BaseData &node, const BaseData &parentNode) +void CCTransformHelp::transformToParentWithoutScale(CCBaseData &node, const CCBaseData &parentNode) { helpParentNode.copy(&parentNode); @@ -92,7 +92,7 @@ void TransformHelp::transformToParentWithoutScale(BaseData &node, const BaseData matrixToNode(helpMatrix1, node); } -void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix) +void CCTransformHelp::nodeToMatrix(const CCBaseData &node, AffineTransform &matrix) { matrix.a = node.scaleX * cos(node.skewY); matrix.b = node.scaleX * sin(node.skewY); @@ -103,7 +103,7 @@ void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix) matrix.ty = node.y; } -void TransformHelp::matrixToNode(const AffineTransform &matrix, BaseData &node) +void CCTransformHelp::matrixToNode(const AffineTransform &matrix, CCBaseData &node) { /* * In as3 language, there is a function called "deltaTransformPoint", it calculate a point used give Transform @@ -129,7 +129,7 @@ void TransformHelp::matrixToNode(const AffineTransform &matrix, BaseData &node) node.y = matrix.ty; } -void TransformHelp::nodeConcat(BaseData &target, BaseData &source) +void CCTransformHelp::nodeConcat(CCBaseData &target, CCBaseData &source) { target.x += source.x; target.y += source.y; @@ -139,4 +139,14 @@ void TransformHelp::nodeConcat(BaseData &target, BaseData &source) target.scaleY += source.scaleY; } -}}} // namespace cocos2d { namespace extension { namespace armature { +void CCTransformHelp::nodeSub(CCBaseData &target, CCBaseData &source) +{ + target.x -= source.x; + target.y -= source.y; + target.skewX -= source.skewX; + target.skewY -= source.skewY; + target.scaleX -= source.scaleX; + target.scaleY -= source.scaleY; +} + +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCTransformHelp.h b/extensions/CocoStudio/Armature/utils/CCTransformHelp.h index 0fe2691a44..7838e66184 100644 --- a/extensions/CocoStudio/Armature/utils/CCTransformHelp.h +++ b/extensions/CocoStudio/Armature/utils/CCTransformHelp.h @@ -28,26 +28,27 @@ THE SOFTWARE. #include "CCArmatureDefine.h" #include "../datas/CCDatas.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN /* * use to calculate the matrix of node from parent node */ -class TransformHelp +class CCTransformHelp { public: - TransformHelp(); + CCTransformHelp(); - static void transformFromParent(BaseData &node, const BaseData &parentNode); - static void transformToParent(BaseData &node, const BaseData &parentNode); + static void transformFromParent(CCBaseData &node, const CCBaseData &parentNode); + static void transformToParent(CCBaseData &node, const CCBaseData &parentNode); - static void transformFromParentWithoutScale(BaseData &node, const BaseData &parentNode); - static void transformToParentWithoutScale(BaseData &node, const BaseData &parentNode); + static void transformFromParentWithoutScale(CCBaseData &node, const CCBaseData &parentNode); + static void transformToParentWithoutScale(CCBaseData &node, const CCBaseData &parentNode); - static void nodeToMatrix(const BaseData &_node, AffineTransform &_matrix); - static void matrixToNode(const AffineTransform &_matrix, BaseData &_node); + static void nodeToMatrix(const CCBaseData &_node, AffineTransform &_matrix); + static void matrixToNode(const AffineTransform &_matrix, CCBaseData &_node); - static void nodeConcat(BaseData &target, BaseData &source); + static void nodeConcat(CCBaseData &target, CCBaseData &source); + static void nodeSub(CCBaseData &target, CCBaseData &source); public: static AffineTransform helpMatrix1; static AffineTransform helpMatrix2; @@ -56,6 +57,6 @@ public: static Point helpPoint2; }; -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCTRANSFORMHELP_H__*/ diff --git a/extensions/CocoStudio/Armature/utils/CCTweenFunction.cpp b/extensions/CocoStudio/Armature/utils/CCTweenFunction.cpp index 7346f4c0b4..340da10da5 100644 --- a/extensions/CocoStudio/Armature/utils/CCTweenFunction.cpp +++ b/extensions/CocoStudio/Armature/utils/CCTweenFunction.cpp @@ -25,9 +25,9 @@ THE SOFTWARE. #include "CCTweenFunction.h" #include "CCUtilMath.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -float TweenFunction::tweenTo(float from, float change, float time, float duration, TweenType tweenType) +float CCTweenFunction::tweenTo(float from, float change, float time, float duration, CCTweenType tweenType) { float delta = 0; @@ -146,109 +146,109 @@ float TweenFunction::tweenTo(float from, float change, float time, float duratio return delta; } -float TweenFunction::linear(float t, float b, float c, float d) +float CCTweenFunction::linear(float t, float b, float c, float d) { return c * t / d + b; } -float TweenFunction::quadEaseIn(float t, float b, float c, float d) +float CCTweenFunction::quadEaseIn(float t, float b, float c, float d) { - t /= d; + t /= d; return c * t * t + b; } -float TweenFunction::quadEaseOut(float t, float b, float c, float d) +float CCTweenFunction::quadEaseOut(float t, float b, float c, float d) { - t /= d; + t /= d; return -c * t * (t - 2) + b; } -float TweenFunction::quadEaseInOut(float t, float b, float c, float d) +float CCTweenFunction::quadEaseInOut(float t, float b, float c, float d) { - t /= d; + t /= d; if ((t / 2) < 1) return c / 2 * t * t + b; - --t; + --t; return -c / 2 * (t * (t - 2) - 1) + b; } -float TweenFunction::cubicEaseIn(float t, float b, float c, float d) +float CCTweenFunction::cubicEaseIn(float t, float b, float c, float d) { - t /= d; + t /= d; return c * t * t * t + b; } -float TweenFunction::cubicEaseOut(float t, float b, float c, float d) +float CCTweenFunction::cubicEaseOut(float t, float b, float c, float d) { - t = t / d - 1; + t = t / d - 1; return c * (t * t * t + 1) + b; } -float TweenFunction::cubicEaseInOut(float t, float b, float c, float d) +float CCTweenFunction::cubicEaseInOut(float t, float b, float c, float d) { - t /= d; + t /= d; if ((t / 2) < 1) return c / 2 * t * t * t + b; t -= 2; - return c / 2 * (t * t * t + 2) + b; + return c / 2 * (t * t * t + 2) + b; } -float TweenFunction::quartEaseIn(float t, float b, float c, float d) +float CCTweenFunction::quartEaseIn(float t, float b, float c, float d) { - t /= d; + t /= d; return c * t * t * t * t + b; } -float TweenFunction::quartEaseOut(float t, float b, float c, float d) +float CCTweenFunction::quartEaseOut(float t, float b, float c, float d) { - t = t / d - 1; + t = t / d - 1; return -c * (t * t * t * t - 1) + b; } -float TweenFunction::quartEaseInOut(float t, float b, float c, float d) +float CCTweenFunction::quartEaseInOut(float t, float b, float c, float d) { - t /= d; + t /= d; if ((t / 2) < 1) return c / 2 * t * t * t * t + b; t -= 2; - return -c / 2 * (t * t * t * t - 2) + b; + return -c / 2 * (t * t * t * t - 2) + b; } -float TweenFunction::quintEaseIn(float t, float b, float c, float d) +float CCTweenFunction::quintEaseIn(float t, float b, float c, float d) { - t /= d; + t /= d; return c * t * t * t * t * t + b; } -float TweenFunction::quintEaseOut(float t, float b, float c, float d) +float CCTweenFunction::quintEaseOut(float t, float b, float c, float d) { - t = t / d - 1; + t = t / d - 1; return c * (t * t * t * t * t + 1) + b; } -float TweenFunction::quintEaseInOut(float t, float b, float c, float d) +float CCTweenFunction::quintEaseInOut(float t, float b, float c, float d) { - t /= d; + t /= d; if ((t / 2) < 1) return c / 2 * t * t * t * t * t + b; - t -= 2; + t -= 2; return c / 2 * (t * t * t * t * t + 2) + b; } -float TweenFunction::sineEaseIn(float t, float b, float c, float d) +float CCTweenFunction::sineEaseIn(float t, float b, float c, float d) { return -c * cos(t / d * (M_PI / 2)) + c + b; } -float TweenFunction::sineEaseOut(float t, float b, float c, float d) +float CCTweenFunction::sineEaseOut(float t, float b, float c, float d) { return c * sin(t / d * (M_PI / 2)) + b; } -float TweenFunction::sineEaseInOut(float t, float b, float c, float d) +float CCTweenFunction::sineEaseInOut(float t, float b, float c, float d) { return -c / 2 * (cos(M_PI * t / d) - 1) + b; } -float TweenFunction::expoEaseIn(float t, float b, float c, float d) +float CCTweenFunction::expoEaseIn(float t, float b, float c, float d) { return (t == 0) ? b : c * pow(2, 10 * (t / d - 1)) + b; } -float TweenFunction::expoEaseOut(float t, float b, float c, float d) +float CCTweenFunction::expoEaseOut(float t, float b, float c, float d) { return (t == d) ? b + c : c * (-pow(2, -10 * t / d) + 1) + b; } -float TweenFunction::expoEaseInOut(float t, float b, float c, float d) +float CCTweenFunction::expoEaseInOut(float t, float b, float c, float d) { if (t == 0) return b; @@ -256,36 +256,36 @@ float TweenFunction::expoEaseInOut(float t, float b, float c, float d) return b + c; if ((t /= d / 2) < 1) return c / 2 * pow(2, 10 * (t - 1)) + b; - --t; + --t; return c / 2 * (-pow(2, -10 * t) + 2) + b; } -float TweenFunction::circEaseIn(float t, float b, float c, float d) +float CCTweenFunction::circEaseIn(float t, float b, float c, float d) { - t /= d; + t /= d; return -c * (sqrt(1 - t * t) - 1) + b; } -float TweenFunction::circEaseOut(float t, float b, float c, float d) +float CCTweenFunction::circEaseOut(float t, float b, float c, float d) { - t = t / d - 1; + t = t / d - 1; return c * sqrt(1 - t * t) + b; } -float TweenFunction::circEaseInOut(float t, float b, float c, float d) +float CCTweenFunction::circEaseInOut(float t, float b, float c, float d) { - t /= d; + t /= d; if ((t / 2) < 1) return -c / 2 * (sqrt(1 - t * t) - 1) + b; - t -= 2; + t -= 2; return c / 2 * (sqrt(1 - t * t) + 1) + b; } -float TweenFunction::elasticEaseIn(float t, float b, float c, float d, float a, float p) +float CCTweenFunction::elasticEaseIn(float t, float b, float c, float d, float a, float p) { float s = 0; if (t == 0) return b; t /= d; - if (t == 1) + if (t == 1) return b + c; if (!p) p = d * .3; @@ -296,15 +296,15 @@ float TweenFunction::elasticEaseIn(float t, float b, float c, float d, float a, } else s = p / (2 * M_PI) * asin(c / a); - t -= 1; + t -= 1; return -(a * pow(2, 10 * t) * sin((t * d - s) * (2 * M_PI) / p)) + b; } -float TweenFunction::elasticEaseOut(float t, float b, float c, float d, float a, float p) +float CCTweenFunction::elasticEaseOut(float t, float b, float c, float d, float a, float p) { float s = 0; if (t == 0) return b; - t /= d; + t /= d; if (t == 1) return b + c; if (!p) @@ -318,13 +318,13 @@ float TweenFunction::elasticEaseOut(float t, float b, float c, float d, float a, s = p / (2 * M_PI) * asin(c / a); return (a * pow(2, -10 * t) * sin((t * d - s) * (2 * M_PI) / p) + c + b); } -float TweenFunction::elasticEaseInOut(float t, float b, float c, float d, float a, float p) +float CCTweenFunction::elasticEaseInOut(float t, float b, float c, float d, float a, float p) { float s = 0; if (t == 0) return b; t /= d; - if ((t / 2) == 2) + if ((t / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5); @@ -336,73 +336,73 @@ float TweenFunction::elasticEaseInOut(float t, float b, float c, float d, float else s = p / (2 * M_PI) * asin(c / a); if (t < 1) - { - t -= 1; - return -.5 * (a * pow(2, 10 * t) * sin((t * d - s) * (2 * M_PI) / p)) + b; - } - t -= 1; + { + t -= 1; + return -.5 * (a * pow(2, 10 * t) * sin((t * d - s) * (2 * M_PI) / p)) + b; + } + t -= 1; return a * pow(2, -10 * t) * sin((t * d - s) * (2 * M_PI) / p) * .5 + c + b; } -float TweenFunction::backEaseIn(float t, float b, float c, float d, float s) +float CCTweenFunction::backEaseIn(float t, float b, float c, float d, float s) { if (s == 0) s = 1.70158f; t /= d; - return c * t * t * ((s + 1) * t - s) + b; + return c * t * t * ((s + 1) * t - s) + b; } -float TweenFunction::backEaseOut(float t, float b, float c, float d, float s) +float CCTweenFunction::backEaseOut(float t, float b, float c, float d, float s) { if (s == 0) s = 1.70158f; - t = t / d - 1; + t = t / d - 1; return c * (t * t * ((s + 1) * t + s) + 1) + b; } -float TweenFunction::backEaseInOut(float t, float b, float c, float d, float s) +float CCTweenFunction::backEaseInOut(float t, float b, float c, float d, float s) { if (s == 0) s = 1.70158f; if ((t /= d / 2) < 1) - { - s *= (1.525f); - return c / 2 * (t * t * ((s + 1) * t - s)) + b; - } - - t -= 2; - s *= (1.525f); + { + s *= (1.525f); + return c / 2 * (t * t * ((s + 1) * t - s)) + b; + } + + t -= 2; + s *= (1.525f); return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b; } -float TweenFunction::bounceEaseIn(float t, float b, float c, float d) +float CCTweenFunction::bounceEaseIn(float t, float b, float c, float d) { return c - bounceEaseOut(d - t, 0, c, d) + b; } -float TweenFunction::bounceEaseOut(float t, float b, float c, float d) +float CCTweenFunction::bounceEaseOut(float t, float b, float c, float d) { - t /= d; + t /= d; if (t < (1 / 2.75f)) { return c * (7.5625f * t * t) + b; } else if (t < (2 / 2.75f)) { - t -= (1.5f / 2.75f); + t -= (1.5f / 2.75f); return c * (7.5625f * t * t + .75f) + b; } else if (t < (2.5f / 2.75f)) { - t -= (2.25f / 2.75f); + t -= (2.25f / 2.75f); return c * (7.5625f * t * t + .9375f) + b; } else { - t -= (2.625f / 2.75f); + t -= (2.625f / 2.75f); return c * (7.5625f * t * t + .984375f) + b; } } -float TweenFunction::bounceEaseInOut(float t, float b, float c, float d) +float CCTweenFunction::bounceEaseInOut(float t, float b, float c, float d) { if (t < d / 2) return bounceEaseIn(t * 2, 0, c, d) * .5 + b; @@ -411,4 +411,4 @@ float TweenFunction::bounceEaseInOut(float t, float b, float c, float d) } -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCTweenFunction.h b/extensions/CocoStudio/Armature/utils/CCTweenFunction.h index ce5bdf6da3..b45b3598a5 100644 --- a/extensions/CocoStudio/Armature/utils/CCTweenFunction.h +++ b/extensions/CocoStudio/Armature/utils/CCTweenFunction.h @@ -29,22 +29,23 @@ THE SOFTWARE. #include "CCArmatureDefine.h" #include -namespace cocos2d { namespace extension { namespace armature { - -enum TweenType{ +NS_CC_EXT_ARMATURE_BEGIN + +enum CCTweenType +{ TWEEN_EASING_MIN = -1, - + Linear, - + Sine_EaseIn, Sine_EaseInOut, Sine_EaseOut, - - + + Quad_EaseIn, Quad_EaseOut, Quad_EaseInOut, - + Cubic_EaseIn, Cubic_EaseOut, Cubic_EaseInOut, @@ -52,83 +53,84 @@ enum TweenType{ Quart_EaseIn, Quart_EaseOut, Quart_EaseInOut, - + Quint_EaseIn, Quint_EaseOut, Quint_EaseInOut, - + Expo_EaseIn, Expo_EaseOut, Expo_EaseInOut, - + Circ_EaseIn, Circ_EaseOut, Circ_EaseInOut, - + Elastic_EaseIn, Elastic_EaseOut, Elastic_EaseInOut, - + Back_EaseIn, Back_EaseOut, Back_EaseInOut, - + Bounce_EaseIn, Bounce_EaseOut, Bounce_EaseInOut, - + TWEEN_EASING_MAX = 10000 }; - -class TweenFunction{ + +class CCTweenFunction +{ public: - - static float tweenTo(float from, float change, float time, float duration, TweenType tweenType); - + + static float tweenTo(float from, float change, float time, float duration, CCTweenType tweenType); + static float linear(float t, float b, float c, float d); - + static float sineEaseIn(float t, float b, float c, float d); static float sineEaseOut(float t, float b, float c, float d); static float sineEaseInOut(float t, float b, float c, float d); - + static float quadEaseIn(float t, float b, float c, float d); static float quadEaseOut(float t, float b, float c, float d); static float quadEaseInOut(float t, float b, float c, float d); - + static float cubicEaseIn(float t, float b, float c, float d); static float cubicEaseOut(float t, float b, float c, float d); static float cubicEaseInOut(float t, float b, float c, float d); - + static float quartEaseIn(float t, float b, float c, float d); static float quartEaseOut(float t, float b, float c, float d); static float quartEaseInOut(float t, float b, float c, float d); - + static float quintEaseIn(float t, float b, float c, float d); static float quintEaseOut(float t, float b, float c, float d); static float quintEaseInOut(float t, float b, float c, float d); - + static float expoEaseIn(float t, float b, float c, float d); static float expoEaseOut(float t, float b, float c, float d); static float expoEaseInOut(float t, float b, float c, float d); - + static float circEaseIn(float t, float b, float c, float d); static float circEaseOut(float t, float b, float c, float d); static float circEaseInOut(float t, float b, float c, float d); - + static float elasticEaseIn(float t, float b, float c, float d, float a = 0, float p = 0); static float elasticEaseOut(float t, float b, float c, float d, float a = 0, float p = 0); static float elasticEaseInOut(float t, float b, float c, float d, float a = 0, float p = 0); - + static float backEaseIn(float t, float b, float c, float d, float s = 0); static float backEaseOut(float t, float b, float c, float d, float s = 0); static float backEaseInOut(float t, float b, float c, float d, float s = 0); - + static float bounceEaseIn(float t, float b, float c, float d); static float bounceEaseOut(float t, float b, float c, float d); static float bounceEaseInOut(float t, float b, float c, float d); }; - -}}} // namespace cocos2d { namespace extension { namespace armature { + +NS_CC_EXT_ARMATURE_END #endif /*__CCTWEENFUNCTION_H__*/ diff --git a/extensions/CocoStudio/Armature/utils/CCUtilMath.cpp b/extensions/CocoStudio/Armature/utils/CCUtilMath.cpp index 61910dcca7..7197aa1fd4 100644 --- a/extensions/CocoStudio/Armature/utils/CCUtilMath.cpp +++ b/extensions/CocoStudio/Armature/utils/CCUtilMath.cpp @@ -25,22 +25,22 @@ THE SOFTWARE. #include "CCUtilMath.h" -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN -bool isSpriteContainPoint(Sprite *_sprite, Point _point, Point &_outPoint) +bool isSpriteContainPoint(Sprite *sprite, Point point, Point &outPoint) { - _outPoint = _sprite->convertToNodeSpace(_point); + outPoint = sprite->convertToNodeSpace(point); - Size _s = _sprite->getContentSize(); - Rect _r(0, 0, _s.width, _s.height); + Size s = sprite->getContentSize(); + Rect r(0, 0, s.width, s.height); - return _r.containsPoint(_outPoint); + return r.containsPoint(outPoint); } -bool isSpriteContainPoint(Sprite *_sprite, Point _point) +bool isSpriteContainPoint(Sprite *sprite, Point point) { - Point _p = Point(0, 0); - return isSpriteContainPoint(_sprite, _point, _p); + Point p = Point(0, 0); + return isSpriteContainPoint(sprite, point, p); } @@ -75,4 +75,4 @@ Point circleTo(float t, Point ¢er, float radius, float fromRadian, float rad return p; } -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCUtilMath.h b/extensions/CocoStudio/Armature/utils/CCUtilMath.h index c110db53f1..376e02b522 100644 --- a/extensions/CocoStudio/Armature/utils/CCUtilMath.h +++ b/extensions/CocoStudio/Armature/utils/CCUtilMath.h @@ -28,7 +28,7 @@ THE SOFTWARE. #include "CCArmatureDefine.h" #include -namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_BEGIN #define CC_DOUBLE_PI (M_PI*2) @@ -50,6 +50,6 @@ Point bezierTo(float t, Point &point1, Point &point2, Point &point3, Point &poin Point circleTo(float t, Point ¢er, float radius, float fromRadian, float radianDif); -}}} // namespace cocos2d { namespace extension { namespace armature { +NS_CC_EXT_ARMATURE_END #endif /*__CCUTILMATH_H__*/ diff --git a/extensions/CocoStudio/Reader/CCSSceneReader.cpp b/extensions/CocoStudio/Reader/CCSSceneReader.cpp index 00f6f2e932..323f9b0f1f 100644 --- a/extensions/CocoStudio/Reader/CCSSceneReader.cpp +++ b/extensions/CocoStudio/Reader/CCSSceneReader.cpp @@ -249,7 +249,7 @@ NS_CC_EXT_BEGIN } - cocos2d::extension::armature::Armature *pAr = cocos2d::extension::armature::Armature::create(name); + cocos2d::extension::armature::CCArmature *pAr = cocos2d::extension::armature::CCArmature::create(name); ComRender *pRender = ComRender::create(pAr, "CCArmature"); if (pComName != NULL) { diff --git a/extensions/cocos-ext.h b/extensions/cocos-ext.h index 9d5e3f0501..51d15653c1 100644 --- a/extensions/cocos-ext.h +++ b/extensions/cocos-ext.h @@ -59,9 +59,7 @@ #include "CocoStudio/Armature/display/CCDisplayManager.h" #include "CocoStudio/Armature/display/CCSkin.h" #include "CocoStudio/Armature/physics/CCColliderDetector.h" -#include "CocoStudio/Armature/physics/CCPhysicsWorld.h" #include "CocoStudio/Armature/utils/CCArmatureDataManager.h" -#include "CocoStudio/Armature/utils/CCConstValue.h" #include "CocoStudio/Armature/utils/CCDataReaderHelper.h" #include "CocoStudio/Armature/utils/CCTweenFunction.h" #include "CocoStudio/Armature/utils/CCArmatureDataManager.h" diff --git a/extensions/proj.win32/libExtensions.vcxproj b/extensions/proj.win32/libExtensions.vcxproj index 964cc89d22..69b33937f0 100644 --- a/extensions/proj.win32/libExtensions.vcxproj +++ b/extensions/proj.win32/libExtensions.vcxproj @@ -127,12 +127,10 @@ - - - + @@ -235,12 +233,9 @@ - - - diff --git a/extensions/proj.win32/libExtensions.vcxproj.filters b/extensions/proj.win32/libExtensions.vcxproj.filters index 9bcc34aceb..5fb460acef 100644 --- a/extensions/proj.win32/libExtensions.vcxproj.filters +++ b/extensions/proj.win32/libExtensions.vcxproj.filters @@ -316,18 +316,12 @@ CocoStudio\Armature\display - - CocoStudio\Armature\display - CocoStudio\Armature\display CocoStudio\Armature\physics - - CocoStudio\Armature\physics - CocoStudio\Armature\utils @@ -373,8 +367,8 @@ CocoStudio\Components - - CocoStudio\Armature\external_tool + + CocoStudio\Armature\utils @@ -653,9 +647,6 @@ CocoStudio\Armature\display - - CocoStudio\Armature\display - CocoStudio\Armature\display @@ -665,9 +656,6 @@ CocoStudio\Armature\physics - - CocoStudio\Armature\physics - CocoStudio\Armature\utils @@ -740,9 +728,6 @@ CocoStudio\Components - - CocoStudio\Armature\external_tool - diff --git a/samples/Cpp/TestCpp/Classes/AppDelegate.cpp b/samples/Cpp/TestCpp/Classes/AppDelegate.cpp index 5b226d028b..89b6ccd15a 100644 --- a/samples/Cpp/TestCpp/Classes/AppDelegate.cpp +++ b/samples/Cpp/TestCpp/Classes/AppDelegate.cpp @@ -15,7 +15,7 @@ AppDelegate::AppDelegate() AppDelegate::~AppDelegate() { // SimpleAudioEngine::end(); - cocos2d::extension::armature::ArmatureDataManager::purgeArmatureSystem(); + cocos2d::extension::armature::CCArmatureDataManager::purge(); } bool AppDelegate::applicationDidFinishLaunching() diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index d70d0a7e5d..7a27e63fef 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -1,119 +1,128 @@ #include "ArmatureScene.h" #include "../../testResource.h" + using namespace cocos2d; using namespace cocos2d::extension::armature; -Layer* NextTest(); -Layer* BackTest(); -Layer* RestartTest(); +Layer *NextTest(); +Layer *BackTest(); +Layer *RestartTest(); static int s_nActionIdx = -1; Layer *CreateLayer(int index) { - Layer *layer = NULL; - switch(index) - { - case TEST_DRAGON_BONES_2_0: - layer = new TestDragonBones20(); break; - case TEST_COCOSTUDIO_WITH_SKELETON: - layer = new TestCSWithSkeleton(); break; - case TEST_COCOSTUDIO_WITHOUT_SKELETON: - layer = new TestCSWithoutSkeleton(); break; - case TEST_PERFORMANCE: - layer = new TestPerformance(); break; - case TEST_CHANGE_ZORDER: - layer = new TestChangeZorder(); break; - case TEST_ANIMATION_EVENT: - layer = new TestAnimationEvent(); break; - case TEST_PARTICLE_DISPLAY: - layer = new TestParticleDisplay(); break; - case TEST_USE_DIFFERENT_PICTURE: - layer = new TestUseMutiplePicture(); break; - case TEST_BOX2D_DETECTOR: - layer = new TestBox2DDetector(); break; - case TEST_BOUDINGBOX: - layer = new TestBoundingBox(); break; - case TEST_ANCHORPOINT: - layer = new TestAnchorPoint(); break; - case TEST_ARMATURE_NESTING: - layer = new TestArmatureNesting(); break; - default: - break; - } + Layer *pLayer = NULL; + switch(index) + { + case TEST_ASYNCHRONOUS_LOADING: + pLayer = new TestAsynchronousLoading(); + break; + case TEST_DRAGON_BONES_2_0: + pLayer = new TestDragonBones20(); + break; + case TEST_COCOSTUDIO_WITH_SKELETON: + pLayer = new TestCSWithSkeleton(); + break; + case TEST_PERFORMANCE: + pLayer = new TestPerformance(); + break; + case TEST_CHANGE_ZORDER: + pLayer = new TestChangeZorder(); + break; + case TEST_ANIMATION_EVENT: + pLayer = new TestAnimationEvent(); + break; + case TEST_PARTICLE_DISPLAY: + pLayer = new TestParticleDisplay(); + break; + case TEST_USE_DIFFERENT_PICTURE: + pLayer = new TestUseMutiplePicture(); + break; + case TEST_BCOLLIDER_DETECTOR: + pLayer = new TestColliderDetector(); + break; + case TEST_BOUDINGBOX: + pLayer = new TestBoundingBox(); + break; + case TEST_ANCHORPOINT: + pLayer = new TestAnchorPoint(); + break; + case TEST_ARMATURE_NESTING: + pLayer = new TestArmatureNesting(); + break; + default: + break; + } - return layer; + return pLayer; } -Layer* NextTest() +Layer *NextTest() { - ++s_nActionIdx; - s_nActionIdx = s_nActionIdx % TEST_LAYER_COUNT; + ++s_nActionIdx; + s_nActionIdx = s_nActionIdx % TEST_LAYER_COUNT; - Layer* layer = CreateLayer(s_nActionIdx); - layer->autorelease(); + Layer *pLayer = CreateLayer(s_nActionIdx); + pLayer->autorelease(); - return layer; + return pLayer; } -Layer* BackTest() +Layer *BackTest() { - --s_nActionIdx; - if( s_nActionIdx < 0 ) - s_nActionIdx += TEST_LAYER_COUNT; + --s_nActionIdx; + if( s_nActionIdx < 0 ) + s_nActionIdx += TEST_LAYER_COUNT; - Layer* layer = CreateLayer(s_nActionIdx); - layer->autorelease(); + Layer *pLayer = CreateLayer(s_nActionIdx); + pLayer->autorelease(); - return layer; + return pLayer; } -Layer* RestartTest() +Layer *RestartTest() { - Layer* layer = CreateLayer(s_nActionIdx); - layer->autorelease(); + Layer *pLayer = CreateLayer(s_nActionIdx); + pLayer->autorelease(); - return layer; + return pLayer; } ArmatureTestScene::ArmatureTestScene(bool bPortrait) { - TestScene::init(); + TestScene::init(); - Sprite *bg = Sprite::create("armature/bg.jpg"); - bg->setPosition(VisibleRect::center()); + Sprite *bg = Sprite::create("armature/bg.jpg"); + bg->setPosition(VisibleRect::center()); - float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width; - float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height; + float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width; + float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height; - bg->setScaleX(scaleX); - bg->setScaleY(scaleY); + bg->setScaleX(scaleX); + bg->setScaleY(scaleY); - addChild(bg); + addChild(bg); } void ArmatureTestScene::runThisTest() { - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/TestBone0.png", "armature/TestBone0.plist", "armature/TestBone.json"); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy0.png", "armature/Cowboy0.plist", "armature/Cowboy.json"); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml"); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml"); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml"); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml"); - s_nActionIdx = -1; - addChild(NextTest()); - Director::getInstance()->replaceScene(this); + s_nActionIdx = -1; + addChild(NextTest()); + + Director::getInstance()->replaceScene(this); } -void ArmatureTestScene::MainMenuCallback(Object* sender) +void ArmatureTestScene::MainMenuCallback(Object *pSender) { - removeAllChildren(); - ArmatureDataManager::sharedArmatureDataManager()->purgeArmatureSystem(); + //TestScene::MainMenuCallback(pSender); + + removeAllChildren(); + CCArmatureDataManager::purge(); } @@ -121,187 +130,234 @@ void ArmatureTestScene::MainMenuCallback(Object* sender) void ArmatureTestLayer::onEnter() { - Layer::onEnter(); + Layer::onEnter(); - // add title and subtitle - std::string str = title(); - const char * pTitle = str.c_str(); - LabelTTF* label = LabelTTF::create(pTitle, "Arial", 18); - label->setColor(Color3B(0, 0, 0)); - addChild(label, 1, 10000); - label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) ); + // add title and subtitle + std::string str = title(); + const char *pTitle = str.c_str(); + LabelTTF *label = LabelTTF::create(pTitle, "Arial", 18); + label->setColor(Color3B(0, 0, 0)); + addChild(label, 1, 10000); + label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) ); - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - auto l = LabelTTF::create(strSubtitle.c_str(), "Arial", 18); - l->setColor(Color3B(0, 0, 0)); - addChild(l, 1, 10001); - l->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 60) ); - } + std::string strSubtitle = subtitle(); + if( ! strSubtitle.empty() ) + { + LabelTTF *l = LabelTTF::create(strSubtitle.c_str(), "Arial", 18); + l->setColor(Color3B(0, 0, 0)); + addChild(l, 1, 10001); + l->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 60) ); + } - // add menu - MenuItemImage *item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(ArmatureTestLayer::backCallback,this)); - MenuItemImage *item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(ArmatureTestLayer::restartCallback, this)); - MenuItemImage *item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(ArmatureTestLayer::nextCallback, this)); + // add menu + backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(ArmatureTestLayer::backCallback, this) ); + 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(item1, item2, item3, NULL); + Menu *menu = Menu::create(backItem, restartItem, nextItem, NULL); - menu->setPosition(Point::ZERO); - item1->setPosition(Point(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(Point(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); + menu->setPosition(Point::ZERO); + backItem->setPosition(Point(VisibleRect::center().x - restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2)); + restartItem->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2)); + nextItem->setPosition(Point(VisibleRect::center().x + restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2)); - addChild(menu, 100); + addChild(menu, 100); - setShaderProgram(ShaderCache::getInstance()->programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setShaderProgram(ShaderCache::getInstance()->programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); } void ArmatureTestLayer::onExit() { + removeAllChildren(); + + backItem = restartItem = nextItem = NULL; } std::string ArmatureTestLayer::title() { - return "CSArmature Test Bed"; + return "CCArmature Test Bed"; } std::string ArmatureTestLayer::subtitle() { - return ""; + return ""; } -void ArmatureTestLayer::restartCallback(Object* sender) +void ArmatureTestLayer::restartCallback(Object *pSender) { - Scene* s = new ArmatureTestScene(); - s->addChild( RestartTest() ); - Director::getInstance()->replaceScene(s); - s->release(); + Scene *s = new ArmatureTestScene(); + s->addChild( RestartTest() ); + Director::getInstance()->replaceScene(s); + s->release(); } -void ArmatureTestLayer::nextCallback(Object* sender) +void ArmatureTestLayer::nextCallback(Object *pSender) { - Scene* s = new ArmatureTestScene(); - s->addChild( NextTest() ); - Director::getInstance()->replaceScene(s); - s->release(); + Scene *s = new ArmatureTestScene(); + s->addChild( NextTest() ); + Director::getInstance()->replaceScene(s); + s->release(); } -void ArmatureTestLayer::backCallback(Object* sender) +void ArmatureTestLayer::backCallback(Object *pSender) { - Scene* s = new ArmatureTestScene(); - s->addChild( BackTest() ); - Director::getInstance()->replaceScene(s); - s->release(); + Scene *s = new ArmatureTestScene(); + s->addChild( BackTest() ); + Director::getInstance()->replaceScene(s); + s->release(); } void ArmatureTestLayer::draw() { - Layer::draw(); + Layer::draw(); } +void TestAsynchronousLoading::onEnter() +{ + ArmatureTestLayer::onEnter(); + + CCLOG("armature version : %s", armatureVersion()); + + backItem->setEnabled(false); + restartItem->setEnabled(false); + nextItem->setEnabled(false); + + char pszPercent[255]; + sprintf(pszPercent, "%s %f", subtitle().c_str(), 0.0f); + LabelTTF *label = (LabelTTF *)getChildByTag(10001); + label->setString(pszPercent); + + + //! create a new thread to load data + CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/robot.png", "armature/robot.plist", "armature/robot.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/Cowboy.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + + //! load data directly + // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); + // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml"); + // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml"); + // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml"); + // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml"); + // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy.ExportJson"); + +} + +std::string TestAsynchronousLoading::title() +{ + return "Test Asynchronous Loading"; +} +std::string TestAsynchronousLoading::subtitle() +{ + return "current percent : "; +} +void TestAsynchronousLoading::dataLoaded(float percent) +{ + LabelTTF *label = (LabelTTF *)getChildByTag(10001); + if (label) + { + char pszPercent[255]; + sprintf(pszPercent, "%s %f", subtitle().c_str(), percent * 100); + label->setString(pszPercent); + } + + if (percent >= 1 && backItem && restartItem && nextItem) + { + backItem->setEnabled(true); + restartItem->setEnabled(true); + nextItem->setEnabled(true); + } +} + + + +void TestCSWithSkeleton::onEnter() +{ + ArmatureTestLayer::onEnter(); + CCArmature *armature = NULL; + armature = CCArmature::create("Cowboy"); + armature->getAnimation()->playByIndex(0); + armature->setScale(0.2f); + + armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y/*-100*/)); + addChild(armature); +} + +std::string TestCSWithSkeleton::title() +{ + return "Test Export From CocoStudio With Skeleton Effect"; +} + + + void TestDragonBones20::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureTestLayer::onEnter(); - Armature *armature = NULL; - armature = Armature::create("Dragon"); - armature->getAnimation()->playByIndex(1); - armature->getAnimation()->setAnimationScale(0.4f); - armature->setPosition(VisibleRect::center().x, VisibleRect::center().y * 0.3f); - armature->setScale(0.6f); + CCArmature *armature = NULL; + armature = CCArmature::create("Dragon"); + armature->getAnimation()->playByIndex(1); + armature->getAnimation()->setSpeedScale(0.4f); + armature->setPosition(VisibleRect::center().x, VisibleRect::center().y * 0.3f); + armature->setScale(0.6f); addChild(armature); } std::string TestDragonBones20::title() { - return "Test Export From DragonBones version 2.0"; + return "Test Export From DragonBones version 2.0"; } -void TestCSWithSkeleton::onEnter() -{ - ArmatureTestLayer::onEnter(); - Armature *armature = NULL; - armature = Armature::create("Cowboy"); - armature->getAnimation()->playByIndex(0); - armature->setScale(0.2f); - armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y/*-100*/)); - addChild(armature); -} - -std::string TestCSWithSkeleton::title() -{ - return "Test Export From CocoStudio With Skeleton Effect"; -} - - - -void TestCSWithoutSkeleton::onEnter() -{ - ArmatureTestLayer::onEnter(); - Armature *armature = NULL; - armature = Armature::create("TestBone"); - armature->getAnimation()->playByIndex(0); - armature->setAnchorPoint(Point(0.5f, -0.1f)); - armature->setScale(0.2f); - armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y-100)); - addChild(armature); -} - -std::string TestCSWithoutSkeleton::title() -{ - return "Test Export From CocoStudio Without Skeleton Effect"; -} - - - TestPerformance::~TestPerformance() { } void TestPerformance::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureTestLayer::onEnter(); - armatureCount = frames = times = lastTimes = 0; - generated = false; + armatureCount = frames = times = lastTimes = 0; + generated = false; - scheduleUpdate(); + scheduleUpdate(); } std::string TestPerformance::title() { - return "Test Performance"; + return "Test Performance"; } std::string TestPerformance::subtitle() { - return "Current Armature Count : "; + return "Current CCArmature Count : "; } -void TestPerformance::addArmature(Armature *armature) +void TestPerformance::addArmature(CCArmature *armature) { - armatureCount++; - addChild(armature, armatureCount); + armatureCount++; + addChild(armature, armatureCount); } void TestPerformance::update(float delta) { - frames ++; - times += delta; + frames ++; + times += delta; - if (frames/times > 58) - { - Armature *armature = NULL; - armature = new Armature(); - armature->init("Knight_f/Knight"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(50 + armatureCount * 2, 150); - armature->setScale(0.6f); - addArmature(armature); - armature->release(); + if (frames / times > 58) + { + CCArmature *armature = NULL; + armature = new CCArmature(); + armature->init("Knight_f/Knight"); + armature->getAnimation()->playByIndex(0); + armature->setPosition(50 + armatureCount * 2, 150); + armature->setScale(0.6f); + addArmature(armature); + armature->release(); - char pszCount[255]; - sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount); - auto label = (LabelTTF*)getChildByTag(10001); - label->setString(pszCount); - } + char pszCount[255]; + sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount); + LabelTTF *label = (LabelTTF *)getChildByTag(10001); + label->setString(pszCount); + } } @@ -311,49 +367,49 @@ void TestPerformance::update(float delta) void TestChangeZorder::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureTestLayer::onEnter(); - Armature *armature = NULL; - currentTag = -1; + CCArmature *armature = NULL; + currentTag = -1; - armature = Armature::create("Knight_f/Knight"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y-100)); - ++currentTag; - armature->setScale(0.6f); - addChild(armature, currentTag, currentTag); + armature = CCArmature::create("Knight_f/Knight"); + armature->getAnimation()->playByIndex(0); + armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y - 100)); + ++currentTag; + armature->setScale(0.6f); + addChild(armature, currentTag, currentTag); - armature = Armature::create("TestBone"); - armature->getAnimation()->playByIndex(0); - armature->setScale(0.24f); - armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y-100)); - ++currentTag; - addChild(armature, currentTag, currentTag); + armature = CCArmature::create("Cowboy"); + armature->getAnimation()->playByIndex(0); + armature->setScale(0.24f); + armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y - 100)); + ++currentTag; + addChild(armature, currentTag, currentTag); - armature = Armature::create("Dragon"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(Point(VisibleRect::center().x , VisibleRect::center().y-100)); - ++currentTag; - armature->setScale(0.6f); - addChild(armature, currentTag, currentTag); + armature = CCArmature::create("Dragon"); + armature->getAnimation()->playByIndex(0); + armature->setPosition(Point(VisibleRect::center().x , VisibleRect::center().y - 100)); + ++currentTag; + armature->setScale(0.6f); + addChild(armature, currentTag, currentTag); - schedule( schedule_selector(TestChangeZorder::changeZorder), 1); + schedule( schedule_selector(TestChangeZorder::changeZorder), 1); - currentTag = 0; + currentTag = 0; } std::string TestChangeZorder::title() { - return "Test Change ZOrder Of Different Armature"; + return "Test Change ZOrder Of Different CCArmature"; } void TestChangeZorder::changeZorder(float dt) { - - Node *node = getChildByTag(currentTag); - node->setZOrder(CCRANDOM_0_1() * 3); + Node *node = getChildByTag(currentTag); - currentTag ++; - currentTag = currentTag % 3; + node->setZOrder(CCRANDOM_0_1() * 3); + + currentTag ++; + currentTag = currentTag % 3; } @@ -361,50 +417,55 @@ void TestChangeZorder::changeZorder(float dt) void TestAnimationEvent::onEnter() { - ArmatureTestLayer::onEnter(); - armature = Armature::create("Cowboy"); - armature->getAnimation()->play("Fire"); - armature->setScaleX(-0.24f); - armature->setScaleY(0.24f); - armature->setPosition(Point(VisibleRect::left().x + 50, VisibleRect::left().y)); - armature->getAnimation()->MovementEventSignal.connect(this, &TestAnimationEvent::animationEvent); - addChild(armature); + ArmatureTestLayer::onEnter(); + armature = CCArmature::create("Cowboy"); + armature->getAnimation()->play("Fire"); + armature->setScaleX(-0.24f); + armature->setScaleY(0.24f); + armature->setPosition(Point(VisibleRect::left().x + 50, VisibleRect::left().y)); + + /* + * Set armature's movement event callback function + * To disconnect this event, just setMovementEventCallFunc(NULL, NULL); + */ + armature->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(TestAnimationEvent::animationEvent)); + addChild(armature); } std::string TestAnimationEvent::title() { - return "Test Armature Animation Event"; + return "Test CCArmature Animation Event"; } -void TestAnimationEvent::animationEvent(Armature *armature, MovementEventType movementType, const char *movementID) +void TestAnimationEvent::animationEvent(CCArmature *armature, MovementEventType movementType, const char *movementID) { - std::string id = movementID; + std::string id = movementID; - if (movementType == LOOP_COMPLETE) - { - if (id.compare("Fire") == 0) - { - auto 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->getAnimation()->play("Walk"); - } - else if (id.compare("FireMax") == 0) - { - auto 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->getAnimation()->play("Walk"); - } - } + if (movementType == LOOP_COMPLETE) + { + if (id.compare("Fire") == 0) + { + 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->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->getAnimation()->play("Walk"); + } + } } void TestAnimationEvent::callback1() { - armature->runAction(ScaleTo::create(0.3f, 0.3f, 0.3f)); - armature->getAnimation()->play("FireMax", 10); + armature->runAction(ScaleTo::create(0.3f, 0.24f, 0.24f)); + armature->getAnimation()->play("FireMax", 10); } void TestAnimationEvent::callback2() { - armature->runAction(ScaleTo::create(0.3f, -0.3f, 0.3f)); - armature->getAnimation()->play("Fire", 10); + armature->runAction(ScaleTo::create(0.3f, -0.24f, 0.24f)); + armature->getAnimation()->play("Fire", 10); } @@ -412,55 +473,62 @@ void TestAnimationEvent::callback2() void TestParticleDisplay::onEnter() { - ArmatureTestLayer::onEnter(); - setTouchEnabled(true); + ArmatureTestLayer::onEnter(); + setTouchEnabled(true); - animationID = 0; + animationID = 0; - armature = Armature::create("robot"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(VisibleRect::center()); - armature->setScale(0.48f); - addChild(armature); + armature = CCArmature::create("robot"); + armature->getAnimation()->playByIndex(0); + armature->setPosition(VisibleRect::center()); + armature->setScale(0.48f); + armature->getAnimation()->setSpeedScale(0.5f); + addChild(armature); - ParticleDisplayData displayData; - displayData.setParam("Particles/SmallSun.plist"); - Bone *bone = Bone::create("p1"); - bone->addDisplay(&displayData, 0); - bone->changeDisplayByIndex(0, true); - bone->setIgnoreMovementBoneData(true); - bone->setZOrder(100); - bone->setScale(1.2f); - armature->addBone(bone, "bady-a3"); - - bone = Bone::create("p2"); - bone->addDisplay(&displayData, 0); - bone->changeDisplayByIndex(0, true); - bone->setIgnoreMovementBoneData(true); - bone->setZOrder(100); - bone->setScale(1.2f); - armature->addBone(bone, "bady-a30"); + ParticleSystem *p1 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); + ParticleSystem *p2 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); + + CCBone *bone = CCBone::create("p1"); + bone->addDisplay(p1, 0); + bone->changeDisplayByIndex(0, true); + bone->setIgnoreMovementBoneData(true); + bone->setZOrder(100); + bone->setScale(1.2f); + armature->addBone(bone, "bady-a3"); + + bone = CCBone::create("p2"); + bone->addDisplay(p2, 0); + bone->changeDisplayByIndex(0, true); + bone->setIgnoreMovementBoneData(true); + bone->setZOrder(100); + bone->setScale(1.2f); + armature->addBone(bone, "bady-a30"); +} +void TestParticleDisplay::onExit() +{ + Director::getInstance()->getTouchDispatcher()->removeDelegate(this); + ArmatureTestLayer::onExit(); } std::string TestParticleDisplay::title() { - return "Test Particle Display"; + return "Test Particle Display"; } std::string TestParticleDisplay::subtitle() { - return "Touch to change animation"; + return "Touch to change animation"; } -bool TestParticleDisplay::ccTouchBegan(Touch *touch, Event *event) +bool TestParticleDisplay::ccTouchBegan(Touch *pTouch, Event *pEvent) { - ++animationID; - animationID = animationID % armature->getAnimation()->getMovementCount(); - armature->getAnimation()->playByIndex(animationID); - return false; + ++animationID; + animationID = animationID % armature->getAnimation()->getMovementCount(); + armature->getAnimation()->playByIndex(animationID); + return false; } void TestParticleDisplay::registerWithTouchDispatcher() { - Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true); + Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN + 1, true); } @@ -468,179 +536,447 @@ void TestParticleDisplay::registerWithTouchDispatcher() void TestUseMutiplePicture::onEnter() { - ArmatureTestLayer::onEnter(); - setTouchEnabled(true); + ArmatureTestLayer::onEnter(); + setTouchEnabled(true); - displayIndex = 0; + displayIndex = 0; - armature = Armature::create("Knight_f/Knight"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(Point(VisibleRect::left().x+70, VisibleRect::left().y)); - armature->setScale(1.2f); - addChild(armature); + armature = CCArmature::create("Knight_f/Knight"); + armature->getAnimation()->playByIndex(0); + armature->setPosition(Point(VisibleRect::center().x, VisibleRect::left().y)); + armature->setScale(1.2f); + addChild(armature); - std::string weapon[] = {"weapon_f-sword.png", "weapon_f-sword2.png", "weapon_f-sword3.png", "weapon_f-sword4.png", "weapon_f-sword5.png", "weapon_f-knife.png", "weapon_f-hammer.png"}; + std::string weapon[] = {"weapon_f-sword.png", "weapon_f-sword2.png", "weapon_f-sword3.png", "weapon_f-sword4.png", "weapon_f-sword5.png", "weapon_f-knife.png", "weapon_f-hammer.png"}; - SpriteDisplayData displayData; - for (int i = 0; i < 7; i++) - { - displayData.setParam(weapon[i].c_str()); - armature->getBone("weapon")->addDisplay(&displayData, i); - } + for (int i = 0; i < 7; i++) + { + CCSkin *skin = CCSkin::createWithSpriteFrameName(weapon[i].c_str()); + armature->getBone("weapon")->addDisplay(skin, i); + } + + // CCSpriteDisplayData displayData; + // for (int i = 0; i < 7; i++) + // { + // displayData.setParam(weapon[i].c_str()); + // armature->getBone("weapon")->addDisplay(&displayData, i); + // } + + LabelTTF *l = LabelTTF::create("This is a weapon!", "Arial", 18); + l->setAnchorPoint(Point(0.2f, 0.5f)); + armature->getBone("weapon")->addDisplay(l, 7); +} +void TestUseMutiplePicture::onExit() +{ + Director::getInstance()->getTouchDispatcher()->removeDelegate(this); + ArmatureTestLayer::onExit(); } std::string TestUseMutiplePicture::title() { - return "Test One Armature Use Different Picture"; + return "Test One CCArmature Use Different Picture"; } std::string TestUseMutiplePicture::subtitle() { - return "weapon and armature are in different picture"; + return "weapon and armature are in different picture"; } -bool TestUseMutiplePicture::ccTouchBegan(Touch *touch, Event *event) +bool TestUseMutiplePicture::ccTouchBegan(Touch *pTouch, Event *pEvent) { - ++displayIndex; - displayIndex = (displayIndex) % 6; - armature->getBone("weapon")->changeDisplayByIndex(displayIndex, true); - return false; + ++displayIndex; + displayIndex = (displayIndex) % 8; + armature->getBone("weapon")->changeDisplayByIndex(displayIndex, true); + return false; } void TestUseMutiplePicture::registerWithTouchDispatcher() { - Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true); + Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN + 1, true); } -void TestBox2DDetector::onEnter() + + +TestColliderDetector::~TestColliderDetector() { - ArmatureTestLayer::onEnter(); - - scheduleUpdate(); - - armature = Armature::create("Cowboy"); - armature->getAnimation()->play("Fire"); - armature->getAnimation()->setAnimationScale(0.1f); - armature->setScaleX(-0.2f); - armature->setScaleY(0.2f); - armature->setPosition(Point(VisibleRect::left().x + 70, VisibleRect::left().y)); - addChild(armature); - - armature2 = Armature::create("Cowboy"); - armature2->getAnimation()->play("Walk"); - armature2->setScaleX(-0.2f); - armature2->setScaleY(0.2f); - armature2->setPosition(Point(VisibleRect::right().x - 30, VisibleRect::left().y)); - addChild(armature2); - - PhysicsWorld::sharedPhysicsWorld()->BoneColliderSignal.connect(this, &TestBox2DDetector::onHit); } -std::string TestBox2DDetector::title() +void TestColliderDetector::onEnter() { - return "Test Box2D Detector"; -} -void TestBox2DDetector::draw() -{ - GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); + ArmatureTestLayer::onEnter(); - kmGLPushMatrix(); + scheduleUpdate(); - PhysicsWorld::sharedPhysicsWorld()->drawDebug(); + armature = CCArmature::create("Cowboy"); + armature->getAnimation()->play("FireWithoutBullet"); + armature->getAnimation()->setSpeedScale(0.2f); + armature->setScaleX(-0.2f); + armature->setScaleY(0.2f); + armature->setPosition(Point(VisibleRect::left().x + 70, VisibleRect::left().y)); - kmGLPopMatrix(); - + /* + * Set armature's frame event callback function + * To disconnect this event, just setFrameEventCallFunc(NULL, NULL); + */ + armature->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(TestColliderDetector::onFrameEvent)); + + addChild(armature); + + armature2 = CCArmature::create("Cowboy"); + armature2->getAnimation()->play("Walk"); + armature2->setScaleX(-0.2f); + armature2->setScaleY(0.2f); + armature2->setPosition(Point(VisibleRect::right().x - 60, VisibleRect::left().y)); + addChild(armature2); + + bullet = cocos2d::extension::PhysicsSprite::createWithSpriteFrameName("25.png"); + addChild(bullet); + + initWorld(); } -void TestBox2DDetector::update(float delta) +std::string TestColliderDetector::title() { - armature2->setVisible(true); - PhysicsWorld::sharedPhysicsWorld()->update(delta); + return "Test Collider Detector"; } -void TestBox2DDetector::onHit(Bone *bone, Bone *bone2) +void TestColliderDetector::onFrameEvent(CCBone *bone, const char *evt, int originFrameIndex, int currentFrameIndex) { - armature2->setVisible(false); + CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt, currentFrameIndex); + + /* + * originFrameIndex is the frame index editted in Action Editor + * currentFrameIndex is the current index animation played to + * frame event may be delay emit, so originFrameIndex may be different from currentFrameIndex. + */ + + Point p = armature->getBone("Layer126")->getDisplayRenderNode()->convertToWorldSpaceAR(Point(0, 0)); + bullet->setPosition(Point(p.x + 60, p.y)); + + bullet->stopAllActions(); + bullet->runAction(CCMoveBy::create(1.5f, Point(350, 0))); } +#if ENABLE_PHYSICS_BOX2D_DETECT + +class Contact +{ +public: + b2Fixture *fixtureA; + b2Fixture *fixtureB; +}; + +class ContactListener : public b2ContactListener +{ + //! Callbacks for derived classes. + virtual void BeginContact(b2Contact *contact) + { + if (contact) + { + Contact c; + c.fixtureA = contact->GetFixtureA(); + c.fixtureB = contact->GetFixtureB(); + + contact_list.push_back(c); + } + B2_NOT_USED(contact); + } + virtual void EndContact(b2Contact *contact) + { + contact_list.clear(); + B2_NOT_USED(contact); + } + virtual void PreSolve(b2Contact *contact, const b2Manifold *oldManifold) + { + B2_NOT_USED(contact); + B2_NOT_USED(oldManifold); + } + virtual void PostSolve(const b2Contact *contact, const b2ContactImpulse *impulse) + { + B2_NOT_USED(contact); + B2_NOT_USED(impulse); + } + +public: + std::list contact_list; +}; + + +void TestColliderDetector::onExit() +{ + CC_SAFE_DELETE(world); + CC_SAFE_DELETE(listener); + CC_SAFE_DELETE(debugDraw); + + ArmatureTestLayer::onExit(); +} +void TestColliderDetector::draw() +{ + ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position ); + kmGLPushMatrix(); + world->DrawDebugData(); + kmGLPopMatrix(); +} +void TestColliderDetector::update(float delta) +{ + armature2->setVisible(true); + + world->Step(delta, 0, 0); + + for (std::list::iterator it = listener->contact_list.begin(); it != listener->contact_list.end(); ++it) + { + Contact &contact = *it; + + CCBone *ba = (CCBone *)contact.fixtureA->GetUserData(); + CCBone *bb = (CCBone *)contact.fixtureB->GetUserData(); + + bb->getArmature()->setVisible(false); + } +} +void TestColliderDetector::initWorld() +{ + b2Vec2 noGravity(0, 0); + + world = new b2World(noGravity); + world->SetAllowSleeping(true); + + listener = new ContactListener(); + world->SetContactListener(listener); + + debugDraw = new GLESDebugDraw( PT_RATIO ); + world->SetDebugDraw(debugDraw); + + uint32 flags = 0; + flags += b2Draw::e_shapeBit; + // flags += b2Draw::e_jointBit; + // flags += b2Draw::e_aabbBit; + // flags += b2Draw::e_pairBit; + // flags += b2Draw::e_centerOfMassBit; + debugDraw->SetFlags(flags); + + + // Define the dynamic body. + //Set up a 1m squared box in the physics world + b2BodyDef bodyDef; + bodyDef.type = b2_dynamicBody; + + b2Body *body = world->CreateBody(&bodyDef); + + // Define another box shape for our dynamic body. + b2PolygonShape dynamicBox; + dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box + + // Define the dynamic body fixture. + b2FixtureDef fixtureDef; + fixtureDef.shape = &dynamicBox; + fixtureDef.isSensor = true; + body->CreateFixture(&fixtureDef); + + + bullet->setB2Body(body); + bullet->setPTMRatio(PT_RATIO); + bullet->setPosition( Point( -100, -100) ); + + body = world->CreateBody(&bodyDef); + armature2->setBody(body); +} + +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + +enum ColliderType +{ + eBulletTag, + eEnemyTag +}; + + +int TestColliderDetector::beginHit(cpArbiter *arb, cpSpace *space, void *unused) +{ + CP_ARBITER_GET_SHAPES(arb, a, b); + + CCBone *bone = (CCBone *)a->data; + bone->getArmature()->setVisible(false); + + return 0; +} + +void TestColliderDetector::endHit(cpArbiter *arb, cpSpace *space, void *unused) +{ + CP_ARBITER_GET_SHAPES(arb, a, b); + + CCBone *bone = (CCBone *)a->data; + bone->getArmature()->setVisible(true); +} + +void TestColliderDetector::destroyCPBody(cpBody *body) +{ + cpShape *shape = body->shapeList_private; + while(shape) + { + cpShape *temp = shape->next_private; + + cpSpaceRemoveShape(space, shape); + cpShapeFree(shape); + + shape = temp; + } + + cpSpaceRemoveBody(space, body); + cpBodyFree(body); +} + +void TestColliderDetector::onExit() +{ + destroyCPBody(armature2->getBody()); + destroyCPBody(bullet->getCPBody()); + + cpSpaceFree(space); + + ArmatureTestLayer::onExit(); +} + +void TestColliderDetector::update(float delta) +{ + cpSpaceStep(space, delta); +} +void TestColliderDetector::initWorld() +{ + space = cpSpaceNew(); + space->gravity = cpv(0, 0); + + // Physics debug layer + cocos2d::extension::PhysicsDebugNode *debugLayer = cocos2d::extension::PhysicsDebugNode::create(space); + this->addChild(debugLayer, INT_MAX); + + Size size = bullet->getContentSize(); + + int num = 4; + cpVect verts[] = + { + cpv(-size.width / 2, -size.height / 2), + cpv(-size.width / 2, size.height / 2), + cpv(size.width / 2, size.height / 2), + cpv(size.width / 2, -size.height / 2), + }; + + cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero)); + cpSpaceAddBody(space, body); + + cpShape *shape = cpPolyShapeNew(body, num, verts, cpvzero); + shape->collision_type = eBulletTag; + cpSpaceAddShape(space, shape); + + bullet->setCPBody(body); + + body = cpBodyNew(INFINITY, INFINITY); + cpSpaceAddBody(space, body); + armature2->setBody(body); + + shape = armature2->getShapeList(); + while(shape) + { + cpShape *next = shape->next_private; + shape->collision_type = eEnemyTag; + shape = next; + } + + cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, NULL, NULL, endHit, NULL); +} +#endif + + + + void TestBoundingBox::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureTestLayer::onEnter(); - armature = Armature::create("Cowboy"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(VisibleRect::center()); - armature->setScale(0.2f); - addChild(armature); + armature = CCArmature::create("Cowboy"); + armature->getAnimation()->playByIndex(0); + armature->setPosition(VisibleRect::center()); + armature->setScale(0.2f); + addChild(armature); + + Sprite *sprite = Sprite::create("Images/background3.png"); + armature->addChild(sprite); } std::string TestBoundingBox::title() { - return "Test BoundingBox"; + return "Test BoundingBox"; } void TestBoundingBox::draw() { - CC_NODE_DRAW_SETUP(); + CC_NODE_DRAW_SETUP(); - rect = RectApplyAffineTransform(armature->getBoundingBox(), armature->getNodeToParentTransform()); - - DrawPrimitives::setDrawColor4B(100, 100, 100, 255); - DrawPrimitives::drawRect(rect.origin, Point(rect.getMaxX(), rect.getMaxY())); + rect = RectApplyAffineTransform(armature->getBoundingBox(), armature->getNodeToParentTransform()); + + DrawPrimitives::setDrawColor4B(100, 100, 100, 255); + DrawPrimitives::drawRect(rect.origin, Point(rect.getMaxX(), rect.getMaxY())); } void TestAnchorPoint::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureTestLayer::onEnter(); - for (int i = 0; i<5; i++) - { - Armature *armature = Armature::create("Cowboy"); - armature->getAnimation()->playByIndex(0); - armature->setPosition(VisibleRect::center()); - armature->setScale(0.2f); - addChild(armature, 0, i); - } + for (int i = 0; i < 5; i++) + { + CCArmature *armature = CCArmature::create("Cowboy"); + armature->getAnimation()->playByIndex(0); + armature->setPosition(VisibleRect::center()); + armature->setScale(0.2f); + addChild(armature, 0, i); + } - getChildByTag(0)->setAnchorPoint(Point(0,0)); - getChildByTag(1)->setAnchorPoint(Point(0,1)); - getChildByTag(2)->setAnchorPoint(Point(1,0)); - getChildByTag(3)->setAnchorPoint(Point(1,1)); - getChildByTag(4)->setAnchorPoint(Point(0.5,0.5)); + getChildByTag(0)->setAnchorPoint(Point(0, 0)); + getChildByTag(1)->setAnchorPoint(Point(0, 1)); + getChildByTag(2)->setAnchorPoint(Point(1, 0)); + getChildByTag(3)->setAnchorPoint(Point(1, 1)); + getChildByTag(4)->setAnchorPoint(Point(0.5, 0.5)); } std::string TestAnchorPoint::title() { - return "Test Set AnchorPoint"; + return "Test Set AnchorPoint"; } void TestArmatureNesting::onEnter() { - ArmatureTestLayer::onEnter(); - setTouchEnabled(true); + ArmatureTestLayer::onEnter(); + setTouchEnabled(true); - armature = Armature::create("cyborg"); - armature->getAnimation()->playByIndex(1); - armature->setPosition(VisibleRect::center()); - armature->setScale(1.2f); - armature->getAnimation()->setAnimationScale(0.4f); - addChild(armature); + armature = CCArmature::create("cyborg"); + armature->getAnimation()->playByIndex(1); + armature->setPosition(VisibleRect::center()); + armature->setScale(1.2f); + armature->getAnimation()->setSpeedScale(0.4f); + addChild(armature); - weaponIndex = 0; + weaponIndex = 0; +} +void TestArmatureNesting::onExit() +{ + Director::getInstance()->getTouchDispatcher()->removeDelegate(this); + ArmatureTestLayer::onExit(); } std::string TestArmatureNesting::title() { - return "Test Armature Nesting"; + return "Test CCArmature Nesting"; } -bool TestArmatureNesting::ccTouchBegan(Touch *touch, Event *event) +bool TestArmatureNesting::ccTouchBegan(Touch *pTouch, Event *pEvent) { - ++weaponIndex; - weaponIndex = weaponIndex % 4; + ++weaponIndex; + weaponIndex = weaponIndex % 4; - armature->getBone("armInside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); - armature->getBone("armOutside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); - return false; + if(armature != NULL) + { + armature->getBone("armInside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); + armature->getBone("armOutside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); + } + + return false; } void TestArmatureNesting::registerWithTouchDispatcher() { - Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true); + Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN + 1, true); } \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index 2022432ac3..f743f82a22 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -6,6 +6,13 @@ #include "../../VisibleRect.h" #include "../../testBasic.h" +#if ENABLE_PHYSICS_BOX2D_DETECT +#include "../../Box2DTestBed/GLES-Render.h" +#include "Box2D/Box2D.h" +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT +#include "chipmunk.h" +#endif + class ArmatureTestScene : public TestScene { public: @@ -14,19 +21,19 @@ public: virtual void runThisTest(); // The CallBack for back to the main menu scene - virtual void MainMenuCallback(Object* sender); + virtual void MainMenuCallback(Object* pSender); }; enum { - TEST_COCOSTUDIO_WITH_SKELETON = 0, - TEST_COCOSTUDIO_WITHOUT_SKELETON, + TEST_ASYNCHRONOUS_LOADING = 0, + TEST_COCOSTUDIO_WITH_SKELETON, TEST_DRAGON_BONES_2_0, TEST_PERFORMANCE, TEST_CHANGE_ZORDER, TEST_ANIMATION_EVENT, TEST_PARTICLE_DISPLAY, TEST_USE_DIFFERENT_PICTURE, - TEST_BOX2D_DETECTOR, + TEST_BCOLLIDER_DETECTOR, TEST_BOUDINGBOX, TEST_ANCHORPOINT, TEST_ARMATURE_NESTING, @@ -43,32 +50,39 @@ public: virtual std::string title(); virtual std::string subtitle(); - void restartCallback(Object* sender); - void nextCallback(Object* sender); - void backCallback(Object* sender); + virtual void restartCallback(Object* pSender); + virtual void nextCallback(Object* pSender); + virtual void backCallback(Object* pSender); virtual void draw(); + +protected: + MenuItemImage *restartItem; + MenuItemImage *nextItem; + MenuItemImage *backItem; }; - -class TestDragonBones20 : public ArmatureTestLayer +class TestAsynchronousLoading : public ArmatureTestLayer { public: virtual void onEnter(); virtual std::string title(); + virtual std::string subtitle(); + + void dataLoaded(float percent); }; - - class TestCSWithSkeleton : public ArmatureTestLayer { virtual void onEnter(); virtual std::string title(); }; -class TestCSWithoutSkeleton : public ArmatureTestLayer + +class TestDragonBones20 : public ArmatureTestLayer { +public: virtual void onEnter(); virtual std::string title(); }; @@ -82,7 +96,7 @@ public: virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); - virtual void addArmature(cocos2d::extension::armature::Armature *armature); + virtual void addArmature(cocos2d::extension::armature::CCArmature *armature); void update(float delta); int armatureCount; @@ -104,57 +118,116 @@ class TestChangeZorder : public ArmatureTestLayer }; -class TestAnimationEvent : public ArmatureTestLayer, public sigslot::has_slots<> +class TestAnimationEvent : public ArmatureTestLayer { public: virtual void onEnter(); virtual std::string title(); - void animationEvent(cocos2d::extension::armature::Armature *armature, cocos2d::extension::armature::MovementEventType movementType, const char *movementID); + void animationEvent(cocos2d::extension::armature::CCArmature *armature, cocos2d::extension::armature::MovementEventType movementType, const char *movementID); void callback1(); void callback2(); - cocos2d::extension::armature::Armature *armature; + cocos2d::extension::armature::CCArmature *armature; }; class TestUseMutiplePicture : public ArmatureTestLayer { virtual void onEnter(); + virtual void onExit(); virtual std::string title(); virtual std::string subtitle(); - virtual bool ccTouchBegan(Touch *touch, Event *event); + virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent); virtual void registerWithTouchDispatcher(); int displayIndex; - cocos2d::extension::armature::Armature *armature; + cocos2d::extension::armature::CCArmature *armature; }; class TestParticleDisplay : public ArmatureTestLayer { virtual void onEnter(); + virtual void onExit(); virtual std::string title(); virtual std::string subtitle(); - virtual bool ccTouchBegan(Touch *touch, Event *event); + virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent); virtual void registerWithTouchDispatcher(); int animationID; - cocos2d::extension::armature::Armature *armature; + cocos2d::extension::armature::CCArmature *armature; }; -class TestBox2DDetector : public ArmatureTestLayer, public sigslot::has_slots<> + + + +#if ENABLE_PHYSICS_BOX2D_DETECT + +class ContactListener; + +class TestColliderDetector : public ArmatureTestLayer { public: + ~TestColliderDetector(); + virtual void onEnter(); + virtual void onExit(); virtual std::string title(); virtual void draw(); virtual void update(float delta); - void onHit(cocos2d::extension::armature::Bone *bone, cocos2d::extension::armature::Bone *bone2); + void onFrameEvent(cocos2d::extension::armature::CCBone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); - cocos2d::extension::armature::Armature *armature; - cocos2d::extension::armature::Armature *armature2; + void initWorld(); + + + cocos2d::extension::armature::CCArmature *armature; + cocos2d::extension::armature::CCArmature *armature2; + + cocos2d::extension::PhysicsSprite *bullet; + + b2World *world; + ContactListener *listener; + GLESDebugDraw *debugDraw; }; + +#elif ENABLE_PHYSICS_CHIPMUNK_DETECT + + +class TestColliderDetector : public ArmatureTestLayer +{ +public: + ~TestColliderDetector(); + + virtual void onEnter(); + virtual void onExit(); + virtual std::string title(); + virtual void update(float delta); + + void onFrameEvent(cocos2d::extension::armature::CCBone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); + + void initWorld(); + + + cocos2d::extension::armature::CCArmature *armature; + cocos2d::extension::armature::CCArmature *armature2; + + cocos2d::extension::PhysicsSprite *bullet; + + + cpSpace *space; + + static int beginHit(cpArbiter *arb, cpSpace *space, void *unused); + static void endHit(cpArbiter *arb, cpSpace *space, void *unused); + + void destroyCPBody(cpBody *body); +}; +#endif + + + + + class TestBoundingBox : public ArmatureTestLayer { public: @@ -162,7 +235,7 @@ public: virtual std::string title(); virtual void draw(); - cocos2d::extension::armature::Armature *armature; + cocos2d::extension::armature::CCArmature *armature; Rect rect; }; @@ -177,11 +250,12 @@ class TestArmatureNesting : public ArmatureTestLayer { public: virtual void onEnter(); + virtual void onExit(); virtual std::string title(); - virtual bool ccTouchBegan(Touch *touch, Event *event); + virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent); virtual void registerWithTouchDispatcher(); - cocos2d::extension::armature::Armature *armature; + cocos2d::extension::armature::CCArmature *armature; int weaponIndex; }; #endif // __HELLOWORLD_SCENE_H__ \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp index 3478a4ae68..646cc6ef79 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp @@ -95,14 +95,14 @@ void SceneEditorTestLayer::toExtensionsMainLayer(cocos2d::Object *sender) } -cocos2d::extension::armature::Armature* SceneEditorTestLayer::getFish(int nTag, const char *pszName) +cocos2d::extension::armature::CCArmature* SceneEditorTestLayer::getFish(int nTag, const char *pszName) { if (_curNode == NULL) { return NULL; } ComRender *pFishRender = (ComRender*)(_curNode->getChildByTag(nTag)->getComponent(pszName)); - return (cocos2d::extension::armature::Armature *)(pFishRender->getNode()); + return (cocos2d::extension::armature::CCArmature *)(pFishRender->getNode()); } void runSceneEditorTestLayer() diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h index 783e320cbd..66a5407c5c 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h @@ -29,7 +29,7 @@ public: void toExtensionsMainLayer(cocos2d::Object *sender); //get Fish based on Tag and name of Compoent - cocos2d::extension::armature::Armature* getFish(int nTag, const char *pszName); + cocos2d::extension::armature::CCArmature* getFish(int nTag, const char *pszName); private: cocos2d::Node *_curNode; diff --git a/samples/Cpp/TestCpp/Resources/armature/Cowboy.ExportJson.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/armature/Cowboy.ExportJson.REMOVED.git-id new file mode 100644 index 0000000000..4dd0da7eee --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/armature/Cowboy.ExportJson.REMOVED.git-id @@ -0,0 +1 @@ +434a36b3e7fa9c849986cf6128b7d4402a382eb7 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/armature/Cowboy0.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/armature/Cowboy0.png.REMOVED.git-id index 9bac07216b..d2c12af0e0 100644 --- a/samples/Cpp/TestCpp/Resources/armature/Cowboy0.png.REMOVED.git-id +++ b/samples/Cpp/TestCpp/Resources/armature/Cowboy0.png.REMOVED.git-id @@ -1 +1 @@ -db891b84393bfe4b806f46bbf9c2879fa9438608 \ No newline at end of file +2b61d3b005b4076c5ff22a78a00822c0f0dc0875 \ No newline at end of file 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 From 2213e8118d83477eedad6410be3f8f9f9b070cdf Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Sat, 14 Sep 2013 23:31:33 +0800 Subject: [PATCH 13/28] fix armature hd crash --- .../Cpp/TestCpp/Resources/armature/TestBone0.png.REMOVED.git-id | 1 - .../TestCpp/Resources/hd/armature/TestBone0.png.REMOVED.git-id | 1 - 2 files changed, 2 deletions(-) delete mode 100644 samples/Cpp/TestCpp/Resources/armature/TestBone0.png.REMOVED.git-id delete mode 100644 samples/Cpp/TestCpp/Resources/hd/armature/TestBone0.png.REMOVED.git-id diff --git a/samples/Cpp/TestCpp/Resources/armature/TestBone0.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/armature/TestBone0.png.REMOVED.git-id deleted file mode 100644 index 40c3fb460f..0000000000 --- a/samples/Cpp/TestCpp/Resources/armature/TestBone0.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9214ad04b05ad72fa41db4d989510b785b200f0b \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/armature/TestBone0.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/armature/TestBone0.png.REMOVED.git-id deleted file mode 100644 index 1ab13aff50..0000000000 --- a/samples/Cpp/TestCpp/Resources/hd/armature/TestBone0.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -06fb5524ddc56e1aaa5872fae8b646a97345f6fe \ No newline at end of file From b329eb3854832e588e8a39840883e840cf61c49d Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Sat, 14 Sep 2013 23:47:15 +0800 Subject: [PATCH 14/28] update linux Makefile --- extensions/proj.linux/Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/extensions/proj.linux/Makefile b/extensions/proj.linux/Makefile index 9194c047cd..b0e07840a4 100644 --- a/extensions/proj.linux/Makefile +++ b/extensions/proj.linux/Makefile @@ -67,12 +67,9 @@ SOURCES = ../CCBReader/CCBFileLoader.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/CCArmatureDefine.cpp \ ../CocoStudio/Armature/utils/CCArmatureDataManager.cpp \ ../CocoStudio/Armature/utils/CCDataReaderHelper.cpp \ ../CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp \ From db4813f16152a92aecb240234b2f7f778bd2f80d Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Sun, 15 Sep 2013 19:08:45 +0800 Subject: [PATCH 15/28] 1.remove CC from class name 2.fix async loading --- extensions/CocoStudio/Armature/CCArmature.cpp | 134 +++++----- extensions/CocoStudio/Armature/CCArmature.h | 62 ++--- extensions/CocoStudio/Armature/CCBone.cpp | 92 +++---- extensions/CocoStudio/Armature/CCBone.h | 64 ++--- .../animation/CCArmatureAnimation.cpp | 74 +++--- .../Armature/animation/CCArmatureAnimation.h | 54 ++-- .../Armature/animation/CCProcessBase.cpp | 18 +- .../Armature/animation/CCProcessBase.h | 18 +- .../CocoStudio/Armature/animation/CCTween.cpp | 46 ++-- .../CocoStudio/Armature/animation/CCTween.h | 64 ++--- .../CocoStudio/Armature/datas/CCDatas.cpp | 124 ++++----- .../CocoStudio/Armature/datas/CCDatas.h | 202 +++++++-------- .../Armature/display/CCBatchNode.cpp | 18 +- .../CocoStudio/Armature/display/CCBatchNode.h | 6 +- .../Armature/display/CCDecorativeDisplay.cpp | 10 +- .../Armature/display/CCDecorativeDisplay.h | 12 +- .../Armature/display/CCDisplayFactory.cpp | 70 +++--- .../Armature/display/CCDisplayFactory.h | 36 +-- .../Armature/display/CCDisplayManager.cpp | 96 +++---- .../Armature/display/CCDisplayManager.h | 34 +-- .../CocoStudio/Armature/display/CCSkin.cpp | 34 +-- .../CocoStudio/Armature/display/CCSkin.h | 14 +- .../Armature/physics/CCColliderDetector.cpp | 58 ++--- .../Armature/physics/CCColliderDetector.h | 26 +- .../Armature/utils/CCArmatureDataManager.cpp | 86 +++---- .../Armature/utils/CCArmatureDataManager.h | 48 ++-- .../Armature/utils/CCDataReaderHelper.cpp | 236 +++++++++--------- .../Armature/utils/CCDataReaderHelper.h | 58 ++--- .../utils/CCSpriteFrameCacheHelper.cpp | 16 +- .../Armature/utils/CCSpriteFrameCacheHelper.h | 10 +- .../Armature/utils/CCTransformHelp.cpp | 28 +-- .../Armature/utils/CCTransformHelp.h | 20 +- .../Armature/utils/CCTweenFunction.cpp | 64 ++--- .../Armature/utils/CCTweenFunction.h | 2 +- .../CocoStudio/Reader/CCSSceneReader.cpp | 4 +- extensions/proj.win32/libExtensions.vcxproj | 1 - .../proj.win32/libExtensions.vcxproj.filters | 3 - samples/Cpp/TestCpp/Classes/AppDelegate.cpp | 2 +- .../CocoStudioArmatureTest/ArmatureScene.cpp | 94 +++---- .../CocoStudioArmatureTest/ArmatureScene.h | 26 +- .../CocoStudioSceneTest/SceneEditorTest.cpp | 4 +- .../CocoStudioSceneTest/SceneEditorTest.h | 2 +- 42 files changed, 1033 insertions(+), 1037 deletions(-) diff --git a/extensions/CocoStudio/Armature/CCArmature.cpp b/extensions/CocoStudio/Armature/CCArmature.cpp index 4782688381..61fabf20d0 100644 --- a/extensions/CocoStudio/Armature/CCArmature.cpp +++ b/extensions/CocoStudio/Armature/CCArmature.cpp @@ -38,11 +38,11 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -std::map CCArmature::m_sArmatureIndexDic; +std::map Armature::m_sArmatureIndexDic; -CCArmature *CCArmature::create() +Armature *Armature::create() { - CCArmature *armature = new CCArmature(); + Armature *armature = new Armature(); if (armature && armature->init()) { armature->autorelease(); @@ -53,9 +53,9 @@ CCArmature *CCArmature::create() } -CCArmature *CCArmature::create(const char *name) +Armature *Armature::create(const char *name) { - CCArmature *armature = new CCArmature(); + Armature *armature = new Armature(); if (armature && armature->init(name)) { armature->autorelease(); @@ -65,9 +65,9 @@ CCArmature *CCArmature::create(const char *name) return NULL; } -CCArmature *CCArmature::create(const char *name, CCBone *parentBone) +Armature *Armature::create(const char *name, Bone *parentBone) { - CCArmature *armature = new CCArmature(); + Armature *armature = new Armature(); if (armature && armature->init(name, parentBone)) { armature->autorelease(); @@ -77,7 +77,7 @@ CCArmature *CCArmature::create(const char *name, CCBone *parentBone) return NULL; } -CCArmature::CCArmature() +Armature::Armature() : m_pArmatureData(NULL) , m_pBatchNode(NULL) , m_pAtlas(NULL) @@ -90,7 +90,7 @@ CCArmature::CCArmature() } -CCArmature::~CCArmature(void) +Armature::~Armature(void) { if(NULL != m_pBoneDic) { @@ -106,13 +106,13 @@ CCArmature::~CCArmature(void) } -bool CCArmature::init() +bool Armature::init() { return init(NULL); } -bool CCArmature::init(const char *name) +bool Armature::init(const char *name) { bool bRet = false; do @@ -120,7 +120,7 @@ bool CCArmature::init(const char *name) removeAllChildren(); CC_SAFE_DELETE(m_pAnimation); - m_pAnimation = new CCArmatureAnimation(); + m_pAnimation = new ArmatureAnimation(); m_pAnimation->init(this); CC_SAFE_DELETE(m_pBoneDic); @@ -137,19 +137,19 @@ bool CCArmature::init(const char *name) m_strName = name == NULL ? "" : name; - CCArmatureDataManager *armatureDataManager = CCArmatureDataManager::sharedArmatureDataManager(); + ArmatureDataManager *armatureDataManager = ArmatureDataManager::sharedArmatureDataManager(); if(m_strName.length() != 0) { m_strName = name; - CCAnimationData *animationData = armatureDataManager->getAnimationData(name); - CCAssert(animationData, "CCAnimationData not exist! "); + AnimationData *animationData = armatureDataManager->getAnimationData(name); + CCAssert(animationData, "AnimationData not exist! "); m_pAnimation->setAnimationData(animationData); - CCArmatureData *armatureData = armatureDataManager->getArmatureData(name); + ArmatureData *armatureData = armatureDataManager->getArmatureData(name); CCAssert(armatureData, ""); m_pArmatureData = armatureData; @@ -159,19 +159,19 @@ bool CCArmature::init(const char *name) Dictionary *boneDataDic = &armatureData->boneDataDic; CCDICT_FOREACH(boneDataDic, _element) { - CCBone *bone = createBone(_element->getStrKey()); + Bone *bone = createBone(_element->getStrKey()); - //! init bone's CCTween to 1st movement's 1st frame + //! init bone's Tween to 1st movement's 1st frame do { - CCMovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str()); + MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str()); CC_BREAK_IF(!movData); - CCMovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str()); + MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str()); CC_BREAK_IF(!movBoneData || movBoneData->frameList.count() <= 0); - CCFrameData *frameData = movBoneData->getFrameData(0); + FrameData *frameData = movBoneData->getFrameData(0); CC_BREAK_IF(!frameData); bone->getTweenData()->copy(frameData); @@ -186,10 +186,10 @@ bool CCArmature::init(const char *name) else { m_strName = "new_armature"; - m_pArmatureData = CCArmatureData::create(); + m_pArmatureData = ArmatureData::create(); m_pArmatureData->name = m_strName; - CCAnimationData *animationData = CCAnimationData::create(); + AnimationData *animationData = AnimationData::create(); animationData->name = m_strName; armatureDataManager->addArmatureData(m_strName.c_str(), m_pArmatureData); @@ -214,33 +214,33 @@ bool CCArmature::init(const char *name) return bRet; } -bool CCArmature::init(const char *name, CCBone *parentBone) +bool Armature::init(const char *name, Bone *parentBone) { m_pParentBone = parentBone; return init(name); } -CCBone *CCArmature::createBone(const char *boneName) +Bone *Armature::createBone(const char *boneName) { - CCBone *existedBone = getBone(boneName); + Bone *existedBone = getBone(boneName); if(existedBone != NULL) return existedBone; - CCBoneData *boneData = (CCBoneData *)m_pArmatureData->getBoneData(boneName); + BoneData *boneData = (BoneData *)m_pArmatureData->getBoneData(boneName); std::string parentName = boneData->parentName; - CCBone *bone = NULL; + Bone *bone = NULL; if( parentName.length() != 0 ) { createBone(parentName.c_str()); - bone = CCBone::create(boneName); + bone = Bone::create(boneName); addBone(bone, parentName.c_str()); } else { - bone = CCBone::create(boneName); + bone = Bone::create(boneName); addBone(bone, ""); } @@ -251,14 +251,14 @@ CCBone *CCArmature::createBone(const char *boneName) } -void CCArmature::addBone(CCBone *bone, const char *parentName) +void Armature::addBone(Bone *bone, const char *parentName) { CCAssert( bone != NULL, "Argument must be non-nil"); CCAssert(m_pBoneDic->objectForKey(bone->getName()) == NULL, "bone already added. It can't be added again"); if (NULL != parentName) { - CCBone *boneParent = (CCBone *)m_pBoneDic->objectForKey(parentName); + Bone *boneParent = (Bone *)m_pBoneDic->objectForKey(parentName); if (boneParent) { boneParent->addChildBone(bone); @@ -286,7 +286,7 @@ void CCArmature::addBone(CCBone *bone, const char *parentName) } -void CCArmature::removeBone(CCBone *bone, bool recursion) +void Armature::removeBone(Bone *bone, bool recursion) { CCAssert(bone != NULL, "bone must be added to the bone dictionary!"); @@ -302,13 +302,13 @@ void CCArmature::removeBone(CCBone *bone, bool recursion) } -CCBone *CCArmature::getBone(const char *name) const +Bone *Armature::getBone(const char *name) const { - return (CCBone *)m_pBoneDic->objectForKey(name); + return (Bone *)m_pBoneDic->objectForKey(name); } -void CCArmature::changeBoneParent(CCBone *bone, const char *parentName) +void Armature::changeBoneParent(Bone *bone, const char *parentName) { CCAssert(bone != NULL, "bone must be added to the bone dictionary!"); @@ -320,7 +320,7 @@ void CCArmature::changeBoneParent(CCBone *bone, const char *parentName) if (parentName != NULL) { - CCBone *boneParent = (CCBone *)m_pBoneDic->objectForKey(parentName); + Bone *boneParent = (Bone *)m_pBoneDic->objectForKey(parentName); if (boneParent) { @@ -337,12 +337,12 @@ void CCArmature::changeBoneParent(CCBone *bone, const char *parentName) } } -Dictionary *CCArmature::getBoneDic() +Dictionary *Armature::getBoneDic() { return m_pBoneDic; } -const AffineTransform& CCArmature::getNodeToParentTransform() const +const AffineTransform& Armature::getNodeToParentTransform() const { if (_transformDirty) { @@ -422,7 +422,7 @@ const AffineTransform& CCArmature::getNodeToParentTransform() const return _transform; } -void CCArmature::updateOffsetPoint() +void Armature::updateOffsetPoint() { // Set contentsize and Calculate anchor point. Rect rect = boundingBox(); @@ -434,35 +434,35 @@ void CCArmature::updateOffsetPoint() } } -void CCArmature::setAnimation(CCArmatureAnimation *animation) +void Armature::setAnimation(ArmatureAnimation *animation) { m_pAnimation = animation; } -CCArmatureAnimation *CCArmature::getAnimation() +ArmatureAnimation *Armature::getAnimation() { return m_pAnimation; } -bool CCArmature::getArmatureTransformDirty() +bool Armature::getArmatureTransformDirty() { return m_bArmatureTransformDirty; } -void CCArmature::update(float dt) +void Armature::update(float dt) { m_pAnimation->update(dt); Object *object = NULL; CCARRAY_FOREACH(m_pTopBoneList, object) { - ((CCBone *)object)->update(dt); + ((Bone *)object)->update(dt); } m_bArmatureTransformDirty = false; } -void CCArmature::draw() +void Armature::draw() { if (m_pParentBone == NULL) { @@ -473,9 +473,9 @@ void CCArmature::draw() Object *object = NULL; CCARRAY_FOREACH(_children, object) { - if (CCBone *bone = dynamic_cast(object)) + if (Bone *bone = dynamic_cast(object)) { - CCDisplayManager *displayManager = bone->getDisplayManager(); + DisplayManager *displayManager = bone->getDisplayManager(); Node *node = displayManager->getDisplayRenderNode(); if (NULL == node) @@ -485,10 +485,10 @@ void CCArmature::draw() { case CS_DISPLAY_SPRITE: { - CCSkin *skin = (CCSkin *)node; + Skin *skin = (Skin *)node; TextureAtlas *textureAtlas = skin->getTextureAtlas(); - CCBlendType blendType = bone->getBlendType(); + BlendType blendType = bone->getBlendType(); if(m_pAtlas != textureAtlas || blendType != BLEND_NORMAL) { if (m_pAtlas) @@ -515,7 +515,7 @@ void CCArmature::draw() break; case CS_DISPLAY_ARMATURE: { - CCArmature *armature = (CCArmature *)(node); + Armature *armature = (Armature *)(node); TextureAtlas *textureAtlas = armature->getTextureAtlas(); if(m_pAtlas != textureAtlas) @@ -566,7 +566,7 @@ void CCArmature::draw() } -void CCArmature::updateBlendType(CCBlendType blendType) +void Armature::updateBlendType(BlendType blendType) { BlendFunc blendFunc; switch (blendType) @@ -607,7 +607,7 @@ void CCArmature::updateBlendType(CCBlendType blendType) -void CCArmature::visit() +void Armature::visit() { // quick return if not visible. children won't be drawn. if (!_visible) @@ -636,7 +636,7 @@ void CCArmature::visit() kmGLPopMatrix(); } -Rect CCArmature::getBoundingBox() const +Rect Armature::getBoundingBox() const { float minx, miny, maxx, maxy = 0; @@ -647,7 +647,7 @@ Rect CCArmature::getBoundingBox() const Object *object = NULL; CCARRAY_FOREACH(_children, object) { - if (CCBone *bone = dynamic_cast(object)) + if (Bone *bone = dynamic_cast(object)) { Rect r = bone->getDisplayManager()->getBoundingBox(); @@ -675,10 +675,10 @@ Rect CCArmature::getBoundingBox() const return boundingBox; } -CCBone *CCArmature::getBoneAtPoint(float x, float y) +Bone *Armature::getBoneAtPoint(float x, float y) { int length = _children->data->num; - CCBone **bs = (CCBone **)_children->data->arr; + Bone **bs = (Bone **)_children->data->arr; for(int i = length - 1; i >= 0; i--) { @@ -691,12 +691,12 @@ CCBone *CCArmature::getBoneAtPoint(float x, float y) } #if ENABLE_PHYSICS_BOX2D_DETECT -b2Body *CCArmature::getBody() +b2Body *Armature::getBody() { return m_pBody; } -void CCArmature::setBody(b2Body *body) +void Armature::setBody(b2Body *body) { if (m_pBody == body) { @@ -709,14 +709,14 @@ void CCArmature::setBody(b2Body *body) Object *object = NULL; CCARRAY_FOREACH(_children, object) { - if (CCBone *bone = dynamic_cast(object)) + if (Bone *bone = dynamic_cast(object)) { Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); Object *displayObject = NULL; CCARRAY_FOREACH(displayList, displayObject) { - CCColliderDetector *detector = ((CCDecorativeDisplay *)displayObject)->getColliderDetector(); + ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); if (detector != NULL) { detector->setBody(m_pBody); @@ -726,7 +726,7 @@ void CCArmature::setBody(b2Body *body) } } -b2Fixture *CCArmature::getShapeList() +b2Fixture *Armature::getShapeList() { if (m_pBody) { @@ -739,12 +739,12 @@ b2Fixture *CCArmature::getShapeList() } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT -cpBody *CCArmature::getBody() +cpBody *Armature::getBody() { return m_pBody; } -void CCArmature::setBody(cpBody *body) +void Armature::setBody(cpBody *body) { if (m_pBody == body) { @@ -757,14 +757,14 @@ void CCArmature::setBody(cpBody *body) Object *object = NULL; CCARRAY_FOREACH(_children, object) { - if (CCBone *bone = dynamic_cast(object)) + if (Bone *bone = dynamic_cast(object)) { Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); Object *displayObject = NULL; CCARRAY_FOREACH(displayList, displayObject) { - CCColliderDetector *detector = ((CCDecorativeDisplay *)displayObject)->getColliderDetector(); + ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); if (detector != NULL) { detector->setBody(m_pBody); @@ -774,7 +774,7 @@ void CCArmature::setBody(cpBody *body) } } -cpShape *CCArmature::getShapeList() +cpShape *Armature::getShapeList() { if (m_pBody) { diff --git a/extensions/CocoStudio/Armature/CCArmature.h b/extensions/CocoStudio/Armature/CCArmature.h index 6bc39dceca..a89ab05a4e 100644 --- a/extensions/CocoStudio/Armature/CCArmature.h +++ b/extensions/CocoStudio/Armature/CCArmature.h @@ -35,7 +35,7 @@ struct cpBody; NS_CC_EXT_ARMATURE_BEGIN -class CCArmature : public NodeRGBA, public BlendProtocol +class Armature : public NodeRGBA, public BlendProtocol { public: @@ -44,21 +44,21 @@ public: * Allocates and initializes an armature. * @return An initialized armature which is marked as "autorelease". */ - static CCArmature *create(); + static Armature *create(); /** - * Allocates an armature, and use the CCArmatureData named name in CCArmatureDataManager to initializes the armature. + * Allocates an armature, and use the ArmatureData named name in ArmatureDataManager to initializes the armature. * - * @param name CCArmature will use the name to find the CCArmatureData to initializes it. + * @param name Armature will use the name to find the ArmatureData to initializes it. * @return A initialized armature which is marked as "autorelease". */ - static CCArmature *create(const char *name); + static Armature *create(const char *name); - static CCArmature *create(const char *name, CCBone *parentBone); + static Armature *create(const char *name, Bone *parentBone); public: - CCArmature(); - ~CCArmature(void); + Armature(); + ~Armature(void); /** * Init the empty armature @@ -67,42 +67,42 @@ public: /** * Init an armature with specified name - * @param name CCArmature name + * @param name Armature name */ virtual bool init(const char *name); - virtual bool init(const char *name, CCBone *parentBone); + virtual bool init(const char *name, Bone *parentBone); /** - * Add a CCBone to this CCArmature, + * Add a Bone to this Armature, * - * @param bone The CCBone you want to add to CCArmature - * @param parentName The parent CCBone's name you want to add to . If it's NULL, then set CCArmature to its parent + * @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 */ - virtual void addBone(CCBone *bone, const char *parentName); + virtual void addBone(Bone *bone, const char *parentName); /** * Get a bone with the specified name * * @param name The bone's name you want to get */ - virtual CCBone *getBone(const char *name) const; + virtual Bone *getBone(const char *name) const; /** * Change a bone's parent with the specified parent name. * * @param bone The bone you want to change parent * @param parentName The new parent's name. */ - virtual void changeBoneParent(CCBone *bone, const char *parentName); + virtual void changeBoneParent(Bone *bone, const char *parentName); /** - * Remove a bone with the specified name. If recursion it will also remove child CCBone recursionly. + * Remove a bone with the specified name. If recursion it will also remove child Bone recursionly. * * @param bone The bone you want to remove * @param recursion Determine whether remove the bone's child recursion. */ - virtual void removeBone(CCBone *bone, bool recursion); + virtual void removeBone(Bone *bone, bool recursion); /** - * Get CCArmature's bone dictionary - * @return CCArmature's bone dictionary + * Get Armature's bone dictionary + * @return Armature's bone dictionary */ Dictionary *getBoneDic(); @@ -111,7 +111,7 @@ public: */ virtual Rect getBoundingBox() const; - CCBone *getBoneAtPoint(float x, float y); + Bone *getBoneAtPoint(float x, float y); virtual void visit(); virtual void update(float dt); @@ -133,8 +133,8 @@ public: return m_sBlendFunc; } - virtual void setAnimation(CCArmatureAnimation *animation); - virtual CCArmatureAnimation *getAnimation(); + virtual void setAnimation(ArmatureAnimation *animation); + virtual ArmatureAnimation *getAnimation(); virtual bool getArmatureTransformDirty(); @@ -147,22 +147,22 @@ public: protected: /* - * Used to create CCBone internal + * Used to create Bone internal */ - CCBone *createBone(const char *boneName ); + Bone *createBone(const char *boneName ); //! Update blend function - void updateBlendType(CCBlendType blendType); + void updateBlendType(BlendType blendType); - CC_SYNTHESIZE(CCArmatureData *, m_pArmatureData, ArmatureData); + CC_SYNTHESIZE(ArmatureData *, m_pArmatureData, ArmatureData); - CC_SYNTHESIZE(CCBatchNode *, m_pBatchNode, BatchNode); + CC_SYNTHESIZE(BatchNode *, m_pBatchNode, BatchNode); CC_SYNTHESIZE(std::string, m_strName, Name); CC_SYNTHESIZE(TextureAtlas *, m_pAtlas, TextureAtlas); - CC_SYNTHESIZE(CCBone *, m_pParentBone, ParentBone); + CC_SYNTHESIZE(Bone *, m_pParentBone, ParentBone); CC_SYNTHESIZE(float, m_fVersion, Version); @@ -173,13 +173,13 @@ protected: Array *m_pTopBoneList; - static std::map m_sArmatureIndexDic; //! Use to save armature zorder info, + static std::map m_sArmatureIndexDic; //! Use to save armature zorder info, BlendFunc m_sBlendFunc; //! It's required for CCTextureProtocol inheritance Point m_pOffsetPoint; - CCArmatureAnimation *m_pAnimation; + ArmatureAnimation *m_pAnimation; #if ENABLE_PHYSICS_BOX2D_DETECT CC_PROPERTY(b2Body *, m_pBody, Body); diff --git a/extensions/CocoStudio/Armature/CCBone.cpp b/extensions/CocoStudio/Armature/CCBone.cpp index a46333f6f0..9c39567936 100644 --- a/extensions/CocoStudio/Armature/CCBone.cpp +++ b/extensions/CocoStudio/Armature/CCBone.cpp @@ -31,10 +31,10 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -CCBone *CCBone::create() +Bone *Bone::create() { - CCBone *pBone = new CCBone(); + Bone *pBone = new Bone(); if (pBone && pBone->init()) { pBone->autorelease(); @@ -45,10 +45,10 @@ CCBone *CCBone::create() } -CCBone *CCBone::create(const char *name) +Bone *Bone::create(const char *name) { - CCBone *pBone = new CCBone(); + Bone *pBone = new Bone(); if (pBone && pBone->init(name)) { pBone->autorelease(); @@ -58,7 +58,7 @@ CCBone *CCBone::create(const char *name) return NULL; } -CCBone::CCBone() +Bone::Bone() { m_pTweenData = NULL; m_pParentBone = NULL; @@ -76,7 +76,7 @@ CCBone::CCBone() } -CCBone::~CCBone(void) +Bone::~Bone(void) { CC_SAFE_DELETE(m_pTweenData); CC_SAFE_DELETE(_children); @@ -91,13 +91,13 @@ CCBone::~CCBone(void) CC_SAFE_RELEASE(m_pChildArmature); } -bool CCBone::init() +bool Bone::init() { - return CCBone::init(NULL); + return Bone::init(NULL); } -bool CCBone::init(const char *name) +bool Bone::init(const char *name) { bool bRet = false; do @@ -109,14 +109,14 @@ bool CCBone::init(const char *name) } CC_SAFE_DELETE(m_pTweenData); - m_pTweenData = new CCFrameData(); + m_pTweenData = new FrameData(); CC_SAFE_DELETE(m_pTween); - m_pTween = new CCTween(); + m_pTween = new Tween(); m_pTween->init(this); CC_SAFE_DELETE(m_pDisplayManager); - m_pDisplayManager = new CCDisplayManager(); + m_pDisplayManager = new DisplayManager(); m_pDisplayManager->init(this); @@ -127,7 +127,7 @@ bool CCBone::init(const char *name) return bRet; } -void CCBone::setBoneData(CCBoneData *boneData) +void Bone::setBoneData(BoneData *boneData) { CCAssert(NULL != boneData, "_boneData must not be NULL"); @@ -140,12 +140,12 @@ void CCBone::setBoneData(CCBoneData *boneData) m_pDisplayManager->initDisplayList(boneData); } -CCBoneData *CCBone::getBoneData() +BoneData *Bone::getBoneData() { return m_pBoneData; } -void CCBone::setArmature(CCArmature *armature) +void Bone::setArmature(Armature *armature) { m_pArmature = armature; if (m_pArmature) @@ -155,12 +155,12 @@ void CCBone::setArmature(CCArmature *armature) } -CCArmature *CCBone::getArmature() +Armature *Bone::getArmature() { return m_pArmature; } -void CCBone::update(float delta) +void Bone::update(float delta) { if (m_pParentBone) m_bBoneTransformDirty = m_bBoneTransformDirty || m_pParentBone->isTransformDirty(); @@ -169,12 +169,12 @@ void CCBone::update(float delta) { if (m_pArmature->getArmatureData()->dataVersion >= VERSION_COMBINED) { - CCTransformHelp::nodeConcat(*m_pTweenData, *m_pBoneData); + TransformHelp::nodeConcat(*m_pTweenData, *m_pBoneData); m_pTweenData->scaleX -= 1; m_pTweenData->scaleY -= 1; } - CCTransformHelp::nodeToMatrix(*m_pTweenData, m_tWorldTransform); + TransformHelp::nodeToMatrix(*m_pTweenData, m_tWorldTransform); m_tWorldTransform = AffineTransformConcat(getNodeToParentTransform(), m_tWorldTransform); @@ -184,12 +184,12 @@ void CCBone::update(float delta) } } - CCDisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty || m_pArmature->getArmatureTransformDirty()); + DisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty || m_pArmature->getArmatureTransformDirty()); Object *object = NULL; CCARRAY_FOREACH(_children, object) { - CCBone *childBone = (CCBone *)object; + Bone *childBone = (Bone *)object; childBone->update(delta); } @@ -197,21 +197,21 @@ void CCBone::update(float delta) } -void CCBone::updateDisplayedColor(const Color3B &parentColor) +void Bone::updateDisplayedColor(const Color3B &parentColor) { _realColor = Color3B(255, 255, 255); NodeRGBA::updateDisplayedColor(parentColor); updateColor(); } -void CCBone::updateDisplayedOpacity(GLubyte parentOpacity) +void Bone::updateDisplayedOpacity(GLubyte parentOpacity) { _realOpacity = 255; NodeRGBA::updateDisplayedOpacity(parentOpacity); updateColor(); } -void CCBone::updateColor() +void Bone::updateColor() { Node *display = m_pDisplayManager->getDisplayRenderNode(); RGBAProtocol *protocol = dynamic_cast(display); @@ -222,7 +222,7 @@ void CCBone::updateColor() } } -void CCBone::updateZOrder() +void Bone::updateZOrder() { if (m_pArmature->getArmatureData()->dataVersion >= VERSION_COMBINED) { @@ -235,7 +235,7 @@ void CCBone::updateZOrder() } } -void CCBone::addChildBone(CCBone *child) +void Bone::addChildBone(Bone *child) { CCAssert( NULL != child, "Argument must be non-nil"); CCAssert( NULL == child->m_pParentBone, "child already added. It can't be added again"); @@ -253,7 +253,7 @@ void CCBone::addChildBone(CCBone *child) } } -void CCBone::removeChildBone(CCBone *bone, bool recursion) +void Bone::removeChildBone(Bone *bone, bool recursion) { if ( _children->getIndexOfObject(bone) != UINT_MAX ) { @@ -263,7 +263,7 @@ void CCBone::removeChildBone(CCBone *bone, bool recursion) Object *_object = NULL; CCARRAY_FOREACH(_ccbones, _object) { - CCBone *_ccBone = (CCBone *)_object; + Bone *_ccBone = (Bone *)_object; bone->removeChildBone(_ccBone, recursion); } } @@ -276,7 +276,7 @@ void CCBone::removeChildBone(CCBone *bone, bool recursion) } } -void CCBone::removeFromParent(bool recursion) +void Bone::removeFromParent(bool recursion) { if (NULL != m_pParentBone) { @@ -284,17 +284,17 @@ void CCBone::removeFromParent(bool recursion) } } -void CCBone::setParentBone(CCBone *parent) +void Bone::setParentBone(Bone *parent) { m_pParentBone = parent; } -CCBone *CCBone::getParentBone() +Bone *Bone::getParentBone() { return m_pParentBone; } -void CCBone::setChildArmature(CCArmature *armature) +void Bone::setChildArmature(Armature *armature) { if (m_pChildArmature != armature) { @@ -304,67 +304,67 @@ void CCBone::setChildArmature(CCArmature *armature) } } -CCArmature *CCBone::getChildArmature() +Armature *Bone::getChildArmature() { return m_pChildArmature; } -CCTween *CCBone::getTween() +Tween *Bone::getTween() { return m_pTween; } -void CCBone::setZOrder(int zOrder) +void Bone::setZOrder(int zOrder) { if (_ZOrder != zOrder) Node::setZOrder(zOrder); } -void CCBone::setTransformDirty(bool dirty) +void Bone::setTransformDirty(bool dirty) { m_bBoneTransformDirty = dirty; } -bool CCBone::isTransformDirty() +bool Bone::isTransformDirty() { return m_bBoneTransformDirty; } -AffineTransform CCBone::getNodeToArmatureTransform() const +AffineTransform Bone::getNodeToArmatureTransform() const { return m_tWorldTransform; } -AffineTransform CCBone::getNodeToWorldTransform() const +AffineTransform Bone::getNodeToWorldTransform() const { return AffineTransformConcat(m_tWorldTransform, m_pArmature->getNodeToWorldTransform()); } -Node *CCBone::getDisplayRenderNode() +Node *Bone::getDisplayRenderNode() { return m_pDisplayManager->getDisplayRenderNode(); } -void CCBone::addDisplay(CCDisplayData *displayData, int index) +void Bone::addDisplay(DisplayData *displayData, int index) { m_pDisplayManager->addDisplay(displayData, index); } -void CCBone::addDisplay(Node *display, int index) +void Bone::addDisplay(Node *display, int index) { m_pDisplayManager->addDisplay(display, index); } -void CCBone::changeDisplayByIndex(int index, bool force) +void Bone::changeDisplayByIndex(int index, bool force) { m_pDisplayManager->changeDisplayByIndex(index, force); } -Array *CCBone::getColliderBodyList() +Array *Bone::getColliderBodyList() { - if (CCDecorativeDisplay *decoDisplay = m_pDisplayManager->getCurrentDecorativeDisplay()) + if (DecorativeDisplay *decoDisplay = m_pDisplayManager->getCurrentDecorativeDisplay()) { - if (CCColliderDetector *detector = decoDisplay->getColliderDetector()) + if (ColliderDetector *detector = decoDisplay->getColliderDetector()) { return detector->getColliderBodyList(); } diff --git a/extensions/CocoStudio/Armature/CCBone.h b/extensions/CocoStudio/Armature/CCBone.h index d7c0d23837..3484e9d93c 100644 --- a/extensions/CocoStudio/Armature/CCBone.h +++ b/extensions/CocoStudio/Armature/CCBone.h @@ -34,36 +34,36 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -class CCArmature; +class Armature; -class CCBone : public NodeRGBA +class Bone : public NodeRGBA { public: /** * Allocates and initializes a bone. * @return A initialized bone which is marked as "autorelease". */ - static CCBone *create(); + 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 CCBone *create(const char *name); + static Bone *create(const char *name); public: - CCBone(); - virtual ~CCBone(void); + Bone(); + virtual ~Bone(void); /** - * Initializes an empty CCBone with nothing init. + * Initializes an empty Bone with nothing init. */ virtual bool init(); /** - * Initializes a CCBone with the specified name - * @param name CCBone's name. + * Initializes a Bone with the specified name + * @param name Bone's name. */ virtual bool init(const char *name); @@ -73,38 +73,38 @@ public: * 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 CCSpriteDisplayData param + * 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(CCDisplayData *displayData, int index); + 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(CCBone *parent) function to set self to it's parent + * 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(CCBone *child); + void addChildBone(Bone *child); /** * Set parent bone. * If parent is NUll, then also remove this bone from armature. - * It will not set the CCArmature, if you want to add the bone to a CCArmature, you should use CCArmature::addBone(CCBone *bone, const char* parentName). + * 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(CCBone *parent); + void setParentBone(Bone *parent); /** * Get parent bone * @return parent bone */ - CCBone *getParentBone(); + Bone *getParentBone(); /** * Remove itself from its parent. @@ -113,10 +113,10 @@ public: void removeFromParent(bool recursion); /** - * Removes a child CCBone + * Removes a child Bone * @param bone the bone you want to remove */ - void removeChildBone(CCBone *bone, bool recursion); + void removeChildBone(Bone *bone, bool recursion); void update(float delta); @@ -131,7 +131,7 @@ public: virtual void setZOrder(int zOrder); - CCTween *getTween(); + Tween *getTween(); /* * Whether or not the bone's transform property changed. if true, the bone will update the transform. @@ -152,35 +152,35 @@ public: public: /* - * The origin state of the CCBone. Display's state is effected by m_pBoneData, m_pNode, m_pTweenData - * when call setData function, it will copy from the CCBoneData. + * The origin state of the Bone. Display's state is effected by m_pBoneData, m_pNode, m_pTweenData + * when call setData function, it will copy from the BoneData. */ - CC_PROPERTY(CCBoneData *, m_pBoneData, BoneData); + CC_PROPERTY(BoneData *, m_pBoneData, BoneData); - //! A weak reference to the CCArmature - CC_PROPERTY(CCArmature *, m_pArmature, Armature); + //! A weak reference to the Armature + CC_PROPERTY(Armature *, m_pArmature, Armature); - //! A weak reference to the child CCArmature - CC_PROPERTY(CCArmature *, m_pChildArmature, ChildArmature); + //! A weak reference to the child Armature + CC_PROPERTY(Armature *, m_pChildArmature, ChildArmature); - CC_SYNTHESIZE(CCDisplayManager *, m_pDisplayManager, DisplayManager) + CC_SYNTHESIZE(DisplayManager *, m_pDisplayManager, DisplayManager) /* - * When CCArmature play an animation, if there is not a CCMovementBoneData of this bone in this CCMovementData, this bone will be hidden. + * 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, m_bIgnoreMovementBoneData, IgnoreMovementBoneData) - CC_SYNTHESIZE(CCBlendType, m_eBlendType, BlendType) + CC_SYNTHESIZE(BlendType, m_eBlendType, BlendType) protected: - CCTween *m_pTween; //! Calculate tween effect + Tween *m_pTween; //! Calculate tween effect //! Used for making tween effect in every frame - CC_SYNTHESIZE_READONLY(CCFrameData *, m_pTweenData, TweenData); + CC_SYNTHESIZE_READONLY(FrameData *, m_pTweenData, TweenData); CC_SYNTHESIZE(std::string, m_strName, Name); - CCBone *m_pParentBone; //! A weak reference to its parent + Bone *m_pParentBone; //! A weak reference to its parent bool m_bBoneTransformDirty; //! Whether or not transform dirty //! self Transform, use this to change display's state diff --git a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp index c2cd1c19c6..e54621c80f 100644 --- a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp +++ b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp @@ -32,9 +32,9 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -CCArmatureAnimation *CCArmatureAnimation::create(CCArmature *armature) +ArmatureAnimation *ArmatureAnimation::create(Armature *armature) { - CCArmatureAnimation *pArmatureAnimation = new CCArmatureAnimation(); + ArmatureAnimation *pArmatureAnimation = new ArmatureAnimation(); if (pArmatureAnimation && pArmatureAnimation->init(armature)) { pArmatureAnimation->autorelease(); @@ -45,7 +45,7 @@ CCArmatureAnimation *CCArmatureAnimation::create(CCArmature *armature) } -CCArmatureAnimation::CCArmatureAnimation() +ArmatureAnimation::ArmatureAnimation() : m_pAnimationData(NULL) , m_fSpeedScale(1) , m_pMovementData(NULL) @@ -61,7 +61,7 @@ CCArmatureAnimation::CCArmatureAnimation() } -CCArmatureAnimation::~CCArmatureAnimation(void) +ArmatureAnimation::~ArmatureAnimation(void) { CC_SAFE_RELEASE_NULL(m_pTweenList); CC_SAFE_RELEASE_NULL(m_pAnimationData); @@ -70,7 +70,7 @@ CCArmatureAnimation::~CCArmatureAnimation(void) CC_SAFE_RELEASE_NULL(m_sFrameEventTarget); } -bool CCArmatureAnimation::init(CCArmature *armature) +bool ArmatureAnimation::init(Armature *armature) { bool bRet = false; do @@ -88,49 +88,49 @@ bool CCArmatureAnimation::init(CCArmature *armature) } -void CCArmatureAnimation:: pause() +void ArmatureAnimation:: pause() { Object *object = NULL; CCARRAY_FOREACH(m_pTweenList, object) { - ((CCTween *)object)->pause(); + ((Tween *)object)->pause(); } - CCProcessBase::pause(); + ProcessBase::pause(); } -void CCArmatureAnimation::resume() +void ArmatureAnimation::resume() { Object *object = NULL; CCARRAY_FOREACH(m_pTweenList, object) { - ((CCTween *)object)->resume(); + ((Tween *)object)->resume(); } - CCProcessBase::resume(); + ProcessBase::resume(); } -void CCArmatureAnimation::stop() +void ArmatureAnimation::stop() { Object *object = NULL; CCARRAY_FOREACH(m_pTweenList, object) { - ((CCTween *)object)->stop(); + ((Tween *)object)->stop(); } m_pTweenList->removeAllObjects(); - CCProcessBase::stop(); + ProcessBase::stop(); } -void CCArmatureAnimation::setAnimationScale(float animationScale ) +void ArmatureAnimation::setAnimationScale(float animationScale ) { setSpeedScale(animationScale); } -float CCArmatureAnimation::getAnimationScale() const +float ArmatureAnimation::getAnimationScale() const { return getSpeedScale(); } -void CCArmatureAnimation::setSpeedScale(float speedScale) +void ArmatureAnimation::setSpeedScale(float speedScale) { if(speedScale == m_fSpeedScale) { @@ -145,7 +145,7 @@ void CCArmatureAnimation::setSpeedScale(float speedScale) Dictionary *dict = m_pArmature->getBoneDic(); CCDICT_FOREACH(dict, element) { - CCBone *bone = (CCBone *)element->getObject(); + Bone *bone = (Bone *)element->getObject(); bone->getTween()->setProcessScale(m_fProcessScale); if (bone->getChildArmature()) @@ -155,12 +155,12 @@ void CCArmatureAnimation::setSpeedScale(float speedScale) } } -float CCArmatureAnimation::getSpeedScale() const +float ArmatureAnimation::getSpeedScale() const { return m_fSpeedScale; } -void CCArmatureAnimation::setAnimationInternal(float animationInternal) +void ArmatureAnimation::setAnimationInternal(float animationInternal) { if(animationInternal == m_fAnimationInternal) { @@ -173,7 +173,7 @@ void CCArmatureAnimation::setAnimationInternal(float animationInternal) Dictionary *dict = m_pArmature->getBoneDic(); CCDICT_FOREACH(dict, element) { - CCBone *bone = (CCBone *)element->getObject(); + Bone *bone = (Bone *)element->getObject(); bone->getTween()->setAnimationInternal(m_fAnimationInternal); if (bone->getChildArmature()) { @@ -183,7 +183,7 @@ void CCArmatureAnimation::setAnimationInternal(float animationInternal) } -void CCArmatureAnimation::play(const char *animationName, int durationTo, int durationTween, int loop, int tweenEasing) +void ArmatureAnimation::play(const char *animationName, int durationTo, int durationTween, int loop, int tweenEasing) { CCAssert(m_pAnimationData, "m_pAnimationData can not be null"); @@ -207,7 +207,7 @@ void CCArmatureAnimation::play(const char *animationName, int durationTo, int du loop = (loop < 0) ? m_pMovementData->loop : loop; - CCProcessBase::play((void *)animationName, durationTo, durationTween, loop, tweenEasing); + ProcessBase::play((void *)animationName, durationTo, durationTween, loop, tweenEasing); if (m_iRawDuration == 0) @@ -228,7 +228,7 @@ void CCArmatureAnimation::play(const char *animationName, int durationTo, int du m_iDurationTween = durationTween; } - CCMovementBoneData *movementBoneData = NULL; + MovementBoneData *movementBoneData = NULL; m_pTweenList->removeAllObjects(); DictElement *element = NULL; @@ -236,10 +236,10 @@ void CCArmatureAnimation::play(const char *animationName, int durationTo, int du CCDICT_FOREACH(dict, element) { - CCBone *bone = (CCBone *)element->getObject(); - movementBoneData = (CCMovementBoneData *)m_pMovementData->movBoneDataDic.objectForKey(bone->getName()); + Bone *bone = (Bone *)element->getObject(); + movementBoneData = (MovementBoneData *)m_pMovementData->movBoneDataDic.objectForKey(bone->getName()); - CCTween *tween = bone->getTween(); + Tween *tween = bone->getTween(); if(movementBoneData && movementBoneData->frameList.count() > 0) { m_pTweenList->addObject(tween); @@ -269,7 +269,7 @@ void CCArmatureAnimation::play(const char *animationName, int durationTo, int du } -void CCArmatureAnimation::playByIndex(int animationIndex, int durationTo, int durationTween, int loop, int tweenEasing) +void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int durationTween, int loop, int tweenEasing) { std::vector &movName = m_pAnimationData->movementNames; CC_ASSERT((animationIndex > -1) && ((unsigned int)animationIndex < movName.size())); @@ -280,22 +280,22 @@ void CCArmatureAnimation::playByIndex(int animationIndex, int durationTo, int du -int CCArmatureAnimation::getMovementCount() +int ArmatureAnimation::getMovementCount() { return m_pAnimationData->getMovementCount(); } -void CCArmatureAnimation::update(float dt) +void ArmatureAnimation::update(float dt) { - CCProcessBase::update(dt); + ProcessBase::update(dt); Object *object = NULL; CCARRAY_FOREACH(m_pTweenList, object) { - ((CCTween *)object)->update(dt); + ((Tween *)object)->update(dt); } } -void CCArmatureAnimation::updateHandler() +void ArmatureAnimation::updateHandler() { if (m_fCurrentPercent >= 1) { @@ -365,7 +365,7 @@ void CCArmatureAnimation::updateHandler() } } -std::string CCArmatureAnimation::getCurrentMovementID() +std::string ArmatureAnimation::getCurrentMovementID() { if (m_bIsComplete) { @@ -374,7 +374,7 @@ std::string CCArmatureAnimation::getCurrentMovementID() return m_strMovementID; } -void CCArmatureAnimation::setMovementEventCallFunc(Object *target, SEL_MovementEventCallFunc callFunc) +void ArmatureAnimation::setMovementEventCallFunc(Object *target, SEL_MovementEventCallFunc callFunc) { if (target != m_sMovementEventTarget) { @@ -385,7 +385,7 @@ void CCArmatureAnimation::setMovementEventCallFunc(Object *target, SEL_MovementE m_sMovementEventCallFunc = callFunc; } -void CCArmatureAnimation::setFrameEventCallFunc(Object *target, SEL_FrameEventCallFunc callFunc) +void ArmatureAnimation::setFrameEventCallFunc(Object *target, SEL_FrameEventCallFunc callFunc) { if (target != m_sFrameEventTarget) { @@ -396,7 +396,7 @@ void CCArmatureAnimation::setFrameEventCallFunc(Object *target, SEL_FrameEventCa m_sFrameEventCallFunc = callFunc; } -void CCArmatureAnimation::frameEvent(CCBone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex) +void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex) { if (m_sFrameEventTarget && m_sFrameEventCallFunc) { diff --git a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h index 842c7314e5..a9f26911eb 100644 --- a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h +++ b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h @@ -39,33 +39,33 @@ enum MovementEventType }; -class CCArmature; -class CCBone; +class Armature; +class Bone; -typedef void (Object::*SEL_MovementEventCallFunc)(CCArmature *, MovementEventType, const char *); -typedef void (Object::*SEL_FrameEventCallFunc)(CCBone *, const char *, int, int); +typedef void (Object::*SEL_MovementEventCallFunc)(Armature *, MovementEventType, const char *); +typedef void (Object::*SEL_FrameEventCallFunc)(Bone *, const char *, int, int); #define movementEvent_selector(_SELECTOR) (SEL_MovementEventCallFunc)(&_SELECTOR) #define frameEvent_selector(_SELECTOR) (SEL_FrameEventCallFunc)(&_SELECTOR) -class CCArmatureAnimation : public CCProcessBase +class ArmatureAnimation : public ProcessBase { public: /** - * Create with a CCArmature - * @param armature The CCArmature CCArmatureAnimation will bind to + * Create with a Armature + * @param armature The Armature ArmatureAnimation will bind to */ - static CCArmatureAnimation *create(CCArmature *armature); + static ArmatureAnimation *create(Armature *armature); public: - CCArmatureAnimation(); - virtual ~CCArmatureAnimation(void); + ArmatureAnimation(); + virtual ~ArmatureAnimation(void); /** - * Init with a CCArmature - * @param armature The CCArmature CCArmatureAnimation will bind to + * Init with a Armature + * @param armature The Armature ArmatureAnimation will bind to */ - virtual bool init(CCArmature *armature); + virtual bool init(Armature *armature); /** * Scale animation play speed. @@ -91,21 +91,21 @@ public: * @param durationTo The frames between two animation changing-over. * It's meaning is changing to this animation need how many frames * - * -1 : use the value from CCMovementData get from flash design panel + * -1 : use the value from MovementData get from flash design panel * @param durationTween The frame count you want to play in the game. * if _durationTween is 80, then the animation will played 80 frames in a loop * - * -1 : use the value from CCMovementData get from flash design panel + * -1 : use the value from MovementData get from flash design panel * * @param loop Whether the animation is loop * - * loop < 0 : use the value from CCMovementData get from flash design panel + * loop < 0 : use the value from MovementData get from flash design panel * loop = 0 : this animation is not loop * loop > 0 : this animation is loop * - * @param tweenEasing CCTween easing is used for calculate easing effect + * @param tweenEasing Tween easing is used for calculate easing effect * - * TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel + * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel * -1 : fade out * 0 : line * 1 : fade in @@ -174,30 +174,30 @@ protected: /** * Emit a frame event */ - void frameEvent(CCBone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex); + void frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex); - friend class CCTween; + friend class Tween; protected: - //! CCAnimationData save all MovementDatas this animation used. - CC_SYNTHESIZE_RETAIN(CCAnimationData *, m_pAnimationData, AnimationData); + //! AnimationData save all MovementDatas this animation used. + CC_SYNTHESIZE_RETAIN(AnimationData *, m_pAnimationData, AnimationData); //! Scale the animation speed float m_fSpeedScale; - CCMovementData *m_pMovementData; //! CCMovementData save all MovementFrameDatas this animation used. + MovementData *m_pMovementData; //! MovementData save all MovementFrameDatas this animation used. - CCArmature *m_pArmature; //! A weak reference of armature + Armature *m_pArmature; //! A weak reference of armature std::string m_strMovementID; //! Current movment's name - int m_iToIndex; //! The frame index in CCMovementData->m_pMovFrameDataArr, it's different from m_iFrameIndex. + int m_iToIndex; //! The frame index in MovementData->m_pMovFrameDataArr, it's different from m_iFrameIndex. Array *m_pTweenList; protected: /** * MovementEvent CallFunc. - * @param CCArmature* a CCArmature + * @param Armature* a Armature * @param MovementEventType, Event Type, like START, COMPLETE. * @param const char*, Movement ID, also called Movement Name */ @@ -205,7 +205,7 @@ protected: /** * FrameEvent CallFunc. - * @param CCBone*, a CCBone + * @param Bone*, a Bone * @param const char*, the name of this frame event * @param int, origin frame index * @param int, current frame index, animation may be delayed diff --git a/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp b/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp index 10317b0883..eee757a969 100644 --- a/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp +++ b/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp @@ -27,7 +27,7 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -CCProcessBase::CCProcessBase(void) +ProcessBase::ProcessBase(void) : m_fProcessScale(1) , m_bIsPause(true) , m_bIsComplete(true) @@ -49,25 +49,25 @@ CCProcessBase::CCProcessBase(void) } -CCProcessBase::~CCProcessBase(void) +ProcessBase::~ProcessBase(void) { } -void CCProcessBase::pause() +void ProcessBase::pause() { m_bIsPause = true; m_bIsPlaying = false; } -void CCProcessBase::resume() +void ProcessBase::resume() { m_bIsPause = false; m_bIsPlaying = true; } -void CCProcessBase::stop() +void ProcessBase::stop() { m_bIsComplete = true; m_bIsPlaying = false; @@ -75,7 +75,7 @@ void CCProcessBase::stop() m_fCurrentPercent = 0; } -void CCProcessBase::play(void *animation, int durationTo, int durationTween, int loop, int tweenEasing) +void ProcessBase::play(void *animation, int durationTo, int durationTween, int loop, int tweenEasing) { m_bIsComplete = false; m_bIsPause = false; @@ -91,7 +91,7 @@ void CCProcessBase::play(void *animation, int durationTo, int durationTween, in } -void CCProcessBase::update(float dt) +void ProcessBase::update(float dt) { if (m_bIsComplete || m_bIsPause) @@ -137,13 +137,13 @@ void CCProcessBase::update(float dt) -void CCProcessBase::gotoFrame(int frameIndex) +void ProcessBase::gotoFrame(int frameIndex) { m_iCurFrameIndex = frameIndex; pause(); } -int CCProcessBase::getCurrentFrameIndex() +int ProcessBase::getCurrentFrameIndex() { m_iCurFrameIndex = m_iRawDuration * m_fCurrentPercent; return m_iCurFrameIndex; diff --git a/extensions/CocoStudio/Armature/animation/CCProcessBase.h b/extensions/CocoStudio/Armature/animation/CCProcessBase.h index c9cf08b8cc..d94c175530 100644 --- a/extensions/CocoStudio/Armature/animation/CCProcessBase.h +++ b/extensions/CocoStudio/Armature/animation/CCProcessBase.h @@ -47,34 +47,34 @@ enum AnimationType }; -class CCProcessBase : public Object +class ProcessBase : public Object { public: - CCProcessBase(void); - ~CCProcessBase(void); + ProcessBase(void); + ~ProcessBase(void); /** * Play animation by animation name. * - * @param animation It will not used in the CCProcessBase Class + * @param animation It will not used in the ProcessBase Class * @param durationTo The frames between two animation changing-over. * It's meaning is changing to this animation need how many frames * - * -1 : use the value from CCMovementData get from flash design panel + * -1 : use the value from MovementData get from flash design panel * @param durationTween The frame count you want to play in the game. * if _durationTween is 80, then the animation will played 80 frames in a loop * - * -1 : use the value from CCMovementData get from flash design panel + * -1 : use the value from MovementData get from flash design panel * * @param loop Whether the animation is loop * - * loop < 0 : use the value from CCMovementData get from flash design panel + * loop < 0 : use the value from MovementData get from flash design panel * loop = 0 : this animation is not loop * loop > 0 : this animation is loop * - * @param tweenEasing CCTween easing is used for calculate easing effect + * @param tweenEasing Tween easing is used for calculate easing effect * - * TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel + * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel * -1 : fade out * 0 : line * 1 : fade in diff --git a/extensions/CocoStudio/Armature/animation/CCTween.cpp b/extensions/CocoStudio/Armature/animation/CCTween.cpp index bd0c09ba89..9cd15d9264 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.cpp +++ b/extensions/CocoStudio/Armature/animation/CCTween.cpp @@ -34,9 +34,9 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -CCTween *CCTween::create(CCBone *bone) +Tween *Tween::create(Bone *bone) { - CCTween *pTween = new CCTween(); + Tween *pTween = new Tween(); if (pTween && pTween->init(bone)) { pTween->autorelease(); @@ -49,7 +49,7 @@ CCTween *CCTween::create(CCBone *bone) -CCTween::CCTween() +Tween::Tween() : m_pMovementBoneData(NULL) , m_pTweenData(NULL) , m_pFrom(NULL) @@ -66,20 +66,20 @@ CCTween::CCTween() } -CCTween::~CCTween(void) +Tween::~Tween(void) { CC_SAFE_DELETE( m_pFrom ); CC_SAFE_DELETE( m_pBetween ); } -bool CCTween::init(CCBone *bone) +bool Tween::init(Bone *bone) { bool bRet = false; do { - m_pFrom = new CCFrameData(); - m_pBetween = new CCFrameData(); + m_pFrom = new FrameData(); + m_pBetween = new FrameData(); m_pBone = bone; m_pTweenData = m_pBone->getTweenData(); @@ -95,9 +95,9 @@ bool CCTween::init(CCBone *bone) } -void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing) +void Tween::play(MovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing) { - CCProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing); + ProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing); m_eLoopType = (AnimationType)loop; @@ -110,12 +110,12 @@ void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int dur setMovementBoneData(movementBoneData); m_iRawDuration = m_pMovementBoneData->duration; - CCFrameData *nextKeyFrame = m_pMovementBoneData->getFrameData(0); + FrameData *nextKeyFrame = m_pMovementBoneData->getFrameData(0); m_pTweenData->displayIndex = nextKeyFrame->displayIndex; if (m_pBone->getArmature()->getArmatureData()->dataVersion >= VERSION_COMBINED) { - CCTransformHelp::nodeSub(*m_pTweenData, *m_pBone->getBoneData()); + TransformHelp::nodeSub(*m_pTweenData, *m_pBone->getBoneData()); m_pTweenData->scaleX += 1; m_pTweenData->scaleY += 1; } @@ -166,7 +166,7 @@ void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int dur tweenNodeTo(0); } -void CCTween::updateHandler() +void Tween::updateHandler() { if (m_fCurrentPercent >= 1) { @@ -271,7 +271,7 @@ void CCTween::updateHandler() } } -void CCTween::setBetween(CCFrameData *from, CCFrameData *to) +void Tween::setBetween(FrameData *from, FrameData *to) { do { @@ -297,11 +297,11 @@ void CCTween::setBetween(CCFrameData *from, CCFrameData *to) } -void CCTween::arriveKeyFrame(CCFrameData *keyFrameData) +void Tween::arriveKeyFrame(FrameData *keyFrameData) { if(keyFrameData) { - CCDisplayManager *displayManager = m_pBone->getDisplayManager(); + DisplayManager *displayManager = m_pBone->getDisplayManager(); //! Change bone's display int displayIndex = keyFrameData->displayIndex; @@ -319,7 +319,7 @@ void CCTween::arriveKeyFrame(CCFrameData *keyFrameData) m_pBone->setBlendType(keyFrameData->blendType); //! Update child armature's movement - CCArmature *childAramture = m_pBone->getChildArmature(); + Armature *childAramture = m_pBone->getChildArmature(); if(childAramture) { if(keyFrameData->strMovement.length() != 0) @@ -330,7 +330,7 @@ void CCTween::arriveKeyFrame(CCFrameData *keyFrameData) } } -CCFrameData *CCTween::tweenNodeTo(float percent, CCFrameData *node) +FrameData *Tween::tweenNodeTo(float percent, FrameData *node) { node = node == NULL ? m_pTweenData : node; @@ -351,7 +351,7 @@ CCFrameData *CCTween::tweenNodeTo(float percent, CCFrameData *node) return node; } -void CCTween::tweenColorTo(float percent, CCFrameData *node) +void Tween::tweenColorTo(float percent, FrameData *node) { node->a = m_pFrom->a + percent * m_pBetween->a; node->r = m_pFrom->r + percent * m_pBetween->r; @@ -360,7 +360,7 @@ void CCTween::tweenColorTo(float percent, CCFrameData *node) m_pBone->updateColor(); } -float CCTween::updateFrameData(float currentPercent) +float Tween::updateFrameData(float currentPercent) { if (currentPercent > 1 && m_pMovementBoneData->delay != 0) { @@ -378,10 +378,10 @@ float CCTween::updateFrameData(float currentPercent) * m_iToIndex is next index will play */ int length = m_pMovementBoneData->frameList.count(); - CCFrameData **frames = (CCFrameData **)m_pMovementBoneData->frameList.data->arr; + FrameData **frames = (FrameData **)m_pMovementBoneData->frameList.data->arr; - CCFrameData *from = NULL; - CCFrameData *to = NULL; + FrameData *from = NULL; + FrameData *to = NULL; if (playedTime < frames[0]->frameID) { @@ -444,7 +444,7 @@ float CCTween::updateFrameData(float currentPercent) tweenType = (m_eTweenEasing == TWEEN_EASING_MAX) ? m_eFrameTweenEasing : m_eTweenEasing; if (tweenType != TWEEN_EASING_MAX && tweenType != Linear) { - currentPercent = CCTweenFunction::tweenTo(0, 1, currentPercent, 1, tweenType); + currentPercent = TweenFunction::tweenTo(0, 1, currentPercent, 1, tweenType); } } diff --git a/extensions/CocoStudio/Armature/animation/CCTween.h b/extensions/CocoStudio/Armature/animation/CCTween.h index 5570410bb0..acfb1e6ef1 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.h +++ b/extensions/CocoStudio/Armature/animation/CCTween.h @@ -31,56 +31,56 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -class CCBone; -class CCArmatureAnimation; +class Bone; +class ArmatureAnimation; -class CCTween : public CCProcessBase +class Tween : public ProcessBase { public: /** - * Create with a CCBone - * @param bone the CCBone CCTween will bind to + * Create with a Bone + * @param bone the Bone Tween will bind to */ - static CCTween *create(CCBone *bone); + static Tween *create(Bone *bone); public: - CCTween(void); - virtual ~CCTween(void); + Tween(void); + virtual ~Tween(void); /** - * Init with a CCBone - * @param bone the CCBone CCTween will bind to + * Init with a Bone + * @param bone the Bone Tween will bind to */ - virtual bool init(CCBone *bone); + virtual bool init(Bone *bone); /** * Start the Process * - * @param movementBoneData the CCMovementBoneData include all CCFrameData + * @param movementBoneData the MovementBoneData include all FrameData * @param durationTo the number of frames changing to this animation needs. * @param durationTween the number of frames this animation actual last. * * @param loop whether the animation is loop * - * loop < 0 : use the value from CCMovementData get from Action Editor + * loop < 0 : use the value from MovementData get from Action Editor * loop = 0 : this animation is not loop * loop > 0 : this animation is loop * * @param tweenEasing tween easing is used for calculate easing effect * - * TWEEN_EASING_MAX : use the value from CCMovementData get from Action Editor + * TWEEN_EASING_MAX : use the value from MovementData get from Action Editor * -1 : fade out * 0 : line * 1 : fade in * 2 : fade in and out * */ - virtual void play(CCMovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing); + virtual void play(MovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing); - inline void setAnimation(CCArmatureAnimation *animation) + inline void setAnimation(ArmatureAnimation *animation) { m_pAnimation = animation; } - inline CCArmatureAnimation *getAnimation() const + inline ArmatureAnimation *getAnimation() const { return m_pAnimation; } @@ -99,33 +99,33 @@ protected: /** * Calculate the between value of _from and _to, and give it to between frame data */ - virtual void setBetween(CCFrameData *from, CCFrameData *to); + virtual void setBetween(FrameData *from, FrameData *to); /** - * According to the percent to calculate current CCFrameData with tween effect + * According to the percent to calculate current FrameData with tween effect */ - virtual CCFrameData *tweenNodeTo(float percent, CCFrameData *node = NULL); + virtual FrameData *tweenNodeTo(float percent, FrameData *node = NULL); /** * According to the percent to calculate current color with tween effect */ - virtual void tweenColorTo(float percent, CCFrameData *node); + virtual void tweenColorTo(float percent, FrameData *node); /** * Update display index and process the key frame event when arrived a key frame */ - virtual void arriveKeyFrame(CCFrameData *keyFrameData); + virtual void arriveKeyFrame(FrameData *keyFrameData); protected: - //! A weak reference to the current CCMovementBoneData. The data is in the data pool - CC_SYNTHESIZE(CCMovementBoneData *, m_pMovementBoneData, MovementBoneData) + //! A weak reference to the current MovementBoneData. The data is in the data pool + CC_SYNTHESIZE(MovementBoneData *, m_pMovementBoneData, MovementBoneData) - CCFrameData *m_pTweenData; //! The computational tween frame data, //! A weak reference to the CCBone's tweenData - CCFrameData *m_pFrom; //! From frame data, used for calculate between value - CCFrameData *m_pTo; //! To frame data, used for calculate between value - CCFrameData *m_pBetween; //! Between frame data, used for calculate current CCFrameData(m_pNode) value + FrameData *m_pTweenData; //! The computational tween frame data, //! A weak reference to the Bone's tweenData + FrameData *m_pFrom; //! From frame data, used for calculate between value + FrameData *m_pTo; //! To frame data, used for calculate between value + FrameData *m_pBetween; //! Between frame data, used for calculate current FrameData(m_pNode) value - CCBone *m_pBone; //! A weak reference to the CCBone + Bone *m_pBone; //! A weak reference to the Bone CCTweenType m_eFrameTweenEasing; //! Dedermine which tween effect current frame use @@ -133,10 +133,10 @@ protected: int m_iTotalDuration; - int m_iFromIndex; //! The current frame index in FrameList of CCMovementBoneData, it's different from m_iFrameIndex - int m_iToIndex; //! The next frame index in FrameList of CCMovementBoneData, it's different from m_iFrameIndex + int m_iFromIndex; //! The current frame index in FrameList of MovementBoneData, it's different from m_iFrameIndex + int m_iToIndex; //! The next frame index in FrameList of MovementBoneData, it's different from m_iFrameIndex - CCArmatureAnimation *m_pAnimation; + ArmatureAnimation *m_pAnimation; }; diff --git a/extensions/CocoStudio/Armature/datas/CCDatas.cpp b/extensions/CocoStudio/Armature/datas/CCDatas.cpp index bba5f66db6..8b20214f68 100644 --- a/extensions/CocoStudio/Armature/datas/CCDatas.cpp +++ b/extensions/CocoStudio/Armature/datas/CCDatas.cpp @@ -29,7 +29,7 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -CCBaseData::CCBaseData() +BaseData::BaseData() : x(0.0f) , y(0.0f) , zOrder(0) @@ -49,11 +49,11 @@ CCBaseData::CCBaseData() { } -CCBaseData::~CCBaseData() +BaseData::~BaseData() { } -void CCBaseData::copy(const CCBaseData *node ) +void BaseData::copy(const BaseData *node ) { x = node->x; y = node->y; @@ -74,7 +74,7 @@ void CCBaseData::copy(const CCBaseData *node ) } -void CCBaseData::subtract(CCBaseData *from, CCBaseData *to) +void BaseData::subtract(BaseData *from, BaseData *to) { x = to->x - from->x; y = to->y - from->y; @@ -123,7 +123,7 @@ void CCBaseData::subtract(CCBaseData *from, CCBaseData *to) } } -void CCBaseData::setColor(const Color4B &color) +void BaseData::setColor(const Color4B &color) { r = color.r; g = color.g; @@ -131,12 +131,12 @@ void CCBaseData::setColor(const Color4B &color) a = color.a; } -Color4B CCBaseData::getColor() +Color4B BaseData::getColor() { return Color4B(r, g, b, a); } -const char *CCDisplayData::changeDisplayToTexture(const char *displayName) +const char *DisplayData::changeDisplayToTexture(const char *displayName) { // remove .xxx std::string textureName = displayName; @@ -150,26 +150,26 @@ const char *CCDisplayData::changeDisplayToTexture(const char *displayName) return textureName.c_str(); } -CCDisplayData::CCDisplayData(void) +DisplayData::DisplayData(void) : displayType(CS_DISPLAY_MAX) { } -CCDisplayData::~CCDisplayData(void) +DisplayData::~DisplayData(void) { } -CCSpriteDisplayData::CCSpriteDisplayData(void) +SpriteDisplayData::SpriteDisplayData(void) : displayName("") { displayType = CS_DISPLAY_SPRITE; } -CCSpriteDisplayData::~CCSpriteDisplayData() +SpriteDisplayData::~SpriteDisplayData() { } -void CCSpriteDisplayData::copy(CCSpriteDisplayData *displayData) +void SpriteDisplayData::copy(SpriteDisplayData *displayData) { displayName = displayData->displayName; displayType = displayData->displayType; @@ -177,87 +177,87 @@ void CCSpriteDisplayData::copy(CCSpriteDisplayData *displayData) skinData = displayData->skinData; } -CCArmatureDisplayData::CCArmatureDisplayData(void) +ArmatureDisplayData::ArmatureDisplayData(void) : displayName("") { displayType = CS_DISPLAY_ARMATURE; } -CCArmatureDisplayData::~CCArmatureDisplayData() +ArmatureDisplayData::~ArmatureDisplayData() { } -void CCArmatureDisplayData::copy(CCArmatureDisplayData *displayData) +void ArmatureDisplayData::copy(ArmatureDisplayData *displayData) { displayName = displayData->displayName; displayType = displayData->displayType; } -CCParticleDisplayData::CCParticleDisplayData(void) +ParticleDisplayData::ParticleDisplayData(void) : plist("") { displayType = CS_DISPLAY_PARTICLE; } -void CCParticleDisplayData::copy(CCParticleDisplayData *displayData) +void ParticleDisplayData::copy(ParticleDisplayData *displayData) { plist = displayData->plist; displayType = displayData->displayType; } -CCBoneData::CCBoneData(void) +BoneData::BoneData(void) : name("") , parentName("") { } -CCBoneData::~CCBoneData(void) +BoneData::~BoneData(void) { } -bool CCBoneData::init() +bool BoneData::init() { displayDataList.init(); return true; } -void CCBoneData::addDisplayData(CCDisplayData *displayData) +void BoneData::addDisplayData(DisplayData *displayData) { displayDataList.addObject(displayData); } -CCDisplayData *CCBoneData::getDisplayData(int index) +DisplayData *BoneData::getDisplayData(int index) { - return (CCDisplayData *)displayDataList.getObjectAtIndex(index); + return (DisplayData *)displayDataList.getObjectAtIndex(index); } -CCArmatureData::CCArmatureData() +ArmatureData::ArmatureData() : dataVersion(0.1f) { } -CCArmatureData::~CCArmatureData() +ArmatureData::~ArmatureData() { } -bool CCArmatureData::init() +bool ArmatureData::init() { return true; } -void CCArmatureData::addBoneData(CCBoneData *boneData) +void ArmatureData::addBoneData(BoneData *boneData) { boneDataDic.setObject(boneData, boneData->name); } -CCBoneData *CCArmatureData::getBoneData(const char *boneName) +BoneData *ArmatureData::getBoneData(const char *boneName) { - return (CCBoneData *)boneDataDic.objectForKey(boneName); + return (BoneData *)boneDataDic.objectForKey(boneName); } -CCFrameData::CCFrameData(void) +FrameData::FrameData(void) : frameID(0) , duration(1) , tweenEasing(Linear) @@ -271,15 +271,15 @@ CCFrameData::CCFrameData(void) { } -CCFrameData::~CCFrameData(void) +FrameData::~FrameData(void) { } -void CCFrameData::copy(const CCBaseData *baseData) +void FrameData::copy(const BaseData *baseData) { - CCBaseData::copy(baseData); + BaseData::copy(baseData); - if (const CCFrameData *frameData = dynamic_cast(baseData)) + if (const FrameData *frameData = dynamic_cast(baseData)) { duration = frameData->duration; displayIndex = frameData->displayIndex; @@ -288,7 +288,7 @@ void CCFrameData::copy(const CCBaseData *baseData) } } -CCMovementBoneData::CCMovementBoneData() +MovementBoneData::MovementBoneData() : delay(0.0f) , scale(1.0f) , duration(0) @@ -296,28 +296,28 @@ CCMovementBoneData::CCMovementBoneData() { } -CCMovementBoneData::~CCMovementBoneData(void) +MovementBoneData::~MovementBoneData(void) { } -bool CCMovementBoneData::init() +bool MovementBoneData::init() { return frameList.init(); } -void CCMovementBoneData::addFrameData(CCFrameData *frameData) +void MovementBoneData::addFrameData(FrameData *frameData) { frameList.addObject(frameData); } -CCFrameData *CCMovementBoneData::getFrameData(int index) +FrameData *MovementBoneData::getFrameData(int index) { - return (CCFrameData *)frameList.getObjectAtIndex(index); + return (FrameData *)frameList.getObjectAtIndex(index); } -CCMovementData::CCMovementData(void) +MovementData::MovementData(void) : name("") , duration(0) , scale(1.0f) @@ -328,70 +328,70 @@ CCMovementData::CCMovementData(void) { } -CCMovementData::~CCMovementData(void) +MovementData::~MovementData(void) { } -void CCMovementData::addMovementBoneData(CCMovementBoneData *movBoneData) +void MovementData::addMovementBoneData(MovementBoneData *movBoneData) { movBoneDataDic.setObject(movBoneData, movBoneData->name); } -CCMovementBoneData *CCMovementData::getMovementBoneData(const char *boneName) +MovementBoneData *MovementData::getMovementBoneData(const char *boneName) { - return (CCMovementBoneData *)movBoneDataDic.objectForKey(boneName); + return (MovementBoneData *)movBoneDataDic.objectForKey(boneName); } -CCAnimationData::CCAnimationData(void) +AnimationData::AnimationData(void) { } -CCAnimationData::~CCAnimationData(void) +AnimationData::~AnimationData(void) { } -void CCAnimationData::addMovement(CCMovementData *movData) +void AnimationData::addMovement(MovementData *movData) { movementDataDic.setObject(movData, movData->name); movementNames.push_back(movData->name); } -CCMovementData *CCAnimationData::getMovement(const char *movementName) +MovementData *AnimationData::getMovement(const char *movementName) { - return (CCMovementData *)movementDataDic.objectForKey(movementName); + return (MovementData *)movementDataDic.objectForKey(movementName); } -int CCAnimationData::getMovementCount() +int AnimationData::getMovementCount() { return movementDataDic.count(); } -CCContourData::CCContourData() +ContourData::ContourData() { } -CCContourData::~CCContourData() +ContourData::~ContourData() { } -bool CCContourData::init() +bool ContourData::init() { return vertexList.init(); } -void CCContourData::addVertex(Point *vertex) +void ContourData::addVertex(Point *vertex) { - CCContourVertex2 *vertex2 = new CCContourVertex2(vertex->x, vertex->y); + ContourVertex2 *vertex2 = new ContourVertex2(vertex->x, vertex->y); vertex2->autorelease(); vertexList.addObject(vertex2); } -CCTextureData::CCTextureData() +TextureData::TextureData() : height(0.0f) , width(0.0f) , pivotX(0.5f) @@ -400,23 +400,23 @@ CCTextureData::CCTextureData() { } -CCTextureData::~CCTextureData() +TextureData::~TextureData() { } -bool CCTextureData::init() +bool TextureData::init() { return contourDataList.init(); } -void CCTextureData::addContourData(CCContourData *contourData) +void TextureData::addContourData(ContourData *contourData) { contourDataList.addObject(contourData); } -CCContourData *CCTextureData::getContourData(int index) +ContourData *TextureData::getContourData(int index) { - return (CCContourData *)contourDataList.getObjectAtIndex(index); + return (ContourData *)contourDataList.getObjectAtIndex(index); } diff --git a/extensions/CocoStudio/Armature/datas/CCDatas.h b/extensions/CocoStudio/Armature/datas/CCDatas.h index 436c570cec..8325a24536 100644 --- a/extensions/CocoStudio/Armature/datas/CCDatas.h +++ b/extensions/CocoStudio/Armature/datas/CCDatas.h @@ -60,34 +60,34 @@ NS_CC_EXT_ARMATURE_BEGIN /** * The base node include a lot of attributes. */ -class CCBaseData : public Object +class BaseData : public Object { public: - CC_CREATE_NO_PARAM_NO_INIT(CCBaseData) + CC_CREATE_NO_PARAM_NO_INIT(BaseData) public: - CCBaseData(); - ~CCBaseData(void); + BaseData(); + ~BaseData(void); /* * Copy data from node - * @param node A CCBaseData to copy data + * @param node A BaseData to copy data */ - virtual void copy(const CCBaseData *node); + virtual void copy(const BaseData *node); /* - * Calculate two CCBaseData's between value(to - from) and set to self + * Calculate two BaseData's between value(to - from) and set to self * - * @param from from CCBaseData - * @param to to CCBaseData + * @param from from BaseData + * @param to to BaseData */ - virtual void subtract(CCBaseData *from, CCBaseData *to); + virtual void subtract(BaseData *from, BaseData *to); virtual void setColor(const Color4B &color); virtual Color4B getColor(); public: float x; //! position x attribute float y; //! position y attribute - int zOrder; //! zorder attribute, used to order the CCBone's depth order + int zOrder; //! zorder attribute, used to order the Bone's depth order /** * x y skewX skewY scaleX scaleY used to calculate transform matrix @@ -113,94 +113,94 @@ public: enum DisplayType { CS_DISPLAY_SPRITE, //! display is a single Sprite - CS_DISPLAY_ARMATURE, //! display is a CCArmature + CS_DISPLAY_ARMATURE, //! display is a Armature CS_DISPLAY_PARTICLE, //! display is a CCParticle. CS_DISPLAY_MAX }; -class CCDisplayData : public Object +class DisplayData : public Object { public: - CC_CREATE_NO_PARAM_NO_INIT(CCDisplayData) + CC_CREATE_NO_PARAM_NO_INIT(DisplayData) static const char *changeDisplayToTexture(const char *displayName); public: - CCDisplayData(); - virtual ~CCDisplayData(void); + DisplayData(); + virtual ~DisplayData(void); DisplayType displayType; //! mark which type your display is }; -class CCSpriteDisplayData : public CCDisplayData +class SpriteDisplayData : public DisplayData { public: - CC_CREATE_NO_PARAM_NO_INIT(CCSpriteDisplayData) + CC_CREATE_NO_PARAM_NO_INIT(SpriteDisplayData) public: - CCSpriteDisplayData(); - virtual ~CCSpriteDisplayData(); + SpriteDisplayData(); + virtual ~SpriteDisplayData(); inline void setParam(const char *displayName) { this->displayName = displayName; } - void copy(CCSpriteDisplayData *displayData); + void copy(SpriteDisplayData *displayData); public: /** - * If DisplayType is CS_DISPLAY_SPRITE, then CCBone will use this image name to create a Sprite from CCSpriteFrameCache. + * If DisplayType is CS_DISPLAY_SPRITE, then Bone will use this image name to create a Sprite from CCSpriteFrameCache. * It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use m_strDisplayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". * - * If DisplayType is CS_DISPLAY_ARMATURE, the name is the CCArmature's name. When CCBone init display and type is CS_DISPLAY_ARMATURE, - * then CCBone will create a CCArmature. + * If DisplayType is CS_DISPLAY_ARMATURE, the name is the Armature's name. When Bone init display and type is CS_DISPLAY_ARMATURE, + * then Bone will create a Armature. */ std::string displayName; - CCBaseData skinData; + BaseData skinData; }; -class CCArmatureDisplayData : public CCDisplayData +class ArmatureDisplayData : public DisplayData { public: - CC_CREATE_NO_PARAM_NO_INIT(CCArmatureDisplayData) + CC_CREATE_NO_PARAM_NO_INIT(ArmatureDisplayData) public: - CCArmatureDisplayData(); - virtual ~CCArmatureDisplayData(); + ArmatureDisplayData(); + virtual ~ArmatureDisplayData(); inline void setParam(const char *displayName) { this->displayName = displayName; } - void copy(CCArmatureDisplayData *displayData); + void copy(ArmatureDisplayData *displayData); public: /** - * If DisplayType is CS_DISPLAY_SPRITE, then CCBone will use this image name to create a Sprite from CCSpriteFrameCache. + * If DisplayType is CS_DISPLAY_SPRITE, then Bone will use this image name to create a Sprite from CCSpriteFrameCache. * It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use m_strDisplayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". * - * If DisplayType is CS_DISPLAY_ARMATURE, the name is the CCArmature's name. When CCBone init display and type is CS_DISPLAY_ARMATURE, - * then CCBone will create a CCArmature. + * If DisplayType is CS_DISPLAY_ARMATURE, the name is the Armature's name. When Bone init display and type is CS_DISPLAY_ARMATURE, + * then Bone will create a Armature. */ std::string displayName; }; -class CCParticleDisplayData : public CCDisplayData +class ParticleDisplayData : public DisplayData { public: - CC_CREATE_NO_PARAM_NO_INIT(CCParticleDisplayData) + CC_CREATE_NO_PARAM_NO_INIT(ParticleDisplayData) public: - CCParticleDisplayData(); - virtual ~CCParticleDisplayData() {}; + ParticleDisplayData(); + virtual ~ParticleDisplayData() {}; void setParam(const char *plist) { this->plist = plist; } - void copy(CCParticleDisplayData *displayData); + void copy(ParticleDisplayData *displayData); public: std::string plist; }; @@ -208,53 +208,53 @@ public: /** -* CCBoneData used to init a CCBone. -* CCBoneData keeps a CCDisplayData list, a CCBone can have many display to change. -* The display information saved in the CCDisplayData +* BoneData used to init a Bone. +* BoneData keeps a DisplayData list, a Bone can have many display to change. +* The display information saved in the DisplayData */ -class CCBoneData : public CCBaseData +class BoneData : public BaseData { public: - CC_CREATE_NO_PARAM(CCBoneData) + CC_CREATE_NO_PARAM(BoneData) public: - CCBoneData(void); - ~CCBoneData(void); + BoneData(void); + ~BoneData(void); virtual bool init(); - void addDisplayData(CCDisplayData *displayData); - CCDisplayData *getDisplayData(int index); + void addDisplayData(DisplayData *displayData); + DisplayData *getDisplayData(int index); public: std::string name; //! the bone's name std::string parentName; //! the bone parent's name - Array displayDataList; //! save CCDisplayData informations for the CCBone + Array displayDataList; //! save DisplayData informations for the Bone AffineTransform boneDataTransform; }; /** -* CCArmatureData saved the CCArmature name and Bonedata needed for the CCBones in this CCArmature -* When we create a CCArmature, we need to get each CCBone's CCBoneData as it's init information. -* So we can get a CCBoneData from the Dictionary saved in the CCArmatureData. +* ArmatureData saved the Armature name and Bonedata needed for the CCBones in this Armature +* When we create a Armature, we need to get each Bone's BoneData as it's init information. +* So we can get a BoneData from the Dictionary saved in the ArmatureData. */ -class CCArmatureData : public Object +class ArmatureData : public Object { public: - CC_CREATE_NO_PARAM(CCArmatureData) + CC_CREATE_NO_PARAM(ArmatureData) public: - CCArmatureData(); - ~CCArmatureData(); + ArmatureData(); + ~ArmatureData(); bool init(); - void addBoneData(CCBoneData *boneData); - CCBoneData *getBoneData(const char *boneName); + void addBoneData(BoneData *boneData); + BoneData *getBoneData(const char *boneName); public: std::string name; Dictionary boneDataDic; float dataVersion; }; -enum CCBlendType +enum BlendType { BLEND_NORMAL, BLEND_LAYER, @@ -273,15 +273,15 @@ enum CCBlendType }; -class CCFrameData : public CCBaseData +class FrameData : public BaseData { public: - CC_CREATE_NO_PARAM_NO_INIT(CCFrameData) + CC_CREATE_NO_PARAM_NO_INIT(FrameData) public: - CCFrameData(); - ~CCFrameData(); + FrameData(); + ~FrameData(); - virtual void copy(const CCBaseData *baseData); + virtual void copy(const BaseData *baseData); public: int frameID; int duration; //! The frame will last duration frames @@ -293,7 +293,7 @@ public: */ int displayIndex; - CCBlendType blendType; + BlendType blendType; std::string strEvent; /** @@ -305,38 +305,38 @@ public: }; -class CCMovementBoneData : public Object +class MovementBoneData : public Object { public: - CC_CREATE_NO_PARAM(CCMovementBoneData) + CC_CREATE_NO_PARAM(MovementBoneData) public: - CCMovementBoneData(); - ~CCMovementBoneData(void); + MovementBoneData(); + ~MovementBoneData(void); virtual bool init(); - void addFrameData(CCFrameData *frameData); - CCFrameData *getFrameData(int index); + void addFrameData(FrameData *frameData); + FrameData *getFrameData(int index); public: float delay; //! movement delay percent, this value can produce a delay effect float scale; //! scale this movement - float duration; //! this CCBone in this movement will last m_iDuration frames + float duration; //! this Bone in this movement will last m_iDuration frames std::string name; //! bone name Array frameList; }; -class CCMovementData : public Object +class MovementData : public Object { public: - CC_CREATE_NO_PARAM_NO_INIT(CCMovementData) + CC_CREATE_NO_PARAM_NO_INIT(MovementData) public: - CCMovementData(void); - ~CCMovementData(void); + MovementData(void); + ~MovementData(void); - void addMovementBoneData(CCMovementBoneData *movBoneData); - CCMovementBoneData *getMovementBoneData(const char *boneName); + void addMovementBoneData(MovementBoneData *movBoneData); + MovementBoneData *getMovementBoneData(const char *boneName); public: std::string name; int duration; //! the frames this movement will last @@ -362,34 +362,34 @@ public: /** * Which tween easing effect the movement use - * TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel + * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel */ CCTweenType tweenEasing; /** * @brief save movment bone data * @key const char * - * @value CCMovementBoneData * + * @value MovementBoneData * */ Dictionary movBoneDataDic; }; /** -* CCAnimationData include all movement infomation for the CCArmature -* The struct is CCAnimationData -> CCMovementData -> CCMovementBoneData -> CCFrameData +* AnimationData include all movement infomation for the Armature +* The struct is AnimationData -> MovementData -> MovementBoneData -> FrameData * -> MovementFrameData */ -class CCAnimationData : public Object +class AnimationData : public Object { public: - CC_CREATE_NO_PARAM_NO_INIT(CCAnimationData) + CC_CREATE_NO_PARAM_NO_INIT(AnimationData) public: - CCAnimationData(void); - ~CCAnimationData(void); + AnimationData(void); + ~AnimationData(void); - void addMovement(CCMovementData *movData); - CCMovementData *getMovement(const char *movementName); + void addMovement(MovementData *movData); + MovementData *getMovement(const char *movementName); int getMovementCount(); public: std::string name; @@ -398,9 +398,9 @@ public: }; -struct CCContourVertex2 : public Object +struct ContourVertex2 : public Object { - CCContourVertex2(float x, float y) + ContourVertex2(float x, float y) { this->x = x; this->y = y; @@ -411,15 +411,15 @@ struct CCContourVertex2 : public Object }; /* -* CCContourData include a contour vertex information +* ContourData include a contour vertex information */ -class CCContourData : public Object +class ContourData : public Object { public: - CC_CREATE_NO_PARAM(CCContourData) + CC_CREATE_NO_PARAM(ContourData) public: - CCContourData(); - ~CCContourData(void); + ContourData(); + ~ContourData(void); virtual bool init(); virtual void addVertex(Point *vertex); @@ -431,20 +431,20 @@ public: /* -* CCTextureData include a texture's information +* TextureData include a texture's information */ -class CCTextureData : public Object +class TextureData : public Object { public: - CC_CREATE_NO_PARAM(CCTextureData) + CC_CREATE_NO_PARAM(TextureData) public: - CCTextureData(); - ~CCTextureData(void); + TextureData(); + ~TextureData(void); virtual bool init(); - void addContourData(CCContourData *contourData); - CCContourData *getContourData(int index); + void addContourData(ContourData *contourData); + ContourData *getContourData(int index); public: float height; //! The texture's width, height diff --git a/extensions/CocoStudio/Armature/display/CCBatchNode.cpp b/extensions/CocoStudio/Armature/display/CCBatchNode.cpp index 87fe3ff580..c6d3cdcdd2 100644 --- a/extensions/CocoStudio/Armature/display/CCBatchNode.cpp +++ b/extensions/CocoStudio/Armature/display/CCBatchNode.cpp @@ -28,9 +28,9 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -CCBatchNode *CCBatchNode::create() +BatchNode *BatchNode::create() { - CCBatchNode *batchNode = new CCBatchNode(); + BatchNode *batchNode = new BatchNode(); if (batchNode && batchNode->init()) { batchNode->autorelease(); @@ -40,29 +40,29 @@ CCBatchNode *CCBatchNode::create() return NULL; } -CCBatchNode::CCBatchNode() +BatchNode::BatchNode() : m_pAtlas(NULL) { } -bool CCBatchNode::init() +bool BatchNode::init() { bool ret = Node::init(); setShaderProgram(CCShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return ret; } -void CCBatchNode::addChild(Node *child, int zOrder, int tag) +void BatchNode::addChild(Node *child, int zOrder, int tag) { Node::addChild(child, zOrder, tag); - CCArmature *armature = dynamic_cast(child); + Armature *armature = dynamic_cast(child); if (armature != NULL) { armature->setBatchNode(this); } } -void CCBatchNode::visit() +void BatchNode::visit() { // quick return if not visible. children won't be drawn. if (!_visible) @@ -91,13 +91,13 @@ void CCBatchNode::visit() kmGLPopMatrix(); } -void CCBatchNode::draw() +void BatchNode::draw() { CC_NODE_DRAW_SETUP(); Object *object = NULL; CCARRAY_FOREACH(_children, object) { - CCArmature *armature = dynamic_cast(object); + Armature *armature = dynamic_cast(object); if (armature) { armature->visit(); diff --git a/extensions/CocoStudio/Armature/display/CCBatchNode.h b/extensions/CocoStudio/Armature/display/CCBatchNode.h index 375472e988..97450519a8 100644 --- a/extensions/CocoStudio/Armature/display/CCBatchNode.h +++ b/extensions/CocoStudio/Armature/display/CCBatchNode.h @@ -29,12 +29,12 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -class CCBatchNode : public Node +class BatchNode : public Node { public: - static CCBatchNode *create(); + static BatchNode *create(); public: - CCBatchNode(); + BatchNode(); virtual bool init(); virtual void addChild(Node *child, int zOrder, int tag); diff --git a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp index bb65f5fc83..0351fd03b3 100644 --- a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp +++ b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp @@ -26,9 +26,9 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -CCDecorativeDisplay *CCDecorativeDisplay::create() +DecorativeDisplay *DecorativeDisplay::create() { - CCDecorativeDisplay *pDisplay = new CCDecorativeDisplay(); + DecorativeDisplay *pDisplay = new DecorativeDisplay(); if (pDisplay && pDisplay->init()) { pDisplay->autorelease(); @@ -38,7 +38,7 @@ CCDecorativeDisplay *CCDecorativeDisplay::create() return NULL; } -CCDecorativeDisplay::CCDecorativeDisplay() +DecorativeDisplay::DecorativeDisplay() : m_pDisplay(NULL) , m_pDisplayData(NULL) @@ -49,7 +49,7 @@ CCDecorativeDisplay::CCDecorativeDisplay() } -CCDecorativeDisplay::~CCDecorativeDisplay(void) +DecorativeDisplay::~DecorativeDisplay(void) { CC_SAFE_RELEASE_NULL(m_pDisplayData); CC_SAFE_RELEASE_NULL(m_pDisplay); @@ -59,7 +59,7 @@ CCDecorativeDisplay::~CCDecorativeDisplay(void) #endif } -bool CCDecorativeDisplay::init() +bool DecorativeDisplay::init() { return true; } diff --git a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h index e66de887fa..12902535b9 100644 --- a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h +++ b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h @@ -36,23 +36,23 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -class CCDecorativeDisplay: public Object +class DecorativeDisplay: public Object { public: - static CCDecorativeDisplay *create(); + static DecorativeDisplay *create(); public: - CCDecorativeDisplay(void); - ~CCDecorativeDisplay(void); + DecorativeDisplay(void); + ~DecorativeDisplay(void); virtual bool init(); protected: CC_SYNTHESIZE_RETAIN(Node *, m_pDisplay, Display); - CC_SYNTHESIZE_RETAIN(CCDisplayData *, m_pDisplayData, DisplayData); + CC_SYNTHESIZE_RETAIN(DisplayData *, m_pDisplayData, DisplayData); #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_SYNTHESIZE_RETAIN(CCColliderDetector *, m_pColliderDetector, ColliderDetector); + CC_SYNTHESIZE_RETAIN(ColliderDetector *, m_pColliderDetector, ColliderDetector); #endif }; diff --git a/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp b/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp index 451f79d4e8..f57a1e6519 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp +++ b/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp @@ -32,7 +32,7 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -void CCDisplayFactory::addDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) +void DisplayFactory::addDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) { switch(displayData->displayType) { @@ -50,7 +50,7 @@ void CCDisplayFactory::addDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay } } -void CCDisplayFactory::createDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) +void DisplayFactory::createDisplay(Bone *bone, DecorativeDisplay *decoDisplay) { switch(decoDisplay->getDisplayData()->displayType) { @@ -68,14 +68,14 @@ void CCDisplayFactory::createDisplay(CCBone *bone, CCDecorativeDisplay *decoDisp } } -void CCDisplayFactory::updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty) +void DisplayFactory::updateDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty) { CS_RETURN_IF(!decoDisplay); #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT if (dirty) { - CCColliderDetector *detector = decoDisplay->getColliderDetector(); + ColliderDetector *detector = decoDisplay->getColliderDetector(); if (detector) { do @@ -122,19 +122,19 @@ void CCDisplayFactory::updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisp -void CCDisplayFactory::addSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) +void DisplayFactory::addSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) { - CCSpriteDisplayData *sdp = CCSpriteDisplayData::create(); - sdp->copy((CCSpriteDisplayData *)displayData); + SpriteDisplayData *sdp = SpriteDisplayData::create(); + sdp->copy((SpriteDisplayData *)displayData); decoDisplay->setDisplayData(sdp); createSpriteDisplay(bone, decoDisplay); } -void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) +void DisplayFactory::createSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay) { - CCSkin *skin = NULL; + Skin *skin = NULL; - CCSpriteDisplayData *displayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData(); + SpriteDisplayData *displayData = (SpriteDisplayData *)decoDisplay->getDisplayData(); std::string textureName = displayData->displayName; size_t startPos = textureName.find_last_of("."); @@ -147,18 +147,18 @@ void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *de //! create display if(textureName.length() == 0) { - skin = CCSkin::create(); + skin = Skin::create(); } else { - skin = CCSkin::createWithSpriteFrameName((textureName + ".png").c_str()); + skin = Skin::createWithSpriteFrameName((textureName + ".png").c_str()); } skin->setBone(bone); initSpriteDisplay(bone, decoDisplay, displayData->displayName.c_str(), skin); - CCArmature *armature = bone->getArmature(); + Armature *armature = bone->getArmature(); if (armature) { if (armature->getArmatureData()->dataVersion >= VERSION_COMBINED) @@ -175,7 +175,7 @@ void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *de } -void CCDisplayFactory::initSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, const char *displayName, CCSkin *skin) +void DisplayFactory::initSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, const char *displayName, Skin *skin) { //! remove .xxx std::string textureName = displayName; @@ -186,7 +186,7 @@ void CCDisplayFactory::initSpriteDisplay(CCBone *bone, CCDecorativeDisplay *deco textureName = textureName.erase(startPos); } - CCTextureData *textureData = CCArmatureDataManager::sharedArmatureDataManager()->getTextureData(textureName.c_str()); + TextureData *textureData = ArmatureDataManager::sharedArmatureDataManager()->getTextureData(textureName.c_str()); if(textureData) { //! Init display anchorPoint, every Texture have a anchor point @@ -199,7 +199,7 @@ void CCDisplayFactory::initSpriteDisplay(CCBone *bone, CCDecorativeDisplay *deco { //! create ContourSprite - CCColliderDetector *colliderDetector = CCColliderDetector::create(bone); + ColliderDetector *colliderDetector = ColliderDetector::create(bone); colliderDetector->addContourDataList(&textureData->contourDataList); decoDisplay->setColliderDetector(colliderDetector); @@ -207,39 +207,39 @@ void CCDisplayFactory::initSpriteDisplay(CCBone *bone, CCDecorativeDisplay *deco #endif } -void CCDisplayFactory::updateSpriteDisplay(CCBone *bone, Node *display, float dt, bool dirty) +void DisplayFactory::updateSpriteDisplay(Bone *bone, Node *display, float dt, bool dirty) { CS_RETURN_IF(!dirty); - CCSkin *skin = (CCSkin *)display; + Skin *skin = (Skin *)display; skin->updateArmatureTransform(); } -void CCDisplayFactory::addArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) +void DisplayFactory::addArmatureDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) { - CCArmatureDisplayData *adp = CCArmatureDisplayData::create(); ; - adp->copy((CCArmatureDisplayData *)displayData); + ArmatureDisplayData *adp = ArmatureDisplayData::create(); ; + adp->copy((ArmatureDisplayData *)displayData); decoDisplay->setDisplayData(adp); createArmatureDisplay(bone, decoDisplay); } -void CCDisplayFactory::createArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) +void DisplayFactory::createArmatureDisplay(Bone *bone, DecorativeDisplay *decoDisplay) { - CCArmatureDisplayData *displayData = (CCArmatureDisplayData *)decoDisplay->getDisplayData(); + ArmatureDisplayData *displayData = (ArmatureDisplayData *)decoDisplay->getDisplayData(); - CCArmature *armature = CCArmature::create(displayData->displayName.c_str(), bone); + 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 - * CCArmature's bone children. + * Armature's bone children. */ armature->setName((bone->getName() + "_armatureChild").c_str()); decoDisplay->setDisplay(armature); } -void CCDisplayFactory::updateArmatureDisplay(CCBone *bone, Node *display, float dt, bool dirty) +void DisplayFactory::updateArmatureDisplay(Bone *bone, Node *display, float dt, bool dirty) { - CCArmature *armature = (CCArmature *)display; + Armature *armature = (Armature *)display; if(armature) { armature->sortAllChildren(); @@ -249,25 +249,25 @@ void CCDisplayFactory::updateArmatureDisplay(CCBone *bone, Node *display, float -void CCDisplayFactory::addParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) +void DisplayFactory::addParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData) { - CCParticleDisplayData *adp = CCParticleDisplayData::create(); ; - adp->copy((CCParticleDisplayData *)displayData); + ParticleDisplayData *adp = ParticleDisplayData::create(); ; + adp->copy((ParticleDisplayData *)displayData); decoDisplay->setDisplayData(adp); createParticleDisplay(bone, decoDisplay); } -void CCDisplayFactory::createParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) +void DisplayFactory::createParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay) { - CCParticleDisplayData *displayData = (CCParticleDisplayData *)decoDisplay->getDisplayData(); + ParticleDisplayData *displayData = (ParticleDisplayData *)decoDisplay->getDisplayData(); ParticleSystem *system = ParticleSystemQuad::create(displayData->plist.c_str()); decoDisplay->setDisplay(system); } -void CCDisplayFactory::updateParticleDisplay(CCBone *bone, Node *display, float dt, bool dirty) +void DisplayFactory::updateParticleDisplay(Bone *bone, Node *display, float dt, bool dirty) { ParticleSystem *system = (ParticleSystem *)display; - CCBaseData node; - CCTransformHelp::matrixToNode(bone->getNodeToArmatureTransform(), node); + BaseData node; + TransformHelp::matrixToNode(bone->getNodeToArmatureTransform(), node); system->setPosition(node.x, node.y); system->setScaleX(node.scaleX); system->setScaleY(node.scaleY); diff --git a/extensions/CocoStudio/Armature/display/CCDisplayFactory.h b/extensions/CocoStudio/Armature/display/CCDisplayFactory.h index bd3430344e..6df1fff7bb 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayFactory.h +++ b/extensions/CocoStudio/Armature/display/CCDisplayFactory.h @@ -30,31 +30,31 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -class CCSkin; -class CCBone; -class CCDecorativeDisplay; -class CCDisplayData; +class Skin; +class Bone; +class DecorativeDisplay; +class DisplayData; -class CCDisplayFactory +class DisplayFactory { public: - static void addDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); - static void createDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty); + 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 addSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); - static void createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void initSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, const char *displayName, CCSkin *skin); - static void updateSpriteDisplay(CCBone *bone, Node *display, 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, Node *display, float dt, bool dirty); - static void addArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); - static void createArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateArmatureDisplay(CCBone *bone, 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, Node *display, float dt, bool dirty); - static void addParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); - static void createParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateParticleDisplay(CCBone *bone, Node *display, float dt, bool dirty); + static void addParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay, DisplayData *displayData); + static void createParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay); + static void updateParticleDisplay(Bone *bone, Node *display, float dt, bool dirty); }; diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp index 10e70ad288..bdf9874625 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp +++ b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp @@ -30,9 +30,9 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -CCDisplayManager *CCDisplayManager::create(CCBone *bone) +DisplayManager *DisplayManager::create(Bone *bone) { - CCDisplayManager *pDisplayManager = new CCDisplayManager(); + DisplayManager *pDisplayManager = new DisplayManager(); if (pDisplayManager && pDisplayManager->init(bone)) { pDisplayManager->autorelease(); @@ -43,7 +43,7 @@ CCDisplayManager *CCDisplayManager::create(CCBone *bone) } -CCDisplayManager::CCDisplayManager() +DisplayManager::DisplayManager() : m_pDecoDisplayList(NULL) , m_pDisplayRenderNode(NULL) , m_pCurrentDecoDisplay(NULL) @@ -54,7 +54,7 @@ CCDisplayManager::CCDisplayManager() { } -CCDisplayManager::~CCDisplayManager() +DisplayManager::~DisplayManager() { CC_SAFE_DELETE(m_pDecoDisplayList); @@ -67,7 +67,7 @@ CCDisplayManager::~CCDisplayManager() } -bool CCDisplayManager::init(CCBone *bone) +bool DisplayManager::init(Bone *bone) { bool ret = false; @@ -86,21 +86,21 @@ bool CCDisplayManager::init(CCBone *bone) } -void CCDisplayManager::addDisplay(CCDisplayData *displayData, int index) +void DisplayManager::addDisplay(DisplayData *displayData, int index) { - CCDecorativeDisplay *decoDisplay = NULL; + DecorativeDisplay *decoDisplay = NULL; if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) { - decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); + decoDisplay = (DecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); } else { - decoDisplay = CCDecorativeDisplay::create(); + decoDisplay = DecorativeDisplay::create(); m_pDecoDisplayList->addObject(decoDisplay); } - CCDisplayFactory::addDisplay(m_pBone, decoDisplay, displayData); + DisplayFactory::addDisplay(m_pBone, decoDisplay, displayData); //! if changed display index is current display index, then change current display to the new display if(index == m_iDisplayIndex) @@ -110,50 +110,50 @@ void CCDisplayManager::addDisplay(CCDisplayData *displayData, int index) } } -void CCDisplayManager::addDisplay(Node *display, int index) +void DisplayManager::addDisplay(Node *display, int index) { - CCDecorativeDisplay *decoDisplay = NULL; + DecorativeDisplay *decoDisplay = NULL; if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) { - decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); + decoDisplay = (DecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); } else { - decoDisplay = CCDecorativeDisplay::create(); + decoDisplay = DecorativeDisplay::create(); m_pDecoDisplayList->addObject(decoDisplay); } - CCDisplayData *displayData = NULL; - if (CCSkin *skin = dynamic_cast(display)) + DisplayData *displayData = NULL; + if (Skin *skin = dynamic_cast(display)) { skin->setBone(m_pBone); - displayData = CCSpriteDisplayData::create(); + displayData = SpriteDisplayData::create(); - CCDisplayFactory::initSpriteDisplay(m_pBone, decoDisplay, skin->getDisplayName().c_str(), skin); + DisplayFactory::initSpriteDisplay(m_pBone, decoDisplay, skin->getDisplayName().c_str(), skin); - if (CCSpriteDisplayData *spriteDisplayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData()) + if (SpriteDisplayData *spriteDisplayData = (SpriteDisplayData *)decoDisplay->getDisplayData()) { skin->setSkinData(spriteDisplayData->skinData); } else { - CCBaseData baseData; + BaseData baseData; skin->setSkinData(baseData); } } else if (dynamic_cast(display)) { - displayData = CCParticleDisplayData::create(); + displayData = ParticleDisplayData::create(); } - else if(CCArmature *armature = dynamic_cast(display)) + else if(Armature *armature = dynamic_cast(display)) { - displayData = CCArmatureDisplayData::create(); + displayData = ArmatureDisplayData::create(); armature->setParentBone(m_pBone); } else { - displayData = CCDisplayData::create(); + displayData = DisplayData::create(); } decoDisplay->setDisplay(display); @@ -167,7 +167,7 @@ void CCDisplayManager::addDisplay(Node *display, int index) } } -void CCDisplayManager::removeDisplay(int index) +void DisplayManager::removeDisplay(int index) { m_pDecoDisplayList->removeObjectAtIndex(index); @@ -177,12 +177,12 @@ void CCDisplayManager::removeDisplay(int index) } } -Array *CCDisplayManager::getDecorativeDisplayList() +Array *DisplayManager::getDecorativeDisplayList() { return m_pDecoDisplayList; } -void CCDisplayManager::changeDisplayByIndex(int index, bool force) +void DisplayManager::changeDisplayByIndex(int index, bool force) { CCAssert( (m_pDecoDisplayList ? index < (int)m_pDecoDisplayList->count() : true), "the _index value is out of range"); @@ -207,12 +207,12 @@ void CCDisplayManager::changeDisplayByIndex(int index, bool force) } - CCDecorativeDisplay *decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(m_iDisplayIndex); + DecorativeDisplay *decoDisplay = (DecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(m_iDisplayIndex); setCurrentDecorativeDisplay(decoDisplay); } -void CCDisplayManager::setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisplay) +void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay) { #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT if (m_pCurrentDecoDisplay && m_pCurrentDecoDisplay->getColliderDetector()) @@ -233,7 +233,7 @@ void CCDisplayManager::setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisp Node *displayRenderNode = m_pCurrentDecoDisplay == NULL ? NULL : m_pCurrentDecoDisplay->getDisplay(); if (m_pDisplayRenderNode) { - if (dynamic_cast(m_pDisplayRenderNode) != NULL) + if (dynamic_cast(m_pDisplayRenderNode) != NULL) { m_pBone->setChildArmature(NULL); } @@ -245,7 +245,7 @@ void CCDisplayManager::setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisp if(m_pDisplayRenderNode) { - if (CCArmature *armature = dynamic_cast(m_pDisplayRenderNode)) + if (Armature *armature = dynamic_cast(m_pDisplayRenderNode)) { m_pBone->setChildArmature(armature); } @@ -265,27 +265,27 @@ void CCDisplayManager::setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisp } } -Node *CCDisplayManager::getDisplayRenderNode() +Node *DisplayManager::getDisplayRenderNode() { return m_pDisplayRenderNode; } -int CCDisplayManager::getCurrentDisplayIndex() +int DisplayManager::getCurrentDisplayIndex() { return m_iDisplayIndex; } -CCDecorativeDisplay *CCDisplayManager::getCurrentDecorativeDisplay() +DecorativeDisplay *DisplayManager::getCurrentDecorativeDisplay() { return m_pCurrentDecoDisplay; } -CCDecorativeDisplay *CCDisplayManager::getDecorativeDisplayByIndex( int index) +DecorativeDisplay *DisplayManager::getDecorativeDisplayByIndex( int index) { - return (CCDecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); + return (DecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); } -void CCDisplayManager::initDisplayList(CCBoneData *boneData) +void DisplayManager::initDisplayList(BoneData *boneData) { CC_SAFE_DELETE(m_pDecoDisplayList); m_pDecoDisplayList = Array::create(); @@ -297,19 +297,19 @@ void CCDisplayManager::initDisplayList(CCBoneData *boneData) Array *displayDataList = &boneData->displayDataList; CCARRAY_FOREACH(displayDataList, object) { - CCDisplayData *displayData = (CCDisplayData *)object; + DisplayData *displayData = (DisplayData *)object; - CCDecorativeDisplay *decoDisplay = CCDecorativeDisplay::create(); + DecorativeDisplay *decoDisplay = DecorativeDisplay::create(); decoDisplay->setDisplayData(displayData); - CCDisplayFactory::createDisplay(m_pBone, decoDisplay); + DisplayFactory::createDisplay(m_pBone, decoDisplay); m_pDecoDisplayList->addObject(decoDisplay); } } -bool CCDisplayManager::containPoint(Point &point) +bool DisplayManager::containPoint(Point &point) { if(!m_bVisible || m_iDisplayIndex < 0) { @@ -344,14 +344,14 @@ bool CCDisplayManager::containPoint(Point &point) return ret; } -bool CCDisplayManager::containPoint(float x, float y) +bool DisplayManager::containPoint(float x, float y) { Point p = Point(x, y); return containPoint(p); } -void CCDisplayManager::setVisible(bool visible) +void DisplayManager::setVisible(bool visible) { if(!m_pDisplayRenderNode) return; @@ -360,32 +360,32 @@ void CCDisplayManager::setVisible(bool visible) m_pDisplayRenderNode->setVisible(visible); } -bool CCDisplayManager::isVisible() +bool DisplayManager::isVisible() { return m_bVisible; } -Size CCDisplayManager::getContentSize() +Size DisplayManager::getContentSize() { CS_RETURN_IF(!m_pDisplayRenderNode) Size(0, 0); return m_pDisplayRenderNode->getContentSize(); } -Rect CCDisplayManager::getBoundingBox() +Rect DisplayManager::getBoundingBox() { CS_RETURN_IF(!m_pDisplayRenderNode) Rect(0, 0, 0, 0); return m_pDisplayRenderNode->getBoundingBox(); } -Point CCDisplayManager::getAnchorPoint() +Point DisplayManager::getAnchorPoint() { CS_RETURN_IF(!m_pDisplayRenderNode) Point(0, 0); return m_pDisplayRenderNode->getAnchorPoint(); } -Point CCDisplayManager::getAnchorPointInPoints() +Point DisplayManager::getAnchorPointInPoints() { CS_RETURN_IF(!m_pDisplayRenderNode) Point(0, 0); return m_pDisplayRenderNode->getAnchorPointInPoints(); diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.h b/extensions/CocoStudio/Armature/display/CCDisplayManager.h index 46da715c45..cacdfd6002 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.h +++ b/extensions/CocoStudio/Armature/display/CCDisplayManager.h @@ -31,26 +31,26 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -class CCBone; +class Bone; -//! CCDisplayManager manages CCBone's display -class CCDisplayManager : public Object +//! DisplayManager manages Bone's display +class DisplayManager : public Object { public: - static CCDisplayManager *create(CCBone *bone); + static DisplayManager *create(Bone *bone); public: - CCDisplayManager(); - ~CCDisplayManager(); + DisplayManager(); + ~DisplayManager(); - bool init(CCBone *bone); + bool init(Bone *bone); /** - * Use CCBoneData to init the display list. + * Use BoneData to init the display list. * 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 + * If the display is a Armature, then create a new Armature */ - virtual void initDisplayList(CCBoneData *boneData); + virtual void initDisplayList(BoneData *boneData); /** * Add display and use _DisplayData init the display. @@ -58,12 +58,12 @@ public: * 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 CCSpriteDisplayData param + * 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(CCDisplayData *displayData, int index); + void addDisplay(DisplayData *displayData, int index); void addDisplay(Node *display, int index); @@ -87,9 +87,9 @@ public: int getCurrentDisplayIndex(); - virtual void setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisplay); - virtual CCDecorativeDisplay *getCurrentDecorativeDisplay(); - virtual CCDecorativeDisplay *getDecorativeDisplayByIndex( int index); + virtual void setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay); + virtual DecorativeDisplay *getCurrentDecorativeDisplay(); + virtual DecorativeDisplay *getDecorativeDisplayByIndex( int index); /** * Sets whether the display is visible @@ -127,7 +127,7 @@ protected: //! Display render node. Node *m_pDisplayRenderNode; //! Include current display information, like contour sprite, etc. - CCDecorativeDisplay *m_pCurrentDecoDisplay; + DecorativeDisplay *m_pCurrentDecoDisplay; //! Current display index int m_iDisplayIndex; @@ -136,7 +136,7 @@ protected: //! Whether of not the bone is visible. Default is true bool m_bVisible; - CCBone *m_pBone; + Bone *m_pBone; }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCSkin.cpp b/extensions/CocoStudio/Armature/display/CCSkin.cpp index 0717146723..c3445a6e57 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.cpp +++ b/extensions/CocoStudio/Armature/display/CCSkin.cpp @@ -35,9 +35,9 @@ NS_CC_EXT_ARMATURE_BEGIN #define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__)) #endif -CCSkin *CCSkin::create() +Skin *Skin::create() { - CCSkin *skin = new CCSkin(); + Skin *skin = new Skin(); if(skin && skin->init()) { skin->autorelease(); @@ -47,9 +47,9 @@ CCSkin *CCSkin::create() return NULL; } -CCSkin *CCSkin::createWithSpriteFrameName(const char *pszSpriteFrameName) +Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName) { - CCSkin *skin = new CCSkin(); + Skin *skin = new Skin(); if(skin && skin->initWithSpriteFrameName(pszSpriteFrameName)) { skin->autorelease(); @@ -59,9 +59,9 @@ CCSkin *CCSkin::createWithSpriteFrameName(const char *pszSpriteFrameName) return NULL; } -CCSkin *CCSkin::create(const char *pszFileName) +Skin *Skin::create(const char *pszFileName) { - CCSkin *skin = new CCSkin(); + Skin *skin = new Skin(); if(skin && skin->initWithFile(pszFileName)) { skin->autorelease(); @@ -71,20 +71,20 @@ CCSkin *CCSkin::create(const char *pszFileName) return NULL; } -CCSkin::CCSkin() +Skin::Skin() : m_pBone(NULL) , m_strDisplayName("") { m_tSkinTransform = AffineTransformIdentity; } -bool CCSkin::initWithSpriteFrameName(const char *pszSpriteFrameName) +bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) { bool ret = Sprite::initWithSpriteFrameName(pszSpriteFrameName); if (ret) { - TextureAtlas *atlas = CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); + TextureAtlas *atlas = SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); setTextureAtlas(atlas); m_strDisplayName = pszSpriteFrameName; @@ -93,13 +93,13 @@ bool CCSkin::initWithSpriteFrameName(const char *pszSpriteFrameName) return ret; } -bool CCSkin::initWithFile(const char *pszFilename) +bool Skin::initWithFile(const char *pszFilename) { bool ret = Sprite::initWithFile(pszFilename); if (ret) { - TextureAtlas *atlas = CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); + TextureAtlas *atlas = SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); setTextureAtlas(atlas); m_strDisplayName = pszFilename; @@ -108,7 +108,7 @@ bool CCSkin::initWithFile(const char *pszFilename) return ret; } -void CCSkin::setSkinData(const CCBaseData &var) +void Skin::setSkinData(const BaseData &var) { m_sSkinData = var; @@ -120,17 +120,17 @@ void CCSkin::setSkinData(const CCBaseData &var) m_tSkinTransform = getNodeToParentTransform(); } -const CCBaseData &CCSkin::getSkinData() const +const BaseData &Skin::getSkinData() const { return m_sSkinData; } -void CCSkin::updateArmatureTransform() +void Skin::updateArmatureTransform() { _transform = AffineTransformConcat(m_tSkinTransform, m_pBone->getNodeToArmatureTransform()); } -void CCSkin::updateTransform() +void Skin::updateTransform() { // If it is not visible, or one of its ancestors is not visible, then do nothing: if( !_visible) @@ -183,12 +183,12 @@ void CCSkin::updateTransform() } } -AffineTransform CCSkin::getNodeToWorldTransform() const +AffineTransform Skin::getNodeToWorldTransform() const { return AffineTransformConcat(_transform, m_pBone->getArmature()->getNodeToWorldTransform()); } -AffineTransform CCSkin::getNodeToWorldTransformAR() const +AffineTransform Skin::getNodeToWorldTransformAR() const { AffineTransform displayTransform = _transform; Point anchorPoint = _anchorPointInPoints; diff --git a/extensions/CocoStudio/Armature/display/CCSkin.h b/extensions/CocoStudio/Armature/display/CCSkin.h index d7afa85e7d..10f9d7e38d 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.h +++ b/extensions/CocoStudio/Armature/display/CCSkin.h @@ -30,14 +30,14 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -class CCSkin : public Sprite +class Skin : public Sprite { public: - static CCSkin *create(); - static CCSkin *createWithSpriteFrameName(const char *pszSpriteFrameName); - static CCSkin *create(const char *pszFileName); + static Skin *create(); + static Skin *createWithSpriteFrameName(const char *pszSpriteFrameName); + static Skin *create(const char *pszFileName); public: - CCSkin(); + Skin(); bool initWithSpriteFrameName(const char *pszSpriteFrameName); bool initWithFile(const char *pszFilename); @@ -48,8 +48,8 @@ public: AffineTransform getNodeToWorldTransform() const; AffineTransform getNodeToWorldTransformAR() const; - CC_PROPERTY_PASS_BY_REF(CCBaseData, m_sSkinData, SkinData); - CC_SYNTHESIZE(CCBone *, m_pBone, Bone); + CC_PROPERTY_PASS_BY_REF(BaseData, m_sSkinData, SkinData); + CC_SYNTHESIZE(Bone *, m_pBone, Bone); protected: AffineTransform m_tSkinTransform; diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp index 459208a80a..5cfb193a04 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp @@ -37,7 +37,7 @@ NS_CC_EXT_ARMATURE_BEGIN #if ENABLE_PHYSICS_BOX2D_DETECT -ColliderBody::ColliderBody(CCContourData *contourData) +ColliderBody::ColliderBody(ContourData *contourData) : m_pFixture(NULL) , m_pFilter(NULL) , m_pContourData(contourData) @@ -46,7 +46,7 @@ ColliderBody::ColliderBody(CCContourData *contourData) } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT -ColliderBody::ColliderBody(CCContourData *contourData) +ColliderBody::ColliderBody(ContourData *contourData) : m_pShape(NULL) , m_pContourData(contourData) { @@ -65,9 +65,9 @@ ColliderBody::~ColliderBody() -CCColliderDetector *CCColliderDetector::create() +ColliderDetector *ColliderDetector::create() { - CCColliderDetector *pColliderDetector = new CCColliderDetector(); + ColliderDetector *pColliderDetector = new ColliderDetector(); if (pColliderDetector && pColliderDetector->init()) { pColliderDetector->autorelease(); @@ -77,9 +77,9 @@ CCColliderDetector *CCColliderDetector::create() return NULL; } -CCColliderDetector *CCColliderDetector::create(CCBone *bone) +ColliderDetector *ColliderDetector::create(Bone *bone) { - CCColliderDetector *pColliderDetector = new CCColliderDetector(); + ColliderDetector *pColliderDetector = new ColliderDetector(); if (pColliderDetector && pColliderDetector->init(bone)) { pColliderDetector->autorelease(); @@ -89,7 +89,7 @@ CCColliderDetector *CCColliderDetector::create(CCBone *bone) return NULL; } -CCColliderDetector::CCColliderDetector() +ColliderDetector::ColliderDetector() : m_pColliderBodyList(NULL) , m_bActive(false) { @@ -100,13 +100,13 @@ CCColliderDetector::CCColliderDetector() #endif } -CCColliderDetector::~CCColliderDetector() +ColliderDetector::~ColliderDetector() { m_pColliderBodyList->removeAllObjects(); CC_SAFE_DELETE(m_pColliderBodyList); } -bool CCColliderDetector::init() +bool ColliderDetector::init() { m_pColliderBodyList = Array::create(); CCAssert(m_pColliderBodyList, "create m_pColliderBodyList failed!"); @@ -115,7 +115,7 @@ bool CCColliderDetector::init() return true; } -bool CCColliderDetector::init(CCBone *bone) +bool ColliderDetector::init(Bone *bone) { init(); setBone(bone); @@ -123,23 +123,23 @@ bool CCColliderDetector::init(CCBone *bone) return true; } -void CCColliderDetector::addContourData(CCContourData *contourData) +void ColliderDetector::addContourData(ContourData *contourData) { ColliderBody *colliderBody = new ColliderBody(contourData); m_pColliderBodyList->addObject(colliderBody); colliderBody->release(); } -void CCColliderDetector::addContourDataList(Array *contourDataList) +void ColliderDetector::addContourDataList(Array *contourDataList) { Object *object = NULL; CCARRAY_FOREACH(contourDataList, object) { - addContourData((CCContourData *)object); + addContourData((ContourData *)object); } } -void CCColliderDetector::removeContourData(CCContourData *contourData) +void ColliderDetector::removeContourData(ContourData *contourData) { Object *object = NULL; CCARRAY_FOREACH(m_pColliderBodyList, object) @@ -152,13 +152,13 @@ void CCColliderDetector::removeContourData(CCContourData *contourData) } } -void CCColliderDetector::removeAll() +void ColliderDetector::removeAll() { m_pColliderBodyList->removeAllObjects(); } -void CCColliderDetector::setActive(bool active) +void ColliderDetector::setActive(bool active) { if (m_bActive == active) { @@ -216,12 +216,12 @@ void CCColliderDetector::setActive(bool active) #endif } -bool CCColliderDetector::getActive() +bool ColliderDetector::getActive() { return m_bActive; } -Array *CCColliderDetector::getColliderBodyList() +Array *ColliderDetector::getColliderBodyList() { return m_pColliderBodyList; } @@ -229,7 +229,7 @@ Array *CCColliderDetector::getColliderBodyList() Point helpPoint; -void CCColliderDetector::updateTransform(AffineTransform &t) +void ColliderDetector::updateTransform(AffineTransform &t) { if (!m_bActive) { @@ -240,7 +240,7 @@ void CCColliderDetector::updateTransform(AffineTransform &t) CCARRAY_FOREACH(m_pColliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; - CCContourData *contourData = colliderBody->getContourData(); + ContourData *contourData = colliderBody->getContourData(); #if ENABLE_PHYSICS_BOX2D_DETECT b2PolygonShape *shape = NULL; @@ -257,7 +257,7 @@ void CCColliderDetector::updateTransform(AffineTransform &t) #endif int num = contourData->vertexList.count(); - CCContourVertex2 **vs = (CCContourVertex2 **)contourData->vertexList.data->arr; + ContourVertex2 **vs = (ContourVertex2 **)contourData->vertexList.data->arr; for (int i = 0; i < num; i++) { @@ -298,7 +298,7 @@ void CCColliderDetector::updateTransform(AffineTransform &t) #if ENABLE_PHYSICS_BOX2D_DETECT -void CCColliderDetector::setBody(b2Body *pBody) +void ColliderDetector::setBody(b2Body *pBody) { m_pBody = pBody; @@ -307,7 +307,7 @@ void CCColliderDetector::setBody(b2Body *pBody) { ColliderBody *colliderBody = (ColliderBody *)object; - CCContourData *contourData = colliderBody->getContourData(); + ContourData *contourData = colliderBody->getContourData(); const Array *array = &contourData->vertexList; Object *object = NULL; @@ -316,7 +316,7 @@ void CCColliderDetector::setBody(b2Body *pBody) int i = 0; CCARRAY_FOREACH(array, object) { - CCContourVertex2 *v = (CCContourVertex2 *)object; + ContourVertex2 *v = (ContourVertex2 *)object; b2bv[i].Set(v->x / PT_RATIO, v->y / PT_RATIO); i++; } @@ -351,13 +351,13 @@ void CCColliderDetector::setBody(b2Body *pBody) } } -b2Body *CCColliderDetector::getBody() +b2Body *ColliderDetector::getBody() { return m_pBody; } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT -void CCColliderDetector::setBody(cpBody *pBody) +void ColliderDetector::setBody(cpBody *pBody) { m_pBody = pBody; @@ -366,10 +366,10 @@ void CCColliderDetector::setBody(cpBody *pBody) { ColliderBody *colliderBody = (ColliderBody *)object; - CCContourData *contourData = colliderBody->getContourData(); + ContourData *contourData = colliderBody->getContourData(); int num = contourData->vertexList.count(); - CCContourVertex2 **vs = (CCContourVertex2 **)contourData->vertexList.data->arr; + ContourVertex2 **vs = (ContourVertex2 **)contourData->vertexList.data->arr; cpVect *verts = new cpVect[num]; for (int i = 0; i < num; i++) { @@ -389,7 +389,7 @@ void CCColliderDetector::setBody(cpBody *pBody) } } -cpBody *CCColliderDetector::getBody() +cpBody *ColliderDetector::getBody() { return m_pBody; } diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.h b/extensions/CocoStudio/Armature/physics/CCColliderDetector.h index f97582069a..250fbdc665 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.h +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.h @@ -42,7 +42,7 @@ struct cpShape; NS_CC_EXT_ARMATURE_BEGIN -class CCBone; +class Bone; class ColliderBody : public Object { @@ -56,36 +56,36 @@ public: #endif public: - ColliderBody(CCContourData *contourData); + ColliderBody(ContourData *contourData); ~ColliderBody(); - inline CCContourData *getContourData() + inline ContourData *getContourData() { return m_pContourData; } private: - CCContourData *m_pContourData; + ContourData *m_pContourData; }; /* * @brief ContourSprite used to draw the contour of the display */ -class CCColliderDetector : public Object +class ColliderDetector : public Object { public: - static CCColliderDetector *create(); - static CCColliderDetector *create(CCBone *bone); + static ColliderDetector *create(); + static ColliderDetector *create(Bone *bone); public: - CCColliderDetector(); - ~CCColliderDetector(void); + ColliderDetector(); + ~ColliderDetector(void); virtual bool init(); - virtual bool init(CCBone *bone); + virtual bool init(Bone *bone); - void addContourData(CCContourData *contourData); + void addContourData(ContourData *contourData); void addContourDataList(Array *contourDataList); - void removeContourData(CCContourData *contourData); + void removeContourData(ContourData *contourData); void removeAll(); void updateTransform(AffineTransform &t); @@ -97,7 +97,7 @@ public: protected: Array *m_pColliderBodyList; - CC_SYNTHESIZE(CCBone *, m_pBone, Bone); + CC_SYNTHESIZE(Bone *, m_pBone, Bone); #if ENABLE_PHYSICS_BOX2D_DETECT CC_PROPERTY(b2Body *, m_pBody, Body); diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp index cda72df978..02d909a9cf 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp @@ -31,13 +31,13 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -static CCArmatureDataManager *s_sharedArmatureDataManager = NULL; +static ArmatureDataManager *s_sharedArmatureDataManager = NULL; -CCArmatureDataManager *CCArmatureDataManager::sharedArmatureDataManager() +ArmatureDataManager *ArmatureDataManager::sharedArmatureDataManager() { if (s_sharedArmatureDataManager == NULL) { - s_sharedArmatureDataManager = new CCArmatureDataManager(); + s_sharedArmatureDataManager = new ArmatureDataManager(); if (!s_sharedArmatureDataManager || !s_sharedArmatureDataManager->init()) { CC_SAFE_DELETE(s_sharedArmatureDataManager); @@ -46,14 +46,14 @@ CCArmatureDataManager *CCArmatureDataManager::sharedArmatureDataManager() return s_sharedArmatureDataManager; } -void CCArmatureDataManager::purge() +void ArmatureDataManager::purge() { - CCSpriteFrameCacheHelper::purge(); - CCDataReaderHelper::purge(); + SpriteFrameCacheHelper::purge(); + DataReaderHelper::purge(); CC_SAFE_RELEASE_NULL(s_sharedArmatureDataManager); } -CCArmatureDataManager::CCArmatureDataManager(void) +ArmatureDataManager::ArmatureDataManager(void) { m_pArmarureDatas = NULL; m_pAnimationDatas = NULL; @@ -62,7 +62,7 @@ CCArmatureDataManager::CCArmatureDataManager(void) } -CCArmatureDataManager::~CCArmatureDataManager(void) +ArmatureDataManager::~ArmatureDataManager(void) { removeAll(); @@ -72,21 +72,21 @@ CCArmatureDataManager::~CCArmatureDataManager(void) } -bool CCArmatureDataManager::init() +bool ArmatureDataManager::init() { bool bRet = false; do { m_pArmarureDatas = Dictionary::create(); - CCAssert(m_pArmarureDatas, "create CCArmatureDataManager::m_pArmarureDatas fail!"); + CCAssert(m_pArmarureDatas, "create ArmatureDataManager::m_pArmarureDatas fail!"); m_pArmarureDatas->retain(); m_pAnimationDatas = Dictionary::create(); - CCAssert(m_pAnimationDatas, "create CCArmatureDataManager::m_pAnimationDatas fail!"); + CCAssert(m_pAnimationDatas, "create ArmatureDataManager::m_pAnimationDatas fail!"); m_pAnimationDatas->retain(); m_pTextureDatas = Dictionary::create(); - CCAssert(m_pTextureDatas, "create CCArmatureDataManager::m_pTextureDatas fail!"); + CCAssert(m_pTextureDatas, "create ArmatureDataManager::m_pTextureDatas fail!"); m_pTextureDatas->retain(); bRet = true; @@ -96,7 +96,7 @@ bool CCArmatureDataManager::init() return bRet; } -void CCArmatureDataManager::addArmatureData(const char *id, CCArmatureData *armatureData) +void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData) { if(m_pArmarureDatas) { @@ -104,17 +104,17 @@ void CCArmatureDataManager::addArmatureData(const char *id, CCArmatureData *arma } } -CCArmatureData *CCArmatureDataManager::getArmatureData(const char *id) +ArmatureData *ArmatureDataManager::getArmatureData(const char *id) { - CCArmatureData *armatureData = NULL; + ArmatureData *armatureData = NULL; if (m_pArmarureDatas) { - armatureData = (CCArmatureData *)m_pArmarureDatas->objectForKey(id); + armatureData = (ArmatureData *)m_pArmarureDatas->objectForKey(id); } return armatureData; } -void CCArmatureDataManager::removeArmatureData(const char *id) +void ArmatureDataManager::removeArmatureData(const char *id) { if (m_pArmarureDatas) { @@ -122,7 +122,7 @@ void CCArmatureDataManager::removeArmatureData(const char *id) } } -void CCArmatureDataManager::addAnimationData(const char *id, CCAnimationData *animationData) +void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData) { if(m_pAnimationDatas) { @@ -130,17 +130,17 @@ void CCArmatureDataManager::addAnimationData(const char *id, CCAnimationData *an } } -CCAnimationData *CCArmatureDataManager::getAnimationData(const char *id) +AnimationData *ArmatureDataManager::getAnimationData(const char *id) { - CCAnimationData *animationData = NULL; + AnimationData *animationData = NULL; if (m_pAnimationDatas) { - animationData = (CCAnimationData *)m_pAnimationDatas->objectForKey(id); + animationData = (AnimationData *)m_pAnimationDatas->objectForKey(id); } return animationData; } -void CCArmatureDataManager::removeAnimationData(const char *id) +void ArmatureDataManager::removeAnimationData(const char *id) { if (m_pAnimationDatas) { @@ -148,7 +148,7 @@ void CCArmatureDataManager::removeAnimationData(const char *id) } } -void CCArmatureDataManager::addTextureData(const char *id, CCTextureData *textureData) +void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData) { if(m_pTextureDatas) { @@ -157,18 +157,18 @@ void CCArmatureDataManager::addTextureData(const char *id, CCTextureData *textur } -CCTextureData *CCArmatureDataManager::getTextureData(const char *id) +TextureData *ArmatureDataManager::getTextureData(const char *id) { - CCTextureData *textureData = NULL; + TextureData *textureData = NULL; if (m_pTextureDatas) { - textureData = (CCTextureData *)m_pTextureDatas->objectForKey(id); + textureData = (TextureData *)m_pTextureDatas->objectForKey(id); } return textureData; } -void CCArmatureDataManager::removeTextureData(const char *id) +void ArmatureDataManager::removeTextureData(const char *id) { if(m_pTextureDatas) { @@ -176,39 +176,39 @@ void CCArmatureDataManager::removeTextureData(const char *id) } } -void CCArmatureDataManager::addArmatureFileInfo(const char *configFilePath) +void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath) { m_bAutoLoadSpriteFile = true; - CCDataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); + DataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); } -void CCArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector) +void ArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector) { m_bAutoLoadSpriteFile = true; - CCDataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); + DataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); } -void CCArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) +void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) { m_bAutoLoadSpriteFile = false; - CCDataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); + DataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); addSpriteFrameFromFile(plistPath, imagePath); } -void CCArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector) +void ArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector) { m_bAutoLoadSpriteFile = false; - CCDataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); + DataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); addSpriteFrameFromFile(plistPath, imagePath); } -void CCArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) +void ArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) { - CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath); + SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath); } -void CCArmatureDataManager::removeAll() +void ArmatureDataManager::removeAll() { if( m_pAnimationDatas ) { @@ -224,23 +224,23 @@ void CCArmatureDataManager::removeAll() m_pTextureDatas->removeAllObjects(); } - CCDataReaderHelper::clear(); + DataReaderHelper::clear(); } -bool CCArmatureDataManager::isAutoLoadSpriteFile() +bool ArmatureDataManager::isAutoLoadSpriteFile() { return m_bAutoLoadSpriteFile; } -Dictionary *CCArmatureDataManager::getArmatureDatas() const +Dictionary *ArmatureDataManager::getArmatureDatas() const { return m_pArmarureDatas; } -Dictionary *CCArmatureDataManager::getAnimationDatas() const +Dictionary *ArmatureDataManager::getAnimationDatas() const { return m_pAnimationDatas; } -Dictionary *CCArmatureDataManager::getTextureDatas() const +Dictionary *ArmatureDataManager::getTextureDatas() const { return m_pTextureDatas; } diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h index 62f9a558ae..13cefebe34 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h @@ -34,36 +34,36 @@ NS_CC_EXT_ARMATURE_BEGIN /** * @brief format and manage armature configuration and armature animation */ -class CCArmatureDataManager : public Object +class ArmatureDataManager : public Object { public: - static CCArmatureDataManager *sharedArmatureDataManager(); + static ArmatureDataManager *sharedArmatureDataManager(); static void purge(); private: - CCArmatureDataManager(void); - ~CCArmatureDataManager(void); + ArmatureDataManager(void); + ~ArmatureDataManager(void); public: /** - * Init CCArmatureDataManager + * Init ArmatureDataManager */ virtual bool init(); /** * Add armature data * @param id The id of the armature data - * @param armatureData CCArmatureData * + * @param armatureData ArmatureData * */ - void addArmatureData(const char *id, CCArmatureData *armatureData); + void addArmatureData(const char *id, ArmatureData *armatureData); /** * @brief get armature data * @param id the id of the armature data you want to get - * @return CCArmatureData * + * @return ArmatureData * */ - CCArmatureData *getArmatureData(const char *id); + ArmatureData *getArmatureData(const char *id); /** * @brief remove armature data @@ -74,16 +74,16 @@ public: /** * @brief add animation data * @param id the id of the animation data - * @return CCAnimationData * + * @return AnimationData * */ - void addAnimationData(const char *id, CCAnimationData *animationData); + void addAnimationData(const char *id, AnimationData *animationData); /** * @brief get animation data from m_pAnimationDatas(Dictionary) * @param id the id of the animation data you want to get - * @return CCAnimationData * + * @return AnimationData * */ - CCAnimationData *getAnimationData(const char *id); + AnimationData *getAnimationData(const char *id); /** * @brief remove animation data @@ -94,16 +94,16 @@ public: /** * @brief add texture data * @param id the id of the texture data - * @return CCTextureData * + * @return TextureData * */ - void addTextureData(const char *id, CCTextureData *textureData); + void addTextureData(const char *id, TextureData *textureData); /** * @brief get texture data * @param id the id of the texture data you want to get - * @return CCTextureData * + * @return TextureData * */ - CCTextureData *getTextureData(const char *id); + TextureData *getTextureData(const char *id); /** * @brief remove texture data @@ -112,23 +112,23 @@ public: void removeTextureData(const char *id); /** - * @brief Add ArmatureFileInfo, it is managed by CCArmatureDataManager. + * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. */ void addArmatureFileInfo(const char *configFilePath); /** - * @brief Add ArmatureFileInfo, it is managed by CCArmatureDataManager. + * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. * It will load data in a new thread */ void addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector); /** - * @brief Add ArmatureFileInfo, it is managed by CCArmatureDataManager. + * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. */ void addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath); /** - * @brief Add ArmatureFileInfo, it is managed by CCArmatureDataManager. + * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. * It will load data in a new thread */ void addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector); @@ -157,21 +157,21 @@ private: /** * @brief save amature datas * @key std::string - * @value CCArmatureData * + * @value ArmatureData * */ Dictionary *m_pArmarureDatas; /** * @brief save animation datas * @key std::string - * @value CCAnimationData * + * @value AnimationData * */ Dictionary *m_pAnimationDatas; /** * @brief save texture datas * @key std::string - * @value CCTextureData * + * @value TextureData * */ Dictionary *m_pTextureDatas; diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp index ef6941086a..21bafa82b9 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp @@ -142,12 +142,12 @@ static float s_CocoStudioVersion = VERSION_COMBINED; static std::string s_BasefilePath = ""; -CCDataReaderHelper *CCDataReaderHelper::s_DataReaderHelper = NULL; +DataReaderHelper *DataReaderHelper::s_DataReaderHelper = NULL; //! Async load -void CCDataReaderHelper::loadData() +void DataReaderHelper::loadData() { AsyncStruct *pAsyncStruct = NULL; @@ -186,11 +186,11 @@ void CCDataReaderHelper::loadData() if (pAsyncStruct->configType == DragonBone_XML) { - CCDataReaderHelper::addDataFromCache(pAsyncStruct->fileContent.c_str(), pDataInfo); + DataReaderHelper::addDataFromCache(pAsyncStruct->fileContent.c_str(), pDataInfo); } else if(pAsyncStruct->configType == CocoStudio_JSON) { - CCDataReaderHelper::addDataFromJsonCache(pAsyncStruct->fileContent.c_str(), pDataInfo); + DataReaderHelper::addDataFromJsonCache(pAsyncStruct->fileContent.c_str(), pDataInfo); } // put the image info into the queue @@ -209,39 +209,39 @@ void CCDataReaderHelper::loadData() } -CCDataReaderHelper *CCDataReaderHelper::sharedDataReaderHelper() +DataReaderHelper *DataReaderHelper::sharedDataReaderHelper() { if(!s_DataReaderHelper) { - s_DataReaderHelper = new CCDataReaderHelper(); + s_DataReaderHelper = new DataReaderHelper(); } return s_DataReaderHelper; } -void CCDataReaderHelper::setPositionReadScale(float scale) +void DataReaderHelper::setPositionReadScale(float scale) { s_PositionReadScale = scale; } -float CCDataReaderHelper::getPositionReadScale() +float DataReaderHelper::getPositionReadScale() { return s_PositionReadScale; } -void CCDataReaderHelper::purge() +void DataReaderHelper::purge() { - CCDataReaderHelper::clear(); + DataReaderHelper::clear(); CC_SAFE_RELEASE_NULL(s_DataReaderHelper); } -void CCDataReaderHelper::clear() +void DataReaderHelper::clear() { s_arrConfigFileList.clear(); } -CCDataReaderHelper::CCDataReaderHelper() +DataReaderHelper::DataReaderHelper() : s_LoadingThread(nullptr) , s_pAsyncStructQueue(nullptr) , s_pDataQueue(nullptr) @@ -252,21 +252,21 @@ CCDataReaderHelper::CCDataReaderHelper() } -CCDataReaderHelper::~CCDataReaderHelper() +DataReaderHelper::~DataReaderHelper() { need_quit = true; - if (s_LoadingThread) s_LoadingThread->join(); - CC_SAFE_DELETE(s_LoadingThread); - s_SleepCondition.notify_one(); + if (s_LoadingThread) s_LoadingThread->join(); + + CC_SAFE_DELETE(s_LoadingThread); s_DataReaderHelper = NULL; } -void CCDataReaderHelper::addDataFromFile(const char *filePath) +void DataReaderHelper::addDataFromFile(const char *filePath) { /* - * Check if file is already added to CCArmatureDataManager, if then return. + * Check if file is already added to ArmatureDataManager, if then return. */ for(unsigned int i = 0; i < s_arrConfigFileList.size(); i++) { @@ -301,18 +301,18 @@ void CCDataReaderHelper::addDataFromFile(const char *filePath) if (str.compare(".xml") == 0) { - CCDataReaderHelper::addDataFromCache(pFileContent); + DataReaderHelper::addDataFromCache(pFileContent); } else if(str.compare(".json") == 0 || str.compare(".ExportJson") == 0) { - CCDataReaderHelper::addDataFromJsonCache(pFileContent); + DataReaderHelper::addDataFromJsonCache(pFileContent); } } -void CCDataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target, SEL_SCHEDULE selector) +void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target, SEL_SCHEDULE selector) { /* - * Check if file is already added to CCArmatureDataManager, if then return. + * Check if file is already added to ArmatureDataManager, if then return. */ for(unsigned int i = 0; i < s_arrConfigFileList.size(); i++) { @@ -354,14 +354,14 @@ void CCDataReaderHelper::addDataFromFileAsync(const char *filePath, Object *targ s_pDataQueue = new std::queue(); // create a new thread to load images - s_LoadingThread = new std::thread(&CCDataReaderHelper::loadData, this); + s_LoadingThread = new std::thread(&DataReaderHelper::loadData, this); need_quit = false; } if (0 == s_nAsyncRefCount) { - Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(CCDataReaderHelper::addDataAsyncCallBack), this, 0, false); + Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this, 0, false); } ++s_nAsyncRefCount; @@ -378,7 +378,7 @@ void CCDataReaderHelper::addDataFromFileAsync(const char *filePath, Object *targ data->baseFilePath = s_BasefilePath; data->target = target; data->selector = selector; - data->autoLoadSpriteFile = CCArmatureDataManager::sharedArmatureDataManager()->isAutoLoadSpriteFile(); + data->autoLoadSpriteFile = ArmatureDataManager::sharedArmatureDataManager()->isAutoLoadSpriteFile(); std::string filePathStr = filePath; @@ -407,7 +407,7 @@ void CCDataReaderHelper::addDataFromFileAsync(const char *filePath, Object *targ s_SleepCondition.notify_one(); } -void CCDataReaderHelper::addDataAsyncCallBack(float dt) +void DataReaderHelper::addDataAsyncCallBack(float dt) { // the data is generated in loading thread std::queue *dataQueue = s_pDataQueue; @@ -428,7 +428,7 @@ void CCDataReaderHelper::addDataAsyncCallBack(float dt) while (!pDataInfo->configFileQueue.empty()) { std::string configPath = pDataInfo->configFileQueue.front(); - CCArmatureDataManager::sharedArmatureDataManager()->addSpriteFrameFromFile((pAsyncStruct->baseFilePath + configPath + ".plist").c_str(), (pAsyncStruct->baseFilePath + configPath + ".png").c_str()); + ArmatureDataManager::sharedArmatureDataManager()->addSpriteFrameFromFile((pAsyncStruct->baseFilePath + configPath + ".plist").c_str(), (pAsyncStruct->baseFilePath + configPath + ".png").c_str()); pDataInfo->configFileQueue.pop(); } @@ -451,7 +451,7 @@ void CCDataReaderHelper::addDataAsyncCallBack(float dt) if (0 == s_nAsyncRefCount) { s_nAsyncRefTotalCount = 0; - CCDirector::getInstance()->getScheduler()->unscheduleSelector(schedule_selector(CCDataReaderHelper::addDataAsyncCallBack), this); + CCDirector::getInstance()->getScheduler()->unscheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this); } } } @@ -461,7 +461,7 @@ void CCDataReaderHelper::addDataAsyncCallBack(float dt) -void CCDataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *dataInfo) +void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *dataInfo) { tinyxml2::XMLDocument document; document.Parse(pFileContent); @@ -479,13 +479,13 @@ void CCDataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *da tinyxml2::XMLElement *armatureXML = armaturesXML->FirstChildElement(ARMATURE); while(armatureXML) { - CCArmatureData *armatureData = CCDataReaderHelper::decodeArmature(armatureXML); + ArmatureData *armatureData = DataReaderHelper::decodeArmature(armatureXML); if (dataInfo) { s_DataReaderHelper->s_AddDataMutex.lock(); } - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); + ArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); armatureData->release(); if (dataInfo) { @@ -503,12 +503,12 @@ void CCDataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *da tinyxml2::XMLElement *animationXML = animationsXML->FirstChildElement(ANIMATION); while(animationXML) { - CCAnimationData *animationData = CCDataReaderHelper::decodeAnimation(animationXML); + AnimationData *animationData = DataReaderHelper::decodeAnimation(animationXML); if (dataInfo) { s_DataReaderHelper->s_AddDataMutex.lock(); } - CCArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); + ArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); animationData->release(); if (dataInfo) { @@ -525,13 +525,13 @@ void CCDataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *da tinyxml2::XMLElement *textureXML = texturesXML->FirstChildElement(SUB_TEXTURE); while(textureXML) { - CCTextureData *textureData = CCDataReaderHelper::decodeTexture(textureXML); + TextureData *textureData = DataReaderHelper::decodeTexture(textureXML); if (dataInfo) { s_DataReaderHelper->s_AddDataMutex.lock(); } - CCArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); + ArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); textureData->release(); if (dataInfo) { @@ -541,9 +541,9 @@ void CCDataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *da } } -CCArmatureData *CCDataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML) +ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML) { - CCArmatureData *armatureData = new CCArmatureData(); + ArmatureData *armatureData = new ArmatureData(); armatureData->init(); const char *name = armatureXML->Attribute(A_NAME); @@ -573,7 +573,7 @@ CCArmatureData *CCDataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatur } } - CCBoneData *boneData = decodeBone(boneXML, parentXML); + BoneData *boneData = decodeBone(boneXML, parentXML); armatureData->addBoneData(boneData); boneData->release(); @@ -583,9 +583,9 @@ CCArmatureData *CCDataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatur return armatureData; } -CCBoneData *CCDataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXml) +BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXml) { - CCBoneData *boneData = new CCBoneData(); + BoneData *boneData = new BoneData(); boneData->init(); std::string name = boneXML->Attribute(A_NAME); @@ -601,7 +601,7 @@ CCBoneData *CCDataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxm tinyxml2::XMLElement *displayXML = boneXML->FirstChildElement(DISPLAY); while(displayXML) { - CCDisplayData *displayData = decodeBoneDisplay(displayXML); + DisplayData *displayData = decodeBoneDisplay(displayXML); boneData->addDisplayData(displayData); displayData->release(); @@ -611,29 +611,29 @@ CCBoneData *CCDataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxm return boneData; } -CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXML) +DisplayData *DataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXML) { int _isArmature = 0; - CCDisplayData *displayData; + DisplayData *displayData; if( displayXML->QueryIntAttribute(A_IS_ARMATURE, &(_isArmature)) == tinyxml2::XML_SUCCESS ) { if(!_isArmature) { - displayData = new CCSpriteDisplayData(); + displayData = new SpriteDisplayData(); displayData->displayType = CS_DISPLAY_SPRITE; } else { - displayData = new CCArmatureDisplayData(); + displayData = new ArmatureDisplayData(); displayData->displayType = CS_DISPLAY_ARMATURE; } } else { - displayData = new CCSpriteDisplayData(); + displayData = new SpriteDisplayData(); displayData->displayType = CS_DISPLAY_SPRITE; } @@ -642,11 +642,11 @@ CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displ { if(!_isArmature) { - ((CCSpriteDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); + ((SpriteDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); } else { - ((CCArmatureDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); + ((ArmatureDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); } } @@ -654,13 +654,13 @@ CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displ return displayData; } -CCAnimationData *CCDataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animationXML) +AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animationXML) { - CCAnimationData *aniData = new CCAnimationData(); + AnimationData *aniData = new AnimationData(); const char *name = animationXML->Attribute(A_NAME); - CCArmatureData *armatureData = CCArmatureDataManager::sharedArmatureDataManager()->getArmatureData(name); + ArmatureData *armatureData = ArmatureDataManager::sharedArmatureDataManager()->getArmatureData(name); aniData->name = name; @@ -668,7 +668,7 @@ CCAnimationData *CCDataReaderHelper::decodeAnimation(tinyxml2::XMLElement *anima while( movementXML ) { - CCMovementData *movementData = decodeMovement(movementXML, armatureData); + MovementData *movementData = decodeMovement(movementXML, armatureData); aniData->addMovement(movementData); movementData->release(); @@ -679,9 +679,9 @@ CCAnimationData *CCDataReaderHelper::decodeAnimation(tinyxml2::XMLElement *anima return aniData; } -CCMovementData *CCDataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, CCArmatureData *armatureData) +MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, ArmatureData *armatureData) { - CCMovementData *movementData = new CCMovementData(); + MovementData *movementData = new MovementData(); const char *movName = movementXML->Attribute(A_NAME); movementData->name = movName; @@ -735,7 +735,7 @@ CCMovementData *CCDataReaderHelper::decodeMovement(tinyxml2::XMLElement *movemen } - CCBoneData *boneData = (CCBoneData *)armatureData->getBoneData(boneName); + BoneData *boneData = (BoneData *)armatureData->getBoneData(boneName); std::string parentName = boneData->parentName; @@ -755,7 +755,7 @@ CCMovementData *CCDataReaderHelper::decodeMovement(tinyxml2::XMLElement *movemen } } - CCMovementBoneData *moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData); + MovementBoneData *moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData); movementData->addMovementBoneData(moveBoneData); moveBoneData->release(); @@ -766,9 +766,9 @@ CCMovementData *CCDataReaderHelper::decodeMovement(tinyxml2::XMLElement *movemen } -CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, CCBoneData *boneData) +MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, BoneData *boneData) { - CCMovementBoneData *movBoneData = new CCMovementBoneData(); + MovementBoneData *movBoneData = new MovementBoneData(); movBoneData->init(); float scale, delay; @@ -841,7 +841,7 @@ CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(tinyxml2::XMLElement } } - CCFrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData); + FrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData); movBoneData->addFrameData(frameData); frameData->release(); @@ -854,8 +854,8 @@ CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(tinyxml2::XMLElement // - CCFrameData *frameData = new CCFrameData(); - frameData->copy((CCFrameData *)movBoneData->frameList.getLastObject()); + FrameData *frameData = new FrameData(); + frameData->copy((FrameData *)movBoneData->frameList.getLastObject()); frameData->frameID = movBoneData->duration; movBoneData->addFrameData(frameData); frameData->release(); @@ -863,12 +863,12 @@ CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(tinyxml2::XMLElement return movBoneData; } -CCFrameData *CCDataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, CCBoneData *boneData) +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; - CCFrameData *frameData = new CCFrameData(); + FrameData *frameData = new FrameData(); if(frameXML->Attribute(A_MOVEMENT) != NULL) { @@ -946,7 +946,7 @@ CCFrameData *CCDataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, ti } if ( frameXML->QueryIntAttribute(A_BLEND_TYPE, &blendType) == tinyxml2::XML_SUCCESS ) { - frameData->blendType = (CCBlendType)blendType; + frameData->blendType = (BlendType)blendType; } tinyxml2::XMLElement *colorTransformXML = frameXML->FirstChildElement(A_COLOR_TRANSFORM); @@ -996,7 +996,7 @@ CCFrameData *CCDataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, ti /* * recalculate frame data from parent frame data, use for translate matrix */ - CCBaseData helpNode; + BaseData helpNode; if (s_FlashToolVersion >= VERSION_2_0) { parentFrameXml->QueryFloatAttribute(A_COCOS2DX_X, &helpNode.x); @@ -1016,14 +1016,14 @@ CCFrameData *CCDataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, ti helpNode.skewX = CC_DEGREES_TO_RADIANS(helpNode.skewX); helpNode.skewY = CC_DEGREES_TO_RADIANS(-helpNode.skewY); - CCTransformHelp::transformFromParent(*frameData, helpNode); + TransformHelp::transformFromParent(*frameData, helpNode); } return frameData; } -CCTextureData *CCDataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) +TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) { - CCTextureData *textureData = new CCTextureData(); + TextureData *textureData = new TextureData(); textureData->init(); if( textureXML->Attribute(A_NAME) != NULL) @@ -1057,7 +1057,7 @@ CCTextureData *CCDataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXM while (contourXML) { - CCContourData *contourData = decodeContour(contourXML); + ContourData *contourData = decodeContour(contourXML); textureData->addContourData(contourData); contourData->release(); @@ -1067,16 +1067,16 @@ CCTextureData *CCDataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXM return textureData; } -CCContourData *CCDataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML) +ContourData *DataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML) { - CCContourData *contourData = new CCContourData(); + ContourData *contourData = new ContourData(); contourData->init(); tinyxml2::XMLElement *vertexDataXML = contourXML->FirstChildElement(CONTOUR_VERTEX); while (vertexDataXML) { - CCContourVertex2 *vertex = new CCContourVertex2(0, 0); + ContourVertex2 *vertex = new ContourVertex2(0, 0); vertex->release(); vertexDataXML->QueryFloatAttribute(A_X, &vertex->x); @@ -1093,7 +1093,7 @@ CCContourData *CCDataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXM -void CCDataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo) +void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo) { cs::JsonDictionary json; json.initWithDescription(fileContent); @@ -1103,13 +1103,13 @@ void CCDataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo for (int i = 0; i < length; i++) { cs::JsonDictionary *armatureDic = json.getSubItemFromArray(ARMATURE_DATA, i); - CCArmatureData *armatureData = decodeArmature(*armatureDic); + ArmatureData *armatureData = decodeArmature(*armatureDic); if (dataInfo) { s_DataReaderHelper->s_AddDataMutex.lock(); } - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); + ArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); armatureData->release(); if (dataInfo) { @@ -1123,13 +1123,13 @@ void CCDataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo for (int i = 0; i < length; i++) { cs::JsonDictionary *animationDic = json.getSubItemFromArray(ANIMATION_DATA, i); - CCAnimationData *animationData = decodeAnimation(*animationDic); + AnimationData *animationData = decodeAnimation(*animationDic); if (dataInfo) { s_DataReaderHelper->s_AddDataMutex.lock(); } - CCArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); + ArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); animationData->release(); if (dataInfo) { @@ -1143,13 +1143,13 @@ void CCDataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo for (int i = 0; i < length; i++) { cs::JsonDictionary *textureDic = json.getSubItemFromArray(TEXTURE_DATA, i); - CCTextureData *textureData = decodeTexture(*textureDic); + TextureData *textureData = decodeTexture(*textureDic); if (dataInfo) { s_DataReaderHelper->s_AddDataMutex.lock(); } - CCArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); + ArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); textureData->release(); if (dataInfo) { @@ -1159,7 +1159,7 @@ void CCDataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo } // Auto load sprite file - bool autoLoad = dataInfo == NULL ? CCArmatureDataManager::sharedArmatureDataManager()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; + bool autoLoad = dataInfo == NULL ? ArmatureDataManager::sharedArmatureDataManager()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; if (autoLoad) { length = json.getArrayItemCount(CONFIG_FILE_PATH); @@ -1184,15 +1184,15 @@ void CCDataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo std::string plistPath = filePath + ".plist"; std::string pngPath = filePath + ".png"; - CCArmatureDataManager::sharedArmatureDataManager()->addSpriteFrameFromFile((s_BasefilePath + plistPath).c_str(), (s_BasefilePath + pngPath).c_str()); + ArmatureDataManager::sharedArmatureDataManager()->addSpriteFrameFromFile((s_BasefilePath + plistPath).c_str(), (s_BasefilePath + pngPath).c_str()); } } } } -CCArmatureData *CCDataReaderHelper::decodeArmature(cs::JsonDictionary &json) +ArmatureData *DataReaderHelper::decodeArmature(cs::JsonDictionary &json) { - CCArmatureData *armatureData = new CCArmatureData(); + ArmatureData *armatureData = new ArmatureData(); armatureData->init(); const char *name = json.getItemStringValue(A_NAME); @@ -1207,7 +1207,7 @@ CCArmatureData *CCDataReaderHelper::decodeArmature(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(BONE_DATA, i); - CCBoneData *boneData = decodeBone(*dic); + BoneData *boneData = decodeBone(*dic); armatureData->addBoneData(boneData); boneData->release(); @@ -1217,9 +1217,9 @@ CCArmatureData *CCDataReaderHelper::decodeArmature(cs::JsonDictionary &json) return armatureData; } -CCBoneData *CCDataReaderHelper::decodeBone(cs::JsonDictionary &json) +BoneData *DataReaderHelper::decodeBone(cs::JsonDictionary &json) { - CCBoneData *boneData = new CCBoneData(); + BoneData *boneData = new BoneData(); boneData->init(); decodeNode(boneData, json); @@ -1241,7 +1241,7 @@ CCBoneData *CCDataReaderHelper::decodeBone(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(DISPLAY_DATA, i); - CCDisplayData *displayData = decodeBoneDisplay(*dic); + DisplayData *displayData = decodeBoneDisplay(*dic); boneData->addDisplayData(displayData); displayData->release(); @@ -1251,28 +1251,28 @@ CCBoneData *CCDataReaderHelper::decodeBone(cs::JsonDictionary &json) return boneData; } -CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(cs::JsonDictionary &json) +DisplayData *DataReaderHelper::decodeBoneDisplay(cs::JsonDictionary &json) { DisplayType displayType = (DisplayType)json.getItemIntValue(A_DISPLAY_TYPE, CS_DISPLAY_SPRITE); - CCDisplayData *displayData = NULL; + DisplayData *displayData = NULL; switch (displayType) { case CS_DISPLAY_SPRITE: { - displayData = new CCSpriteDisplayData(); + displayData = new SpriteDisplayData(); const char *name = json.getItemStringValue(A_NAME); if(name != NULL) { - ((CCSpriteDisplayData *)displayData)->displayName = name; + ((SpriteDisplayData *)displayData)->displayName = name; } cs::JsonDictionary *dic = json.getSubItemFromArray(SKIN_DATA, 0); if (dic != NULL) { - CCSpriteDisplayData *sdd = (CCSpriteDisplayData *)displayData; + 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); @@ -1286,28 +1286,28 @@ CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(cs::JsonDictionary &json) break; case CS_DISPLAY_ARMATURE: { - displayData = new CCArmatureDisplayData(); + displayData = new ArmatureDisplayData(); const char *name = json.getItemStringValue(A_NAME); if(name != NULL) { - ((CCArmatureDisplayData *)displayData)->displayName = name; + ((ArmatureDisplayData *)displayData)->displayName = name; } } break; case CS_DISPLAY_PARTICLE: { - displayData = new CCParticleDisplayData(); + displayData = new ParticleDisplayData(); const char *plist = json.getItemStringValue(A_PLIST); if(plist != NULL) { - ((CCParticleDisplayData *)displayData)->plist = s_BasefilePath + plist; + ((ParticleDisplayData *)displayData)->plist = s_BasefilePath + plist; } } break; default: - displayData = new CCSpriteDisplayData(); + displayData = new SpriteDisplayData(); break; } @@ -1318,9 +1318,9 @@ CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(cs::JsonDictionary &json) return displayData; } -CCAnimationData *CCDataReaderHelper::decodeAnimation(cs::JsonDictionary &json) +AnimationData *DataReaderHelper::decodeAnimation(cs::JsonDictionary &json) { - CCAnimationData *aniData = new CCAnimationData(); + AnimationData *aniData = new AnimationData(); const char *name = json.getItemStringValue(A_NAME); if(name != NULL) @@ -1333,7 +1333,7 @@ CCAnimationData *CCDataReaderHelper::decodeAnimation(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_DATA, i); - CCMovementData *movementData = decodeMovement(*dic); + MovementData *movementData = decodeMovement(*dic); aniData->addMovement(movementData); movementData->release(); @@ -1343,9 +1343,9 @@ CCAnimationData *CCDataReaderHelper::decodeAnimation(cs::JsonDictionary &json) return aniData; } -CCMovementData *CCDataReaderHelper::decodeMovement(cs::JsonDictionary &json) +MovementData *DataReaderHelper::decodeMovement(cs::JsonDictionary &json) { - CCMovementData *movementData = new CCMovementData(); + MovementData *movementData = new MovementData(); movementData->loop = json.getItemBoolvalue(A_LOOP, true); movementData->durationTween = json.getItemIntValue(A_DURATION_TWEEN, 0); @@ -1364,7 +1364,7 @@ CCMovementData *CCDataReaderHelper::decodeMovement(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_BONE_DATA, i); - CCMovementBoneData *movementBoneData = decodeMovementBone(*dic); + MovementBoneData *movementBoneData = decodeMovementBone(*dic); movementData->addMovementBoneData(movementBoneData); movementBoneData->release(); @@ -1374,9 +1374,9 @@ CCMovementData *CCDataReaderHelper::decodeMovement(cs::JsonDictionary &json) return movementData; } -CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(cs::JsonDictionary &json) +MovementBoneData *DataReaderHelper::decodeMovementBone(cs::JsonDictionary &json) { - CCMovementBoneData *movementBoneData = new CCMovementBoneData(); + MovementBoneData *movementBoneData = new MovementBoneData(); movementBoneData->init(); movementBoneData->delay = json.getItemFloatValue(A_MOVEMENT_DELAY, 0); @@ -1391,7 +1391,7 @@ CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(cs::JsonDictionary &j for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(FRAME_DATA, i); - CCFrameData *frameData = decodeFrame(*dic); + FrameData *frameData = decodeFrame(*dic); movementBoneData->addFrameData(frameData); frameData->release(); @@ -1409,8 +1409,8 @@ CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(cs::JsonDictionary &j { if (movementBoneData->frameList.count() > 0) { - CCFrameData *frameData = new CCFrameData(); - frameData->copy((CCFrameData *)movementBoneData->frameList.getLastObject()); + FrameData *frameData = new FrameData(); + frameData->copy((FrameData *)movementBoneData->frameList.getLastObject()); movementBoneData->addFrameData(frameData); frameData->release(); @@ -1421,15 +1421,15 @@ CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(cs::JsonDictionary &j return movementBoneData; } -CCFrameData *CCDataReaderHelper::decodeFrame(cs::JsonDictionary &json) +FrameData *DataReaderHelper::decodeFrame(cs::JsonDictionary &json) { - CCFrameData *frameData = new CCFrameData(); + 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 = (CCBlendType)json.getItemIntValue(A_BLEND_TYPE, 0); + frameData->blendType = (BlendType)json.getItemIntValue(A_BLEND_TYPE, 0); const char *event = json.getItemStringValue(A_EVENT); if (event != NULL) @@ -1449,9 +1449,9 @@ CCFrameData *CCDataReaderHelper::decodeFrame(cs::JsonDictionary &json) return frameData; } -CCTextureData *CCDataReaderHelper::decodeTexture(cs::JsonDictionary &json) +TextureData *DataReaderHelper::decodeTexture(cs::JsonDictionary &json) { - CCTextureData *textureData = new CCTextureData(); + TextureData *textureData = new TextureData(); textureData->init(); const char *name = json.getItemStringValue(A_NAME); @@ -1469,7 +1469,7 @@ CCTextureData *CCDataReaderHelper::decodeTexture(cs::JsonDictionary &json) for (int i = 0; i < length; i++) { cs::JsonDictionary *dic = json.getSubItemFromArray(CONTOUR_DATA, i); - CCContourData *contourData = decodeContour(*dic); + ContourData *contourData = decodeContour(*dic); textureData->contourDataList.addObject(contourData); contourData->release(); @@ -1479,9 +1479,9 @@ CCTextureData *CCDataReaderHelper::decodeTexture(cs::JsonDictionary &json) return textureData; } -CCContourData *CCDataReaderHelper::decodeContour(cs::JsonDictionary &json) +ContourData *DataReaderHelper::decodeContour(cs::JsonDictionary &json) { - CCContourData *contourData = new CCContourData(); + ContourData *contourData = new ContourData(); contourData->init(); int length = json.getArrayItemCount(VERTEX_POINT); @@ -1489,7 +1489,7 @@ CCContourData *CCDataReaderHelper::decodeContour(cs::JsonDictionary &json) { cs::JsonDictionary *dic = json.getSubItemFromArray(VERTEX_POINT, i); - CCContourVertex2 *vertex = new CCContourVertex2(0, 0); + ContourVertex2 *vertex = new ContourVertex2(0, 0); vertex->x = dic->getItemFloatValue(A_X, 0); vertex->y = dic->getItemFloatValue(A_Y, 0); @@ -1503,7 +1503,7 @@ CCContourData *CCDataReaderHelper::decodeContour(cs::JsonDictionary &json) return contourData; } -void CCDataReaderHelper::decodeNode(CCBaseData *node, cs::JsonDictionary &json) +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; diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h index 5830f7ef9e..5306fa22a0 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h @@ -44,7 +44,7 @@ namespace tinyxml2 NS_CC_EXT_ARMATURE_BEGIN -class CCDataReaderHelper : Object +class DataReaderHelper : Object { protected: @@ -73,7 +73,7 @@ protected: public: - static CCDataReaderHelper *sharedDataReaderHelper(); + static DataReaderHelper *sharedDataReaderHelper(); /** * Scale the position data, used for multiresolution adapter @@ -85,8 +85,8 @@ public: static void purge(); static void clear(); public: - CCDataReaderHelper(); - ~CCDataReaderHelper(); + DataReaderHelper(); + ~DataReaderHelper(); void addDataFromFile(const char *filePath); void addDataFromFileAsync(const char *filePath, Object *target, SEL_SCHEDULE selector); @@ -96,7 +96,7 @@ public: public: /** - * Translate XML export from Dragon CCBone flash tool to datas, and save them. + * Translate XML export from Dragon Bone flash tool to datas, and save them. * When you add a new xml, the data already saved will be keeped. * * @param xmlPath The cache of the xml @@ -106,49 +106,49 @@ public: /** - * Decode CCArmature Datas from xml export from Dragon CCBone flash tool + * Decode Armature Datas from xml export from Dragon Bone flash tool */ - static CCArmatureData *decodeArmature(tinyxml2::XMLElement *armatureXML); - static CCBoneData *decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXML); - static CCDisplayData *decodeBoneDisplay(tinyxml2::XMLElement *displayXML); + static ArmatureData *decodeArmature(tinyxml2::XMLElement *armatureXML); + static BoneData *decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXML); + static DisplayData *decodeBoneDisplay(tinyxml2::XMLElement *displayXML); /** - * Decode CCArmatureAnimation Datas from xml export from Dragon CCBone flash tool + * Decode ArmatureAnimation Datas from xml export from Dragon Bone flash tool */ - static CCAnimationData *decodeAnimation(tinyxml2::XMLElement *animationXML); - static CCMovementData *decodeMovement(tinyxml2::XMLElement *movementXML, CCArmatureData *armatureData); - static CCMovementBoneData *decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, CCBoneData *boneData); - static CCFrameData *decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, CCBoneData *boneData); + 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); /** - * Decode Texture Datas from xml export from Dragon CCBone flash tool + * Decode Texture Datas from xml export from Dragon Bone flash tool */ - static CCTextureData *decodeTexture(tinyxml2::XMLElement *textureXML); + static TextureData *decodeTexture(tinyxml2::XMLElement *textureXML); /** - * Decode Contour Datas from xml export from Dragon CCBone flash tool + * Decode Contour Datas from xml export from Dragon Bone flash tool */ - static CCContourData *decodeContour(tinyxml2::XMLElement *contourXML); + static ContourData *decodeContour(tinyxml2::XMLElement *contourXML); public: static void addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo = NULL); - static CCArmatureData *decodeArmature(cs::JsonDictionary &json); - static CCBoneData *decodeBone(cs::JsonDictionary &json); - static CCDisplayData *decodeBoneDisplay(cs::JsonDictionary &json); + static ArmatureData *decodeArmature(cs::JsonDictionary &json); + static BoneData *decodeBone(cs::JsonDictionary &json); + static DisplayData *decodeBoneDisplay(cs::JsonDictionary &json); - static CCAnimationData *decodeAnimation(cs::JsonDictionary &json); - static CCMovementData *decodeMovement(cs::JsonDictionary &json); - static CCMovementBoneData *decodeMovementBone(cs::JsonDictionary &json); - static CCFrameData *decodeFrame(cs::JsonDictionary &json); + static AnimationData *decodeAnimation(cs::JsonDictionary &json); + static MovementData *decodeMovement(cs::JsonDictionary &json); + static MovementBoneData *decodeMovementBone(cs::JsonDictionary &json); + static FrameData *decodeFrame(cs::JsonDictionary &json); - static CCTextureData *decodeTexture(cs::JsonDictionary &json); + static TextureData *decodeTexture(cs::JsonDictionary &json); - static CCContourData *decodeContour(cs::JsonDictionary &json); + static ContourData *decodeContour(cs::JsonDictionary &json); - static void decodeNode(CCBaseData *node, cs::JsonDictionary &json); + static void decodeNode(BaseData *node, cs::JsonDictionary &json); protected: void loadData(); @@ -178,7 +178,7 @@ protected: std::queue *s_pDataQueue; - static CCDataReaderHelper *s_DataReaderHelper; + static DataReaderHelper *s_DataReaderHelper; }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp index d2ac1f20c5..c6e56b5e6c 100644 --- a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp @@ -27,30 +27,30 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -CCSpriteFrameCacheHelper *CCSpriteFrameCacheHelper::s_SpriteFrameCacheHelper = NULL; +SpriteFrameCacheHelper *SpriteFrameCacheHelper::s_SpriteFrameCacheHelper = NULL; -CCSpriteFrameCacheHelper *CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper() +SpriteFrameCacheHelper *SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper() { if(!s_SpriteFrameCacheHelper) { - s_SpriteFrameCacheHelper = new CCSpriteFrameCacheHelper(); + s_SpriteFrameCacheHelper = new SpriteFrameCacheHelper(); } return s_SpriteFrameCacheHelper; } -void CCSpriteFrameCacheHelper::purge() +void SpriteFrameCacheHelper::purge() { delete s_SpriteFrameCacheHelper; s_SpriteFrameCacheHelper = NULL; } -void CCSpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) +void SpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) { CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath, imagePath); } -TextureAtlas *CCSpriteFrameCacheHelper::getTexureAtlasWithTexture(Texture2D *texture) +TextureAtlas *SpriteFrameCacheHelper::getTexureAtlasWithTexture(Texture2D *texture) { int key = texture->getName(); TextureAtlas *atlas = (TextureAtlas *)m_pTextureAtlasDic->objectForKey(key); @@ -62,12 +62,12 @@ TextureAtlas *CCSpriteFrameCacheHelper::getTexureAtlasWithTexture(Texture2D *tex return atlas; } -CCSpriteFrameCacheHelper::CCSpriteFrameCacheHelper() +SpriteFrameCacheHelper::SpriteFrameCacheHelper() { m_pTextureAtlasDic = new Dictionary(); } -CCSpriteFrameCacheHelper::~CCSpriteFrameCacheHelper() +SpriteFrameCacheHelper::~SpriteFrameCacheHelper() { CC_SAFE_RELEASE_NULL(m_pTextureAtlasDic); } diff --git a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h index bd7ce29978..194da81a8e 100644 --- a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h @@ -31,10 +31,10 @@ using namespace std; NS_CC_EXT_ARMATURE_BEGIN -class CCSpriteFrameCacheHelper +class SpriteFrameCacheHelper { public: - static CCSpriteFrameCacheHelper *sharedSpriteFrameCacheHelper(); + static SpriteFrameCacheHelper *sharedSpriteFrameCacheHelper(); static void purge(); public: @@ -47,12 +47,12 @@ public: TextureAtlas *getTexureAtlasWithTexture(Texture2D *texture); private: - CCSpriteFrameCacheHelper(); - ~CCSpriteFrameCacheHelper(); + SpriteFrameCacheHelper(); + ~SpriteFrameCacheHelper(); Dictionary *m_pTextureAtlasDic; - static CCSpriteFrameCacheHelper *s_SpriteFrameCacheHelper; + static SpriteFrameCacheHelper *s_SpriteFrameCacheHelper; }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCTransformHelp.cpp b/extensions/CocoStudio/Armature/utils/CCTransformHelp.cpp index dadbe909da..081b160b26 100644 --- a/extensions/CocoStudio/Armature/utils/CCTransformHelp.cpp +++ b/extensions/CocoStudio/Armature/utils/CCTransformHelp.cpp @@ -27,19 +27,19 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -AffineTransform CCTransformHelp::helpMatrix1; -AffineTransform CCTransformHelp::helpMatrix2; +AffineTransform TransformHelp::helpMatrix1; +AffineTransform TransformHelp::helpMatrix2; -Point CCTransformHelp::helpPoint1; -Point CCTransformHelp::helpPoint2; +Point TransformHelp::helpPoint1; +Point TransformHelp::helpPoint2; -CCBaseData helpParentNode; +BaseData helpParentNode; -CCTransformHelp::CCTransformHelp() +TransformHelp::TransformHelp() { } -void CCTransformHelp::transformFromParent(CCBaseData &node, const CCBaseData &parentNode) +void TransformHelp::transformFromParent(BaseData &node, const BaseData &parentNode) { nodeToMatrix(node, helpMatrix1); nodeToMatrix(parentNode, helpMatrix2); @@ -50,7 +50,7 @@ void CCTransformHelp::transformFromParent(CCBaseData &node, const CCBaseData &pa matrixToNode(helpMatrix1, node); } -void CCTransformHelp::transformToParent(CCBaseData &node, const CCBaseData &parentNode) +void TransformHelp::transformToParent(BaseData &node, const BaseData &parentNode) { nodeToMatrix(node, helpMatrix1); @@ -61,7 +61,7 @@ void CCTransformHelp::transformToParent(CCBaseData &node, const CCBaseData &pare matrixToNode(helpMatrix1, node); } -void CCTransformHelp::transformFromParentWithoutScale(CCBaseData &node, const CCBaseData &parentNode) +void TransformHelp::transformFromParentWithoutScale(BaseData &node, const BaseData &parentNode) { helpParentNode.copy(&parentNode); @@ -77,7 +77,7 @@ void CCTransformHelp::transformFromParentWithoutScale(CCBaseData &node, const CC matrixToNode(helpMatrix1, node); } -void CCTransformHelp::transformToParentWithoutScale(CCBaseData &node, const CCBaseData &parentNode) +void TransformHelp::transformToParentWithoutScale(BaseData &node, const BaseData &parentNode) { helpParentNode.copy(&parentNode); @@ -92,7 +92,7 @@ void CCTransformHelp::transformToParentWithoutScale(CCBaseData &node, const CCBa matrixToNode(helpMatrix1, node); } -void CCTransformHelp::nodeToMatrix(const CCBaseData &node, AffineTransform &matrix) +void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix) { matrix.a = node.scaleX * cos(node.skewY); matrix.b = node.scaleX * sin(node.skewY); @@ -103,7 +103,7 @@ void CCTransformHelp::nodeToMatrix(const CCBaseData &node, AffineTransform &matr matrix.ty = node.y; } -void CCTransformHelp::matrixToNode(const AffineTransform &matrix, CCBaseData &node) +void TransformHelp::matrixToNode(const AffineTransform &matrix, BaseData &node) { /* * In as3 language, there is a function called "deltaTransformPoint", it calculate a point used give Transform @@ -129,7 +129,7 @@ void CCTransformHelp::matrixToNode(const AffineTransform &matrix, CCBaseData &no node.y = matrix.ty; } -void CCTransformHelp::nodeConcat(CCBaseData &target, CCBaseData &source) +void TransformHelp::nodeConcat(BaseData &target, BaseData &source) { target.x += source.x; target.y += source.y; @@ -139,7 +139,7 @@ void CCTransformHelp::nodeConcat(CCBaseData &target, CCBaseData &source) target.scaleY += source.scaleY; } -void CCTransformHelp::nodeSub(CCBaseData &target, CCBaseData &source) +void TransformHelp::nodeSub(BaseData &target, BaseData &source) { target.x -= source.x; target.y -= source.y; diff --git a/extensions/CocoStudio/Armature/utils/CCTransformHelp.h b/extensions/CocoStudio/Armature/utils/CCTransformHelp.h index 7838e66184..5542691616 100644 --- a/extensions/CocoStudio/Armature/utils/CCTransformHelp.h +++ b/extensions/CocoStudio/Armature/utils/CCTransformHelp.h @@ -33,22 +33,22 @@ NS_CC_EXT_ARMATURE_BEGIN /* * use to calculate the matrix of node from parent node */ -class CCTransformHelp +class TransformHelp { public: - CCTransformHelp(); + TransformHelp(); - static void transformFromParent(CCBaseData &node, const CCBaseData &parentNode); - static void transformToParent(CCBaseData &node, const CCBaseData &parentNode); + static void transformFromParent(BaseData &node, const BaseData &parentNode); + static void transformToParent(BaseData &node, const BaseData &parentNode); - static void transformFromParentWithoutScale(CCBaseData &node, const CCBaseData &parentNode); - static void transformToParentWithoutScale(CCBaseData &node, const CCBaseData &parentNode); + static void transformFromParentWithoutScale(BaseData &node, const BaseData &parentNode); + static void transformToParentWithoutScale(BaseData &node, const BaseData &parentNode); - static void nodeToMatrix(const CCBaseData &_node, AffineTransform &_matrix); - static void matrixToNode(const AffineTransform &_matrix, CCBaseData &_node); + static void nodeToMatrix(const BaseData &_node, AffineTransform &_matrix); + static void matrixToNode(const AffineTransform &_matrix, BaseData &_node); - static void nodeConcat(CCBaseData &target, CCBaseData &source); - static void nodeSub(CCBaseData &target, CCBaseData &source); + static void nodeConcat(BaseData &target, BaseData &source); + static void nodeSub(BaseData &target, BaseData &source); public: static AffineTransform helpMatrix1; static AffineTransform helpMatrix2; diff --git a/extensions/CocoStudio/Armature/utils/CCTweenFunction.cpp b/extensions/CocoStudio/Armature/utils/CCTweenFunction.cpp index 340da10da5..8546a88d27 100644 --- a/extensions/CocoStudio/Armature/utils/CCTweenFunction.cpp +++ b/extensions/CocoStudio/Armature/utils/CCTweenFunction.cpp @@ -27,7 +27,7 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -float CCTweenFunction::tweenTo(float from, float change, float time, float duration, CCTweenType tweenType) +float TweenFunction::tweenTo(float from, float change, float time, float duration, CCTweenType tweenType) { float delta = 0; @@ -146,22 +146,22 @@ float CCTweenFunction::tweenTo(float from, float change, float time, float durat return delta; } -float CCTweenFunction::linear(float t, float b, float c, float d) +float TweenFunction::linear(float t, float b, float c, float d) { return c * t / d + b; } -float CCTweenFunction::quadEaseIn(float t, float b, float c, float d) +float TweenFunction::quadEaseIn(float t, float b, float c, float d) { t /= d; return c * t * t + b; } -float CCTweenFunction::quadEaseOut(float t, float b, float c, float d) +float TweenFunction::quadEaseOut(float t, float b, float c, float d) { t /= d; return -c * t * (t - 2) + b; } -float CCTweenFunction::quadEaseInOut(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) @@ -170,17 +170,17 @@ float CCTweenFunction::quadEaseInOut(float t, float b, float c, float d) return -c / 2 * (t * (t - 2) - 1) + b; } -float CCTweenFunction::cubicEaseIn(float t, float b, float c, float d) +float TweenFunction::cubicEaseIn(float t, float b, float c, float d) { t /= d; return c * t * t * t + b; } -float CCTweenFunction::cubicEaseOut(float t, float b, float c, float d) +float TweenFunction::cubicEaseOut(float t, float b, float c, float d) { t = t / d - 1; return c * (t * t * t + 1) + b; } -float CCTweenFunction::cubicEaseInOut(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) @@ -189,17 +189,17 @@ float CCTweenFunction::cubicEaseInOut(float t, float b, float c, float d) return c / 2 * (t * t * t + 2) + b; } -float CCTweenFunction::quartEaseIn(float t, float b, float c, float d) +float TweenFunction::quartEaseIn(float t, float b, float c, float d) { t /= d; return c * t * t * t * t + b; } -float CCTweenFunction::quartEaseOut(float t, float b, float c, float d) +float TweenFunction::quartEaseOut(float t, float b, float c, float d) { t = t / d - 1; return -c * (t * t * t * t - 1) + b; } -float CCTweenFunction::quartEaseInOut(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) @@ -208,17 +208,17 @@ float CCTweenFunction::quartEaseInOut(float t, float b, float c, float d) return -c / 2 * (t * t * t * t - 2) + b; } -float CCTweenFunction::quintEaseIn(float t, float b, float c, float d) +float TweenFunction::quintEaseIn(float t, float b, float c, float d) { t /= d; return c * t * t * t * t * t + b; } -float CCTweenFunction::quintEaseOut(float t, float b, float c, float d) +float TweenFunction::quintEaseOut(float t, float b, float c, float d) { t = t / d - 1; return c * (t * t * t * t * t + 1) + b; } -float CCTweenFunction::quintEaseInOut(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) @@ -227,28 +227,28 @@ float CCTweenFunction::quintEaseInOut(float t, float b, float c, float d) return c / 2 * (t * t * t * t * t + 2) + b; } -float CCTweenFunction::sineEaseIn(float t, float b, float c, float d) +float TweenFunction::sineEaseIn(float t, float b, float c, float d) { return -c * cos(t / d * (M_PI / 2)) + c + b; } -float CCTweenFunction::sineEaseOut(float t, float b, float c, float d) +float TweenFunction::sineEaseOut(float t, float b, float c, float d) { return c * sin(t / d * (M_PI / 2)) + b; } -float CCTweenFunction::sineEaseInOut(float t, float b, float c, float d) +float TweenFunction::sineEaseInOut(float t, float b, float c, float d) { return -c / 2 * (cos(M_PI * t / d) - 1) + b; } -float CCTweenFunction::expoEaseIn(float t, float b, float c, float d) +float TweenFunction::expoEaseIn(float t, float b, float c, float d) { return (t == 0) ? b : c * pow(2, 10 * (t / d - 1)) + b; } -float CCTweenFunction::expoEaseOut(float t, float b, float c, float d) +float TweenFunction::expoEaseOut(float t, float b, float c, float d) { return (t == d) ? b + c : c * (-pow(2, -10 * t / d) + 1) + b; } -float CCTweenFunction::expoEaseInOut(float t, float b, float c, float d) +float TweenFunction::expoEaseInOut(float t, float b, float c, float d) { if (t == 0) return b; @@ -260,17 +260,17 @@ float CCTweenFunction::expoEaseInOut(float t, float b, float c, float d) return c / 2 * (-pow(2, -10 * t) + 2) + b; } -float CCTweenFunction::circEaseIn(float t, float b, float c, float d) +float TweenFunction::circEaseIn(float t, float b, float c, float d) { t /= d; return -c * (sqrt(1 - t * t) - 1) + b; } -float CCTweenFunction::circEaseOut(float t, float b, float c, float d) +float TweenFunction::circEaseOut(float t, float b, float c, float d) { t = t / d - 1; return c * sqrt(1 - t * t) + b; } -float CCTweenFunction::circEaseInOut(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) @@ -279,7 +279,7 @@ float CCTweenFunction::circEaseInOut(float t, float b, float c, float d) return c / 2 * (sqrt(1 - t * t) + 1) + b; } -float CCTweenFunction::elasticEaseIn(float t, float b, float c, float d, float a, float p) +float TweenFunction::elasticEaseIn(float t, float b, float c, float d, float a, float p) { float s = 0; if (t == 0) @@ -299,7 +299,7 @@ float CCTweenFunction::elasticEaseIn(float t, float b, float c, float d, float a t -= 1; return -(a * pow(2, 10 * t) * sin((t * d - s) * (2 * M_PI) / p)) + b; } -float CCTweenFunction::elasticEaseOut(float t, float b, float c, float d, float a, float p) +float TweenFunction::elasticEaseOut(float t, float b, float c, float d, float a, float p) { float s = 0; if (t == 0) @@ -318,7 +318,7 @@ float CCTweenFunction::elasticEaseOut(float t, float b, float c, float d, float s = p / (2 * M_PI) * asin(c / a); return (a * pow(2, -10 * t) * sin((t * d - s) * (2 * M_PI) / p) + c + b); } -float CCTweenFunction::elasticEaseInOut(float t, float b, float c, float d, float a, float p) +float TweenFunction::elasticEaseInOut(float t, float b, float c, float d, float a, float p) { float s = 0; if (t == 0) @@ -344,21 +344,21 @@ float CCTweenFunction::elasticEaseInOut(float t, float b, float c, float d, floa return a * pow(2, -10 * t) * sin((t * d - s) * (2 * M_PI) / p) * .5 + c + b; } -float CCTweenFunction::backEaseIn(float t, float b, float c, float d, float s) +float TweenFunction::backEaseIn(float t, float b, float c, float d, float s) { if (s == 0) s = 1.70158f; t /= d; return c * t * t * ((s + 1) * t - s) + b; } -float CCTweenFunction::backEaseOut(float t, float b, float c, float d, float s) +float TweenFunction::backEaseOut(float t, float b, float c, float d, float s) { if (s == 0) s = 1.70158f; t = t / d - 1; return c * (t * t * ((s + 1) * t + s) + 1) + b; } -float CCTweenFunction::backEaseInOut(float t, float b, float c, float d, float s) +float TweenFunction::backEaseInOut(float t, float b, float c, float d, float s) { if (s == 0) s = 1.70158f; @@ -373,12 +373,12 @@ float CCTweenFunction::backEaseInOut(float t, float b, float c, float d, float s return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b; } -float CCTweenFunction::bounceEaseIn(float t, float b, float c, float d) +float TweenFunction::bounceEaseIn(float t, float b, float c, float d) { return c - bounceEaseOut(d - t, 0, c, d) + b; } -float CCTweenFunction::bounceEaseOut(float t, float b, float c, float d) +float TweenFunction::bounceEaseOut(float t, float b, float c, float d) { t /= d; if (t < (1 / 2.75f)) @@ -402,7 +402,7 @@ float CCTweenFunction::bounceEaseOut(float t, float b, float c, float d) } } -float CCTweenFunction::bounceEaseInOut(float t, float b, float c, float d) +float TweenFunction::bounceEaseInOut(float t, float b, float c, float d) { if (t < d / 2) return bounceEaseIn(t * 2, 0, c, d) * .5 + b; diff --git a/extensions/CocoStudio/Armature/utils/CCTweenFunction.h b/extensions/CocoStudio/Armature/utils/CCTweenFunction.h index b45b3598a5..d0c76e8cc1 100644 --- a/extensions/CocoStudio/Armature/utils/CCTweenFunction.h +++ b/extensions/CocoStudio/Armature/utils/CCTweenFunction.h @@ -81,7 +81,7 @@ enum CCTweenType TWEEN_EASING_MAX = 10000 }; -class CCTweenFunction +class TweenFunction { public: diff --git a/extensions/CocoStudio/Reader/CCSSceneReader.cpp b/extensions/CocoStudio/Reader/CCSSceneReader.cpp index 323f9b0f1f..757e8c7924 100644 --- a/extensions/CocoStudio/Reader/CCSSceneReader.cpp +++ b/extensions/CocoStudio/Reader/CCSSceneReader.cpp @@ -245,11 +245,11 @@ NS_CC_EXT_BEGIN textupath += file_path; textupath.append(textureFileName); - cocos2d::extension::armature::CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(textupath.c_str(), plistpath.c_str(), pPath.c_str()); + cocos2d::extension::armature::ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(textupath.c_str(), plistpath.c_str(), pPath.c_str()); } - cocos2d::extension::armature::CCArmature *pAr = cocos2d::extension::armature::CCArmature::create(name); + cocos2d::extension::armature::Armature *pAr = cocos2d::extension::armature::Armature::create(name); ComRender *pRender = ComRender::create(pAr, "CCArmature"); if (pComName != NULL) { diff --git a/extensions/proj.win32/libExtensions.vcxproj b/extensions/proj.win32/libExtensions.vcxproj index 69b33937f0..de82211ac4 100644 --- a/extensions/proj.win32/libExtensions.vcxproj +++ b/extensions/proj.win32/libExtensions.vcxproj @@ -238,7 +238,6 @@ - diff --git a/extensions/proj.win32/libExtensions.vcxproj.filters b/extensions/proj.win32/libExtensions.vcxproj.filters index 5fb460acef..38153de465 100644 --- a/extensions/proj.win32/libExtensions.vcxproj.filters +++ b/extensions/proj.win32/libExtensions.vcxproj.filters @@ -662,9 +662,6 @@ CocoStudio\Armature\utils - - CocoStudio\Armature\utils - CocoStudio\Armature\utils diff --git a/samples/Cpp/TestCpp/Classes/AppDelegate.cpp b/samples/Cpp/TestCpp/Classes/AppDelegate.cpp index 89b6ccd15a..f997b34109 100644 --- a/samples/Cpp/TestCpp/Classes/AppDelegate.cpp +++ b/samples/Cpp/TestCpp/Classes/AppDelegate.cpp @@ -15,7 +15,7 @@ AppDelegate::AppDelegate() AppDelegate::~AppDelegate() { // SimpleAudioEngine::end(); - cocos2d::extension::armature::CCArmatureDataManager::purge(); + cocos2d::extension::armature::ArmatureDataManager::purge(); } bool AppDelegate::applicationDidFinishLaunching() diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index eb81fa5776..8275dc642a 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -122,7 +122,7 @@ void ArmatureTestScene::MainMenuCallback(Object *pSender) //TestScene::MainMenuCallback(pSender); removeAllChildren(); - CCArmatureDataManager::purge(); + ArmatureDataManager::purge(); } @@ -175,7 +175,7 @@ void ArmatureTestLayer::onExit() std::string ArmatureTestLayer::title() { - return "CCArmature Test Bed"; + return "Armature Test Bed"; } std::string ArmatureTestLayer::subtitle() { @@ -226,20 +226,20 @@ void TestAsynchronousLoading::onEnter() //! create a new thread to load data - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/robot.png", "armature/robot.plist", "armature/robot.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/Cowboy.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/robot.png", "armature/robot.plist", "armature/robot.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/Cowboy.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); //! load data directly - // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); - // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml"); - // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml"); - // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml"); - // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml"); - // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy.ExportJson"); + // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); + // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml"); + // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml"); + // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml"); + // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml"); + // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy.ExportJson"); } @@ -274,8 +274,8 @@ void TestAsynchronousLoading::dataLoaded(float percent) void TestCSWithSkeleton::onEnter() { ArmatureTestLayer::onEnter(); - CCArmature *armature = NULL; - armature = CCArmature::create("Cowboy"); + Armature *armature = NULL; + armature = Armature::create("Cowboy"); armature->getAnimation()->playByIndex(0); armature->setScale(0.2f); @@ -295,8 +295,8 @@ void TestDragonBones20::onEnter() { ArmatureTestLayer::onEnter(); - CCArmature *armature = NULL; - armature = CCArmature::create("Dragon"); + Armature *armature = NULL; + armature = Armature::create("Dragon"); armature->getAnimation()->playByIndex(1); armature->getAnimation()->setSpeedScale(0.4f); armature->setPosition(VisibleRect::center().x, VisibleRect::center().y * 0.3f); @@ -330,9 +330,9 @@ std::string TestPerformance::title() } std::string TestPerformance::subtitle() { - return "Current CCArmature Count : "; + return "Current Armature Count : "; } -void TestPerformance::addArmature(CCArmature *armature) +void TestPerformance::addArmature(Armature *armature) { armatureCount++; addChild(armature, armatureCount); @@ -344,8 +344,8 @@ void TestPerformance::update(float delta) if (frames / times > 58) { - CCArmature *armature = NULL; - armature = new CCArmature(); + Armature *armature = NULL; + armature = new Armature(); armature->init("Knight_f/Knight"); armature->getAnimation()->playByIndex(0); armature->setPosition(50 + armatureCount * 2, 150); @@ -369,24 +369,24 @@ void TestChangeZorder::onEnter() { ArmatureTestLayer::onEnter(); - CCArmature *armature = NULL; + Armature *armature = NULL; currentTag = -1; - armature = CCArmature::create("Knight_f/Knight"); + armature = Armature::create("Knight_f/Knight"); armature->getAnimation()->playByIndex(0); armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y - 100)); ++currentTag; armature->setScale(0.6f); addChild(armature, currentTag, currentTag); - armature = CCArmature::create("Cowboy"); + armature = Armature::create("Cowboy"); armature->getAnimation()->playByIndex(0); armature->setScale(0.24f); armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y - 100)); ++currentTag; addChild(armature, currentTag, currentTag); - armature = CCArmature::create("Dragon"); + armature = Armature::create("Dragon"); armature->getAnimation()->playByIndex(0); armature->setPosition(Point(VisibleRect::center().x , VisibleRect::center().y - 100)); ++currentTag; @@ -399,7 +399,7 @@ void TestChangeZorder::onEnter() } std::string TestChangeZorder::title() { - return "Test Change ZOrder Of Different CCArmature"; + return "Test Change ZOrder Of Different Armature"; } void TestChangeZorder::changeZorder(float dt) { @@ -418,7 +418,7 @@ void TestChangeZorder::changeZorder(float dt) void TestAnimationEvent::onEnter() { ArmatureTestLayer::onEnter(); - armature = CCArmature::create("Cowboy"); + armature = Armature::create("Cowboy"); armature->getAnimation()->play("Fire"); armature->setScaleX(-0.24f); armature->setScaleY(0.24f); @@ -433,9 +433,9 @@ void TestAnimationEvent::onEnter() } std::string TestAnimationEvent::title() { - return "Test CCArmature Animation Event"; + return "Test Armature Animation Event"; } -void TestAnimationEvent::animationEvent(CCArmature *armature, MovementEventType movementType, const char *movementID) +void TestAnimationEvent::animationEvent(Armature *armature, MovementEventType movementType, const char *movementID) { std::string id = movementID; @@ -478,7 +478,7 @@ void TestParticleDisplay::onEnter() animationID = 0; - armature = CCArmature::create("robot"); + armature = Armature::create("robot"); armature->getAnimation()->playByIndex(0); armature->setPosition(VisibleRect::center()); armature->setScale(0.48f); @@ -489,7 +489,7 @@ void TestParticleDisplay::onEnter() ParticleSystem *p1 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); ParticleSystem *p2 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); - CCBone *bone = CCBone::create("p1"); + Bone *bone = Bone::create("p1"); bone->addDisplay(p1, 0); bone->changeDisplayByIndex(0, true); bone->setIgnoreMovementBoneData(true); @@ -497,7 +497,7 @@ void TestParticleDisplay::onEnter() bone->setScale(1.2f); armature->addBone(bone, "bady-a3"); - bone = CCBone::create("p2"); + bone = Bone::create("p2"); bone->addDisplay(p2, 0); bone->changeDisplayByIndex(0, true); bone->setIgnoreMovementBoneData(true); @@ -541,7 +541,7 @@ void TestUseMutiplePicture::onEnter() displayIndex = 0; - armature = CCArmature::create("Knight_f/Knight"); + armature = Armature::create("Knight_f/Knight"); armature->getAnimation()->playByIndex(0); armature->setPosition(Point(VisibleRect::center().x, VisibleRect::left().y)); armature->setScale(1.2f); @@ -551,7 +551,7 @@ void TestUseMutiplePicture::onEnter() for (int i = 0; i < 7; i++) { - CCSkin *skin = CCSkin::createWithSpriteFrameName(weapon[i].c_str()); + Skin *skin = Skin::createWithSpriteFrameName(weapon[i].c_str()); armature->getBone("weapon")->addDisplay(skin, i); } @@ -573,7 +573,7 @@ void TestUseMutiplePicture::onExit() } std::string TestUseMutiplePicture::title() { - return "Test One CCArmature Use Different Picture"; + return "Test One Armature Use Different Picture"; } std::string TestUseMutiplePicture::subtitle() { @@ -604,7 +604,7 @@ void TestColliderDetector::onEnter() scheduleUpdate(); - armature = CCArmature::create("Cowboy"); + armature = Armature::create("Cowboy"); armature->getAnimation()->play("FireWithoutBullet"); armature->getAnimation()->setSpeedScale(0.2f); armature->setScaleX(-0.2f); @@ -619,7 +619,7 @@ void TestColliderDetector::onEnter() addChild(armature); - armature2 = CCArmature::create("Cowboy"); + armature2 = Armature::create("Cowboy"); armature2->getAnimation()->play("Walk"); armature2->setScaleX(-0.2f); armature2->setScaleY(0.2f); @@ -635,7 +635,7 @@ std::string TestColliderDetector::title() { return "Test Collider Detector"; } -void TestColliderDetector::onFrameEvent(CCBone *bone, const char *evt, int originFrameIndex, int currentFrameIndex) +void TestColliderDetector::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); @@ -724,8 +724,8 @@ void TestColliderDetector::update(float delta) { Contact &contact = *it; - CCBone *ba = (CCBone *)contact.fixtureA->GetUserData(); - CCBone *bb = (CCBone *)contact.fixtureB->GetUserData(); + Bone *ba = (Bone *)contact.fixtureA->GetUserData(); + Bone *bb = (Bone *)contact.fixtureB->GetUserData(); bb->getArmature()->setVisible(false); } @@ -791,7 +791,7 @@ int TestColliderDetector::beginHit(cpArbiter *arb, cpSpace *space, void *unused) { CP_ARBITER_GET_SHAPES(arb, a, b); - CCBone *bone = (CCBone *)a->data; + Bone *bone = (Bone *)a->data; bone->getArmature()->setVisible(false); return 0; @@ -801,7 +801,7 @@ void TestColliderDetector::endHit(cpArbiter *arb, cpSpace *space, void *unused) { CP_ARBITER_GET_SHAPES(arb, a, b); - CCBone *bone = (CCBone *)a->data; + Bone *bone = (Bone *)a->data; bone->getArmature()->setVisible(true); } @@ -889,7 +889,7 @@ void TestBoundingBox::onEnter() { ArmatureTestLayer::onEnter(); - armature = CCArmature::create("Cowboy"); + armature = Armature::create("Cowboy"); armature->getAnimation()->playByIndex(0); armature->setPosition(VisibleRect::center()); armature->setScale(0.2f); @@ -920,7 +920,7 @@ void TestAnchorPoint::onEnter() for (int i = 0; i < 5; i++) { - CCArmature *armature = CCArmature::create("Cowboy"); + Armature *armature = Armature::create("Cowboy"); armature->getAnimation()->playByIndex(0); armature->setPosition(VisibleRect::center()); armature->setScale(0.2f); @@ -945,7 +945,7 @@ void TestArmatureNesting::onEnter() ArmatureTestLayer::onEnter(); setTouchEnabled(true); - armature = CCArmature::create("cyborg"); + armature = Armature::create("cyborg"); armature->getAnimation()->playByIndex(1); armature->setPosition(VisibleRect::center()); armature->setScale(1.2f); @@ -961,7 +961,7 @@ void TestArmatureNesting::onExit() } std::string TestArmatureNesting::title() { - return "Test CCArmature Nesting"; + return "Test Armature Nesting"; } bool TestArmatureNesting::ccTouchBegan(Touch *pTouch, Event *pEvent) { diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index f743f82a22..d76f678afa 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -96,7 +96,7 @@ public: virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); - virtual void addArmature(cocos2d::extension::armature::CCArmature *armature); + virtual void addArmature(cocos2d::extension::armature::Armature *armature); void update(float delta); int armatureCount; @@ -124,11 +124,11 @@ public: virtual void onEnter(); virtual std::string title(); - void animationEvent(cocos2d::extension::armature::CCArmature *armature, cocos2d::extension::armature::MovementEventType movementType, const char *movementID); + void animationEvent(cocos2d::extension::armature::Armature *armature, cocos2d::extension::armature::MovementEventType movementType, const char *movementID); void callback1(); void callback2(); - cocos2d::extension::armature::CCArmature *armature; + cocos2d::extension::armature::Armature *armature; }; class TestUseMutiplePicture : public ArmatureTestLayer @@ -141,7 +141,7 @@ class TestUseMutiplePicture : public ArmatureTestLayer virtual void registerWithTouchDispatcher(); int displayIndex; - cocos2d::extension::armature::CCArmature *armature; + cocos2d::extension::armature::Armature *armature; }; class TestParticleDisplay : public ArmatureTestLayer @@ -154,7 +154,7 @@ class TestParticleDisplay : public ArmatureTestLayer virtual void registerWithTouchDispatcher(); int animationID; - cocos2d::extension::armature::CCArmature *armature; + cocos2d::extension::armature::Armature *armature; }; @@ -175,13 +175,13 @@ public: virtual void draw(); virtual void update(float delta); - void onFrameEvent(cocos2d::extension::armature::CCBone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); + void onFrameEvent(cocos2d::extension::armature::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); void initWorld(); - cocos2d::extension::armature::CCArmature *armature; - cocos2d::extension::armature::CCArmature *armature2; + cocos2d::extension::armature::Armature *armature; + cocos2d::extension::armature::Armature *armature2; cocos2d::extension::PhysicsSprite *bullet; @@ -204,13 +204,13 @@ public: virtual std::string title(); virtual void update(float delta); - void onFrameEvent(cocos2d::extension::armature::CCBone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); + void onFrameEvent(cocos2d::extension::armature::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); void initWorld(); - cocos2d::extension::armature::CCArmature *armature; - cocos2d::extension::armature::CCArmature *armature2; + cocos2d::extension::armature::Armature *armature; + cocos2d::extension::armature::Armature *armature2; cocos2d::extension::PhysicsSprite *bullet; @@ -235,7 +235,7 @@ public: virtual std::string title(); virtual void draw(); - cocos2d::extension::armature::CCArmature *armature; + cocos2d::extension::armature::Armature *armature; Rect rect; }; @@ -255,7 +255,7 @@ public: virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent); virtual void registerWithTouchDispatcher(); - cocos2d::extension::armature::CCArmature *armature; + cocos2d::extension::armature::Armature *armature; int weaponIndex; }; #endif // __HELLOWORLD_SCENE_H__ \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp index 646cc6ef79..3478a4ae68 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp @@ -95,14 +95,14 @@ void SceneEditorTestLayer::toExtensionsMainLayer(cocos2d::Object *sender) } -cocos2d::extension::armature::CCArmature* SceneEditorTestLayer::getFish(int nTag, const char *pszName) +cocos2d::extension::armature::Armature* SceneEditorTestLayer::getFish(int nTag, const char *pszName) { if (_curNode == NULL) { return NULL; } ComRender *pFishRender = (ComRender*)(_curNode->getChildByTag(nTag)->getComponent(pszName)); - return (cocos2d::extension::armature::CCArmature *)(pFishRender->getNode()); + return (cocos2d::extension::armature::Armature *)(pFishRender->getNode()); } void runSceneEditorTestLayer() diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h index 66a5407c5c..783e320cbd 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h @@ -29,7 +29,7 @@ public: void toExtensionsMainLayer(cocos2d::Object *sender); //get Fish based on Tag and name of Compoent - cocos2d::extension::armature::CCArmature* getFish(int nTag, const char *pszName); + cocos2d::extension::armature::Armature* getFish(int nTag, const char *pszName); private: cocos2d::Node *_curNode; From 77db15bd0d8c12e555b3e643c69f7fd1555bfc95 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Sun, 15 Sep 2013 20:24:25 +0800 Subject: [PATCH 16/28] change variables name --- extensions/CocoStudio/Armature/CCArmature.cpp | 218 ++++++++------- extensions/CocoStudio/Armature/CCArmature.h | 34 ++- extensions/CocoStudio/Armature/CCBone.cpp | 66 ++--- extensions/CocoStudio/Armature/CCBone.h | 10 +- .../animation/CCArmatureAnimation.cpp | 198 +++++++------- .../Armature/animation/CCArmatureAnimation.h | 22 +- .../Armature/animation/CCProcessBase.cpp | 80 +++--- .../Armature/animation/CCProcessBase.h | 26 +- .../CocoStudio/Armature/animation/CCTween.cpp | 250 +++++++++--------- .../CocoStudio/Armature/animation/CCTween.h | 28 +- .../CocoStudio/Armature/datas/CCDatas.h | 4 +- .../Armature/display/CCBatchNode.cpp | 10 +- .../CocoStudio/Armature/display/CCBatchNode.h | 2 +- .../Armature/display/CCDecorativeDisplay.cpp | 12 +- .../Armature/display/CCDecorativeDisplay.h | 6 +- .../Armature/display/CCDisplayManager.cpp | 166 ++++++------ .../Armature/display/CCDisplayManager.h | 14 +- .../CocoStudio/Armature/display/CCSkin.cpp | 30 +-- .../CocoStudio/Armature/display/CCSkin.h | 8 +- .../Armature/physics/CCColliderDetector.cpp | 104 ++++---- .../Armature/physics/CCColliderDetector.h | 20 +- .../Armature/utils/CCArmatureDataManager.cpp | 96 +++---- .../Armature/utils/CCArmatureDataManager.h | 12 +- .../Armature/utils/CCDataReaderHelper.cpp | 122 ++++----- .../Armature/utils/CCDataReaderHelper.h | 25 +- .../utils/CCSpriteFrameCacheHelper.cpp | 20 +- .../Armature/utils/CCSpriteFrameCacheHelper.h | 4 +- 27 files changed, 791 insertions(+), 796 deletions(-) diff --git a/extensions/CocoStudio/Armature/CCArmature.cpp b/extensions/CocoStudio/Armature/CCArmature.cpp index 61fabf20d0..6bcfcf0f5c 100644 --- a/extensions/CocoStudio/Armature/CCArmature.cpp +++ b/extensions/CocoStudio/Armature/CCArmature.cpp @@ -38,8 +38,6 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -std::map Armature::m_sArmatureIndexDic; - Armature *Armature::create() { Armature *armature = new Armature(); @@ -78,31 +76,31 @@ Armature *Armature::create(const char *name, Bone *parentBone) } Armature::Armature() - : m_pArmatureData(NULL) - , m_pBatchNode(NULL) - , m_pAtlas(NULL) - , m_pParentBone(NULL) - , m_bArmatureTransformDirty(true) - , m_pBoneDic(NULL) - , m_pTopBoneList(NULL) - , m_pAnimation(NULL) + : _armatureData(NULL) + , _batchNode(NULL) + , _atlas(NULL) + , _parentBone(NULL) + , _armatureTransformDirty(true) + , _boneDic(NULL) + , _topBoneList(NULL) + , _animation(NULL) { } Armature::~Armature(void) { - if(NULL != m_pBoneDic) + if(NULL != _boneDic) { - m_pBoneDic->removeAllObjects(); - CC_SAFE_DELETE(m_pBoneDic); + _boneDic->removeAllObjects(); + CC_SAFE_DELETE(_boneDic); } - if (NULL != m_pTopBoneList) + if (NULL != _topBoneList) { - m_pTopBoneList->removeAllObjects(); - CC_SAFE_DELETE(m_pTopBoneList); + _topBoneList->removeAllObjects(); + CC_SAFE_DELETE(_topBoneList); } - CC_SAFE_DELETE(m_pAnimation); + CC_SAFE_DELETE(_animation); } @@ -119,40 +117,40 @@ bool Armature::init(const char *name) { removeAllChildren(); - CC_SAFE_DELETE(m_pAnimation); - m_pAnimation = new ArmatureAnimation(); - m_pAnimation->init(this); + CC_SAFE_DELETE(_animation); + _animation = new ArmatureAnimation(); + _animation->init(this); - CC_SAFE_DELETE(m_pBoneDic); - m_pBoneDic = new Dictionary(); + CC_SAFE_DELETE(_boneDic); + _boneDic = new Dictionary(); - CC_SAFE_DELETE(m_pTopBoneList); - m_pTopBoneList = new Array(); - m_pTopBoneList->init(); + CC_SAFE_DELETE(_topBoneList); + _topBoneList = new Array(); + _topBoneList->init(); - m_sBlendFunc.src = CC_BLEND_SRC; - m_sBlendFunc.dst = CC_BLEND_DST; + _blendFunc.src = CC_BLEND_SRC; + _blendFunc.dst = CC_BLEND_DST; - m_strName = name == NULL ? "" : name; + _name = name == NULL ? "" : name; ArmatureDataManager *armatureDataManager = ArmatureDataManager::sharedArmatureDataManager(); - if(m_strName.length() != 0) + if(_name.length() != 0) { - m_strName = name; + _name = name; AnimationData *animationData = armatureDataManager->getAnimationData(name); CCAssert(animationData, "AnimationData not exist! "); - m_pAnimation->setAnimationData(animationData); + _animation->setAnimationData(animationData); ArmatureData *armatureData = armatureDataManager->getArmatureData(name); CCAssert(armatureData, ""); - m_pArmatureData = armatureData; + _armatureData = armatureData; DictElement *_element = NULL; @@ -185,17 +183,17 @@ bool Armature::init(const char *name) } else { - m_strName = "new_armature"; - m_pArmatureData = ArmatureData::create(); - m_pArmatureData->name = m_strName; + _name = "new_armature"; + _armatureData = ArmatureData::create(); + _armatureData->name = _name; AnimationData *animationData = AnimationData::create(); - animationData->name = m_strName; + animationData->name = _name; - armatureDataManager->addArmatureData(m_strName.c_str(), m_pArmatureData); - armatureDataManager->addAnimationData(m_strName.c_str(), animationData); + armatureDataManager->addArmatureData(_name.c_str(), _armatureData); + armatureDataManager->addAnimationData(_name.c_str(), animationData); - m_pAnimation->setAnimationData(animationData); + _animation->setAnimationData(animationData); } @@ -216,7 +214,7 @@ bool Armature::init(const char *name) bool Armature::init(const char *name, Bone *parentBone) { - m_pParentBone = parentBone; + _parentBone = parentBone; return init(name); } @@ -227,7 +225,7 @@ Bone *Armature::createBone(const char *boneName) if(existedBone != NULL) return existedBone; - BoneData *boneData = (BoneData *)m_pArmatureData->getBoneData(boneName); + BoneData *boneData = (BoneData *)_armatureData->getBoneData(boneName); std::string parentName = boneData->parentName; Bone *bone = NULL; @@ -254,34 +252,34 @@ Bone *Armature::createBone(const char *boneName) void Armature::addBone(Bone *bone, const char *parentName) { CCAssert( bone != NULL, "Argument must be non-nil"); - CCAssert(m_pBoneDic->objectForKey(bone->getName()) == NULL, "bone already added. It can't be added again"); + CCAssert(_boneDic->objectForKey(bone->getName()) == NULL, "bone already added. It can't be added again"); if (NULL != parentName) { - Bone *boneParent = (Bone *)m_pBoneDic->objectForKey(parentName); + Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName); if (boneParent) { boneParent->addChildBone(bone); } else { - if (m_pParentBone) - m_pParentBone->addChildBone(bone); + if (_parentBone) + _parentBone->addChildBone(bone); else - m_pTopBoneList->addObject(bone); + _topBoneList->addObject(bone); } } else { - if (m_pParentBone) - m_pParentBone->addChildBone(bone); + if (_parentBone) + _parentBone->addChildBone(bone); else - m_pTopBoneList->addObject(bone); + _topBoneList->addObject(bone); } bone->setArmature(this); - m_pBoneDic->setObject(bone, bone->getName()); + _boneDic->setObject(bone, bone->getName()); addChild(bone); } @@ -293,18 +291,18 @@ void Armature::removeBone(Bone *bone, bool recursion) bone->setArmature(NULL); bone->removeFromParent(recursion); - if (m_pTopBoneList->containsObject(bone)) + if (_topBoneList->containsObject(bone)) { - m_pTopBoneList->removeObject(bone); + _topBoneList->removeObject(bone); } - m_pBoneDic->removeObjectForKey(bone->getName()); + _boneDic->removeObjectForKey(bone->getName()); removeChild(bone, true); } Bone *Armature::getBone(const char *name) const { - return (Bone *)m_pBoneDic->objectForKey(name); + return (Bone *)_boneDic->objectForKey(name); } @@ -320,33 +318,33 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName) if (parentName != NULL) { - Bone *boneParent = (Bone *)m_pBoneDic->objectForKey(parentName); + Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName); if (boneParent) { boneParent->addChildBone(bone); - if (m_pTopBoneList->containsObject(bone)) + if (_topBoneList->containsObject(bone)) { - m_pTopBoneList->removeObject(bone); + _topBoneList->removeObject(bone); } } else { - m_pTopBoneList->addObject(bone); + _topBoneList->addObject(bone); } } } Dictionary *Armature::getBoneDic() { - return m_pBoneDic; + return _boneDic; } const AffineTransform& Armature::getNodeToParentTransform() const { if (_transformDirty) { - m_bArmatureTransformDirty = true; + _armatureTransformDirty = true; // Translate values float x = _position.x; @@ -373,8 +371,8 @@ const AffineTransform& Armature::getNodeToParentTransform() const } // Add offset point - x += cy * m_pOffsetPoint.x * _scaleX + -sx * m_pOffsetPoint.y * _scaleY; - y += sy * m_pOffsetPoint.x * _scaleX + cx * m_pOffsetPoint.y * _scaleY; + x += cy * _offsetPoint.x * _scaleX + -sx * _offsetPoint.y * _scaleY; + y += sy * _offsetPoint.x * _scaleX + cx * _offsetPoint.y * _scaleY; bool needsSkewMatrix = ( _skewX || _skewY ); @@ -427,47 +425,47 @@ void Armature::updateOffsetPoint() // Set contentsize and Calculate anchor point. Rect rect = boundingBox(); setContentSize(rect.size); - m_pOffsetPoint = Point(-rect.origin.x, -rect.origin.y); + _offsetPoint = Point(-rect.origin.x, -rect.origin.y); if (rect.size.width != 0 && rect.size.height != 0) { - setAnchorPoint(Point(m_pOffsetPoint.x / rect.size.width, m_pOffsetPoint.y / rect.size.height)); + setAnchorPoint(Point(_offsetPoint.x / rect.size.width, _offsetPoint.y / rect.size.height)); } } void Armature::setAnimation(ArmatureAnimation *animation) { - m_pAnimation = animation; + _animation = animation; } ArmatureAnimation *Armature::getAnimation() { - return m_pAnimation; + return _animation; } bool Armature::getArmatureTransformDirty() { - return m_bArmatureTransformDirty; + return _armatureTransformDirty; } void Armature::update(float dt) { - m_pAnimation->update(dt); + _animation->update(dt); Object *object = NULL; - CCARRAY_FOREACH(m_pTopBoneList, object) + CCARRAY_FOREACH(_topBoneList, object) { ((Bone *)object)->update(dt); } - m_bArmatureTransformDirty = false; + _armatureTransformDirty = false; } void Armature::draw() { - if (m_pParentBone == NULL) + if (_parentBone == NULL) { CC_NODE_DRAW_SETUP(); - GL::blendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); + GL::blendFunc(_blendFunc.src, _blendFunc.dst); } Object *object = NULL; @@ -489,17 +487,17 @@ void Armature::draw() TextureAtlas *textureAtlas = skin->getTextureAtlas(); BlendType blendType = bone->getBlendType(); - if(m_pAtlas != textureAtlas || blendType != BLEND_NORMAL) + if(_atlas != textureAtlas || blendType != BLEND_NORMAL) { - if (m_pAtlas) + if (_atlas) { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); + _atlas->drawQuads(); + _atlas->removeAllQuads(); } } - m_pAtlas = textureAtlas; - if (m_pAtlas->getCapacity() == m_pAtlas->getTotalQuads() && !m_pAtlas->resizeCapacity(m_pAtlas->getCapacity() * 2)) + _atlas = textureAtlas; + if (_atlas->getCapacity() == _atlas->getTotalQuads() && !_atlas->resizeCapacity(_atlas->getCapacity() * 2)) return; skin->updateTransform(); @@ -507,9 +505,9 @@ void Armature::draw() if (blendType != BLEND_NORMAL) { updateBlendType(blendType); - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); - GL::blendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); + _atlas->drawQuads(); + _atlas->removeAllQuads(); + GL::blendFunc(_blendFunc.src, _blendFunc.dst); } } break; @@ -518,12 +516,12 @@ void Armature::draw() Armature *armature = (Armature *)(node); TextureAtlas *textureAtlas = armature->getTextureAtlas(); - if(m_pAtlas != textureAtlas) + if(_atlas != textureAtlas) { - if (m_pAtlas) + if (_atlas) { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); + _atlas->drawQuads(); + _atlas->removeAllQuads(); } } armature->draw(); @@ -531,37 +529,37 @@ void Armature::draw() break; default: { - if (m_pAtlas) + if (_atlas) { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); + _atlas->drawQuads(); + _atlas->removeAllQuads(); } node->visit(); CC_NODE_DRAW_SETUP(); - GL::blendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); + GL::blendFunc(_blendFunc.src, _blendFunc.dst); } break; } } else if(Node *node = dynamic_cast(object)) { - if (m_pAtlas) + if (_atlas) { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); + _atlas->drawQuads(); + _atlas->removeAllQuads(); } node->visit(); CC_NODE_DRAW_SETUP(); - GL::blendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); + GL::blendFunc(_blendFunc.src, _blendFunc.dst); } } - if(m_pAtlas && !m_pBatchNode && m_pParentBone == NULL) + if(_atlas && !_batchNode && _parentBone == NULL) { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); + _atlas->drawQuads(); + _atlas->removeAllQuads(); } } @@ -693,18 +691,18 @@ Bone *Armature::getBoneAtPoint(float x, float y) #if ENABLE_PHYSICS_BOX2D_DETECT b2Body *Armature::getBody() { - return m_pBody; + return _body; } void Armature::setBody(b2Body *body) { - if (m_pBody == body) + if (_body == body) { return; } - m_pBody = body; - m_pBody->SetUserData(this); + _body = body; + _body->SetUserData(this); Object *object = NULL; CCARRAY_FOREACH(_children, object) @@ -719,7 +717,7 @@ void Armature::setBody(b2Body *body) ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); if (detector != NULL) { - detector->setBody(m_pBody); + detector->setBody(_body); } } } @@ -728,9 +726,9 @@ void Armature::setBody(b2Body *body) b2Fixture *Armature::getShapeList() { - if (m_pBody) + if (_body) { - return m_pBody->GetFixtureList(); + return _body->GetFixtureList(); } else { @@ -741,18 +739,18 @@ b2Fixture *Armature::getShapeList() #elif ENABLE_PHYSICS_CHIPMUNK_DETECT cpBody *Armature::getBody() { - return m_pBody; + return _body; } void Armature::setBody(cpBody *body) { - if (m_pBody == body) + if (_body == body) { return; } - m_pBody = body; - m_pBody->data = this; + _body = body; + _body->data = this; Object *object = NULL; CCARRAY_FOREACH(_children, object) @@ -767,7 +765,7 @@ void Armature::setBody(cpBody *body) ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector(); if (detector != NULL) { - detector->setBody(m_pBody); + detector->setBody(_body); } } } @@ -776,9 +774,9 @@ void Armature::setBody(cpBody *body) cpShape *Armature::getShapeList() { - if (m_pBody) + if (_body) { - return m_pBody->shapeList_private; + return _body->shapeList_private; } else { diff --git a/extensions/CocoStudio/Armature/CCArmature.h b/extensions/CocoStudio/Armature/CCArmature.h index a89ab05a4e..a13f2722cc 100644 --- a/extensions/CocoStudio/Armature/CCArmature.h +++ b/extensions/CocoStudio/Armature/CCArmature.h @@ -126,11 +126,11 @@ public: inline void setBlendFunc(const BlendFunc &blendFunc) { - m_sBlendFunc = blendFunc; + _blendFunc = blendFunc; } inline const BlendFunc &getBlendFunc(void) const { - return m_sBlendFunc; + return _blendFunc; } virtual void setAnimation(ArmatureAnimation *animation); @@ -154,37 +154,35 @@ protected: //! Update blend function void updateBlendType(BlendType blendType); - CC_SYNTHESIZE(ArmatureData *, m_pArmatureData, ArmatureData); + CC_SYNTHESIZE(ArmatureData *, _armatureData, ArmatureData); - CC_SYNTHESIZE(BatchNode *, m_pBatchNode, BatchNode); + CC_SYNTHESIZE(BatchNode *, _batchNode, BatchNode); - CC_SYNTHESIZE(std::string, m_strName, Name); + CC_SYNTHESIZE(std::string, _name, Name); - CC_SYNTHESIZE(TextureAtlas *, m_pAtlas, TextureAtlas); + CC_SYNTHESIZE(TextureAtlas *, _atlas, TextureAtlas); - CC_SYNTHESIZE(Bone *, m_pParentBone, ParentBone); + CC_SYNTHESIZE(Bone *, _parentBone, ParentBone); - CC_SYNTHESIZE(float, m_fVersion, Version); + CC_SYNTHESIZE(float, _version, Version); protected: - mutable bool m_bArmatureTransformDirty; + mutable bool _armatureTransformDirty; - Dictionary *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. + 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. - Array *m_pTopBoneList; + Array *_topBoneList; - static std::map m_sArmatureIndexDic; //! Use to save armature zorder info, + BlendFunc _blendFunc; //! It's required for CCTextureProtocol inheritance - BlendFunc m_sBlendFunc; //! It's required for CCTextureProtocol inheritance + Point _offsetPoint; - Point m_pOffsetPoint; - - ArmatureAnimation *m_pAnimation; + ArmatureAnimation *_animation; #if ENABLE_PHYSICS_BOX2D_DETECT - CC_PROPERTY(b2Body *, m_pBody, Body); + CC_PROPERTY(b2Body *, _body, Body); #elif ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_PROPERTY(cpBody *, m_pBody, Body); + CC_PROPERTY(cpBody *, _body, Body); #endif }; diff --git a/extensions/CocoStudio/Armature/CCBone.cpp b/extensions/CocoStudio/Armature/CCBone.cpp index 9c39567936..d15c7d8e6a 100644 --- a/extensions/CocoStudio/Armature/CCBone.cpp +++ b/extensions/CocoStudio/Armature/CCBone.cpp @@ -60,9 +60,9 @@ Bone *Bone::create(const char *name) Bone::Bone() { - m_pTweenData = NULL; - m_pParentBone = NULL; - m_pArmature = NULL; + _tweenData = NULL; + _parentBone = NULL; + _armature = NULL; m_pChildArmature = NULL; m_pBoneData = NULL; m_pTween = NULL; @@ -78,7 +78,7 @@ Bone::Bone() Bone::~Bone(void) { - CC_SAFE_DELETE(m_pTweenData); + CC_SAFE_DELETE(_tweenData); CC_SAFE_DELETE(_children); CC_SAFE_DELETE(m_pTween); CC_SAFE_DELETE(m_pDisplayManager); @@ -105,11 +105,11 @@ bool Bone::init(const char *name) if(NULL != name) { - m_strName = name; + _name = name; } - CC_SAFE_DELETE(m_pTweenData); - m_pTweenData = new FrameData(); + CC_SAFE_DELETE(_tweenData); + _tweenData = new FrameData(); CC_SAFE_DELETE(m_pTween); m_pTween = new Tween(); @@ -134,7 +134,7 @@ void Bone::setBoneData(BoneData *boneData) m_pBoneData = boneData; m_pBoneData->retain(); - m_strName = m_pBoneData->name; + _name = m_pBoneData->name; _ZOrder = m_pBoneData->zOrder; m_pDisplayManager->initDisplayList(boneData); @@ -147,44 +147,44 @@ BoneData *Bone::getBoneData() void Bone::setArmature(Armature *armature) { - m_pArmature = armature; - if (m_pArmature) + _armature = armature; + if (_armature) { - m_pTween->setAnimation(m_pArmature->getAnimation()); + m_pTween->setAnimation(_armature->getAnimation()); } } Armature *Bone::getArmature() { - return m_pArmature; + return _armature; } void Bone::update(float delta) { - if (m_pParentBone) - m_bBoneTransformDirty = m_bBoneTransformDirty || m_pParentBone->isTransformDirty(); + if (_parentBone) + m_bBoneTransformDirty = m_bBoneTransformDirty || _parentBone->isTransformDirty(); if (m_bBoneTransformDirty) { - if (m_pArmature->getArmatureData()->dataVersion >= VERSION_COMBINED) + if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) { - TransformHelp::nodeConcat(*m_pTweenData, *m_pBoneData); - m_pTweenData->scaleX -= 1; - m_pTweenData->scaleY -= 1; + TransformHelp::nodeConcat(*_tweenData, *m_pBoneData); + _tweenData->scaleX -= 1; + _tweenData->scaleY -= 1; } - TransformHelp::nodeToMatrix(*m_pTweenData, m_tWorldTransform); + TransformHelp::nodeToMatrix(*_tweenData, m_tWorldTransform); m_tWorldTransform = AffineTransformConcat(getNodeToParentTransform(), m_tWorldTransform); - if(m_pParentBone) + if(_parentBone) { - m_tWorldTransform = AffineTransformConcat(m_tWorldTransform, m_pParentBone->m_tWorldTransform); + m_tWorldTransform = AffineTransformConcat(m_tWorldTransform, _parentBone->m_tWorldTransform); } } - DisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty || m_pArmature->getArmatureTransformDirty()); + DisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty || _armature->getArmatureTransformDirty()); Object *object = NULL; CCARRAY_FOREACH(_children, object) @@ -217,28 +217,28 @@ void Bone::updateColor() RGBAProtocol *protocol = dynamic_cast(display); if(protocol != NULL) { - protocol->setColor(Color3B(_displayedColor.r * m_pTweenData->r / 255, _displayedColor.g * m_pTweenData->g / 255, _displayedColor.b * m_pTweenData->b / 255)); - protocol->setOpacity(_displayedOpacity * m_pTweenData->a / 255); + 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 (m_pArmature->getArmatureData()->dataVersion >= VERSION_COMBINED) + if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) { - int zorder = m_pTweenData->zOrder + m_pBoneData->zOrder; + int zorder = _tweenData->zOrder + m_pBoneData->zOrder; setZOrder(zorder); } else { - setZOrder(m_pTweenData->zOrder); + setZOrder(_tweenData->zOrder); } } void Bone::addChildBone(Bone *child) { CCAssert( NULL != child, "Argument must be non-nil"); - CCAssert( NULL == child->m_pParentBone, "child already added. It can't be added again"); + CCAssert( NULL == child->_parentBone, "child already added. It can't be added again"); if(!_children) { @@ -278,20 +278,20 @@ void Bone::removeChildBone(Bone *bone, bool recursion) void Bone::removeFromParent(bool recursion) { - if (NULL != m_pParentBone) + if (NULL != _parentBone) { - m_pParentBone->removeChildBone(this, recursion); + _parentBone->removeChildBone(this, recursion); } } void Bone::setParentBone(Bone *parent) { - m_pParentBone = parent; + _parentBone = parent; } Bone *Bone::getParentBone() { - return m_pParentBone; + return _parentBone; } void Bone::setChildArmature(Armature *armature) @@ -337,7 +337,7 @@ AffineTransform Bone::getNodeToArmatureTransform() const AffineTransform Bone::getNodeToWorldTransform() const { - return AffineTransformConcat(m_tWorldTransform, m_pArmature->getNodeToWorldTransform()); + return AffineTransformConcat(m_tWorldTransform, _armature->getNodeToWorldTransform()); } Node *Bone::getDisplayRenderNode() diff --git a/extensions/CocoStudio/Armature/CCBone.h b/extensions/CocoStudio/Armature/CCBone.h index 3484e9d93c..20cf1080c9 100644 --- a/extensions/CocoStudio/Armature/CCBone.h +++ b/extensions/CocoStudio/Armature/CCBone.h @@ -152,13 +152,13 @@ public: public: /* - * The origin state of the Bone. Display's state is effected by m_pBoneData, m_pNode, m_pTweenData + * The origin state of the Bone. Display's state is effected by m_pBoneData, m_pNode, _tweenData * when call setData function, it will copy from the BoneData. */ CC_PROPERTY(BoneData *, m_pBoneData, BoneData); //! A weak reference to the Armature - CC_PROPERTY(Armature *, m_pArmature, Armature); + CC_PROPERTY(Armature *, _armature, Armature); //! A weak reference to the child Armature CC_PROPERTY(Armature *, m_pChildArmature, ChildArmature); @@ -176,11 +176,11 @@ protected: Tween *m_pTween; //! Calculate tween effect //! Used for making tween effect in every frame - CC_SYNTHESIZE_READONLY(FrameData *, m_pTweenData, TweenData); + CC_SYNTHESIZE_READONLY(FrameData *, _tweenData, TweenData); - CC_SYNTHESIZE(std::string, m_strName, Name); + CC_SYNTHESIZE(std::string, _name, Name); - Bone *m_pParentBone; //! A weak reference to its parent + Bone *_parentBone; //! A weak reference to its parent bool m_bBoneTransformDirty; //! Whether or not transform dirty //! self Transform, use this to change display's state diff --git a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp index e54621c80f..96543635a6 100644 --- a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp +++ b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp @@ -46,28 +46,28 @@ ArmatureAnimation *ArmatureAnimation::create(Armature *armature) ArmatureAnimation::ArmatureAnimation() - : m_pAnimationData(NULL) - , m_fSpeedScale(1) - , m_pMovementData(NULL) - , m_pArmature(NULL) - , m_strMovementID("") - , m_iToIndex(0) + : _animationData(NULL) + , _speedScale(1) + , _movementData(NULL) + , _armature(NULL) + , _movementID("") + , _toIndex(0) - , m_sMovementEventCallFunc(NULL) - , m_sFrameEventCallFunc(NULL) - , m_sMovementEventTarget(NULL) - , m_sFrameEventTarget(NULL) + , _movementEventCallFunc(NULL) + , _frameEventCallFunc(NULL) + , _movementEventTarget(NULL) + , _frameEventTarget(NULL) { } ArmatureAnimation::~ArmatureAnimation(void) { - CC_SAFE_RELEASE_NULL(m_pTweenList); - CC_SAFE_RELEASE_NULL(m_pAnimationData); + CC_SAFE_RELEASE_NULL(_tweenList); + CC_SAFE_RELEASE_NULL(_animationData); - CC_SAFE_RELEASE_NULL(m_sMovementEventTarget); - CC_SAFE_RELEASE_NULL(m_sFrameEventTarget); + CC_SAFE_RELEASE_NULL(_movementEventTarget); + CC_SAFE_RELEASE_NULL(_frameEventTarget); } bool ArmatureAnimation::init(Armature *armature) @@ -75,10 +75,10 @@ bool ArmatureAnimation::init(Armature *armature) bool bRet = false; do { - m_pArmature = armature; + _armature = armature; - m_pTweenList = new Array(); - m_pTweenList->init(); + _tweenList = new Array(); + _tweenList->init(); bRet = true; } @@ -91,7 +91,7 @@ bool ArmatureAnimation::init(Armature *armature) void ArmatureAnimation:: pause() { Object *object = NULL; - CCARRAY_FOREACH(m_pTweenList, object) + CCARRAY_FOREACH(_tweenList, object) { ((Tween *)object)->pause(); } @@ -101,7 +101,7 @@ void ArmatureAnimation:: pause() void ArmatureAnimation::resume() { Object *object = NULL; - CCARRAY_FOREACH(m_pTweenList, object) + CCARRAY_FOREACH(_tweenList, object) { ((Tween *)object)->resume(); } @@ -111,11 +111,11 @@ void ArmatureAnimation::resume() void ArmatureAnimation::stop() { Object *object = NULL; - CCARRAY_FOREACH(m_pTweenList, object) + CCARRAY_FOREACH(_tweenList, object) { ((Tween *)object)->stop(); } - m_pTweenList->removeAllObjects(); + _tweenList->removeAllObjects(); ProcessBase::stop(); } @@ -132,52 +132,52 @@ float ArmatureAnimation::getAnimationScale() const void ArmatureAnimation::setSpeedScale(float speedScale) { - if(speedScale == m_fSpeedScale) + if(speedScale == _speedScale) { return; } - m_fSpeedScale = speedScale; + _speedScale = speedScale; - m_fProcessScale = !m_pMovementData ? m_fSpeedScale : m_fSpeedScale * m_pMovementData->scale; + _processScale = !_movementData ? _speedScale : _speedScale * _movementData->scale; DictElement *element = NULL; - Dictionary *dict = m_pArmature->getBoneDic(); + Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { Bone *bone = (Bone *)element->getObject(); - bone->getTween()->setProcessScale(m_fProcessScale); + bone->getTween()->setProcessScale(_processScale); if (bone->getChildArmature()) { - bone->getChildArmature()->getAnimation()->setProcessScale(m_fProcessScale); + bone->getChildArmature()->getAnimation()->setProcessScale(_processScale); } } } float ArmatureAnimation::getSpeedScale() const { - return m_fSpeedScale; + return _speedScale; } void ArmatureAnimation::setAnimationInternal(float animationInternal) { - if(animationInternal == m_fAnimationInternal) + if(animationInternal == _animationInternal) { return; } - m_fAnimationInternal = animationInternal; + _animationInternal = animationInternal; DictElement *element = NULL; - Dictionary *dict = m_pArmature->getBoneDic(); + Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { Bone *bone = (Bone *)element->getObject(); - bone->getTween()->setAnimationInternal(m_fAnimationInternal); + bone->getTween()->setAnimationInternal(_animationInternal); if (bone->getChildArmature()) { - bone->getChildArmature()->getAnimation()->setAnimationInternal(m_fAnimationInternal); + bone->getChildArmature()->getAnimation()->setAnimationInternal(_animationInternal); } } } @@ -185,74 +185,74 @@ void ArmatureAnimation::setAnimationInternal(float animationInternal) void ArmatureAnimation::play(const char *animationName, int durationTo, int durationTween, int loop, int tweenEasing) { - CCAssert(m_pAnimationData, "m_pAnimationData can not be null"); + CCAssert(_animationData, "_animationData can not be null"); - m_pMovementData = m_pAnimationData->getMovement(animationName); - CCAssert(m_pMovementData, "m_pMovementData can not be null"); + _movementData = _animationData->getMovement(animationName); + CCAssert(_movementData, "_movementData can not be null"); //! Get key frame count - m_iRawDuration = m_pMovementData->duration; + _rawDuration = _movementData->duration; - m_strMovementID = animationName; + _movementID = animationName; - m_fProcessScale = m_fSpeedScale * m_pMovementData->scale; + _processScale = _speedScale * _movementData->scale; //! Further processing parameters - durationTo = (durationTo == -1) ? m_pMovementData->durationTo : durationTo; + durationTo = (durationTo == -1) ? _movementData->durationTo : durationTo; - durationTween = (durationTween == -1) ? m_pMovementData->durationTween : durationTween; - durationTween = (durationTween == 0) ? m_pMovementData->duration : durationTween; + durationTween = (durationTween == -1) ? _movementData->durationTween : durationTween; + durationTween = (durationTween == 0) ? _movementData->duration : durationTween; - tweenEasing = (tweenEasing == TWEEN_EASING_MAX) ? m_pMovementData->tweenEasing : tweenEasing; - loop = (loop < 0) ? m_pMovementData->loop : loop; + tweenEasing = (tweenEasing == TWEEN_EASING_MAX) ? _movementData->tweenEasing : tweenEasing; + loop = (loop < 0) ? _movementData->loop : loop; ProcessBase::play((void *)animationName, durationTo, durationTween, loop, tweenEasing); - if (m_iRawDuration == 0) + if (_rawDuration == 0) { - m_eLoopType = SINGLE_FRAME; + _loopType = SINGLE_FRAME; } else { if (loop) { - m_eLoopType = ANIMATION_TO_LOOP_FRONT; + _loopType = ANIMATION_TO_LOOP_FRONT; } else { - m_eLoopType = ANIMATION_NO_LOOP; - m_iRawDuration --; + _loopType = ANIMATION_NO_LOOP; + _rawDuration --; } - m_iDurationTween = durationTween; + _durationTween = durationTween; } MovementBoneData *movementBoneData = NULL; - m_pTweenList->removeAllObjects(); + _tweenList->removeAllObjects(); DictElement *element = NULL; - Dictionary *dict = m_pArmature->getBoneDic(); + Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { Bone *bone = (Bone *)element->getObject(); - movementBoneData = (MovementBoneData *)m_pMovementData->movBoneDataDic.objectForKey(bone->getName()); + movementBoneData = (MovementBoneData *)_movementData->movBoneDataDic.objectForKey(bone->getName()); Tween *tween = bone->getTween(); if(movementBoneData && movementBoneData->frameList.count() > 0) { - m_pTweenList->addObject(tween); - movementBoneData->duration = m_pMovementData->duration; + _tweenList->addObject(tween); + movementBoneData->duration = _movementData->duration; tween->play(movementBoneData, durationTo, durationTween, loop, tweenEasing); - tween->setProcessScale(m_fProcessScale); - tween->setAnimationInternal(m_fAnimationInternal); + tween->setProcessScale(_processScale); + tween->setAnimationInternal(_animationInternal); if (bone->getChildArmature()) { - bone->getChildArmature()->getAnimation()->setProcessScale(m_fProcessScale); - bone->getChildArmature()->getAnimation()->setAnimationInternal(m_fAnimationInternal); + bone->getChildArmature()->getAnimation()->setProcessScale(_processScale); + bone->getChildArmature()->getAnimation()->setAnimationInternal(_animationInternal); } } else @@ -271,7 +271,7 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int durationTween, int loop, int tweenEasing) { - std::vector &movName = m_pAnimationData->movementNames; + std::vector &movName = _animationData->movementNames; CC_ASSERT((animationIndex > -1) && ((unsigned int)animationIndex < movName.size())); std::string animationName = movName.at(animationIndex); @@ -282,14 +282,14 @@ void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int dura int ArmatureAnimation::getMovementCount() { - return m_pAnimationData->getMovementCount(); + return _animationData->getMovementCount(); } void ArmatureAnimation::update(float dt) { ProcessBase::update(dt); Object *object = NULL; - CCARRAY_FOREACH(m_pTweenList, object) + CCARRAY_FOREACH(_tweenList, object) { ((Tween *)object)->update(dt); } @@ -297,26 +297,26 @@ void ArmatureAnimation::update(float dt) void ArmatureAnimation::updateHandler() { - if (m_fCurrentPercent >= 1) + if (_currentPercent >= 1) { - switch(m_eLoopType) + switch(_loopType) { case ANIMATION_NO_LOOP: { - m_eLoopType = ANIMATION_MAX; - m_fCurrentFrame = (m_fCurrentPercent - 1) * m_iNextFrameIndex; - m_fCurrentPercent = m_fCurrentFrame / m_iDurationTween; + _loopType = ANIMATION_MAX; + _currentFrame = (_currentPercent - 1) * m_iNextFrameIndex; + _currentPercent = _currentFrame / _durationTween; - if (m_fCurrentPercent >= 1.0f) + if (_currentPercent >= 1.0f) { } else { - m_iNextFrameIndex = m_iDurationTween; + m_iNextFrameIndex = _durationTween; - if (m_sMovementEventTarget && m_sMovementEventCallFunc) + if (_movementEventTarget && _movementEventCallFunc) { - (m_sMovementEventTarget->*m_sMovementEventCallFunc)(m_pArmature, START, m_strMovementID.c_str()); + (_movementEventTarget->*_movementEventCallFunc)(_armature, START, _movementID.c_str()); } break; @@ -326,38 +326,38 @@ void ArmatureAnimation::updateHandler() case ANIMATION_MAX: case SINGLE_FRAME: { - m_fCurrentPercent = 1; - m_bIsComplete = true; - m_bIsPlaying = false; + _currentPercent = 1; + _isComplete = true; + _isPlaying = false; - if (m_sMovementEventTarget && m_sMovementEventCallFunc) + if (_movementEventTarget && _movementEventCallFunc) { - (m_sMovementEventTarget->*m_sMovementEventCallFunc)(m_pArmature, COMPLETE, m_strMovementID.c_str()); + (_movementEventTarget->*_movementEventCallFunc)(_armature, COMPLETE, _movementID.c_str()); } } break; case ANIMATION_TO_LOOP_FRONT: { - m_eLoopType = ANIMATION_LOOP_FRONT; - m_fCurrentPercent = fmodf(m_fCurrentPercent, 1); - m_fCurrentFrame = m_iNextFrameIndex == 0 ? 0 : fmodf(m_fCurrentFrame, m_iNextFrameIndex); - m_iNextFrameIndex = m_iDurationTween > 0 ? m_iDurationTween : 1; + _loopType = ANIMATION_LOOP_FRONT; + _currentPercent = fmodf(_currentPercent, 1); + _currentFrame = m_iNextFrameIndex == 0 ? 0 : fmodf(_currentFrame, m_iNextFrameIndex); + m_iNextFrameIndex = _durationTween > 0 ? _durationTween : 1; - if (m_sMovementEventTarget && m_sMovementEventCallFunc) + if (_movementEventTarget && _movementEventCallFunc) { - (m_sMovementEventTarget->*m_sMovementEventCallFunc)(m_pArmature, START, m_strMovementID.c_str()); + (_movementEventTarget->*_movementEventCallFunc)(_armature, START, _movementID.c_str()); } } break; default: { - //m_fCurrentPercent = fmodf(m_fCurrentPercent, 1); - m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); - m_iToIndex = 0; + //_currentPercent = fmodf(_currentPercent, 1); + _currentFrame = fmodf(_currentFrame, m_iNextFrameIndex); + _toIndex = 0; - if (m_sMovementEventTarget && m_sMovementEventCallFunc) + if (_movementEventTarget && _movementEventCallFunc) { - (m_sMovementEventTarget->*m_sMovementEventCallFunc)(m_pArmature, LOOP_COMPLETE, m_strMovementID.c_str()); + (_movementEventTarget->*_movementEventCallFunc)(_armature, LOOP_COMPLETE, _movementID.c_str()); } } break; @@ -367,40 +367,40 @@ void ArmatureAnimation::updateHandler() std::string ArmatureAnimation::getCurrentMovementID() { - if (m_bIsComplete) + if (_isComplete) { return ""; } - return m_strMovementID; + return _movementID; } void ArmatureAnimation::setMovementEventCallFunc(Object *target, SEL_MovementEventCallFunc callFunc) { - if (target != m_sMovementEventTarget) + if (target != _movementEventTarget) { CC_SAFE_RETAIN(target); - CC_SAFE_RELEASE_NULL(m_sMovementEventTarget); - m_sMovementEventTarget = target; + CC_SAFE_RELEASE_NULL(_movementEventTarget); + _movementEventTarget = target; } - m_sMovementEventCallFunc = callFunc; + _movementEventCallFunc = callFunc; } void ArmatureAnimation::setFrameEventCallFunc(Object *target, SEL_FrameEventCallFunc callFunc) { - if (target != m_sFrameEventTarget) + if (target != _frameEventTarget) { CC_SAFE_RETAIN(target); - CC_SAFE_RELEASE_NULL(m_sFrameEventTarget); - m_sFrameEventTarget = target; + CC_SAFE_RELEASE_NULL(_frameEventTarget); + _frameEventTarget = target; } - m_sFrameEventCallFunc = callFunc; + _frameEventCallFunc = callFunc; } void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex) { - if (m_sFrameEventTarget && m_sFrameEventCallFunc) + if (_frameEventTarget && _frameEventCallFunc) { - (m_sFrameEventTarget->*m_sFrameEventCallFunc)(bone, frameEventName, originFrameIndex, currentFrameIndex); + (_frameEventTarget->*_frameEventCallFunc)(bone, frameEventName, originFrameIndex, currentFrameIndex); } } NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h index a9f26911eb..d8813ef31b 100644 --- a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h +++ b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h @@ -179,20 +179,20 @@ protected: friend class Tween; protected: //! AnimationData save all MovementDatas this animation used. - CC_SYNTHESIZE_RETAIN(AnimationData *, m_pAnimationData, AnimationData); + CC_SYNTHESIZE_RETAIN(AnimationData *, _animationData, AnimationData); //! Scale the animation speed - float m_fSpeedScale; + float _speedScale; - MovementData *m_pMovementData; //! MovementData save all MovementFrameDatas this animation used. + MovementData *_movementData; //! MovementData save all MovementFrameDatas this animation used. - Armature *m_pArmature; //! A weak reference of armature + Armature *_armature; //! A weak reference of armature - std::string m_strMovementID; //! Current movment's name + std::string _movementID; //! Current movment's name - int m_iToIndex; //! The frame index in MovementData->m_pMovFrameDataArr, it's different from m_iFrameIndex. + int _toIndex; //! The frame index in MovementData->m_pMovFrameDataArr, it's different from m_iFrameIndex. - Array *m_pTweenList; + Array *_tweenList; protected: /** @@ -201,7 +201,7 @@ protected: * @param MovementEventType, Event Type, like START, COMPLETE. * @param const char*, Movement ID, also called Movement Name */ - SEL_MovementEventCallFunc m_sMovementEventCallFunc; + SEL_MovementEventCallFunc _movementEventCallFunc; /** * FrameEvent CallFunc. @@ -210,11 +210,11 @@ protected: * @param int, origin frame index * @param int, current frame index, animation may be delayed */ - SEL_FrameEventCallFunc m_sFrameEventCallFunc; + SEL_FrameEventCallFunc _frameEventCallFunc; - Object *m_sMovementEventTarget; - Object *m_sFrameEventTarget; + Object *_movementEventTarget; + Object *_frameEventTarget; }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp b/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp index eee757a969..c17137f1c3 100644 --- a/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp +++ b/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp @@ -28,24 +28,24 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN ProcessBase::ProcessBase(void) - : m_fProcessScale(1) - , m_bIsPause(true) - , m_bIsComplete(true) - , m_bIsPlaying(false) - , m_fCurrentPercent(0.0f) - , m_iRawDuration(0) - , m_eLoopType(ANIMATION_LOOP_BACK) - , m_eTweenEasing(Linear) - , m_iDurationTween(0) - , m_fCurrentFrame(0) - , m_iCurFrameIndex(0) - , m_bIsLoopBack(false) + : _processScale(1) + , _isPause(true) + , _isComplete(true) + , _isPlaying(false) + , _currentPercent(0.0f) + , _rawDuration(0) + , _loopType(ANIMATION_LOOP_BACK) + , _tweenEasing(Linear) + , _durationTween(0) + , _currentFrame(0) + , _curFrameIndex(0) + , _isLoopBack(false) { /* - * set m_fAnimationInternal defualt value to CCDirector::sharedDirector() + * set _animationInternal defualt value to CCDirector::sharedDirector() * ->getAnimationInterval(), in line with game update speed */ - m_fAnimationInternal = CCDirector::getInstance()->getAnimationInterval(); + _animationInternal = CCDirector::getInstance()->getAnimationInterval(); } @@ -56,45 +56,45 @@ ProcessBase::~ProcessBase(void) void ProcessBase::pause() { - m_bIsPause = true; - m_bIsPlaying = false; + _isPause = true; + _isPlaying = false; } void ProcessBase::resume() { - m_bIsPause = false; - m_bIsPlaying = true; + _isPause = false; + _isPlaying = true; } void ProcessBase::stop() { - m_bIsComplete = true; - m_bIsPlaying = false; - m_fCurrentFrame = 0; - m_fCurrentPercent = 0; + _isComplete = true; + _isPlaying = false; + _currentFrame = 0; + _currentPercent = 0; } void ProcessBase::play(void *animation, int durationTo, int durationTween, int loop, int tweenEasing) { - m_bIsComplete = false; - m_bIsPause = false; - m_bIsPlaying = true; - m_fCurrentFrame = 0; + _isComplete = false; + _isPause = false; + _isPlaying = true; + _currentFrame = 0; /* * Set m_iTotalFrames to durationTo, it is used for change tween between two animation. * When changing end, m_iTotalFrames will be setted to _durationTween */ m_iNextFrameIndex = durationTo; - m_eTweenEasing = (CCTweenType)tweenEasing; + _tweenEasing = (CCTweenType)tweenEasing; } void ProcessBase::update(float dt) { - if (m_bIsComplete || m_bIsPause) + if (_isComplete || _isPause) { return; } @@ -103,33 +103,33 @@ void ProcessBase::update(float dt) * Fileter the m_iDuration <=0 and dt >1 * If dt>1, generally speaking the reason is the device is stuck. */ - if(m_iRawDuration <= 0 || dt > 1) + if(_rawDuration <= 0 || dt > 1) { return; } if (m_iNextFrameIndex <= 0) { - m_fCurrentPercent = 1; - m_fCurrentFrame = 0; + _currentPercent = 1; + _currentFrame = 0; } else { /* - * update m_fCurrentFrame, every update add the frame passed. - * dt/m_fAnimationInternal determine it is not a frame animation. If frame speed changed, it will not make our + * update _currentFrame, every update add the frame passed. + * dt/_animationInternal determine it is not a frame animation. If frame speed changed, it will not make our * animation speed slower or quicker. */ - m_fCurrentFrame += m_fProcessScale * (dt / m_fAnimationInternal); + _currentFrame += _processScale * (dt / _animationInternal); - m_fCurrentPercent = m_fCurrentFrame / m_iNextFrameIndex; + _currentPercent = _currentFrame / m_iNextFrameIndex; /* - * if m_fCurrentFrame is bigger or equal than m_iTotalFrames, then reduce it util m_fCurrentFrame is + * if _currentFrame is bigger or equal than m_iTotalFrames, then reduce it util _currentFrame is * smaller than m_iTotalFrames */ - m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); + _currentFrame = fmodf(_currentFrame, m_iNextFrameIndex); } updateHandler(); @@ -139,14 +139,14 @@ void ProcessBase::update(float dt) void ProcessBase::gotoFrame(int frameIndex) { - m_iCurFrameIndex = frameIndex; + _curFrameIndex = frameIndex; pause(); } int ProcessBase::getCurrentFrameIndex() { - m_iCurFrameIndex = m_iRawDuration * m_fCurrentPercent; - return m_iCurFrameIndex; + _curFrameIndex = _rawDuration * _currentPercent; + return _curFrameIndex; } NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/animation/CCProcessBase.h b/extensions/CocoStudio/Armature/animation/CCProcessBase.h index d94c175530..fe1388aa6a 100644 --- a/extensions/CocoStudio/Armature/animation/CCProcessBase.h +++ b/extensions/CocoStudio/Armature/animation/CCProcessBase.h @@ -119,47 +119,47 @@ protected: protected: //! Scale the process speed - CC_SYNTHESIZE(float, m_fProcessScale, ProcessScale); + CC_SYNTHESIZE(float, _processScale, ProcessScale); //! Set and get whether the aniamtion is pause - CC_SYNTHESIZE(bool, m_bIsPause, IsPause); + CC_SYNTHESIZE(bool, _isPause, IsPause); //! Set and get whether the aniamtion is complete - CC_SYNTHESIZE(bool, m_bIsComplete, IsComplete); + CC_SYNTHESIZE(bool, _isComplete, IsComplete); //! Set and get whether the aniamtion is playing - CC_SYNTHESIZE(bool, m_bIsPlaying, IsPlaying); + CC_SYNTHESIZE(bool, _isPlaying, IsPlaying); //! Current percent this process arrived - CC_SYNTHESIZE(float, m_fCurrentPercent, CurrentPercent); + CC_SYNTHESIZE(float, _currentPercent, CurrentPercent); //! The raw duration - CC_SYNTHESIZE(int, m_iRawDuration, RawDuration); + CC_SYNTHESIZE(int, _rawDuration, RawDuration); //! The animation whether or not loop - CC_SYNTHESIZE(AnimationType, m_eLoopType, LoopType); + CC_SYNTHESIZE(AnimationType, _loopType, LoopType); //! The tween easing effect - CC_SYNTHESIZE(CCTweenType, m_eTweenEasing, TweenEasing); + CC_SYNTHESIZE(CCTweenType, _tweenEasing, TweenEasing); //! The animation update speed - CC_SYNTHESIZE(float, m_fAnimationInternal, AnimationInternal); + CC_SYNTHESIZE(float, _animationInternal, AnimationInternal); protected: //! The durantion frame count will run - int m_iDurationTween; + int _durationTween; //! Current frame this process arrived, this frame is tween frame - float m_fCurrentFrame; + float _currentFrame; //! Frame index it the time line - int m_iCurFrameIndex; + int _curFrameIndex; //! Next frame this process need run to int m_iNextFrameIndex; - bool m_bIsLoopBack; + bool _isLoopBack; }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/animation/CCTween.cpp b/extensions/CocoStudio/Armature/animation/CCTween.cpp index 9cd15d9264..1cdf1354ea 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.cpp +++ b/extensions/CocoStudio/Armature/animation/CCTween.cpp @@ -50,17 +50,17 @@ Tween *Tween::create(Bone *bone) Tween::Tween() - : m_pMovementBoneData(NULL) - , m_pTweenData(NULL) - , m_pFrom(NULL) - , m_pTo(NULL) - , m_pBetween(NULL) - , m_pBone(NULL) + : _movementBoneData(NULL) + , _tweenData(NULL) + , _from(NULL) + , _to(NULL) + , _between(NULL) + , _bone(NULL) - , m_eFrameTweenEasing(Linear) - , m_iFromIndex(0) - , m_iToIndex(0) - , m_pAnimation(NULL) + , _frameTweenEasing(Linear) + , _fromIndex(0) + , _toIndex(0) + , _animation(NULL) { } @@ -68,8 +68,8 @@ Tween::Tween() Tween::~Tween(void) { - CC_SAFE_DELETE( m_pFrom ); - CC_SAFE_DELETE( m_pBetween ); + CC_SAFE_DELETE( _from ); + CC_SAFE_DELETE( _between ); } @@ -78,14 +78,14 @@ bool Tween::init(Bone *bone) bool bRet = false; do { - m_pFrom = new FrameData(); - m_pBetween = new FrameData(); + _from = new FrameData(); + _between = new FrameData(); - m_pBone = bone; - m_pTweenData = m_pBone->getTweenData(); - m_pTweenData->displayIndex = -1; + _bone = bone; + _tweenData = _bone->getTweenData(); + _tweenData->displayIndex = -1; - m_pAnimation = m_pBone->getArmature() != NULL ? m_pBone->getArmature()->getAnimation() : NULL; + _animation = _bone->getArmature() != NULL ? _bone->getArmature()->getAnimation() : NULL; bRet = true; } @@ -99,56 +99,56 @@ void Tween::play(MovementBoneData *movementBoneData, int durationTo, int duratio { ProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing); - m_eLoopType = (AnimationType)loop; + _loopType = (AnimationType)loop; - m_iTotalDuration = 0; - m_iBetweenDuration = 0; - m_iFromIndex = m_iToIndex = 0; + _totalDuration = 0; + _betweenDuration = 0; + _fromIndex = _toIndex = 0; - bool difMovement = movementBoneData != m_pMovementBoneData; + bool difMovement = movementBoneData != _movementBoneData; setMovementBoneData(movementBoneData); - m_iRawDuration = m_pMovementBoneData->duration; + _rawDuration = _movementBoneData->duration; - FrameData *nextKeyFrame = m_pMovementBoneData->getFrameData(0); - m_pTweenData->displayIndex = nextKeyFrame->displayIndex; + FrameData *nextKeyFrame = _movementBoneData->getFrameData(0); + _tweenData->displayIndex = nextKeyFrame->displayIndex; - if (m_pBone->getArmature()->getArmatureData()->dataVersion >= VERSION_COMBINED) + if (_bone->getArmature()->getArmatureData()->dataVersion >= VERSION_COMBINED) { - TransformHelp::nodeSub(*m_pTweenData, *m_pBone->getBoneData()); - m_pTweenData->scaleX += 1; - m_pTweenData->scaleY += 1; + TransformHelp::nodeSub(*_tweenData, *_bone->getBoneData()); + _tweenData->scaleX += 1; + _tweenData->scaleY += 1; } - if (m_iRawDuration == 0 ) + if (_rawDuration == 0 ) { - m_eLoopType = SINGLE_FRAME; + _loopType = SINGLE_FRAME; if(durationTo == 0) { setBetween(nextKeyFrame, nextKeyFrame); } else { - setBetween(m_pTweenData, nextKeyFrame); + setBetween(_tweenData, nextKeyFrame); } - m_eFrameTweenEasing = Linear; + _frameTweenEasing = Linear; } - else if (m_pMovementBoneData->frameList.count() > 1) + else if (_movementBoneData->frameList.count() > 1) { if (loop) { - m_eLoopType = ANIMATION_TO_LOOP_BACK; + _loopType = ANIMATION_TO_LOOP_BACK; } else { - m_eLoopType = ANIMATION_NO_LOOP; + _loopType = ANIMATION_NO_LOOP; } - m_iDurationTween = durationTween * m_pMovementBoneData->scale; + _durationTween = durationTween * _movementBoneData->scale; - if (loop && m_pMovementBoneData->delay != 0) + if (loop && _movementBoneData->delay != 0) { - setBetween(m_pTweenData, tweenNodeTo(updateFrameData(1 - m_pMovementBoneData->delay), m_pBetween)); + setBetween(_tweenData, tweenNodeTo(updateFrameData(1 - _movementBoneData->delay), _between)); } else { @@ -158,7 +158,7 @@ void Tween::play(MovementBoneData *movementBoneData, int durationTo, int duratio } else { - setBetween(m_pTweenData, nextKeyFrame); + setBetween(_tweenData, nextKeyFrame); } } } @@ -168,104 +168,104 @@ void Tween::play(MovementBoneData *movementBoneData, int durationTo, int duratio void Tween::updateHandler() { - if (m_fCurrentPercent >= 1) + if (_currentPercent >= 1) { - switch(m_eLoopType) + switch(_loopType) { case SINGLE_FRAME: { - m_fCurrentPercent = 1; - m_bIsComplete = true; - m_bIsPlaying = false; + _currentPercent = 1; + _isComplete = true; + _isPlaying = false; } break; case ANIMATION_NO_LOOP: { - m_eLoopType = ANIMATION_MAX; + _loopType = ANIMATION_MAX; - if (m_iDurationTween <= 0) + if (_durationTween <= 0) { - m_fCurrentPercent = 1; + _currentPercent = 1; } else { - m_fCurrentPercent = (m_fCurrentPercent - 1) * m_iNextFrameIndex / m_iDurationTween; + _currentPercent = (_currentPercent - 1) * m_iNextFrameIndex / _durationTween; } - if (m_fCurrentPercent >= 1) + if (_currentPercent >= 1) { - m_fCurrentPercent = 1; - m_bIsComplete = true; - m_bIsPlaying = false; + _currentPercent = 1; + _isComplete = true; + _isPlaying = false; break; } else { - m_iNextFrameIndex = m_iDurationTween; - m_fCurrentFrame = m_fCurrentPercent * m_iNextFrameIndex; - m_iTotalDuration = 0; - m_iBetweenDuration = 0; - m_iFromIndex = m_iToIndex = 0; + m_iNextFrameIndex = _durationTween; + _currentFrame = _currentPercent * m_iNextFrameIndex; + _totalDuration = 0; + _betweenDuration = 0; + _fromIndex = _toIndex = 0; break; } } break; case ANIMATION_TO_LOOP_BACK: { - m_eLoopType = ANIMATION_LOOP_BACK; + _loopType = ANIMATION_LOOP_BACK; - m_iNextFrameIndex = m_iDurationTween > 0 ? m_iDurationTween : 1; + m_iNextFrameIndex = _durationTween > 0 ? _durationTween : 1; - if (m_pMovementBoneData->delay != 0) + if (_movementBoneData->delay != 0) { // - m_fCurrentFrame = (1 - m_pMovementBoneData->delay) * (float)m_iNextFrameIndex; - m_fCurrentPercent = m_fCurrentFrame / m_iNextFrameIndex; + _currentFrame = (1 - _movementBoneData->delay) * (float)m_iNextFrameIndex; + _currentPercent = _currentFrame / m_iNextFrameIndex; } else { - m_fCurrentPercent = 0; - m_fCurrentFrame = 0; + _currentPercent = 0; + _currentFrame = 0; } - m_iTotalDuration = 0; - m_iBetweenDuration = 0; - m_iFromIndex = m_iToIndex = 0; + _totalDuration = 0; + _betweenDuration = 0; + _fromIndex = _toIndex = 0; } break; case ANIMATION_MAX: { - m_fCurrentPercent = 1; - m_bIsComplete = true; - m_bIsPlaying = false; + _currentPercent = 1; + _isComplete = true; + _isPlaying = false; } break; default: { - m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); + _currentFrame = fmodf(_currentFrame, m_iNextFrameIndex); - m_iTotalDuration = 0; - m_iBetweenDuration = 0; - m_iFromIndex = m_iToIndex = 0; + _totalDuration = 0; + _betweenDuration = 0; + _fromIndex = _toIndex = 0; } break; } } - if (m_fCurrentPercent < 1 && m_eLoopType <= ANIMATION_TO_LOOP_BACK) + if (_currentPercent < 1 && _loopType <= ANIMATION_TO_LOOP_BACK) { - m_fCurrentPercent = sin(m_fCurrentPercent * CC_HALF_PI); + _currentPercent = sin(_currentPercent * CC_HALF_PI); } - float percent = m_fCurrentPercent; + float percent = _currentPercent; - if (m_eLoopType > ANIMATION_TO_LOOP_BACK) + if (_loopType > ANIMATION_TO_LOOP_BACK) { percent = updateFrameData(percent); } - if(m_eFrameTweenEasing != TWEEN_EASING_MAX) + if(_frameTweenEasing != TWEEN_EASING_MAX) { tweenNodeTo(percent); } @@ -277,19 +277,19 @@ void Tween::setBetween(FrameData *from, FrameData *to) { if(from->displayIndex < 0 && to->displayIndex >= 0) { - m_pFrom->copy(to); - m_pBetween->subtract(to, to); + _from->copy(to); + _between->subtract(to, to); break; } else if(to->displayIndex < 0 && from->displayIndex >= 0) { - m_pFrom->copy(from); - m_pBetween->subtract(to, to); + _from->copy(from); + _between->subtract(to, to); break; } - m_pFrom->copy(from); - m_pBetween->subtract(from, to); + _from->copy(from); + _between->subtract(from, to); } while (0); @@ -301,7 +301,7 @@ void Tween::arriveKeyFrame(FrameData *keyFrameData) { if(keyFrameData) { - DisplayManager *displayManager = m_pBone->getDisplayManager(); + DisplayManager *displayManager = _bone->getDisplayManager(); //! Change bone's display int displayIndex = keyFrameData->displayIndex; @@ -312,14 +312,14 @@ void Tween::arriveKeyFrame(FrameData *keyFrameData) } //! Update bone zorder, bone's zorder is determined by frame zorder and bone zorder - m_pTweenData->zOrder = keyFrameData->zOrder; - m_pBone->updateZOrder(); + _tweenData->zOrder = keyFrameData->zOrder; + _bone->updateZOrder(); //! Update blend type - m_pBone->setBlendType(keyFrameData->blendType); + _bone->setBlendType(keyFrameData->blendType); //! Update child armature's movement - Armature *childAramture = m_pBone->getChildArmature(); + Armature *childAramture = _bone->getChildArmature(); if(childAramture) { if(keyFrameData->strMovement.length() != 0) @@ -332,18 +332,18 @@ void Tween::arriveKeyFrame(FrameData *keyFrameData) FrameData *Tween::tweenNodeTo(float percent, FrameData *node) { - node = node == NULL ? m_pTweenData : node; + node = node == NULL ? _tweenData : node; - node->x = m_pFrom->x + percent * m_pBetween->x; - node->y = m_pFrom->y + percent * m_pBetween->y; - node->scaleX = m_pFrom->scaleX + percent * m_pBetween->scaleX; - node->scaleY = m_pFrom->scaleY + percent * m_pBetween->scaleY; - node->skewX = m_pFrom->skewX + percent * m_pBetween->skewX; - node->skewY = m_pFrom->skewY + percent * m_pBetween->skewY; + node->x = _from->x + percent * _between->x; + node->y = _from->y + percent * _between->y; + node->scaleX = _from->scaleX + percent * _between->scaleX; + node->scaleY = _from->scaleY + percent * _between->scaleY; + node->skewX = _from->skewX + percent * _between->skewX; + node->skewY = _from->skewY + percent * _between->skewY; - m_pBone->setTransformDirty(true); + _bone->setTransformDirty(true); - if (node && m_pBetween->isUseColorInfo) + if (node && _between->isUseColorInfo) { tweenColorTo(percent, node); } @@ -353,32 +353,32 @@ FrameData *Tween::tweenNodeTo(float percent, FrameData *node) void Tween::tweenColorTo(float percent, FrameData *node) { - node->a = m_pFrom->a + percent * m_pBetween->a; - node->r = m_pFrom->r + percent * m_pBetween->r; - node->g = m_pFrom->g + percent * m_pBetween->g; - node->b = m_pFrom->b + percent * m_pBetween->b; - m_pBone->updateColor(); + node->a = _from->a + percent * _between->a; + node->r = _from->r + percent * _between->r; + node->g = _from->g + percent * _between->g; + node->b = _from->b + percent * _between->b; + _bone->updateColor(); } float Tween::updateFrameData(float currentPercent) { - if (currentPercent > 1 && m_pMovementBoneData->delay != 0) + if (currentPercent > 1 && _movementBoneData->delay != 0) { currentPercent = fmodf(currentPercent, 1); } - float playedTime = (float)m_iRawDuration * currentPercent; + float playedTime = (float)_rawDuration * currentPercent; //! If play to current frame's front or back, then find current frame again - if (playedTime < m_iTotalDuration || playedTime >= m_iTotalDuration + m_iBetweenDuration) + if (playedTime < _totalDuration || playedTime >= _totalDuration + _betweenDuration) { /* - * Get frame length, if m_iToIndex >= _length, then set m_iToIndex to 0, start anew. - * m_iToIndex is next index will play + * Get frame length, if _toIndex >= _length, then set _toIndex to 0, start anew. + * _toIndex is next index will play */ - int length = m_pMovementBoneData->frameList.count(); - FrameData **frames = (FrameData **)m_pMovementBoneData->frameList.data->arr; + int length = _movementBoneData->frameList.count(); + FrameData **frames = (FrameData **)_movementBoneData->frameList.data->arr; FrameData *from = NULL; FrameData *to = NULL; @@ -399,21 +399,21 @@ float Tween::updateFrameData(float currentPercent) do { - from = frames[m_iFromIndex]; - m_iTotalDuration = from->frameID; + from = frames[_fromIndex]; + _totalDuration = from->frameID; - if (++m_iToIndex >= length) + if (++_toIndex >= length) { - m_iToIndex = 0; + _toIndex = 0; } - m_iFromIndex = m_iToIndex; - to = frames[m_iToIndex]; + _fromIndex = _toIndex; + to = frames[_toIndex]; //! Guaranteed to trigger frame event if(from->strEvent.length() != 0) { - m_pAnimation->frameEvent(m_pBone, from->strEvent.c_str(), from->frameID, playedTime); + _animation->frameEvent(_bone, from->strEvent.c_str(), from->frameID, playedTime); } if (playedTime == from->frameID) @@ -423,14 +423,14 @@ float Tween::updateFrameData(float currentPercent) } while (playedTime < from->frameID || playedTime >= to->frameID); - m_iBetweenDuration = to->frameID - from->frameID; + _betweenDuration = to->frameID - from->frameID; - m_eFrameTweenEasing = from->tweenEasing; + _frameTweenEasing = from->tweenEasing; setBetween(from, to); } - currentPercent = m_iBetweenDuration == 0 ? 0 : (playedTime - m_iTotalDuration) / (float)m_iBetweenDuration; + currentPercent = _betweenDuration == 0 ? 0 : (playedTime - _totalDuration) / (float)_betweenDuration; /* @@ -439,9 +439,9 @@ float Tween::updateFrameData(float currentPercent) CCTweenType tweenType; - if ( m_eFrameTweenEasing != TWEEN_EASING_MAX) + if ( _frameTweenEasing != TWEEN_EASING_MAX) { - tweenType = (m_eTweenEasing == TWEEN_EASING_MAX) ? m_eFrameTweenEasing : m_eTweenEasing; + tweenType = (_tweenEasing == TWEEN_EASING_MAX) ? _frameTweenEasing : _tweenEasing; if (tweenType != TWEEN_EASING_MAX && tweenType != Linear) { currentPercent = TweenFunction::tweenTo(0, 1, currentPercent, 1, tweenType); diff --git a/extensions/CocoStudio/Armature/animation/CCTween.h b/extensions/CocoStudio/Armature/animation/CCTween.h index acfb1e6ef1..0b823cdcad 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.h +++ b/extensions/CocoStudio/Armature/animation/CCTween.h @@ -78,11 +78,11 @@ public: inline void setAnimation(ArmatureAnimation *animation) { - m_pAnimation = animation; + _animation = animation; } inline ArmatureAnimation *getAnimation() const { - return m_pAnimation; + return _animation; } protected: @@ -117,26 +117,26 @@ protected: virtual void arriveKeyFrame(FrameData *keyFrameData); protected: //! A weak reference to the current MovementBoneData. The data is in the data pool - CC_SYNTHESIZE(MovementBoneData *, m_pMovementBoneData, MovementBoneData) + CC_SYNTHESIZE(MovementBoneData *, _movementBoneData, MovementBoneData) - FrameData *m_pTweenData; //! The computational tween frame data, //! A weak reference to the Bone's tweenData - FrameData *m_pFrom; //! From frame data, used for calculate between value - FrameData *m_pTo; //! To frame data, used for calculate between value - FrameData *m_pBetween; //! 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 *m_pBone; //! A weak reference to the Bone + Bone *_bone; //! A weak reference to the Bone - CCTweenType m_eFrameTweenEasing; //! Dedermine which tween effect current frame use + CCTweenType _frameTweenEasing; //! Dedermine which tween effect current frame use - int m_iBetweenDuration; //! Current key frame will last m_iBetweenDuration frames - int m_iTotalDuration; + int _betweenDuration; //! Current key frame will last _betweenDuration frames + int _totalDuration; - int m_iFromIndex; //! The current frame index in FrameList of MovementBoneData, it's different from m_iFrameIndex - int m_iToIndex; //! 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 *m_pAnimation; + ArmatureAnimation *_animation; }; diff --git a/extensions/CocoStudio/Armature/datas/CCDatas.h b/extensions/CocoStudio/Armature/datas/CCDatas.h index 8325a24536..75352f662d 100644 --- a/extensions/CocoStudio/Armature/datas/CCDatas.h +++ b/extensions/CocoStudio/Armature/datas/CCDatas.h @@ -150,7 +150,7 @@ public: public: /** * If DisplayType is CS_DISPLAY_SPRITE, then Bone will use this image name to create a Sprite from CCSpriteFrameCache. - * It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use m_strDisplayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". + * It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use _displayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". * * If DisplayType is CS_DISPLAY_ARMATURE, the name is the Armature's name. When Bone init display and type is CS_DISPLAY_ARMATURE, * then Bone will create a Armature. @@ -177,7 +177,7 @@ public: public: /** * If DisplayType is CS_DISPLAY_SPRITE, then Bone will use this image name to create a Sprite from CCSpriteFrameCache. - * It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use m_strDisplayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". + * It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use _displayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". * * If DisplayType is CS_DISPLAY_ARMATURE, the name is the Armature's name. When Bone init display and type is CS_DISPLAY_ARMATURE, * then Bone will create a Armature. diff --git a/extensions/CocoStudio/Armature/display/CCBatchNode.cpp b/extensions/CocoStudio/Armature/display/CCBatchNode.cpp index c6d3cdcdd2..c52823e407 100644 --- a/extensions/CocoStudio/Armature/display/CCBatchNode.cpp +++ b/extensions/CocoStudio/Armature/display/CCBatchNode.cpp @@ -41,7 +41,7 @@ BatchNode *BatchNode::create() } BatchNode::BatchNode() - : m_pAtlas(NULL) + : _atlas(NULL) { } @@ -101,7 +101,7 @@ void BatchNode::draw() if (armature) { armature->visit(); - m_pAtlas = armature->getTextureAtlas(); + _atlas = armature->getTextureAtlas(); } else { @@ -109,10 +109,10 @@ void BatchNode::draw() } } - if (m_pAtlas) + if (_atlas) { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); + _atlas->drawQuads(); + _atlas->removeAllQuads(); } } diff --git a/extensions/CocoStudio/Armature/display/CCBatchNode.h b/extensions/CocoStudio/Armature/display/CCBatchNode.h index 97450519a8..9d3c89e498 100644 --- a/extensions/CocoStudio/Armature/display/CCBatchNode.h +++ b/extensions/CocoStudio/Armature/display/CCBatchNode.h @@ -42,7 +42,7 @@ public: void draw(); protected: - TextureAtlas *m_pAtlas; + TextureAtlas *_atlas; }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp index 0351fd03b3..d92fef659b 100644 --- a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp +++ b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.cpp @@ -39,23 +39,23 @@ DecorativeDisplay *DecorativeDisplay::create() } DecorativeDisplay::DecorativeDisplay() - : m_pDisplay(NULL) - , m_pDisplayData(NULL) + : _display(NULL) + , _displayData(NULL) { #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - m_pColliderDetector = NULL; + _colliderDetector = NULL; #endif } DecorativeDisplay::~DecorativeDisplay(void) { - CC_SAFE_RELEASE_NULL(m_pDisplayData); - CC_SAFE_RELEASE_NULL(m_pDisplay); + CC_SAFE_RELEASE_NULL(_displayData); + CC_SAFE_RELEASE_NULL(_display); #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_SAFE_RELEASE_NULL(m_pColliderDetector); + CC_SAFE_RELEASE_NULL(_colliderDetector); #endif } diff --git a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h index 12902535b9..f8a0309592 100644 --- a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h +++ b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h @@ -48,11 +48,11 @@ public: protected: - CC_SYNTHESIZE_RETAIN(Node *, m_pDisplay, Display); - CC_SYNTHESIZE_RETAIN(DisplayData *, m_pDisplayData, DisplayData); + CC_SYNTHESIZE_RETAIN(Node *, _display, Display); + CC_SYNTHESIZE_RETAIN(DisplayData *, _displayData, DisplayData); #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_SYNTHESIZE_RETAIN(ColliderDetector *, m_pColliderDetector, ColliderDetector); + CC_SYNTHESIZE_RETAIN(ColliderDetector *, _colliderDetector, ColliderDetector); #endif }; diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp index bdf9874625..8b3bd2b837 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp +++ b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp @@ -44,25 +44,25 @@ DisplayManager *DisplayManager::create(Bone *bone) DisplayManager::DisplayManager() - : m_pDecoDisplayList(NULL) - , m_pDisplayRenderNode(NULL) - , m_pCurrentDecoDisplay(NULL) - , m_iDisplayIndex(-1) - , m_bForceChangeDisplay(false) - , m_bVisible(true) - , m_pBone(NULL) + : _decoDisplayList(NULL) + , _displayRenderNode(NULL) + , _currentDecoDisplay(NULL) + , _displayIndex(-1) + , _forceChangeDisplay(false) + , _visible(true) + , _bone(NULL) { } DisplayManager::~DisplayManager() { - CC_SAFE_DELETE(m_pDecoDisplayList); + CC_SAFE_DELETE(_decoDisplayList); - if( m_pDisplayRenderNode ) + if( _displayRenderNode ) { - m_pDisplayRenderNode->removeFromParentAndCleanup(true); - if(m_pDisplayRenderNode->retainCount() > 0) - CC_SAFE_RELEASE_NULL(m_pDisplayRenderNode); + _displayRenderNode->removeFromParentAndCleanup(true); + if(_displayRenderNode->retainCount() > 0) + CC_SAFE_RELEASE_NULL(_displayRenderNode); } } @@ -74,7 +74,7 @@ bool DisplayManager::init(Bone *bone) do { - m_pBone = bone; + _bone = bone; initDisplayList(bone->getBoneData()); @@ -90,22 +90,22 @@ void DisplayManager::addDisplay(DisplayData *displayData, int index) { DecorativeDisplay *decoDisplay = NULL; - if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) + if(index >= 0 && (unsigned int)index < _decoDisplayList->count()) { - decoDisplay = (DecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); + decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index); } else { decoDisplay = DecorativeDisplay::create(); - m_pDecoDisplayList->addObject(decoDisplay); + _decoDisplayList->addObject(decoDisplay); } - DisplayFactory::addDisplay(m_pBone, decoDisplay, displayData); + DisplayFactory::addDisplay(_bone, decoDisplay, displayData); //! if changed display index is current display index, then change current display to the new display - if(index == m_iDisplayIndex) + if(index == _displayIndex) { - m_iDisplayIndex = -1; + _displayIndex = -1; changeDisplayByIndex(index, false); } } @@ -114,23 +114,23 @@ void DisplayManager::addDisplay(Node *display, int index) { DecorativeDisplay *decoDisplay = NULL; - if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) + if(index >= 0 && (unsigned int)index < _decoDisplayList->count()) { - decoDisplay = (DecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); + decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index); } else { decoDisplay = DecorativeDisplay::create(); - m_pDecoDisplayList->addObject(decoDisplay); + _decoDisplayList->addObject(decoDisplay); } DisplayData *displayData = NULL; if (Skin *skin = dynamic_cast(display)) { - skin->setBone(m_pBone); + skin->setBone(_bone); displayData = SpriteDisplayData::create(); - DisplayFactory::initSpriteDisplay(m_pBone, decoDisplay, skin->getDisplayName().c_str(), skin); + DisplayFactory::initSpriteDisplay(_bone, decoDisplay, skin->getDisplayName().c_str(), skin); if (SpriteDisplayData *spriteDisplayData = (SpriteDisplayData *)decoDisplay->getDisplayData()) { @@ -149,7 +149,7 @@ void DisplayManager::addDisplay(Node *display, int index) else if(Armature *armature = dynamic_cast(display)) { displayData = ArmatureDisplayData::create(); - armature->setParentBone(m_pBone); + armature->setParentBone(_bone); } else { @@ -160,18 +160,18 @@ void DisplayManager::addDisplay(Node *display, int index) decoDisplay->setDisplayData(displayData); //! if changed display index is current display index, then change current display to the new display - if(index == m_iDisplayIndex) + if(index == _displayIndex) { - m_iDisplayIndex = -1; + _displayIndex = -1; changeDisplayByIndex(index, false); } } void DisplayManager::removeDisplay(int index) { - m_pDecoDisplayList->removeObjectAtIndex(index); + _decoDisplayList->removeObjectAtIndex(index); - if(index == m_iDisplayIndex) + if(index == _displayIndex) { setCurrentDecorativeDisplay(NULL); } @@ -179,35 +179,35 @@ void DisplayManager::removeDisplay(int index) Array *DisplayManager::getDecorativeDisplayList() { - return m_pDecoDisplayList; + return _decoDisplayList; } void DisplayManager::changeDisplayByIndex(int index, bool force) { - CCAssert( (m_pDecoDisplayList ? index < (int)m_pDecoDisplayList->count() : true), "the _index value is out of range"); + CCAssert( (_decoDisplayList ? index < (int)_decoDisplayList->count() : true), "the _index value is out of range"); - m_bForceChangeDisplay = force; + _forceChangeDisplay = force; //! If index is equal to current display index,then do nothing - if ( m_iDisplayIndex == index) + if ( _displayIndex == index) return; - m_iDisplayIndex = index; + _displayIndex = index; //! If displayIndex < 0, it means you want to hide you display - if (m_iDisplayIndex < 0) + if (_displayIndex < 0) { - if(m_pDisplayRenderNode) + if(_displayRenderNode) { - m_pDisplayRenderNode->removeFromParentAndCleanup(true); + _displayRenderNode->removeFromParentAndCleanup(true); setCurrentDecorativeDisplay(NULL); } return; } - DecorativeDisplay *decoDisplay = (DecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(m_iDisplayIndex); + DecorativeDisplay *decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(_displayIndex); setCurrentDecorativeDisplay(decoDisplay); } @@ -215,81 +215,81 @@ void DisplayManager::changeDisplayByIndex(int index, bool force) void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay) { #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - if (m_pCurrentDecoDisplay && m_pCurrentDecoDisplay->getColliderDetector()) + if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector()) { - m_pCurrentDecoDisplay->getColliderDetector()->setActive(false); + _currentDecoDisplay->getColliderDetector()->setActive(false); } #endif - m_pCurrentDecoDisplay = decoDisplay; + _currentDecoDisplay = decoDisplay; #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - if (m_pCurrentDecoDisplay && m_pCurrentDecoDisplay->getColliderDetector()) + if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector()) { - m_pCurrentDecoDisplay->getColliderDetector()->setActive(true); + _currentDecoDisplay->getColliderDetector()->setActive(true); } #endif - Node *displayRenderNode = m_pCurrentDecoDisplay == NULL ? NULL : m_pCurrentDecoDisplay->getDisplay(); - if (m_pDisplayRenderNode) + Node *displayRenderNode = _currentDecoDisplay == NULL ? NULL : _currentDecoDisplay->getDisplay(); + if (_displayRenderNode) { - if (dynamic_cast(m_pDisplayRenderNode) != NULL) + if (dynamic_cast(_displayRenderNode) != NULL) { - m_pBone->setChildArmature(NULL); + _bone->setChildArmature(NULL); } - m_pDisplayRenderNode->removeFromParentAndCleanup(true); - m_pDisplayRenderNode->release(); + _displayRenderNode->removeFromParentAndCleanup(true); + _displayRenderNode->release(); } - m_pDisplayRenderNode = displayRenderNode; + _displayRenderNode = displayRenderNode; - if(m_pDisplayRenderNode) + if(_displayRenderNode) { - if (Armature *armature = dynamic_cast(m_pDisplayRenderNode)) + if (Armature *armature = dynamic_cast(_displayRenderNode)) { - m_pBone->setChildArmature(armature); + _bone->setChildArmature(armature); } - else if (ParticleSystemQuad *particle = dynamic_cast(m_pDisplayRenderNode)) + else if (ParticleSystemQuad *particle = dynamic_cast(_displayRenderNode)) { particle->resetSystem(); } - if (RGBAProtocol *rgbaProtocaol = dynamic_cast(m_pDisplayRenderNode)) + if (RGBAProtocol *rgbaProtocaol = dynamic_cast(_displayRenderNode)) { - rgbaProtocaol->setColor(m_pBone->getDisplayedColor()); - rgbaProtocaol->setOpacity(m_pBone->getDisplayedOpacity()); + rgbaProtocaol->setColor(_bone->getDisplayedColor()); + rgbaProtocaol->setOpacity(_bone->getDisplayedOpacity()); } - m_pDisplayRenderNode->retain(); - m_pDisplayRenderNode->setVisible(m_bVisible); + _displayRenderNode->retain(); + _displayRenderNode->setVisible(_visible); } } Node *DisplayManager::getDisplayRenderNode() { - return m_pDisplayRenderNode; + return _displayRenderNode; } int DisplayManager::getCurrentDisplayIndex() { - return m_iDisplayIndex; + return _displayIndex; } DecorativeDisplay *DisplayManager::getCurrentDecorativeDisplay() { - return m_pCurrentDecoDisplay; + return _currentDecoDisplay; } DecorativeDisplay *DisplayManager::getDecorativeDisplayByIndex( int index) { - return (DecorativeDisplay *)m_pDecoDisplayList->getObjectAtIndex(index); + return (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index); } void DisplayManager::initDisplayList(BoneData *boneData) { - CC_SAFE_DELETE(m_pDecoDisplayList); - m_pDecoDisplayList = Array::create(); - m_pDecoDisplayList->retain(); + CC_SAFE_DELETE(_decoDisplayList); + _decoDisplayList = Array::create(); + _decoDisplayList->retain(); CS_RETURN_IF(!boneData); @@ -302,23 +302,23 @@ void DisplayManager::initDisplayList(BoneData *boneData) DecorativeDisplay *decoDisplay = DecorativeDisplay::create(); decoDisplay->setDisplayData(displayData); - DisplayFactory::createDisplay(m_pBone, decoDisplay); + DisplayFactory::createDisplay(_bone, decoDisplay); - m_pDecoDisplayList->addObject(decoDisplay); + _decoDisplayList->addObject(decoDisplay); } } bool DisplayManager::containPoint(Point &point) { - if(!m_bVisible || m_iDisplayIndex < 0) + if(!_visible || _displayIndex < 0) { return false; } bool ret = false; - switch (m_pCurrentDecoDisplay->getDisplayData()->displayType) + switch (_currentDecoDisplay->getDisplayData()->displayType) { case CS_DISPLAY_SPRITE: { @@ -330,7 +330,7 @@ bool DisplayManager::containPoint(Point &point) Point outPoint = Point(0, 0); - Sprite *sprite = (Sprite *)m_pCurrentDecoDisplay->getDisplay(); + Sprite *sprite = (Sprite *)_currentDecoDisplay->getDisplay(); sprite = (Sprite *)sprite->getChildByTag(0); ret = CC_SPRITE_CONTAIN_POINT_WITH_RETURN(sprite, point, outPoint); @@ -353,42 +353,42 @@ bool DisplayManager::containPoint(float x, float y) void DisplayManager::setVisible(bool visible) { - if(!m_pDisplayRenderNode) + if(!_displayRenderNode) return; - m_bVisible = visible; - m_pDisplayRenderNode->setVisible(visible); + _visible = visible; + _displayRenderNode->setVisible(visible); } bool DisplayManager::isVisible() { - return m_bVisible; + return _visible; } Size DisplayManager::getContentSize() { - CS_RETURN_IF(!m_pDisplayRenderNode) Size(0, 0); - return m_pDisplayRenderNode->getContentSize(); + CS_RETURN_IF(!_displayRenderNode) Size(0, 0); + return _displayRenderNode->getContentSize(); } Rect DisplayManager::getBoundingBox() { - CS_RETURN_IF(!m_pDisplayRenderNode) Rect(0, 0, 0, 0); - return m_pDisplayRenderNode->getBoundingBox(); + CS_RETURN_IF(!_displayRenderNode) Rect(0, 0, 0, 0); + return _displayRenderNode->getBoundingBox(); } Point DisplayManager::getAnchorPoint() { - CS_RETURN_IF(!m_pDisplayRenderNode) Point(0, 0); - return m_pDisplayRenderNode->getAnchorPoint(); + CS_RETURN_IF(!_displayRenderNode) Point(0, 0); + return _displayRenderNode->getAnchorPoint(); } Point DisplayManager::getAnchorPointInPoints() { - CS_RETURN_IF(!m_pDisplayRenderNode) Point(0, 0); - return m_pDisplayRenderNode->getAnchorPointInPoints(); + CS_RETURN_IF(!_displayRenderNode) Point(0, 0); + return _displayRenderNode->getAnchorPointInPoints(); } diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.h b/extensions/CocoStudio/Armature/display/CCDisplayManager.h index cacdfd6002..0e2ddcb968 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.h +++ b/extensions/CocoStudio/Armature/display/CCDisplayManager.h @@ -123,20 +123,20 @@ public: virtual bool containPoint(float x, float y); protected: - Array *m_pDecoDisplayList; + Array *_decoDisplayList; //! Display render node. - Node *m_pDisplayRenderNode; + Node *_displayRenderNode; //! Include current display information, like contour sprite, etc. - DecorativeDisplay *m_pCurrentDecoDisplay; + DecorativeDisplay *_currentDecoDisplay; //! Current display index - int m_iDisplayIndex; + int _displayIndex; - CC_SYNTHESIZE(bool, m_bForceChangeDisplay, ForceChangeDisplay) + CC_SYNTHESIZE(bool, _forceChangeDisplay, ForceChangeDisplay) //! Whether of not the bone is visible. Default is true - bool m_bVisible; + bool _visible; - Bone *m_pBone; + Bone *_bone; }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCSkin.cpp b/extensions/CocoStudio/Armature/display/CCSkin.cpp index c3445a6e57..3989ca5928 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.cpp +++ b/extensions/CocoStudio/Armature/display/CCSkin.cpp @@ -72,10 +72,10 @@ Skin *Skin::create(const char *pszFileName) } Skin::Skin() - : m_pBone(NULL) - , m_strDisplayName("") + : _bone(NULL) + , _displayName("") { - m_tSkinTransform = AffineTransformIdentity; + _skinTransform = AffineTransformIdentity; } bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) @@ -87,7 +87,7 @@ bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) TextureAtlas *atlas = SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); setTextureAtlas(atlas); - m_strDisplayName = pszSpriteFrameName; + _displayName = pszSpriteFrameName; } return ret; @@ -102,7 +102,7 @@ bool Skin::initWithFile(const char *pszFilename) TextureAtlas *atlas = SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); setTextureAtlas(atlas); - m_strDisplayName = pszFilename; + _displayName = pszFilename; } return ret; @@ -110,24 +110,24 @@ bool Skin::initWithFile(const char *pszFilename) void Skin::setSkinData(const BaseData &var) { - m_sSkinData = var; + _skinData = var; - setScaleX(m_sSkinData.scaleX); - setScaleY(m_sSkinData.scaleY); - setRotation(CC_RADIANS_TO_DEGREES(m_sSkinData.skewX)); - setPosition(Point(m_sSkinData.x, m_sSkinData.y)); + setScaleX(_skinData.scaleX); + setScaleY(_skinData.scaleY); + setRotation(CC_RADIANS_TO_DEGREES(_skinData.skewX)); + setPosition(Point(_skinData.x, _skinData.y)); - m_tSkinTransform = getNodeToParentTransform(); + _skinTransform = getNodeToParentTransform(); } const BaseData &Skin::getSkinData() const { - return m_sSkinData; + return _skinData; } void Skin::updateArmatureTransform() { - _transform = AffineTransformConcat(m_tSkinTransform, m_pBone->getNodeToArmatureTransform()); + _transform = AffineTransformConcat(_skinTransform, _bone->getNodeToArmatureTransform()); } void Skin::updateTransform() @@ -185,7 +185,7 @@ void Skin::updateTransform() AffineTransform Skin::getNodeToWorldTransform() const { - return AffineTransformConcat(_transform, m_pBone->getArmature()->getNodeToWorldTransform()); + return AffineTransformConcat(_transform, _bone->getArmature()->getNodeToWorldTransform()); } AffineTransform Skin::getNodeToWorldTransformAR() const @@ -198,7 +198,7 @@ AffineTransform Skin::getNodeToWorldTransformAR() const displayTransform.tx = anchorPoint.x; displayTransform.ty = anchorPoint.y; - return AffineTransformConcat(displayTransform, m_pBone->getArmature()->getNodeToWorldTransform()); + return AffineTransformConcat(displayTransform, _bone->getArmature()->getNodeToWorldTransform()); } NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/display/CCSkin.h b/extensions/CocoStudio/Armature/display/CCSkin.h index 10f9d7e38d..26453ece1a 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.h +++ b/extensions/CocoStudio/Armature/display/CCSkin.h @@ -48,12 +48,12 @@ public: AffineTransform getNodeToWorldTransform() const; AffineTransform getNodeToWorldTransformAR() const; - CC_PROPERTY_PASS_BY_REF(BaseData, m_sSkinData, SkinData); - CC_SYNTHESIZE(Bone *, m_pBone, Bone); + CC_PROPERTY_PASS_BY_REF(BaseData, _skinData, SkinData); + CC_SYNTHESIZE(Bone *, _bone, Bone); protected: - AffineTransform m_tSkinTransform; - CC_SYNTHESIZE_READONLY(std::string, m_strDisplayName, DisplayName) + AffineTransform _skinTransform; + CC_SYNTHESIZE_READONLY(std::string, _displayName, DisplayName) }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp index 5cfb193a04..cabdffc318 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp @@ -38,28 +38,28 @@ NS_CC_EXT_ARMATURE_BEGIN #if ENABLE_PHYSICS_BOX2D_DETECT ColliderBody::ColliderBody(ContourData *contourData) - : m_pFixture(NULL) - , m_pFilter(NULL) - , m_pContourData(contourData) + : _fixture(NULL) + , _filter(NULL) + , _contourData(contourData) { - CC_SAFE_RETAIN(m_pContourData); + CC_SAFE_RETAIN(_contourData); } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT ColliderBody::ColliderBody(ContourData *contourData) - : m_pShape(NULL) - , m_pContourData(contourData) + : _shape(NULL) + , _contourData(contourData) { - CC_SAFE_RETAIN(m_pContourData); + CC_SAFE_RETAIN(_contourData); } #endif ColliderBody::~ColliderBody() { - CC_SAFE_RELEASE(m_pContourData); + CC_SAFE_RELEASE(_contourData); #if ENABLE_PHYSICS_BOX2D_DETECT - CC_SAFE_DELETE(m_pFilter); + CC_SAFE_DELETE(_filter); #endif } @@ -90,27 +90,27 @@ ColliderDetector *ColliderDetector::create(Bone *bone) } ColliderDetector::ColliderDetector() - : m_pColliderBodyList(NULL) - , m_bActive(false) + : _colliderBodyList(NULL) + , _active(false) { #if ENABLE_PHYSICS_BOX2D_DETECT - m_pBody = NULL; + _body = NULL; #elif ENABLE_PHYSICS_CHIPMUNK_DETECT - m_pBody = NULL; + _body = NULL; #endif } ColliderDetector::~ColliderDetector() { - m_pColliderBodyList->removeAllObjects(); - CC_SAFE_DELETE(m_pColliderBodyList); + _colliderBodyList->removeAllObjects(); + CC_SAFE_DELETE(_colliderBodyList); } bool ColliderDetector::init() { - m_pColliderBodyList = Array::create(); - CCAssert(m_pColliderBodyList, "create m_pColliderBodyList failed!"); - m_pColliderBodyList->retain(); + _colliderBodyList = Array::create(); + CCAssert(_colliderBodyList, "create _colliderBodyList failed!"); + _colliderBodyList->retain(); return true; } @@ -126,7 +126,7 @@ bool ColliderDetector::init(Bone *bone) void ColliderDetector::addContourData(ContourData *contourData) { ColliderBody *colliderBody = new ColliderBody(contourData); - m_pColliderBodyList->addObject(colliderBody); + _colliderBodyList->addObject(colliderBody); colliderBody->release(); } @@ -142,42 +142,42 @@ void ColliderDetector::addContourDataList(Array *contourDataList) void ColliderDetector::removeContourData(ContourData *contourData) { Object *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) + CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *body = (ColliderBody*)object; if (body && body->getContourData() == contourData) { - m_pColliderBodyList->removeObject(body); + _colliderBodyList->removeObject(body); } } } void ColliderDetector::removeAll() { - m_pColliderBodyList->removeAllObjects(); + _colliderBodyList->removeAllObjects(); } void ColliderDetector::setActive(bool active) { - if (m_bActive == active) + if (_active == active) { return; } - m_bActive = active; + _active = active; #if ENABLE_PHYSICS_BOX2D_DETECT - if (m_pBody) + if (_body) { if (active) { - setBody(m_pBody); + setBody(_body); } else { Object *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) + CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; b2Fixture *fixture = colliderBody->getB2Fixture(); @@ -185,31 +185,31 @@ void ColliderDetector::setActive(bool active) b2Filter *filter = colliderBody->getB2Filter(); *filter = fixture->GetFilterData(); - m_pBody->DestroyFixture(fixture); + _body->DestroyFixture(fixture); colliderBody->setB2Fixture(NULL); } } } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT - if (m_pBody) + if (_body) { Object *object = NULL; - if (m_bActive) + if (_active) { - CCARRAY_FOREACH(m_pColliderBodyList, object) + CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; cpShape *shape = colliderBody->getShape(); - cpSpaceAddShape(m_pBody->space_private, shape); + cpSpaceAddShape(_body->space_private, shape); } } else { - CCARRAY_FOREACH(m_pColliderBodyList, object) + CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; cpShape *shape = colliderBody->getShape(); - cpSpaceRemoveShape(m_pBody->space_private, shape); + cpSpaceRemoveShape(_body->space_private, shape); } } } @@ -218,12 +218,12 @@ void ColliderDetector::setActive(bool active) bool ColliderDetector::getActive() { - return m_bActive; + return _active; } Array *ColliderDetector::getColliderBodyList() { - return m_pColliderBodyList; + return _colliderBodyList; } @@ -231,26 +231,26 @@ Point helpPoint; void ColliderDetector::updateTransform(AffineTransform &t) { - if (!m_bActive) + if (!_active) { return; } Object *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) + CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; ContourData *contourData = colliderBody->getContourData(); #if ENABLE_PHYSICS_BOX2D_DETECT b2PolygonShape *shape = NULL; - if (m_pBody != NULL) + if (_body != NULL) { shape = (b2PolygonShape *)colliderBody->getB2Fixture()->GetShape(); } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT cpPolyShape *shape = NULL; - if (m_pBody != NULL) + if (_body != NULL) { shape = (cpPolyShape *)colliderBody->getShape(); } @@ -300,10 +300,10 @@ void ColliderDetector::updateTransform(AffineTransform &t) void ColliderDetector::setBody(b2Body *pBody) { - m_pBody = pBody; + _body = pBody; Object *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) + CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; @@ -330,12 +330,12 @@ void ColliderDetector::setBody(b2Body *pBody) fixtureDef.shape = &polygon; fixtureDef.isSensor = true; - b2Fixture *fixture = m_pBody->CreateFixture(&fixtureDef); - fixture->SetUserData(m_pBone); + b2Fixture *fixture = _body->CreateFixture(&fixtureDef); + fixture->SetUserData(_bone); if (colliderBody->getB2Fixture() != NULL) { - m_pBody->DestroyFixture(colliderBody->getB2Fixture()); + _body->DestroyFixture(colliderBody->getB2Fixture()); } colliderBody->setB2Fixture(fixture); @@ -353,16 +353,16 @@ void ColliderDetector::setBody(b2Body *pBody) b2Body *ColliderDetector::getBody() { - return m_pBody; + return _body; } #elif ENABLE_PHYSICS_CHIPMUNK_DETECT void ColliderDetector::setBody(cpBody *pBody) { - m_pBody = pBody; + _body = pBody; Object *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) + CCARRAY_FOREACH(_colliderBodyList, object) { ColliderBody *colliderBody = (ColliderBody *)object; @@ -377,11 +377,11 @@ void ColliderDetector::setBody(cpBody *pBody) verts[num - 1 - i].y = vs[i]->y; } - cpShape *shape = cpPolyShapeNew(m_pBody, num, verts, cpvzero); + cpShape *shape = cpPolyShapeNew(_body, num, verts, cpvzero); shape->sensor = true; - shape->data = m_pBone; - cpSpaceAddShape(m_pBody->space_private, shape); + shape->data = _bone; + cpSpaceAddShape(_body->space_private, shape); colliderBody->setShape(shape); @@ -391,7 +391,7 @@ void ColliderDetector::setBody(cpBody *pBody) cpBody *ColliderDetector::getBody() { - return m_pBody; + return _body; } #endif diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.h b/extensions/CocoStudio/Armature/physics/CCColliderDetector.h index 250fbdc665..4a54ad4090 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.h +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.h @@ -48,11 +48,11 @@ class ColliderBody : public Object { public: #if ENABLE_PHYSICS_BOX2D_DETECT - CC_SYNTHESIZE(b2Fixture *, m_pFixture, B2Fixture) - CC_SYNTHESIZE(b2Filter *, m_pFilter, B2Filter) + CC_SYNTHESIZE(b2Fixture *, _fixture, B2Fixture) + CC_SYNTHESIZE(b2Filter *, _filter, B2Filter) #elif ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_SYNTHESIZE(cpShape *, m_pShape, Shape) + CC_SYNTHESIZE(cpShape *, _shape, Shape) #endif public: @@ -61,10 +61,10 @@ public: inline ContourData *getContourData() { - return m_pContourData; + return _contourData; } private: - ContourData *m_pContourData; + ContourData *_contourData; }; /* @@ -96,17 +96,17 @@ public: Array *getColliderBodyList(); protected: - Array *m_pColliderBodyList; - CC_SYNTHESIZE(Bone *, m_pBone, Bone); + Array *_colliderBodyList; + CC_SYNTHESIZE(Bone *, _bone, Bone); #if ENABLE_PHYSICS_BOX2D_DETECT - CC_PROPERTY(b2Body *, m_pBody, Body); + CC_PROPERTY(b2Body *, _body, Body); #elif ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_PROPERTY(cpBody *, m_pBody, Body); + CC_PROPERTY(cpBody *, _body, Body); #endif protected: - bool m_bActive; + bool _active; }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp index 02d909a9cf..acded20944 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp @@ -55,10 +55,10 @@ void ArmatureDataManager::purge() ArmatureDataManager::ArmatureDataManager(void) { - m_pArmarureDatas = NULL; - m_pAnimationDatas = NULL; - m_pTextureDatas = NULL; - m_bAutoLoadSpriteFile = false; + _armarureDatas = NULL; + _animationDatas = NULL; + _textureDatas = NULL; + _autoLoadSpriteFile = false; } @@ -66,9 +66,9 @@ ArmatureDataManager::~ArmatureDataManager(void) { removeAll(); - CC_SAFE_DELETE(m_pAnimationDatas); - CC_SAFE_DELETE(m_pArmarureDatas); - CC_SAFE_DELETE(m_pTextureDatas); + CC_SAFE_DELETE(_animationDatas); + CC_SAFE_DELETE(_armarureDatas); + CC_SAFE_DELETE(_textureDatas); } @@ -77,17 +77,17 @@ bool ArmatureDataManager::init() bool bRet = false; do { - m_pArmarureDatas = Dictionary::create(); - CCAssert(m_pArmarureDatas, "create ArmatureDataManager::m_pArmarureDatas fail!"); - m_pArmarureDatas->retain(); + _armarureDatas = Dictionary::create(); + CCAssert(_armarureDatas, "create ArmatureDataManager::_armarureDatas fail!"); + _armarureDatas->retain(); - m_pAnimationDatas = Dictionary::create(); - CCAssert(m_pAnimationDatas, "create ArmatureDataManager::m_pAnimationDatas fail!"); - m_pAnimationDatas->retain(); + _animationDatas = Dictionary::create(); + CCAssert(_animationDatas, "create ArmatureDataManager::_animationDatas fail!"); + _animationDatas->retain(); - m_pTextureDatas = Dictionary::create(); - CCAssert(m_pTextureDatas, "create ArmatureDataManager::m_pTextureDatas fail!"); - m_pTextureDatas->retain(); + _textureDatas = Dictionary::create(); + CCAssert(_textureDatas, "create ArmatureDataManager::_textureDatas fail!"); + _textureDatas->retain(); bRet = true; } @@ -98,61 +98,61 @@ bool ArmatureDataManager::init() void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData) { - if(m_pArmarureDatas) + if(_armarureDatas) { - m_pArmarureDatas->setObject(armatureData, id); + _armarureDatas->setObject(armatureData, id); } } ArmatureData *ArmatureDataManager::getArmatureData(const char *id) { ArmatureData *armatureData = NULL; - if (m_pArmarureDatas) + if (_armarureDatas) { - armatureData = (ArmatureData *)m_pArmarureDatas->objectForKey(id); + armatureData = (ArmatureData *)_armarureDatas->objectForKey(id); } return armatureData; } void ArmatureDataManager::removeArmatureData(const char *id) { - if (m_pArmarureDatas) + if (_armarureDatas) { - m_pArmarureDatas->removeObjectForKey(id); + _armarureDatas->removeObjectForKey(id); } } void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData) { - if(m_pAnimationDatas) + if(_animationDatas) { - m_pAnimationDatas->setObject(animationData, id); + _animationDatas->setObject(animationData, id); } } AnimationData *ArmatureDataManager::getAnimationData(const char *id) { AnimationData *animationData = NULL; - if (m_pAnimationDatas) + if (_animationDatas) { - animationData = (AnimationData *)m_pAnimationDatas->objectForKey(id); + animationData = (AnimationData *)_animationDatas->objectForKey(id); } return animationData; } void ArmatureDataManager::removeAnimationData(const char *id) { - if (m_pAnimationDatas) + if (_animationDatas) { - m_pAnimationDatas->removeObjectForKey(id); + _animationDatas->removeObjectForKey(id); } } void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData) { - if(m_pTextureDatas) + if(_textureDatas) { - m_pTextureDatas->setObject(textureData, id); + _textureDatas->setObject(textureData, id); } } @@ -160,9 +160,9 @@ void ArmatureDataManager::addTextureData(const char *id, TextureData *textureDat TextureData *ArmatureDataManager::getTextureData(const char *id) { TextureData *textureData = NULL; - if (m_pTextureDatas) + if (_textureDatas) { - textureData = (TextureData *)m_pTextureDatas->objectForKey(id); + textureData = (TextureData *)_textureDatas->objectForKey(id); } return textureData; } @@ -170,34 +170,34 @@ TextureData *ArmatureDataManager::getTextureData(const char *id) void ArmatureDataManager::removeTextureData(const char *id) { - if(m_pTextureDatas) + if(_textureDatas) { - m_pTextureDatas->removeObjectForKey(id); + _textureDatas->removeObjectForKey(id); } } void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath) { - m_bAutoLoadSpriteFile = true; + _autoLoadSpriteFile = true; DataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); } void ArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector) { - m_bAutoLoadSpriteFile = true; + _autoLoadSpriteFile = true; DataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); } void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) { - m_bAutoLoadSpriteFile = false; + _autoLoadSpriteFile = false; DataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); addSpriteFrameFromFile(plistPath, imagePath); } void ArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector) { - m_bAutoLoadSpriteFile = false; + _autoLoadSpriteFile = false; DataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); addSpriteFrameFromFile(plistPath, imagePath); } @@ -210,18 +210,18 @@ void ArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const ch void ArmatureDataManager::removeAll() { - if( m_pAnimationDatas ) + if( _animationDatas ) { - m_pAnimationDatas->removeAllObjects(); + _animationDatas->removeAllObjects(); } - if( m_pArmarureDatas ) + if( _armarureDatas ) { - m_pArmarureDatas->removeAllObjects(); + _armarureDatas->removeAllObjects(); } - if( m_pTextureDatas ) + if( _textureDatas ) { - m_pTextureDatas->removeAllObjects(); + _textureDatas->removeAllObjects(); } DataReaderHelper::clear(); @@ -229,20 +229,20 @@ void ArmatureDataManager::removeAll() bool ArmatureDataManager::isAutoLoadSpriteFile() { - return m_bAutoLoadSpriteFile; + return _autoLoadSpriteFile; } Dictionary *ArmatureDataManager::getArmatureDatas() const { - return m_pArmarureDatas; + return _armarureDatas; } Dictionary *ArmatureDataManager::getAnimationDatas() const { - return m_pAnimationDatas; + return _animationDatas; } Dictionary *ArmatureDataManager::getTextureDatas() const { - return m_pTextureDatas; + return _textureDatas; } NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h index 13cefebe34..fd42be10a6 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h @@ -79,7 +79,7 @@ public: void addAnimationData(const char *id, AnimationData *animationData); /** - * @brief get animation data from m_pAnimationDatas(Dictionary) + * @brief get animation data from _animationDatas(Dictionary) * @param id the id of the animation data you want to get * @return AnimationData * */ @@ -140,7 +140,7 @@ public: /** - * @brief Clear the data in the m_pArmarureDatas and m_pAnimationDatas, and set m_pArmarureDatas and m_pAnimationDatas to NULL + * @brief Clear the data in the _armarureDatas and _animationDatas, and set _armarureDatas and _animationDatas to NULL */ void removeAll(); @@ -159,23 +159,23 @@ private: * @key std::string * @value ArmatureData * */ - Dictionary *m_pArmarureDatas; + Dictionary *_armarureDatas; /** * @brief save animation datas * @key std::string * @value AnimationData * */ - Dictionary *m_pAnimationDatas; + Dictionary *_animationDatas; /** * @brief save texture datas * @key std::string * @value TextureData * */ - Dictionary *m_pTextureDatas; + Dictionary *_textureDatas; - bool m_bAutoLoadSpriteFile; + bool _autoLoadSpriteFile; }; diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp index 21bafa82b9..89ae47ad8e 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp @@ -142,7 +142,7 @@ static float s_CocoStudioVersion = VERSION_COMBINED; static std::string s_BasefilePath = ""; -DataReaderHelper *DataReaderHelper::s_DataReaderHelper = NULL; +DataReaderHelper *DataReaderHelper::_dataReaderHelper = NULL; @@ -157,19 +157,19 @@ void DataReaderHelper::loadData() Thread thread; thread.createAutoreleasePool(); - std::queue *pQueue = s_pAsyncStructQueue; - s_AsyncStructQueueMutex.lock(); // get async struct from queue + std::queue *pQueue = _asyncStructQueue; + _asyncStructQueueMutex.lock(); // get async struct from queue if (pQueue->empty()) { - s_AsyncStructQueueMutex.unlock(); + _asyncStructQueueMutex.unlock(); if (need_quit) { break; } else { - std::unique_lock lk(s_SleepMutex); - s_SleepCondition.wait(lk); + std::unique_lock lk(_sleepMutex); + _sleepCondition.wait(lk); continue; } } @@ -177,7 +177,7 @@ void DataReaderHelper::loadData() { pAsyncStruct = pQueue->front(); pQueue->pop(); - s_AsyncStructQueueMutex.unlock(); + _asyncStructQueueMutex.unlock(); } // generate image info @@ -194,29 +194,29 @@ void DataReaderHelper::loadData() } // put the image info into the queue - s_DataInfoMutex.lock(); - s_pDataQueue->push(pDataInfo); - s_DataInfoMutex.unlock(); + _dataInfoMutex.lock(); + _dataQueue->push(pDataInfo); + _dataInfoMutex.unlock(); } - if( s_pAsyncStructQueue != NULL ) + if( _asyncStructQueue != NULL ) { - delete s_pAsyncStructQueue; - s_pAsyncStructQueue = NULL; - delete s_pDataQueue; - s_pDataQueue = NULL; + delete _asyncStructQueue; + _asyncStructQueue = NULL; + delete _dataQueue; + _dataQueue = NULL; } } DataReaderHelper *DataReaderHelper::sharedDataReaderHelper() { - if(!s_DataReaderHelper) + if(!_dataReaderHelper) { - s_DataReaderHelper = new DataReaderHelper(); + _dataReaderHelper = new DataReaderHelper(); } - return s_DataReaderHelper; + return _dataReaderHelper; } void DataReaderHelper::setPositionReadScale(float scale) @@ -233,7 +233,7 @@ float DataReaderHelper::getPositionReadScale() void DataReaderHelper::purge() { DataReaderHelper::clear(); - CC_SAFE_RELEASE_NULL(s_DataReaderHelper); + CC_SAFE_RELEASE_NULL(_dataReaderHelper); } void DataReaderHelper::clear() @@ -242,12 +242,12 @@ void DataReaderHelper::clear() } DataReaderHelper::DataReaderHelper() - : s_LoadingThread(nullptr) - , s_pAsyncStructQueue(nullptr) - , s_pDataQueue(nullptr) + : _loadingThread(nullptr) + , _asyncStructQueue(nullptr) + , _dataQueue(nullptr) , need_quit(false) - , s_nAsyncRefCount(0) - , s_nAsyncRefTotalCount(0) + , _asyncRefCount(0) + , _asyncRefTotalCount(0) { } @@ -256,11 +256,11 @@ DataReaderHelper::~DataReaderHelper() { need_quit = true; - s_SleepCondition.notify_one(); - if (s_LoadingThread) s_LoadingThread->join(); + _sleepCondition.notify_one(); + if (_loadingThread) _loadingThread->join(); - CC_SAFE_DELETE(s_LoadingThread); - s_DataReaderHelper = NULL; + CC_SAFE_DELETE(_loadingThread); + _dataReaderHelper = NULL; } void DataReaderHelper::addDataFromFile(const char *filePath) @@ -320,13 +320,13 @@ void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target { if (target && selector) { - if (s_nAsyncRefTotalCount == 0 && s_nAsyncRefCount == 0) + if (_asyncRefTotalCount == 0 && _asyncRefCount == 0) { (target->*selector)(1); } else { - (target->*selector)((s_nAsyncRefTotalCount - s_nAsyncRefCount) / (float)s_nAsyncRefTotalCount); + (target->*selector)((_asyncRefTotalCount - _asyncRefCount) / (float)_asyncRefTotalCount); } } return; @@ -348,24 +348,24 @@ void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target // lazy init - if (s_pAsyncStructQueue == NULL) + if (_asyncStructQueue == NULL) { - s_pAsyncStructQueue = new std::queue(); - s_pDataQueue = new std::queue(); + _asyncStructQueue = new std::queue(); + _dataQueue = new std::queue(); // create a new thread to load images - s_LoadingThread = new std::thread(&DataReaderHelper::loadData, this); + _loadingThread = new std::thread(&DataReaderHelper::loadData, this); need_quit = false; } - if (0 == s_nAsyncRefCount) + if (0 == _asyncRefCount) { Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this, 0, false); } - ++s_nAsyncRefCount; - ++s_nAsyncRefTotalCount; + ++_asyncRefCount; + ++_asyncRefTotalCount; if (target) { @@ -400,28 +400,28 @@ void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target // add async struct into queue - s_AsyncStructQueueMutex.lock(); - s_pAsyncStructQueue->push(data); - s_AsyncStructQueueMutex.unlock(); + _asyncStructQueueMutex.lock(); + _asyncStructQueue->push(data); + _asyncStructQueueMutex.unlock(); - s_SleepCondition.notify_one(); + _sleepCondition.notify_one(); } void DataReaderHelper::addDataAsyncCallBack(float dt) { // the data is generated in loading thread - std::queue *dataQueue = s_pDataQueue; + std::queue *dataQueue = _dataQueue; - s_DataInfoMutex.lock(); + _dataInfoMutex.lock(); if (dataQueue->empty()) { - s_DataInfoMutex.unlock(); + _dataInfoMutex.unlock(); } else { DataInfo *pDataInfo = dataQueue->front(); dataQueue->pop(); - s_DataInfoMutex.unlock(); + _dataInfoMutex.unlock(); AsyncStruct *pAsyncStruct = pDataInfo->asyncStruct; @@ -436,11 +436,11 @@ void DataReaderHelper::addDataAsyncCallBack(float dt) Object *target = pAsyncStruct->target; SEL_SCHEDULE selector = pAsyncStruct->selector; - --s_nAsyncRefCount; + --_asyncRefCount; if (target && selector) { - (target->*selector)((s_nAsyncRefTotalCount - s_nAsyncRefCount) / (float)s_nAsyncRefTotalCount); + (target->*selector)((_asyncRefTotalCount - _asyncRefCount) / (float)_asyncRefTotalCount); target->release(); } @@ -448,9 +448,9 @@ void DataReaderHelper::addDataAsyncCallBack(float dt) delete pAsyncStruct; delete pDataInfo; - if (0 == s_nAsyncRefCount) + if (0 == _asyncRefCount) { - s_nAsyncRefTotalCount = 0; + _asyncRefTotalCount = 0; CCDirector::getInstance()->getScheduler()->unscheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this); } } @@ -483,13 +483,13 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.lock(); + _dataReaderHelper->_addDataMutex.lock(); } ArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); armatureData->release(); if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.unlock(); + _dataReaderHelper->_addDataMutex.unlock(); } armatureXML = armatureXML->NextSiblingElement(ARMATURE); @@ -506,13 +506,13 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data AnimationData *animationData = DataReaderHelper::decodeAnimation(animationXML); if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.lock(); + _dataReaderHelper->_addDataMutex.lock(); } ArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); animationData->release(); if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.unlock(); + _dataReaderHelper->_addDataMutex.unlock(); } animationXML = animationXML->NextSiblingElement(ANIMATION); } @@ -529,13 +529,13 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.lock(); + _dataReaderHelper->_addDataMutex.lock(); } ArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); textureData->release(); if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.unlock(); + _dataReaderHelper->_addDataMutex.unlock(); } textureXML = textureXML->NextSiblingElement(SUB_TEXTURE); } @@ -1107,13 +1107,13 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.lock(); + _dataReaderHelper->_addDataMutex.lock(); } ArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); armatureData->release(); if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.unlock(); + _dataReaderHelper->_addDataMutex.unlock(); } delete armatureDic; } @@ -1127,13 +1127,13 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.lock(); + _dataReaderHelper->_addDataMutex.lock(); } ArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); animationData->release(); if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.unlock(); + _dataReaderHelper->_addDataMutex.unlock(); } delete animationDic; } @@ -1147,13 +1147,13 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.lock(); + _dataReaderHelper->_addDataMutex.lock(); } ArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); textureData->release(); if (dataInfo) { - s_DataReaderHelper->s_AddDataMutex.unlock(); + _dataReaderHelper->_addDataMutex.unlock(); } delete textureDic; } diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h index 5306fa22a0..c854766d53 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h @@ -156,29 +156,28 @@ protected: - std::condition_variable s_SleepCondition; + std::condition_variable _sleepCondition; - std::thread *s_LoadingThread; + std::thread *_loadingThread; - std::mutex s_SleepMutex; + std::mutex _sleepMutex; - std::mutex s_AsyncStructQueueMutex; - std::mutex s_DataInfoMutex; + std::mutex _asyncStructQueueMutex; + std::mutex _dataInfoMutex; - std::mutex s_AddDataMutex; - std::mutex s_ReadFileMutex; + std::mutex _addDataMutex; - - unsigned long s_nAsyncRefCount; - unsigned long s_nAsyncRefTotalCount; + + unsigned long _asyncRefCount; + unsigned long _asyncRefTotalCount; bool need_quit; - std::queue *s_pAsyncStructQueue; - std::queue *s_pDataQueue; + std::queue *_asyncStructQueue; + std::queue *_dataQueue; - static DataReaderHelper *s_DataReaderHelper; + static DataReaderHelper *_dataReaderHelper; }; NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp index c6e56b5e6c..d4317e97ae 100644 --- a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp @@ -27,22 +27,22 @@ THE SOFTWARE. NS_CC_EXT_ARMATURE_BEGIN -SpriteFrameCacheHelper *SpriteFrameCacheHelper::s_SpriteFrameCacheHelper = NULL; +SpriteFrameCacheHelper *SpriteFrameCacheHelper::_spriteFrameCacheHelper = NULL; SpriteFrameCacheHelper *SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper() { - if(!s_SpriteFrameCacheHelper) + if(!_spriteFrameCacheHelper) { - s_SpriteFrameCacheHelper = new SpriteFrameCacheHelper(); + _spriteFrameCacheHelper = new SpriteFrameCacheHelper(); } - return s_SpriteFrameCacheHelper; + return _spriteFrameCacheHelper; } void SpriteFrameCacheHelper::purge() { - delete s_SpriteFrameCacheHelper; - s_SpriteFrameCacheHelper = NULL; + delete _spriteFrameCacheHelper; + _spriteFrameCacheHelper = NULL; } void SpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) @@ -53,23 +53,23 @@ void SpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const TextureAtlas *SpriteFrameCacheHelper::getTexureAtlasWithTexture(Texture2D *texture) { int key = texture->getName(); - TextureAtlas *atlas = (TextureAtlas *)m_pTextureAtlasDic->objectForKey(key); + TextureAtlas *atlas = (TextureAtlas *)_textureAtlasDic->objectForKey(key); if (atlas == NULL) { atlas = TextureAtlas::createWithTexture(texture, 4); - m_pTextureAtlasDic->setObject(atlas, key); + _textureAtlasDic->setObject(atlas, key); } return atlas; } SpriteFrameCacheHelper::SpriteFrameCacheHelper() { - m_pTextureAtlasDic = new Dictionary(); + _textureAtlasDic = new Dictionary(); } SpriteFrameCacheHelper::~SpriteFrameCacheHelper() { - CC_SAFE_RELEASE_NULL(m_pTextureAtlasDic); + CC_SAFE_RELEASE_NULL(_textureAtlasDic); } NS_CC_EXT_ARMATURE_END diff --git a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h index 194da81a8e..2ccd1860e7 100644 --- a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h @@ -50,9 +50,9 @@ private: SpriteFrameCacheHelper(); ~SpriteFrameCacheHelper(); - Dictionary *m_pTextureAtlasDic; + Dictionary *_textureAtlasDic; - static SpriteFrameCacheHelper *s_SpriteFrameCacheHelper; + static SpriteFrameCacheHelper *_spriteFrameCacheHelper; }; NS_CC_EXT_ARMATURE_END From ac8261bcd5fad2b7bdd17737dfb8dd3ec8290607 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Mon, 16 Sep 2013 09:56:25 +0800 Subject: [PATCH 17/28] update Android.mk --- extensions/Android.mk | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/extensions/Android.mk b/extensions/Android.mk index b0c6196ec7..c0429efe4a 100644 --- a/extensions/Android.mk +++ b/extensions/Android.mk @@ -69,12 +69,9 @@ 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/CCArmatureDefine.cpp \ CocoStudio/Armature/utils/CCArmatureDataManager.cpp \ CocoStudio/Armature/utils/CCDataReaderHelper.cpp \ CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp \ From c767ff355cf12edbf85d0c173ea304aacd4c4ab7 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Mon, 16 Sep 2013 11:46:08 +0800 Subject: [PATCH 18/28] delete extensions/CCArmature --- extensions/CCArmature/CCArmature.cpp | 654 ------ extensions/CCArmature/CCArmature.h | 172 -- extensions/CCArmature/CCBone.cpp | 360 ---- extensions/CCArmature/CCBone.h | 185 -- .../animation/CCArmatureAnimation.cpp | 316 --- extensions/CCArmature/animation/CCTween.cpp | 444 ---- extensions/CCArmature/animation/CCTween.h | 146 -- extensions/CCArmature/datas/CCDatas.cpp | 445 ---- extensions/CCArmature/datas/CCDatas.h | 467 ----- .../display/CCDecorativeDisplay.cpp | 68 - .../CCArmature/display/CCDecorativeDisplay.h | 61 - .../CCArmature/display/CCDisplayFactory.cpp | 253 --- .../CCArmature/display/CCDisplayFactory.h | 61 - .../CCArmature/display/CCDisplayManager.cpp | 353 ---- .../CCArmature/display/CCDisplayManager.h | 144 -- extensions/CCArmature/display/CCSkin.cpp | 171 -- extensions/CCArmature/display/CCSkin.h | 57 - .../external_tool/CCTexture2DMutable.cpp | 318 --- .../Json/CSContentJsonDictionary.cpp | 388 ---- .../Json/CSContentJsonDictionary.h | 103 - .../Json/lib_json/json_reader.cpp | 882 -------- .../Json/lib_json/json_value.cpp | 1837 ----------------- .../external_tool/Json/lib_json/value.h | 1103 ---------- .../CCArmature/physics/CCColliderDetector.cpp | 298 --- .../CCArmature/physics/CCColliderDetector.h | 129 -- .../utils/CCArmatureDataManager.cpp | 196 -- .../CCArmature/utils/CCArmatureDefine.h | 51 - .../CCArmature/utils/CCDataReaderHelper.cpp | 1191 ----------- .../utils/CCSpriteFrameCacheHelper.cpp | 188 -- .../utils/CCSpriteFrameCacheHelper.h | 70 - extensions/CCArmature/utils/CCUtilMath.cpp | 78 - 31 files changed, 11189 deletions(-) delete mode 100644 extensions/CCArmature/CCArmature.cpp delete mode 100644 extensions/CCArmature/CCArmature.h delete mode 100644 extensions/CCArmature/CCBone.cpp delete mode 100644 extensions/CCArmature/CCBone.h delete mode 100644 extensions/CCArmature/animation/CCArmatureAnimation.cpp delete mode 100644 extensions/CCArmature/animation/CCTween.cpp delete mode 100644 extensions/CCArmature/animation/CCTween.h delete mode 100644 extensions/CCArmature/datas/CCDatas.cpp delete mode 100644 extensions/CCArmature/datas/CCDatas.h delete mode 100644 extensions/CCArmature/display/CCDecorativeDisplay.cpp delete mode 100644 extensions/CCArmature/display/CCDecorativeDisplay.h delete mode 100644 extensions/CCArmature/display/CCDisplayFactory.cpp delete mode 100644 extensions/CCArmature/display/CCDisplayFactory.h delete mode 100644 extensions/CCArmature/display/CCDisplayManager.cpp delete mode 100644 extensions/CCArmature/display/CCDisplayManager.h delete mode 100644 extensions/CCArmature/display/CCSkin.cpp delete mode 100644 extensions/CCArmature/display/CCSkin.h delete mode 100644 extensions/CCArmature/external_tool/CCTexture2DMutable.cpp delete mode 100644 extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.cpp delete mode 100644 extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.h delete mode 100644 extensions/CCArmature/external_tool/Json/lib_json/json_reader.cpp delete mode 100644 extensions/CCArmature/external_tool/Json/lib_json/json_value.cpp delete mode 100644 extensions/CCArmature/external_tool/Json/lib_json/value.h delete mode 100644 extensions/CCArmature/physics/CCColliderDetector.cpp delete mode 100644 extensions/CCArmature/physics/CCColliderDetector.h delete mode 100644 extensions/CCArmature/utils/CCArmatureDataManager.cpp delete mode 100644 extensions/CCArmature/utils/CCArmatureDefine.h delete mode 100644 extensions/CCArmature/utils/CCDataReaderHelper.cpp delete mode 100644 extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp delete mode 100644 extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h delete mode 100644 extensions/CCArmature/utils/CCUtilMath.cpp diff --git a/extensions/CCArmature/CCArmature.cpp b/extensions/CCArmature/CCArmature.cpp deleted file mode 100644 index ca29548a10..0000000000 --- a/extensions/CCArmature/CCArmature.cpp +++ /dev/null @@ -1,654 +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" - -NS_CC_EXT_BEGIN - -std::map CCArmature::m_sArmatureIndexDic; - -CCArmature *CCArmature::create() -{ - CCArmature *armature = new CCArmature(); - if (armature && armature->init()) - { - armature->autorelease(); - return armature; - } - CC_SAFE_DELETE(armature); - return NULL; -} - - -CCArmature *CCArmature::create(const char *_name) -{ - CCArmature *armature = new CCArmature(); - if (armature && armature->init(_name)) - { - armature->autorelease(); - return armature; - } - CC_SAFE_DELETE(armature); - return NULL; -} - -CCArmature *CCArmature::create(const char *name, CCBone *parentBone) -{ - CCArmature *armature = new CCArmature(); - if (armature && armature->init(name, parentBone)) - { - armature->autorelease(); - return armature; - } - CC_SAFE_DELETE(armature); - return NULL; -} - -CCArmature::CCArmature() - : m_pAnimation(NULL) - , m_pArmatureData(NULL) - , m_pBatchNode(NULL) - , m_pAtlas(NULL) - , m_pParentBone(NULL) - , m_pBoneDic(NULL) - , m_pTopBoneList(NULL) -{ -} - - -CCArmature::~CCArmature(void) -{ - if(NULL != m_pBoneDic) - { - m_pBoneDic->removeAllObjects(); - CC_SAFE_DELETE(m_pBoneDic); - } - if (NULL != m_pTopBoneList) - { - m_pTopBoneList->removeAllObjects(); - CC_SAFE_DELETE(m_pTopBoneList); - } - CC_SAFE_DELETE(m_pAnimation); -} - - -bool CCArmature::init() -{ - return init(NULL); -} - - -bool CCArmature::init(const char *name) -{ - bool bRet = false; - do - { - removeAllChildren(); - - CC_SAFE_DELETE(m_pAnimation); - m_pAnimation = new CCArmatureAnimation(); - m_pAnimation->init(this); - - CC_SAFE_DELETE(m_pBoneDic); - m_pBoneDic = new CCDictionary(); - - CC_SAFE_DELETE(m_pTopBoneList); - m_pTopBoneList = new CCArray(); - m_pTopBoneList->init(); - - - m_sBlendFunc.src = CC_BLEND_SRC; - m_sBlendFunc.dst = CC_BLEND_DST; - - - m_strName = name == NULL ? "" : name; - - CCArmatureDataManager *armatureDataManager = CCArmatureDataManager::sharedArmatureDataManager(); - - if(m_strName.length() != 0) - { - m_strName = name; - - CCAnimationData *animationData = armatureDataManager->getAnimationData(name); - CCAssert(animationData, "CCAnimationData not exist! "); - - m_pAnimation->setAnimationData(animationData); - - - CCArmatureData *armatureData = armatureDataManager->getArmatureData(name); - CCAssert(armatureData, ""); - - m_pArmatureData = armatureData; - - - CCDictElement *_element = NULL; - CCDictionary *boneDataDic = &armatureData->boneDataDic; - CCDICT_FOREACH(boneDataDic, _element) - { - CCBone *bone = createBone(_element->getStrKey()); - - //! init bone's CCTween to 1st movement's 1st frame - do - { - - CCMovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str()); - CC_BREAK_IF(!movData); - - CCMovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str()); - CC_BREAK_IF(!movBoneData || movBoneData->frameList.count() <= 0); - - CCFrameData *frameData = movBoneData->getFrameData(0); - CC_BREAK_IF(!frameData); - - bone->getTweenData()->copy(frameData); - bone->changeDisplayByIndex(frameData->displayIndex, false); - } - while (0); - } - - update(0); - updateOffsetPoint(); - } - else - { - m_strName = "new_armature"; - m_pArmatureData = CCArmatureData::create(); - m_pArmatureData->name = m_strName; - - CCAnimationData *animationData = CCAnimationData::create(); - animationData->name = m_strName; - - armatureDataManager->addArmatureData(m_strName.c_str(), m_pArmatureData); - armatureDataManager->addAnimationData(m_strName.c_str(), animationData); - - m_pAnimation->setAnimationData(animationData); - - } - - setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); - - unscheduleUpdate(); - scheduleUpdate(); - - setCascadeOpacityEnabled(true); - setCascadeColorEnabled(true); - - bRet = true; - } - while (0); - - return bRet; -} - -bool CCArmature::init(const char *name, CCBone *parentBone) -{ - m_pParentBone = parentBone; - return init(name); -} - - -CCBone *CCArmature::createBone(const char *boneName) -{ - CCBone *existedBone = getBone(boneName); - if(existedBone != NULL) - return existedBone; - - CCBoneData *boneData = (CCBoneData *)m_pArmatureData->getBoneData(boneName); - std::string parentName = boneData->parentName; - - CCBone *bone = NULL; - - if( parentName.length() != 0 ) - { - createBone(parentName.c_str()); - bone = CCBone::create(boneName); - addBone(bone, parentName.c_str()); - } - else - { - bone = CCBone::create(boneName); - addBone(bone, ""); - } - - bone->setBoneData(boneData); - bone->getDisplayManager()->changeDisplayByIndex(-1, false); - - return bone; -} - - -void CCArmature::addBone(CCBone *bone, const char *parentName) -{ - CCAssert( bone != NULL, "Argument must be non-nil"); - CCAssert(m_pBoneDic->objectForKey(bone->getName()) == NULL, "bone already added. It can't be added again"); - - if (NULL != parentName) - { - CCBone *boneParent = (CCBone *)m_pBoneDic->objectForKey(parentName); - if (boneParent) - { - boneParent->addChildBone(bone); - } - else - { - if (m_pParentBone) - m_pParentBone->addChildBone(bone); - else - m_pTopBoneList->addObject(bone); - } - } - else - { - if (m_pParentBone) - m_pParentBone->addChildBone(bone); - else - m_pTopBoneList->addObject(bone); - } - - bone->setArmature(this); - - m_pBoneDic->setObject(bone, bone->getName()); - addChild(bone); -} - - -void CCArmature::removeBone(CCBone *bone, bool recursion) -{ - CCAssert(bone != NULL, "bone must be added to the bone dictionary!"); - - bone->setArmature(NULL); - bone->removeFromParent(recursion); - - if (m_pTopBoneList->containsObject(bone)) - { - m_pTopBoneList->removeObject(bone); - } - m_pBoneDic->removeObjectForKey(bone->getName()); - removeChild(bone, true); -} - - -CCBone *CCArmature::getBone(const char *_name) const -{ - return (CCBone *)m_pBoneDic->objectForKey(_name); -} - - -void CCArmature::changeBoneParent(CCBone *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) - { - CCBone *boneParent = (CCBone *)m_pBoneDic->objectForKey(parentName); - - if (boneParent) - { - boneParent->addChildBone(bone); - } - } -} - -CCDictionary *CCArmature::getBoneDic() -{ - return m_pBoneDic; -} - -CCAffineTransform CCArmature::nodeToParentTransform() -{ - if (m_bTransformDirty) - { - // Translate values - float x = m_obPosition.x; - float y = m_obPosition.y; - - if (m_bIgnoreAnchorPointForPosition) - { - x += m_obAnchorPointInPoints.x; - y += m_obAnchorPointInPoints.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 (m_fRotationX || m_fRotationY) - { - float radiansX = -CC_DEGREES_TO_RADIANS(m_fRotationX); - float radiansY = -CC_DEGREES_TO_RADIANS(m_fRotationY); - cx = cosf(radiansX); - sx = sinf(radiansX); - cy = cosf(radiansY); - sy = sinf(radiansY); - } - - // Add offset point - x += cy * m_pOffsetPoint.x * m_fScaleX + -sx * m_pOffsetPoint.y * m_fScaleY; - y += sy * m_pOffsetPoint.x * m_fScaleX + cx * m_pOffsetPoint.y * m_fScaleY; - - bool needsSkewMatrix = ( m_fSkewX || m_fSkewY ); - - // optimization: - // inline anchor point calculation if skew is not needed - // Adjusted transform calculation for rotational skew - if (! needsSkewMatrix && !m_obAnchorPointInPoints.equals(CCPointZero)) - { - x += cy * -m_obAnchorPointInPoints.x * m_fScaleX + -sx * -m_obAnchorPointInPoints.y * m_fScaleY; - y += sy * -m_obAnchorPointInPoints.x * m_fScaleX + cx * -m_obAnchorPointInPoints.y * m_fScaleY; - } - - - // Build Transform Matrix - // Adjusted transform calculation for rotational skew - m_sTransform = CCAffineTransformMake( cy * m_fScaleX, sy * m_fScaleX, - -sx * m_fScaleY, cx * m_fScaleY, - x, y ); - - // XXX: Try to inline skew - // If skew is needed, apply skew and then anchor point - if (needsSkewMatrix) - { - CCAffineTransform skewMatrix = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)), - tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, - 0.0f, 0.0f ); - m_sTransform = CCAffineTransformConcat(skewMatrix, m_sTransform); - - // adjust anchor point - if (!m_obAnchorPointInPoints.equals(CCPointZero)) - { - m_sTransform = CCAffineTransformTranslate(m_sTransform, -m_obAnchorPointInPoints.x, -m_obAnchorPointInPoints.y); - } - } - - if (m_bAdditionalTransformDirty) - { - m_sTransform = CCAffineTransformConcat(m_sTransform, m_sAdditionalTransform); - m_bAdditionalTransformDirty = false; - } - - m_bTransformDirty = false; - } - - return m_sTransform; -} - -void CCArmature::updateOffsetPoint() -{ - // Set contentsize and Calculate anchor point. - CCRect rect = boundingBox(); - setContentSize(rect.size); - m_pOffsetPoint = ccp(-rect.origin.x, -rect.origin.y); - if (rect.size.width != 0 && rect.size.height!= 0) - { - setAnchorPoint(ccp(m_pOffsetPoint.x / rect.size.width, m_pOffsetPoint.y / rect.size.height)); - } -} - -void CCArmature::setAnimation(CCArmatureAnimation *animation) -{ - m_pAnimation = animation; -} - -CCArmatureAnimation *CCArmature::getAnimation() -{ - return m_pAnimation; -} - -void CCArmature::update(float dt) -{ - m_pAnimation->update(dt); - - CCObject *object = NULL; - CCARRAY_FOREACH(m_pTopBoneList, object) - { - ((CCBone *)object)->update(dt); - } -} - -void CCArmature::draw() -{ - if (m_pParentBone == NULL) - { - CC_NODE_DRAW_SETUP(); - ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); - } - - CCObject *object = NULL; - CCARRAY_FOREACH(m_pChildren, object) - { - CCBone *bone = (CCBone *)object; - - CCDisplayManager *displayManager = bone->getDisplayManager(); - CCNode *node = displayManager->getDisplayRenderNode(); - - if (NULL == node) - continue; - - if(CCSkin *skin = dynamic_cast(node)) - { - CCTextureAtlas *textureAtlas = skin->getTextureAtlas(); - if(m_pAtlas != textureAtlas) - { - if (m_pAtlas) - { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); - } - } - - m_pAtlas = textureAtlas; - if (m_pAtlas->getCapacity() == m_pAtlas->getTotalQuads() && !m_pAtlas->resizeCapacity(m_pAtlas->getCapacity() * 2)) - return; - - skin->updateTransform(); - } - else if(CCArmature *armature = dynamic_cast(node)) - { - CCTextureAtlas *textureAtlas = armature->getTextureAtlas(); - - if(m_pAtlas != textureAtlas) - { - if (m_pAtlas) - { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); - } - } - armature->draw(); - } - else - { - if (m_pAtlas) - { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); - } - node->visit(); - - CC_NODE_DRAW_SETUP(); - ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst); - } - } - - if(m_pAtlas && !m_pBatchNode && m_pParentBone == NULL) - { - m_pAtlas->drawQuads(); - m_pAtlas->removeAllQuads(); - } -} - -void CCArmature::visit() -{ - // quick return if not visible. children won't be drawn. - if (!m_bVisible) - { - return; - } - kmGLPushMatrix(); - - if (m_pGrid && m_pGrid->isActive()) - { - m_pGrid->beforeDraw(); - } - - transform(); - sortAllChildren(); - draw(); - - // reset for next frame - m_uOrderOfArrival = 0; - - if (m_pGrid && m_pGrid->isActive()) - { - m_pGrid->afterDraw(this); - } - - kmGLPopMatrix(); -} - -CCRect CCArmature::boundingBox() -{ - float minx, miny, maxx, maxy = 0; - - bool first = true; - - CCRect boundingBox = CCRectMake(0, 0, 0, 0); - - CCObject *object = NULL; - CCARRAY_FOREACH(m_pChildren, object) - { - CCBone *bone = (CCBone *)object; - CCRect 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; -} - -CCBone *CCArmature::getBoneAtPoint(float x, float y) -{ - int length = m_pChildren->data->num; - CCBone **bs = (CCBone **)m_pChildren->data->arr; - - for(int i = length - 1; i >= 0; i--) - { - if(bs[i]->getDisplayManager()->containPoint(x, y)) - { - return bs[i]; - } - } - return NULL; -} - -#if ENABLE_PHYSICS_BOX2D_DETECT -b2Body *CCArmature::getB2Body() -{ - return m_pB2Body; -} - -void CCArmature::setB2Body(b2Body *body) -{ - m_pB2Body = body; - - CCObject *object = NULL; - CCARRAY_FOREACH(m_pChildren, object) - { - if (CCBone *bone = dynamic_cast(object)) - { - CCArray *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - - CCObject *displayObject = NULL; - CCARRAY_FOREACH(displayList, displayObject) - { - CCColliderDetector *detector = ((CCDecorativeDisplay*)displayObject)->getColliderDetector(); - if (detector != NULL) - { - detector->setB2Body(m_pB2Body); - } - } - } - } -} -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT -cpBody *CCArmature::getCPBody() -{ - return m_pCPBody; -} - -void CCArmature::setCPBody(cpBody *body) -{ - m_pCPBody = body; - - CCObject *object = NULL; - CCARRAY_FOREACH(m_pChildren, object) - { - if (CCBone *bone = dynamic_cast(object)) - { - CCArray *displayList = bone->getDisplayManager()->getDecorativeDisplayList(); - - CCObject *displayObject = NULL; - CCARRAY_FOREACH(displayList, displayObject) - { - CCColliderDetector *detector = ((CCDecorativeDisplay*)displayObject)->getColliderDetector(); - if (detector != NULL) - { - detector->setCPBody(m_pCPBody); - } - } - } - } -} -#endif - - -NS_CC_EXT_END diff --git a/extensions/CCArmature/CCArmature.h b/extensions/CCArmature/CCArmature.h deleted file mode 100644 index 42396f6e9b..0000000000 --- a/extensions/CCArmature/CCArmature.h +++ /dev/null @@ -1,172 +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 __CCARMATURE_H__ -#define __CCARMATURE_H__ - -#include "utils/CCArmatureDefine.h" -#include "CCBone.h" -#include "display/CCBatchNode.h" -#include "animation/CCArmatureAnimation.h" - -class b2Body; -struct cpBody; - -NS_CC_EXT_BEGIN - -class CCArmature : public CCNodeRGBA, public CCBlendProtocol -{ - -public: - /** - * Allocates and initializes a armature. - * @return A initialized armature which is marked as "autorelease". - */ - static CCArmature *create(); - - /** - * Allocates a armature, and use the CCArmatureData named name in CCArmatureDataManager to initializes the armature. - * - * @param name CCArmature will use the name to find to the CCArmatureData to initializes it. - * @return A initialized armature which is marked as "autorelease". - */ - static CCArmature *create(const char *name); - - static CCArmature *create(const char *name, CCBone *parentBone); - -public: - CCArmature(); - ~CCArmature(void); - - /** - * Init the empty armature - */ - virtual bool init(); - - /** - * Init a armature with specified name - * @param name CCArmature name - */ - virtual bool init(const char *name); - - virtual bool init(const char *name, CCBone *parentBone); - /** - * Add a CCBone to this CCArmature, - * - * @param bone The CCBone you want to add to CCArmature - * @param parentName The parent CCBone's name you want to add to . If it's NULL, then set CCArmature to it's parent - */ - virtual void addBone(CCBone *bone, const char* parentName); - /** - * Get a bone with the specified name - * - * @param name The bone's name you want to get - */ - virtual CCBone *getBone(const char *name) const; - /** - * Change a bone's parent with the specified parent name. - * - * @param bone The bone you want to change parent - * @param parentName The new parent's name. - */ - virtual void changeBoneParent(CCBone *bone, const char *parentName); - /** - * Remove a bone with the specified name. If recursion it will also remove child CCBone recursionly. - * - * @param bone The bone you want to remove - * @param recursion Determine whether remove the bone's child recursion. - */ - virtual void removeBone(CCBone *bone, bool recursion); - - /** - * Get CCArmature's bone dictionary - * @return CCArmature's bone dictionary - */ - CCDictionary *getBoneDic(); - - /** - * This boundingBox will calculate all bones' boundingBox every time - */ - virtual CCRect boundingBox(); - - CCBone *getBoneAtPoint(float x, float y); - - virtual void visit(); - virtual void update(float dt); - virtual void draw(); - - virtual CCAffineTransform nodeToParentTransform(); - - /** - * Set contentsize and Calculate anchor point. - */ - virtual void updateOffsetPoint(); - - inline void setBlendFunc(ccBlendFunc blendFunc) { m_sBlendFunc = blendFunc; } - inline ccBlendFunc getBlendFunc(void) { return m_sBlendFunc; } - - virtual void setAnimation(CCArmatureAnimation *animation); - virtual CCArmatureAnimation *getAnimation(); -protected: - - /* - * Used to create CCBone internal - */ - CCBone *createBone(const char *boneName ); - - - CC_SYNTHESIZE(CCArmatureData *, m_pArmatureData, ArmatureData); - - CC_SYNTHESIZE(CCBatchNode*, m_pBatchNode, BatchNode); - - CC_SYNTHESIZE_PASS_BY_REF(std::string, m_strName, Name); - - 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. - - CCArray *m_pTopBoneList; - - static std::map m_sArmatureIndexDic; //! Use to save armature zorder info, - - ccBlendFunc m_sBlendFunc; //! It's required for CCTextureProtocol inheritance - - CCPoint m_pOffsetPoint; - - CCArmatureAnimation *m_pAnimation; - -#if ENABLE_PHYSICS_BOX2D_DETECT - CC_PROPERTY(b2Body*, m_pB2Body, B2Body); -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_PROPERTY(cpBody*, m_pCPBody, CPBody); -#endif -}; - -NS_CC_EXT_END - -#endif /*__CCARMATURE_H__*/ diff --git a/extensions/CCArmature/CCBone.cpp b/extensions/CCArmature/CCBone.cpp deleted file mode 100644 index f4e4bf0d2f..0000000000 --- a/extensions/CCArmature/CCBone.cpp +++ /dev/null @@ -1,360 +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_BEGIN - -CCBone *CCBone::create() -{ - - CCBone *pBone = new CCBone(); - if (pBone && pBone->init()) - { - pBone->autorelease(); - return pBone; - } - CC_SAFE_DELETE(pBone); - return NULL; - -} - -CCBone *CCBone::create(const char *name) -{ - - CCBone *pBone = new CCBone(); - if (pBone && pBone->init(name)) - { - pBone->autorelease(); - return pBone; - } - CC_SAFE_DELETE(pBone); - return NULL; -} - -CCBone::CCBone() -{ - m_pTweenData = NULL; - m_pParentBone = NULL; - m_pArmature = NULL; - m_pChildArmature = NULL; - m_pBoneData = NULL; - m_pTween = NULL; - m_pTween = NULL; - m_pChildren = NULL; - m_pDisplayManager = NULL; - m_bIgnoreMovementBoneData = false; - m_tWorldTransform = CCAffineTransformMake(1, 0, 0, 1, 0, 0); - m_bBoneTransformDirty = true; -} - - -CCBone::~CCBone(void) -{ - CC_SAFE_DELETE(m_pTweenData); - CC_SAFE_DELETE(m_pChildren); - CC_SAFE_DELETE(m_pTween); - CC_SAFE_DELETE(m_pDisplayManager); - - if(m_pBoneData) - { - m_pBoneData->release(); - } - - CC_SAFE_RELEASE(m_pChildArmature); -} - -bool CCBone::init() -{ - return CCBone::init(NULL); -} - - -bool CCBone::init(const char *name) -{ - bool bRet = false; - do - { - - if(NULL != name) - { - m_strName = name; - } - - CC_SAFE_DELETE(m_pTweenData); - m_pTweenData = new CCFrameData(); - - CC_SAFE_DELETE(m_pTween); - m_pTween = new CCTween(); - m_pTween->init(this); - - CC_SAFE_DELETE(m_pDisplayManager); - m_pDisplayManager = new CCDisplayManager(); - m_pDisplayManager->init(this); - - - bRet = true; - } - while (0); - - return bRet; -} - -void CCBone::setBoneData(CCBoneData *boneData) -{ - CCAssert(NULL != boneData, "_boneData must not be NULL"); - - m_pBoneData = boneData; - m_pBoneData->retain(); - - m_strName = m_pBoneData->name; - m_nZOrder = m_pBoneData->zOrder; - - m_pDisplayManager->initDisplayList(boneData); -} - -CCBoneData *CCBone::getBoneData() -{ - return m_pBoneData; -} - -void CCBone::setArmature(CCArmature *armature) -{ - m_pArmature = armature; - m_pTween->setAnimation(m_pArmature->getAnimation()); -} - - -CCArmature *CCBone::getArmature() -{ - return m_pArmature; -} - -void CCBone::update(float delta) -{ - if (m_pParentBone) - m_bBoneTransformDirty = m_bBoneTransformDirty || m_pParentBone->isTransformDirty(); - - if (m_bBoneTransformDirty) - { - float cosX = cos(m_pTweenData->skewX); - float cosY = cos(m_pTweenData->skewY); - float sinX = sin(m_pTweenData->skewX); - float sinY = sin(m_pTweenData->skewY); - - m_tWorldTransform.a = m_pTweenData->scaleX * cosY; - m_tWorldTransform.b = m_pTweenData->scaleX * sinY; - m_tWorldTransform.c = m_pTweenData->scaleY * sinX; - m_tWorldTransform.d = m_pTweenData->scaleY * cosX; - m_tWorldTransform.tx = m_pTweenData->x; - m_tWorldTransform.ty = m_pTweenData->y; - - m_tWorldTransform = CCAffineTransformConcat(nodeToParentTransform(), m_tWorldTransform); - - if(m_pParentBone) - { - m_tWorldTransform = CCAffineTransformConcat(m_tWorldTransform, m_pParentBone->m_tWorldTransform); - } - } - - CCDisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty); - - CCObject *object = NULL; - CCARRAY_FOREACH(m_pChildren, object) - { - CCBone *childBone = (CCBone *)object; - childBone->update(delta); - } - - m_bBoneTransformDirty = false; -} - - -void CCBone::updateDisplayedColor(const ccColor3B &parentColor) -{ - CCNodeRGBA::updateDisplayedColor(parentColor); - updateColor(); -} - -void CCBone::updateDisplayedOpacity(GLubyte parentOpacity) -{ - CCNodeRGBA::updateDisplayedOpacity(parentOpacity); - updateColor(); -} - -void CCBone::updateColor() -{ - CCNode *display = m_pDisplayManager->getDisplayRenderNode(); - CCRGBAProtocol *protocol = dynamic_cast(display); - if(protocol != NULL) - { - protocol->setColor(ccc3(_displayedColor.r * m_pTweenData->r / 255, _displayedColor.g * m_pTweenData->g / 255, _displayedColor.b * m_pTweenData->b / 255)); - protocol->setOpacity(_displayedOpacity * m_pTweenData->a / 255); - } -} - -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) -{ - CCAssert( NULL != child, "Argument must be non-nil"); - CCAssert( NULL == child->m_pParentBone, "child already added. It can't be added again"); - - if(!m_pChildren) - { - m_pChildren = CCArray::createWithCapacity(4); - m_pChildren->retain(); - } - - if (m_pChildren->indexOfObject(child) == UINT_MAX) - { - m_pChildren->addObject(child); - child->setParentBone(this); - } -} - -void CCBone::removeChildBone(CCBone *bone, bool recursion) -{ - if ( m_pChildren->indexOfObject(bone) != UINT_MAX ) - { - if(recursion) - { - CCArray *_ccbones = bone->m_pChildren; - CCObject *_object = NULL; - CCARRAY_FOREACH(_ccbones, _object) - { - CCBone *_ccBone = (CCBone *)_object; - bone->removeChildBone(_ccBone, recursion); - } - } - - bone->setParentBone(NULL); - - bone->getDisplayManager()->setCurrentDecorativeDisplay(NULL); - - m_pChildren->removeObject(bone); - } -} - -void CCBone::removeFromParent(bool recursion) -{ - if (NULL != m_pParentBone) - { - m_pParentBone->removeChildBone(this, recursion); - } -} - -void CCBone::setParentBone(CCBone *parent) -{ - m_pParentBone = parent; -} - -CCBone *CCBone::getParentBone() -{ - return m_pParentBone; -} - -void CCBone::setChildArmature(CCArmature *armature) -{ - if (m_pChildArmature != armature) - { - CC_SAFE_RETAIN(armature); - CC_SAFE_RELEASE(m_pChildArmature); - m_pChildArmature = armature; - } -} - -CCArmature *CCBone::getChildArmature() -{ - return m_pChildArmature; -} - -CCTween *CCBone::getTween() -{ - return m_pTween; -} - -void CCBone::setZOrder(int zOrder) -{ - if (m_nZOrder != zOrder) - CCNode::setZOrder(zOrder); -} - -void CCBone::setTransformDirty(bool dirty) -{ - m_bBoneTransformDirty = dirty; -} - -bool CCBone::isTransformDirty() -{ - return m_bBoneTransformDirty; -} - -CCAffineTransform CCBone::nodeToArmatureTransform() -{ - return m_tWorldTransform; -} - -CCAffineTransform CCBone::nodeToWorldTransform() -{ - return CCAffineTransformConcat(m_tWorldTransform, m_pArmature->nodeToWorldTransform()); -} - -CCNode *CCBone::getDisplayRenderNode() -{ - return m_pDisplayManager->getDisplayRenderNode(); -} - -void CCBone::addDisplay(CCDisplayData *displayData, int index) -{ - m_pDisplayManager->addDisplay(displayData, index); -} - -void CCBone::addDisplay(CCNode *display, int index) -{ - m_pDisplayManager->addDisplay(display, index); -} - -void CCBone::changeDisplayByIndex(int _index, bool _force) -{ - m_pDisplayManager->changeDisplayByIndex(_index, _force); -} - -NS_CC_EXT_END diff --git a/extensions/CCArmature/CCBone.h b/extensions/CCArmature/CCBone.h deleted file mode 100644 index 46b1641d7b..0000000000 --- a/extensions/CCArmature/CCBone.h +++ /dev/null @@ -1,185 +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 "external_tool/CCTexture2DMutable.h" -#include "display/CCDecorativeDisplay.h" -#include "display/CCDisplayManager.h" - -NS_CC_EXT_BEGIN - -class CCArmature; - -class CCBone : public CCNodeRGBA -{ -public: - /** - * Allocates and initializes a bone. - * @return A initialized bone which is marked as "autorelease". - */ - static CCBone *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 CCBone *create(const char *name); - -public: - CCBone(); - virtual ~CCBone(void); - - /** - * Initializes an empty CCBone with nothing init. - */ - virtual bool init(); - - /** - * Initializes a CCBone with the specified name - * @param name CCBone's name. - */ - virtual bool init(const char *name); - - /** - * Add display and use _DisplayData 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 CCSpriteDisplayData param - * - * @param _index the index of the display you want to replace or add to - * -1 : append display from back - */ - void addDisplay(CCDisplayData *displayData, int index); - - void addDisplay(CCNode *display, int index); - - void changeDisplayByIndex(int index, bool force); - - /** - * Add a child to this bone, and it will let this child call setParent(CCBone *_parent) function to set self to it's parent - * @param _child the child you want to add - */ - void addChildBone(CCBone *_child); - - /** - * Set parent bone. - * If _parent is NUll, then also remove this bone from armature. - * It will not set the CCArmature, if you want to add the bone to a CCArmature, you should use CCArmature::addBone(CCBone *bone, const char* _parentName). - * - * @param parent the parent bone. - * NULL : remove this bone from armature - */ - void setParentBone(CCBone *parent); - - /** - * Get parent bone - * @return parent bone - */ - CCBone *getParentBone(); - - /** - * Remove itself from its parent CCBone. - * @param recursion whether or not remove Child display - */ - void removeFromParent(bool recursion); - - /** - * Removes a child CCBone - * @param bone the bone you want to remove - */ - void removeChildBone(CCBone *bone, bool recursion); - - void update(float delta); - - void updateDisplayedColor(const ccColor3B &parentColor); - void updateDisplayedOpacity(GLubyte parentOpacity); - - //! Update color to render display - void updateColor(); - - //! 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. - */ - virtual void setTransformDirty(bool dirty); - - virtual bool isTransformDirty(); - - virtual CCAffineTransform nodeToArmatureTransform(); - virtual CCAffineTransform nodeToWorldTransform(); - - CCNode *getDisplayRenderNode(); -public: - /* - * The origin state of the CCBone. Display's state is effected by m_pBoneData, m_pNode, m_pTweenData - * when call setData function, it will copy from the CCBoneData. - */ - CC_PROPERTY(CCBoneData *, m_pBoneData, BoneData); - - //! A weak reference to the CCArmature - CC_PROPERTY(CCArmature *, m_pArmature, Armature); - - //! A weak reference to the child CCArmature - CC_PROPERTY(CCArmature *, m_pChildArmature, ChildArmature); - - CC_SYNTHESIZE(CCDisplayManager *, m_pDisplayManager, DisplayManager) - - /* - * When CCArmature play a animation, if there is not a CCMovementBoneData of this bone in this CCMovementData, this bone will hide. - * Set IgnoreMovementBoneData to true, then this bone will also show. - */ - CC_SYNTHESIZE_PASS_BY_REF(bool, m_bIgnoreMovementBoneData, IgnoreMovementBoneData) - -protected: - CCTween *m_pTween; //! Calculate tween effect - - //! Used for make tween effect between every frame - CC_SYNTHESIZE_READONLY(CCFrameData *, m_pTweenData, TweenData); - - CC_SYNTHESIZE_PASS_BY_REF(std::string, m_strName, Name); - - CCBone *m_pParentBone; //! A weak reference to it's parent - bool m_bBoneTransformDirty; //! Whether or not transform dirty - - //! self Transform, use this to change display's state - CCAffineTransform m_tWorldTransform; -}; - -NS_CC_EXT_END - -#endif /*__CCBONE_H__*/ diff --git a/extensions/CCArmature/animation/CCArmatureAnimation.cpp b/extensions/CCArmature/animation/CCArmatureAnimation.cpp deleted file mode 100644 index 031c2dc30d..0000000000 --- a/extensions/CCArmature/animation/CCArmatureAnimation.cpp +++ /dev/null @@ -1,316 +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 "CCArmatureAnimation.h" -#include "../CCArmature.h" -#include "../CCBone.h" -#include "../utils/CCArmatureDefine.h" -#include "../utils/CCUtilMath.h" -#include "../utils/CCConstValue.h" -#include "../datas/CCDatas.h" - - -NS_CC_EXT_BEGIN - -CCArmatureAnimation *CCArmatureAnimation::create(CCArmature *armature) -{ - CCArmatureAnimation *pArmatureAnimation = new CCArmatureAnimation(); - if (pArmatureAnimation && pArmatureAnimation->init(armature)) - { - pArmatureAnimation->autorelease(); - return pArmatureAnimation; - } - CC_SAFE_DELETE(pArmatureAnimation); - return NULL; -} - - -CCArmatureAnimation::CCArmatureAnimation() - : m_pAnimationData(NULL) - , m_pArmature(NULL) - , m_strMovementID("") - , m_iToIndex(0) -{ - -} - -CCArmatureAnimation::~CCArmatureAnimation(void) -{ - CC_SAFE_RELEASE_NULL(m_pTweenList); - CC_SAFE_RELEASE_NULL(m_pAnimationData); -} - -bool CCArmatureAnimation::init(CCArmature *armature) -{ - bool bRet = false; - do - { - m_pArmature = armature; - - m_pTweenList = new CCArray(); - m_pTweenList->init(); - - bRet = true; - } - while (0); - - return bRet; -} - - -void CCArmatureAnimation:: pause() -{ - CCObject *object = NULL; - CCARRAY_FOREACH(m_pTweenList, object) - { - ((CCTween *)object)->pause(); - } - CCProcessBase::pause(); -} - -void CCArmatureAnimation::resume() -{ - CCObject *object = NULL; - CCARRAY_FOREACH(m_pTweenList, object) - { - ((CCTween *)object)->resume(); - } - CCProcessBase::resume(); -} - -void CCArmatureAnimation::stop() -{ - CCObject *object = NULL; - CCARRAY_FOREACH(m_pTweenList, object) - { - ((CCTween *)object)->stop(); - } - m_pTweenList->removeAllObjects(); - CCProcessBase::stop(); -} - -void CCArmatureAnimation::setAnimationScale(float animationScale ) -{ - if(animationScale == m_fAnimationScale) - { - return; - } - - m_fAnimationScale = animationScale; - - CCDictElement *element = NULL; - CCDictionary *dict = m_pArmature->getBoneDic(); - CCDICT_FOREACH(dict, element) - { - CCBone *bone = (CCBone *)element->getObject(); - bone->getTween()->setAnimationScale(m_fAnimationScale); - if (bone->getChildArmature()) - { - bone->getChildArmature()->getAnimation()->setAnimationScale(m_fAnimationScale); - } - } -} - - -void CCArmatureAnimation::play(const char *animationName, int durationTo, int durationTween, int loop, int tweenEasing) -{ - CCAssert(m_pAnimationData, "m_pAnimationData can not be null"); - - m_pMovementData = m_pAnimationData->getMovement(animationName); - CCAssert(m_pMovementData, "m_pMovementData can not be null"); - - //! Get key frame count - m_iRawDuration = m_pMovementData->duration; - - m_strMovementID = animationName; - - //! Further processing parameters - durationTo = (durationTo == -1) ? m_pMovementData->durationTo : durationTo; - - durationTween = (durationTween == -1) ? m_pMovementData->durationTween : durationTween; - durationTween = (durationTween == 0) ? m_pMovementData->duration : durationTween; - - tweenEasing = (tweenEasing == TWEEN_EASING_MAX) ? m_pMovementData->tweenEasing : tweenEasing; - loop = (loop < 0) ? m_pMovementData->loop : loop; - - - CCProcessBase::play((void *)animationName, durationTo, durationTween, loop, tweenEasing); - - - if (m_iRawDuration == 0) - { - m_eLoopType = SINGLE_FRAME; - } - else - { - if (loop) - { - m_eLoopType = ANIMATION_TO_LOOP_FRONT; - } - else - { - m_eLoopType = ANIMATION_NO_LOOP; - m_iRawDuration --; - } - m_iDurationTween = durationTween; - } - - CCMovementBoneData *movementBoneData = NULL; - m_pTweenList->removeAllObjects(); - - CCDictElement *element = NULL; - CCDictionary *dict = m_pArmature->getBoneDic(); - - CCDICT_FOREACH(dict, element) - { - CCBone *bone = (CCBone *)element->getObject(); - movementBoneData = (CCMovementBoneData *)m_pMovementData->movBoneDataDic.objectForKey(bone->getName()); - - CCTween *tween = bone->getTween(); - 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); - if (bone->getChildArmature()) - { - bone->getChildArmature()->getAnimation()->setAnimationScale(m_fAnimationScale); - } - } - else - { - if(!bone->getIgnoreMovementBoneData()) - { - //! this bone is not include in this movement, so hide it - bone->getDisplayManager()->changeDisplayByIndex(-1, false); - tween->stop(); - } - - } - } - - //m_pArmature->update(0); -} - - -void CCArmatureAnimation::playByIndex(int animationIndex, int durationTo, int durationTween, int loop, int tweenEasing) -{ - std::vector &movName = m_pAnimationData->movementNames; - CC_ASSERT((animationIndex > -1) && ((unsigned int)animationIndex < movName.size())); - - std::string animationName = movName.at(animationIndex); - play(animationName.c_str(), durationTo, durationTween, loop, tweenEasing); -} - - - -int CCArmatureAnimation::getMovementCount() -{ - return m_pAnimationData->getMovementCount(); -} - -void CCArmatureAnimation::update(float dt) -{ - CCProcessBase::update(dt); - CCObject *object = NULL; - CCARRAY_FOREACH(m_pTweenList, object) - { - ((CCTween *)object)->update(dt); - } -} - -void CCArmatureAnimation::updateHandler() -{ - if (m_fCurrentPercent >= 1) - { - switch(m_eLoopType) - { - case ANIMATION_NO_LOOP: - { - m_eLoopType = ANIMATION_MAX; - m_fCurrentFrame = (m_fCurrentPercent - 1) * m_iNextFrameIndex; - m_fCurrentPercent = m_fCurrentFrame / m_iDurationTween; - - if (m_fCurrentPercent >= 1.0f) - { - } - else - { - m_iNextFrameIndex = m_iDurationTween; - - MovementEventSignal.emit(m_pArmature, START, m_strMovementID.c_str()); - - break; - } - } - break; - case ANIMATION_MAX: - case SINGLE_FRAME: - { - m_fCurrentPercent = 1; - m_bIsComplete = true; - - MovementEventSignal.emit(m_pArmature, COMPLETE, m_strMovementID.c_str()); - } - break; - case ANIMATION_TO_LOOP_FRONT: - { - m_eLoopType = ANIMATION_LOOP_FRONT; - m_fCurrentPercent = fmodf(m_fCurrentPercent, 1); - m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); - m_iNextFrameIndex = m_iDurationTween > 0 ? m_iDurationTween : 1; - - MovementEventSignal.emit(m_pArmature, START, m_strMovementID.c_str()); - } - break; - default: - { - m_fCurrentPercent = fmodf(m_fCurrentPercent, 1); - m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); - m_iToIndex = 0; - - MovementEventSignal.emit(m_pArmature, LOOP_COMPLETE, m_strMovementID.c_str()); - } - break; - } - } - - if (m_eLoopType == ANIMATION_LOOP_FRONT || m_eLoopType == ANIMATION_LOOP_BACK) - { - updateFrameData(m_fCurrentPercent); - } -} - - -void CCArmatureAnimation::updateFrameData(float currentPercent) -{ - m_iPrevFrameIndex = m_iCurFrameIndex; - m_iCurFrameIndex = m_iRawDuration * currentPercent; - m_iCurFrameIndex = m_iCurFrameIndex % m_iRawDuration; -} - - -NS_CC_EXT_END diff --git a/extensions/CCArmature/animation/CCTween.cpp b/extensions/CCArmature/animation/CCTween.cpp deleted file mode 100644 index 03742cba6d..0000000000 --- a/extensions/CCArmature/animation/CCTween.cpp +++ /dev/null @@ -1,444 +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 "CCTween.h" -#include "CCArmatureAnimation.h" -#include "../CCBone.h" -#include "../CCArmature.h" -#include "../utils/CCUtilMath.h" -#include "../utils/CCTweenFunction.h" - - -NS_CC_EXT_BEGIN - -CCTween *CCTween::create(CCBone *bone) -{ - CCTween *pTween = new CCTween(); - if (pTween && pTween->init(bone)) - { - pTween->autorelease(); - return pTween; - } - CC_SAFE_DELETE(pTween); - return NULL; - -} - - - -CCTween::CCTween() - : m_pMovementBoneData(NULL) - , m_pTweenData(NULL) - , m_pFrom(NULL) - , m_pTo(NULL) - , m_pBetween(NULL) - , m_pBone(NULL) - - , m_eFrameTweenEasing(Linear) - , m_iFromIndex(0) - , m_iToIndex(0) - , m_pAnimation(NULL) -{ - -} - - -CCTween::~CCTween(void) -{ - CC_SAFE_DELETE( m_pFrom ); - CC_SAFE_DELETE( m_pBetween ); -} - - -bool CCTween::init(CCBone *bone) -{ - bool bRet = false; - do - { - m_pFrom = new CCFrameData(); - m_pBetween = new CCFrameData(); - - m_pBone = bone; - m_pTweenData = m_pBone->getTweenData(); - m_pTweenData->displayIndex = -1; - - m_pAnimation = m_pBone->getArmature() != NULL ? m_pBone->getArmature()->getAnimation() : NULL; - - bRet = true; - } - while (0); - - return bRet; -} - - -void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing) -{ - CCProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing); - - m_eLoopType = (AnimationType)loop; - - m_iTotalDuration = 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_iRawDuration == 0 ) - { - m_eLoopType = SINGLE_FRAME; - if(durationTo == 0) - { - setBetween(nextKeyFrame, nextKeyFrame); - } - else - { - setBetween(m_pTweenData, nextKeyFrame); - } - m_eFrameTweenEasing = Linear; - } - else if (m_pMovementBoneData->frameList.count() > 1) - { - if (loop) - { - m_eLoopType = ANIMATION_TO_LOOP_BACK; - } - else - { - m_eLoopType = ANIMATION_NO_LOOP; - } - - m_iDurationTween = durationTween * m_pMovementBoneData->scale; - - if (loop && m_pMovementBoneData->delay != 0) - { - setBetween(m_pTweenData, tweenNodeTo(updateFrameData(1 - m_pMovementBoneData->delay), m_pBetween)); - } - else - { - if (!difMovement) - { - setBetween(nextKeyFrame, nextKeyFrame); - } - else - { - setBetween(m_pTweenData, nextKeyFrame); - } - } - } - - tweenColorTo(0, m_pTweenData, true); -} - -void CCTween::updateHandler() -{ - if (m_fCurrentPercent >= 1) - { - switch(m_eLoopType) - { - case SINGLE_FRAME: - { - m_fCurrentPercent = 1; - m_bIsComplete = true; - } - break; - case ANIMATION_NO_LOOP: - { - m_eLoopType = ANIMATION_MAX; - - - if (m_iDurationTween <= 0) - { - m_fCurrentPercent = 1; - } - else - { - m_fCurrentPercent = (m_fCurrentPercent - 1) * m_iNextFrameIndex / m_iDurationTween; - } - - if (m_fCurrentPercent >= 1) - { - m_fCurrentPercent = 1; - m_bIsComplete = true; - break; - } - else - { - m_iNextFrameIndex = m_iDurationTween; - m_fCurrentFrame = m_fCurrentPercent * m_iNextFrameIndex; - m_iTotalDuration = 0; - m_iBetweenDuration = 0; - m_iToIndex = 0; - break; - } - } - break; - case ANIMATION_TO_LOOP_BACK: - { - m_eLoopType = ANIMATION_LOOP_BACK; - - m_iNextFrameIndex = m_iDurationTween > 0 ? m_iDurationTween : 1; - - if (m_pMovementBoneData->delay != 0) - { - // - m_fCurrentFrame = (1 - m_pMovementBoneData->delay) * (float)m_iNextFrameIndex; - m_fCurrentPercent = m_fCurrentFrame / m_iNextFrameIndex; - } - else - { - m_fCurrentPercent = 0; - m_fCurrentFrame = 0; - } - - m_iTotalDuration = 0; - m_iBetweenDuration = 0; - m_iToIndex = 0; - } - break; - case ANIMATION_MAX: - { - m_fCurrentPercent = 1; - m_bIsComplete = true; - } - break; - default: - { - m_fCurrentPercent = fmodf(m_fCurrentPercent, 1); - m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); - - m_iTotalDuration = 0; - m_iBetweenDuration = 0; - m_iToIndex = 0; - } - break; - } - } - - if (m_fCurrentPercent < 1 && m_eLoopType <= ANIMATION_TO_LOOP_BACK) - { - m_fCurrentPercent = sin(m_fCurrentPercent * CC_HALF_PI); - } - - float percent = m_fCurrentPercent; - - if (m_eLoopType > ANIMATION_TO_LOOP_BACK) - { - percent = updateFrameData(percent); - } - - if(m_eFrameTweenEasing != TWEEN_EASING_MAX) - { - tweenNodeTo(percent); - } -} - -void CCTween::setBetween(CCFrameData *from, CCFrameData *to) -{ - do - { - if(from->displayIndex < 0 && to->displayIndex >= 0) - { - m_pFrom->copy(to); - m_pBetween->subtract(to, to); - break; - } - else if(to->displayIndex < 0 && from->displayIndex >= 0) - { - m_pFrom->copy(from); - m_pBetween->subtract(to, to); - break; - } - - m_pFrom->copy(from); - m_pBetween->subtract(from, to); - } - while (0); - - arriveKeyFrame(from); -} - - -void CCTween::arriveKeyFrame(CCFrameData *keyFrameData) -{ - if(keyFrameData) - { - //! Change bone's display - int displayIndex = keyFrameData->displayIndex; - - if (!m_pBone->getDisplayManager()->getForceChangeDisplay()) - { - m_pBone->getDisplayManager()->changeDisplayByIndex(displayIndex, false); - } - - //! 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->strMovement.length() != 0) - { - childAramture->getAnimation()->play(keyFrameData->strMovement.c_str()); - } - } - - if(keyFrameData->strEvent.length() != 0) - { - m_pAnimation->FrameEventSignal.emit(m_pBone, keyFrameData->strEvent.c_str()); - } - } -} - - -CCFrameData *CCTween::tweenNodeTo(float percent, CCFrameData *node) -{ - node = node == NULL ? m_pTweenData : node; - - node->x = m_pFrom->x + percent * m_pBetween->x; - node->y = m_pFrom->y + percent * m_pBetween->y; - node->scaleX = m_pFrom->scaleX + percent * m_pBetween->scaleX; - node->scaleY = m_pFrom->scaleY + percent * m_pBetween->scaleY; - node->skewX = m_pFrom->skewX + percent * m_pBetween->skewX; - node->skewY = m_pFrom->skewY + percent * m_pBetween->skewY; - - m_pBone->setTransformDirty(true); - - tweenColorTo(percent, node, m_pBetween->isUseColorInfo); - - return node; -} - -void CCTween::tweenColorTo(float percent, CCFrameData *node, bool dirty) -{ - if(node && dirty) - { - node->a = m_pFrom->a + percent * m_pBetween->a; - node->r = m_pFrom->r + percent * m_pBetween->r; - node->g = m_pFrom->g + percent * m_pBetween->g; - node->b = m_pFrom->b + percent * m_pBetween->b; - m_pBone->updateColor(); - } -} - -float CCTween::updateFrameData(float currentPrecent) -{ - if (currentPrecent > 1) - { - currentPrecent = fmodf(currentPrecent,1); - } - - float playedTime = (float)m_iRawDuration * currentPrecent; - - - //! If play to current frame's front or back, then find current frame again - 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; - - do - { - from = frames[m_iFromIndex]; - to = frames[m_iToIndex]; - - m_iTotalDuration = from->frameID; - m_iFromIndex = m_iToIndex; - - if (++m_iToIndex >= length) - { - m_iToIndex = 0; - } - - if (playedTime == from->frameID) - { - break; - } - } - while (playedTime < from->frameID || playedTime>=to->frameID); - - m_iBetweenDuration = to->frameID - from->frameID; - - isListEnd = m_eLoopType == ANIMATION_MAX && m_iToIndex == 0; - - if(isListEnd) - { - to = from = frames[m_iFromIndex]; - } - - m_eFrameTweenEasing = from->tweenEasing; - - setBetween(from, to); - - } - currentPrecent = m_iBetweenDuration == 0 ? 0 : (playedTime - m_iTotalDuration) / (float)m_iBetweenDuration; - - - /* - * If frame tween easing equal to TWEEN_EASING_MAX, then it will not do tween. - */ - - CCTweenType tweenType; - - if ( m_eFrameTweenEasing != TWEEN_EASING_MAX) - { - tweenType = (m_eTweenEasing == TWEEN_EASING_MAX) ? m_eFrameTweenEasing : m_eTweenEasing; - if (tweenType != TWEEN_EASING_MAX) - { - currentPrecent = CCTweenFunction::tweenTo(0, 1, currentPrecent, 1, tweenType); - } - } - - return currentPrecent; -} - -NS_CC_EXT_END diff --git a/extensions/CCArmature/animation/CCTween.h b/extensions/CCArmature/animation/CCTween.h deleted file mode 100644 index 4aade7c626..0000000000 --- a/extensions/CCArmature/animation/CCTween.h +++ /dev/null @@ -1,146 +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 __CCTWEEN_H__ -#define __CCTWEEN_H__ - -#include "CCProcessBase.h" -#include "../utils/CCTweenFunction.h" - -NS_CC_EXT_BEGIN - -class CCBone; -class CCArmatureAnimation; - -class CCTween : public CCProcessBase -{ -public: - /** - * Create with a CCBone - * @param bone the CCBone CCTween will bind to - */ - static CCTween *create(CCBone *bone); -public: - CCTween(void); - virtual ~CCTween(void); - - /** - * Init with a CCBone - * @param bone the CCBone CCTween will bind to - */ - virtual bool init(CCBone *bone); - - /** - * Start the Process - * - * @param movementBoneData the CCMovementBoneData include all frame datas - * @param durationTo the frames between two animation changing-over. - * It's meaning is changing to this animation need how many frames - * - * -1 : use the value from CCMovementData get from flash design panel - * @param durationTween the frame count you want to play in the game. - * if _durationTween is 80, then the animation will played 80 frames in a loop - * - * -1 : use the value from CCMovementData get from flash design panel - * - * @param loop whether the animation is loop - * - * loop < 0 : use the value from CCMovementData get from flash design panel - * loop = 0 : this animation is not loop - * loop > 0 : this animation is loop - * - * @param tweenEasing tween easing is used for calculate easing effect - * - * TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel - * -1 : fade out - * 0 : line - * 1 : fade in - * 2 : fade in and out - * - */ - virtual void play(CCMovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing); - - inline void setAnimation(CCArmatureAnimation *animation) { m_pAnimation = animation; } - inline CCArmatureAnimation *getAnimation() const { return m_pAnimation; } -protected: - - /** - * Update(float dt) will call this handler, you can handle your logic here - */ - virtual void updateHandler(); - - /** - * Calculate which frame arrived, and if current frame have event, then call the event listener - */ - virtual float updateFrameData(float currentPrecent); - - /** - * Calculate the between value of _from and _to, and give it to between frame data - */ - virtual void setBetween(CCFrameData *from, CCFrameData *to); - - /** - * According to the percent to calculate current CCFrameData with tween effect - */ - virtual CCFrameData *tweenNodeTo(float percent, CCFrameData *node = NULL); - - /** - * According to the percent to calculate current color with tween effect - */ - virtual void tweenColorTo(float percent, CCFrameData *node = NULL, bool dirty = false); - - /** - * Update display index and process the key frame event when arrived a key frame - */ - virtual void arriveKeyFrame(CCFrameData *keyFrameData); -protected: - //! A weak reference to the current CCMovementBoneData. The data is in the data pool - CC_SYNTHESIZE(CCMovementBoneData *, m_pMovementBoneData, MovementBoneData) - - CCFrameData *m_pTweenData; //! The computational tween frame data, //! A weak reference to the CCBone's tweenData - CCFrameData *m_pFrom; //! From frame data, used for calculate between value - CCFrameData *m_pTo; //! To frame data, used for calculate between value - CCFrameData *m_pBetween; //! Between frame data, used for calculate current CCFrameData(m_pNode) value - - - CCBone *m_pBone; //! A weak reference to the CCBone - - CCTweenType m_eFrameTweenEasing; //! Dedermine which tween effect current frame use - - int m_iBetweenDuration; //! Current key frame will last m_iBetweenDuration frames - int m_iTotalDuration; - - - int m_iFromIndex; //! The current frame index in FrameList of CCMovementBoneData, it's different from m_iFrameIndex - 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 - -#endif /*__CCTWEEN_H__*/ diff --git a/extensions/CCArmature/datas/CCDatas.cpp b/extensions/CCArmature/datas/CCDatas.cpp deleted file mode 100644 index 358a68e226..0000000000 --- a/extensions/CCArmature/datas/CCDatas.cpp +++ /dev/null @@ -1,445 +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 "CCDatas.h" -#include "../utils/CCUtilMath.h" -#include "../utils/CCTransformHelp.h" - -NS_CC_EXT_BEGIN - - -CCBaseData::CCBaseData() - : x(0.0f) - , y(0.0f) - , zOrder(0) - - , skewX(0.0f) - , skewY(0.0f) - , scaleX(1.0f) - , scaleY(1.0f) - - , tweenRotate(0.0f) - - , isUseColorInfo(false) - , a(255) - , r(255) - , g(255) - , b(255) -{ -} - -CCBaseData::~CCBaseData() -{ -} - -void CCBaseData::copy(const CCBaseData *node ) -{ - x = node->x; - y = node->y; - zOrder = node->zOrder; - - scaleX = node->scaleX; - scaleY = node->scaleY; - skewX = node->skewX; - skewY = node->skewY; - - tweenRotate = node->tweenRotate; - - isUseColorInfo = node->isUseColorInfo; - r = node->r; - g = node->g; - b = node->b; - a = node->a; -} - - -void CCBaseData::subtract(CCBaseData *from, CCBaseData *to) -{ - x = to->x - from->x; - y = to->y - from->y; - scaleX = to->scaleX - from->scaleX; - scaleY = to->scaleY - from->scaleY; - skewX = to->skewX - from->skewX; - skewY = to->skewY - from->skewY; - - if(from->isUseColorInfo || to->isUseColorInfo) - { - a = to->a - from->a; - r = to->r - from->r; - g = to->g - from->g; - b = to->b - from->b; - - isUseColorInfo = true; - } - else - { - a = r = g = b = 0; - isUseColorInfo = false; - } - - if (skewX > M_PI) - { - skewX -= (float)CC_DOUBLE_PI; - } - if (skewX < -M_PI) - { - skewX += (float)CC_DOUBLE_PI; - } - - if (skewY > M_PI) - { - skewY -= (float)CC_DOUBLE_PI; - } - if (skewY < -M_PI) - { - skewY += (float)CC_DOUBLE_PI; - } - - if (to->tweenRotate) - { - skewX += to->tweenRotate; - skewY -= to->tweenRotate; - } -} - -void CCBaseData::setColor(ccColor4B &color) -{ - r = color.r; - g = color.g; - b = color.b; - a = color.a; -} - -ccColor4B CCBaseData::getColor() -{ - return ccc4(r, g, b, a); -} - -const char *CCDisplayData::changeDisplayToTexture(const char *displayName) -{ - // remove .xxx - std::string textureName = displayName; - size_t startPos = textureName.find_last_of("."); - - if(startPos != std::string::npos) - { - textureName = textureName.erase(startPos); - } - - return textureName.c_str(); -} - -CCDisplayData::CCDisplayData(void) - : displayType(CS_DISPLAY_SPRITE) -{ -} - -CCDisplayData::~CCDisplayData(void) -{ -} - -CCSpriteDisplayData::CCSpriteDisplayData(void) - : displayName("") -{ - displayType = CS_DISPLAY_SPRITE; -} - -CCSpriteDisplayData::~CCSpriteDisplayData() -{ -} - -void CCSpriteDisplayData::copy(CCSpriteDisplayData *displayData) -{ - displayName = displayData->displayName; - displayType = displayData->displayType; - - skinData = displayData->skinData; -} - -CCArmatureDisplayData::CCArmatureDisplayData(void) - : displayName("") -{ - displayType = CS_DISPLAY_ARMATURE; -} - -CCArmatureDisplayData::~CCArmatureDisplayData() -{ -} - -void CCArmatureDisplayData::copy(CCArmatureDisplayData *displayData) -{ - displayName = displayData->displayName; - displayType = displayData->displayType; -} - -CCParticleDisplayData::CCParticleDisplayData(void) - : plist("") -{ - displayType = CS_DISPLAY_PARTICLE; -} - -void CCParticleDisplayData::copy(CCParticleDisplayData *displayData) -{ - plist = displayData->plist; - displayType = displayData->displayType; -} - -CCShaderDisplayData::CCShaderDisplayData(void) - : vert("") - , frag("") -{ - displayType = CS_DISPLAY_SHADER; -} - -void CCShaderDisplayData::copy(CCShaderDisplayData *displayData) -{ - vert = displayData->vert; - frag = displayData->frag; - displayType = displayData->displayType; -} - - -CCBoneData::CCBoneData(void) - : name("") - , parentName("") -{ -} - -CCBoneData::~CCBoneData(void) -{ -} - -bool CCBoneData::init() -{ - displayDataList.init(); - return true; -} - -void CCBoneData::addDisplayData(CCDisplayData *displayData) -{ - displayDataList.addObject(displayData); -} - -CCDisplayData *CCBoneData::getDisplayData(int index) -{ - return (CCDisplayData *)displayDataList.objectAtIndex(index); -} -void CCBoneData::updateBoneDataTransform() -{ - CCTransformHelp::nodeToMatrix(*this, boneDataTransform); -} - - -CCArmatureData::CCArmatureData() - :dataVersion(0.1f) -{ -} - -CCArmatureData::~CCArmatureData() -{ -} - -bool CCArmatureData::init() -{ - return true; -} - -void CCArmatureData::addBoneData(CCBoneData *boneData) -{ - boneDataDic.setObject(boneData, boneData->name); -} - -CCBoneData *CCArmatureData::getBoneData(const char *boneName) -{ - return (CCBoneData *)boneDataDic.objectForKey(boneName); -} - -CCFrameData::CCFrameData(void) - : frameID(0) - , duration(1) - , tweenEasing(Linear) - , displayIndex(0) - - , strMovement("") - , strEvent("") - , strSound("") - , strSoundEffect("") -{ -} - -CCFrameData::~CCFrameData(void) -{ -} - -void CCFrameData::copy(CCFrameData *frameData) -{ - CCBaseData::copy(frameData); - - duration = frameData->duration; - displayIndex = frameData->displayIndex; - tweenEasing = frameData->tweenEasing; -} - -CCMovementBoneData::CCMovementBoneData() - : delay(0.0f) - , scale(1.0f) - , duration(0) - , name("") -{ -} - -CCMovementBoneData::~CCMovementBoneData(void) -{ -} - -bool CCMovementBoneData::init() -{ - return frameList.init(); -} - -void CCMovementBoneData::addFrameData(CCFrameData *frameData) -{ - frameList.addObject(frameData); -} - -CCFrameData *CCMovementBoneData::getFrameData(int index) -{ - return (CCFrameData *)frameList.objectAtIndex(index); -} - - - -CCMovementData::CCMovementData(void) - : name("") - , duration(0) - , durationTo(0) - , durationTween(0) - , loop(true) - , tweenEasing(Linear) -{ -} - -CCMovementData::~CCMovementData(void) -{ -} - -void CCMovementData::addMovementBoneData(CCMovementBoneData *movBoneData) -{ - movBoneDataDic.setObject(movBoneData, movBoneData->name); -} - -CCMovementBoneData *CCMovementData::getMovementBoneData(const char *boneName) -{ - return (CCMovementBoneData *)movBoneDataDic.objectForKey(boneName); -} - - - -CCAnimationData::CCAnimationData(void) -{ -} - -CCAnimationData::~CCAnimationData(void) -{ -} - -void CCAnimationData::release() -{ - CCObject::release(); -} - -void CCAnimationData::retain() -{ - CCObject::retain(); -} - -void CCAnimationData::addMovement(CCMovementData *movData) -{ - movementDataDic.setObject(movData, movData->name); - movementNames.push_back(movData->name); -} - -CCMovementData *CCAnimationData::getMovement(const char *movementName) -{ - return (CCMovementData *)movementDataDic.objectForKey(movementName); -} - -int CCAnimationData::getMovementCount() -{ - return movementDataDic.count(); -} - - - -CCContourData::CCContourData() -{ -} - -CCContourData::~CCContourData() -{ -} - -bool CCContourData::init() -{ - return vertexList.init(); -} - -void CCContourData::addVertex(CCPoint *vertex) -{ - CCContourVertex2 *vertex2 = new CCContourVertex2(vertex->x, vertex->y); - vertex2->autorelease(); - - vertexList.addObject(vertex2); -} - -CCTextureData::CCTextureData() - : height(0.0f) - , width(0.0f) - , pivotX(0.5f) - , pivotY(0.5f) - , name("") -{ -} - -CCTextureData::~CCTextureData() -{ -} - -bool CCTextureData::init() -{ - return contourDataList.init(); -} - -void CCTextureData::addContourData(CCContourData *contourData) -{ - contourDataList.addObject(contourData); -} - -CCContourData *CCTextureData::getContourData(int index) -{ - return (CCContourData *)contourDataList.objectAtIndex(index); -} - - -NS_CC_EXT_END diff --git a/extensions/CCArmature/datas/CCDatas.h b/extensions/CCArmature/datas/CCDatas.h deleted file mode 100644 index b7ea23d1df..0000000000 --- a/extensions/CCArmature/datas/CCDatas.h +++ /dev/null @@ -1,467 +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 __CCARMATURE_DATAS_H__ -#define __CCARMATURE_DATAS_H__ - -#include "../utils/CCArmatureDefine.h" -#include "../utils/CCTweenFunction.h" - - -#define CS_CREATE_NO_PARAM_NO_INIT(varType)\ -public: \ - static inline varType *create(void){ \ - varType *var = new varType();\ - if (var)\ -{\ - var->autorelease();\ - return var;\ -}\ - CC_SAFE_DELETE(var);\ - return NULL;\ -} - -#define CS_CREATE_NO_PARAM(varType)\ -public: \ - static inline varType *create(void){ \ - varType *var = new varType();\ - if (var && var->init())\ -{\ - var->autorelease();\ - return var;\ -}\ - CC_SAFE_DELETE(var);\ - return NULL;\ -} - -NS_CC_EXT_BEGIN - -/** -* the base node include a lot of attribute. -*/ -class CCBaseData : public CCObject -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(CCBaseData) -public: - CCBaseData(); - ~CCBaseData(void); - - /* - * Copy datas from node - * @param node A CCBaseData to copy datas - */ - virtual void copy(const CCBaseData *_node); - - /* - * Calculate two CCBaseData's between value(_to - _from) and set to self - * - * @param from from CCBaseData - * @param to to CCBaseData - */ - virtual void subtract(CCBaseData *_from, CCBaseData *_to); - - virtual void setColor(ccColor4B &color); - virtual ccColor4B getColor(); -public: - float x; //! position x attribute - float y; //! position y attribute - int zOrder; //! zorder attribute, used to order the CCBone's depth order - - /** - * x y skewX skewY scaleX scaleY used to calculate transform matrix - * skewX, skewY can have rotation effect - * To get more matrix information, you can have a look at this pape : http://www.senocular.com/flash/tutorials/transformmatrix/ - */ - float skewX; - float skewY; - float scaleX; - float scaleY; - - float tweenRotate; //! SkewX, SkewY, and TweenRotate effect the rotation - - bool isUseColorInfo; //! Whether or not this frame have the color changed Info - int a, r, g, b; - -}; - - -/** -* DisplayType distinguish which type you display is. -*/ -enum DisplayType -{ - CS_DISPLAY_SPRITE, //! display is a single CCSprite - CS_DISPLAY_ARMATURE, //! display is a CCArmature - CS_DISPLAY_PARTICLE, //! display is a CCParticle. - CS_DISPLAY_SHADER, //! display is a shader - - CS_DISPLAY_MAX -}; - -class CCDisplayData : public CCObject -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(CCDisplayData) - - static const char *changeDisplayToTexture(const char *); -public: - CCDisplayData(); - virtual ~CCDisplayData(void); - - DisplayType displayType; //! mark which type your display is -}; - - - -class CCSpriteDisplayData : public CCDisplayData -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(CCSpriteDisplayData) -public: - CCSpriteDisplayData(); - virtual ~CCSpriteDisplayData(); - - inline void setParam(const char *displayName) - { - this->displayName = displayName; - } - void copy(CCSpriteDisplayData *displayData); -public: - /** - * If DisplayType is CS_DISPLAY_SPRITE, then CCBone will use this image name to create a CCSprite from CCSpriteFrameCache. - * It should note that when use this name to create CCSprite from CCSpriteFrameCache, you should use m_strDisplayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". - * - * If DisplayType is CS_DISPLAY_ARMATURE, the name is the CCArmature's name. When CCBone init display and type is CS_DISPLAY_ARMATURE, - * then CCBone will create a CCArmature. - */ - std::string displayName; - - CCBaseData skinData; -}; - - -class CCArmatureDisplayData : public CCDisplayData -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(CCArmatureDisplayData) -public: - CCArmatureDisplayData(); - virtual ~CCArmatureDisplayData(); - - inline void setParam(const char *displayName) - { - this->displayName = displayName; - } - void copy(CCArmatureDisplayData *displayData); -public: - /** - * If DisplayType is CS_DISPLAY_SPRITE, then CCBone will use this image name to create a CCSprite from CCSpriteFrameCache. - * It should note that when use this name to create CCSprite from CCSpriteFrameCache, you should use m_strDisplayName + ".png", because when use Texture Packer to pack single image file, the name have ".png". - * - * If DisplayType is CS_DISPLAY_ARMATURE, the name is the CCArmature's name. When CCBone init display and type is CS_DISPLAY_ARMATURE, - * then CCBone will create a CCArmature. - */ - std::string displayName; - -}; - - -class CCParticleDisplayData : public CCDisplayData -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(CCParticleDisplayData) -public: - CCParticleDisplayData(); - virtual ~CCParticleDisplayData() {}; - - void setParam(const char *plist) - { - this->plist = plist; - } - - void copy(CCParticleDisplayData *displayData); -public: - std::string plist; -}; - - -class CCShaderDisplayData : public CCDisplayData -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(CCShaderDisplayData) -public: - CCShaderDisplayData(); - virtual ~CCShaderDisplayData() {}; - - inline void setParam(const char *vert, const char *frag) - { - this->vert = vert; - this->frag = frag; - } - - void copy(CCShaderDisplayData *displayData); -public: - std::string vert; - std::string frag; -}; - - -/** -* CCBoneData used to init a CCBone. -* CCBoneData keeps a CCDisplayData list, a CCBone can have many display to change. -* The display information saved in the CCDisplayData -*/ -class CCBoneData : public CCBaseData -{ -public: - CS_CREATE_NO_PARAM(CCBoneData) -public: - CCBoneData(void); - ~CCBoneData(void); - - virtual bool init(); - - 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; -}; - - -/** -* CCArmatureData saved the CCArmature name and Bonedatas needed for the Bones in this CCArmature -* When we create a CCArmature, we need to get each CCBone's CCBoneData as it's init information. -* So we can get a CCBoneData from the CCDictionary saved in the CCArmatureData. -*/ -class CCArmatureData : public CCObject -{ -public: - CS_CREATE_NO_PARAM(CCArmatureData) -public: - CCArmatureData(); - ~CCArmatureData(); - - bool init(); - void addBoneData(CCBoneData *boneData); - CCBoneData *getBoneData(const char *boneName); -public: - std::string name; - CCDictionary boneDataDic; - float dataVersion; -}; - - -class CCFrameData : public CCBaseData -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(CCFrameData) -public: - CCFrameData(); - ~CCFrameData(); - - virtual void copy(CCFrameData *frameData); -public: - int frameID; - int duration; //! The frame will last m_iDuration frames - CCTweenType tweenEasing; //! Every frame's tween easing effect - - /** - * The current display index when change to this frame. - * If value is -1, then display will not show. - */ - int displayIndex; - - /** - * m_strMovement, m_strEvent, m_strSound, m_strSoundEffect do not support yet - */ - std::string strMovement; - std::string strEvent; - std::string strSound; - std::string strSoundEffect; -}; - - -class CCMovementBoneData : public CCObject -{ -public: - CS_CREATE_NO_PARAM(CCMovementBoneData) -public: - CCMovementBoneData(); - ~CCMovementBoneData(void); - - virtual bool init(); - - void addFrameData(CCFrameData *frameData); - CCFrameData *getFrameData(int index); -public: - float delay; //! movement delay percent, this value can produce a delay effect - float scale; //! scale this movement - float duration; //! this CCBone in this movement will last m_iDuration frames - std::string name; //! bone name - - CCArray frameList; -}; - - -class CCMovementData : public CCObject -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(CCMovementData) -public: - CCMovementData(void); - ~CCMovementData(void); - - void addMovementBoneData(CCMovementBoneData *movBoneData); - CCMovementBoneData *getMovementBoneData(const char *boneName); -public: - std::string name; - int duration; //! the frames this movement will last - - /** - * Change to this movement will last m_iDurationTo frames. Use this effect can avoid too suddenly changing. - * - * Example : current movement is "stand", we want to change to "run", then we fill m_iDurationTo frames before - * change to "run" instead of changing to "run" directly. - */ - int durationTo; - - /* - * This is different from m_iDuration, m_iDurationTween contain tween effect. - * - * Example : If we edit 10 frames in the flash, then m_iDuration is 10. When we set m_iDurationTween to 50, the movement will last 50 frames, the extra 40 frames will auto filled with tween effect - */ - int durationTween; - - bool loop; //! whether the movement is looped - - /** - * Which tween easing effect the movement use - * TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel - */ - CCTweenType tweenEasing; - - /** - * @brief save movment bone datas - * @key std::string - * @value CCMovementBoneData * - */ - CCDictionary movBoneDataDic; -}; - - -/** -* CCAnimationData include all movement infomation for the CCArmature -* The struct is CCAnimationData -> CCMovementData -> CCMovementBoneData -> CCFrameData -* -> MovementFrameData -*/ -class CCAnimationData : public CCObject -{ -public: - CS_CREATE_NO_PARAM_NO_INIT(CCAnimationData) -public: - CCAnimationData(void); - ~CCAnimationData(void); - - void release(); - void retain(); - - void addMovement(CCMovementData *movData); - CCMovementData *getMovement(const char *movementName); - int getMovementCount(); -public: - std::string name; - CCDictionary movementDataDic; - std::vector movementNames; -}; - - -struct CCContourVertex2 : public CCObject -{ - CCContourVertex2(float x, float y) - { - this->x = x; - this->y = y; - } - - float x; - float y; -}; - -/* -* CCContourData include a contour vertex information -*/ -class CCContourData : public CCObject -{ -public: - CS_CREATE_NO_PARAM(CCContourData) -public: - CCContourData(); - ~CCContourData(void); - - virtual bool init(); - virtual void addVertex(CCPoint *vertex); -public: - CCArray vertexList; //! Save contour vertex info, vertex saved in a CCPoint -}; - - - - -/* -* CCTextureData include a texture's information -*/ -class CCTextureData : public CCObject -{ -public: - CS_CREATE_NO_PARAM(CCTextureData) -public: - CCTextureData(); - ~CCTextureData(void); - - virtual bool init(); - - void addContourData(CCContourData *contourData); - CCContourData *getContourData(int index); -public: - - float height; //! The texture's width, height - float width; - - float pivotX; //! The texture's anchor point - float pivotY; - - std::string name; //! The texture's name - - CCArray contourDataList; -}; - - -NS_CC_EXT_END - -#endif /*__CCARMATURE_DATAS_H__*/ diff --git a/extensions/CCArmature/display/CCDecorativeDisplay.cpp b/extensions/CCArmature/display/CCDecorativeDisplay.cpp deleted file mode 100644 index d58f1a713c..0000000000 --- a/extensions/CCArmature/display/CCDecorativeDisplay.cpp +++ /dev/null @@ -1,68 +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 "CCDecorativeDisplay.h" -#include "../utils/CCConstValue.h" - -NS_CC_EXT_BEGIN - -CCDecorativeDisplay *CCDecorativeDisplay::create() -{ - CCDecorativeDisplay *pDisplay = new CCDecorativeDisplay(); - if (pDisplay && pDisplay->init()) - { - pDisplay->autorelease(); - return pDisplay; - } - CC_SAFE_DELETE(pDisplay); - return NULL; -} - -CCDecorativeDisplay::CCDecorativeDisplay() - : m_pDisplay(NULL) - , m_pDisplayData(NULL) - -{ -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - m_pColliderDetector = NULL; -#endif -} - - -CCDecorativeDisplay::~CCDecorativeDisplay(void) -{ - CC_SAFE_RELEASE_NULL(m_pDisplayData); - CC_SAFE_RELEASE_NULL(m_pDisplay); - -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_SAFE_RELEASE_NULL(m_pColliderDetector); -#endif -} - -bool CCDecorativeDisplay::init() -{ - return true; -} - -NS_CC_EXT_END diff --git a/extensions/CCArmature/display/CCDecorativeDisplay.h b/extensions/CCArmature/display/CCDecorativeDisplay.h deleted file mode 100644 index b8b486f01e..0000000000 --- a/extensions/CCArmature/display/CCDecorativeDisplay.h +++ /dev/null @@ -1,61 +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 __CCDECORATIVEDISPLAY_H__ -#define __CCDECORATIVEDISPLAY_H__ - -#include "../utils/CCArmatureDefine.h" -#include "CCDisplayFactory.h" -#include "../datas/CCDatas.h" - - -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT -#include "../physics/CCColliderDetector.h" -#endif - -NS_CC_EXT_BEGIN - -class CCDecorativeDisplay: public CCObject -{ -public: - static CCDecorativeDisplay *create(); -public: - CCDecorativeDisplay(void); - ~CCDecorativeDisplay(void); - - virtual bool init(); - -protected: - - CC_SYNTHESIZE_RETAIN(CCNode *, m_pDisplay, Display); - CC_SYNTHESIZE_RETAIN(CCDisplayData *, m_pDisplayData, DisplayData); - -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_SYNTHESIZE_RETAIN(CCColliderDetector *, m_pColliderDetector, ColliderDetector); -#endif -}; - -NS_CC_EXT_END - -#endif /*__CCDECORATIVEDISPLAY_H__*/ diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp deleted file mode 100644 index 530830b80e..0000000000 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ /dev/null @@ -1,253 +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 "CCDisplayFactory.h" -#include "../CCBone.h" -#include "../CCArmature.h" -#include "../display/CCSkin.h" -#include "../utils/CCSpriteFrameCacheHelper.h" -#include "../utils/CCArmatureDataManager.h" -#include "../utils/CCTransformHelp.h" - -NS_CC_EXT_BEGIN - -void CCDisplayFactory::addDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) -{ - switch(displayData->displayType) - { - case CS_DISPLAY_SPRITE: - addSpriteDisplay(bone, decoDisplay, displayData); - break; - case CS_DISPLAY_PARTICLE: - addParticleDisplay(bone, decoDisplay, displayData); - break; - case CS_DISPLAY_ARMATURE: - addArmatureDisplay(bone, decoDisplay, displayData); - break; - default: - break; - } -} - -void CCDisplayFactory::createDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) -{ - switch(decoDisplay->getDisplayData()->displayType) - { - case CS_DISPLAY_SPRITE: - createSpriteDisplay(bone, decoDisplay); - break; - case CS_DISPLAY_PARTICLE: - createParticleDisplay(bone, decoDisplay); - break; - case CS_DISPLAY_ARMATURE: - createArmatureDisplay(bone, decoDisplay); - break; - default: - break; - } -} - -void CCDisplayFactory::updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty) -{ - CS_RETURN_IF(!decoDisplay); - -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - if (dirty) - { - CCColliderDetector *detector = decoDisplay->getColliderDetector(); - if (detector) - { - CCNode *node = decoDisplay->getDisplay(); - CCAffineTransform displayTransform = node->nodeToParentTransform(); - CCPoint anchorPoint = node->getAnchorPointInPoints(); - anchorPoint = CCPointApplyAffineTransform(anchorPoint, displayTransform); - displayTransform.tx = anchorPoint.x; - displayTransform.ty = anchorPoint.y; - CCAffineTransform t = CCAffineTransformConcat(displayTransform, bone->getArmature()->nodeToWorldTransform()); - detector->updateTransform(t); - } - } -#endif - - CCNode *display = decoDisplay->getDisplay(); - - if (dynamic_cast(display) != NULL) - { - updateSpriteDisplay(bone, display, dt, dirty); - } - else if (dynamic_cast(display) != NULL) - { - updateParticleDisplay(bone, display, dt, dirty); - } - else if (dynamic_cast(display) != NULL) - { - updateArmatureDisplay(bone, display, dt, dirty); - } -} - - - -void CCDisplayFactory::addSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) -{ - CCSpriteDisplayData *sdp = CCSpriteDisplayData::create(); - sdp->copy((CCSpriteDisplayData *)displayData); - decoDisplay->setDisplayData(sdp); - createSpriteDisplay(bone, decoDisplay); -} - -void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) -{ - CCSkin *skin = NULL; - - CCSpriteDisplayData *displayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData(); - - //! remove .xxx - std::string textureName = displayData->displayName; - size_t startPos = textureName.find_last_of("."); - - if(startPos != std::string::npos) - { - textureName = textureName.erase(startPos); - } - - //! create display - if(textureName.length() == 0) - { - skin = CCSkin::create(); - } - else - { - skin = CCSkin::createWithSpriteFrameName((textureName + ".png").c_str()); - } - - CCTextureAtlas *atlas = CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTextureAtlasWithDisplayName((textureName + ".png").c_str()); - skin->setTextureAtlas(atlas); - - CCTextureData *textureData = CCArmatureDataManager::sharedArmatureDataManager()->getTextureData(textureName.c_str()); - if(textureData) - { - //! Init display anchorPoint, every Texture have a anchor point - skin->setAnchorPoint(ccp( textureData->pivotX, textureData->pivotY)); - } - - skin->setBone(bone); - - CCArmature *armature = bone->getArmature(); - if (armature) - { - if (armature->getArmatureData()->dataVersion >= VERSION_COMBINED) - { - skin->setSkinData(displayData->skinData); - } - else - { - skin->setSkinData(*bone->getBoneData()); - } - } - - decoDisplay->setDisplay(skin); - -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - if (textureData && textureData->contourDataList.count() > 0) - { - - //! create ContourSprite - CCColliderDetector *colliderDetector = CCColliderDetector::create(bone); - colliderDetector->addContourDataList(&textureData->contourDataList); - - decoDisplay->setColliderDetector(colliderDetector); - } -#endif -} - -void CCDisplayFactory::updateSpriteDisplay(CCBone *bone, CCNode *display, float dt, bool dirty) -{ - CCSkin *skin = (CCSkin *)display; - skin->updateArmatureTransform(); -} - - -void CCDisplayFactory::addArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) -{ - CCArmatureDisplayData *adp = CCArmatureDisplayData::create(); ; - adp->copy((CCArmatureDisplayData *)displayData); - decoDisplay->setDisplayData(adp); - - createArmatureDisplay(bone, decoDisplay); -} -void CCDisplayFactory::createArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) -{ - CCArmatureDisplayData *displayData = (CCArmatureDisplayData *)decoDisplay->getDisplayData(); - - CCArmature *armature = CCArmature::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 - * CCArmature's bone children. - */ - armature->setName((bone->getName() + "_armatureChild").c_str()); - - decoDisplay->setDisplay(armature); -} -void CCDisplayFactory::updateArmatureDisplay(CCBone *bone, CCNode *display, float dt, bool dirty) -{ - CS_RETURN_IF(!dirty); - - CCArmature *armature = (CCArmature*)display; - if(armature) - { - armature->sortAllChildren(); - armature->update(dt); - } -} - - - -void CCDisplayFactory::addParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData) -{ - CCParticleDisplayData *adp = CCParticleDisplayData::create(); ; - adp->copy((CCParticleDisplayData *)displayData); - decoDisplay->setDisplayData(adp); - - createParticleDisplay(bone, decoDisplay); -} -void CCDisplayFactory::createParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) -{ - CCParticleDisplayData *displayData = (CCParticleDisplayData *)decoDisplay->getDisplayData(); - CCParticleSystem *system = CCParticleSystemQuad::create(displayData->plist.c_str()); - decoDisplay->setDisplay(system); -} -void CCDisplayFactory::updateParticleDisplay(CCBone *bone, CCNode *display, float dt, bool dirty) -{ - CCParticleSystem *system = (CCParticleSystem *)display; - CCBaseData node; - CCTransformHelp::matrixToNode(bone->nodeToArmatureTransform(), node); - system->setPosition(node.x, node.y); - system->setScaleX(node.scaleX); - system->setScaleY(node.scaleY); - system->update(dt); -} - - -NS_CC_EXT_END diff --git a/extensions/CCArmature/display/CCDisplayFactory.h b/extensions/CCArmature/display/CCDisplayFactory.h deleted file mode 100644 index 7e9c244ca8..0000000000 --- a/extensions/CCArmature/display/CCDisplayFactory.h +++ /dev/null @@ -1,61 +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 __CCDISPLAYFACTORY_H__ -#define __CCDISPLAYFACTORY_H__ - -#include "../utils/CCArmatureDefine.h" -#include "../datas/CCDatas.h" - -NS_CC_EXT_BEGIN - -class CCSkin; -class CCBone; -class CCDecorativeDisplay; -class CCDisplayData; - -class CCDisplayFactory -{ -public: - static void addDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); - static void createDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty); - - static void addSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); - static void createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateSpriteDisplay(CCBone *bone, CCNode *display, float dt, bool dirty); - - static void addArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); - static void createArmatureDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateArmatureDisplay(CCBone *bone, CCNode *display, float dt, bool dirty); - - static void addParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, CCDisplayData *displayData); - static void createParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay); - static void updateParticleDisplay(CCBone *bone, CCNode *display, float dt, bool dirty); -}; - - -NS_CC_EXT_END - -#endif /*__CCDISPLAYFACTORY_H__*/ diff --git a/extensions/CCArmature/display/CCDisplayManager.cpp b/extensions/CCArmature/display/CCDisplayManager.cpp deleted file mode 100644 index d39d8e7b68..0000000000 --- a/extensions/CCArmature/display/CCDisplayManager.cpp +++ /dev/null @@ -1,353 +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_BEGIN - -CCDisplayManager *CCDisplayManager::create(CCBone *bone) -{ - CCDisplayManager *pDisplayManager = new CCDisplayManager(); - if (pDisplayManager && pDisplayManager->init(bone)) - { - pDisplayManager->autorelease(); - return pDisplayManager; - } - CC_SAFE_DELETE(pDisplayManager); - return NULL; -} - - -CCDisplayManager::CCDisplayManager() - : m_pDecoDisplayList(NULL) - , m_pDisplayRenderNode(NULL) - , m_pCurrentDecoDisplay(NULL) - , m_iDisplayIndex(-1) - , m_bForceChangeDisplay(false) - , m_bVisible(true) - , m_pBone(NULL) -{ -} - -CCDisplayManager::~CCDisplayManager() -{ - CC_SAFE_DELETE(m_pDecoDisplayList); - - if( m_pDisplayRenderNode ) - { - m_pDisplayRenderNode->removeFromParentAndCleanup(true); - if(m_pDisplayRenderNode->retainCount() > 0) - CC_SAFE_RELEASE_NULL(m_pDisplayRenderNode); - } - -} - -bool CCDisplayManager::init(CCBone *bone) -{ - bool ret = false; - - do - { - - m_pBone = bone; - - initDisplayList(bone->getBoneData()); - - ret = true; - } - while (0); - - return ret; -} - - -void CCDisplayManager::addDisplay(CCDisplayData *displayData, int index) -{ - CCDecorativeDisplay *decoDisplay = NULL; - - if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) - { - decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->objectAtIndex(index); - } - else - { - decoDisplay = CCDecorativeDisplay::create(); - m_pDecoDisplayList->addObject(decoDisplay); - } - - CCDisplayFactory::addDisplay(m_pBone, decoDisplay, displayData); - - //! if changed display index is current display index, then change current display to the new display - if(index == m_iDisplayIndex) - { - m_iDisplayIndex = -1; - changeDisplayByIndex(index, false); - } -} - -void CCDisplayManager::addDisplay(CCNode *display, int index) -{ - CCDecorativeDisplay *decoDisplay = NULL; - - if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) - { - decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->objectAtIndex(index); - } - else - { - decoDisplay = CCDecorativeDisplay::create(); - m_pDecoDisplayList->addObject(decoDisplay); - } - - /*CCDisplayFactory::addDisplay(m_pBone, decoDisplay, displayData);*/ - decoDisplay->setDisplay(display); - - //! if changed display index is current display index, then change current display to the new display - if(index == m_iDisplayIndex) - { - m_iDisplayIndex = -1; - changeDisplayByIndex(index, false); - } -} - -void CCDisplayManager::removeDisplay(int index) -{ - m_pDecoDisplayList->removeObjectAtIndex(index); - - if(index == m_iDisplayIndex) - { - setCurrentDecorativeDisplay(NULL); - } -} - -CCArray *CCDisplayManager::getDecorativeDisplayList() -{ - return m_pDecoDisplayList; -} - -void CCDisplayManager::changeDisplayByIndex(int index, bool force) -{ - CCAssert( (m_pDecoDisplayList ? index < (int)m_pDecoDisplayList->count() : true), "the _index value is out of range"); - - m_bForceChangeDisplay = force; - - //! If index is equal to current display index,then do nothing - if ( m_iDisplayIndex == index) - return; - - - m_iDisplayIndex = index; - - //! If displayIndex < 0, it means you want to hide you display - if (m_iDisplayIndex < 0) - { - if(m_pDisplayRenderNode) - { - m_pDisplayRenderNode->removeFromParentAndCleanup(true); - setCurrentDecorativeDisplay(NULL); - } - return; - } - - - CCDecorativeDisplay *decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->objectAtIndex(m_iDisplayIndex); - - setCurrentDecorativeDisplay(decoDisplay); -} - -void CCDisplayManager::setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisplay) -{ -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - if (m_pCurrentDecoDisplay && m_pCurrentDecoDisplay->getColliderDetector()) - { - m_pCurrentDecoDisplay->getColliderDetector()->setActive(false); - } -#endif - - m_pCurrentDecoDisplay = decoDisplay; - -#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT - if (m_pCurrentDecoDisplay && m_pCurrentDecoDisplay->getColliderDetector()) - { - m_pCurrentDecoDisplay->getColliderDetector()->setActive(true); - } -#endif - - CCNode *displayRenderNode = m_pCurrentDecoDisplay == NULL ? NULL : m_pCurrentDecoDisplay->getDisplay(); - if (m_pDisplayRenderNode) - { - if (dynamic_cast(m_pDisplayRenderNode) != NULL) - { - m_pBone->setChildArmature(NULL); - } - - m_pDisplayRenderNode->removeFromParentAndCleanup(true); - m_pDisplayRenderNode->release(); - } - - m_pDisplayRenderNode = displayRenderNode; - - if(m_pDisplayRenderNode) - { - if (dynamic_cast(m_pDisplayRenderNode) != NULL) - { - m_pBone->setChildArmature((CCArmature *)m_pDisplayRenderNode); - } - m_pDisplayRenderNode->retain(); - m_pDisplayRenderNode->setVisible(m_bVisible); - } -} - -CCNode *CCDisplayManager::getDisplayRenderNode() -{ - return m_pDisplayRenderNode; -} - -int CCDisplayManager::getCurrentDisplayIndex() -{ - return m_iDisplayIndex; -} - -CCDecorativeDisplay *CCDisplayManager::getCurrentDecorativeDisplay() -{ - return m_pCurrentDecoDisplay; -} - -CCDecorativeDisplay *CCDisplayManager::getDecorativeDisplayByIndex( int index) -{ - return (CCDecorativeDisplay *)m_pDecoDisplayList->objectAtIndex(index); -} - -void CCDisplayManager::initDisplayList(CCBoneData *boneData) -{ - CC_SAFE_DELETE(m_pDecoDisplayList); - m_pDecoDisplayList = CCArray::create(); - m_pDecoDisplayList->retain(); - - CS_RETURN_IF(!boneData); - - CCObject *object = NULL; - CCArray *displayDataList = &boneData->displayDataList; - CCARRAY_FOREACH(displayDataList, object) - { - CCDisplayData *displayData = (CCDisplayData *)object; - - CCDecorativeDisplay *decoDisplay = CCDecorativeDisplay::create(); - decoDisplay->setDisplayData(displayData); - - CCDisplayFactory::createDisplay(m_pBone, decoDisplay); - - m_pDecoDisplayList->addObject(decoDisplay); - } -} - - -bool CCDisplayManager::containPoint(CCPoint &point) -{ - if(!m_bVisible || m_iDisplayIndex < 0) - { - return false; - } - - bool ret = false; - - switch (m_pCurrentDecoDisplay->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. - * - */ - - CCPoint outPoint = ccp(0, 0); - - CCSprite *sprite = (CCSprite *)m_pCurrentDecoDisplay->getDisplay(); - sprite = (CCSprite *)sprite->getChildByTag(0); - - ret = CC_SPRITE_CONTAIN_POINT_WITH_RETURN(sprite, point, outPoint); - - } - break; - - default: - break; - } - return ret; -} - -bool CCDisplayManager::containPoint(float x, float y) -{ - CCPoint p = ccp(x, y); - return containPoint(p); -} - - -void CCDisplayManager::setVisible(bool visible) -{ - if(!m_pDisplayRenderNode) - return; - - m_bVisible = visible; - m_pDisplayRenderNode->setVisible(visible); -} - -bool CCDisplayManager::isVisible() -{ - return m_bVisible; -} - - -CCSize CCDisplayManager::getContentSize() -{ - CS_RETURN_IF(!m_pDisplayRenderNode) CCSizeMake(0, 0); - return m_pDisplayRenderNode->getContentSize(); -} - -CCRect CCDisplayManager::getBoundingBox() -{ - CS_RETURN_IF(!m_pDisplayRenderNode) CCRectMake(0, 0, 0, 0); - return m_pDisplayRenderNode->boundingBox(); -} - - -CCPoint CCDisplayManager::getAnchorPoint() -{ - CS_RETURN_IF(!m_pDisplayRenderNode) ccp(0, 0); - return m_pDisplayRenderNode->getAnchorPoint(); -} - -CCPoint CCDisplayManager::getAnchorPointInPoints() -{ - CS_RETURN_IF(!m_pDisplayRenderNode) ccp(0, 0); - return m_pDisplayRenderNode->getAnchorPointInPoints(); -} - - -NS_CC_EXT_END diff --git a/extensions/CCArmature/display/CCDisplayManager.h b/extensions/CCArmature/display/CCDisplayManager.h deleted file mode 100644 index 15bdfa43a6..0000000000 --- a/extensions/CCArmature/display/CCDisplayManager.h +++ /dev/null @@ -1,144 +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 __CCDISPLAYMANAGER_H__ -#define __CCDISPLAYMANAGER_H__ - -#include "../utils/CCArmatureDefine.h" -#include "../display/CCDecorativeDisplay.h" -#include "../datas/CCDatas.h" - -NS_CC_EXT_BEGIN - -class CCBone; - -//! CCDisplayManager manages CCBone's display -class CCDisplayManager : public CCObject -{ -public: - static CCDisplayManager *create(CCBone *bone); - -public: - CCDisplayManager(); - ~CCDisplayManager(); - - bool init(CCBone *bone); - - /** - * Use CCBoneData to init the display list. - * 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 - */ - virtual void initDisplayList(CCBoneData *boneData); - - /** - * Add display and use _DisplayData 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 CCSpriteDisplayData param - * - * @param index the index of the display you want to replace or add to - * -1 : append display from back - */ - void addDisplay(CCDisplayData *displayData, int index); - - void addDisplay(CCNode *display, int index); - - void removeDisplay(int index); - - CCArray *getDecorativeDisplayList(); - - /** - * Change display by index. You can just use this method to change display in the display list. - * The display list is just used for this bone, and it is the displays you may use in every frame. - * - * Note : if index is the same with prev index, the method will not effect - * - * @param index The index of the display you want to change - * @param force If true, then force change display to specified display, or current display will set to display index edit in the flash every key frame. - */ - void changeDisplayByIndex(int index, bool force); - - - CCNode *getDisplayRenderNode(); - - int getCurrentDisplayIndex(); - - void setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisplay); - CCDecorativeDisplay *getCurrentDecorativeDisplay(); - CCDecorativeDisplay *getDecorativeDisplayByIndex( int index); - - /** - * Sets whether the display is visible - * The default value is true, a node is default to visible - * - * @param visible true if the node is visible, false if the node is hidden. - */ - virtual void setVisible(bool visible); - /** - * Determines if the display is visible - * - * @see setVisible(bool) - * @return true if the node is visible, false if the node is hidden. - */ - virtual bool isVisible(); - - CCSize getContentSize(); - CCRect getBoundingBox(); - - CCPoint getAnchorPoint(); - CCPoint getAnchorPointInPoints(); - - /** - * Check if the position is inside the bone. - */ - virtual bool containPoint(CCPoint &_point); - - /** - * Check if the position is inside the bone. - */ - virtual bool containPoint(float x, float y); - -protected: - CCArray *m_pDecoDisplayList; - //! Display render node. - CCNode *m_pDisplayRenderNode; - //! Include current display information, like contour sprite, etc. - CCDecorativeDisplay *m_pCurrentDecoDisplay; - //! Current display index - int m_iDisplayIndex; - - CC_SYNTHESIZE_PASS_BY_REF(bool, m_bForceChangeDisplay, ForceChangeDisplay) - - //! Whether of not the bone is visible. Default is true - bool m_bVisible; - - CCBone *m_pBone; -}; - -NS_CC_EXT_END - -#endif /*__CCDISPLAYMANAGER_H__*/ diff --git a/extensions/CCArmature/display/CCSkin.cpp b/extensions/CCArmature/display/CCSkin.cpp deleted file mode 100644 index 11c924bac8..0000000000 --- a/extensions/CCArmature/display/CCSkin.cpp +++ /dev/null @@ -1,171 +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 "../CCArmature.h" - -NS_CC_EXT_BEGIN - -#if CC_SPRITEBATCHNODE_RENDER_SUBPIXEL -#define RENDER_IN_SUBPIXEL -#else -#define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__)) -#endif - -CCSkin *CCSkin::create() -{ - CCSkin *skin = new CCSkin(); - if(skin && skin->init()) - { - skin->autorelease(); - return skin; - } - CC_SAFE_DELETE(skin); - return NULL; -} - -CCSkin *CCSkin::createWithSpriteFrameName(const char *pszSpriteFrameName) -{ - CCSkin *skin = new CCSkin(); - if(skin && skin->initWithSpriteFrameName(pszSpriteFrameName)) - { - skin->autorelease(); - return skin; - } - CC_SAFE_DELETE(skin); - return NULL; -} - -CCSkin *CCSkin::create(const char *pszFileName) -{ - CCSkin *skin = new CCSkin(); - if(skin && skin->initWithFile(pszFileName)) - { - skin->autorelease(); - return skin; - } - CC_SAFE_DELETE(skin); - return NULL; -} - -CCSkin::CCSkin() - : m_pBone(NULL) -{ -} - -void CCSkin::setSkinData(const CCBaseData &var) -{ - m_sSkinData = var; - - setScaleX(m_sSkinData.scaleX); - setScaleY(m_sSkinData.scaleY); - setRotation(CC_RADIANS_TO_DEGREES(m_sSkinData.skewX)); - setPosition(ccp(m_sSkinData.x, m_sSkinData.y)); - - m_tSkinTransform = nodeToParentTransform(); -} - -const CCBaseData &CCSkin::getSkinData() -{ - return m_sSkinData; -} - -void CCSkin::updateArmatureTransform() -{ - m_sTransform = CCAffineTransformConcat(m_tSkinTransform, m_pBone->nodeToArmatureTransform()); -} - -void CCSkin::updateTransform() -{ - // If it is not visible, or one of its ancestors is not visible, then do nothing: - if( !m_bVisible) - { - m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = vertex3(0, 0, 0); - } - else - { - // - // calculate the Quad based on the Affine Matrix - // - - CCSize size = m_obRect.size; - - float x1 = m_obOffsetPosition.x; - float y1 = m_obOffsetPosition.y; - - float x2 = x1 + size.width; - float y2 = y1 + size.height; - - float x = m_sTransform.tx; - float y = m_sTransform.ty; - - float cr = m_sTransform.a; - float sr = m_sTransform.b; - float cr2 = m_sTransform.d; - float sr2 = -m_sTransform.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; - - m_sQuad.bl.vertices = vertex3( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), m_fVertexZ ); - m_sQuad.br.vertices = vertex3( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), m_fVertexZ ); - m_sQuad.tl.vertices = vertex3( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), m_fVertexZ ); - m_sQuad.tr.vertices = vertex3( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), m_fVertexZ ); - } - - // MARMALADE CHANGE: ADDED CHECK FOR NULL, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS - if (m_pobTextureAtlas) - { - m_pobTextureAtlas->updateQuad(&m_sQuad, m_pobTextureAtlas->getTotalQuads()); - } -} - -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 deleted file mode 100644 index c2eeb76c2f..0000000000 --- a/extensions/CCArmature/display/CCSkin.h +++ /dev/null @@ -1,57 +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 __CCSKIN_H__ -#define __CCSKIN_H__ - -#include "../utils/CCArmatureDefine.h" -#include "../CCBone.h" - -NS_CC_EXT_BEGIN - -class CCSkin : public CCSprite -{ -public: - static CCSkin *create(); - static CCSkin *createWithSpriteFrameName(const char *pszSpriteFrameName); - static CCSkin *create(const char *pszFileName); -public: - CCSkin(); - - void updateArmatureTransform(); - void updateTransform(); - - CCAffineTransform nodeToWorldTransform(); - CCAffineTransform nodeToWorldTransformAR(); - - CC_PROPERTY_PASS_BY_REF(CCBaseData, m_sSkinData, SkinData); - CC_SYNTHESIZE(CCBone *, m_pBone, Bone); - -protected: - CCAffineTransform m_tSkinTransform; -}; - -NS_CC_EXT_END - -#endif /*__CCSKIN_H__*/ diff --git a/extensions/CCArmature/external_tool/CCTexture2DMutable.cpp b/extensions/CCArmature/external_tool/CCTexture2DMutable.cpp deleted file mode 100644 index 9a41db7fe8..0000000000 --- a/extensions/CCArmature/external_tool/CCTexture2DMutable.cpp +++ /dev/null @@ -1,318 +0,0 @@ -// -// CCTexture2DMutable.cpp -// Ported to C++ by Dmitry Matyukhin -// -// CCMutableTexture.m -// Created by Lam Hoang Pham. -// Improved by Manuel Martinez-Almeida. -// - - -#include "CCTexture2DMutable.h" - - -using namespace cocos2d; - -#if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA -void* CCTexture2DMutable::getOriginalTexData() { - return originalData_; -} -#endif - -void* CCTexture2DMutable::getTexData() { - return data_; -} - -void CCTexture2DMutable::setTexData(void *var) { - data_ = var; -} - - -void CCTexture2DMutable::releaseData(void* data) -{ - //Don't free the data -} - -void* CCTexture2DMutable::keepData(void* data, unsigned int lenght) -{ - void *newData = malloc(lenght); - memmove(newData, data, lenght); - return newData; -} - -bool CCTexture2DMutable::initWithImageFile(const char *imageFile, cocos2d::CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const cocos2d::CCSize& contentSize) -{ - image_ = new cocos2d::CCImage(); - image_->initWithImageFile(imageFile); - - - return initWithData(image_->getData(), pixelFormat, pixelsWide, pixelsHigh, contentSize); -} - -bool CCTexture2DMutable::initWithImageFile(const char *imageFile) -{ - image_ = new cocos2d::CCImage(); - image_->initWithImageFile(imageFile); - - bool hasAlpha = image_->hasAlpha(); - CCSize imageSize = CCSizeMake((float)(image_->getWidth()), (float)(image_->getHeight())); - size_t bpp = image_->getBitsPerComponent(); - cocos2d::CCTexture2DPixelFormat pixelFormat; - - // compute pixel format - if(hasAlpha) - { - pixelFormat = kCCTexture2DPixelFormat_Default; - } - else - { - if (bpp >= 8) - { - pixelFormat = kCCTexture2DPixelFormat_RGB888; - } - else - { - pixelFormat = kCCTexture2DPixelFormat_RGB565; - } - - } - - return initWithData(image_->getData(), pixelFormat, imageSize.width, imageSize.height, imageSize); -} - -bool CCTexture2DMutable::initWithData(const void* data, CCTexture2DPixelFormat pixelFormat, unsigned int width, unsigned int height, const CCSize& size) -{ - if(!CCTexture2D::initWithData(data, pixelFormat, width, height, size)) { - return false; - } - - switch (pixelFormat) { - case kTexture2DPixelFormat_RGBA8888: bytesPerPixel_ = 4; break; - case kTexture2DPixelFormat_A8: bytesPerPixel_ = 1; break; - case kTexture2DPixelFormat_RGBA4444: - case kTexture2DPixelFormat_RGB565: - case kTexture2DPixelFormat_RGB5A1: - bytesPerPixel_ = 2; - break; - default:break; - } - - data_ = (void*) data; - -#if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA - unsigned int max = width * height * bytesPerPixel_; - originalData_ = malloc(max); - memcpy(originalData_, data_, max); -#endif - - return true; -} - -ccColor4B CCTexture2DMutable::pixelAt(const CCPoint& pt) -{ - - ccColor4B c = {0, 0, 0, 0}; - if(!data_) return c; - if(pt.x < 0 || pt.y < 0) return c; - if(pt.x >= m_tContentSize.width || pt.y >= m_tContentSize.height) return c; - - //! 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 - 1 - pt.y; - - if(m_ePixelFormat == kTexture2DPixelFormat_RGBA8888){ - unsigned int *pixel = (unsigned int *)data_; - pixel = pixel + (y * m_uPixelsWide) + x; - c.r = *pixel & 0xff; - c.g = (*pixel >> 8) & 0xff; - c.b = (*pixel >> 16) & 0xff; - c.a = (*pixel >> 24) & 0xff; - } else if(m_ePixelFormat == kTexture2DPixelFormat_RGBA4444){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * m_uPixelsWide) + x; - c.a = ((*pixel & 0xf) << 4) | (*pixel & 0xf); - c.b = (((*pixel >> 4) & 0xf) << 4) | ((*pixel >> 4) & 0xf); - c.g = (((*pixel >> 8) & 0xf) << 4) | ((*pixel >> 8) & 0xf); - c.r = (((*pixel >> 12) & 0xf) << 4) | ((*pixel >> 12) & 0xf); - } else if(m_ePixelFormat == kTexture2DPixelFormat_RGB5A1){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * m_uPixelsWide) + x; - c.r = ((*pixel >> 11) & 0x1f)<<3; - c.g = ((*pixel >> 6) & 0x1f)<<3; - c.b = ((*pixel >> 1) & 0x1f)<<3; - c.a = (*pixel & 0x1)*255; - } else if(m_ePixelFormat == kTexture2DPixelFormat_RGB565){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * m_uPixelsWide) + x; - c.b = (*pixel & 0x1f)<<3; - c.g = ((*pixel >> 5) & 0x3f)<<2; - c.r = ((*pixel >> 11) & 0x1f)<<3; - c.a = 255; - } else if(m_ePixelFormat == kTexture2DPixelFormat_A8){ - GLubyte *pixel = (GLubyte *)data_; - c.a = pixel[(y * m_uPixelsWide) + x]; - // Default white - c.r = 255; - c.g = 255; - c.b = 255; - } - - //CCLog("color : %i, %i, %i, %i", c.r, c.g, c.b, c.a); - - return c; -} - -bool CCTexture2DMutable::setPixelAt(const CCPoint& pt, ccColor4B c) -{ - if(!data_)return false; - if(pt.x < 0 || pt.y < 0) return false; - if(pt.x >= m_tContentSize.width || pt.y >= m_tContentSize.height) return false; - unsigned int x = pt.x, y = pt.y; - - dirty_ = true; - - // Shifted bit placement based on little-endian, let's make this more - // portable =/ - - if(m_ePixelFormat == kTexture2DPixelFormat_RGBA8888){ - unsigned int *pixel = (unsigned int *)data_; - pixel[(y * m_uPixelsWide) + x] = (c.a << 24) | (c.b << 16) | (c.g << 8) | c.r; - } else if(m_ePixelFormat == kTexture2DPixelFormat_RGBA4444){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * m_uPixelsWide) + x; - *pixel = ((c.r >> 4) << 12) | ((c.g >> 4) << 8) | ((c.b >> 4) << 4) | (c.a >> 4); - } else if(m_ePixelFormat == kTexture2DPixelFormat_RGB5A1){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * m_uPixelsWide) + x; - *pixel = ((c.r >> 3) << 11) | ((c.g >> 3) << 6) | ((c.b >> 3) << 1) | (c.a > 0); - } else if(m_ePixelFormat == kTexture2DPixelFormat_RGB565){ - GLushort *pixel = (GLushort *)data_; - pixel = pixel + (y * m_uPixelsWide) + x; - *pixel = ((c.r >> 3) << 11) | ((c.g >> 2) << 5) | (c.b >> 3); - } else if(m_ePixelFormat == kTexture2DPixelFormat_A8){ - GLubyte *pixel = (GLubyte *)data_; - pixel[(y * m_uPixelsWide) + x] = c.a; - } else { - dirty_ = false; - return false; - } - return true; -} - -void CCTexture2DMutable::fill(ccColor4B p) -{ - for(int r = 0; r < m_tContentSize.height; ++r) - for(int c = 0; c < m_tContentSize.width; ++c) - this->setPixelAt(CCPointMake(c, r), p); -} - -CCTexture2D* CCTexture2DMutable::copyMutable(bool isMutable ) -{ - CCTexture2D* co; - if(isMutable) - { - int mem = m_uPixelsWide*m_uPixelsHigh*bytesPerPixel_; - void *newData = malloc(mem); - memcpy(newData, data_, mem); - co = new CCTexture2DMutable(); - if (!co->initWithData(newData, m_ePixelFormat, m_uPixelsWide, m_uPixelsHigh, m_tContentSize)) { - delete co; - co = NULL; - } - }else { - - co = new CCTexture2D(); - if (!co->initWithData(data_, m_ePixelFormat, m_uPixelsWide, m_uPixelsHigh, m_tContentSize)) { - delete co; - co = NULL; - } - } - - return co; -} - -CCTexture2DMutable* CCTexture2DMutable::copy() -{ - return (CCTexture2DMutable*)this->copyMutable( true ); -} - -void CCTexture2DMutable::copy(CCTexture2DMutable* textureToCopy, const CCPoint& offset) -{ - for(int r = 0; r < m_tContentSize.height;++r){ - for(int c = 0; c < m_tContentSize.width; ++c){ - setPixelAt(CCPointMake(c + offset.x, r + offset.y), textureToCopy->pixelAt(CCPointMake(c, r))); - } - } -} - -void CCTexture2DMutable::restore() -{ -#if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA - memcpy(data_, originalData_, bytesPerPixel_*m_uPixelsWide*m_uPixelsHigh); - this->apply(); -#else - //You should set CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA 1 in CCTexture2DMutable.h - CCAssert(false, "Exception: CCMutableTexture.restore was disabled by the user."); -#endif -} - -void CCTexture2DMutable::apply() -{ - if(!data_) return; - - glBindTexture(GL_TEXTURE_2D, m_uName); - - switch(m_ePixelFormat) - { - case kTexture2DPixelFormat_RGBA8888: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_uPixelsWide, m_uPixelsHigh, 0, GL_RGBA, GL_UNSIGNED_BYTE, data_); - break; - case kTexture2DPixelFormat_RGBA4444: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_uPixelsWide, m_uPixelsHigh, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, data_); - break; - case kTexture2DPixelFormat_RGB5A1: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_uPixelsWide, m_uPixelsHigh, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, data_); - break; - case kTexture2DPixelFormat_RGB565: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_uPixelsWide, m_uPixelsHigh, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data_); - break; - case kTexture2DPixelFormat_A8: - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, m_uPixelsWide, m_uPixelsHigh, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data_); - break; - default: - CCAssert(false, "NSInternalInconsistencyException"); - - } - glBindTexture(GL_TEXTURE_2D, 0); - dirty_ = false; -} - -void *CCTexture2DMutable::getData() -{ - return data_; -} - -CCTexture2DMutable::CCTexture2DMutable(void) -{ - image_ = NULL; -} - -CCTexture2DMutable::~CCTexture2DMutable(void) -{ - CCLOGINFO("cocos2d: deallocing %p", this); - - if (image_) - { - CC_SAFE_DELETE(image_); - } - else - { - 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 deleted file mode 100644 index c1b6cea44a..0000000000 --- a/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.cpp +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright (c) 2012 Chukong Technologies, Inc. - * - * http://www.cocostudio.com - * http://tools.cocoachina.com - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the - * following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include -#include "CSContentJsonDictionary.h" - -namespace cs { - - CSJsonDictionary::CSJsonDictionary() - { - m_cValue.clear(); - } - - - CSJsonDictionary::~CSJsonDictionary() - { - m_cValue.clear(); - } - - - void CSJsonDictionary::initWithDescription(const char *pszDescription) - { - CSJson::Reader cReader; - m_cValue.clear(); - if (pszDescription && *pszDescription) - { - std::string strValue = pszDescription; - cReader.parse(strValue, m_cValue, false); - } - } - - - void CSJsonDictionary::initWithValue(CSJson::Value& value) - { - m_cValue = value; - } - - - void CSJsonDictionary::insertItem(const char *pszKey, int nValue) - { - m_cValue[pszKey] = nValue; - } - - - void CSJsonDictionary::insertItem(const char *pszKey, double fValue) - { - m_cValue[pszKey] = fValue; - } - - - void CSJsonDictionary::insertItem(const char *pszKey, const char * pszValue) - { - m_cValue[pszKey] = pszValue; - } - - void CSJsonDictionary::insertItem(const char *pszKey, bool bValue) - { - m_cValue[pszKey] = bValue; - } - - void CSJsonDictionary::insertItem(const char *pszKey, CSJsonDictionary * subDictionary) - { - if (subDictionary) - m_cValue[pszKey] = subDictionary->m_cValue; - } - - - bool CSJsonDictionary::deleteItem(const char *pszKey) - { - if(!m_cValue.isMember(pszKey)) - return false; - - m_cValue.removeMember(pszKey); - - return true; - } - - - void CSJsonDictionary::cleanUp() - { - m_cValue.clear(); - } - - - bool CSJsonDictionary::isKeyValidate(const char *pszKey) - { - return m_cValue.isMember(pszKey); - } - - - int CSJsonDictionary::getItemIntValue(const char *pszKey, int nDefaultValue) - { - if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isNumeric()) - return nDefaultValue; - - return m_cValue[pszKey].asInt(); - } - - - double CSJsonDictionary::getItemFloatValue(const char *pszKey, double fDefaultValue) - { - if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isNumeric()) - return fDefaultValue; - - return m_cValue[pszKey].asDouble(); - } - - - const char * CSJsonDictionary::getItemStringValue(const char *pszKey) - { - if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isString()) - return NULL; - - return m_cValue[pszKey].asCString(); - } - - bool CSJsonDictionary::getItemBoolvalue(const char *pszKey, bool bDefaultValue) - { - if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isBool()) - return bDefaultValue; - - return m_cValue[pszKey].asBool(); - } - - - CSJsonDictionary * CSJsonDictionary::getSubDictionary(const char *pszKey) - { - CSJsonDictionary * pNewDictionary; - if (!isKeyValidate(pszKey, m_cValue) || (!m_cValue[pszKey].isArray() && - !m_cValue[pszKey].isObject() && - !m_cValue[pszKey].isConvertibleTo(CSJson::arrayValue) && - !m_cValue[pszKey].isConvertibleTo(CSJson::objectValue))) - { - pNewDictionary = NULL; - } - else - { - pNewDictionary = new CSJsonDictionary(); - pNewDictionary->initWithValue(m_cValue[pszKey]); - } - return pNewDictionary; - } - - - std::string CSJsonDictionary::getDescription() - { - std::string strReturn = m_cValue.toStyledString(); - return strReturn; - } - - - bool CSJsonDictionary::insertItemToArray(const char *pszArrayKey, int nValue) - { - CSJson::Value array; - if(m_cValue.isMember(pszArrayKey)) - { - if (!m_cValue[pszArrayKey].isArray() && !m_cValue[pszArrayKey].isConvertibleTo(CSJson::arrayValue)) - return false; - - array = m_cValue[pszArrayKey]; - } - - array.append(nValue); - m_cValue[pszArrayKey] = array; - - return true; - } - - - bool CSJsonDictionary::insertItemToArray(const char *pszArrayKey, double fValue) - { - CSJson::Value array; - if(m_cValue.isMember(pszArrayKey)) - { - if (!m_cValue[pszArrayKey].isArray() && !m_cValue[pszArrayKey].isConvertibleTo(CSJson::arrayValue)) - return false; - - array = m_cValue[pszArrayKey]; - } - - array.append(fValue); - m_cValue[pszArrayKey] = array; - - return true; - } - - - bool CSJsonDictionary::insertItemToArray(const char *pszArrayKey, const char * pszValue) - { - CSJson::Value array; - if(m_cValue.isMember(pszArrayKey)) - { - if (!m_cValue[pszArrayKey].isArray() && !m_cValue[pszArrayKey].isConvertibleTo(CSJson::arrayValue)) - return false; - - array = m_cValue[pszArrayKey]; - } - - array.append(pszValue); - m_cValue[pszArrayKey] = array; - - return true; - } - - - bool CSJsonDictionary::insertItemToArray(const char *pszArrayKey, CSJsonDictionary * subDictionary) - { - CSJson::Value array; - if(m_cValue.isMember(pszArrayKey)) - { - if (!m_cValue[pszArrayKey].isArray() && !m_cValue[pszArrayKey].isConvertibleTo(CSJson::arrayValue)) - return false; - - array = m_cValue[pszArrayKey]; - } - - array.append(subDictionary->m_cValue); - m_cValue[pszArrayKey] = array; - - return true; - } - - - int CSJsonDictionary::getItemCount() - { - return m_cValue.size(); - } - - - DicItemType CSJsonDictionary::getItemType(int nIndex) - { - return (DicItemType)m_cValue[nIndex].type(); - } - - - DicItemType CSJsonDictionary::getItemType(const char *pszKey) - { - return (DicItemType)m_cValue[pszKey].type(); - } - - std::vector CSJsonDictionary::getAllMemberNames() - { - return m_cValue.getMemberNames(); - } - - - int CSJsonDictionary::getArrayItemCount(const char *pszArrayKey) - { - int nRet = 0; - if (!isKeyValidate(pszArrayKey, m_cValue) || - (!m_cValue[pszArrayKey].isArray() && !m_cValue[pszArrayKey].isObject() && - !m_cValue[pszArrayKey].isConvertibleTo(CSJson::arrayValue) && !m_cValue[pszArrayKey].isConvertibleTo(CSJson::objectValue))) - { - nRet = 0; - } - else - { - CSJson::Value arrayValue = m_cValue[pszArrayKey]; - nRet = arrayValue.size(); - } - - return nRet; - } - - - int CSJsonDictionary::getIntValueFromArray(const char *pszArrayKey, int nIndex, int nDefaultValue) - { - int nRet = nDefaultValue; - CSJson::Value * arrayValue = validateArrayItem(pszArrayKey, nIndex); - if (arrayValue) - { - if ((*arrayValue)[nIndex].isNumeric()) - nRet = (*arrayValue)[nIndex].asInt(); - } - - return nRet; - } - - - double CSJsonDictionary::getFloatValueFromArray(const char *pszArrayKey, int nIndex, double fDefaultValue) - { - double fRet = fDefaultValue; - CSJson::Value * arrayValue = validateArrayItem(pszArrayKey, nIndex); - if (arrayValue) - { - if ((*arrayValue)[nIndex].isNumeric()) - fRet = (*arrayValue)[nIndex].asDouble(); - } - - 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) - { - CSJson::Value * arrayValue = validateArrayItem(pszArrayKey, nIndex); - if (arrayValue) - { - if ((*arrayValue)[nIndex].isString()) - return (*arrayValue)[nIndex].asCString(); - } - - return NULL; - } - - - CSJsonDictionary * CSJsonDictionary::getSubItemFromArray(const char *pszArrayKey, int nIndex) - { - CSJson::Value * arrayValue = validateArrayItem(pszArrayKey, nIndex); - if (arrayValue) - { - if ((*arrayValue)[nIndex].isArray() || (*arrayValue)[nIndex].isObject()) - { - CSJsonDictionary * pNewDictionary = new CSJsonDictionary(); - pNewDictionary->initWithValue((*arrayValue)[nIndex]); - return pNewDictionary; - } - } - - return NULL; - } - - - DicItemType CSJsonDictionary::getItemTypeFromArray(const char *pszArrayKey, int nIndex) - { - CSJson::Value * arrayValue = validateArrayItem(pszArrayKey, nIndex); - if (arrayValue) - return (DicItemType)((*arrayValue)[nIndex].type()); - - return (DicItemType)CSJson::nullValue; - } - - - inline bool CSJsonDictionary::isKeyValidate(const char *pszKey, CSJson::Value& root) - { - if (root.isNull() || !root.isMember(pszKey)) - return false; - - return true; - } - - - inline CSJson::Value * CSJsonDictionary::validateArrayItem(const char *pszArrayKey, int nIndex) - { - if (!isKeyValidate(pszArrayKey, m_cValue) && !m_cValue[pszArrayKey].isArray() && !m_cValue[pszArrayKey].isConvertibleTo(CSJson::arrayValue)) - return NULL; - if (!m_cValue[pszArrayKey].isValidIndex(nIndex)) - return NULL; - - return &m_cValue[pszArrayKey]; - } -} diff --git a/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.h b/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.h deleted file mode 100644 index 4054b14f61..0000000000 --- a/extensions/CCArmature/external_tool/Json/CSContentJsonDictionary.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2012 Chukong Technologies, Inc. - * - * http://www.cocostudio.com - * http://tools.cocoachina.com - * - * 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 COCOSTUDIO_CSCONTENTJSONDICTIONARY_H -#define COCOSTUDIO_CSCONTENTJSONDICTIONARY_H - - -#include "lib_json/json_lib.h" -#include -#include - -namespace cs { - - typedef enum _DicItemType - { - EDIC_TYPENULL = 0, - EDIC_TYPEINT, - EDIC_TYPEUINT, - EDIC_TYPEFLOAT, - EDIC_TYPESTRING, - EDIC_TYPEBOOLEN, - EDIC_TYPEARRAY, - EDIC_TYPEOBJECT - }DicItemType; - - class CSJsonDictionary - { - public: - CSJsonDictionary(); - ~CSJsonDictionary(); - - public: - void initWithDescription(const char *pszDescription); - void insertItem(const char *pszKey, int nValue); - void insertItem(const char *pszKey, double fValue); - void insertItem(const char *pszKey, const char * pszValue); - void insertItem(const char *pszKey, CSJsonDictionary * subDictionary); - void insertItem(const char *pszKey, bool bValue); - bool deleteItem(const char *pszKey); - void cleanUp(); - bool isKeyValidate(const char *pszKey); - - int getItemIntValue(const char *pszKey, int nDefaultValue); - double getItemFloatValue(const char *pszKey, double fDefaultValue); - const char * getItemStringValue(const char *pszKey); - bool getItemBoolvalue(const char *pszKey, bool bDefaultValue); - CSJsonDictionary * getSubDictionary(const char *pszKey); - - std::string getDescription(); - - bool insertItemToArray(const char *pszArrayKey, int nValue); - bool insertItemToArray(const char *pszArrayKey, double fValue); - bool insertItemToArray(const char *pszArrayKey, const char * pszValue); - bool insertItemToArray(const char *pszArrayKey, CSJsonDictionary * subDictionary); - - 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); - - int getItemCount(); - DicItemType getItemType(int nIndex); - DicItemType getItemType(const char *pszKey); - std::vector getAllMemberNames(); - - protected: - CSJson::Value m_cValue; - - private: - void initWithValue(CSJson::Value& value); - inline bool isKeyValidate(const char *pszKey, CSJson::Value& root); - inline CSJson::Value * validateArrayItem(const char *pszArrayKey, int nIndex); - }; - -} - -#endif diff --git a/extensions/CCArmature/external_tool/Json/lib_json/json_reader.cpp b/extensions/CCArmature/external_tool/Json/lib_json/json_reader.cpp deleted file mode 100644 index 5d336cf2a7..0000000000 --- a/extensions/CCArmature/external_tool/Json/lib_json/json_reader.cpp +++ /dev/null @@ -1,882 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#if !defined(JSON_IS_AMALGAMATION) -# include "reader.h" -# include "value.h" -# include "json_tool.h" -#endif // if !defined(JSON_IS_AMALGAMATION) -#include -#include -#include -#include -#include -#include -#include -#include - -#if _MSC_VER >= 1400 // VC++ 8.0 -#pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. -#endif - -namespace CSJson { - -// Implementation of class Features -// //////////////////////////////// - -Features::Features() - : allowComments_( true ) - , strictRoot_( false ) -{ -} - - -Features -Features::all() -{ - return Features(); -} - - -Features -Features::strictMode() -{ - Features features; - features.allowComments_ = false; - features.strictRoot_ = true; - return features; -} - -// Implementation of class Reader -// //////////////////////////////// - - -static inline bool -in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4 ) -{ - return c == c1 || c == c2 || c == c3 || c == c4; -} - -static inline bool -in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4, Reader::Char c5 ) -{ - return c == c1 || c == c2 || c == c3 || c == c4 || c == c5; -} - - -static bool -containsNewLine( Reader::Location begin, - Reader::Location end ) -{ - for ( ;begin < end; ++begin ) - if ( *begin == '\n' || *begin == '\r' ) - return true; - return false; -} - - -// Class Reader -// ////////////////////////////////////////////////////////////////// - -Reader::Reader() - : features_( Features::all() ) -{ -} - - -Reader::Reader( const Features &features ) - : features_( features ) -{ -} - - -bool -Reader::parse( const std::string &document, - Value &root, - bool collectComments ) -{ - document_ = document; - const char *begin = document_.c_str(); - const char *end = begin + document_.length(); - return parse( begin, end, root, collectComments ); -} - - -bool -Reader::parse( std::istream& sin, - Value &root, - bool collectComments ) -{ - //std::istream_iterator begin(sin); - //std::istream_iterator end; - // Those would allow streamed input from a file, if parse() were a - // template function. - - // Since std::string is reference-counted, this at least does not - // create an extra copy. - std::string doc; - std::getline(sin, doc, (char)EOF); - return parse( doc, root, collectComments ); -} - -bool -Reader::parse( const char *beginDoc, const char *endDoc, - Value &root, - bool collectComments ) -{ - if ( !features_.allowComments_ ) - { - collectComments = false; - } - - begin_ = beginDoc; - end_ = endDoc; - collectComments_ = collectComments; - current_ = begin_; - lastValueEnd_ = 0; - lastValue_ = 0; - commentsBefore_ = ""; - errors_.clear(); - while ( !nodes_.empty() ) - nodes_.pop(); - nodes_.push( &root ); - - bool successful = readValue(); - Token token; - skipCommentTokens( token ); - if ( collectComments_ && !commentsBefore_.empty() ) - root.setComment( commentsBefore_, commentAfter ); - if ( features_.strictRoot_ ) - { - if ( !root.isArray() && !root.isObject() ) - { - // Set error location to start of doc, ideally should be first token found in doc - token.type_ = tokenError; - token.start_ = beginDoc; - token.end_ = endDoc; - addError( "A valid JSON document must be either an array or an object value.", - token ); - return false; - } - } - return successful; -} - - -bool -Reader::readValue() -{ - Token token; - skipCommentTokens( token ); - bool successful = true; - - if ( collectComments_ && !commentsBefore_.empty() ) - { - currentValue().setComment( commentsBefore_, commentBefore ); - commentsBefore_ = ""; - } - - - switch ( token.type_ ) - { - case tokenObjectBegin: - successful = readObject( token ); - break; - case tokenArrayBegin: - successful = readArray( token ); - break; - case tokenNumber: - successful = decodeNumber( token ); - break; - case tokenString: - successful = decodeString( token ); - break; - case tokenTrue: - currentValue() = true; - break; - case tokenFalse: - currentValue() = false; - break; - case tokenNull: - currentValue() = Value(); - break; - default: - return addError( "Syntax error: value, object or array expected.", token ); - } - - if ( collectComments_ ) - { - lastValueEnd_ = current_; - lastValue_ = ¤tValue(); - } - - return successful; -} - - -void -Reader::skipCommentTokens( Token &token ) -{ - if ( features_.allowComments_ ) - { - do - { - readToken( token ); - } - while ( token.type_ == tokenComment ); - } - else - { - readToken( token ); - } -} - - -bool -Reader::expectToken( TokenType type, Token &token, const char *message ) -{ - readToken( token ); - if ( token.type_ != type ) - return addError( message, token ); - return true; -} - - -bool -Reader::readToken( Token &token ) -{ - skipSpaces(); - token.start_ = current_; - Char c = getNextChar(); - bool ok = true; - switch ( c ) - { - case '{': - token.type_ = tokenObjectBegin; - break; - case '}': - token.type_ = tokenObjectEnd; - break; - case '[': - token.type_ = tokenArrayBegin; - break; - case ']': - token.type_ = tokenArrayEnd; - break; - case '"': - token.type_ = tokenString; - ok = readString(); - break; - case '/': - token.type_ = tokenComment; - ok = readComment(); - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '-': - token.type_ = tokenNumber; - readNumber(); - break; - case 't': - token.type_ = tokenTrue; - ok = match( "rue", 3 ); - break; - case 'f': - token.type_ = tokenFalse; - ok = match( "alse", 4 ); - break; - case 'n': - token.type_ = tokenNull; - ok = match( "ull", 3 ); - break; - case ',': - token.type_ = tokenArraySeparator; - break; - case ':': - token.type_ = tokenMemberSeparator; - break; - case 0: - token.type_ = tokenEndOfStream; - break; - default: - ok = false; - break; - } - if ( !ok ) - token.type_ = tokenError; - token.end_ = current_; - return true; -} - - -void -Reader::skipSpaces() -{ - while ( current_ != end_ ) - { - Char c = *current_; - if ( c == ' ' || c == '\t' || c == '\r' || c == '\n' ) - ++current_; - else - break; - } -} - - -bool -Reader::match( Location pattern, - int patternLength ) -{ - if ( end_ - current_ < patternLength ) - return false; - int index = patternLength; - while ( index-- ) - if ( current_[index] != pattern[index] ) - return false; - current_ += patternLength; - return true; -} - - -bool -Reader::readComment() -{ - Location commentBegin = current_ - 1; - Char c = getNextChar(); - bool successful = false; - if ( c == '*' ) - successful = readCStyleComment(); - else if ( c == '/' ) - successful = readCppStyleComment(); - if ( !successful ) - return false; - - if ( collectComments_ ) - { - CommentPlacement placement = commentBefore; - if ( lastValueEnd_ && !containsNewLine( lastValueEnd_, commentBegin ) ) - { - if ( c != '*' || !containsNewLine( commentBegin, current_ ) ) - placement = commentAfterOnSameLine; - } - - addComment( commentBegin, current_, placement ); - } - return true; -} - - -void -Reader::addComment( Location begin, - Location end, - CommentPlacement placement ) -{ - assert( collectComments_ ); - if ( placement == commentAfterOnSameLine ) - { - assert( lastValue_ != 0 ); - lastValue_->setComment( std::string( begin, end ), placement ); - } - else - { - if ( !commentsBefore_.empty() ) - commentsBefore_ += "\n"; - commentsBefore_ += std::string( begin, end ); - } -} - - -bool -Reader::readCStyleComment() -{ - while ( current_ != end_ ) - { - Char c = getNextChar(); - if ( c == '*' && *current_ == '/' ) - break; - } - return getNextChar() == '/'; -} - - -bool -Reader::readCppStyleComment() -{ - while ( current_ != end_ ) - { - Char c = getNextChar(); - if ( c == '\r' || c == '\n' ) - break; - } - return true; -} - - -void -Reader::readNumber() -{ - while ( current_ != end_ ) - { - if ( !(*current_ >= '0' && *current_ <= '9') && - !in( *current_, '.', 'e', 'E', '+', '-' ) ) - break; - ++current_; - } -} - -bool -Reader::readString() -{ - Char c = 0; - while ( current_ != end_ ) - { - c = getNextChar(); - if ( c == '\\' ) - getNextChar(); - else if ( c == '"' ) - break; - } - return c == '"'; -} - - -bool -Reader::readObject( Token &/*tokenStart*/ ) -{ - Token tokenName; - std::string name; - currentValue() = Value( objectValue ); - while ( readToken( tokenName ) ) - { - bool initialTokenOk = true; - while ( tokenName.type_ == tokenComment && initialTokenOk ) - initialTokenOk = readToken( tokenName ); - if ( !initialTokenOk ) - break; - if ( tokenName.type_ == tokenObjectEnd && name.empty() ) // empty object - return true; - if ( tokenName.type_ != tokenString ) - break; - - name = ""; - if ( !decodeString( tokenName, name ) ) - return recoverFromError( tokenObjectEnd ); - - Token colon; - if ( !readToken( colon ) || colon.type_ != tokenMemberSeparator ) - { - return addErrorAndRecover( "Missing ':' after object member name", - colon, - tokenObjectEnd ); - } - Value &value = currentValue()[ name ]; - nodes_.push( &value ); - bool ok = readValue(); - nodes_.pop(); - if ( !ok ) // error already set - return recoverFromError( tokenObjectEnd ); - - Token comma; - if ( !readToken( comma ) - || ( comma.type_ != tokenObjectEnd && - comma.type_ != tokenArraySeparator && - comma.type_ != tokenComment ) ) - { - return addErrorAndRecover( "Missing ',' or '}' in object declaration", - comma, - tokenObjectEnd ); - } - bool finalizeTokenOk = true; - while ( comma.type_ == tokenComment && - finalizeTokenOk ) - finalizeTokenOk = readToken( comma ); - if ( comma.type_ == tokenObjectEnd ) - return true; - } - return addErrorAndRecover( "Missing '}' or object member name", - tokenName, - tokenObjectEnd ); -} - - -bool -Reader::readArray( Token &/*tokenStart*/ ) -{ - currentValue() = Value( arrayValue ); - skipSpaces(); - if ( *current_ == ']' ) // empty array - { - Token endArray; - readToken( endArray ); - return true; - } - int index = 0; - for (;;) - { - Value &value = currentValue()[ index++ ]; - nodes_.push( &value ); - bool ok = readValue(); - nodes_.pop(); - if ( !ok ) // error already set - return recoverFromError( tokenArrayEnd ); - - Token token; - // Accept Comment after last item in the array. - ok = readToken( token ); - while ( token.type_ == tokenComment && ok ) - { - ok = readToken( token ); - } - bool badTokenType = ( token.type_ != tokenArraySeparator && - token.type_ != tokenArrayEnd ); - if ( !ok || badTokenType ) - { - return addErrorAndRecover( "Missing ',' or ']' in array declaration", - token, - tokenArrayEnd ); - } - if ( token.type_ == tokenArrayEnd ) - break; - } - return true; -} - - -bool -Reader::decodeNumber( Token &token ) -{ - bool isDouble = false; - for ( Location inspect = token.start_; inspect != token.end_; ++inspect ) - { - isDouble = isDouble - || in( *inspect, '.', 'e', 'E', '+' ) - || ( *inspect == '-' && inspect != token.start_ ); - } - if ( isDouble ) - return decodeDouble( token ); - // Attempts to parse the number as an integer. If the number is - // larger than the maximum supported value of an integer then - // we decode the number as a double. - Location current = token.start_; - bool isNegative = *current == '-'; - if ( isNegative ) - ++current; - Value::LargestUInt maxIntegerValue = isNegative ? Value::LargestUInt(-Value::minLargestInt) - : Value::maxLargestUInt; - Value::LargestUInt threshold = maxIntegerValue / 10; - Value::UInt lastDigitThreshold = Value::UInt( maxIntegerValue % 10 ); - assert( lastDigitThreshold >=0 && lastDigitThreshold <= 9 ); - Value::LargestUInt value = 0; - while ( current < token.end_ ) - { - Char c = *current++; - if ( c < '0' || c > '9' ) - return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); - Value::UInt digit(c - '0'); - if ( value >= threshold ) - { - // If the current digit is not the last one, or if it is - // greater than the last digit of the maximum integer value, - // the parse the number as a double. - if ( current != token.end_ || digit > lastDigitThreshold ) - { - return decodeDouble( token ); - } - } - value = value * 10 + digit; - } - if ( isNegative ) - currentValue() = -Value::LargestInt( value ); - else if ( value <= Value::LargestUInt(Value::maxInt) ) - currentValue() = Value::LargestInt( value ); - else - currentValue() = value; - return true; -} - - -bool -Reader::decodeDouble( Token &token ) -{ - double value = 0; - const int bufferSize = 32; - int count; - int length = int(token.end_ - token.start_); - if ( length <= bufferSize ) - { - Char buffer[bufferSize+1]; - memcpy( buffer, token.start_, length ); - buffer[length] = 0; - count = sscanf( buffer, "%lf", &value ); - } - else - { - std::string buffer( token.start_, token.end_ ); - count = sscanf( buffer.c_str(), "%lf", &value ); - } - - if ( count != 1 ) - return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); - currentValue() = value; - return true; -} - - -bool -Reader::decodeString( Token &token ) -{ - std::string decoded; - if ( !decodeString( token, decoded ) ) - return false; - currentValue() = decoded; - return true; -} - - -bool -Reader::decodeString( Token &token, std::string &decoded ) -{ - decoded.reserve( token.end_ - token.start_ - 2 ); - Location current = token.start_ + 1; // skip '"' - Location end = token.end_ - 1; // do not include '"' - while ( current != end ) - { - Char c = *current++; - if ( c == '"' ) - break; - else if ( c == '\\' ) - { - if ( current == end ) - return addError( "Empty escape sequence in string", token, current ); - Char escape = *current++; - switch ( escape ) - { - case '"': decoded += '"'; break; - case '/': decoded += '/'; break; - case '\\': decoded += '\\'; break; - case 'b': decoded += '\b'; break; - case 'f': decoded += '\f'; break; - case 'n': decoded += '\n'; break; - case 'r': decoded += '\r'; break; - case 't': decoded += '\t'; break; - case 'u': - { - unsigned int unicode; - if ( !decodeUnicodeCodePoint( token, current, end, unicode ) ) - return false; - decoded += codePointToUTF8(unicode); - } - break; - default: - return addError( "Bad escape sequence in string", token, current ); - } - } - else - { - decoded += c; - } - } - return true; -} - -bool -Reader::decodeUnicodeCodePoint( Token &token, - Location ¤t, - Location end, - unsigned int &unicode ) -{ - - if ( !decodeUnicodeEscapeSequence( token, current, end, unicode ) ) - return false; - if (unicode >= 0xD800 && unicode <= 0xDBFF) - { - // surrogate pairs - if (end - current < 6) - return addError( "additional six characters expected to parse unicode surrogate pair.", token, current ); - unsigned int surrogatePair; - if (*(current++) == '\\' && *(current++)== 'u') - { - if (decodeUnicodeEscapeSequence( token, current, end, surrogatePair )) - { - unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF); - } - else - return false; - } - else - return addError( "expecting another \\u token to begin the second half of a unicode surrogate pair", token, current ); - } - return true; -} - -bool -Reader::decodeUnicodeEscapeSequence( Token &token, - Location ¤t, - Location end, - unsigned int &unicode ) -{ - if ( end - current < 4 ) - return addError( "Bad unicode escape sequence in string: four digits expected.", token, current ); - unicode = 0; - for ( int index =0; index < 4; ++index ) - { - Char c = *current++; - unicode *= 16; - if ( c >= '0' && c <= '9' ) - unicode += c - '0'; - else if ( c >= 'a' && c <= 'f' ) - unicode += c - 'a' + 10; - else if ( c >= 'A' && c <= 'F' ) - unicode += c - 'A' + 10; - else - return addError( "Bad unicode escape sequence in string: hexadecimal digit expected.", token, current ); - } - return true; -} - - -bool -Reader::addError( const std::string &message, - Token &token, - Location extra ) -{ - ErrorInfo info; - info.token_ = token; - info.message_ = message; - info.extra_ = extra; - errors_.push_back( info ); - return false; -} - - -bool -Reader::recoverFromError( TokenType skipUntilToken ) -{ - int errorCount = int(errors_.size()); - Token skip; - for (;;) - { - if ( !readToken(skip) ) - errors_.resize( errorCount ); // discard errors caused by recovery - if ( skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream ) - break; - } - errors_.resize( errorCount ); - return false; -} - - -bool -Reader::addErrorAndRecover( const std::string &message, - Token &token, - TokenType skipUntilToken ) -{ - addError( message, token ); - return recoverFromError( skipUntilToken ); -} - - -Value & -Reader::currentValue() -{ - return *(nodes_.top()); -} - - -Reader::Char -Reader::getNextChar() -{ - if ( current_ == end_ ) - return 0; - return *current_++; -} - - -void -Reader::getLocationLineAndColumn( Location location, - int &line, - int &column ) const -{ - Location current = begin_; - Location lastLineStart = current; - line = 0; - while ( current < location && current != end_ ) - { - Char c = *current++; - if ( c == '\r' ) - { - if ( *current == '\n' ) - ++current; - lastLineStart = current; - ++line; - } - else if ( c == '\n' ) - { - lastLineStart = current; - ++line; - } - } - // column & line start at 1 - column = int(location - lastLineStart) + 1; - ++line; -} - - -std::string -Reader::getLocationLineAndColumn( Location location ) const -{ - int line, column; - getLocationLineAndColumn( location, line, column ); - char buffer[18+16+16+1]; - sprintf( buffer, "Line %d, Column %d", line, column ); - return buffer; -} - - -// Deprecated. Preserved for backward compatibility -std::string -Reader::getFormatedErrorMessages() const -{ - return getFormattedErrorMessages(); -} - - -std::string -Reader::getFormattedErrorMessages() const -{ - std::string formattedMessage; - for ( Errors::const_iterator itError = errors_.begin(); - itError != errors_.end(); - ++itError ) - { - const ErrorInfo &error = *itError; - formattedMessage += "* " + getLocationLineAndColumn( error.token_.start_ ) + "\n"; - formattedMessage += " " + error.message_ + "\n"; - if ( error.extra_ ) - formattedMessage += "See " + getLocationLineAndColumn( error.extra_ ) + " for detail.\n"; - } - return formattedMessage; -} - - -std::istream& operator>>( std::istream &sin, Value &root ) -{ - CSJson::Reader reader; - bool ok = reader.parse(sin, root, true); - //JSON_ASSERT( ok ); - if (!ok) throw std::runtime_error(reader.getFormattedErrorMessages()); - return sin; -} - - -} // namespace CSJson diff --git a/extensions/CCArmature/external_tool/Json/lib_json/json_value.cpp b/extensions/CCArmature/external_tool/Json/lib_json/json_value.cpp deleted file mode 100644 index 0090a5279d..0000000000 --- a/extensions/CCArmature/external_tool/Json/lib_json/json_value.cpp +++ /dev/null @@ -1,1837 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#if !defined(JSON_IS_AMALGAMATION) -# include "value.h" -# include "writer.h" -# ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR -# include "json_batchallocator.h" -# endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR -#endif // if !defined(JSON_IS_AMALGAMATION) -#include -#include -#include -#include -#include -#ifdef JSON_USE_CPPTL -# include -#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 ); -#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) JSON_FAIL_MESSAGE( message ) - -namespace CSJson { - -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); -const Int64 Value::minInt64 = Int64( ~(UInt64(-1)/2) ); -const Int64 Value::maxInt64 = Int64( UInt64(-1)/2 ); -const UInt64 Value::maxUInt64 = UInt64(-1); -const LargestInt Value::minLargestInt = LargestInt( ~(LargestUInt(-1)/2) ); -const LargestInt Value::maxLargestInt = LargestInt( LargestUInt(-1)/2 ); -const LargestUInt Value::maxLargestUInt = LargestUInt(-1); - - -/// Unknown size marker -static const unsigned int unknown = (unsigned)-1; - - -/** Duplicates the specified string value. - * @param value Pointer to the string to duplicate. Must be zero-terminated if - * length is "unknown". - * @param length Length of the value. if equals to unknown, then it will be - * computed using strlen(value). - * @return Pointer on the duplicate instance of string. - */ -static inline char * -duplicateStringValue( const char *value, - unsigned int length = unknown ) -{ - if ( length == unknown ) - length = (unsigned int)strlen(value); - char *newString = static_cast( malloc( length + 1 ) ); - JSON_ASSERT_MESSAGE( newString != 0, "Failed to allocate string value buffer" ); - memcpy( newString, value, length ); - newString[length] = 0; - return newString; -} - - -/** Free the string duplicated by duplicateStringValue(). - */ -static inline void -releaseStringValue( char *value ) -{ - if ( value ) - free( value ); -} - -} // namespace CSJson - - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ValueInternals... -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -#if !defined(JSON_IS_AMALGAMATION) -# ifdef JSON_VALUE_USE_INTERNAL_MAP -# include "json_internalarray.inl" -# include "json_internalmap.inl" -# endif // JSON_VALUE_USE_INTERNAL_MAP - -# include "json_valueiterator.inl" -#endif // if !defined(JSON_IS_AMALGAMATION) - -namespace CSJson { - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class Value::CommentInfo -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// - - -Value::CommentInfo::CommentInfo() - : comment_( 0 ) -{ -} - -Value::CommentInfo::~CommentInfo() -{ - if ( comment_ ) - releaseStringValue( comment_ ); -} - - -void -Value::CommentInfo::setComment( const char *text ) -{ - if ( comment_ ) - releaseStringValue( comment_ ); - JSON_ASSERT( text != 0 ); - JSON_ASSERT_MESSAGE( text[0]=='\0' || text[0]=='/', "Comments must start with /"); - // It seems that /**/ style comments are acceptable as well. - comment_ = duplicateStringValue( text ); -} - - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class Value::CZString -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -# ifndef JSON_VALUE_USE_INTERNAL_MAP - -// Notes: index_ indicates if the string was allocated when -// a string is stored. - -Value::CZString::CZString( ArrayIndex index ) - : cstr_( 0 ) - , index_( index ) -{ -} - -Value::CZString::CZString( const char *cstr, DuplicationPolicy allocate ) - : cstr_( allocate == duplicate ? duplicateStringValue(cstr) - : cstr ) - , index_( allocate ) -{ -} - -Value::CZString::CZString( const CZString &other ) -: cstr_( other.index_ != noDuplication && other.cstr_ != 0 - ? duplicateStringValue( other.cstr_ ) - : other.cstr_ ) - , index_( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate) - : other.index_ ) -{ -} - -Value::CZString::~CZString() -{ - if ( cstr_ && index_ == duplicate ) - releaseStringValue( const_cast( cstr_ ) ); -} - -void -Value::CZString::swap( CZString &other ) -{ - std::swap( cstr_, other.cstr_ ); - std::swap( index_, other.index_ ); -} - -Value::CZString & -Value::CZString::operator =( const CZString &other ) -{ - CZString temp( other ); - swap( temp ); - return *this; -} - -bool -Value::CZString::operator<( const CZString &other ) const -{ - if ( cstr_ ) - return strcmp( cstr_, other.cstr_ ) < 0; - return index_ < other.index_; -} - -bool -Value::CZString::operator==( const CZString &other ) const -{ - if ( cstr_ ) - return strcmp( cstr_, other.cstr_ ) == 0; - return index_ == other.index_; -} - - -ArrayIndex -Value::CZString::index() const -{ - return index_; -} - - -const char * -Value::CZString::c_str() const -{ - return cstr_; -} - -bool -Value::CZString::isStaticString() const -{ - return index_ == noDuplication; -} - -#endif // ifndef JSON_VALUE_USE_INTERNAL_MAP - - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class Value::Value -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// - -/*! \internal Default constructor initialization must be equivalent to: - * memset( this, 0, sizeof(Value) ) - * This optimization is used in ValueInternalMap fast allocator. - */ -Value::Value( ValueType type ) - : type_( type ) - , allocated_( 0 ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - switch ( type ) - { - case nullValue: - break; - case intValue: - case uintValue: - value_.int_ = 0; - break; - case realValue: - value_.real_ = 0.0; - break; - case stringValue: - value_.string_ = 0; - break; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - value_.map_ = new ObjectValues(); - break; -#else - case arrayValue: - value_.array_ = arrayAllocator()->newArray(); - break; - case objectValue: - value_.map_ = mapAllocator()->newMap(); - break; -#endif - case booleanValue: - value_.bool_ = false; - break; - default: - JSON_ASSERT_UNREACHABLE; - } -} - - -#if defined(JSON_HAS_INT64) -Value::Value( UInt value ) - : type_( uintValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.uint_ = value; -} - -Value::Value( Int value ) - : type_( intValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.int_ = value; -} - -#endif // if defined(JSON_HAS_INT64) - - -Value::Value( Int64 value ) - : type_( intValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.int_ = value; -} - - -Value::Value( UInt64 value ) - : type_( uintValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.uint_ = value; -} - -Value::Value( double value ) - : type_( realValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.real_ = value; -} - -Value::Value( const char *value ) - : type_( stringValue ) - , allocated_( true ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = duplicateStringValue( value ); -} - - -Value::Value( const char *beginValue, - const char *endValue ) - : type_( stringValue ) - , allocated_( true ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = duplicateStringValue( beginValue, - (unsigned int)(endValue - beginValue) ); -} - - -Value::Value( const std::string &value ) - : type_( stringValue ) - , allocated_( true ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = duplicateStringValue( value.c_str(), - (unsigned int)value.length() ); - -} - -Value::Value( const StaticString &value ) - : type_( stringValue ) - , allocated_( false ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = const_cast( value.c_str() ); -} - - -# ifdef JSON_USE_CPPTL -Value::Value( const CppTL::ConstString &value ) - : type_( stringValue ) - , allocated_( true ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = duplicateStringValue( value, value.length() ); -} -# endif - -Value::Value( bool value ) - : type_( booleanValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.bool_ = value; -} - - -Value::Value( const Value &other ) - : type_( other.type_ ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - switch ( type_ ) - { - case nullValue: - case intValue: - case uintValue: - case realValue: - case booleanValue: - value_ = other.value_; - break; - case stringValue: - if ( other.value_.string_ ) - { - value_.string_ = duplicateStringValue( other.value_.string_ ); - allocated_ = true; - } - else - value_.string_ = 0; - break; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - value_.map_ = new ObjectValues( *other.value_.map_ ); - break; -#else - case arrayValue: - value_.array_ = arrayAllocator()->newArrayCopy( *other.value_.array_ ); - break; - case objectValue: - value_.map_ = mapAllocator()->newMapCopy( *other.value_.map_ ); - break; -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - if ( other.comments_ ) - { - comments_ = new CommentInfo[numberOfCommentPlacement]; - for ( int comment =0; comment < numberOfCommentPlacement; ++comment ) - { - const CommentInfo &otherComment = other.comments_[comment]; - if ( otherComment.comment_ ) - comments_[comment].setComment( otherComment.comment_ ); - } - } -} - - -Value::~Value() -{ - switch ( type_ ) - { - case nullValue: - case intValue: - case uintValue: - case realValue: - case booleanValue: - break; - case stringValue: - if ( allocated_ ) - releaseStringValue( value_.string_ ); - break; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - delete value_.map_; - break; -#else - case arrayValue: - arrayAllocator()->destructArray( value_.array_ ); - break; - case objectValue: - mapAllocator()->destructMap( value_.map_ ); - break; -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - - if ( comments_ ) - delete[] comments_; -} - -Value & -Value::operator=( const Value &other ) -{ - Value temp( other ); - swap( temp ); - return *this; -} - -void -Value::swap( Value &other ) -{ - ValueType temp = type_; - type_ = other.type_; - other.type_ = temp; - std::swap( value_, other.value_ ); - int temp2 = allocated_; - allocated_ = other.allocated_; - other.allocated_ = temp2; -} - -ValueType -Value::type() const -{ - return type_; -} - - -int -Value::compare( const Value &other ) const -{ - if ( *this < other ) - return -1; - if ( *this > other ) - return 1; - return 0; -} - - -bool -Value::operator <( const Value &other ) const -{ - int typeDelta = type_ - other.type_; - if ( typeDelta ) - return typeDelta < 0 ? true : false; - switch ( type_ ) - { - case nullValue: - return false; - case intValue: - return value_.int_ < other.value_.int_; - case uintValue: - return value_.uint_ < other.value_.uint_; - case realValue: - return value_.real_ < other.value_.real_; - case booleanValue: - return value_.bool_ < other.value_.bool_; - case stringValue: - return ( value_.string_ == 0 && other.value_.string_ ) - || ( other.value_.string_ - && value_.string_ - && strcmp( value_.string_, other.value_.string_ ) < 0 ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - { - int delta = int( value_.map_->size() - other.value_.map_->size() ); - if ( delta ) - return delta < 0; - return (*value_.map_) < (*other.value_.map_); - } -#else - case arrayValue: - return value_.array_->compare( *(other.value_.array_) ) < 0; - case objectValue: - return value_.map_->compare( *(other.value_.map_) ) < 0; -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - return false; // unreachable -} - -bool -Value::operator <=( const Value &other ) const -{ - return !(other < *this); -} - -bool -Value::operator >=( const Value &other ) const -{ - return !(*this < other); -} - -bool -Value::operator >( const Value &other ) const -{ - return other < *this; -} - -bool -Value::operator ==( const Value &other ) const -{ - //if ( type_ != other.type_ ) - // GCC 2.95.3 says: - // attempt to take address of bit-field structure member `Json::Value::type_' - // Beats me, but a temp solves the problem. - int temp = other.type_; - if ( type_ != temp ) - return false; - switch ( type_ ) - { - case nullValue: - return true; - case intValue: - return value_.int_ == other.value_.int_; - case uintValue: - return value_.uint_ == other.value_.uint_; - case realValue: - return value_.real_ == other.value_.real_; - case booleanValue: - return value_.bool_ == other.value_.bool_; - case stringValue: - return ( value_.string_ == other.value_.string_ ) - || ( other.value_.string_ - && value_.string_ - && strcmp( value_.string_, other.value_.string_ ) == 0 ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - return value_.map_->size() == other.value_.map_->size() - && (*value_.map_) == (*other.value_.map_); -#else - case arrayValue: - return value_.array_->compare( *(other.value_.array_) ) == 0; - case objectValue: - return value_.map_->compare( *(other.value_.map_) ) == 0; -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - return false; // unreachable -} - -bool -Value::operator !=( const Value &other ) const -{ - return !( *this == other ); -} - -const char * -Value::asCString() const -{ - JSON_ASSERT( type_ == stringValue ); - return value_.string_; -} - - -std::string -Value::asString() const -{ - switch ( type_ ) - { - case nullValue: - return ""; - case stringValue: - return value_.string_ ? value_.string_ : ""; - case booleanValue: - return value_.bool_ ? "true" : "false"; - case intValue: - case uintValue: - case realValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to string" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return ""; // unreachable -} - -# ifdef JSON_USE_CPPTL -CppTL::ConstString -Value::asConstString() const -{ - return CppTL::ConstString( asString().c_str() ); -} -# endif - - -Value::Int -Value::asInt() const -{ - switch ( type_ ) - { - case nullValue: - return 0; - case intValue: - JSON_ASSERT_MESSAGE( value_.int_ >= minInt && value_.int_ <= maxInt, "unsigned integer out of signed int range" ); - return Int(value_.int_); - case uintValue: - JSON_ASSERT_MESSAGE( value_.uint_ <= UInt(maxInt), "unsigned integer out of signed int range" ); - return Int(value_.uint_); - case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" ); - return Int( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1 : 0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to int" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - - -Value::UInt -Value::asUInt() const -{ - switch ( type_ ) - { - case nullValue: - return 0; - case intValue: - JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" ); - JSON_ASSERT_MESSAGE( value_.int_ <= maxUInt, "signed integer out of UInt range" ); - return UInt(value_.int_); - case uintValue: - JSON_ASSERT_MESSAGE( value_.uint_ <= maxUInt, "unsigned integer out of UInt range" ); - return UInt(value_.uint_); - case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" ); - return UInt( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1 : 0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to uint" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - - -# if defined(JSON_HAS_INT64) - -Value::Int64 -Value::asInt64() const -{ - switch ( type_ ) - { - case nullValue: - return 0; - case intValue: - return value_.int_; - case uintValue: - JSON_ASSERT_MESSAGE( value_.uint_ <= UInt64(maxInt64), "unsigned integer out of Int64 range" ); - return value_.uint_; - case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= minInt64 && value_.real_ <= maxInt64, "Real out of Int64 range" ); - return Int( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1 : 0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to Int64" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - - -Value::UInt64 -Value::asUInt64() const -{ - switch ( type_ ) - { - case nullValue: - return 0; - case intValue: - JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to UInt64" ); - return value_.int_; - case uintValue: - return value_.uint_; - case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt64, "Real out of UInt64 range" ); - return UInt( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1 : 0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to UInt64" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} -# endif // if defined(JSON_HAS_INT64) - - -LargestInt -Value::asLargestInt() const -{ -#if defined(JSON_NO_INT64) - return asInt(); -#else - return asInt64(); -#endif -} - - -LargestUInt -Value::asLargestUInt() const -{ -#if defined(JSON_NO_INT64) - return asUInt(); -#else - return asUInt64(); -#endif -} - - -double -Value::asDouble() const -{ - switch ( type_ ) - { - case nullValue: - return 0.0; - case intValue: - return static_cast( value_.int_ ); - case uintValue: -#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return static_cast( value_.uint_ ); -#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return static_cast( Int(value_.uint_/2) ) * 2 + Int(value_.uint_ & 1); -#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - case realValue: - return value_.real_; - case booleanValue: - return value_.bool_ ? 1.0 : 0.0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to double" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - -float -Value::asFloat() const -{ - switch ( type_ ) - { - case nullValue: - return 0.0f; - case intValue: - return static_cast( value_.int_ ); - case uintValue: -#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return static_cast( value_.uint_ ); -#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return static_cast( Int(value_.uint_/2) ) * 2 + Int(value_.uint_ & 1); -#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - case realValue: - return static_cast( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1.0f : 0.0f; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to float" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0.0f; // unreachable; -} - -bool -Value::asBool() const -{ - switch ( type_ ) - { - case nullValue: - return false; - case intValue: - case uintValue: - return value_.int_ != 0; - case realValue: - return value_.real_ != 0.0; - case booleanValue: - return value_.bool_; - case stringValue: - return value_.string_ && value_.string_[0] != 0; - case arrayValue: - case objectValue: - return value_.map_->size() != 0; - default: - JSON_ASSERT_UNREACHABLE; - } - return false; // unreachable; -} - - -bool -Value::isConvertibleTo( ValueType other ) const -{ - switch ( type_ ) - { - case nullValue: - return true; - case intValue: - return ( other == nullValue && value_.int_ == 0 ) - || other == intValue - || ( other == uintValue && value_.int_ >= 0 ) - || other == realValue - || other == stringValue - || other == booleanValue; - case uintValue: - return ( other == nullValue && value_.uint_ == 0 ) - || ( other == intValue && value_.uint_ <= (unsigned)maxInt ) - || other == uintValue - || other == realValue - || other == stringValue - || other == booleanValue; - case realValue: - return ( other == nullValue && value_.real_ == 0.0 ) - || ( other == intValue && value_.real_ >= minInt && value_.real_ <= maxInt ) - || ( other == uintValue && value_.real_ >= 0 && value_.real_ <= maxUInt ) - || other == realValue - || other == stringValue - || other == booleanValue; - case booleanValue: - return ( other == nullValue && value_.bool_ == false ) - || other == intValue - || other == uintValue - || other == realValue - || other == stringValue - || other == booleanValue; - case stringValue: - return other == stringValue - || ( other == nullValue && (!value_.string_ || value_.string_[0] == 0) ); - case arrayValue: - return other == arrayValue - || ( other == nullValue && value_.map_->size() == 0 ); - case objectValue: - return other == objectValue - || ( other == nullValue && value_.map_->size() == 0 ); - default: - JSON_ASSERT_UNREACHABLE; - } - return false; // unreachable; -} - - -/// Number of values in array or object -ArrayIndex -Value::size() const -{ - switch ( type_ ) - { - case nullValue: - case intValue: - case uintValue: - case realValue: - case booleanValue: - case stringValue: - return 0; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: // size of the array is highest index + 1 - if ( !value_.map_->empty() ) - { - ObjectValues::const_iterator itLast = value_.map_->end(); - --itLast; - return (*itLast).first.index()+1; - } - return 0; - case objectValue: - return ArrayIndex( value_.map_->size() ); -#else - case arrayValue: - return Int( value_.array_->size() ); - case objectValue: - return Int( value_.map_->size() ); -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - - -bool -Value::empty() const -{ - if ( isNull() || isArray() || isObject() ) - return size() == 0u; - else - return false; -} - - -bool -Value::operator!() const -{ - return isNull(); -} - - -void -Value::clear() -{ - JSON_ASSERT( type_ == nullValue || type_ == arrayValue || type_ == objectValue ); - - switch ( type_ ) - { -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - // value_.map_->clear(); - if (!value_.map_) - { - value_.map_->clear(); - delete value_.map_; - value_.map_ = NULL; - } - break; -#else - case arrayValue: - value_.array_->clear(); - break; - case objectValue: - value_.map_->clear(); - break; -#endif - default: - break; - } -} - -void -Value::resize( ArrayIndex newSize ) -{ - JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); - if ( type_ == nullValue ) - *this = Value( arrayValue ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - ArrayIndex oldSize = size(); - if ( newSize == 0 ) - clear(); - else if ( newSize > oldSize ) - (*this)[ newSize - 1 ]; - else - { - for ( ArrayIndex index = newSize; index < oldSize; ++index ) - { - value_.map_->erase( index ); - } - assert( size() == newSize ); - } -#else - value_.array_->resize( newSize ); -#endif -} - - -Value & -Value::operator[]( ArrayIndex index ) -{ - JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); - if ( type_ == nullValue ) - *this = Value( arrayValue ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - CZString key( index ); - ObjectValues::iterator it = value_.map_->lower_bound( key ); - if ( it != value_.map_->end() && (*it).first == key ) - return (*it).second; - - ObjectValues::value_type defaultValue( key, jsonNull ); - it = value_.map_->insert( it, defaultValue ); - return (*it).second; -#else - return value_.array_->resolveReference( index ); -#endif -} - - -Value & -Value::operator[]( int index ) -{ - JSON_ASSERT( index >= 0 ); - return (*this)[ ArrayIndex(index) ]; -} - - -const Value & -Value::operator[]( ArrayIndex index ) const -{ - JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); - if ( type_ == nullValue ) - 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 jsonNull; - return (*it).second; -#else - Value *value = value_.array_->find( index ); - return value ? *value : null; -#endif -} - - -const Value & -Value::operator[]( int index ) const -{ - JSON_ASSERT( index >= 0 ); - return (*this)[ ArrayIndex(index) ]; -} - - -Value & -Value::operator[]( const char *key ) -{ - return resolveReference( key, false ); -} - - -Value & -Value::resolveReference( const char *key, - bool isStatic ) -{ - JSON_ASSERT( type_ == nullValue || type_ == objectValue ); - if ( type_ == nullValue ) - *this = Value( objectValue ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - CZString actualKey( key, isStatic ? CZString::noDuplication - : CZString::duplicateOnCopy ); - ObjectValues::iterator it = value_.map_->lower_bound( actualKey ); - if ( it != value_.map_->end() && (*it).first == actualKey ) - return (*it).second; - - ObjectValues::value_type defaultValue( actualKey, jsonNull ); - it = value_.map_->insert( it, defaultValue ); - Value &value = (*it).second; - return value; -#else - return value_.map_->resolveReference( key, isStatic ); -#endif -} - - -Value -Value::get( ArrayIndex index, - const Value &defaultValue ) const -{ - const Value *value = &((*this)[index]); - return value == &jsonNull ? defaultValue : *value; -} - - -bool -Value::isValidIndex( ArrayIndex index ) const -{ - return index < size(); -} - - - -const Value & -Value::operator[]( const char *key ) const -{ - JSON_ASSERT( type_ == nullValue || type_ == objectValue ); - if ( type_ == nullValue ) - 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 jsonNull; - return (*it).second; -#else - const Value *value = value_.map_->find( key ); - return value ? *value : null; -#endif -} - - -Value & -Value::operator[]( const std::string &key ) -{ - return (*this)[ key.c_str() ]; -} - - -const Value & -Value::operator[]( const std::string &key ) const -{ - return (*this)[ key.c_str() ]; -} - -Value & -Value::operator[]( const StaticString &key ) -{ - return resolveReference( key, true ); -} - - -# ifdef JSON_USE_CPPTL -Value & -Value::operator[]( const CppTL::ConstString &key ) -{ - return (*this)[ key.c_str() ]; -} - - -const Value & -Value::operator[]( const CppTL::ConstString &key ) const -{ - return (*this)[ key.c_str() ]; -} -# endif - - -Value & -Value::append( const Value &value ) -{ - return (*this)[size()] = value; -} - - -Value -Value::get( const char *key, - const Value &defaultValue ) const -{ - const Value *value = &((*this)[key]); - return value == &jsonNull ? defaultValue : *value; -} - - -Value -Value::get( const std::string &key, - const Value &defaultValue ) const -{ - return get( key.c_str(), defaultValue ); -} - -Value -Value::removeMember( const char* key ) -{ - JSON_ASSERT( type_ == nullValue || type_ == objectValue ); - if ( type_ == nullValue ) - 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 jsonNull; - Value old(it->second); - value_.map_->erase(it); - return old; -#else - Value *value = value_.map_->find( key ); - if (value){ - Value old(*value); - value_.map_.remove( key ); - return old; - } else { - return null; - } -#endif -} - -Value -Value::removeMember( const std::string &key ) -{ - return removeMember( key.c_str() ); -} - -# ifdef JSON_USE_CPPTL -Value -Value::get( const CppTL::ConstString &key, - const Value &defaultValue ) const -{ - return get( key.c_str(), defaultValue ); -} -# endif - -bool -Value::isMember( const char *key ) const -{ - const Value *value = &((*this)[key]); - return value != &jsonNull; -} - - -bool -Value::isMember( const std::string &key ) const -{ - return isMember( key.c_str() ); -} - - -# ifdef JSON_USE_CPPTL -bool -Value::isMember( const CppTL::ConstString &key ) const -{ - return isMember( key.c_str() ); -} -#endif - -Value::Members -Value::getMemberNames() const -{ - JSON_ASSERT( type_ == nullValue || type_ == objectValue ); - if ( type_ == nullValue ) - return Value::Members(); - Members members; - members.reserve( value_.map_->size() ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - ObjectValues::const_iterator it = value_.map_->begin(); - ObjectValues::const_iterator itEnd = value_.map_->end(); - for ( ; it != itEnd; ++it ) - members.push_back( std::string( (*it).first.c_str() ) ); -#else - ValueInternalMap::IteratorState it; - ValueInternalMap::IteratorState itEnd; - value_.map_->makeBeginIterator( it ); - value_.map_->makeEndIterator( itEnd ); - for ( ; !ValueInternalMap::equals( it, itEnd ); ValueInternalMap::increment(it) ) - members.push_back( std::string( ValueInternalMap::key( it ) ) ); -#endif - return members; -} -// -//# ifdef JSON_USE_CPPTL -//EnumMemberNames -//Value::enumMemberNames() const -//{ -// if ( type_ == objectValue ) -// { -// return CppTL::Enum::any( CppTL::Enum::transform( -// CppTL::Enum::keys( *(value_.map_), CppTL::Type() ), -// MemberNamesTransform() ) ); -// } -// return EnumMemberNames(); -//} -// -// -//EnumValues -//Value::enumValues() const -//{ -// if ( type_ == objectValue || type_ == arrayValue ) -// return CppTL::Enum::anyValues( *(value_.map_), -// CppTL::Type() ); -// return EnumValues(); -//} -// -//# endif - - -bool -Value::isNull() const -{ - return type_ == nullValue; -} - - -bool -Value::isBool() const -{ - return type_ == booleanValue; -} - - -bool -Value::isInt() const -{ - return type_ == intValue; -} - - -bool -Value::isUInt() const -{ - return type_ == uintValue; -} - - -bool -Value::isIntegral() const -{ - return type_ == intValue - || type_ == uintValue - || type_ == booleanValue; -} - - -bool -Value::isDouble() const -{ - return type_ == realValue; -} - - -bool -Value::isNumeric() const -{ - return isIntegral() || isDouble(); -} - - -bool -Value::isString() const -{ - return type_ == stringValue; -} - - -bool -Value::isArray() const -{ - return type_ == nullValue || type_ == arrayValue; -} - - -bool -Value::isObject() const -{ - return type_ == nullValue || type_ == objectValue; -} - - -void -Value::setComment( const char *comment, - CommentPlacement placement ) -{ - if ( !comments_ ) - comments_ = new CommentInfo[numberOfCommentPlacement]; - comments_[placement].setComment( comment ); -} - - -void -Value::setComment( const std::string &comment, - CommentPlacement placement ) -{ - setComment( comment.c_str(), placement ); -} - - -bool -Value::hasComment( CommentPlacement placement ) const -{ - return comments_ != 0 && comments_[placement].comment_ != 0; -} - -std::string -Value::getComment( CommentPlacement placement ) const -{ - if ( hasComment(placement) ) - return comments_[placement].comment_; - return ""; -} - - -std::string -Value::toStyledString() const -{ - StyledWriter writer; - return writer.write( *this ); -} - - -Value::const_iterator -Value::begin() const -{ - switch ( type_ ) - { -#ifdef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - if ( value_.array_ ) - { - ValueInternalArray::IteratorState it; - value_.array_->makeBeginIterator( it ); - return const_iterator( it ); - } - break; - case objectValue: - if ( value_.map_ ) - { - ValueInternalMap::IteratorState it; - value_.map_->makeBeginIterator( it ); - return const_iterator( it ); - } - break; -#else - case arrayValue: - case objectValue: - if ( value_.map_ ) - return const_iterator( value_.map_->begin() ); - break; -#endif - default: - break; - } - return const_iterator(); -} - -Value::const_iterator -Value::end() const -{ - switch ( type_ ) - { -#ifdef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - if ( value_.array_ ) - { - ValueInternalArray::IteratorState it; - value_.array_->makeEndIterator( it ); - return const_iterator( it ); - } - break; - case objectValue: - if ( value_.map_ ) - { - ValueInternalMap::IteratorState it; - value_.map_->makeEndIterator( it ); - return const_iterator( it ); - } - break; -#else - case arrayValue: - case objectValue: - if ( value_.map_ ) - return const_iterator( value_.map_->end() ); - break; -#endif - default: - break; - } - return const_iterator(); -} - - -Value::iterator -Value::begin() -{ - switch ( type_ ) - { -#ifdef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - if ( value_.array_ ) - { - ValueInternalArray::IteratorState it; - value_.array_->makeBeginIterator( it ); - return iterator( it ); - } - break; - case objectValue: - if ( value_.map_ ) - { - ValueInternalMap::IteratorState it; - value_.map_->makeBeginIterator( it ); - return iterator( it ); - } - break; -#else - case arrayValue: - case objectValue: - if ( value_.map_ ) - return iterator( value_.map_->begin() ); - break; -#endif - default: - break; - } - return iterator(); -} - -Value::iterator -Value::end() -{ - switch ( type_ ) - { -#ifdef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - if ( value_.array_ ) - { - ValueInternalArray::IteratorState it; - value_.array_->makeEndIterator( it ); - return iterator( it ); - } - break; - case objectValue: - if ( value_.map_ ) - { - ValueInternalMap::IteratorState it; - value_.map_->makeEndIterator( it ); - return iterator( it ); - } - break; -#else - case arrayValue: - case objectValue: - if ( value_.map_ ) - return iterator( value_.map_->end() ); - break; -#endif - default: - break; - } - return iterator(); -} - - -// class PathArgument -// ////////////////////////////////////////////////////////////////// - -PathArgument::PathArgument() - : kind_( kindNone ) -{ -} - - -PathArgument::PathArgument( ArrayIndex index ) - : index_( index ) - , kind_( kindIndex ) -{ -} - - -PathArgument::PathArgument( const char *key ) - : key_( key ) - , kind_( kindKey ) -{ -} - - -PathArgument::PathArgument( const std::string &key ) - : key_( key.c_str() ) - , kind_( kindKey ) -{ -} - -// class Path -// ////////////////////////////////////////////////////////////////// - -Path::Path( const std::string &path, - const PathArgument &a1, - const PathArgument &a2, - const PathArgument &a3, - const PathArgument &a4, - const PathArgument &a5 ) -{ - InArgs in; - in.push_back( &a1 ); - in.push_back( &a2 ); - in.push_back( &a3 ); - in.push_back( &a4 ); - in.push_back( &a5 ); - makePath( path, in ); -} - - -void -Path::makePath( const std::string &path, - const InArgs &in ) -{ - const char *current = path.c_str(); - const char *end = current + path.length(); - InArgs::const_iterator itInArg = in.begin(); - while ( current != end ) - { - if ( *current == '[' ) - { - ++current; - if ( *current == '%' ) - addPathInArg( path, in, itInArg, PathArgument::kindIndex ); - else - { - ArrayIndex index = 0; - for ( ; current != end && *current >= '0' && *current <= '9'; ++current ) - index = index * 10 + ArrayIndex(*current - '0'); - args_.push_back( index ); - } - if ( current == end || *current++ != ']' ) - invalidPath( path, int(current - path.c_str()) ); - } - else if ( *current == '%' ) - { - addPathInArg( path, in, itInArg, PathArgument::kindKey ); - ++current; - } - else if ( *current == '.' ) - { - ++current; - } - else - { - const char *beginName = current; - while ( current != end && !strchr( "[.", *current ) ) - ++current; - args_.push_back( std::string( beginName, current ) ); - } - } -} - - -void -Path::addPathInArg( const std::string &path, - const InArgs &in, - InArgs::const_iterator &itInArg, - PathArgument::Kind kind ) -{ - if ( itInArg == in.end() ) - { - // Error: missing argument %d - } - else if ( (*itInArg)->kind_ != kind ) - { - // Error: bad argument type - } - else - { - args_.push_back( **itInArg ); - } -} - - -void -Path::invalidPath( const std::string &path, - int location ) -{ - // Error: invalid path. -} - - -const Value & -Path::resolve( const Value &root ) const -{ - const Value *node = &root; - for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) - { - const PathArgument &arg = *it; - if ( arg.kind_ == PathArgument::kindIndex ) - { - if ( !node->isArray() || node->isValidIndex( arg.index_ ) ) - { - // Error: unable to resolve path (array value expected at position... - } - node = &((*node)[arg.index_]); - } - else if ( arg.kind_ == PathArgument::kindKey ) - { - if ( !node->isObject() ) - { - // Error: unable to resolve path (object value expected at position...) - } - node = &((*node)[arg.key_]); - if ( node == &Value::jsonNull ) - { - // Error: unable to resolve path (object has no member named '' at position...) - } - } - } - return *node; -} - - -Value -Path::resolve( const Value &root, - const Value &defaultValue ) const -{ - const Value *node = &root; - for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) - { - const PathArgument &arg = *it; - if ( arg.kind_ == PathArgument::kindIndex ) - { - if ( !node->isArray() || node->isValidIndex( arg.index_ ) ) - return defaultValue; - node = &((*node)[arg.index_]); - } - else if ( arg.kind_ == PathArgument::kindKey ) - { - if ( !node->isObject() ) - return defaultValue; - node = &((*node)[arg.key_]); - if ( node == &Value::jsonNull ) - return defaultValue; - } - } - return *node; -} - - -Value & -Path::make( Value &root ) const -{ - Value *node = &root; - for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) - { - const PathArgument &arg = *it; - if ( arg.kind_ == PathArgument::kindIndex ) - { - if ( !node->isArray() ) - { - // Error: node is not an array at position ... - } - node = &((*node)[arg.index_]); - } - else if ( arg.kind_ == PathArgument::kindKey ) - { - if ( !node->isObject() ) - { - // Error: node is not an object at position... - } - node = &((*node)[arg.key_]); - } - } - return *node; -} - - -} // namespace CSJson diff --git a/extensions/CCArmature/external_tool/Json/lib_json/value.h b/extensions/CCArmature/external_tool/Json/lib_json/value.h deleted file mode 100644 index 73c612c94e..0000000000 --- a/extensions/CCArmature/external_tool/Json/lib_json/value.h +++ /dev/null @@ -1,1103 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef CPPTL_JSON_H_INCLUDED -# define CPPTL_JSON_H_INCLUDED - -#if !defined(JSON_IS_AMALGAMATION) -# include "forwards.h" -#endif // if !defined(JSON_IS_AMALGAMATION) -# include -# include - -# ifndef JSON_USE_CPPTL_SMALLMAP -# include -# else -# include -# endif -# ifdef JSON_USE_CPPTL -# include -# endif - -/** \brief JSON (JavaScript Object Notation). - */ -namespace CSJson { - - /** \brief Type of the value held by a Value object. - */ - enum ValueType - { - nullValue = 0, ///< 'null' value - intValue, ///< signed integer value - uintValue, ///< unsigned integer value - realValue, ///< double value - stringValue, ///< UTF-8 string value - booleanValue, ///< bool value - arrayValue, ///< array value (ordered list) - objectValue ///< object value (collection of name/value pairs). - }; - - enum CommentPlacement - { - commentBefore = 0, ///< a comment placed on the line before a value - commentAfterOnSameLine, ///< a comment just after a value on the same line - commentAfter, ///< a comment on the line after a value (only make sense for root value) - numberOfCommentPlacement - }; - -//# ifdef JSON_USE_CPPTL -// typedef CppTL::AnyEnumerator EnumMemberNames; -// typedef CppTL::AnyEnumerator EnumValues; -//# endif - - /** \brief Lightweight wrapper to tag static string. - * - * Value constructor and objectValue member assignement takes advantage of the - * StaticString and avoid the cost of string duplication when storing the - * string or the member name. - * - * Example of usage: - * \code - * CSJson::Value aValue( StaticString("some text") ); - * CSJson::Value object; - * static const StaticString code("code"); - * object[code] = 1234; - * \endcode - */ - class JSON_API StaticString - { - public: - explicit StaticString( const char *czstring ) - : str_( czstring ) - { - } - - operator const char *() const - { - return str_; - } - - const char *c_str() const - { - return str_; - } - - private: - const char *str_; - }; - - /** \brief Represents a JSON value. - * - * This class is a discriminated union wrapper that can represents a: - * - signed integer [range: Value::minInt - Value::maxInt] - * - unsigned integer (range: 0 - Value::maxUInt) - * - double - * - UTF-8 string - * - boolean - * - 'null' - * - an ordered list of Value - * - collection of name/value pairs (javascript object) - * - * The type of the held value is represented by a #ValueType and - * can be obtained using type(). - * - * values of an #objectValue or #arrayValue can be accessed using operator[]() methods. - * Non const methods will automatically create the a #nullValue element - * if it does not exist. - * The sequence of an #arrayValue will be automatically resize and initialized - * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue. - * - * The get() methods can be used to obtanis default value in the case the required element - * does not exist. - * - * It is possible to iterate over the list of a #objectValue values using - * the getMemberNames() method. - */ - class JSON_API Value - { - friend class ValueIteratorBase; -# ifdef JSON_VALUE_USE_INTERNAL_MAP - friend class ValueInternalLink; - friend class ValueInternalMap; -# endif - public: - typedef std::vector Members; - typedef ValueIterator iterator; - typedef ValueConstIterator const_iterator; - typedef CSJson::UInt UInt; - typedef CSJson::Int Int; -# if defined(JSON_HAS_INT64) - typedef CSJson::UInt64 UInt64; - typedef CSJson::Int64 Int64; -#endif // defined(JSON_HAS_INT64) - typedef CSJson::LargestInt LargestInt; - typedef CSJson::LargestUInt LargestUInt; - typedef CSJson::ArrayIndex ArrayIndex; - - 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. - static const LargestInt maxLargestInt; - /// Maximum unsigned integer value that can be stored in a CSJson::Value. - static const LargestUInt maxLargestUInt; - - /// Minimum signed int value that can be stored in a CSJson::Value. - static const Int minInt; - /// Maximum signed int value that can be stored in a CSJson::Value. - static const Int maxInt; - /// Maximum unsigned int value that can be stored in a CSJson::Value. - static const UInt maxUInt; - - /// Minimum signed 64 bits int value that can be stored in a CSJson::Value. - static const Int64 minInt64; - /// Maximum signed 64 bits int value that can be stored in a CSJson::Value. - static const Int64 maxInt64; - /// Maximum unsigned 64 bits int value that can be stored in a CSJson::Value. - static const UInt64 maxUInt64; - - private: -#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION -# ifndef JSON_VALUE_USE_INTERNAL_MAP - class CZString - { - public: - enum DuplicationPolicy - { - noDuplication = 0, - duplicate, - duplicateOnCopy - }; - CZString( ArrayIndex index ); - CZString( const char *cstr, DuplicationPolicy allocate ); - CZString( const CZString &other ); - ~CZString(); - CZString &operator =( const CZString &other ); - bool operator<( const CZString &other ) const; - bool operator==( const CZString &other ) const; - ArrayIndex index() const; - const char *c_str() const; - bool isStaticString() const; - private: - void swap( CZString &other ); - const char *cstr_; - ArrayIndex index_; - }; - - public: -# ifndef JSON_USE_CPPTL_SMALLMAP - typedef std::map ObjectValues; -# else - typedef CppTL::SmallMap ObjectValues; -# endif // ifndef JSON_USE_CPPTL_SMALLMAP -# endif // ifndef JSON_VALUE_USE_INTERNAL_MAP -#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - - public: - /** \brief Create a default Value of the given type. - - This is a very useful constructor. - To create an empty array, pass arrayValue. - To create an empty object, pass objectValue. - Another Value can then be set to this one by assignment. - This is useful since clear() and resize() will not alter types. - - Examples: - \code - CSJson::Value null_value; // null - CSJson::Value arr_value(Json::arrayValue); // [] - CSJson::Value obj_value(Json::objectValue); // {} - \endcode - */ - Value( ValueType type = nullValue ); - Value( Int value ); - Value( UInt value ); -#if defined(JSON_HAS_INT64) - Value( Int64 value ); - Value( UInt64 value ); -#endif // if defined(JSON_HAS_INT64) - Value( double value ); - Value( const char *value ); - Value( const char *beginValue, const char *endValue ); - /** \brief Constructs a value from a static string. - - * Like other value string constructor but do not duplicate the string for - * internal storage. The given string must remain alive after the call to this - * constructor. - * Example of usage: - * \code - * CSJson::Value aValue( StaticString("some text") ); - * \endcode - */ - Value( const StaticString &value ); - Value( const std::string &value ); -# ifdef JSON_USE_CPPTL - Value( const CppTL::ConstString &value ); -# endif - Value( bool value ); - Value( const Value &other ); - ~Value(); - - Value &operator=( const Value &other ); - /// Swap values. - /// \note Currently, comments are intentionally not swapped, for - /// both logic and efficiency. - void swap( Value &other ); - - ValueType type() const; - - bool operator <( const Value &other ) const; - bool operator <=( const Value &other ) const; - bool operator >=( const Value &other ) const; - bool operator >( const Value &other ) const; - - bool operator ==( const Value &other ) const; - bool operator !=( const Value &other ) const; - - int compare( const Value &other ) const; - - const char *asCString() const; - std::string asString() const; -# ifdef JSON_USE_CPPTL - CppTL::ConstString asConstString() const; -# endif - Int asInt() const; - UInt asUInt() const; - Int64 asInt64() const; - UInt64 asUInt64() const; - LargestInt asLargestInt() const; - LargestUInt asLargestUInt() const; - float asFloat() const; - double asDouble() const; - bool asBool() const; - - bool isNull() const; - bool isBool() const; - bool isInt() const; - bool isUInt() const; - bool isIntegral() const; - bool isDouble() const; - bool isNumeric() const; - bool isString() const; - bool isArray() const; - bool isObject() const; - - bool isConvertibleTo( ValueType other ) const; - - /// Number of values in array or object - ArrayIndex size() const; - - /// \brief Return true if empty array, empty object, or null; - /// otherwise, false. - bool empty() const; - - /// Return isNull() - bool operator!() const; - - /// Remove all object members and array elements. - /// \pre type() is arrayValue, objectValue, or nullValue - /// \post type() is unchanged - void clear(); - - /// Resize the array to size elements. - /// New elements are initialized to null. - /// May only be called on nullValue or arrayValue. - /// \pre type() is arrayValue or nullValue - /// \post type() is arrayValue - void resize( ArrayIndex size ); - - /// Access an array element (zero based index ). - /// If the array contains less than index element, then null value are inserted - /// in the array so that its size is index+1. - /// (You may need to say 'value[0u]' to get your compiler to distinguish - /// this from the operator[] which takes a string.) - Value &operator[]( ArrayIndex index ); - - /// Access an array element (zero based index ). - /// If the array contains less than index element, then null value are inserted - /// in the array so that its size is index+1. - /// (You may need to say 'value[0u]' to get your compiler to distinguish - /// this from the operator[] which takes a string.) - Value &operator[]( int index ); - - /// Access an array element (zero based index ) - /// (You may need to say 'value[0u]' to get your compiler to distinguish - /// this from the operator[] which takes a string.) - const Value &operator[]( ArrayIndex index ) const; - - /// Access an array element (zero based index ) - /// (You may need to say 'value[0u]' to get your compiler to distinguish - /// this from the operator[] which takes a string.) - const Value &operator[]( int index ) const; - - /// If the array contains at least index+1 elements, returns the element value, - /// otherwise returns defaultValue. - Value get( ArrayIndex index, - const Value &defaultValue ) const; - /// Return true if index < size(). - bool isValidIndex( ArrayIndex index ) const; - /// \brief Append value to array at the end. - /// - /// Equivalent to jsonvalue[jsonvalue.size()] = value; - Value &append( const Value &value ); - - /// Access an object value by name, create a null member if it does not exist. - Value &operator[]( const char *key ); - /// Access an object value by name, returns null if there is no member with that name. - const Value &operator[]( const char *key ) const; - /// Access an object value by name, create a null member if it does not exist. - Value &operator[]( const std::string &key ); - /// Access an object value by name, returns null if there is no member with that name. - const Value &operator[]( const std::string &key ) const; - /** \brief Access an object value by name, create a null member if it does not exist. - - * If the object as no entry for that name, then the member name used to store - * the new entry is not duplicated. - * Example of use: - * \code - * CSJson::Value object; - * static const StaticString code("code"); - * object[code] = 1234; - * \endcode - */ - Value &operator[]( const StaticString &key ); -# ifdef JSON_USE_CPPTL - /// Access an object value by name, create a null member if it does not exist. - Value &operator[]( const CppTL::ConstString &key ); - /// Access an object value by name, returns null if there is no member with that name. - const Value &operator[]( const CppTL::ConstString &key ) const; -# endif - /// Return the member named key if it exist, defaultValue otherwise. - Value get( const char *key, - const Value &defaultValue ) const; - /// Return the member named key if it exist, defaultValue otherwise. - Value get( const std::string &key, - const Value &defaultValue ) const; -# ifdef JSON_USE_CPPTL - /// Return the member named key if it exist, defaultValue otherwise. - Value get( const CppTL::ConstString &key, - const Value &defaultValue ) const; -# endif - /// \brief Remove and return the named member. - /// - /// Do nothing if it did not exist. - /// \return the removed Value, or null. - /// \pre type() is objectValue or nullValue - /// \post type() is unchanged - Value removeMember( const char* key ); - /// Same as removeMember(const char*) - Value removeMember( const std::string &key ); - - /// Return true if the object has a member named key. - bool isMember( const char *key ) const; - /// Return true if the object has a member named key. - bool isMember( const std::string &key ) const; -# ifdef JSON_USE_CPPTL - /// Return true if the object has a member named key. - bool isMember( const CppTL::ConstString &key ) const; -# endif - - /// \brief Return a list of the member names. - /// - /// If null, return an empty list. - /// \pre type() is objectValue or nullValue - /// \post if type() was nullValue, it remains nullValue - Members getMemberNames() const; - -//# ifdef JSON_USE_CPPTL -// EnumMemberNames enumMemberNames() const; -// EnumValues enumValues() const; -//# endif - - /// Comments must be //... or /* ... */ - void setComment( const char *comment, - CommentPlacement placement ); - /// Comments must be //... or /* ... */ - void setComment( const std::string &comment, - CommentPlacement placement ); - bool hasComment( CommentPlacement placement ) const; - /// Include delimiters and embedded newlines. - std::string getComment( CommentPlacement placement ) const; - - std::string toStyledString() const; - - const_iterator begin() const; - const_iterator end() const; - - iterator begin(); - iterator end(); - - private: - Value &resolveReference( const char *key, - bool isStatic ); - -# ifdef JSON_VALUE_USE_INTERNAL_MAP - inline bool isItemAvailable() const - { - return itemIsUsed_ == 0; - } - - inline void setItemUsed( bool isUsed = true ) - { - itemIsUsed_ = isUsed ? 1 : 0; - } - - inline bool isMemberNameStatic() const - { - return memberNameIsStatic_ == 0; - } - - inline void setMemberNameIsStatic( bool isStatic ) - { - memberNameIsStatic_ = isStatic ? 1 : 0; - } -# endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP - - private: - struct CommentInfo - { - CommentInfo(); - ~CommentInfo(); - - void setComment( const char *text ); - - char *comment_; - }; - - //struct MemberNamesTransform - //{ - // typedef const char *result_type; - // const char *operator()( const CZString &name ) const - // { - // return name.c_str(); - // } - //}; - - union ValueHolder - { - LargestInt int_; - LargestUInt uint_; - double real_; - bool bool_; - char *string_; -# ifdef JSON_VALUE_USE_INTERNAL_MAP - ValueInternalArray *array_; - ValueInternalMap *map_; -#else - ObjectValues *map_; -# endif - } value_; - ValueType type_ : 8; - int allocated_ : 1; // Notes: if declared as bool, bitfield is useless. -# ifdef JSON_VALUE_USE_INTERNAL_MAP - unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container. - int memberNameIsStatic_ : 1; // used by the ValueInternalMap container. -# endif - CommentInfo *comments_; - }; - - - /** \brief Experimental and untested: represents an element of the "path" to access a node. - */ - class PathArgument - { - public: - friend class Path; - - PathArgument(); - PathArgument( ArrayIndex index ); - PathArgument( const char *key ); - PathArgument( const std::string &key ); - - private: - enum Kind - { - kindNone = 0, - kindIndex, - kindKey - }; - std::string key_; - ArrayIndex index_; - Kind kind_; - }; - - /** \brief Experimental and untested: represents a "path" to access a node. - * - * Syntax: - * - "." => root node - * - ".[n]" => elements at index 'n' of root node (an array value) - * - ".name" => member named 'name' of root node (an object value) - * - ".name1.name2.name3" - * - ".[0][1][2].name1[3]" - * - ".%" => member name is provided as parameter - * - ".[%]" => index is provied as parameter - */ - class Path - { - public: - Path( const std::string &path, - const PathArgument &a1 = PathArgument(), - const PathArgument &a2 = PathArgument(), - const PathArgument &a3 = PathArgument(), - const PathArgument &a4 = PathArgument(), - const PathArgument &a5 = PathArgument() ); - - const Value &resolve( const Value &root ) const; - Value resolve( const Value &root, - const Value &defaultValue ) const; - /// Creates the "path" to access the specified node and returns a reference on the node. - Value &make( Value &root ) const; - - private: - typedef std::vector InArgs; - typedef std::vector Args; - - void makePath( const std::string &path, - const InArgs &in ); - void addPathInArg( const std::string &path, - const InArgs &in, - InArgs::const_iterator &itInArg, - PathArgument::Kind kind ); - void invalidPath( const std::string &path, - int location ); - - Args args_; - }; - - - -#ifdef JSON_VALUE_USE_INTERNAL_MAP - /** \brief Allocator to customize Value internal map. - * Below is an example of a simple implementation (default implementation actually - * use memory pool for speed). - * \code - class DefaultValueMapAllocator : public ValueMapAllocator - { - public: // overridden from ValueMapAllocator - virtual ValueInternalMap *newMap() - { - return new ValueInternalMap(); - } - - virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) - { - return new ValueInternalMap( other ); - } - - virtual void destructMap( ValueInternalMap *map ) - { - delete map; - } - - virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) - { - return new ValueInternalLink[size]; - } - - virtual void releaseMapBuckets( ValueInternalLink *links ) - { - delete [] links; - } - - virtual ValueInternalLink *allocateMapLink() - { - return new ValueInternalLink(); - } - - virtual void releaseMapLink( ValueInternalLink *link ) - { - delete link; - } - }; - * \endcode - */ - class JSON_API ValueMapAllocator - { - public: - virtual ~ValueMapAllocator(); - virtual ValueInternalMap *newMap() = 0; - virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0; - virtual void destructMap( ValueInternalMap *map ) = 0; - virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0; - virtual void releaseMapBuckets( ValueInternalLink *links ) = 0; - virtual ValueInternalLink *allocateMapLink() = 0; - virtual void releaseMapLink( ValueInternalLink *link ) = 0; - }; - - /** \brief ValueInternalMap hash-map bucket chain link (for internal use only). - * \internal previous_ & next_ allows for bidirectional traversal. - */ - class JSON_API ValueInternalLink - { - public: - enum { itemPerLink = 6 }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture. - enum InternalFlags { - flagAvailable = 0, - flagUsed = 1 - }; - - ValueInternalLink(); - - ~ValueInternalLink(); - - Value items_[itemPerLink]; - char *keys_[itemPerLink]; - ValueInternalLink *previous_; - ValueInternalLink *next_; - }; - - - /** \brief A linked page based hash-table implementation used internally by Value. - * \internal ValueInternalMap is a tradional bucket based hash-table, with a linked - * list in each bucket to handle collision. There is an addional twist in that - * each node of the collision linked list is a page containing a fixed amount of - * value. This provides a better compromise between memory usage and speed. - * - * Each bucket is made up of a chained list of ValueInternalLink. The last - * link of a given bucket can be found in the 'previous_' field of the following bucket. - * The last link of the last bucket is stored in tailLink_ as it has no following bucket. - * Only the last link of a bucket may contains 'available' item. The last link always - * contains at least one element unless is it the bucket one very first link. - */ - class JSON_API ValueInternalMap - { - friend class ValueIteratorBase; - friend class Value; - public: - typedef unsigned int HashKey; - typedef unsigned int BucketIndex; - -# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - struct IteratorState - { - IteratorState() - : map_(0) - , link_(0) - , itemIndex_(0) - , bucketIndex_(0) - { - } - ValueInternalMap *map_; - ValueInternalLink *link_; - BucketIndex itemIndex_; - BucketIndex bucketIndex_; - }; -# endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - - ValueInternalMap(); - ValueInternalMap( const ValueInternalMap &other ); - ValueInternalMap &operator =( const ValueInternalMap &other ); - ~ValueInternalMap(); - - void swap( ValueInternalMap &other ); - - BucketIndex size() const; - - void clear(); - - bool reserveDelta( BucketIndex growth ); - - bool reserve( BucketIndex newItemCount ); - - const Value *find( const char *key ) const; - - Value *find( const char *key ); - - Value &resolveReference( const char *key, - bool isStatic ); - - void remove( const char *key ); - - void doActualRemove( ValueInternalLink *link, - BucketIndex index, - BucketIndex bucketIndex ); - - ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex ); - - Value &setNewItem( const char *key, - bool isStatic, - ValueInternalLink *link, - BucketIndex index ); - - Value &unsafeAdd( const char *key, - bool isStatic, - HashKey hashedKey ); - - HashKey hash( const char *key ) const; - - int compare( const ValueInternalMap &other ) const; - - private: - void makeBeginIterator( IteratorState &it ) const; - void makeEndIterator( IteratorState &it ) const; - static bool equals( const IteratorState &x, const IteratorState &other ); - static void increment( IteratorState &iterator ); - static void incrementBucket( IteratorState &iterator ); - static void decrement( IteratorState &iterator ); - static const char *key( const IteratorState &iterator ); - static const char *key( const IteratorState &iterator, bool &isStatic ); - static Value &value( const IteratorState &iterator ); - static int distance( const IteratorState &x, const IteratorState &y ); - - private: - ValueInternalLink *buckets_; - ValueInternalLink *tailLink_; - BucketIndex bucketsSize_; - BucketIndex itemCount_; - }; - - /** \brief A simplified deque implementation used internally by Value. - * \internal - * It is based on a list of fixed "page", each page contains a fixed number of items. - * Instead of using a linked-list, a array of pointer is used for fast item look-up. - * Look-up for an element is as follow: - * - compute page index: pageIndex = itemIndex / itemsPerPage - * - look-up item in page: pages_[pageIndex][itemIndex % itemsPerPage] - * - * Insertion is amortized constant time (only the array containing the index of pointers - * need to be reallocated when items are appended). - */ - class JSON_API ValueInternalArray - { - friend class Value; - friend class ValueIteratorBase; - public: - enum { itemsPerPage = 8 }; // should be a power of 2 for fast divide and modulo. - typedef Value::ArrayIndex ArrayIndex; - typedef unsigned int PageIndex; - -# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - struct IteratorState // Must be a POD - { - IteratorState() - : array_(0) - , currentPageIndex_(0) - , currentItemIndex_(0) - { - } - ValueInternalArray *array_; - Value **currentPageIndex_; - unsigned int currentItemIndex_; - }; -# endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - - ValueInternalArray(); - ValueInternalArray( const ValueInternalArray &other ); - ValueInternalArray &operator =( const ValueInternalArray &other ); - ~ValueInternalArray(); - void swap( ValueInternalArray &other ); - - void clear(); - void resize( ArrayIndex newSize ); - - Value &resolveReference( ArrayIndex index ); - - Value *find( ArrayIndex index ) const; - - ArrayIndex size() const; - - int compare( const ValueInternalArray &other ) const; - - private: - static bool equals( const IteratorState &x, const IteratorState &other ); - static void increment( IteratorState &iterator ); - static void decrement( IteratorState &iterator ); - static Value &dereference( const IteratorState &iterator ); - static Value &unsafeDereference( const IteratorState &iterator ); - static int distance( const IteratorState &x, const IteratorState &y ); - static ArrayIndex indexOf( const IteratorState &iterator ); - void makeBeginIterator( IteratorState &it ) const; - void makeEndIterator( IteratorState &it ) const; - void makeIterator( IteratorState &it, ArrayIndex index ) const; - - void makeIndexValid( ArrayIndex index ); - - Value **pages_; - ArrayIndex size_; - PageIndex pageCount_; - }; - - /** \brief Experimental: do not use. Allocator to customize Value internal array. - * Below is an example of a simple implementation (actual implementation use - * memory pool). - \code -class DefaultValueArrayAllocator : public ValueArrayAllocator -{ -public: // overridden from ValueArrayAllocator - virtual ~DefaultValueArrayAllocator() - { - } - - virtual ValueInternalArray *newArray() - { - return new ValueInternalArray(); - } - - virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) - { - return new ValueInternalArray( other ); - } - - virtual void destruct( ValueInternalArray *array ) - { - delete array; - } - - virtual void reallocateArrayPageIndex( Value **&indexes, - ValueInternalArray::PageIndex &indexCount, - ValueInternalArray::PageIndex minNewIndexCount ) - { - ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1; - if ( minNewIndexCount > newIndexCount ) - newIndexCount = minNewIndexCount; - void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount ); - if ( !newIndexes ) - throw std::bad_alloc(); - indexCount = newIndexCount; - indexes = static_cast( newIndexes ); - } - virtual void releaseArrayPageIndex( Value **indexes, - ValueInternalArray::PageIndex indexCount ) - { - if ( indexes ) - free( indexes ); - } - - virtual Value *allocateArrayPage() - { - return static_cast( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) ); - } - - virtual void releaseArrayPage( Value *value ) - { - if ( value ) - free( value ); - } -}; - \endcode - */ - class JSON_API ValueArrayAllocator - { - public: - virtual ~ValueArrayAllocator(); - virtual ValueInternalArray *newArray() = 0; - virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0; - virtual void destructArray( ValueInternalArray *array ) = 0; - /** \brief Reallocate array page index. - * Reallocates an array of pointer on each page. - * \param indexes [input] pointer on the current index. May be \c NULL. - * [output] pointer on the new index of at least - * \a minNewIndexCount pages. - * \param indexCount [input] current number of pages in the index. - * [output] number of page the reallocated index can handle. - * \b MUST be >= \a minNewIndexCount. - * \param minNewIndexCount Minimum number of page the new index must be able to - * handle. - */ - virtual void reallocateArrayPageIndex( Value **&indexes, - ValueInternalArray::PageIndex &indexCount, - ValueInternalArray::PageIndex minNewIndexCount ) = 0; - virtual void releaseArrayPageIndex( Value **indexes, - ValueInternalArray::PageIndex indexCount ) = 0; - virtual Value *allocateArrayPage() = 0; - virtual void releaseArrayPage( Value *value ) = 0; - }; -#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP - - - /** \brief base class for Value iterators. - * - */ - class ValueIteratorBase - { - public: - typedef unsigned int size_t; - typedef int difference_type; - typedef ValueIteratorBase SelfType; - - ValueIteratorBase(); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - explicit ValueIteratorBase( const Value::ObjectValues::iterator ¤t ); -#else - ValueIteratorBase( const ValueInternalArray::IteratorState &state ); - ValueIteratorBase( const ValueInternalMap::IteratorState &state ); -#endif - - bool operator ==( const SelfType &other ) const - { - return isEqual( other ); - } - - bool operator !=( const SelfType &other ) const - { - return !isEqual( other ); - } - - difference_type operator -( const SelfType &other ) const - { - return computeDistance( other ); - } - - /// Return either the index or the member name of the referenced value as a Value. - Value key() const; - - /// Return the index of the referenced Value. -1 if it is not an arrayValue. - UInt index() const; - - /// Return the member name of the referenced Value. "" if it is not an objectValue. - const char *memberName() const; - - protected: - Value &deref() const; - - void increment(); - - void decrement(); - - difference_type computeDistance( const SelfType &other ) const; - - bool isEqual( const SelfType &other ) const; - - void copy( const SelfType &other ); - - private: -#ifndef JSON_VALUE_USE_INTERNAL_MAP - Value::ObjectValues::iterator current_; - // Indicates that iterator is for a null value. - bool isNull_; -#else - union - { - ValueInternalArray::IteratorState array_; - ValueInternalMap::IteratorState map_; - } iterator_; - bool isArray_; -#endif - }; - - /** \brief const iterator for object and array value. - * - */ - class ValueConstIterator : public ValueIteratorBase - { - friend class Value; - public: - typedef unsigned int size_t; - typedef int difference_type; - typedef const Value &reference; - typedef const Value *pointer; - typedef ValueConstIterator SelfType; - - ValueConstIterator(); - private: - /*! \internal Use by Value to create an iterator. - */ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - explicit ValueConstIterator( const Value::ObjectValues::iterator ¤t ); -#else - ValueConstIterator( const ValueInternalArray::IteratorState &state ); - ValueConstIterator( const ValueInternalMap::IteratorState &state ); -#endif - public: - SelfType &operator =( const ValueIteratorBase &other ); - - SelfType operator++( int ) - { - SelfType temp( *this ); - ++*this; - return temp; - } - - SelfType operator--( int ) - { - SelfType temp( *this ); - --*this; - return temp; - } - - SelfType &operator--() - { - decrement(); - return *this; - } - - SelfType &operator++() - { - increment(); - return *this; - } - - reference operator *() const - { - return deref(); - } - }; - - - /** \brief Iterator for object and array value. - */ - class ValueIterator : public ValueIteratorBase - { - friend class Value; - public: - typedef unsigned int size_t; - typedef int difference_type; - typedef Value &reference; - typedef Value *pointer; - typedef ValueIterator SelfType; - - ValueIterator(); - ValueIterator( const ValueConstIterator &other ); - ValueIterator( const ValueIterator &other ); - private: - /*! \internal Use by Value to create an iterator. - */ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - explicit ValueIterator( const Value::ObjectValues::iterator ¤t ); -#else - ValueIterator( const ValueInternalArray::IteratorState &state ); - ValueIterator( const ValueInternalMap::IteratorState &state ); -#endif - public: - - SelfType &operator =( const SelfType &other ); - - SelfType operator++( int ) - { - SelfType temp( *this ); - ++*this; - return temp; - } - - SelfType operator--( int ) - { - SelfType temp( *this ); - --*this; - return temp; - } - - SelfType &operator--() - { - decrement(); - return *this; - } - - SelfType &operator++() - { - increment(); - return *this; - } - - reference operator *() const - { - return deref(); - } - }; - - -} // namespace CSJson - - -#endif // CPPTL_JSON_H_INCLUDED diff --git a/extensions/CCArmature/physics/CCColliderDetector.cpp b/extensions/CCArmature/physics/CCColliderDetector.cpp deleted file mode 100644 index 3b0c42d472..0000000000 --- a/extensions/CCArmature/physics/CCColliderDetector.cpp +++ /dev/null @@ -1,298 +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 "CCColliderDetector.h" -#include "../CCBone.h" -#include "../utils/CCTransformHelp.h" - -#if ENABLE_PHYSICS_BOX2D_DETECT -#include "Box2D/Box2D.h" -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT -#include "chipmunk.h" -#endif - - -NS_CC_EXT_BEGIN - -CCColliderDetector *CCColliderDetector::create() -{ - CCColliderDetector *pColliderDetector = new CCColliderDetector(); - if (pColliderDetector && pColliderDetector->init()) - { - pColliderDetector->autorelease(); - return pColliderDetector; - } - CC_SAFE_DELETE(pColliderDetector); - return NULL; -} - -CCColliderDetector *CCColliderDetector::create(CCBone *bone) -{ - CCColliderDetector *pColliderDetector = new CCColliderDetector(); - if (pColliderDetector && pColliderDetector->init(bone)) - { - pColliderDetector->autorelease(); - return pColliderDetector; - } - CC_SAFE_DELETE(pColliderDetector); - return NULL; -} - -CCColliderDetector::CCColliderDetector() - : m_pColliderBodyList(NULL) -{ -#if ENABLE_PHYSICS_BOX2D_DETECT - m_pB2Body = NULL; -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - m_pCPBody = NULL; -#endif -} - -CCColliderDetector::~CCColliderDetector() -{ - m_pColliderBodyList->removeAllObjects(); - CC_SAFE_DELETE(m_pColliderBodyList); -} - -bool CCColliderDetector::init() -{ - m_pColliderBodyList = CCArray::create(); - CCAssert(m_pColliderBodyList, "create m_pColliderBodyList failed!"); - m_pColliderBodyList->retain(); - - return true; -} - -bool CCColliderDetector::init(CCBone *bone) -{ - init(); - setBone(bone); - - return true; -} - -void CCColliderDetector::addContourData(CCContourData *contourData) -{ - ColliderBody *colliderBody = new ColliderBody(contourData); - m_pColliderBodyList->addObject(colliderBody); - colliderBody->release(); -} - -void CCColliderDetector::addContourDataList(CCArray *contourDataList) -{ - CCObject *object = NULL; - CCARRAY_FOREACH(contourDataList, object) - { - addContourData((CCContourData *)object); - } -} - -void CCColliderDetector::removeContourData(CCContourData *_contourData) -{ - m_pColliderBodyList->removeObject(_contourData); -} - -void CCColliderDetector::removeAll() -{ - m_pColliderBodyList->removeAllObjects(); -} - - -void CCColliderDetector::setActive(bool active) -{ -#if ENABLE_PHYSICS_BOX2D_DETECT - if (m_pB2Body) - { - m_pB2Body->SetActive(active); - } -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - if (m_pCPBody) - { - if (active) - { - cpBodyActivate(m_pCPBody); - } - else - { - cpBodySleep(m_pCPBody); - } - } -#endif -} - -CCArray *CCColliderDetector::getColliderBodyList() -{ - return m_pColliderBodyList; -} - - -CCPoint helpPoint; - -void CCColliderDetector::updateTransform(CCAffineTransform &t) -{ - CCObject *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) - { - ColliderBody *colliderBody = (ColliderBody *)object; - CCContourData *contourData = colliderBody->getContourData(); - -#if ENABLE_PHYSICS_BOX2D_DETECT - b2PolygonShape *shape = NULL; - if (m_pB2Body != NULL) - { - shape = (b2PolygonShape *)colliderBody->getB2Fixture()->GetShape(); - } -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - cpPolyShape *shape = NULL; - if (m_pCPBody != NULL) - { - shape = (cpPolyShape *)colliderBody->getShape(); - } -#endif - - //! update every vertex - const CCArray *array = &contourData->vertexList; - CCObject *object = NULL; - int i = 0; - CCARRAY_FOREACH(array, object) - { - CCContourVertex2 *cv = (CCContourVertex2 *)object; - - helpPoint.setPoint(cv->x, cv->y); - helpPoint = CCPointApplyAffineTransform(helpPoint, t); - -#if ENABLE_PHYSICS_BOX2D_DETECT - if (shape != NULL) - { - b2Vec2 &bv = shape->m_vertices[i]; - bv.Set(helpPoint.x / PT_RATIO, helpPoint.y / PT_RATIO); - } -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - if (shape != NULL) - { - cpVect v ; - v.x = helpPoint.x; - v.y = helpPoint.y; - shape->tVerts[i] = shape->verts[i] = v; - - cpVect b = shape->verts[(i+1)%shape->numVerts]; - cpVect n = cpvnormalize(cpvperp(cpvsub(b, shape->verts[i]))); - - shape->planes[i].n = n; - shape->planes[i].d = cpvdot(n, shape->verts[i]); - } -#endif - i++; - } - } -} - -#if ENABLE_PHYSICS_BOX2D_DETECT - -void CCColliderDetector::setB2Body(b2Body *pBody) -{ - m_pB2Body = pBody; - m_pB2Body->SetUserData(m_pBone); - - CCObject *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) - { - ColliderBody *colliderBody = (ColliderBody *)object; - - CCContourData *contourData = colliderBody->getContourData(); - const CCArray *array = &contourData->vertexList; - CCObject *object = NULL; - - b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.count()]; - - int i = 0; - CCARRAY_FOREACH(array, object) - { - CCContourVertex2 *v = (CCContourVertex2 *)object; - b2bv[i].Set(v->x / PT_RATIO, v->y / PT_RATIO); - i++; - } - - b2PolygonShape polygon; - polygon.Set(b2bv, contourData->vertexList.count()); - - CC_SAFE_DELETE(b2bv); - - b2FixtureDef fixtureDef; - fixtureDef.shape = &polygon; - fixtureDef.isSensor = true; - - b2Fixture *fixture = m_pB2Body->CreateFixture(&fixtureDef); - colliderBody->setB2Fixture(fixture); - } -} - -b2Body *CCColliderDetector::getB2Body() -{ - return m_pB2Body; -} - -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT -void CCColliderDetector::setCPBody(cpBody *pBody) -{ - m_pCPBody = pBody; - - CCObject *object = NULL; - CCARRAY_FOREACH(m_pColliderBodyList, object) - { - ColliderBody *colliderBody = (ColliderBody *)object; - - CCContourData *contourData = colliderBody->getContourData(); - const CCArray *array = &contourData->vertexList; - CCObject *object = NULL; - - int num = contourData->vertexList.count(); - CCContourVertex2 **vs = (CCContourVertex2 **)contourData->vertexList.data->arr; - cpVect *verts = new cpVect[num]; - for (int i=0; ix; - verts[num-1-i].y = vs[i]->y; - } - - cpShape* shape = cpPolyShapeNew(m_pCPBody, num, verts, cpvzero); - shape->sensor = true; - shape->data = m_pBone; - cpSpaceAddShape(m_pCPBody->space_private, shape); - - colliderBody->setShape(shape); - - delete []verts; - } -} - -cpBody *CCColliderDetector::getCPBody() -{ - return m_pCPBody; -} - -#endif - - -NS_CC_EXT_END diff --git a/extensions/CCArmature/physics/CCColliderDetector.h b/extensions/CCArmature/physics/CCColliderDetector.h deleted file mode 100644 index 3b66511c92..0000000000 --- a/extensions/CCArmature/physics/CCColliderDetector.h +++ /dev/null @@ -1,129 +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 __CCCOLLIDERDETECTOR_H__ -#define __CCCOLLIDERDETECTOR_H__ - -#include "../utils/CCArmatureDefine.h" -#include "../datas/CCDatas.h" - -#ifndef PT_RATIO -#define PT_RATIO 32 -#endif - - -class b2Body; -class b2Fixture; - -struct cpBody; -struct cpShape; - -NS_CC_EXT_BEGIN - -class CCBone; - -class ColliderBody : public CCObject -{ -public: -#if ENABLE_PHYSICS_BOX2D_DETECT - ColliderBody(CCContourData *contourData) - : m_pFixture(NULL) - , m_pContourData(contourData) - { - CC_SAFE_RETAIN(m_pContourData); - } -private: - CC_SYNTHESIZE(b2Fixture*, m_pFixture, B2Fixture) - -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - - ColliderBody(CCContourData *contourData) - : m_pShape(NULL) - , m_pContourData(contourData) - { - CC_SAFE_RETAIN(m_pContourData); - } -private: - CC_SYNTHESIZE(cpShape*, m_pShape, Shape) - -#endif - - -public: - ~ColliderBody() - { - CC_SAFE_RELEASE(m_pContourData); - } - - - inline CCContourData *getContourData() - { - return m_pContourData; - } - -private: - CCContourData *m_pContourData; -}; - -/* - * @brief ContourSprite used to draw the contour of the display - */ -class CCColliderDetector : public CCObject -{ -public: - static CCColliderDetector *create(); - static CCColliderDetector *create(CCBone *bone); -public: - CCColliderDetector(); - ~CCColliderDetector(void); - - virtual bool init(); - virtual bool init(CCBone *bone); - - void addContourData(CCContourData *contourData); - void addContourDataList(CCArray *contourDataList); - - void removeContourData(CCContourData *contourData); - void removeAll(); - - void updateTransform(CCAffineTransform &t); - - void setActive(bool active); - - CCArray *getColliderBodyList(); - -protected: - CCArray *m_pColliderBodyList; - CC_SYNTHESIZE(CCBone*, m_pBone, Bone); - -#if ENABLE_PHYSICS_BOX2D_DETECT - CC_PROPERTY(b2Body*, m_pB2Body, B2Body); -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_PROPERTY(cpBody*, m_pCPBody, CPBody); -#endif -}; - -NS_CC_EXT_END - -#endif /*__CCCOLLIDERDETECTOR_H__*/ diff --git a/extensions/CCArmature/utils/CCArmatureDataManager.cpp b/extensions/CCArmature/utils/CCArmatureDataManager.cpp deleted file mode 100644 index 9d1bc62e5f..0000000000 --- a/extensions/CCArmature/utils/CCArmatureDataManager.cpp +++ /dev/null @@ -1,196 +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 "CCArmatureDataManager.h" -#include "CCTransformHelp.h" -#include "CCDataReaderHelper.h" -#include "CCSpriteFrameCacheHelper.h" - - -NS_CC_EXT_BEGIN - -static CCArmatureDataManager *s_sharedArmatureDataManager = NULL; - -CCArmatureDataManager *CCArmatureDataManager::sharedArmatureDataManager() -{ - if (s_sharedArmatureDataManager == NULL) - { - s_sharedArmatureDataManager = new CCArmatureDataManager(); - if (!s_sharedArmatureDataManager || !s_sharedArmatureDataManager->init()) - { - CC_SAFE_DELETE(s_sharedArmatureDataManager); - } - } - return s_sharedArmatureDataManager; -} - -CCArmatureDataManager::CCArmatureDataManager(void) -{ - m_pArmarureDatas = NULL; - m_pAnimationDatas = NULL; - m_pTextureDatas = NULL; -} - - -CCArmatureDataManager::~CCArmatureDataManager(void) -{ - removeAll(); - - CC_SAFE_DELETE(m_pAnimationDatas); - CC_SAFE_DELETE(m_pArmarureDatas); - CC_SAFE_DELETE(m_pTextureDatas); -} - -void CCArmatureDataManager::purgeArmatureSystem() -{ - CCSpriteFrameCacheHelper::purgeSpriteFrameCacheHelper(); - CC_SAFE_RELEASE_NULL(s_sharedArmatureDataManager); -} - -bool CCArmatureDataManager::init() -{ - bool bRet = false; - do - { - m_pArmarureDatas = CCDictionary::create(); - CCAssert(m_pArmarureDatas, "create CCArmatureDataManager::m_pArmarureDatas fail!"); - m_pArmarureDatas->retain(); - - m_pAnimationDatas = CCDictionary::create(); - CCAssert(m_pAnimationDatas, "create CCArmatureDataManager::m_pAnimationDatas fail!"); - m_pAnimationDatas->retain(); - - m_pTextureDatas = CCDictionary::create(); - CCAssert(m_pTextureDatas, "create CCArmatureDataManager::m_pTextureDatas fail!"); - m_pTextureDatas->retain(); - - bRet = true; - } - while (0); - - return bRet; -} - -void CCArmatureDataManager::addArmatureData(const char *id, CCArmatureData *armatureData) -{ - if(m_pArmarureDatas) - { - m_pArmarureDatas->setObject(armatureData, id); - } -} - -CCArmatureData *CCArmatureDataManager::getArmatureData(const char *id) -{ - CCArmatureData *armatureData = NULL; - if (m_pArmarureDatas) - { - armatureData = (CCArmatureData *)m_pArmarureDatas->objectForKey(id); - } - return armatureData; -} - -void CCArmatureDataManager::addAnimationData(const char *id, CCAnimationData *animationData) -{ - if(m_pAnimationDatas) - { - m_pAnimationDatas->setObject(animationData, id); - } -} - -void CCArmatureDataManager::addTextureData(const char *id, CCTextureData *textureData) -{ - if(m_pTextureDatas) - { - m_pTextureDatas->setObject(textureData, id); - } -} - -CCAnimationData *CCArmatureDataManager::getAnimationData(const char *id) -{ - CCAnimationData *animationData = NULL; - if (m_pAnimationDatas) - { - animationData = (CCAnimationData *)m_pAnimationDatas->objectForKey(id); - } - return animationData; -} - -CCTextureData *CCArmatureDataManager::getTextureData(const char *id) -{ - CCTextureData *textureData = NULL; - if (m_pTextureDatas) - { - textureData = (CCTextureData *)m_pTextureDatas->objectForKey(id); - } - return textureData; -} - - - -void CCArmatureDataManager::addArmatureFileInfo(const char *armatureName, const char *useExistFileInfo, const char *imagePath, const char *plistPath, const char *configFilePath) -{ - addArmatureFileInfo(imagePath, plistPath, configFilePath); -} - -void CCArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) -{ - CCDataReaderHelper::addDataFromFile(configFilePath); - addSpriteFrameFromFile(plistPath, imagePath); -} - -void CCArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) -{ - // if(Game::sharedGame()->isUsePackage()) - // { - // CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromPak(plistPath, imagePath); - // } - // else - // { - // CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath); - // } - CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath); -} - - -void CCArmatureDataManager::removeAll() -{ - if( m_pAnimationDatas ) - { - m_pAnimationDatas->removeAllObjects(); - } - if( m_pArmarureDatas ) - { - m_pArmarureDatas->removeAllObjects(); - } - - if( m_pTextureDatas ) - { - m_pTextureDatas->removeAllObjects(); - } - - CCDataReaderHelper::clear(); -} - -NS_CC_EXT_END diff --git a/extensions/CCArmature/utils/CCArmatureDefine.h b/extensions/CCArmature/utils/CCArmatureDefine.h deleted file mode 100644 index aab765523c..0000000000 --- a/extensions/CCArmature/utils/CCArmatureDefine.h +++ /dev/null @@ -1,51 +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 __CCARMATUREDEFINE_H__ -#define __CCARMATUREDEFINE_H__ - -//#define _USRDLL 1 - -#include "cocos2d.h" -#include "ExtensionMacros.h" - -#define VERSION_COMBINED 0.25f - -#ifndef ENABLE_PHYSICS_BOX2D_DETECT -#define ENABLE_PHYSICS_BOX2D_DETECT 0 -#endif - -#ifndef ENABLE_PHYSICS_CHIPMUNK_DETECT -#define ENABLE_PHYSICS_CHIPMUNK_DETECT 1 -#endif - -#define MAX_VERTEXZ_VALUE 5000000.0f -#define ARMATURE_MAX_CHILD 50.0f -#define ARMATURE_MAX_ZORDER 100 -#define ARMATURE_MAX_COUNT ((MAX_VERTEXZ_VALUE) / (ARMATURE_MAX_CHILD) / ARMATURE_MAX_ZORDER) - -#define CS_RETURN_IF(cond) if (cond) return -#define CS_RETURN_NULL_IF(cond) if (cond) return NULL; - -#endif /*__CCARMATUREDEFINE_H__*/ diff --git a/extensions/CCArmature/utils/CCDataReaderHelper.cpp b/extensions/CCArmature/utils/CCDataReaderHelper.cpp deleted file mode 100644 index 8b6be9f72b..0000000000 --- a/extensions/CCArmature/utils/CCDataReaderHelper.cpp +++ /dev/null @@ -1,1191 +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_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_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"; - - -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) -{ - s_PositionReadScale = scale; -} - -float CCDataReaderHelper::getPositionReadScale() -{ - return s_PositionReadScale; -} - -void CCDataReaderHelper::clear() -{ - s_arrConfigFileList.clear(); -} - -void CCDataReaderHelper::addDataFromFile(const char *filePath) -{ - /* - * Check if file is already added to CCArmatureDataManager, 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); - - - std::string filePathStr = filePath; - size_t startPos = filePathStr.find_last_of("."); - std::string str = &filePathStr[startPos]; - - if (str.compare(".xml") == 0) - { - CCDataReaderHelper::addDataFromXML(filePathStr.c_str()); - } - else if(str.compare(".json") == 0 || str.compare(".ExportJson") == 0) - { - CCDataReaderHelper::addDataFromJson(filePathStr.c_str()); - } -} - - - -void CCDataReaderHelper::addDataFromXML(const char *xmlPath) -{ - /* - * Need to get the full path of the xml file, or the Tiny XML can't find the xml at IOS - */ - std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(xmlPath); - - /* - * Need to read the tiny xml into memory first, or the Tiny XML can't find the xml at IOS - */ - unsigned long size; - const char *pFileContent = (char *)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str() , "r", &size); - - if (pFileContent) - { - addDataFromCache(pFileContent); - } -} - -void CCDataReaderHelper::addDataFromXMLPak(const char *xmlPakPath) -{ - // #if CS_TOOL_PLATFORM - // - // char *_pFileContent = NULL; - // JsonReader::getFileBuffer(xmlPakPath, &_pFileContent); - // - // if (_pFileContent) - // { - // addDataFromCache(_pFileContent); - // } - // #endif -} - -void CCDataReaderHelper::addDataFromCache(const char *pFileContent) -{ - 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) - { - CCArmatureData *armatureData = CCDataReaderHelper::decodeArmature(armatureXML); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); - - armatureXML = armatureXML->NextSiblingElement(ARMATURE); - } - - /* - * Begin decode animation data from xml - */ - tinyxml2::XMLElement *animationsXML = root->FirstChildElement(ANIMATIONS); - tinyxml2::XMLElement *animationXML = animationsXML->FirstChildElement(ANIMATION); - while(animationXML) - { - CCAnimationData *animationData = CCDataReaderHelper::decodeAnimation(animationXML); - CCArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); - - 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) - { - CCTextureData *textureData = CCDataReaderHelper::decodeTexture(textureXML); - CCArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); - - textureXML = textureXML->NextSiblingElement(SUB_TEXTURE); - } - -} - -CCArmatureData *CCDataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML) -{ - const char *name = armatureXML->Attribute(A_NAME); - - - CCArmatureData *armatureData = CCArmatureData::create(); - 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); - } - } - - CCBoneData *boneData = decodeBone(boneXML, parentXML); - armatureData->addBoneData(boneData); - - boneXML = boneXML->NextSiblingElement(BONE); - } - - return armatureData; -} - -CCBoneData *CCDataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXml) -{ - - std::string name = boneXML->Attribute(A_NAME); - - CCAssert(name.length() != 0, ""); - - CCBoneData *boneData = CCBoneData::create(); - - boneData->name = name; - - if( boneXML->Attribute(A_PARENT) != NULL ) - { - boneData->parentName = boneXML->Attribute(A_PARENT); - } - - tinyxml2::XMLElement *displayXML = boneXML->FirstChildElement(DISPLAY); - while(displayXML) - { - CCDisplayData *displayData = decodeBoneDisplay(displayXML); - boneData->addDisplayData(displayData); - - displayXML = displayXML->NextSiblingElement(DISPLAY); - } - - return boneData; -} - -CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXML) -{ - int _isArmature = 0; - - CCDisplayData *displayData; - - if( displayXML->QueryIntAttribute(A_IS_ARMATURE, &(_isArmature)) == tinyxml2::XML_SUCCESS ) - { - if(!_isArmature) - { - displayData = CCSpriteDisplayData::create(); - displayData->displayType = CS_DISPLAY_SPRITE; - } - else - { - displayData = CCArmatureDisplayData::create(); - displayData->displayType = CS_DISPLAY_ARMATURE; - } - - } - else - { - displayData = CCSpriteDisplayData::create(); - displayData->displayType = CS_DISPLAY_SPRITE; - } - - if(displayXML->Attribute(A_NAME) != NULL ) - { - if(!_isArmature) - { - ((CCSpriteDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); - } - else - { - ((CCArmatureDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME); - } - - } - - return displayData; -} - -CCAnimationData *CCDataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animationXML) -{ - const char *name = animationXML->Attribute(A_NAME); - - - CCAnimationData *aniData = CCAnimationData::create(); - - CCArmatureData *armatureData = CCArmatureDataManager::sharedArmatureDataManager()->getArmatureData(name); - - aniData->name = name; - - tinyxml2::XMLElement *movementXML = animationXML->FirstChildElement(MOVEMENT); - - while( movementXML ) - { - CCMovementData *movementData = decodeMovement(movementXML, armatureData); - aniData->addMovement(movementData); - - movementXML = movementXML->NextSiblingElement(MOVEMENT); - - } - - return aniData; -} - -CCMovementData *CCDataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, CCArmatureData *armatureData) -{ - const char *movName = movementXML->Attribute(A_NAME); - - CCMovementData *movementData = CCMovementData::create(); - - 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; - } - - - CCBoneData *boneData = (CCBoneData *)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); - } - } - - CCMovementBoneData *_moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData); - movementData->addMovementBoneData(_moveBoneData); - - movBoneXml = movBoneXml->NextSiblingElement(BONE); - } - - return movementData; -} - - -CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, CCBoneData *boneData) -{ - CCMovementBoneData *movBoneData = CCMovementBoneData::create(); - 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++; - - } - } - - CCFrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData); - movBoneData->addFrameData(frameData); - - frameData->frameID = totalDuration; - totalDuration += frameData->duration; - movBoneData->duration = totalDuration; - - frameXML = frameXML->NextSiblingElement(FRAME); - } - - - // - CCFrameData *frameData = CCFrameData::create(); - frameData->copy((CCFrameData*)movBoneData->frameList.lastObject()); - frameData->frameID = movBoneData->duration; - movBoneData->addFrameData(frameData); - - - return movBoneData; -} - -CCFrameData *CCDataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, CCBoneData *boneData) -{ - float _x, _y, _scale_x, _scale_y, _skew_x, _skew_y = 0; - int _duration, _displayIndex, _zOrder, _tweenEasing = 0; - - CCFrameData *frameData = CCFrameData::create(); - - - 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; - } - - - 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 - */ - CCBaseData 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); - - CCTransformHelp::transformFromParent(*frameData, helpNode); - } - return frameData; -} - -CCTextureData *CCDataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML) -{ - CCTextureData *textureData = CCTextureData::create(); - - 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) - { - CCContourData *contourData = decodeContour(contourXML); - textureData->addContourData(contourData); - - contourXML = contourXML->NextSiblingElement(CONTOUR); - } - - return textureData; -} - -CCContourData *CCDataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML) -{ - CCContourData *contourData = CCContourData::create(); - - tinyxml2::XMLElement *vertexDataXML = contourXML->FirstChildElement(CONTOUR_VERTEX); - - while (vertexDataXML) - { - CCContourVertex2 *vertex = new CCContourVertex2(0, 0); - vertex->autorelease(); - - 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 CCDataReaderHelper::addDataFromJson(const char *filePath) -{ - unsigned long size; - std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(filePath); - const char *pFileContent = (char *)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str() , "r", &size); - - addDataFromJsonCache(pFileContent); -} - -void CCDataReaderHelper::addDataFromJsonCache(const char *fileContent) -{ - cs::CSJsonDictionary json; - json.initWithDescription(fileContent); - - // Decode armatures - int length = json.getArrayItemCount(ARMATURE_DATA); - for (int i = 0; i < length; i++) - { - cs::CSJsonDictionary *armatureDic = json.getSubItemFromArray(ARMATURE_DATA, i); - CCArmatureData *armatureData = decodeArmature(*armatureDic); - CCArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); - - delete armatureDic; - } - - // Decode animations - length = json.getArrayItemCount(ANIMATION_DATA); - for (int i = 0; i < length; i++) - { - cs::CSJsonDictionary *animationDic = json.getSubItemFromArray(ANIMATION_DATA, i); - CCAnimationData *animationData = decodeAnimation(*animationDic); - CCArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); - - delete animationDic; - } - - // Decode textures - length = json.getArrayItemCount(TEXTURE_DATA); - for (int i = 0; i < length; i++) - { - cs::CSJsonDictionary *textureDic = json.getSubItemFromArray(TEXTURE_DATA, i); - CCTextureData *textureData = decodeTexture(*textureDic); - CCArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); - - delete textureDic; - } -} - -CCArmatureData *CCDataReaderHelper::decodeArmature(cs::CSJsonDictionary &json) -{ - CCArmatureData *armatureData = CCArmatureData::create(); - - 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::CSJsonDictionary *dic = json.getSubItemFromArray(BONE_DATA, i); - armatureData->addBoneData(decodeBone(*dic)); - - delete dic; - } - - return armatureData; -} - -CCBoneData *CCDataReaderHelper::decodeBone(cs::CSJsonDictionary &json) -{ - CCBoneData *boneData = CCBoneData::create(); - - 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::CSJsonDictionary *dic = json.getSubItemFromArray(DISPLAY_DATA, i); - boneData->addDisplayData(decodeBoneDisplay(*dic)); - - delete dic; - } - - return boneData; -} - -CCDisplayData *CCDataReaderHelper::decodeBoneDisplay(cs::CSJsonDictionary &json) -{ - DisplayType displayType = (DisplayType)json.getItemIntValue(A_DISPLAY_TYPE, CS_DISPLAY_SPRITE); - - CCDisplayData *displayData = NULL; - - switch (displayType) - { - case CS_DISPLAY_SPRITE: - { - displayData = CCSpriteDisplayData::create(); - const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) - { - ((CCSpriteDisplayData *)displayData)->displayName = name; - } - - cs::CSJsonDictionary *dic = json.getSubItemFromArray(SKIN_DATA, 0); - if (dic != NULL) - { - CCSpriteDisplayData *sdd = (CCSpriteDisplayData *)displayData; - sdd->skinData.x = dic->getItemFloatValue(A_X, 0); - sdd->skinData.y = dic->getItemFloatValue(A_Y, 0); - 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 = CCArmatureDisplayData::create(); - const char *name = json.getItemStringValue(A_NAME); - if(name != NULL) - { - ((CCArmatureDisplayData *)displayData)->displayName = name; - } - } - break; - case CS_DISPLAY_PARTICLE: - { - displayData = CCParticleDisplayData::create(); - const char *plist = json.getItemStringValue(A_PLIST); - if(plist != NULL) - { - ((CCParticleDisplayData *)displayData)->plist = plist; - } - } - break; - case CS_DISPLAY_SHADER: - { - displayData = CCShaderDisplayData::create(); - const char *vert = json.getItemStringValue(A_VERT); - if(vert != NULL) - { - ((CCShaderDisplayData *)displayData)->vert = vert; - } - - const char *frag = json.getItemStringValue(A_FRAG); - if(frag != NULL) - { - ((CCShaderDisplayData *)displayData)->frag = vert; - } - - } - break; - default: - displayData = CCSpriteDisplayData::create(); - break; - } - - displayData->displayType = displayType; - - return displayData; -} - -CCAnimationData *CCDataReaderHelper::decodeAnimation(cs::CSJsonDictionary &json) -{ - CCAnimationData *aniData = CCAnimationData::create(); - - 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::CSJsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_DATA, i); - aniData->addMovement(decodeMovement(*dic)); - - delete dic; - } - - return aniData; -} - -CCMovementData *CCDataReaderHelper::decodeMovement(cs::CSJsonDictionary &json) -{ - CCMovementData *movementData = CCMovementData::create(); - - 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->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::CSJsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_BONE_DATA, i); - movementData->addMovementBoneData(decodeMovementBone(*dic)); - - delete dic; - } - - return movementData; -} - -CCMovementBoneData *CCDataReaderHelper::decodeMovementBone(cs::CSJsonDictionary &json) -{ - CCMovementBoneData *movementBoneData = CCMovementBoneData::create(); - - movementBoneData->delay = json.getItemFloatValue(A_MOVEMENT_DELAY, 0); - movementBoneData->scale = json.getItemFloatValue(A_MOVEMENT_SCALE, 1); - - 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::CSJsonDictionary *dic = json.getSubItemFromArray(FRAME_DATA, i); - CCFrameData *frameData = decodeFrame(*dic); - - movementBoneData->addFrameData(frameData); - - if (s_CocoStudioVersion < VERSION_COMBINED) - { - frameData->frameID = movementBoneData->duration; - movementBoneData->duration += frameData->duration; - } - - delete dic; - } - - if (s_CocoStudioVersion < VERSION_COMBINED) - { - CCFrameData *frameData = CCFrameData::create(); - frameData->copy((CCFrameData*)movementBoneData->frameList.lastObject()); - movementBoneData->addFrameData(frameData); - - frameData->frameID = movementBoneData->duration; - } - - return movementBoneData; -} - -CCFrameData *CCDataReaderHelper::decodeFrame(cs::CSJsonDictionary &json) -{ - CCFrameData *frameData = CCFrameData::create(); - - decodeNode(frameData, json); - - 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->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; -} - -CCTextureData *CCDataReaderHelper::decodeTexture(cs::CSJsonDictionary &json) -{ - CCTextureData *textureData = CCTextureData::create(); - - 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::CSJsonDictionary *dic = json.getSubItemFromArray(CONTOUR_DATA, i); - textureData->contourDataList.addObject(decodeContour(*dic)); - - delete dic; - } - - return textureData; -} - -CCContourData *CCDataReaderHelper::decodeContour(cs::CSJsonDictionary &json) -{ - CCContourData *contourData = CCContourData::create(); - - int length = json.getArrayItemCount(VERTEX_POINT); - for (int i = length - 1; i >= 0; i--) - { - cs::CSJsonDictionary *dic = json.getSubItemFromArray(VERTEX_POINT, i); - - CCContourVertex2 *vertex = new CCContourVertex2(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 CCDataReaderHelper::decodeNode(CCBaseData *node, cs::CSJsonDictionary &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::CSJsonDictionary *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_END diff --git a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp deleted file mode 100644 index 176a182e1b..0000000000 --- a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp +++ /dev/null @@ -1,188 +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 "CCSpriteFrameCacheHelper.h" - - -NS_CC_EXT_BEGIN - -CCSpriteFrameCacheHelper *CCSpriteFrameCacheHelper::s_SpriteFrameCacheHelper = NULL; - -CCSpriteFrameCacheHelper *CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper() -{ - if(!s_SpriteFrameCacheHelper) - { - s_SpriteFrameCacheHelper = new CCSpriteFrameCacheHelper(); - } - - return s_SpriteFrameCacheHelper; -} - -void CCSpriteFrameCacheHelper::purgeSpriteFrameCacheHelper() -{ - delete s_SpriteFrameCacheHelper; - s_SpriteFrameCacheHelper = NULL; -} - -void CCSpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) -{ - - std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(plistPath); - CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(path.c_str()); - - - CCTexture2D *pobTexture = CCTextureCache::sharedTextureCache()->addImage(imagePath); - - addSpriteFrameFromDict(dict, pobTexture, imagePath); - - dict->release(); - -} - -void CCSpriteFrameCacheHelper::addSpriteFrameFromDict(CCDictionary *dictionary, CCTexture2D *pobTexture, const char *imagePath) -{ - /* - Supported Zwoptex Formats: - - ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version - ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b - ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1 - ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+ - */ - - CCDictionary *metadataDict = (CCDictionary *)dictionary->objectForKey("metadata"); - CCDictionary *framesDict = (CCDictionary *)dictionary->objectForKey("frames"); - int format = 0; - - // get the format - if(metadataDict != NULL) - { - format = metadataDict->valueForKey("format")->intValue(); - } - - // check the format - CCAssert(format >= 0 && format <= 3, "format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:textureFilename:"); - - CCDictElement *pElement = NULL; - CCDICT_FOREACH(framesDict, pElement) - { - CCDictionary *frameDict = (CCDictionary *)pElement->getObject(); - std::string spriteFrameName = pElement->getStrKey(); - - m_Display2ImageMap[spriteFrameName] = imagePath; - - //CCLog("spriteFrameName : %s, imagePath : %s", spriteFrameName.c_str(), _imagePath); - - CCSpriteFrame *spriteFrame = (CCSpriteFrame *)CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrameName.c_str()); - if (spriteFrame) - { - continue; - } - - if(format == 0) - { - float x = frameDict->valueForKey("x")->floatValue(); - float y = frameDict->valueForKey("y")->floatValue(); - float w = frameDict->valueForKey("width")->floatValue(); - float h = frameDict->valueForKey("height")->floatValue(); - float ox = frameDict->valueForKey("offsetX")->floatValue(); - float oy = frameDict->valueForKey("offsetY")->floatValue(); - int ow = frameDict->valueForKey("originalWidth")->intValue(); - int oh = frameDict->valueForKey("originalHeight")->intValue(); - // check ow/oh - if(!ow || !oh) - { - CCLOG("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist"); - } - // abs ow/oh - ow = abs(ow); - oh = abs(oh); - // create frame - spriteFrame = new CCSpriteFrame(); - spriteFrame->initWithTexture(pobTexture, CCRectMake(x, y, w, h), false, CCPointMake(ox, oy), CCSizeMake((float)ow, (float)oh)); - } - else if(format == 1 || format == 2) - { - CCRect frame = CCRectFromString(frameDict->valueForKey("frame")->getCString()); - bool rotated = false; - - // rotation - if (format == 2) - { - rotated = frameDict->valueForKey("rotated")->boolValue(); - } - - CCPoint offset = CCPointFromString(frameDict->valueForKey("offset")->getCString()); - CCSize sourceSize = CCSizeFromString(frameDict->valueForKey("sourceSize")->getCString()); - - // create frame - spriteFrame = new CCSpriteFrame(); - spriteFrame->initWithTexture(pobTexture, frame, rotated, offset, sourceSize ); - } - else if (format == 3) - { - - } - - // add sprite frame - CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(spriteFrame, spriteFrameName.c_str()); - spriteFrame->release(); - } -} - -const char *CCSpriteFrameCacheHelper::getDisplayImagePath(const char *displayName) -{ - return m_Display2ImageMap[displayName].c_str(); -} - - -CCTextureAtlas *CCSpriteFrameCacheHelper::getTextureAtlasWithImageName(const char *imageName) -{ - CCTextureAtlas *atlas = (CCTextureAtlas*)m_pDisplay2TextureAtlas->objectForKey(imageName); - if (atlas == NULL) - { - atlas = CCTextureAtlas::createWithTexture(CCTextureCache::sharedTextureCache()->addImage(imageName), 4); - m_pDisplay2TextureAtlas->setObject(atlas, imageName); - } - - return atlas; -} - -CCTextureAtlas *CCSpriteFrameCacheHelper::getTextureAtlasWithDisplayName(const char *displayName) -{ - const char *textureName = getDisplayImagePath(displayName); - return getTextureAtlasWithImageName(textureName); -} - -CCSpriteFrameCacheHelper::CCSpriteFrameCacheHelper() -{ - m_pDisplay2TextureAtlas = new CCDictionary(); -} - -CCSpriteFrameCacheHelper::~CCSpriteFrameCacheHelper() -{ - CC_SAFE_RELEASE_NULL(m_pDisplay2TextureAtlas); -} - -NS_CC_EXT_END diff --git a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h deleted file mode 100644 index 66b47b9897..0000000000 --- a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h +++ /dev/null @@ -1,70 +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 __CCSPRITEFRAMECACHEHELPER_H__ -#define __CCSPRITEFRAMECACHEHELPER_H__ - -#include "CCArmatureDefine.h" -#include - -using namespace std; - -NS_CC_EXT_BEGIN - -class CCSpriteFrameCacheHelper -{ -public: - static CCSpriteFrameCacheHelper *sharedSpriteFrameCacheHelper(); - - static void purgeSpriteFrameCacheHelper(); -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 addSpriteFrameFromDict(CCDictionary *dictionary, CCTexture2D *pobTexture, const char *imagePath); - - /** - * Get this display in which image - */ - const char *getDisplayImagePath(const char *displayName); - - cocos2d::CCTextureAtlas *getTextureAtlasWithImageName(const char *imageName); - cocos2d::CCTextureAtlas *getTextureAtlasWithDisplayName(const char *displayName); - -private: - CCSpriteFrameCacheHelper(); - ~CCSpriteFrameCacheHelper(); - - std::map m_Display2ImageMap; - CCDictionary *m_pDisplay2TextureAtlas; - - static CCSpriteFrameCacheHelper *s_SpriteFrameCacheHelper; -}; - -NS_CC_EXT_END - -#endif /*__CCSPRITEFRAMECACHEHELPER_H__*/ diff --git a/extensions/CCArmature/utils/CCUtilMath.cpp b/extensions/CCArmature/utils/CCUtilMath.cpp deleted file mode 100644 index 3bc4dcbe23..0000000000 --- a/extensions/CCArmature/utils/CCUtilMath.cpp +++ /dev/null @@ -1,78 +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 "CCUtilMath.h" - - -NS_CC_EXT_BEGIN - -bool isSpriteContainPoint(CCSprite *sprite, CCPoint _point, CCPoint &outPoint) -{ - outPoint = sprite->convertToNodeSpace(_point); - - CCSize _s = sprite->getContentSize(); - CCRect _r(0, 0, _s.width, _s.height); - - return _r.containsPoint(outPoint); -} - -bool isSpriteContainPoint(CCSprite *_sprite, CCPoint _point) -{ - CCPoint _p = ccp(0, 0); - return isSpriteContainPoint(_sprite, _point, _p); -} - - -CCPoint bezierTo(float t, CCPoint &point1, CCPoint &point2, CCPoint &point3) -{ - - CCPoint p; - - p.x = pow((1 - t), 2) * point1.x + 2 * t * (1 - t) * point2.x + pow(t, 2) * point3.x; - p.y = pow((1 - t), 2) * point1.y + 2 * t * (1 - t) * point2.y + pow(t, 2) * point3.y; - - return p; -} - -CCPoint bezierTo(float t, CCPoint &point1, CCPoint &point2, CCPoint &point3, CCPoint &point4) -{ - CCPoint p; - - p.x = point1.x * pow((1 - t), 3) + 3 * t * point2.x * pow((1 - t), 2) + 3 * point3.x * pow(t, 2) * (1 - t) + point4.x * pow(t, 3); - p.y = point1.y * pow((1 - t), 3) + 3 * t * point2.y * pow((1 - t), 2) + 3 * point3.y * pow(t, 2) * (1 - t) + point4.y * pow(t, 3); - - return p; -} - -CCPoint circleTo(float t, CCPoint ¢er, float radius, float fromRadian, float radianDif) -{ - CCPoint p; - - p.x = center.x + radius * cos(fromRadian + radianDif * t); - p.y = center.y + radius * sin(fromRadian + radianDif * t); - - return p; -} - -NS_CC_EXT_END From b7b079c1c61a4fcf4b25a52bce080199009b6e3e Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Mon, 16 Sep 2013 12:02:57 +0800 Subject: [PATCH 19/28] standardize code --- extensions/CocoStudio/Armature/CCArmature.cpp | 16 ++++++++-------- extensions/CocoStudio/Armature/CCBone.cpp | 6 +++--- .../Armature/animation/CCArmatureAnimation.cpp | 4 ++-- .../CocoStudio/Armature/display/CCBatchNode.cpp | 2 +- .../Armature/display/CCDisplayManager.cpp | 2 +- .../Armature/physics/CCColliderDetector.cpp | 2 +- .../Armature/utils/CCArmatureDataManager.cpp | 6 +++--- .../Armature/utils/CCDataReaderHelper.cpp | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/extensions/CocoStudio/Armature/CCArmature.cpp b/extensions/CocoStudio/Armature/CCArmature.cpp index 6bcfcf0f5c..f42630464f 100644 --- a/extensions/CocoStudio/Armature/CCArmature.cpp +++ b/extensions/CocoStudio/Armature/CCArmature.cpp @@ -142,13 +142,13 @@ bool Armature::init(const char *name) _name = name; AnimationData *animationData = armatureDataManager->getAnimationData(name); - CCAssert(animationData, "AnimationData not exist! "); + CCASSERT(animationData, "AnimationData not exist! "); _animation->setAnimationData(animationData); ArmatureData *armatureData = armatureDataManager->getArmatureData(name); - CCAssert(armatureData, ""); + CCASSERT(armatureData, ""); _armatureData = armatureData; @@ -197,7 +197,7 @@ bool Armature::init(const char *name) } - setShaderProgram(CCShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); unscheduleUpdate(); scheduleUpdate(); @@ -251,8 +251,8 @@ 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 != NULL, "Argument must be non-nil"); + CCASSERT(_boneDic->objectForKey(bone->getName()) == NULL, "bone already added. It can't be added again"); if (NULL != parentName) { @@ -286,7 +286,7 @@ 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 != NULL, "bone must be added to the bone dictionary!"); bone->setArmature(NULL); bone->removeFromParent(recursion); @@ -308,7 +308,7 @@ 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 != NULL, "bone must be added to the bone dictionary!"); if(bone->getParentBone()) { @@ -423,7 +423,7 @@ const AffineTransform& Armature::getNodeToParentTransform() const void Armature::updateOffsetPoint() { // Set contentsize and Calculate anchor point. - Rect rect = boundingBox(); + Rect rect = getBoundingBox(); setContentSize(rect.size); _offsetPoint = Point(-rect.origin.x, -rect.origin.y); if (rect.size.width != 0 && rect.size.height != 0) diff --git a/extensions/CocoStudio/Armature/CCBone.cpp b/extensions/CocoStudio/Armature/CCBone.cpp index d15c7d8e6a..22efd6e3d8 100644 --- a/extensions/CocoStudio/Armature/CCBone.cpp +++ b/extensions/CocoStudio/Armature/CCBone.cpp @@ -129,7 +129,7 @@ bool Bone::init(const char *name) void Bone::setBoneData(BoneData *boneData) { - CCAssert(NULL != boneData, "_boneData must not be NULL"); + CCASSERT(NULL != boneData, "_boneData must not be NULL"); m_pBoneData = boneData; m_pBoneData->retain(); @@ -237,8 +237,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( NULL != child, "Argument must be non-nil"); + CCASSERT( NULL == child->_parentBone, "child already added. It can't be added again"); if(!_children) { diff --git a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp index 96543635a6..82ffd42501 100644 --- a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp +++ b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp @@ -185,10 +185,10 @@ void ArmatureAnimation::setAnimationInternal(float animationInternal) void ArmatureAnimation::play(const char *animationName, int durationTo, int durationTween, int loop, int tweenEasing) { - CCAssert(_animationData, "_animationData can not be null"); + CCASSERT(_animationData, "_animationData can not be null"); _movementData = _animationData->getMovement(animationName); - CCAssert(_movementData, "_movementData can not be null"); + CCASSERT(_movementData, "_movementData can not be null"); //! Get key frame count _rawDuration = _movementData->duration; diff --git a/extensions/CocoStudio/Armature/display/CCBatchNode.cpp b/extensions/CocoStudio/Armature/display/CCBatchNode.cpp index c52823e407..299d38a842 100644 --- a/extensions/CocoStudio/Armature/display/CCBatchNode.cpp +++ b/extensions/CocoStudio/Armature/display/CCBatchNode.cpp @@ -48,7 +48,7 @@ BatchNode::BatchNode() bool BatchNode::init() { bool ret = Node::init(); - setShaderProgram(CCShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return ret; } diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp index 8b3bd2b837..01103f392d 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp +++ b/extensions/CocoStudio/Armature/display/CCDisplayManager.cpp @@ -184,7 +184,7 @@ Array *DisplayManager::getDecorativeDisplayList() void DisplayManager::changeDisplayByIndex(int index, bool force) { - CCAssert( (_decoDisplayList ? index < (int)_decoDisplayList->count() : true), "the _index value is out of range"); + CCASSERT( (_decoDisplayList ? index < (int)_decoDisplayList->count() : true), "the _index value is out of range"); _forceChangeDisplay = force; diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp index cabdffc318..941b7d59c5 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp @@ -109,7 +109,7 @@ ColliderDetector::~ColliderDetector() bool ColliderDetector::init() { _colliderBodyList = Array::create(); - CCAssert(_colliderBodyList, "create _colliderBodyList failed!"); + CCASSERT(_colliderBodyList, "create _colliderBodyList failed!"); _colliderBodyList->retain(); return true; diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp index acded20944..4bdd9ca9e6 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp @@ -78,15 +78,15 @@ bool ArmatureDataManager::init() do { _armarureDatas = Dictionary::create(); - CCAssert(_armarureDatas, "create ArmatureDataManager::_armarureDatas fail!"); + CCASSERT(_armarureDatas, "create ArmatureDataManager::_armarureDatas fail!"); _armarureDatas->retain(); _animationDatas = Dictionary::create(); - CCAssert(_animationDatas, "create ArmatureDataManager::_animationDatas fail!"); + CCASSERT(_animationDatas, "create ArmatureDataManager::_animationDatas fail!"); _animationDatas->retain(); _textureDatas = Dictionary::create(); - CCAssert(_textureDatas, "create ArmatureDataManager::_textureDatas fail!"); + CCASSERT(_textureDatas, "create ArmatureDataManager::_textureDatas fail!"); _textureDatas->retain(); bRet = true; diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp index 89ae47ad8e..7bc1c7f55f 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp @@ -467,7 +467,7 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data document.Parse(pFileContent); tinyxml2::XMLElement *root = document.RootElement(); - CCAssert(root, "XML error or XML is empty."); + CCASSERT(root, "XML error or XML is empty."); root->QueryFloatAttribute(VERSION, &s_FlashToolVersion); From d8b64b86452c08561ae79b1c8129a4a6acc532d7 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Mon, 16 Sep 2013 12:21:18 +0800 Subject: [PATCH 20/28] standardize code --- extensions/CocoStudio/Armature/CCArmature.cpp | 15 ++-- extensions/CocoStudio/Armature/CCBone.cpp | 86 +++++++++---------- extensions/CocoStudio/Armature/CCBone.h | 16 ++-- 3 files changed, 59 insertions(+), 58 deletions(-) diff --git a/extensions/CocoStudio/Armature/CCArmature.cpp b/extensions/CocoStudio/Armature/CCArmature.cpp index f42630464f..22ec3d17ca 100644 --- a/extensions/CocoStudio/Armature/CCArmature.cpp +++ b/extensions/CocoStudio/Armature/CCArmature.cpp @@ -454,7 +454,7 @@ void Armature::update(float dt) Object *object = NULL; CCARRAY_FOREACH(_topBoneList, object) { - ((Bone *)object)->update(dt); + static_cast(object)->update(dt); } _armatureTransformDirty = false; @@ -483,7 +483,7 @@ void Armature::draw() { case CS_DISPLAY_SPRITE: { - Skin *skin = (Skin *)node; + Skin *skin = static_cast(node); TextureAtlas *textureAtlas = skin->getTextureAtlas(); BlendType blendType = bone->getBlendType(); @@ -513,7 +513,7 @@ void Armature::draw() break; case CS_DISPLAY_ARMATURE: { - Armature *armature = (Armature *)(node); + Armature *armature = static_cast(node); TextureAtlas *textureAtlas = armature->getTextureAtlas(); if(_atlas != textureAtlas) @@ -675,14 +675,15 @@ Rect Armature::getBoundingBox() const Bone *Armature::getBoneAtPoint(float x, float y) { - int length = _children->data->num; - Bone **bs = (Bone **)_children->data->arr; + int length = _children->count(); + Bone *bs; for(int i = length - 1; i >= 0; i--) { - if(bs[i]->getDisplayManager()->containPoint(x, y)) + bs = static_cast( _children->getObjectAtIndex(i) ); + if(bs->getDisplayManager()->containPoint(x, y)) { - return bs[i]; + return bs; } } return NULL; diff --git a/extensions/CocoStudio/Armature/CCBone.cpp b/extensions/CocoStudio/Armature/CCBone.cpp index 22efd6e3d8..9c10b69e8c 100644 --- a/extensions/CocoStudio/Armature/CCBone.cpp +++ b/extensions/CocoStudio/Armature/CCBone.cpp @@ -63,16 +63,16 @@ Bone::Bone() _tweenData = NULL; _parentBone = NULL; _armature = NULL; - m_pChildArmature = NULL; - m_pBoneData = NULL; + _childArmature = NULL; + _boneData = NULL; m_pTween = NULL; m_pTween = NULL; _children = NULL; - m_pDisplayManager = NULL; - m_bIgnoreMovementBoneData = false; - m_tWorldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0); - m_bBoneTransformDirty = true; - m_eBlendType = BLEND_NORMAL; + _displayManager = NULL; + _ignoreMovementBoneData = false; + _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0); + _boneTransformDirty = true; + _blendType = BLEND_NORMAL; } @@ -81,14 +81,14 @@ Bone::~Bone(void) CC_SAFE_DELETE(_tweenData); CC_SAFE_DELETE(_children); CC_SAFE_DELETE(m_pTween); - CC_SAFE_DELETE(m_pDisplayManager); + CC_SAFE_DELETE(_displayManager); - if(m_pBoneData) + if(_boneData) { - m_pBoneData->release(); + _boneData->release(); } - CC_SAFE_RELEASE(m_pChildArmature); + CC_SAFE_RELEASE(_childArmature); } bool Bone::init() @@ -115,9 +115,9 @@ bool Bone::init(const char *name) m_pTween = new Tween(); m_pTween->init(this); - CC_SAFE_DELETE(m_pDisplayManager); - m_pDisplayManager = new DisplayManager(); - m_pDisplayManager->init(this); + CC_SAFE_DELETE(_displayManager); + _displayManager = new DisplayManager(); + _displayManager->init(this); bRet = true; @@ -131,18 +131,18 @@ void Bone::setBoneData(BoneData *boneData) { CCASSERT(NULL != boneData, "_boneData must not be NULL"); - m_pBoneData = boneData; - m_pBoneData->retain(); + _boneData = boneData; + _boneData->retain(); - _name = m_pBoneData->name; - _ZOrder = m_pBoneData->zOrder; + _name = _boneData->name; + _ZOrder = _boneData->zOrder; - m_pDisplayManager->initDisplayList(boneData); + _displayManager->initDisplayList(boneData); } BoneData *Bone::getBoneData() { - return m_pBoneData; + return _boneData; } void Bone::setArmature(Armature *armature) @@ -163,28 +163,28 @@ Armature *Bone::getArmature() void Bone::update(float delta) { if (_parentBone) - m_bBoneTransformDirty = m_bBoneTransformDirty || _parentBone->isTransformDirty(); + _boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty(); - if (m_bBoneTransformDirty) + if (_boneTransformDirty) { if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) { - TransformHelp::nodeConcat(*_tweenData, *m_pBoneData); + TransformHelp::nodeConcat(*_tweenData, *_boneData); _tweenData->scaleX -= 1; _tweenData->scaleY -= 1; } - TransformHelp::nodeToMatrix(*_tweenData, m_tWorldTransform); + TransformHelp::nodeToMatrix(*_tweenData, _worldTransform); - m_tWorldTransform = AffineTransformConcat(getNodeToParentTransform(), m_tWorldTransform); + _worldTransform = AffineTransformConcat(getNodeToParentTransform(), _worldTransform); if(_parentBone) { - m_tWorldTransform = AffineTransformConcat(m_tWorldTransform, _parentBone->m_tWorldTransform); + _worldTransform = AffineTransformConcat(_worldTransform, _parentBone->_worldTransform); } } - DisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty || _armature->getArmatureTransformDirty()); + DisplayFactory::updateDisplay(this, _displayManager->getCurrentDecorativeDisplay(), delta, _boneTransformDirty || _armature->getArmatureTransformDirty()); Object *object = NULL; CCARRAY_FOREACH(_children, object) @@ -193,7 +193,7 @@ void Bone::update(float delta) childBone->update(delta); } - m_bBoneTransformDirty = false; + _boneTransformDirty = false; } @@ -213,7 +213,7 @@ void Bone::updateDisplayedOpacity(GLubyte parentOpacity) void Bone::updateColor() { - Node *display = m_pDisplayManager->getDisplayRenderNode(); + Node *display = _displayManager->getDisplayRenderNode(); RGBAProtocol *protocol = dynamic_cast(display); if(protocol != NULL) { @@ -226,7 +226,7 @@ void Bone::updateZOrder() { if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) { - int zorder = _tweenData->zOrder + m_pBoneData->zOrder; + int zorder = _tweenData->zOrder + _boneData->zOrder; setZOrder(zorder); } else @@ -296,17 +296,17 @@ Bone *Bone::getParentBone() void Bone::setChildArmature(Armature *armature) { - if (m_pChildArmature != armature) + if (_childArmature != armature) { CC_SAFE_RETAIN(armature); - CC_SAFE_RELEASE(m_pChildArmature); - m_pChildArmature = armature; + CC_SAFE_RELEASE(_childArmature); + _childArmature = armature; } } Armature *Bone::getChildArmature() { - return m_pChildArmature; + return _childArmature; } Tween *Bone::getTween() @@ -322,47 +322,47 @@ void Bone::setZOrder(int zOrder) void Bone::setTransformDirty(bool dirty) { - m_bBoneTransformDirty = dirty; + _boneTransformDirty = dirty; } bool Bone::isTransformDirty() { - return m_bBoneTransformDirty; + return _boneTransformDirty; } AffineTransform Bone::getNodeToArmatureTransform() const { - return m_tWorldTransform; + return _worldTransform; } AffineTransform Bone::getNodeToWorldTransform() const { - return AffineTransformConcat(m_tWorldTransform, _armature->getNodeToWorldTransform()); + return AffineTransformConcat(_worldTransform, _armature->getNodeToWorldTransform()); } Node *Bone::getDisplayRenderNode() { - return m_pDisplayManager->getDisplayRenderNode(); + return _displayManager->getDisplayRenderNode(); } void Bone::addDisplay(DisplayData *displayData, int index) { - m_pDisplayManager->addDisplay(displayData, index); + _displayManager->addDisplay(displayData, index); } void Bone::addDisplay(Node *display, int index) { - m_pDisplayManager->addDisplay(display, index); + _displayManager->addDisplay(display, index); } void Bone::changeDisplayByIndex(int index, bool force) { - m_pDisplayManager->changeDisplayByIndex(index, force); + _displayManager->changeDisplayByIndex(index, force); } Array *Bone::getColliderBodyList() { - if (DecorativeDisplay *decoDisplay = m_pDisplayManager->getCurrentDecorativeDisplay()) + if (DecorativeDisplay *decoDisplay = _displayManager->getCurrentDecorativeDisplay()) { if (ColliderDetector *detector = decoDisplay->getColliderDetector()) { diff --git a/extensions/CocoStudio/Armature/CCBone.h b/extensions/CocoStudio/Armature/CCBone.h index 20cf1080c9..8d1cd75c71 100644 --- a/extensions/CocoStudio/Armature/CCBone.h +++ b/extensions/CocoStudio/Armature/CCBone.h @@ -152,26 +152,26 @@ public: public: /* - * The origin state of the Bone. Display's state is effected by m_pBoneData, m_pNode, _tweenData + * 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 *, m_pBoneData, 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 *, m_pChildArmature, ChildArmature); + CC_PROPERTY(Armature *, _childArmature, ChildArmature); - CC_SYNTHESIZE(DisplayManager *, m_pDisplayManager, DisplayManager) + 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, m_bIgnoreMovementBoneData, IgnoreMovementBoneData) + CC_SYNTHESIZE(bool, _ignoreMovementBoneData, IgnoreMovementBoneData) - CC_SYNTHESIZE(BlendType, m_eBlendType, BlendType) + CC_SYNTHESIZE(BlendType, _blendType, BlendType) protected: Tween *m_pTween; //! Calculate tween effect @@ -181,10 +181,10 @@ protected: CC_SYNTHESIZE(std::string, _name, Name); Bone *_parentBone; //! A weak reference to its parent - bool m_bBoneTransformDirty; //! Whether or not transform dirty + bool _boneTransformDirty; //! Whether or not transform dirty //! self Transform, use this to change display's state - AffineTransform m_tWorldTransform; + AffineTransform _worldTransform; }; NS_CC_EXT_ARMATURE_END From 302555e7116a69a0d0b54602f09ce2664cffafdb Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Mon, 16 Sep 2013 14:13:55 +0800 Subject: [PATCH 21/28] standardizate code --- extensions/CocoStudio/Armature/CCArmature.h | 61 +- extensions/CocoStudio/Armature/CCBone.h | 6 +- .../animation/CCArmatureAnimation.cpp | 26 +- .../Armature/animation/CCArmatureAnimation.h | 7 + .../Armature/animation/CCProcessBase.cpp | 10 +- .../Armature/animation/CCProcessBase.h | 9 +- .../CocoStudio/Armature/animation/CCTween.cpp | 14 +- .../CocoStudio/Armature/animation/CCTween.h | 7 + .../CocoStudio/Armature/datas/CCDatas.cpp | 12 +- .../CocoStudio/Armature/datas/CCDatas.h | 91 + .../CocoStudio/Armature/display/CCBatchNode.h | 3 + .../Armature/display/CCDecorativeDisplay.h | 7 + .../Armature/display/CCDisplayFactory.cpp | 5 +- .../Armature/display/CCDisplayManager.h | 7 + .../Armature/external_tool/sigslot.h | 2535 ----------------- .../Armature/physics/CCColliderDetector.h | 7 + .../Armature/utils/CCArmatureDataManager.h | 7 + .../Armature/utils/CCDataReaderHelper.h | 7 + .../Armature/utils/CCSpriteFrameCacheHelper.h | 7 + extensions/cocos-ext.h | 1 - extensions/proj.win32/libExtensions.vcxproj | 1 - .../proj.win32/libExtensions.vcxproj.filters | 6 - 22 files changed, 243 insertions(+), 2593 deletions(-) delete mode 100644 extensions/CocoStudio/Armature/external_tool/sigslot.h diff --git a/extensions/CocoStudio/Armature/CCArmature.h b/extensions/CocoStudio/Armature/CCArmature.h index a13f2722cc..204ab34d8a 100644 --- a/extensions/CocoStudio/Armature/CCArmature.h +++ b/extensions/CocoStudio/Armature/CCArmature.h @@ -29,12 +29,43 @@ THE SOFTWARE. #include "CCBone.h" #include "display/CCBatchNode.h" #include "animation/CCArmatureAnimation.h" +#include "utils/CCSpriteFrameCacheHelper.h" +#include "utils/CCArmatureDataManager.h" class b2Body; struct cpBody; NS_CC_EXT_ARMATURE_BEGIN +CC_DEPRECATED_ATTRIBUTE typedef ProcessBase CCProcessBase; +CC_DEPRECATED_ATTRIBUTE typedef BaseData CCBaseData; +CC_DEPRECATED_ATTRIBUTE typedef DisplayData CCDisplayData; +CC_DEPRECATED_ATTRIBUTE typedef SpriteDisplayData CCSpriteDisplayData; +CC_DEPRECATED_ATTRIBUTE typedef ArmatureDisplayData CCArmatureDisplayData; +CC_DEPRECATED_ATTRIBUTE typedef ParticleDisplayData CCParticleDisplayData; +CC_DEPRECATED_ATTRIBUTE typedef BoneData CCBoneData; +CC_DEPRECATED_ATTRIBUTE typedef FrameData CCFrameData; +CC_DEPRECATED_ATTRIBUTE typedef MovementBoneData CCMovementBoneData; +CC_DEPRECATED_ATTRIBUTE typedef MovementData CCMovementData; +CC_DEPRECATED_ATTRIBUTE typedef AnimationData CCAnimationData; +CC_DEPRECATED_ATTRIBUTE typedef ContourData CCContourData; +CC_DEPRECATED_ATTRIBUTE typedef TextureData CCTextureData; +CC_DEPRECATED_ATTRIBUTE typedef DecorativeDisplay CCDecorativeDisplay; +CC_DEPRECATED_ATTRIBUTE typedef DisplayData CCDisplayData; +CC_DEPRECATED_ATTRIBUTE typedef DisplayFactory CCDisplayFactory; +CC_DEPRECATED_ATTRIBUTE typedef BatchNode CCBatchNode; +CC_DEPRECATED_ATTRIBUTE typedef DecorativeDisplay CCDecorativeDisplay; +CC_DEPRECATED_ATTRIBUTE typedef DisplayManager CCDisplayManager; +CC_DEPRECATED_ATTRIBUTE typedef ColliderBody CCColliderBody; +CC_DEPRECATED_ATTRIBUTE typedef ColliderDetector CCColliderDetector; +CC_DEPRECATED_ATTRIBUTE typedef SpriteFrameCacheHelper CCSpriteFrameCacheHelper; +CC_DEPRECATED_ATTRIBUTE typedef TweenFunction CCTweenFunction; +CC_DEPRECATED_ATTRIBUTE typedef ArmatureData CCArmatureData; +CC_DEPRECATED_ATTRIBUTE typedef Bone CCBone; +CC_DEPRECATED_ATTRIBUTE typedef ArmatureAnimation CCArmatureAnimation; +CC_DEPRECATED_ATTRIBUTE typedef Armature CCArmature; +CC_DEPRECATED_ATTRIBUTE typedef ArmatureDataManager CCArmatureDataManager; + class Armature : public NodeRGBA, public BlendProtocol { @@ -58,6 +89,10 @@ public: public: Armature(); + /** + * @js NA + * @lua NA + */ ~Armature(void); /** @@ -113,26 +148,26 @@ public: Bone *getBoneAtPoint(float x, float y); - virtual void visit(); - virtual void update(float dt); - virtual void draw(); + // overrides + /** + * @js NA + * @lua NA + */ + virtual void visit() override; + virtual void update(float dt) override; + virtual void draw() override; - virtual const AffineTransform& getNodeToParentTransform() const; + virtual const AffineTransform& getNodeToParentTransform() const override; + + inline void setBlendFunc(const BlendFunc &blendFunc) override { _blendFunc = blendFunc; } + inline const BlendFunc &getBlendFunc(void) const override{ return _blendFunc; } + /** * Set contentsize and Calculate anchor point. */ virtual void updateOffsetPoint(); - inline void setBlendFunc(const BlendFunc &blendFunc) - { - _blendFunc = blendFunc; - } - inline const BlendFunc &getBlendFunc(void) const - { - return _blendFunc; - } - virtual void setAnimation(ArmatureAnimation *animation); virtual ArmatureAnimation *getAnimation(); diff --git a/extensions/CocoStudio/Armature/CCBone.h b/extensions/CocoStudio/Armature/CCBone.h index 8d1cd75c71..904e7ebbb3 100644 --- a/extensions/CocoStudio/Armature/CCBone.h +++ b/extensions/CocoStudio/Armature/CCBone.h @@ -54,6 +54,10 @@ public: public: Bone(); + /** + * @js NA + * @lua NA + */ virtual ~Bone(void); /** @@ -141,7 +145,7 @@ public: virtual bool isTransformDirty(); virtual AffineTransform getNodeToArmatureTransform() const; - virtual AffineTransform getNodeToWorldTransform() const; + virtual AffineTransform getNodeToWorldTransform() const override; Node *getDisplayRenderNode(); diff --git a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp index 82ffd42501..02c0e8d688 100644 --- a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp +++ b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.cpp @@ -93,7 +93,7 @@ void ArmatureAnimation:: pause() Object *object = NULL; CCARRAY_FOREACH(_tweenList, object) { - ((Tween *)object)->pause(); + static_cast(object)->pause(); } ProcessBase::pause(); } @@ -103,7 +103,7 @@ void ArmatureAnimation::resume() Object *object = NULL; CCARRAY_FOREACH(_tweenList, object) { - ((Tween *)object)->resume(); + static_cast(object)->resume(); } ProcessBase::resume(); } @@ -113,7 +113,7 @@ void ArmatureAnimation::stop() Object *object = NULL; CCARRAY_FOREACH(_tweenList, object) { - ((Tween *)object)->stop(); + static_cast(object)->stop(); } _tweenList->removeAllObjects(); ProcessBase::stop(); @@ -145,7 +145,7 @@ void ArmatureAnimation::setSpeedScale(float speedScale) Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { - Bone *bone = (Bone *)element->getObject(); + Bone *bone = static_cast(element->getObject()); bone->getTween()->setProcessScale(_processScale); if (bone->getChildArmature()) @@ -173,7 +173,7 @@ void ArmatureAnimation::setAnimationInternal(float animationInternal) Dictionary *dict = _armature->getBoneDic(); CCDICT_FOREACH(dict, element) { - Bone *bone = (Bone *)element->getObject(); + Bone *bone = static_cast(element->getObject()); bone->getTween()->setAnimationInternal(_animationInternal); if (bone->getChildArmature()) { @@ -236,8 +236,8 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura CCDICT_FOREACH(dict, element) { - Bone *bone = (Bone *)element->getObject(); - movementBoneData = (MovementBoneData *)_movementData->movBoneDataDic.objectForKey(bone->getName()); + Bone *bone = static_cast(element->getObject()); + movementBoneData = static_cast(_movementData->movBoneDataDic.objectForKey(bone->getName())); Tween *tween = bone->getTween(); if(movementBoneData && movementBoneData->frameList.count() > 0) @@ -291,7 +291,7 @@ void ArmatureAnimation::update(float dt) Object *object = NULL; CCARRAY_FOREACH(_tweenList, object) { - ((Tween *)object)->update(dt); + static_cast(object)->update(dt); } } @@ -304,7 +304,7 @@ void ArmatureAnimation::updateHandler() case ANIMATION_NO_LOOP: { _loopType = ANIMATION_MAX; - _currentFrame = (_currentPercent - 1) * m_iNextFrameIndex; + _currentFrame = (_currentPercent - 1) * _nextFrameIndex; _currentPercent = _currentFrame / _durationTween; if (_currentPercent >= 1.0f) @@ -312,7 +312,7 @@ void ArmatureAnimation::updateHandler() } else { - m_iNextFrameIndex = _durationTween; + _nextFrameIndex = _durationTween; if (_movementEventTarget && _movementEventCallFunc) { @@ -340,8 +340,8 @@ void ArmatureAnimation::updateHandler() { _loopType = ANIMATION_LOOP_FRONT; _currentPercent = fmodf(_currentPercent, 1); - _currentFrame = m_iNextFrameIndex == 0 ? 0 : fmodf(_currentFrame, m_iNextFrameIndex); - m_iNextFrameIndex = _durationTween > 0 ? _durationTween : 1; + _currentFrame = _nextFrameIndex == 0 ? 0 : fmodf(_currentFrame, _nextFrameIndex); + _nextFrameIndex = _durationTween > 0 ? _durationTween : 1; if (_movementEventTarget && _movementEventCallFunc) { @@ -352,7 +352,7 @@ void ArmatureAnimation::updateHandler() default: { //_currentPercent = fmodf(_currentPercent, 1); - _currentFrame = fmodf(_currentFrame, m_iNextFrameIndex); + _currentFrame = fmodf(_currentFrame, _nextFrameIndex); _toIndex = 0; if (_movementEventTarget && _movementEventCallFunc) diff --git a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h index d8813ef31b..967878874a 100644 --- a/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h +++ b/extensions/CocoStudio/Armature/animation/CCArmatureAnimation.h @@ -58,7 +58,14 @@ public: */ static ArmatureAnimation *create(Armature *armature); public: + /** + * @js ctor + */ ArmatureAnimation(); + /** + * @js NA + * @lua NA + */ virtual ~ArmatureAnimation(void); /** diff --git a/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp b/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp index c17137f1c3..00609f83b8 100644 --- a/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp +++ b/extensions/CocoStudio/Armature/animation/CCProcessBase.cpp @@ -42,7 +42,7 @@ ProcessBase::ProcessBase(void) , _isLoopBack(false) { /* - * set _animationInternal defualt value to CCDirector::sharedDirector() + * set _animationInternal defualt value to Director::getInstance() * ->getAnimationInterval(), in line with game update speed */ _animationInternal = CCDirector::getInstance()->getAnimationInterval(); @@ -86,7 +86,7 @@ void ProcessBase::play(void *animation, int durationTo, int durationTween, int * Set m_iTotalFrames to durationTo, it is used for change tween between two animation. * When changing end, m_iTotalFrames will be setted to _durationTween */ - m_iNextFrameIndex = durationTo; + _nextFrameIndex = durationTo; _tweenEasing = (CCTweenType)tweenEasing; } @@ -108,7 +108,7 @@ void ProcessBase::update(float dt) return; } - if (m_iNextFrameIndex <= 0) + if (_nextFrameIndex <= 0) { _currentPercent = 1; _currentFrame = 0; @@ -123,13 +123,13 @@ void ProcessBase::update(float dt) _currentFrame += _processScale * (dt / _animationInternal); - _currentPercent = _currentFrame / m_iNextFrameIndex; + _currentPercent = _currentFrame / _nextFrameIndex; /* * if _currentFrame is bigger or equal than m_iTotalFrames, then reduce it util _currentFrame is * smaller than m_iTotalFrames */ - _currentFrame = fmodf(_currentFrame, m_iNextFrameIndex); + _currentFrame = fmodf(_currentFrame, _nextFrameIndex); } updateHandler(); diff --git a/extensions/CocoStudio/Armature/animation/CCProcessBase.h b/extensions/CocoStudio/Armature/animation/CCProcessBase.h index fe1388aa6a..5ee5a1ca01 100644 --- a/extensions/CocoStudio/Armature/animation/CCProcessBase.h +++ b/extensions/CocoStudio/Armature/animation/CCProcessBase.h @@ -50,7 +50,14 @@ enum AnimationType class ProcessBase : public Object { public: + /** + * @js ctor + */ ProcessBase(void); + /** + * @js NA + * @lua NA + */ ~ProcessBase(void); /** @@ -156,7 +163,7 @@ protected: int _curFrameIndex; //! Next frame this process need run to - int m_iNextFrameIndex; + int _nextFrameIndex; bool _isLoopBack; diff --git a/extensions/CocoStudio/Armature/animation/CCTween.cpp b/extensions/CocoStudio/Armature/animation/CCTween.cpp index 1cdf1354ea..22893e3dd6 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.cpp +++ b/extensions/CocoStudio/Armature/animation/CCTween.cpp @@ -190,7 +190,7 @@ void Tween::updateHandler() } else { - _currentPercent = (_currentPercent - 1) * m_iNextFrameIndex / _durationTween; + _currentPercent = (_currentPercent - 1) * _nextFrameIndex / _durationTween; } if (_currentPercent >= 1) @@ -202,8 +202,8 @@ void Tween::updateHandler() } else { - m_iNextFrameIndex = _durationTween; - _currentFrame = _currentPercent * m_iNextFrameIndex; + _nextFrameIndex = _durationTween; + _currentFrame = _currentPercent * _nextFrameIndex; _totalDuration = 0; _betweenDuration = 0; _fromIndex = _toIndex = 0; @@ -215,13 +215,13 @@ void Tween::updateHandler() { _loopType = ANIMATION_LOOP_BACK; - m_iNextFrameIndex = _durationTween > 0 ? _durationTween : 1; + _nextFrameIndex = _durationTween > 0 ? _durationTween : 1; if (_movementBoneData->delay != 0) { // - _currentFrame = (1 - _movementBoneData->delay) * (float)m_iNextFrameIndex; - _currentPercent = _currentFrame / m_iNextFrameIndex; + _currentFrame = (1 - _movementBoneData->delay) * (float)_nextFrameIndex; + _currentPercent = _currentFrame / _nextFrameIndex; } else { @@ -243,7 +243,7 @@ void Tween::updateHandler() break; default: { - _currentFrame = fmodf(_currentFrame, m_iNextFrameIndex); + _currentFrame = fmodf(_currentFrame, _nextFrameIndex); _totalDuration = 0; _betweenDuration = 0; diff --git a/extensions/CocoStudio/Armature/animation/CCTween.h b/extensions/CocoStudio/Armature/animation/CCTween.h index 0b823cdcad..6069ccb0fb 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.h +++ b/extensions/CocoStudio/Armature/animation/CCTween.h @@ -43,7 +43,14 @@ public: */ static Tween *create(Bone *bone); public: + /** + * @js ctor + */ Tween(void); + /** + * @js NA + * @lua NA + */ virtual ~Tween(void); /** diff --git a/extensions/CocoStudio/Armature/datas/CCDatas.cpp b/extensions/CocoStudio/Armature/datas/CCDatas.cpp index 8b20214f68..ce1839059e 100644 --- a/extensions/CocoStudio/Armature/datas/CCDatas.cpp +++ b/extensions/CocoStudio/Armature/datas/CCDatas.cpp @@ -229,7 +229,7 @@ void BoneData::addDisplayData(DisplayData *displayData) DisplayData *BoneData::getDisplayData(int index) { - return (DisplayData *)displayDataList.getObjectAtIndex(index); + return static_cast(displayDataList.getObjectAtIndex(index)); } @@ -254,7 +254,7 @@ void ArmatureData::addBoneData(BoneData *boneData) BoneData *ArmatureData::getBoneData(const char *boneName) { - return (BoneData *)boneDataDic.objectForKey(boneName); + return static_cast(boneDataDic.objectForKey(boneName)); } FrameData::FrameData(void) @@ -312,7 +312,7 @@ void MovementBoneData::addFrameData(FrameData *frameData) FrameData *MovementBoneData::getFrameData(int index) { - return (FrameData *)frameList.getObjectAtIndex(index); + return static_cast(frameList.getObjectAtIndex(index)); } @@ -339,7 +339,7 @@ void MovementData::addMovementBoneData(MovementBoneData *movBoneData) MovementBoneData *MovementData::getMovementBoneData(const char *boneName) { - return (MovementBoneData *)movBoneDataDic.objectForKey(boneName); + return static_cast(movBoneDataDic.objectForKey(boneName)); } @@ -360,7 +360,7 @@ void AnimationData::addMovement(MovementData *movData) MovementData *AnimationData::getMovement(const char *movementName) { - return (MovementData *)movementDataDic.objectForKey(movementName); + return static_cast(movementDataDic.objectForKey(movementName)); } int AnimationData::getMovementCount() @@ -416,7 +416,7 @@ void TextureData::addContourData(ContourData *contourData) ContourData *TextureData::getContourData(int index) { - return (ContourData *)contourDataList.getObjectAtIndex(index); + return static_cast(contourDataList.getObjectAtIndex(index)); } diff --git a/extensions/CocoStudio/Armature/datas/CCDatas.h b/extensions/CocoStudio/Armature/datas/CCDatas.h index 75352f662d..7b69e9c438 100644 --- a/extensions/CocoStudio/Armature/datas/CCDatas.h +++ b/extensions/CocoStudio/Armature/datas/CCDatas.h @@ -65,7 +65,14 @@ class BaseData : public Object public: CC_CREATE_NO_PARAM_NO_INIT(BaseData) public: + /** + * @js ctor + */ BaseData(); + /** + * @js NA + * @lua NA + */ ~BaseData(void); /* @@ -126,7 +133,14 @@ public: static const char *changeDisplayToTexture(const char *displayName); public: + /** + * @js ctor + */ DisplayData(); + /** + * @js NA + * @lua NA + */ virtual ~DisplayData(void); DisplayType displayType; //! mark which type your display is @@ -139,7 +153,14 @@ class SpriteDisplayData : public DisplayData public: CC_CREATE_NO_PARAM_NO_INIT(SpriteDisplayData) public: + /** + * @js ctor + */ SpriteDisplayData(); + /** + * @js NA + * @lua NA + */ virtual ~SpriteDisplayData(); inline void setParam(const char *displayName) @@ -166,7 +187,14 @@ class ArmatureDisplayData : public DisplayData public: CC_CREATE_NO_PARAM_NO_INIT(ArmatureDisplayData) public: + /** + * @js ctor + */ ArmatureDisplayData(); + /** + * @js NA + * @lua NA + */ virtual ~ArmatureDisplayData(); inline void setParam(const char *displayName) @@ -192,7 +220,14 @@ class ParticleDisplayData : public DisplayData public: CC_CREATE_NO_PARAM_NO_INIT(ParticleDisplayData) public: + /** + * @js ctor + */ ParticleDisplayData(); + /** + * @js NA + * @lua NA + */ virtual ~ParticleDisplayData() {}; void setParam(const char *plist) @@ -217,7 +252,14 @@ class BoneData : public BaseData public: CC_CREATE_NO_PARAM(BoneData) public: + /** + * @js ctor + */ BoneData(void); + /** + * @js NA + * @lua NA + */ ~BoneData(void); virtual bool init(); @@ -242,7 +284,14 @@ class ArmatureData : public Object public: CC_CREATE_NO_PARAM(ArmatureData) public: + /** + * @js ctor + */ ArmatureData(); + /** + * @js NA + * @lua NA + */ ~ArmatureData(); bool init(); @@ -278,7 +327,14 @@ class FrameData : public BaseData public: CC_CREATE_NO_PARAM_NO_INIT(FrameData) public: + /** + * @js ctor + */ FrameData(); + /** + * @js NA + * @lua NA + */ ~FrameData(); virtual void copy(const BaseData *baseData); @@ -310,7 +366,14 @@ class MovementBoneData : public Object public: CC_CREATE_NO_PARAM(MovementBoneData) public: + /** + * @js ctor + */ MovementBoneData(); + /** + * @js NA + * @lua NA + */ ~MovementBoneData(void); virtual bool init(); @@ -332,7 +395,14 @@ class MovementData : public Object public: CC_CREATE_NO_PARAM_NO_INIT(MovementData) public: + /** + * @js ctor + */ MovementData(void); + /** + * @js NA + * @lua NA + */ ~MovementData(void); void addMovementBoneData(MovementBoneData *movBoneData); @@ -385,7 +455,14 @@ class AnimationData : public Object public: CC_CREATE_NO_PARAM_NO_INIT(AnimationData) public: + /** + * @js ctor + */ AnimationData(void); + /** + * @js NA + * @lua NA + */ ~AnimationData(void); void addMovement(MovementData *movData); @@ -418,7 +495,14 @@ class ContourData : public Object public: CC_CREATE_NO_PARAM(ContourData) public: + /** + * @js ctor + */ ContourData(); + /** + * @js NA + * @lua NA + */ ~ContourData(void); virtual bool init(); @@ -438,7 +522,14 @@ class TextureData : public Object public: CC_CREATE_NO_PARAM(TextureData) public: + /** + * @js ctor + */ TextureData(); + /** + * @js NA + * @lua NA + */ ~TextureData(void); virtual bool init(); diff --git a/extensions/CocoStudio/Armature/display/CCBatchNode.h b/extensions/CocoStudio/Armature/display/CCBatchNode.h index 9d3c89e498..b79fc97d5d 100644 --- a/extensions/CocoStudio/Armature/display/CCBatchNode.h +++ b/extensions/CocoStudio/Armature/display/CCBatchNode.h @@ -34,6 +34,9 @@ class BatchNode : public Node public: static BatchNode *create(); public: + /** + * @js ctor + */ BatchNode(); virtual bool init(); diff --git a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h index f8a0309592..2b08dce2a8 100644 --- a/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h +++ b/extensions/CocoStudio/Armature/display/CCDecorativeDisplay.h @@ -41,7 +41,14 @@ class DecorativeDisplay: public Object public: static DecorativeDisplay *create(); public: + /** + * @js ctor + */ DecorativeDisplay(void); + /** + * @js NA + * @lua NA + */ ~DecorativeDisplay(void); virtual bool init(); diff --git a/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp b/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp index f57a1e6519..1d23d79e1b 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp +++ b/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp @@ -80,11 +80,8 @@ void DisplayFactory::updateDisplay(Bone *bone, DecorativeDisplay *decoDisplay, f { do { -#if ENABLE_PHYSICS_BOX2D_DETECT CC_BREAK_IF(!detector->getBody()); -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - CC_BREAK_IF(!detector->getBody()); -#endif + Node *node = decoDisplay->getDisplay(); AffineTransform displayTransform = node->getNodeToParentTransform(); Point anchorPoint = node->getAnchorPointInPoints(); diff --git a/extensions/CocoStudio/Armature/display/CCDisplayManager.h b/extensions/CocoStudio/Armature/display/CCDisplayManager.h index 0e2ddcb968..94933f96b5 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayManager.h +++ b/extensions/CocoStudio/Armature/display/CCDisplayManager.h @@ -40,7 +40,14 @@ public: static DisplayManager *create(Bone *bone); public: + /** + * @js ctor + */ DisplayManager(); + /** + * @js NA + * @lua NA + */ ~DisplayManager(); bool init(Bone *bone); diff --git a/extensions/CocoStudio/Armature/external_tool/sigslot.h b/extensions/CocoStudio/Armature/external_tool/sigslot.h deleted file mode 100644 index 319bc29ae3..0000000000 --- a/extensions/CocoStudio/Armature/external_tool/sigslot.h +++ /dev/null @@ -1,2535 +0,0 @@ -// sigslot.h: Signal/Slot classes -// -// Written by Sarah Thompson (sarah@telergy.com) 2002. -// -// License: Public domain. You are free to use this code however you like, with the proviso that -// the author takes on no responsibility or liability for any use. -// -// QUICK DOCUMENTATION -// -// (see also the full documentation at http://sigslot.sourceforge.net/) -// -// #define switches -// SIGSLOT_PURE_ISO - Define this to force ISO C++ compliance. This also disables -// all of the thread safety support on platforms where it is -// available. -// -// SIGSLOT_USE_POSIX_THREADS - Force use of Posix threads when using a C++ compiler other than -// gcc on a platform that supports Posix threads. (When using gcc, -// this is the default - use SIGSLOT_PURE_ISO to disable this if -// necessary) -// -// SIGSLOT_DEFAULT_MT_POLICY - Where thread support is enabled, this defaults to multi_threaded_global. -// Otherwise, the default is single_threaded. #define this yourself to -// override the default. In pure ISO mode, anything other than -// single_threaded will cause a compiler error. -// -// PLATFORM NOTES -// -// Win32 - On Win32, the WIN32 symbol must be #defined. Most mainstream -// compilers do this by default, but you may need to define it -// yourself if your build environment is less standard. This causes -// the Win32 thread support to be compiled in and used automatically. -// -// Unix/Linux/BSD, etc. - If you're using gcc, it is assumed that you have Posix threads -// available, so they are used automatically. You can override this -// (as under Windows) with the SIGSLOT_PURE_ISO switch. If you're using -// something other than gcc but still want to use Posix threads, you -// need to #define SIGSLOT_USE_POSIX_THREADS. -// -// ISO C++ - If none of the supported platforms are detected, or if -// SIGSLOT_PURE_ISO is defined, all multithreading support is turned off, -// along with any code that might cause a pure ISO C++ environment to -// complain. Before you ask, gcc -ansi -pedantic won't compile this -// library, but gcc -ansi is fine. Pedantic mode seems to throw a lot of -// errors that aren't really there. If you feel like investigating this, -// please contact the author. -// -// -// THREADING MODES -// -// single_threaded - Your program is assumed to be single threaded from the point of view -// of signal/slot usage (i.e. all objects using signals and slots are -// created and destroyed from a single thread). Behaviour if objects are -// destroyed concurrently is undefined (i.e. you'll get the occasional -// segmentation fault/memory exception). -// -// multi_threaded_global - Your program is assumed to be multi threaded. Objects using signals and -// slots can be safely created and destroyed from any thread, even when -// connections exist. In multi_threaded_global mode, this is achieved by a -// single global mutex (actually a critical section on Windows because they -// are faster). This option uses less OS resources, but results in more -// opportunities for contention, possibly resulting in more context switches -// than are strictly necessary. -// -// multi_threaded_local - Behaviour in this mode is essentially the same as multi_threaded_global, -// except that each signal, and each object that inherits has_slots, all -// have their own mutex/critical section. In practice, this means that -// mutex collisions (and hence context switches) only happen if they are -// absolutely essential. However, on some platforms, creating a lot of -// mutexes can slow down the whole OS, so use this option with care. -// -// USING THE LIBRARY -// -// See the full documentation at http://sigslot.sourceforge.net/ -// -// - -#ifndef SIGSLOT_H__ -#define SIGSLOT_H__ - -#include -#include - -#if defined(SIGSLOT_PURE_ISO) || (!defined(WIN32) && !defined(__GNUG__) && !defined(SIGSLOT_USE_POSIX_THREADS)) -# define _SIGSLOT_SINGLE_THREADED -#elif defined(WIN32) -# define _SIGSLOT_HAS_WIN32_THREADS -# include -#elif defined(__GNUG__) || defined(SIGSLOT_USE_POSIX_THREADS) -# define _SIGSLOT_HAS_POSIX_THREADS -# include -#else -# define _SIGSLOT_SINGLE_THREADED -#endif - -#ifndef SIGSLOT_DEFAULT_MT_POLICY -# ifdef _SIGSLOT_SINGLE_THREADED -# define SIGSLOT_DEFAULT_MT_POLICY single_threaded -# else -# define SIGSLOT_DEFAULT_MT_POLICY multi_threaded_local -# endif -#endif - - -namespace sigslot { - - class single_threaded - { - public: - single_threaded() - { - ; - } - - virtual ~single_threaded() - { - ; - } - - virtual void lock() - { - ; - } - - virtual void unlock() - { - ; - } - }; - -#ifdef _SIGSLOT_HAS_WIN32_THREADS - // The multi threading policies only get compiled in if they are enabled. - class multi_threaded_global - { - public: - multi_threaded_global() - { - static bool isinitialised = false; - - if(!isinitialised) - { - InitializeCriticalSection(get_critsec()); - isinitialised = true; - } - } - - multi_threaded_global(const multi_threaded_global&) - { - ; - } - - virtual ~multi_threaded_global() - { - ; - } - - virtual void lock() - { - EnterCriticalSection(get_critsec()); - } - - virtual void unlock() - { - LeaveCriticalSection(get_critsec()); - } - - private: - CRITICAL_SECTION* get_critsec() - { - static CRITICAL_SECTION g_critsec; - return &g_critsec; - } - }; - - class multi_threaded_local - { - public: - multi_threaded_local() - { - InitializeCriticalSection(&m_critsec); - } - - multi_threaded_local(const multi_threaded_local&) - { - InitializeCriticalSection(&m_critsec); - } - - virtual ~multi_threaded_local() - { - DeleteCriticalSection(&m_critsec); - } - - virtual void lock() - { - EnterCriticalSection(&m_critsec); - } - - virtual void unlock() - { - LeaveCriticalSection(&m_critsec); - } - - private: - CRITICAL_SECTION m_critsec; - }; -#endif // _SIGSLOT_HAS_WIN32_THREADS - -#ifdef _SIGSLOT_HAS_POSIX_THREADS - // The multi threading policies only get compiled in if they are enabled. - class multi_threaded_global - { - public: - multi_threaded_global() - { - pthread_mutex_init(get_mutex(), NULL); - } - - multi_threaded_global(const multi_threaded_global&) - { - ; - } - - virtual ~multi_threaded_global() - { - ; - } - - virtual void lock() - { - pthread_mutex_lock(get_mutex()); - } - - virtual void unlock() - { - pthread_mutex_unlock(get_mutex()); - } - - private: - pthread_mutex_t* get_mutex() - { - static pthread_mutex_t g_mutex; - return &g_mutex; - } - }; - - class multi_threaded_local - { - public: - multi_threaded_local() - { - pthread_mutex_init(&m_mutex, NULL); - } - - multi_threaded_local(const multi_threaded_local&) - { - pthread_mutex_init(&m_mutex, NULL); - } - - virtual ~multi_threaded_local() - { - pthread_mutex_destroy(&m_mutex); - } - - virtual void lock() - { - pthread_mutex_lock(&m_mutex); - } - - virtual void unlock() - { - pthread_mutex_unlock(&m_mutex); - } - - private: - pthread_mutex_t m_mutex; - }; -#endif // _SIGSLOT_HAS_POSIX_THREADS - - template - class lock_block - { - public: - mt_policy *m_mutex; - - lock_block(mt_policy *mtx) - : m_mutex(mtx) - { - m_mutex->lock(); - } - - ~lock_block() - { - m_mutex->unlock(); - } - }; - - template - class has_slots; - - template - class _connection_base0 - { - public: - virtual has_slots* getdest() const = 0; - virtual void emit() = 0; - virtual _connection_base0* clone() = 0; - virtual _connection_base0* duplicate(has_slots* pnewdest) = 0; - }; - - template - class _connection_base1 - { - public: - virtual has_slots* getdest() const = 0; - virtual void emit(arg1_type) = 0; - virtual _connection_base1* clone() = 0; - virtual _connection_base1* duplicate(has_slots* pnewdest) = 0; - }; - - template - class _connection_base2 - { - public: - virtual has_slots* getdest() const = 0; - virtual void emit(arg1_type, arg2_type) = 0; - virtual _connection_base2* clone() = 0; - virtual _connection_base2* duplicate(has_slots* pnewdest) = 0; - }; - - template - class _connection_base3 - { - public: - virtual has_slots* getdest() const = 0; - virtual void emit(arg1_type, arg2_type, arg3_type) = 0; - virtual _connection_base3* clone() = 0; - virtual _connection_base3* duplicate(has_slots* pnewdest) = 0; - }; - - template - class _connection_base4 - { - public: - virtual has_slots* getdest() const = 0; - virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type) = 0; - virtual _connection_base4* clone() = 0; - virtual _connection_base4* duplicate(has_slots* pnewdest) = 0; - }; - - template - class _connection_base5 - { - public: - virtual has_slots* getdest() const = 0; - virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, - arg5_type) = 0; - virtual _connection_base5* clone() = 0; - virtual _connection_base5* duplicate(has_slots* pnewdest) = 0; - }; - - template - class _connection_base6 - { - public: - virtual has_slots* getdest() const = 0; - virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, - arg6_type) = 0; - virtual _connection_base6* clone() = 0; - virtual _connection_base6* duplicate(has_slots* pnewdest) = 0; - }; - - template - class _connection_base7 - { - public: - virtual has_slots* getdest() const = 0; - virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, - arg6_type, arg7_type) = 0; - virtual _connection_base7* clone() = 0; - virtual _connection_base7* duplicate(has_slots* pnewdest) = 0; - }; - - template - class _connection_base8 - { - public: - virtual has_slots* getdest() const = 0; - virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, - arg6_type, arg7_type, arg8_type) = 0; - virtual _connection_base8* clone() = 0; - virtual _connection_base8* duplicate(has_slots* pnewdest) = 0; - }; - - template - class _signal_base : public mt_policy - { - public: - virtual void slot_disconnect(has_slots* pslot) = 0; - virtual void slot_duplicate(const has_slots* poldslot, has_slots* pnewslot) = 0; - }; - - template - class has_slots : public mt_policy - { - private: - typedef std::set<_signal_base *> sender_set; - typedef typename sender_set::const_iterator const_iterator; - - public: - has_slots() - { - ; - } - - has_slots(const has_slots& hs) - : mt_policy(hs) - { - lock_block lock(this); - const_iterator it = hs.m_senders.begin(); - const_iterator itEnd = hs.m_senders.end(); - - while(it != itEnd) - { - (*it)->slot_duplicate(&hs, this); - m_senders.insert(*it); - ++it; - } - } - - void signal_connect(_signal_base* sender) - { - lock_block lock(this); - m_senders.insert(sender); - } - - void signal_disconnect(_signal_base* sender) - { - lock_block lock(this); - m_senders.erase(sender); - } - - virtual ~has_slots() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - const_iterator it = m_senders.begin(); - const_iterator itEnd = m_senders.end(); - - while(it != itEnd) - { - (*it)->slot_disconnect(this); - ++it; - } - - m_senders.erase(m_senders.begin(), m_senders.end()); - } - - private: - sender_set m_senders; - }; - - template - class _signal_base0 : public _signal_base - { - public: - typedef std::list<_connection_base0 *> connections_list; - - _signal_base0() - { - ; - } - - _signal_base0(const _signal_base0& s) - : _signal_base(s) - { - lock_block lock(this); - typename connections_list::const_iterator it = s.m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_connect(this); - m_connected_slots.push_back((*it)->clone()); - - ++it; - } - } - - ~_signal_base0() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - typename connections_list::const_iterator it = m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_disconnect(this); - delete *it; - - ++it; - } - - m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); - } - - void disconnect(has_slots* pclass) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == pclass) - { - delete *it; - m_connected_slots.erase(it); - pclass->signal_disconnect(this); - return; - } - - ++it; - } - } - - void slot_disconnect(has_slots* pslot) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - typename connections_list::iterator itNext = it; - ++itNext; - - if((*it)->getdest() == pslot) - { - delete *it; - m_connected_slots.erase(it); - } - - it = itNext; - } - } - - void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == oldtarget) - { - m_connected_slots.push_back((*it)->duplicate(newtarget)); - } - - ++it; - } - } - - protected: - connections_list m_connected_slots; - }; - - template - class _signal_base1 : public _signal_base - { - public: - typedef std::list<_connection_base1 *> connections_list; - - _signal_base1() - { - ; - } - - _signal_base1(const _signal_base1& s) - : _signal_base(s) - { - lock_block lock(this); - typename connections_list::const_iterator it = s.m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_connect(this); - m_connected_slots.push_back((*it)->clone()); - - ++it; - } - } - - void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == oldtarget) - { - m_connected_slots.push_back((*it)->duplicate(newtarget)); - } - - ++it; - } - } - - ~_signal_base1() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - typename connections_list::const_iterator it = m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_disconnect(this); - delete *it; - - ++it; - } - - m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); - } - - void disconnect(has_slots* pclass) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == pclass) - { - delete *it; - m_connected_slots.erase(it); - pclass->signal_disconnect(this); - return; - } - - ++it; - } - } - - void slot_disconnect(has_slots* pslot) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - typename connections_list::iterator itNext = it; - ++itNext; - - if((*it)->getdest() == pslot) - { - delete *it; - m_connected_slots.erase(it); - } - - it = itNext; - } - } - - - protected: - connections_list m_connected_slots; - }; - - template - class _signal_base2 : public _signal_base - { - public: - typedef std::list<_connection_base2 *> - connections_list; - - _signal_base2() - { - ; - } - - _signal_base2(const _signal_base2& s) - : _signal_base(s) - { - lock_block lock(this); - typename connections_list::const_iterator it = s.m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_connect(this); - m_connected_slots.push_back((*it)->clone()); - - ++it; - } - } - - void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == oldtarget) - { - m_connected_slots.push_back((*it)->duplicate(newtarget)); - } - - ++it; - } - } - - ~_signal_base2() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - typename connections_list::const_iterator it = m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_disconnect(this); - delete *it; - - ++it; - } - - m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); - } - - void disconnect(has_slots* pclass) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == pclass) - { - delete *it; - m_connected_slots.erase(it); - pclass->signal_disconnect(this); - return; - } - - ++it; - } - } - - void slot_disconnect(has_slots* pslot) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - typename connections_list::iterator itNext = it; - ++itNext; - - if((*it)->getdest() == pslot) - { - delete *it; - m_connected_slots.erase(it); - } - - it = itNext; - } - } - - protected: - connections_list m_connected_slots; - }; - - template - class _signal_base3 : public _signal_base - { - public: - typedef std::list<_connection_base3 *> - connections_list; - - _signal_base3() - { - ; - } - - _signal_base3(const _signal_base3& s) - : _signal_base(s) - { - lock_block lock(this); - typename connections_list::const_iterator it = s.m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_connect(this); - m_connected_slots.push_back((*it)->clone()); - - ++it; - } - } - - void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == oldtarget) - { - m_connected_slots.push_back((*it)->duplicate(newtarget)); - } - - ++it; - } - } - - ~_signal_base3() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - typename connections_list::const_iterator it = m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_disconnect(this); - delete *it; - - ++it; - } - - m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); - } - - void disconnect(has_slots* pclass) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == pclass) - { - delete *it; - m_connected_slots.erase(it); - pclass->signal_disconnect(this); - return; - } - - ++it; - } - } - - void slot_disconnect(has_slots* pslot) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - typename connections_list::iterator itNext = it; - ++itNext; - - if((*it)->getdest() == pslot) - { - delete *it; - m_connected_slots.erase(it); - } - - it = itNext; - } - } - - protected: - connections_list m_connected_slots; - }; - - template - class _signal_base4 : public _signal_base - { - public: - typedef std::list<_connection_base4 *> connections_list; - - _signal_base4() - { - ; - } - - _signal_base4(const _signal_base4& s) - : _signal_base(s) - { - lock_block lock(this); - typename connections_list::const_iterator it = s.m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_connect(this); - m_connected_slots.push_back((*it)->clone()); - - ++it; - } - } - - void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == oldtarget) - { - m_connected_slots.push_back((*it)->duplicate(newtarget)); - } - - ++it; - } - } - - ~_signal_base4() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - typename connections_list::const_iterator it = m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_disconnect(this); - delete *it; - - ++it; - } - - m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); - } - - void disconnect(has_slots* pclass) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == pclass) - { - delete *it; - m_connected_slots.erase(it); - pclass->signal_disconnect(this); - return; - } - - ++it; - } - } - - void slot_disconnect(has_slots* pslot) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - typename connections_list::iterator itNext = it; - ++itNext; - - if((*it)->getdest() == pslot) - { - delete *it; - m_connected_slots.erase(it); - } - - it = itNext; - } - } - - protected: - connections_list m_connected_slots; - }; - - template - class _signal_base5 : public _signal_base - { - public: - typedef std::list<_connection_base5 *> connections_list; - - _signal_base5() - { - ; - } - - _signal_base5(const _signal_base5& s) - : _signal_base(s) - { - lock_block lock(this); - typename connections_list::const_iterator it = s.m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_connect(this); - m_connected_slots.push_back((*it)->clone()); - - ++it; - } - } - - void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == oldtarget) - { - m_connected_slots.push_back((*it)->duplicate(newtarget)); - } - - ++it; - } - } - - ~_signal_base5() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - typename connections_list::const_iterator it = m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_disconnect(this); - delete *it; - - ++it; - } - - m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); - } - - void disconnect(has_slots* pclass) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == pclass) - { - delete *it; - m_connected_slots.erase(it); - pclass->signal_disconnect(this); - return; - } - - ++it; - } - } - - void slot_disconnect(has_slots* pslot) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - typename connections_list::iterator itNext = it; - ++itNext; - - if((*it)->getdest() == pslot) - { - delete *it; - m_connected_slots.erase(it); - } - - it = itNext; - } - } - - protected: - connections_list m_connected_slots; - }; - - template - class _signal_base6 : public _signal_base - { - public: - typedef std::list<_connection_base6 *> connections_list; - - _signal_base6() - { - ; - } - - _signal_base6(const _signal_base6& s) - : _signal_base(s) - { - lock_block lock(this); - typename connections_list::const_iterator it = s.m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_connect(this); - m_connected_slots.push_back((*it)->clone()); - - ++it; - } - } - - void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == oldtarget) - { - m_connected_slots.push_back((*it)->duplicate(newtarget)); - } - - ++it; - } - } - - ~_signal_base6() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - typename connections_list::const_iterator it = m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_disconnect(this); - delete *it; - - ++it; - } - - m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); - } - - void disconnect(has_slots* pclass) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == pclass) - { - delete *it; - m_connected_slots.erase(it); - pclass->signal_disconnect(this); - return; - } - - ++it; - } - } - - void slot_disconnect(has_slots* pslot) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - typename connections_list::iterator itNext = it; - ++itNext; - - if((*it)->getdest() == pslot) - { - delete *it; - m_connected_slots.erase(it); - } - - it = itNext; - } - } - - protected: - connections_list m_connected_slots; - }; - - template - class _signal_base7 : public _signal_base - { - public: - typedef std::list<_connection_base7 *> connections_list; - - _signal_base7() - { - ; - } - - _signal_base7(const _signal_base7& s) - : _signal_base(s) - { - lock_block lock(this); - typename connections_list::const_iterator it = s.m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_connect(this); - m_connected_slots.push_back((*it)->clone()); - - ++it; - } - } - - void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == oldtarget) - { - m_connected_slots.push_back((*it)->duplicate(newtarget)); - } - - ++it; - } - } - - ~_signal_base7() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - typename connections_list::const_iterator it = m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_disconnect(this); - delete *it; - - ++it; - } - - m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); - } - - void disconnect(has_slots* pclass) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == pclass) - { - delete *it; - m_connected_slots.erase(it); - pclass->signal_disconnect(this); - return; - } - - ++it; - } - } - - void slot_disconnect(has_slots* pslot) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - typename connections_list::iterator itNext = it; - ++itNext; - - if((*it)->getdest() == pslot) - { - delete *it; - m_connected_slots.erase(it); - } - - it = itNext; - } - } - - protected: - connections_list m_connected_slots; - }; - - template - class _signal_base8 : public _signal_base - { - public: - typedef std::list<_connection_base8 *> - connections_list; - - _signal_base8() - { - ; - } - - _signal_base8(const _signal_base8& s) - : _signal_base(s) - { - lock_block lock(this); - typename connections_list::const_iterator it = s.m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = s.m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_connect(this); - m_connected_slots.push_back((*it)->clone()); - - ++it; - } - } - - void slot_duplicate(const has_slots* oldtarget, has_slots* newtarget) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == oldtarget) - { - m_connected_slots.push_back((*it)->duplicate(newtarget)); - } - - ++it; - } - } - - ~_signal_base8() - { - disconnect_all(); - } - - void disconnect_all() - { - lock_block lock(this); - typename connections_list::const_iterator it = m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - (*it)->getdest()->signal_disconnect(this); - delete *it; - - ++it; - } - - m_connected_slots.erase(m_connected_slots.begin(), m_connected_slots.end()); - } - - void disconnect(has_slots* pclass) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - if((*it)->getdest() == pclass) - { - delete *it; - m_connected_slots.erase(it); - pclass->signal_disconnect(this); - return; - } - - ++it; - } - } - - void slot_disconnect(has_slots* pslot) - { - lock_block lock(this); - typename connections_list::iterator it = m_connected_slots.begin(); - typename connections_list::iterator itEnd = m_connected_slots.end(); - - while(it != itEnd) - { - typename connections_list::iterator itNext = it; - ++itNext; - - if((*it)->getdest() == pslot) - { - delete *it; - m_connected_slots.erase(it); - } - - it = itNext; - } - } - - protected: - connections_list m_connected_slots; - }; - - - template - class _connection0 : public _connection_base0 - { - public: - _connection0() - { - m_pobject = NULL; - m_pmemfun = NULL; - } - - _connection0(dest_type* pobject, void (dest_type::*pmemfun)()) - { - m_pobject = pobject; - m_pmemfun = pmemfun; - } - - virtual _connection_base0* clone() - { - return new _connection0(*this); - } - - virtual _connection_base0* duplicate(has_slots* pnewdest) - { - return new _connection0((dest_type *)pnewdest, m_pmemfun); - } - - virtual void emit() - { - (m_pobject->*m_pmemfun)(); - } - - virtual has_slots* getdest() const - { - return m_pobject; - } - - private: - dest_type* m_pobject; - void (dest_type::* m_pmemfun)(); - }; - - template - class _connection1 : public _connection_base1 - { - public: - _connection1() - { - m_pobject = NULL; - m_pmemfun = NULL; - } - - _connection1(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type)) - { - m_pobject = pobject; - m_pmemfun = pmemfun; - } - - virtual _connection_base1* clone() - { - return new _connection1(*this); - } - - virtual _connection_base1* duplicate(has_slots* pnewdest) - { - return new _connection1((dest_type *)pnewdest, m_pmemfun); - } - - virtual void emit(arg1_type a1) - { - (m_pobject->*m_pmemfun)(a1); - } - - virtual has_slots* getdest() const - { - return m_pobject; - } - - private: - dest_type* m_pobject; - void (dest_type::* m_pmemfun)(arg1_type); - }; - - template - class _connection2 : public _connection_base2 - { - public: - _connection2() - { - m_pobject = NULL; - m_pmemfun = NULL; - } - - _connection2(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, - arg2_type)) - { - m_pobject = pobject; - m_pmemfun = pmemfun; - } - - virtual _connection_base2* clone() - { - return new _connection2(*this); - } - - virtual _connection_base2* duplicate(has_slots* pnewdest) - { - return new _connection2((dest_type *)pnewdest, m_pmemfun); - } - - virtual void emit(arg1_type a1, arg2_type a2) - { - (m_pobject->*m_pmemfun)(a1, a2); - } - - virtual has_slots* getdest() const - { - return m_pobject; - } - - private: - dest_type* m_pobject; - void (dest_type::* m_pmemfun)(arg1_type, arg2_type); - }; - - template - class _connection3 : public _connection_base3 - { - public: - _connection3() - { - m_pobject = NULL; - m_pmemfun = NULL; - } - - _connection3(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, - arg2_type, arg3_type)) - { - m_pobject = pobject; - m_pmemfun = pmemfun; - } - - virtual _connection_base3* clone() - { - return new _connection3(*this); - } - - virtual _connection_base3* duplicate(has_slots* pnewdest) - { - return new _connection3((dest_type *)pnewdest, m_pmemfun); - } - - virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3) - { - (m_pobject->*m_pmemfun)(a1, a2, a3); - } - - virtual has_slots* getdest() const - { - return m_pobject; - } - - private: - dest_type* m_pobject; - void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type); - }; - - template - class _connection4 : public _connection_base4 - { - public: - _connection4() - { - m_pobject = NULL; - m_pmemfun = NULL; - } - - _connection4(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type)) - { - m_pobject = pobject; - m_pmemfun = pmemfun; - } - - virtual _connection_base4* clone() - { - return new _connection4(*this); - } - - virtual _connection_base4* duplicate(has_slots* pnewdest) - { - return new _connection4((dest_type *)pnewdest, m_pmemfun); - } - - virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, - arg4_type a4) - { - (m_pobject->*m_pmemfun)(a1, a2, a3, a4); - } - - virtual has_slots* getdest() const - { - return m_pobject; - } - - private: - dest_type* m_pobject; - void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, - arg4_type); - }; - - template - class _connection5 : public _connection_base5 - { - public: - _connection5() - { - m_pobject = NULL; - m_pmemfun = NULL; - } - - _connection5(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type, arg5_type)) - { - m_pobject = pobject; - m_pmemfun = pmemfun; - } - - virtual _connection_base5* clone() - { - return new _connection5(*this); - } - - virtual _connection_base5* duplicate(has_slots* pnewdest) - { - return new _connection5((dest_type *)pnewdest, m_pmemfun); - } - - virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5) - { - (m_pobject->*m_pmemfun)(a1, a2, a3, a4, a5); - } - - virtual has_slots* getdest() const - { - return m_pobject; - } - - private: - dest_type* m_pobject; - void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, - arg5_type); - }; - - template - class _connection6 : public _connection_base6 - { - public: - _connection6() - { - m_pobject = NULL; - m_pmemfun = NULL; - } - - _connection6(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type, arg5_type, arg6_type)) - { - m_pobject = pobject; - m_pmemfun = pmemfun; - } - - virtual _connection_base6* clone() - { - return new _connection6(*this); - } - - virtual _connection_base6* duplicate(has_slots* pnewdest) - { - return new _connection6((dest_type *)pnewdest, m_pmemfun); - } - - virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5, arg6_type a6) - { - (m_pobject->*m_pmemfun)(a1, a2, a3, a4, a5, a6); - } - - virtual has_slots* getdest() const - { - return m_pobject; - } - - private: - dest_type* m_pobject; - void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, - arg5_type, arg6_type); - }; - - template - class _connection7 : public _connection_base7 - { - public: - _connection7() - { - m_pobject = NULL; - m_pmemfun = NULL; - } - - _connection7(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type)) - { - m_pobject = pobject; - m_pmemfun = pmemfun; - } - - virtual _connection_base7* clone() - { - return new _connection7(*this); - } - - virtual _connection_base7* duplicate(has_slots* pnewdest) - { - return new _connection7((dest_type *)pnewdest, m_pmemfun); - } - - virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5, arg6_type a6, arg7_type a7) - { - (m_pobject->*m_pmemfun)(a1, a2, a3, a4, a5, a6, a7); - } - - virtual has_slots* getdest() const - { - return m_pobject; - } - - private: - dest_type* m_pobject; - void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, - arg5_type, arg6_type, arg7_type); - }; - - template - class _connection8 : public _connection_base8 - { - public: - _connection8() - { - m_pobject = NULL; - m_pmemfun = NULL; - } - - _connection8(dest_type* pobject, void (dest_type::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, - arg7_type, arg8_type)) - { - m_pobject = pobject; - m_pmemfun = pmemfun; - } - - virtual _connection_base8* clone() - { - return new _connection8(*this); - } - - virtual _connection_base8* duplicate(has_slots* pnewdest) - { - return new _connection8((dest_type *)pnewdest, m_pmemfun); - } - - virtual void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5, arg6_type a6, arg7_type a7, arg8_type a8) - { - (m_pobject->*m_pmemfun)(a1, a2, a3, a4, a5, a6, a7, a8); - } - - virtual has_slots* getdest() const - { - return m_pobject; - } - - private: - dest_type* m_pobject; - void (dest_type::* m_pmemfun)(arg1_type, arg2_type, arg3_type, arg4_type, - arg5_type, arg6_type, arg7_type, arg8_type); - }; - - template - class signal0 : public _signal_base0 - { - public: - typedef std::list<_connection_base0 *> connections_list; - signal0() - { - ; - } - - signal0(const signal0& s) - : _signal_base0(s) - { - ; - } - - - template - void connect(desttype* pclass, void (desttype::*pmemfun)()) - { - lock_block lock(this); - _connection0* conn = - new _connection0(pclass, pmemfun); - - _signal_base0::m_connected_slots.push_back(conn); - pclass->signal_connect(this); - } - - void emit() - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = _signal_base0::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = _signal_base0::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(); - - it = itNext; - } - } - - void operator()() - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = _signal_base0::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = _signal_base0::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(); - - it = itNext; - } - } - - }; - - template - class signal1 : public _signal_base1 - { - public: - typedef std::list<_connection_base1 *> connections_list; - typedef _signal_base1 signal_base; - signal1() - { - ; - } - - signal1(const signal1& s) - : _signal_base1(s) - { - ; - } - - template - void connect(desttype* pclass, void (desttype::*pmemfun)(arg1_type)) - { - lock_block lock(this); - _connection1* conn = - new _connection1(pclass, pmemfun); - signal_base::m_connected_slots.push_back(conn); - pclass->signal_connect(this); - } - - void emit(arg1_type a1) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1); - - it = itNext; - } - } - - void operator()(arg1_type a1) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1); - - it = itNext; - } - } - }; - - template - class signal2 : public _signal_base2 - { - public: - typedef std::list<_connection_base2 *> - connections_list; - typedef _signal_base2 signal_base; - signal2() - { - ; - } - - signal2(const signal2& s) - : _signal_base2(s) - { - ; - } - - template - void connect(desttype* pclass, void (desttype::*pmemfun)(arg1_type, - arg2_type)) - { - lock_block lock(this); - _connection2* conn = new - _connection2(pclass, pmemfun); - signal_base::m_connected_slots.push_back(conn); - pclass->signal_connect(this); - } - - void emit(arg1_type a1, arg2_type a2) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2); - - it = itNext; - } - } - - void operator()(arg1_type a1, arg2_type a2) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2); - - it = itNext; - } - } - }; - - template - class signal3 : public _signal_base3 - { - public: - typedef std::list<_connection_base3 *> - connections_list; - typedef _signal_base3 signal_base; - signal3() - { - ; - } - - ~signal3() - { - - } - - signal3(const signal3& s) - : _signal_base3(s) - { - ; - } - - template - void connect(desttype* pclass, void (desttype::*pmemfun)(arg1_type, - arg2_type, arg3_type)) - { - lock_block lock(this); - _connection3* conn = - new _connection3(pclass, - pmemfun); - signal_base::m_connected_slots.push_back(conn); - pclass->signal_connect(this); - } - - void emit(arg1_type a1, arg2_type a2, arg3_type a3) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3); - - it = itNext; - } - } - - void operator()(arg1_type a1, arg2_type a2, arg3_type a3) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3); - - it = itNext; - } - } - }; - - template - class signal4 : public _signal_base4 - { - public: - typedef std::list<_connection_base4 *> connections_list; - typedef _signal_base4 signal_base; - signal4() - { - ; - } - - signal4(const signal4& s) - : _signal_base4(s) - { - ; - } - - template - void connect(desttype* pclass, void (desttype::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type)) - { - lock_block lock(this); - _connection4* - conn = new _connection4(pclass, pmemfun); - signal_base::m_connected_slots.push_back(conn); - pclass->signal_connect(this); - } - - void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4); - - it = itNext; - } - } - - void operator()(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4); - - it = itNext; - } - } - }; - - template - class signal5 : public _signal_base5 - { - public: - typedef std::list<_connection_base5 *> connections_list; - typedef _signal_base5 signal_base; - signal5() - { - ; - } - - signal5(const signal5& s) - : _signal_base5(s) - { - ; - } - - template - void connect(desttype* pclass, void (desttype::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type, arg5_type)) - { - lock_block lock(this); - _connection5* conn = new _connection5(pclass, pmemfun); - signal_base::m_connected_slots.push_back(conn); - pclass->signal_connect(this); - } - - void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4, a5); - - it = itNext; - } - } - - void operator()(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4, a5); - - it = itNext; - } - } - }; - - - template - class signal6 : public _signal_base6 - { - public: - typedef std::list<_connection_base6 *> connections_list; - typedef _signal_base6 signal_base; - signal6() - { - ; - } - - signal6(const signal6& s) - : _signal_base6(s) - { - ; - } - - template - void connect(desttype* pclass, void (desttype::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type, arg5_type, arg6_type)) - { - lock_block lock(this); - _connection6* conn = - new _connection6(pclass, pmemfun); - signal_base::m_connected_slots.push_back(conn); - pclass->signal_connect(this); - } - - void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5, arg6_type a6) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4, a5, a6); - - it = itNext; - } - } - - void operator()(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5, arg6_type a6) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4, a5, a6); - - it = itNext; - } - } - }; - - template - class signal7 : public _signal_base7 - { - public: - typedef std::list<_connection_base7 *> connections_list; - typedef _signal_base7 signal_base; - signal7() - { - ; - } - - signal7(const signal7& s) - : _signal_base7(s) - { - ; - } - - template - void connect(desttype* pclass, void (desttype::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, - arg7_type)) - { - lock_block lock(this); - _connection7* conn = - new _connection7(pclass, pmemfun); - signal_base::m_connected_slots.push_back(conn); - pclass->signal_connect(this); - } - - void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5, arg6_type a6, arg7_type a7) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4, a5, a6, a7); - - it = itNext; - } - } - - void operator()(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5, arg6_type a6, arg7_type a7) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4, a5, a6, a7); - - it = itNext; - } - } - }; - - template - class signal8 : public _signal_base8 - { - public: - typedef std::list<_connection_base8 *> - connections_list; - typedef _signal_base8 signal_base; - signal8() - { - ; - } - - signal8(const signal8& s) - : _signal_base8(s) - { - ; - } - - template - void connect(desttype* pclass, void (desttype::*pmemfun)(arg1_type, - arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, - arg7_type, arg8_type)) - { - lock_block lock(this); - _connection8* conn = - new _connection8(pclass, pmemfun); - signal_base::m_connected_slots.push_back(conn); - pclass->signal_connect(this); - } - - void emit(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5, arg6_type a6, arg7_type a7, arg8_type a8) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4, a5, a6, a7, a8); - - it = itNext; - } - } - - void operator()(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, - arg5_type a5, arg6_type a6, arg7_type a7, arg8_type a8) - { - lock_block lock(this); - typename connections_list::const_iterator itNext, it = signal_base::m_connected_slots.begin(); - typename connections_list::const_iterator itEnd = signal_base::m_connected_slots.end(); - - while(it != itEnd) - { - itNext = it; - ++itNext; - - (*it)->emit(a1, a2, a3, a4, a5, a6, a7, a8); - - it = itNext; - } - } - }; - -}; // namespace sigslot - -#endif // SIGSLOT_H__ - diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.h b/extensions/CocoStudio/Armature/physics/CCColliderDetector.h index 4a54ad4090..63990d3bf9 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.h +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.h @@ -76,7 +76,14 @@ public: static ColliderDetector *create(); static ColliderDetector *create(Bone *bone); public: + /** + * @js ctor + */ ColliderDetector(); + /** + * @js NA + * @lua NA + */ ~ColliderDetector(void); virtual bool init(); diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h index fd42be10a6..38284ababe 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h @@ -41,7 +41,14 @@ public: static void purge(); private: + /** + * @js ctor + */ ArmatureDataManager(void); + /** + * @js NA + * @lua NA + */ ~ArmatureDataManager(void); public: diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h index c854766d53..a05f846cae 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h @@ -85,7 +85,14 @@ public: static void purge(); static void clear(); public: + /** + * @js ctor + */ DataReaderHelper(); + /** + * @js NA + * @lua NA + */ ~DataReaderHelper(); void addDataFromFile(const char *filePath); diff --git a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h index 2ccd1860e7..57bc7c5296 100644 --- a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h @@ -47,7 +47,14 @@ public: TextureAtlas *getTexureAtlasWithTexture(Texture2D *texture); private: + /** + * @js ctor + */ SpriteFrameCacheHelper(); + /** + * @js NA + * @lua NA + */ ~SpriteFrameCacheHelper(); Dictionary *_textureAtlasDic; diff --git a/extensions/cocos-ext.h b/extensions/cocos-ext.h index 51d15653c1..60b785ce24 100644 --- a/extensions/cocos-ext.h +++ b/extensions/cocos-ext.h @@ -63,7 +63,6 @@ #include "CocoStudio/Armature/utils/CCDataReaderHelper.h" #include "CocoStudio/Armature/utils/CCTweenFunction.h" #include "CocoStudio/Armature/utils/CCArmatureDataManager.h" -#include "CocoStudio/Armature/external_tool/sigslot.h" #include "CocoStudio/Components/CCComAttribute.h" #include "CocoStudio/Components/CCComAudio.h" diff --git a/extensions/proj.win32/libExtensions.vcxproj b/extensions/proj.win32/libExtensions.vcxproj index de82211ac4..544088ccce 100644 --- a/extensions/proj.win32/libExtensions.vcxproj +++ b/extensions/proj.win32/libExtensions.vcxproj @@ -234,7 +234,6 @@ - diff --git a/extensions/proj.win32/libExtensions.vcxproj.filters b/extensions/proj.win32/libExtensions.vcxproj.filters index 38153de465..88e5a3a1a2 100644 --- a/extensions/proj.win32/libExtensions.vcxproj.filters +++ b/extensions/proj.win32/libExtensions.vcxproj.filters @@ -55,9 +55,6 @@ {5e5b3d7d-62a7-493e-a130-ed72ee7c65f2} - - {bd365bbb-6972-4073-b268-8360df428166} - {d797adcd-2e59-4486-944e-b3e7f3a954b8} @@ -650,9 +647,6 @@ CocoStudio\Armature\display - - CocoStudio\Armature\external_tool - CocoStudio\Armature\physics From 16c70363dde03122bc85931320dd029c50b58eb3 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Mon, 16 Sep 2013 14:56:59 +0800 Subject: [PATCH 22/28] standardizate code --- extensions/CocoStudio/Armature/CCBone.cpp | 16 ++++++------- extensions/CocoStudio/Armature/CCBone.h | 2 +- .../Armature/physics/CCColliderDetector.cpp | 4 ---- .../CocoStudioArmatureTest/ArmatureScene.cpp | 24 ++++--------------- .../CocoStudioArmatureTest/ArmatureScene.h | 9 +++---- 5 files changed, 16 insertions(+), 39 deletions(-) diff --git a/extensions/CocoStudio/Armature/CCBone.cpp b/extensions/CocoStudio/Armature/CCBone.cpp index 9c10b69e8c..e6063e51c3 100644 --- a/extensions/CocoStudio/Armature/CCBone.cpp +++ b/extensions/CocoStudio/Armature/CCBone.cpp @@ -65,8 +65,8 @@ Bone::Bone() _armature = NULL; _childArmature = NULL; _boneData = NULL; - m_pTween = NULL; - m_pTween = NULL; + _tween = NULL; + _tween = NULL; _children = NULL; _displayManager = NULL; _ignoreMovementBoneData = false; @@ -80,7 +80,7 @@ Bone::~Bone(void) { CC_SAFE_DELETE(_tweenData); CC_SAFE_DELETE(_children); - CC_SAFE_DELETE(m_pTween); + CC_SAFE_DELETE(_tween); CC_SAFE_DELETE(_displayManager); if(_boneData) @@ -111,9 +111,9 @@ bool Bone::init(const char *name) CC_SAFE_DELETE(_tweenData); _tweenData = new FrameData(); - CC_SAFE_DELETE(m_pTween); - m_pTween = new Tween(); - m_pTween->init(this); + CC_SAFE_DELETE(_tween); + _tween = new Tween(); + _tween->init(this); CC_SAFE_DELETE(_displayManager); _displayManager = new DisplayManager(); @@ -150,7 +150,7 @@ void Bone::setArmature(Armature *armature) _armature = armature; if (_armature) { - m_pTween->setAnimation(_armature->getAnimation()); + _tween->setAnimation(_armature->getAnimation()); } } @@ -311,7 +311,7 @@ Armature *Bone::getChildArmature() Tween *Bone::getTween() { - return m_pTween; + return _tween; } void Bone::setZOrder(int zOrder) diff --git a/extensions/CocoStudio/Armature/CCBone.h b/extensions/CocoStudio/Armature/CCBone.h index 904e7ebbb3..9f979e616a 100644 --- a/extensions/CocoStudio/Armature/CCBone.h +++ b/extensions/CocoStudio/Armature/CCBone.h @@ -177,7 +177,7 @@ public: CC_SYNTHESIZE(BlendType, _blendType, BlendType) protected: - Tween *m_pTween; //! Calculate tween effect + Tween *_tween; //! Calculate tween effect //! Used for making tween effect in every frame CC_SYNTHESIZE_READONLY(FrameData *, _tweenData, TweenData); diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp index 941b7d59c5..798a9b83b5 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.cpp @@ -93,11 +93,7 @@ ColliderDetector::ColliderDetector() : _colliderBodyList(NULL) , _active(false) { -#if ENABLE_PHYSICS_BOX2D_DETECT _body = NULL; -#elif ENABLE_PHYSICS_CHIPMUNK_DETECT - _body = NULL; -#endif } ColliderDetector::~ColliderDetector() diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 8275dc642a..69f0fca23d 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -518,17 +518,11 @@ std::string TestParticleDisplay::subtitle() { return "Touch to change animation"; } -bool TestParticleDisplay::ccTouchBegan(Touch *pTouch, Event *pEvent) +void TestParticleDisplay::ccTouchesEnded(Set* touches, Event* event) { ++animationID; animationID = animationID % armature->getAnimation()->getMovementCount(); armature->getAnimation()->playByIndex(animationID); - return false; -} - -void TestParticleDisplay::registerWithTouchDispatcher() -{ - Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN + 1, true); } @@ -579,22 +573,18 @@ std::string TestUseMutiplePicture::subtitle() { return "weapon and armature are in different picture"; } -bool TestUseMutiplePicture::ccTouchBegan(Touch *pTouch, Event *pEvent) +void TestUseMutiplePicture::ccTouchesEnded(Set* touches, Event* event) { ++displayIndex; displayIndex = (displayIndex) % 8; armature->getBone("weapon")->changeDisplayByIndex(displayIndex, true); - return false; -} -void TestUseMutiplePicture::registerWithTouchDispatcher() -{ - Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN + 1, true); } + TestColliderDetector::~TestColliderDetector() { } @@ -963,7 +953,7 @@ std::string TestArmatureNesting::title() { return "Test Armature Nesting"; } -bool TestArmatureNesting::ccTouchBegan(Touch *pTouch, Event *pEvent) +void TestArmatureNesting::ccTouchesEnded(Set* touches, Event* event) { ++weaponIndex; weaponIndex = weaponIndex % 4; @@ -973,10 +963,4 @@ bool TestArmatureNesting::ccTouchBegan(Touch *pTouch, Event *pEvent) armature->getBone("armInside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); armature->getBone("armOutside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex); } - - return false; } -void TestArmatureNesting::registerWithTouchDispatcher() -{ - Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN + 1, true); -} \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index d76f678afa..d78af5d7df 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -137,8 +137,7 @@ class TestUseMutiplePicture : public ArmatureTestLayer virtual void onExit(); virtual std::string title(); virtual std::string subtitle(); - virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent); - virtual void registerWithTouchDispatcher(); + virtual void ccTouchesEnded(Set* touches, Event* event); int displayIndex; cocos2d::extension::armature::Armature *armature; @@ -150,8 +149,7 @@ class TestParticleDisplay : public ArmatureTestLayer virtual void onExit(); virtual std::string title(); virtual std::string subtitle(); - virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent); - virtual void registerWithTouchDispatcher(); + virtual void ccTouchesEnded(Set* touches, Event* event); int animationID; cocos2d::extension::armature::Armature *armature; @@ -252,8 +250,7 @@ public: virtual void onEnter(); virtual void onExit(); virtual std::string title(); - virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent); - virtual void registerWithTouchDispatcher(); + virtual void ccTouchesEnded(Set* touches, Event* event); cocos2d::extension::armature::Armature *armature; int weaponIndex; From a08ce3df7311df8de137632b5c340f40f036fc3b Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Mon, 16 Sep 2013 15:16:05 +0800 Subject: [PATCH 23/28] change singleton class get method to getInstance --- extensions/CocoStudio/Armature/CCArmature.cpp | 2 +- .../Armature/display/CCDisplayFactory.cpp | 2 +- .../CocoStudio/Armature/display/CCSkin.cpp | 4 ++-- .../Armature/utils/CCArmatureDataManager.cpp | 12 +++++----- .../Armature/utils/CCArmatureDataManager.h | 5 +++- .../Armature/utils/CCDataReaderHelper.cpp | 24 +++++++++---------- .../Armature/utils/CCDataReaderHelper.h | 5 +++- .../utils/CCSpriteFrameCacheHelper.cpp | 2 +- .../Armature/utils/CCSpriteFrameCacheHelper.h | 5 +++- .../CocoStudio/Reader/CCSSceneReader.cpp | 2 +- .../CocoStudioArmatureTest/ArmatureScene.cpp | 24 +++++++++---------- 11 files changed, 48 insertions(+), 39 deletions(-) diff --git a/extensions/CocoStudio/Armature/CCArmature.cpp b/extensions/CocoStudio/Armature/CCArmature.cpp index 22ec3d17ca..3557933374 100644 --- a/extensions/CocoStudio/Armature/CCArmature.cpp +++ b/extensions/CocoStudio/Armature/CCArmature.cpp @@ -135,7 +135,7 @@ bool Armature::init(const char *name) _name = name == NULL ? "" : name; - ArmatureDataManager *armatureDataManager = ArmatureDataManager::sharedArmatureDataManager(); + ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance(); if(_name.length() != 0) { diff --git a/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp b/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp index 1d23d79e1b..4cef6fad53 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp +++ b/extensions/CocoStudio/Armature/display/CCDisplayFactory.cpp @@ -183,7 +183,7 @@ void DisplayFactory::initSpriteDisplay(Bone *bone, DecorativeDisplay *decoDispla textureName = textureName.erase(startPos); } - TextureData *textureData = ArmatureDataManager::sharedArmatureDataManager()->getTextureData(textureName.c_str()); + TextureData *textureData = ArmatureDataManager::getInstance()->getTextureData(textureName.c_str()); if(textureData) { //! Init display anchorPoint, every Texture have a anchor point diff --git a/extensions/CocoStudio/Armature/display/CCSkin.cpp b/extensions/CocoStudio/Armature/display/CCSkin.cpp index 3989ca5928..2fdf2b24af 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.cpp +++ b/extensions/CocoStudio/Armature/display/CCSkin.cpp @@ -84,7 +84,7 @@ bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName) if (ret) { - TextureAtlas *atlas = SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); + TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); setTextureAtlas(atlas); _displayName = pszSpriteFrameName; @@ -99,7 +99,7 @@ bool Skin::initWithFile(const char *pszFilename) if (ret) { - TextureAtlas *atlas = SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTexureAtlasWithTexture(_texture); + TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); setTextureAtlas(atlas); _displayName = pszFilename; diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp index 4bdd9ca9e6..b2fa7b8b68 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.cpp @@ -33,7 +33,7 @@ NS_CC_EXT_ARMATURE_BEGIN static ArmatureDataManager *s_sharedArmatureDataManager = NULL; -ArmatureDataManager *ArmatureDataManager::sharedArmatureDataManager() +ArmatureDataManager *ArmatureDataManager::getInstance() { if (s_sharedArmatureDataManager == NULL) { @@ -179,32 +179,32 @@ void ArmatureDataManager::removeTextureData(const char *id) void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath) { _autoLoadSpriteFile = true; - DataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); + DataReaderHelper::getInstance()->addDataFromFile(configFilePath); } void ArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector) { _autoLoadSpriteFile = true; - DataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); + DataReaderHelper::getInstance()->addDataFromFileAsync(configFilePath, target, selector); } void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) { _autoLoadSpriteFile = false; - DataReaderHelper::sharedDataReaderHelper()->addDataFromFile(configFilePath); + DataReaderHelper::getInstance()->addDataFromFile(configFilePath); addSpriteFrameFromFile(plistPath, imagePath); } void ArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector) { _autoLoadSpriteFile = false; - DataReaderHelper::sharedDataReaderHelper()->addDataFromFileAsync(configFilePath, target, selector); + DataReaderHelper::getInstance()->addDataFromFileAsync(configFilePath, target, selector); addSpriteFrameFromFile(plistPath, imagePath); } void ArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) { - SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath); + SpriteFrameCacheHelper::getInstance()->addSpriteFrameFromFile(plistPath, imagePath); } diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h index 38284ababe..6bef41bb13 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDataManager.h @@ -37,7 +37,10 @@ NS_CC_EXT_ARMATURE_BEGIN class ArmatureDataManager : public Object { public: - static ArmatureDataManager *sharedArmatureDataManager(); + /** @deprecated Use getInstance() instead */ + CC_DEPRECATED_ATTRIBUTE static ArmatureDataManager *sharedArmatureDataManager() { return ArmatureDataManager::getInstance(); } + + static ArmatureDataManager *getInstance(); static void purge(); private: diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp index 7bc1c7f55f..a9c7830706 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp @@ -209,7 +209,7 @@ void DataReaderHelper::loadData() } -DataReaderHelper *DataReaderHelper::sharedDataReaderHelper() +DataReaderHelper *DataReaderHelper::getInstance() { if(!_dataReaderHelper) { @@ -378,7 +378,7 @@ void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target data->baseFilePath = s_BasefilePath; data->target = target; data->selector = selector; - data->autoLoadSpriteFile = ArmatureDataManager::sharedArmatureDataManager()->isAutoLoadSpriteFile(); + data->autoLoadSpriteFile = ArmatureDataManager::getInstance()->isAutoLoadSpriteFile(); std::string filePathStr = filePath; @@ -428,7 +428,7 @@ void DataReaderHelper::addDataAsyncCallBack(float dt) while (!pDataInfo->configFileQueue.empty()) { std::string configPath = pDataInfo->configFileQueue.front(); - ArmatureDataManager::sharedArmatureDataManager()->addSpriteFrameFromFile((pAsyncStruct->baseFilePath + configPath + ".plist").c_str(), (pAsyncStruct->baseFilePath + configPath + ".png").c_str()); + ArmatureDataManager::getInstance()->addSpriteFrameFromFile((pAsyncStruct->baseFilePath + configPath + ".plist").c_str(), (pAsyncStruct->baseFilePath + configPath + ".png").c_str()); pDataInfo->configFileQueue.pop(); } @@ -485,7 +485,7 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data { _dataReaderHelper->_addDataMutex.lock(); } - ArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); + ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData); armatureData->release(); if (dataInfo) { @@ -508,7 +508,7 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data { _dataReaderHelper->_addDataMutex.lock(); } - ArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); + ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData); animationData->release(); if (dataInfo) { @@ -531,7 +531,7 @@ void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *data { _dataReaderHelper->_addDataMutex.lock(); } - ArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); + ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData); textureData->release(); if (dataInfo) { @@ -660,7 +660,7 @@ AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animation const char *name = animationXML->Attribute(A_NAME); - ArmatureData *armatureData = ArmatureDataManager::sharedArmatureDataManager()->getArmatureData(name); + ArmatureData *armatureData = ArmatureDataManager::getInstance()->getArmatureData(name); aniData->name = name; @@ -1109,7 +1109,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d { _dataReaderHelper->_addDataMutex.lock(); } - ArmatureDataManager::sharedArmatureDataManager()->addArmatureData(armatureData->name.c_str(), armatureData); + ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData); armatureData->release(); if (dataInfo) { @@ -1129,7 +1129,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d { _dataReaderHelper->_addDataMutex.lock(); } - ArmatureDataManager::sharedArmatureDataManager()->addAnimationData(animationData->name.c_str(), animationData); + ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData); animationData->release(); if (dataInfo) { @@ -1149,7 +1149,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d { _dataReaderHelper->_addDataMutex.lock(); } - ArmatureDataManager::sharedArmatureDataManager()->addTextureData(textureData->name.c_str(), textureData); + ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData); textureData->release(); if (dataInfo) { @@ -1159,7 +1159,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d } // Auto load sprite file - bool autoLoad = dataInfo == NULL ? ArmatureDataManager::sharedArmatureDataManager()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; + bool autoLoad = dataInfo == NULL ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; if (autoLoad) { length = json.getArrayItemCount(CONFIG_FILE_PATH); @@ -1184,7 +1184,7 @@ void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *d std::string plistPath = filePath + ".plist"; std::string pngPath = filePath + ".png"; - ArmatureDataManager::sharedArmatureDataManager()->addSpriteFrameFromFile((s_BasefilePath + plistPath).c_str(), (s_BasefilePath + pngPath).c_str()); + ArmatureDataManager::getInstance()->addSpriteFrameFromFile((s_BasefilePath + plistPath).c_str(), (s_BasefilePath + pngPath).c_str()); } } } diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h index a05f846cae..2389245c20 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.h @@ -73,7 +73,10 @@ protected: public: - static DataReaderHelper *sharedDataReaderHelper(); + /** @deprecated Use getInstance() instead */ + CC_DEPRECATED_ATTRIBUTE static DataReaderHelper *sharedDataReaderHelper() { return DataReaderHelper::getInstance(); } + + static DataReaderHelper *getInstance(); /** * Scale the position data, used for multiresolution adapter diff --git a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp index d4317e97ae..acbdf4c542 100644 --- a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.cpp @@ -29,7 +29,7 @@ NS_CC_EXT_ARMATURE_BEGIN SpriteFrameCacheHelper *SpriteFrameCacheHelper::_spriteFrameCacheHelper = NULL; -SpriteFrameCacheHelper *SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper() +SpriteFrameCacheHelper *SpriteFrameCacheHelper::getInstance() { if(!_spriteFrameCacheHelper) { diff --git a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h index 57bc7c5296..257cf49cd8 100644 --- a/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h +++ b/extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.h @@ -34,7 +34,10 @@ NS_CC_EXT_ARMATURE_BEGIN class SpriteFrameCacheHelper { public: - static SpriteFrameCacheHelper *sharedSpriteFrameCacheHelper(); + /** @deprecated Use getInstance() instead */ + CC_DEPRECATED_ATTRIBUTE static SpriteFrameCacheHelper *sharedSpriteFrameCacheHelper(){ return SpriteFrameCacheHelper::getInstance(); } + + static SpriteFrameCacheHelper *getInstance(); static void purge(); public: diff --git a/extensions/CocoStudio/Reader/CCSSceneReader.cpp b/extensions/CocoStudio/Reader/CCSSceneReader.cpp index 757e8c7924..7c1e2c4e16 100644 --- a/extensions/CocoStudio/Reader/CCSSceneReader.cpp +++ b/extensions/CocoStudio/Reader/CCSSceneReader.cpp @@ -245,7 +245,7 @@ NS_CC_EXT_BEGIN textupath += file_path; textupath.append(textureFileName); - cocos2d::extension::armature::ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(textupath.c_str(), plistpath.c_str(), pPath.c_str()); + cocos2d::extension::armature::ArmatureDataManager::getInstance()->addArmatureFileInfo(textupath.c_str(), plistpath.c_str(), pPath.c_str()); } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 69f0fca23d..3806241d18 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -226,20 +226,20 @@ void TestAsynchronousLoading::onEnter() //! create a new thread to load data - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/robot.png", "armature/robot.plist", "armature/robot.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); - ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/Cowboy.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/robot.png", "armature/robot.plist", "armature/robot.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded)); + 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)); //! load data directly - // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); - // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml"); - // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml"); - // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml"); - // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml"); - // ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy.ExportJson"); + // ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml"); + // ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml"); + // ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml"); + // ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml"); + // ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml"); + // ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Cowboy.ExportJson"); } From 22fd21db13e5ac7f2eee78499461202cf19f4675 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 16 Sep 2013 18:20:52 +0800 Subject: [PATCH 24/28] Fixing iOS and Mac project config. --- cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index fb7706c627..b299b031e3 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -82031186c5a74b94209ee517854294f4a1b672bc \ No newline at end of file +fad913317d2e64eb308c7066f450f3a351ee0aab \ No newline at end of file From 83d61dff4420e40223b96a25d3b3f99d342729e7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 16 Sep 2013 19:27:34 +0800 Subject: [PATCH 25/28] [Armature] Fixing compilation errors. --- .../CocoStudioArmatureTest/ArmatureScene.cpp | 29 +++++++++---------- .../CocoStudioArmatureTest/ArmatureScene.h | 6 ++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 3806241d18..70aead4f66 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -505,29 +505,29 @@ void TestParticleDisplay::onEnter() bone->setScale(1.2f); armature->addBone(bone, "bady-a30"); } + void TestParticleDisplay::onExit() { - Director::getInstance()->getTouchDispatcher()->removeDelegate(this); ArmatureTestLayer::onExit(); } + std::string TestParticleDisplay::title() { return "Test Particle Display"; } + std::string TestParticleDisplay::subtitle() { return "Touch to change animation"; } -void TestParticleDisplay::ccTouchesEnded(Set* touches, Event* event) + +void TestParticleDisplay::onTouchesEnded(const std::vector& touches, Event* event) { ++animationID; animationID = animationID % armature->getAnimation()->getMovementCount(); armature->getAnimation()->playByIndex(animationID); } - - - void TestUseMutiplePicture::onEnter() { ArmatureTestLayer::onEnter(); @@ -560,31 +560,29 @@ void TestUseMutiplePicture::onEnter() l->setAnchorPoint(Point(0.2f, 0.5f)); armature->getBone("weapon")->addDisplay(l, 7); } + void TestUseMutiplePicture::onExit() { - Director::getInstance()->getTouchDispatcher()->removeDelegate(this); ArmatureTestLayer::onExit(); } + std::string TestUseMutiplePicture::title() { return "Test One Armature Use Different Picture"; } + std::string TestUseMutiplePicture::subtitle() { return "weapon and armature are in different picture"; } -void TestUseMutiplePicture::ccTouchesEnded(Set* touches, Event* event) + +void TestUseMutiplePicture::onTouchesEnded(const std::vector& touches, Event* event) { ++displayIndex; displayIndex = (displayIndex) % 8; armature->getBone("weapon")->changeDisplayByIndex(displayIndex, true); } - - - - - TestColliderDetector::~TestColliderDetector() { } @@ -929,7 +927,6 @@ std::string TestAnchorPoint::title() return "Test Set AnchorPoint"; } - void TestArmatureNesting::onEnter() { ArmatureTestLayer::onEnter(); @@ -944,16 +941,18 @@ void TestArmatureNesting::onEnter() weaponIndex = 0; } + void TestArmatureNesting::onExit() { - Director::getInstance()->getTouchDispatcher()->removeDelegate(this); ArmatureTestLayer::onExit(); } + std::string TestArmatureNesting::title() { return "Test Armature Nesting"; } -void TestArmatureNesting::ccTouchesEnded(Set* touches, Event* event) + +void TestArmatureNesting::onTouchesEnded(const std::vector& touches, Event* event) { ++weaponIndex; weaponIndex = weaponIndex % 4; diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index d78af5d7df..587938b052 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -137,7 +137,7 @@ class TestUseMutiplePicture : public ArmatureTestLayer virtual void onExit(); virtual std::string title(); virtual std::string subtitle(); - virtual void ccTouchesEnded(Set* touches, Event* event); + virtual void onTouchesEnded(const std::vector& touches, Event* event) override; int displayIndex; cocos2d::extension::armature::Armature *armature; @@ -149,7 +149,7 @@ class TestParticleDisplay : public ArmatureTestLayer virtual void onExit(); virtual std::string title(); virtual std::string subtitle(); - virtual void ccTouchesEnded(Set* touches, Event* event); + virtual void onTouchesEnded(const std::vector& touches, Event* event); int animationID; cocos2d::extension::armature::Armature *armature; @@ -250,7 +250,7 @@ public: virtual void onEnter(); virtual void onExit(); virtual std::string title(); - virtual void ccTouchesEnded(Set* touches, Event* event); + virtual void onTouchesEnded(const std::vector& touches, Event* event); cocos2d::extension::armature::Armature *armature; int weaponIndex; From dba7f3eae61e7a704215d2190437d54c054de3f9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 16 Sep 2013 19:53:59 +0800 Subject: [PATCH 26/28] [GUI] Fixing compilation errors for win32. --- extensions/CocoStudio/GUI/Layouts/Layout.cpp | 4 +- extensions/proj.win32/libExtensions.vcxproj | 57 ++++++ .../proj.win32/libExtensions.vcxproj.filters | 192 ++++++++++++++++++ 3 files changed, 251 insertions(+), 2 deletions(-) diff --git a/extensions/CocoStudio/GUI/Layouts/Layout.cpp b/extensions/CocoStudio/GUI/Layouts/Layout.cpp index 9d098cf367..47843aec1f 100644 --- a/extensions/CocoStudio/GUI/Layouts/Layout.cpp +++ b/extensions/CocoStudio/GUI/Layouts/Layout.cpp @@ -462,7 +462,7 @@ bool RectClippingNode::init() rect[2] = Point(m_clippingSize.width, m_clippingSize.height); rect[3] = Point(0, m_clippingSize.height); - Color4F green = {0, 1, 0, 1}; + Color4F green = Color4F(0, 1, 0, 1); m_pInnerStencil->drawPolygon(rect, 4, green, 0, green); if (CCClippingNode::init(m_pInnerStencil)) { @@ -480,7 +480,7 @@ void RectClippingNode::setClippingSize(const Size &size) rect[1] = Point(m_clippingSize.width, 0); rect[2] = Point(m_clippingSize.width, m_clippingSize.height); rect[3] = Point(0, m_clippingSize.height); - Color4F green = {0, 1, 0, 1}; + Color4F green = Color4F(0, 1, 0, 1); m_pInnerStencil->clear(); m_pInnerStencil->drawPolygon(rect, 4, green, 0, green); } diff --git a/extensions/proj.win32/libExtensions.vcxproj b/extensions/proj.win32/libExtensions.vcxproj index 544088ccce..62fa470bff 100644 --- a/extensions/proj.win32/libExtensions.vcxproj +++ b/extensions/proj.win32/libExtensions.vcxproj @@ -141,11 +141,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -247,6 +275,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -259,6 +315,7 @@ + diff --git a/extensions/proj.win32/libExtensions.vcxproj.filters b/extensions/proj.win32/libExtensions.vcxproj.filters index 88e5a3a1a2..113fd2c41c 100644 --- a/extensions/proj.win32/libExtensions.vcxproj.filters +++ b/extensions/proj.win32/libExtensions.vcxproj.filters @@ -64,6 +64,27 @@ {d305abea-33cc-4ae8-b78d-b5fb59927e59} + + {9af947f9-84cd-4051-953e-67291da6528c} + + + {6ad66a63-e7d6-4285-b30a-7ab70a299f7e} + + + {9713ac75-d9ba-494a-8dcf-03e30f8ee2b2} + + + {2d6f3e38-bb46-4bec-9ec1-73d90cefb3ba} + + + {7556b22b-b7ca-4f3b-938d-0f9c8047892c} + + + {f66c34f1-f75a-4f06-9788-c48972bc0ff2} + + + {1c44450b-d06e-4638-9f0c-1ff62e67ec84} + @@ -367,6 +388,90 @@ CocoStudio\Armature\utils + + CocoStudio\GUI\UIWidgets\ScrollWidget + + + CocoStudio\GUI\UIWidgets\ScrollWidget + + + CocoStudio\GUI\UIWidgets\ScrollWidget + + + CocoStudio\GUI\UIWidgets\ScrollWidget + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\Action + + + CocoStudio\GUI\Action + + + CocoStudio\GUI\Action + + + CocoStudio\GUI\Action + + + CocoStudio\GUI\BaseClasses + + + CocoStudio\GUI\BaseClasses + + + CocoStudio\GUI\Layouts + + + CocoStudio\GUI\Layouts + + + CocoStudio\GUI\Layouts + + + CocoStudio\GUI\Layouts + + + CocoStudio\GUI\System + + + CocoStudio\GUI\System + + + CocoStudio\GUI\System + + + CocoStudio\GUI\System + + + CocoStudio\Reader + @@ -719,6 +824,93 @@ CocoStudio\Components + + CocoStudio\GUI\UIWidgets\ScrollWidget + + + CocoStudio\GUI\UIWidgets\ScrollWidget + + + CocoStudio\GUI\UIWidgets\ScrollWidget + + + CocoStudio\GUI\UIWidgets\ScrollWidget + + + CocoStudio\GUI\UIWidgets\ScrollWidget + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\UIWidgets + + + CocoStudio\GUI\Action + + + CocoStudio\GUI\Action + + + CocoStudio\GUI\Action + + + CocoStudio\GUI\Action + + + CocoStudio\GUI\BaseClasses + + + CocoStudio\GUI\BaseClasses + + + CocoStudio\GUI\Layouts + + + CocoStudio\GUI\Layouts + + + CocoStudio\GUI\Layouts + + + CocoStudio\GUI\Layouts + + + CocoStudio\GUI\System + + + CocoStudio\GUI\System + + + CocoStudio\GUI\System + + + CocoStudio\GUI\System + + + CocoStudio\Reader + From 9981aecddf43eb7a762077a454e8a7926156fd30 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 16 Sep 2013 20:41:03 +0800 Subject: [PATCH 27/28] Removing unneeded log in win32/CCEGLView.cpp. --- cocos2dx/platform/win32/CCEGLView.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index a58bd59941..4754b1892c 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -285,8 +285,6 @@ void EGLViewEventHandler::OnGLFWError(int errorID, const char* errorDesc) void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify) { - static int countxxx = 0; - CCLOG("OnGLFWMouseCallBack = %d", ++countxxx); EGLView* eglView = EGLView::getInstance(); if(nullptr == eglView) return; if(GLFW_MOUSE_BUTTON_LEFT == button) @@ -314,8 +312,6 @@ void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, in void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y) { - static int countxxx = 0; - CCLOG("OnGLFWMouseMoveCallBack = %d, %lf, %lf", ++countxxx, x, y); s_mouseX = (float)x; s_mouseY = (float)y; EGLView* eglView = EGLView::getInstance(); From 6a662c094ff088befe662c6a4979936ba2c23cea Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 16 Sep 2013 20:53:27 +0800 Subject: [PATCH 28/28] Re-adding the submodule of plugin which was deleted in pull request #3623. --- plugin | 1 + 1 file changed, 1 insertion(+) create mode 160000 plugin diff --git a/plugin b/plugin new file mode 160000 index 0000000000..d583b83c58 --- /dev/null +++ b/plugin @@ -0,0 +1 @@ +Subproject commit d583b83c5806a0d44788095dfc541fb2812c600e