From 53844c9cce0dd58f568fa9e052cdef4ab51287cb Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 23 Oct 2024 23:13:32 +0800 Subject: [PATCH 01/80] AOT test --- .../editor-support/spine-wasm/CMakeLists.txt | 7 +-- .../spine-wasm/spine-type-export.cpp | 45 ++++++++++++------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index b1ba7deff18..c9ff0d6c50f 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required(VERSION 3.8) set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_BUILD_TYPE "MinSizeRel") +# set(CMAKE_BUILD_TYPE "MinSizeRel") +set(CMAKE_BUILD_TYPE "Debug") set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) @@ -19,13 +20,13 @@ file(GLOB COCOS_ADAPTER_SRC "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC}) -set(EMS_LINK_FLAGS "-O3 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ +set(EMS_LINK_FLAGS "-s VERBOSE=1 -s EMBIND_AOT=1 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ -s MIN_SAFARI_VERSION=110000 \ -s EXPORTED_FUNCTIONS=['_spineListenerCallBackFromJS','_spineTrackListenerCallback'] \ --js-library ../library_spine.js \ - --closure=1 \ + --closure=0 \ --closure-args=--externs=../library_spine_externs.js") diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 7d8e28fcc9f..a816ff0f54e 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -77,6 +77,7 @@ using SPVectorConstraintDataPtr = Vector; using SPVectorSlotPtr = Vector; using SPVectorSkinPtr = Vector; using SPVectorEventDataPtr = Vector; +using SPVectorEventPtr = Vector; using SPVectorAnimationPtr = Vector; using SPVectorIkConstraintPtr = Vector; using SPVectorIkConstraintDataPtr = Vector; @@ -236,6 +237,10 @@ EMSCRIPTEN_BINDINGS(spine) { .function("size", &SPVectorEventDataPtr::size) .function("get", &SPVectorEventDataPtr::operator[], allow_raw_pointers()); + class_("SPVectorEventPtr") + .function("size", &SPVectorEventPtr::size) + .function("get", &SPVectorEventPtr::operator[], allow_raw_pointers()); + class_("SPVectorAnimationPtr") .function("size", &SPVectorAnimationPtr::size) .function("get", &SPVectorAnimationPtr::operator[], allow_raw_pointers()); @@ -323,7 +328,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("isEmpty", &String::isEmpty) .function("append", select_overload(&String::append)) .function("equals", select_overload(&String::operator=)) - .function("buffer", &String::buffer, allow_raw_pointer()) + // .function("buffer", &String::buffer, allow_raw_pointer()) //.function("estr", optional_override([](String &obj) { // auto str = emscripten::val(obj.buffer()); // return str; }), allow_raw_pointers()) @@ -347,10 +352,13 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Interpolation") .function("apply", &Interpolation::apply, pure_virtual()); - class_("Triangulator") - .constructor<>() - .function("triangulate", &Triangulator::triangulate) - .function("decompose", &Triangulator::decompose, allow_raw_pointers()); + class_("HasRendererObject") + .constructor<>(); + + // class_("Triangulator") + // .constructor<>() + // .function("triangulate", &Triangulator::triangulate) + // .function("decompose", &Triangulator::decompose, allow_raw_pointers()); class_("ConstraintData") .constructor() @@ -410,14 +418,14 @@ EMSCRIPTEN_BINDINGS(spine) { .function("aabbIntersectsSkeleton", &SkeletonBounds::aabbIntersectsSkeleton) .function("containsPoint", optional_override([](SkeletonBounds &obj, float x, float y) { return obj.containsPoint(x, y); }),allow_raw_pointers()) - .function("containsPointPolygon", optional_override([](SkeletonBounds &obj,Polygon* polygon, float x, float y) { - return obj.containsPoint(polygon, x, y); }),allow_raw_pointers()) + // .function("containsPointPolygon", optional_override([](SkeletonBounds &obj,Polygon* polygon, float x, float y) { + // return obj.containsPoint(polygon, x, y); }),allow_raw_pointers()) .function("intersectsSegment", optional_override([](SkeletonBounds &obj, float x1, float y1, float x2, float y2){ return obj.intersectsSegment(x1, y1, x2, y2); }),allow_raw_pointers()) - .function("intersectsSegmentPolygon", optional_override([](SkeletonBounds &obj,Polygon* polygon, - float x1, float y1, float x2, float y2){ - return obj.intersectsSegment(polygon, x1, y1, x2, y2); }),allow_raw_pointers()) - .function("getPolygon", &SkeletonBounds::getPolygon, allow_raw_pointers()) + // .function("intersectsSegmentPolygon", optional_override([](SkeletonBounds &obj,Polygon* polygon, + // float x1, float y1, float x2, float y2){ + // return obj.intersectsSegment(polygon, x1, y1, x2, y2); }),allow_raw_pointers()) + // .function("getPolygon", &SkeletonBounds::getPolygon, allow_raw_pointers()) .function("getWidth", &SkeletonBounds::getWidth) .function("getHeight", &SkeletonBounds::getHeight); @@ -567,7 +575,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setPath", optional_override([](RegionAttachment &obj, const std::string &path) { const String &pathSP = STRING_STD2SP(path); obj.setPath(pathSP); })) - .function("getRendererObject", &RegionAttachment::getRendererObject, allow_raw_pointers()) + // .function("getRendererObject", &RegionAttachment::getRendererObject, allow_raw_pointers()) .function("getOffset", optional_override([](RegionAttachment &obj) { return &obj.getOffset(); }), allow_raw_pointer()) .function("setUVs", &RegionAttachment::setUVs) @@ -619,6 +627,9 @@ EMSCRIPTEN_BINDINGS(spine) { .property("degrees", &AtlasRegion::degrees); //.property("texture", &AtlasRegion::height) + class_("TextureLoader"); + + class_("TextureAtlas") .constructor() .function("findRegion", optional_override([](Atlas &obj, const std::string &name) { @@ -1169,7 +1180,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getFrames", optional_override([](EventTimeline &obj) { return &obj.getFrames(); }), allow_raw_pointer()) .function("getEvents", optional_override([](EventTimeline &obj) { - return &obj.getEvents(); }), allow_raw_pointer()) + return &obj.getEvents(); }), allow_raw_pointer()) .function("getPropertyId", &EventTimeline::getPropertyId) .function("getFrameCount", &EventTimeline::getFrameCount) .function("setFrame", &EventTimeline::setFrame, allow_raw_pointers()) @@ -1326,10 +1337,10 @@ EMSCRIPTEN_BINDINGS(spine) { .function("addEmptyAnimation", &AnimationState::addEmptyAnimation, allow_raw_pointers()) .function("setEmptyAnimations", &AnimationState::setEmptyAnimations) .function("getCurrent", &AnimationState::getCurrent, allow_raw_pointer()) - .function("setListener", optional_override([](AnimationState &obj, AnimationStateListener inValue) { - obj.setListener(inValue); }),allow_raw_pointers()) - .function("setListenerObject", optional_override([](AnimationState &obj, AnimationStateListenerObject *inValue) { - obj.setListener(inValue); }),allow_raw_pointers()) + // .function("setListener", optional_override([](AnimationState &obj, AnimationStateListener inValue) { + // obj.setListener(inValue); }),allow_raw_pointers()) + // .function("setListenerObject", optional_override([](AnimationState &obj, AnimationStateListenerObject *inValue) { + // obj.setListener(inValue); }),allow_raw_pointers()) .function("disableQueue", &AnimationState::disableQueue) .function("enableQueue", &AnimationState::enableQueue); //.function("addListener", &AnimationState::addListener) From e150e610d40a80f48581239ad8c771c4e3b7f2d7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 10:13:33 +0800 Subject: [PATCH 02/80] Add size_type, value_type for spine::Vector --- native/cocos/editor-support/spine/Vector.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/native/cocos/editor-support/spine/Vector.h b/native/cocos/editor-support/spine/Vector.h index 91ee93f84b5..5e5b12861aa 100644 --- a/native/cocos/editor-support/spine/Vector.h +++ b/native/cocos/editor-support/spine/Vector.h @@ -39,6 +39,9 @@ namespace spine { template class SP_API Vector : public SpineObject { public: + using size_type = size_t; + using value_type = T; + Vector() : _size(0), _capacity(0), _buffer(NULL) { } @@ -164,6 +167,12 @@ class SP_API Vector : public SpineObject { return _buffer[inIndex]; } + inline const T &operator[](size_t inIndex) const { + assert(inIndex < _size); + + return _buffer[inIndex]; + } + inline friend bool operator==(Vector &lhs, Vector &rhs) { if (lhs.size() != rhs.size()) { return false; From befaa70316474493c2816196211232cd2539a935 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 10:14:08 +0800 Subject: [PATCH 03/80] spine::Vector getX/Y should be const functions. --- native/cocos/editor-support/spine-wasm/Vector2.cpp | 6 +++--- native/cocos/editor-support/spine-wasm/Vector2.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/Vector2.cpp b/native/cocos/editor-support/spine-wasm/Vector2.cpp index 3b18308506c..bac1dfcaea4 100644 --- a/native/cocos/editor-support/spine-wasm/Vector2.cpp +++ b/native/cocos/editor-support/spine-wasm/Vector2.cpp @@ -17,7 +17,7 @@ void Vector2::setX(float x) { this->x = x; } -float Vector2::getX() { +float Vector2::getX() const { return x; } @@ -25,7 +25,7 @@ void Vector2::setY(float y) { this->y = y; } -float Vector2::getY() { +float Vector2::getY() const { return y; } @@ -35,7 +35,7 @@ Vector2& Vector2::set(float x, float y) { return *this; } -float Vector2::length() { +float Vector2::length() const { return sqrt(x * x + y * y); } diff --git a/native/cocos/editor-support/spine-wasm/Vector2.h b/native/cocos/editor-support/spine-wasm/Vector2.h index 0f62883bc4c..24842bad4fa 100644 --- a/native/cocos/editor-support/spine-wasm/Vector2.h +++ b/native/cocos/editor-support/spine-wasm/Vector2.h @@ -42,13 +42,13 @@ namespace spine { ~Vector2(); void setX(float x); - float getX(); + float getX() const; void setY(float y); - float getY(); + float getY() const; Vector2 &set(float x, float y); - float length(); + float length() const; Vector2 &normalize(); }; } \ No newline at end of file From 83a596e64db41a8f3ab1d5f952325ddb6b6e28de Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 10:14:25 +0800 Subject: [PATCH 04/80] spine::Vector getX/Y should be const functions. --- .../cocos/editor-support/spine-creator-support/Vector2.cpp | 6 +++--- native/cocos/editor-support/spine-creator-support/Vector2.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/native/cocos/editor-support/spine-creator-support/Vector2.cpp b/native/cocos/editor-support/spine-creator-support/Vector2.cpp index 3b18308506c..bac1dfcaea4 100644 --- a/native/cocos/editor-support/spine-creator-support/Vector2.cpp +++ b/native/cocos/editor-support/spine-creator-support/Vector2.cpp @@ -17,7 +17,7 @@ void Vector2::setX(float x) { this->x = x; } -float Vector2::getX() { +float Vector2::getX() const { return x; } @@ -25,7 +25,7 @@ void Vector2::setY(float y) { this->y = y; } -float Vector2::getY() { +float Vector2::getY() const { return y; } @@ -35,7 +35,7 @@ Vector2& Vector2::set(float x, float y) { return *this; } -float Vector2::length() { +float Vector2::length() const { return sqrt(x * x + y * y); } diff --git a/native/cocos/editor-support/spine-creator-support/Vector2.h b/native/cocos/editor-support/spine-creator-support/Vector2.h index 0f62883bc4c..24842bad4fa 100644 --- a/native/cocos/editor-support/spine-creator-support/Vector2.h +++ b/native/cocos/editor-support/spine-creator-support/Vector2.h @@ -42,13 +42,13 @@ namespace spine { ~Vector2(); void setX(float x); - float getX(); + float getX() const; void setY(float y); - float getY(); + float getY() const; Vector2 &set(float x, float y); - float length(); + float length() const; Vector2 &normalize(); }; } \ No newline at end of file From f8ffec0cd264b8d1a746d46ce29c301e1c9daf6c Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 10:15:09 +0800 Subject: [PATCH 05/80] cleanup spine-wasm/CMakeLists.txt --- .../editor-support/spine-wasm/CMakeLists.txt | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index c9ff0d6c50f..1e73a98d1b3 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -1,18 +1,34 @@ cmake_minimum_required(VERSION 3.8) set(CMAKE_VERBOSE_MAKEFILE ON) + +set(BUILD_WASM 1) + # set(CMAKE_BUILD_TYPE "MinSizeRel") set(CMAKE_BUILD_TYPE "Debug") +# set(CMAKE_BUILD_TYPE "Release") + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(ENABLE_CLOSURE_COMPILER 0) +else() + set(ENABLE_CLOSURE_COMPILER 1) +endif() + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) -set(BUILD_WASM 1) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -frtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=1") -message("Current directory: ${CMAKE_CURRENT_LIST_DIR}") +message(">>> --------------------------------------------------------------") +message(">>> Current directory: ${CMAKE_CURRENT_LIST_DIR}") +message(">>> CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +message(">>> ENABLE_CLOSURE_COMPILER: ${ENABLE_CLOSURE_COMPILER}") +message(">>> --------------------------------------------------------------") include_directories(${CMAKE_CURRENT_LIST_DIR}/..) file(GLOB SPINE_CORE_SRC "${CMAKE_CURRENT_LIST_DIR}/../spine/*.cpp") @@ -20,13 +36,13 @@ file(GLOB COCOS_ADAPTER_SRC "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC}) -set(EMS_LINK_FLAGS "-s VERBOSE=1 -s EMBIND_AOT=1 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ +set(EMS_LINK_FLAGS "-s VERBOSE=0 -s EMBIND_AOT=0 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ -s MIN_SAFARI_VERSION=110000 \ -s EXPORTED_FUNCTIONS=['_spineListenerCallBackFromJS','_spineTrackListenerCallback'] \ --js-library ../library_spine.js \ - --closure=0 \ + --closure=${ENABLE_CLOSURE_COMPILER} \ --closure-args=--externs=../library_spine_externs.js") From ccb8ddfdfeadffc5c68380f91b7a9864dac67fbb Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 10:16:50 +0800 Subject: [PATCH 06/80] Refactor spine-type-export.cpp, remove unused apply binding. --- .../spine-wasm/spine-type-export.cpp | 594 ++++++++---------- 1 file changed, 270 insertions(+), 324 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index a816ff0f54e..f6d10f03a38 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -8,6 +8,16 @@ using namespace emscripten; using namespace spine; +#define DEFINE_ALLOW_RAW_POINTER(type) \ +namespace emscripten { namespace internal { \ + template<> \ + struct TypeID { \ + static constexpr TYPEID get() { \ + return TypeID::get(); \ + } \ + }; \ +}} + namespace { std::string STRING_SP2STD(const spine::String &str) { std::string stdStr(str.buffer(), str.length()); @@ -31,7 +41,7 @@ const std::vector VECTOR_SP2STD_STRING(Vector &container) { template Vector VECTOR_STD2SP(std::vector &container) { int count = container.size(); - Vector vecSP = Vector(); + Vector vecSP; vecSP.setSize(count, 0); for (int i = 0; i < count; i++) { vecSP[i] = container[i]; @@ -86,6 +96,8 @@ using SPVectorPathConstraintPtr = Vector; using SPVectorTimelinePtr = Vector; using SPVectorTrackEntryPtr = Vector; using SPVectorUpdatablePtr = Vector; +using SPVectorSkinEntry = Vector; +using SPVectorVectorSkinEntry = Vector; template static void register_integer(const char* name) { using namespace internal; @@ -97,8 +109,210 @@ template static void register_integer(const char* name) { #define REGISTER_SPINE_ENUM(name) \ register_integer("spine::" #name) + +template +struct SpineVectorTrait {}; + +template +struct SpineVectorTrait { + static emscripten::class_> register_spine_vector(const char* name) { + typedef spine::Vector VecType; + + void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; + size_t (VecType::*size)() const = &VecType::size; + return class_>(name) + .template constructor<>() + .function("resize", setSize) + .function("size", size) + .function("get", &internal::VectorAccess::get); + } +}; + +template +struct SpineVectorTrait { + static emscripten::class_> register_spine_vector(const char* name) { + typedef spine::Vector VecType; + + void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; + size_t (VecType::*size)() const = &VecType::size; + return class_>(name) + .template constructor<>() + .function("resize", setSize) + .function("size", size) + .function("get", &internal::VectorAccess::get) + .function("set", &internal::VectorAccess::set); + } +}; + + +// // export get only for spine::Vector +// template +// typename std::enable_if>>::type +// register_spine_vector(const char* name) { +// typedef spine::Vector VecType; + +// void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; +// size_t (VecType::*size)() const = &VecType::size; +// return class_>(name) +// .template constructor<>() +// .function("resize", setSize) +// .function("size", size) +// .function("get", &internal::VectorAccess::get); +// } + +// // export both get and set for spine::Vector +// template +// typename std::enable_if>>::type +// register_spine_vector(const char* name) { +// typedef spine::Vector VecType; + +// void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; +// size_t (VecType::*size)() const = &VecType::size; +// return class_>(name) +// .template constructor<>() +// .function("resize", setSize) +// .function("size", size) +// .function("get", &internal::VectorAccess::get) +// .function("set", &internal::VectorAccess::set); +// } + +// #define REGISTER_SPINE_VECTOR(name, needSetter) \ +// register_spine_vector(#name) + +#define REGISTER_SPINE_VECTOR(name, needSetter) \ + SpineVectorTrait::register_spine_vector(#name) + + } // namespace +namespace emscripten { namespace internal { + +// template +// struct GetterPolicy { +// using ReturnValueType = typename std::enable_if::value, typename std::remove_reference::type>::type; +// using PointerReturnType = std::add_pointer; +// using ReturnType = PointerReturnType; + +// using OriginalContext = GetterReturnType (GetterThisType::*)(); +// using Context = PointerReturnType (GetterThisType::*)(); + +// using Binding = internal::BindingType; +// using WireType = typename Binding::WireType; + +// template +// static WireType get(const OriginalContext& context, const ClassType& ptr) { +// return Binding::toWireType(&(ptr.*context)()); +// } + +// static void* getContext(OriginalContext context) { +// return internal::getContext(context); +// } +// }; + +template +struct GetterPolicy { + using ReturnType = GetterReturnType; + using Context = GetterReturnType (GetterThisType::*)(); + + using Binding = internal::BindingType; + using WireType = typename Binding::WireType; + + template + static WireType get(const Context& context, ClassType& ptr) { + return Binding::toWireType(((ptr.*context)()), ReturnPolicy{}); + } + + static void* getContext(Context context) { + return internal::getContext(context); + } +}; + +} // namespace internal +} // namespace emscripten + +#define ENABLE_EMBIND_TEST 0 + +#if ENABLE_EMBIND_TEST + +class TestFoo { +public: + TestFoo() { + printf("TestFoo::TestFoo: %p\n", this); + } + + TestFoo(const TestFoo& o) { + printf("TestFoo copy constructor %p\n", this); + *this = o; + } + + ~TestFoo() { + printf("TestFoo::~TestFoo: %p\n", this); + } + + TestFoo &operator=(const TestFoo& o) { + printf("TestFoo::operator=: %p\n", this); + if (this != &o) { + _x = o._x; + } + return *this; + } + + void setX(int x) { + _x = x; + } + int getX() const { + return _x; + } +private: + int _x = 0; +}; + +class TestBar { +public: + TestBar() { + printf("TestBar::TestBar: %p\n", this); + } + + TestBar(const TestBar& o) { + printf("TestBar copy constructor %p\n", this); + *this = o; + } + + ~TestBar() { + printf("TestBar::~TestBar: %p\n", this); + delete _foo; + } + + TestBar &operator=(const TestBar& o) { + printf("TestBar::operator=: %p\n", this); + if (this != &o) { + _foo = o._foo; + } + return *this; + } + + TestFoo* getFoo() const { + return _foo; + } + void setFoo(TestFoo *foo) { + if (_foo != foo) { + delete _foo; + _foo = foo; + } + } + +private: + TestFoo *_foo = new TestFoo(); +}; + +DEFINE_ALLOW_RAW_POINTER(TestFoo) + +#endif // ENABLE_EMBIND_TEST + + +DEFINE_ALLOW_RAW_POINTER(BoneData) + + EMSCRIPTEN_BINDINGS(spine) { REGISTER_SPINE_ENUM(TimelineType); REGISTER_SPINE_ENUM(MixDirection); @@ -113,209 +327,51 @@ EMSCRIPTEN_BINDINGS(spine) { REGISTER_SPINE_ENUM(TextureWrap); REGISTER_SPINE_ENUM(AttachmentType); - register_vector("VectorFloat"); - register_vector>("VectorVectorFloat"); register_vector("VectorUnsignedShort"); register_vector("VectorOfUInt"); register_vector("VectorString"); - register_vector("VectorBoneData"); - register_vector("VectorBone"); - register_vector("VectorSkinEntry"); - register_vector("VectorSlotData"); - register_vector("VectorSlot"); - register_vector("VectorAnimation"); - register_vector("VectorTimeline"); - register_vector("VectorSkin"); - register_vector("VectorEventData"); - register_vector("VectorEvent"); - register_vector("VectorConstraintData"); - register_vector("VectorIkConstraint"); - register_vector("VectorPathConstraint"); - register_vector("VectorTransformConstraint"); - register_vector("VectorIkConstraintData"); - register_vector("VectorTransformConstraintData"); - register_vector("VectorPathConstraintData"); - register_vector("VectorTrackEntry"); - - class_("SPVectorFloat") - .constructor<>() - .function("resize", &SPVectorFloat::setSize) - .function("size", &SPVectorFloat::size) - .function("get", &SPVectorFloat::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorFloat &obj, int index, float value) { - obj[index] = value; - })); - - class_("SPVectorVectorFloat") - .constructor<>() - .function("resize", &SPVectorVectorFloat::setSize) - .function("size", &SPVectorVectorFloat::size) - .function("get", &SPVectorVectorFloat::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorVectorFloat &obj, int index, SPVectorFloat &value) { - obj[index] = value; - })); - - class_("SPVectorInt") - .constructor<>() - .function("resize", &SPVectorInt::setSize) - .function("size", &SPVectorInt::size) - .function("get", &SPVectorInt::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorInt &obj, int index, int value) { - obj[index] = value; - })); - - class_("SPVectorVectorInt") - .constructor<>() - .function("resize", &SPVectorVectorInt::setSize) - .function("size", &SPVectorVectorInt::size) - .function("get", &SPVectorVectorInt::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorVectorInt &obj, int index, SPVectorInt &value) { - obj[index] = value; - })); - - class_("SPVectorSize_t") - .constructor<>() - .function("resize", &SPVectorSize_t::setSize) - .function("size", &SPVectorSize_t::size) - .function("get", &SPVectorSize_t::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorSize_t &obj, size_t index, size_t value) { - obj[index] = value; - })); - - class_("SPVectorUnsignedShort") - .constructor<>() - .function("resize", &SPVectorUnsignedShort::setSize) - .function("size", &SPVectorUnsignedShort::size) - .function("get", &SPVectorUnsignedShort::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorUnsignedShort &obj, int index, int value) { - obj[index] = value; - })); - - class_("SPVectorBonePtr") - .constructor<>() - .function("resize", &SPVectorBonePtr::setSize) - .function("size", &SPVectorBonePtr::size) - .function("get", &SPVectorBonePtr::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorBonePtr &obj, int index, Bone *value) { - obj[index] = value; - }), allow_raw_pointer()); - - class_("SPVectorBoneDataPtr") - .constructor<>() - .function("resize", &SPVectorBoneDataPtr::setSize) - .function("size", &SPVectorBoneDataPtr::size) - .function("get", &SPVectorBoneDataPtr::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorBoneDataPtr &obj, int index, BoneData *value) { - obj[index] = value; - }), allow_raw_pointer()); - - class_("SPVectorSlotDataPtr") - .function("size", &SPVectorSlotDataPtr::size) - .function("get", &SPVectorSlotDataPtr::operator[], allow_raw_pointers()); - - class_("SPVectorTransformConstraintDataPtr") - .function("size", &SPVectorTransformConstraintDataPtr::size) - .function("get", &SPVectorTransformConstraintDataPtr::operator[], allow_raw_pointers()); - - class_("SPVectorPathConstraintDataPtr") - .function("size", &SPVectorPathConstraintDataPtr::size) - .function("get", &SPVectorPathConstraintDataPtr::operator[], allow_raw_pointers()); - - class_("SPVectorConstraintDataPtr") - .function("size", &SPVectorConstraintDataPtr::size) - .function("get", &SPVectorConstraintDataPtr::operator[], allow_raw_pointers()); - - class_("SPVectorSlotPtr") - .function("size", &SPVectorSlotPtr::size) - .function("get", &SPVectorSlotPtr::operator[], allow_raw_pointers()); - - class_("SPVectorSkinPtr") - .function("size", &SPVectorSkinPtr::size) - .function("get", &SPVectorSkinPtr::operator[], allow_raw_pointers()); - - class_("SPVectorEventDataPtr") - .function("size", &SPVectorEventDataPtr::size) - .function("get", &SPVectorEventDataPtr::operator[], allow_raw_pointers()); - - class_("SPVectorEventPtr") - .function("size", &SPVectorEventPtr::size) - .function("get", &SPVectorEventPtr::operator[], allow_raw_pointers()); - - class_("SPVectorAnimationPtr") - .function("size", &SPVectorAnimationPtr::size) - .function("get", &SPVectorAnimationPtr::operator[], allow_raw_pointers()); - - class_("SPVectorIkConstraintPtr") - .constructor<>() - .function("resize", &SPVectorIkConstraintPtr::setSize) - .function("size", &SPVectorIkConstraintPtr::size) - .function("get", &SPVectorIkConstraintPtr::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorIkConstraintPtr &obj, int index, IkConstraint *value) { - obj[index] = value; - }), allow_raw_pointer()); - - class_("SPVectorIkConstraintDataPtr") - .constructor<>() - .function("resize", &SPVectorIkConstraintDataPtr::setSize) - .function("size", &SPVectorIkConstraintDataPtr::size) - .function("get", &SPVectorIkConstraintDataPtr::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorIkConstraintDataPtr &obj, int index, IkConstraintData *value) { - obj[index] = value; - }), allow_raw_pointer()); - - class_("SPVectorTransformConstraintPtr") - .constructor<>() - .function("resize", &SPVectorTransformConstraintPtr::setSize) - .function("size", &SPVectorTransformConstraintPtr::size) - .function("get", &SPVectorTransformConstraintPtr::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorTransformConstraintPtr &obj, int index, TransformConstraint *value) { - obj[index] = value; - }), allow_raw_pointer()); - - class_("SPVectorPathConstraintPtr") - .constructor<>() - .function("resize", &SPVectorPathConstraintPtr::setSize) - .function("size", &SPVectorPathConstraintPtr::size) - .function("get", &SPVectorPathConstraintPtr::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorPathConstraintPtr &obj, int index, PathConstraint *value) { - obj[index] = value; - }), allow_raw_pointer()); - - class_("SPVectorTimelinePtr") - .constructor<>() - .function("resize", &SPVectorTimelinePtr::setSize) - .function("size", &SPVectorTimelinePtr::size) - .function("get", &SPVectorTimelinePtr::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorTimelinePtr &obj, int index, Timeline *value) { - obj[index] = value; - }), allow_raw_pointer()); - - class_("SPVectorTrackEntryPtr") - .constructor<>() - .function("resize", &SPVectorTrackEntryPtr::setSize) - .function("size", &SPVectorTrackEntryPtr::size) - .function("get", &SPVectorTrackEntryPtr::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorTrackEntryPtr &obj, int index, TrackEntry *value) { - obj[index] = value; - }), allow_raw_pointer()); - - class_("SPVectorUpdatablePtr") - .constructor<>() - .function("resize", &SPVectorUpdatablePtr::setSize) - .function("size", &SPVectorUpdatablePtr::size) - .function("get", &SPVectorUpdatablePtr::operator[], allow_raw_pointers()) - .function("set",optional_override([](SPVectorUpdatablePtr &obj, int index, Updatable *value) { - obj[index] = value; - }), allow_raw_pointer()); + REGISTER_SPINE_VECTOR(SPVectorFloat, true); + REGISTER_SPINE_VECTOR(SPVectorVectorFloat, true); + REGISTER_SPINE_VECTOR(SPVectorInt, true); + REGISTER_SPINE_VECTOR(SPVectorVectorInt, true); + REGISTER_SPINE_VECTOR(SPVectorSize_t, true); + REGISTER_SPINE_VECTOR(SPVectorUnsignedShort, true); + + REGISTER_SPINE_VECTOR(SPVectorBonePtr, false); + REGISTER_SPINE_VECTOR(SPVectorBoneDataPtr, false); + REGISTER_SPINE_VECTOR(SPVectorSlotDataPtr, false); + REGISTER_SPINE_VECTOR(SPVectorTransformConstraintDataPtr, false); + REGISTER_SPINE_VECTOR(SPVectorPathConstraintDataPtr, false); + REGISTER_SPINE_VECTOR(SPVectorConstraintDataPtr, false); + REGISTER_SPINE_VECTOR(SPVectorSlotPtr, false); + REGISTER_SPINE_VECTOR(SPVectorSkinPtr, false); + REGISTER_SPINE_VECTOR(SPVectorEventDataPtr, false); + REGISTER_SPINE_VECTOR(SPVectorEventPtr, false); + REGISTER_SPINE_VECTOR(SPVectorAnimationPtr, false); + REGISTER_SPINE_VECTOR(SPVectorIkConstraintPtr, false); + REGISTER_SPINE_VECTOR(SPVectorIkConstraintDataPtr, false); + REGISTER_SPINE_VECTOR(SPVectorTransformConstraintPtr, false); + REGISTER_SPINE_VECTOR(SPVectorPathConstraintPtr, false); + REGISTER_SPINE_VECTOR(SPVectorTimelinePtr, true); // .set used in Animation constructor + REGISTER_SPINE_VECTOR(SPVectorTrackEntryPtr, false); + REGISTER_SPINE_VECTOR(SPVectorUpdatablePtr, false); + REGISTER_SPINE_VECTOR(SPVectorSkinEntry, false); + REGISTER_SPINE_VECTOR(SPVectorVectorSkinEntry, false); + + class_("TestFoo") + .constructor() + .property("x", &TestFoo::getX, &TestFoo::setX); + + class_("TestBar") + .constructor() + .property("foo", &TestBar::getFoo, &TestBar::setFoo); class_("Vector2") .constructor<>() .constructor() - .function("setX", &Vector2::setX) - .function("getX", &Vector2::getX) - .function("setY", &Vector2::setY) - .function("getY", &Vector2::getY) + .property("x", &Vector2::x) + .property("y", &Vector2::y) .function("set", &Vector2::set) .function("length", &Vector2::length) .function("normalize", &Vector2::normalize); @@ -372,8 +428,9 @@ EMSCRIPTEN_BINDINGS(spine) { .constructor() .function("getBones", optional_override([](IkConstraintData &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .function("getTarget", &IkConstraintData::getTarget, allow_raw_pointer()) - .function("setTarget", &IkConstraintData::setTarget, allow_raw_pointer()) + .property("target", &IkConstraintData::getTarget, &IkConstraintData::setTarget, allow_raw_pointer()) + // .function("getTarget", &IkConstraintData::getTarget, allow_raw_pointer()) + // .function("setTarget", &IkConstraintData::setTarget, allow_raw_pointer()) .function("getBendDirection", &IkConstraintData::getBendDirection) .function("setBendDirection", &IkConstraintData::setBendDirection) .function("getCompress", &IkConstraintData::getCompress) @@ -681,7 +738,6 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getActive", &IkConstraint::isActive) .function("setActive", &IkConstraint::setActive) .function("isActive", &IkConstraint::isActive) - .function("apply", static_cast(&IkConstraint::apply)) .function("update", &IkConstraint::update) .class_function("apply1", optional_override([]( IkConstraint &obj, Bone &bone, float targetX, float targetY, @@ -712,7 +768,6 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getActive", &PathConstraint::isActive) .function("isActive", &PathConstraint::isActive) .function("setActive", &PathConstraint::setActive) - .function("apply", &PathConstraint::apply) .function("update", &PathConstraint::update); class_>("TransformConstraintData") @@ -750,15 +805,15 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getActive", &TransformConstraint::isActive) .function("setActive", &TransformConstraint::setActive) .function("isActive", &TransformConstraint::isActive) - .function("apply", &TransformConstraint::apply) .function("update", &TransformConstraint::update); class_>("Bone") .constructor() .function("getData", optional_override([](Bone &obj) { return &obj.getData(); }), allow_raw_pointers()) - .function("getSkeleton", optional_override([](Bone &obj) { - return &obj.getSkeleton(); }), allow_raw_pointers()) + .property("skeleton", &Bone::getSkeleton) + // .function("getSkeleton", optional_override([](Bone &obj) { + // return &obj.getSkeleton(); }), allow_raw_pointers()) .function("getParent", optional_override([](Bone &obj) { return obj.getParent(); }), allow_raw_pointers()) .function("getChildren", optional_override([](Bone &obj) { @@ -1016,12 +1071,6 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Animation") .constructor &, float>() - .function("apply", optional_override([](Animation &obj, Skeleton &skeleton, - float lastTime, float time, bool loop, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, loop, &pEvents, alpha, blend, direction); - })) .function("getName", optional_override([](Animation &obj) { return STRING_SP2STD(obj.getName()); })) .function("getTimelines", optional_override([](Animation &obj) { return &obj.getTimelines(); }), allow_raw_pointer()) @@ -1030,21 +1079,9 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setDuration", &Animation::setDuration); class_("Timeline") - .function("apply", optional_override([](Timeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), pure_virtual()) .function("getPropertyId", &Timeline::getPropertyId, pure_virtual()); class_>("CurveTimeline") - .function("apply", optional_override([](CurveTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), pure_virtual()) .function("getPropertyId", &CurveTimeline::getPropertyId, pure_virtual()) .function("getFrameCount", &CurveTimeline::getFrameCount) .function("setLinear", &CurveTimeline::setLinear) @@ -1057,33 +1094,15 @@ EMSCRIPTEN_BINDINGS(spine) { .constructor() .class_property("ENTRIES", &TranslateTimeline::ENTRIES) .function("getPropertyId", &TranslateTimeline::getPropertyId) - .function("setFrame", &TranslateTimeline::setFrame) - .function("apply", optional_override([](TranslateTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("setFrame", &TranslateTimeline::setFrame); class_>("ScaleTimeline") .constructor() - .function("getPropertyId", &ScaleTimeline::getPropertyId) - .function("apply", optional_override([](ScaleTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("getPropertyId", &ScaleTimeline::getPropertyId); class_>("ShearTimeline") .constructor() - .function("getPropertyId", &ShearTimeline::getPropertyId) - .function("apply", optional_override([](ShearTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("getPropertyId", &ShearTimeline::getPropertyId); class_>("RotateTimeline") .constructor() @@ -1093,13 +1112,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getFrames", optional_override([](RotateTimeline &obj) { return &obj.getFrames(); }), allow_raw_pointer()) .function("getPropertyId", &RotateTimeline::getPropertyId) - .function("setFrame", &RotateTimeline::setFrame) - .function("apply", optional_override([](RotateTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("setFrame", &RotateTimeline::setFrame); class_>("ColorTimeline") .constructor() @@ -1109,13 +1122,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getFrames", optional_override([](ColorTimeline &obj) { return &obj.getFrames(); }), allow_raw_pointer()) .function("getPropertyId", &ColorTimeline::getPropertyId) - .function("setFrame", &ColorTimeline::setFrame) - .function("apply", optional_override([](ColorTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("setFrame", &ColorTimeline::setFrame); class_>("TwoColorTimeline") .constructor() @@ -1123,13 +1130,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getSlotIndex", &TwoColorTimeline::getSlotIndex) .function("setSlotIndex", &TwoColorTimeline::setSlotIndex) .function("getPropertyId", &TwoColorTimeline::getPropertyId) - .function("setFrame", &TwoColorTimeline::setFrame) - .function("apply", optional_override([](TwoColorTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("setFrame", &TwoColorTimeline::setFrame); class_>("AttachmentTimeline") .constructor() @@ -1145,12 +1146,6 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setFrame", optional_override([](AttachmentTimeline &obj, int frameIndex, float time, const std::string &attachmentName){ const String attachmentNameSP = STRING_STD2SP(attachmentName); obj.setFrame(frameIndex, time, attachmentNameSP); - }), allow_raw_pointers()) - .function("apply", optional_override([](AttachmentTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); }), allow_raw_pointers()); class_>("DeformTimeline") @@ -1167,12 +1162,6 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setFrame", optional_override([](DeformTimeline &obj, int frameIndex, float time, std::vector &vertices){ Vector sp_vertices = VECTOR_STD2SP(vertices); obj.setFrame(frameIndex, time, sp_vertices); - }), allow_raw_pointers()) - .function("apply", optional_override([](DeformTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); }), allow_raw_pointers()); class_>("EventTimeline") @@ -1183,13 +1172,7 @@ EMSCRIPTEN_BINDINGS(spine) { return &obj.getEvents(); }), allow_raw_pointer()) .function("getPropertyId", &EventTimeline::getPropertyId) .function("getFrameCount", &EventTimeline::getFrameCount) - .function("setFrame", &EventTimeline::setFrame, allow_raw_pointers()) - .function("apply", optional_override([](EventTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("setFrame", &EventTimeline::setFrame, allow_raw_pointers()); class_>("DrawOrderTimeline") .constructor() @@ -1199,60 +1182,30 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getFrameCount", &DrawOrderTimeline::getFrameCount) .function("getDrawOrders", optional_override([](DrawOrderTimeline &obj) { return &obj.getDrawOrders(); }), allow_raw_pointer()) - .function("setFrame", &DrawOrderTimeline::setFrame, allow_raw_pointers()) - .function("apply", optional_override([](DrawOrderTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("setFrame", &DrawOrderTimeline::setFrame, allow_raw_pointers()); class_>("IkConstraintTimeline") .constructor() .class_property("ENTRIES", &IkConstraintTimeline::ENTRIES) .function("getPropertyId", &IkConstraintTimeline::getPropertyId) - .function("setFrame", &IkConstraintTimeline::setFrame) - .function("apply", optional_override([](IkConstraintTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("setFrame", &IkConstraintTimeline::setFrame); class_>("TransformConstraintTimeline") .constructor() .class_property("ENTRIES", &TransformConstraintTimeline::ENTRIES) .function("getPropertyId", &TransformConstraintTimeline::getPropertyId) - .function("setFrame", &TransformConstraintTimeline::setFrame) - .function("apply", optional_override([](TransformConstraintTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("setFrame", &TransformConstraintTimeline::setFrame); class_>("PathConstraintPositionTimeline") .constructor() .class_property("ENTRIES", &TransformConstraintTimeline::ENTRIES) .function("getPropertyId", &PathConstraintPositionTimeline::getPropertyId) - .function("setFrame", &PathConstraintPositionTimeline::setFrame) - .function("apply", optional_override([](PathConstraintPositionTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("setFrame", &PathConstraintPositionTimeline::setFrame); class_>("PathConstraintMixTimeline") .constructor() .class_property("ENTRIES", &PathConstraintMixTimeline::ENTRIES) - .function("getPropertyId", &PathConstraintMixTimeline::getPropertyId) - .function("apply", optional_override([](PathConstraintMixTimeline &obj, Skeleton &skeleton, - float lastTime, float time, std::vector &stdPEvents, float alpha, - MixBlend blend, MixDirection direction) { - auto pEvents = VECTOR_STD2SP_POINTER(stdPEvents); - obj.apply(skeleton, lastTime, time, &pEvents, alpha, blend, direction); - }), allow_raw_pointers()); + .function("getPropertyId", &PathConstraintMixTimeline::getPropertyId); class_("TrackEntry") .constructor<>() @@ -1477,13 +1430,6 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getWorldY", &SwirlVertexEffect::getWorldY) .function("setWorldY", &SwirlVertexEffect::setWorldY); - class_("SlotMesh") - .property("vCount", &SlotMesh::vCount) - .property("iCount", &SlotMesh::iCount) - .property("blendMode", &SlotMesh::blendMode) - .property("textureID", &SlotMesh::textureID); - - register_vector("VectorSlotMesh"); class_("SpineModel") .property("vCount", &SpineModel::vCount) .property("iCount", &SpineModel::iCount) From a46a5dd9226c39bf7bf5002052482a23662ceeea Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 10:17:25 +0800 Subject: [PATCH 07/80] Remove extra spine:: namespace in SkeletonData.h --- native/cocos/editor-support/spine/SkeletonData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/editor-support/spine/SkeletonData.h b/native/cocos/editor-support/spine/SkeletonData.h index 7de7d8d3657..c9ec083c52b 100644 --- a/native/cocos/editor-support/spine/SkeletonData.h +++ b/native/cocos/editor-support/spine/SkeletonData.h @@ -117,7 +117,7 @@ class SP_API SkeletonData : public SpineObject { void setDefaultSkin(Skin *inValue); - Vector &getEvents(); + Vector &getEvents(); Vector &getAnimations(); From 93d649b4248593c20d9aefea8477402c4b02ba47 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 10:18:36 +0800 Subject: [PATCH 08/80] Update spine-type-export.cpp --- .../spine-wasm/spine-type-export.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index f6d10f03a38..6a366517404 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -314,6 +314,17 @@ DEFINE_ALLOW_RAW_POINTER(BoneData) EMSCRIPTEN_BINDINGS(spine) { + +#if ENABLE_EMBIND_TEST + class_("TestFoo") + .constructor() + .property("x", &TestFoo::getX, &TestFoo::setX); + + class_("TestBar") + .constructor() + .property("foo", &TestBar::getFoo, &TestBar::setFoo); +#endif // ENABLE_EMBIND_TEST + REGISTER_SPINE_ENUM(TimelineType); REGISTER_SPINE_ENUM(MixDirection); REGISTER_SPINE_ENUM(MixBlend); @@ -359,14 +370,6 @@ EMSCRIPTEN_BINDINGS(spine) { REGISTER_SPINE_VECTOR(SPVectorSkinEntry, false); REGISTER_SPINE_VECTOR(SPVectorVectorSkinEntry, false); - class_("TestFoo") - .constructor() - .property("x", &TestFoo::getX, &TestFoo::setX); - - class_("TestBar") - .constructor() - .property("foo", &TestBar::getFoo, &TestBar::setFoo); - class_("Vector2") .constructor<>() .constructor() From 31445e1366fddfcebd5276878c87f89f6f0dbadb Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 23 Oct 2024 19:24:58 +0800 Subject: [PATCH 09/80] Don't using namespace in header files. --- .../AtlasAttachmentLoaderExtension.h | 5 +-- .../spine-wasm/mesh-type-define.h | 6 +-- .../spine-wasm/spine-mesh-data.h | 6 +-- .../editor-support/spine-wasm/spine-model.h | 9 +---- .../spine-wasm/spine-skeleton-instance.cpp | 10 ++--- .../spine-wasm/spine-skeleton-instance.h | 38 +++++++++---------- .../editor-support/spine-wasm/spine-wasm.cpp | 2 + .../editor-support/spine-wasm/spine-wasm.h | 29 ++++++-------- 8 files changed, 43 insertions(+), 62 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h index 77230f8fa5d..256f72d99b6 100644 --- a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h +++ b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h @@ -1,5 +1,4 @@ -#ifndef __SPINE_ATLAS_ATTACHMENT_LOADER_EXT_H -#define __SPINE_ATLAS_ATTACHMENT_LOADER_EXT_H +#pragma once #include "mesh-type-define.h" #include "spine/spine.h" @@ -22,5 +21,3 @@ class AtlasAttachmentLoaderExtension : public spine::AtlasAttachmentLoader { private: spine::Atlas *_atlasCache; }; - -#endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/mesh-type-define.h b/native/cocos/editor-support/spine-wasm/mesh-type-define.h index de4e69301f0..e2d0470bda9 100644 --- a/native/cocos/editor-support/spine-wasm/mesh-type-define.h +++ b/native/cocos/editor-support/spine-wasm/mesh-type-define.h @@ -1,5 +1,5 @@ -#ifndef __MESH_TYPE_DEF_H__ -#define __MESH_TYPE_DEF_H__ +#pragma once + #include struct Vec3 { @@ -69,5 +69,3 @@ struct Triangles { /**The number of indices.*/ int indexCount = 0; }; - -#endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-mesh-data.h b/native/cocos/editor-support/spine-wasm/spine-mesh-data.h index 66ad046b02f..f29e67ce5d3 100644 --- a/native/cocos/editor-support/spine-wasm/spine-mesh-data.h +++ b/native/cocos/editor-support/spine-wasm/spine-mesh-data.h @@ -1,5 +1,5 @@ -#ifndef __SPINE_MESH_DATA_H__ -#define __SPINE_MESH_DATA_H__ +#pragma once + #include class SpineMeshData { @@ -22,5 +22,3 @@ class SpineMeshData { static uint8_t *vEnd; static uint16_t *iEnd; }; - -#endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-model.h b/native/cocos/editor-support/spine-wasm/spine-model.h index bb278bc856d..a83092a5ee3 100644 --- a/native/cocos/editor-support/spine-wasm/spine-model.h +++ b/native/cocos/editor-support/spine-wasm/spine-model.h @@ -1,10 +1,7 @@ -#ifndef __SPINE_MODEL_H__ -#define __SPINE_MODEL_H__ +#pragma once + #include #include -#include "mesh-type-define.h" - -using namespace spine; class SlotMesh { public: SlotMesh() {} @@ -43,5 +40,3 @@ class SpineModel { uint32_t iPtr; uint32_t byteStride; }; - -#endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index 4fe0b12b068..70401ee525d 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -366,8 +366,8 @@ void SpineSkeletonInstance::collectMeshData() { currMesh.blendMode = static_cast(slot->getData().getBlendMode()); if (_userData.useSlotTexture) { - auto iter = slotTextureSet.find(slot); - if (iter != slotTextureSet.end()) { + auto iter = _slotTextureSet.find(slot); + if (iter != _slotTextureSet.end()) { currMesh.textureID = iter->second; } } @@ -514,10 +514,10 @@ void SpineSkeletonInstance::setSlotTexture(const std::string &slotName, uint32_t auto slot = _skeleton->findSlot(slotName.c_str()); if (!slot) return; _userData.useSlotTexture = true; - auto iter = slotTextureSet.find(slot); - if (iter != slotTextureSet.end()) { + auto iter = _slotTextureSet.find(slot); + if (iter != _slotTextureSet.end()) { iter->second = textureID; } else { - slotTextureSet[slot] = textureID; + _slotTextureSet[slot] = textureID; } } \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index 735f4e5ea06..b3785bad0ad 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -1,13 +1,11 @@ -#ifndef _SPINE_SKELETON_INSTANCE_H_ -#define _SPINE_SKELETON_INSTANCE_H_ +#pragma once + #include #include #include #include "mesh-type-define.h" #include "spine-model.h" -using namespace spine; - enum DEBUG_SHAPE_TYPE { DEBUG_REGION = 0, @@ -36,8 +34,8 @@ class SpineSkeletonInstance { public: SpineSkeletonInstance(); ~SpineSkeletonInstance(); - Skeleton *initSkeleton(SkeletonData *data); - TrackEntry *setAnimation(float trackIndex, const std::string &name, bool loop); + spine::Skeleton *initSkeleton(spine::SkeletonData *data); + spine::TrackEntry *setAnimation(float trackIndex, const std::string &name, bool loop); void setSkin(const std::string &name); void updateAnimation(float dltTime); SpineModel *updateRenderData(); @@ -45,15 +43,15 @@ class SpineSkeletonInstance { void setUseTint(bool useTint); void setDebugMode(bool debug); void setColor(float r, float g, float b, float a); - void setJitterEffect(JitterVertexEffect *effect); - void setSwirlEffect(SwirlVertexEffect *effect); + void setJitterEffect(spine::JitterVertexEffect *effect); + void setSwirlEffect(spine::SwirlVertexEffect *effect); void clearEffect(); - AnimationState *getAnimationState(); + spine::AnimationState *getAnimationState(); void setMix(const std::string &from, const std::string &to, float duration); inline void setListener(uint32_t listenerID) { _eventListenerID = listenerID;} - void setTrackEntryListener(uint32_t trackId, TrackEntry *entry); - void onAnimationStateEvent(TrackEntry *entry, EventType type, Event *event); - void onTrackEntryEvent(TrackEntry *entry, EventType type, Event *event); + void setTrackEntryListener(uint32_t trackId, spine::TrackEntry *entry); + void onAnimationStateEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); + void onTrackEntryEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); std::vector &getDebugShapes(); void resizeSlotRegion(const std::string &slotName, uint32_t width, uint32_t height, bool createNew = false); void setSlotTexture(const std::string &slotName, uint32_t index); @@ -65,18 +63,16 @@ class SpineSkeletonInstance { void collectMeshData(); private: - Skeleton *_skeleton = nullptr; - SkeletonData *_skeletonData = nullptr; - AnimationStateData *_animStateData = nullptr; - AnimationState *_animState = nullptr; - SkeletonClipping *_clipper = nullptr; - VertexEffect *_effect = nullptr; + spine::Skeleton *_skeleton = nullptr; + spine::SkeletonData *_skeletonData = nullptr; + spine::AnimationStateData *_animStateData = nullptr; + spine::AnimationState *_animState = nullptr; + spine::SkeletonClipping *_clipper = nullptr; + spine::VertexEffect *_effect = nullptr; SpineModel *_model = nullptr; uint32_t _eventListenerID = 0; uint32_t _trackEntryListenerID = 0; UserData _userData; std::vector _debugShapes{}; - std::map slotTextureSet{}; + std::map _slotTextureSet{}; }; - -#endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index 4fa26f2004b..2e8707800f1 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -5,6 +5,8 @@ #include "util-function.h" #include "wasmSpineExtension.h" +using namespace spine; + std::map skeletonDataMap{}; uint32_t SpineWasmUtil::s_listenerID = 0; diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.h b/native/cocos/editor-support/spine-wasm/spine-wasm.h index 993e2c97eca..7cf65fd7e27 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.h +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.h @@ -1,10 +1,7 @@ +#pragma once -#ifndef _SPINE_WASM_H_ -#define _SPINE_WASM_H_ #include #include -#include "spine-skeleton-instance.h" -using namespace spine; class SpineWasmUtil { public: @@ -13,25 +10,23 @@ class SpineWasmUtil { static uint32_t queryStoreMemory(uint32_t size); static void freeStoreMemory(); - static SkeletonData* querySpineSkeletonDataByUUID(const std::string& uuid); - static SkeletonData* createSpineSkeletonDataWithJson(const std::string& jsonStr, const std::string& altasStr); - static SkeletonData* createSpineSkeletonDataWithBinary(uint32_t byteSize, const std::string& altasStr); - static void registerSpineSkeletonDataWithUUID(SkeletonData* data, const std::string& uuid); + static spine::SkeletonData* querySpineSkeletonDataByUUID(const std::string& uuid); + static spine::SkeletonData* createSpineSkeletonDataWithJson(const std::string& jsonStr, const std::string& altasStr); + static spine::SkeletonData* createSpineSkeletonDataWithBinary(uint32_t byteSize, const std::string& altasStr); + static void registerSpineSkeletonDataWithUUID(spine::SkeletonData* data, const std::string& uuid); static void destroySpineSkeletonDataWithUUID(const std::string& uuid); - static void destroySpineSkeleton(Skeleton* skeleton); + static void destroySpineSkeleton(spine::Skeleton* skeleton); static uint32_t getCurrentListenerID(); - static EventType getCurrentEventType(); - static TrackEntry* getCurrentTrackEntry(); - static Event* getCurrentEvent(); + static spine::EventType getCurrentEventType(); + static spine::TrackEntry* getCurrentTrackEntry(); + static spine::Event* getCurrentEvent(); static uint32_t s_listenerID; - static EventType s_currentType; - static TrackEntry* s_currentEntry; - static Event* s_currentEvent; + static spine::EventType s_currentType; + static spine::TrackEntry* s_currentEntry; + static spine::Event* s_currentEvent; static uint8_t* s_mem; static uint32_t s_memSize; }; - -#endif From b7f87e5c765406bf56f27f8993d62bde3018a457 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 10:29:40 +0800 Subject: [PATCH 10/80] Update spine-wasm/CMakeLists.txt --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index 1e73a98d1b3..dbce452e023 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -4,9 +4,8 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(BUILD_WASM 1) -# set(CMAKE_BUILD_TYPE "MinSizeRel") -set(CMAKE_BUILD_TYPE "Debug") -# set(CMAKE_BUILD_TYPE "Release") +set(CMAKE_BUILD_TYPE "MinSizeRel") +# set(CMAKE_BUILD_TYPE "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(ENABLE_CLOSURE_COMPILER 0) From d5f1d86ae904aeb164ef4aa9787ca1451835a0cb Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 10:29:51 +0800 Subject: [PATCH 11/80] Use select_overload --- native/cocos/editor-support/spine-wasm/spine-type-export.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 6a366517404..a46f834a222 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -400,8 +400,8 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Color") .constructor<>() .constructor() - .function("set", static_cast(&Color::set)) - .function("add", static_cast(&Color::add)) + .function("set", select_overload(&Color::set)) + .function("add", select_overload(&Color::add)) .function("clamp", &Color::clamp) .property("r", &Color::r) .property("g", &Color::g) From 09d6f22aaecca1df176ae3d2929f3249f87b66f8 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 23 Oct 2024 19:26:12 +0800 Subject: [PATCH 12/80] Bind spine::String, treat it as std::string. --- cocos/spine/lib/spine-define.ts | 16 +- .../spine-wasm/spine-type-export.cpp | 321 ++++++------------ native/cocos/editor-support/spine/Skin.h | 1 + .../cocos/editor-support/spine/SpineString.h | 10 +- 4 files changed, 119 insertions(+), 229 deletions(-) diff --git a/cocos/spine/lib/spine-define.ts b/cocos/spine/lib/spine-define.ts index afcafb3e0d8..040d4a26d53 100644 --- a/cocos/spine/lib/spine-define.ts +++ b/cocos/spine/lib/spine-define.ts @@ -127,17 +127,6 @@ function overrideProperty_String (): void { overrideDefinePtrStringFunction(prototype, prototype.strPtr, 'strPtr'); } -function overrideProperty_Vector2 (): void { - const prototype = spine.Vector2.prototype as any; - const propertyPolyfills = [ - ['x', prototype.getX, prototype.setX], - ['y', prototype.getY, prototype.setY], - ]; - propertyPolyfills.forEach((prop): void => { - js.get(prototype, prop[0], prop[1], prop[2]); - }); -} - function overrideProperty_BoneData (): void { const prototype = spine.BoneData.prototype as any; const propertyPolyfills = [ @@ -180,7 +169,7 @@ function overrideProperty_ConstraintData (): void { function overrideProperty_IkConstraintData (): void { const prototype = spine.IkConstraintData.prototype as any; const propertyPolyfills = [ - ['target', prototype.getTarget, prototype.setTarget], + // ['target', prototype.getTarget, prototype.setTarget], ['bendDirection', prototype.getBendDirection, prototype.setBendDirection], ['compress', prototype.getCompress, prototype.setCompress], ['stretch', prototype.getStretch, prototype.setStretch], @@ -484,7 +473,7 @@ function overrideProperty_TransformConstraint (): void { function overrideProperty_Bone (): void { const prototype = spine.Bone.prototype as any; const propertyPolyfills = [ - ['skeleton', prototype.getSkeleton], + // ['skeleton', prototype.getSkeleton], ['data', prototype.getData], ['parent', prototype.getParent], ['x', prototype.getX, prototype.setX], @@ -807,7 +796,6 @@ function overrideProperty_SwirlEffect (): void { export function overrideSpineDefine (wasm): void { overrideClass(wasm); overrideProperty_String(); - overrideProperty_Vector2(); overrideProperty_BoneData(); overrideProperty_ConstraintData(); overrideProperty_IkConstraintData(); diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index a46f834a222..fd5abd50bed 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1,11 +1,12 @@ #include +#include #include #include #include "spine-skeleton-instance.h" #include "spine-wasm.h" #include "Vector2.h" -using namespace emscripten; + using namespace spine; #define DEFINE_ALLOW_RAW_POINTER(type) \ @@ -24,10 +25,10 @@ std::string STRING_SP2STD(const spine::String &str) { return stdStr; } -const spine::String STRING_STD2SP(const std::string &str) { - const spine::String spString(str.c_str()); - return spString; -} +// const String STRING_STD2SP(const std::string &str) { +// const String spString(str.c_str()); +// return spString; +// } const std::vector VECTOR_SP2STD_STRING(Vector &container) { int count = container.size(); @@ -68,9 +69,9 @@ void VECTOR_STD_COPY_SP(std::vector &stdVector, Vector &spVector) { } } -String* constructorSpineString(emscripten::val name, bool own) { - return new String(name.as().c_str(), own); -} +// String* constructorSpineString(emscripten::val name, bool own) { +// return new String(name.as().c_str(), own); +// } using SPVectorFloat = Vector; using SPVectorVectorFloat = Vector>; @@ -86,7 +87,7 @@ using SPVectorUnsignedShort = Vector; using SPVectorConstraintDataPtr = Vector; using SPVectorSlotPtr = Vector; using SPVectorSkinPtr = Vector; -using SPVectorEventDataPtr = Vector; +using SPVectorEventDataPtr = Vector; using SPVectorEventPtr = Vector; using SPVectorAnimationPtr = Vector; using SPVectorIkConstraintPtr = Vector; @@ -99,15 +100,16 @@ using SPVectorUpdatablePtr = Vector; using SPVectorSkinEntry = Vector; using SPVectorVectorSkinEntry = Vector; -template static void register_integer(const char* name) { - using namespace internal; - using UnderlyingType = typename std::underlying_type::type; - _embind_register_integer(TypeID::get(), name, sizeof(T), std::numeric_limits::min(), +template +void registerSpineInteger(const char* name) { + using namespace emscripten::internal; + using UnderlyingType = typename std::underlying_type::type; + _embind_register_integer(TypeID::get(), name, sizeof(T), std::numeric_limits::min(), std::numeric_limits::max()); } #define REGISTER_SPINE_ENUM(name) \ - register_integer("spine::" #name) + registerSpineInteger("spine::" #name) template @@ -120,11 +122,11 @@ struct SpineVectorTrait { void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; size_t (VecType::*size)() const = &VecType::size; - return class_>(name) + return emscripten::class_>(name) .template constructor<>() .function("resize", setSize) .function("size", size) - .function("get", &internal::VectorAccess::get); + .function("get", &emscripten::internal::VectorAccess::get); } }; @@ -135,50 +137,15 @@ struct SpineVectorTrait { void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; size_t (VecType::*size)() const = &VecType::size; - return class_>(name) + return emscripten::class_>(name) .template constructor<>() .function("resize", setSize) .function("size", size) - .function("get", &internal::VectorAccess::get) - .function("set", &internal::VectorAccess::set); + .function("get", &emscripten::internal::VectorAccess::get) + .function("set", &emscripten::internal::VectorAccess::set); } }; - -// // export get only for spine::Vector -// template -// typename std::enable_if>>::type -// register_spine_vector(const char* name) { -// typedef spine::Vector VecType; - -// void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; -// size_t (VecType::*size)() const = &VecType::size; -// return class_>(name) -// .template constructor<>() -// .function("resize", setSize) -// .function("size", size) -// .function("get", &internal::VectorAccess::get); -// } - -// // export both get and set for spine::Vector -// template -// typename std::enable_if>>::type -// register_spine_vector(const char* name) { -// typedef spine::Vector VecType; - -// void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; -// size_t (VecType::*size)() const = &VecType::size; -// return class_>(name) -// .template constructor<>() -// .function("resize", setSize) -// .function("size", size) -// .function("get", &internal::VectorAccess::get) -// .function("set", &internal::VectorAccess::set); -// } - -// #define REGISTER_SPINE_VECTOR(name, needSetter) \ -// register_spine_vector(#name) - #define REGISTER_SPINE_VECTOR(name, needSetter) \ SpineVectorTrait::register_spine_vector(#name) @@ -187,28 +154,6 @@ struct SpineVectorTrait { namespace emscripten { namespace internal { -// template -// struct GetterPolicy { -// using ReturnValueType = typename std::enable_if::value, typename std::remove_reference::type>::type; -// using PointerReturnType = std::add_pointer; -// using ReturnType = PointerReturnType; - -// using OriginalContext = GetterReturnType (GetterThisType::*)(); -// using Context = PointerReturnType (GetterThisType::*)(); - -// using Binding = internal::BindingType; -// using WireType = typename Binding::WireType; - -// template -// static WireType get(const OriginalContext& context, const ClassType& ptr) { -// return Binding::toWireType(&(ptr.*context)()); -// } - -// static void* getContext(OriginalContext context) { -// return internal::getContext(context); -// } -// }; - template struct GetterPolicy { using ReturnType = GetterReturnType; @@ -314,6 +259,8 @@ DEFINE_ALLOW_RAW_POINTER(BoneData) EMSCRIPTEN_BINDINGS(spine) { + using namespace emscripten; + using namespace emscripten::internal; #if ENABLE_EMBIND_TEST class_("TestFoo") @@ -325,6 +272,8 @@ EMSCRIPTEN_BINDINGS(spine) { .property("foo", &TestBar::getFoo, &TestBar::setFoo); #endif // ENABLE_EMBIND_TEST + _embind_register_std_string(TypeID::get(), "std::string"); + REGISTER_SPINE_ENUM(TimelineType); REGISTER_SPINE_ENUM(MixDirection); REGISTER_SPINE_ENUM(MixBlend); @@ -379,23 +328,23 @@ EMSCRIPTEN_BINDINGS(spine) { .function("length", &Vector2::length) .function("normalize", &Vector2::normalize); - class_("String") - .constructor<>() - .constructor(constructorSpineString) - .constructor() - .function("length", &String::length) - .function("isEmpty", &String::isEmpty) - .function("append", select_overload(&String::append)) - .function("equals", select_overload(&String::operator=)) - // .function("buffer", &String::buffer, allow_raw_pointer()) - //.function("estr", optional_override([](String &obj) { - // auto str = emscripten::val(obj.buffer()); - // return str; }), allow_raw_pointers()) - .function("strPtr", optional_override([](String &obj) { - return reinterpret_cast(obj.buffer());}), allow_raw_pointers()) - .function("str", optional_override([](String &obj) { - std::string stdStr(obj.buffer(), obj.length()); - return stdStr; }), allow_raw_pointers()); + // class_("String") + // .constructor<>() + // .constructor(constructorSpineString) + // .constructor() + // .function("length", &String::length) + // .function("isEmpty", &String::isEmpty) + // .function("append", select_overload(&String::append)) + // .function("equals", select_overload(&String::operator=)) + // .function("buffer", &String::buffer, allow_raw_pointer()) + // //.function("estr", optional_override([](String &obj) { + // // auto str = emscripten::val(obj.buffer()); + // // return str; }), allow_raw_pointers()) + // .function("strPtr", optional_override([](String &obj) { + // return reinterpret_cast(obj.buffer());}), allow_raw_pointers()) + // .function("str", optional_override([](String &obj) { + // std::string stdStr(obj.buffer(), obj.length()); + // return stdStr; }), allow_raw_pointers()); class_("Color") .constructor<>() @@ -421,7 +370,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_("ConstraintData") .constructor() - .function("getName", optional_override([](ConstraintData &obj) { return STRING_SP2STD(obj.getName()); })) + .function("getName", &ConstraintData::getName) .function("getOrder", &ConstraintData::getOrder) .function("setOrder", &ConstraintData::setOrder) .function("getSkinRequired", &ConstraintData::isSkinRequired) @@ -497,10 +446,8 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setIntValue", &Event::setIntValue) .function("getFloatValue", &Event::getFloatValue) .function("setFloatValue", &Event::setFloatValue) - .function("getStringValue", optional_override([](Event &obj) { - return STRING_SP2STD(obj.getStringValue()); })) - .function("setStringValue", optional_override([](Event &obj, const std::string &name) { - return obj.setStringValue(STRING_STD2SP(name)); }), allow_raw_pointers()) + .function("getStringValue", &Event::getStringValue) + .function("setStringValue", &Event::setStringValue) .function("getTime", &Event::getTime) .function("getVolume", &Event::getVolume) .function("setVolume", &Event::setVolume) @@ -509,20 +456,15 @@ EMSCRIPTEN_BINDINGS(spine) { class_("EventData") .constructor() - .function("getName", optional_override([](EventData &obj) { - return STRING_SP2STD(obj.getName()); })) + .function("getName", &EventData::getName) .function("getIntValue", &EventData::getIntValue) .function("setIntValue", &EventData::setIntValue) .function("getFloatValue", &EventData::getFloatValue) .function("setFloatValue", &EventData::setFloatValue) - .function("getStringValue", optional_override([](EventData &obj) { - return STRING_SP2STD(obj.getStringValue()); })) - .function("setStringValue", optional_override([](EventData &obj, const std::string &name) { - return obj.setStringValue(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("getAudioPath", optional_override([](EventData &obj) { - return STRING_SP2STD(obj.getAudioPath()); })) - .function("setAudioPath", optional_override([](EventData &obj, const std::string &name) { - return obj.setAudioPath(STRING_STD2SP(name)); }), allow_raw_pointers()) + .function("getStringValue", &EventData::getStringValue) + .function("setStringValue", &EventData::setStringValue) + .function("getAudioPath", &EventData::getAudioPath) + .function("setAudioPath", &EventData::setAudioPath) .function("getVolume", &EventData::getVolume) .function("setVolume", &EventData::setVolume) .function("getBalance", &EventData::getBalance) @@ -550,8 +492,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("BoundingBoxAttachment") .constructor() - .function("getName", optional_override([](BoundingBoxAttachment &obj) { - return STRING_SP2STD(obj.getName()); })) + .function("getName", &BoundingBoxAttachment::getName) .function("copy", &BoundingBoxAttachment::copy, allow_raw_pointers()); class_>("ClippingAttachment") @@ -562,11 +503,8 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("MeshAttachment") .constructor() - .function("getPath", optional_override([](MeshAttachment &obj) { - return STRING_SP2STD(obj.getPath()); })) - .function("setPath", optional_override([](MeshAttachment &obj, const std::string &path) { - const String &pathSP = STRING_STD2SP(path); - obj.setPath(pathSP); })) + .function("getPath", &MeshAttachment::getPath) + .function("setPath", &MeshAttachment::setPath) .function("getRegionUVs", optional_override([](MeshAttachment &obj) { return &obj.getRegionUVs(); }), allow_raw_pointer()) .function("getUVs", optional_override([](MeshAttachment &obj) { @@ -630,12 +568,9 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setHeight", &RegionAttachment::setHeight) .function("getColor", optional_override([](RegionAttachment &obj) { return &obj.getColor(); }), allow_raw_pointers()) - .function("getPath", optional_override([](RegionAttachment &obj) { - return STRING_SP2STD(obj.getPath()); })) - .function("setPath", optional_override([](RegionAttachment &obj, const std::string &path) { - const String &pathSP = STRING_STD2SP(path); - obj.setPath(pathSP); })) - // .function("getRendererObject", &RegionAttachment::getRendererObject, allow_raw_pointers()) + .function("getPath", &RegionAttachment::getPath) + .function("setPath", &RegionAttachment::setPath) + //cjh .function("getRendererObject", &RegionAttachment::getRendererObject, allow_raw_pointers()) .function("getOffset", optional_override([](RegionAttachment &obj) { return &obj.getOffset(); }), allow_raw_pointer()) .function("setUVs", &RegionAttachment::setUVs) @@ -666,8 +601,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_("TextureAtlasPage") .constructor() - .function("getName", optional_override([](AtlasPage &obj) { - return STRING_SP2STD((const String)obj.name); })) + .function("getName", optional_override([] (AtlasPage &obj) { return obj.name; })) .property("minFilter", &AtlasPage::minFilter) .property("magFilter", &AtlasPage::magFilter) .property("uWrap", &AtlasPage::uWrap) @@ -678,8 +612,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_("TextureAtlasRegion") //.property("page", &AtlasRegion::page) - .function("getName", optional_override([](AtlasRegion &obj) { - return STRING_SP2STD((const String)obj.name); })) + .function("getName", optional_override([] (AtlasRegion &obj) { return obj.name; })) .property("x", &AtlasRegion::x) .property("y", &AtlasRegion::y) .property("index", &AtlasRegion::index) @@ -692,22 +625,21 @@ EMSCRIPTEN_BINDINGS(spine) { class_("TextureAtlas") .constructor() - .function("findRegion", optional_override([](Atlas &obj, const std::string &name) { - return obj.findRegion(STRING_STD2SP(name)); }), allow_raw_pointers()); + .function("findRegion", &Atlas::findRegion, allow_raw_pointers()); class_>("Pow") .constructor() .function("apply", &PowInterpolation::apply); + class_>("PowOut") .constructor() - .function("apply", &PowInterpolation::apply); + .function("apply", &PowOutInterpolation::apply); class_("SlotData") .constructor() .function("getIndex", &SlotData::getIndex) - .function("getName", optional_override([](SlotData &obj) { - return STRING_SP2STD(obj.getName()); })) + .function("getName", &SlotData::getName) .function("getBoneData", optional_override([](SlotData &obj) { return &obj.getBoneData(); }), allow_raw_pointers()) .function("getColor", optional_override([](SlotData &obj) { @@ -863,10 +795,12 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setWorldX", &Bone::setWorldX) .function("getWorldY", &Bone::getWorldY) .function("setWorldY", &Bone::setWorldY) + .function("getActive", &Bone::isActive) .function("setActive", &Bone::setActive) .function("isActive", &Bone::isActive) .function("update", &Bone::update) + .function("updateWorldTransform", select_overload(&Bone::updateWorldTransform)) .function("updateWorldTransformWith", select_overload(&Bone::updateWorldTransform)) .function("setToSetupPose", &Bone::setToSetupPose) @@ -897,7 +831,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_("BoneData") .constructor() .function("getIndex", &BoneData::getIndex) - .function("getName", optional_override([](BoneData &obj) { return STRING_SP2STD(obj.getName()); })) + .function("getName", &BoneData::getName) .function("getParent", &BoneData::getParent, allow_raw_pointer()) .function("getLength", &BoneData::getLength) .function("setLength", &BoneData::setLength) @@ -941,16 +875,12 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Skin") .constructor() - .function("getName", optional_override([](Skin &obj) { - return STRING_SP2STD(obj.getName()); })) + .function("getName", &Skin::getName) .function("getBones", optional_override([](Skin &obj) { return &obj.getBones(); }), allow_raw_pointer()) .function("getConstraints", optional_override([](Skin &obj) { return &obj.getConstraints(); }), allow_raw_pointer()) - .function("setAttachment", optional_override([](Skin &obj, size_t index, - const std::string &name, Attachment *attachment) { - return obj.setAttachment(index, STRING_STD2SP(name), attachment); - }), allow_raw_pointers()) + .function("setAttachment", &Skin::setAttachment, allow_raw_pointers()) .function("addSkin", select_overload(&Skin::addSkin), allow_raw_pointers()) .function("copySkin", select_overload(&Skin::copySkin), allow_raw_pointers()) .function("findNamesForSlot", optional_override([](Skin &obj, size_t slotIndex) { @@ -959,14 +889,11 @@ EMSCRIPTEN_BINDINGS(spine) { auto entries = obj.getAttachments(); while (entries.hasNext()) { Skin::AttachmentMap::Entry &entry = entries.next(); - if (entry._slotIndex == slotIndex) vetNames.push_back(STRING_SP2STD(entry._name)); + if (entry._slotIndex == slotIndex) vetNames.push_back(entry._name.buffer()); } return vetNames; }), allow_raw_pointers()) - .function("getAttachment", optional_override([](Skin &obj, size_t slotIndex, - const std::string &name) { - return obj.getAttachment(slotIndex, STRING_STD2SP(name)); - }), allow_raw_pointers()) + .function("getAttachment", &Skin::getAttachment, allow_raw_pointers()) .function("getAttachments", optional_override([](Skin &obj) { std::vector entriesVector; auto entries = obj.getAttachments(); @@ -975,9 +902,7 @@ EMSCRIPTEN_BINDINGS(spine) { } return entriesVector; }),allow_raw_pointers()) - .function("removeAttachment", optional_override([](Skin &obj, size_t index, - const std::string &name) { - obj.removeAttachment(index, STRING_STD2SP(name)); })) + .function("removeAttachment", &Skin::removeAttachment) .function("getAttachmentsForSlot", optional_override([](Skin &obj, size_t index) { std::vector entriesVector; auto entries = obj.getAttachments(); @@ -991,7 +916,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_("SkinEntry") .constructor() .property("slotIndex", &Skin::AttachmentMap::Entry::_slotIndex) - .function("getName", optional_override([](Skin::AttachmentMap::Entry &obj) { return STRING_SP2STD((const String)obj._name); })) + .function("getName", optional_override([](Skin::AttachmentMap::Entry& obj) { return obj._name; })) .function("getAttachment", optional_override([](Skin::AttachmentMap::Entry &obj) { return obj._attachment; }), allow_raw_pointers()); class_("SkeletonClipping") @@ -1006,8 +931,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_("SkeletonData") .constructor<>() - .function("getName", optional_override([](SkeletonData &obj) { - return STRING_SP2STD(obj.getName()); })) + .function("getName", &SkeletonData::getName) .function("setName", &SkeletonData::setName) .function("getBones", optional_override([](SkeletonData &obj) { return &obj.getBones(); }), allow_raw_pointer()) @@ -1035,46 +959,31 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setWidth", &SkeletonData::setWidth) .function("getHeight", &SkeletonData::getHeight) .function("setHeight", &SkeletonData::setHeight) - .function("getVersion", optional_override([](SkeletonData &obj) { - return STRING_SP2STD(obj.getVersion()); })) + .function("getVersion", &SkeletonData::getVersion) .function("setVersion", &SkeletonData::setVersion) - .function("getHash", optional_override([](SkeletonData &obj) { - return STRING_SP2STD(obj.getHash()); })) + .function("getHash", &SkeletonData::getHash) .function("setHash", &SkeletonData::setHash) .function("getFps", &SkeletonData::getFps) .function("setFps", &SkeletonData::setFps) - .function("getImagesPath", optional_override([](SkeletonData &obj) { - return STRING_SP2STD(obj.getImagesPath()); })) + .function("getImagesPath", &SkeletonData::getImagesPath) .function("setImagesPath", &SkeletonData::setImagesPath) - .function("getAudioPath", optional_override([](SkeletonData &obj) { - return STRING_SP2STD(obj.getAudioPath()); })) + .function("getAudioPath", &SkeletonData::getAudioPath) .function("setAudioPath", &SkeletonData::setAudioPath) - .function("findBone", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findBone(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findBoneIndex", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findBoneIndex(STRING_STD2SP(name)); })) - .function("findSlot", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findSlot(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findSlotIndex", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findSlotIndex(STRING_STD2SP(name)); })) - .function("findSkin", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findSkin(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findEvent", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findEvent(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findAnimation", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findAnimation(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findIkConstraint", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findIkConstraint(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findTransformConstraint", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findTransformConstraint(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findPathConstraint", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findPathConstraint(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findPathConstraintIndex", optional_override([](SkeletonData &obj, const std::string &name) { - return obj.findPathConstraintIndex(STRING_STD2SP(name)); })); + .function("findBone", &SkeletonData::findBone, allow_raw_pointers()) + .function("findBoneIndex", &SkeletonData::findBoneIndex) + .function("findSlot", &SkeletonData::findSlot, allow_raw_pointers()) + .function("findSlotIndex", &SkeletonData::findSlotIndex) + .function("findSkin", &SkeletonData::findSkin, allow_raw_pointers()) + .function("findEvent", &SkeletonData::findEvent, allow_raw_pointers()) + .function("findAnimation", &SkeletonData::findAnimation, allow_raw_pointers()) + .function("findIkConstraint", &SkeletonData::findIkConstraint, allow_raw_pointers()) + .function("findTransformConstraint", &SkeletonData::findTransformConstraint, allow_raw_pointers()) + .function("findPathConstraint", &SkeletonData::findPathConstraint, allow_raw_pointers()) + .function("findPathConstraintIndex", &SkeletonData::findPathConstraintIndex); class_("Animation") .constructor &, float>() - .function("getName", optional_override([](Animation &obj) { return STRING_SP2STD(obj.getName()); })) + .function("getName", &Animation::getName) .function("getTimelines", optional_override([](Animation &obj) { return &obj.getTimelines(); }), allow_raw_pointer()) .function("hasTimeline", &Animation::hasTimeline) @@ -1146,10 +1055,7 @@ EMSCRIPTEN_BINDINGS(spine) { return VECTOR_SP2STD_STRING(attachmentNames); }), allow_raw_pointers()) .function("getPropertyId", &AttachmentTimeline::getPropertyId) .function("getFrameCount", &AttachmentTimeline::getFrameCount) - .function("setFrame", optional_override([](AttachmentTimeline &obj, int frameIndex, float time, const std::string &attachmentName){ - const String attachmentNameSP = STRING_STD2SP(attachmentName); - obj.setFrame(frameIndex, time, attachmentNameSP); - }), allow_raw_pointers()); + .function("setFrame", &AttachmentTimeline::setFrame, allow_raw_pointers()); class_>("DeformTimeline") .constructor() @@ -1163,8 +1069,8 @@ EMSCRIPTEN_BINDINGS(spine) { return &obj.getVertices(); }), allow_raw_pointer()) .function("getPropertyId", &DeformTimeline::getPropertyId) .function("setFrame", optional_override([](DeformTimeline &obj, int frameIndex, float time, std::vector &vertices){ - Vector sp_vertices = VECTOR_STD2SP(vertices); - obj.setFrame(frameIndex, time, sp_vertices); + Vector spVertices = VECTOR_STD2SP(vertices); + obj.setFrame(frameIndex, time, spVertices); }), allow_raw_pointers()); class_>("EventTimeline") @@ -1268,10 +1174,8 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getDefaultMix", &AnimationStateData::getDefaultMix) .function("setDefaultMix", &AnimationStateData::setDefaultMix) .function("getSkeletonData", &AnimationStateData::getSkeletonData, allow_raw_pointers()) - .function("setMix", optional_override([](AnimationStateData &obj, const std::string& fromName, const std::string& toName, float duration) { - return obj.setMix(STRING_STD2SP(fromName), STRING_STD2SP(toName), duration);})) - .function("setMixWith", optional_override([](AnimationStateData &obj, Animation* from, Animation* to, float duration) { - return obj.setMix(from, to, duration);}), allow_raw_pointers()) + .function("setMix", select_overload(&AnimationStateData::setMix), allow_raw_pointers()) + .function("setMixWith", select_overload(&AnimationStateData::setMix), allow_raw_pointers()) .function("getMix", &AnimationStateData::getMix, allow_raw_pointers()); class_("AnimationState") @@ -1285,10 +1189,10 @@ EMSCRIPTEN_BINDINGS(spine) { .function("apply", &AnimationState::apply) .function("clearTracks", &AnimationState::clearTracks) .function("clearTrack", &AnimationState::clearTrack) - .function("setAnimation", optional_override([](AnimationState &obj, uint32_t trackIndex, const std::string &animName, bool loop) { return obj.setAnimation(trackIndex, STRING_STD2SP(animName), loop); }), allow_raw_pointers()) + .function("setAnimation", select_overload(&AnimationState::setAnimation), allow_raw_pointers()) .function("setAnimationWith", optional_override([](AnimationState &obj, uint32_t trackIndex, Animation *animation, bool loop) { return obj.setAnimation(trackIndex, animation, loop); }), allow_raw_pointers()) - .function("addAnimation", optional_override([](AnimationState &obj, uint32_t trackIndex, const std::string &animName, bool loop, float delay) { return obj.addAnimation(trackIndex, STRING_STD2SP(animName), loop, delay); }), allow_raw_pointers()) - .function("addAnimationWith", optional_override([](AnimationState &obj, uint32_t trackIndex, Animation *animation, bool loop, float delay) { return obj.addAnimation(trackIndex, animation, loop, delay); }), allow_raw_pointers()) + .function("addAnimation", select_overload(&AnimationState::addAnimation), allow_raw_pointers()) + .function("addAnimationWith", select_overload(&AnimationState::addAnimation), allow_raw_pointers()) .function("setEmptyAnimation", &AnimationState::setEmptyAnimation, allow_raw_pointers()) .function("addEmptyAnimation", &AnimationState::addEmptyAnimation, allow_raw_pointers()) .function("setEmptyAnimations", &AnimationState::setEmptyAnimations) @@ -1359,26 +1263,18 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setBonesToSetupPose", &Skeleton::setBonesToSetupPose) .function("setSlotsToSetupPose", &Skeleton::setSlotsToSetupPose) .function("getRootBone", &Skeleton::getRootBone, allow_raw_pointer()) - .function("findBone", optional_override([](Skeleton &obj, const std::string& name) { - return obj.findBone(STRING_STD2SP(name));}), allow_raw_pointers()) - .function("findBoneIndex", optional_override([](Skeleton &obj, const std::string& name) { - return obj.findBoneIndex(STRING_STD2SP(name));})) - .function("findSlot", optional_override([](Skeleton &obj, const std::string& name) { - return obj.findSlot(STRING_STD2SP(name));}), allow_raw_pointers()) - .function("findSlotIndex", optional_override([](Skeleton &obj, const std::string& name) { - return obj.findSlotIndex(STRING_STD2SP(name));})) - .function("setSkinByName", optional_override([](Skeleton &obj, const std::string& name) { - return obj.setSkin(STRING_STD2SP(name));})) + .function("findBone", &Skeleton::findBone, allow_raw_pointers()) + .function("findBoneIndex", &Skeleton::findBoneIndex) + .function("findSlot", &Skeleton::findSlot, allow_raw_pointers()) + .function("findSlotIndex", &Skeleton::findSlotIndex) + .function("setSkinByName", select_overload(&Skeleton::setSkin)) .function("setSkin", static_cast(&Skeleton::setSkin), allow_raw_pointer()) - .function("getAttachmentByName", optional_override([](Skeleton &obj, const std::string& slotName, const std::string& attachmentName) { - return obj.getAttachment(STRING_STD2SP(slotName), STRING_STD2SP(attachmentName));}), allow_raw_pointers()) - .function("getAttachment", optional_override([](Skeleton &obj, int slotIndex, const std::string& attachmentName) { - return obj.getAttachment(slotIndex, STRING_STD2SP(attachmentName));}),allow_raw_pointers()) - .function("setAttachment", optional_override([](Skeleton &obj, const std::string& slotName, const std::string& attachmentName) { - return obj.setAttachment(STRING_STD2SP(slotName), STRING_STD2SP(attachmentName));})) - .function("findIkConstraint", optional_override([](Skeleton &obj, const std::string &name) { return obj.findIkConstraint(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findTransformConstraint", optional_override([](Skeleton &obj, const std::string &name) { return obj.findTransformConstraint(STRING_STD2SP(name)); }), allow_raw_pointers()) - .function("findPathConstraint", optional_override([](Skeleton &obj, const std::string &name) { return obj.findPathConstraint(STRING_STD2SP(name)); }), allow_raw_pointers()) + .function("getAttachmentByName", select_overload(&Skeleton::getAttachment), allow_raw_pointers()) + .function("getAttachment", select_overload(&Skeleton::getAttachment),allow_raw_pointers()) + .function("setAttachment", &Skeleton::setAttachment) + .function("findIkConstraint", &Skeleton::findIkConstraint, allow_raw_pointers()) + .function("findTransformConstraint", &Skeleton::findTransformConstraint, allow_raw_pointers()) + .function("findPathConstraint", &Skeleton::findPathConstraint, allow_raw_pointers()) //.function("getBounds", optional_override([](Skeleton &obj, &outX, ) {}), allow_raw_pointers()) .function("update", &Skeleton::update); @@ -1388,7 +1284,7 @@ EMSCRIPTEN_BINDINGS(spine) { // .constructor() // .function("setScale", &SkeletonBinary::setScale) // .function("getError", &SkeletonBinary::getError); - //.function("readSkeletonDataFile", optional_override([](SkeletonBinary &obj, const spine::String& path) { return obj.readSkeletonDataFile(path); })); + //.function("readSkeletonDataFile", optional_override([](SkeletonBinary &obj, const String& path) { return obj.readSkeletonDataFile(path); })); // incomplete //class_("SkeletonJson") @@ -1476,6 +1372,7 @@ EMSCRIPTEN_BINDINGS(spine) { } EMSCRIPTEN_BINDINGS(cocos_spine) { + using namespace emscripten; class_("SpineWasmUtil") .class_function("spineWasmInit", &SpineWasmUtil::spineWasmInit) .class_function("spineWasmDestroy", &SpineWasmUtil::spineWasmDestroy) diff --git a/native/cocos/editor-support/spine/Skin.h b/native/cocos/editor-support/spine/Skin.h index 7ce6574e18b..c04cbc54aa8 100644 --- a/native/cocos/editor-support/spine/Skin.h +++ b/native/cocos/editor-support/spine/Skin.h @@ -144,6 +144,7 @@ class SP_API Skin : public SpineObject { void copySkin(Skin *other); AttachmentMap::Entries getAttachments(); + Vector> & getAttachmentEntries() { return _attachments._buckets; } Vector &getBones(); diff --git a/native/cocos/editor-support/spine/SpineString.h b/native/cocos/editor-support/spine/SpineString.h index baa1a12a2f8..e6cc5921d2d 100644 --- a/native/cocos/editor-support/spine/SpineString.h +++ b/native/cocos/editor-support/spine/SpineString.h @@ -47,21 +47,25 @@ class SP_API String : public SpineObject { String() : _length(0), _buffer(NULL) { } - String(const char *chars, bool own = false) { + String(const char *chars, size_t len, bool own) { if (!chars) { _length = 0; _buffer = NULL; } else { - _length = strlen(chars); + _length = len; if (!own) { _buffer = SpineExtension::calloc(_length + 1, __FILE__, __LINE__); - memcpy((void *)_buffer, chars, _length + 1); + _buffer[_length] = '\0'; + memcpy((void *)_buffer, chars, _length); } else { _buffer = (char *)chars; } } } + String(const char *chars, bool own = false): String(chars, strlen(chars), own) { + } + String(const String &other) { if (!other._buffer) { _length = 0; From 96d95a8158dc77c3983f474c35337f1ccac97b8b Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 11:43:42 +0800 Subject: [PATCH 13/80] Fix setFrame binding --- .../editor-support/spine-wasm/spine-type-export.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index fd5abd50bed..1613a02f2c6 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1068,8 +1068,13 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getFrameVertices", optional_override([](DeformTimeline &obj) { return &obj.getVertices(); }), allow_raw_pointer()) .function("getPropertyId", &DeformTimeline::getPropertyId) - .function("setFrame", optional_override([](DeformTimeline &obj, int frameIndex, float time, std::vector &vertices){ - Vector spVertices = VECTOR_STD2SP(vertices); + .function("setFrame", optional_override([](DeformTimeline &obj, int frameIndex, float time, emscripten::val jsArray){ + unsigned count = jsArray["length"].as(); + Vector spVertices; + spVertices.setSize(count, 0); + for (int i = 0; i < count; i++) { + spVertices[i] = jsArray[i].as(); + } obj.setFrame(frameIndex, time, spVertices); }), allow_raw_pointers()); From 4d613ae267d3acdce44ea9f8aa187c8360245ad5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 11:44:07 +0800 Subject: [PATCH 14/80] fix spine::String binding --- .../editor-support/spine-wasm/CMakeLists.txt | 3 +- .../spine-wasm/spine-type-export.cpp | 85 ++++++++++++------- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index dbce452e023..d0b8d4b3bb4 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -35,7 +35,8 @@ file(GLOB COCOS_ADAPTER_SRC "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC}) -set(EMS_LINK_FLAGS "-s VERBOSE=0 -s EMBIND_AOT=0 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ +# -s EMBIND_AOT=0 +set(EMS_LINK_FLAGS "-s VERBOSE=0 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ -s MIN_SAFARI_VERSION=110000 \ diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 1613a02f2c6..5b762808bc4 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -39,35 +39,35 @@ const std::vector VECTOR_SP2STD_STRING(Vector &container) { return stdVector; } -template -Vector VECTOR_STD2SP(std::vector &container) { - int count = container.size(); - Vector vecSP; - vecSP.setSize(count, 0); - for (int i = 0; i < count; i++) { - vecSP[i] = container[i]; - } - return vecSP; -} +// template +// Vector VECTOR_STD2SP(std::vector &container) { +// int count = container.size(); +// Vector vecSP; +// vecSP.setSize(count, 0); +// for (int i = 0; i < count; i++) { +// vecSP[i] = container[i]; +// } +// return vecSP; +// } -template -Vector VECTOR_STD2SP_POINTER(std::vector &container) { - int count = container.size(); - Vector vecSP = Vector(); - vecSP.setSize(count, nullptr); - for (int i = 0; i < count; i++) { - vecSP[i] = container[i]; - } - return vecSP; -} +// template +// Vector VECTOR_STD2SP_POINTER(std::vector &container) { +// int count = container.size(); +// Vector vecSP = Vector(); +// vecSP.setSize(count, nullptr); +// for (int i = 0; i < count; i++) { +// vecSP[i] = container[i]; +// } +// return vecSP; +// } -template -void VECTOR_STD_COPY_SP(std::vector &stdVector, Vector &spVector) { - int count = stdVector.size(); - for (int i = 0; i < count; i++) { - stdVector[i] = spVector[i]; - } -} +// template +// void VECTOR_STD_COPY_SP(std::vector &stdVector, Vector &spVector) { +// int count = stdVector.size(); +// for (int i = 0; i < count; i++) { +// stdVector[i] = spVector[i]; +// } +// } // String* constructorSpineString(emscripten::val name, bool own) { // return new String(name.as().c_str(), own); @@ -162,9 +162,11 @@ struct GetterPolicy { using Binding = internal::BindingType; using WireType = typename Binding::WireType; - template + // template + template static WireType get(const Context& context, ClassType& ptr) { - return Binding::toWireType(((ptr.*context)()), ReturnPolicy{}); + // return Binding::toWireType(((ptr.*context)()), ReturnPolicy{}); + return Binding::toWireType(((ptr.*context)())); } static void* getContext(Context context) { @@ -172,6 +174,25 @@ struct GetterPolicy { } }; +template<> +struct BindingType { + using T = char; + static_assert(std::is_trivially_copyable::value, "basic_string elements are memcpy'd"); + using WireType = struct { + size_t length; + T data[1]; // trailing data + } *; + static WireType toWireType(const String& v) { + auto* wt = static_cast(malloc(sizeof(size_t) + v.length() * sizeof(T))); + wt->length = v.length(); + memcpy(wt->data, v.buffer(), v.length() * sizeof(T)); + return wt; + } + static String fromWireType(WireType v) { + return String(v->data, v->length, false); + } +}; + } // namespace internal } // namespace emscripten @@ -380,7 +401,7 @@ EMSCRIPTEN_BINDINGS(spine) { .constructor() .function("getBones", optional_override([](IkConstraintData &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .property("target", &IkConstraintData::getTarget, &IkConstraintData::setTarget, allow_raw_pointer()) + .property("target", &IkConstraintData::getTarget, &IkConstraintData::setTarget) // .function("getTarget", &IkConstraintData::getTarget, allow_raw_pointer()) // .function("setTarget", &IkConstraintData::setTarget, allow_raw_pointer()) .function("getBendDirection", &IkConstraintData::getBendDirection) @@ -1050,9 +1071,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setSlotIndex", &AttachmentTimeline::setSlotIndex) .function("getFrames", optional_override([](AttachmentTimeline &obj) { return &obj.getFrames(); }), allow_raw_pointer()) - .function("getAttachmentNames",optional_override([](AttachmentTimeline &obj) { - Vector attachmentNames = obj.getAttachmentNames(); - return VECTOR_SP2STD_STRING(attachmentNames); }), allow_raw_pointers()) + .function("getAttachmentNames", &AttachmentTimeline::getAttachmentNames) .function("getPropertyId", &AttachmentTimeline::getPropertyId) .function("getFrameCount", &AttachmentTimeline::getFrameCount) .function("setFrame", &AttachmentTimeline::setFrame, allow_raw_pointers()); From de446fdc348ed928d0ffaff327b2aded9928dd41 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 13:35:47 +0800 Subject: [PATCH 15/80] Move implementation of spine::String to .cpp --- .../editor-support/spine/SpineString.cpp | 190 ++++++++++++++++++ .../cocos/editor-support/spine/SpineString.h | 170 ++-------------- 2 files changed, 207 insertions(+), 153 deletions(-) create mode 100644 native/cocos/editor-support/spine/SpineString.cpp diff --git a/native/cocos/editor-support/spine/SpineString.cpp b/native/cocos/editor-support/spine/SpineString.cpp new file mode 100644 index 00000000000..fc0d0d69771 --- /dev/null +++ b/native/cocos/editor-support/spine/SpineString.cpp @@ -0,0 +1,190 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated January 1, 2020. Replaces all prior versions. + * + * Copyright (c) 2013-2020, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, + * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#include + + +// Required for sprintf on MSVC +#ifdef _MSC_VER + #pragma warning(disable : 4996) +#endif + +namespace spine { +String::String() : _length(0), _buffer(NULL) { +} + +String::String(const char *chars, size_t len, bool own) { + if (!chars) { + _length = 0; + _buffer = NULL; + } else { + _length = len; + if (!own) { + _buffer = SpineExtension::calloc(_length + 1, __FILE__, __LINE__); + _buffer[_length] = '\0'; + memcpy((void *)_buffer, chars, _length); + } else { + _buffer = (char *)chars; + } + } +} + +String::String(const char *chars, bool own/* = false*/): String(chars, strlen(chars), own) { +} + +String::String(const String &other) { + if (!other._buffer) { + _length = 0; + _buffer = NULL; + } else { + _length = other._length; + _buffer = SpineExtension::calloc(other._length + 1, __FILE__, __LINE__); + memcpy((void *)_buffer, other._buffer, other._length + 1); + } +} + +void String::own(const String &other) { + if (this == &other) return; + if (_buffer) { + SpineExtension::free(_buffer, __FILE__, __LINE__); + } + _length = other._length; + _buffer = other._buffer; + other._length = 0; + other._buffer = NULL; +} + +void String::own(const char *chars) { + if (_buffer == chars) return; + if (_buffer) { + SpineExtension::free(_buffer, __FILE__, __LINE__); + } + + if (!chars) { + _length = 0; + _buffer = NULL; + } else { + _length = strlen(chars); + _buffer = (char *)chars; + } +} + +void String::unown() { + _length = 0; + _buffer = NULL; +} + +String &String::operator=(const String &other) { + if (this == &other) return *this; + if (_buffer) { + SpineExtension::free(_buffer, __FILE__, __LINE__); + } + if (!other._buffer) { + _length = 0; + _buffer = NULL; + } else { + _length = other._length; + _buffer = SpineExtension::calloc(other._length + 1, __FILE__, __LINE__); + memcpy((void *)_buffer, other._buffer, other._length + 1); + } + return *this; +} + +String &String::operator=(const char *chars) { + if (_buffer == chars) return *this; + if (_buffer) { + SpineExtension::free(_buffer, __FILE__, __LINE__); + } + if (!chars) { + _length = 0; + _buffer = NULL; + } else { + _length = strlen(chars); + _buffer = SpineExtension::calloc(_length + 1, __FILE__, __LINE__); + memcpy((void *)_buffer, chars, _length + 1); + } + return *this; +} + +String &String::append(const char *chars) { + size_t len = strlen(chars); + size_t thisLen = _length; + _length = _length + len; + bool same = chars == _buffer; + _buffer = SpineExtension::realloc(_buffer, _length + 1, __FILE__, __LINE__); + memcpy((void *)(_buffer + thisLen), (void *)(same ? _buffer : chars), len + 1); + return *this; +} + +String &String::append(const String &other) { + size_t len = other.length(); + size_t thisLen = _length; + _length = _length + len; + bool same = other._buffer == _buffer; + _buffer = SpineExtension::realloc(_buffer, _length + 1, __FILE__, __LINE__); + memcpy((void *)(_buffer + thisLen), (void *)(same ? _buffer : other._buffer), len + 1); + return *this; +} + +String &String::append(int other) { + char str[100]; + sprintf(str, "%i", other); + append(str); + return *this; +} + +String &String::append(float other) { + char str[100]; + sprintf(str, "%f", other); + append(str); + return *this; +} + +bool operator==(const String &a, const String &b) { + if (a._buffer == b._buffer) return true; + if (a._length != b._length) return false; + if (a._buffer && b._buffer) { + return strcmp(a._buffer, b._buffer) == 0; + } else { + return false; + } +} + +bool operator!=(const String &a, const String &b) { + return !(a == b); +} + +String::~String() { + if (_buffer) { + SpineExtension::free(_buffer, __FILE__, __LINE__); + } +} + +} // namespace spine + diff --git a/native/cocos/editor-support/spine/SpineString.h b/native/cocos/editor-support/spine/SpineString.h index e6cc5921d2d..e66f3d2b561 100644 --- a/native/cocos/editor-support/spine/SpineString.h +++ b/native/cocos/editor-support/spine/SpineString.h @@ -32,50 +32,17 @@ #include #include - #include #include -// Required for sprintf on MSVC -#ifdef _MSC_VER - #pragma warning(disable : 4996) -#endif - namespace spine { class SP_API String : public SpineObject { public: - String() : _length(0), _buffer(NULL) { - } - - String(const char *chars, size_t len, bool own) { - if (!chars) { - _length = 0; - _buffer = NULL; - } else { - _length = len; - if (!own) { - _buffer = SpineExtension::calloc(_length + 1, __FILE__, __LINE__); - _buffer[_length] = '\0'; - memcpy((void *)_buffer, chars, _length); - } else { - _buffer = (char *)chars; - } - } - } - - String(const char *chars, bool own = false): String(chars, strlen(chars), own) { - } - - String(const String &other) { - if (!other._buffer) { - _length = 0; - _buffer = NULL; - } else { - _length = other._length; - _buffer = SpineExtension::calloc(other._length + 1, __FILE__, __LINE__); - memcpy((void *)_buffer, other._buffer, other._length + 1); - } - } + String(); + String(const char *chars, size_t len, bool own); + String(const char *chars, bool own = false); + String(const String &other); + ~String(); size_t length() const { return _length; @@ -89,123 +56,20 @@ class SP_API String : public SpineObject { return _buffer; } - void own(const String &other) { - if (this == &other) return; - if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); - } - _length = other._length; - _buffer = other._buffer; - other._length = 0; - other._buffer = NULL; - } - - void own(const char *chars) { - if (_buffer == chars) return; - if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); - } - - if (!chars) { - _length = 0; - _buffer = NULL; - } else { - _length = strlen(chars); - _buffer = (char *)chars; - } - } - - void unown() { - _length = 0; - _buffer = NULL; - } - - String &operator=(const String &other) { - if (this == &other) return *this; - if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); - } - if (!other._buffer) { - _length = 0; - _buffer = NULL; - } else { - _length = other._length; - _buffer = SpineExtension::calloc(other._length + 1, __FILE__, __LINE__); - memcpy((void *)_buffer, other._buffer, other._length + 1); - } - return *this; - } - - String &operator=(const char *chars) { - if (_buffer == chars) return *this; - if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); - } - if (!chars) { - _length = 0; - _buffer = NULL; - } else { - _length = strlen(chars); - _buffer = SpineExtension::calloc(_length + 1, __FILE__, __LINE__); - memcpy((void *)_buffer, chars, _length + 1); - } - return *this; - } - - String &append(const char *chars) { - size_t len = strlen(chars); - size_t thisLen = _length; - _length = _length + len; - bool same = chars == _buffer; - _buffer = SpineExtension::realloc(_buffer, _length + 1, __FILE__, __LINE__); - memcpy((void *)(_buffer + thisLen), (void *)(same ? _buffer : chars), len + 1); - return *this; - } - - String &append(const String &other) { - size_t len = other.length(); - size_t thisLen = _length; - _length = _length + len; - bool same = other._buffer == _buffer; - _buffer = SpineExtension::realloc(_buffer, _length + 1, __FILE__, __LINE__); - memcpy((void *)(_buffer + thisLen), (void *)(same ? _buffer : other._buffer), len + 1); - return *this; - } - - String &append(int other) { - char str[100]; - sprintf(str, "%i", other); - append(str); - return *this; - } - - String &append(float other) { - char str[100]; - sprintf(str, "%f", other); - append(str); - return *this; - } - - friend bool operator==(const String &a, const String &b) { - if (a._buffer == b._buffer) return true; - if (a._length != b._length) return false; - if (a._buffer && b._buffer) { - return strcmp(a._buffer, b._buffer) == 0; - } else { - return false; - } - } - - friend bool operator!=(const String &a, const String &b) { - return !(a == b); - } + void own(const String &other); + void own(const char *chars); + void unown(); + String &operator=(const String &other); + String &operator=(const char *chars); - ~String() { - if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); - } - } + String &append(const char *chars); + String &append(const String &other); + String &append(int other); + String &append(float other); + friend bool operator==(const String &a, const String &b); + friend bool operator!=(const String &a, const String &b); + private: mutable size_t _length; mutable char *_buffer; From 564e67764095a6a2e61697869779eb12d17d9f46 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 13:36:06 +0800 Subject: [PATCH 16/80] opt start. --- .../spine-wasm/spine-type-export.cpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 5b762808bc4..ab79c4b5c88 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -20,24 +20,24 @@ namespace emscripten { namespace internal { \ }} namespace { -std::string STRING_SP2STD(const spine::String &str) { - std::string stdStr(str.buffer(), str.length()); - return stdStr; -} +// std::string STRING_SP2STD(const spine::String &str) { +// std::string stdStr(str.buffer(), str.length()); +// return stdStr; +// } // const String STRING_STD2SP(const std::string &str) { // const String spString(str.c_str()); // return spString; // } -const std::vector VECTOR_SP2STD_STRING(Vector &container) { - int count = container.size(); - std::vector stdVector(count); - for (int i = 0; i < count; i++) { - stdVector[i] = STRING_SP2STD(container[i]); - } - return stdVector; -} +// const std::vector VECTOR_SP2STD_STRING(Vector &container) { +// int count = container.size(); +// std::vector stdVector(count); +// for (int i = 0; i < count; i++) { +// stdVector[i] = STRING_SP2STD(container[i]); +// } +// return stdVector; +// } // template // Vector VECTOR_STD2SP(std::vector &container) { @@ -84,6 +84,7 @@ using SPVectorSlotDataPtr = Vector; using SPVectorTransformConstraintDataPtr = Vector; using SPVectorPathConstraintDataPtr = Vector; using SPVectorUnsignedShort = Vector; +using SPVectorSPString = Vector; using SPVectorConstraintDataPtr = Vector; using SPVectorSlotPtr = Vector; using SPVectorSkinPtr = Vector; @@ -319,6 +320,7 @@ EMSCRIPTEN_BINDINGS(spine) { REGISTER_SPINE_VECTOR(SPVectorSize_t, true); REGISTER_SPINE_VECTOR(SPVectorUnsignedShort, true); + REGISTER_SPINE_VECTOR(SPVectorSPString, true); REGISTER_SPINE_VECTOR(SPVectorBonePtr, false); REGISTER_SPINE_VECTOR(SPVectorBoneDataPtr, false); REGISTER_SPINE_VECTOR(SPVectorSlotDataPtr, false); From c6838d8bf1202d3d0750023af68f4e21b8be7a44 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 15:50:30 +0800 Subject: [PATCH 17/80] disable RTTI --- .../editor-support/spine-wasm/CMakeLists.txt | 2 +- .../spine-wasm/spine-type-export.cpp | 126 +++++++++++++++++- .../editor-support/spine/ConstraintData.cpp | 2 + .../editor-support/spine/ConstraintData.h | 1 + .../editor-support/spine/IkConstraintData.cpp | 2 + .../editor-support/spine/IkConstraintData.h | 1 + .../cocos/editor-support/spine/MathUtil.cpp | 4 + native/cocos/editor-support/spine/MathUtil.h | 6 +- .../spine/PathConstraintData.cpp | 2 + .../editor-support/spine/PathConstraintData.h | 1 + .../spine/TransformConstraintData.cpp | 3 + .../spine/TransformConstraintData.h | 1 + .../editor-support/spine/VertexEffect.cpp | 6 + .../cocos/editor-support/spine/VertexEffect.h | 4 + 14 files changed, 155 insertions(+), 6 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index d0b8d4b3bb4..ac276b5a0e1 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -21,7 +21,7 @@ set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -frtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=1") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0") message(">>> --------------------------------------------------------------") message(">>> Current directory: ${CMAKE_CURRENT_LIST_DIR}") diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index ab79c4b5c88..0d18e6e542d 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -13,12 +13,71 @@ using namespace spine; namespace emscripten { namespace internal { \ template<> \ struct TypeID { \ - static constexpr TYPEID get() { \ + static TYPEID get() { \ return TypeID::get(); \ } \ }; \ }} + +#define DEFINE_SPINE_CLASS_TYPEID(cls) \ +namespace emscripten { namespace internal { \ + template<> \ + constexpr TYPEID getLightTypeID(const cls& value) { \ + return value.getRTTI().getClassName(); \ + } \ + \ + template<> \ + struct TypeID { \ + static TYPEID get() { \ + return cls::rtti.getClassName(); \ + } \ + }; \ +}} + +DEFINE_SPINE_CLASS_TYPEID(ConstraintData) +DEFINE_SPINE_CLASS_TYPEID(IkConstraintData) +DEFINE_SPINE_CLASS_TYPEID(PathConstraintData) +DEFINE_SPINE_CLASS_TYPEID(Attachment) +DEFINE_SPINE_CLASS_TYPEID(VertexAttachment) +DEFINE_SPINE_CLASS_TYPEID(BoundingBoxAttachment) +DEFINE_SPINE_CLASS_TYPEID(ClippingAttachment) +DEFINE_SPINE_CLASS_TYPEID(MeshAttachment) +DEFINE_SPINE_CLASS_TYPEID(PathAttachment) +DEFINE_SPINE_CLASS_TYPEID(PointAttachment) +DEFINE_SPINE_CLASS_TYPEID(RegionAttachment) +DEFINE_SPINE_CLASS_TYPEID(AttachmentLoader) +DEFINE_SPINE_CLASS_TYPEID(AtlasAttachmentLoader) +DEFINE_SPINE_CLASS_TYPEID(Interpolation) +DEFINE_SPINE_CLASS_TYPEID(PowInterpolation) +DEFINE_SPINE_CLASS_TYPEID(PowOutInterpolation) +DEFINE_SPINE_CLASS_TYPEID(Updatable) +DEFINE_SPINE_CLASS_TYPEID(IkConstraint) +DEFINE_SPINE_CLASS_TYPEID(PathConstraint) +DEFINE_SPINE_CLASS_TYPEID(TransformConstraintData) +DEFINE_SPINE_CLASS_TYPEID(TransformConstraint) +DEFINE_SPINE_CLASS_TYPEID(Bone) +DEFINE_SPINE_CLASS_TYPEID(Timeline) +DEFINE_SPINE_CLASS_TYPEID(CurveTimeline) +DEFINE_SPINE_CLASS_TYPEID(TranslateTimeline) +DEFINE_SPINE_CLASS_TYPEID(ScaleTimeline) +DEFINE_SPINE_CLASS_TYPEID(ShearTimeline) +DEFINE_SPINE_CLASS_TYPEID(RotateTimeline) +DEFINE_SPINE_CLASS_TYPEID(ColorTimeline) +DEFINE_SPINE_CLASS_TYPEID(TwoColorTimeline) +DEFINE_SPINE_CLASS_TYPEID(AttachmentTimeline) +DEFINE_SPINE_CLASS_TYPEID(DeformTimeline) +DEFINE_SPINE_CLASS_TYPEID(EventTimeline) +DEFINE_SPINE_CLASS_TYPEID(DrawOrderTimeline) +DEFINE_SPINE_CLASS_TYPEID(IkConstraintTimeline) +DEFINE_SPINE_CLASS_TYPEID(TransformConstraintTimeline) +DEFINE_SPINE_CLASS_TYPEID(PathConstraintPositionTimeline) +DEFINE_SPINE_CLASS_TYPEID(PathConstraintMixTimeline) +DEFINE_SPINE_CLASS_TYPEID(VertexEffect) +DEFINE_SPINE_CLASS_TYPEID(JitterVertexEffect) +DEFINE_SPINE_CLASS_TYPEID(SwirlVertexEffect) + + namespace { // std::string STRING_SP2STD(const spine::String &str) { // std::string stdStr(str.buffer(), str.length()); @@ -201,7 +260,18 @@ struct BindingType { #if ENABLE_EMBIND_TEST -class TestFoo { +class TestBase { + RTTI_DECL +public: + virtual void hello(const String& msg) { + printf("TestBase::hello: %s\n", msg.buffer()); + } +}; + +RTTI_IMPL_NOPARENT(TestBase) + +class TestFoo: public TestBase { + RTTI_DECL public: TestFoo() { printf("TestFoo::TestFoo: %p\n", this); @@ -224,6 +294,10 @@ class TestFoo { return *this; } + virtual void hello(const String& msg) override { + printf("TestFoo::hello: %s\n", msg.buffer()); + } + void setX(int x) { _x = x; } @@ -233,6 +307,7 @@ class TestFoo { private: int _x = 0; }; +RTTI_IMPL(TestFoo, TestBase) class TestBar { public: @@ -261,6 +336,7 @@ class TestBar { TestFoo* getFoo() const { return _foo; } + void setFoo(TestFoo *foo) { if (_foo != foo) { delete _foo; @@ -268,12 +344,48 @@ class TestBar { } } + TestBase* getBase() const { + return _foo; + } + private: TestFoo *_foo = new TestFoo(); }; +// namespace emscripten { namespace internal { +// template <> +// constexpr TYPEID getLightTypeID(const TestBase& value) { +// return value.getRTTI().getClassName(); +// } + +// template <> +// struct TypeID { +// static TYPEID get() { +// return TestBase::rtti.getClassName(); +// } +// }; +// }} +// namespace emscripten { namespace internal { +// template<> +// constexpr TYPEID getLightTypeID(const TestFoo& value) { +// return value.getRTTI().getClassName(); +// } + +// template <> +// struct TypeID { +// static TYPEID get() { +// return TestFoo::rtti.getClassName(); +// } +// }; +// }} + +DEFINE_SPINE_CLASS_TYPEID(TestBase) +DEFINE_SPINE_CLASS_TYPEID(TestFoo) + +DEFINE_ALLOW_RAW_POINTER(TestBase) DEFINE_ALLOW_RAW_POINTER(TestFoo) + #endif // ENABLE_EMBIND_TEST @@ -285,13 +397,19 @@ EMSCRIPTEN_BINDINGS(spine) { using namespace emscripten::internal; #if ENABLE_EMBIND_TEST - class_("TestFoo") + class_("TestBase") + .constructor() + .function("hello", &TestBase::hello); + + class_>("TestFoo") .constructor() .property("x", &TestFoo::getX, &TestFoo::setX); class_("TestBar") .constructor() - .property("foo", &TestBar::getFoo, &TestBar::setFoo); + .property("foo", &TestBar::getFoo, &TestBar::setFoo) + .property("base", &TestBar::getBase) + .function("getBase", &TestBar::getBase, allow_raw_pointers()); #endif // ENABLE_EMBIND_TEST _embind_register_std_string(TypeID::get(), "std::string"); diff --git a/native/cocos/editor-support/spine/ConstraintData.cpp b/native/cocos/editor-support/spine/ConstraintData.cpp index 59547a9d2a9..367085850ef 100644 --- a/native/cocos/editor-support/spine/ConstraintData.cpp +++ b/native/cocos/editor-support/spine/ConstraintData.cpp @@ -35,6 +35,8 @@ using namespace spine; +RTTI_IMPL_NOPARENT(ConstraintData) + ConstraintData::ConstraintData(const String& name) : _name(name), _order(0), _skinRequired(false) { } diff --git a/native/cocos/editor-support/spine/ConstraintData.h b/native/cocos/editor-support/spine/ConstraintData.h index bbdb9b87ec8..d740d22c3ff 100644 --- a/native/cocos/editor-support/spine/ConstraintData.h +++ b/native/cocos/editor-support/spine/ConstraintData.h @@ -36,6 +36,7 @@ namespace spine { /// The interface for all constraints. class SP_API ConstraintData : public SpineObject { + RTTI_DECL public: ConstraintData(const String& name); diff --git a/native/cocos/editor-support/spine/IkConstraintData.cpp b/native/cocos/editor-support/spine/IkConstraintData.cpp index 263f9df8309..e6fa2b774cc 100644 --- a/native/cocos/editor-support/spine/IkConstraintData.cpp +++ b/native/cocos/editor-support/spine/IkConstraintData.cpp @@ -37,6 +37,8 @@ using namespace spine; +RTTI_IMPL(IkConstraintData, ConstraintData) + IkConstraintData::IkConstraintData(const String &name) : ConstraintData(name), _target(NULL), _bendDirection(1), diff --git a/native/cocos/editor-support/spine/IkConstraintData.h b/native/cocos/editor-support/spine/IkConstraintData.h index 3461e96585b..cd766c09e9e 100644 --- a/native/cocos/editor-support/spine/IkConstraintData.h +++ b/native/cocos/editor-support/spine/IkConstraintData.h @@ -39,6 +39,7 @@ namespace spine { class BoneData; class SP_API IkConstraintData : public ConstraintData { + RTTI_DECL friend class SkeletonBinary; friend class SkeletonJson; friend class IkConstraint; diff --git a/native/cocos/editor-support/spine/MathUtil.cpp b/native/cocos/editor-support/spine/MathUtil.cpp index 30f8ae2bfc4..c9c230bf4fc 100644 --- a/native/cocos/editor-support/spine/MathUtil.cpp +++ b/native/cocos/editor-support/spine/MathUtil.cpp @@ -42,6 +42,10 @@ using namespace spine; +RTTI_IMPL_NOPARENT(Interpolation) +RTTI_IMPL(PowInterpolation, Interpolation) +RTTI_IMPL(PowOutInterpolation, Interpolation) + const float MathUtil::Pi = 3.1415926535897932385f; const float MathUtil::Pi_2 = 3.1415926535897932385f * 2; const float MathUtil::Deg_Rad = (3.1415926535897932385f / 180.0f); diff --git a/native/cocos/editor-support/spine/MathUtil.h b/native/cocos/editor-support/spine/MathUtil.h index 1041eb6ebca..c2a43f205bb 100644 --- a/native/cocos/editor-support/spine/MathUtil.h +++ b/native/cocos/editor-support/spine/MathUtil.h @@ -31,7 +31,7 @@ #define Spine_MathUtil_h #include - +#include #include namespace spine { @@ -92,6 +92,7 @@ class SP_API MathUtil : public SpineObject { }; struct SP_API Interpolation { + RTTI_DECL virtual float apply(float a) = 0; virtual float interpolate(float start, float end, float a) { @@ -101,7 +102,9 @@ struct SP_API Interpolation { virtual ~Interpolation(){}; }; + struct SP_API PowInterpolation : public Interpolation { + RTTI_DECL PowInterpolation(int power) : power(power) { } @@ -114,6 +117,7 @@ struct SP_API PowInterpolation : public Interpolation { }; struct SP_API PowOutInterpolation : public Interpolation { + RTTI_DECL PowOutInterpolation(int power) : power(power) { } diff --git a/native/cocos/editor-support/spine/PathConstraintData.cpp b/native/cocos/editor-support/spine/PathConstraintData.cpp index 607cd9a7fdb..03757df305b 100644 --- a/native/cocos/editor-support/spine/PathConstraintData.cpp +++ b/native/cocos/editor-support/spine/PathConstraintData.cpp @@ -40,6 +40,8 @@ using namespace spine; +RTTI_IMPL(PathConstraintData, ConstraintData) + PathConstraintData::PathConstraintData(const String &name) : ConstraintData(name), _target(NULL), _positionMode(PositionMode_Fixed), diff --git a/native/cocos/editor-support/spine/PathConstraintData.h b/native/cocos/editor-support/spine/PathConstraintData.h index 915d65b09b3..07e3a489b5a 100644 --- a/native/cocos/editor-support/spine/PathConstraintData.h +++ b/native/cocos/editor-support/spine/PathConstraintData.h @@ -43,6 +43,7 @@ class BoneData; class SlotData; class SP_API PathConstraintData : public ConstraintData { + RTTI_DECL friend class SkeletonBinary; friend class SkeletonJson; diff --git a/native/cocos/editor-support/spine/TransformConstraintData.cpp b/native/cocos/editor-support/spine/TransformConstraintData.cpp index 5da407b2b9a..845204a2dc5 100644 --- a/native/cocos/editor-support/spine/TransformConstraintData.cpp +++ b/native/cocos/editor-support/spine/TransformConstraintData.cpp @@ -38,6 +38,9 @@ #include using namespace spine; + +RTTI_IMPL(TransformConstraintData, ConstraintData) + TransformConstraintData::TransformConstraintData(const String &name) : ConstraintData(name), _target(NULL), _rotateMix(0), diff --git a/native/cocos/editor-support/spine/TransformConstraintData.h b/native/cocos/editor-support/spine/TransformConstraintData.h index 8da5520c129..93f577f350a 100644 --- a/native/cocos/editor-support/spine/TransformConstraintData.h +++ b/native/cocos/editor-support/spine/TransformConstraintData.h @@ -39,6 +39,7 @@ namespace spine { class BoneData; class SP_API TransformConstraintData : public ConstraintData { + RTTI_DECL friend class SkeletonBinary; friend class SkeletonJson; diff --git a/native/cocos/editor-support/spine/VertexEffect.cpp b/native/cocos/editor-support/spine/VertexEffect.cpp index 12b4346bc23..5267d225400 100644 --- a/native/cocos/editor-support/spine/VertexEffect.cpp +++ b/native/cocos/editor-support/spine/VertexEffect.cpp @@ -37,6 +37,10 @@ using namespace spine; +RTTI_IMPL_NOPARENT(VertexEffect) + +RTTI_IMPL(JitterVertexEffect, VertexEffect) + JitterVertexEffect::JitterVertexEffect(float jitterX, float jitterY) : _jitterX(jitterX), _jitterY(jitterY) { } @@ -74,6 +78,8 @@ float JitterVertexEffect::getJitterY() { return _jitterY; } +RTTI_IMPL(SwirlVertexEffect, VertexEffect) + SwirlVertexEffect::SwirlVertexEffect(float radius, Interpolation &interpolation) : _centerX(0), _centerY(0), _radius(radius), diff --git a/native/cocos/editor-support/spine/VertexEffect.h b/native/cocos/editor-support/spine/VertexEffect.h index 71a21d2970f..478ea707b86 100644 --- a/native/cocos/editor-support/spine/VertexEffect.h +++ b/native/cocos/editor-support/spine/VertexEffect.h @@ -32,6 +32,7 @@ #include #include +#include namespace spine { @@ -39,6 +40,7 @@ class Skeleton; class Color; class SP_API VertexEffect : public SpineObject { + RTTI_DECL public: virtual void begin(Skeleton &skeleton) = 0; virtual void transform(float &x, float &y) = 0; @@ -46,6 +48,7 @@ class SP_API VertexEffect : public SpineObject { }; class SP_API JitterVertexEffect : public VertexEffect { + RTTI_DECL public: JitterVertexEffect(float jitterX, float jitterY); @@ -65,6 +68,7 @@ class SP_API JitterVertexEffect : public VertexEffect { }; class SP_API SwirlVertexEffect : public VertexEffect { + RTTI_DECL public: SwirlVertexEffect(float radius, Interpolation &interpolation); From aa9f33e46487059af48b905e0687a259b4db8f35 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 25 Oct 2024 15:50:49 +0800 Subject: [PATCH 18/80] update sp[ine-define.ts, don't hack String. --- cocos/spine/lib/spine-define.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cocos/spine/lib/spine-define.ts b/cocos/spine/lib/spine-define.ts index 040d4a26d53..1bd3fadcc81 100644 --- a/cocos/spine/lib/spine-define.ts +++ b/cocos/spine/lib/spine-define.ts @@ -114,18 +114,18 @@ function overrideClass (wasm): void { } } -function overrideProperty_String (): void { - const prototype = spine.String.prototype as any; - const propertyPolyfills = [ - ['length', prototype.length], - ['isEmpty', prototype.isEmpty], - ['str', prototype.str], - ]; - propertyPolyfills.forEach((prop): void => { - js.get(prototype, prop[0], prop[1]); - }); - overrideDefinePtrStringFunction(prototype, prototype.strPtr, 'strPtr'); -} +// function overrideProperty_String (): void { +// const prototype = spine.String.prototype as any; +// const propertyPolyfills = [ +// ['length', prototype.length], +// ['isEmpty', prototype.isEmpty], +// ['str', prototype.str], +// ]; +// propertyPolyfills.forEach((prop): void => { +// js.get(prototype, prop[0], prop[1]); +// }); +// overrideDefinePtrStringFunction(prototype, prototype.strPtr, 'strPtr'); +// } function overrideProperty_BoneData (): void { const prototype = spine.BoneData.prototype as any; @@ -795,7 +795,7 @@ function overrideProperty_SwirlEffect (): void { export function overrideSpineDefine (wasm): void { overrideClass(wasm); - overrideProperty_String(); + // overrideProperty_String(); overrideProperty_BoneData(); overrideProperty_ConstraintData(); overrideProperty_IkConstraintData(); From 0a5d1599ad827949eb5f2b2ec688759dc386e259 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 28 Oct 2024 18:21:58 +0800 Subject: [PATCH 19/80] embind property --- cocos/spine/lib/spine-define.ts | 406 +++++++------- .../spine-wasm/spine-type-export.cpp | 523 +++++++++--------- 2 files changed, 442 insertions(+), 487 deletions(-) diff --git a/cocos/spine/lib/spine-define.ts b/cocos/spine/lib/spine-define.ts index 1bd3fadcc81..991b9e3f6f9 100644 --- a/cocos/spine/lib/spine-define.ts +++ b/cocos/spine/lib/spine-define.ts @@ -27,6 +27,12 @@ import spine from './spine-core'; import { js } from '../../core'; +function doPolyfill (proto: any, propertyPolyfills: any[]): void { + propertyPolyfills.forEach((prop): void => { + js.getset(proto, prop[0], prop[1], prop[2]); + }); +} + function resizeArray (array: any[], newSize: number): any[] { if (!array) return new Array(newSize); if (newSize === array.length) return array; @@ -127,78 +133,76 @@ function overrideClass (wasm): void { // overrideDefinePtrStringFunction(prototype, prototype.strPtr, 'strPtr'); // } -function overrideProperty_BoneData (): void { - const prototype = spine.BoneData.prototype as any; - const propertyPolyfills = [ - ['index', prototype.getIndex], - ['name', prototype.getName], - ['parent', prototype.getParent], - ['length', prototype.getLength, prototype.setLength], - ['x', prototype.getX, prototype.setX], - ['y', prototype.getY, prototype.setY], - ['rotation', prototype.getRotation, prototype.setRotation], - ['scaleX', prototype.getScaleX, prototype.setScaleX], - ['scaleY', prototype.getScaleY, prototype.setScaleY], - ['shearX', prototype.getShearX, prototype.setShearX], - ['shearY', prototype.getShearY, prototype.setShearY], - ['transformMode', prototype.getTransformMode, prototype.setTransformMode], - ['skinRequired', prototype.getSkinRequired, prototype.setSkinRequired], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} +// function overrideProperty_BoneData (): void { +// const prototype = spine.BoneData.prototype as any; +// const propertyPolyfills = [ +// ['index', prototype.getIndex], +// ['name', prototype.getName], +// ['parent', prototype.getParent], +// ['length', prototype.getLength, prototype.setLength], +// ['x', prototype.getX, prototype.setX], +// ['y', prototype.getY, prototype.setY], +// ['rotation', prototype.getRotation, prototype.setRotation], +// ['scaleX', prototype.getScaleX, prototype.setScaleX], +// ['scaleY', prototype.getScaleY, prototype.setScaleY], +// ['shearX', prototype.getShearX, prototype.setShearX], +// ['shearY', prototype.getShearY, prototype.setShearY], +// ['transformMode', prototype.getTransformMode, prototype.setTransformMode], +// ['skinRequired', prototype.getSkinRequired, prototype.setSkinRequired], +// ]; +// doPolyfill(prototype, propertyPolyfills); +// } -function overrideProperty_Attachment (): void { - const prototype = spine.Attachment.prototype as any; - js.getset(prototype, 'name', prototype.getName); -} +// function overrideProperty_Attachment (): void { +// const prototype = spine.Attachment.prototype as any; +// js.getset(prototype, 'name', prototype.getName); +// } -function overrideProperty_ConstraintData (): void { - const prototype = spine.ConstraintData.prototype as any; - const propertyPolyfills = [ - ['name', prototype.getName], - ['order', prototype.getOrder, prototype.setOder], - ['skinRequired', prototype.getSkinRequired, prototype.setSkinRequired], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} +// function overrideProperty_ConstraintData (): void { +// const prototype = spine.ConstraintData.prototype as any; +// const propertyPolyfills = [ +// ['name', prototype.getName], +// ['order', prototype.getOrder, prototype.setOder], +// ['skinRequired', prototype.getSkinRequired, prototype.setSkinRequired], +// ]; +// propertyPolyfills.forEach((prop): void => { +// js.getset(prototype, prop[0], prop[1], prop[2]); +// }); +// } function overrideProperty_IkConstraintData (): void { const prototype = spine.IkConstraintData.prototype as any; - const propertyPolyfills = [ - // ['target', prototype.getTarget, prototype.setTarget], - ['bendDirection', prototype.getBendDirection, prototype.setBendDirection], - ['compress', prototype.getCompress, prototype.setCompress], - ['stretch', prototype.getStretch, prototype.setStretch], - ['uniform', prototype.getUniform, prototype.setUniform], - ['mix', prototype.getMix, prototype.setMix], - ['softness', prototype.getSoftness, prototype.setSoftness], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + // const propertyPolyfills = [ + // // ['target', prototype.getTarget, prototype.setTarget], + // ['bendDirection', prototype.getBendDirection, prototype.setBendDirection], + // ['compress', prototype.getCompress, prototype.setCompress], + // ['stretch', prototype.getStretch, prototype.setStretch], + // ['uniform', prototype.getUniform, prototype.setUniform], + // ['mix', prototype.getMix, prototype.setMix], + // ['softness', prototype.getSoftness, prototype.setSoftness], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1], prop[2]); + // }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_PathConstraintData (): void { const prototype = spine.PathConstraintData.prototype as any; - const propertyPolyfills = [ - ['target', prototype.getTarget, prototype.setTarget], - ['positionMode', prototype.getPositionMode, prototype.setPositionMode], - ['spacingMode', prototype.getSpacingMode, prototype.setSpacingMode], - ['rotateMode', prototype.getRotateMode, prototype.setRotateMode], - ['offsetRotation', prototype.getOffsetRotation, prototype.setOffsetRotation], - ['position', prototype.getPosition, prototype.setPosition], - ['spacing', prototype.getSpacing, prototype.setSpacing], - ['rotateMix', prototype.getRotateMix, prototype.setRotateMix], - ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + // const propertyPolyfills = [ + // ['target', prototype.getTarget, prototype.setTarget], + // ['positionMode', prototype.getPositionMode, prototype.setPositionMode], + // ['spacingMode', prototype.getSpacingMode, prototype.setSpacingMode], + // ['rotateMode', prototype.getRotateMode, prototype.setRotateMode], + // ['offsetRotation', prototype.getOffsetRotation, prototype.setOffsetRotation], + // ['position', prototype.getPosition, prototype.setPosition], + // ['spacing', prototype.getSpacing, prototype.setSpacing], + // ['rotateMix', prototype.getRotateMix, prototype.setRotateMix], + // ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1], prop[2]); + // }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } @@ -206,44 +210,32 @@ function overrideProperty_Event (): void { const prototype = spine.Event.prototype as any; const propertyPolyfills = [ ['data', prototype.getData], - ['intValue', prototype.getIntValue, prototype.setIntValue], - ['floatValue', prototype.getFloatValue, prototype.setFloatValue], - ['stringValue', prototype.getStringValue, prototype.setStringValue], - ['time', prototype.getTime], - ['volume', prototype.getVolume, prototype.setVolume], - ['balance', prototype.getBalance, prototype.setBalance], + // ['intValue', prototype.getIntValue, prototype.setIntValue], + // ['floatValue', prototype.getFloatValue, prototype.setFloatValue], + // ['stringValue', prototype.getStringValue, prototype.setStringValue], + // ['time', prototype.getTime], + // ['volume', prototype.getVolume, prototype.setVolume], + // ['balance', prototype.getBalance, prototype.setBalance], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); } -function overrideProperty_EventData (): void { - const prototype = spine.EventData.prototype as any; - const propertyPolyfills = [ - ['name', prototype.getName], - ['intValue', prototype.getIntValue, prototype.setIntValue], - ['floatValue', prototype.getFloatValue, prototype.setFloatValue], - ['stringValue', prototype.getStringValue, prototype.setStringValue], - ['audioPath', prototype.getAudioPath, prototype.setAudioPath], - ['volume', prototype.getVolume, prototype.setVolume], - ['balance', prototype.getBalance, prototype.setBalance], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} +// function overrideProperty_EventData (): void { +// const prototype = spine.EventData.prototype as any; +// const propertyPolyfills = [ +// ['name', prototype.getName], +// ['intValue', prototype.getIntValue, prototype.setIntValue], +// ['floatValue', prototype.getFloatValue, prototype.setFloatValue], +// ['stringValue', prototype.getStringValue, prototype.setStringValue], +// ['audioPath', prototype.getAudioPath, prototype.setAudioPath], +// ['volume', prototype.getVolume, prototype.setVolume], +// ['balance', prototype.getBalance, prototype.setBalance], +// ]; +// doPolyfill(prototype, propertyPolyfills); +// } function overrideProperty_VertexAttachment (): void { const prototype = spine.VertexAttachment.prototype as any; - const propertyPolyfills = [ - ['id', prototype.getId], - ['worldVerticesLength', prototype.getWorldVerticesLength, prototype.setWorldVerticesLength], - ['deformAttachment', prototype.getDeformAttachment, prototype.setDeformAttachment], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getVertices, 'vertices'); const originComputeWorldVertices = prototype.computeWorldVertices; @@ -259,28 +251,26 @@ function overrideProperty_VertexAttachment (): void { }); } -function overrideProperty_BoundingBoxAttachment (): void { - const prototype = spine.BoundingBoxAttachment.prototype as any; - js.getset(prototype, 'name', prototype.getName); -} +// function overrideProperty_BoundingBoxAttachment (): void { +// const prototype = spine.BoundingBoxAttachment.prototype as any; +// js.getset(prototype, 'name', prototype.getName); +// } -function overrideProperty_ClippingAttachment (): void { - const prototype = spine.ClippingAttachment.prototype as any; - js.getset(prototype, 'endSlot', prototype.getEndSlot, prototype.setEndSlot); -} +// function overrideProperty_ClippingAttachment (): void { +// const prototype = spine.ClippingAttachment.prototype as any; +// js.getset(prototype, 'endSlot', prototype.getEndSlot, prototype.setEndSlot); +// } function overrideProperty_MeshAttachment (): void { const prototype = spine.MeshAttachment.prototype as any; - const propertyPolyfills = [ - ['path', prototype.getPath, prototype.setPath], - ['color', prototype.getColor], - ['width', prototype.getWidth, prototype.setWidth], - ['height', prototype.getHeight, prototype.setHeight], - ['hullLength', prototype.getHullLength, prototype.setHullLength], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + // const propertyPolyfills = [ + // ['path', prototype.getPath, prototype.setPath], + // ['color', prototype.getColor], + // ['width', prototype.getWidth, prototype.setWidth], + // ['height', prototype.getHeight, prototype.setHeight], + // ['hullLength', prototype.getHullLength, prototype.setHullLength], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getRegionUVs, 'regionUVs'); overrideDefineArrayProp(prototype, prototype.getUVs, 'uvs'); overrideDefineArrayProp(prototype, prototype.getTriangles, 'triangles'); @@ -289,27 +279,25 @@ function overrideProperty_MeshAttachment (): void { function overrideProperty_PathAttachment (): void { const prototype = spine.PathAttachment.prototype as any; - const propertyPolyfills = [ - ['closed', prototype.getClosed, prototype.setClosed], - ['constantSpeed', prototype.getConstantSpeed, prototype.setConstantSpeed], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); + // const propertyPolyfills = [ + // ['closed', prototype.getClosed, prototype.setClosed], + // ['constantSpeed', prototype.getConstantSpeed, prototype.setConstantSpeed], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1]); + // }); overrideDefineArrayProp(prototype, prototype.getLengths, 'lengths'); } -function overrideProperty_PointAttachment (): void { - const prototype = spine.PointAttachment.prototype as any; - const propertyPolyfills = [ - ['x', prototype.getX, prototype.setX], - ['y', prototype.getY, prototype.setY], - ['rotation', prototype.getRotation, prototype.setRotation], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} +// function overrideProperty_PointAttachment (): void { +// const prototype = spine.PointAttachment.prototype as any; +// const propertyPolyfills = [ +// ['x', prototype.getX, prototype.setX], +// ['y', prototype.getY, prototype.setY], +// ['rotation', prototype.getRotation, prototype.setRotation], +// ]; +// doPolyfill(prototype, propertyPolyfills); +// } function overrideProperty_RegionAttachment (): void { const prototype = spine.RegionAttachment.prototype as any; @@ -325,9 +313,7 @@ function overrideProperty_RegionAttachment (): void { ['path', prototype.getPath, prototype.setPath], ['rendererObject', prototype.getRendererObject], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getOffset, 'offset'); const getUVs = prototype.getUVs; @@ -390,9 +376,7 @@ function overrideProperty_SlotData (): void { ['darkColor', prototype.getDarkColor], ['blendMode', prototype.getBlendMode, prototype.setBlendMode], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); } function overrideProperty_IkConstraint (): void { @@ -407,9 +391,7 @@ function overrideProperty_IkConstraint (): void { ['softness', prototype.getSoftness, prototype.setSoftness], ['active', prototype.getActive, prototype.setActive], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } @@ -424,9 +406,7 @@ function overrideProperty_PathConstraint (): void { ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], ['active', prototype.getActive, prototype.setActive], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } @@ -464,59 +444,55 @@ function overrideProperty_TransformConstraint (): void { ['shearMix', prototype.getShearMix, prototype.setShearMix], ['active', prototype.getActive, prototype.setActive], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_Bone (): void { const prototype = spine.Bone.prototype as any; - const propertyPolyfills = [ - // ['skeleton', prototype.getSkeleton], - ['data', prototype.getData], - ['parent', prototype.getParent], - ['x', prototype.getX, prototype.setX], - ['y', prototype.getY, prototype.setY], - ['rotation', prototype.getRotation, prototype.setRotation], - ['scaleX', prototype.getScaleX, prototype.setScaleX], - ['scaleY', prototype.getScaleY, prototype.setScaleY], - ['shearX', prototype.getShearX, prototype.setShearX], - ['shearY', prototype.getShearY, prototype.setShearY], - ['ax', prototype.getAX, prototype.setAX], - ['ay', prototype.getAY, prototype.setAY], - ['arotation', prototype.getARotation, prototype.setARotation], - ['ascaleX', prototype.getAScaleX, prototype.setAScaleX], - ['ascaleY', prototype.getAScaleY, prototype.setAScaleY], - ['ashearX', prototype.getAShearX, prototype.setAShearX], - ['ashearY', prototype.getAShearY, prototype.setAShearY], - ['appliedValid', prototype.getAppliedValid, prototype.setAppliedValid], - ['a', prototype.getA, prototype.setA], - ['b', prototype.getB, prototype.setB], - ['c', prototype.getC, prototype.setC], - ['d', prototype.getD, prototype.setD], - ['worldX', prototype.getWorldX, prototype.setWorldX], - ['worldY', prototype.getWorldY, prototype.setWorldY], - ['active', prototype.getActive, prototype.setActive], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + // const propertyPolyfills = [ + // // ['skeleton', prototype.getSkeleton], + // ['data', prototype.getData], + // ['parent', prototype.getParent], + // ['x', prototype.getX, prototype.setX], + // ['y', prototype.getY, prototype.setY], + // ['rotation', prototype.getRotation, prototype.setRotation], + // ['scaleX', prototype.getScaleX, prototype.setScaleX], + // ['scaleY', prototype.getScaleY, prototype.setScaleY], + // ['shearX', prototype.getShearX, prototype.setShearX], + // ['shearY', prototype.getShearY, prototype.setShearY], + // ['ax', prototype.getAX, prototype.setAX], + // ['ay', prototype.getAY, prototype.setAY], + // ['arotation', prototype.getARotation, prototype.setARotation], + // ['ascaleX', prototype.getAScaleX, prototype.setAScaleX], + // ['ascaleY', prototype.getAScaleY, prototype.setAScaleY], + // ['ashearX', prototype.getAShearX, prototype.setAShearX], + // ['ashearY', prototype.getAShearY, prototype.setAShearY], + // ['appliedValid', prototype.getAppliedValid, prototype.setAppliedValid], + // ['a', prototype.getA, prototype.setA], + // ['b', prototype.getB, prototype.setB], + // ['c', prototype.getC, prototype.setC], + // ['d', prototype.getD, prototype.setD], + // ['worldX', prototype.getWorldX, prototype.setWorldX], + // ['worldY', prototype.getWorldY, prototype.setWorldY], + // ['active', prototype.getActive, prototype.setActive], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getChildren, 'children'); } function overrideProperty_Slot (): void { const prototype = spine.Slot.prototype as any; - const propertyPolyfills = [ - ['data', prototype.getData], - ['bone', prototype.getBone], - ['color', prototype.getColor], - ['darkColor', prototype.getDarkColor], - ['skeleton', prototype.getSkeleton], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); + // const propertyPolyfills = [ + // ['data', prototype.getData], + // ['bone', prototype.getBone], + // ['color', prototype.getColor], + // ['darkColor', prototype.getDarkColor], + // ['skeleton', prototype.getSkeleton], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1]); + // }); overrideDefineArrayProp(prototype, prototype.getDeform, 'deform'); } @@ -583,22 +559,20 @@ function overrideProperty_SkeletonClipping (): void { function overrideProperty_SkeletonData (): void { const prototype = spine.SkeletonData.prototype as any; - const propertyPolyfills = [ - ['name', prototype.getName], - ['defaultSkin', prototype.getDefaultSkin, prototype.setDefaultSkin], - ['x', prototype.getX, prototype.setX], - ['y', prototype.getY, prototype.setY], - ['width', prototype.getWidth, prototype.setWidth], - ['height', prototype.getHeight, prototype.setHeight], - ['version', prototype.getVersion, prototype.setVersion], - ['hash', prototype.getHash, prototype.setHash], - ['fps', prototype.getFps, prototype.setFps], - ['imagesPath', prototype.getImagesPath, prototype.setImagesPath], - ['audioPath', prototype.getAudioPath, prototype.setAudioPath], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + // const propertyPolyfills = [ + // ['name', prototype.getName], + // ['defaultSkin', prototype.getDefaultSkin, prototype.setDefaultSkin], + // ['x', prototype.getX, prototype.setX], + // ['y', prototype.getY, prototype.setY], + // ['width', prototype.getWidth, prototype.setWidth], + // ['height', prototype.getHeight, prototype.setHeight], + // ['version', prototype.getVersion, prototype.setVersion], + // ['hash', prototype.getHash, prototype.setHash], + // ['fps', prototype.getFps, prototype.setFps], + // ['imagesPath', prototype.getImagesPath, prototype.setImagesPath], + // ['audioPath', prototype.getAudioPath, prototype.setAudioPath], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getSlots, 'slots'); @@ -703,9 +677,7 @@ function overrideProperty_TrackEntry (): void { ['mixDuration', prototype.getMixDuration, prototype.setMixDuration], ['mixBlend', prototype.getMixBlend, prototype.setMixBlend], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); } function overrideProperty_AnimationStateData (): void { @@ -725,9 +697,7 @@ function overrideProperty_AnimationState (): void { ['data', prototype.getData], ['timeScale', prototype.getTimeScale, prototype.setTimeScale], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getTracks, 'tracks'); } @@ -738,9 +708,7 @@ function overrideProperty_Animation (): void { ['name', prototype.getName], ['duration', prototype.getDuration, prototype.setDuration], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getTimelines, 'timelines'); } @@ -756,9 +724,7 @@ function overrideProperty_Skeleton (): void { ['x', prototype.getX, prototype.setX], ['y', prototype.getY, prototype.setY], ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getSlots, 'slots'); @@ -796,17 +762,17 @@ function overrideProperty_SwirlEffect (): void { export function overrideSpineDefine (wasm): void { overrideClass(wasm); // overrideProperty_String(); - overrideProperty_BoneData(); - overrideProperty_ConstraintData(); + // overrideProperty_BoneData(); + // overrideProperty_ConstraintData(); overrideProperty_IkConstraintData(); overrideProperty_PathConstraintData(); overrideProperty_Event(); - overrideProperty_EventData(); - overrideProperty_BoundingBoxAttachment(); - overrideProperty_ClippingAttachment(); + // overrideProperty_EventData(); + // overrideProperty_BoundingBoxAttachment(); + // overrideProperty_ClippingAttachment(); overrideProperty_MeshAttachment(); overrideProperty_PathAttachment(); - overrideProperty_PointAttachment(); + // overrideProperty_PointAttachment(); overrideProperty_RegionAttachment(); overrideProperty_VertexAttachment(); overrideProperty_TextureAtlas(); @@ -818,7 +784,7 @@ export function overrideSpineDefine (wasm): void { overrideProperty_Bone(); overrideProperty_Slot(); overrideProperty_Skin(); - overrideProperty_Attachment(); + // overrideProperty_Attachment(); overrideProperty_SkinEntry(); overrideProperty_SkeletonClipping(); overrideProperty_SkeletonData(); diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 0d18e6e542d..9f68ffef710 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -13,7 +13,13 @@ using namespace spine; namespace emscripten { namespace internal { \ template<> \ struct TypeID { \ - static TYPEID get() { \ + static constexpr TYPEID get() { \ + return TypeID::get(); \ + } \ + }; \ + template<> \ + struct TypeID { \ + static constexpr TYPEID get() { \ return TypeID::get(); \ } \ }; \ @@ -26,15 +32,84 @@ namespace emscripten { namespace internal { \ constexpr TYPEID getLightTypeID(const cls& value) { \ return value.getRTTI().getClassName(); \ } \ - \ template<> \ - struct TypeID { \ - static TYPEID get() { \ - return cls::rtti.getClassName(); \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return #cls "*"; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return #cls "*"; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return #cls "*"; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return #cls "*"; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return "const " #cls "*"; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return "const " #cls "*"; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return "const " #cls "*"; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return "const " #cls "*"; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return #cls; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return #cls; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return #cls; \ + } \ + }; \ + template<> \ + struct LightTypeID { \ + static constexpr TYPEID get() { \ + return #cls; \ } \ }; \ }} +#define GETTER_RVAL_TO_PTR(ClassType, Method, ReturnType) \ + optional_override([](ClassType &obj) { return const_cast(&obj.Method()); }) + + DEFINE_SPINE_CLASS_TYPEID(ConstraintData) DEFINE_SPINE_CLASS_TYPEID(IkConstraintData) DEFINE_SPINE_CLASS_TYPEID(PathConstraintData) @@ -78,6 +153,15 @@ DEFINE_SPINE_CLASS_TYPEID(JitterVertexEffect) DEFINE_SPINE_CLASS_TYPEID(SwirlVertexEffect) +DEFINE_ALLOW_RAW_POINTER(BoneData) +DEFINE_ALLOW_RAW_POINTER(Bone) +DEFINE_ALLOW_RAW_POINTER(SlotData) +DEFINE_ALLOW_RAW_POINTER(VertexAttachment) +DEFINE_ALLOW_RAW_POINTER(Color) +DEFINE_ALLOW_RAW_POINTER(EventData) +DEFINE_ALLOW_RAW_POINTER(Skeleton) +DEFINE_ALLOW_RAW_POINTER(Skin) + namespace { // std::string STRING_SP2STD(const spine::String &str) { // std::string stdStr(str.buffer(), str.length()); @@ -182,11 +266,12 @@ struct SpineVectorTrait { void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; size_t (VecType::*size)() const = &VecType::size; + T& (VecType::*get)(size_t) = &VecType::operator[]; return emscripten::class_>(name) .template constructor<>() .function("resize", setSize) .function("size", size) - .function("get", &emscripten::internal::VectorAccess::get); + .function("get", get, emscripten::allow_raw_pointers()); } }; @@ -197,12 +282,15 @@ struct SpineVectorTrait { void (VecType::*setSize)(const size_t, const T&) = &VecType::setSize; size_t (VecType::*size)() const = &VecType::size; + T& (VecType::*get)(size_t) = &VecType::operator[]; return emscripten::class_>(name) .template constructor<>() .function("resize", setSize) .function("size", size) - .function("get", &emscripten::internal::VectorAccess::get) - .function("set", &emscripten::internal::VectorAccess::set); + .function("get", get) + .function("set", emscripten::optional_override([](VecType& obj, int index, const T& value){ + obj[index] = value; + }), emscripten::allow_raw_pointers()); } }; @@ -234,6 +322,25 @@ struct GetterPolicy { } }; +// Non-const version +template +struct GetterPolicy { + using ReturnType = GetterReturnType; + using Context = GetterReturnType (*)(GetterThisType &); + + using Binding = internal::BindingType; + using WireType = typename Binding::WireType; + + template + static WireType get(const Context& context, ClassType& ptr) { + return Binding::toWireType(context(ptr)); + } + + static void* getContext(Context context) { + return internal::getContext(context); + } +}; + template<> struct BindingType { using T = char; @@ -278,7 +385,7 @@ class TestFoo: public TestBase { } TestFoo(const TestFoo& o) { - printf("TestFoo copy constructor %p\n", this); + printf("TestFoo copy constructor %p, %p, o.x=%d\n", this, &o, o._x); *this = o; } @@ -290,6 +397,9 @@ class TestFoo: public TestBase { printf("TestFoo::operator=: %p\n", this); if (this != &o) { _x = o._x; + printf("TestFoo::operator=, _x=%d\n", _x); + } else { + printf("TestFoo::operator=, same address\n"); } return *this; } @@ -309,8 +419,15 @@ class TestFoo: public TestBase { }; RTTI_IMPL(TestFoo, TestBase) +DEFINE_SPINE_CLASS_TYPEID(TestBase) +DEFINE_SPINE_CLASS_TYPEID(TestFoo) + +DEFINE_ALLOW_RAW_POINTER(TestBase) +DEFINE_ALLOW_RAW_POINTER(TestFoo) + class TestBar { public: + RTTI_DECL TestBar() { printf("TestBar::TestBar: %p\n", this); } @@ -333,7 +450,7 @@ class TestBar { return *this; } - TestFoo* getFoo() const { + const TestFoo* getFoo() const { return _foo; } @@ -344,54 +461,28 @@ class TestBar { } } - TestBase* getBase() const { + const TestBase* getBase() const { return _foo; } -private: - TestFoo *_foo = new TestFoo(); -}; - -// namespace emscripten { namespace internal { -// template <> -// constexpr TYPEID getLightTypeID(const TestBase& value) { -// return value.getRTTI().getClassName(); -// } + const TestFoo& getFooConst() { + return *_foo; + } -// template <> -// struct TypeID { -// static TYPEID get() { -// return TestBase::rtti.getClassName(); -// } -// }; -// }} -// namespace emscripten { namespace internal { -// template<> -// constexpr TYPEID getLightTypeID(const TestFoo& value) { -// return value.getRTTI().getClassName(); -// } + void setFooConst(const TestFoo& foo) { + _foo = &foo; + } -// template <> -// struct TypeID { -// static TYPEID get() { -// return TestFoo::rtti.getClassName(); -// } -// }; -// }} +private: + const TestFoo *_foo = new TestFoo(); +}; -DEFINE_SPINE_CLASS_TYPEID(TestBase) -DEFINE_SPINE_CLASS_TYPEID(TestFoo) - -DEFINE_ALLOW_RAW_POINTER(TestBase) -DEFINE_ALLOW_RAW_POINTER(TestFoo) +RTTI_IMPL_NOPARENT(TestBar) #endif // ENABLE_EMBIND_TEST -DEFINE_ALLOW_RAW_POINTER(BoneData) - - EMSCRIPTEN_BINDINGS(spine) { using namespace emscripten; using namespace emscripten::internal; @@ -407,9 +498,12 @@ EMSCRIPTEN_BINDINGS(spine) { class_("TestBar") .constructor() - .property("foo", &TestBar::getFoo, &TestBar::setFoo) - .property("base", &TestBar::getBase) - .function("getBase", &TestBar::getBase, allow_raw_pointers()); + // .property("foo", &TestBar::getFoo, &TestBar::setFoo) + // .property("base", &TestBar::getBase) + // .function("getBase", &TestBar::getBase, allow_raw_pointers()) + .function("getFooConst", &TestBar::getFooConst, allow_raw_pointers()) + .function("setFooConst", &TestBar::setFooConst, allow_raw_pointers()) + ; #endif // ENABLE_EMBIND_TEST _embind_register_std_string(TypeID::get(), "std::string"); @@ -511,54 +605,35 @@ EMSCRIPTEN_BINDINGS(spine) { class_("ConstraintData") .constructor() - .function("getName", &ConstraintData::getName) - .function("getOrder", &ConstraintData::getOrder) - .function("setOrder", &ConstraintData::setOrder) - .function("getSkinRequired", &ConstraintData::isSkinRequired) - .function("setSkinRequired", &ConstraintData::setSkinRequired); + .property("name", &ConstraintData::getName) + .property("order", &ConstraintData::getOrder, &ConstraintData::setOrder) + .property("skinRequired", &ConstraintData::isSkinRequired, &ConstraintData::setSkinRequired); class_>("IkConstraintData") .constructor() .function("getBones", optional_override([](IkConstraintData &obj) { return &obj.getBones(); }), allow_raw_pointer()) .property("target", &IkConstraintData::getTarget, &IkConstraintData::setTarget) - // .function("getTarget", &IkConstraintData::getTarget, allow_raw_pointer()) - // .function("setTarget", &IkConstraintData::setTarget, allow_raw_pointer()) - .function("getBendDirection", &IkConstraintData::getBendDirection) - .function("setBendDirection", &IkConstraintData::setBendDirection) - .function("getCompress", &IkConstraintData::getCompress) - .function("setCompress", &IkConstraintData::setCompress) - .function("getStretch", &IkConstraintData::getStretch) - .function("setStretch", &IkConstraintData::setStretch) - .function("getUniform", &IkConstraintData::getUniform) - .function("setUniform", &IkConstraintData::setUniform) - .function("getMix", &IkConstraintData::getMix) - .function("setMix", &IkConstraintData::setMix) - .function("getSoftness", &IkConstraintData::getSoftness) - .function("setSoftness", &IkConstraintData::setSoftness); + .property("bendDirection", &IkConstraintData::getBendDirection, &IkConstraintData::setBendDirection) + .property("compress", &IkConstraintData::getCompress, &IkConstraintData::setCompress) + .property("stretch", &IkConstraintData::getStretch, &IkConstraintData::setStretch) + .property("uniform", &IkConstraintData::getUniform, &IkConstraintData::setUniform) + .property("mix", &IkConstraintData::getMix, &IkConstraintData::setMix) + .property("softness", &IkConstraintData::getSoftness, &IkConstraintData::setSoftness); class_>("PathConstraintData") .constructor() .function("getBones",optional_override([](PathConstraintData &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .function("getTarget", &PathConstraintData::getTarget, allow_raw_pointer()) - .function("setTarget", &PathConstraintData::setTarget, allow_raw_pointer()) - .function("getPositionMode", &PathConstraintData::getPositionMode) - .function("setPositionMode", &PathConstraintData::setPositionMode) - .function("getSpacingMode", &PathConstraintData::getSpacingMode) - .function("setSpacingMode", &PathConstraintData::setSpacingMode) - .function("getRotateMode", &PathConstraintData::getRotateMode) - .function("setRotateMode", &PathConstraintData::setRotateMode) - .function("getOffsetRotation", &PathConstraintData::getOffsetRotation) - .function("setOffsetRotation", &PathConstraintData::setOffsetRotation) - .function("getPosition", &PathConstraintData::getPosition) - .function("setPosition", &PathConstraintData::setPosition) - .function("getSpacing", &PathConstraintData::getSpacing) - .function("setSpacing", &PathConstraintData::setSpacing) - .function("getRotateMix", &PathConstraintData::getRotateMix) - .function("setRotateMix", &PathConstraintData::setRotateMix) - .function("getTranslateMix", &PathConstraintData::getTranslateMix) - .function("setTranslateMix", &PathConstraintData::setTranslateMix); + .property("target", &PathConstraintData::getTarget, &PathConstraintData::setTarget) + .property("positionMode", &PathConstraintData::getPositionMode, &PathConstraintData::setPositionMode) + .property("spacingMode", &PathConstraintData::getSpacingMode, &PathConstraintData::setSpacingMode) + .property("rotateMode", &PathConstraintData::getRotateMode, &PathConstraintData::setRotateMode) + .property("offsetRotation", &PathConstraintData::getOffsetRotation, &PathConstraintData::setOffsetRotation) + .property("position", &PathConstraintData::getPosition, &PathConstraintData::setPosition) + .property("spacing", &PathConstraintData::getSpacing, &PathConstraintData::setSpacing) + .property("rotateMix", &PathConstraintData::getRotateMix, &PathConstraintData::setRotateMix) + .property("translateMix", &PathConstraintData::getTranslateMix, &PathConstraintData::setTranslateMix); class_("SkeletonBounds") .constructor<>() @@ -581,85 +656,63 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Event") .constructor() - .function("getData", optional_override([](Event &obj) { - return const_cast(&obj.getData()); }), allow_raw_pointers()) - .function("getIntValue", &Event::getIntValue) - .function("setIntValue", &Event::setIntValue) - .function("getFloatValue", &Event::getFloatValue) - .function("setFloatValue", &Event::setFloatValue) - .function("getStringValue", &Event::getStringValue) - .function("setStringValue", &Event::setStringValue) - .function("getTime", &Event::getTime) - .function("getVolume", &Event::getVolume) - .function("setVolume", &Event::setVolume) - .function("getBalance", &Event::getBalance) - .function("setBalance", &Event::setBalance); + .property("data", GETTER_RVAL_TO_PTR(Event, getData, EventData*)) + .property("intValue", &Event::getIntValue, &Event::setIntValue) + .property("floatValue", &Event::getFloatValue, &Event::setFloatValue) + .property("stringValue", &Event::getStringValue, &Event::setStringValue) + .property("time", &Event::getTime) + .property("volume", &Event::getVolume, &Event::setVolume) + .property("balance", &Event::getBalance, &Event::setBalance); class_("EventData") .constructor() - .function("getName", &EventData::getName) - .function("getIntValue", &EventData::getIntValue) - .function("setIntValue", &EventData::setIntValue) - .function("getFloatValue", &EventData::getFloatValue) - .function("setFloatValue", &EventData::setFloatValue) - .function("getStringValue", &EventData::getStringValue) - .function("setStringValue", &EventData::setStringValue) - .function("getAudioPath", &EventData::getAudioPath) - .function("setAudioPath", &EventData::setAudioPath) - .function("getVolume", &EventData::getVolume) - .function("setVolume", &EventData::setVolume) - .function("getBalance", &EventData::getBalance) - .function("setBalance", &EventData::setBalance); + .property("name", &EventData::getName) + .property("intValue", &EventData::getIntValue, &EventData::setIntValue) + .property("floatValue", &EventData::getFloatValue, &EventData::setFloatValue) + .property("stringValue", &EventData::getStringValue, &EventData::setStringValue) + .property("audioPath", &EventData::getAudioPath, &EventData::setAudioPath) + .property("volume", &EventData::getVolume, &EventData::setVolume) + .property("balance", &EventData::getBalance, &EventData::setBalance); class_("Attachment") - //.function("getName", optional_override([](Attachment &obj) { - // return emscripten::val(obj.getName().buffer()); })); - .function("getName", &Attachment::getName, allow_raw_pointers()); + .property("name", &Attachment::getName); // pure_virtual and raw pointer class_>("VertexAttachment") - .function("getId", &VertexAttachment::getId) + .property("id", &VertexAttachment::getId) .function("getBones", optional_override([](VertexAttachment &obj){ return &obj.getBones(); }), allow_raw_pointer()) .function("getVertices", optional_override([](VertexAttachment &obj){ return &obj.getVertices(); }), allow_raw_pointer()) - .function("getWorldVerticesLength", &VertexAttachment::getWorldVerticesLength) - .function("setWorldVerticesLength", &VertexAttachment::setWorldVerticesLength) - .function("getDeformAttachment", &VertexAttachment::getDeformAttachment, allow_raw_pointer()) - .function("setDeformAttachment", &VertexAttachment::setDeformAttachment, allow_raw_pointer()) + .property("worldVerticesLength", &VertexAttachment::getWorldVerticesLength, &VertexAttachment::setWorldVerticesLength) + .property("deformAttachment", &VertexAttachment::getDeformAttachment, &VertexAttachment::setDeformAttachment) .function("computeWorldVertices", select_overload&, size_t, size_t)> (&VertexAttachment::computeWorldVertices), allow_raw_pointer()) .function("copyTo", &VertexAttachment::copyTo, allow_raw_pointers()); class_>("BoundingBoxAttachment") .constructor() - .function("getName", &BoundingBoxAttachment::getName) + .property("name", &BoundingBoxAttachment::getName) .function("copy", &BoundingBoxAttachment::copy, allow_raw_pointers()); class_>("ClippingAttachment") .constructor() - .function("getEndSlot", &ClippingAttachment::getEndSlot, allow_raw_pointers()) - .function("setEndSlot", &ClippingAttachment::setEndSlot, allow_raw_pointers()) + .property("endSlot", &ClippingAttachment::getEndSlot, &ClippingAttachment::setEndSlot) .function("copy", &ClippingAttachment::copy, allow_raw_pointers()); class_>("MeshAttachment") .constructor() - .function("getPath", &MeshAttachment::getPath) - .function("setPath", &MeshAttachment::setPath) + .property("path", &MeshAttachment::getPath, &MeshAttachment::setPath) .function("getRegionUVs", optional_override([](MeshAttachment &obj) { return &obj.getRegionUVs(); }), allow_raw_pointer()) .function("getUVs", optional_override([](MeshAttachment &obj) { return &obj.getUVs(); }), allow_raw_pointer()) .function("getTriangles", optional_override([](MeshAttachment &obj) { return &obj.getTriangles(); }), allow_raw_pointer()) - .function("getColor", optional_override([](MeshAttachment &obj) { - return &obj.getColor(); }), allow_raw_pointers()) - .function("getWidth", &MeshAttachment::getWidth) - .function("setWidth", &MeshAttachment::setWidth) - .function("getHeight", &MeshAttachment::getHeight) - .function("setHeight", &MeshAttachment::setHeight) - .function("getHullLength", &MeshAttachment::getHullLength) - .function("setHullLength", &MeshAttachment::setHullLength) + .property("color", GETTER_RVAL_TO_PTR(MeshAttachment, getColor, Color*)) + .property("width", &MeshAttachment::getWidth, &MeshAttachment::setWidth) + .property("height", &MeshAttachment::getHeight, &MeshAttachment::setHeight) + .property("hullLength", &MeshAttachment::getHullLength, &MeshAttachment::setHullLength) .function("getEdges", optional_override([](MeshAttachment &obj) { return &obj.getEdges(); }), allow_raw_pointer()) .function("updateUVs", &MeshAttachment::updateUVs) @@ -672,20 +725,15 @@ EMSCRIPTEN_BINDINGS(spine) { .constructor() .function("getLengths", optional_override([](PathAttachment &obj) { return &obj.getLengths(); }), allow_raw_pointer()) - .function("getClosed", &PathAttachment::isClosed) - .function("setClosed", &PathAttachment::setClosed) - .function("getConstantSpeed", &PathAttachment::isConstantSpeed) - .function("setConstantSpeed", &PathAttachment::setConstantSpeed) + .property("closed", &PathAttachment::isClosed, &PathAttachment::setClosed) + .property("constantSpeed", &PathAttachment::isConstantSpeed, &PathAttachment::setConstantSpeed) .function("copy", &PathAttachment::copy, allow_raw_pointers()); class_>("PointAttachment") .constructor() - .function("getX", &PointAttachment::getX) - .function("setX", &PointAttachment::setX) - .function("getY", &PointAttachment::getY) - .function("setY", &PointAttachment::setY) - .function("getRotation", &PointAttachment::getRotation) - .function("setRotation", &PointAttachment::setRotation) + .property("x", &PointAttachment::getX, &PointAttachment::setX) + .property("y", &PointAttachment::getY, &PointAttachment::setY) + .property("rotation", &PointAttachment::getRotation, &PointAttachment::setRotation) .function("computeWorldPosition", optional_override([](PointAttachment &obj, Bone &bone, float ox, float oy) { obj.computeWorldPosition(bone, ox, oy);})) .function("computeWorldRotation", &PointAttachment::computeWorldRotation) @@ -693,24 +741,15 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("RegionAttachment") .constructor() - .function("getX", &RegionAttachment::getX) - .function("setX", &RegionAttachment::setX) - .function("getY", &RegionAttachment::getY) - .function("setY", &RegionAttachment::setY) - .function("getScaleX", &RegionAttachment::getScaleX) - .function("setScaleX", &RegionAttachment::setScaleX) - .function("getScaleY", &RegionAttachment::getScaleY) - .function("setScaleY", &RegionAttachment::setScaleY) - .function("getRotation", &RegionAttachment::getRotation) - .function("setRotation", &RegionAttachment::setRotation) - .function("getWidth", &RegionAttachment::getWidth) - .function("setWidth", &RegionAttachment::setWidth) - .function("getHeight", &RegionAttachment::getHeight) - .function("setHeight", &RegionAttachment::setHeight) - .function("getColor", optional_override([](RegionAttachment &obj) { - return &obj.getColor(); }), allow_raw_pointers()) - .function("getPath", &RegionAttachment::getPath) - .function("setPath", &RegionAttachment::setPath) + .property("x", &RegionAttachment::getX, &RegionAttachment::setX) + .property("y", &RegionAttachment::getY, &RegionAttachment::setY) + .property("scaleX", &RegionAttachment::getScaleX, &RegionAttachment::setScaleX) + .property("scaleY", &RegionAttachment::getScaleY, &RegionAttachment::setScaleY) + .property("rotation", &RegionAttachment::getRotation, &RegionAttachment::setRotation) + .property("width", &RegionAttachment::getWidth, &RegionAttachment::setWidth) + .property("height", &RegionAttachment::getHeight, &RegionAttachment::setHeight) + .property("color", GETTER_RVAL_TO_PTR(RegionAttachment, getColor, Color*)) + .property("path", &RegionAttachment::getPath, &RegionAttachment::setPath) //cjh .function("getRendererObject", &RegionAttachment::getRendererObject, allow_raw_pointers()) .function("getOffset", optional_override([](RegionAttachment &obj) { return &obj.getOffset(); }), allow_raw_pointer()) @@ -885,60 +924,34 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("Bone") .constructor() - .function("getData", optional_override([](Bone &obj) { - return &obj.getData(); }), allow_raw_pointers()) + .property("data", GETTER_RVAL_TO_PTR(Bone, getData, BoneData*)) .property("skeleton", &Bone::getSkeleton) - // .function("getSkeleton", optional_override([](Bone &obj) { - // return &obj.getSkeleton(); }), allow_raw_pointers()) - .function("getParent", optional_override([](Bone &obj) { - return obj.getParent(); }), allow_raw_pointers()) + .property("parent", &Bone::getParent) .function("getChildren", optional_override([](Bone &obj) { return &obj.getChildren(); }), allow_raw_pointer()) - .function("getX", &Bone::getX) - .function("setX", &Bone::setX) - .function("getY", &Bone::getY) - .function("setY", &Bone::setY) - .function("getRotation", &Bone::getRotation) - .function("setRotation", &Bone::setRotation) - .function("getScaleX", &Bone::getScaleX) - .function("setScaleX", &Bone::setScaleX) - .function("getScaleY", &Bone::getScaleY) - .function("setScaleY", &Bone::setScaleY) - .function("getShearX", &Bone::getShearX) - .function("setShearX", &Bone::setShearX) - .function("getShearY", &Bone::getShearY) - .function("setShearY", &Bone::setShearY) - .function("getAX", &Bone::getAX) - .function("setAX", &Bone::setAX) - .function("getAY", &Bone::getAY) - .function("setAY", &Bone::setAY) - .function("getARotation", &Bone::getAppliedRotation) - .function("setARotation", &Bone::setAppliedRotation) - .function("getAScaleX", &Bone::getAScaleX) - .function("setAScaleX", &Bone::setAScaleX) - .function("getAScaleY", &Bone::getAScaleY) - .function("setAScaleY", &Bone::setAScaleY) - .function("getAShearX", &Bone::getAShearX) - .function("setAShearX", &Bone::setAShearX) - .function("getAShearY", &Bone::getAShearY) - .function("setAShearY", &Bone::setAShearY) - .function("getAppliedValid", &Bone::isAppliedValid) - .function("setAppliedValid", &Bone::setAppliedValid) - .function("getA", &Bone::getA) - .function("setA", &Bone::setA) - .function("getB", &Bone::getB) - .function("setB", &Bone::setB) - .function("getC", &Bone::getC) - .function("setC", &Bone::setC) - .function("getD", &Bone::getD) - .function("setD", &Bone::setD) - .function("getWorldX", &Bone::getWorldX) - .function("setWorldX", &Bone::setWorldX) - .function("getWorldY", &Bone::getWorldY) - .function("setWorldY", &Bone::setWorldY) + .property("x", &Bone::getX, &Bone::setX) + .property("y", &Bone::getY, &Bone::setY) + .property("rotation", &Bone::getRotation, &Bone::setRotation) + .property("scaleX", &Bone::getScaleX, &Bone::setScaleX) + .property("scaleY", &Bone::getScaleY, &Bone::setScaleY) + .property("shearX", &Bone::getShearX, &Bone::setShearX) + .property("shearY", &Bone::getShearY, &Bone::setShearY) + .property("ax", &Bone::getAX, &Bone::setAX) + .property("ay", &Bone::getAY, &Bone::setAY) + .property("arotation", &Bone::getAppliedRotation, &Bone::setAppliedRotation) + .property("ascaleX", &Bone::getAScaleX, &Bone::setAScaleX) + .property("ascaleY", &Bone::getAScaleY, &Bone::setAScaleY) + .property("ashearX", &Bone::getAShearX, &Bone::setAShearX) + .property("ashearY", &Bone::getAShearY, &Bone::setAShearY) + .property("appliedValid", &Bone::isAppliedValid, &Bone::setAppliedValid) + .property("a", &Bone::getA, &Bone::setA) + .property("b", &Bone::getB, &Bone::setB) + .property("c", &Bone::getC, &Bone::setC) + .property("d", &Bone::getD, &Bone::setD) + .property("worldX", &Bone::getWorldX, &Bone::setWorldX) + .property("worldY", &Bone::getWorldY, &Bone::setWorldY) + .property("active", &Bone::isActive, &Bone::setActive) - .function("getActive", &Bone::isActive) - .function("setActive", &Bone::setActive) .function("isActive", &Bone::isActive) .function("update", &Bone::update) @@ -971,43 +984,29 @@ EMSCRIPTEN_BINDINGS(spine) { class_("BoneData") .constructor() - .function("getIndex", &BoneData::getIndex) - .function("getName", &BoneData::getName) - .function("getParent", &BoneData::getParent, allow_raw_pointer()) - .function("getLength", &BoneData::getLength) - .function("setLength", &BoneData::setLength) - .function("getX", &BoneData::getX) - .function("setX", &BoneData::setX) - .function("getY", &BoneData::getY) - .function("setY", &BoneData::setY) - .function("getRotation", &BoneData::getRotation) - .function("setRotation", &BoneData::setRotation) - .function("getScaleX", &BoneData::getScaleX) - .function("setScaleX", &BoneData::setScaleX) - .function("getScaleY", &BoneData::getScaleY) - .function("setScaleY", &BoneData::setScaleY) - .function("getShearX", &BoneData::getShearX) - .function("setShearX", &BoneData::setShearX) - .function("getShearY", &BoneData::getShearY) - .function("setShearY", &BoneData::setShearY) - .function("getTransformMode", &BoneData::getTransformMode) - .function("setTransformMode", &BoneData::setTransformMode) - .function("getSkinRequired", &BoneData::isSkinRequired) - .function("setShinRequired", &BoneData::setSkinRequired); + .property("index", &BoneData::getIndex) + .property("name", &BoneData::getName) //FIXME(cjh): Don't copy string + .property("parent", &BoneData::getParent) + .property("length", &BoneData::getLength, &BoneData::setLength) + .property("x", &BoneData::getX, &BoneData::setX) + .property("y", &BoneData::getY, &BoneData::setY) + .property("rotation", &BoneData::getRotation, &BoneData::setRotation) + .property("scaleX", &BoneData::getScaleX, &BoneData::setScaleX) + .property("scaleY", &BoneData::getScaleY, &BoneData::setScaleY) + .property("shearX", &BoneData::getShearX, &BoneData::setShearX) + .property("shearY", &BoneData::getShearY, &BoneData::setShearY) + .property("transformMode", &BoneData::getTransformMode, &BoneData::setTransformMode) + .property("skinRequired", &BoneData::isSkinRequired, &BoneData::setSkinRequired); + class_("Slot") .constructor() - .function("getData", optional_override([](Slot &obj) { - return &obj.getData(); }), allow_raw_pointers()) - .function("getBone", optional_override([](Slot &obj) { - return &obj.getBone(); }), allow_raw_pointers()) - .function("getColor", optional_override([](Slot &obj) { - return &obj.getColor(); }), allow_raw_pointers()) - .function("getDarkColor", optional_override([](Slot &obj) { - return &obj.getDarkColor(); }), allow_raw_pointers()) + .property("data", GETTER_RVAL_TO_PTR(Slot, getData, SlotData*)) + .property("bone", GETTER_RVAL_TO_PTR(Slot, getBone, Bone*)) + .property("color", GETTER_RVAL_TO_PTR(Slot, getColor, Color*)) + .property("darkColor", GETTER_RVAL_TO_PTR(Slot, getDarkColor, Color*)) .function("getDeform", &Slot::getDeform, allow_raw_pointers()) - .function("getSkeleton", optional_override([](Slot &obj) { - return &obj.getSkeleton(); }), allow_raw_pointers()) + .property("skeleton", GETTER_RVAL_TO_PTR(Slot, getSkeleton, Skeleton*)) .function("getAttachment", &Slot::getAttachment, allow_raw_pointers()) .function("setAttachment", &Slot::setAttachment, allow_raw_pointers()) .function("setAttachmentTime", &Slot::setAttachmentTime) @@ -1072,16 +1071,14 @@ EMSCRIPTEN_BINDINGS(spine) { class_("SkeletonData") .constructor<>() - .function("getName", &SkeletonData::getName) - .function("setName", &SkeletonData::setName) + .property("name", &SkeletonData::getName, &SkeletonData::setName) .function("getBones", optional_override([](SkeletonData &obj) { return &obj.getBones(); }), allow_raw_pointer()) .function("getSlots", optional_override([](SkeletonData &obj) { return &obj.getSlots(); }), allow_raw_pointer()) .function("getSkins", optional_override([](SkeletonData &obj) { return &obj.getSkins(); }), allow_raw_pointer()) - .function("getDefaultSkin", &SkeletonData::getDefaultSkin, allow_raw_pointers()) - .function("setDefaultSkin", &SkeletonData::setDefaultSkin, allow_raw_pointers()) + .property("defaultSkin", &SkeletonData::getDefaultSkin, &SkeletonData::setDefaultSkin) .function("getEvents", optional_override([](SkeletonData &obj) { return &obj.getEvents(); }), allow_raw_pointer()) .function("getAnimations", optional_override([](SkeletonData &obj) { @@ -1092,24 +1089,16 @@ EMSCRIPTEN_BINDINGS(spine) { return &obj.getTransformConstraints(); }), allow_raw_pointer()) .function("getPathConstraints", optional_override([](SkeletonData &obj) { return &obj.getPathConstraints(); }), allow_raw_pointer()) - .function("getX", &SkeletonData::getX) - .function("setX", &SkeletonData::setX) - .function("getY", &SkeletonData::getY) - .function("setY", &SkeletonData::setY) - .function("getWidth", &SkeletonData::getWidth) - .function("setWidth", &SkeletonData::setWidth) - .function("getHeight", &SkeletonData::getHeight) - .function("setHeight", &SkeletonData::setHeight) - .function("getVersion", &SkeletonData::getVersion) - .function("setVersion", &SkeletonData::setVersion) - .function("getHash", &SkeletonData::getHash) - .function("setHash", &SkeletonData::setHash) - .function("getFps", &SkeletonData::getFps) - .function("setFps", &SkeletonData::setFps) - .function("getImagesPath", &SkeletonData::getImagesPath) - .function("setImagesPath", &SkeletonData::setImagesPath) - .function("getAudioPath", &SkeletonData::getAudioPath) - .function("setAudioPath", &SkeletonData::setAudioPath) + .property("x", &SkeletonData::getX, &SkeletonData::setX) + .property("y", &SkeletonData::getY, &SkeletonData::setY) + .property("width", &SkeletonData::getWidth, &SkeletonData::setWidth) + .property("height", &SkeletonData::getHeight, &SkeletonData::setHeight) + .property("version", &SkeletonData::getVersion, &SkeletonData::setVersion) + .property("hash", &SkeletonData::getHash, &SkeletonData::setHash) + .property("fps", &SkeletonData::getFps, &SkeletonData::setFps) + .property("imagesPath", &SkeletonData::getImagesPath, &SkeletonData::setImagesPath) + .property("audioPath", &SkeletonData::getAudioPath, &SkeletonData::setAudioPath) + .function("findBone", &SkeletonData::findBone, allow_raw_pointers()) .function("findBoneIndex", &SkeletonData::findBoneIndex) .function("findSlot", &SkeletonData::findSlot, allow_raw_pointers()) From e6a72dba1364528ab463ef7e11da24295740da2b Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 28 Oct 2024 19:18:24 +0800 Subject: [PATCH 20/80] Temp --- cocos/spine/lib/spine-define.ts | 414 +++++++++--------- .../spine-wasm/spine-type-export.cpp | 272 +++++------- 2 files changed, 323 insertions(+), 363 deletions(-) diff --git a/cocos/spine/lib/spine-define.ts b/cocos/spine/lib/spine-define.ts index 991b9e3f6f9..ef243b13a0e 100644 --- a/cocos/spine/lib/spine-define.ts +++ b/cocos/spine/lib/spine-define.ts @@ -301,19 +301,19 @@ function overrideProperty_PathAttachment (): void { function overrideProperty_RegionAttachment (): void { const prototype = spine.RegionAttachment.prototype as any; - const propertyPolyfills = [ - ['x', prototype.getX, prototype.setX], - ['y', prototype.getY, prototype.setY], - ['scaleX', prototype.getScaleX, prototype.setScaleX], - ['scaleY', prototype.getScaleY, prototype.setScaleY], - ['rotation', prototype.getRotation, prototype.setRotation], - ['width', prototype.getWidth, prototype.setWidth], - ['height', prototype.getHeight, prototype.setHeight], - ['color', prototype.getColor], - ['path', prototype.getPath, prototype.setPath], - ['rendererObject', prototype.getRendererObject], - ]; - doPolyfill(prototype, propertyPolyfills); + // const propertyPolyfills = [ + // ['x', prototype.getX, prototype.setX], + // ['y', prototype.getY, prototype.setY], + // ['scaleX', prototype.getScaleX, prototype.setScaleX], + // ['scaleY', prototype.getScaleY, prototype.setScaleY], + // ['rotation', prototype.getRotation, prototype.setRotation], + // ['width', prototype.getWidth, prototype.setWidth], + // ['height', prototype.getHeight, prototype.setHeight], + // ['color', prototype.getColor], + // ['path', prototype.getPath, prototype.setPath], + // ['rendererObject', prototype.getRendererObject], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getOffset, 'offset'); const getUVs = prototype.getUVs; @@ -366,85 +366,85 @@ function overrideProperty_TextureAtlas (): void { // }); } -function overrideProperty_SlotData (): void { - const prototype = spine.SlotData.prototype as any; - const propertyPolyfills = [ - ['index', prototype.getIndex], - ['boneData', prototype.getBoneData], - ['name', prototype.getName], - ['color', prototype.getColor], - ['darkColor', prototype.getDarkColor], - ['blendMode', prototype.getBlendMode, prototype.setBlendMode], - ]; - doPolyfill(prototype, propertyPolyfills); -} +// function overrideProperty_SlotData (): void { +// const prototype = spine.SlotData.prototype as any; +// const propertyPolyfills = [ +// ['index', prototype.getIndex], +// ['boneData', prototype.getBoneData], +// ['name', prototype.getName], +// ['color', prototype.getColor], +// ['darkColor', prototype.getDarkColor], +// ['blendMode', prototype.getBlendMode, prototype.setBlendMode], +// ]; +// doPolyfill(prototype, propertyPolyfills); +// } function overrideProperty_IkConstraint (): void { const prototype = spine.IkConstraint.prototype as any; - const propertyPolyfills = [ - ['data', prototype.getData], - ['target', prototype.getTarget, prototype.setTarget], - ['bendDirection', prototype.getBendDirection, prototype.setBendDirection], - ['compress', prototype.getCompress, prototype.setCompress], - ['stretch', prototype.getStretch, prototype.setStretch], - ['mix', prototype.getMix, prototype.setMix], - ['softness', prototype.getSoftness, prototype.setSoftness], - ['active', prototype.getActive, prototype.setActive], - ]; - doPolyfill(prototype, propertyPolyfills); + // const propertyPolyfills = [ + // ['data', prototype.getData], + // ['target', prototype.getTarget, prototype.setTarget], + // ['bendDirection', prototype.getBendDirection, prototype.setBendDirection], + // ['compress', prototype.getCompress, prototype.setCompress], + // ['stretch', prototype.getStretch, prototype.setStretch], + // ['mix', prototype.getMix, prototype.setMix], + // ['softness', prototype.getSoftness, prototype.setSoftness], + // ['active', prototype.getActive, prototype.setActive], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_PathConstraint (): void { const prototype = spine.PathConstraint.prototype as any; - const propertyPolyfills = [ - ['data', prototype.getData], - ['target', prototype.getTarget, prototype.setTarget], - ['position', prototype.getPosition, prototype.setPosition], - ['spacing', prototype.getSpacing, prototype.setSpacing], - ['rotateMix', prototype.getRotateMix, prototype.setRotateMix], - ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], - ['active', prototype.getActive, prototype.setActive], - ]; - doPolyfill(prototype, propertyPolyfills); + // const propertyPolyfills = [ + // ['data', prototype.getData], + // ['target', prototype.getTarget, prototype.setTarget], + // ['position', prototype.getPosition, prototype.setPosition], + // ['spacing', prototype.getSpacing, prototype.setSpacing], + // ['rotateMix', prototype.getRotateMix, prototype.setRotateMix], + // ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], + // ['active', prototype.getActive, prototype.setActive], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_TransformConstraintData (): void { const prototype = spine.TransformConstraintData.prototype as any; - const propertyPolyfills = [ - ['target', prototype.getTarget], - ['rotateMix', prototype.getRotateMix], - ['translateMix', prototype.getTranslateMix], - ['scaleMix', prototype.getScaleMix], - ['shearMix', prototype.getShearMix], - ['offsetRotation', prototype.getOffsetRotation], - ['offsetX', prototype.getOffsetX], - ['offsetY', prototype.getOffsetY], - ['offsetScaleX', prototype.getOffsetScaleX], - ['offsetScaleY', prototype.getOffsetScaleY], - ['offsetShearY', prototype.getOffsetShearY], - ['relative', prototype.getRelative], - ['local', prototype.getLocal], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); + // const propertyPolyfills = [ + // ['target', prototype.getTarget], + // ['rotateMix', prototype.getRotateMix], + // ['translateMix', prototype.getTranslateMix], + // ['scaleMix', prototype.getScaleMix], + // ['shearMix', prototype.getShearMix], + // ['offsetRotation', prototype.getOffsetRotation], + // ['offsetX', prototype.getOffsetX], + // ['offsetY', prototype.getOffsetY], + // ['offsetScaleX', prototype.getOffsetScaleX], + // ['offsetScaleY', prototype.getOffsetScaleY], + // ['offsetShearY', prototype.getOffsetShearY], + // ['relative', prototype.getRelative], + // ['local', prototype.getLocal], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1]); + // }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_TransformConstraint (): void { const prototype = spine.TransformConstraint.prototype as any; - const propertyPolyfills = [ - ['data', prototype.getData], - ['target', prototype.getTarget], - ['rotateMix', prototype.getRotateMix, prototype.setRotateMix], - ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], - ['scaleMix', prototype.getScaleMix, prototype.setScaleMix], - ['shearMix', prototype.getShearMix, prototype.setShearMix], - ['active', prototype.getActive, prototype.setActive], - ]; - doPolyfill(prototype, propertyPolyfills); + // const propertyPolyfills = [ + // ['data', prototype.getData], + // ['target', prototype.getTarget], + // ['rotateMix', prototype.getRotateMix, prototype.setRotateMix], + // ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], + // ['scaleMix', prototype.getScaleMix, prototype.setScaleMix], + // ['shearMix', prototype.getShearMix, prototype.setShearMix], + // ['active', prototype.getActive, prototype.setActive], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } @@ -498,12 +498,12 @@ function overrideProperty_Slot (): void { function overrideProperty_Skin (): void { const prototype = spine.Skin.prototype as any; - const propertyPolyfills = [ - ['name', prototype.getName], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); + // const propertyPolyfills = [ + // ['name', prototype.getName], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1]); + // }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getAttachments, 'attachments'); overrideDefineArrayProp(prototype, prototype.getConstraints, 'constraints'); @@ -545,17 +545,17 @@ function overrideProperty_SkinEntry (): void { }); } -function overrideProperty_SkeletonClipping (): void { - const prototype = spine.SkeletonClipping.prototype as any; - const propertyPolyfills = [ - ['clippedVertices', prototype.getClippedVertices], - ['clippedTriangles', prototype.getClippedTriangles], - ['clippedUVs', prototype.getClippedUVs], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); -} +// function overrideProperty_SkeletonClipping (): void { +// const prototype = spine.SkeletonClipping.prototype as any; +// const propertyPolyfills = [ +// ['clippedVertices', prototype.getClippedVertices], +// ['clippedTriangles', prototype.getClippedTriangles], +// ['clippedUVs', prototype.getClippedUVs], +// ]; +// propertyPolyfills.forEach((prop): void => { +// js.getset(prototype, prop[0], prop[1]); +// }); +// } function overrideProperty_SkeletonData (): void { const prototype = spine.SkeletonData.prototype as any; @@ -586,57 +586,57 @@ function overrideProperty_SkeletonData (): void { function overrideProperty_RotateTimeline (): void { const prototype = spine.RotateTimeline.prototype as any; - const propertyPolyfills = [ - ['boneIndex', prototype.getBoneIndex], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); + // const propertyPolyfills = [ + // ['boneIndex', prototype.getBoneIndex], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1]); + // }); overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); } function overrideProperty_ColorTimeline (): void { const prototype = spine.ColorTimeline.prototype as any; - const propertyPolyfills = [ - ['slotIndex', prototype.getSlotIndex], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); + // const propertyPolyfills = [ + // ['slotIndex', prototype.getSlotIndex], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1]); + // }); overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); } -function overrideProperty_TwoColorTimeline (): void { - const prototype = spine.TwoColorTimeline.prototype as any; - const propertyPolyfills = [ - ['slotIndex', prototype.getSlotIndex], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); -} +// function overrideProperty_TwoColorTimeline (): void { +// const prototype = spine.TwoColorTimeline.prototype as any; +// const propertyPolyfills = [ +// ['slotIndex', prototype.getSlotIndex], +// ]; +// propertyPolyfills.forEach((prop): void => { +// js.getset(prototype, prop[0], prop[1]); +// }); +// } function overrideProperty_AttachmentTimeline (): void { const prototype = spine.AttachmentTimeline.prototype as any; - const propertyPolyfills = [ - ['slotIndex', prototype.getSlotIndex], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); + // const propertyPolyfills = [ + // ['slotIndex', prototype.getSlotIndex], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1]); + // }); overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); overrideDefineArrayProp(prototype, prototype.getAttachmentNames, 'attachmentNames'); } function overrideProperty_DeformTimeline (): void { const prototype = spine.DeformTimeline.prototype as any; - const propertyPolyfills = [ - ['slotIndex', prototype.getSlotIndex], - ['attachment', prototype.getAttachment], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); + // const propertyPolyfills = [ + // ['slotIndex', prototype.getSlotIndex], + // ['attachment', prototype.getAttachment], + // ]; + // propertyPolyfills.forEach((prop): void => { + // js.getset(prototype, prop[0], prop[1]); + // }); overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); overrideDefineArrayArrayProp(prototype, prototype.getFrameVertices, 'frameVertices'); } @@ -652,44 +652,44 @@ function overrideProperty_DrawOrderTimeline (): void { overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); } -function overrideProperty_TrackEntry (): void { - const prototype = spine.TrackEntry.prototype as any; - const propertyPolyfills = [ - ['animation', prototype.getAnimation], - ['next', prototype.getNext], - ['mixingFrom', prototype.getMixingFrom], - ['mixingTo', prototype.getMixingTo], - ['trackIndex', prototype.getTrackIndex], - ['loop', prototype.getLoop, prototype.setLoop], - ['holdPrevious', prototype.getHoldPrevious, prototype.setHoldPrevious], - ['eventThreshold', prototype.getEventThreshold, prototype.setEventThreshold], - ['attachmentThreshold', prototype.getAttachmentThreshold, prototype.setAttachmentThreshold], - ['drawOrderThreshold', prototype.getDrawOrderThreshold, prototype.setDrawOrderThreshold], - ['animationStart', prototype.getAnimationStart, prototype.setAnimationStart], - ['animationEnd', prototype.getAnimationEnd, prototype.setAnimationEnd], - ['animationLast', prototype.getAnimationLast, prototype.setAnimationLast], - ['delay', prototype.getDelay, prototype.setDelay], - ['trackTime', prototype.getTrackTime, prototype.setTrackTime], - ['trackEnd', prototype.getTrackEnd, prototype.setTrackEnd], - ['timeScale', prototype.getTimeScale, prototype.setTimeScale], - ['alpha', prototype.getAlpha, prototype.setAlpha], - ['mixTime', prototype.getMixTime, prototype.setMixTime], - ['mixDuration', prototype.getMixDuration, prototype.setMixDuration], - ['mixBlend', prototype.getMixBlend, prototype.setMixBlend], - ]; - doPolyfill(prototype, propertyPolyfills); -} +// function overrideProperty_TrackEntry (): void { +// const prototype = spine.TrackEntry.prototype as any; +// const propertyPolyfills = [ +// ['animation', prototype.getAnimation], +// ['next', prototype.getNext], +// ['mixingFrom', prototype.getMixingFrom], +// ['mixingTo', prototype.getMixingTo], +// ['trackIndex', prototype.getTrackIndex], +// ['loop', prototype.getLoop, prototype.setLoop], +// ['holdPrevious', prototype.getHoldPrevious, prototype.setHoldPrevious], +// ['eventThreshold', prototype.getEventThreshold, prototype.setEventThreshold], +// ['attachmentThreshold', prototype.getAttachmentThreshold, prototype.setAttachmentThreshold], +// ['drawOrderThreshold', prototype.getDrawOrderThreshold, prototype.setDrawOrderThreshold], +// ['animationStart', prototype.getAnimationStart, prototype.setAnimationStart], +// ['animationEnd', prototype.getAnimationEnd, prototype.setAnimationEnd], +// ['animationLast', prototype.getAnimationLast, prototype.setAnimationLast], +// ['delay', prototype.getDelay, prototype.setDelay], +// ['trackTime', prototype.getTrackTime, prototype.setTrackTime], +// ['trackEnd', prototype.getTrackEnd, prototype.setTrackEnd], +// ['timeScale', prototype.getTimeScale, prototype.setTimeScale], +// ['alpha', prototype.getAlpha, prototype.setAlpha], +// ['mixTime', prototype.getMixTime, prototype.setMixTime], +// ['mixDuration', prototype.getMixDuration, prototype.setMixDuration], +// ['mixBlend', prototype.getMixBlend, prototype.setMixBlend], +// ]; +// doPolyfill(prototype, propertyPolyfills); +// } -function overrideProperty_AnimationStateData (): void { - const prototype = spine.AnimationStateData.prototype as any; - const propertyPolyfills = [ - ['defaultMix', prototype.getDefaultMix], - ['skeletonData', prototype.getSkeletonData], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1]); - }); -} +// function overrideProperty_AnimationStateData (): void { +// const prototype = spine.AnimationStateData.prototype as any; +// const propertyPolyfills = [ +// ['defaultMix', prototype.getDefaultMix], +// ['skeletonData', prototype.getSkeletonData], +// ]; +// propertyPolyfills.forEach((prop): void => { +// js.getset(prototype, prop[0], prop[1]); +// }); +// } function overrideProperty_AnimationState (): void { const prototype = spine.AnimationState.prototype as any; @@ -704,27 +704,27 @@ function overrideProperty_AnimationState (): void { function overrideProperty_Animation (): void { const prototype = spine.Animation.prototype as any; - const propertyPolyfills = [ - ['name', prototype.getName], - ['duration', prototype.getDuration, prototype.setDuration], - ]; - doPolyfill(prototype, propertyPolyfills); + // const propertyPolyfills = [ + // ['name', prototype.getName], + // ['duration', prototype.getDuration, prototype.setDuration], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getTimelines, 'timelines'); } function overrideProperty_Skeleton (): void { const prototype = spine.Skeleton.prototype as any; - const propertyPolyfills = [ - ['data', prototype.getData], - ['skin', prototype.getSkin], - ['color', prototype.getColor], - ['time', prototype.getTime], - ['scaleX', prototype.getScaleX, prototype.setScaleX], - ['scaleY', prototype.getScaleY, prototype.setScaleY], - ['x', prototype.getX, prototype.setX], - ['y', prototype.getY, prototype.setY], - ]; - doPolyfill(prototype, propertyPolyfills); + // const propertyPolyfills = [ + // ['data', prototype.getData], + // ['skin', prototype.getSkin], + // ['color', prototype.getColor], + // ['time', prototype.getTime], + // ['scaleX', prototype.getScaleX, prototype.setScaleX], + // ['scaleY', prototype.getScaleY, prototype.setScaleY], + // ['x', prototype.getX, prototype.setX], + // ['y', prototype.getY, prototype.setY], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getSlots, 'slots'); @@ -735,29 +735,29 @@ function overrideProperty_Skeleton (): void { overrideDefineArrayProp(prototype, prototype.getUpdateCacheList, '_updateCache'); } -function overrideProperty_JitterEffect (): void { - const prototype = spine.JitterEffect.prototype as any; - const propertyPolyfills = [ - ['jitterX', prototype.getJitterX, prototype.setJitterX], - ['jitterY', prototype.getJitterY, prototype.setJitterY], - ]; - propertyPolyfills.forEach((prop) => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} +// function overrideProperty_JitterEffect (): void { +// const prototype = spine.JitterEffect.prototype as any; +// const propertyPolyfills = [ +// ['jitterX', prototype.getJitterX, prototype.setJitterX], +// ['jitterY', prototype.getJitterY, prototype.setJitterY], +// ]; +// propertyPolyfills.forEach((prop) => { +// js.getset(prototype, prop[0], prop[1], prop[2]); +// }); +// } -function overrideProperty_SwirlEffect (): void { - const prototype = spine.SwirlEffect.prototype as any; - const propertyPolyfills = [ - ['centerX', prototype.getCenterX, prototype.setCenterX], - ['centerY', prototype.getCenterY, prototype.setCenterY], - ['radius', prototype.getRadius, prototype.setRadius], - ['angle', prototype.getAngle, prototype.setAngle], - ]; - propertyPolyfills.forEach((prop) => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} +// function overrideProperty_SwirlEffect (): void { +// const prototype = spine.SwirlEffect.prototype as any; +// const propertyPolyfills = [ +// ['centerX', prototype.getCenterX, prototype.setCenterX], +// ['centerY', prototype.getCenterY, prototype.setCenterY], +// ['radius', prototype.getRadius, prototype.setRadius], +// ['angle', prototype.getAngle, prototype.setAngle], +// ]; +// propertyPolyfills.forEach((prop) => { +// js.getset(prototype, prop[0], prop[1], prop[2]); +// }); +// } export function overrideSpineDefine (wasm): void { overrideClass(wasm); @@ -776,7 +776,7 @@ export function overrideSpineDefine (wasm): void { overrideProperty_RegionAttachment(); overrideProperty_VertexAttachment(); overrideProperty_TextureAtlas(); - overrideProperty_SlotData(); + // overrideProperty_SlotData(); overrideProperty_IkConstraint(); overrideProperty_PathConstraint(); overrideProperty_TransformConstraintData(); @@ -786,20 +786,20 @@ export function overrideSpineDefine (wasm): void { overrideProperty_Skin(); // overrideProperty_Attachment(); overrideProperty_SkinEntry(); - overrideProperty_SkeletonClipping(); + // overrideProperty_SkeletonClipping(); overrideProperty_SkeletonData(); overrideProperty_RotateTimeline(); overrideProperty_ColorTimeline(); - overrideProperty_TwoColorTimeline(); + // overrideProperty_TwoColorTimeline(); overrideProperty_AttachmentTimeline(); overrideProperty_DeformTimeline(); overrideProperty_EventTimeline(); overrideProperty_DrawOrderTimeline(); - overrideProperty_TrackEntry(); - overrideProperty_AnimationStateData(); + // overrideProperty_TrackEntry(); + // overrideProperty_AnimationStateData(); overrideProperty_AnimationState(); overrideProperty_Animation(); overrideProperty_Skeleton(); - overrideProperty_JitterEffect(); - overrideProperty_SwirlEffect(); + // overrideProperty_JitterEffect(); + // overrideProperty_SwirlEffect(); } diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 9f68ffef710..b17ae1595fc 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -155,12 +155,19 @@ DEFINE_SPINE_CLASS_TYPEID(SwirlVertexEffect) DEFINE_ALLOW_RAW_POINTER(BoneData) DEFINE_ALLOW_RAW_POINTER(Bone) +DEFINE_ALLOW_RAW_POINTER(Slot) DEFINE_ALLOW_RAW_POINTER(SlotData) DEFINE_ALLOW_RAW_POINTER(VertexAttachment) DEFINE_ALLOW_RAW_POINTER(Color) DEFINE_ALLOW_RAW_POINTER(EventData) DEFINE_ALLOW_RAW_POINTER(Skeleton) +DEFINE_ALLOW_RAW_POINTER(SkeletonData) DEFINE_ALLOW_RAW_POINTER(Skin) +DEFINE_ALLOW_RAW_POINTER(Animation) +DEFINE_ALLOW_RAW_POINTER(TrackEntry) +DEFINE_ALLOW_RAW_POINTER(IkConstraintData) +DEFINE_ALLOW_RAW_POINTER(PathConstraintData) +DEFINE_ALLOW_RAW_POINTER(TransformConstraintData) namespace { // std::string STRING_SP2STD(const spine::String &str) { @@ -473,6 +480,13 @@ class TestBar { _foo = &foo; } + Vector getNames() { + Vector ret; + ret.add(String("你好")); + ret.add(String("World")); + return ret; + } + private: const TestFoo *_foo = new TestFoo(); }; @@ -498,11 +512,13 @@ EMSCRIPTEN_BINDINGS(spine) { class_("TestBar") .constructor() - // .property("foo", &TestBar::getFoo, &TestBar::setFoo) - // .property("base", &TestBar::getBase) - // .function("getBase", &TestBar::getBase, allow_raw_pointers()) + .property("foo", &TestBar::getFoo, &TestBar::setFoo) + .property("base", &TestBar::getBase) + .function("getBase", &TestBar::getBase, allow_raw_pointers()) .function("getFooConst", &TestBar::getFooConst, allow_raw_pointers()) .function("setFooConst", &TestBar::setFooConst, allow_raw_pointers()) + .function("getNames", &TestBar::getNames) + .property("names", &TestBar::getNames) ; #endif // ENABLE_EMBIND_TEST @@ -750,7 +766,7 @@ EMSCRIPTEN_BINDINGS(spine) { .property("height", &RegionAttachment::getHeight, &RegionAttachment::setHeight) .property("color", GETTER_RVAL_TO_PTR(RegionAttachment, getColor, Color*)) .property("path", &RegionAttachment::getPath, &RegionAttachment::setPath) - //cjh .function("getRendererObject", &RegionAttachment::getRendererObject, allow_raw_pointers()) + //FIXME(cjh): .function("getRendererObject", &RegionAttachment::getRendererObject, allow_raw_pointers()) .function("getOffset", optional_override([](RegionAttachment &obj) { return &obj.getOffset(); }), allow_raw_pointer()) .function("setUVs", &RegionAttachment::setUVs) @@ -818,16 +834,12 @@ EMSCRIPTEN_BINDINGS(spine) { class_("SlotData") .constructor() - .function("getIndex", &SlotData::getIndex) - .function("getName", &SlotData::getName) - .function("getBoneData", optional_override([](SlotData &obj) { - return &obj.getBoneData(); }), allow_raw_pointers()) - .function("getColor", optional_override([](SlotData &obj) { - return &obj.getColor();}), allow_raw_pointers()) - .function("getDarkColor", optional_override([](SlotData &obj) { - return &obj.getDarkColor();}), allow_raw_pointers()) - .function("getBlendMode", &SlotData::getBlendMode) - .function("setBlendMode", &SlotData::setBlendMode); + .property("index", &SlotData::getIndex) + .property("name", &SlotData::getName) + .property("boneData", GETTER_RVAL_TO_PTR(SlotData, getBoneData, BoneData*)) + .property("color", GETTER_RVAL_TO_PTR(SlotData, getColor, Color*)) + .property("darkColor", GETTER_RVAL_TO_PTR(SlotData, getDarkColor, Color*)) + .property("blendMode", &SlotData::getBlendMode, &SlotData::setBlendMode); class_("Updatable") .function("update", &Updatable::update, pure_virtual()) @@ -835,23 +847,16 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("IkConstraint") .constructor() - .function("getData", &IkConstraint::getData, allow_raw_pointers()) + .property("data", GETTER_RVAL_TO_PTR(IkConstraint, getData, IkConstraintData*)) .function("getBones", optional_override([](IkConstraint &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .function("getTarget", &IkConstraint::getTarget, allow_raw_pointer()) - .function("setTarget", &IkConstraint::setTarget, allow_raw_pointer()) - .function("getBendDirection", &IkConstraint::getBendDirection) - .function("setBendDirection", &IkConstraint::setBendDirection) - .function("getCompress", &IkConstraint::getCompress) - .function("setCompress", &IkConstraint::setCompress) - .function("getStretch", &IkConstraint::getStretch) - .function("setStretch", &IkConstraint::setStretch) - .function("getMix", &IkConstraint::getMix) - .function("setMix", &IkConstraint::setMix) - .function("getSoftness", &IkConstraint::getSoftness) - .function("setSoftness", &IkConstraint::setSoftness) - .function("getActive", &IkConstraint::isActive) - .function("setActive", &IkConstraint::setActive) + .property("target", &IkConstraint::getTarget, &IkConstraint::setTarget) + .property("bendDirection", &IkConstraint::getBendDirection, &IkConstraint::setBendDirection) + .property("compress", &IkConstraint::getCompress, &IkConstraint::setCompress) + .property("stretch", &IkConstraint::getStretch, &IkConstraint::setStretch) + .property("mix", &IkConstraint::getMix, &IkConstraint::setMix) + .property("softness", &IkConstraint::getSoftness, &IkConstraint::setSoftness) + .property("active", &IkConstraint::isActive, &IkConstraint::setActive) .function("isActive", &IkConstraint::isActive) .function("update", &IkConstraint::update) .class_function("apply1", optional_override([]( @@ -867,58 +872,47 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("PathConstraint") .constructor() - .function("getData", &PathConstraint::getData, allow_raw_pointers()) + .property("data", GETTER_RVAL_TO_PTR(PathConstraint, getData, PathConstraintData*)) .function("getBones", optional_override([](PathConstraint &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .function("getTarget", &PathConstraint::getTarget, allow_raw_pointer()) - .function("setTarget", &PathConstraint::setTarget, allow_raw_pointer()) - .function("getPosition", &PathConstraint::getPosition) - .function("setPosition", &PathConstraint::setPosition) - .function("getSpacing", &PathConstraint::getSpacing) - .function("setSpacing", &PathConstraint::setSpacing) - .function("getRotateMix", &PathConstraint::getRotateMix) - .function("setRotateMix", &PathConstraint::setRotateMix) - .function("getTranslateMix", &PathConstraint::getTranslateMix) - .function("getTranslateMix", &PathConstraint::setTranslateMix) - .function("getActive", &PathConstraint::isActive) + .property("target", &PathConstraint::getTarget, &PathConstraint::setTarget) + .property("position", &PathConstraint::getPosition, &PathConstraint::setPosition) + .property("spacing", &PathConstraint::getSpacing, &PathConstraint::setSpacing) + .property("rotateMix", &PathConstraint::getRotateMix, &PathConstraint::setRotateMix) + .property("translateMix", &PathConstraint::getTranslateMix, &PathConstraint::setTranslateMix) + .property("active", &PathConstraint::isActive, &PathConstraint::setActive) .function("isActive", &PathConstraint::isActive) - .function("setActive", &PathConstraint::setActive) .function("update", &PathConstraint::update); class_>("TransformConstraintData") .constructor() .function("getBones", optional_override([](TransformConstraintData &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .function("getTarget", &TransformConstraintData::getTarget, allow_raw_pointers()) - .function("getRotateMix", &TransformConstraintData::getRotateMix) - .function("getTranslateMix", &TransformConstraintData::getTranslateMix) - .function("getScaleMix", &TransformConstraintData::getScaleMix) - .function("getShearMix", &TransformConstraintData::getShearMix) - .function("getOffsetRotation", &TransformConstraintData::getOffsetRotation) - .function("getOffsetX", &TransformConstraintData::getOffsetX) - .function("getOffsetY", &TransformConstraintData::getOffsetY) - .function("getOffsetScaleX", &TransformConstraintData::getOffsetScaleX) - .function("getOffsetScaleY", &TransformConstraintData::getOffsetScaleY) - .function("getOffsetShearY", &TransformConstraintData::getOffsetShearY) - .function("getRelative", &TransformConstraintData::isRelative) - .function("getLocal", &TransformConstraintData::isLocal); + .property("target", &TransformConstraintData::getTarget) + .property("rotateMix", &TransformConstraintData::getRotateMix) + .property("translateMix", &TransformConstraintData::getTranslateMix) + .property("scaleMix", &TransformConstraintData::getScaleMix) + .property("shearMix", &TransformConstraintData::getShearMix) + .property("offsetRotation", &TransformConstraintData::getOffsetRotation) + .property("offsetX", &TransformConstraintData::getOffsetX) + .property("offsetY", &TransformConstraintData::getOffsetY) + .property("offsetScaleX", &TransformConstraintData::getOffsetScaleX) + .property("offsetScaleY", &TransformConstraintData::getOffsetScaleY) + .property("offsetShearY", &TransformConstraintData::getOffsetShearY) + .property("relative", &TransformConstraintData::isRelative) + .property("local", &TransformConstraintData::isLocal); class_>("TransformConstraint") .constructor() - .function("getData", &TransformConstraint::getData, allow_raw_pointers()) + .property("data", GETTER_RVAL_TO_PTR(TransformConstraint, getData, TransformConstraintData*)) .function("getBones", optional_override([](TransformConstraint &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .function("getTarget", &TransformConstraint::getTarget, allow_raw_pointers()) - .function("getRotateMix", &TransformConstraint::getRotateMix) - .function("setRotateMix", &TransformConstraint::setRotateMix) - .function("getTranslateMix", &TransformConstraint::getTranslateMix) - .function("setTranslateMix", &TransformConstraint::setTranslateMix) - .function("getScaleMix", &TransformConstraint::getScaleMix) - .function("setScaleMix", &TransformConstraint::setScaleMix) - .function("getShearMix", &TransformConstraint::getShearMix) - .function("setShearMix", &TransformConstraint::setShearMix) - .function("getActive", &TransformConstraint::isActive) - .function("setActive", &TransformConstraint::setActive) + .property("target", &TransformConstraint::getTarget) + .property("rotateMix", &TransformConstraint::getRotateMix, &TransformConstraint::setRotateMix) + .property("translateMix", &TransformConstraint::getTranslateMix, &TransformConstraint::setTranslateMix) + .property("scaleMix", &TransformConstraint::getScaleMix, &TransformConstraint::setScaleMix) + .property("shearMix", &TransformConstraint::getShearMix, &TransformConstraint::setShearMix) + .property("active", &TransformConstraint::isActive, &TransformConstraint::setActive) .function("isActive", &TransformConstraint::isActive) .function("update", &TransformConstraint::update); @@ -1015,7 +1009,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Skin") .constructor() - .function("getName", &Skin::getName) + .property("name", &Skin::getName) .function("getBones", optional_override([](Skin &obj) { return &obj.getBones(); }), allow_raw_pointer()) .function("getConstraints", optional_override([](Skin &obj) { @@ -1061,9 +1055,9 @@ EMSCRIPTEN_BINDINGS(spine) { class_("SkeletonClipping") .constructor<>() - .function("getClippedVertices", &SkeletonClipping::getClippedVertices) - .function("getClippedTriangles", &SkeletonClipping::getClippedTriangles) - .function("getClippedUVs", &SkeletonClipping::getClippedUVs) + .property("clippedVertices", &SkeletonClipping::getClippedVertices) + .property("clippedTriangles", &SkeletonClipping::getClippedTriangles) + .property("clippedUVs", &SkeletonClipping::getClippedUVs) .function("clipStart", &SkeletonClipping::clipStart, allow_raw_pointers()) .function("clipEndWithSlot", select_overload(&SkeletonClipping::clipEnd)) .function("clipEnd", select_overload(&SkeletonClipping::clipEnd)) @@ -1113,12 +1107,11 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Animation") .constructor &, float>() - .function("getName", &Animation::getName) + .property("name", &Animation::getName) .function("getTimelines", optional_override([](Animation &obj) { return &obj.getTimelines(); }), allow_raw_pointer()) .function("hasTimeline", &Animation::hasTimeline) - .function("getDuration", &Animation::getDuration) - .function("setDuration", &Animation::setDuration); + .property("duration", &Animation::getDuration, &Animation::setDuration); class_("Timeline") .function("getPropertyId", &Timeline::getPropertyId, pure_virtual()); @@ -1149,8 +1142,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("RotateTimeline") .constructor() //.class_property("ENTRIES", &RotateTimeline::ENTRIES) not bind - .function("getBoneIndex", &RotateTimeline::getBoneIndex) - .function("setBoneIndex", &RotateTimeline::setBoneIndex) + .property("boneIndex", &RotateTimeline::getBoneIndex, &RotateTimeline::setBoneIndex) .function("getFrames", optional_override([](RotateTimeline &obj) { return &obj.getFrames(); }), allow_raw_pointer()) .function("getPropertyId", &RotateTimeline::getPropertyId) @@ -1159,8 +1151,8 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("ColorTimeline") .constructor() .class_property("ENTRIES", &ColorTimeline::ENTRIES) - .function("getSlotIndex", &ColorTimeline::getSlotIndex) - .function("setSlotIndex", &ColorTimeline::setSlotIndex) + .property("slotIndex", &ColorTimeline::getSlotIndex, &ColorTimeline::setSlotIndex) + .function("getFrames", optional_override([](ColorTimeline &obj) { return &obj.getFrames(); }), allow_raw_pointer()) .function("getPropertyId", &ColorTimeline::getPropertyId) @@ -1169,15 +1161,13 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("TwoColorTimeline") .constructor() .class_property("ENTRIES", &ColorTimeline::ENTRIES) - .function("getSlotIndex", &TwoColorTimeline::getSlotIndex) - .function("setSlotIndex", &TwoColorTimeline::setSlotIndex) + .property("slotIndex", &TwoColorTimeline::getSlotIndex, &TwoColorTimeline::setSlotIndex) .function("getPropertyId", &TwoColorTimeline::getPropertyId) .function("setFrame", &TwoColorTimeline::setFrame); class_>("AttachmentTimeline") .constructor() - .function("getSlotIndex", &AttachmentTimeline::getSlotIndex) - .function("setSlotIndex", &AttachmentTimeline::setSlotIndex) + .property("slotIndex", &AttachmentTimeline::getSlotIndex, &AttachmentTimeline::setSlotIndex) .function("getFrames", optional_override([](AttachmentTimeline &obj) { return &obj.getFrames(); }), allow_raw_pointer()) .function("getAttachmentNames", &AttachmentTimeline::getAttachmentNames) @@ -1187,10 +1177,8 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("DeformTimeline") .constructor() - .function("getSlotIndex", &DeformTimeline::getSlotIndex) - .function("setSlotIndex", &DeformTimeline::setSlotIndex) - .function("getAttachment", &DeformTimeline::getAttachment, allow_raw_pointers()) - .function("setAttachment", &DeformTimeline::setAttachment, allow_raw_pointers()) + .property("slotIndex", &DeformTimeline::getSlotIndex, &DeformTimeline::setSlotIndex) + .property("attachment", &DeformTimeline::getAttachment, &DeformTimeline::setAttachment) .function("getFrames", optional_override([](DeformTimeline &obj) { return &obj.getFrames(); }), allow_raw_pointer()) .function("getFrameVertices", optional_override([](DeformTimeline &obj) { @@ -1251,49 +1239,34 @@ EMSCRIPTEN_BINDINGS(spine) { class_("TrackEntry") .constructor<>() - .function("getAnimation", &TrackEntry::getAnimation, allow_raw_pointer()) - .function("getNext", &TrackEntry::getNext, allow_raw_pointer()) - .function("getMixingFrom", &TrackEntry::getMixingFrom, allow_raw_pointer()) - .function("getMixingTo", &TrackEntry::getMixingTo, allow_raw_pointer()) + .property("animation", &TrackEntry::getAnimation) + .property("next", &TrackEntry::getNext) + .property("mixingFrom", &TrackEntry::getMixingFrom) + .property("mixingTo", &TrackEntry::getMixingTo) //.function("getProp_listener", &TrackEntry::listener) - .function("getTrackIndex", &TrackEntry::getTrackIndex) - .function("getLoop", &TrackEntry::getLoop) - .function("setLoop", &TrackEntry::setLoop) - .function("getHoldPrevious", &TrackEntry::getHoldPrevious) - .function("setHoldPrevious", &TrackEntry::setHoldPrevious) - .function("getEventThreshold", &TrackEntry::getEventThreshold) - .function("setEventThreshold", &TrackEntry::setEventThreshold) - .function("getAttachmentThreshold", &TrackEntry::getAttachmentThreshold) - .function("setAttachmentThreshold", &TrackEntry::setAttachmentThreshold) - .function("getDrawOrderThreshold", &TrackEntry::getDrawOrderThreshold) - .function("setDrawOrderThreshold", &TrackEntry::setDrawOrderThreshold) - .function("getAnimationStart", &TrackEntry::getAnimationStart) - .function("setAnimationStart", &TrackEntry::setAnimationStart) - .function("getAnimationEnd", &TrackEntry::getAnimationEnd) - .function("setAnimationEnd", &TrackEntry::setAnimationEnd) - .function("getAnimationLast", &TrackEntry::getAnimationLast) - .function("setAnimationLast", &TrackEntry::setAnimationLast) + .property("trackIndex", &TrackEntry::getTrackIndex) + .property("loop", &TrackEntry::getLoop, &TrackEntry::setLoop) + .property("holdPrevious", &TrackEntry::getHoldPrevious, &TrackEntry::setHoldPrevious) + .property("eventThreshold", &TrackEntry::getEventThreshold, &TrackEntry::setEventThreshold) + .property("attachmentThreshold", &TrackEntry::getAttachmentThreshold, &TrackEntry::setAttachmentThreshold) + .property("drawOrderThreshold", &TrackEntry::getDrawOrderThreshold, &TrackEntry::setDrawOrderThreshold) + .property("animationStart", &TrackEntry::getAnimationStart, &TrackEntry::setAnimationStart) + .property("animationEnd", &TrackEntry::getAnimationEnd, &TrackEntry::setAnimationEnd) + .property("animationLast", &TrackEntry::getAnimationLast, &TrackEntry::setAnimationLast) //.function("getProp_nextAnimationLast", &TrackEntry::nextAnimationLast) - .function("getDelay", &TrackEntry::getDelay) - .function("setDelay", &TrackEntry::setDelay) - .function("getTrackTime", &TrackEntry::getTrackTime) - .function("setTrackTime", &TrackEntry::setTrackTime) + .property("delay", &TrackEntry::getDelay, &TrackEntry::setDelay) + .property("trackTime", &TrackEntry::getTrackTime, &TrackEntry::setTrackTime) //.function("getProp_trackLast", &TrackEntry::trackLast) //.function("getProp_nextTrackLast", &TrackEntry::nextTrackLast) - .function("getTrackEnd", &TrackEntry::getTrackEnd) - .function("setTrackEnd", &TrackEntry::setTrackEnd) - .function("getTimeScale", &TrackEntry::getTimeScale) - .function("setTimeScale", &TrackEntry::setTimeScale) - .function("getAlpha", &TrackEntry::getAlpha) - .function("setAlpha", &TrackEntry::setAlpha) - .function("getMixTime", &TrackEntry::getMixTime) - .function("setMixTime", &TrackEntry::setMixTime) - .function("getMixDuration", &TrackEntry::getMixDuration) - .function("setMixDuration", &TrackEntry::setMixDuration) + .property("trackEnd", &TrackEntry::getTrackEnd, &TrackEntry::setTrackEnd) + .property("timeScale", &TrackEntry::getTimeScale, &TrackEntry::setTimeScale) + .property("alpha", &TrackEntry::getAlpha, &TrackEntry::setAlpha) + .property("mixTime", &TrackEntry::getMixTime, &TrackEntry::setMixTime) + .property("mixDuration", &TrackEntry::getMixDuration, &TrackEntry::setMixDuration) //.function("getProp_interruptAlpha", &TrackEntry::_interruptAlpha) //.function("getProp_totalAlpha", &TrackEntry::getAlpha) - .function("getMixBlend", &TrackEntry::getMixBlend) - .function("setMixBlend", &TrackEntry::setMixBlend) + .property("mixBlend", &TrackEntry::getMixBlend, &TrackEntry::setMixBlend) + //.function("getProp_timelineMode", &TrackEntry::timelineMode) //.function("getProp_timelineHoldMix", &TrackEntry::timelineHoldMix) //.function("getProp_timelinesRotation", &TrackEntry::timelinesRotation) @@ -1304,9 +1277,8 @@ EMSCRIPTEN_BINDINGS(spine) { class_("AnimationStateData") .constructor() - .function("getDefaultMix", &AnimationStateData::getDefaultMix) - .function("setDefaultMix", &AnimationStateData::setDefaultMix) - .function("getSkeletonData", &AnimationStateData::getSkeletonData, allow_raw_pointers()) + .property("defaultMix", &AnimationStateData::getDefaultMix, &AnimationStateData::setDefaultMix) + .property("skeletonData", &AnimationStateData::getSkeletonData) .function("setMix", select_overload(&AnimationStateData::setMix), allow_raw_pointers()) .function("setMixWith", select_overload(&AnimationStateData::setMix), allow_raw_pointers()) .function("getMix", &AnimationStateData::getMix, allow_raw_pointers()); @@ -1362,7 +1334,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Skeleton") .constructor() - .function("getData", &Skeleton::getData, allow_raw_pointer()) + .property("data", &Skeleton::getData) .function("getBones", optional_override([](Skeleton &obj){ return &obj.getBones(); }), allow_raw_pointer()) .function("getSlots", optional_override([](Skeleton &obj){ @@ -1377,19 +1349,14 @@ EMSCRIPTEN_BINDINGS(spine) { return &obj.getPathConstraints(); }), allow_raw_pointer()) .function("getUpdateCacheList", optional_override([](Skeleton &obj){ return &obj.getUpdateCacheList(); }), allow_raw_pointer()) - .function("getSkin", &Skeleton::getSkin, allow_raw_pointer()) - .function("getColor", optional_override([](Skeleton &obj){ - return &obj.getColor(); }), allow_raw_pointers()) - .function("getTime", &Skeleton::getTime) - .function("setTime", &Skeleton::setTime) - .function("getScaleX", &Skeleton::getScaleX) - .function("setScaleX", &Skeleton::setScaleX) - .function("getScaleY", &Skeleton::getScaleY) - .function("setScaleY", &Skeleton::setScaleY) - .function("getX", &Skeleton::getX) - .function("setX", &Skeleton::setX) - .function("getY", &Skeleton::getY) - .function("setY", &Skeleton::setY) + .property("getSkin", &Skeleton::getSkin) + .property("getColor", GETTER_RVAL_TO_PTR(Skeleton, getColor, Color*)) + .property("time", &Skeleton::getTime, &Skeleton::setTime) + .property("scaleX", &Skeleton::getScaleX, &Skeleton::setScaleX) + .property("scaleY", &Skeleton::getScaleY, &Skeleton::setScaleY) + .property("x", &Skeleton::getX, &Skeleton::setX) + .property("y", &Skeleton::getY, &Skeleton::setY) + .function("updateCache", &Skeleton::updateCache) .function("updateWorldTransform", &Skeleton::updateWorldTransform) .function("setToSetupPose", &Skeleton::setToSetupPose) @@ -1434,10 +1401,8 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("JitterEffect") .constructor() - .function("getJitterX", &JitterVertexEffect::getJitterX) - .function("setJitterX", &JitterVertexEffect::setJitterX) - .function("getJitterY", &JitterVertexEffect::getJitterY) - .function("setJitterY", &JitterVertexEffect::setJitterY) + .property("jitterX", &JitterVertexEffect::getJitterX, &JitterVertexEffect::setJitterX) + .property("jitterY", &JitterVertexEffect::getJitterY, &JitterVertexEffect::setJitterY) .function("begin", &JitterVertexEffect::begin) .function("transform", optional_override([](VertexEffect &obj, float x, float y) { obj.transform(x, y); }), pure_virtual()) @@ -1449,18 +1414,13 @@ EMSCRIPTEN_BINDINGS(spine) { .function("transform", optional_override([](VertexEffect &obj, float x, float y) { obj.transform(x, y); }), pure_virtual()) .function("end", &SwirlVertexEffect::end) - .function("getCenterX", &SwirlVertexEffect::getCenterX) - .function("setCenterX", &SwirlVertexEffect::setCenterX) - .function("getCenterY", &SwirlVertexEffect::getCenterY) - .function("setCenterY", &SwirlVertexEffect::setCenterY) - .function("getRadius", &SwirlVertexEffect::getRadius) - .function("setRadius", &SwirlVertexEffect::setRadius) - .function("getAngle", &SwirlVertexEffect::getAngle) - .function("setAngle", &SwirlVertexEffect::setAngle) - .function("getWorldX", &SwirlVertexEffect::getWorldX) - .function("setWorldX", &SwirlVertexEffect::setWorldX) - .function("getWorldY", &SwirlVertexEffect::getWorldY) - .function("setWorldY", &SwirlVertexEffect::setWorldY); + + .property("centerX", &SwirlVertexEffect::getCenterX, &SwirlVertexEffect::setCenterX) + .property("centerY", &SwirlVertexEffect::getCenterY, &SwirlVertexEffect::setCenterY) + .property("radius", &SwirlVertexEffect::getRadius, &SwirlVertexEffect::setRadius) + .property("angle", &SwirlVertexEffect::getAngle, &SwirlVertexEffect::setAngle) + .property("worldX", &SwirlVertexEffect::getWorldX, &SwirlVertexEffect::setWorldX) + .property("worldY", &SwirlVertexEffect::getWorldY, &SwirlVertexEffect::setWorldY); class_("SpineModel") .property("vCount", &SpineModel::vCount) From 4f8aa6c4f5b4a798517cec19ee8b6b99800aeafd Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 28 Oct 2024 21:34:39 +0800 Subject: [PATCH 21/80] Add ENABLE_JSON_PARSER configuration --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 6 ++++-- native/cocos/editor-support/spine-wasm/spine-wasm.cpp | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index ac276b5a0e1..c826fde4289 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.8) set(CMAKE_VERBOSE_MAKEFILE ON) set(BUILD_WASM 1) +set(ENABLE_JSON_PARSER 1) set(CMAKE_BUILD_TYPE "MinSizeRel") # set(CMAKE_BUILD_TYPE "Debug") @@ -20,13 +21,14 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER}") message(">>> --------------------------------------------------------------") message(">>> Current directory: ${CMAKE_CURRENT_LIST_DIR}") message(">>> CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(">>> ENABLE_CLOSURE_COMPILER: ${ENABLE_CLOSURE_COMPILER}") +message(">>> ENABLE_JSON_PARSER: ${ENABLE_JSON_PARSER}") message(">>> --------------------------------------------------------------") include_directories(${CMAKE_CURRENT_LIST_DIR}/..) diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index 2e8707800f1..b44dc5b0dcf 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -44,6 +44,7 @@ SkeletonData* SpineWasmUtil::querySpineSkeletonDataByUUID(const std::string& uui } SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const std::string& jsonStr, const std::string& altasStr) { +#if ENABLE_JSON_PARSER auto* atlas = new Atlas(altasStr.c_str(), altasStr.size(), "", nullptr, false); if (!atlas) { return nullptr; @@ -54,6 +55,9 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const std::string& SkeletonData* skeletonData = json.readSkeletonData(jsonStr.c_str()); return skeletonData; +#else + return nullptr; +#endif } SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize, const std::string& altasStr) { From 88e1e616f55be75b8bf776bf062e163f3054952b Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 28 Oct 2024 21:54:57 +0800 Subject: [PATCH 22/80] Update --- cocos/spine/lib/spine-define.ts | 76 +++++++++---------- .../editor-support/spine-wasm/CMakeLists.txt | 2 +- .../spine-wasm/spine-type-export.cpp | 6 +- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/cocos/spine/lib/spine-define.ts b/cocos/spine/lib/spine-define.ts index ef243b13a0e..8d17c613b10 100644 --- a/cocos/spine/lib/spine-define.ts +++ b/cocos/spine/lib/spine-define.ts @@ -206,19 +206,19 @@ function overrideProperty_PathConstraintData (): void { overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } -function overrideProperty_Event (): void { - const prototype = spine.Event.prototype as any; - const propertyPolyfills = [ - ['data', prototype.getData], - // ['intValue', prototype.getIntValue, prototype.setIntValue], - // ['floatValue', prototype.getFloatValue, prototype.setFloatValue], - // ['stringValue', prototype.getStringValue, prototype.setStringValue], - // ['time', prototype.getTime], - // ['volume', prototype.getVolume, prototype.setVolume], - // ['balance', prototype.getBalance, prototype.setBalance], - ]; - doPolyfill(prototype, propertyPolyfills); -} +// function overrideProperty_Event (): void { +// const prototype = spine.Event.prototype as any; +// const propertyPolyfills = [ +// ['data', prototype.getData], +// // ['intValue', prototype.getIntValue, prototype.setIntValue], +// // ['floatValue', prototype.getFloatValue, prototype.setFloatValue], +// // ['stringValue', prototype.getStringValue, prototype.setStringValue], +// // ['time', prototype.getTime], +// // ['volume', prototype.getVolume, prototype.setVolume], +// // ['balance', prototype.getBalance, prototype.setBalance], +// ]; +// doPolyfill(prototype, propertyPolyfills); +// } // function overrideProperty_EventData (): void { // const prototype = spine.EventData.prototype as any; @@ -347,24 +347,24 @@ function overrideProperty_RegionAttachment (): void { }); } -function overrideProperty_TextureAtlas (): void { - // const prototype = spine.TextureAtlas.prototype as any; - // const propertyPolyfills = [ - // { - // proto: prototype, - // property: 'pages', - // getter: prototype.getProp_pages, - // }, - // { - // proto: prototype, - // property: 'regions', - // getter: prototype.getProp_regions, - // }, - // ]; - // propertyPolyfills.forEach((prop) => { - // js.getset(prototype, prop[0], prop[1]); - // }); -} +// function overrideProperty_TextureAtlas (): void { +// const prototype = spine.TextureAtlas.prototype as any; +// const propertyPolyfills = [ +// { +// proto: prototype, +// property: 'pages', +// getter: prototype.getProp_pages, +// }, +// { +// proto: prototype, +// property: 'regions', +// getter: prototype.getProp_regions, +// }, +// ]; +// propertyPolyfills.forEach((prop) => { +// js.getset(prototype, prop[0], prop[1]); +// }); +// } // function overrideProperty_SlotData (): void { // const prototype = spine.SlotData.prototype as any; @@ -693,11 +693,11 @@ function overrideProperty_DrawOrderTimeline (): void { function overrideProperty_AnimationState (): void { const prototype = spine.AnimationState.prototype as any; - const propertyPolyfills = [ - ['data', prototype.getData], - ['timeScale', prototype.getTimeScale, prototype.setTimeScale], - ]; - doPolyfill(prototype, propertyPolyfills); + // const propertyPolyfills = [ + // ['data', prototype.getData], + // ['timeScale', prototype.getTimeScale, prototype.setTimeScale], + // ]; + // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getTracks, 'tracks'); } @@ -766,7 +766,7 @@ export function overrideSpineDefine (wasm): void { // overrideProperty_ConstraintData(); overrideProperty_IkConstraintData(); overrideProperty_PathConstraintData(); - overrideProperty_Event(); + // overrideProperty_Event(); // overrideProperty_EventData(); // overrideProperty_BoundingBoxAttachment(); // overrideProperty_ClippingAttachment(); @@ -775,7 +775,7 @@ export function overrideSpineDefine (wasm): void { // overrideProperty_PointAttachment(); overrideProperty_RegionAttachment(); overrideProperty_VertexAttachment(); - overrideProperty_TextureAtlas(); + // overrideProperty_TextureAtlas(); // overrideProperty_SlotData(); overrideProperty_IkConstraint(); overrideProperty_PathConstraint(); diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index c826fde4289..d5725b61187 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.8) set(CMAKE_VERBOSE_MAKEFILE ON) set(BUILD_WASM 1) -set(ENABLE_JSON_PARSER 1) +set(ENABLE_JSON_PARSER 0) set(CMAKE_BUILD_TYPE "MinSizeRel") # set(CMAKE_BUILD_TYPE "Debug") diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index b17ae1595fc..7b1e6c19a8e 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -164,6 +164,7 @@ DEFINE_ALLOW_RAW_POINTER(Skeleton) DEFINE_ALLOW_RAW_POINTER(SkeletonData) DEFINE_ALLOW_RAW_POINTER(Skin) DEFINE_ALLOW_RAW_POINTER(Animation) +DEFINE_ALLOW_RAW_POINTER(AnimationStateData) DEFINE_ALLOW_RAW_POINTER(TrackEntry) DEFINE_ALLOW_RAW_POINTER(IkConstraintData) DEFINE_ALLOW_RAW_POINTER(PathConstraintData) @@ -1285,11 +1286,10 @@ EMSCRIPTEN_BINDINGS(spine) { class_("AnimationState") .constructor() - .function("getData", &AnimationState::getData, allow_raw_pointers()) + .property("data", &AnimationState::getData) .function("getTracks", optional_override([](AnimationState &obj) { return &obj.getTracks(); }), allow_raw_pointer()) - .function("getTimeScale", &AnimationState::getTimeScale) - .function("setTimeScale", &AnimationState::setTimeScale) + .property("timeScale", &AnimationState::getTimeScale, &AnimationState::setTimeScale) .function("update", &AnimationState::update) .function("apply", &AnimationState::apply) .function("clearTracks", &AnimationState::clearTracks) From 6fd4e42c761d9449d379437cfd3585d9898beecf Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 28 Oct 2024 22:31:04 +0800 Subject: [PATCH 23/80] Update --- .../editor-support/spine-wasm/CMakeLists.txt | 4 +- .../editor-support/spine/AnimationState.cpp | 2 +- native/cocos/editor-support/spine/Atlas.cpp | 16 ++--- .../spine/AtlasAttachmentLoader.cpp | 12 ++-- .../spine/BoundingBoxAttachment.cpp | 2 +- .../spine/ClippingAttachment.cpp | 2 +- .../cocos/editor-support/spine/Extension.cpp | 2 +- native/cocos/editor-support/spine/HashMap.h | 2 +- native/cocos/editor-support/spine/Json.cpp | 9 ++- native/cocos/editor-support/spine/Json.h | 4 ++ .../editor-support/spine/MeshAttachment.cpp | 4 +- .../editor-support/spine/PathAttachment.cpp | 2 +- .../editor-support/spine/PointAttachment.cpp | 2 +- native/cocos/editor-support/spine/Pool.h | 2 +- .../editor-support/spine/RegionAttachment.cpp | 2 +- .../cocos/editor-support/spine/Skeleton.cpp | 12 ++-- .../editor-support/spine/SkeletonBinary.cpp | 64 +++++++++---------- .../editor-support/spine/SkeletonBounds.cpp | 2 +- .../editor-support/spine/SkeletonData.cpp | 2 +- .../editor-support/spine/SkeletonJson.cpp | 60 +++++++++-------- .../cocos/editor-support/spine/SkeletonJson.h | 4 ++ .../editor-support/spine/SpineObject.cpp | 6 +- .../cocos/editor-support/spine/SpineObject.h | 10 +++ .../editor-support/spine/SpineString.cpp | 22 +++---- native/cocos/editor-support/spine/Vector.h | 10 +-- 25 files changed, 143 insertions(+), 116 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index d5725b61187..53b1ee84cf8 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -4,6 +4,7 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(BUILD_WASM 1) set(ENABLE_JSON_PARSER 0) +set(DEBUG_NEW 0) set(CMAKE_BUILD_TYPE "MinSizeRel") # set(CMAKE_BUILD_TYPE "Debug") @@ -22,13 +23,14 @@ set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DDEBUG_NEW=${DEBUG_NEW}") message(">>> --------------------------------------------------------------") message(">>> Current directory: ${CMAKE_CURRENT_LIST_DIR}") message(">>> CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(">>> ENABLE_CLOSURE_COMPILER: ${ENABLE_CLOSURE_COMPILER}") message(">>> ENABLE_JSON_PARSER: ${ENABLE_JSON_PARSER}") +message(">>> DEBUG_NEW: ${DEBUG_NEW}") message(">>> --------------------------------------------------------------") include_directories(${CMAKE_CURRENT_LIST_DIR}/..) diff --git a/native/cocos/editor-support/spine/AnimationState.cpp b/native/cocos/editor-support/spine/AnimationState.cpp index b0894424cb2..873fcbc1603 100644 --- a/native/cocos/editor-support/spine/AnimationState.cpp +++ b/native/cocos/editor-support/spine/AnimationState.cpp @@ -187,7 +187,7 @@ EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Ev } EventQueue *EventQueue::newEventQueue(AnimationState &state, Pool &trackEntryPool) { - return new (__FILE__, __LINE__) EventQueue(state, trackEntryPool); + return spine_new EventQueue(state, trackEntryPool); } EventQueueEntry EventQueue::newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event) { diff --git a/native/cocos/editor-support/spine/Atlas.cpp b/native/cocos/editor-support/spine/Atlas.cpp index f26fc1d74d6..b2927fe856a 100644 --- a/native/cocos/editor-support/spine/Atlas.cpp +++ b/native/cocos/editor-support/spine/Atlas.cpp @@ -51,7 +51,7 @@ Atlas::Atlas(const String &path, TextureLoader *textureLoader, bool createTextur const char *lastSlash = lastForwardSlash > lastBackwardSlash ? lastForwardSlash : lastBackwardSlash; if (lastSlash == path) lastSlash++; /* Never drop starting slash. */ dirLength = (int)(lastSlash ? lastSlash - path.buffer() : 0); - dir = SpineExtension::calloc(dirLength + 1, __FILE__, __LINE__); + dir = SpineExtension::calloc(dirLength + 1, __SPINE_FILE__, __SPINE_LINE__); memcpy(dir, path.buffer(), dirLength); dir[dirLength] = '\0'; @@ -60,8 +60,8 @@ Atlas::Atlas(const String &path, TextureLoader *textureLoader, bool createTextur load(data, length, dir, createTexture); } - SpineExtension::free(data, __FILE__, __LINE__); - SpineExtension::free(dir, __FILE__, __LINE__); + SpineExtension::free(data, __SPINE_FILE__, __SPINE_LINE__); + SpineExtension::free(dir, __SPINE_FILE__, __SPINE_LINE__); } Atlas::Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader, bool createTexture) : _textureLoader( @@ -117,12 +117,12 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText page = 0; } else if (!page) { char *name = mallocString(&str); - char *path = SpineExtension::calloc(dirLength + needsSlash + strlen(name) + 1, __FILE__, __LINE__); + char *path = SpineExtension::calloc(dirLength + needsSlash + strlen(name) + 1, __SPINE_FILE__, __SPINE_LINE__); memcpy(path, dir, dirLength); if (needsSlash) path[dirLength] = '/'; strcpy(path + dirLength + needsSlash, name); - page = new (__FILE__, __LINE__) AtlasPage(String(name, true)); + page = spine_new AtlasPage(String(name, true)); int tupleVal = readTuple(&begin, end, tuple); assert(tupleVal == 2); @@ -157,13 +157,13 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText if (createTexture) { if (_textureLoader) _textureLoader->load(*page, String(path)); - SpineExtension::free(path, __FILE__, __LINE__); + SpineExtension::free(path, __SPINE_FILE__, __SPINE_LINE__); } else page->texturePath = String(path, true); _pages.add(page); } else { - AtlasRegion *region = new (__FILE__, __LINE__) AtlasRegion(); + AtlasRegion *region = spine_new AtlasRegion(); region->page = page; region->name = String(mallocString(&str), true); @@ -309,7 +309,7 @@ int Atlas::readTuple(const char **begin, const char *end, Str tuple[]) { char *Atlas::mallocString(Str *str) { int length = (int)(str->end - str->begin); - char *string = SpineExtension::calloc(length + 1, __FILE__, __LINE__); + char *string = SpineExtension::calloc(length + 1, __SPINE_FILE__, __SPINE_LINE__); memcpy(string, str->begin, length); string[length] = '\0'; return string; diff --git a/native/cocos/editor-support/spine/AtlasAttachmentLoader.cpp b/native/cocos/editor-support/spine/AtlasAttachmentLoader.cpp index 68ee7d38d5c..b236c5825ed 100644 --- a/native/cocos/editor-support/spine/AtlasAttachmentLoader.cpp +++ b/native/cocos/editor-support/spine/AtlasAttachmentLoader.cpp @@ -56,7 +56,7 @@ RegionAttachment *AtlasAttachmentLoader::newRegionAttachment(Skin &skin, const S AtlasRegion ®ion = *regionP; - RegionAttachment *attachmentP = new (__FILE__, __LINE__) RegionAttachment(name); + RegionAttachment *attachmentP = spine_new RegionAttachment(name); RegionAttachment &attachment = *attachmentP; attachment.setRendererObject(regionP); @@ -78,7 +78,7 @@ MeshAttachment *AtlasAttachmentLoader::newMeshAttachment(Skin &skin, const Strin AtlasRegion ®ion = *regionP; - MeshAttachment *attachmentP = new (__FILE__, __LINE__) MeshAttachment(name); + MeshAttachment *attachmentP = spine_new MeshAttachment(name); MeshAttachment &attachment = *attachmentP; attachment.setRendererObject(regionP); @@ -100,22 +100,22 @@ MeshAttachment *AtlasAttachmentLoader::newMeshAttachment(Skin &skin, const Strin BoundingBoxAttachment *AtlasAttachmentLoader::newBoundingBoxAttachment(Skin &skin, const String &name) { SP_UNUSED(skin); - return new (__FILE__, __LINE__) BoundingBoxAttachment(name); + return spine_new BoundingBoxAttachment(name); } PathAttachment *AtlasAttachmentLoader::newPathAttachment(Skin &skin, const String &name) { SP_UNUSED(skin); - return new (__FILE__, __LINE__) PathAttachment(name); + return spine_new PathAttachment(name); } PointAttachment *AtlasAttachmentLoader::newPointAttachment(Skin &skin, const String &name) { SP_UNUSED(skin); - return new (__FILE__, __LINE__) PointAttachment(name); + return spine_new PointAttachment(name); } ClippingAttachment *AtlasAttachmentLoader::newClippingAttachment(Skin &skin, const String &name) { SP_UNUSED(skin); - return new (__FILE__, __LINE__) ClippingAttachment(name); + return spine_new ClippingAttachment(name); } void AtlasAttachmentLoader::configureAttachment(Attachment *attachment) { diff --git a/native/cocos/editor-support/spine/BoundingBoxAttachment.cpp b/native/cocos/editor-support/spine/BoundingBoxAttachment.cpp index 1ff2e5f94dd..f3d66157fe1 100644 --- a/native/cocos/editor-support/spine/BoundingBoxAttachment.cpp +++ b/native/cocos/editor-support/spine/BoundingBoxAttachment.cpp @@ -41,7 +41,7 @@ BoundingBoxAttachment::BoundingBoxAttachment(const String& name) : VertexAttachm } Attachment* BoundingBoxAttachment::copy() { - BoundingBoxAttachment* copy = new (__FILE__, __LINE__) BoundingBoxAttachment(getName()); + BoundingBoxAttachment* copy = spine_new BoundingBoxAttachment(getName()); copyTo(copy); return copy; } diff --git a/native/cocos/editor-support/spine/ClippingAttachment.cpp b/native/cocos/editor-support/spine/ClippingAttachment.cpp index e8ff0422fa5..6f3a2743638 100644 --- a/native/cocos/editor-support/spine/ClippingAttachment.cpp +++ b/native/cocos/editor-support/spine/ClippingAttachment.cpp @@ -51,7 +51,7 @@ void ClippingAttachment::setEndSlot(SlotData *inValue) { } Attachment *ClippingAttachment::copy() { - ClippingAttachment *copy = new (__FILE__, __LINE__) ClippingAttachment(getName()); + ClippingAttachment *copy = spine_new ClippingAttachment(getName()); copyTo(copy); copy->_endSlot = _endSlot; return copy; diff --git a/native/cocos/editor-support/spine/Extension.cpp b/native/cocos/editor-support/spine/Extension.cpp index 000e69e63ec..e730b065f9b 100644 --- a/native/cocos/editor-support/spine/Extension.cpp +++ b/native/cocos/editor-support/spine/Extension.cpp @@ -116,7 +116,7 @@ char *DefaultSpineExtension::_readFile(const String &path, int *length) { *length = (int)ftell(file); fseek(file, 0, SEEK_SET); - data = SpineExtension::alloc(*length, __FILE__, __LINE__); + data = SpineExtension::alloc(*length, __SPINE_FILE__, __SPINE_LINE__); fread(data, 1, *length, file); fclose(file); diff --git a/native/cocos/editor-support/spine/HashMap.h b/native/cocos/editor-support/spine/HashMap.h index d7e14cf6d64..115911751e0 100644 --- a/native/cocos/editor-support/spine/HashMap.h +++ b/native/cocos/editor-support/spine/HashMap.h @@ -111,7 +111,7 @@ class SP_API HashMap : public SpineObject { entry->_key = key; entry->_value = value; } else { - entry = new (__FILE__, __LINE__) Entry(); + entry = spine_new Entry(); entry->_key = key; entry->_value = value; diff --git a/native/cocos/editor-support/spine/Json.cpp b/native/cocos/editor-support/spine/Json.cpp index 0c50d0f58cb..5fb81c4afc6 100644 --- a/native/cocos/editor-support/spine/Json.cpp +++ b/native/cocos/editor-support/spine/Json.cpp @@ -20,6 +20,7 @@ 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. */ +#if 1//ENABLE_JSON_PARSER #ifdef SPINE_UE4 #include "SpinePluginPrivatePCH.h" @@ -132,11 +133,11 @@ Json::~Json() { } while (next); if (_valueString) { - SpineExtension::free(_valueString, __FILE__, __LINE__); + SpineExtension::free(_valueString, __SPINE_FILE__, __SPINE_LINE__); } if (_name) { - SpineExtension::free(_name, __FILE__, __LINE__); + SpineExtension::free(_name, __SPINE_FILE__, __SPINE_LINE__); } } @@ -233,7 +234,7 @@ const char *Json::parseString(Json *item, const char *str) { } } - out = SpineExtension::alloc(len + 1, __FILE__, __LINE__); /* The length needed for the string, roughly. */ + out = SpineExtension::alloc(len + 1, __SPINE_FILE__, __SPINE_LINE__); /* The length needed for the string, roughly. */ if (!out) { return 0; } @@ -554,3 +555,5 @@ int Json::json_strcasecmp(const char *s1, const char *s2) { } } } + +#endif // ENABLE_JSON_PARSER diff --git a/native/cocos/editor-support/spine/Json.h b/native/cocos/editor-support/spine/Json.h index 478d84b43b3..48d44930a2b 100644 --- a/native/cocos/editor-support/spine/Json.h +++ b/native/cocos/editor-support/spine/Json.h @@ -30,6 +30,8 @@ #ifndef Spine_Json_h #define Spine_Json_h +#if 1//ENABLE_JSON_PARSER + #include #ifndef SPINE_JSON_HAVE_PREV @@ -110,4 +112,6 @@ class SP_API Json { }; } // namespace spine +#endif // ENABLE_JSON_PARSER + #endif /* Spine_Json_h */ diff --git a/native/cocos/editor-support/spine/MeshAttachment.cpp b/native/cocos/editor-support/spine/MeshAttachment.cpp index 9e73ede98aa..a8ba686e1c2 100644 --- a/native/cocos/editor-support/spine/MeshAttachment.cpp +++ b/native/cocos/editor-support/spine/MeshAttachment.cpp @@ -276,7 +276,7 @@ spine::Color &MeshAttachment::getColor() { Attachment *MeshAttachment::copy() { if (_parentMesh) return newLinkedMesh(); - MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); + MeshAttachment *copy = spine_new MeshAttachment(getName()); copy->setRendererObject(getRendererObject()); copy->_regionU = _regionU; copy->_regionV = _regionV; @@ -307,7 +307,7 @@ Attachment *MeshAttachment::copy() { } MeshAttachment *MeshAttachment::newLinkedMesh() { - MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); + MeshAttachment *copy = spine_new MeshAttachment(getName()); copy->setRendererObject(getRendererObject()); copy->_regionU = _regionU; copy->_regionV = _regionV; diff --git a/native/cocos/editor-support/spine/PathAttachment.cpp b/native/cocos/editor-support/spine/PathAttachment.cpp index 3bdc71945a1..161ce94c9be 100644 --- a/native/cocos/editor-support/spine/PathAttachment.cpp +++ b/native/cocos/editor-support/spine/PathAttachment.cpp @@ -61,7 +61,7 @@ void PathAttachment::setConstantSpeed(bool inValue) { } Attachment* PathAttachment::copy() { - PathAttachment* copy = new (__FILE__, __LINE__) PathAttachment(getName()); + PathAttachment* copy = spine_new PathAttachment(getName()); copyTo(copy); copy->_lengths.clearAndAddAll(_lengths); copy->_closed = _closed; diff --git a/native/cocos/editor-support/spine/PointAttachment.cpp b/native/cocos/editor-support/spine/PointAttachment.cpp index d71d89cf4bb..3dda211bb18 100644 --- a/native/cocos/editor-support/spine/PointAttachment.cpp +++ b/native/cocos/editor-support/spine/PointAttachment.cpp @@ -82,7 +82,7 @@ void PointAttachment::setRotation(float inValue) { } Attachment *PointAttachment::copy() { - PointAttachment *copy = new (__FILE__, __LINE__) PointAttachment(getName()); + PointAttachment *copy = spine_new PointAttachment(getName()); copy->_x = _x; copy->_y = _y; copy->_rotation = _rotation; diff --git a/native/cocos/editor-support/spine/Pool.h b/native/cocos/editor-support/spine/Pool.h index 6dd4cee87f0..7e1fdb45988 100644 --- a/native/cocos/editor-support/spine/Pool.h +++ b/native/cocos/editor-support/spine/Pool.h @@ -54,7 +54,7 @@ class SP_API Pool : public SpineObject { return ret; } else { - T *ret = new (__FILE__, __LINE__) T(); + T *ret = spine_new T(); return ret; } diff --git a/native/cocos/editor-support/spine/RegionAttachment.cpp b/native/cocos/editor-support/spine/RegionAttachment.cpp index e83afc98441..f8d86dff210 100644 --- a/native/cocos/editor-support/spine/RegionAttachment.cpp +++ b/native/cocos/editor-support/spine/RegionAttachment.cpp @@ -264,7 +264,7 @@ spine::Color &RegionAttachment::getColor() { } Attachment *RegionAttachment::copy() { - RegionAttachment *copy = new (__FILE__, __LINE__) RegionAttachment(getName()); + RegionAttachment *copy = spine_new RegionAttachment(getName()); copy->_regionWidth = _regionWidth; copy->_regionHeight = _regionHeight; copy->_regionOffsetX = _regionOffsetX; diff --git a/native/cocos/editor-support/spine/Skeleton.cpp b/native/cocos/editor-support/spine/Skeleton.cpp index b2021b9ce1b..c0896e9781c 100644 --- a/native/cocos/editor-support/spine/Skeleton.cpp +++ b/native/cocos/editor-support/spine/Skeleton.cpp @@ -71,10 +71,10 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData), Bone *bone; if (data->getParent() == NULL) { - bone = new (__FILE__, __LINE__) Bone(*data, *this, NULL); + bone = spine_new Bone(*data, *this, NULL); } else { Bone *parent = _bones[data->getParent()->getIndex()]; - bone = new (__FILE__, __LINE__) Bone(*data, *this, parent); + bone = spine_new Bone(*data, *this, parent); parent->getChildren().add(bone); } @@ -87,7 +87,7 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData), SlotData *data = _data->getSlots()[i]; Bone *bone = _bones[data->getBoneData().getIndex()]; - Slot *slot = new (__FILE__, __LINE__) Slot(*data, *bone); + Slot *slot = spine_new Slot(*data, *bone); _slots.add(slot); _drawOrder.add(slot); @@ -97,7 +97,7 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData), for (size_t i = 0; i < _data->getIkConstraints().size(); ++i) { IkConstraintData *data = _data->getIkConstraints()[i]; - IkConstraint *constraint = new (__FILE__, __LINE__) IkConstraint(*data, *this); + IkConstraint *constraint = spine_new IkConstraint(*data, *this); _ikConstraints.add(constraint); } @@ -106,7 +106,7 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData), for (size_t i = 0; i < _data->getTransformConstraints().size(); ++i) { TransformConstraintData *data = _data->getTransformConstraints()[i]; - TransformConstraint *constraint = new (__FILE__, __LINE__) TransformConstraint(*data, *this); + TransformConstraint *constraint = spine_new TransformConstraint(*data, *this); _transformConstraints.add(constraint); } @@ -115,7 +115,7 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData), for (size_t i = 0; i < _data->getPathConstraints().size(); ++i) { PathConstraintData *data = _data->getPathConstraints()[i]; - PathConstraint *constraint = new (__FILE__, __LINE__) PathConstraint(*data, *this); + PathConstraint *constraint = spine_new PathConstraint(*data, *this); _pathConstraints.add(constraint); } diff --git a/native/cocos/editor-support/spine/SkeletonBinary.cpp b/native/cocos/editor-support/spine/SkeletonBinary.cpp index c3742e2d33f..4d43b8da39e 100644 --- a/native/cocos/editor-support/spine/SkeletonBinary.cpp +++ b/native/cocos/editor-support/spine/SkeletonBinary.cpp @@ -94,7 +94,7 @@ const int SkeletonBinary::CURVE_STEPPED = 1; const int SkeletonBinary::CURVE_BEZIER = 2; SkeletonBinary::SkeletonBinary(Atlas *atlasArray) : _attachmentLoader( - new (__FILE__, __LINE__) AtlasAttachmentLoader(atlasArray)), + spine_new AtlasAttachmentLoader(atlasArray)), _error(), _scale(1), _ownsLoader(true) { @@ -115,13 +115,13 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons bool nonessential; SkeletonData *skeletonData; - DataInput *input = new (__FILE__, __LINE__) DataInput(); + DataInput *input = spine_new DataInput(); input->cursor = binary; input->end = binary + length; _linkedMeshes.clear(); - skeletonData = new (__FILE__, __LINE__) SkeletonData(); + skeletonData = spine_new SkeletonData(); char *skeletonData_hash = readString(input); skeletonData->_hash.own(skeletonData_hash); @@ -159,7 +159,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons for (int i = 0; i < numBones; ++i) { const char *name = readString(input); BoneData *parent = i == 0 ? 0 : skeletonData->_bones[readVarint(input, true)]; - BoneData *data = new (__FILE__, __LINE__) BoneData(i, String(name, true), parent); + BoneData *data = spine_new BoneData(i, String(name, true), parent); data->_rotation = readFloat(input); data->_x = readFloat(input) * _scale; data->_y = readFloat(input) * _scale; @@ -180,7 +180,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons for (int i = 0; i < slotsCount; ++i) { const char *slotName = readString(input); BoneData *boneData = skeletonData->_bones[readVarint(input, true)]; - SlotData *slotData = new (__FILE__, __LINE__) SlotData(i, String(slotName, true), *boneData); + SlotData *slotData = spine_new SlotData(i, String(slotName, true), *boneData); readColor(input, slotData->getColor()); unsigned char r = readByte(input); @@ -201,7 +201,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons skeletonData->_ikConstraints.setSize(ikConstraintsCount, 0); for (int i = 0; i < ikConstraintsCount; ++i) { const char *name = readString(input); - IkConstraintData *data = new (__FILE__, __LINE__) IkConstraintData(String(name, true)); + IkConstraintData *data = spine_new IkConstraintData(String(name, true)); data->setOrder(readVarint(input, true)); data->setSkinRequired(readBoolean(input)); int bonesCount = readVarint(input, true); @@ -223,7 +223,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons skeletonData->_transformConstraints.setSize(transformConstraintsCount, 0); for (int i = 0; i < transformConstraintsCount; ++i) { const char *name = readString(input); - TransformConstraintData *data = new (__FILE__, __LINE__) TransformConstraintData(String(name, true)); + TransformConstraintData *data = spine_new TransformConstraintData(String(name, true)); data->setOrder(readVarint(input, true)); data->setSkinRequired(readBoolean(input)); int bonesCount = readVarint(input, true); @@ -251,7 +251,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons skeletonData->_pathConstraints.setSize(pathConstraintsCount, 0); for (int i = 0; i < pathConstraintsCount; ++i) { const char *name = readString(input); - PathConstraintData *data = new (__FILE__, __LINE__) PathConstraintData(String(name, true)); + PathConstraintData *data = spine_new PathConstraintData(String(name, true)); data->setOrder(readVarint(input, true)); data->setSkinRequired(readBoolean(input)); int bonesCount = readVarint(input, true); @@ -314,7 +314,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons skeletonData->_events.setSize(eventsCount, 0); for (int i = 0; i < eventsCount; ++i) { const char *name = readStringRef(input, skeletonData); - EventData *eventData = new (__FILE__, __LINE__) EventData(String(name)); + EventData *eventData = spine_new EventData(String(name)); eventData->_intValue = readVarint(input, false); eventData->_floatValue = readFloat(input); eventData->_stringValue.own(readString(input)); @@ -353,7 +353,7 @@ SkeletonData *SkeletonBinary::readSkeletonDataFile(const String &path) { return NULL; } skeletonData = readSkeletonData((unsigned char *)binary, length); - SpineExtension::free(binary, __FILE__, __LINE__); + SpineExtension::free(binary, __SPINE_FILE__, __SPINE_LINE__); return skeletonData; } @@ -370,7 +370,7 @@ char *SkeletonBinary::readString(DataInput *input) { int length = readVarint(input, true); char *string; if (length == 0) return NULL; - string = SpineExtension::alloc(length, __FILE__, __LINE__); + string = SpineExtension::alloc(length, __SPINE_FILE__, __SPINE_LINE__); memcpy(string, input->cursor, length - 1); input->cursor += length - 1; string[length - 1] = '\0'; @@ -447,9 +447,9 @@ Skin *SkeletonBinary::readSkin(DataInput *input, bool defaultSkin, SkeletonData if (defaultSkin) { slotCount = readVarint(input, true); if (slotCount == 0) return NULL; - skin = new (__FILE__, __LINE__) Skin("default"); + skin = spine_new Skin("default"); } else { - skin = new (__FILE__, __LINE__) Skin(readStringRef(input, skeletonData)); + skin = spine_new Skin(readStringRef(input, skeletonData)); for (int i = 0, n = readVarint(input, true); i < n; i++) skin->getBones().add(skeletonData->_bones[readVarint(input, true)]); @@ -577,7 +577,7 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo mesh->_height = readFloat(input) * _scale; } - LinkedMesh *linkedMesh = new (__FILE__, __LINE__) LinkedMesh(mesh, String(skinName), slotIndex, + LinkedMesh *linkedMesh = spine_new LinkedMesh(mesh, String(skinName), slotIndex, String(parent), inheritDeform); _linkedMeshes.add(linkedMesh); return mesh; @@ -696,7 +696,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S int frameCount = readVarint(input, true); switch (timelineType) { case SLOT_ATTACHMENT: { - AttachmentTimeline *timeline = new (__FILE__, __LINE__) AttachmentTimeline(frameCount); + AttachmentTimeline *timeline = spine_new AttachmentTimeline(frameCount); timeline->_slotIndex = slotIndex; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); @@ -708,7 +708,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S break; } case SLOT_COLOR: { - ColorTimeline *timeline = new (__FILE__, __LINE__) ColorTimeline(frameCount); + ColorTimeline *timeline = spine_new ColorTimeline(frameCount); timeline->_slotIndex = slotIndex; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); @@ -725,7 +725,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S break; } case SLOT_TWO_COLOR: { - TwoColorTimeline *timeline = new (__FILE__, __LINE__) TwoColorTimeline(frameCount); + TwoColorTimeline *timeline = spine_new TwoColorTimeline(frameCount); timeline->_slotIndex = slotIndex; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); @@ -763,7 +763,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S int frameCount = readVarint(input, true); switch (timelineType) { case BONE_ROTATE: { - RotateTimeline *timeline = new (__FILE__, __LINE__) RotateTimeline(frameCount); + RotateTimeline *timeline = spine_new RotateTimeline(frameCount); timeline->_boneIndex = boneIndex; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); @@ -781,11 +781,11 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S TranslateTimeline *timeline; float timelineScale = 1; if (timelineType == BONE_SCALE) { - timeline = new (__FILE__, __LINE__) ScaleTimeline(frameCount); + timeline = spine_new ScaleTimeline(frameCount); } else if (timelineType == BONE_SHEAR) { - timeline = new (__FILE__, __LINE__) ShearTimeline(frameCount); + timeline = spine_new ShearTimeline(frameCount); } else { - timeline = new (__FILE__, __LINE__) TranslateTimeline(frameCount); + timeline = spine_new TranslateTimeline(frameCount); timelineScale = scale; } timeline->_boneIndex = boneIndex; @@ -815,7 +815,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S for (int i = 0, n = readVarint(input, true); i < n; ++i) { int index = readVarint(input, true); int frameCount = readVarint(input, true); - IkConstraintTimeline *timeline = new (__FILE__, __LINE__) IkConstraintTimeline(frameCount); + IkConstraintTimeline *timeline = spine_new IkConstraintTimeline(frameCount); timeline->_ikConstraintIndex = index; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); @@ -835,7 +835,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S for (int i = 0, n = readVarint(input, true); i < n; ++i) { int index = readVarint(input, true); int frameCount = readVarint(input, true); - TransformConstraintTimeline *timeline = new (__FILE__, __LINE__) TransformConstraintTimeline(frameCount); + TransformConstraintTimeline *timeline = spine_new TransformConstraintTimeline(frameCount); timeline->_transformConstraintIndex = index; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); @@ -863,11 +863,11 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S PathConstraintPositionTimeline *timeline; float timelineScale = 1; if (timelineType == PATH_SPACING) { - timeline = new (__FILE__, __LINE__) PathConstraintSpacingTimeline(frameCount); + timeline = spine_new PathConstraintSpacingTimeline(frameCount); if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) timelineScale = scale; } else { - timeline = new (__FILE__, __LINE__) PathConstraintPositionTimeline(frameCount); + timeline = spine_new PathConstraintPositionTimeline(frameCount); if (data->_positionMode == PositionMode_Fixed) timelineScale = scale; } @@ -883,7 +883,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S break; } case PATH_MIX: { - PathConstraintMixTimeline *timeline = new (__FILE__, __LINE__) PathConstraintMixTimeline(frameCount); + PathConstraintMixTimeline *timeline = spine_new PathConstraintMixTimeline(frameCount); timeline->_pathConstraintIndex = index; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { @@ -924,7 +924,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S size_t frameCount = (size_t)readVarint(input, true); - DeformTimeline *timeline = new (__FILE__, __LINE__) DeformTimeline(frameCount); + DeformTimeline *timeline = spine_new DeformTimeline(frameCount); timeline->_slotIndex = slotIndex; timeline->_attachment = attachment; @@ -971,7 +971,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S // Draw order timeline. size_t drawOrderCount = (size_t)readVarint(input, true); if (drawOrderCount > 0) { - DrawOrderTimeline *timeline = new (__FILE__, __LINE__) DrawOrderTimeline(drawOrderCount); + DrawOrderTimeline *timeline = spine_new DrawOrderTimeline(drawOrderCount); size_t slotCount = skeletonData->_slots.size(); for (size_t i = 0; i < drawOrderCount; ++i) { @@ -1013,19 +1013,19 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S // Event timeline. int eventCount = readVarint(input, true); if (eventCount > 0) { - EventTimeline *timeline = new (__FILE__, __LINE__) EventTimeline(eventCount); + EventTimeline *timeline = spine_new EventTimeline(eventCount); for (int i = 0; i < eventCount; ++i) { float time = readFloat(input); EventData *eventData = skeletonData->_events[readVarint(input, true)]; - Event *event = new (__FILE__, __LINE__) Event(time, *eventData); + Event *event = spine_new Event(time, *eventData); event->_intValue = readVarint(input, false); event->_floatValue = readFloat(input); bool freeString = readBoolean(input); const char *event_stringValue = freeString ? readString(input) : eventData->_stringValue.buffer(); event->_stringValue = String(event_stringValue); - if (freeString) SpineExtension::free(event_stringValue, __FILE__, __LINE__); + if (freeString) SpineExtension::free(event_stringValue, __SPINE_FILE__, __SPINE_LINE__); if (!eventData->_audioPath.isEmpty()) { event->_volume = readFloat(input); @@ -1038,7 +1038,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S duration = MathUtil::max(duration, timeline->_frames[eventCount - 1]); } - return new (__FILE__, __LINE__) Animation(String(name), timelines, duration); + return spine_new Animation(String(name), timelines, duration); } void SkeletonBinary::readCurve(DataInput *input, int frameIndex, CurveTimeline *timeline) { diff --git a/native/cocos/editor-support/spine/SkeletonBounds.cpp b/native/cocos/editor-support/spine/SkeletonBounds.cpp index 005c788bc4a..f08ee2ecd82 100644 --- a/native/cocos/editor-support/spine/SkeletonBounds.cpp +++ b/native/cocos/editor-support/spine/SkeletonBounds.cpp @@ -72,7 +72,7 @@ void SkeletonBounds::update(Skeleton &skeleton, bool updateAabb) { polygonP = _polygonPool[poolCount - 1]; _polygonPool.removeAt(poolCount - 1); } else - polygonP = new (__FILE__, __LINE__) Polygon(); + polygonP = spine_new Polygon(); _polygons.add(polygonP); diff --git a/native/cocos/editor-support/spine/SkeletonData.cpp b/native/cocos/editor-support/spine/SkeletonData.cpp index b6c75b9f6e0..e260cba5ed0 100644 --- a/native/cocos/editor-support/spine/SkeletonData.cpp +++ b/native/cocos/editor-support/spine/SkeletonData.cpp @@ -71,7 +71,7 @@ SkeletonData::~SkeletonData() { ContainerUtil::cleanUpVectorOfPointers(_transformConstraints); ContainerUtil::cleanUpVectorOfPointers(_pathConstraints); for (size_t i = 0; i < _strings.size(); i++) { - SpineExtension::free(_strings[i], __FILE__, __LINE__); + SpineExtension::free(_strings[i], __SPINE_FILE__, __SPINE_LINE__); } } diff --git a/native/cocos/editor-support/spine/SkeletonJson.cpp b/native/cocos/editor-support/spine/SkeletonJson.cpp index a6eb5882479..3e2f20d77bc 100644 --- a/native/cocos/editor-support/spine/SkeletonJson.cpp +++ b/native/cocos/editor-support/spine/SkeletonJson.cpp @@ -27,6 +27,8 @@ * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +#if 1//ENABLE_JSON_PARSER + #ifdef SPINE_UE4 #include "SpinePluginPrivatePCH.h" #endif @@ -80,7 +82,7 @@ using namespace spine; -SkeletonJson::SkeletonJson(Atlas *atlas) : _attachmentLoader(new (__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), +SkeletonJson::SkeletonJson(Atlas *atlas) : _attachmentLoader(spine_new AtlasAttachmentLoader(atlas)), _scale(1), _ownsLoader(true) {} @@ -105,7 +107,7 @@ SkeletonData *SkeletonJson::readSkeletonDataFile(const String &path) { skeletonData = readSkeletonData(json); - SpineExtension::free(json, __FILE__, __LINE__); + SpineExtension::free(json, __SPINE_FILE__, __SPINE_LINE__); return skeletonData; } @@ -125,7 +127,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { return NULL; } - skeletonData = new (__FILE__, __LINE__) SkeletonData(); + skeletonData = spine_new SkeletonData(); skeleton = Json::getItem(root, "skeleton"); if (skeleton) { @@ -159,7 +161,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { } } - data = new (__FILE__, __LINE__) BoneData(bonesCount, Json::getString(boneMap, "name", 0), parent); + data = spine_new BoneData(bonesCount, Json::getString(boneMap, "name", 0), parent); data->_length = Json::getFloat(boneMap, "length", 0) * _scale; data->_x = Json::getFloat(boneMap, "x", 0) * _scale; @@ -207,7 +209,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { return NULL; } - data = new (__FILE__, __LINE__) SlotData(i, Json::getString(slotMap, "name", 0), *boneData); + data = spine_new SlotData(i, Json::getString(slotMap, "name", 0), *boneData); color = Json::getString(slotMap, "color", 0); if (color) { @@ -254,7 +256,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { for (constraintMap = ik->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { const char *targetName; - IkConstraintData *data = new (__FILE__, __LINE__) IkConstraintData(Json::getString(constraintMap, "name", 0)); + IkConstraintData *data = spine_new IkConstraintData(Json::getString(constraintMap, "name", 0)); data->setOrder(Json::getInt(constraintMap, "order", 0)); data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); @@ -298,7 +300,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { for (constraintMap = transform->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { const char *name; - TransformConstraintData *data = new (__FILE__, __LINE__) TransformConstraintData(Json::getString(constraintMap, "name", 0)); + TransformConstraintData *data = spine_new TransformConstraintData(Json::getString(constraintMap, "name", 0)); data->setOrder(Json::getInt(constraintMap, "order", 0)); data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); @@ -350,7 +352,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { const char *name; const char *item; - PathConstraintData *data = new (__FILE__, __LINE__) PathConstraintData(Json::getString(constraintMap, "name", 0)); + PathConstraintData *data = spine_new PathConstraintData(Json::getString(constraintMap, "name", 0)); data->setOrder(Json::getInt(constraintMap, "order", 0)); data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); @@ -425,7 +427,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { if (strlen(skinName) == 0) { skinName = skinMap->_name; } - skin = new (__FILE__, __LINE__) Skin(skinName); + skin = spine_new Skin(skinName); Json *item = Json::getItem(skinMap, "bones"); if (item) { @@ -612,7 +614,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { _attachmentLoader->configureAttachment(mesh); } else { bool inheritDeform = Json::getInt(attachmentMap, "deform", 1) ? true : false; - LinkedMesh *linkedMesh = new (__FILE__, __LINE__) LinkedMesh(mesh, + LinkedMesh *linkedMesh = spine_new LinkedMesh(mesh, String(Json::getString(attachmentMap, "skin", 0)), slot->getIndex(), String(entry->_valueString), inheritDeform); _linkedMeshes.add(linkedMesh); @@ -714,7 +716,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { skeletonData->_events.ensureCapacity(events->_size); skeletonData->_events.setSize(events->_size, 0); for (eventMap = events->_child, i = 0; eventMap; eventMap = eventMap->_next, ++i) { - EventData *eventData = new (__FILE__, __LINE__) EventData(String(eventMap->_name)); + EventData *eventData = spine_new EventData(String(eventMap->_name)); eventData->_intValue = Json::getInt(eventMap, "int", 0); eventData->_floatValue = Json::getFloat(eventMap, "float", 0); @@ -841,7 +843,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { for (timelineMap = slotMap->_child; timelineMap; timelineMap = timelineMap->_next) { if (strcmp(timelineMap->_name, "attachment") == 0) { - AttachmentTimeline *timeline = new (__FILE__, __LINE__) AttachmentTimeline(timelineMap->_size); + AttachmentTimeline *timeline = spine_new AttachmentTimeline(timelineMap->_size); timeline->_slotIndex = slotIndex; @@ -855,7 +857,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { duration = MathUtil::max(duration, timeline->_frames[timelineMap->_size - 1]); } else if (strcmp(timelineMap->_name, "color") == 0) { - ColorTimeline *timeline = new (__FILE__, __LINE__) ColorTimeline(timelineMap->_size); + ColorTimeline *timeline = spine_new ColorTimeline(timelineMap->_size); timeline->_slotIndex = slotIndex; @@ -870,7 +872,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * ColorTimeline::ENTRIES]); } else if (strcmp(timelineMap->_name, "twoColor") == 0) { - TwoColorTimeline *timeline = new (__FILE__, __LINE__) TwoColorTimeline(timelineMap->_size); + TwoColorTimeline *timeline = spine_new TwoColorTimeline(timelineMap->_size); timeline->_slotIndex = slotIndex; @@ -906,7 +908,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { for (timelineMap = boneMap->_child; timelineMap; timelineMap = timelineMap->_next) { if (strcmp(timelineMap->_name, "rotate") == 0) { - RotateTimeline *timeline = new (__FILE__, __LINE__) RotateTimeline(timelineMap->_size); + RotateTimeline *timeline = spine_new RotateTimeline(timelineMap->_size); timeline->_boneIndex = boneIndex; @@ -926,12 +928,12 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { float defaultValue = 0; TranslateTimeline *timeline = 0; if (isScale) { - timeline = new (__FILE__, __LINE__) ScaleTimeline(timelineMap->_size); + timeline = spine_new ScaleTimeline(timelineMap->_size); defaultValue = 1; } else if (isTranslate) { - timeline = new (__FILE__, __LINE__) TranslateTimeline(timelineMap->_size); + timeline = spine_new TranslateTimeline(timelineMap->_size); } else if (isShear) { - timeline = new (__FILE__, __LINE__) ShearTimeline(timelineMap->_size); + timeline = spine_new ShearTimeline(timelineMap->_size); } timeline->_boneIndex = boneIndex; @@ -957,7 +959,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { /** IK constraint timelines. */ for (constraintMap = ik ? ik->_child : 0; constraintMap; constraintMap = constraintMap->_next) { IkConstraintData *constraint = skeletonData->findIkConstraint(constraintMap->_name); - IkConstraintTimeline *timeline = new (__FILE__, __LINE__) IkConstraintTimeline(constraintMap->_size); + IkConstraintTimeline *timeline = spine_new IkConstraintTimeline(constraintMap->_size); for (frameIndex = 0; frameIndex < skeletonData->_ikConstraints.size(); ++frameIndex) { if (constraint == skeletonData->_ikConstraints[frameIndex]) { @@ -979,7 +981,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { /** Transform constraint timelines. */ for (constraintMap = transform ? transform->_child : 0; constraintMap; constraintMap = constraintMap->_next) { TransformConstraintData *constraint = skeletonData->findTransformConstraint(constraintMap->_name); - TransformConstraintTimeline *timeline = new (__FILE__, __LINE__) TransformConstraintTimeline(constraintMap->_size); + TransformConstraintTimeline *timeline = spine_new TransformConstraintTimeline(constraintMap->_size); for (frameIndex = 0; frameIndex < skeletonData->_transformConstraints.size(); ++frameIndex) { if (constraint == skeletonData->_transformConstraints[frameIndex]) { @@ -1023,13 +1025,13 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { PathConstraintPositionTimeline *timeline; float timelineScale = 1; if (strcmp(timelineName, "spacing") == 0) { - timeline = new (__FILE__, __LINE__) PathConstraintSpacingTimeline(timelineMap->_size); + timeline = spine_new PathConstraintSpacingTimeline(timelineMap->_size); if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) { timelineScale = _scale; } } else { - timeline = new (__FILE__, __LINE__) PathConstraintPositionTimeline(timelineMap->_size); + timeline = spine_new PathConstraintPositionTimeline(timelineMap->_size); if (data->_positionMode == PositionMode_Fixed) { timelineScale = _scale; @@ -1047,7 +1049,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintPositionTimeline::ENTRIES]); } else if (strcmp(timelineName, "mix") == 0) { - PathConstraintMixTimeline *timeline = new (__FILE__, __LINE__) PathConstraintMixTimeline(timelineMap->_size); + PathConstraintMixTimeline *timeline = spine_new PathConstraintMixTimeline(timelineMap->_size); timeline->_pathConstraintIndex = constraintIndex; for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), @@ -1087,7 +1089,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { Vector &verts = attachment->_vertices; deformLength = weighted ? verts.size() / 3 * 2 : verts.size(); - timeline = new (__FILE__, __LINE__) DeformTimeline(timelineMap->_size); + timeline = spine_new DeformTimeline(timelineMap->_size); timeline->_slotIndex = slotIndex; timeline->_attachment = attachment; @@ -1134,7 +1136,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { /** Draw order timeline. */ if (drawOrder) { - DrawOrderTimeline *timeline = new (__FILE__, __LINE__) DrawOrderTimeline(drawOrder->_size); + DrawOrderTimeline *timeline = spine_new DrawOrderTimeline(drawOrder->_size); for (valueMap = drawOrder->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { int ii; @@ -1182,7 +1184,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { /** Event timeline. */ if (events) { - EventTimeline *timeline = new (__FILE__, __LINE__) EventTimeline(events->_size); + EventTimeline *timeline = spine_new EventTimeline(events->_size); for (valueMap = events->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { Event *event; @@ -1193,7 +1195,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { return NULL; } - event = new (__FILE__, __LINE__) Event(Json::getFloat(valueMap, "time", 0), *eventData); + event = spine_new Event(Json::getFloat(valueMap, "time", 0), *eventData); event->_intValue = Json::getInt(valueMap, "int", eventData->_intValue); event->_floatValue = Json::getFloat(valueMap, "float", eventData->_floatValue); event->_stringValue = Json::getString(valueMap, "string", eventData->_stringValue.buffer()); @@ -1208,7 +1210,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { duration = MathUtil::max(duration, timeline->_frames[events->_size - 1]); } - return new (__FILE__, __LINE__) Animation(String(root->_name), timelines, duration); + return spine_new Animation(String(root->_name), timelines, duration); } void SkeletonJson::readVertices(Json *attachmentMap, VertexAttachment *attachment, size_t verticesLength) { @@ -1258,3 +1260,5 @@ void SkeletonJson::setError(Json *root, const String &value1, const String &valu _error = String(value1).append(value2); delete root; } + +#endif // ENABLE_JSON_PARSER diff --git a/native/cocos/editor-support/spine/SkeletonJson.h b/native/cocos/editor-support/spine/SkeletonJson.h index 3aa87077357..2194262efa7 100644 --- a/native/cocos/editor-support/spine/SkeletonJson.h +++ b/native/cocos/editor-support/spine/SkeletonJson.h @@ -30,6 +30,8 @@ #ifndef Spine_SkeletonJson_h #define Spine_SkeletonJson_h +#if 1//ENABLE_JSON_PARSER + #include #include #include @@ -88,4 +90,6 @@ class SP_API SkeletonJson : public SpineObject { }; } // namespace spine +#endif // ENABLE_JSON_PARSER + #endif /* Spine_SkeletonJson_h */ diff --git a/native/cocos/editor-support/spine/SpineObject.cpp b/native/cocos/editor-support/spine/SpineObject.cpp index f635b042630..b0f866588a2 100644 --- a/native/cocos/editor-support/spine/SpineObject.cpp +++ b/native/cocos/editor-support/spine/SpineObject.cpp @@ -37,7 +37,7 @@ using namespace spine; void *SpineObject::operator new(size_t sz) { - return SpineExtension::getInstance()->_calloc(sz, __FILE__, __LINE__); + return SpineExtension::getInstance()->_calloc(sz, __SPINE_FILE__, __SPINE_LINE__); } void *SpineObject::operator new(size_t sz, const char *file, int line) { @@ -55,11 +55,11 @@ void SpineObject::operator delete(void *p, const char *file, int line) { void SpineObject::operator delete(void *p, void *mem) { SP_UNUSED(mem); - SpineExtension::free(p, __FILE__, __LINE__); + SpineExtension::free(p, __SPINE_FILE__, __SPINE_LINE__); } void SpineObject::operator delete(void *p) { - SpineExtension::free(p, __FILE__, __LINE__); + SpineExtension::free(p, __SPINE_FILE__, __SPINE_LINE__); } SpineObject::~SpineObject() { diff --git a/native/cocos/editor-support/spine/SpineObject.h b/native/cocos/editor-support/spine/SpineObject.h index 4b76811c673..5c08549b691 100644 --- a/native/cocos/editor-support/spine/SpineObject.h +++ b/native/cocos/editor-support/spine/SpineObject.h @@ -56,4 +56,14 @@ class SP_API SpineObject { }; } // namespace spine +#if DEBUG_NEW + #define __SPINE_FILE__ __FILE__ + #define __SPINE_LINE__ __LINE__ + #define spine_new new (__FILE__, __LINE__) +#else + #define __SPINE_FILE__ "" + #define __SPINE_LINE__ __LINE__ + #define spine_new new +#endif + #endif diff --git a/native/cocos/editor-support/spine/SpineString.cpp b/native/cocos/editor-support/spine/SpineString.cpp index fc0d0d69771..d72601b5bf1 100644 --- a/native/cocos/editor-support/spine/SpineString.cpp +++ b/native/cocos/editor-support/spine/SpineString.cpp @@ -46,7 +46,7 @@ String::String(const char *chars, size_t len, bool own) { } else { _length = len; if (!own) { - _buffer = SpineExtension::calloc(_length + 1, __FILE__, __LINE__); + _buffer = SpineExtension::calloc(_length + 1, __SPINE_FILE__, __SPINE_LINE__); _buffer[_length] = '\0'; memcpy((void *)_buffer, chars, _length); } else { @@ -64,7 +64,7 @@ String::String(const String &other) { _buffer = NULL; } else { _length = other._length; - _buffer = SpineExtension::calloc(other._length + 1, __FILE__, __LINE__); + _buffer = SpineExtension::calloc(other._length + 1, __SPINE_FILE__, __SPINE_LINE__); memcpy((void *)_buffer, other._buffer, other._length + 1); } } @@ -72,7 +72,7 @@ String::String(const String &other) { void String::own(const String &other) { if (this == &other) return; if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); + SpineExtension::free(_buffer, __SPINE_FILE__, __SPINE_LINE__); } _length = other._length; _buffer = other._buffer; @@ -83,7 +83,7 @@ void String::own(const String &other) { void String::own(const char *chars) { if (_buffer == chars) return; if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); + SpineExtension::free(_buffer, __SPINE_FILE__, __SPINE_LINE__); } if (!chars) { @@ -103,14 +103,14 @@ void String::unown() { String &String::operator=(const String &other) { if (this == &other) return *this; if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); + SpineExtension::free(_buffer, __SPINE_FILE__, __SPINE_LINE__); } if (!other._buffer) { _length = 0; _buffer = NULL; } else { _length = other._length; - _buffer = SpineExtension::calloc(other._length + 1, __FILE__, __LINE__); + _buffer = SpineExtension::calloc(other._length + 1, __SPINE_FILE__, __SPINE_LINE__); memcpy((void *)_buffer, other._buffer, other._length + 1); } return *this; @@ -119,14 +119,14 @@ String &String::operator=(const String &other) { String &String::operator=(const char *chars) { if (_buffer == chars) return *this; if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); + SpineExtension::free(_buffer, __SPINE_FILE__, __SPINE_LINE__); } if (!chars) { _length = 0; _buffer = NULL; } else { _length = strlen(chars); - _buffer = SpineExtension::calloc(_length + 1, __FILE__, __LINE__); + _buffer = SpineExtension::calloc(_length + 1, __SPINE_FILE__, __SPINE_LINE__); memcpy((void *)_buffer, chars, _length + 1); } return *this; @@ -137,7 +137,7 @@ String &String::append(const char *chars) { size_t thisLen = _length; _length = _length + len; bool same = chars == _buffer; - _buffer = SpineExtension::realloc(_buffer, _length + 1, __FILE__, __LINE__); + _buffer = SpineExtension::realloc(_buffer, _length + 1, __SPINE_FILE__, __SPINE_LINE__); memcpy((void *)(_buffer + thisLen), (void *)(same ? _buffer : chars), len + 1); return *this; } @@ -147,7 +147,7 @@ String &String::append(const String &other) { size_t thisLen = _length; _length = _length + len; bool same = other._buffer == _buffer; - _buffer = SpineExtension::realloc(_buffer, _length + 1, __FILE__, __LINE__); + _buffer = SpineExtension::realloc(_buffer, _length + 1, __SPINE_FILE__, __SPINE_LINE__); memcpy((void *)(_buffer + thisLen), (void *)(same ? _buffer : other._buffer), len + 1); return *this; } @@ -182,7 +182,7 @@ bool operator!=(const String &a, const String &b) { String::~String() { if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); + SpineExtension::free(_buffer, __SPINE_FILE__, __SPINE_LINE__); } } diff --git a/native/cocos/editor-support/spine/Vector.h b/native/cocos/editor-support/spine/Vector.h index 5e5b12861aa..cb2c00e3480 100644 --- a/native/cocos/editor-support/spine/Vector.h +++ b/native/cocos/editor-support/spine/Vector.h @@ -82,7 +82,7 @@ class SP_API Vector : public SpineObject { if (_capacity < newSize) { _capacity = (int)(_size * 1.75f); if (_capacity < 8) _capacity = 8; - _buffer = spine::SpineExtension::realloc(_buffer, _capacity, __FILE__, __LINE__); + _buffer = spine::SpineExtension::realloc(_buffer, _capacity, __SPINE_FILE__, __SPINE_LINE__); } if (oldSize < _size) { for (size_t i = oldSize; i < _size; i++) { @@ -94,7 +94,7 @@ class SP_API Vector : public SpineObject { inline void ensureCapacity(size_t newCapacity = 0) { if (_capacity >= newCapacity) return; _capacity = newCapacity; - _buffer = SpineExtension::realloc(_buffer, newCapacity, __FILE__, __LINE__); + _buffer = SpineExtension::realloc(_buffer, newCapacity, __SPINE_FILE__, __SPINE_LINE__); } inline void add(const T &inValue) { @@ -106,7 +106,7 @@ class SP_API Vector : public SpineObject { T valueCopy = inValue; _capacity = (int)(_size * 1.75f); if (_capacity < 8) _capacity = 8; - _buffer = spine::SpineExtension::realloc(_buffer, _capacity, __FILE__, __LINE__); + _buffer = spine::SpineExtension::realloc(_buffer, _capacity, __SPINE_FILE__, __SPINE_LINE__); construct(_buffer + _size++, valueCopy); } else { construct(_buffer + _size++, inValue); @@ -203,7 +203,7 @@ class SP_API Vector : public SpineObject { inline T *allocate(size_t n) { assert(n > 0); - T *ptr = SpineExtension::calloc(n, __FILE__, __LINE__); + T *ptr = SpineExtension::calloc(n, __SPINE_FILE__, __SPINE_LINE__); assert(ptr); @@ -212,7 +212,7 @@ class SP_API Vector : public SpineObject { inline void deallocate(T *buffer) { if (_buffer) { - SpineExtension::free(buffer, __FILE__, __LINE__); + SpineExtension::free(buffer, __SPINE_FILE__, __SPINE_LINE__); } } From 5b59d17c1d9b4d2caf2d4f13c73428966337c317 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 28 Oct 2024 22:51:53 +0800 Subject: [PATCH 24/80] Update --- .../spine-wasm/spine-skeleton-instance.cpp | 23 +++++++++++-------- .../spine-wasm/spine-skeleton-instance.h | 6 +++-- .../editor-support/spine-wasm/spine-wasm.cpp | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index 70401ee525d..1345608dd7b 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -366,9 +366,12 @@ void SpineSkeletonInstance::collectMeshData() { currMesh.blendMode = static_cast(slot->getData().getBlendMode()); if (_userData.useSlotTexture) { - auto iter = _slotTextureSet.find(slot); - if (iter != _slotTextureSet.end()) { - currMesh.textureID = iter->second; + // auto iter = _slotTextureSet.find(slot); + // if (iter != _slotTextureSet.end()) { + // currMesh.textureID = iter->second; + // } + if (_slotTextureSet.containsKey(slot)) { + currMesh.textureID = _slotTextureSet[slot]; } } _model->addSlotMesh(currMesh); @@ -514,10 +517,12 @@ void SpineSkeletonInstance::setSlotTexture(const std::string &slotName, uint32_t auto slot = _skeleton->findSlot(slotName.c_str()); if (!slot) return; _userData.useSlotTexture = true; - auto iter = _slotTextureSet.find(slot); - if (iter != _slotTextureSet.end()) { - iter->second = textureID; - } else { - _slotTextureSet[slot] = textureID; - } + // auto iter = _slotTextureSet.find(slot); + // if (iter != _slotTextureSet.end()) { + // iter->second = textureID; + // } else { + // _slotTextureSet[slot] = textureID; + // } + + _slotTextureSet.put(slot, textureID); } \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index b3785bad0ad..926d2067d93 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -2,7 +2,8 @@ #include -#include +// #include +#include #include #include "mesh-type-define.h" #include "spine-model.h" @@ -74,5 +75,6 @@ class SpineSkeletonInstance { uint32_t _trackEntryListenerID = 0; UserData _userData; std::vector _debugShapes{}; - std::map _slotTextureSet{}; + // std::map _slotTextureSet{}; + spine::HashMap _slotTextureSet{}; }; diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index b44dc5b0dcf..49371bb8cea 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -45,7 +45,7 @@ SkeletonData* SpineWasmUtil::querySpineSkeletonDataByUUID(const std::string& uui SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const std::string& jsonStr, const std::string& altasStr) { #if ENABLE_JSON_PARSER - auto* atlas = new Atlas(altasStr.c_str(), altasStr.size(), "", nullptr, false); + auto* atlas = new Atlas(altasStr.c_str(), altasStr.size(), "", nullptr, false); if (!atlas) { return nullptr; } From bf6072346a612fdf8ff53b90464a3b14eb4814cf Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 10:53:20 +0800 Subject: [PATCH 25/80] Add ENABLE_BINARY_PARSER and fix the binding of addAnimationWith --- .../editor-support/spine-wasm/CMakeLists.txt | 8 +++-- .../spine-wasm/spine-type-export.cpp | 32 ++++++++++++------- .../editor-support/spine-wasm/spine-wasm.cpp | 4 +++ .../cocos/editor-support/spine/SpineObject.h | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index 53b1ee84cf8..3c7a8216ea3 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -3,7 +3,8 @@ cmake_minimum_required(VERSION 3.8) set(CMAKE_VERBOSE_MAKEFILE ON) set(BUILD_WASM 1) -set(ENABLE_JSON_PARSER 0) +set(ENABLE_JSON_PARSER 1) +set(ENABLE_BINARY_PARSER 1) set(DEBUG_NEW 0) set(CMAKE_BUILD_TYPE "MinSizeRel") @@ -22,14 +23,15 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DDEBUG_NEW=${DEBUG_NEW}") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER} -DDEBUG_NEW=${DEBUG_NEW}") message(">>> --------------------------------------------------------------") message(">>> Current directory: ${CMAKE_CURRENT_LIST_DIR}") message(">>> CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(">>> ENABLE_CLOSURE_COMPILER: ${ENABLE_CLOSURE_COMPILER}") message(">>> ENABLE_JSON_PARSER: ${ENABLE_JSON_PARSER}") +message(">>> ENABLE_BINARY_PARSER: ${ENABLE_BINARY_PARSER}") message(">>> DEBUG_NEW: ${DEBUG_NEW}") message(">>> --------------------------------------------------------------") diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 7b1e6c19a8e..872a092581b 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "spine-skeleton-instance.h" @@ -249,8 +250,8 @@ using SPVectorPathConstraintPtr = Vector; using SPVectorTimelinePtr = Vector; using SPVectorTrackEntryPtr = Vector; using SPVectorUpdatablePtr = Vector; -using SPVectorSkinEntry = Vector; -using SPVectorVectorSkinEntry = Vector; +using SPVectorSkinEntryPtr = Vector; +using SPVectorVectorSkinEntryPtr = Vector; template void registerSpineInteger(const char* name) { @@ -568,8 +569,8 @@ EMSCRIPTEN_BINDINGS(spine) { REGISTER_SPINE_VECTOR(SPVectorTimelinePtr, true); // .set used in Animation constructor REGISTER_SPINE_VECTOR(SPVectorTrackEntryPtr, false); REGISTER_SPINE_VECTOR(SPVectorUpdatablePtr, false); - REGISTER_SPINE_VECTOR(SPVectorSkinEntry, false); - REGISTER_SPINE_VECTOR(SPVectorVectorSkinEntry, false); + REGISTER_SPINE_VECTOR(SPVectorSkinEntryPtr, false); + REGISTER_SPINE_VECTOR(SPVectorVectorSkinEntryPtr, false); class_("Vector2") .constructor<>() @@ -1001,7 +1002,7 @@ EMSCRIPTEN_BINDINGS(spine) { .property("color", GETTER_RVAL_TO_PTR(Slot, getColor, Color*)) .property("darkColor", GETTER_RVAL_TO_PTR(Slot, getDarkColor, Color*)) .function("getDeform", &Slot::getDeform, allow_raw_pointers()) - .property("skeleton", GETTER_RVAL_TO_PTR(Slot, getSkeleton, Skeleton*)) + .function("getSkeleton", GETTER_RVAL_TO_PTR(Slot, getSkeleton, Skeleton*)) .function("getAttachment", &Slot::getAttachment, allow_raw_pointers()) .function("setAttachment", &Slot::setAttachment, allow_raw_pointers()) .function("setAttachmentTime", &Slot::setAttachmentTime) @@ -1020,7 +1021,6 @@ EMSCRIPTEN_BINDINGS(spine) { .function("copySkin", select_overload(&Skin::copySkin), allow_raw_pointers()) .function("findNamesForSlot", optional_override([](Skin &obj, size_t slotIndex) { std::vector vetNames; - std::vector entriesVector; auto entries = obj.getAttachments(); while (entries.hasNext()) { Skin::AttachmentMap::Entry &entry = entries.next(); @@ -1030,20 +1030,20 @@ EMSCRIPTEN_BINDINGS(spine) { }), allow_raw_pointers()) .function("getAttachment", &Skin::getAttachment, allow_raw_pointers()) .function("getAttachments", optional_override([](Skin &obj) { - std::vector entriesVector; + SPVectorSkinEntryPtr entriesVector; auto entries = obj.getAttachments(); while (entries.hasNext()) { - entriesVector.push_back(&entries.next()); + entriesVector.add(&entries.next()); } return entriesVector; }),allow_raw_pointers()) .function("removeAttachment", &Skin::removeAttachment) .function("getAttachmentsForSlot", optional_override([](Skin &obj, size_t index) { - std::vector entriesVector; + SPVectorSkinEntryPtr entriesVector; auto entries = obj.getAttachments(); while (entries.hasNext()) { Skin::AttachmentMap::Entry &entry = entries.next(); - if (entry._slotIndex == index) entriesVector.push_back(&entry); + if (entry._slotIndex == index) entriesVector.add(&entry); } return entriesVector; }),allow_raw_pointers()); @@ -1107,7 +1107,15 @@ EMSCRIPTEN_BINDINGS(spine) { .function("findPathConstraintIndex", &SkeletonData::findPathConstraintIndex); class_("Animation") - .constructor &, float>() + .constructor(optional_override([](const String &name, const emscripten::val &value, float duration) -> Animation* { + auto length = value["length"].as(); + Vector timelines; + timelines.setSize(length, nullptr); + for (uint32_t i = 0; i < length; ++i) { + timelines[i] = value[i].as(allow_raw_pointers()); + } + return new Animation(name, timelines, duration); + })) .property("name", &Animation::getName) .function("getTimelines", optional_override([](Animation &obj) { return &obj.getTimelines(); }), allow_raw_pointer()) @@ -1297,7 +1305,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setAnimation", select_overload(&AnimationState::setAnimation), allow_raw_pointers()) .function("setAnimationWith", optional_override([](AnimationState &obj, uint32_t trackIndex, Animation *animation, bool loop) { return obj.setAnimation(trackIndex, animation, loop); }), allow_raw_pointers()) .function("addAnimation", select_overload(&AnimationState::addAnimation), allow_raw_pointers()) - .function("addAnimationWith", select_overload(&AnimationState::addAnimation), allow_raw_pointers()) + .function("addAnimationWith", select_overload(&AnimationState::addAnimation), allow_raw_pointers()) .function("setEmptyAnimation", &AnimationState::setEmptyAnimation, allow_raw_pointers()) .function("addEmptyAnimation", &AnimationState::addEmptyAnimation, allow_raw_pointers()) .function("setEmptyAnimations", &AnimationState::setEmptyAnimations) diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index 49371bb8cea..b43dc8b9d00 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -61,6 +61,7 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const std::string& } SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize, const std::string& altasStr) { +#if ENABLE_BINARY_PARSER auto* atlas = new Atlas(altasStr.c_str(), altasStr.size(), "", nullptr, false); if (!atlas) { return nullptr; @@ -70,6 +71,9 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize binary.setScale(1.0F); SkeletonData* skeletonData = binary.readSkeletonData(s_mem, byteSize); return skeletonData; +#else + return nullptr; +#endif } void SpineWasmUtil::registerSpineSkeletonDataWithUUID(SkeletonData* data, const std::string& uuid) { diff --git a/native/cocos/editor-support/spine/SpineObject.h b/native/cocos/editor-support/spine/SpineObject.h index 5c08549b691..594c3a60e4c 100644 --- a/native/cocos/editor-support/spine/SpineObject.h +++ b/native/cocos/editor-support/spine/SpineObject.h @@ -63,7 +63,7 @@ class SP_API SpineObject { #else #define __SPINE_FILE__ "" #define __SPINE_LINE__ __LINE__ - #define spine_new new + #define spine_new new ("", 0) #endif #endif From c8233164bc4ba587764eadf193dc39a3107bf31d Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 10:53:41 +0800 Subject: [PATCH 26/80] Check whether skin name is valid. --- cocos/spine/skeleton.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 415094e3a8e..e65cda2573a 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -924,7 +924,7 @@ export class Skeleton extends UIRenderer { let cache = this._skeletonCache.getAnimationCache(this._skeletonData!.uuid, name); if (!cache) { cache = this._skeletonCache.initAnimationCache(this.skeletonData!.uuid, this._skeletonData!, name); - cache?.setSkin(this._skinName); + if (cache && this._skinName) cache.setSkin(this._skinName); } if (cache) { this._animationName = name; From bf87c3d01809c30ae40895d90b0be2dffb226cd8 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 11:31:55 +0800 Subject: [PATCH 27/80] Use malloc/free to implement WasmSpineExtension. --- .../spine-wasm/wasmSpineExtension.cpp | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp index 2a9858e7670..5f85ac3c232 100644 --- a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp +++ b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp @@ -30,33 +30,36 @@ void *WasmSpineExtension::_alloc(size_t size, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); - if (size == 0) - return 0; - void *ptr = new uint8_t[size]; - return (void *)ptr; + if (size == 0) { + return nullptr; + } + return ::malloc(sizeof(uint8_t) * size); } void *WasmSpineExtension::_calloc(size_t size, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); - if (size == 0) - return 0; - uint8_t *ptr = new uint8_t[size]; - if (ptr) memset(ptr, 0, size); - return (void *)ptr; + if (size == 0) { + return nullptr; + } + const size_t bytes = sizeof(uint8_t) * size; + uint8_t *ptr = static_cast(::malloc(bytes)); + if (ptr) memset(ptr, 0, bytes); + return ptr; } void *WasmSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); - if (size == 0) - return 0; - uint8_t *mem = new uint8_t[size]; - memcpy(mem, ptr, size); - delete[](char *) ptr; - ptr = mem; + if (size == 0) { + return nullptr; + } + const size_t bytes = sizeof(uint8_t) * size; + uint8_t *mem = static_cast(::malloc(bytes)); + if (mem) memset(mem, 0, bytes); + ::free(ptr); return mem; } @@ -64,7 +67,7 @@ void WasmSpineExtension::_free(void *mem, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); - delete[](char *) mem; + ::free(mem); } SpineExtension *spine::getDefaultExtension() { From 865a444d16f897aea466a95c8ff8f43dabc45472 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 11:32:21 +0800 Subject: [PATCH 28/80] update spine_new --- native/cocos/editor-support/spine/SpineObject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/editor-support/spine/SpineObject.h b/native/cocos/editor-support/spine/SpineObject.h index 594c3a60e4c..5c08549b691 100644 --- a/native/cocos/editor-support/spine/SpineObject.h +++ b/native/cocos/editor-support/spine/SpineObject.h @@ -63,7 +63,7 @@ class SP_API SpineObject { #else #define __SPINE_FILE__ "" #define __SPINE_LINE__ __LINE__ - #define spine_new new ("", 0) + #define spine_new new #endif #endif From e1308118a6d95bff68ac1d3f7d9e9ab4cd263c89 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 12:28:34 +0800 Subject: [PATCH 29/80] virtual function, isActive, setActive --- .../spine-wasm/spine-type-export.cpp | 19 +++++-------------- native/cocos/editor-support/spine/Bone.h | 6 +++--- .../cocos/editor-support/spine/Constraint.h | 2 -- .../cocos/editor-support/spine/IkConstraint.h | 6 +++--- .../editor-support/spine/PathConstraint.h | 6 +++--- .../spine/TransformConstraint.h | 6 +++--- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 872a092581b..402eaf5033e 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -845,7 +845,9 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Updatable") .function("update", &Updatable::update, pure_virtual()) - .function("isActive", &Updatable::isActive, pure_virtual()); + .function("isActive", &Updatable::isActive, pure_virtual()) + .property("active", &Updatable::isActive, &Updatable::setActive) + ; class_>("IkConstraint") .constructor() @@ -858,9 +860,6 @@ EMSCRIPTEN_BINDINGS(spine) { .property("stretch", &IkConstraint::getStretch, &IkConstraint::setStretch) .property("mix", &IkConstraint::getMix, &IkConstraint::setMix) .property("softness", &IkConstraint::getSoftness, &IkConstraint::setSoftness) - .property("active", &IkConstraint::isActive, &IkConstraint::setActive) - .function("isActive", &IkConstraint::isActive) - .function("update", &IkConstraint::update) .class_function("apply1", optional_override([]( IkConstraint &obj, Bone &bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha){ @@ -882,9 +881,7 @@ EMSCRIPTEN_BINDINGS(spine) { .property("spacing", &PathConstraint::getSpacing, &PathConstraint::setSpacing) .property("rotateMix", &PathConstraint::getRotateMix, &PathConstraint::setRotateMix) .property("translateMix", &PathConstraint::getTranslateMix, &PathConstraint::setTranslateMix) - .property("active", &PathConstraint::isActive, &PathConstraint::setActive) - .function("isActive", &PathConstraint::isActive) - .function("update", &PathConstraint::update); + ; class_>("TransformConstraintData") .constructor() @@ -914,9 +911,7 @@ EMSCRIPTEN_BINDINGS(spine) { .property("translateMix", &TransformConstraint::getTranslateMix, &TransformConstraint::setTranslateMix) .property("scaleMix", &TransformConstraint::getScaleMix, &TransformConstraint::setScaleMix) .property("shearMix", &TransformConstraint::getShearMix, &TransformConstraint::setShearMix) - .property("active", &TransformConstraint::isActive, &TransformConstraint::setActive) - .function("isActive", &TransformConstraint::isActive) - .function("update", &TransformConstraint::update); + ; class_>("Bone") .constructor() @@ -946,11 +941,7 @@ EMSCRIPTEN_BINDINGS(spine) { .property("d", &Bone::getD, &Bone::setD) .property("worldX", &Bone::getWorldX, &Bone::setWorldX) .property("worldY", &Bone::getWorldY, &Bone::setWorldY) - .property("active", &Bone::isActive, &Bone::setActive) - .function("isActive", &Bone::isActive) - .function("update", &Bone::update) - .function("updateWorldTransform", select_overload(&Bone::updateWorldTransform)) .function("updateWorldTransformWith", select_overload(&Bone::updateWorldTransform)) .function("setToSetupPose", &Bone::setToSetupPose) diff --git a/native/cocos/editor-support/spine/Bone.h b/native/cocos/editor-support/spine/Bone.h index 5e3b81f4d11..3ad356bf73f 100644 --- a/native/cocos/editor-support/spine/Bone.h +++ b/native/cocos/editor-support/spine/Bone.h @@ -80,7 +80,7 @@ class SP_API Bone : public Updatable { Bone(BoneData &data, Skeleton &skeleton, Bone *parent = NULL); /// Same as updateWorldTransform. This method exists for Bone to implement Spine::Updatable. - virtual void update(); + void update() override; /// Computes the world transform using the parent bone and this bone's local transform. void updateWorldTransform(); @@ -221,9 +221,9 @@ class SP_API Bone : public Updatable { bool isAppliedValid(); void setAppliedValid(bool valid); - bool isActive(); + bool isActive() override; - void setActive(bool inValue); + void setActive(bool inValue) override; private: static bool yDown; diff --git a/native/cocos/editor-support/spine/Constraint.h b/native/cocos/editor-support/spine/Constraint.h index b3f6875fd45..462a4b2ae07 100644 --- a/native/cocos/editor-support/spine/Constraint.h +++ b/native/cocos/editor-support/spine/Constraint.h @@ -43,8 +43,6 @@ class SP_API Constraint : public Updatable { virtual ~Constraint(); - virtual void update() = 0; - /// The ordinal for the order a skeleton's constraints will be applied. virtual int getOrder() = 0; }; diff --git a/native/cocos/editor-support/spine/IkConstraint.h b/native/cocos/editor-support/spine/IkConstraint.h index 5fb217a9bf8..29578200bed 100644 --- a/native/cocos/editor-support/spine/IkConstraint.h +++ b/native/cocos/editor-support/spine/IkConstraint.h @@ -63,7 +63,7 @@ class SP_API IkConstraint : public Updatable { /// Applies the constraint to the constrained bones. void apply(); - virtual void update(); + void update() override; virtual int getOrder(); @@ -95,9 +95,9 @@ class SP_API IkConstraint : public Updatable { void setSoftness(float inValue); - bool isActive(); + bool isActive() override; - void setActive(bool inValue); + void setActive(bool inValue) override; private: IkConstraintData &_data; diff --git a/native/cocos/editor-support/spine/PathConstraint.h b/native/cocos/editor-support/spine/PathConstraint.h index f8fb569b3e7..6fdda994986 100644 --- a/native/cocos/editor-support/spine/PathConstraint.h +++ b/native/cocos/editor-support/spine/PathConstraint.h @@ -55,7 +55,7 @@ class SP_API PathConstraint : public Updatable { /// Applies the constraint to the constrained bones. void apply(); - virtual void update(); + void update() override; virtual int getOrder(); @@ -78,9 +78,9 @@ class SP_API PathConstraint : public Updatable { PathConstraintData& getData(); - bool isActive(); + bool isActive() override; - void setActive(bool inValue); + void setActive(bool inValue) override; private: static const float EPSILON; diff --git a/native/cocos/editor-support/spine/TransformConstraint.h b/native/cocos/editor-support/spine/TransformConstraint.h index 625dc8ea1f3..c900cca34dc 100644 --- a/native/cocos/editor-support/spine/TransformConstraint.h +++ b/native/cocos/editor-support/spine/TransformConstraint.h @@ -50,7 +50,7 @@ class SP_API TransformConstraint : public Updatable { void apply(); - virtual void update(); + void update() override; virtual int getOrder(); @@ -73,9 +73,9 @@ class SP_API TransformConstraint : public Updatable { float getShearMix(); void setShearMix(float inValue); - bool isActive(); + bool isActive() override; - void setActive(bool inValue); + void setActive(bool inValue) override; private: TransformConstraintData& _data; From 22b7e19884f32043ea75fecc108c7d401532c66d Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 12:28:47 +0800 Subject: [PATCH 30/80] fix a typo in spine.-core.d.ts --- cocos/spine/lib/spine-core.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/spine/lib/spine-core.d.ts b/cocos/spine/lib/spine-core.d.ts index 0abe29e8027..6bcf725f17e 100644 --- a/cocos/spine/lib/spine-core.d.ts +++ b/cocos/spine/lib/spine-core.d.ts @@ -189,7 +189,7 @@ declare namespace spine { setFrame(frameIndex: number, time: number, drawOrder: Array): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; } - class IkConstraintTimeline extends Updatable { + class IkConstraintTimeline extends CurveTimeline { static readonly ENTRIES: number; frames: ArrayLike; constructor(frameCount: number); From 420e5132502f9106d2c784fa77d9a87ae8ad8dd3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 13:44:51 +0800 Subject: [PATCH 31/80] Use c calloc, malloc, free directly in wasmSpineExtension.cpp --- .../spine-wasm/wasmSpineExtension.cpp | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp index 5f85ac3c232..24e75a26c3a 100644 --- a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp +++ b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp @@ -1,4 +1,5 @@ #include "wasmSpineExtension.h" +#include #include "util-function.h" using namespace spine; @@ -29,44 +30,24 @@ char *WasmSpineExtension::_readFile(const String &path, int *length) { void *WasmSpineExtension::_alloc(size_t size, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); - - if (size == 0) { - return nullptr; - } return ::malloc(sizeof(uint8_t) * size); } void *WasmSpineExtension::_calloc(size_t size, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); - - if (size == 0) { - return nullptr; - } - const size_t bytes = sizeof(uint8_t) * size; - uint8_t *ptr = static_cast(::malloc(bytes)); - if (ptr) memset(ptr, 0, bytes); - return ptr; + return ::calloc(1, size); } void *WasmSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); - - if (size == 0) { - return nullptr; - } - const size_t bytes = sizeof(uint8_t) * size; - uint8_t *mem = static_cast(::malloc(bytes)); - if (mem) memset(mem, 0, bytes); - ::free(ptr); - return mem; + return ::realloc(ptr, sizeof(uint8_t) * size); } void WasmSpineExtension::_free(void *mem, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); - ::free(mem); } From 1a9774e2967c0afe82a724fbbcc0c1ee76fc5fd0 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 13:53:29 +0800 Subject: [PATCH 32/80] Update, use malloc --- .../spine-wasm/spine-mesh-data.cpp | 17 ++++----- .../editor-support/spine-wasm/spine-model.cpp | 35 +++++++++---------- .../editor-support/spine-wasm/spine-model.h | 29 +++++++-------- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-mesh-data.cpp b/native/cocos/editor-support/spine-wasm/spine-mesh-data.cpp index 91cb713f096..6ad0204df3d 100644 --- a/native/cocos/editor-support/spine-wasm/spine-mesh-data.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-mesh-data.cpp @@ -12,22 +12,19 @@ void SpineMeshData::initMeshMemory() { if (vBuf) return; const auto vCount = 65535; const auto byteStride = 7 * sizeof(float); - vBuf = new uint8_t[2 * vCount * byteStride]; - iBuf = new uint16_t[8 * 65535]; + vBuf = static_cast(::malloc(sizeof(uint8_t) * (2 * vCount * byteStride))); // 2 * 64KB * 28 = 3.5MB + iBuf = static_cast(::malloc(sizeof(uint16_t) * (8 * 65535))); // 512KB vPtr = vBuf; iPtr = iBuf; } void SpineMeshData::releaseMeshMemory() { - if (vBuf) { - delete[] vBuf; - vBuf = nullptr; - } - if (iBuf) { - delete[] iBuf; - iBuf = nullptr; - } + ::free(vBuf); + vBuf = nullptr; + + ::free(iBuf); + iBuf = nullptr; } void SpineMeshData::reset() { diff --git a/native/cocos/editor-support/spine-wasm/spine-model.cpp b/native/cocos/editor-support/spine-wasm/spine-model.cpp index b191eca7968..64df206d738 100644 --- a/native/cocos/editor-support/spine-wasm/spine-model.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-model.cpp @@ -1,44 +1,42 @@ #include "spine-model.h" SpineModel::SpineModel() { - SpineModel::data = new std::vector(6, 0); + _data.resize(6, 0); } SpineModel::~SpineModel() { - delete SpineModel::data; - SpineModel::data = nullptr; } void SpineModel::addSlotMesh(SlotMesh& mesh, bool needMerge) { bool canMerge = false; - auto count = data->size(); + auto count = _data.size(); if (needMerge && count > 0) { - if (data->at(count - 2) == mesh.blendMode && data->at(count - 1) == mesh.textureID) { + if (_data.at(count - 2) == mesh.blendMode && _data.at(count - 1) == mesh.textureID) { canMerge = true; - data->at(count-4) += mesh.vCount; - data->at(count-3) += mesh.iCount; + _data.at(count-4) += mesh.vCount; + _data.at(count-3) += mesh.iCount; } } if (!canMerge) { - data->resize(count + 6); - data->at(count) = (uint32_t)mesh.vBuf; - data->at(count + 1) = (uint32_t)mesh.iBuf; - data->at(count + 2) = mesh.vCount; - data->at(count + 3) = mesh.iCount; - data->at(count + 4) = mesh.blendMode; - data->at(count + 5) = mesh.textureID; + _data.resize(count + 6); + _data[count] = (uint32_t)mesh.vBuf; + _data[count + 1] = (uint32_t)mesh.iBuf; + _data[count + 2] = mesh.vCount; + _data[count + 3] = mesh.iCount; + _data[count + 4] = mesh.blendMode; + _data[count + 5] = mesh.textureID; } auto indexCount = mesh.iCount; uint16_t* iiPtr = mesh.iBuf; - for (uint16_t i = 0; i < indexCount; i++) { + for (uint32_t i = 0; i < indexCount; i++) { iiPtr[i] += vCount; } auto vertexCount = mesh.vCount; float* floatPtr = (float*)mesh.vBuf; int floatStride = this->byteStride / 4; - for (int i = 0; i < vertexCount; i++) { + for (uint32_t i = 0; i < vertexCount; i++) { floatPtr[floatStride * i + 2] = 0; } vCount += vertexCount; @@ -46,13 +44,14 @@ void SpineModel::addSlotMesh(SlotMesh& mesh, bool needMerge) { } void SpineModel::clearMeshes() { - data->resize(0); + _data.resize(0); + _data.shrink_to_fit(); vCount = 0; iCount = 0; } std::vector* SpineModel::getData() { - return data; + return &_data; } void SpineModel::setBufferPtr(uint8_t* vp, uint16_t* ip) { diff --git a/native/cocos/editor-support/spine-wasm/spine-model.h b/native/cocos/editor-support/spine-wasm/spine-model.h index a83092a5ee3..266a35d1efe 100644 --- a/native/cocos/editor-support/spine-wasm/spine-model.h +++ b/native/cocos/editor-support/spine-wasm/spine-model.h @@ -4,7 +4,7 @@ #include class SlotMesh { public: - SlotMesh() {} + SlotMesh() = default; SlotMesh(uint8_t* vb, uint16_t* ib, uint32_t vc, uint32_t ic) : vBuf(vb), iBuf(ib), vCount(vc), iCount(ic) {} ~SlotMesh() {} @@ -15,12 +15,12 @@ class SlotMesh { this->vCount = vc; this->iCount = ic; } - uint8_t* vBuf; - uint16_t* iBuf; - uint32_t vCount; - uint32_t iCount; - uint32_t blendMode; - uint32_t textureID; + uint8_t* vBuf{}; + uint16_t* iBuf{}; + uint32_t vCount{}; + uint32_t iCount{}; + uint32_t blendMode{}; + uint32_t textureID{}; }; class SpineModel { @@ -30,13 +30,14 @@ class SpineModel { void addSlotMesh(SlotMesh& mesh, bool needMerge = true); void clearMeshes(); void setBufferPtr(uint8_t* vp, uint16_t* ip); - std::vector* data; + std::vector* getData(); - +private: + std::vector _data; public: - uint32_t vCount; - uint32_t iCount; - uint32_t vPtr; - uint32_t iPtr; - uint32_t byteStride; + uint32_t vCount{}; + uint32_t iCount{}; + uint32_t vPtr{}; + uint32_t iPtr{}; + uint32_t byteStride{}; }; From 6bb7eed308ad265abf3b5027eab7657fc36c2710 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 13:53:41 +0800 Subject: [PATCH 33/80] Update CMakeLists.txt --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index 3c7a8216ea3..fa42a209c1a 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -24,7 +24,9 @@ set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER} -DDEBUG_NEW=${DEBUG_NEW}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override \ + -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER} \ + -DDEBUG_NEW=${DEBUG_NEW}") message(">>> --------------------------------------------------------------") message(">>> Current directory: ${CMAKE_CURRENT_LIST_DIR}") From 782766d83804edd29149825ea9b4ecda9c374c56 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 14:36:42 +0800 Subject: [PATCH 34/80] Update getPropertyId binding, fix AttachmentTimeline::getFrames binding --- .../spine-wasm/spine-type-export.cpp | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 402eaf5033e..471d4d2823f 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1117,7 +1117,6 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getPropertyId", &Timeline::getPropertyId, pure_virtual()); class_>("CurveTimeline") - .function("getPropertyId", &CurveTimeline::getPropertyId, pure_virtual()) .function("getFrameCount", &CurveTimeline::getFrameCount) .function("setLinear", &CurveTimeline::setLinear) .function("setStepped", &CurveTimeline::setStepped) @@ -1128,24 +1127,21 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("TranslateTimeline") .constructor() .class_property("ENTRIES", &TranslateTimeline::ENTRIES) - .function("getPropertyId", &TranslateTimeline::getPropertyId) .function("setFrame", &TranslateTimeline::setFrame); class_>("ScaleTimeline") .constructor() - .function("getPropertyId", &ScaleTimeline::getPropertyId); + ; class_>("ShearTimeline") .constructor() - .function("getPropertyId", &ShearTimeline::getPropertyId); + ; class_>("RotateTimeline") .constructor() //.class_property("ENTRIES", &RotateTimeline::ENTRIES) not bind .property("boneIndex", &RotateTimeline::getBoneIndex, &RotateTimeline::setBoneIndex) - .function("getFrames", optional_override([](RotateTimeline &obj) { - return &obj.getFrames(); }), allow_raw_pointer()) - .function("getPropertyId", &RotateTimeline::getPropertyId) + .function("getFrames", GETTER_RVAL_TO_PTR(RotateTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("setFrame", &RotateTimeline::setFrame); class_>("ColorTimeline") @@ -1153,25 +1149,20 @@ EMSCRIPTEN_BINDINGS(spine) { .class_property("ENTRIES", &ColorTimeline::ENTRIES) .property("slotIndex", &ColorTimeline::getSlotIndex, &ColorTimeline::setSlotIndex) - .function("getFrames", optional_override([](ColorTimeline &obj) { - return &obj.getFrames(); }), allow_raw_pointer()) - .function("getPropertyId", &ColorTimeline::getPropertyId) + .function("getFrames", GETTER_RVAL_TO_PTR(ColorTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("setFrame", &ColorTimeline::setFrame); class_>("TwoColorTimeline") .constructor() .class_property("ENTRIES", &ColorTimeline::ENTRIES) .property("slotIndex", &TwoColorTimeline::getSlotIndex, &TwoColorTimeline::setSlotIndex) - .function("getPropertyId", &TwoColorTimeline::getPropertyId) .function("setFrame", &TwoColorTimeline::setFrame); class_>("AttachmentTimeline") .constructor() .property("slotIndex", &AttachmentTimeline::getSlotIndex, &AttachmentTimeline::setSlotIndex) - .function("getFrames", optional_override([](AttachmentTimeline &obj) { - return &obj.getFrames(); }), allow_raw_pointer()) + .function("getFrames", GETTER_RVAL_TO_PTR(AttachmentTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("getAttachmentNames", &AttachmentTimeline::getAttachmentNames) - .function("getPropertyId", &AttachmentTimeline::getPropertyId) .function("getFrameCount", &AttachmentTimeline::getFrameCount) .function("setFrame", &AttachmentTimeline::setFrame, allow_raw_pointers()); @@ -1179,11 +1170,9 @@ EMSCRIPTEN_BINDINGS(spine) { .constructor() .property("slotIndex", &DeformTimeline::getSlotIndex, &DeformTimeline::setSlotIndex) .property("attachment", &DeformTimeline::getAttachment, &DeformTimeline::setAttachment) - .function("getFrames", optional_override([](DeformTimeline &obj) { - return &obj.getFrames(); }), allow_raw_pointer()) + .function("getFrames", GETTER_RVAL_TO_PTR(DeformTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("getFrameVertices", optional_override([](DeformTimeline &obj) { return &obj.getVertices(); }), allow_raw_pointer()) - .function("getPropertyId", &DeformTimeline::getPropertyId) .function("setFrame", optional_override([](DeformTimeline &obj, int frameIndex, float time, emscripten::val jsArray){ unsigned count = jsArray["length"].as(); Vector spVertices; @@ -1196,19 +1185,15 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("EventTimeline") .constructor() - .function("getFrames", optional_override([](EventTimeline &obj) { - return &obj.getFrames(); }), allow_raw_pointer()) + .function("getFrames", GETTER_RVAL_TO_PTR(EventTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("getEvents", optional_override([](EventTimeline &obj) { return &obj.getEvents(); }), allow_raw_pointer()) - .function("getPropertyId", &EventTimeline::getPropertyId) .function("getFrameCount", &EventTimeline::getFrameCount) .function("setFrame", &EventTimeline::setFrame, allow_raw_pointers()); class_>("DrawOrderTimeline") .constructor() - .function("getFrames", optional_override([](DrawOrderTimeline &obj) { - return &obj.getFrames(); }), allow_raw_pointer()) - .function("getPropertyId", &DrawOrderTimeline::getPropertyId) + .function("getFrames", GETTER_RVAL_TO_PTR(DrawOrderTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("getFrameCount", &DrawOrderTimeline::getFrameCount) .function("getDrawOrders", optional_override([](DrawOrderTimeline &obj) { return &obj.getDrawOrders(); }), allow_raw_pointer()) @@ -1217,25 +1202,22 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("IkConstraintTimeline") .constructor() .class_property("ENTRIES", &IkConstraintTimeline::ENTRIES) - .function("getPropertyId", &IkConstraintTimeline::getPropertyId) .function("setFrame", &IkConstraintTimeline::setFrame); class_>("TransformConstraintTimeline") .constructor() .class_property("ENTRIES", &TransformConstraintTimeline::ENTRIES) - .function("getPropertyId", &TransformConstraintTimeline::getPropertyId) .function("setFrame", &TransformConstraintTimeline::setFrame); class_>("PathConstraintPositionTimeline") .constructor() .class_property("ENTRIES", &TransformConstraintTimeline::ENTRIES) - .function("getPropertyId", &PathConstraintPositionTimeline::getPropertyId) .function("setFrame", &PathConstraintPositionTimeline::setFrame); class_>("PathConstraintMixTimeline") .constructor() .class_property("ENTRIES", &PathConstraintMixTimeline::ENTRIES) - .function("getPropertyId", &PathConstraintMixTimeline::getPropertyId); + ; class_("TrackEntry") .constructor<>() From 7a357976a205375dc9a5dc5ca42f7a4cf83aeb88 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 14:37:05 +0800 Subject: [PATCH 35/80] Remove unused virtual getPropertyId in CurveTimeline.h --- native/cocos/editor-support/spine/CurveTimeline.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/native/cocos/editor-support/spine/CurveTimeline.h b/native/cocos/editor-support/spine/CurveTimeline.h index cacb2860ac2..d00ff92a8c5 100644 --- a/native/cocos/editor-support/spine/CurveTimeline.h +++ b/native/cocos/editor-support/spine/CurveTimeline.h @@ -45,8 +45,6 @@ class SP_API CurveTimeline : public Timeline { virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction) = 0; - virtual int getPropertyId() = 0; - size_t getFrameCount(); void setLinear(size_t frameIndex); From 500e72ea15b6317118efabebb6eeccad6e31cabe Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 14:43:11 +0800 Subject: [PATCH 36/80] Revert SkeletonJson.h/.cpp --- native/cocos/editor-support/spine/SkeletonJson.cpp | 4 ---- native/cocos/editor-support/spine/SkeletonJson.h | 4 ---- 2 files changed, 8 deletions(-) diff --git a/native/cocos/editor-support/spine/SkeletonJson.cpp b/native/cocos/editor-support/spine/SkeletonJson.cpp index 3e2f20d77bc..25db058d251 100644 --- a/native/cocos/editor-support/spine/SkeletonJson.cpp +++ b/native/cocos/editor-support/spine/SkeletonJson.cpp @@ -27,8 +27,6 @@ * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -#if 1//ENABLE_JSON_PARSER - #ifdef SPINE_UE4 #include "SpinePluginPrivatePCH.h" #endif @@ -1260,5 +1258,3 @@ void SkeletonJson::setError(Json *root, const String &value1, const String &valu _error = String(value1).append(value2); delete root; } - -#endif // ENABLE_JSON_PARSER diff --git a/native/cocos/editor-support/spine/SkeletonJson.h b/native/cocos/editor-support/spine/SkeletonJson.h index 2194262efa7..3aa87077357 100644 --- a/native/cocos/editor-support/spine/SkeletonJson.h +++ b/native/cocos/editor-support/spine/SkeletonJson.h @@ -30,8 +30,6 @@ #ifndef Spine_SkeletonJson_h #define Spine_SkeletonJson_h -#if 1//ENABLE_JSON_PARSER - #include #include #include @@ -90,6 +88,4 @@ class SP_API SkeletonJson : public SpineObject { }; } // namespace spine -#endif // ENABLE_JSON_PARSER - #endif /* Spine_SkeletonJson_h */ From 0dcd70d8ff2a7d80f27c70742be17c4f543111dd Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 14:45:21 +0800 Subject: [PATCH 37/80] Revert override -> virtual for spine runtime, it may support lower version c++. --- native/cocos/editor-support/spine/Bone.h | 6 +++--- native/cocos/editor-support/spine/IkConstraint.h | 6 +++--- native/cocos/editor-support/spine/PathConstraint.h | 6 +++--- native/cocos/editor-support/spine/TransformConstraint.h | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/native/cocos/editor-support/spine/Bone.h b/native/cocos/editor-support/spine/Bone.h index 3ad356bf73f..593d65cd10a 100644 --- a/native/cocos/editor-support/spine/Bone.h +++ b/native/cocos/editor-support/spine/Bone.h @@ -80,7 +80,7 @@ class SP_API Bone : public Updatable { Bone(BoneData &data, Skeleton &skeleton, Bone *parent = NULL); /// Same as updateWorldTransform. This method exists for Bone to implement Spine::Updatable. - void update() override; + virtual void update(); /// Computes the world transform using the parent bone and this bone's local transform. void updateWorldTransform(); @@ -221,9 +221,9 @@ class SP_API Bone : public Updatable { bool isAppliedValid(); void setAppliedValid(bool valid); - bool isActive() override; + virtual bool isActive(); - void setActive(bool inValue) override; + virtual void setActive(bool inValue);; private: static bool yDown; diff --git a/native/cocos/editor-support/spine/IkConstraint.h b/native/cocos/editor-support/spine/IkConstraint.h index 29578200bed..55cb6637744 100644 --- a/native/cocos/editor-support/spine/IkConstraint.h +++ b/native/cocos/editor-support/spine/IkConstraint.h @@ -63,7 +63,7 @@ class SP_API IkConstraint : public Updatable { /// Applies the constraint to the constrained bones. void apply(); - void update() override; + virtual void update(); virtual int getOrder(); @@ -95,9 +95,9 @@ class SP_API IkConstraint : public Updatable { void setSoftness(float inValue); - bool isActive() override; + virtual bool isActive(); - void setActive(bool inValue) override; + virtual void setActive(bool inValue);; private: IkConstraintData &_data; diff --git a/native/cocos/editor-support/spine/PathConstraint.h b/native/cocos/editor-support/spine/PathConstraint.h index 6fdda994986..289bd3c0ae2 100644 --- a/native/cocos/editor-support/spine/PathConstraint.h +++ b/native/cocos/editor-support/spine/PathConstraint.h @@ -55,7 +55,7 @@ class SP_API PathConstraint : public Updatable { /// Applies the constraint to the constrained bones. void apply(); - void update() override; + virtual void update(); virtual int getOrder(); @@ -78,9 +78,9 @@ class SP_API PathConstraint : public Updatable { PathConstraintData& getData(); - bool isActive() override; + virtual bool isActive(); - void setActive(bool inValue) override; + virtual void setActive(bool inValue);; private: static const float EPSILON; diff --git a/native/cocos/editor-support/spine/TransformConstraint.h b/native/cocos/editor-support/spine/TransformConstraint.h index c900cca34dc..dcdf2fce83c 100644 --- a/native/cocos/editor-support/spine/TransformConstraint.h +++ b/native/cocos/editor-support/spine/TransformConstraint.h @@ -50,7 +50,7 @@ class SP_API TransformConstraint : public Updatable { void apply(); - void update() override; + virtual void update(); virtual int getOrder(); @@ -73,9 +73,9 @@ class SP_API TransformConstraint : public Updatable { float getShearMix(); void setShearMix(float inValue); - bool isActive() override; + virtual bool isActive(); - void setActive(bool inValue) override; + virtual void setActive(bool inValue);; private: TransformConstraintData& _data; From fccaca22314adeb425f3aeaa10e922b0d706bbd2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 15:47:27 +0800 Subject: [PATCH 38/80] Fix property binding by mistake. --- native/cocos/editor-support/spine-wasm/spine-type-export.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 471d4d2823f..5a90831570d 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1330,8 +1330,8 @@ EMSCRIPTEN_BINDINGS(spine) { return &obj.getPathConstraints(); }), allow_raw_pointer()) .function("getUpdateCacheList", optional_override([](Skeleton &obj){ return &obj.getUpdateCacheList(); }), allow_raw_pointer()) - .property("getSkin", &Skeleton::getSkin) - .property("getColor", GETTER_RVAL_TO_PTR(Skeleton, getColor, Color*)) + .property("skin", &Skeleton::getSkin) + .property("color", GETTER_RVAL_TO_PTR(Skeleton, getColor, Color*)) .property("time", &Skeleton::getTime, &Skeleton::setTime) .property("scaleX", &Skeleton::getScaleX, &Skeleton::setScaleX) .property("scaleY", &Skeleton::getScaleY, &Skeleton::setScaleY) From 08cb4ab967dbfab5abc3577a2409450a79e676a2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 15:47:49 +0800 Subject: [PATCH 39/80] Using spine::Vector instead. --- .../editor-support/spine-wasm/spine-model.cpp | 15 +- .../editor-support/spine-wasm/spine-model.h | 5 +- .../spine-wasm/spine-skeleton-instance.cpp | 4 +- .../spine-wasm/spine-skeleton-instance.h | 4 +- .../spine-wasm/spine-type-export.cpp | 159 +++++------------- 5 files changed, 58 insertions(+), 129 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-model.cpp b/native/cocos/editor-support/spine-wasm/spine-model.cpp index 64df206d738..e44fc15a492 100644 --- a/native/cocos/editor-support/spine-wasm/spine-model.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-model.cpp @@ -1,7 +1,7 @@ #include "spine-model.h" SpineModel::SpineModel() { - _data.resize(6, 0); + _data.setSize(6, 0); } SpineModel::~SpineModel() { @@ -11,14 +11,14 @@ void SpineModel::addSlotMesh(SlotMesh& mesh, bool needMerge) { bool canMerge = false; auto count = _data.size(); if (needMerge && count > 0) { - if (_data.at(count - 2) == mesh.blendMode && _data.at(count - 1) == mesh.textureID) { + if (_data[count - 2] == mesh.blendMode && _data[count - 1] == mesh.textureID) { canMerge = true; - _data.at(count-4) += mesh.vCount; - _data.at(count-3) += mesh.iCount; + _data[count-4] += mesh.vCount; + _data[count-3] += mesh.iCount; } } if (!canMerge) { - _data.resize(count + 6); + _data.setSize(count + 6, 0); _data[count] = (uint32_t)mesh.vBuf; _data[count + 1] = (uint32_t)mesh.iBuf; _data[count + 2] = mesh.vCount; @@ -44,13 +44,12 @@ void SpineModel::addSlotMesh(SlotMesh& mesh, bool needMerge) { } void SpineModel::clearMeshes() { - _data.resize(0); - _data.shrink_to_fit(); + _data.setSize(0, 0); vCount = 0; iCount = 0; } -std::vector* SpineModel::getData() { +spine::Vector* SpineModel::getData() { return &_data; } diff --git a/native/cocos/editor-support/spine-wasm/spine-model.h b/native/cocos/editor-support/spine-wasm/spine-model.h index 266a35d1efe..6921fd592e9 100644 --- a/native/cocos/editor-support/spine-wasm/spine-model.h +++ b/native/cocos/editor-support/spine-wasm/spine-model.h @@ -1,7 +1,6 @@ #pragma once #include -#include class SlotMesh { public: SlotMesh() = default; @@ -31,9 +30,9 @@ class SpineModel { void clearMeshes(); void setBufferPtr(uint8_t* vp, uint16_t* ip); - std::vector* getData(); + spine::Vector* getData(); private: - std::vector _data; + spine::Vector _data; public: uint32_t vCount{}; uint32_t iCount{}; diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index 1345608dd7b..d167f777bdc 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -361,7 +361,7 @@ void SpineSkeletonInstance::collectMeshData() { debugShape.vCount = currMesh.vCount; debugShape.iOffset = _model->iCount; debugShape.iCount = currMesh.iCount; - _debugShapes.push_back(debugShape); + _debugShapes.add(debugShape); } currMesh.blendMode = static_cast(slot->getData().getBlendMode()); @@ -448,7 +448,7 @@ void SpineSkeletonInstance::onAnimationStateEvent(TrackEntry *entry, EventType t } } -std::vector &SpineSkeletonInstance::getDebugShapes() { +Vector &SpineSkeletonInstance::getDebugShapes() { return this->_debugShapes; } diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index 926d2067d93..76b5951e88f 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -53,7 +53,7 @@ class SpineSkeletonInstance { void setTrackEntryListener(uint32_t trackId, spine::TrackEntry *entry); void onAnimationStateEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); void onTrackEntryEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); - std::vector &getDebugShapes(); + spine::Vector &getDebugShapes(); void resizeSlotRegion(const std::string &slotName, uint32_t width, uint32_t height, bool createNew = false); void setSlotTexture(const std::string &slotName, uint32_t index); void destroy(); @@ -74,7 +74,7 @@ class SpineSkeletonInstance { uint32_t _eventListenerID = 0; uint32_t _trackEntryListenerID = 0; UserData _userData; - std::vector _debugShapes{}; + spine::Vector _debugShapes{}; // std::map _slotTextureSet{}; spine::HashMap _slotTextureSet{}; }; diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 5a90831570d..3064d55d09b 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -2,14 +2,42 @@ #include #include #include -#include #include "spine-skeleton-instance.h" #include "spine-wasm.h" #include "Vector2.h" - using namespace spine; +using SPVectorFloat = Vector; +using SPVectorVectorFloat = Vector>; +using SPVectorInt = Vector; +using SPVectorUint = Vector; +using SPVectorVectorInt = Vector>; +using SPVectorSize_t = Vector; +using SPVectorBonePtr = Vector; +using SPVectorBoneDataPtr = Vector; +using SPVectorSlotDataPtr = Vector; +using SPVectorTransformConstraintDataPtr = Vector; +using SPVectorPathConstraintDataPtr = Vector; +using SPVectorUnsignedShort = Vector; +using SPVectorSPString = Vector; +using SPVectorConstraintDataPtr = Vector; +using SPVectorSlotPtr = Vector; +using SPVectorSkinPtr = Vector; +using SPVectorEventDataPtr = Vector; +using SPVectorEventPtr = Vector; +using SPVectorAnimationPtr = Vector; +using SPVectorIkConstraintPtr = Vector; +using SPVectorIkConstraintDataPtr = Vector; +using SPVectorTransformConstraintPtr = Vector; +using SPVectorPathConstraintPtr = Vector; +using SPVectorTimelinePtr = Vector; +using SPVectorTrackEntryPtr = Vector; +using SPVectorUpdatablePtr = Vector; +using SPVectorSkinEntryPtr = Vector; +using SPVectorVectorSkinEntryPtr = Vector; +using SPVectorDebugShape = Vector; + #define DEFINE_ALLOW_RAW_POINTER(type) \ namespace emscripten { namespace internal { \ template<> \ @@ -170,88 +198,10 @@ DEFINE_ALLOW_RAW_POINTER(TrackEntry) DEFINE_ALLOW_RAW_POINTER(IkConstraintData) DEFINE_ALLOW_RAW_POINTER(PathConstraintData) DEFINE_ALLOW_RAW_POINTER(TransformConstraintData) +DEFINE_ALLOW_RAW_POINTER(SPVectorUnsignedShort) +DEFINE_ALLOW_RAW_POINTER(SPVectorFloat) namespace { -// std::string STRING_SP2STD(const spine::String &str) { -// std::string stdStr(str.buffer(), str.length()); -// return stdStr; -// } - -// const String STRING_STD2SP(const std::string &str) { -// const String spString(str.c_str()); -// return spString; -// } - -// const std::vector VECTOR_SP2STD_STRING(Vector &container) { -// int count = container.size(); -// std::vector stdVector(count); -// for (int i = 0; i < count; i++) { -// stdVector[i] = STRING_SP2STD(container[i]); -// } -// return stdVector; -// } - -// template -// Vector VECTOR_STD2SP(std::vector &container) { -// int count = container.size(); -// Vector vecSP; -// vecSP.setSize(count, 0); -// for (int i = 0; i < count; i++) { -// vecSP[i] = container[i]; -// } -// return vecSP; -// } - -// template -// Vector VECTOR_STD2SP_POINTER(std::vector &container) { -// int count = container.size(); -// Vector vecSP = Vector(); -// vecSP.setSize(count, nullptr); -// for (int i = 0; i < count; i++) { -// vecSP[i] = container[i]; -// } -// return vecSP; -// } - -// template -// void VECTOR_STD_COPY_SP(std::vector &stdVector, Vector &spVector) { -// int count = stdVector.size(); -// for (int i = 0; i < count; i++) { -// stdVector[i] = spVector[i]; -// } -// } - -// String* constructorSpineString(emscripten::val name, bool own) { -// return new String(name.as().c_str(), own); -// } - -using SPVectorFloat = Vector; -using SPVectorVectorFloat = Vector>; -using SPVectorInt = Vector; -using SPVectorVectorInt = Vector>; -using SPVectorSize_t = Vector; -using SPVectorBonePtr = Vector; -using SPVectorBoneDataPtr = Vector; -using SPVectorSlotDataPtr = Vector; -using SPVectorTransformConstraintDataPtr = Vector; -using SPVectorPathConstraintDataPtr = Vector; -using SPVectorUnsignedShort = Vector; -using SPVectorSPString = Vector; -using SPVectorConstraintDataPtr = Vector; -using SPVectorSlotPtr = Vector; -using SPVectorSkinPtr = Vector; -using SPVectorEventDataPtr = Vector; -using SPVectorEventPtr = Vector; -using SPVectorAnimationPtr = Vector; -using SPVectorIkConstraintPtr = Vector; -using SPVectorIkConstraintDataPtr = Vector; -using SPVectorTransformConstraintPtr = Vector; -using SPVectorPathConstraintPtr = Vector; -using SPVectorTimelinePtr = Vector; -using SPVectorTrackEntryPtr = Vector; -using SPVectorUpdatablePtr = Vector; -using SPVectorSkinEntryPtr = Vector; -using SPVectorVectorSkinEntryPtr = Vector; template void registerSpineInteger(const char* name) { @@ -539,13 +489,13 @@ EMSCRIPTEN_BINDINGS(spine) { REGISTER_SPINE_ENUM(TextureWrap); REGISTER_SPINE_ENUM(AttachmentType); - register_vector("VectorUnsignedShort"); - register_vector("VectorOfUInt"); - register_vector("VectorString"); + + REGISTER_SPINE_VECTOR(SPVectorDebugShape, false); REGISTER_SPINE_VECTOR(SPVectorFloat, true); REGISTER_SPINE_VECTOR(SPVectorVectorFloat, true); REGISTER_SPINE_VECTOR(SPVectorInt, true); + REGISTER_SPINE_VECTOR(SPVectorUint, true); REGISTER_SPINE_VECTOR(SPVectorVectorInt, true); REGISTER_SPINE_VECTOR(SPVectorSize_t, true); REGISTER_SPINE_VECTOR(SPVectorUnsignedShort, true); @@ -581,24 +531,6 @@ EMSCRIPTEN_BINDINGS(spine) { .function("length", &Vector2::length) .function("normalize", &Vector2::normalize); - // class_("String") - // .constructor<>() - // .constructor(constructorSpineString) - // .constructor() - // .function("length", &String::length) - // .function("isEmpty", &String::isEmpty) - // .function("append", select_overload(&String::append)) - // .function("equals", select_overload(&String::operator=)) - // .function("buffer", &String::buffer, allow_raw_pointer()) - // //.function("estr", optional_override([](String &obj) { - // // auto str = emscripten::val(obj.buffer()); - // // return str; }), allow_raw_pointers()) - // .function("strPtr", optional_override([](String &obj) { - // return reinterpret_cast(obj.buffer());}), allow_raw_pointers()) - // .function("str", optional_override([](String &obj) { - // std::string stdStr(obj.buffer(), obj.length()); - // return stdStr; }), allow_raw_pointers()); - class_("Color") .constructor<>() .constructor() @@ -916,7 +848,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("Bone") .constructor() .property("data", GETTER_RVAL_TO_PTR(Bone, getData, BoneData*)) - .property("skeleton", &Bone::getSkeleton) + .property("skeleton", GETTER_RVAL_TO_PTR(Bone, getSkeleton, Skeleton*)) .property("parent", &Bone::getParent) .function("getChildren", optional_override([](Bone &obj) { return &obj.getChildren(); }), allow_raw_pointer()) @@ -992,7 +924,7 @@ EMSCRIPTEN_BINDINGS(spine) { .property("bone", GETTER_RVAL_TO_PTR(Slot, getBone, Bone*)) .property("color", GETTER_RVAL_TO_PTR(Slot, getColor, Color*)) .property("darkColor", GETTER_RVAL_TO_PTR(Slot, getDarkColor, Color*)) - .function("getDeform", &Slot::getDeform, allow_raw_pointers()) + .function("getDeform", GETTER_RVAL_TO_PTR(Slot, getDeform, SPVectorFloat*), allow_raw_pointers()) .function("getSkeleton", GETTER_RVAL_TO_PTR(Slot, getSkeleton, Skeleton*)) .function("getAttachment", &Slot::getAttachment, allow_raw_pointers()) .function("setAttachment", &Slot::setAttachment, allow_raw_pointers()) @@ -1011,11 +943,11 @@ EMSCRIPTEN_BINDINGS(spine) { .function("addSkin", select_overload(&Skin::addSkin), allow_raw_pointers()) .function("copySkin", select_overload(&Skin::copySkin), allow_raw_pointers()) .function("findNamesForSlot", optional_override([](Skin &obj, size_t slotIndex) { - std::vector vetNames; + Vector vetNames; auto entries = obj.getAttachments(); while (entries.hasNext()) { - Skin::AttachmentMap::Entry &entry = entries.next(); - if (entry._slotIndex == slotIndex) vetNames.push_back(entry._name.buffer()); + auto &entry = entries.next(); + if (entry._slotIndex == slotIndex) vetNames.add(entry._name); } return vetNames; }), allow_raw_pointers()) @@ -1047,9 +979,9 @@ EMSCRIPTEN_BINDINGS(spine) { class_("SkeletonClipping") .constructor<>() - .property("clippedVertices", &SkeletonClipping::getClippedVertices) - .property("clippedTriangles", &SkeletonClipping::getClippedTriangles) - .property("clippedUVs", &SkeletonClipping::getClippedUVs) + .property("clippedVertices", GETTER_RVAL_TO_PTR(SkeletonClipping, getClippedVertices, SPVectorFloat*)) + .property("clippedTriangles", GETTER_RVAL_TO_PTR(SkeletonClipping, getClippedTriangles, SPVectorUnsignedShort*)) + .property("clippedUVs", GETTER_RVAL_TO_PTR(SkeletonClipping, getClippedUVs, SPVectorFloat*)) .function("clipStart", &SkeletonClipping::clipStart, allow_raw_pointers()) .function("clipEndWithSlot", select_overload(&SkeletonClipping::clipEnd)) .function("clipEnd", select_overload(&SkeletonClipping::clipEnd)) @@ -1408,7 +1340,7 @@ EMSCRIPTEN_BINDINGS(spine) { .property("iCount", &SpineModel::iCount) .property("vPtr", &SpineModel::vPtr) .property("iPtr", &SpineModel::iPtr) - .function("getData", &SpineModel::getData, allow_raw_pointer>()); + .function("getData", &SpineModel::getData, allow_raw_pointer()); class_("SpineDebugShape") .property("type", &SpineDebugShape::type) @@ -1417,7 +1349,6 @@ EMSCRIPTEN_BINDINGS(spine) { .property("iOffset", &SpineDebugShape::iOffset) .property("iCount", &SpineDebugShape::iCount); - register_vector("VectorDebugShape"); class_("SkeletonInstance") .constructor<>() .property("isCache", &SpineSkeletonInstance::isCache) @@ -1439,7 +1370,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setListener", &SpineSkeletonInstance::setListener) .function("setTrackEntryListener", &SpineSkeletonInstance::setTrackEntryListener, allow_raw_pointer()) .function("setDebugMode", &SpineSkeletonInstance::setDebugMode) - .function("getDebugShapes", &SpineSkeletonInstance::getDebugShapes) + .function("getDebugShapes", GETTER_RVAL_TO_PTR(SpineSkeletonInstance, getDebugShapes, SPVectorDebugShape*), allow_raw_pointers()) .function("resizeSlotRegion", &SpineSkeletonInstance::resizeSlotRegion) .function("destroy", &SpineSkeletonInstance::destroy) .function("setSlotTexture", &SpineSkeletonInstance::setSlotTexture); From f228aadb3f55df63645aa010c8a6763940b80678 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 16:09:04 +0800 Subject: [PATCH 40/80] Fix binding of apply. --- .../spine-wasm/spine-type-export.cpp | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 3064d55d09b..119ccbb2467 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -373,9 +373,20 @@ class TestFoo: public TestBase { int getX() const { return _x; } + + static void apply(int a, int b) { + printf("apply1, a: %d, b: %d\n", a, b); + } + static void apply(const Vector& a, bool b) { + printf("apply2, a, size: %d, b: %d\n", (int)a.size(), b); + for (int i = 0; i < a.size(); ++i) { + printf("apply2, aaa: [%d]=%d\n", i, a[i]); + } + } private: int _x = 0; }; + RTTI_IMPL(TestFoo, TestBase) DEFINE_SPINE_CLASS_TYPEID(TestBase) @@ -460,7 +471,10 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("TestFoo") .constructor() - .property("x", &TestFoo::getX, &TestFoo::setX); + .property("x", &TestFoo::getX, &TestFoo::setX) + .class_function("apply1", select_overload(&TestFoo::apply)) + .class_function("apply2", select_overload &, bool)>(&TestFoo::apply)) + ; class_("TestBar") .constructor() @@ -758,13 +772,11 @@ EMSCRIPTEN_BINDINGS(spine) { .function("findRegion", &Atlas::findRegion, allow_raw_pointers()); class_>("Pow") - .constructor() - .function("apply", &PowInterpolation::apply); + .constructor(); class_>("PowOut") - .constructor() - .function("apply", &PowOutInterpolation::apply); + .constructor(); class_("SlotData") .constructor() @@ -792,16 +804,9 @@ EMSCRIPTEN_BINDINGS(spine) { .property("stretch", &IkConstraint::getStretch, &IkConstraint::setStretch) .property("mix", &IkConstraint::getMix, &IkConstraint::setMix) .property("softness", &IkConstraint::getSoftness, &IkConstraint::setSoftness) - .class_function("apply1", optional_override([]( - IkConstraint &obj, Bone &bone, float targetX, float targetY, - bool compress, bool stretch, bool uniform, float alpha){ - obj.apply(bone, targetX, targetY, compress, stretch, uniform, alpha); - })) - .class_function("apply2", optional_override([]( - IkConstraint &obj, Bone &parent, Bone &child, float targetX, float targetY, - int bendDir, bool stretch, float softness, float alpha){ - obj.apply(parent, child, targetX, targetY, bendDir, stretch, softness, alpha); - })); + .class_function("apply1", select_overload(&IkConstraint::apply)) + .class_function("apply2", select_overload(&IkConstraint::apply)) + ; class_>("PathConstraint") .constructor() From 36f053437653004a86a1577fa52438097e77a104 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 16:45:13 +0800 Subject: [PATCH 41/80] Remove unused code --- .../spine-wasm/spine-skeleton-instance.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index d167f777bdc..6e2a350c1de 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -366,10 +366,6 @@ void SpineSkeletonInstance::collectMeshData() { currMesh.blendMode = static_cast(slot->getData().getBlendMode()); if (_userData.useSlotTexture) { - // auto iter = _slotTextureSet.find(slot); - // if (iter != _slotTextureSet.end()) { - // currMesh.textureID = iter->second; - // } if (_slotTextureSet.containsKey(slot)) { currMesh.textureID = _slotTextureSet[slot]; } @@ -517,12 +513,6 @@ void SpineSkeletonInstance::setSlotTexture(const std::string &slotName, uint32_t auto slot = _skeleton->findSlot(slotName.c_str()); if (!slot) return; _userData.useSlotTexture = true; - // auto iter = _slotTextureSet.find(slot); - // if (iter != _slotTextureSet.end()) { - // iter->second = textureID; - // } else { - // _slotTextureSet[slot] = textureID; - // } _slotTextureSet.put(slot, textureID); } \ No newline at end of file From 673f0f3151e32c253d254ecaf79ff4956865fe7a Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 16:46:00 +0800 Subject: [PATCH 42/80] Cleanup --- .../cocos/editor-support/spine-wasm/spine-skeleton-instance.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index 76b5951e88f..f6d37b027b7 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -2,7 +2,6 @@ #include -// #include #include #include #include "mesh-type-define.h" @@ -75,6 +74,5 @@ class SpineSkeletonInstance { uint32_t _trackEntryListenerID = 0; UserData _userData; spine::Vector _debugShapes{}; - // std::map _slotTextureSet{}; spine::HashMap _slotTextureSet{}; }; From d89106e5aa33fbb90e6e5a635306e3d7a6ec234f Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 16:47:29 +0800 Subject: [PATCH 43/80] Cleanup --- native/cocos/editor-support/spine/Json.cpp | 3 --- native/cocos/editor-support/spine/Json.h | 4 ---- 2 files changed, 7 deletions(-) diff --git a/native/cocos/editor-support/spine/Json.cpp b/native/cocos/editor-support/spine/Json.cpp index 5fb81c4afc6..be55269e3ba 100644 --- a/native/cocos/editor-support/spine/Json.cpp +++ b/native/cocos/editor-support/spine/Json.cpp @@ -20,7 +20,6 @@ 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. */ -#if 1//ENABLE_JSON_PARSER #ifdef SPINE_UE4 #include "SpinePluginPrivatePCH.h" @@ -555,5 +554,3 @@ int Json::json_strcasecmp(const char *s1, const char *s2) { } } } - -#endif // ENABLE_JSON_PARSER diff --git a/native/cocos/editor-support/spine/Json.h b/native/cocos/editor-support/spine/Json.h index 48d44930a2b..478d84b43b3 100644 --- a/native/cocos/editor-support/spine/Json.h +++ b/native/cocos/editor-support/spine/Json.h @@ -30,8 +30,6 @@ #ifndef Spine_Json_h #define Spine_Json_h -#if 1//ENABLE_JSON_PARSER - #include #ifndef SPINE_JSON_HAVE_PREV @@ -112,6 +110,4 @@ class SP_API Json { }; } // namespace spine -#endif // ENABLE_JSON_PARSER - #endif /* Spine_Json_h */ From 07f9547383f2b78ab92f682f3c65dd13f80f55b4 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 16:48:27 +0800 Subject: [PATCH 44/80] Revert --- native/cocos/editor-support/spine/Skin.h | 1 - 1 file changed, 1 deletion(-) diff --git a/native/cocos/editor-support/spine/Skin.h b/native/cocos/editor-support/spine/Skin.h index c04cbc54aa8..7ce6574e18b 100644 --- a/native/cocos/editor-support/spine/Skin.h +++ b/native/cocos/editor-support/spine/Skin.h @@ -144,7 +144,6 @@ class SP_API Skin : public SpineObject { void copySkin(Skin *other); AttachmentMap::Entries getAttachments(); - Vector> & getAttachmentEntries() { return _attachments._buckets; } Vector &getBones(); From 75e95a65b6f70962c10d02fdcd40f0f843c049e3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 16:58:28 +0800 Subject: [PATCH 45/80] cleanup spine-define.ts --- cocos/spine/lib/spine-define.ts | 461 +------------------------------- 1 file changed, 1 insertion(+), 460 deletions(-) diff --git a/cocos/spine/lib/spine-define.ts b/cocos/spine/lib/spine-define.ts index 8d17c613b10..b84e7b8fe8a 100644 --- a/cocos/spine/lib/spine-define.ts +++ b/cocos/spine/lib/spine-define.ts @@ -27,12 +27,6 @@ import spine from './spine-core'; import { js } from '../../core'; -function doPolyfill (proto: any, propertyPolyfills: any[]): void { - propertyPolyfills.forEach((prop): void => { - js.getset(proto, prop[0], prop[1], prop[2]); - }); -} - function resizeArray (array: any[], newSize: number): any[] { if (!array) return new Array(newSize); if (newSize === array.length) return array; @@ -93,20 +87,6 @@ function overrideDefineArrayFunction (prototype: any, getPropVector: any, name: }); } -function overrideDefinePtrStringFunction (prototype: any, getPtr: any, name: string): void { - Object.defineProperty(prototype, name, { - value (): string { - let str = ''; - const ptr = getPtr.call(this); - const HEAPU8 = spine.wasmUtil.wasm.HEAPU8; - const length = this.length; - const buffer = HEAPU8.subarray(ptr, ptr + length); - str = String.fromCharCode(...buffer); - return str; - }, - }); -} - function overrideClass (wasm): void { spine.wasmUtil = wasm.SpineWasmUtil; spine.wasmUtil.wasm = wasm; @@ -120,120 +100,16 @@ function overrideClass (wasm): void { } } -// function overrideProperty_String (): void { -// const prototype = spine.String.prototype as any; -// const propertyPolyfills = [ -// ['length', prototype.length], -// ['isEmpty', prototype.isEmpty], -// ['str', prototype.str], -// ]; -// propertyPolyfills.forEach((prop): void => { -// js.get(prototype, prop[0], prop[1]); -// }); -// overrideDefinePtrStringFunction(prototype, prototype.strPtr, 'strPtr'); -// } - -// function overrideProperty_BoneData (): void { -// const prototype = spine.BoneData.prototype as any; -// const propertyPolyfills = [ -// ['index', prototype.getIndex], -// ['name', prototype.getName], -// ['parent', prototype.getParent], -// ['length', prototype.getLength, prototype.setLength], -// ['x', prototype.getX, prototype.setX], -// ['y', prototype.getY, prototype.setY], -// ['rotation', prototype.getRotation, prototype.setRotation], -// ['scaleX', prototype.getScaleX, prototype.setScaleX], -// ['scaleY', prototype.getScaleY, prototype.setScaleY], -// ['shearX', prototype.getShearX, prototype.setShearX], -// ['shearY', prototype.getShearY, prototype.setShearY], -// ['transformMode', prototype.getTransformMode, prototype.setTransformMode], -// ['skinRequired', prototype.getSkinRequired, prototype.setSkinRequired], -// ]; -// doPolyfill(prototype, propertyPolyfills); -// } - -// function overrideProperty_Attachment (): void { -// const prototype = spine.Attachment.prototype as any; -// js.getset(prototype, 'name', prototype.getName); -// } - -// function overrideProperty_ConstraintData (): void { -// const prototype = spine.ConstraintData.prototype as any; -// const propertyPolyfills = [ -// ['name', prototype.getName], -// ['order', prototype.getOrder, prototype.setOder], -// ['skinRequired', prototype.getSkinRequired, prototype.setSkinRequired], -// ]; -// propertyPolyfills.forEach((prop): void => { -// js.getset(prototype, prop[0], prop[1], prop[2]); -// }); -// } - function overrideProperty_IkConstraintData (): void { const prototype = spine.IkConstraintData.prototype as any; - // const propertyPolyfills = [ - // // ['target', prototype.getTarget, prototype.setTarget], - // ['bendDirection', prototype.getBendDirection, prototype.setBendDirection], - // ['compress', prototype.getCompress, prototype.setCompress], - // ['stretch', prototype.getStretch, prototype.setStretch], - // ['uniform', prototype.getUniform, prototype.setUniform], - // ['mix', prototype.getMix, prototype.setMix], - // ['softness', prototype.getSoftness, prototype.setSoftness], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1], prop[2]); - // }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_PathConstraintData (): void { const prototype = spine.PathConstraintData.prototype as any; - // const propertyPolyfills = [ - // ['target', prototype.getTarget, prototype.setTarget], - // ['positionMode', prototype.getPositionMode, prototype.setPositionMode], - // ['spacingMode', prototype.getSpacingMode, prototype.setSpacingMode], - // ['rotateMode', prototype.getRotateMode, prototype.setRotateMode], - // ['offsetRotation', prototype.getOffsetRotation, prototype.setOffsetRotation], - // ['position', prototype.getPosition, prototype.setPosition], - // ['spacing', prototype.getSpacing, prototype.setSpacing], - // ['rotateMix', prototype.getRotateMix, prototype.setRotateMix], - // ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1], prop[2]); - // }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } -// function overrideProperty_Event (): void { -// const prototype = spine.Event.prototype as any; -// const propertyPolyfills = [ -// ['data', prototype.getData], -// // ['intValue', prototype.getIntValue, prototype.setIntValue], -// // ['floatValue', prototype.getFloatValue, prototype.setFloatValue], -// // ['stringValue', prototype.getStringValue, prototype.setStringValue], -// // ['time', prototype.getTime], -// // ['volume', prototype.getVolume, prototype.setVolume], -// // ['balance', prototype.getBalance, prototype.setBalance], -// ]; -// doPolyfill(prototype, propertyPolyfills); -// } - -// function overrideProperty_EventData (): void { -// const prototype = spine.EventData.prototype as any; -// const propertyPolyfills = [ -// ['name', prototype.getName], -// ['intValue', prototype.getIntValue, prototype.setIntValue], -// ['floatValue', prototype.getFloatValue, prototype.setFloatValue], -// ['stringValue', prototype.getStringValue, prototype.setStringValue], -// ['audioPath', prototype.getAudioPath, prototype.setAudioPath], -// ['volume', prototype.getVolume, prototype.setVolume], -// ['balance', prototype.getBalance, prototype.setBalance], -// ]; -// doPolyfill(prototype, propertyPolyfills); -// } - function overrideProperty_VertexAttachment (): void { const prototype = spine.VertexAttachment.prototype as any; overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); @@ -251,26 +127,9 @@ function overrideProperty_VertexAttachment (): void { }); } -// function overrideProperty_BoundingBoxAttachment (): void { -// const prototype = spine.BoundingBoxAttachment.prototype as any; -// js.getset(prototype, 'name', prototype.getName); -// } - -// function overrideProperty_ClippingAttachment (): void { -// const prototype = spine.ClippingAttachment.prototype as any; -// js.getset(prototype, 'endSlot', prototype.getEndSlot, prototype.setEndSlot); -// } - function overrideProperty_MeshAttachment (): void { const prototype = spine.MeshAttachment.prototype as any; - // const propertyPolyfills = [ - // ['path', prototype.getPath, prototype.setPath], - // ['color', prototype.getColor], - // ['width', prototype.getWidth, prototype.setWidth], - // ['height', prototype.getHeight, prototype.setHeight], - // ['hullLength', prototype.getHullLength, prototype.setHullLength], - // ]; - // doPolyfill(prototype, propertyPolyfills); + overrideDefineArrayProp(prototype, prototype.getRegionUVs, 'regionUVs'); overrideDefineArrayProp(prototype, prototype.getUVs, 'uvs'); overrideDefineArrayProp(prototype, prototype.getTriangles, 'triangles'); @@ -279,41 +138,11 @@ function overrideProperty_MeshAttachment (): void { function overrideProperty_PathAttachment (): void { const prototype = spine.PathAttachment.prototype as any; - // const propertyPolyfills = [ - // ['closed', prototype.getClosed, prototype.setClosed], - // ['constantSpeed', prototype.getConstantSpeed, prototype.setConstantSpeed], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1]); - // }); overrideDefineArrayProp(prototype, prototype.getLengths, 'lengths'); } -// function overrideProperty_PointAttachment (): void { -// const prototype = spine.PointAttachment.prototype as any; -// const propertyPolyfills = [ -// ['x', prototype.getX, prototype.setX], -// ['y', prototype.getY, prototype.setY], -// ['rotation', prototype.getRotation, prototype.setRotation], -// ]; -// doPolyfill(prototype, propertyPolyfills); -// } - function overrideProperty_RegionAttachment (): void { const prototype = spine.RegionAttachment.prototype as any; - // const propertyPolyfills = [ - // ['x', prototype.getX, prototype.setX], - // ['y', prototype.getY, prototype.setY], - // ['scaleX', prototype.getScaleX, prototype.setScaleX], - // ['scaleY', prototype.getScaleY, prototype.setScaleY], - // ['rotation', prototype.getRotation, prototype.setRotation], - // ['width', prototype.getWidth, prototype.setWidth], - // ['height', prototype.getHeight, prototype.setHeight], - // ['color', prototype.getColor], - // ['path', prototype.getPath, prototype.setPath], - // ['rendererObject', prototype.getRendererObject], - // ]; - // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getOffset, 'offset'); const getUVs = prototype.getUVs; @@ -347,163 +176,38 @@ function overrideProperty_RegionAttachment (): void { }); } -// function overrideProperty_TextureAtlas (): void { -// const prototype = spine.TextureAtlas.prototype as any; -// const propertyPolyfills = [ -// { -// proto: prototype, -// property: 'pages', -// getter: prototype.getProp_pages, -// }, -// { -// proto: prototype, -// property: 'regions', -// getter: prototype.getProp_regions, -// }, -// ]; -// propertyPolyfills.forEach((prop) => { -// js.getset(prototype, prop[0], prop[1]); -// }); -// } - -// function overrideProperty_SlotData (): void { -// const prototype = spine.SlotData.prototype as any; -// const propertyPolyfills = [ -// ['index', prototype.getIndex], -// ['boneData', prototype.getBoneData], -// ['name', prototype.getName], -// ['color', prototype.getColor], -// ['darkColor', prototype.getDarkColor], -// ['blendMode', prototype.getBlendMode, prototype.setBlendMode], -// ]; -// doPolyfill(prototype, propertyPolyfills); -// } - function overrideProperty_IkConstraint (): void { const prototype = spine.IkConstraint.prototype as any; - // const propertyPolyfills = [ - // ['data', prototype.getData], - // ['target', prototype.getTarget, prototype.setTarget], - // ['bendDirection', prototype.getBendDirection, prototype.setBendDirection], - // ['compress', prototype.getCompress, prototype.setCompress], - // ['stretch', prototype.getStretch, prototype.setStretch], - // ['mix', prototype.getMix, prototype.setMix], - // ['softness', prototype.getSoftness, prototype.setSoftness], - // ['active', prototype.getActive, prototype.setActive], - // ]; - // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_PathConstraint (): void { const prototype = spine.PathConstraint.prototype as any; - // const propertyPolyfills = [ - // ['data', prototype.getData], - // ['target', prototype.getTarget, prototype.setTarget], - // ['position', prototype.getPosition, prototype.setPosition], - // ['spacing', prototype.getSpacing, prototype.setSpacing], - // ['rotateMix', prototype.getRotateMix, prototype.setRotateMix], - // ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], - // ['active', prototype.getActive, prototype.setActive], - // ]; - // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_TransformConstraintData (): void { const prototype = spine.TransformConstraintData.prototype as any; - // const propertyPolyfills = [ - // ['target', prototype.getTarget], - // ['rotateMix', prototype.getRotateMix], - // ['translateMix', prototype.getTranslateMix], - // ['scaleMix', prototype.getScaleMix], - // ['shearMix', prototype.getShearMix], - // ['offsetRotation', prototype.getOffsetRotation], - // ['offsetX', prototype.getOffsetX], - // ['offsetY', prototype.getOffsetY], - // ['offsetScaleX', prototype.getOffsetScaleX], - // ['offsetScaleY', prototype.getOffsetScaleY], - // ['offsetShearY', prototype.getOffsetShearY], - // ['relative', prototype.getRelative], - // ['local', prototype.getLocal], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1]); - // }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_TransformConstraint (): void { const prototype = spine.TransformConstraint.prototype as any; - // const propertyPolyfills = [ - // ['data', prototype.getData], - // ['target', prototype.getTarget], - // ['rotateMix', prototype.getRotateMix, prototype.setRotateMix], - // ['translateMix', prototype.getTranslateMix, prototype.setTranslateMix], - // ['scaleMix', prototype.getScaleMix, prototype.setScaleMix], - // ['shearMix', prototype.getShearMix, prototype.setShearMix], - // ['active', prototype.getActive, prototype.setActive], - // ]; - // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); } function overrideProperty_Bone (): void { const prototype = spine.Bone.prototype as any; - // const propertyPolyfills = [ - // // ['skeleton', prototype.getSkeleton], - // ['data', prototype.getData], - // ['parent', prototype.getParent], - // ['x', prototype.getX, prototype.setX], - // ['y', prototype.getY, prototype.setY], - // ['rotation', prototype.getRotation, prototype.setRotation], - // ['scaleX', prototype.getScaleX, prototype.setScaleX], - // ['scaleY', prototype.getScaleY, prototype.setScaleY], - // ['shearX', prototype.getShearX, prototype.setShearX], - // ['shearY', prototype.getShearY, prototype.setShearY], - // ['ax', prototype.getAX, prototype.setAX], - // ['ay', prototype.getAY, prototype.setAY], - // ['arotation', prototype.getARotation, prototype.setARotation], - // ['ascaleX', prototype.getAScaleX, prototype.setAScaleX], - // ['ascaleY', prototype.getAScaleY, prototype.setAScaleY], - // ['ashearX', prototype.getAShearX, prototype.setAShearX], - // ['ashearY', prototype.getAShearY, prototype.setAShearY], - // ['appliedValid', prototype.getAppliedValid, prototype.setAppliedValid], - // ['a', prototype.getA, prototype.setA], - // ['b', prototype.getB, prototype.setB], - // ['c', prototype.getC, prototype.setC], - // ['d', prototype.getD, prototype.setD], - // ['worldX', prototype.getWorldX, prototype.setWorldX], - // ['worldY', prototype.getWorldY, prototype.setWorldY], - // ['active', prototype.getActive, prototype.setActive], - // ]; - // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getChildren, 'children'); } function overrideProperty_Slot (): void { const prototype = spine.Slot.prototype as any; - // const propertyPolyfills = [ - // ['data', prototype.getData], - // ['bone', prototype.getBone], - // ['color', prototype.getColor], - // ['darkColor', prototype.getDarkColor], - // ['skeleton', prototype.getSkeleton], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1]); - // }); overrideDefineArrayProp(prototype, prototype.getDeform, 'deform'); } function overrideProperty_Skin (): void { const prototype = spine.Skin.prototype as any; - // const propertyPolyfills = [ - // ['name', prototype.getName], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1]); - // }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getAttachments, 'attachments'); overrideDefineArrayProp(prototype, prototype.getConstraints, 'constraints'); @@ -545,34 +249,8 @@ function overrideProperty_SkinEntry (): void { }); } -// function overrideProperty_SkeletonClipping (): void { -// const prototype = spine.SkeletonClipping.prototype as any; -// const propertyPolyfills = [ -// ['clippedVertices', prototype.getClippedVertices], -// ['clippedTriangles', prototype.getClippedTriangles], -// ['clippedUVs', prototype.getClippedUVs], -// ]; -// propertyPolyfills.forEach((prop): void => { -// js.getset(prototype, prop[0], prop[1]); -// }); -// } - function overrideProperty_SkeletonData (): void { const prototype = spine.SkeletonData.prototype as any; - // const propertyPolyfills = [ - // ['name', prototype.getName], - // ['defaultSkin', prototype.getDefaultSkin, prototype.setDefaultSkin], - // ['x', prototype.getX, prototype.setX], - // ['y', prototype.getY, prototype.setY], - // ['width', prototype.getWidth, prototype.setWidth], - // ['height', prototype.getHeight, prototype.setHeight], - // ['version', prototype.getVersion, prototype.setVersion], - // ['hash', prototype.getHash, prototype.setHash], - // ['fps', prototype.getFps, prototype.setFps], - // ['imagesPath', prototype.getImagesPath, prototype.setImagesPath], - // ['audioPath', prototype.getAudioPath, prototype.setAudioPath], - // ]; - // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getSlots, 'slots'); @@ -586,57 +264,22 @@ function overrideProperty_SkeletonData (): void { function overrideProperty_RotateTimeline (): void { const prototype = spine.RotateTimeline.prototype as any; - // const propertyPolyfills = [ - // ['boneIndex', prototype.getBoneIndex], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1]); - // }); overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); } function overrideProperty_ColorTimeline (): void { const prototype = spine.ColorTimeline.prototype as any; - // const propertyPolyfills = [ - // ['slotIndex', prototype.getSlotIndex], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1]); - // }); overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); } -// function overrideProperty_TwoColorTimeline (): void { -// const prototype = spine.TwoColorTimeline.prototype as any; -// const propertyPolyfills = [ -// ['slotIndex', prototype.getSlotIndex], -// ]; -// propertyPolyfills.forEach((prop): void => { -// js.getset(prototype, prop[0], prop[1]); -// }); -// } - function overrideProperty_AttachmentTimeline (): void { const prototype = spine.AttachmentTimeline.prototype as any; - // const propertyPolyfills = [ - // ['slotIndex', prototype.getSlotIndex], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1]); - // }); overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); overrideDefineArrayProp(prototype, prototype.getAttachmentNames, 'attachmentNames'); } function overrideProperty_DeformTimeline (): void { const prototype = spine.DeformTimeline.prototype as any; - // const propertyPolyfills = [ - // ['slotIndex', prototype.getSlotIndex], - // ['attachment', prototype.getAttachment], - // ]; - // propertyPolyfills.forEach((prop): void => { - // js.getset(prototype, prop[0], prop[1]); - // }); overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); overrideDefineArrayArrayProp(prototype, prototype.getFrameVertices, 'frameVertices'); } @@ -652,79 +295,18 @@ function overrideProperty_DrawOrderTimeline (): void { overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); } -// function overrideProperty_TrackEntry (): void { -// const prototype = spine.TrackEntry.prototype as any; -// const propertyPolyfills = [ -// ['animation', prototype.getAnimation], -// ['next', prototype.getNext], -// ['mixingFrom', prototype.getMixingFrom], -// ['mixingTo', prototype.getMixingTo], -// ['trackIndex', prototype.getTrackIndex], -// ['loop', prototype.getLoop, prototype.setLoop], -// ['holdPrevious', prototype.getHoldPrevious, prototype.setHoldPrevious], -// ['eventThreshold', prototype.getEventThreshold, prototype.setEventThreshold], -// ['attachmentThreshold', prototype.getAttachmentThreshold, prototype.setAttachmentThreshold], -// ['drawOrderThreshold', prototype.getDrawOrderThreshold, prototype.setDrawOrderThreshold], -// ['animationStart', prototype.getAnimationStart, prototype.setAnimationStart], -// ['animationEnd', prototype.getAnimationEnd, prototype.setAnimationEnd], -// ['animationLast', prototype.getAnimationLast, prototype.setAnimationLast], -// ['delay', prototype.getDelay, prototype.setDelay], -// ['trackTime', prototype.getTrackTime, prototype.setTrackTime], -// ['trackEnd', prototype.getTrackEnd, prototype.setTrackEnd], -// ['timeScale', prototype.getTimeScale, prototype.setTimeScale], -// ['alpha', prototype.getAlpha, prototype.setAlpha], -// ['mixTime', prototype.getMixTime, prototype.setMixTime], -// ['mixDuration', prototype.getMixDuration, prototype.setMixDuration], -// ['mixBlend', prototype.getMixBlend, prototype.setMixBlend], -// ]; -// doPolyfill(prototype, propertyPolyfills); -// } - -// function overrideProperty_AnimationStateData (): void { -// const prototype = spine.AnimationStateData.prototype as any; -// const propertyPolyfills = [ -// ['defaultMix', prototype.getDefaultMix], -// ['skeletonData', prototype.getSkeletonData], -// ]; -// propertyPolyfills.forEach((prop): void => { -// js.getset(prototype, prop[0], prop[1]); -// }); -// } - function overrideProperty_AnimationState (): void { const prototype = spine.AnimationState.prototype as any; - // const propertyPolyfills = [ - // ['data', prototype.getData], - // ['timeScale', prototype.getTimeScale, prototype.setTimeScale], - // ]; - // doPolyfill(prototype, propertyPolyfills); - overrideDefineArrayProp(prototype, prototype.getTracks, 'tracks'); } function overrideProperty_Animation (): void { const prototype = spine.Animation.prototype as any; - // const propertyPolyfills = [ - // ['name', prototype.getName], - // ['duration', prototype.getDuration, prototype.setDuration], - // ]; - // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getTimelines, 'timelines'); } function overrideProperty_Skeleton (): void { const prototype = spine.Skeleton.prototype as any; - // const propertyPolyfills = [ - // ['data', prototype.getData], - // ['skin', prototype.getSkin], - // ['color', prototype.getColor], - // ['time', prototype.getTime], - // ['scaleX', prototype.getScaleX, prototype.setScaleX], - // ['scaleY', prototype.getScaleY, prototype.setScaleY], - // ['x', prototype.getX, prototype.setX], - // ['y', prototype.getY, prototype.setY], - // ]; - // doPolyfill(prototype, propertyPolyfills); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getSlots, 'slots'); @@ -735,48 +317,14 @@ function overrideProperty_Skeleton (): void { overrideDefineArrayProp(prototype, prototype.getUpdateCacheList, '_updateCache'); } -// function overrideProperty_JitterEffect (): void { -// const prototype = spine.JitterEffect.prototype as any; -// const propertyPolyfills = [ -// ['jitterX', prototype.getJitterX, prototype.setJitterX], -// ['jitterY', prototype.getJitterY, prototype.setJitterY], -// ]; -// propertyPolyfills.forEach((prop) => { -// js.getset(prototype, prop[0], prop[1], prop[2]); -// }); -// } - -// function overrideProperty_SwirlEffect (): void { -// const prototype = spine.SwirlEffect.prototype as any; -// const propertyPolyfills = [ -// ['centerX', prototype.getCenterX, prototype.setCenterX], -// ['centerY', prototype.getCenterY, prototype.setCenterY], -// ['radius', prototype.getRadius, prototype.setRadius], -// ['angle', prototype.getAngle, prototype.setAngle], -// ]; -// propertyPolyfills.forEach((prop) => { -// js.getset(prototype, prop[0], prop[1], prop[2]); -// }); -// } - export function overrideSpineDefine (wasm): void { overrideClass(wasm); - // overrideProperty_String(); - // overrideProperty_BoneData(); - // overrideProperty_ConstraintData(); overrideProperty_IkConstraintData(); overrideProperty_PathConstraintData(); - // overrideProperty_Event(); - // overrideProperty_EventData(); - // overrideProperty_BoundingBoxAttachment(); - // overrideProperty_ClippingAttachment(); overrideProperty_MeshAttachment(); overrideProperty_PathAttachment(); - // overrideProperty_PointAttachment(); overrideProperty_RegionAttachment(); overrideProperty_VertexAttachment(); - // overrideProperty_TextureAtlas(); - // overrideProperty_SlotData(); overrideProperty_IkConstraint(); overrideProperty_PathConstraint(); overrideProperty_TransformConstraintData(); @@ -784,22 +332,15 @@ export function overrideSpineDefine (wasm): void { overrideProperty_Bone(); overrideProperty_Slot(); overrideProperty_Skin(); - // overrideProperty_Attachment(); overrideProperty_SkinEntry(); - // overrideProperty_SkeletonClipping(); overrideProperty_SkeletonData(); overrideProperty_RotateTimeline(); overrideProperty_ColorTimeline(); - // overrideProperty_TwoColorTimeline(); overrideProperty_AttachmentTimeline(); overrideProperty_DeformTimeline(); overrideProperty_EventTimeline(); overrideProperty_DrawOrderTimeline(); - // overrideProperty_TrackEntry(); - // overrideProperty_AnimationStateData(); overrideProperty_AnimationState(); overrideProperty_Animation(); overrideProperty_Skeleton(); - // overrideProperty_JitterEffect(); - // overrideProperty_SwirlEffect(); } From f3cfe223fba126d6956311d29c63fc9bc43d2e1a Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 17:14:50 +0800 Subject: [PATCH 46/80] Update external --- native/external-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/external-config.json b/native/external-config.json index 3d75f3e5a05..e04dab5e6c6 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.5-6" + "checkout": "v3.8.5-7" } } \ No newline at end of file From 3c48bf67488078c26d563f5d33dbb7b1c1adae28 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 29 Oct 2024 17:31:24 +0800 Subject: [PATCH 47/80] Fix compile errors. --- native/CMakeLists.txt | 1 + native/tools/swig-config/spine.i | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index a7fb148f195..d01596560bb 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -2349,6 +2349,7 @@ if(USE_MIDDLEWARE) cocos/editor-support/spine/spine.h NO_WERROR cocos/editor-support/spine/SpineObject.cpp cocos/editor-support/spine/SpineObject.h + cocos/editor-support/spine/SpineString.cpp cocos/editor-support/spine/SpineString.h NO_WERROR cocos/editor-support/spine/TextureLoader.cpp cocos/editor-support/spine/TextureLoader.h diff --git a/native/tools/swig-config/spine.i b/native/tools/swig-config/spine.i index c8fa9127528..82e9a0e5219 100644 --- a/native/tools/swig-config/spine.i +++ b/native/tools/swig-config/spine.i @@ -102,6 +102,10 @@ using namespace spine; %ignore spine::TranslateTimeline::getRTTI; %ignore spine::TwoColorTimeline::getRTTI; %ignore spine::VertexAttachment::getRTTI; +%ignore spine::Interpolation::getRTTI; +%ignore spine::VertexEffect::getRTTI; +%ignore spine::ConstraintData::getRTTI; + %ignore spine::SkeletonDataMgr::destroyInstance; %ignore spine::SkeletonDataMgr::hasSkeletonData; %ignore spine::SkeletonDataMgr::setSkeletonData; From ed2bd998f4f95a27a106396deac5f1dc14270602 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 11:36:57 +0800 Subject: [PATCH 48/80] Don't use std types. --- .../editor-support/spine-wasm/CMakeLists.txt | 6 +- .../spine-wasm/spine-skeleton-instance.cpp | 24 ++-- .../spine-wasm/spine-skeleton-instance.h | 10 +- .../editor-support/spine-wasm/spine-wasm.cpp | 51 ++++---- .../editor-support/spine-wasm/spine-wasm.h | 10 +- .../spine-wasm/util-function.cpp | 110 +++++++++--------- .../editor-support/spine-wasm/util-function.h | 22 ++-- .../cocos/editor-support/spine/Extension.cpp | 4 + native/cocos/editor-support/spine/Json.cpp | 36 ++++++ .../cocos/editor-support/spine/Skeleton.cpp | 9 +- .../cocos/editor-support/spine/SpineObject.h | 10 +- .../editor-support/spine/SpineString.cpp | 2 + .../cocos/editor-support/spine/SpineString.h | 10 +- 13 files changed, 174 insertions(+), 130 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index fa42a209c1a..913bdeb1813 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -5,9 +5,9 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(BUILD_WASM 1) set(ENABLE_JSON_PARSER 1) set(ENABLE_BINARY_PARSER 1) -set(DEBUG_NEW 0) set(CMAKE_BUILD_TYPE "MinSizeRel") +# set(CMAKE_BUILD_TYPE "RelWithDebInfo") # set(CMAKE_BUILD_TYPE "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -25,8 +25,7 @@ project(${APP_NAME}_wasm) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override \ - -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER} \ - -DDEBUG_NEW=${DEBUG_NEW}") + -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") message(">>> --------------------------------------------------------------") message(">>> Current directory: ${CMAKE_CURRENT_LIST_DIR}") @@ -34,7 +33,6 @@ message(">>> CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(">>> ENABLE_CLOSURE_COMPILER: ${ENABLE_CLOSURE_COMPILER}") message(">>> ENABLE_JSON_PARSER: ${ENABLE_JSON_PARSER}") message(">>> ENABLE_BINARY_PARSER: ${ENABLE_BINARY_PARSER}") -message(">>> DEBUG_NEW: ${DEBUG_NEW}") message(">>> --------------------------------------------------------------") include_directories(${CMAKE_CURRENT_LIST_DIR}/..) diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index 6e2a350c1de..dad2e743715 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -1,10 +1,8 @@ #include "spine-skeleton-instance.h" #include -#include #include "AtlasAttachmentLoaderExtension.h" #include "spine-mesh-data.h" #include "spine-wasm.h" -#include "util-function.h" SlotMesh globalMesh(nullptr, nullptr, 0, 0); @@ -66,9 +64,9 @@ Skeleton *SpineSkeletonInstance::initSkeleton(SkeletonData *data) { return _skeleton; } -TrackEntry *SpineSkeletonInstance::setAnimation(float trackIndex, const std::string &name, bool loop) { +TrackEntry *SpineSkeletonInstance::setAnimation(float trackIndex, const spine::String &name, bool loop) { if (!_skeleton) return nullptr; - spine::Animation *animation = _skeleton->getData()->findAnimation(name.c_str()); + spine::Animation *animation = _skeleton->getData()->findAnimation(name); if (!animation) { _animState->clearTracks(); _skeleton->setToSetupPose(); @@ -80,9 +78,9 @@ TrackEntry *SpineSkeletonInstance::setAnimation(float trackIndex, const std::str return trackEntry; } -void SpineSkeletonInstance::setSkin(const std::string &name) { +void SpineSkeletonInstance::setSkin(const spine::String &name) { if (!_skeleton) return; - _skeleton->setSkin(name.c_str()); + _skeleton->setSkin(name); _skeleton->setSlotsToSetupPose(); } @@ -135,7 +133,7 @@ void SpineSkeletonInstance::collectMeshData() { for (uint32_t drawIdx = 0; drawIdx < slotCount; ++drawIdx) { auto slot = slotArray[drawIdx]; auto& bone = slot->getBone(); - if (bone.isActive() == false) { + if (!bone.isActive()) { continue; } @@ -405,8 +403,8 @@ AnimationState *SpineSkeletonInstance::getAnimationState() { return _animState; } -void SpineSkeletonInstance::setMix(const std::string &from, const std::string &to, float duration) { - _animStateData->setMix(from.c_str(), to.c_str(), duration); +void SpineSkeletonInstance::setMix(const spine::String &from, const spine::String &to, float duration) { + _animStateData->setMix(from, to, duration); } void SpineSkeletonInstance::setTrackEntryListener(uint32_t trackId, TrackEntry *entry) { @@ -448,9 +446,9 @@ Vector &SpineSkeletonInstance::getDebugShapes() { return this->_debugShapes; } -void SpineSkeletonInstance::resizeSlotRegion(const std::string &slotName, uint32_t width, uint32_t height, bool createNew) { +void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint32_t width, uint32_t height, bool createNew) { if (!_skeleton) return; - auto slot = _skeleton->findSlot(slotName.c_str()); + auto slot = _skeleton->findSlot(slotName); if (!slot) return; auto attachment = slot->getAttachment(); if (!attachment) return; @@ -508,9 +506,9 @@ void SpineSkeletonInstance::resizeSlotRegion(const std::string &slotName, uint32 } } -void SpineSkeletonInstance::setSlotTexture(const std::string &slotName, uint32_t textureID) { +void SpineSkeletonInstance::setSlotTexture(const spine::String &slotName, uint32_t textureID) { if (!_skeleton) return; - auto slot = _skeleton->findSlot(slotName.c_str()); + auto slot = _skeleton->findSlot(slotName); if (!slot) return; _userData.useSlotTexture = true; diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index f6d37b027b7..2de5258bd22 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -35,8 +35,8 @@ class SpineSkeletonInstance { SpineSkeletonInstance(); ~SpineSkeletonInstance(); spine::Skeleton *initSkeleton(spine::SkeletonData *data); - spine::TrackEntry *setAnimation(float trackIndex, const std::string &name, bool loop); - void setSkin(const std::string &name); + spine::TrackEntry *setAnimation(float trackIndex, const spine::String &name, bool loop); + void setSkin(const spine::String &name); void updateAnimation(float dltTime); SpineModel *updateRenderData(); void setPremultipliedAlpha(bool val); @@ -47,14 +47,14 @@ class SpineSkeletonInstance { void setSwirlEffect(spine::SwirlVertexEffect *effect); void clearEffect(); spine::AnimationState *getAnimationState(); - void setMix(const std::string &from, const std::string &to, float duration); + void setMix(const spine::String &from, const spine::String &to, float duration); inline void setListener(uint32_t listenerID) { _eventListenerID = listenerID;} void setTrackEntryListener(uint32_t trackId, spine::TrackEntry *entry); void onAnimationStateEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); void onTrackEntryEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); spine::Vector &getDebugShapes(); - void resizeSlotRegion(const std::string &slotName, uint32_t width, uint32_t height, bool createNew = false); - void setSlotTexture(const std::string &slotName, uint32_t index); + void resizeSlotRegion(const spine::String &slotName, uint32_t width, uint32_t height, bool createNew = false); + void setSlotTexture(const spine::String &slotName, uint32_t index); void destroy(); bool isCache{false}; bool enable{true}; diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index b43dc8b9d00..ce8cc0e90b0 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -1,5 +1,4 @@ #include "spine-wasm.h" -#include #include "AtlasAttachmentLoaderExtension.h" #include "spine-mesh-data.h" #include "util-function.h" @@ -7,7 +6,9 @@ using namespace spine; -std::map skeletonDataMap{}; +namespace { + HashMap skeletonDataMap{}; +} uint32_t SpineWasmUtil::s_listenerID = 0; EventType SpineWasmUtil::s_currentType = EventType_Event; @@ -17,9 +18,9 @@ uint8_t* SpineWasmUtil::s_mem = nullptr; uint32_t SpineWasmUtil::s_memSize = 0; void SpineWasmUtil::spineWasmInit() { - LogUtil::Initialize(); - spine::SpineExtension* tension = new WasmSpineExtension(); - spine::SpineExtension::setInstance(tension); + // LogUtil::Initialize(); + SpineExtension* tension = new WasmSpineExtension(); + SpineExtension::setInstance(tension); SpineMeshData::initMeshMemory(); @@ -27,32 +28,30 @@ void SpineWasmUtil::spineWasmInit() { } void SpineWasmUtil::spineWasmDestroy() { - auto* extension = spine::SpineExtension::getInstance(); + auto* extension = SpineExtension::getInstance(); delete extension; freeStoreMemory(); SpineMeshData::releaseMeshMemory(); - LogUtil::ReleaseBuffer(); + // LogUtil::ReleaseBuffer(); } -SkeletonData* SpineWasmUtil::querySpineSkeletonDataByUUID(const std::string& uuid) { - auto iter = skeletonDataMap.find(uuid); - if (iter == skeletonDataMap.end()) { +SkeletonData* SpineWasmUtil::querySpineSkeletonDataByUUID(const String& uuid) { + if (!skeletonDataMap.containsKey(uuid)) { return nullptr; } - SkeletonData* ptrVal = iter->second; - return ptrVal; + return skeletonDataMap[uuid]; } -SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const std::string& jsonStr, const std::string& altasStr) { +SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const String& jsonStr, const String& altasStr) { #if ENABLE_JSON_PARSER - auto* atlas = new Atlas(altasStr.c_str(), altasStr.size(), "", nullptr, false); + auto* atlas = new Atlas(altasStr.buffer(), altasStr.length(), "", nullptr, false); if (!atlas) { return nullptr; } AttachmentLoader* attachmentLoader = new AtlasAttachmentLoaderExtension(atlas); - spine::SkeletonJson json(attachmentLoader); + SkeletonJson json(attachmentLoader); json.setScale(1.0F); - SkeletonData* skeletonData = json.readSkeletonData(jsonStr.c_str()); + SkeletonData* skeletonData = json.readSkeletonData(jsonStr.buffer()); return skeletonData; #else @@ -60,14 +59,14 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const std::string& #endif } -SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize, const std::string& altasStr) { +SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize, const String& altasStr) { #if ENABLE_BINARY_PARSER - auto* atlas = new Atlas(altasStr.c_str(), altasStr.size(), "", nullptr, false); + auto* atlas = new Atlas(altasStr.buffer(), altasStr.length(), "", nullptr, false); if (!atlas) { return nullptr; } AttachmentLoader* attachmentLoader = new AtlasAttachmentLoaderExtension(atlas); - spine::SkeletonBinary binary(attachmentLoader); + SkeletonBinary binary(attachmentLoader); binary.setScale(1.0F); SkeletonData* skeletonData = binary.readSkeletonData(s_mem, byteSize); return skeletonData; @@ -76,19 +75,17 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize #endif } -void SpineWasmUtil::registerSpineSkeletonDataWithUUID(SkeletonData* data, const std::string& uuid) { - auto iter = skeletonDataMap.find(uuid); - if (iter == skeletonDataMap.end()) { - skeletonDataMap[uuid] = data; +void SpineWasmUtil::registerSpineSkeletonDataWithUUID(SkeletonData* data, const String& uuid) { + if (!skeletonDataMap.containsKey(uuid)) { + skeletonDataMap.put(uuid, data); } } -void SpineWasmUtil::destroySpineSkeletonDataWithUUID(const std::string& uuid) { - auto iter = skeletonDataMap.find(uuid); - if (iter != skeletonDataMap.end()) { +void SpineWasmUtil::destroySpineSkeletonDataWithUUID(const String& uuid) { + if (skeletonDataMap.containsKey(uuid)) { auto* data = skeletonDataMap[uuid]; delete data; - skeletonDataMap.erase(iter); + skeletonDataMap.remove(uuid); } } diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.h b/native/cocos/editor-support/spine-wasm/spine-wasm.h index 7cf65fd7e27..655b7f743c1 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.h +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.h @@ -10,11 +10,11 @@ class SpineWasmUtil { static uint32_t queryStoreMemory(uint32_t size); static void freeStoreMemory(); - static spine::SkeletonData* querySpineSkeletonDataByUUID(const std::string& uuid); - static spine::SkeletonData* createSpineSkeletonDataWithJson(const std::string& jsonStr, const std::string& altasStr); - static spine::SkeletonData* createSpineSkeletonDataWithBinary(uint32_t byteSize, const std::string& altasStr); - static void registerSpineSkeletonDataWithUUID(spine::SkeletonData* data, const std::string& uuid); - static void destroySpineSkeletonDataWithUUID(const std::string& uuid); + static spine::SkeletonData* querySpineSkeletonDataByUUID(const spine::String& uuid); + static spine::SkeletonData* createSpineSkeletonDataWithJson(const spine::String& jsonStr, const spine::String& altasStr); + static spine::SkeletonData* createSpineSkeletonDataWithBinary(uint32_t byteSize, const spine::String& altasStr); + static void registerSpineSkeletonDataWithUUID(spine::SkeletonData* data, const spine::String& uuid); + static void destroySpineSkeletonDataWithUUID(const spine::String& uuid); static void destroySpineSkeleton(spine::Skeleton* skeleton); static uint32_t getCurrentListenerID(); diff --git a/native/cocos/editor-support/spine-wasm/util-function.cpp b/native/cocos/editor-support/spine-wasm/util-function.cpp index b3a4bed9353..6dce8fc0af2 100644 --- a/native/cocos/editor-support/spine-wasm/util-function.cpp +++ b/native/cocos/editor-support/spine-wasm/util-function.cpp @@ -1,67 +1,67 @@ #include "util-function.h" -#include -// extern "C" { -// extern void consoleInfo(char* ptr, uint32_t length); -// } -static char* logBuffer = nullptr; -const int LOG_LENGTH = 1024; +// #include +// // extern "C" { +// // extern void consoleInfo(char* ptr, uint32_t length); +// // } +// static char* logBuffer = nullptr; +// const int LOG_LENGTH = 1024; -void LogUtil::Initialize() { - //logBuffer = new char[LOG_LENGTH]; -} +// void LogUtil::Initialize() { +// //logBuffer = new char[LOG_LENGTH]; +// } -void LogUtil::PrintToJs(std::string& message) { - // int length = message.length(); - // if (length >= LOG_LENGTH) length = LOG_LENGTH -1; - // memcpy(logBuffer, message.c_str(), length); - // logBuffer[length] = 0; - // consoleInfo(logBuffer, length); -} +// void LogUtil::PrintToJs(std::string& message) { +// // int length = message.length(); +// // if (length >= LOG_LENGTH) length = LOG_LENGTH -1; +// // memcpy(logBuffer, message.c_str(), length); +// // logBuffer[length] = 0; +// // consoleInfo(logBuffer, length); +// } -void LogUtil::PrintToJs(const char* message) { - // std::string strMessage(message); - // int length = strMessage.length(); - // if (length >= LOG_LENGTH) length = LOG_LENGTH - 1; - // memcpy(logBuffer, strMessage.c_str(), length); - // logBuffer[length] = 0; - // consoleInfo(logBuffer, length); -} +// void LogUtil::PrintToJs(const char* message) { +// // std::string strMessage(message); +// // int length = strMessage.length(); +// // if (length >= LOG_LENGTH) length = LOG_LENGTH - 1; +// // memcpy(logBuffer, strMessage.c_str(), length); +// // logBuffer[length] = 0; +// // consoleInfo(logBuffer, length); +// } -void LogUtil::PrintToJs(char* str, int length) { - // if (length >= LOG_LENGTH) length = LOG_LENGTH - 1; - // memcpy(logBuffer, str, length); - // logBuffer[length] = 0; - // consoleInfo(logBuffer, length); -} +// void LogUtil::PrintToJs(char* str, int length) { +// // if (length >= LOG_LENGTH) length = LOG_LENGTH - 1; +// // memcpy(logBuffer, str, length); +// // logBuffer[length] = 0; +// // consoleInfo(logBuffer, length); +// } -void LogUtil::PrintIntValue(int value, const char* message) { - // std::string strInt = std::to_string(value); - // std::string finalStr = std::string(message) + strInt; - // LogUtil::PrintToJs(finalStr); -} +// void LogUtil::PrintIntValue(int value, const char* message) { +// // std::string strInt = std::to_string(value); +// // std::string finalStr = std::string(message) + strInt; +// // LogUtil::PrintToJs(finalStr); +// } -void LogUtil::ReleaseBuffer() { - //delete[] logBuffer; -} +// void LogUtil::ReleaseBuffer() { +// //delete[] logBuffer; +// } -// const uint32_t MEMORY_SIZE = 8 * 1024 * 1024; -// static uint8_t* uint8Ptr = nullptr; +// // const uint32_t MEMORY_SIZE = 8 * 1024 * 1024; +// // static uint8_t* uint8Ptr = nullptr; -// uint8_t* StoreMemory::getStoreMemory() { -// if (uint8Ptr) return uint8Ptr; +// // uint8_t* StoreMemory::getStoreMemory() { +// // if (uint8Ptr) return uint8Ptr; -// uint32_t* uint32Ptr = new uint32_t[MEMORY_SIZE / 4]; -// uint8Ptr = (uint8_t*)uint32Ptr; -// return uint8Ptr; -// } +// // uint32_t* uint32Ptr = new uint32_t[MEMORY_SIZE / 4]; +// // uint8Ptr = (uint8_t*)uint32Ptr; +// // return uint8Ptr; +// // } -// void StoreMemory::freeStoreMemory() { -// if (uint8Ptr) { -// delete[] uint8Ptr; -// uint8Ptr = nullptr; -// } -// } +// // void StoreMemory::freeStoreMemory() { +// // if (uint8Ptr) { +// // delete[] uint8Ptr; +// // uint8Ptr = nullptr; +// // } +// // } -// uint32_t StoreMemory::storeMemorySize() { -// return MEMORY_SIZE; -// } +// // uint32_t StoreMemory::storeMemorySize() { +// // return MEMORY_SIZE; +// // } diff --git a/native/cocos/editor-support/spine-wasm/util-function.h b/native/cocos/editor-support/spine-wasm/util-function.h index 657033eff2b..f1ca8ddff73 100644 --- a/native/cocos/editor-support/spine-wasm/util-function.h +++ b/native/cocos/editor-support/spine-wasm/util-function.h @@ -1,16 +1,16 @@ #ifndef __UTIL_FUNCTION_H__ #define __UTIL_FUNCTION_H__ -#include -#include -class LogUtil { -public: - static void Initialize(); - static void PrintToJs(std::string& message); - static void PrintToJs(const char* message); - static void PrintToJs(char* str, int length); - static void PrintIntValue(int value, const char* message); - static void ReleaseBuffer(); -}; +// #include +// #include +// class LogUtil { +// public: +// static void Initialize(); +// static void PrintToJs(std::string& message); +// static void PrintToJs(const char* message); +// static void PrintToJs(char* str, int length); +// static void PrintIntValue(int value, const char* message); +// static void ReleaseBuffer(); +// }; // class StoreMemory { // public: diff --git a/native/cocos/editor-support/spine/Extension.cpp b/native/cocos/editor-support/spine/Extension.cpp index e730b065f9b..ca111a1e33b 100644 --- a/native/cocos/editor-support/spine/Extension.cpp +++ b/native/cocos/editor-support/spine/Extension.cpp @@ -108,6 +108,9 @@ void DefaultSpineExtension::_free(void *mem, const char *file, int line) { } char *DefaultSpineExtension::_readFile(const String &path, int *length) { +#ifdef __EMSCRIPTEN__ + return nullptr; +#else char *data; FILE *file = fopen(path.buffer(), "rb"); if (!file) return 0; @@ -121,6 +124,7 @@ char *DefaultSpineExtension::_readFile(const String &path, int *length) { fclose(file); return data; +#endif } DefaultSpineExtension::DefaultSpineExtension() : SpineExtension() { diff --git a/native/cocos/editor-support/spine/Json.cpp b/native/cocos/editor-support/spine/Json.cpp index be55269e3ba..59c6b3c8147 100644 --- a/native/cocos/editor-support/spine/Json.cpp +++ b/native/cocos/editor-support/spine/Json.cpp @@ -44,6 +44,34 @@ THE SOFTWARE. #include #include +#ifndef __EMSCRIPTEN__ +#include +#endif + +#ifdef __EMSCRIPTEN__ +bool parseHex(const char *str, unsigned int *result_) { + auto &result = *result_; + result = 0; + for (int i = 0; i < 4; ++i) { + char c = str[i]; + if ((c < '0' || c > '9') && (c < 'A' || c > 'F') && (c < 'a' || c > 'f')) { + result = 0; + return false; + } + + result <<= 4; + if (c >= '0' && c <= '9') { + result |= (c - '0'); + } else if (c >= 'A' && c <= 'F') { + result |= (c - 'A' + 10); + } else if (c >= 'a' && c <= 'f') { + result |= (c - 'a' + 10); + } + } + return true; +} + +#endif using namespace spine; @@ -263,7 +291,11 @@ const char *Json::parseString(Json *item, const char *str) { break; case 'u': { /* transcode utf16 to utf8. */ +#ifdef __EMSCRIPTEN__ + parseHex(ptr + 1, &uc); +#else sscanf(ptr + 1, "%4x", &uc); +#endif ptr += 4; /* get the unicode char. */ if ((uc >= 0xDC00 && uc <= 0xDFFF) || uc == 0) { @@ -275,7 +307,11 @@ const char *Json::parseString(Json *item, const char *str) { if (ptr[1] != '\\' || ptr[2] != 'u') { break; /* missing second-half of surrogate. */ } +#ifdef __EMSCRIPTEN__ + parseHex(ptr + 3, &uc2); +#else sscanf(ptr + 3, "%4x", &uc2); +#endif ptr += 6; if (uc2 < 0xDC00 || uc2 > 0xDFFF) { break; /* invalid second-half of surrogate. */ diff --git a/native/cocos/editor-support/spine/Skeleton.cpp b/native/cocos/editor-support/spine/Skeleton.cpp index c0896e9781c..67deee47364 100644 --- a/native/cocos/editor-support/spine/Skeleton.cpp +++ b/native/cocos/editor-support/spine/Skeleton.cpp @@ -55,6 +55,10 @@ #include +#ifndef __EMSCRIPTEN__ +#include +#endif + using namespace spine; Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData), @@ -197,6 +201,7 @@ void Skeleton::updateCache() { } void Skeleton::printUpdateCache() { +#ifndef __EMSCRIPTEN__ for (size_t i = 0; i < _updateCache.size(); i++) { Updatable *updatable = _updateCache[i]; if (updatable->getRTTI().isExactly(Bone::rtti)) { @@ -209,6 +214,7 @@ void Skeleton::printUpdateCache() { printf("path constraint %s\n", ((PathConstraint *)updatable)->getData().getName().buffer()); } } +#endif } void Skeleton::updateWorldTransform() { @@ -369,8 +375,9 @@ void Skeleton::setAttachment(const String &slotName, const String &attachmentNam return; } } - +#ifndef __EMSCRIPTEN__ printf("Slot not found: %s", slotName.buffer()); +#endif assert(false); } diff --git a/native/cocos/editor-support/spine/SpineObject.h b/native/cocos/editor-support/spine/SpineObject.h index 5c08549b691..6f2e3feec29 100644 --- a/native/cocos/editor-support/spine/SpineObject.h +++ b/native/cocos/editor-support/spine/SpineObject.h @@ -56,14 +56,14 @@ class SP_API SpineObject { }; } // namespace spine -#if DEBUG_NEW - #define __SPINE_FILE__ __FILE__ - #define __SPINE_LINE__ __LINE__ - #define spine_new new (__FILE__, __LINE__) -#else +#ifdef __EMSCRIPTEN__ #define __SPINE_FILE__ "" #define __SPINE_LINE__ __LINE__ #define spine_new new +#else + #define __SPINE_FILE__ __FILE__ + #define __SPINE_LINE__ __LINE__ + #define spine_new new (__FILE__, __LINE__) #endif #endif diff --git a/native/cocos/editor-support/spine/SpineString.cpp b/native/cocos/editor-support/spine/SpineString.cpp index d72601b5bf1..c86cfc439f2 100644 --- a/native/cocos/editor-support/spine/SpineString.cpp +++ b/native/cocos/editor-support/spine/SpineString.cpp @@ -152,6 +152,7 @@ String &String::append(const String &other) { return *this; } +#ifndef __EMSCRIPTEN__ String &String::append(int other) { char str[100]; sprintf(str, "%i", other); @@ -165,6 +166,7 @@ String &String::append(float other) { append(str); return *this; } +#endif bool operator==(const String &a, const String &b) { if (a._buffer == b._buffer) return true; diff --git a/native/cocos/editor-support/spine/SpineString.h b/native/cocos/editor-support/spine/SpineString.h index e66f3d2b561..32c349e5fb9 100644 --- a/native/cocos/editor-support/spine/SpineString.h +++ b/native/cocos/editor-support/spine/SpineString.h @@ -32,7 +32,6 @@ #include #include -#include #include namespace spine { @@ -44,15 +43,15 @@ class SP_API String : public SpineObject { String(const String &other); ~String(); - size_t length() const { + inline size_t length() const { return _length; } - bool isEmpty() const { + inline bool isEmpty() const { return _length == 0; } - const char *buffer() const { + inline const char *buffer() const { return _buffer; } @@ -64,8 +63,11 @@ class SP_API String : public SpineObject { String &append(const char *chars); String &append(const String &other); + +#ifndef __EMSCRIPTEN__ String &append(int other); String &append(float other); +#endif friend bool operator==(const String &a, const String &b); friend bool operator!=(const String &a, const String &b); From bd721e0f1d6cec3d0eae3228324201512dd069d5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 16:14:14 +0800 Subject: [PATCH 49/80] Update CMAKE --- .../editor-support/spine-wasm/CMakeLists.txt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index 913bdeb1813..d61f9aad590 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -23,9 +23,10 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) +# --profiling set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override \ - -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti \ + -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") message(">>> --------------------------------------------------------------") message(">>> Current directory: ${CMAKE_CURRENT_LIST_DIR}") @@ -41,15 +42,15 @@ file(GLOB COCOS_ADAPTER_SRC "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC}) -# -s EMBIND_AOT=0 -set(EMS_LINK_FLAGS "-s VERBOSE=0 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ - -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ - -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ - -s MIN_SAFARI_VERSION=110000 \ - -s EXPORTED_FUNCTIONS=['_spineListenerCallBackFromJS','_spineTrackListenerCallback'] \ - --js-library ../library_spine.js \ - --closure=${ENABLE_CLOSURE_COMPILER} \ - --closure-args=--externs=../library_spine_externs.js") +# -s EMBIND_AOT=0 -s MALLOC=emmalloc +set(EMS_LINK_FLAGS "-s VERBOSE=1 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ + -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ + -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ + -s MIN_SAFARI_VERSION=110000 \ + -s EXPORTED_FUNCTIONS=['_spineListenerCallBackFromJS','_spineTrackListenerCallback'] \ + --js-library ../library_spine.js \ + --closure=${ENABLE_CLOSURE_COMPILER} \ + --closure-args=--externs=../library_spine_externs.js") set_target_properties(${APP_NAME} PROPERTIES CXX_STANDARD 11 LINK_FLAGS ${EMS_LINK_FLAGS}) \ No newline at end of file From a5431a0ba6041ba7f39f451df26d71972f484224 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 16:14:29 +0800 Subject: [PATCH 50/80] Update CMakeLists.header.txt --- .../editor-support/spine-wasm/scripts/CMakeLists.header.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/native/cocos/editor-support/spine-wasm/scripts/CMakeLists.header.txt b/native/cocos/editor-support/spine-wasm/scripts/CMakeLists.header.txt index cfa01c69663..0518cb24df4 100644 --- a/native/cocos/editor-support/spine-wasm/scripts/CMakeLists.header.txt +++ b/native/cocos/editor-support/spine-wasm/scripts/CMakeLists.header.txt @@ -2,4 +2,6 @@ cmake_minimum_required(VERSION 3.8) project(spine_wasm_header CXX) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__EMSCRIPTEN__=1") + include(${CMAKE_CURRENT_LIST_DIR}/../../CMakeLists.txt) \ No newline at end of file From 31d7b7cbbc733c4e6ca12ed1f2b99f17888f38f7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 16:16:53 +0800 Subject: [PATCH 51/80] Update property binding, reduce property binding size. --- .../spine-wasm/spine-type-export.cpp | 295 +++++++++--------- native/cocos/editor-support/spine/Animation.h | 2 + .../editor-support/spine/AnimationState.h | 3 +- .../editor-support/spine/AnimationStateData.h | 3 +- .../editor-support/spine/AttachmentTimeline.h | 2 + native/cocos/editor-support/spine/Bone.cpp | 180 +---------- native/cocos/editor-support/spine/Bone.h | 182 ++++++++--- native/cocos/editor-support/spine/BoneData.h | 2 + .../editor-support/spine/ColorTimeline.h | 4 + .../editor-support/spine/ConstraintData.h | 2 + .../editor-support/spine/DeformTimeline.h | 2 + native/cocos/editor-support/spine/Event.h | 3 + native/cocos/editor-support/spine/EventData.h | 3 + .../cocos/editor-support/spine/IkConstraint.h | 2 + .../editor-support/spine/IkConstraintData.h | 2 + .../editor-support/spine/MeshAttachment.h | 2 + .../editor-support/spine/PathAttachment.h | 2 + .../editor-support/spine/PathConstraint.h | 3 +- .../editor-support/spine/PathConstraintData.h | 2 + .../editor-support/spine/PointAttachment.h | 2 + .../editor-support/spine/RegionAttachment.h | 4 + .../editor-support/spine/RotateTimeline.h | 3 +- .../cocos/editor-support/spine/Skeleton.cpp | 45 --- native/cocos/editor-support/spine/Skeleton.h | 68 ++-- .../cocos/editor-support/spine/SkeletonData.h | 3 +- native/cocos/editor-support/spine/SlotData.h | 2 + .../spine/TransformConstraint.h | 2 + .../editor-support/spine/VertexAttachment.h | 2 + .../cocos/editor-support/spine/VertexEffect.h | 4 + 29 files changed, 388 insertions(+), 443 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 119ccbb2467..5663eed4ae0 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -570,34 +570,34 @@ EMSCRIPTEN_BINDINGS(spine) { class_("ConstraintData") .constructor() .property("name", &ConstraintData::getName) - .property("order", &ConstraintData::getOrder, &ConstraintData::setOrder) - .property("skinRequired", &ConstraintData::isSkinRequired, &ConstraintData::setSkinRequired); + .property("order", &ConstraintData::_order) + .property("skinRequired", &ConstraintData::_skinRequired); class_>("IkConstraintData") .constructor() .function("getBones", optional_override([](IkConstraintData &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .property("target", &IkConstraintData::getTarget, &IkConstraintData::setTarget) - .property("bendDirection", &IkConstraintData::getBendDirection, &IkConstraintData::setBendDirection) - .property("compress", &IkConstraintData::getCompress, &IkConstraintData::setCompress) - .property("stretch", &IkConstraintData::getStretch, &IkConstraintData::setStretch) - .property("uniform", &IkConstraintData::getUniform, &IkConstraintData::setUniform) - .property("mix", &IkConstraintData::getMix, &IkConstraintData::setMix) - .property("softness", &IkConstraintData::getSoftness, &IkConstraintData::setSoftness); + .property("target", &IkConstraintData::_target) + .property("bendDirection", &IkConstraintData::_bendDirection) + .property("compress", &IkConstraintData::_compress) + .property("stretch", &IkConstraintData::_stretch) + .property("uniform", &IkConstraintData::_uniform) + .property("mix", &IkConstraintData::_mix) + .property("softness", &IkConstraintData::_softness); class_>("PathConstraintData") .constructor() .function("getBones",optional_override([](PathConstraintData &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .property("target", &PathConstraintData::getTarget, &PathConstraintData::setTarget) - .property("positionMode", &PathConstraintData::getPositionMode, &PathConstraintData::setPositionMode) - .property("spacingMode", &PathConstraintData::getSpacingMode, &PathConstraintData::setSpacingMode) - .property("rotateMode", &PathConstraintData::getRotateMode, &PathConstraintData::setRotateMode) - .property("offsetRotation", &PathConstraintData::getOffsetRotation, &PathConstraintData::setOffsetRotation) - .property("position", &PathConstraintData::getPosition, &PathConstraintData::setPosition) - .property("spacing", &PathConstraintData::getSpacing, &PathConstraintData::setSpacing) - .property("rotateMix", &PathConstraintData::getRotateMix, &PathConstraintData::setRotateMix) - .property("translateMix", &PathConstraintData::getTranslateMix, &PathConstraintData::setTranslateMix); + .property("target", &PathConstraintData::_target) + .property("positionMode", &PathConstraintData::_positionMode) + .property("spacingMode", &PathConstraintData::_spacingMode) + .property("rotateMode", &PathConstraintData::_rotateMode) + .property("offsetRotation", &PathConstraintData::_offsetRotation) + .property("position", &PathConstraintData::_position) + .property("spacing", &PathConstraintData::_spacing) + .property("rotateMix", &PathConstraintData::_rotateMix) + .property("translateMix", &PathConstraintData::_translateMix); class_("SkeletonBounds") .constructor<>() @@ -621,22 +621,22 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Event") .constructor() .property("data", GETTER_RVAL_TO_PTR(Event, getData, EventData*)) - .property("intValue", &Event::getIntValue, &Event::setIntValue) - .property("floatValue", &Event::getFloatValue, &Event::setFloatValue) - .property("stringValue", &Event::getStringValue, &Event::setStringValue) - .property("time", &Event::getTime) - .property("volume", &Event::getVolume, &Event::setVolume) - .property("balance", &Event::getBalance, &Event::setBalance); + .property("intValue", &Event::_intValue) + .property("floatValue", &Event::_floatValue) + .property("stringValue", &Event::_stringValue) + .property("time", &Event::_time) + .property("volume", &Event::_volume) + .property("balance", &Event::_balance); class_("EventData") .constructor() .property("name", &EventData::getName) - .property("intValue", &EventData::getIntValue, &EventData::setIntValue) - .property("floatValue", &EventData::getFloatValue, &EventData::setFloatValue) - .property("stringValue", &EventData::getStringValue, &EventData::setStringValue) - .property("audioPath", &EventData::getAudioPath, &EventData::setAudioPath) - .property("volume", &EventData::getVolume, &EventData::setVolume) - .property("balance", &EventData::getBalance, &EventData::setBalance); + .property("intValue", &EventData::_intValue) + .property("floatValue", &EventData::_floatValue) + .property("stringValue", &EventData::_stringValue) + .property("audioPath", &EventData::_audioPath) + .property("volume", &EventData::_volume) + .property("balance", &EventData::_balance); class_("Attachment") .property("name", &Attachment::getName); @@ -648,8 +648,8 @@ EMSCRIPTEN_BINDINGS(spine) { return &obj.getBones(); }), allow_raw_pointer()) .function("getVertices", optional_override([](VertexAttachment &obj){ return &obj.getVertices(); }), allow_raw_pointer()) - .property("worldVerticesLength", &VertexAttachment::getWorldVerticesLength, &VertexAttachment::setWorldVerticesLength) - .property("deformAttachment", &VertexAttachment::getDeformAttachment, &VertexAttachment::setDeformAttachment) + .property("worldVerticesLength", &VertexAttachment::_worldVerticesLength) + .property("deformAttachment", &VertexAttachment::_deformAttachment) .function("computeWorldVertices", select_overload&, size_t, size_t)> (&VertexAttachment::computeWorldVertices), allow_raw_pointer()) .function("copyTo", &VertexAttachment::copyTo, allow_raw_pointers()); @@ -666,7 +666,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("MeshAttachment") .constructor() - .property("path", &MeshAttachment::getPath, &MeshAttachment::setPath) + .property("path", &MeshAttachment::_path) .function("getRegionUVs", optional_override([](MeshAttachment &obj) { return &obj.getRegionUVs(); }), allow_raw_pointer()) .function("getUVs", optional_override([](MeshAttachment &obj) { @@ -674,9 +674,9 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getTriangles", optional_override([](MeshAttachment &obj) { return &obj.getTriangles(); }), allow_raw_pointer()) .property("color", GETTER_RVAL_TO_PTR(MeshAttachment, getColor, Color*)) - .property("width", &MeshAttachment::getWidth, &MeshAttachment::setWidth) - .property("height", &MeshAttachment::getHeight, &MeshAttachment::setHeight) - .property("hullLength", &MeshAttachment::getHullLength, &MeshAttachment::setHullLength) + .property("width", &MeshAttachment::_width) + .property("height", &MeshAttachment::_height) + .property("hullLength", &MeshAttachment::_hullLength) .function("getEdges", optional_override([](MeshAttachment &obj) { return &obj.getEdges(); }), allow_raw_pointer()) .function("updateUVs", &MeshAttachment::updateUVs) @@ -689,15 +689,15 @@ EMSCRIPTEN_BINDINGS(spine) { .constructor() .function("getLengths", optional_override([](PathAttachment &obj) { return &obj.getLengths(); }), allow_raw_pointer()) - .property("closed", &PathAttachment::isClosed, &PathAttachment::setClosed) - .property("constantSpeed", &PathAttachment::isConstantSpeed, &PathAttachment::setConstantSpeed) + .property("closed", &PathAttachment::_closed) + .property("constantSpeed", &PathAttachment::_constantSpeed) .function("copy", &PathAttachment::copy, allow_raw_pointers()); class_>("PointAttachment") .constructor() - .property("x", &PointAttachment::getX, &PointAttachment::setX) - .property("y", &PointAttachment::getY, &PointAttachment::setY) - .property("rotation", &PointAttachment::getRotation, &PointAttachment::setRotation) + .property("x", &PointAttachment::_x) + .property("y", &PointAttachment::_y) + .property("rotation", &PointAttachment::_rotation) .function("computeWorldPosition", optional_override([](PointAttachment &obj, Bone &bone, float ox, float oy) { obj.computeWorldPosition(bone, ox, oy);})) .function("computeWorldRotation", &PointAttachment::computeWorldRotation) @@ -705,15 +705,15 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("RegionAttachment") .constructor() - .property("x", &RegionAttachment::getX, &RegionAttachment::setX) - .property("y", &RegionAttachment::getY, &RegionAttachment::setY) - .property("scaleX", &RegionAttachment::getScaleX, &RegionAttachment::setScaleX) - .property("scaleY", &RegionAttachment::getScaleY, &RegionAttachment::setScaleY) - .property("rotation", &RegionAttachment::getRotation, &RegionAttachment::setRotation) - .property("width", &RegionAttachment::getWidth, &RegionAttachment::setWidth) - .property("height", &RegionAttachment::getHeight, &RegionAttachment::setHeight) + .property("x", &RegionAttachment::_x) + .property("y", &RegionAttachment::_y) + .property("scaleX", &RegionAttachment::_scaleX) + .property("scaleY", &RegionAttachment::_scaleY) + .property("rotation", &RegionAttachment::_rotation) + .property("width", &RegionAttachment::_width) + .property("height", &RegionAttachment::_height) .property("color", GETTER_RVAL_TO_PTR(RegionAttachment, getColor, Color*)) - .property("path", &RegionAttachment::getPath, &RegionAttachment::setPath) + .property("path", &RegionAttachment::_path) //FIXME(cjh): .function("getRendererObject", &RegionAttachment::getRendererObject, allow_raw_pointers()) .function("getOffset", optional_override([](RegionAttachment &obj) { return &obj.getOffset(); }), allow_raw_pointer()) @@ -785,7 +785,7 @@ EMSCRIPTEN_BINDINGS(spine) { .property("boneData", GETTER_RVAL_TO_PTR(SlotData, getBoneData, BoneData*)) .property("color", GETTER_RVAL_TO_PTR(SlotData, getColor, Color*)) .property("darkColor", GETTER_RVAL_TO_PTR(SlotData, getDarkColor, Color*)) - .property("blendMode", &SlotData::getBlendMode, &SlotData::setBlendMode); + .property("blendMode", &SlotData::_blendMode); class_("Updatable") .function("update", &Updatable::update, pure_virtual()) @@ -798,12 +798,12 @@ EMSCRIPTEN_BINDINGS(spine) { .property("data", GETTER_RVAL_TO_PTR(IkConstraint, getData, IkConstraintData*)) .function("getBones", optional_override([](IkConstraint &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .property("target", &IkConstraint::getTarget, &IkConstraint::setTarget) - .property("bendDirection", &IkConstraint::getBendDirection, &IkConstraint::setBendDirection) - .property("compress", &IkConstraint::getCompress, &IkConstraint::setCompress) - .property("stretch", &IkConstraint::getStretch, &IkConstraint::setStretch) - .property("mix", &IkConstraint::getMix, &IkConstraint::setMix) - .property("softness", &IkConstraint::getSoftness, &IkConstraint::setSoftness) + .property("target", &IkConstraint::_target) + .property("bendDirection", &IkConstraint::_bendDirection) + .property("compress", &IkConstraint::_compress) + .property("stretch", &IkConstraint::_stretch) + .property("mix", &IkConstraint::_mix) + .property("softness", &IkConstraint::_softness) .class_function("apply1", select_overload(&IkConstraint::apply)) .class_function("apply2", select_overload(&IkConstraint::apply)) ; @@ -813,11 +813,11 @@ EMSCRIPTEN_BINDINGS(spine) { .property("data", GETTER_RVAL_TO_PTR(PathConstraint, getData, PathConstraintData*)) .function("getBones", optional_override([](PathConstraint &obj) { return &obj.getBones(); }), allow_raw_pointer()) - .property("target", &PathConstraint::getTarget, &PathConstraint::setTarget) - .property("position", &PathConstraint::getPosition, &PathConstraint::setPosition) - .property("spacing", &PathConstraint::getSpacing, &PathConstraint::setSpacing) - .property("rotateMix", &PathConstraint::getRotateMix, &PathConstraint::setRotateMix) - .property("translateMix", &PathConstraint::getTranslateMix, &PathConstraint::setTranslateMix) + .property("target", &PathConstraint::_target) + .property("position", &PathConstraint::_position) + .property("spacing", &PathConstraint::_spacing) + .property("rotateMix", &PathConstraint::_rotateMix) + .property("translateMix", &PathConstraint::_translateMix) ; class_>("TransformConstraintData") @@ -844,10 +844,10 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getBones", optional_override([](TransformConstraint &obj) { return &obj.getBones(); }), allow_raw_pointer()) .property("target", &TransformConstraint::getTarget) - .property("rotateMix", &TransformConstraint::getRotateMix, &TransformConstraint::setRotateMix) - .property("translateMix", &TransformConstraint::getTranslateMix, &TransformConstraint::setTranslateMix) - .property("scaleMix", &TransformConstraint::getScaleMix, &TransformConstraint::setScaleMix) - .property("shearMix", &TransformConstraint::getShearMix, &TransformConstraint::setShearMix) + .property("rotateMix", &TransformConstraint::_rotateMix) + .property("translateMix", &TransformConstraint::_translateMix) + .property("scaleMix", &TransformConstraint::_scaleMix) + .property("shearMix", &TransformConstraint::_shearMix) ; class_>("Bone") @@ -857,27 +857,27 @@ EMSCRIPTEN_BINDINGS(spine) { .property("parent", &Bone::getParent) .function("getChildren", optional_override([](Bone &obj) { return &obj.getChildren(); }), allow_raw_pointer()) - .property("x", &Bone::getX, &Bone::setX) - .property("y", &Bone::getY, &Bone::setY) - .property("rotation", &Bone::getRotation, &Bone::setRotation) - .property("scaleX", &Bone::getScaleX, &Bone::setScaleX) - .property("scaleY", &Bone::getScaleY, &Bone::setScaleY) - .property("shearX", &Bone::getShearX, &Bone::setShearX) - .property("shearY", &Bone::getShearY, &Bone::setShearY) - .property("ax", &Bone::getAX, &Bone::setAX) - .property("ay", &Bone::getAY, &Bone::setAY) - .property("arotation", &Bone::getAppliedRotation, &Bone::setAppliedRotation) - .property("ascaleX", &Bone::getAScaleX, &Bone::setAScaleX) - .property("ascaleY", &Bone::getAScaleY, &Bone::setAScaleY) - .property("ashearX", &Bone::getAShearX, &Bone::setAShearX) - .property("ashearY", &Bone::getAShearY, &Bone::setAShearY) - .property("appliedValid", &Bone::isAppliedValid, &Bone::setAppliedValid) - .property("a", &Bone::getA, &Bone::setA) - .property("b", &Bone::getB, &Bone::setB) - .property("c", &Bone::getC, &Bone::setC) - .property("d", &Bone::getD, &Bone::setD) - .property("worldX", &Bone::getWorldX, &Bone::setWorldX) - .property("worldY", &Bone::getWorldY, &Bone::setWorldY) + .property("x", &Bone::_x) + .property("y", &Bone::_y) + .property("rotation", &Bone::_rotation) + .property("scaleX", &Bone::_scaleX) + .property("scaleY", &Bone::_scaleY) + .property("shearX", &Bone::_shearX) + .property("shearY", &Bone::_shearY) + .property("ax", &Bone::_ax) + .property("ay", &Bone::_ay) + .property("arotation", &Bone::_arotation) + .property("ascaleX", &Bone::_ascaleX) + .property("ascaleY", &Bone::_ascaleY) + .property("ashearX", &Bone::_ashearX) + .property("ashearY", &Bone::_ashearY) + .property("appliedValid", &Bone::_appliedValid) + .property("a", &Bone::_a) + .property("b", &Bone::_b) + .property("c", &Bone::_c) + .property("d", &Bone::_d) + .property("worldX", &Bone::_worldX) + .property("worldY", &Bone::_worldY) .function("updateWorldTransform", select_overload(&Bone::updateWorldTransform)) .function("updateWorldTransformWith", select_overload(&Bone::updateWorldTransform)) @@ -910,17 +910,17 @@ EMSCRIPTEN_BINDINGS(spine) { .constructor() .property("index", &BoneData::getIndex) .property("name", &BoneData::getName) //FIXME(cjh): Don't copy string - .property("parent", &BoneData::getParent) - .property("length", &BoneData::getLength, &BoneData::setLength) - .property("x", &BoneData::getX, &BoneData::setX) - .property("y", &BoneData::getY, &BoneData::setY) - .property("rotation", &BoneData::getRotation, &BoneData::setRotation) - .property("scaleX", &BoneData::getScaleX, &BoneData::setScaleX) - .property("scaleY", &BoneData::getScaleY, &BoneData::setScaleY) - .property("shearX", &BoneData::getShearX, &BoneData::setShearX) - .property("shearY", &BoneData::getShearY, &BoneData::setShearY) - .property("transformMode", &BoneData::getTransformMode, &BoneData::setTransformMode) - .property("skinRequired", &BoneData::isSkinRequired, &BoneData::setSkinRequired); + .property("parent", &BoneData::_parent) + .property("length", &BoneData::_length) + .property("x", &BoneData::_x) + .property("y", &BoneData::_y) + .property("rotation", &BoneData::_rotation) + .property("scaleX", &BoneData::_scaleX) + .property("scaleY", &BoneData::_scaleY) + .property("shearX", &BoneData::_shearX) + .property("shearY", &BoneData::_shearY) + .property("transformMode", &BoneData::_transformMode) + .property("skinRequired", &BoneData::_skinRequired); class_("Slot") @@ -994,14 +994,14 @@ EMSCRIPTEN_BINDINGS(spine) { class_("SkeletonData") .constructor<>() - .property("name", &SkeletonData::getName, &SkeletonData::setName) + .property("name", &SkeletonData::_name) .function("getBones", optional_override([](SkeletonData &obj) { return &obj.getBones(); }), allow_raw_pointer()) .function("getSlots", optional_override([](SkeletonData &obj) { return &obj.getSlots(); }), allow_raw_pointer()) .function("getSkins", optional_override([](SkeletonData &obj) { return &obj.getSkins(); }), allow_raw_pointer()) - .property("defaultSkin", &SkeletonData::getDefaultSkin, &SkeletonData::setDefaultSkin) + .property("defaultSkin", &SkeletonData::_defaultSkin) .function("getEvents", optional_override([](SkeletonData &obj) { return &obj.getEvents(); }), allow_raw_pointer()) .function("getAnimations", optional_override([](SkeletonData &obj) { @@ -1012,15 +1012,15 @@ EMSCRIPTEN_BINDINGS(spine) { return &obj.getTransformConstraints(); }), allow_raw_pointer()) .function("getPathConstraints", optional_override([](SkeletonData &obj) { return &obj.getPathConstraints(); }), allow_raw_pointer()) - .property("x", &SkeletonData::getX, &SkeletonData::setX) - .property("y", &SkeletonData::getY, &SkeletonData::setY) - .property("width", &SkeletonData::getWidth, &SkeletonData::setWidth) - .property("height", &SkeletonData::getHeight, &SkeletonData::setHeight) - .property("version", &SkeletonData::getVersion, &SkeletonData::setVersion) - .property("hash", &SkeletonData::getHash, &SkeletonData::setHash) - .property("fps", &SkeletonData::getFps, &SkeletonData::setFps) - .property("imagesPath", &SkeletonData::getImagesPath, &SkeletonData::setImagesPath) - .property("audioPath", &SkeletonData::getAudioPath, &SkeletonData::setAudioPath) + .property("x", &SkeletonData::_x) + .property("y", &SkeletonData::_y) + .property("width", &SkeletonData::_width) + .property("height", &SkeletonData::_height) + .property("version", &SkeletonData::_version) + .property("hash", &SkeletonData::_hash) + .property("fps", &SkeletonData::_fps) + .property("imagesPath", &SkeletonData::_imagesPath) + .property("audioPath", &SkeletonData::_audioPath) .function("findBone", &SkeletonData::findBone, allow_raw_pointers()) .function("findBoneIndex", &SkeletonData::findBoneIndex) @@ -1048,7 +1048,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getTimelines", optional_override([](Animation &obj) { return &obj.getTimelines(); }), allow_raw_pointer()) .function("hasTimeline", &Animation::hasTimeline) - .property("duration", &Animation::getDuration, &Animation::setDuration); + .property("duration", &Animation::_duration); class_("Timeline") .function("getPropertyId", &Timeline::getPropertyId, pure_virtual()); @@ -1077,14 +1077,14 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("RotateTimeline") .constructor() //.class_property("ENTRIES", &RotateTimeline::ENTRIES) not bind - .property("boneIndex", &RotateTimeline::getBoneIndex, &RotateTimeline::setBoneIndex) + .property("boneIndex", &RotateTimeline::_boneIndex) .function("getFrames", GETTER_RVAL_TO_PTR(RotateTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("setFrame", &RotateTimeline::setFrame); class_>("ColorTimeline") .constructor() .class_property("ENTRIES", &ColorTimeline::ENTRIES) - .property("slotIndex", &ColorTimeline::getSlotIndex, &ColorTimeline::setSlotIndex) + .property("slotIndex", &ColorTimeline::_slotIndex) .function("getFrames", GETTER_RVAL_TO_PTR(ColorTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("setFrame", &ColorTimeline::setFrame); @@ -1097,7 +1097,7 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("AttachmentTimeline") .constructor() - .property("slotIndex", &AttachmentTimeline::getSlotIndex, &AttachmentTimeline::setSlotIndex) + .property("slotIndex", &AttachmentTimeline::_slotIndex) .function("getFrames", GETTER_RVAL_TO_PTR(AttachmentTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("getAttachmentNames", &AttachmentTimeline::getAttachmentNames) .function("getFrameCount", &AttachmentTimeline::getFrameCount) @@ -1105,8 +1105,8 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("DeformTimeline") .constructor() - .property("slotIndex", &DeformTimeline::getSlotIndex, &DeformTimeline::setSlotIndex) - .property("attachment", &DeformTimeline::getAttachment, &DeformTimeline::setAttachment) + .property("slotIndex", &DeformTimeline::_slotIndex) + .property("attachment", &DeformTimeline::_attachment) .function("getFrames", GETTER_RVAL_TO_PTR(DeformTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) .function("getFrameVertices", optional_override([](DeformTimeline &obj) { return &obj.getVertices(); }), allow_raw_pointer()) @@ -1164,39 +1164,30 @@ EMSCRIPTEN_BINDINGS(spine) { .property("mixingTo", &TrackEntry::getMixingTo) //.function("getProp_listener", &TrackEntry::listener) .property("trackIndex", &TrackEntry::getTrackIndex) - .property("loop", &TrackEntry::getLoop, &TrackEntry::setLoop) - .property("holdPrevious", &TrackEntry::getHoldPrevious, &TrackEntry::setHoldPrevious) - .property("eventThreshold", &TrackEntry::getEventThreshold, &TrackEntry::setEventThreshold) - .property("attachmentThreshold", &TrackEntry::getAttachmentThreshold, &TrackEntry::setAttachmentThreshold) - .property("drawOrderThreshold", &TrackEntry::getDrawOrderThreshold, &TrackEntry::setDrawOrderThreshold) - .property("animationStart", &TrackEntry::getAnimationStart, &TrackEntry::setAnimationStart) - .property("animationEnd", &TrackEntry::getAnimationEnd, &TrackEntry::setAnimationEnd) + .property("loop", &TrackEntry::_loop) + .property("holdPrevious", &TrackEntry::_holdPrevious) + .property("eventThreshold", &TrackEntry::_eventThreshold) + .property("attachmentThreshold", &TrackEntry::_attachmentThreshold) + .property("drawOrderThreshold", &TrackEntry::_drawOrderThreshold) + .property("animationStart", &TrackEntry::_animationStart) + .property("animationEnd", &TrackEntry::_animationEnd) .property("animationLast", &TrackEntry::getAnimationLast, &TrackEntry::setAnimationLast) - //.function("getProp_nextAnimationLast", &TrackEntry::nextAnimationLast) - .property("delay", &TrackEntry::getDelay, &TrackEntry::setDelay) - .property("trackTime", &TrackEntry::getTrackTime, &TrackEntry::setTrackTime) - //.function("getProp_trackLast", &TrackEntry::trackLast) - //.function("getProp_nextTrackLast", &TrackEntry::nextTrackLast) - .property("trackEnd", &TrackEntry::getTrackEnd, &TrackEntry::setTrackEnd) - .property("timeScale", &TrackEntry::getTimeScale, &TrackEntry::setTimeScale) - .property("alpha", &TrackEntry::getAlpha, &TrackEntry::setAlpha) - .property("mixTime", &TrackEntry::getMixTime, &TrackEntry::setMixTime) - .property("mixDuration", &TrackEntry::getMixDuration, &TrackEntry::setMixDuration) - //.function("getProp_interruptAlpha", &TrackEntry::_interruptAlpha) - //.function("getProp_totalAlpha", &TrackEntry::getAlpha) - .property("mixBlend", &TrackEntry::getMixBlend, &TrackEntry::setMixBlend) - - //.function("getProp_timelineMode", &TrackEntry::timelineMode) - //.function("getProp_timelineHoldMix", &TrackEntry::timelineHoldMix) - //.function("getProp_timelinesRotation", &TrackEntry::timelinesRotation) - //.function("reset", &TrackEntry::reset) //private + .property("delay", &TrackEntry::_delay) + .property("trackTime", &TrackEntry::_trackTime) + .property("trackEnd", &TrackEntry::_trackEnd) + .property("timeScale", &TrackEntry::_timeScale) + .property("alpha", &TrackEntry::_alpha) + .property("mixTime", &TrackEntry::_mixTime) + .property("mixDuration", &TrackEntry::_mixDuration) + .property("mixBlend", &TrackEntry::_mixBlend) + .function("getAnimationTime", &TrackEntry::getAnimationTime) .function("isComplete", &TrackEntry::isComplete) .function("resetRotationDirections", &TrackEntry::resetRotationDirections); class_("AnimationStateData") .constructor() - .property("defaultMix", &AnimationStateData::getDefaultMix, &AnimationStateData::setDefaultMix) + .property("defaultMix", &AnimationStateData::_defaultMix) .property("skeletonData", &AnimationStateData::getSkeletonData) .function("setMix", select_overload(&AnimationStateData::setMix), allow_raw_pointers()) .function("setMixWith", select_overload(&AnimationStateData::setMix), allow_raw_pointers()) @@ -1269,11 +1260,11 @@ EMSCRIPTEN_BINDINGS(spine) { return &obj.getUpdateCacheList(); }), allow_raw_pointer()) .property("skin", &Skeleton::getSkin) .property("color", GETTER_RVAL_TO_PTR(Skeleton, getColor, Color*)) - .property("time", &Skeleton::getTime, &Skeleton::setTime) - .property("scaleX", &Skeleton::getScaleX, &Skeleton::setScaleX) - .property("scaleY", &Skeleton::getScaleY, &Skeleton::setScaleY) - .property("x", &Skeleton::getX, &Skeleton::setX) - .property("y", &Skeleton::getY, &Skeleton::setY) + .property("time", &Skeleton::_time) + .property("scaleX", &Skeleton::_scaleX) + .property("scaleY", &Skeleton::_scaleY) + .property("x", &Skeleton::_x) + .property("y", &Skeleton::_y) .function("updateCache", &Skeleton::updateCache) .function("updateWorldTransform", &Skeleton::updateWorldTransform) @@ -1319,8 +1310,8 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("JitterEffect") .constructor() - .property("jitterX", &JitterVertexEffect::getJitterX, &JitterVertexEffect::setJitterX) - .property("jitterY", &JitterVertexEffect::getJitterY, &JitterVertexEffect::setJitterY) + .property("jitterX", &JitterVertexEffect::_jitterX) + .property("jitterY", &JitterVertexEffect::_jitterY) .function("begin", &JitterVertexEffect::begin) .function("transform", optional_override([](VertexEffect &obj, float x, float y) { obj.transform(x, y); }), pure_virtual()) @@ -1333,12 +1324,12 @@ EMSCRIPTEN_BINDINGS(spine) { obj.transform(x, y); }), pure_virtual()) .function("end", &SwirlVertexEffect::end) - .property("centerX", &SwirlVertexEffect::getCenterX, &SwirlVertexEffect::setCenterX) - .property("centerY", &SwirlVertexEffect::getCenterY, &SwirlVertexEffect::setCenterY) - .property("radius", &SwirlVertexEffect::getRadius, &SwirlVertexEffect::setRadius) + .property("centerX", &SwirlVertexEffect::_centerX) + .property("centerY", &SwirlVertexEffect::_centerY) + .property("radius", &SwirlVertexEffect::_radius) .property("angle", &SwirlVertexEffect::getAngle, &SwirlVertexEffect::setAngle) - .property("worldX", &SwirlVertexEffect::getWorldX, &SwirlVertexEffect::setWorldX) - .property("worldY", &SwirlVertexEffect::getWorldY, &SwirlVertexEffect::setWorldY); + .property("worldX", &SwirlVertexEffect::_worldX) + .property("worldY", &SwirlVertexEffect::_worldY); class_("SpineModel") .property("vCount", &SpineModel::vCount) diff --git a/native/cocos/editor-support/spine/Animation.h b/native/cocos/editor-support/spine/Animation.h index 8d2e42ba1b3..22ed8fc3035 100644 --- a/native/cocos/editor-support/spine/Animation.h +++ b/native/cocos/editor-support/spine/Animation.h @@ -101,7 +101,9 @@ class SP_API Animation : public SpineObject { void setDuration(float inValue); +#ifndef __EMSCRIPTEN__ private: +#endif Vector _timelines; HashMap _timelineIds; float _duration; diff --git a/native/cocos/editor-support/spine/AnimationState.h b/native/cocos/editor-support/spine/AnimationState.h index eddae7070a1..be9182affa8 100644 --- a/native/cocos/editor-support/spine/AnimationState.h +++ b/native/cocos/editor-support/spine/AnimationState.h @@ -230,8 +230,9 @@ class SP_API TrackEntry : public SpineObject, public HasRendererObject { void setListener(AnimationStateListener listener); void setListener(AnimationStateListenerObject* listener); - +#ifndef __EMSCRIPTEN__ private: +#endif Animation* _animation; TrackEntry* _next; diff --git a/native/cocos/editor-support/spine/AnimationStateData.h b/native/cocos/editor-support/spine/AnimationStateData.h index 95a47e23742..c39ee87a3c5 100644 --- a/native/cocos/editor-support/spine/AnimationStateData.h +++ b/native/cocos/editor-support/spine/AnimationStateData.h @@ -64,8 +64,9 @@ class SP_API AnimationStateData : public SpineObject { /// The mix duration to use when changing from the specified animation to the other, /// or the DefaultMix if no mix duration has been set. float getMix(Animation* from, Animation* to); - +#ifndef __EMSCRIPTEN__ private: +#endif class AnimationPair : public SpineObject { public: Animation* _a1; diff --git a/native/cocos/editor-support/spine/AttachmentTimeline.h b/native/cocos/editor-support/spine/AttachmentTimeline.h index 951add5c324..e69c532f85a 100644 --- a/native/cocos/editor-support/spine/AttachmentTimeline.h +++ b/native/cocos/editor-support/spine/AttachmentTimeline.h @@ -64,7 +64,9 @@ class SP_API AttachmentTimeline : public Timeline { const Vector& getAttachmentNames(); size_t getFrameCount(); +#ifndef __EMSCRIPTEN__ private: +#endif size_t _slotIndex; Vector _frames; Vector _attachmentNames; diff --git a/native/cocos/editor-support/spine/Bone.cpp b/native/cocos/editor-support/spine/Bone.cpp index 0e174a349cb..8643693b577 100644 --- a/native/cocos/editor-support/spine/Bone.cpp +++ b/native/cocos/editor-support/spine/Bone.cpp @@ -123,7 +123,8 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, _worldX = pa * x + pb * y + parent->_worldX; _worldY = pc * x + pd * y + parent->_worldY; - switch (_data.getTransformMode()) { + const TransformMode mode = _data.getTransformMode(); + switch (mode) { case TransformMode_Normal: { float rotationY = rotation + 90 + shearY; float la = MathUtil::cosDeg(rotation + shearX) * scaleX; @@ -182,7 +183,7 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, za *= s; zc *= s; s = MathUtil::sqrt(za * za + zc * zc); - if (_data.getTransformMode() == TransformMode_NoScale && (pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) + if (mode == TransformMode_NoScale && (pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) s = -s; r = MathUtil::Pi / 2 + MathUtil::atan2(zc, za); zb = MathUtil::cos(r) * s; @@ -314,189 +315,22 @@ Vector &Bone::getChildren() { return _children; } -float Bone::getX() { - return _x; -} - -void Bone::setX(float inValue) { - _x = inValue; -} - -float Bone::getY() { - return _y; -} - -void Bone::setY(float inValue) { - _y = inValue; -} - -float Bone::getRotation() { - return _rotation; -} - -void Bone::setRotation(float inValue) { - _rotation = inValue; -} - -float Bone::getScaleX() { - return _scaleX; -} - -void Bone::setScaleX(float inValue) { - _scaleX = inValue; -} - -float Bone::getScaleY() { - return _scaleY; -} - -void Bone::setScaleY(float inValue) { - _scaleY = inValue; -} - -float Bone::getShearX() { - return _shearX; -} - -void Bone::setShearX(float inValue) { - _shearX = inValue; -} - -float Bone::getShearY() { - return _shearY; -} - -void Bone::setShearY(float inValue) { - _shearY = inValue; -} - -float Bone::getAppliedRotation() { - return _arotation; -} - -void Bone::setAppliedRotation(float inValue) { - _arotation = inValue; -} - -float Bone::getAX() { - return _ax; -} - -void Bone::setAX(float inValue) { - _ax = inValue; -} - -float Bone::getAY() { - return _ay; -} - -void Bone::setAY(float inValue) { - _ay = inValue; -} - -float Bone::getAScaleX() { - return _ascaleX; -} - -void Bone::setAScaleX(float inValue) { - _ascaleX = inValue; -} - -float Bone::getAScaleY() { - return _ascaleY; -} - -void Bone::setAScaleY(float inValue) { - _ascaleY = inValue; -} - -float Bone::getAShearX() { - return _ashearX; -} - -void Bone::setAShearX(float inValue) { - _ashearX = inValue; -} - -float Bone::getAShearY() { - return _ashearY; -} - -void Bone::setAShearY(float inValue) { - _ashearY = inValue; -} - -float Bone::getA() { - return _a; -} - -void Bone::setA(float inValue) { - _a = inValue; -} - -float Bone::getB() { - return _b; -} - -void Bone::setB(float inValue) { - _b = inValue; -} - -float Bone::getC() { - return _c; -} - -void Bone::setC(float inValue) { - _c = inValue; -} - -float Bone::getD() { - return _d; -} - -void Bone::setD(float inValue) { - _d = inValue; -} - -float Bone::getWorldX() { - return _worldX; -} - -void Bone::setWorldX(float inValue) { - _worldX = inValue; -} - -float Bone::getWorldY() { - return _worldY; -} - -void Bone::setWorldY(float inValue) { - _worldY = inValue; -} - -float Bone::getWorldRotationX() { +float Bone::getWorldRotationX() const { return MathUtil::atan2(_c, _a) * MathUtil::MathUtil::Rad_Deg; } -float Bone::getWorldRotationY() { +float Bone::getWorldRotationY() const { return MathUtil::atan2(_d, _b) * MathUtil::Rad_Deg; } -float Bone::getWorldScaleX() { +float Bone::getWorldScaleX() const { return MathUtil::sqrt(_a * _a + _c * _c); } -float Bone::getWorldScaleY() { +float Bone::getWorldScaleY() const { return MathUtil::sqrt(_b * _b + _d * _d); } -bool Bone::isAppliedValid() { - return _appliedValid; -} -void Bone::setAppliedValid(bool valid) { - _appliedValid = valid; -} - void Bone::updateAppliedTransform() { Bone *parent = _parent; _appliedValid = 1; diff --git a/native/cocos/editor-support/spine/Bone.h b/native/cocos/editor-support/spine/Bone.h index 593d65cd10a..88b12d20613 100644 --- a/native/cocos/editor-support/spine/Bone.h +++ b/native/cocos/editor-support/spine/Bone.h @@ -115,111 +115,196 @@ class SP_API Bone : public Updatable { Vector &getChildren(); /// The local X translation. - float getX(); + inline float getX() const { + return _x; + } - void setX(float inValue); + inline void setX(float inValue) { + _x = inValue; + } /// The local Y translation. - float getY(); + inline float getY() const { + return _y; + } - void setY(float inValue); + inline void setY(float inValue) { + _y = inValue; + } /// The local rotation. - float getRotation(); + inline float getRotation() const { + return _rotation; + } - void setRotation(float inValue); + inline void setRotation(float inValue) { + _rotation = inValue; + } /// The local scaleX. - float getScaleX(); + inline float getScaleX() const { + return _scaleX; + } - void setScaleX(float inValue); + inline void setScaleX(float inValue) { + _scaleX = inValue; + } /// The local scaleY. - float getScaleY(); + inline float getScaleY() const { + return _scaleY; + } - void setScaleY(float inValue); + inline void setScaleY(float inValue) { + _scaleY = inValue; + } /// The local shearX. - float getShearX(); + inline float getShearX() const { + return _shearX; + } - void setShearX(float inValue); + inline void setShearX(float inValue) { + _shearX = inValue; + } /// The local shearY. - float getShearY(); + inline float getShearY() const { + return _shearY; + } - void setShearY(float inValue); + inline void setShearY(float inValue) { + _shearY = inValue; + } /// The rotation, as calculated by any constraints. - float getAppliedRotation(); + inline float getAppliedRotation() const { + return _arotation; + } - void setAppliedRotation(float inValue); + inline void setAppliedRotation(float inValue) { + _arotation = inValue; + } /// The applied local x translation. - float getAX(); + inline float getAX() const { + return _ax; + } - void setAX(float inValue); + inline void setAX(float inValue) { + _ax = inValue; + } /// The applied local y translation. - float getAY(); + inline float getAY() const { + return _ay; + } - void setAY(float inValue); + inline void setAY(float inValue) { + _ay = inValue; + } /// The applied local scaleX. - float getAScaleX(); + inline float getAScaleX() const { + return _ascaleX; + } - void setAScaleX(float inValue); + inline void setAScaleX(float inValue) { + _ascaleX = inValue; + } /// The applied local scaleY. - float getAScaleY(); + inline float getAScaleY() const { + return _ascaleY; + } - void setAScaleY(float inValue); + inline void setAScaleY(float inValue) { + _ascaleY = inValue; + } /// The applied local shearX. - float getAShearX(); + inline float getAShearX() const { + return _ashearX; + } - void setAShearX(float inValue); + inline void setAShearX(float inValue) { + _ashearX = inValue; + } /// The applied local shearY. - float getAShearY(); + inline float getAShearY() const { + return _ashearY; + } - void setAShearY(float inValue); + inline void setAShearY(float inValue) { + _ashearY = inValue; + } - float getA(); + inline float getA() const { + return _a; + } - void setA(float inValue); + inline void setA(float inValue) { + _a = inValue; + } - float getB(); + inline float getB() const { + return _b; + } - void setB(float inValue); + inline void setB(float inValue) { + _b = inValue; + } - float getC(); + inline float getC() const { + return _c; + } - void setC(float inValue); + inline void setC(float inValue) { + _c = inValue; + } - float getD(); + inline float getD() const { + return _d; + } - void setD(float inValue); + inline void setD(float inValue) { + _d = inValue; + } - float getWorldX(); + inline float getWorldX() const { + return _worldX; + } - void setWorldX(float inValue); + inline void setWorldX(float inValue) { + _worldX = inValue; + } - float getWorldY(); + inline float getWorldY() const { + return _worldY; + } - void setWorldY(float inValue); + inline void setWorldY(float inValue) { + _worldY = inValue; + } - float getWorldRotationX(); + float getWorldRotationX() const; - float getWorldRotationY(); + float getWorldRotationY() const; /// Returns the magnitide (always positive) of the world scale X. - float getWorldScaleX(); + float getWorldScaleX() const; /// Returns the magnitide (always positive) of the world scale Y. - float getWorldScaleY(); + float getWorldScaleY() const; - bool isAppliedValid(); - void setAppliedValid(bool valid); + inline bool isAppliedValid() const { + return _appliedValid; + } + + void setAppliedValid(bool valid) { + _appliedValid = valid; + } virtual bool isActive(); @@ -232,6 +317,10 @@ class SP_API Bone : public Updatable { Skeleton &_skeleton; Bone *_parent; Vector _children; + +#ifdef __EMSCRIPTEN__ +public: +#endif float _x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY; float _ax, _ay, _arotation, _ascaleX, _ascaleY, _ashearX, _ashearY; bool _appliedValid; @@ -246,6 +335,7 @@ class SP_API Bone : public Updatable { /// Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. void updateAppliedTransform(); }; + } // namespace spine #endif /* Spine_Bone_h */ diff --git a/native/cocos/editor-support/spine/BoneData.h b/native/cocos/editor-support/spine/BoneData.h index 1ae439be748..2a1447787be 100644 --- a/native/cocos/editor-support/spine/BoneData.h +++ b/native/cocos/editor-support/spine/BoneData.h @@ -109,7 +109,9 @@ class SP_API BoneData : public SpineObject { bool isSkinRequired(); void setSkinRequired(bool inValue); +#ifndef __EMSCRIPTEN__ private: +#endif const int _index; const String _name; BoneData *_parent; diff --git a/native/cocos/editor-support/spine/ColorTimeline.h b/native/cocos/editor-support/spine/ColorTimeline.h index 6c02f6ddf9c..d3f0e85cf29 100644 --- a/native/cocos/editor-support/spine/ColorTimeline.h +++ b/native/cocos/editor-support/spine/ColorTimeline.h @@ -71,7 +71,11 @@ class SP_API ColorTimeline : public CurveTimeline { static const int B; static const int A; +#ifdef __EMSCRIPTEN__ +public: +#else private: +#endif int _slotIndex; Vector _frames; }; diff --git a/native/cocos/editor-support/spine/ConstraintData.h b/native/cocos/editor-support/spine/ConstraintData.h index d740d22c3ff..731ed56ff0f 100644 --- a/native/cocos/editor-support/spine/ConstraintData.h +++ b/native/cocos/editor-support/spine/ConstraintData.h @@ -53,7 +53,9 @@ class SP_API ConstraintData : public SpineObject { bool isSkinRequired(); void setSkinRequired(bool inValue); +#ifndef __EMSCRIPTEN__ private: +#endif const String _name; size_t _order; bool _skinRequired; diff --git a/native/cocos/editor-support/spine/DeformTimeline.h b/native/cocos/editor-support/spine/DeformTimeline.h index c3c9110e59d..9b06d8eaa2c 100644 --- a/native/cocos/editor-support/spine/DeformTimeline.h +++ b/native/cocos/editor-support/spine/DeformTimeline.h @@ -58,7 +58,9 @@ class SP_API DeformTimeline : public CurveTimeline { VertexAttachment* getAttachment(); void setAttachment(VertexAttachment* inValue); +#ifndef __EMSCRIPTEN__ private: +#endif int _slotIndex; Vector _frames; Vector > _frameVertices; diff --git a/native/cocos/editor-support/spine/Event.h b/native/cocos/editor-support/spine/Event.h index 8eba17ab84c..e9010db6c8a 100644 --- a/native/cocos/editor-support/spine/Event.h +++ b/native/cocos/editor-support/spine/Event.h @@ -74,6 +74,9 @@ class SP_API Event : public SpineObject { private: const EventData &_data; +#ifdef __EMSCRIPTEN__ +public: +#endif const float _time; int _intValue; float _floatValue; diff --git a/native/cocos/editor-support/spine/EventData.h b/native/cocos/editor-support/spine/EventData.h index 28fdbe02a6c..4e27850dc90 100644 --- a/native/cocos/editor-support/spine/EventData.h +++ b/native/cocos/editor-support/spine/EventData.h @@ -74,6 +74,9 @@ class SP_API EventData : public SpineObject { private: const String _name; +#ifdef __EMSCRIPTEN__ +public: +#endif int _intValue; float _floatValue; String _stringValue; diff --git a/native/cocos/editor-support/spine/IkConstraint.h b/native/cocos/editor-support/spine/IkConstraint.h index 55cb6637744..deeb06c226b 100644 --- a/native/cocos/editor-support/spine/IkConstraint.h +++ b/native/cocos/editor-support/spine/IkConstraint.h @@ -99,7 +99,9 @@ class SP_API IkConstraint : public Updatable { virtual void setActive(bool inValue);; +#ifndef __EMSCRIPTEN__ private: +#endif IkConstraintData &_data; Vector _bones; int _bendDirection; diff --git a/native/cocos/editor-support/spine/IkConstraintData.h b/native/cocos/editor-support/spine/IkConstraintData.h index cd766c09e9e..c1c731b1f3e 100644 --- a/native/cocos/editor-support/spine/IkConstraintData.h +++ b/native/cocos/editor-support/spine/IkConstraintData.h @@ -75,7 +75,9 @@ class SP_API IkConstraintData : public ConstraintData { float getSoftness(); void setSoftness(float inValue); +#ifndef __EMSCRIPTEN__ private: +#endif Vector _bones; BoneData* _target; int _bendDirection; diff --git a/native/cocos/editor-support/spine/MeshAttachment.h b/native/cocos/editor-support/spine/MeshAttachment.h index 9220b768a8a..6c5207e2bca 100644 --- a/native/cocos/editor-support/spine/MeshAttachment.h +++ b/native/cocos/editor-support/spine/MeshAttachment.h @@ -119,7 +119,9 @@ class SP_API MeshAttachment : public VertexAttachment, public HasRendererObject MeshAttachment* newLinkedMesh(); +#ifndef __EMSCRIPTEN__ private: +#endif float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; MeshAttachment* _parentMesh; Vector _uvs; diff --git a/native/cocos/editor-support/spine/PathAttachment.h b/native/cocos/editor-support/spine/PathAttachment.h index 0c968aff50c..8c3ae2fc29b 100644 --- a/native/cocos/editor-support/spine/PathAttachment.h +++ b/native/cocos/editor-support/spine/PathAttachment.h @@ -51,7 +51,9 @@ class SP_API PathAttachment : public VertexAttachment { virtual Attachment* copy(); +#ifndef __EMSCRIPTEN__ private: +#endif Vector _lengths; bool _closed; bool _constantSpeed; diff --git a/native/cocos/editor-support/spine/PathConstraint.h b/native/cocos/editor-support/spine/PathConstraint.h index 289bd3c0ae2..ae9b0b162ca 100644 --- a/native/cocos/editor-support/spine/PathConstraint.h +++ b/native/cocos/editor-support/spine/PathConstraint.h @@ -81,8 +81,9 @@ class SP_API PathConstraint : public Updatable { virtual bool isActive(); virtual void setActive(bool inValue);; - +#ifndef __EMSCRIPTEN__ private: +#endif static const float EPSILON; static const int NONE; static const int BEFORE; diff --git a/native/cocos/editor-support/spine/PathConstraintData.h b/native/cocos/editor-support/spine/PathConstraintData.h index 07e3a489b5a..a9cb306027a 100644 --- a/native/cocos/editor-support/spine/PathConstraintData.h +++ b/native/cocos/editor-support/spine/PathConstraintData.h @@ -85,7 +85,9 @@ class SP_API PathConstraintData : public ConstraintData { float getTranslateMix(); void setTranslateMix(float inValue); +#ifndef __EMSCRIPTEN__ private: +#endif Vector _bones; SlotData* _target; PositionMode _positionMode; diff --git a/native/cocos/editor-support/spine/PointAttachment.h b/native/cocos/editor-support/spine/PointAttachment.h index b9caaff7f31..5fdf57d2681 100644 --- a/native/cocos/editor-support/spine/PointAttachment.h +++ b/native/cocos/editor-support/spine/PointAttachment.h @@ -65,7 +65,9 @@ class SP_API PointAttachment : public Attachment { virtual Attachment* copy(); +#ifndef __EMSCRIPTEN__ private: +#endif float _x, _y, _rotation; }; } // namespace spine diff --git a/native/cocos/editor-support/spine/RegionAttachment.h b/native/cocos/editor-support/spine/RegionAttachment.h index ae2ee479f3a..19e1961f74c 100644 --- a/native/cocos/editor-support/spine/RegionAttachment.h +++ b/native/cocos/editor-support/spine/RegionAttachment.h @@ -117,8 +117,12 @@ class SP_API RegionAttachment : public Attachment, public HasRendererObject { static const int BRX; static const int BRY; +#ifdef __EMSCRIPTEN__ +public: +#endif float _x, _y, _rotation, _scaleX, _scaleY, _width, _height; float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; + Vector _vertexOffset; Vector _uvs; String _path; diff --git a/native/cocos/editor-support/spine/RotateTimeline.h b/native/cocos/editor-support/spine/RotateTimeline.h index fc9e4633285..3d4b57867dc 100644 --- a/native/cocos/editor-support/spine/RotateTimeline.h +++ b/native/cocos/editor-support/spine/RotateTimeline.h @@ -56,8 +56,9 @@ class SP_API RotateTimeline : public CurveTimeline { void setBoneIndex(int inValue); Vector& getFrames(); - +#ifndef __EMSCRIPTEN__ private: +#endif static const int PREV_TIME = -2; static const int PREV_ROTATION = -1; static const int ROTATION = 1; diff --git a/native/cocos/editor-support/spine/Skeleton.cpp b/native/cocos/editor-support/spine/Skeleton.cpp index 67deee47364..04f4bd0440d 100644 --- a/native/cocos/editor-support/spine/Skeleton.cpp +++ b/native/cocos/editor-support/spine/Skeleton.cpp @@ -516,51 +516,6 @@ Color &Skeleton::getColor() { return _color; } -float Skeleton::getTime() { - return _time; -} - -void Skeleton::setTime(float inValue) { - _time = inValue; -} - -void Skeleton::setPosition(float x, float y) { - _x = x; - _y = y; -} - -float Skeleton::getX() { - return _x; -} - -void Skeleton::setX(float inValue) { - _x = inValue; -} - -float Skeleton::getY() { - return _y; -} - -void Skeleton::setY(float inValue) { - _y = inValue; -} - -float Skeleton::getScaleX() { - return _scaleX; -} - -void Skeleton::setScaleX(float inValue) { - _scaleX = inValue; -} - -float Skeleton::getScaleY() { - return _scaleY * (Bone::isYDown() ? -1 : 1); -} - -void Skeleton::setScaleY(float inValue) { - _scaleY = inValue; -} - void Skeleton::sortIkConstraint(IkConstraint *constraint) { constraint->_active = constraint->_target->_active && (!constraint->_data.isSkinRequired() || (_skin && _skin->_constraints.contains(&constraint->_data))); if (!constraint->_active) return; diff --git a/native/cocos/editor-support/spine/Skeleton.h b/native/cocos/editor-support/spine/Skeleton.h index b75756b76c0..16f8f15d002 100644 --- a/native/cocos/editor-support/spine/Skeleton.h +++ b/native/cocos/editor-support/spine/Skeleton.h @@ -186,29 +186,53 @@ class SP_API Skeleton : public SpineObject { Color &getColor(); - float getTime(); - - void setTime(float inValue); - - void setPosition(float x, float y); - - float getX(); - - void setX(float inValue); - - float getY(); - - void setY(float inValue); - - float getScaleX(); - - void setScaleX(float inValue); - - float getScaleY(); - - void setScaleY(float inValue); - + inline float getTime() const { + return _time; + } + + inline void setTime(float inValue) { + _time = inValue; + } + + inline void setPosition(float x, float y) { + _x = x; + _y = y; + } + + inline float getX() const { + return _x; + } + + inline void setX(float inValue) { + _x = inValue; + } + + inline float getY() const { + return _y; + } + + inline void setY(float inValue) { + _y = inValue; + } + + inline float getScaleX() const { + return _scaleX; + } + + inline void setScaleX(float inValue) { + _scaleX = inValue; + } + + inline float getScaleY() const { + return _scaleY; + } + + inline void setScaleY(float inValue) { + _scaleY = inValue; + } +#ifndef __EMSCRIPTEN__ private: +#endif SkeletonData *_data; Vector _bones; Vector _slots; diff --git a/native/cocos/editor-support/spine/SkeletonData.h b/native/cocos/editor-support/spine/SkeletonData.h index c9ec083c52b..6ffff49c087 100644 --- a/native/cocos/editor-support/spine/SkeletonData.h +++ b/native/cocos/editor-support/spine/SkeletonData.h @@ -164,8 +164,9 @@ class SP_API SkeletonData : public SpineObject { float getFps(); void setFps(float inValue); - +#ifndef __EMSCRIPTEN__ private: +#endif String _name; Vector _bones; // Ordered parents first Vector _slots; // Setup pose draw order. diff --git a/native/cocos/editor-support/spine/SlotData.h b/native/cocos/editor-support/spine/SlotData.h index f64e2dcfff0..2501fed0cbf 100644 --- a/native/cocos/editor-support/spine/SlotData.h +++ b/native/cocos/editor-support/spine/SlotData.h @@ -97,7 +97,9 @@ class SP_API SlotData : public SpineObject { void setBlendMode(BlendMode inValue); +#ifndef __EMSCRIPTEN__ private: +#endif const int _index; String _name; BoneData &_boneData; diff --git a/native/cocos/editor-support/spine/TransformConstraint.h b/native/cocos/editor-support/spine/TransformConstraint.h index dcdf2fce83c..f00cfd9dd5a 100644 --- a/native/cocos/editor-support/spine/TransformConstraint.h +++ b/native/cocos/editor-support/spine/TransformConstraint.h @@ -77,7 +77,9 @@ class SP_API TransformConstraint : public Updatable { virtual void setActive(bool inValue);; +#ifndef __EMSCRIPTEN__ private: +#endif TransformConstraintData& _data; Vector _bones; Bone* _target; diff --git a/native/cocos/editor-support/spine/VertexAttachment.h b/native/cocos/editor-support/spine/VertexAttachment.h index d522f4a624e..12c3f67b193 100644 --- a/native/cocos/editor-support/spine/VertexAttachment.h +++ b/native/cocos/editor-support/spine/VertexAttachment.h @@ -77,7 +77,9 @@ class SP_API VertexAttachment : public Attachment { void copyTo(VertexAttachment* other); +#ifndef __EMSCRIPTEN__ protected: +#endif Vector _bones; Vector _vertices; size_t _worldVerticesLength; diff --git a/native/cocos/editor-support/spine/VertexEffect.h b/native/cocos/editor-support/spine/VertexEffect.h index 478ea707b86..3cc2f44a5e5 100644 --- a/native/cocos/editor-support/spine/VertexEffect.h +++ b/native/cocos/editor-support/spine/VertexEffect.h @@ -62,7 +62,9 @@ class SP_API JitterVertexEffect : public VertexEffect { void setJitterY(float jitterY); float getJitterY(); +#ifndef __EMSCRIPTEN__ protected: +#endif float _jitterX; float _jitterY; }; @@ -94,7 +96,9 @@ class SP_API SwirlVertexEffect : public VertexEffect { void setWorldY(float worldY); float getWorldY(); +#ifndef __EMSCRIPTEN__ protected: +#endif float _centerX; float _centerY; float _radius; From 5348e7bf632ebae1d48d34fce355cfb9a11d6262 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 16:17:20 +0800 Subject: [PATCH 52/80] inline MathUtil --- .../cocos/editor-support/spine/MathUtil.cpp | 55 +------------------ native/cocos/editor-support/spine/MathUtil.h | 52 ++++++++++++------ 2 files changed, 38 insertions(+), 69 deletions(-) diff --git a/native/cocos/editor-support/spine/MathUtil.cpp b/native/cocos/editor-support/spine/MathUtil.cpp index c9c230bf4fc..48fcb2318f8 100644 --- a/native/cocos/editor-support/spine/MathUtil.cpp +++ b/native/cocos/editor-support/spine/MathUtil.cpp @@ -31,9 +31,9 @@ #include "SpinePluginPrivatePCH.h" #endif -#include #include #include +#include // Required for division by 0 in _isNaN on MSVC #ifdef _MSC_VER @@ -46,11 +46,6 @@ RTTI_IMPL_NOPARENT(Interpolation) RTTI_IMPL(PowInterpolation, Interpolation) RTTI_IMPL(PowOutInterpolation, Interpolation) -const float MathUtil::Pi = 3.1415926535897932385f; -const float MathUtil::Pi_2 = 3.1415926535897932385f * 2; -const float MathUtil::Deg_Rad = (3.1415926535897932385f / 180.0f); -const float MathUtil::Rad_Deg = (180.0f / 3.1415926535897932385f); - float MathUtil::abs(float v) { return ((v) < 0 ? -(v) : (v)); } @@ -64,46 +59,8 @@ float MathUtil::clamp(float x, float min, float max) { return ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x))); } -float MathUtil::fmod(float a, float b) { - return (float)::fmod(a, b); -} - -/// Returns atan2 in radians, faster but less accurate than Math.Atan2. Average error of 0.00231 radians (0.1323 -/// degrees), largest error of 0.00488 radians (0.2796 degrees). -float MathUtil::atan2(float y, float x) { - return (float)::atan2(y, x); -} - -/// Returns the cosine in radians from a lookup table. -float MathUtil::cos(float radians) { - return (float)::cos(radians); -} - -/// Returns the sine in radians from a lookup table. -float MathUtil::sin(float radians) { - return (float)::sin(radians); -} - -float MathUtil::sqrt(float v) { - return (float)::sqrt(v); -} - -float MathUtil::acos(float v) { - return (float)::acos(v); -} - -/// Returns the sine in radians from a lookup table. -float MathUtil::sinDeg(float degrees) { - return (float)::sin(degrees * MathUtil::Deg_Rad); -} - -/// Returns the cosine in radians from a lookup table. -float MathUtil::cosDeg(float degrees) { - return (float)::cos(degrees * MathUtil::Deg_Rad); -} - /* Need to pass 0 as an argument, so VC++ doesn't error with C2124 */ -static bool _isNan(float value, float zero) { +static inline bool _isNan(float value, float zero) { float _nan = (float)0.0 / zero; return 0 == memcmp((void *)&value, (void *)&_nan, sizeof(value)); } @@ -112,14 +69,6 @@ bool MathUtil::isNan(float v) { return _isNan(v, 0); } -float MathUtil::random() { - return ::rand() / (float)RAND_MAX; -} - -float MathUtil::randomTriangular(float min, float max) { - return randomTriangular(min, max, (min + max) * 0.5f); -} - float MathUtil::randomTriangular(float min, float max, float mode) { float u = random(); float d = max - min; diff --git a/native/cocos/editor-support/spine/MathUtil.h b/native/cocos/editor-support/spine/MathUtil.h index c2a43f205bb..28d6a62ab5a 100644 --- a/native/cocos/editor-support/spine/MathUtil.h +++ b/native/cocos/editor-support/spine/MathUtil.h @@ -32,19 +32,19 @@ #include #include -#include +#include namespace spine { -class SP_API MathUtil : public SpineObject { +class SP_API MathUtil { private: MathUtil(); public: - static const float Pi; - static const float Pi_2; - static const float Deg_Rad; - static const float Rad_Deg; + static constexpr float Pi = 3.1415926535897932385f; + static constexpr float Pi_2 = 3.1415926535897932385f * 2; + static constexpr float Deg_Rad = (3.1415926535897932385f / 180.0f); + static constexpr float Rad_Deg = (180.0f / 3.1415926535897932385f); template static inline T min(T a, T b) { return a < b ? a : b; } @@ -59,32 +59,52 @@ class SP_API MathUtil : public SpineObject { static float abs(float v); /// Returns the sine in radians from a lookup table. - static float sin(float radians); + static inline float sin(float radians) { + return ::sin(radians); + } /// Returns the cosine in radians from a lookup table. - static float cos(float radians); + static inline float cos(float radians) { + return ::cos(radians); + } /// Returns the sine in radians from a lookup table. - static float sinDeg(float degrees); + static inline float sinDeg(float degrees) { + return ::sin(degrees * MathUtil::Deg_Rad); + } /// Returns the cosine in radians from a lookup table. - static float cosDeg(float degrees); + static inline float cosDeg(float degrees) { + return ::cos(degrees * MathUtil::Deg_Rad); + } /// Returns atan2 in radians, faster but less accurate than Math.Atan2. Average error of 0.00231 radians (0.1323 /// degrees), largest error of 0.00488 radians (0.2796 degrees). - static float atan2(float y, float x); + static inline float atan2(float y, float x) { + return ::atan2(y, x); + } - static float acos(float v); + static inline float acos(float v) { + return ::acos(v); + } - static float sqrt(float v); + static inline float sqrt(float v) { + return ::sqrt(v); + } - static float fmod(float a, float b); + static inline float fmod(float a, float b) { + return ::fmod(a, b); + } static bool isNan(float v); - static float random(); + static inline float random() { + return ::rand() / static_cast(RAND_MAX); + } - static float randomTriangular(float min, float max); + static inline float randomTriangular(float min, float max) { + return randomTriangular(min, max, (min + max) * 0.5f); + } static float randomTriangular(float min, float max, float mode); From 889e8b9ac1aa0b961e7122f7c0c6022c3f189466 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 16:32:17 +0800 Subject: [PATCH 53/80] Add missing include --- native/cocos/editor-support/spine/SpineString.h | 1 + 1 file changed, 1 insertion(+) diff --git a/native/cocos/editor-support/spine/SpineString.h b/native/cocos/editor-support/spine/SpineString.h index 32c349e5fb9..c3a4c095aca 100644 --- a/native/cocos/editor-support/spine/SpineString.h +++ b/native/cocos/editor-support/spine/SpineString.h @@ -32,6 +32,7 @@ #include #include +#include #include namespace spine { From d0b5f451f4cf4d9f8587a460afdb874d3fa1eb09 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 17:11:15 +0800 Subject: [PATCH 54/80] [CI] interface-check use the latest spine wasm --- .github/workflows/build-wasm-libs.yml | 2 +- .github/workflows/generate-emsdk-cache.yml | 2 +- .github/workflows/native-compile-webgpu.yml | 2 +- .github/workflows/web-interface-check.yml | 61 +++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-wasm-libs.yml b/.github/workflows/build-wasm-libs.yml index a619a24ecec..6fcd7121304 100644 --- a/.github/workflows/build-wasm-libs.yml +++ b/.github/workflows/build-wasm-libs.yml @@ -22,7 +22,7 @@ jobs: uses: dumganhar/setup-emsdk@997d2cde2deabda085a11f98e86e842915b0e846 with: version: 3.1.41 - actions-cache-folder: 'emsdk-cache' + actions-cache-folder: 'emsdk-cache-3.1.41' - name: Verify run: | diff --git a/.github/workflows/generate-emsdk-cache.yml b/.github/workflows/generate-emsdk-cache.yml index 09b5221a0e7..41eae3b2a85 100644 --- a/.github/workflows/generate-emsdk-cache.yml +++ b/.github/workflows/generate-emsdk-cache.yml @@ -18,7 +18,7 @@ jobs: uses: dumganhar/setup-emsdk@997d2cde2deabda085a11f98e86e842915b0e846 with: version: ${{ github.event.inputs.emsdk_version }} - actions-cache-folder: 'emsdk-cache' + actions-cache-folder: 'emsdk-cache-${{ github.event.inputs.emsdk_version }}' - name: Verify run: | diff --git a/.github/workflows/native-compile-webgpu.yml b/.github/workflows/native-compile-webgpu.yml index 2c8424a159f..74d2338d0d1 100644 --- a/.github/workflows/native-compile-webgpu.yml +++ b/.github/workflows/native-compile-webgpu.yml @@ -35,7 +35,7 @@ jobs: uses: dumganhar/setup-emsdk@997d2cde2deabda085a11f98e86e842915b0e846 with: version: 3.1.45 - actions-cache-folder: 'emsdk-cache' + actions-cache-folder: 'emsdk-cache-3.1.45' - name: Verify run: | diff --git a/.github/workflows/web-interface-check.yml b/.github/workflows/web-interface-check.yml index 2e9dbe753b5..1c257bfc4ec 100644 --- a/.github/workflows/web-interface-check.yml +++ b/.github/workflows/web-interface-check.yml @@ -67,6 +67,67 @@ jobs: ref: "${{ env.EXT_VERSION_HEAD }}" fetch-depth: 1 + - name: Setup emsdk + uses: dumganhar/setup-emsdk@997d2cde2deabda085a11f98e86e842915b0e846 + with: + version: 3.1.41 + actions-cache-folder: 'emsdk-cache-3.1.41' + + - name: Verify + run: | + which emcc + emcc -v + + - name: Install ninja + run: | + if ! command -v ninja &> /dev/null; then + echo "Ninja not found, installing..." + # sudo apt update + sudo apt install ninja-build + else + echo "Ninja is already installed." + fi + which ninja + + - name: Build Spine WASM + run: | + cd ./native/cocos/editor-support/spine-wasm + mkdir build-wasm + cd build-wasm + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Build Spine ASMJS + run: | + cd ./native/cocos/editor-support/spine-wasm + sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt + mkdir build-asmjs + cd build-asmjs + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Copy files to external directory + run: | + mkdir dist + cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./dist/ + cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./dist/spine.wasm.js + cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./dist/ + cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./dist/spine.asm.js + echo "-------- Before replace spine wasm -----------" + ls -l ./native/external/emscripten/spine/ + cp -f ./dist/* ./native/external/emscripten/spine/ + echo "-------- After replace spine wasm ------------" + ls -l ./native/external/emscripten/spine/ + echo "-----------------------------------------------" + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: spine-emscripten + path: dist + - name: Build Head Declarations working-directory: ./engine-HEAD run: | From 62f614bbf274f92fb5dd4009e13ed1f87fd47138 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 17:35:02 +0800 Subject: [PATCH 55/80] Update ci --- .../emscripten-patches/embind/bind.cpp | 205 ++++++++++++++++++ .github/workflows/web-interface-check.yml | 32 ++- 2 files changed, 228 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/emscripten-patches/embind/bind.cpp diff --git a/.github/workflows/emscripten-patches/embind/bind.cpp b/.github/workflows/emscripten-patches/embind/bind.cpp new file mode 100644 index 00000000000..eb440f7560e --- /dev/null +++ b/.github/workflows/emscripten-patches/embind/bind.cpp @@ -0,0 +1,205 @@ +// Copyright 2012 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#ifdef USE_CXA_DEMANGLE +#include <../lib/libcxxabi/include/cxxabi.h> +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace emscripten; +using namespace internal; + +static char* pointerToHexString(const void* ptr) { + static const char hexDigits[] = "0123456789abcdef"; + uintptr_t address = reinterpret_cast(ptr); + char str[20] = "0x"; // Includes the "0x" prefix + int index = 2; + bool leadingZero = true; // Used to skip leading zeros + + // Convert the address to a hexadecimal string + for (int i = (sizeof(address) * 2) - 1; i >= 0; --i) { + char hexChar = hexDigits[(address >> (i * 4)) & 0xF]; + if (hexChar != '0' || !leadingZero || i == 0) { // Ensures at least one zero in the final character + str[index++] = hexChar; + leadingZero = false; + } + } + str[index] = '\0'; + + return strdup(str); +} + +extern "C" { +const char* EMSCRIPTEN_KEEPALIVE __getTypeName(const std::type_info* ti) { + if (has_unbound_type_names) { +#ifdef USE_CXA_DEMANGLE + int stat; + char* demangled = abi::__cxa_demangle(ti->name(), NULL, NULL, &stat); + if (stat == 0 && demangled) { + return demangled; + } + + switch (stat) { + case -1: + return strdup(""); + case -2: + return strdup(""); + case -3: + return strdup(""); + default: + return strdup(""); + } +#else + return strdup(ti->name()); +#endif + } else { + //cjh char str[80]; + // sprintf(str, "%p", reinterpret_cast(ti)); + // return strdup(str); + return pointerToHexString(reinterpret_cast(ti)); + } +} + +static InitFunc* init_funcs = nullptr; + +EMSCRIPTEN_KEEPALIVE void _embind_initialize_bindings() { + for (auto* f = init_funcs; f; f = f->next) { + f->init_func(); + } +} + +void _embind_register_bindings(InitFunc* f) { + f->next = init_funcs; + init_funcs = f; +} + +} + +namespace { +template static void register_integer(const char* name) { + using namespace internal; + _embind_register_integer(TypeID::get(), name, sizeof(T), std::numeric_limits::min(), + std::numeric_limits::max()); +} + +template static void register_bigint(const char* name) { + using namespace internal; + _embind_register_bigint(TypeID::get(), name, sizeof(T), std::numeric_limits::min(), + std::numeric_limits::max()); +} + +template static void register_float(const char* name) { + using namespace internal; + _embind_register_float(TypeID::get(), name, sizeof(T)); +} + +// matches typeMapping in embind.js +enum TypedArrayIndex { + Int8Array, + Uint8Array, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + // Only available if WASM_BIGINT + Int64Array, + Uint64Array, +}; + +template constexpr TypedArrayIndex getTypedArrayIndex() { + static_assert(internal::typeSupportsMemoryView(), "type does not map to a typed array"); + return std::is_floating_point::value + ? (sizeof(T) == 4 ? Float32Array : Float64Array) + : (sizeof(T) == 1 + ? (std::is_signed::value ? Int8Array : Uint8Array) + : (sizeof(T) == 2 ? (std::is_signed::value ? Int16Array : Uint16Array) + : (sizeof(T) == 4 ? (std::is_signed::value ? Int32Array : Uint32Array) + : (std::is_signed::value ? Int64Array : Uint64Array)))); +} + +template static void register_memory_view(const char* name) { + using namespace internal; + _embind_register_memory_view(TypeID>::get(), getTypedArrayIndex(), name); +} +} // namespace + +EMSCRIPTEN_BINDINGS(builtin) { + using namespace emscripten::internal; + + _embind_register_void(TypeID::get(), "void"); + + _embind_register_bool(TypeID::get(), "bool", sizeof(bool), true, false); + + register_integer("char"); + register_integer("signed char"); + register_integer("unsigned char"); + register_integer("short"); + register_integer("unsigned short"); + register_integer("int"); + register_integer("unsigned int"); +#if __wasm64__ + register_bigint("long"); + register_bigint("unsigned long"); +#else + register_integer("long"); + register_integer("unsigned long"); +#endif + + register_bigint("int64_t"); + register_bigint("uint64_t"); + + register_float("float"); + register_float("double"); + +/*cjh + _embind_register_std_string(TypeID::get(), "std::string"); + _embind_register_std_string( + TypeID>::get(), "std::basic_string"); + _embind_register_std_wstring(TypeID::get(), sizeof(wchar_t), "std::wstring"); + _embind_register_std_wstring(TypeID::get(), sizeof(char16_t), "std::u16string"); + _embind_register_std_wstring(TypeID::get(), sizeof(char32_t), "std::u32string"); +*/ + _embind_register_emval(TypeID::get(), "emscripten::val"); +/*cjh + // Some of these types are aliases for each other. Luckily, + // embind.js's _embind_register_memory_view ignores duplicate + // registrations rather than asserting, so the first + // register_memory_view call for a particular type will take + // precedence. + + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + + register_memory_view("emscripten::memory_view"); + register_memory_view("emscripten::memory_view"); + */ +} diff --git a/.github/workflows/web-interface-check.yml b/.github/workflows/web-interface-check.yml index 1c257bfc4ec..1c375f16152 100644 --- a/.github/workflows/web-interface-check.yml +++ b/.github/workflows/web-interface-check.yml @@ -78,6 +78,20 @@ jobs: which emcc emcc -v + - name: Apply emscripten patches + run: | + echo "Save bind.cpp ..." + cp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak + echo "Apply embind bind.cpp patches ..." + cp -f ./engine-HEAD/.github/workflows/emscripten-patches/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/ + echo "Apply patches DONE!" + cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp + echo "Restore patches ..." + rm $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp + mv $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp + echo "Restore patches DONE!" + cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp + - name: Install ninja run: | if ! command -v ninja &> /dev/null; then @@ -91,7 +105,7 @@ jobs: - name: Build Spine WASM run: | - cd ./native/cocos/editor-support/spine-wasm + cd ./engine-HEAD/native/cocos/editor-support/spine-wasm mkdir build-wasm cd build-wasm emcmake cmake .. -GNinja @@ -100,7 +114,7 @@ jobs: - name: Build Spine ASMJS run: | - cd ./native/cocos/editor-support/spine-wasm + cd ./engine-HEAD/native/cocos/editor-support/spine-wasm sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt mkdir build-asmjs cd build-asmjs @@ -111,15 +125,15 @@ jobs: - name: Copy files to external directory run: | mkdir dist - cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./dist/ - cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./dist/spine.wasm.js - cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./dist/ - cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./dist/spine.asm.js + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./dist/ + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./dist/spine.wasm.js + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./dist/ + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./dist/spine.asm.js echo "-------- Before replace spine wasm -----------" - ls -l ./native/external/emscripten/spine/ - cp -f ./dist/* ./native/external/emscripten/spine/ + ls -l ./engine-HEAD/native/external/emscripten/spine/ + cp -f ./dist/* ./engine-HEAD/native/external/emscripten/spine/ echo "-------- After replace spine wasm ------------" - ls -l ./native/external/emscripten/spine/ + ls -l ./engine-HEAD/native/external/emscripten/spine/ echo "-----------------------------------------------" - name: Upload Artifact From 4c0b57d1f24b2193770c3be02bf3099dc5b69f8b Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 17:51:30 +0800 Subject: [PATCH 56/80] cleanup --- .github/workflows/web-interface-check.yml | 19 +++++++++++-------- .../generate_compile_commands_emscripten.sh | 2 +- native/cocos/editor-support/spine/Json.cpp | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/web-interface-check.yml b/.github/workflows/web-interface-check.yml index 1c375f16152..3f4d39d8db5 100644 --- a/.github/workflows/web-interface-check.yml +++ b/.github/workflows/web-interface-check.yml @@ -80,16 +80,11 @@ jobs: - name: Apply emscripten patches run: | - echo "Save bind.cpp ..." + echo "--------------------------------- Save bind.cpp ---------------------------------" cp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak - echo "Apply embind bind.cpp patches ..." + echo "--------------------------------- Apply embind bind.cpp patches ---------------------------------" cp -f ./engine-HEAD/.github/workflows/emscripten-patches/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/ - echo "Apply patches DONE!" - cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp - echo "Restore patches ..." - rm $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp - mv $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp - echo "Restore patches DONE!" + echo "--------------------------------- Apply patches DONE! ---------------------------------" cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp - name: Install ninja @@ -148,6 +143,14 @@ jobs: npm install node ./.github/workflows/package-size-check.js + - name: Restore patches + run: | + echo "-------------------------- Restore patches ---------------------------------" + rm $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp + mv $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp + echo "-------------------------- Restore patches DONE! ---------------------------------" + cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp + - uses: LouisBrunner/diff-action@v2.0.0 with: old: ./engine/bin/.declarations/cc.d.ts diff --git a/native/cocos/editor-support/spine-wasm/scripts/generate_compile_commands_emscripten.sh b/native/cocos/editor-support/spine-wasm/scripts/generate_compile_commands_emscripten.sh index 1d79370dc9a..2934ab7812d 100755 --- a/native/cocos/editor-support/spine-wasm/scripts/generate_compile_commands_emscripten.sh +++ b/native/cocos/editor-support/spine-wasm/scripts/generate_compile_commands_emscripten.sh @@ -14,7 +14,7 @@ mkdir build cd build cp ../CMakeLists.header.txt ./CMakeLists.txt emcmake cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -GNinja \ - -DCMAKE_CXX_FLAGS="-I${EMSDK}/upstream/emscripten/system/include -I${EMSDK}/upstream/include/c++/v1" + -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -I${EMSDK}/upstream/emscripten/system/include -I${EMSDK}/upstream/include/c++/v1" cp ./compile_commands.json ../.. cd .. diff --git a/native/cocos/editor-support/spine/Json.cpp b/native/cocos/editor-support/spine/Json.cpp index 59c6b3c8147..752c3888321 100644 --- a/native/cocos/editor-support/spine/Json.cpp +++ b/native/cocos/editor-support/spine/Json.cpp @@ -49,7 +49,7 @@ THE SOFTWARE. #endif #ifdef __EMSCRIPTEN__ -bool parseHex(const char *str, unsigned int *result_) { +static bool parseHex(const char *str, unsigned int *result_) { auto &result = *result_; result = 0; for (int i = 0; i < 4; ++i) { From dc9a5f40cb969a178ba005e31c75ce52c0b455ec Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 18:07:19 +0800 Subject: [PATCH 57/80] Cleanup --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index d61f9aad590..4009414f4b5 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -25,7 +25,7 @@ project(${APP_NAME}_wasm) # --profiling set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti \ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override \ -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") message(">>> --------------------------------------------------------------") From 89b3dba4dbacc373159effa1bb80db2778162a00 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 18:20:31 +0800 Subject: [PATCH 58/80] Add spine::Json test. --- native/cocos/editor-support/spine-wasm/spine-type-export.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 5663eed4ae0..ac34fbc3f01 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -486,6 +486,11 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getNames", &TestBar::getNames) .property("names", &TestBar::getNames) ; + + Json json(R"({"smile": "\uD83D\uDE0A🇨🇳 \uD83D\uDE00 \uD83D\uDE02 \uD83D\uDE21 "})"); + const char *smileValue = Json::getString(&json, R"(smile)", ""); + printf(">>> smile value: %s\n", smileValue); + #endif // ENABLE_EMBIND_TEST _embind_register_std_string(TypeID::get(), "std::string"); From b6cfcddbfb26c40926a0f8f791e6053979432339 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 19:08:54 +0800 Subject: [PATCH 59/80] update cmake --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index 4009414f4b5..8ebcfebb2ed 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -5,6 +5,7 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(BUILD_WASM 1) set(ENABLE_JSON_PARSER 1) set(ENABLE_BINARY_PARSER 1) +# set(ENABLE_PROFILING "--profiling") set(CMAKE_BUILD_TYPE "MinSizeRel") # set(CMAKE_BUILD_TYPE "RelWithDebInfo") @@ -23,9 +24,8 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) -# --profiling set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override \ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override ${ENABLE_PROFILING} \ -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") message(">>> --------------------------------------------------------------") @@ -34,6 +34,7 @@ message(">>> CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(">>> ENABLE_CLOSURE_COMPILER: ${ENABLE_CLOSURE_COMPILER}") message(">>> ENABLE_JSON_PARSER: ${ENABLE_JSON_PARSER}") message(">>> ENABLE_BINARY_PARSER: ${ENABLE_BINARY_PARSER}") +message(">>> ENABLE_PROFILING: ${ENABLE_PROFILING}") message(">>> --------------------------------------------------------------") include_directories(${CMAKE_CURRENT_LIST_DIR}/..) @@ -43,7 +44,7 @@ file(GLOB COCOS_ADAPTER_SRC "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC}) # -s EMBIND_AOT=0 -s MALLOC=emmalloc -set(EMS_LINK_FLAGS "-s VERBOSE=1 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ +set(EMS_LINK_FLAGS "-s VERBOSE=0 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ -s MIN_SAFARI_VERSION=110000 \ From d1b9b68641ed97c73adada2ef1f0e480829570cc Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 30 Oct 2024 23:54:01 +0800 Subject: [PATCH 60/80] More inline and code refactors --- native/cocos/editor-support/spine/Color.h | 2 +- .../editor-support/spine/PathAttachment.cpp | 20 ---------- .../editor-support/spine/PathAttachment.h | 10 ++--- .../editor-support/spine/PathConstraint.cpp | 5 --- .../editor-support/spine/PathConstraint.h | 8 ++-- native/cocos/editor-support/spine/Slot.cpp | 8 ---- native/cocos/editor-support/spine/Slot.h | 4 +- .../editor-support/spine/TwoColorTimeline.cpp | 37 +++++++++---------- native/cocos/editor-support/spine/Vector.h | 12 +++--- .../editor-support/spine/VertexAttachment.cpp | 28 -------------- .../editor-support/spine/VertexAttachment.h | 14 +++---- 11 files changed, 43 insertions(+), 105 deletions(-) diff --git a/native/cocos/editor-support/spine/Color.h b/native/cocos/editor-support/spine/Color.h index f56b5c83d1d..5c475293fda 100644 --- a/native/cocos/editor-support/spine/Color.h +++ b/native/cocos/editor-support/spine/Color.h @@ -78,7 +78,7 @@ class SP_API Color : public SpineObject { return *this; } - inline Color &clamp() { + Color &clamp() { r = MathUtil::clamp(this->r, 0, 1); g = MathUtil::clamp(this->g, 0, 1); b = MathUtil::clamp(this->b, 0, 1); diff --git a/native/cocos/editor-support/spine/PathAttachment.cpp b/native/cocos/editor-support/spine/PathAttachment.cpp index 161ce94c9be..a4b5a67036f 100644 --- a/native/cocos/editor-support/spine/PathAttachment.cpp +++ b/native/cocos/editor-support/spine/PathAttachment.cpp @@ -40,26 +40,6 @@ RTTI_IMPL(PathAttachment, VertexAttachment) PathAttachment::PathAttachment(const String& name) : VertexAttachment(name), _closed(false), _constantSpeed(false) { } -Vector& PathAttachment::getLengths() { - return _lengths; -} - -bool PathAttachment::isClosed() { - return _closed; -} - -void PathAttachment::setClosed(bool inValue) { - _closed = inValue; -} - -bool PathAttachment::isConstantSpeed() { - return _constantSpeed; -} - -void PathAttachment::setConstantSpeed(bool inValue) { - _constantSpeed = inValue; -} - Attachment* PathAttachment::copy() { PathAttachment* copy = spine_new PathAttachment(getName()); copyTo(copy); diff --git a/native/cocos/editor-support/spine/PathAttachment.h b/native/cocos/editor-support/spine/PathAttachment.h index 8c3ae2fc29b..32a6ac2ea73 100644 --- a/native/cocos/editor-support/spine/PathAttachment.h +++ b/native/cocos/editor-support/spine/PathAttachment.h @@ -43,11 +43,11 @@ class SP_API PathAttachment : public VertexAttachment { explicit PathAttachment(const String& name); /// The length in the setup pose from the start of the path to the end of each curve. - Vector& getLengths(); - bool isClosed(); - void setClosed(bool inValue); - bool isConstantSpeed(); - void setConstantSpeed(bool inValue); + inline Vector& getLengths() { return _lengths; } + inline bool isClosed() const { return _closed; } + inline void setClosed(bool inValue) { _closed = inValue; } + inline bool isConstantSpeed() const { return _constantSpeed; } + inline void setConstantSpeed(bool inValue) { _constantSpeed = inValue; } virtual Attachment* copy(); diff --git a/native/cocos/editor-support/spine/PathConstraint.cpp b/native/cocos/editor-support/spine/PathConstraint.cpp index b5aac9ea9c6..d93d1e4272b 100644 --- a/native/cocos/editor-support/spine/PathConstraint.cpp +++ b/native/cocos/editor-support/spine/PathConstraint.cpp @@ -46,11 +46,6 @@ using namespace spine; RTTI_IMPL(PathConstraint, Updatable) -const float PathConstraint::EPSILON = 0.00001f; -const int PathConstraint::NONE = -1; -const int PathConstraint::BEFORE = -2; -const int PathConstraint::AFTER = -3; - PathConstraint::PathConstraint(PathConstraintData &data, Skeleton &skeleton) : Updatable(), _data(data), _target(skeleton.findSlot( diff --git a/native/cocos/editor-support/spine/PathConstraint.h b/native/cocos/editor-support/spine/PathConstraint.h index ae9b0b162ca..1cf594c1314 100644 --- a/native/cocos/editor-support/spine/PathConstraint.h +++ b/native/cocos/editor-support/spine/PathConstraint.h @@ -84,10 +84,10 @@ class SP_API PathConstraint : public Updatable { #ifndef __EMSCRIPTEN__ private: #endif - static const float EPSILON; - static const int NONE; - static const int BEFORE; - static const int AFTER; + static constexpr float EPSILON = 0.00001f; + static constexpr int NONE = -1; + static constexpr int BEFORE = -2; + static constexpr int AFTER = -3; PathConstraintData& _data; Vector _bones; diff --git a/native/cocos/editor-support/spine/Slot.cpp b/native/cocos/editor-support/spine/Slot.cpp index 49a60208052..1d8c0826fa8 100644 --- a/native/cocos/editor-support/spine/Slot.cpp +++ b/native/cocos/editor-support/spine/Slot.cpp @@ -75,14 +75,6 @@ Skeleton &Slot::getSkeleton() { return _skeleton; } -Color &Slot::getColor() { - return _color; -} - -Color &Slot::getDarkColor() { - return _darkColor; -} - bool Slot::hasDarkColor() { return _hasDarkColor; } diff --git a/native/cocos/editor-support/spine/Slot.h b/native/cocos/editor-support/spine/Slot.h index 5668ae68d83..277eec1effb 100644 --- a/native/cocos/editor-support/spine/Slot.h +++ b/native/cocos/editor-support/spine/Slot.h @@ -91,9 +91,9 @@ class SP_API Slot : public SpineObject { Skeleton &getSkeleton(); - Color &getColor(); + Color &getColor() { return _color; } - Color &getDarkColor(); + inline Color &getDarkColor() { return _darkColor; } bool hasDarkColor(); diff --git a/native/cocos/editor-support/spine/TwoColorTimeline.cpp b/native/cocos/editor-support/spine/TwoColorTimeline.cpp index e2eb7bca25b..46933cf3b0b 100644 --- a/native/cocos/editor-support/spine/TwoColorTimeline.cpp +++ b/native/cocos/editor-support/spine/TwoColorTimeline.cpp @@ -78,24 +78,26 @@ void TwoColorTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec Slot &slot = *slotP; if (!slot._bone.isActive()) return; + Color &color = slot.getColor(); + Color &darkColor = slot.getDarkColor(); + const Color &dataColor = slot._data.getColor(); + const Color &dataDarkColor = slot._data.getDarkColor(); if (time < _frames[0]) { // Time is before first frame. switch (blend) { case MixBlend_Setup: - slot.getColor().set(slot.getData().getColor()); - slot.getDarkColor().set(slot.getData().getDarkColor()); + color.set(dataColor); + darkColor.set(dataDarkColor); return; case MixBlend_First: { - Color &color = slot.getColor(); - color.r += (color.r - slot._data.getColor().r) * alpha; - color.g += (color.g - slot._data.getColor().g) * alpha; - color.b += (color.b - slot._data.getColor().b) * alpha; - color.a += (color.a - slot._data.getColor().a) * alpha; - - Color &darkColor = slot.getDarkColor(); - darkColor.r += (darkColor.r - slot._data.getDarkColor().r) * alpha; - darkColor.g += (darkColor.g - slot._data.getDarkColor().g) * alpha; - darkColor.b += (darkColor.b - slot._data.getDarkColor().b) * alpha; + color.r += (color.r - dataColor.r) * alpha; + color.g += (color.g - dataColor.g) * alpha; + color.b += (color.b - dataColor.b) * alpha; + color.a += (color.a - dataColor.a) * alpha; + + darkColor.r += (darkColor.r - dataDarkColor.r) * alpha; + darkColor.g += (darkColor.g - dataDarkColor.g) * alpha; + darkColor.b += (darkColor.b - dataDarkColor.b) * alpha; return; } default: @@ -138,17 +140,14 @@ void TwoColorTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec } if (alpha == 1) { - Color &color = slot.getColor(); color.set(r, g, b, a); - - Color &darkColor = slot.getDarkColor(); darkColor.set(r2, g2, b2, 1); } else { - Color &light = slot._color; - Color &dark = slot._darkColor; + Color &light = color; + Color &dark = darkColor; if (blend == MixBlend_Setup) { - light.set(slot._data._color); - dark.set(slot._data._darkColor); + color.set(dataColor); + darkColor.set(dataDarkColor); } light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha); dark.add((r2 - dark.r) * alpha, (g2 - dark.g) * alpha, (b2 - dark.b) * alpha, 0); diff --git a/native/cocos/editor-support/spine/Vector.h b/native/cocos/editor-support/spine/Vector.h index cb2c00e3480..55c15dd924e 100644 --- a/native/cocos/editor-support/spine/Vector.h +++ b/native/cocos/editor-support/spine/Vector.h @@ -75,7 +75,7 @@ class SP_API Vector : public SpineObject { return _size; } - inline void setSize(size_t newSize, const T &defaultValue) { + void setSize(size_t newSize, const T &defaultValue) { assert(newSize >= 0); size_t oldSize = _size; _size = newSize; @@ -91,13 +91,13 @@ class SP_API Vector : public SpineObject { } } - inline void ensureCapacity(size_t newCapacity = 0) { + void ensureCapacity(size_t newCapacity = 0) { if (_capacity >= newCapacity) return; _capacity = newCapacity; _buffer = SpineExtension::realloc(_buffer, newCapacity, __SPINE_FILE__, __SPINE_LINE__); } - inline void add(const T &inValue) { + void add(const T &inValue) { if (_size == _capacity) { // inValue might reference an element in this buffer // When we reallocate, the reference becomes invalid. @@ -113,19 +113,19 @@ class SP_API Vector : public SpineObject { } } - inline void addAll(Vector &inValue) { + void addAll(Vector &inValue) { ensureCapacity(this->size() + inValue.size()); for (size_t i = 0; i < inValue.size(); i++) { add(inValue[i]); } } - inline void clearAndAddAll(Vector &inValue) { + void clearAndAddAll(Vector &inValue) { this->clear(); this->addAll(inValue); } - inline void removeAt(size_t inIndex) { + void removeAt(size_t inIndex) { assert(inIndex < _size); --_size; diff --git a/native/cocos/editor-support/spine/VertexAttachment.cpp b/native/cocos/editor-support/spine/VertexAttachment.cpp index 58a09799017..b027b7b091a 100644 --- a/native/cocos/editor-support/spine/VertexAttachment.cpp +++ b/native/cocos/editor-support/spine/VertexAttachment.cpp @@ -127,34 +127,6 @@ void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t cou } } -int VertexAttachment::getId() { - return _id; -} - -Vector &VertexAttachment::getBones() { - return _bones; -} - -Vector &VertexAttachment::getVertices() { - return _vertices; -} - -size_t VertexAttachment::getWorldVerticesLength() { - return _worldVerticesLength; -} - -void VertexAttachment::setWorldVerticesLength(size_t inValue) { - _worldVerticesLength = inValue; -} - -VertexAttachment *VertexAttachment::getDeformAttachment() { - return _deformAttachment; -} - -void VertexAttachment::setDeformAttachment(VertexAttachment *attachment) { - _deformAttachment = attachment; -} - int VertexAttachment::getNextID() { static int nextID = 0; diff --git a/native/cocos/editor-support/spine/VertexAttachment.h b/native/cocos/editor-support/spine/VertexAttachment.h index 12c3f67b193..a5f6d3973df 100644 --- a/native/cocos/editor-support/spine/VertexAttachment.h +++ b/native/cocos/editor-support/spine/VertexAttachment.h @@ -63,17 +63,17 @@ class SP_API VertexAttachment : public Attachment { void computeWorldVertices(Slot& slot, size_t start, size_t count, Vector& worldVertices, size_t offset, size_t stride = 2); /// Gets a unique ID for this attachment. - int getId(); + inline int getId() const { return _id; } - Vector& getBones(); + inline Vector& getBones() { return _bones; } - Vector& getVertices(); + inline Vector& getVertices() { return _vertices; } - size_t getWorldVerticesLength(); - void setWorldVerticesLength(size_t inValue); + inline size_t getWorldVerticesLength() const { return _worldVerticesLength; } + inline void setWorldVerticesLength(size_t inValue) { _worldVerticesLength = inValue; } - VertexAttachment* getDeformAttachment(); - void setDeformAttachment(VertexAttachment* attachment); + inline VertexAttachment* getDeformAttachment() { return _deformAttachment; } + inline void setDeformAttachment(VertexAttachment* attachment) { _deformAttachment = attachment; } void copyTo(VertexAttachment* other); From 1b4d2a015d60ab2b868fb35714bb3405cfcb351d Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 09:36:49 +0800 Subject: [PATCH 61/80] Add -Oz support --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index 8ebcfebb2ed..b8d215c034d 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -15,6 +15,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(ENABLE_CLOSURE_COMPILER 0) else() set(ENABLE_CLOSURE_COMPILER 1) + set(EXTRA_FLAGS "-Oz") endif() set(CMAKE_CXX_STANDARD 11) @@ -24,8 +25,8 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override ${ENABLE_PROFILING} \ +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override ${ENABLE_PROFILING} \ -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") message(">>> --------------------------------------------------------------") @@ -35,6 +36,7 @@ message(">>> ENABLE_CLOSURE_COMPILER: ${ENABLE_CLOSURE_COMPILER}") message(">>> ENABLE_JSON_PARSER: ${ENABLE_JSON_PARSER}") message(">>> ENABLE_BINARY_PARSER: ${ENABLE_BINARY_PARSER}") message(">>> ENABLE_PROFILING: ${ENABLE_PROFILING}") +message(">>> EXTRA_FLAGS: ${EXTRA_FLAGS}") message(">>> --------------------------------------------------------------") include_directories(${CMAKE_CURRENT_LIST_DIR}/..) @@ -44,7 +46,7 @@ file(GLOB COCOS_ADAPTER_SRC "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC}) # -s EMBIND_AOT=0 -s MALLOC=emmalloc -set(EMS_LINK_FLAGS "-s VERBOSE=0 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ +set(EMS_LINK_FLAGS "${EXTRA_FLAGS} -s VERBOSE=0 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ -s MIN_SAFARI_VERSION=110000 \ From a61c834057a207864089fa3d891e883e1a7c24a6 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 09:52:40 +0800 Subject: [PATCH 62/80] Remove inline for Vector::clear --- native/cocos/editor-support/spine/Vector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/editor-support/spine/Vector.h b/native/cocos/editor-support/spine/Vector.h index 55c15dd924e..802db245307 100644 --- a/native/cocos/editor-support/spine/Vector.h +++ b/native/cocos/editor-support/spine/Vector.h @@ -59,7 +59,7 @@ class SP_API Vector : public SpineObject { deallocate(_buffer); } - inline void clear() { + void clear() { for (size_t i = 0; i < _size; ++i) { destroy(_buffer + (_size - 1 - i)); } From ff561506b9596217f8fec66dd6eaef249babeedd Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 09:55:00 +0800 Subject: [PATCH 63/80] Refactor WasmSpineExtension --- native/cocos/editor-support/spine-wasm/spine-wasm.cpp | 6 +++--- .../cocos/editor-support/spine-wasm/wasmSpineExtension.cpp | 6 +----- native/cocos/editor-support/spine-wasm/wasmSpineExtension.h | 2 +- native/cocos/editor-support/spine/Extension.cpp | 5 +++++ native/cocos/editor-support/spine/Extension.h | 4 ++++ 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index ce8cc0e90b0..cc486db5c5a 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -19,8 +19,8 @@ uint32_t SpineWasmUtil::s_memSize = 0; void SpineWasmUtil::spineWasmInit() { // LogUtil::Initialize(); - SpineExtension* tension = new WasmSpineExtension(); - SpineExtension::setInstance(tension); + SpineExtension* extension = new WasmSpineExtension(); + SpineExtension::setInstance(extension); SpineMeshData::initMeshMemory(); @@ -44,7 +44,7 @@ SkeletonData* SpineWasmUtil::querySpineSkeletonDataByUUID(const String& uuid) { SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const String& jsonStr, const String& altasStr) { #if ENABLE_JSON_PARSER - auto* atlas = new Atlas(altasStr.buffer(), altasStr.length(), "", nullptr, false); + auto* atlas = new Atlas(altasStr.buffer(), altasStr.length(), "", nullptr, false); if (!atlas) { return nullptr; } diff --git a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp index 24e75a26c3a..0c2c78b83b9 100644 --- a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp +++ b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp @@ -7,7 +7,7 @@ using namespace spine; // extern uint32_t jsReadFile(char* fileName, uint32_t length); // } -WasmSpineExtension::WasmSpineExtension() : DefaultSpineExtension() { +WasmSpineExtension::WasmSpineExtension() : SpineExtension() { } WasmSpineExtension::~WasmSpineExtension() { @@ -50,7 +50,3 @@ void WasmSpineExtension::_free(void *mem, const char *file, int line) { SP_UNUSED(line); ::free(mem); } - -SpineExtension *spine::getDefaultExtension() { - return new WasmSpineExtension(); -} diff --git a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.h b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.h index 9ef30fc64f5..f49da86fb82 100644 --- a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.h +++ b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.h @@ -2,7 +2,7 @@ #define __WASM_SPINE_EXTENSION_H__ #include "spine/spine.h" -class WasmSpineExtension : public spine::DefaultSpineExtension { +class WasmSpineExtension : public spine::SpineExtension { public: WasmSpineExtension(); diff --git a/native/cocos/editor-support/spine/Extension.cpp b/native/cocos/editor-support/spine/Extension.cpp index ca111a1e33b..0b3cd797567 100644 --- a/native/cocos/editor-support/spine/Extension.cpp +++ b/native/cocos/editor-support/spine/Extension.cpp @@ -47,7 +47,9 @@ void SpineExtension::setInstance(SpineExtension *inValue) { } SpineExtension *SpineExtension::getInstance() { +#ifndef __EMSCRIPTEN__ if (!_instance) _instance = spine::getDefaultExtension(); +#endif assert(_instance); return _instance; @@ -59,6 +61,8 @@ SpineExtension::~SpineExtension() { SpineExtension::SpineExtension() { } +#ifndef __EMSCRIPTEN__ + DefaultSpineExtension::~DefaultSpineExtension() { } @@ -129,3 +133,4 @@ char *DefaultSpineExtension::_readFile(const String &path, int *length) { DefaultSpineExtension::DefaultSpineExtension() : SpineExtension() { } +#endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine/Extension.h b/native/cocos/editor-support/spine/Extension.h index 12c5cf83afe..1db361b08e7 100644 --- a/native/cocos/editor-support/spine/Extension.h +++ b/native/cocos/editor-support/spine/Extension.h @@ -89,6 +89,7 @@ class SP_API SpineExtension { static SpineExtension *_instance; }; +#ifndef __EMSCRIPTEN__ class SP_API DefaultSpineExtension : public SpineExtension { public: DefaultSpineExtension(); @@ -107,11 +108,14 @@ class SP_API DefaultSpineExtension : public SpineExtension { virtual char *_readFile(const String &path, int *length); }; +#endif + // This function is to be implemented by engine specific runtimes to provide // the default extension for that engine. It is called the first time // SpineExtension::getInstance() is called, when no instance has been set // yet. extern SpineExtension *getDefaultExtension(); + } // namespace spine #endif /* Spine_Extension_h */ From 7ae611d4ecf6a63a30af1f9ce15b5cd47fecfc2e Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 13:45:24 +0800 Subject: [PATCH 64/80] more inlines --- native/cocos/editor-support/spine/Atlas.cpp | 4 ---- native/cocos/editor-support/spine/Atlas.h | 2 +- native/cocos/editor-support/spine/Attachment.cpp | 2 +- native/cocos/editor-support/spine/Attachment.h | 2 +- native/cocos/editor-support/spine/MeshAttachment.cpp | 12 ------------ native/cocos/editor-support/spine/MeshAttachment.h | 6 +++--- .../cocos/editor-support/spine/RegionAttachment.cpp | 8 -------- native/cocos/editor-support/spine/RegionAttachment.h | 4 ++-- native/cocos/editor-support/spine/SlotData.cpp | 4 ---- native/cocos/editor-support/spine/SlotData.h | 2 +- 10 files changed, 9 insertions(+), 37 deletions(-) diff --git a/native/cocos/editor-support/spine/Atlas.cpp b/native/cocos/editor-support/spine/Atlas.cpp index b2927fe856a..a1770642553 100644 --- a/native/cocos/editor-support/spine/Atlas.cpp +++ b/native/cocos/editor-support/spine/Atlas.cpp @@ -94,10 +94,6 @@ AtlasRegion *Atlas::findRegion(const String &name) { return NULL; } -Vector &Atlas::getPages() { - return _pages; -} - void Atlas::load(const char *begin, int length, const char *dir, bool createTexture) { static const char *formatNames[] = {"", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888", "RGBA8888"}; static const char *textureFilterNames[] = {"", "Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", diff --git a/native/cocos/editor-support/spine/Atlas.h b/native/cocos/editor-support/spine/Atlas.h index 83cd413f283..5766a84af54 100644 --- a/native/cocos/editor-support/spine/Atlas.h +++ b/native/cocos/editor-support/spine/Atlas.h @@ -111,7 +111,7 @@ class SP_API Atlas : public SpineObject { /// @return The region, or NULL. AtlasRegion *findRegion(const String &name); - Vector &getPages(); + Vector &getPages() { return _pages; } private: Vector _pages; diff --git a/native/cocos/editor-support/spine/Attachment.cpp b/native/cocos/editor-support/spine/Attachment.cpp index 7172b4c67b3..9258215c463 100644 --- a/native/cocos/editor-support/spine/Attachment.cpp +++ b/native/cocos/editor-support/spine/Attachment.cpp @@ -50,7 +50,7 @@ const String &Attachment::getName() const { return _name; } -int Attachment::getRefCount() { +int Attachment::getRefCount() const { return _refCount; } diff --git a/native/cocos/editor-support/spine/Attachment.h b/native/cocos/editor-support/spine/Attachment.h index a88516d28bf..83655422029 100644 --- a/native/cocos/editor-support/spine/Attachment.h +++ b/native/cocos/editor-support/spine/Attachment.h @@ -47,7 +47,7 @@ class SP_API Attachment : public SpineObject { virtual Attachment *copy() = 0; - int getRefCount(); + int getRefCount() const; void reference(); void dereference(); diff --git a/native/cocos/editor-support/spine/MeshAttachment.cpp b/native/cocos/editor-support/spine/MeshAttachment.cpp index a8ba686e1c2..9a97f175838 100644 --- a/native/cocos/editor-support/spine/MeshAttachment.cpp +++ b/native/cocos/editor-support/spine/MeshAttachment.cpp @@ -114,18 +114,6 @@ void MeshAttachment::setHullLength(int inValue) { _hullLength = inValue; } -Vector &MeshAttachment::getRegionUVs() { - return _regionUVs; -} - -Vector &MeshAttachment::getUVs() { - return _uvs; -} - -Vector &MeshAttachment::getTriangles() { - return _triangles; -} - const String &MeshAttachment::getPath() { return _path; } diff --git a/native/cocos/editor-support/spine/MeshAttachment.h b/native/cocos/editor-support/spine/MeshAttachment.h index 6c5207e2bca..f0ec5128a3c 100644 --- a/native/cocos/editor-support/spine/MeshAttachment.h +++ b/native/cocos/editor-support/spine/MeshAttachment.h @@ -54,12 +54,12 @@ class SP_API MeshAttachment : public VertexAttachment, public HasRendererObject int getHullLength(); void setHullLength(int inValue); - Vector& getRegionUVs(); + inline Vector& getRegionUVs() { return _regionUVs; } /// The UV pair for each vertex, normalized within the entire texture. See also MeshAttachment::updateUVs - Vector& getUVs(); + inline Vector& getUVs() { return _uvs; } - Vector& getTriangles(); + inline Vector& getTriangles() { return _triangles; } Color& getColor(); diff --git a/native/cocos/editor-support/spine/RegionAttachment.cpp b/native/cocos/editor-support/spine/RegionAttachment.cpp index f8d86dff210..943a5bd75f7 100644 --- a/native/cocos/editor-support/spine/RegionAttachment.cpp +++ b/native/cocos/editor-support/spine/RegionAttachment.cpp @@ -251,14 +251,6 @@ void RegionAttachment::setRegionOriginalHeight(float inValue) { _regionOriginalHeight = inValue; } -Vector &RegionAttachment::getOffset() { - return _vertexOffset; -} - -Vector &RegionAttachment::getUVs() { - return _uvs; -} - spine::Color &RegionAttachment::getColor() { return _color; } diff --git a/native/cocos/editor-support/spine/RegionAttachment.h b/native/cocos/editor-support/spine/RegionAttachment.h index 19e1961f74c..a31dd85b4cb 100644 --- a/native/cocos/editor-support/spine/RegionAttachment.h +++ b/native/cocos/editor-support/spine/RegionAttachment.h @@ -102,8 +102,8 @@ class SP_API RegionAttachment : public Attachment, public HasRendererObject { float getRegionOriginalHeight(); void setRegionOriginalHeight(float inValue); - Vector& getOffset(); - Vector& getUVs(); + inline Vector& getOffset() { return _vertexOffset; } + inline Vector& getUVs() { return _uvs; } virtual Attachment* copy(); diff --git a/native/cocos/editor-support/spine/SlotData.cpp b/native/cocos/editor-support/spine/SlotData.cpp index 281c9da3656..60ddcf7cd7e 100644 --- a/native/cocos/editor-support/spine/SlotData.cpp +++ b/native/cocos/editor-support/spine/SlotData.cpp @@ -57,10 +57,6 @@ const String &SlotData::getName() { return _name; } -BoneData &SlotData::getBoneData() { - return _boneData; -} - Color &SlotData::getColor() { return _color; } diff --git a/native/cocos/editor-support/spine/SlotData.h b/native/cocos/editor-support/spine/SlotData.h index 2501fed0cbf..c645c351e40 100644 --- a/native/cocos/editor-support/spine/SlotData.h +++ b/native/cocos/editor-support/spine/SlotData.h @@ -78,7 +78,7 @@ class SP_API SlotData : public SpineObject { const String &getName(); - BoneData &getBoneData(); + inline BoneData &getBoneData() { return _boneData; } Color &getColor(); From 0de18c9d1e6beae4b6e7009b6dedeb441ab8e237 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 13:45:58 +0800 Subject: [PATCH 65/80] getUVs return reference, so don't copy it. --- .../spine-creator-support/SkeletonRenderer.cpp | 4 ++-- .../AtlasAttachmentLoaderExtension.cpp | 10 ++++++---- .../spine-wasm/spine-skeleton-instance.cpp | 18 +++++++++--------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp index 65d3b8a64c2..2411f9604ad 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp @@ -1074,7 +1074,7 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D region->setRendererObject(attachmentVertices); } V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; - auto UVs = region->getUVs(); + const auto &UVs = region->getUVs(); for (int i = 0, ii = 0; i < 4; ++i, ii += 2) { vertices[i].texCoord.u = UVs[ii]; vertices[i].texCoord.v = UVs[ii + 1]; @@ -1100,7 +1100,7 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D mesh->setRendererObject(attachmentVertices); } V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; - auto UVs = mesh->getUVs(); + const auto &UVs = mesh->getUVs(); for (size_t i = 0, ii = 0, nn = mesh->getWorldVerticesLength(); ii < nn; ++i, ii += 2) { vertices[i].texCoord.u = UVs[ii]; vertices[i].texCoord.v = UVs[ii + 1]; diff --git a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp index e8429ac1fc2..5ca9d9d9ea1 100644 --- a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp +++ b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp @@ -40,9 +40,10 @@ void AtlasAttachmentLoaderExtension::configureAttachment(Attachment *attachment) auto *region = static_cast(regionAttachment->getRendererObject()); auto *attachmentVertices = new AttachmentVertices(4, quadTriangles, 6, pages.indexOf(region->page)); V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; + const auto &uvs = regionAttachment->getUVs(); for (int i = 0, ii = 0; i < 4; ++i, ii += 2) { - vertices[i].texCoord.u = regionAttachment->getUVs()[ii]; - vertices[i].texCoord.v = regionAttachment->getUVs()[ii + 1]; + vertices[i].texCoord.u = uvs[ii]; + vertices[i].texCoord.v = uvs[ii + 1]; } regionAttachment->setRendererObject(attachmentVertices, deleteAttachmentVertices); } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { @@ -52,9 +53,10 @@ void AtlasAttachmentLoaderExtension::configureAttachment(Attachment *attachment) auto *attachmentVertices = new AttachmentVertices( static_cast(meshAttachment->getWorldVerticesLength() >> 1), meshAttachment->getTriangles().buffer(), static_cast(meshAttachment->getTriangles().size()), pages.indexOf(region->page)); V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; + const auto &uvs = meshAttachment->getUVs(); for (size_t i = 0, ii = 0, nn = meshAttachment->getWorldVerticesLength(); ii < nn; ++i, ii += 2) { - vertices[i].texCoord.u = meshAttachment->getUVs()[ii]; - vertices[i].texCoord.v = meshAttachment->getUVs()[ii + 1]; + vertices[i].texCoord.u = uvs[ii]; + vertices[i].texCoord.v = uvs[ii + 1]; } meshAttachment->setRendererObject(attachmentVertices, deleteAttachmentVertices); } diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index dad2e743715..4b984a9a495 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -448,16 +448,16 @@ Vector &SpineSkeletonInstance::getDebugShapes() { void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint32_t width, uint32_t height, bool createNew) { if (!_skeleton) return; - auto slot = _skeleton->findSlot(slotName); + auto* slot = _skeleton->findSlot(slotName); if (!slot) return; - auto attachment = slot->getAttachment(); + auto*attachment = slot->getAttachment(); if (!attachment) return; if (createNew) { attachment = attachment->copy(); slot->setAttachment(attachment); } if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) { - auto region = static_cast(attachment); + auto *region = static_cast(attachment); region->setRegionWidth(width); region->setRegionHeight(height); region->setRegionOriginalWidth(width); @@ -466,19 +466,19 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint region->setHeight(height); region->setUVs(0, 0, 1.0f, 1.0f, false); region->updateOffset(); - auto attachmentVertices = static_cast(region->getRendererObject()); + auto *attachmentVertices = static_cast(region->getRendererObject()); if (createNew) { attachmentVertices = attachmentVertices->copy(); region->setRendererObject(attachmentVertices); } V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; - auto UVs = region->getUVs(); + const auto &UVs = region->getUVs(); for (int i = 0, ii = 0; i < 4; ++i, ii += 2) { vertices[i].texCoord.u = UVs[ii]; vertices[i].texCoord.v = UVs[ii + 1]; } } else if (attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) { - auto mesh = static_cast(attachment); + auto *mesh = static_cast(attachment); mesh->setRegionWidth(width); mesh->setRegionHeight(height); mesh->setRegionOriginalWidth(width); @@ -492,13 +492,13 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint mesh->setRegionRotate(true); mesh->setRegionDegrees(0); mesh->updateUVs(); - auto attachmentVertices = static_cast(mesh->getRendererObject()); + auto *attachmentVertices = static_cast(mesh->getRendererObject()); if (createNew) { attachmentVertices = attachmentVertices->copy(); mesh->setRendererObject(attachmentVertices); } V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; - auto UVs = mesh->getUVs(); + const auto &UVs = mesh->getUVs(); for (size_t i = 0, ii = 0, nn = mesh->getWorldVerticesLength(); ii < nn; ++i, ii += 2) { vertices[i].texCoord.u = UVs[ii]; vertices[i].texCoord.v = UVs[ii + 1]; @@ -508,7 +508,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint void SpineSkeletonInstance::setSlotTexture(const spine::String &slotName, uint32_t textureID) { if (!_skeleton) return; - auto slot = _skeleton->findSlot(slotName); + auto* slot = _skeleton->findSlot(slotName); if (!slot) return; _userData.useSlotTexture = true; From 1fa66293de347ff2b1c8ecc09af0ee9151101eb4 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 13:46:28 +0800 Subject: [PATCH 66/80] Refactor logic in Skeleton.cpp, avoid some invocations. --- .../cocos/editor-support/spine/Skeleton.cpp | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/native/cocos/editor-support/spine/Skeleton.cpp b/native/cocos/editor-support/spine/Skeleton.cpp index 04f4bd0440d..9f185a9f5a8 100644 --- a/native/cocos/editor-support/spine/Skeleton.cpp +++ b/native/cocos/editor-support/spine/Skeleton.cpp @@ -69,15 +69,17 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData), _scaleY(1), _x(0), _y(0) { - _bones.ensureCapacity(_data->getBones().size()); - for (size_t i = 0; i < _data->getBones().size(); ++i) { - BoneData *data = _data->getBones()[i]; + const auto &boneDatas = _data->getBones(); + _bones.ensureCapacity(boneDatas.size()); + for (size_t i = 0; i < boneDatas.size(); ++i) { + BoneData *data = boneDatas[i]; Bone *bone; - if (data->getParent() == NULL) { + auto* dataParent = data->getParent(); + if (dataParent == NULL) { bone = spine_new Bone(*data, *this, NULL); } else { - Bone *parent = _bones[data->getParent()->getIndex()]; + Bone *parent = _bones[dataParent->getIndex()]; bone = spine_new Bone(*data, *this, parent); parent->getChildren().add(bone); } @@ -85,10 +87,11 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData), _bones.add(bone); } - _slots.ensureCapacity(_data->getSlots().size()); - _drawOrder.ensureCapacity(_data->getSlots().size()); - for (size_t i = 0; i < _data->getSlots().size(); ++i) { - SlotData *data = _data->getSlots()[i]; + const auto &dataSlots = _data->getSlots(); + _slots.ensureCapacity(dataSlots.size()); + _drawOrder.ensureCapacity(dataSlots.size()); + for (size_t i = 0; i < dataSlots.size(); ++i) { + SlotData *data = dataSlots[i]; Bone *bone = _bones[data->getBoneData().getIndex()]; Slot *slot = spine_new Slot(*data, *bone); @@ -97,27 +100,30 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData), _drawOrder.add(slot); } - _ikConstraints.ensureCapacity(_data->getIkConstraints().size()); - for (size_t i = 0; i < _data->getIkConstraints().size(); ++i) { - IkConstraintData *data = _data->getIkConstraints()[i]; + const auto &dataIkConstraints = _data->getIkConstraints(); + _ikConstraints.ensureCapacity(dataIkConstraints.size()); + for (size_t i = 0; i < dataIkConstraints.size(); ++i) { + IkConstraintData *data = dataIkConstraints[i]; IkConstraint *constraint = spine_new IkConstraint(*data, *this); _ikConstraints.add(constraint); } - _transformConstraints.ensureCapacity(_data->getTransformConstraints().size()); - for (size_t i = 0; i < _data->getTransformConstraints().size(); ++i) { - TransformConstraintData *data = _data->getTransformConstraints()[i]; + const auto &dataTransformConstraints = _data->getTransformConstraints(); + _transformConstraints.ensureCapacity(dataTransformConstraints.size()); + for (size_t i = 0; i < dataTransformConstraints.size(); ++i) { + TransformConstraintData *data = dataTransformConstraints[i]; TransformConstraint *constraint = spine_new TransformConstraint(*data, *this); _transformConstraints.add(constraint); } - _pathConstraints.ensureCapacity(_data->getPathConstraints().size()); - for (size_t i = 0; i < _data->getPathConstraints().size(); ++i) { - PathConstraintData *data = _data->getPathConstraints()[i]; + const auto &dataPathConstraints = _data->getPathConstraints(); + _pathConstraints.ensureCapacity(dataPathConstraints.size()); + for (size_t i = 0; i < dataPathConstraints.size(); ++i) { + PathConstraintData *data = dataPathConstraints[i]; PathConstraint *constraint = spine_new PathConstraint(*data, *this); From 0a2a3a1e6cc89645a25c330f6996a88345dd7da2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 13:46:36 +0800 Subject: [PATCH 67/80] Tweak Skin.cpp --- native/cocos/editor-support/spine/Skin.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/native/cocos/editor-support/spine/Skin.cpp b/native/cocos/editor-support/spine/Skin.cpp index 5a495fb4ef9..0f290386940 100644 --- a/native/cocos/editor-support/spine/Skin.cpp +++ b/native/cocos/editor-support/spine/Skin.cpp @@ -83,8 +83,9 @@ void Skin::AttachmentMap::remove(size_t slotIndex, const String &attachmentName) } int Skin::AttachmentMap::findInBucket(Vector &bucket, const String &attachmentName) { - for (size_t i = 0; i < bucket.size(); i++) - if (bucket[i]._name == attachmentName) return i; + for (size_t i = 0; i < bucket.size(); i++) { + if (bucket[i]._name == attachmentName) return static_cast(i); + } return -1; } From cf2e54dfa8bf070efbd0fade05dabeda1bf95ffc Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 15:54:46 +0800 Subject: [PATCH 68/80] Using ::abs --- native/cocos/editor-support/spine/MathUtil.cpp | 8 -------- native/cocos/editor-support/spine/MathUtil.h | 8 ++++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/native/cocos/editor-support/spine/MathUtil.cpp b/native/cocos/editor-support/spine/MathUtil.cpp index 48fcb2318f8..25c2a9d94e7 100644 --- a/native/cocos/editor-support/spine/MathUtil.cpp +++ b/native/cocos/editor-support/spine/MathUtil.cpp @@ -46,10 +46,6 @@ RTTI_IMPL_NOPARENT(Interpolation) RTTI_IMPL(PowInterpolation, Interpolation) RTTI_IMPL(PowOutInterpolation, Interpolation) -float MathUtil::abs(float v) { - return ((v) < 0 ? -(v) : (v)); -} - float MathUtil::sign(float v) { return ((v) < 0 ? -1.0f : (v) > 0 ? 1.0f : 0.0f); @@ -75,7 +71,3 @@ float MathUtil::randomTriangular(float min, float max, float mode) { if (u <= (mode - min) / d) return min + sqrt(u * d * (mode - min)); return max - sqrt((1 - u) * d * (max - mode)); } - -float MathUtil::pow(float a, float b) { - return (float)::pow(a, b); -} diff --git a/native/cocos/editor-support/spine/MathUtil.h b/native/cocos/editor-support/spine/MathUtil.h index 28d6a62ab5a..8526d859fb6 100644 --- a/native/cocos/editor-support/spine/MathUtil.h +++ b/native/cocos/editor-support/spine/MathUtil.h @@ -56,7 +56,9 @@ class SP_API MathUtil { static float clamp(float x, float lower, float upper); - static float abs(float v); + static inline float abs(float v) { + return ::abs(v); + } /// Returns the sine in radians from a lookup table. static inline float sin(float radians) { @@ -108,7 +110,9 @@ class SP_API MathUtil { static float randomTriangular(float min, float max, float mode); - static float pow(float a, float b); + static inline float pow(float a, float b) { + return (float)::pow(a, b); + } }; struct SP_API Interpolation { From 66a73f64d2ee059e5d774cf6c696f8121f46dd86 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 17:46:19 +0800 Subject: [PATCH 69/80] More inline for Vector getter. --- .../spine-wasm/spine-skeleton-instance.cpp | 2 +- .../cocos/editor-support/spine/Animation.cpp | 4 --- native/cocos/editor-support/spine/Animation.h | 2 +- .../editor-support/spine/AnimationState.cpp | 4 --- .../editor-support/spine/AnimationState.h | 2 +- native/cocos/editor-support/spine/Atlas.h | 2 +- .../cocos/editor-support/spine/Attachment.cpp | 4 +-- .../spine/AttachmentTimeline.cpp | 8 ----- .../editor-support/spine/AttachmentTimeline.h | 4 +-- native/cocos/editor-support/spine/Bone.cpp | 23 ++++++------- native/cocos/editor-support/spine/Bone.h | 2 +- .../editor-support/spine/ColorTimeline.cpp | 4 --- .../editor-support/spine/ColorTimeline.h | 2 +- .../editor-support/spine/DeformTimeline.cpp | 8 ----- .../editor-support/spine/DeformTimeline.h | 4 +-- .../spine/DrawOrderTimeline.cpp | 8 ----- .../editor-support/spine/DrawOrderTimeline.h | 4 +-- .../editor-support/spine/EventTimeline.cpp | 4 --- .../editor-support/spine/EventTimeline.h | 4 +-- .../editor-support/spine/IkConstraint.cpp | 4 --- .../cocos/editor-support/spine/IkConstraint.h | 2 +- .../editor-support/spine/IkConstraintData.cpp | 4 --- .../editor-support/spine/IkConstraintData.h | 2 +- .../editor-support/spine/MeshAttachment.cpp | 4 --- .../editor-support/spine/MeshAttachment.h | 2 +- .../editor-support/spine/PathConstraint.cpp | 4 --- .../editor-support/spine/PathConstraint.h | 2 +- .../spine/PathConstraintData.cpp | 4 --- .../editor-support/spine/PathConstraintData.h | 2 +- .../editor-support/spine/RotateTimeline.cpp | 4 --- .../editor-support/spine/RotateTimeline.h | 2 +- .../cocos/editor-support/spine/Skeleton.cpp | 28 ---------------- native/cocos/editor-support/spine/Skeleton.h | 14 ++++---- .../editor-support/spine/SkeletonClipping.cpp | 18 +++++------ .../editor-support/spine/SkeletonClipping.h | 6 ++-- .../editor-support/spine/SkeletonData.cpp | 32 ------------------- .../cocos/editor-support/spine/SkeletonData.h | 16 +++++----- native/cocos/editor-support/spine/Skin.cpp | 8 ----- native/cocos/editor-support/spine/Skin.h | 4 +-- native/cocos/editor-support/spine/Slot.cpp | 4 --- native/cocos/editor-support/spine/Slot.h | 2 +- .../spine/TransformConstraint.cpp | 4 --- .../spine/TransformConstraint.h | 2 +- .../spine/TransformConstraintData.cpp | 11 ------- .../spine/TransformConstraintData.h | 6 ++-- 45 files changed, 66 insertions(+), 220 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index 4b984a9a495..56ca0f311e8 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -131,7 +131,7 @@ void SpineSkeletonInstance::collectMeshData() { } const Color& skeletonColor = _skeleton->getColor(); for (uint32_t drawIdx = 0; drawIdx < slotCount; ++drawIdx) { - auto slot = slotArray[drawIdx]; + auto* slot = slotArray[drawIdx]; auto& bone = slot->getBone(); if (!bone.isActive()) { continue; diff --git a/native/cocos/editor-support/spine/Animation.cpp b/native/cocos/editor-support/spine/Animation.cpp index e500cb19b80..367ae4b39d5 100644 --- a/native/cocos/editor-support/spine/Animation.cpp +++ b/native/cocos/editor-support/spine/Animation.cpp @@ -77,10 +77,6 @@ const String &Animation::getName() { return _name; } -Vector &Animation::getTimelines() { - return _timelines; -} - float Animation::getDuration() { return _duration; } diff --git a/native/cocos/editor-support/spine/Animation.h b/native/cocos/editor-support/spine/Animation.h index 22ed8fc3035..b466f0f5e4b 100644 --- a/native/cocos/editor-support/spine/Animation.h +++ b/native/cocos/editor-support/spine/Animation.h @@ -93,7 +93,7 @@ class SP_API Animation : public SpineObject { const String &getName(); - Vector &getTimelines(); + inline Vector &getTimelines() { return _timelines; } bool hasTimeline(int id); diff --git a/native/cocos/editor-support/spine/AnimationState.cpp b/native/cocos/editor-support/spine/AnimationState.cpp index 873fcbc1603..14b7871c2f7 100644 --- a/native/cocos/editor-support/spine/AnimationState.cpp +++ b/native/cocos/editor-support/spine/AnimationState.cpp @@ -610,10 +610,6 @@ AnimationStateData *AnimationState::getData() { return _data; } -Vector &AnimationState::getTracks() { - return _tracks; -} - float AnimationState::getTimeScale() { return _timeScale; } diff --git a/native/cocos/editor-support/spine/AnimationState.h b/native/cocos/editor-support/spine/AnimationState.h index be9182affa8..05ee988114b 100644 --- a/native/cocos/editor-support/spine/AnimationState.h +++ b/native/cocos/editor-support/spine/AnimationState.h @@ -375,7 +375,7 @@ class SP_API AnimationState : public SpineObject, public HasRendererObject { AnimationStateData* getData(); /// A list of tracks that have animations, which may contain NULLs. - Vector& getTracks(); + inline Vector& getTracks() { return _tracks; } float getTimeScale(); void setTimeScale(float inValue); diff --git a/native/cocos/editor-support/spine/Atlas.h b/native/cocos/editor-support/spine/Atlas.h index 5766a84af54..469a32be2dd 100644 --- a/native/cocos/editor-support/spine/Atlas.h +++ b/native/cocos/editor-support/spine/Atlas.h @@ -111,7 +111,7 @@ class SP_API Atlas : public SpineObject { /// @return The region, or NULL. AtlasRegion *findRegion(const String &name); - Vector &getPages() { return _pages; } + inline Vector &getPages() { return _pages; } private: Vector _pages; diff --git a/native/cocos/editor-support/spine/Attachment.cpp b/native/cocos/editor-support/spine/Attachment.cpp index 9258215c463..86367e71ea8 100644 --- a/native/cocos/editor-support/spine/Attachment.cpp +++ b/native/cocos/editor-support/spine/Attachment.cpp @@ -55,9 +55,9 @@ int Attachment::getRefCount() const { } void Attachment::reference() { - _refCount++; + ++_refCount; } void Attachment::dereference() { - _refCount--; + --_refCount; } diff --git a/native/cocos/editor-support/spine/AttachmentTimeline.cpp b/native/cocos/editor-support/spine/AttachmentTimeline.cpp index eab3779a9c2..2ee9aa6654c 100644 --- a/native/cocos/editor-support/spine/AttachmentTimeline.cpp +++ b/native/cocos/editor-support/spine/AttachmentTimeline.cpp @@ -114,14 +114,6 @@ void AttachmentTimeline::setSlotIndex(size_t inValue) { _slotIndex = inValue; } -const Vector &AttachmentTimeline::getFrames() { - return _frames; -} - -const Vector &AttachmentTimeline::getAttachmentNames() { - return _attachmentNames; -} - size_t AttachmentTimeline::getFrameCount() { return _frames.size(); } diff --git a/native/cocos/editor-support/spine/AttachmentTimeline.h b/native/cocos/editor-support/spine/AttachmentTimeline.h index e69c532f85a..0ed4413dc8c 100644 --- a/native/cocos/editor-support/spine/AttachmentTimeline.h +++ b/native/cocos/editor-support/spine/AttachmentTimeline.h @@ -60,8 +60,8 @@ class SP_API AttachmentTimeline : public Timeline { size_t getSlotIndex(); void setSlotIndex(size_t inValue); - const Vector& getFrames(); - const Vector& getAttachmentNames(); + inline const Vector& getFrames() const { return _frames; } + inline const Vector& getAttachmentNames() const { return _attachmentNames; } size_t getFrameCount(); #ifndef __EMSCRIPTEN__ diff --git a/native/cocos/editor-support/spine/Bone.cpp b/native/cocos/editor-support/spine/Bone.cpp index 8643693b577..cd402ded120 100644 --- a/native/cocos/editor-support/spine/Bone.cpp +++ b/native/cocos/editor-support/spine/Bone.cpp @@ -102,10 +102,11 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, _ashearY = shearY; _appliedValid = true; + float sx = _skeleton.getScaleX(); + float sy = _skeleton.getScaleY(); + if (!parent) { /* Root bone. */ float rotationY = rotation + 90 + shearY; - float sx = _skeleton.getScaleX(); - float sy = _skeleton.getScaleY(); _a = MathUtil::cosDeg(rotation + shearX) * scaleX * sx; _b = MathUtil::cosDeg(rotationY) * scaleY * sx; _c = MathUtil::sinDeg(rotation + shearX) * scaleX * sy; @@ -176,14 +177,14 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float r, zb, zd, la, lb, lc, ld; cosine = MathUtil::cosDeg(rotation); sine = MathUtil::sinDeg(rotation); - za = (pa * cosine + pb * sine) / _skeleton.getScaleX(); - zc = (pc * cosine + pd * sine) / _skeleton.getScaleY(); + za = (pa * cosine + pb * sine) / sx; + zc = (pc * cosine + pd * sine) / sy; s = MathUtil::sqrt(za * za + zc * zc); if (s > 0.00001f) s = 1 / s; za *= s; zc *= s; s = MathUtil::sqrt(za * za + zc * zc); - if (mode == TransformMode_NoScale && (pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) + if (mode == TransformMode_NoScale && (pa * pd - pb * pc < 0) != (sx < 0 != sy < 0)) s = -s; r = MathUtil::Pi / 2 + MathUtil::atan2(zc, za); zb = MathUtil::cos(r) * s; @@ -199,10 +200,10 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, break; } } - _a *= _skeleton.getScaleX(); - _b *= _skeleton.getScaleX(); - _c *= _skeleton.getScaleY(); - _d *= _skeleton.getScaleY(); + _a *= sx; + _b *= sx; + _c *= sy; + _d *= sy; } void Bone::setToSetupPose() { @@ -311,10 +312,6 @@ Bone *Bone::getParent() { return _parent; } -Vector &Bone::getChildren() { - return _children; -} - float Bone::getWorldRotationX() const { return MathUtil::atan2(_c, _a) * MathUtil::MathUtil::Rad_Deg; } diff --git a/native/cocos/editor-support/spine/Bone.h b/native/cocos/editor-support/spine/Bone.h index 88b12d20613..08022ffbb5d 100644 --- a/native/cocos/editor-support/spine/Bone.h +++ b/native/cocos/editor-support/spine/Bone.h @@ -112,7 +112,7 @@ class SP_API Bone : public Updatable { Bone *getParent(); - Vector &getChildren(); + inline Vector &getChildren() { return _children; } /// The local X translation. inline float getX() const { diff --git a/native/cocos/editor-support/spine/ColorTimeline.cpp b/native/cocos/editor-support/spine/ColorTimeline.cpp index 988fed21080..2f65d26f760 100644 --- a/native/cocos/editor-support/spine/ColorTimeline.cpp +++ b/native/cocos/editor-support/spine/ColorTimeline.cpp @@ -138,7 +138,3 @@ int ColorTimeline::getSlotIndex() { void ColorTimeline::setSlotIndex(int inValue) { _slotIndex = inValue; } - -Vector &ColorTimeline::getFrames() { - return _frames; -} diff --git a/native/cocos/editor-support/spine/ColorTimeline.h b/native/cocos/editor-support/spine/ColorTimeline.h index d3f0e85cf29..1ef937e0278 100644 --- a/native/cocos/editor-support/spine/ColorTimeline.h +++ b/native/cocos/editor-support/spine/ColorTimeline.h @@ -58,7 +58,7 @@ class SP_API ColorTimeline : public CurveTimeline { void setSlotIndex(int inValue); - Vector &getFrames(); + inline Vector &getFrames() { return _frames; } protected: static const int PREV_TIME; diff --git a/native/cocos/editor-support/spine/DeformTimeline.cpp b/native/cocos/editor-support/spine/DeformTimeline.cpp index 164f60c34dd..f2443700d93 100644 --- a/native/cocos/editor-support/spine/DeformTimeline.cpp +++ b/native/cocos/editor-support/spine/DeformTimeline.cpp @@ -280,14 +280,6 @@ void DeformTimeline::setSlotIndex(int inValue) { _slotIndex = inValue; } -Vector &DeformTimeline::getFrames() { - return _frames; -} - -Vector > &DeformTimeline::getVertices() { - return _frameVertices; -} - VertexAttachment *DeformTimeline::getAttachment() { return _attachment; } diff --git a/native/cocos/editor-support/spine/DeformTimeline.h b/native/cocos/editor-support/spine/DeformTimeline.h index 9b06d8eaa2c..ff12953d892 100644 --- a/native/cocos/editor-support/spine/DeformTimeline.h +++ b/native/cocos/editor-support/spine/DeformTimeline.h @@ -53,8 +53,8 @@ class SP_API DeformTimeline : public CurveTimeline { int getSlotIndex(); void setSlotIndex(int inValue); - Vector& getFrames(); - Vector >& getVertices(); + inline Vector& getFrames() { return _frames; } + inline Vector >& getVertices() { return _frameVertices; } VertexAttachment* getAttachment(); void setAttachment(VertexAttachment* inValue); diff --git a/native/cocos/editor-support/spine/DrawOrderTimeline.cpp b/native/cocos/editor-support/spine/DrawOrderTimeline.cpp index 0c1dce7575d..0a3a3525f40 100644 --- a/native/cocos/editor-support/spine/DrawOrderTimeline.cpp +++ b/native/cocos/editor-support/spine/DrawOrderTimeline.cpp @@ -111,14 +111,6 @@ void DrawOrderTimeline::setFrame(size_t frameIndex, float time, Vector &dra _drawOrders[frameIndex].addAll(drawOrder); } -Vector &DrawOrderTimeline::getFrames() { - return _frames; -} - -Vector > &DrawOrderTimeline::getDrawOrders() { - return _drawOrders; -} - size_t DrawOrderTimeline::getFrameCount() { return _frames.size(); } diff --git a/native/cocos/editor-support/spine/DrawOrderTimeline.h b/native/cocos/editor-support/spine/DrawOrderTimeline.h index 4236ab2b093..d320cfbe333 100644 --- a/native/cocos/editor-support/spine/DrawOrderTimeline.h +++ b/native/cocos/editor-support/spine/DrawOrderTimeline.h @@ -50,8 +50,8 @@ class SP_API DrawOrderTimeline : public Timeline { /// @param drawOrder May be NULL to use bind pose draw order void setFrame(size_t frameIndex, float time, Vector& drawOrder); - Vector& getFrames(); - Vector >& getDrawOrders(); + inline Vector& getFrames() { return _frames; } + inline Vector >& getDrawOrders() { return _drawOrders; } size_t getFrameCount(); private: diff --git a/native/cocos/editor-support/spine/EventTimeline.cpp b/native/cocos/editor-support/spine/EventTimeline.cpp index c3f01276355..7d04e8dbd96 100644 --- a/native/cocos/editor-support/spine/EventTimeline.cpp +++ b/native/cocos/editor-support/spine/EventTimeline.cpp @@ -103,8 +103,4 @@ void EventTimeline::setFrame(size_t frameIndex, Event *event) { _events[frameIndex] = event; } -Vector &EventTimeline::getFrames() { return _frames; } - -Vector &EventTimeline::getEvents() { return _events; } - size_t EventTimeline::getFrameCount() { return _frames.size(); } diff --git a/native/cocos/editor-support/spine/EventTimeline.h b/native/cocos/editor-support/spine/EventTimeline.h index 17fe1958eb0..54bf9fda836 100644 --- a/native/cocos/editor-support/spine/EventTimeline.h +++ b/native/cocos/editor-support/spine/EventTimeline.h @@ -51,8 +51,8 @@ class SP_API EventTimeline : public Timeline { /// Sets the time and value of the specified keyframe. void setFrame(size_t frameIndex, Event* event); - Vector& getFrames(); - Vector& getEvents(); + inline Vector& getFrames() { return _frames; } + inline Vector& getEvents() { return _events; } size_t getFrameCount(); private: diff --git a/native/cocos/editor-support/spine/IkConstraint.cpp b/native/cocos/editor-support/spine/IkConstraint.cpp index e7079afa430..ae6fb9a4388 100644 --- a/native/cocos/editor-support/spine/IkConstraint.cpp +++ b/native/cocos/editor-support/spine/IkConstraint.cpp @@ -298,10 +298,6 @@ IkConstraintData &IkConstraint::getData() { return _data; } -Vector &IkConstraint::getBones() { - return _bones; -} - Bone *IkConstraint::getTarget() { return _target; } diff --git a/native/cocos/editor-support/spine/IkConstraint.h b/native/cocos/editor-support/spine/IkConstraint.h index deeb06c226b..20b20259247 100644 --- a/native/cocos/editor-support/spine/IkConstraint.h +++ b/native/cocos/editor-support/spine/IkConstraint.h @@ -69,7 +69,7 @@ class SP_API IkConstraint : public Updatable { IkConstraintData &getData(); - Vector &getBones(); + inline Vector &getBones() { return _bones; } Bone *getTarget(); diff --git a/native/cocos/editor-support/spine/IkConstraintData.cpp b/native/cocos/editor-support/spine/IkConstraintData.cpp index e6fa2b774cc..b0bd1b4082e 100644 --- a/native/cocos/editor-support/spine/IkConstraintData.cpp +++ b/native/cocos/editor-support/spine/IkConstraintData.cpp @@ -49,10 +49,6 @@ IkConstraintData::IkConstraintData(const String &name) : ConstraintData(name), _softness(0) { } -Vector &IkConstraintData::getBones() { - return _bones; -} - BoneData *IkConstraintData::getTarget() { return _target; } diff --git a/native/cocos/editor-support/spine/IkConstraintData.h b/native/cocos/editor-support/spine/IkConstraintData.h index c1c731b1f3e..8787abaaa4a 100644 --- a/native/cocos/editor-support/spine/IkConstraintData.h +++ b/native/cocos/editor-support/spine/IkConstraintData.h @@ -50,7 +50,7 @@ class SP_API IkConstraintData : public ConstraintData { explicit IkConstraintData(const String& name); /// The bones that are constrained by this IK Constraint. - Vector& getBones(); + inline Vector& getBones() { return _bones; } /// The bone that is the IK target. BoneData* getTarget(); diff --git a/native/cocos/editor-support/spine/MeshAttachment.cpp b/native/cocos/editor-support/spine/MeshAttachment.cpp index 9a97f175838..6f073f080dc 100644 --- a/native/cocos/editor-support/spine/MeshAttachment.cpp +++ b/native/cocos/editor-support/spine/MeshAttachment.cpp @@ -237,10 +237,6 @@ void MeshAttachment::setParentMesh(MeshAttachment *inValue) { } } -Vector &MeshAttachment::getEdges() { - return _edges; -} - float MeshAttachment::getWidth() { return _width; } diff --git a/native/cocos/editor-support/spine/MeshAttachment.h b/native/cocos/editor-support/spine/MeshAttachment.h index f0ec5128a3c..6e2bcbf21a3 100644 --- a/native/cocos/editor-support/spine/MeshAttachment.h +++ b/native/cocos/editor-support/spine/MeshAttachment.h @@ -109,7 +109,7 @@ class SP_API MeshAttachment : public VertexAttachment, public HasRendererObject void setParentMesh(MeshAttachment* inValue); // Nonessential. - Vector& getEdges(); + inline Vector& getEdges() { return _edges; } float getWidth(); void setWidth(float inValue); float getHeight(); diff --git a/native/cocos/editor-support/spine/PathConstraint.cpp b/native/cocos/editor-support/spine/PathConstraint.cpp index d93d1e4272b..90a667d43c8 100644 --- a/native/cocos/editor-support/spine/PathConstraint.cpp +++ b/native/cocos/editor-support/spine/PathConstraint.cpp @@ -236,10 +236,6 @@ void PathConstraint::setTranslateMix(float inValue) { _translateMix = inValue; } -Vector &PathConstraint::getBones() { - return _bones; -} - Slot *PathConstraint::getTarget() { return _target; } diff --git a/native/cocos/editor-support/spine/PathConstraint.h b/native/cocos/editor-support/spine/PathConstraint.h index 1cf594c1314..2f5e4eb5103 100644 --- a/native/cocos/editor-support/spine/PathConstraint.h +++ b/native/cocos/editor-support/spine/PathConstraint.h @@ -71,7 +71,7 @@ class SP_API PathConstraint : public Updatable { float getTranslateMix(); void setTranslateMix(float inValue); - Vector& getBones(); + inline Vector& getBones() { return _bones; } Slot* getTarget(); void setTarget(Slot* inValue); diff --git a/native/cocos/editor-support/spine/PathConstraintData.cpp b/native/cocos/editor-support/spine/PathConstraintData.cpp index 03757df305b..66f37d0f96c 100644 --- a/native/cocos/editor-support/spine/PathConstraintData.cpp +++ b/native/cocos/editor-support/spine/PathConstraintData.cpp @@ -54,10 +54,6 @@ PathConstraintData::PathConstraintData(const String &name) : ConstraintData(name _translateMix(0) { } -Vector &PathConstraintData::getBones() { - return _bones; -} - SlotData *PathConstraintData::getTarget() { return _target; } diff --git a/native/cocos/editor-support/spine/PathConstraintData.h b/native/cocos/editor-support/spine/PathConstraintData.h index a9cb306027a..6dbf881f35a 100644 --- a/native/cocos/editor-support/spine/PathConstraintData.h +++ b/native/cocos/editor-support/spine/PathConstraintData.h @@ -56,7 +56,7 @@ class SP_API PathConstraintData : public ConstraintData { public: explicit PathConstraintData(const String& name); - Vector& getBones(); + inline Vector& getBones() { return _bones; } SlotData* getTarget(); void setTarget(SlotData* inValue); diff --git a/native/cocos/editor-support/spine/RotateTimeline.cpp b/native/cocos/editor-support/spine/RotateTimeline.cpp index c74d0b413a2..30900a637ff 100644 --- a/native/cocos/editor-support/spine/RotateTimeline.cpp +++ b/native/cocos/editor-support/spine/RotateTimeline.cpp @@ -132,7 +132,3 @@ int RotateTimeline::getBoneIndex() { void RotateTimeline::setBoneIndex(int inValue) { _boneIndex = inValue; } - -Vector &RotateTimeline::getFrames() { - return _frames; -} diff --git a/native/cocos/editor-support/spine/RotateTimeline.h b/native/cocos/editor-support/spine/RotateTimeline.h index 3d4b57867dc..79ed87007e5 100644 --- a/native/cocos/editor-support/spine/RotateTimeline.h +++ b/native/cocos/editor-support/spine/RotateTimeline.h @@ -55,7 +55,7 @@ class SP_API RotateTimeline : public CurveTimeline { int getBoneIndex(); void setBoneIndex(int inValue); - Vector& getFrames(); + inline Vector& getFrames() { return _frames; } #ifndef __EMSCRIPTEN__ private: #endif diff --git a/native/cocos/editor-support/spine/Skeleton.cpp b/native/cocos/editor-support/spine/Skeleton.cpp index 9f185a9f5a8..7aa575a1209 100644 --- a/native/cocos/editor-support/spine/Skeleton.cpp +++ b/native/cocos/editor-support/spine/Skeleton.cpp @@ -486,34 +486,6 @@ SkeletonData *Skeleton::getData() { return _data; } -Vector &Skeleton::getBones() { - return _bones; -} - -Vector &Skeleton::getUpdateCacheList() { - return _updateCache; -} - -Vector &Skeleton::getSlots() { - return _slots; -} - -Vector &Skeleton::getDrawOrder() { - return _drawOrder; -} - -Vector &Skeleton::getIkConstraints() { - return _ikConstraints; -} - -Vector &Skeleton::getPathConstraints() { - return _pathConstraints; -} - -Vector &Skeleton::getTransformConstraints() { - return _transformConstraints; -} - Skin *Skeleton::getSkin() { return _skin; } diff --git a/native/cocos/editor-support/spine/Skeleton.h b/native/cocos/editor-support/spine/Skeleton.h index 16f8f15d002..cf94bd5c137 100644 --- a/native/cocos/editor-support/spine/Skeleton.h +++ b/native/cocos/editor-support/spine/Skeleton.h @@ -168,19 +168,19 @@ class SP_API Skeleton : public SpineObject { SkeletonData *getData(); - Vector &getBones(); + inline Vector &getBones() { return _bones; } - Vector &getUpdateCacheList(); + inline Vector &getUpdateCacheList() { return _updateCache; } - Vector &getSlots(); + inline Vector &getSlots() { return _slots; } - Vector &getDrawOrder(); + inline Vector &getDrawOrder() { return _drawOrder; } - Vector &getIkConstraints(); + inline Vector &getIkConstraints() { return _ikConstraints; } - Vector &getPathConstraints(); + inline Vector &getPathConstraints() { return _pathConstraints; } - Vector &getTransformConstraints(); + inline Vector &getTransformConstraints() { return _transformConstraints; } Skin *getSkin(); diff --git a/native/cocos/editor-support/spine/SkeletonClipping.cpp b/native/cocos/editor-support/spine/SkeletonClipping.cpp index 370f4a08c52..ad6a5c3d846 100644 --- a/native/cocos/editor-support/spine/SkeletonClipping.cpp +++ b/native/cocos/editor-support/spine/SkeletonClipping.cpp @@ -186,17 +186,17 @@ bool SkeletonClipping::isClipping() { return _clipAttachment != NULL; } -Vector &SkeletonClipping::getClippedVertices() { - return _clippedVertices; -} +// Vector &SkeletonClipping::getClippedVertices() { +// return _clippedVertices; +// } -Vector &SkeletonClipping::getClippedTriangles() { - return _clippedTriangles; -} +// Vector &SkeletonClipping::getClippedTriangles() { +// return _clippedTriangles; +// } -Vector &SkeletonClipping::getClippedUVs() { - return _clippedUVs; -} +// Vector &SkeletonClipping::getClippedUVs() { +// return _clippedUVs; +// } bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector *clippingArea, Vector *output) { diff --git a/native/cocos/editor-support/spine/SkeletonClipping.h b/native/cocos/editor-support/spine/SkeletonClipping.h index 2046f8cc203..23e10538941 100644 --- a/native/cocos/editor-support/spine/SkeletonClipping.h +++ b/native/cocos/editor-support/spine/SkeletonClipping.h @@ -53,9 +53,9 @@ class SP_API SkeletonClipping : public SpineObject { bool isClipping(); - Vector& getClippedVertices(); - Vector& getClippedTriangles(); - Vector& getClippedUVs(); + inline Vector& getClippedVertices() { return _clippedVertices; } + inline Vector& getClippedTriangles() { return _clippedTriangles; } + inline Vector& getClippedUVs() { return _clippedUVs; } private: Triangulator _triangulator; diff --git a/native/cocos/editor-support/spine/SkeletonData.cpp b/native/cocos/editor-support/spine/SkeletonData.cpp index e260cba5ed0..09cd79181ae 100644 --- a/native/cocos/editor-support/spine/SkeletonData.cpp +++ b/native/cocos/editor-support/spine/SkeletonData.cpp @@ -127,18 +127,6 @@ void SkeletonData::setName(const String &inValue) { _name = inValue; } -Vector &SkeletonData::getBones() { - return _bones; -} - -Vector &SkeletonData::getSlots() { - return _slots; -} - -Vector &SkeletonData::getSkins() { - return _skins; -} - Skin *SkeletonData::getDefaultSkin() { return _defaultSkin; } @@ -147,26 +135,6 @@ void SkeletonData::setDefaultSkin(Skin *inValue) { _defaultSkin = inValue; } -Vector &SkeletonData::getEvents() { - return _events; -} - -Vector &SkeletonData::getAnimations() { - return _animations; -} - -Vector &SkeletonData::getIkConstraints() { - return _ikConstraints; -} - -Vector &SkeletonData::getTransformConstraints() { - return _transformConstraints; -} - -Vector &SkeletonData::getPathConstraints() { - return _pathConstraints; -} - float SkeletonData::getX() { return _x; } diff --git a/native/cocos/editor-support/spine/SkeletonData.h b/native/cocos/editor-support/spine/SkeletonData.h index 6ffff49c087..911787bb5d0 100644 --- a/native/cocos/editor-support/spine/SkeletonData.h +++ b/native/cocos/editor-support/spine/SkeletonData.h @@ -103,12 +103,12 @@ class SP_API SkeletonData : public SpineObject { void setName(const String &inValue); /// The skeleton's bones, sorted parent first. The root bone is always the first bone. - Vector &getBones(); + inline Vector &getBones() { return _bones; } - Vector &getSlots(); + inline Vector &getSlots() { return _slots; } /// All skins, including the default skin. - Vector &getSkins(); + inline Vector &getSkins() { return _skins; } /// The skeleton's default skin. /// By default this skin contains all attachments that were not in a skin in Spine. @@ -117,15 +117,15 @@ class SP_API SkeletonData : public SpineObject { void setDefaultSkin(Skin *inValue); - Vector &getEvents(); + inline Vector &getEvents() { return _events; } - Vector &getAnimations(); + inline Vector &getAnimations() { return _animations; } - Vector &getIkConstraints(); + inline Vector &getIkConstraints() { return _ikConstraints; } - Vector &getTransformConstraints(); + inline Vector &getTransformConstraints() { return _transformConstraints; } - Vector &getPathConstraints(); + inline Vector &getPathConstraints() { return _pathConstraints; } float getX(); diff --git a/native/cocos/editor-support/spine/Skin.cpp b/native/cocos/editor-support/spine/Skin.cpp index 0f290386940..7a405d3a581 100644 --- a/native/cocos/editor-support/spine/Skin.cpp +++ b/native/cocos/editor-support/spine/Skin.cpp @@ -189,11 +189,3 @@ void Skin::copySkin(Skin *other) { setAttachment(entry._slotIndex, entry._name, entry._attachment->copy()); } } - -Vector &Skin::getConstraints() { - return _constraints; -} - -Vector &Skin::getBones() { - return _bones; -} diff --git a/native/cocos/editor-support/spine/Skin.h b/native/cocos/editor-support/spine/Skin.h index 7ce6574e18b..416659bced9 100644 --- a/native/cocos/editor-support/spine/Skin.h +++ b/native/cocos/editor-support/spine/Skin.h @@ -145,9 +145,9 @@ class SP_API Skin : public SpineObject { AttachmentMap::Entries getAttachments(); - Vector &getBones(); + inline Vector &getBones() { return _bones; } - Vector &getConstraints(); + inline Vector &getConstraints() { return _constraints; } private: const String _name; diff --git a/native/cocos/editor-support/spine/Slot.cpp b/native/cocos/editor-support/spine/Slot.cpp index 1d8c0826fa8..9e0732feb7f 100644 --- a/native/cocos/editor-support/spine/Slot.cpp +++ b/native/cocos/editor-support/spine/Slot.cpp @@ -100,7 +100,3 @@ float Slot::getAttachmentTime() { void Slot::setAttachmentTime(float inValue) { _attachmentTime = _skeleton.getTime() - inValue; } - -Vector &Slot::getDeform() { - return _deform; -} diff --git a/native/cocos/editor-support/spine/Slot.h b/native/cocos/editor-support/spine/Slot.h index 277eec1effb..71ac6ac75ce 100644 --- a/native/cocos/editor-support/spine/Slot.h +++ b/native/cocos/editor-support/spine/Slot.h @@ -106,7 +106,7 @@ class SP_API Slot : public SpineObject { void setAttachmentTime(float inValue); - Vector &getDeform(); + inline Vector &getDeform() { return _deform; } private: SlotData &_data; diff --git a/native/cocos/editor-support/spine/TransformConstraint.cpp b/native/cocos/editor-support/spine/TransformConstraint.cpp index 0252768236d..dc68ac0e1ef 100644 --- a/native/cocos/editor-support/spine/TransformConstraint.cpp +++ b/native/cocos/editor-support/spine/TransformConstraint.cpp @@ -89,10 +89,6 @@ TransformConstraintData &TransformConstraint::getData() { return _data; } -Vector &TransformConstraint::getBones() { - return _bones; -} - Bone *TransformConstraint::getTarget() { return _target; } diff --git a/native/cocos/editor-support/spine/TransformConstraint.h b/native/cocos/editor-support/spine/TransformConstraint.h index f00cfd9dd5a..8af3b3fb6e7 100644 --- a/native/cocos/editor-support/spine/TransformConstraint.h +++ b/native/cocos/editor-support/spine/TransformConstraint.h @@ -56,7 +56,7 @@ class SP_API TransformConstraint : public Updatable { TransformConstraintData& getData(); - Vector& getBones(); + inline Vector& getBones() { return _bones; } Bone* getTarget(); void setTarget(Bone* inValue); diff --git a/native/cocos/editor-support/spine/TransformConstraintData.cpp b/native/cocos/editor-support/spine/TransformConstraintData.cpp index 845204a2dc5..ae8ca3734c5 100644 --- a/native/cocos/editor-support/spine/TransformConstraintData.cpp +++ b/native/cocos/editor-support/spine/TransformConstraintData.cpp @@ -57,10 +57,6 @@ TransformConstraintData::TransformConstraintData(const String &name) : Constrain _local(false) { } -Vector &TransformConstraintData::getBones() { - return _bones; -} - BoneData *TransformConstraintData::getTarget() { return _target; } @@ -105,10 +101,3 @@ float TransformConstraintData::getOffsetShearY() { return _offsetShearY; } -bool TransformConstraintData::isRelative() { - return _relative; -} - -bool TransformConstraintData::isLocal() { - return _local; -} diff --git a/native/cocos/editor-support/spine/TransformConstraintData.h b/native/cocos/editor-support/spine/TransformConstraintData.h index 93f577f350a..32fc76b1ebe 100644 --- a/native/cocos/editor-support/spine/TransformConstraintData.h +++ b/native/cocos/editor-support/spine/TransformConstraintData.h @@ -50,7 +50,7 @@ class SP_API TransformConstraintData : public ConstraintData { public: explicit TransformConstraintData(const String& name); - Vector& getBones(); + inline Vector& getBones() { return _bones; } BoneData* getTarget(); float getRotateMix(); float getTranslateMix(); @@ -64,8 +64,8 @@ class SP_API TransformConstraintData : public ConstraintData { float getOffsetScaleY(); float getOffsetShearY(); - bool isRelative(); - bool isLocal(); + inline bool isRelative() const { return _relative; } + inline bool isLocal() const { return _local; } private: Vector _bones; From 66b3e15b4bb402a444868c927d23e3d4be217c53 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 17:46:36 +0800 Subject: [PATCH 70/80] Update CMakeLists.txt --- .../editor-support/spine-wasm/CMakeLists.txt | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index b8d215c034d..a674ea119b6 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -1,11 +1,18 @@ cmake_minimum_required(VERSION 3.8) -set(CMAKE_VERBOSE_MAKEFILE ON) +set(APP_NAME "spine") + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +project(${APP_NAME}_wasm) set(BUILD_WASM 1) set(ENABLE_JSON_PARSER 1) set(ENABLE_BINARY_PARSER 1) # set(ENABLE_PROFILING "--profiling") +set(VERBOSE_LOG 0) set(CMAKE_BUILD_TYPE "MinSizeRel") # set(CMAKE_BUILD_TYPE "RelWithDebInfo") @@ -13,20 +20,14 @@ set(CMAKE_BUILD_TYPE "MinSizeRel") if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(ENABLE_CLOSURE_COMPILER 0) + set(SPINE_EXTRA_FLAGS "") else() - set(ENABLE_CLOSURE_COMPILER 1) - set(EXTRA_FLAGS "-Oz") + set(ENABLE_CLOSURE_COMPILER 0) + set(SPINE_EXTRA_FLAGS "-Oz") endif() -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -set(APP_NAME "spine" CACHE STRING "Project Name") -project(${APP_NAME}_wasm) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override ${ENABLE_PROFILING} \ +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SPINE_EXTRA_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SPINE_EXTRA_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override ${ENABLE_PROFILING} \ -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") message(">>> --------------------------------------------------------------") @@ -36,7 +37,16 @@ message(">>> ENABLE_CLOSURE_COMPILER: ${ENABLE_CLOSURE_COMPILER}") message(">>> ENABLE_JSON_PARSER: ${ENABLE_JSON_PARSER}") message(">>> ENABLE_BINARY_PARSER: ${ENABLE_BINARY_PARSER}") message(">>> ENABLE_PROFILING: ${ENABLE_PROFILING}") -message(">>> EXTRA_FLAGS: ${EXTRA_FLAGS}") +message(">>> EXTRA_FLAGS: ${SPINE_EXTRA_FLAGS}") +message(">>> --------------------------------------------------------------") +message(">>> CMAKE_C_COMPILER_VERSION is ${CMAKE_C_COMPILER_VERSION}") +message(">>> CMAKE_CXX_COMPILER_VERSION is ${CMAKE_CXX_COMPILER_VERSION}") +message(">>> CMAKE_C_COMPILER_TARGET is ${CMAKE_C_COMPILER_TARGET}") +message(">>> CMAKE_CXX_COMPILER_TARGET is ${CMAKE_CXX_COMPILER_TARGET}") +message(">>> CMAKE_C_PLATFORM_ID is ${CMAKE_C_PLATFORM_ID}") +message(">>> CMAKE_CXX_PLATFORM_ID is ${CMAKE_CXX_PLATFORM_ID}") +message(">>> CMAKE_C_COMPILE_FEATURES is ${CMAKE_C_COMPILE_FEATURES}") +message(">>> CMAKE_CXX_COMPILE_FEATURES is ${CMAKE_CXX_COMPILE_FEATURES}") message(">>> --------------------------------------------------------------") include_directories(${CMAKE_CURRENT_LIST_DIR}/..) @@ -46,7 +56,7 @@ file(GLOB COCOS_ADAPTER_SRC "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC}) # -s EMBIND_AOT=0 -s MALLOC=emmalloc -set(EMS_LINK_FLAGS "${EXTRA_FLAGS} -s VERBOSE=0 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ +set(EMS_LINK_FLAGS "${SPINE_EXTRA_FLAGS} -s EVAL_CTORS=1 -s VERBOSE=${VERBOSE_LOG} -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ -s MIN_SAFARI_VERSION=110000 \ From b149905cef91ea6283e06c0875e4948287b683cf Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 31 Oct 2024 17:46:56 +0800 Subject: [PATCH 71/80] revert --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index a674ea119b6..7178de19cbe 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -22,7 +22,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(ENABLE_CLOSURE_COMPILER 0) set(SPINE_EXTRA_FLAGS "") else() - set(ENABLE_CLOSURE_COMPILER 0) + set(ENABLE_CLOSURE_COMPILER 1) set(SPINE_EXTRA_FLAGS "-Oz") endif() From 78e14354a912053a55a91f296576ce8d73930837 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 1 Nov 2024 09:50:12 +0800 Subject: [PATCH 72/80] Optimize Vector --- .../spine-wasm/spine-skeleton-instance.cpp | 9 +++------ .../editor-support/spine-wasm/spine-skeleton-instance.h | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index 56ca0f311e8..ed4bc3a85e8 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -353,13 +353,14 @@ void SpineSkeletonInstance::collectMeshData() { SpineMeshData::moveIB(currMesh.iCount); // record debug shape info if (_userData.debugMode) { - SpineDebugShape debugShape; + size_t currentShapesLen = _debugShapes.size(); + _debugShapes.setSize(currentShapesLen + 1, {}); + SpineDebugShape& debugShape = _debugShapes[currentShapesLen]; debugShape.type = static_cast(debugShapeType); debugShape.vOffset = _model->vCount; debugShape.vCount = currMesh.vCount; debugShape.iOffset = _model->iCount; debugShape.iCount = currMesh.iCount; - _debugShapes.add(debugShape); } currMesh.blendMode = static_cast(slot->getData().getBlendMode()); @@ -442,10 +443,6 @@ void SpineSkeletonInstance::onAnimationStateEvent(TrackEntry *entry, EventType t } } -Vector &SpineSkeletonInstance::getDebugShapes() { - return this->_debugShapes; -} - void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint32_t width, uint32_t height, bool createNew) { if (!_skeleton) return; auto* slot = _skeleton->findSlot(slotName); diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index 2de5258bd22..2743a0e799f 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -52,7 +52,7 @@ class SpineSkeletonInstance { void setTrackEntryListener(uint32_t trackId, spine::TrackEntry *entry); void onAnimationStateEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); void onTrackEntryEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); - spine::Vector &getDebugShapes(); + inline spine::Vector &getDebugShapes() { return _debugShapes; } void resizeSlotRegion(const spine::String &slotName, uint32_t width, uint32_t height, bool createNew = false); void setSlotTexture(const spine::String &slotName, uint32_t index); void destroy(); From 5c94b34c0a606663ce2cfd574c280fb78b400a62 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 1 Nov 2024 09:52:03 +0800 Subject: [PATCH 73/80] Add MathUtil::ipow which is depended by Json.cpp. --- native/cocos/editor-support/spine/Json.cpp | 11 ++++++----- native/cocos/editor-support/spine/MathUtil.cpp | 14 ++++++++++++++ native/cocos/editor-support/spine/MathUtil.h | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/native/cocos/editor-support/spine/Json.cpp b/native/cocos/editor-support/spine/Json.cpp index 752c3888321..0eb3ad41d8c 100644 --- a/native/cocos/editor-support/spine/Json.cpp +++ b/native/cocos/editor-support/spine/Json.cpp @@ -41,6 +41,7 @@ THE SOFTWARE. #include #include #include +#include #include #include @@ -393,7 +394,7 @@ const char *Json::parseNumber(Json *item, const char *num) { ++ptr; ++n; } - result += fraction / pow(10.0, n); + result += fraction / MathUtil::ipow(10, n); } if (negative) { @@ -401,7 +402,7 @@ const char *Json::parseNumber(Json *item, const char *num) { } if (*ptr == 'e' || *ptr == 'E') { - double exponent = 0; + uint32_t exponent = 0; int expNegative = 0; int n = 0; ++ptr; @@ -414,15 +415,15 @@ const char *Json::parseNumber(Json *item, const char *num) { } while (*ptr >= '0' && *ptr <= '9') { - exponent = (exponent * 10.0) + (*ptr - '0'); + exponent = (exponent * 10) + (*ptr - '0'); ++ptr; ++n; } if (expNegative) { - result = result / pow(10, exponent); + result = result / MathUtil::ipow(10, exponent); } else { - result = result * pow(10, exponent); + result = result * MathUtil::ipow(10, exponent); } } diff --git a/native/cocos/editor-support/spine/MathUtil.cpp b/native/cocos/editor-support/spine/MathUtil.cpp index 25c2a9d94e7..6fb1b39604d 100644 --- a/native/cocos/editor-support/spine/MathUtil.cpp +++ b/native/cocos/editor-support/spine/MathUtil.cpp @@ -71,3 +71,17 @@ float MathUtil::randomTriangular(float min, float max, float mode) { if (u <= (mode - min) / d) return min + sqrt(u * d * (mode - min)); return max - sqrt((1 - u) * d * (max - mode)); } + +uint64_t MathUtil::ipow(uint64_t base, uint32_t exp) { + uint64_t result = 1; + + while (exp) { + if (exp & 1) { + result *= base; + } + exp >>= 1; + base *= base; + } + + return result; +} \ No newline at end of file diff --git a/native/cocos/editor-support/spine/MathUtil.h b/native/cocos/editor-support/spine/MathUtil.h index 8526d859fb6..2f32c23f349 100644 --- a/native/cocos/editor-support/spine/MathUtil.h +++ b/native/cocos/editor-support/spine/MathUtil.h @@ -113,6 +113,8 @@ class SP_API MathUtil { static inline float pow(float a, float b) { return (float)::pow(a, b); } + + static uint64_t ipow(uint64_t base, uint32_t exp); }; struct SP_API Interpolation { From 01fdec95644dec3aa4390b84661c7619ed04a1ed Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 1 Nov 2024 10:13:32 +0800 Subject: [PATCH 74/80] Fix asmjs build --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index 7178de19cbe..fb6a270d7f8 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -26,6 +26,12 @@ else() set(SPINE_EXTRA_FLAGS "-Oz") endif() +if(BUILD_WASM EQUAL 1) + set(EVAL_CTOR_FLAG "-s EVAL_CTORS=1") +else() + set(EVAL_CTOR_FLAG "") # asmjs doesn't support EVAL_CTORS +endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SPINE_EXTRA_FLAGS} -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SPINE_EXTRA_FLAGS} -fno-exceptions -fno-rtti -Wno-inconsistent-missing-override ${ENABLE_PROFILING} \ -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DENABLE_JSON_PARSER=${ENABLE_JSON_PARSER} -DENABLE_BINARY_PARSER=${ENABLE_BINARY_PARSER}") @@ -37,7 +43,8 @@ message(">>> ENABLE_CLOSURE_COMPILER: ${ENABLE_CLOSURE_COMPILER}") message(">>> ENABLE_JSON_PARSER: ${ENABLE_JSON_PARSER}") message(">>> ENABLE_BINARY_PARSER: ${ENABLE_BINARY_PARSER}") message(">>> ENABLE_PROFILING: ${ENABLE_PROFILING}") -message(">>> EXTRA_FLAGS: ${SPINE_EXTRA_FLAGS}") +message(">>> SPINE_EXTRA_FLAGS: ${SPINE_EXTRA_FLAGS}") +message(">>> EVAL_CTOR_FLAG: ${EVAL_CTOR_FLAG}") message(">>> --------------------------------------------------------------") message(">>> CMAKE_C_COMPILER_VERSION is ${CMAKE_C_COMPILER_VERSION}") message(">>> CMAKE_CXX_COMPILER_VERSION is ${CMAKE_CXX_COMPILER_VERSION}") @@ -56,7 +63,7 @@ file(GLOB COCOS_ADAPTER_SRC "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC}) # -s EMBIND_AOT=0 -s MALLOC=emmalloc -set(EMS_LINK_FLAGS "${SPINE_EXTRA_FLAGS} -s EVAL_CTORS=1 -s VERBOSE=${VERBOSE_LOG} -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ +set(EMS_LINK_FLAGS "${SPINE_EXTRA_FLAGS} ${EVAL_CTOR_FLAG} -s VERBOSE=${VERBOSE_LOG} -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ -s MIN_SAFARI_VERSION=110000 \ From 2aed5fa4a776e1e3b363a4483cd5c6a5ae637d4a Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 1 Nov 2024 10:44:47 +0800 Subject: [PATCH 75/80] Fix missing #include --- native/cocos/editor-support/spine/MathUtil.h | 1 + 1 file changed, 1 insertion(+) diff --git a/native/cocos/editor-support/spine/MathUtil.h b/native/cocos/editor-support/spine/MathUtil.h index 2f32c23f349..312c9401c76 100644 --- a/native/cocos/editor-support/spine/MathUtil.h +++ b/native/cocos/editor-support/spine/MathUtil.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace spine { From 564d356806aa4414388306bf8e1e57d966ae3de3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 1 Nov 2024 11:08:50 +0800 Subject: [PATCH 76/80] Update CMakeLists.txt --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index fb6a270d7f8..578c32a5c10 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -26,7 +26,7 @@ else() set(SPINE_EXTRA_FLAGS "-Oz") endif() -if(BUILD_WASM EQUAL 1) +if(BUILD_WASM EQUAL 1 AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug") set(EVAL_CTOR_FLAG "-s EVAL_CTORS=1") else() set(EVAL_CTOR_FLAG "") # asmjs doesn't support EVAL_CTORS From 1bcd9147603d36cdffa3384982682dc9576cc1db Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 1 Nov 2024 14:27:08 +0800 Subject: [PATCH 77/80] Update Extension.cpp --- native/cocos/editor-support/spine/Extension.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/native/cocos/editor-support/spine/Extension.cpp b/native/cocos/editor-support/spine/Extension.cpp index 0b3cd797567..53555d65c8d 100644 --- a/native/cocos/editor-support/spine/Extension.cpp +++ b/native/cocos/editor-support/spine/Extension.cpp @@ -112,9 +112,6 @@ void DefaultSpineExtension::_free(void *mem, const char *file, int line) { } char *DefaultSpineExtension::_readFile(const String &path, int *length) { -#ifdef __EMSCRIPTEN__ - return nullptr; -#else char *data; FILE *file = fopen(path.buffer(), "rb"); if (!file) return 0; @@ -128,7 +125,6 @@ char *DefaultSpineExtension::_readFile(const String &path, int *length) { fclose(file); return data; -#endif } DefaultSpineExtension::DefaultSpineExtension() : SpineExtension() { From c6439cc574fdabbc27ce5031317fefcb68f29601 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 5 Nov 2024 10:51:48 +0800 Subject: [PATCH 78/80] Revert wasmSpineExtension.cpp, return nullptr if size is zero. --- .../editor-support/spine-wasm/wasmSpineExtension.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp index 0c2c78b83b9..068716e354b 100644 --- a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp +++ b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp @@ -30,18 +30,27 @@ char *WasmSpineExtension::_readFile(const String &path, int *length) { void *WasmSpineExtension::_alloc(size_t size, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); + if (size == 0) { + return nullptr; + } return ::malloc(sizeof(uint8_t) * size); } void *WasmSpineExtension::_calloc(size_t size, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); + if (size == 0) { + return nullptr; + } return ::calloc(1, size); } void *WasmSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); + if (size == 0) { + return nullptr; + } return ::realloc(ptr, sizeof(uint8_t) * size); } From 492ae954acd480860ebd531703787ace3a0a95f7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 5 Nov 2024 15:44:38 +0800 Subject: [PATCH 79/80] Fix memory leak in _realloc if size is zero. --- native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp index 068716e354b..31bbeb5d386 100644 --- a/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp +++ b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp @@ -49,6 +49,8 @@ void *WasmSpineExtension::_realloc(void *ptr, size_t size, const char *file, int SP_UNUSED(file); SP_UNUSED(line); if (size == 0) { + // Need to free the old memory before returning nullptr, otherwise the old memory block will be leaked. + ::free(ptr); return nullptr; } return ::realloc(ptr, sizeof(uint8_t) * size); From bd05c2b5f3d4512aa5b0f3864a23851fa2b91b23 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 5 Nov 2024 16:42:08 +0800 Subject: [PATCH 80/80] Update external --- native/external-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/external-config.json b/native/external-config.json index e04dab5e6c6..00d984fac5a 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.5-7" + "checkout": "v3.8.5-8" } } \ No newline at end of file