Skip to content
Merged
Changes from 2 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
69 changes: 36 additions & 33 deletions native/cocos/editor-support/spine-wasm/spine-wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,57 +171,60 @@ SkeletonData* SpineWasmUtil::querySpineSkeletonDataByUUID(const String& uuid) {
}

SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const String& jsonStr, const String& altasStr, const spine::Vector<spine::String>& textureNames, const spine::Vector<spine::String>& textureUUIDs) {
SkeletonData* skeletonData = nullptr;
#if ENABLE_JSON_PARSER
auto* atlas = new Atlas(altasStr.buffer(), altasStr.length(), "", nullptr, false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use std::unique_ptr<Atlas> ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart pointers may increase the size of WASM binary files.

if (!atlas) {
return nullptr;
}
AttachmentLoader* attachmentLoader = new AtlasAttachmentLoaderExtension(atlas);
#ifdef CC_SPINE_VERSION_3_8
SkeletonJson json(attachmentLoader);
#else
SkeletonJson json(attachmentLoader, true);
#endif
json.setScale(1.0F);
SkeletonData* skeletonData = json.readSkeletonData(jsonStr.buffer());
auto& errorMsg = json.getError();
if (!errorMsg.isEmpty()) {
logToConsole(errorMsg.buffer(), LOG_LEVEL_WARN);
}
{
AttachmentLoader* attachmentLoader = new AtlasAttachmentLoaderExtension(atlas);
#ifdef CC_SPINE_VERSION_3_8
SkeletonJson json(attachmentLoader);
#else
SkeletonJson json(attachmentLoader, true);
#endif
json.setScale(1.0F);
skeletonData = json.readSkeletonData(jsonStr.buffer());
auto& errorMsg = json.getError();
if (!errorMsg.isEmpty()) {
logToConsole(errorMsg.buffer(), LOG_LEVEL_WARN);
}

saveAttachmentVertices(skeletonData, textureNames, textureUUIDs);
saveAttachmentVertices(skeletonData, textureNames, textureUUIDs);
}
delete atlas;
#endif

return skeletonData;
#else
return nullptr;
#endif
}

SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize, const String& altasStr, const spine::Vector<spine::String>& textureNames, const spine::Vector<spine::String>& textureUUIDs) {
SkeletonData* skeletonData = nullptr;
#if ENABLE_BINARY_PARSER
auto* atlas = new Atlas(altasStr.buffer(), altasStr.length(), "", nullptr, false);
if (!atlas) {
return nullptr;
}
AttachmentLoader* attachmentLoader = new AtlasAttachmentLoaderExtension(atlas);
#ifdef CC_SPINE_VERSION_3_8
SkeletonBinary binary(attachmentLoader);
#else
SkeletonBinary binary(attachmentLoader, true);
#endif
binary.setScale(1.0F);
SkeletonData* skeletonData = binary.readSkeletonData(s_mem, byteSize);
auto& errorMsg = binary.getError();
if (!errorMsg.isEmpty()) {
logToConsole(errorMsg.buffer(), LOG_LEVEL_WARN);
}

saveAttachmentVertices(skeletonData, textureNames, textureUUIDs);
{
AttachmentLoader* attachmentLoader = new AtlasAttachmentLoaderExtension(atlas);
#ifdef CC_SPINE_VERSION_3_8
SkeletonBinary binary(attachmentLoader);
#else
SkeletonBinary binary(attachmentLoader, true);
#endif
binary.setScale(1.0F);
skeletonData = binary.readSkeletonData(s_mem, byteSize);
auto& errorMsg = binary.getError();
if (!errorMsg.isEmpty()) {
logToConsole(errorMsg.buffer(), LOG_LEVEL_WARN);
}

return skeletonData;
#else
return nullptr;
saveAttachmentVertices(skeletonData, textureNames, textureUUIDs);
}
delete atlas;
#endif
return skeletonData;
}

void SpineWasmUtil::registerSpineSkeletonDataWithUUID(SkeletonData* data, const String& uuid) {
Expand Down
Loading