2013-06-06 12:02:54 +08:00
|
|
|
/****************************************************************************
|
2019-11-24 23:15:56 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
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"
|
2013-06-06 12:02:54 +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"
|
2014-06-18 17:43:13 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
#include <string>
|
|
|
|
#include <queue>
|
|
|
|
#include <mutex>
|
|
|
|
#include <thread>
|
2014-01-17 13:49:14 +08:00
|
|
|
#include <condition_variable>
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
class CocoLoader;
|
|
|
|
struct stExpCocoNode;
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL DataReaderHelper : cocos2d::Ref
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
protected:
|
2015-06-17 13:16:06 +08:00
|
|
|
enum ConfigType
|
|
|
|
{
|
|
|
|
DragonBone_XML,
|
|
|
|
CocoStudio_JSON,
|
2014-06-18 20:09:12 +08:00
|
|
|
CocoStudio_Binary
|
2015-06-17 13:16:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2015-06-17 13:16:06 +08:00
|
|
|
} AsyncStruct;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2015-06-17 13:16:06 +08:00
|
|
|
typedef struct _DataInfo
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
AsyncStruct* asyncStruct;
|
|
|
|
std::queue<std::string> configFileQueue;
|
2013-10-30 09:41:40 +08:00
|
|
|
float contentScale;
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string filename;
|
|
|
|
std::string baseFilePath;
|
2013-11-05 11:57:20 +08:00
|
|
|
float flashToolVersion;
|
|
|
|
float cocoStudioVersion;
|
2015-06-17 13:16:06 +08:00
|
|
|
} DataInfo;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
public:
|
2015-06-17 13:16:06 +08:00
|
|
|
/** @deprecated Use getInstance() instead */
|
2021-12-25 10:04:45 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static DataReaderHelper* sharedDataReaderHelper()
|
|
|
|
{
|
|
|
|
return DataReaderHelper::getInstance();
|
|
|
|
}
|
2013-09-16 15:16:05 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static DataReaderHelper* getInstance();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-06-07 10:52:32 +08:00
|
|
|
* Scale the position data, used for multiresolution adapter
|
|
|
|
* It won't effect the data already read.
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
|
|
|
static void setPositionReadScale(float scale);
|
|
|
|
static float getPositionReadScale();
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
static void purge();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
public:
|
2015-06-17 13:16:06 +08:00
|
|
|
/**
|
2013-09-16 14:13:55 +08:00
|
|
|
* @js ctor
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
DataReaderHelper();
|
2013-09-16 14:13:55 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-09-15 19:08:45 +08:00
|
|
|
~DataReaderHelper();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void addDataFromFile(std::string_view filePath);
|
|
|
|
void addDataFromFileAsync(std::string_view imagePath,
|
|
|
|
std::string_view plistPath,
|
|
|
|
std::string_view filePath,
|
2021-12-25 10:04:45 +08:00
|
|
|
cocos2d::Ref* target,
|
|
|
|
cocos2d::SEL_SCHEDULE selector);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
void addDataAsyncCallBack(float dt);
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void removeConfigFile(std::string_view configFile);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
public:
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-09-15 19:08:45 +08:00
|
|
|
* Translate XML export from Dragon Bone flash tool to datas, and save them.
|
2017-02-07 09:41:52 +08:00
|
|
|
* When you add a new xml, the data already saved will be kept.
|
2013-06-06 12:02:54 +08:00
|
|
|
*
|
2013-09-13 18:07:37 +08:00
|
|
|
* @param xmlPath The cache of the xml
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static void addDataFromCache(std::string_view pFileContent, DataInfo* dataInfo = nullptr);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-09-15 19:08:45 +08:00
|
|
|
* Decode Armature Datas from xml export from Dragon Bone flash tool
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
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);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
/**
|
2013-09-15 19:08:45 +08:00
|
|
|
* Decode ArmatureAnimation Datas from xml export from Dragon Bone flash tool
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
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);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-09-15 19:08:45 +08:00
|
|
|
* Decode Texture Datas from xml export from Dragon Bone flash tool
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static TextureData* decodeTexture(pugi::xml_node& textureXML, DataInfo* dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-09-15 19:08:45 +08:00
|
|
|
* Decode Contour Datas from xml export from Dragon Bone flash tool
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static ContourData* decodeContour(pugi::xml_node& contourXML, DataInfo* dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-07 14:01:03 +08:00
|
|
|
public:
|
2021-12-26 23:26:34 +08:00
|
|
|
static void addDataFromJsonCache(std::string_view fileContent, DataInfo* dataInfo = nullptr);
|
2013-09-13 18:07:37 +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);
|
2013-09-13 18:07:37 +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);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static TextureData* decodeTexture(const rapidjson::Value& json);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static ContourData* decodeContour(const rapidjson::Value& json);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static void decodeNode(BaseData* node, const rapidjson::Value& json, DataInfo* dataInfo);
|
|
|
|
|
|
|
|
// for binary decode
|
2014-06-18 17:43:13 +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);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static TextureData* decodeTexture(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
|
|
|
|
static ContourData* decodeContour(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static void decodeNode(BaseData* node, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, DataInfo* dataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
protected:
|
|
|
|
void loadData();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::condition_variable _sleepCondition;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::thread* _loadingThread;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::mutex _sleepMutex;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::mutex _asyncStructQueueMutex;
|
|
|
|
std::mutex _dataInfoMutex;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::mutex _addDataMutex;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::mutex _getFileMutex;
|
2013-10-30 09:41:40 +08:00
|
|
|
|
2015-06-17 13:16:06 +08:00
|
|
|
unsigned long _asyncRefCount;
|
|
|
|
unsigned long _asyncRefTotalCount;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2015-06-17 13:16:06 +08:00
|
|
|
bool need_quit;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
std::queue<AsyncStruct*>* _asyncStructQueue;
|
|
|
|
std::queue<DataInfo*>* _dataQueue;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
static std::vector<std::string> _configFileList;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static DataReaderHelper* _dataReaderHelper;
|
2013-06-06 12:02:54 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
#endif /*__CCDATAREADERHELPER_H__*/
|