From c6495719cacda43ff6a66bbe063c8b4e4bc35877 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 23 Sep 2025 17:07:03 +0200 Subject: [PATCH] [c][cpp][flutter][ios] Make attachment in Skin.setAttachment optional --- spine-c/src/generated/skin.cpp | 4 +- spine-c/src/generated/skin.h | 2 +- spine-cpp/include/spine/Skin.h | 2 +- spine-cpp/src/spine/SkeletonBinary.cpp | 2 +- spine-cpp/src/spine/SkeletonJson.cpp | 2 +- spine-cpp/src/spine/Skin.cpp | 10 ++-- spine-flutter/lib/generated/skin.dart | 6 +-- spine-godot/.vscode/settings.json | 4 +- .../build/generate-compile-commands.sh | 47 +++++++++++++++++++ spine-godot/build/setup.sh | 27 +++++++++++ .../Sources/SpineSwift/Generated/Skin.swift | 4 +- 11 files changed, 92 insertions(+), 18 deletions(-) create mode 100755 spine-godot/build/generate-compile-commands.sh diff --git a/spine-c/src/generated/skin.cpp b/spine-c/src/generated/skin.cpp index 1bc4c432c..fb785f710 100644 --- a/spine-c/src/generated/skin.cpp +++ b/spine-c/src/generated/skin.cpp @@ -11,9 +11,9 @@ void spine_skin_dispose(spine_skin self) { delete (Skin *) self; } -void spine_skin_set_attachment(spine_skin self, size_t slotIndex, const char *name, spine_attachment attachment) { +void spine_skin_set_attachment(spine_skin self, size_t slotIndex, const char *name, /*@null*/ spine_attachment attachment) { Skin *_self = (Skin *) self; - _self->setAttachment(slotIndex, String(name), *((Attachment *) attachment)); + _self->setAttachment(slotIndex, String(name), (Attachment *) attachment); } /*@null*/ spine_attachment spine_skin_get_attachment(spine_skin self, size_t slotIndex, const char *name) { diff --git a/spine-c/src/generated/skin.h b/spine-c/src/generated/skin.h index 43e995691..ca9ffd2df 100644 --- a/spine-c/src/generated/skin.h +++ b/spine-c/src/generated/skin.h @@ -17,7 +17,7 @@ SPINE_C_API void spine_skin_dispose(spine_skin self); * Adds an attachment to the skin for the specified slot index and name. If the * name already exists for the slot, the previous value is replaced. */ -SPINE_C_API void spine_skin_set_attachment(spine_skin self, size_t slotIndex, const char *name, spine_attachment attachment); +SPINE_C_API void spine_skin_set_attachment(spine_skin self, size_t slotIndex, const char *name, /*@null*/ spine_attachment attachment); /** * Returns the attachment for the specified slot index and name, or NULL. */ diff --git a/spine-cpp/include/spine/Skin.h b/spine-cpp/include/spine/Skin.h index bf645e2eb..0093bbc0e 100644 --- a/spine-cpp/include/spine/Skin.h +++ b/spine-cpp/include/spine/Skin.h @@ -118,7 +118,7 @@ namespace spine { /// Adds an attachment to the skin for the specified slot index and name. /// If the name already exists for the slot, the previous value is replaced. - void setAttachment(size_t slotIndex, const String &name, Attachment &attachment); + void setAttachment(size_t slotIndex, const String &name, Attachment *attachment); /// Returns the attachment for the specified slot index and name, or NULL. Attachment *getAttachment(size_t slotIndex, const String &name); diff --git a/spine-cpp/src/spine/SkeletonBinary.cpp b/spine-cpp/src/spine/SkeletonBinary.cpp index 741b1fef6..364fbf305 100644 --- a/spine-cpp/src/spine/SkeletonBinary.cpp +++ b/spine-cpp/src/spine/SkeletonBinary.cpp @@ -560,7 +560,7 @@ Skin *SkeletonBinary::readSkin(DataInput &input, SkeletonData &skeletonData, boo String name(input.readStringRef()); Attachment *attachment = readAttachment(input, *skin, slotIndex, name, skeletonData, nonessential); if (attachment) - skin->setAttachment(slotIndex, name, *attachment); + skin->setAttachment(slotIndex, name, attachment); else { setError("Error reading attachment: ", name.buffer()); delete skin; diff --git a/spine-cpp/src/spine/SkeletonJson.cpp b/spine-cpp/src/spine/SkeletonJson.cpp index d23c61adf..c66d93516 100644 --- a/spine-cpp/src/spine/SkeletonJson.cpp +++ b/spine-cpp/src/spine/SkeletonJson.cpp @@ -537,7 +537,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { for (Json *entry = slotEntry->_child; entry; entry = entry->_next) { Attachment *attachment = readAttachment(entry, skin, slot->getIndex(), entry->_name, skeletonData); if (attachment) - skin->setAttachment(slot->getIndex(), entry->_name, *attachment); + skin->setAttachment(slot->getIndex(), entry->_name, attachment); else SKELETON_JSON_ERROR(root, "Error reading attachment: ", entry->_name); } diff --git a/spine-cpp/src/spine/Skin.cpp b/spine-cpp/src/spine/Skin.cpp index df7f23744..42e016ee0 100644 --- a/spine-cpp/src/spine/Skin.cpp +++ b/spine-cpp/src/spine/Skin.cpp @@ -99,8 +99,8 @@ Skin::~Skin() { } } -void Skin::setAttachment(size_t slotIndex, const String &name, Attachment &attachment) { - _attachments.put(slotIndex, name, &attachment); +void Skin::setAttachment(size_t slotIndex, const String &name, Attachment *attachment) { + _attachments.put(slotIndex, name, attachment); } Attachment *Skin::getAttachment(size_t slotIndex, const String &name) { @@ -162,7 +162,7 @@ void Skin::addSkin(Skin &other) { AttachmentMap::Entries entries = other.getAttachments(); while (entries.hasNext()) { AttachmentMap::Entry &entry = entries.next(); - setAttachment(entry._slotIndex, entry._name, *entry._attachment); + setAttachment(entry._slotIndex, entry._name, entry._attachment); } } @@ -177,9 +177,9 @@ void Skin::copySkin(Skin &other) { while (entries.hasNext()) { AttachmentMap::Entry &entry = entries.next(); if (entry._attachment->getRTTI().isExactly(MeshAttachment::rtti)) - setAttachment(entry._slotIndex, entry._name, static_cast(entry._attachment)->newLinkedMesh()); + setAttachment(entry._slotIndex, entry._name, &static_cast(entry._attachment)->newLinkedMesh()); else - setAttachment(entry._slotIndex, entry._name, entry._attachment->copy()); + setAttachment(entry._slotIndex, entry._name, &entry._attachment->copy()); } } diff --git a/spine-flutter/lib/generated/skin.dart b/spine-flutter/lib/generated/skin.dart index a28646d15..894c517c8 100644 --- a/spine-flutter/lib/generated/skin.dart +++ b/spine-flutter/lib/generated/skin.dart @@ -65,9 +65,9 @@ class Skin { /// Adds an attachment to the skin for the specified slot index and name. If /// the name already exists for the slot, the previous value is replaced. - void setAttachment(int slotIndex, String name, Attachment attachment) { - SpineBindings.bindings - .spine_skin_set_attachment(_ptr, slotIndex, name.toNativeUtf8().cast(), attachment.nativePtr.cast()); + void setAttachment(int slotIndex, String name, Attachment? attachment) { + SpineBindings.bindings.spine_skin_set_attachment( + _ptr, slotIndex, name.toNativeUtf8().cast(), attachment?.nativePtr.cast() ?? Pointer.fromAddress(0)); } /// Returns the attachment for the specified slot index and name, or NULL. diff --git a/spine-godot/.vscode/settings.json b/spine-godot/.vscode/settings.json index 5fdf13943..4db6a565c 100644 --- a/spine-godot/.vscode/settings.json +++ b/spine-godot/.vscode/settings.json @@ -1,7 +1,7 @@ { + "clangd.enable": true, "cmake.configureOnOpen": false, - "clangd.enable": false, - "C_Cpp.intelliSenseEngine": "default", + "C_Cpp.intelliSenseEngine": "disabled", "C_Cpp.default.browse.path": [ "${workspaceFolder}/godot-cpp/gen", "${workspaceFolder}" diff --git a/spine-godot/build/generate-compile-commands.sh b/spine-godot/build/generate-compile-commands.sh new file mode 100755 index 000000000..9591e535e --- /dev/null +++ b/spine-godot/build/generate-compile-commands.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -e + +dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +pushd "$dir" > /dev/null + +if [ ! -d ../godot ]; then + echo "No Godot clone found. Run ./setup.sh first." + exit 1 +fi + +# Detect system +cpus=2 +if [[ "$OSTYPE" == "darwin"* ]]; then + cpus=$(sysctl -n hw.logicalcpu) + arch="arm64" + if [ `uname -m` == "x86_64" ]; then + arch="x86_64" + fi +else + cpus=$(grep -c ^processor /proc/cpuinfo) +fi + +echo "Generating compile_commands.json..." +pushd ../godot + +# Generate essential header files first +echo "Generating required header files..." +scons -j$cpus custom_modules="../spine_godot" opengl3=yes arch=$arch \ + core/version_generated.gen.h \ + core/disabled_classes.gen.h \ + core/object/gdvirtual.gen.inc + +# Now generate compile_commands.json +# The 'compiledb' target specifically generates only the compile_commands.json +scons compiledb=yes custom_modules="../spine_godot" opengl3=yes arch=$arch compiledb + +# Copy the compile_commands.json to the parent directory for easy IDE access +if [ -f compile_commands.json ]; then + cp compile_commands.json .. + echo "compile_commands.json generated successfully and copied to spine-godot/" +else + echo "Failed to generate compile_commands.json" +fi + +popd +popd > /dev/null \ No newline at end of file diff --git a/spine-godot/build/setup.sh b/spine-godot/build/setup.sh index 5c42cddb3..c25a78c1a 100755 --- a/spine-godot/build/setup.sh +++ b/spine-godot/build/setup.sh @@ -72,4 +72,31 @@ fi popd +# Generate compile_commands.json for IDE integration +echo "Generating compile_commands.json for IDE integration..." +pushd ../godot > /dev/null + +# Detect architecture for macOS +arch="" +if [[ "$OSTYPE" == "darwin"* ]]; then + if [ `uname -m` == "arm64" ]; then + arch="arch=arm64" + else + arch="arch=x86_64" + fi +fi + +# Generate compilation database without building +scons compiledb=yes custom_modules="../spine_godot" opengl3=yes $arch compiledb + +# Copy to parent directory for easy IDE access +if [ -f compile_commands.json ]; then + cp compile_commands.json .. + echo "compile_commands.json generated successfully and copied to spine-godot/" +else + echo "Warning: Failed to generate compile_commands.json" +fi + +popd > /dev/null + popd > /dev/null \ No newline at end of file diff --git a/spine-ios/Sources/SpineSwift/Generated/Skin.swift b/spine-ios/Sources/SpineSwift/Generated/Skin.swift index 693a51738..73cdb8f4f 100644 --- a/spine-ios/Sources/SpineSwift/Generated/Skin.swift +++ b/spine-ios/Sources/SpineSwift/Generated/Skin.swift @@ -72,8 +72,8 @@ public class Skin: NSObject { /// Adds an attachment to the skin for the specified slot index and name. If the name already /// exists for the slot, the previous value is replaced. - public func setAttachment(_ slotIndex: Int, _ name: String, _ attachment: Attachment) { - spine_skin_set_attachment(_ptr.assumingMemoryBound(to: spine_skin_wrapper.self), slotIndex, name, attachment._ptr.assumingMemoryBound(to: spine_attachment_wrapper.self)) + public func setAttachment(_ slotIndex: Int, _ name: String, _ attachment: Attachment?) { + spine_skin_set_attachment(_ptr.assumingMemoryBound(to: spine_skin_wrapper.self), slotIndex, name, attachment?._ptr.assumingMemoryBound(to: spine_attachment_wrapper.self)) } /// Returns the attachment for the specified slot index and name, or NULL.