From 41661830ffa2a9094e177d3cabad3658886ea710 Mon Sep 17 00:00:00 2001 From: pipu Date: Wed, 1 Apr 2015 13:37:36 +0800 Subject: [PATCH 1/2] Remove CCNodeReader.h/.cpp. --- cocos/2d/libcocos2d.vcxproj | 2 - cocos/2d/libcocos2d.vcxproj.filters | 2 - .../ActionTimeline/CCNodeReader.cpp | 473 ------------------ .../cocostudio/ActionTimeline/CCNodeReader.h | 91 ---- cocos/editor-support/cocostudio/Android.mk | 1 - 5 files changed, 569 deletions(-) delete mode 100644 cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.cpp delete mode 100644 cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.h diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index dfbb65c4ee..073e338e2a 100755 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -479,7 +479,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* - @@ -1034,7 +1033,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* - diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index 4f4420da8b..c340b03a2d 100755 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -1240,7 +1240,6 @@ audioengine - cocostudio\TimelineAction @@ -2941,7 +2940,6 @@ audioengine - cocostudio\TimelineAction diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.cpp deleted file mode 100644 index 6ed0ef0e47..0000000000 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.cpp +++ /dev/null @@ -1,473 +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 "CCNodeReader.h" -#include "CCActionTimelineCache.h" -#include "CCActionTimeline.h" - -#include "cocostudio/CCSGUIReader.h" - -using namespace cocos2d; -using namespace ui; - -namespace cocostudio { -namespace timeline{ - - -static const char* ClassName_Node = "Node"; -static const char* ClassName_SubGraph = "SubGraph"; -static const char* ClassName_Sprite = "Sprite"; -static const char* ClassName_Particle = "Particle"; - -static const char* ClassName_Panel = "Panel"; -static const char* ClassName_Button = "Button"; -static const char* ClassName_CheckBox = "CheckBox"; -static const char* ClassName_ImageView = "ImageView"; -static const char* ClassName_TextAtlas = "TextAtlas"; -static const char* ClassName_LabelAtlas = "LabelAtlas"; -static const char* ClassName_LabelBMFont= "LabelBMFont"; -static const char* ClassName_TextBMFont = "TextBMFont"; -static const char* ClassName_Text = "Text"; -static const char* ClassName_LoadingBar = "LoadingBar"; -static const char* ClassName_TextField = "TextField"; -static const char* ClassName_Slider = "Slider"; -static const char* ClassName_Layout = "Layout"; -static const char* ClassName_ScrollView = "ScrollView"; -static const char* ClassName_ListView = "ListView"; -static const char* ClassName_PageView = "PageView"; -static const char* ClassName_Widget = "Widget"; -static const char* ClassName_Label = "Label"; - - -static const char* NODE = "nodeTree"; -static const char* CHILDREN = "children"; -static const char* CLASSNAME = "classname"; -static const char* FILE_PATH = "fileName"; -static const char* PLIST_FILE = "plistFile"; -static const char* TAG = "tag"; -static const char* ACTION_TAG = "actionTag"; - -static const char* OPTIONS = "options"; - -static const char* WIDTH = "width"; -static const char* HEIGHT = "height"; -static const char* X = "x"; -static const char* Y = "y"; -static const char* SCALE_X = "scaleX"; -static const char* SCALE_Y = "scaleY"; -static const char* SKEW_X = "skewX"; -static const char* SKEW_Y = "skewY"; -static const char* ROTATION = "rotation"; -static const char* ROTATION_SKEW_X = "rotationSkewX"; -static const char* ROTATION_SKEW_Y = "rotationSkewY"; -static const char* ANCHOR_X = "anchorPointX"; -static const char* ANCHOR_Y = "anchorPointY"; -static const char* ALPHA = "opacity"; -static const char* RED = "colorR"; -static const char* GREEN = "colorG"; -static const char* BLUE = "colorB"; -static const char* ZORDER = "ZOrder"; -static const char* PARTICLE_NUM = "particleNum"; -static const char* FLIPX = "flipX"; -static const char* FLIPY = "flipY"; -static const char* VISIBLE = "visible"; - -static const char* TEXTURES = "textures"; -static const char* TEXTURES_PNG = "texturesPng"; - - -// NodeReader -static NodeReader* _sharedNodeReader = nullptr; - -NodeReader* NodeReader::getInstance() -{ - if (! _sharedNodeReader) - { - _sharedNodeReader = new (std::nothrow) NodeReader(); - _sharedNodeReader->init(); - } - - return _sharedNodeReader; -} - -void NodeReader::destroyInstance() -{ - CC_SAFE_DELETE(_sharedNodeReader); -} - -NodeReader::NodeReader() - : _recordJsonPath(true) - , _jsonPath("") -{ -} - -void NodeReader::purge() -{ -} - -void NodeReader::init() -{ - using namespace std::placeholders; - - _funcs.insert(Pair(ClassName_Node, std::bind(&NodeReader::loadSimpleNode, this, _1))); - _funcs.insert(Pair(ClassName_SubGraph, std::bind(&NodeReader::loadSubGraph, this, _1))); - _funcs.insert(Pair(ClassName_Sprite, std::bind(&NodeReader::loadSprite, this, _1))); - _funcs.insert(Pair(ClassName_Particle, std::bind(&NodeReader::loadParticle, this, _1))); - _funcs.insert(Pair(ClassName_LabelAtlas,std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_LabelBMFont,std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_Panel, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_Button, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_CheckBox, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_ImageView, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_TextAtlas, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_TextBMFont,std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_Text, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_LoadingBar,std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_TextField, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_Slider, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_Layout, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_ScrollView,std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_ListView, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_PageView, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_Widget, std::bind(&NodeReader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_Label, std::bind(&NodeReader::loadWidget, this, _1))); - -} - -Node* NodeReader::createNode(const std::string& filename) -{ - if(_recordJsonPath) - { - std::string jsonPath = filename.substr(0, filename.find_last_of('/') + 1); - GUIReader::getInstance()->setFilePath(jsonPath); - - _jsonPath = jsonPath; - } - else - { - GUIReader::getInstance()->setFilePath(""); - _jsonPath = ""; - } - - Node* node = loadNodeWithFile(filename); - - return node; -} - -Node* NodeReader::loadNodeWithFile(const std::string& fileName) -{ - // Read content from file - std::string contentStr = FileUtils::getInstance()->getStringFromFile(fileName); - - Node* node = loadNodeWithContent(contentStr); - - // Load animation data from file - ActionTimelineCache::getInstance()->loadAnimationActionWithContent(fileName, contentStr); - - return node; -} - -Node* NodeReader::loadNodeWithContent(const std::string& content) -{ - rapidjson::Document doc; - doc.Parse<0>(content.c_str()); - if (doc.HasParseError()) - { - CCLOG("GetParseError %s\n", doc.GetParseError()); - } - - // decode plist - int length = DICTOOL->getArrayCount_json(doc, TEXTURES); - - for(int i=0; igetStringValueFromArray_json(doc, TEXTURES, i); - std::string png = DICTOOL->getStringValueFromArray_json(doc, TEXTURES_PNG, i); - plist = _jsonPath + plist; - png = _jsonPath + png; - SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plist, png); - } - - // decode node tree - const rapidjson::Value& subJson = DICTOOL->getSubDictionary_json(doc, NODE); - Node* root = loadNode(subJson); - root->release(); - - return root; -} - -Node* NodeReader::loadNode(const rapidjson::Value& json) -{ - Node* node = nullptr; - std::string nodeType = DICTOOL->getStringValue_json(json, CLASSNAME); - - NodeCreateFunc func = _funcs[nodeType]; - if (func != nullptr) - { - const rapidjson::Value& options = DICTOOL->getSubDictionary_json(json, OPTIONS); - node = func(options); - } - - if(node) - { - int length = DICTOOL->getArrayCount_json(json, CHILDREN, 0); - for (int i = 0; igetSubDictionary_json(json, CHILDREN, i); - Node* child = loadNode(dic); - if (child) - { - auto widgetChild = dynamic_cast(child); - if (widgetChild - && dynamic_cast(node) - && !dynamic_cast(node)) - { - if (widgetChild->getPositionType() == ui::Widget::PositionType::PERCENT) - { - widgetChild->setPositionPercent(Vec2(widgetChild->getPositionPercent().x + node->getAnchorPoint().x, widgetChild->getPositionPercent().y + node->getAnchorPoint().y)); - } - widgetChild->setPosition(Vec2(widgetChild->getPositionX() + node->getAnchorPointInPoints().x, widgetChild->getPositionY() + node->getAnchorPointInPoints().y)); - } - - node->addChild(child); - child->release(); - } - } - } - else - { - CCLOG("Not supported NodeType: %s", nodeType.c_str()); - } - - return node; -} - -void NodeReader::initNode(Node* node, const rapidjson::Value& json) -{ - float width = DICTOOL->getFloatValue_json(json, WIDTH); - float height = DICTOOL->getFloatValue_json(json, HEIGHT); - float x = DICTOOL->getFloatValue_json(json, X); - float y = DICTOOL->getFloatValue_json(json, Y); - float scalex = DICTOOL->getFloatValue_json(json, SCALE_X, 1); - float scaley = DICTOOL->getFloatValue_json(json, SCALE_Y, 1); - float rotation = DICTOOL->getFloatValue_json(json, ROTATION); - float rotationSkewX = DICTOOL->getFloatValue_json(json, ROTATION_SKEW_X); - float rotationSkewY = DICTOOL->getFloatValue_json(json, ROTATION_SKEW_Y); - float skewx = DICTOOL->getFloatValue_json(json, SKEW_X); - float skewy = DICTOOL->getFloatValue_json(json, SKEW_Y); - float anchorx = DICTOOL->getFloatValue_json(json, ANCHOR_X, 0.5f); - float anchory = DICTOOL->getFloatValue_json(json, ANCHOR_Y, 0.5f); - GLubyte alpha = (GLubyte)DICTOOL->getIntValue_json(json, ALPHA, 255); - GLubyte red = (GLubyte)DICTOOL->getIntValue_json(json, RED, 255); - GLubyte green = (GLubyte)DICTOOL->getIntValue_json(json, GREEN, 255); - GLubyte blue = (GLubyte)DICTOOL->getIntValue_json(json, BLUE, 255); - int zorder = DICTOOL->getIntValue_json(json, ZORDER); - int tag = DICTOOL->getIntValue_json(json, TAG); - int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG); - bool visible = DICTOOL->getBooleanValue_json(json, VISIBLE); - - if(x != 0 || y != 0) - node->setPosition(x, y); - if(scalex != 1) - node->setScaleX(scalex); - if(scaley != 1) - node->setScaleY(scaley); - if (rotation != 0) - node->setRotation(rotation); - if(rotationSkewX != 0) - node->setRotationSkewX(rotationSkewX); - if(rotationSkewY != 0) - node->setRotationSkewY(rotationSkewY); - if(skewx != 0) - node->setSkewX(skewx); - if(skewy != 0) - node->setSkewY(skewy); - if(anchorx != 0.5f || anchory != 0.5f) - node->setAnchorPoint(Point(anchorx, anchory)); - if(width != 0 || height != 0) - node->setContentSize(Size(width, height)); - if(zorder != 0) - node->setLocalZOrder(zorder); - if(visible != true) - node->setVisible(visible); - - if(alpha != 255) - { - node->setOpacity(alpha); - } - if(red != 255 || green != 255 || blue != 255) - { - node->setColor(Color3B(red, green, blue)); - } - - - node->setTag(tag); - node->setUserObject(ActionTimelineData::create(actionTag)); -} - -Node* NodeReader::loadSimpleNode(const rapidjson::Value& json) -{ - Node* node = Node::create(); - node->retain(); - initNode(node, json); - - return node; -} - -Node* NodeReader::loadSubGraph(const rapidjson::Value& json) -{ - const char* filePath = DICTOOL->getStringValue_json(json, FILE_PATH); - - Node* node = nullptr; - if (filePath && strcmp("", filePath) != 0) - { - node = createNode(filePath); - } - else - { - node = Node::create(); - } - - node->retain(); - - initNode(node, json); - - return node; -} - -Node* NodeReader::loadSprite(const rapidjson::Value& json) -{ - const char* filePath = DICTOOL->getStringValue_json(json, FILE_PATH); - Sprite *sprite = nullptr; - - if(filePath != nullptr) - { - std::string path = filePath; - - SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(path); - if(!spriteFrame) - { - path = _jsonPath + path; - sprite = Sprite::create(path); - } - else - { - sprite = Sprite::createWithSpriteFrame(spriteFrame); - } - - if(!sprite) - { - sprite = CCSprite::create(); - CCLOG("filePath is empty. Create a sprite with no texture"); - } - } - else - { - sprite = Sprite::create(); - } - - sprite->retain(); - - initNode(sprite, json); - - bool flipX = DICTOOL->getBooleanValue_json(json, FLIPX); - bool flipY = DICTOOL->getBooleanValue_json(json, FLIPY); - - if(flipX != false) - sprite->setFlippedX(flipX); - if(flipY != false) - sprite->setFlippedY(flipY); - - return sprite; -} - -Node* NodeReader::loadParticle(const rapidjson::Value& json) -{ - const char* filePath = DICTOOL->getStringValue_json(json, PLIST_FILE); - int num = DICTOOL->getIntValue_json(json, PARTICLE_NUM); - - ParticleSystemQuad* particle = ParticleSystemQuad::create(filePath); - particle->setTotalParticles(num); - particle->retain(); - - initNode(particle, json); - - return particle; -} - -Node* NodeReader::loadWidget(const rapidjson::Value& json) -{ - const char* str = DICTOOL->getStringValue_json(json, CLASSNAME); - if(str == nullptr) - return nullptr; - - std::string classname = str; - - if (classname == "Panel") - { - classname = "Layout"; - } - else if (classname == "TextArea") - { - classname = "Text"; - } - else if (classname == "TextButton") - { - classname = "Button"; - } - else if (classname == "Label") - { - classname = "Text"; - } - else if (classname == "LabelAtlas") - { - classname = "TextAtlas"; - } - else if (classname == "LabelBMFont") - { - classname = "TextBMFont"; - } - - std::string readerName = classname; - readerName.append("Reader"); - - Widget* widget = dynamic_cast(ObjectFactory::getInstance()->createObject(classname)); - widget->retain(); - - WidgetReaderProtocol* reader = dynamic_cast(ObjectFactory::getInstance()->createObject(readerName)); - - WidgetPropertiesReader0300* guiReader = new (std::nothrow) WidgetPropertiesReader0300(); - guiReader->setPropsForAllWidgetFromJsonDictionary(reader, widget, json); - CC_SAFE_DELETE(guiReader); - - int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG); - widget->setUserObject(ActionTimelineData::create(actionTag)); - - initNode(widget, json); - - return widget; -} - -} -} diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.h b/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.h deleted file mode 100644 index 28e358ab5e..0000000000 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.h +++ /dev/null @@ -1,91 +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 __CC_NODE_CACHE_H__ -#define __CC_NODE_CACHE_H__ - -#include -#include "cocostudio/DictionaryHelper.h" -#include "cocostudio/CocosStudioExport.h" -#include "2d/CCNode.h" - -namespace cocostudio { - - -namespace timeline{ - -class CC_STUDIO_DLL NodeReader -{ -public: - static NodeReader* getInstance(); - static void destroyInstance(); - - NodeReader(); - void purge(); - - void init(); - - cocos2d::Node* createNode(const std::string& filename); - - cocos2d::Node* loadNodeWithFile(const std::string& fileName); - cocos2d::Node* loadNodeWithContent(const std::string& content); - - void setRecordJsonPath(bool record) { _recordJsonPath = record; } - bool isRecordJsonPath() const { return _recordJsonPath; } - - void setJsonPath(std::string jsonPath) { _jsonPath = jsonPath; } - std::string getJsonPath() const { return _jsonPath; } - -protected: - - cocos2d::Node* loadNode(const rapidjson::Value& json); - - void locateNodeWithMulresPosition(cocos2d::Node* node, const rapidjson::Value& json); - - void initNode(cocos2d::Node* node, const rapidjson::Value& json); - - // load nodes - cocos2d::Node* loadSimpleNode(const rapidjson::Value& json); - cocos2d::Node* loadSubGraph (const rapidjson::Value& json); - cocos2d::Node* loadSprite (const rapidjson::Value& json); - cocos2d::Node* loadParticle (const rapidjson::Value& json); - - // load gui - cocos2d::Node* loadWidget(const rapidjson::Value& json); - - typedef std::function NodeCreateFunc; - typedef std::pair Pair; - - std::unordered_map _funcs; - - bool _recordJsonPath; - - std::string _jsonPath; -}; - -} -} - - -#endif /*__CC_NODE_CACHE_H__*/ diff --git a/cocos/editor-support/cocostudio/Android.mk b/cocos/editor-support/cocostudio/Android.mk index 6914cfa01c..8ced24200a 100644 --- a/cocos/editor-support/cocostudio/Android.mk +++ b/cocos/editor-support/cocostudio/Android.mk @@ -65,7 +65,6 @@ WidgetReader/Node3DReader/Node3DReader.cpp \ WidgetReader/Sprite3DReader/Sprite3DReader.cpp \ WidgetReader/UserCameraReader/UserCameraReader.cpp \ WidgetReader/Particle3DReader/Particle3DReader.cpp \ -ActionTimeline/CCNodeReader.cpp \ ActionTimeline/CCActionTimelineCache.cpp \ ActionTimeline/CCFrame.cpp \ ActionTimeline/CCTimeLine.cpp \ From 340e26d81a767113e993bcebf8bc172a6bddcd02 Mon Sep 17 00:00:00 2001 From: pipu Date: Wed, 1 Apr 2015 14:08:09 +0800 Subject: [PATCH 2/2] Supplement invoke destroyInstance() of some Reader in destroyCocosStudio(). --- cocos/editor-support/cocostudio/CocoStudio.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cocos/editor-support/cocostudio/CocoStudio.cpp b/cocos/editor-support/cocostudio/CocoStudio.cpp index 894ecc94a4..646166a545 100644 --- a/cocos/editor-support/cocostudio/CocoStudio.cpp +++ b/cocos/editor-support/cocostudio/CocoStudio.cpp @@ -63,5 +63,11 @@ namespace cocostudio Particle3DReader::destroyInstance(); cocos2d::CSLoader::destroyInstance(); + + + ArmatureDataManager::destroyInstance(); + SceneReader::destroyInstance(); + ActionManagerEx::destroyInstance(); + GUIReader::destroyInstance(); } } \ No newline at end of file