From 0f3cb16efd42e5a29f3bdfdb9e2d380dc66cfa3f Mon Sep 17 00:00:00 2001 From: XiaoFeng Date: Thu, 14 Jan 2016 16:16:37 +0800 Subject: [PATCH] Fix when add two ActionTimeLine object in one node, play state is wrong --- .../ActionTimeline/CCActionTimelineCache.cpp | 22 +++++++++++++++++- .../ActionTimeline/CCActionTimelineCache.h | 3 +++ .../cocostudio/ActionTimeline/CSLoader.cpp | 6 ++--- .../ActionTimelineTestScene.cpp | 19 +++++++++++++++ .../ActionTimelineTestScene.h | 10 ++++++++ .../Resources/ActionTimeline/ani1.csb | Bin 0 -> 1216 bytes .../Resources/ActionTimeline/ani2.csb | Bin 0 -> 2360 bytes tools/tolua/cocos2dx_studio.ini | 2 +- 8 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 tests/cpp-tests/Resources/ActionTimeline/ani1.csb create mode 100644 tests/cpp-tests/Resources/ActionTimeline/ani2.csb diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index 51d29f88d5..043babe6b6 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -164,6 +164,16 @@ ActionTimeline* ActionTimelineCache::createActionFromJson(const std::string& fil return action->clone(); } +ActionTimeline* ActionTimelineCache::createActionFromContent(const std::string& fileName, const std::string& content) +{ + ActionTimeline* action = _animationActions.at(fileName); + if (action == nullptr) + { + action = loadAnimationActionWithContent(fileName, content); + } + return action->clone(); +} + ActionTimeline* ActionTimelineCache::loadAnimationActionWithFile(const std::string& fileName) { // Read content from file @@ -403,7 +413,7 @@ Frame* ActionTimelineCache::loadZOrderFrame(const rapidjson::Value& json) return frame; } - + ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersFile(const std::string &fileName) { ActionTimeline* action = _animationActions.at(fileName); @@ -414,6 +424,16 @@ ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersFile(const std:: return action->clone(); } +ActionTimeline* ActionTimelineCache::createActionWithDataBuffer(Data data, const std::string &fileName) +{ + ActionTimeline* action = _animationActions.at(fileName); + if (action == NULL) + { + action = loadAnimationWithDataBuffer(data, fileName); + } + return action->clone(); +} + ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(const std::string &fileName) { // if already exists an action with filename, then return this action diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h index b4bd6a299a..9d06e545b4 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h @@ -78,11 +78,14 @@ public: /** Clone a action with the specified name from the container. */ ActionTimeline* createActionFromJson(const std::string& fileName); + ActionTimeline* createActionFromContent(const std::string& fileName, const std::string& content); ActionTimeline* loadAnimationActionWithFile(const std::string& fileName); ActionTimeline* loadAnimationActionWithContent(const std::string&fileName, const std::string& content); ActionTimeline* createActionWithFlatBuffersFile(const std::string& fileName); + ActionTimeline* createActionWithDataBuffer(cocos2d::Data data, const std::string &fileName); + ActionTimeline* loadAnimationActionWithFlatBuffersFile(const std::string& fileName); ActionTimeline* loadAnimationWithDataBuffer(const cocos2d::Data data, const std::string fileName); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index de6ab1fd0d..80c201cc57 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -356,12 +356,12 @@ ActionTimeline* CSLoader::createTimeline(const Data data, const std::string& fil if (suffix == "csb") { - return cache->loadAnimationWithDataBuffer(data, filename); + return cache->createActionWithDataBuffer(data, filename); } else if (suffix == "json" || suffix == "ExportJson") { std::string content((char *)data.getBytes(), data.getSize()); - return cache->loadAnimationActionWithContent(filename, content); + return cache->createActionFromContent(filename, content); } return nullptr; @@ -1016,7 +1016,7 @@ Node* CSLoader::nodeWithFlatBuffers(const flatbuffers::NodeTree *nodetree, const { Data buf = FileUtils::getInstance()->getDataFromFile(filePath); node = createNode(buf, callback); - action = timeline::ActionTimelineCache::getInstance()->loadAnimationWithDataBuffer(buf, filePath); + action = createTimeline(buf, filePath); } else { diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp index 2b335ed6fc..4f14965561 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp @@ -27,6 +27,7 @@ CocoStudioActionTimelineTests::CocoStudioActionTimelineTests() ADD_TEST_CASE(TestActionTimelineBlendFuncFrame); ADD_TEST_CASE(TestAnimationClipEndCallBack); ADD_TEST_CASE(TestActionTimelinePlayableFrame); + ADD_TEST_CASE(TestActionTimelineIssueWith2SameActionInOneNode); } CocoStudioActionTimelineTests::~CocoStudioActionTimelineTests() @@ -742,3 +743,21 @@ std::string TestActionTimelinePlayableFrame::title() const { return "Test Action Timeline PlayableFrame\n particle and audio"; } + +void TestActionTimelineIssueWith2SameActionInOneNode::onEnter() +{ + CCFileUtils::getInstance()->addSearchPath("ActionTimeline"); + ActionTimelineBaseTest::onEnter(); + + Node* node = CSLoader::createNode("ani2.csb"); + ActionTimeline* action = CSLoader::createTimeline("ani2.csb"); + node->setPosition(Vec2(150, 100)); + node->runAction(action); + action->gotoFrameAndPlay(0); + this->addChild(node); +} + +std::string TestActionTimelineIssueWith2SameActionInOneNode::title() const +{ + return "Add multi same action in one node issue\n These two actions should play async."; +} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h index 0942f9a426..0a8b8a2cbf 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h @@ -164,4 +164,14 @@ public: virtual void onEnter() override; virtual std::string title() const override; }; + +class TestActionTimelineIssueWith2SameActionInOneNode : public ActionTimelineBaseTest +{ +public: + CREATE_FUNC(TestActionTimelineIssueWith2SameActionInOneNode); + + virtual void onEnter() override; + virtual std::string title() const override; +}; + #endif // __ANIMATION_SCENE_H__ diff --git a/tests/cpp-tests/Resources/ActionTimeline/ani1.csb b/tests/cpp-tests/Resources/ActionTimeline/ani1.csb new file mode 100644 index 0000000000000000000000000000000000000000..c6b95db42a80c8f194d854f9d47d6664247db091 GIT binary patch literal 1216 zcmaJ>JuC!46n;2PM4{M-;tJvl5!oD3D1>vlh(hFoLMInah>I%_N~J<4QK%$(5kCcm zWEDcC&?ps3g<8V;zV~jji;I`MnfGSCnfcz&t|uaGl9GfpODil-Ixq@Gk0K^vik;##R3!C*CkSpuW+ zNl8wbk~O)eBnh59GKBq-XVh7L=N52eCPZ4Goa3Ag@5`(* zV6+r+NK2m#DhIA4@p@h+WKs&^a{=K`V(7XW3)RDL3fW(29*1fFeBCECyCo#Kr4h-P9<>B%**Hb@^!%5eu7BN;)Lo?Reb!DwR z#qv8~-Pr@n=e;Auvp*Z4&(K9^yf4O4FZ!%6xze7lY!o+EDr+;Vr7gJH|KxrKEa$f` z*4TvpOVy`MIgH)OPUE*RvrsJaV`48`ueWO~?hKYy+A(sipnYV$ML(~;?I{ouwpAl$ ztS$z|%9sn4^%cfIEIxmkgYup`+(S;5FJhy7-DECv$KAI9aTkByBVX?P6!NwEIP#5F X<#Kd*AG~^x0eSK7#5%f8bGLj0Jzj}$ literal 0 HcmV?d00001 diff --git a/tests/cpp-tests/Resources/ActionTimeline/ani2.csb b/tests/cpp-tests/Resources/ActionTimeline/ani2.csb new file mode 100644 index 0000000000000000000000000000000000000000..3c84f7aee73c238cd9f6350aa368310765fb6be5 GIT binary patch literal 2360 zcmaJ?K}b|#5T4A`Olk=c4+eW!La2SHbT9~WMa07rk{}XNZ0km=;zn*H)WJG*@E8#t zqD$eSLkEk9=%Pq?38GVn>Li^aJVY2-ukU;Fk8k%+9r*YEXWln6-^`o$Z?lLbq)lq2 zL7H%CmR9@mX*ygG{4arK}11Jku#<70#Pu@CRP&_ zCmYU(Smt2P16V^>OB02B*<4{!X$ixSF?%+`kUkAq*@dS)+;h{#&LBT?5l1-;TtD{D zUoZWnPI-y-?#8j@?~}KdMCMNGiXI8zp`Mg?5(@b=Vht3h3M6u&3yLRef5VWR$%V18 z`Vc>(IjX^Hf3!cuwqxyHYaMEA@^!o?`39MOshwC+%A*}Kqkrh0v zjCt;N7*gl#lRwXAOXXa-SehQ5EL?{w2qEKG>?K0V9ejt}+psgY32iHgN1bQNqQeei z->0VNm(SNd>=%bkVK*potxmU?2ca8h-XV-ToX<`1;_$h4;X9(=Dtwfye#^97@#3C$ z*dMSf*BJZI!_GVG`^X;Sc&{P!R{gJ`8`oyo`EG_vGe!27IG=Bii#v;*eC-Y*-z04G zu|7;V>=W$dTZzqj*!vDUhrJS4_Hc|@$(Q$QCQr5_xv6V~i0>?H-Hyjm7kAvnA!m$Q zR42dr{aERAGLy|F(`lSXfMXx{1vW@M=8bQVx(e&Sm_{}FzIR=&n=Tjguopfqz&*Jx>IN#t$&L*_ogN?fN{I#?4C2zfJ_&yWS-9V0Z_mjs9 zFNbpU87fDOr*FCz(a6PO@y!1u-fR3uC~=fVWY-&y`73Mi=aV&zIp1Y)(^+dpOr15= j0e~!^n>*~Ig^)9n5OkQ