2019-11-24 23:15:56 +08:00
|
|
|
#ifndef _SPINESKELETONDATACACHE_H_
|
|
|
|
#define _SPINESKELETONDATACACHE_H_
|
|
|
|
#include <cocos2d.h>
|
|
|
|
#include "spine/spine.h"
|
|
|
|
#include "spine/spine-cocos2dx.h"
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CocosStudioExport.h"
|
2019-11-30 01:32:12 +08:00
|
|
|
#include <functional>
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2020-11-04 19:09:30 +08:00
|
|
|
#if !defined(CC_USE_SPINE_CPP) || CC_USE_SPINE_CPP
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL SpineSkeletonDataCache
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
|
|
|
public:
|
2022-07-11 17:50:21 +08:00
|
|
|
class SkeletonData : public axis::Ref
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SkeletonData(spine::SkeletonData* d, spine::AttachmentLoader* loader) : data(d), attachmentLoader(loader) {}
|
|
|
|
~SkeletonData()
|
|
|
|
{
|
|
|
|
if (data != nullptr)
|
|
|
|
delete (data);
|
|
|
|
if (attachmentLoader != nullptr)
|
|
|
|
delete (attachmentLoader);
|
|
|
|
}
|
|
|
|
spine::AttachmentLoader* attachmentLoader;
|
2019-12-12 23:24:50 +08:00
|
|
|
spine::SkeletonData* data;
|
2021-12-25 10:04:45 +08:00
|
|
|
};
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static SpineSkeletonDataCache* getInstance();
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2019-11-30 01:32:12 +08:00
|
|
|
SpineSkeletonDataCache();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void setErrorReportFunc(void (*errorfunc)(const char* pszFormat, ...));
|
2019-11-30 01:32:12 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
SkeletonData* addData(const char* dataFile, const char* atlasFile, float scale);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void removeData(const char* dataFile);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void removeAllData(void);
|
|
|
|
void removeAllUnusedData(void);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
public:
|
2021-12-31 12:12:40 +08:00
|
|
|
hlookup::string_map<SkeletonData*> _cacheTable;
|
2021-12-25 10:04:45 +08:00
|
|
|
void (*_reportError)(const char* pszFormat, ...);
|
2019-11-24 23:15:56 +08:00
|
|
|
};
|
|
|
|
|
2020-11-04 19:09:30 +08:00
|
|
|
#else
|
|
|
|
class SpineSkeletonDataCache
|
|
|
|
{
|
|
|
|
public:
|
2022-07-11 17:50:21 +08:00
|
|
|
class SkeletonData : public axis::Ref
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SkeletonData(spSkeletonData* d, spAttachmentLoader* loader) : data(d), attachmentLoader(loader) {}
|
|
|
|
~SkeletonData()
|
|
|
|
{
|
|
|
|
if (data != nullptr)
|
|
|
|
spSkeletonData_dispose(data);
|
|
|
|
if (attachmentLoader != nullptr)
|
|
|
|
spAttachmentLoader_dispose(attachmentLoader);
|
|
|
|
}
|
|
|
|
spAttachmentLoader* attachmentLoader;
|
|
|
|
spSkeletonData* data;
|
|
|
|
};
|
2020-11-04 19:09:30 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
SpineSkeletonDataCache();
|
2020-11-04 19:09:30 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void setErrorReportFunc(void (*errorfunc)(const char* pszFormat, ...));
|
2020-11-04 19:09:30 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static SpineSkeletonDataCache* getInstance();
|
2020-11-04 19:09:30 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
SkeletonData* addData(const char* dataFile, const char* atlasFile, float scale);
|
2020-11-04 19:09:30 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void removeData(const char* dataFile);
|
2020-11-04 19:09:30 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void removeAllData(void);
|
|
|
|
void removeAllUnusedData(void);
|
2020-11-04 19:09:30 +08:00
|
|
|
|
|
|
|
public:
|
2021-12-31 12:12:40 +08:00
|
|
|
hlookup::string_map<SkeletonData*> _cacheTable;
|
2021-12-25 10:04:45 +08:00
|
|
|
void (*_reportError)(const char* pszFormat, ...);
|
2020-11-04 19:09:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
#endif
|