Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) {
}


auto *verticesMap = SkeletonDataMgr::getInstance()->getSkeletonDataInfo(_uuid);
if (!verticesMap) return;
auto &attachmentVerticesMap = *verticesMap;
auto *skeletonDataInfo = SkeletonDataMgr::getInstance()->getSkeletonDataInfo(_uuid);
if (!skeletonDataInfo) return;
auto &attachmentVerticesMap = skeletonDataInfo->attachmentVerticesMap;
auto &drawOrder = _skeleton->getDrawOrder();
for (size_t i = 0, n = drawOrder.size(); i < n; ++i) {
slot = drawOrder[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,26 @@ extern "C" AttachmentVertices *generateAttachmentVertices(Attachment *attachment
}

namespace cc {
class SkeletonDataInfo {
public:
SkeletonDataInfo() = default;

~SkeletonDataInfo() {
if (data) {
delete data;
data = nullptr;
}

if (atlas) {
delete atlas;
atlas = nullptr;
}

if (attachmentLoader) {
delete attachmentLoader;
attachmentLoader = nullptr;
}
SkeletonDataInfo::~SkeletonDataInfo() {
if (data) {
delete data;
data = nullptr;
}

for (const auto& pair : attachmentVerticesMap) {
delete pair.second;
}
if (atlas) {
delete atlas;
atlas = nullptr;
}

SkeletonData *data = nullptr;
Atlas *atlas = nullptr;
AttachmentLoader *attachmentLoader = nullptr;
std::vector<int> texturesIndex;
std::unordered_map<Attachment *, AttachmentVertices *> attachmentVerticesMap;
};
if (attachmentLoader) {
delete attachmentLoader;
attachmentLoader = nullptr;
}

for (const auto &pair : attachmentVerticesMap) {
delete pair.second;
}
}

void saveAttachmentVertices(SkeletonDataInfo *info) {
auto &attachmentVerticesMap = info->attachmentVerticesMap;
Expand Down Expand Up @@ -162,13 +150,21 @@ void SkeletonDataMgr::setSkeletonData(const std::string &uuid, SkeletonData *dat
saveAttachmentVertices(info);
}

std::unordered_map<Attachment *, AttachmentVertices *>
*SkeletonDataMgr::getSkeletonDataInfo(const std::string &uuid) {
SkeletonDataInfo *SkeletonDataMgr::getSkeletonDataInfo(const std::string &uuid) {
auto dataIt = _dataMap.find(uuid);
if (dataIt == _dataMap.end()) {
return nullptr;
}
return &dataIt->second->attachmentVerticesMap;
return dataIt->second;
}

std::vector<SkeletonDataInfo *> SkeletonDataMgr::getSkeletonDataInfos() const {
std::vector<SkeletonDataInfo *> infos;
infos.reserve(_dataMap.size());
for (const auto &pair : _dataMap) {
infos.push_back(pair.second);
}
return infos;
}

SkeletonData *SkeletonDataMgr::retainByUUID(const std::string &uuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,30 @@
#include <string>
#include <vector>
#include <unordered_map>
#include "AttachmentVertices.h"
#include "base/RefCounted.h"
#include "spine/SkeletonData.h"
#include "spine/spine.h"

using namespace spine;
namespace cc {

class SkeletonDataInfo;
class AttachmentVertices;


class SkeletonDataInfo {
public:
SkeletonDataInfo() = default;

~SkeletonDataInfo();

SkeletonData *data = nullptr;
Atlas *atlas = nullptr;
AttachmentLoader *attachmentLoader = nullptr;
std::vector<int> texturesIndex;
std::unordered_map<Attachment *, AttachmentVertices *> attachmentVerticesMap;
};

/**
* Cache skeleton data.
*/
Expand Down Expand Up @@ -73,14 +87,15 @@ class SkeletonDataMgr final {
// equal to 'deleteByUUID'
void releaseByUUID(const std::string &uuid);

std::unordered_map<Attachment *, AttachmentVertices *>
*getSkeletonDataInfo(const std::string &uuid);
SkeletonDataInfo *getSkeletonDataInfo(const std::string &uuid);

using destroyCallback = std::function<void(int)>;
void setDestroyCallback(destroyCallback callback) {
_destroyCallback = std::move(callback);
}

std::vector<SkeletonDataInfo*> getSkeletonDataInfos() const;

private:
static SkeletonDataMgr *instance;
destroyCallback _destroyCallback = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ enum DebugType {

extern "C" AttachmentVertices *generateAttachmentVertices(Attachment *attachment);
namespace cc {

/**
* The slot-associated attachment may exist on different skeletonData, so setSlotTexture needs to traverse all skeletonData.
*/
AttachmentVertices *getAttachmentVertices(Attachment *attachment) {
const auto &vecInfos = SkeletonDataMgr::getInstance()->getSkeletonDataInfos();
for (const auto &info : vecInfos) {
auto &attachmentVerticesMap = info->attachmentVerticesMap;
if (attachmentVerticesMap.count(attachment) > 0) {
return attachmentVerticesMap[attachment];
}
}
return nullptr;
}

SkeletonRenderer *SkeletonRenderer::create() {
return new SkeletonRenderer();
}
Expand Down Expand Up @@ -412,9 +427,9 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
void *effect = nullptr;
#endif

auto *verticesMap = SkeletonDataMgr::getInstance()->getSkeletonDataInfo(_uuid);
if (!verticesMap) return;
auto &attachmentVerticesMap = *verticesMap;
auto *skeletonDataInfo = SkeletonDataMgr::getInstance()->getSkeletonDataInfo(_uuid);
if (!skeletonDataInfo) return;
auto &attachmentVerticesMap = skeletonDataInfo->attachmentVerticesMap;
auto &drawOrder = _skeleton->getDrawOrder();
for (size_t i = 0, n = drawOrder.size(); i < n; ++i) {
isFull = 0;
Expand Down Expand Up @@ -449,7 +464,8 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
if (iterAttachment != attachmentVerticesMap.end()) {
attachmentVertices = iterAttachment->second;
} else {
attachmentVertices = nullptr;
//attachment maybe set from other skeletonData
attachmentVertices = getAttachmentVertices(tmpAttachment);
}

auto iter = _slotTextureSet.find(slot);
Expand Down Expand Up @@ -1160,10 +1176,7 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D
if (!attachment) return;
auto width = tex2d->getWidth();
auto height = tex2d->getHeight();
auto *verticesMap = SkeletonDataMgr::getInstance()->getSkeletonDataInfo(_uuid);
if (!verticesMap) return;
auto &attachmentVerticesMap = *verticesMap;
auto *attachmentVertices = attachmentVerticesMap.at(attachment);
auto *attachmentVertices = getAttachmentVertices(slot->getAttachment());

if (createAttachment) {
attachment = attachment->copy();
Expand Down
2 changes: 2 additions & 0 deletions native/tools/swig-config/spine_3_8.i
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ using namespace spine;
%ignore spine::Polygon::Polygon;
%ignore spine::Polygon::_vertices;

%ignore cc::SkeletonDataInfo;
%ignore cc::SlotCacheInfo;
%ignore cc::SkeletonRenderer::create;
%ignore cc::SkeletonRenderer::initWithJsonFile;
Expand Down Expand Up @@ -116,6 +117,7 @@ using namespace spine;
%ignore cc::SkeletonDataMgr::retainByUUID;
%ignore cc::SkeletonDataMgr::releaseByUUID;
%ignore cc::SkeletonDataMgr::getSkeletonDataInfo;
%ignore cc::SkeletonDataMgr::getSkeletonDataInfos();
%ignore cc::SkeletonCacheAnimation::render;
%ignore cc::SkeletonCacheAnimation::requestDrawInfo;
%ignore cc::SkeletonCacheAnimation::requestMaterial;
Expand Down
2 changes: 2 additions & 0 deletions native/tools/swig-config/spine_4_2.i
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ using namespace spine;
%ignore spine::Polygon::Polygon;
%ignore spine::Polygon::_vertices;

%ignore cc::SkeletonDataInfo;
%ignore cc::SlotCacheInfo;
%ignore cc::SkeletonRenderer::create;
%ignore cc::SkeletonRenderer::initWithJsonFile;
Expand Down Expand Up @@ -114,6 +115,7 @@ using namespace spine;
%ignore cc::SkeletonDataMgr::retainByUUID;
%ignore cc::SkeletonDataMgr::releaseByUUID;
%ignore cc::SkeletonDataMgr::getSkeletonDataInfo;
%ignore cc::SkeletonDataMgr::getSkeletonDataInfos();
%ignore cc::SkeletonCacheAnimation::render;
%ignore cc::SkeletonCacheAnimation::requestDrawInfo;
%ignore cc::SkeletonCacheAnimation::requestMaterial;
Expand Down
Loading