2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
2019-11-24 23:15:56 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
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 __CCDATAREADERHELPER_H__
|
|
|
|
#define __CCDATAREADERHELPER_H__
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CCArmatureDefine.h"
|
|
|
|
#include "CCDatas.h"
|
|
|
|
#include "CCArmature.h"
|
|
|
|
#include "DictionaryHelper.h"
|
|
|
|
#include "CocosStudioExport.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2020-10-21 12:28:34 +08:00
|
|
|
#include "pugixml/pugixml.hpp"
|
2019-11-24 23:15:56 +08:00
|
|
|
#include "pugixml/pugiext.hpp"
|
|
|
|
|
2020-05-06 15:42:25 +08:00
|
|
|
#include "rapidjson/document-wrapper.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <queue>
|
|
|
|
#include <mutex>
|
|
|
|
#include <thread>
|
|
|
|
#include <condition_variable>
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
class CocoLoader;
|
|
|
|
struct stExpCocoNode;
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL DataReaderHelper : cocos2d::Ref
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
enum ConfigType
|
|
|
|
{
|
|
|
|
DragonBone_XML,
|
|
|
|
CocoStudio_JSON,
|
|
|
|
CocoStudio_Binary
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _AsyncStruct
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string filename;
|
|
|
|
std::string fileContent;
|
|
|
|
ConfigType configType;
|
|
|
|
std::string baseFilePath;
|
|
|
|
cocos2d::Ref* target;
|
|
|
|
cocos2d::SEL_SCHEDULE selector;
|
|
|
|
bool autoLoadSpriteFile;
|
|
|
|
|
|
|
|
std::string imagePath;
|
|
|
|
std::string plistPath;
|
2019-11-23 20:27:39 +08:00
|
|
|
} AsyncStruct;
|
|
|
|
|
|
|
|
typedef struct _DataInfo
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
AsyncStruct* asyncStruct;
|
|
|
|
std::queue<std::string> configFileQueue;
|
2019-11-23 20:27:39 +08:00
|
|
|
float contentScale;
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string filename;
|
|
|
|
std::string baseFilePath;
|
2019-11-23 20:27:39 +08:00
|
|
|
float flashToolVersion;
|
|
|
|
float cocoStudioVersion;
|
|
|
|
} DataInfo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** @deprecated Use getInstance() instead */
|
2021-12-25 10:04:45 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static DataReaderHelper* sharedDataReaderHelper()
|
|
|
|
{
|
|
|
|
return DataReaderHelper::getInstance();
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static DataReaderHelper* getInstance();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scale the position data, used for multiresolution adapter
|
|
|
|
* It won't effect the data already read.
|
|
|
|
*/
|
|
|
|
static void setPositionReadScale(float scale);
|
|
|
|
static float getPositionReadScale();
|
|
|
|
|
|
|
|
static void purge();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
|
|
|
DataReaderHelper();
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
~DataReaderHelper();
|
|
|
|
|
|
|
|
void addDataFromFile(const std::string& filePath);
|
2021-12-25 10:04:45 +08:00
|
|
|
void addDataFromFileAsync(const std::string& imagePath,
|
|
|
|
const std::string& plistPath,
|
|
|
|
const std::string& filePath,
|
|
|
|
cocos2d::Ref* target,
|
|
|
|
cocos2d::SEL_SCHEDULE selector);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
void addDataAsyncCallBack(float dt);
|
|
|
|
|
|
|
|
void removeConfigFile(const std::string& configFile);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
public:
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* 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 kept.
|
|
|
|
*
|
|
|
|
* @param xmlPath The cache of the xml
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static void addDataFromCache(const std::string& pFileContent, DataInfo* dataInfo = nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode Armature Datas from xml export from Dragon Bone flash tool
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static ArmatureData* decodeArmature(pugi::xml_node& armatureXML, DataInfo* dataInfo);
|
|
|
|
static BoneData* decodeBone(pugi::xml_node& boneXML, pugi::xml_node& parentXML, DataInfo* dataInfo);
|
|
|
|
static DisplayData* decodeBoneDisplay(pugi::xml_node& displayXML, DataInfo* dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode ArmatureAnimation Datas from xml export from Dragon Bone flash tool
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static AnimationData* decodeAnimation(pugi::xml_node& animationXML, DataInfo* dataInfo);
|
|
|
|
static MovementData* decodeMovement(pugi::xml_node& movementXML, ArmatureData* armatureData, DataInfo* dataInfo);
|
|
|
|
static MovementBoneData* decodeMovementBone(pugi::xml_node& movBoneXml,
|
|
|
|
pugi::xml_node& parentXml,
|
|
|
|
BoneData* boneData,
|
|
|
|
DataInfo* dataInfo);
|
|
|
|
static FrameData* decodeFrame(pugi::xml_node& frameXML,
|
|
|
|
pugi::xml_node& parentFrameXml,
|
|
|
|
BoneData* boneData,
|
|
|
|
DataInfo* dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode Texture Datas from xml export from Dragon Bone flash tool
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static TextureData* decodeTexture(pugi::xml_node& textureXML, DataInfo* dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode Contour Datas from xml export from Dragon Bone flash tool
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static ContourData* decodeContour(pugi::xml_node& contourXML, DataInfo* dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
static void addDataFromJsonCache(const std::string& fileContent, DataInfo* dataInfo = nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static ArmatureData* decodeArmature(const rapidjson::Value& json, DataInfo* dataInfo);
|
|
|
|
static BoneData* decodeBone(const rapidjson::Value& json, DataInfo* dataInfo);
|
|
|
|
static DisplayData* decodeBoneDisplay(const rapidjson::Value& json, DataInfo* dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static AnimationData* decodeAnimation(const rapidjson::Value& json, DataInfo* dataInfo);
|
|
|
|
static MovementData* decodeMovement(const rapidjson::Value& json, DataInfo* dataInfo);
|
|
|
|
static MovementBoneData* decodeMovementBone(const rapidjson::Value& json, DataInfo* dataInfo);
|
|
|
|
static FrameData* decodeFrame(const rapidjson::Value& json, DataInfo* dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static TextureData* decodeTexture(const rapidjson::Value& json);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static ContourData* decodeContour(const rapidjson::Value& json);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static void decodeNode(BaseData* node, const rapidjson::Value& json, DataInfo* dataInfo);
|
|
|
|
|
|
|
|
// for binary decode
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
static void addDataFromBinaryCache(const char* fileContent, DataInfo* dataInfo = nullptr);
|
|
|
|
static ArmatureData* decodeArmature(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, DataInfo* dataInfo);
|
|
|
|
static BoneData* decodeBone(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, DataInfo* dataInfo);
|
|
|
|
static DisplayData* decodeBoneDisplay(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, DataInfo* dataInfo);
|
|
|
|
static AnimationData* decodeAnimation(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, DataInfo* dataInfo);
|
|
|
|
static MovementData* decodeMovement(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, DataInfo* dataInfo);
|
|
|
|
|
|
|
|
static MovementBoneData* decodeMovementBone(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, DataInfo* dataInfo);
|
|
|
|
static FrameData* decodeFrame(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, DataInfo* dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static TextureData* decodeTexture(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
|
|
|
|
static ContourData* decodeContour(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static void decodeNode(BaseData* node, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, DataInfo* dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
protected:
|
|
|
|
void loadData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::condition_variable _sleepCondition;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::thread* _loadingThread;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::mutex _sleepMutex;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::mutex _asyncStructQueueMutex;
|
|
|
|
std::mutex _dataInfoMutex;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::mutex _addDataMutex;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::mutex _getFileMutex;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
unsigned long _asyncRefCount;
|
|
|
|
unsigned long _asyncRefTotalCount;
|
|
|
|
|
|
|
|
bool need_quit;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::queue<AsyncStruct*>* _asyncStructQueue;
|
|
|
|
std::queue<DataInfo*>* _dataQueue;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
static std::vector<std::string> _configFileList;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static DataReaderHelper* _dataReaderHelper;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif /*__CCDATAREADERHELPER_H__*/
|