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/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/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..3f4d39d8db5 100644 --- a/.github/workflows/web-interface-check.yml +++ b/.github/workflows/web-interface-check.yml @@ -67,12 +67,90 @@ 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: 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 + + - 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 ./engine-HEAD/native/cocos/editor-support/spine-wasm + mkdir build-wasm + cd build-wasm + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Build Spine ASMJS + run: | + 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 + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Copy files to external directory + run: | + mkdir dist + 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 ./engine-HEAD/native/external/emscripten/spine/ + cp -f ./dist/* ./engine-HEAD/native/external/emscripten/spine/ + echo "-------- After replace spine wasm ------------" + ls -l ./engine-HEAD/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: | 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/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); diff --git a/cocos/spine/lib/spine-define.ts b/cocos/spine/lib/spine-define.ts index afcafb3e0d8..b84e7b8fe8a 100644 --- a/cocos/spine/lib/spine-define.ts +++ b/cocos/spine/lib/spine-define.ts @@ -87,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; @@ -114,147 +100,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_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 = [ - ['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_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], - ]; - 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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} - 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; @@ -270,28 +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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); + overrideDefineArrayProp(prototype, prototype.getRegionUVs, 'regionUVs'); overrideDefineArrayProp(prototype, prototype.getUVs, 'uvs'); overrideDefineArrayProp(prototype, prototype.getTriangles, 'triangles'); @@ -300,45 +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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} - 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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); overrideDefineArrayProp(prototype, prototype.getOffset, 'offset'); const getUVs = prototype.getUVs; @@ -372,173 +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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} - 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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); 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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); 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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); 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]); - }); 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'); @@ -580,36 +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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getSlots, 'slots'); @@ -623,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'); } @@ -689,87 +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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); -} - -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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); - 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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); 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], - ]; - propertyPolyfills.forEach((prop): void => { - js.getset(prototype, prop[0], prop[1], prop[2]); - }); overrideDefineArrayProp(prototype, prototype.getBones, 'bones'); overrideDefineArrayProp(prototype, prototype.getSlots, 'slots'); @@ -780,49 +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_Vector2(); - 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(); @@ -830,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(); } diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 9e2eede6c15..e16e6972785 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -926,7 +926,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; 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/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-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 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/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/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index b1ba7deff18..578c32a5c10 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -1,17 +1,60 @@ cmake_minimum_required(VERSION 3.8) -set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_BUILD_TYPE "MinSizeRel") +set(APP_NAME "spine") + +set(CMAKE_CXX_STANDARD 17) +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(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") +# set(CMAKE_BUILD_TYPE "Debug") + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(ENABLE_CLOSURE_COMPILER 0) + set(SPINE_EXTRA_FLAGS "") +else() + set(ENABLE_CLOSURE_COMPILER 1) + set(SPINE_EXTRA_FLAGS "-Oz") +endif() + +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 +endif() -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_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("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(">>> ENABLE_JSON_PARSER: ${ENABLE_JSON_PARSER}") +message(">>> ENABLE_BINARY_PARSER: ${ENABLE_BINARY_PARSER}") +message(">>> ENABLE_PROFILING: ${ENABLE_PROFILING}") +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}") +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}/..) file(GLOB SPINE_CORE_SRC "${CMAKE_CURRENT_LIST_DIR}/../spine/*.cpp") @@ -19,14 +62,15 @@ 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 \ - -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-args=--externs=../library_spine_externs.js") +# -s EMBIND_AOT=0 -s MALLOC=emmalloc +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 \ + -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 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 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/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 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-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-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.cpp b/native/cocos/editor-support/spine-wasm/spine-model.cpp index b191eca7968..e44fc15a492 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.setSize(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[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->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.setSize(count + 6, 0); + _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,13 @@ void SpineModel::addSlotMesh(SlotMesh& mesh, bool needMerge) { } void SpineModel::clearMeshes() { - data->resize(0); + _data.setSize(0, 0); vCount = 0; iCount = 0; } -std::vector* SpineModel::getData() { - return data; +spine::Vector* SpineModel::getData() { + 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 bb278bc856d..6921fd592e9 100644 --- a/native/cocos/editor-support/spine-wasm/spine-model.h +++ b/native/cocos/editor-support/spine-wasm/spine-model.h @@ -1,13 +1,9 @@ -#ifndef __SPINE_MODEL_H__ -#define __SPINE_MODEL_H__ -#include -#include -#include "mesh-type-define.h" +#pragma once -using namespace spine; +#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() {} @@ -18,12 +14,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 { @@ -33,15 +29,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(); - + + spine::Vector* getData(); +private: + spine::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{}; }; - -#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..ed4bc3a85e8 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(); } @@ -133,9 +131,9 @@ 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() == false) { + if (!bone.isActive()) { continue; } @@ -355,20 +353,20 @@ 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.push_back(debugShape); } 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]; } } _model->addSlotMesh(currMesh); @@ -406,8 +404,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) { @@ -445,22 +443,18 @@ void SpineSkeletonInstance::onAnimationStateEvent(TrackEntry *entry, EventType t } } -std::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(); + 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); @@ -469,19 +463,19 @@ void SpineSkeletonInstance::resizeSlotRegion(const std::string &slotName, uint32 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); @@ -495,13 +489,13 @@ void SpineSkeletonInstance::resizeSlotRegion(const std::string &slotName, uint32 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]; @@ -509,15 +503,11 @@ 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; - 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 735f4e5ea06..2743a0e799f 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 #include "mesh-type-define.h" #include "spine-model.h" -using namespace spine; - enum DEBUG_SHAPE_TYPE { DEBUG_REGION = 0, @@ -36,27 +34,27 @@ class SpineSkeletonInstance { public: SpineSkeletonInstance(); ~SpineSkeletonInstance(); - Skeleton *initSkeleton(SkeletonData *data); - TrackEntry *setAnimation(float trackIndex, const std::string &name, bool loop); - void setSkin(const std::string &name); + spine::Skeleton *initSkeleton(spine::SkeletonData *data); + 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); 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(); - void setMix(const std::string &from, const std::string &to, float duration); + spine::AnimationState *getAnimationState(); + 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, TrackEntry *entry); - void onAnimationStateEvent(TrackEntry *entry, EventType type, Event *event); - void onTrackEntryEvent(TrackEntry *entry, EventType type, 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); + 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); + 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(); bool isCache{false}; bool enable{true}; @@ -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{}; + spine::Vector _debugShapes{}; + spine::HashMap _slotTextureSet{}; }; - -#endif \ No newline at end of file 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..ac34fbc3f01 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1,70 +1,17 @@ #include +#include +#include #include -#include #include "spine-skeleton-instance.h" #include "spine-wasm.h" #include "Vector2.h" -using namespace emscripten; using namespace spine; -namespace { -std::string STRING_SP2STD(const spine::String &str) { - std::string stdStr(str.buffer(), str.length()); - return stdStr; -} - -const spine::String STRING_STD2SP(const std::string &str) { - const spine::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 = Vector(); - 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 SPVectorUint = Vector; using SPVectorVectorInt = Vector>; using SPVectorSize_t = Vector; using SPVectorBonePtr = Vector; @@ -73,10 +20,12 @@ 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 SPVectorEventDataPtr = Vector; +using SPVectorEventPtr = Vector; using SPVectorAnimationPtr = Vector; using SPVectorIkConstraintPtr = Vector; using SPVectorIkConstraintDataPtr = Vector; @@ -85,20 +34,467 @@ 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<> \ + struct TypeID { \ + static constexpr TYPEID get() { \ + return TypeID::get(); \ + } \ + }; \ + template<> \ + struct TypeID { \ + static constexpr 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 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) +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) + + +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(AnimationStateData) +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 { -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 +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; + T& (VecType::*get)(size_t) = &VecType::operator[]; + return emscripten::class_>(name) + .template constructor<>() + .function("resize", setSize) + .function("size", size) + .function("get", get, emscripten::allow_raw_pointers()); + } +}; + +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; + T& (VecType::*get)(size_t) = &VecType::operator[]; + return emscripten::class_>(name) + .template constructor<>() + .function("resize", setSize) + .function("size", size) + .function("get", get) + .function("set", emscripten::optional_override([](VecType& obj, int index, const T& value){ + obj[index] = value; + }), emscripten::allow_raw_pointers()); + } +}; + +#define REGISTER_SPINE_VECTOR(name, needSetter) \ + SpineVectorTrait::register_spine_vector(#name) + } // namespace +namespace emscripten { namespace internal { + +template +struct GetterPolicy { + using ReturnType = GetterReturnType; + using Context = GetterReturnType (GetterThisType::*)(); + + using Binding = internal::BindingType; + using WireType = typename Binding::WireType; + + // template + template + static WireType get(const Context& context, ClassType& ptr) { + // return Binding::toWireType(((ptr.*context)()), ReturnPolicy{}); + return Binding::toWireType(((ptr.*context)())); + } + + static void* getContext(Context context) { + return internal::getContext(context); + } +}; + +// 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; + 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 + +#define ENABLE_EMBIND_TEST 0 + +#if ENABLE_EMBIND_TEST + +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); + } + + TestFoo(const TestFoo& o) { + printf("TestFoo copy constructor %p, %p, o.x=%d\n", this, &o, o._x); + *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; + printf("TestFoo::operator=, _x=%d\n", _x); + } else { + printf("TestFoo::operator=, same address\n"); + } + return *this; + } + + virtual void hello(const String& msg) override { + printf("TestFoo::hello: %s\n", msg.buffer()); + } + + void setX(int x) { + _x = x; + } + 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) +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); + } + + 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; + } + + const TestFoo* getFoo() const { + return _foo; + } + + void setFoo(TestFoo *foo) { + if (_foo != foo) { + delete _foo; + _foo = foo; + } + } + + const TestBase* getBase() const { + return _foo; + } + + const TestFoo& getFooConst() { + return *_foo; + } + + void setFooConst(const TestFoo& foo) { + _foo = &foo; + } + + Vector getNames() { + Vector ret; + ret.add(String("你好")); + ret.add(String("World")); + return ret; + } + +private: + const TestFoo *_foo = new TestFoo(); +}; + +RTTI_IMPL_NOPARENT(TestBar) + + +#endif // ENABLE_EMBIND_TEST + + EMSCRIPTEN_BINDINGS(spine) { + using namespace emscripten; + using namespace emscripten::internal; + +#if ENABLE_EMBIND_TEST + class_("TestBase") + .constructor() + .function("hello", &TestBase::hello); + + class_>("TestFoo") + .constructor() + .property("x", &TestFoo::getX, &TestFoo::setX) + .class_function("apply1", select_overload(&TestFoo::apply)) + .class_function("apply2", select_overload &, bool)>(&TestFoo::apply)) + ; + + class_("TestBar") + .constructor() + .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) + ; + + 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"); + REGISTER_SPINE_ENUM(TimelineType); REGISTER_SPINE_ENUM(MixDirection); REGISTER_SPINE_ENUM(MixBlend); @@ -112,232 +508,53 @@ 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_("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(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); + + REGISTER_SPINE_VECTOR(SPVectorSPString, 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(SPVectorSkinEntryPtr, false); + REGISTER_SPINE_VECTOR(SPVectorVectorSkinEntryPtr, false); 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); - 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() - .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) @@ -347,60 +564,45 @@ 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() - .function("getName", optional_override([](ConstraintData &obj) { return STRING_SP2STD(obj.getName()); })) - .function("getOrder", &ConstraintData::getOrder) - .function("setOrder", &ConstraintData::setOrder) - .function("getSkinRequired", &ConstraintData::isSkinRequired) - .function("setSkinRequired", &ConstraintData::setSkinRequired); + .property("name", &ConstraintData::getName) + .property("order", &ConstraintData::_order) + .property("skinRequired", &ConstraintData::_skinRequired); class_>("IkConstraintData") .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()) - .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("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()) - .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::_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<>() @@ -410,109 +612,76 @@ 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); 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", 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("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::_intValue) + .property("floatValue", &Event::_floatValue) + .property("stringValue", &Event::_stringValue) + .property("time", &Event::_time) + .property("volume", &Event::_volume) + .property("balance", &Event::_balance); class_("EventData") .constructor() - .function("getName", optional_override([](EventData &obj) { - return STRING_SP2STD(obj.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("getVolume", &EventData::getVolume) - .function("setVolume", &EventData::setVolume) - .function("getBalance", &EventData::getBalance) - .function("setBalance", &EventData::setBalance); + .property("name", &EventData::getName) + .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") - //.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::_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()); class_>("BoundingBoxAttachment") .constructor() - .function("getName", optional_override([](BoundingBoxAttachment &obj) { - return STRING_SP2STD(obj.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", 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); })) + .property("path", &MeshAttachment::_path) .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::_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) @@ -525,20 +694,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::_closed) + .property("constantSpeed", &PathAttachment::_constantSpeed) .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::_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) @@ -546,28 +710,16 @@ 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", 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()) + .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::_path) + //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) @@ -598,8 +750,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) @@ -610,8 +761,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) @@ -619,185 +769,121 @@ 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) { - return obj.findRegion(STRING_STD2SP(name)); }), allow_raw_pointers()); + .function("findRegion", &Atlas::findRegion, allow_raw_pointers()); class_>("Pow") - .constructor() - .function("apply", &PowInterpolation::apply); + .constructor(); + class_>("PowOut") - .constructor() - .function("apply", &PowInterpolation::apply); + .constructor(); class_("SlotData") .constructor() - .function("getIndex", &SlotData::getIndex) - .function("getName", optional_override([](SlotData &obj) { - return STRING_SP2STD(obj.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::_blendMode); 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() - .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) - .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, - 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); - })); + .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)) + ; 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) - .function("isActive", &PathConstraint::isActive) - .function("setActive", &PathConstraint::setActive) - .function("apply", &PathConstraint::apply) - .function("update", &PathConstraint::update); + .property("target", &PathConstraint::_target) + .property("position", &PathConstraint::_position) + .property("spacing", &PathConstraint::_spacing) + .property("rotateMix", &PathConstraint::_rotateMix) + .property("translateMix", &PathConstraint::_translateMix) + ; 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) - .function("isActive", &TransformConstraint::isActive) - .function("apply", &TransformConstraint::apply) - .function("update", &TransformConstraint::update); + .property("target", &TransformConstraint::getTarget) + .property("rotateMix", &TransformConstraint::_rotateMix) + .property("translateMix", &TransformConstraint::_translateMix) + .property("scaleMix", &TransformConstraint::_scaleMix) + .property("shearMix", &TransformConstraint::_shearMix) + ; 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()) - .function("getParent", optional_override([](Bone &obj) { - return obj.getParent(); }), allow_raw_pointers()) + .property("data", GETTER_RVAL_TO_PTR(Bone, getData, BoneData*)) + .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()) - .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) - .function("getActive", &Bone::isActive) - .function("setActive", &Bone::setActive) - .function("isActive", &Bone::isActive) - .function("update", &Bone::update) + .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)) .function("setToSetupPose", &Bone::setToSetupPose) @@ -827,43 +913,29 @@ EMSCRIPTEN_BINDINGS(spine) { class_("BoneData") .constructor() - .function("getIndex", &BoneData::getIndex) - .function("getName", optional_override([](BoneData &obj) { return STRING_SP2STD(obj.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::_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") .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()) - .function("getDeform", &Slot::getDeform, allow_raw_pointers()) - .function("getSkeleton", optional_override([](Slot &obj) { - return &obj.getSkeleton(); }), 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", 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()) .function("setAttachmentTime", &Slot::setAttachmentTime) @@ -872,49 +944,39 @@ EMSCRIPTEN_BINDINGS(spine) { class_("Skin") .constructor() - .function("getName", optional_override([](Skin &obj) { - return STRING_SP2STD(obj.getName()); })) + .property("name", &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) { - std::vector vetNames; - std::vector entriesVector; + Vector vetNames; auto entries = obj.getAttachments(); while (entries.hasNext()) { - Skin::AttachmentMap::Entry &entry = entries.next(); - if (entry._slotIndex == slotIndex) vetNames.push_back(STRING_SP2STD(entry._name)); + auto &entry = entries.next(); + if (entry._slotIndex == slotIndex) vetNames.add(entry._name); } 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; + 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", 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; + 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()); @@ -922,14 +984,14 @@ 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") .constructor<>() - .function("getClippedVertices", &SkeletonClipping::getClippedVertices) - .function("getClippedTriangles", &SkeletonClipping::getClippedTriangles) - .function("getClippedUVs", &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)) @@ -937,17 +999,14 @@ EMSCRIPTEN_BINDINGS(spine) { class_("SkeletonData") .constructor<>() - .function("getName", optional_override([](SkeletonData &obj) { - return STRING_SP2STD(obj.getName()); })) - .function("setName", &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()) - .function("getDefaultSkin", &SkeletonData::getDefaultSkin, allow_raw_pointers()) - .function("setDefaultSkin", &SkeletonData::setDefaultSkin, allow_raw_pointers()) + .property("defaultSkin", &SkeletonData::_defaultSkin) .function("getEvents", optional_override([](SkeletonData &obj) { return &obj.getEvents(); }), allow_raw_pointer()) .function("getAnimations", optional_override([](SkeletonData &obj) { @@ -958,83 +1017,48 @@ 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", optional_override([](SkeletonData &obj) { - return STRING_SP2STD(obj.getVersion()); })) - .function("setVersion", &SkeletonData::setVersion) - .function("getHash", optional_override([](SkeletonData &obj) { - return STRING_SP2STD(obj.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("setImagesPath", &SkeletonData::setImagesPath) - .function("getAudioPath", optional_override([](SkeletonData &obj) { - return STRING_SP2STD(obj.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)); })); + .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) + .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("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); + .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); })) - .function("getName", optional_override([](Animation &obj) { return STRING_SP2STD(obj.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::_duration); 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) .function("setStepped", &CurveTimeline::setStepped) @@ -1045,291 +1069,157 @@ EMSCRIPTEN_BINDINGS(spine) { class_>("TranslateTimeline") .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()); + ; 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()); + ; class_>("RotateTimeline") .constructor() //.class_property("ENTRIES", &RotateTimeline::ENTRIES) not bind - .function("getBoneIndex", &RotateTimeline::getBoneIndex) - .function("setBoneIndex", &RotateTimeline::setBoneIndex) - .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()); + .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) - .function("getSlotIndex", &ColorTimeline::getSlotIndex) - .function("setSlotIndex", &ColorTimeline::setSlotIndex) - .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()); + .property("slotIndex", &ColorTimeline::_slotIndex) + + .function("getFrames", GETTER_RVAL_TO_PTR(ColorTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) + .function("setFrame", &ColorTimeline::setFrame); class_>("TwoColorTimeline") .constructor() .class_property("ENTRIES", &ColorTimeline::ENTRIES) - .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()); + .property("slotIndex", &TwoColorTimeline::getSlotIndex, &TwoColorTimeline::setSlotIndex) + .function("setFrame", &TwoColorTimeline::setFrame); class_>("AttachmentTimeline") .constructor() - .function("getSlotIndex", &AttachmentTimeline::getSlotIndex) - .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("getPropertyId", &AttachmentTimeline::getPropertyId) + .property("slotIndex", &AttachmentTimeline::_slotIndex) + .function("getFrames", GETTER_RVAL_TO_PTR(AttachmentTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) + .function("getAttachmentNames", &AttachmentTimeline::getAttachmentNames) .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("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()); + .function("setFrame", &AttachmentTimeline::setFrame, allow_raw_pointers()); 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()) - .function("getFrames", optional_override([](DeformTimeline &obj) { - return &obj.getFrames(); }), allow_raw_pointer()) + .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()) - .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); - }), 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); + .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()); 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) + return &obj.getEvents(); }), allow_raw_pointer()) .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() - .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()) - .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()); + ; 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) - //.function("getProp_nextAnimationLast", &TrackEntry::nextAnimationLast) - .function("getDelay", &TrackEntry::getDelay) - .function("setDelay", &TrackEntry::setDelay) - .function("getTrackTime", &TrackEntry::getTrackTime) - .function("setTrackTime", &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) - //.function("getProp_interruptAlpha", &TrackEntry::_interruptAlpha) - //.function("getProp_totalAlpha", &TrackEntry::getAlpha) - .function("getMixBlend", &TrackEntry::getMixBlend) - .function("setMixBlend", &TrackEntry::setMixBlend) - //.function("getProp_timelineMode", &TrackEntry::timelineMode) - //.function("getProp_timelineHoldMix", &TrackEntry::timelineHoldMix) - //.function("getProp_timelinesRotation", &TrackEntry::timelinesRotation) - //.function("reset", &TrackEntry::reset) //private + .property("trackIndex", &TrackEntry::getTrackIndex) + .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) + .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() - .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()) + .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()) .function("getMix", &AnimationStateData::getMix, allow_raw_pointers()); 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) .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) .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) @@ -1358,7 +1248,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){ @@ -1373,45 +1263,32 @@ 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("skin", &Skeleton::getSkin) + .property("color", GETTER_RVAL_TO_PTR(Skeleton, getColor, Color*)) + .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) .function("setToSetupPose", &Skeleton::setToSetupPose) .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); @@ -1421,7 +1298,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") @@ -1438,10 +1315,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::_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()) @@ -1453,32 +1328,20 @@ 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); - - class_("SlotMesh") - .property("vCount", &SlotMesh::vCount) - .property("iCount", &SlotMesh::iCount) - .property("blendMode", &SlotMesh::blendMode) - .property("textureID", &SlotMesh::textureID); - - register_vector("VectorSlotMesh"); + + .property("centerX", &SwirlVertexEffect::_centerX) + .property("centerY", &SwirlVertexEffect::_centerY) + .property("radius", &SwirlVertexEffect::_radius) + .property("angle", &SwirlVertexEffect::getAngle, &SwirlVertexEffect::setAngle) + .property("worldX", &SwirlVertexEffect::_worldX) + .property("worldY", &SwirlVertexEffect::_worldY); + class_("SpineModel") .property("vCount", &SpineModel::vCount) .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) @@ -1487,7 +1350,6 @@ EMSCRIPTEN_BINDINGS(spine) { .property("iOffset", &SpineDebugShape::iOffset) .property("iCount", &SpineDebugShape::iCount); - register_vector("VectorDebugShape"); class_("SkeletonInstance") .constructor<>() .property("isCache", &SpineSkeletonInstance::isCache) @@ -1509,13 +1371,14 @@ 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); } 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-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index 4fa26f2004b..cc486db5c5a 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -1,11 +1,14 @@ #include "spine-wasm.h" -#include #include "AtlasAttachmentLoaderExtension.h" #include "spine-mesh-data.h" #include "util-function.h" #include "wasmSpineExtension.h" -std::map skeletonDataMap{}; +using namespace spine; + +namespace { + HashMap skeletonDataMap{}; +} uint32_t SpineWasmUtil::s_listenerID = 0; EventType SpineWasmUtil::s_currentType = EventType_Event; @@ -15,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* extension = new WasmSpineExtension(); + SpineExtension::setInstance(extension); SpineMeshData::initMeshMemory(); @@ -25,60 +28,64 @@ 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) { - auto* atlas = new Atlas(altasStr.c_str(), altasStr.size(), "", nullptr, false); +SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const String& jsonStr, const String& altasStr) { +#if ENABLE_JSON_PARSER + 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 + return nullptr; +#endif } -SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize, const std::string& altasStr) { - auto* atlas = new Atlas(altasStr.c_str(), altasStr.size(), "", nullptr, false); +SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize, const String& altasStr) { +#if ENABLE_BINARY_PARSER + 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; +#else + return nullptr; +#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 993e2c97eca..655b7f743c1 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 void destroySpineSkeletonDataWithUUID(const std::string& uuid); - static void destroySpineSkeleton(Skeleton* skeleton); + 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(); - 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 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-wasm/wasmSpineExtension.cpp b/native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp index 2a9858e7670..31bbeb5d386 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; @@ -6,7 +7,7 @@ using namespace spine; // extern uint32_t jsReadFile(char* fileName, uint32_t length); // } -WasmSpineExtension::WasmSpineExtension() : DefaultSpineExtension() { +WasmSpineExtension::WasmSpineExtension() : SpineExtension() { } WasmSpineExtension::~WasmSpineExtension() { @@ -29,44 +30,34 @@ 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 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; + } + 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 0; - uint8_t *mem = new uint8_t[size]; - memcpy(mem, ptr, size); - delete[](char *) ptr; - ptr = mem; - return mem; + 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); } void WasmSpineExtension::_free(void *mem, const char *file, int line) { SP_UNUSED(file); SP_UNUSED(line); - - delete[](char *) mem; -} - -SpineExtension *spine::getDefaultExtension() { - return new WasmSpineExtension(); + ::free(mem); } 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/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 8d2e42ba1b3..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); @@ -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.cpp b/native/cocos/editor-support/spine/AnimationState.cpp index b0894424cb2..14b7871c2f7 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) { @@ -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 eddae7070a1..05ee988114b 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; @@ -374,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/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/Atlas.cpp b/native/cocos/editor-support/spine/Atlas.cpp index f26fc1d74d6..a1770642553 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( @@ -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", @@ -117,12 +113,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 +153,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 +305,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/Atlas.h b/native/cocos/editor-support/spine/Atlas.h index 83cd413f283..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(); + inline Vector &getPages() { return _pages; } private: Vector _pages; 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/Attachment.cpp b/native/cocos/editor-support/spine/Attachment.cpp index 7172b4c67b3..86367e71ea8 100644 --- a/native/cocos/editor-support/spine/Attachment.cpp +++ b/native/cocos/editor-support/spine/Attachment.cpp @@ -50,14 +50,14 @@ const String &Attachment::getName() const { return _name; } -int Attachment::getRefCount() { +int Attachment::getRefCount() const { return _refCount; } void Attachment::reference() { - _refCount++; + ++_refCount; } void Attachment::dereference() { - _refCount--; + --_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/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 951add5c324..0ed4413dc8c 100644 --- a/native/cocos/editor-support/spine/AttachmentTimeline.h +++ b/native/cocos/editor-support/spine/AttachmentTimeline.h @@ -60,11 +60,13 @@ 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__ 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..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; @@ -123,7 +124,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; @@ -175,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 (_data.getTransformMode() == 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; @@ -198,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() { @@ -310,193 +312,22 @@ Bone *Bone::getParent() { return _parent; } -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 5e3b81f4d11..08022ffbb5d 100644 --- a/native/cocos/editor-support/spine/Bone.h +++ b/native/cocos/editor-support/spine/Bone.h @@ -112,118 +112,203 @@ class SP_API Bone : public Updatable { Bone *getParent(); - Vector &getChildren(); + inline Vector &getChildren() { return _children; } /// 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; + } - bool isActive(); + void setAppliedValid(bool valid) { + _appliedValid = valid; + } - void setActive(bool inValue); + virtual bool isActive(); + + virtual void setActive(bool inValue);; private: static bool yDown; @@ -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/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/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/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 6c02f6ddf9c..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; @@ -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/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/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..731ed56ff0f 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); @@ -52,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/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); 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 c3c9110e59d..ff12953d892 100644 --- a/native/cocos/editor-support/spine/DeformTimeline.h +++ b/native/cocos/editor-support/spine/DeformTimeline.h @@ -53,12 +53,14 @@ 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); +#ifndef __EMSCRIPTEN__ private: +#endif int _slotIndex; Vector _frames; Vector > _frameVertices; 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/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/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/Extension.cpp b/native/cocos/editor-support/spine/Extension.cpp index 000e69e63ec..53555d65c8d 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() { } @@ -116,7 +120,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); @@ -125,3 +129,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 */ 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/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 5fb217a9bf8..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(); @@ -95,11 +95,13 @@ class SP_API IkConstraint : public Updatable { void setSoftness(float inValue); - bool isActive(); + virtual bool isActive(); - void setActive(bool inValue); + virtual void setActive(bool inValue);; +#ifndef __EMSCRIPTEN__ private: +#endif IkConstraintData &_data; Vector _bones; int _bendDirection; diff --git a/native/cocos/editor-support/spine/IkConstraintData.cpp b/native/cocos/editor-support/spine/IkConstraintData.cpp index 263f9df8309..b0bd1b4082e 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), @@ -47,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 3461e96585b..8787abaaa4a 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; @@ -49,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(); @@ -74,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/Json.cpp b/native/cocos/editor-support/spine/Json.cpp index 0c50d0f58cb..0eb3ad41d8c 100644 --- a/native/cocos/editor-support/spine/Json.cpp +++ b/native/cocos/editor-support/spine/Json.cpp @@ -41,9 +41,38 @@ THE SOFTWARE. #include #include #include +#include #include #include +#ifndef __EMSCRIPTEN__ +#include +#endif + +#ifdef __EMSCRIPTEN__ +static 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; @@ -132,11 +161,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 +262,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; } @@ -263,7 +292,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 +308,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. */ @@ -357,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) { @@ -365,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; @@ -378,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 30f8ae2bfc4..6fb1b39604d 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 @@ -42,14 +42,9 @@ using namespace spine; -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)); -} +RTTI_IMPL_NOPARENT(Interpolation) +RTTI_IMPL(PowInterpolation, Interpolation) +RTTI_IMPL(PowOutInterpolation, Interpolation) float MathUtil::sign(float v) { return ((v) < 0 ? -1.0f : (v) > 0 ? 1.0f @@ -60,46 +55,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)); } @@ -108,14 +65,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; @@ -123,6 +72,16 @@ float MathUtil::randomTriangular(float min, float max, float mode) { return max - sqrt((1 - u) * d * (max - mode)); } -float MathUtil::pow(float a, float b) { - return (float)::pow(a, b); -} +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 1041eb6ebca..312c9401c76 100644 --- a/native/cocos/editor-support/spine/MathUtil.h +++ b/native/cocos/editor-support/spine/MathUtil.h @@ -31,20 +31,21 @@ #define Spine_MathUtil_h #include - -#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; } @@ -56,42 +57,69 @@ class SP_API MathUtil : public SpineObject { 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 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); - static float pow(float a, float b); + 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 { + RTTI_DECL virtual float apply(float a) = 0; virtual float interpolate(float start, float end, float a) { @@ -101,7 +129,9 @@ struct SP_API Interpolation { virtual ~Interpolation(){}; }; + struct SP_API PowInterpolation : public Interpolation { + RTTI_DECL PowInterpolation(int power) : power(power) { } @@ -114,6 +144,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/MeshAttachment.cpp b/native/cocos/editor-support/spine/MeshAttachment.cpp index 9e73ede98aa..6f073f080dc 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; } @@ -249,10 +237,6 @@ void MeshAttachment::setParentMesh(MeshAttachment *inValue) { } } -Vector &MeshAttachment::getEdges() { - return _edges; -} - float MeshAttachment::getWidth() { return _width; } @@ -276,7 +260,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 +291,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/MeshAttachment.h b/native/cocos/editor-support/spine/MeshAttachment.h index 9220b768a8a..6e2bcbf21a3 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(); @@ -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(); @@ -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.cpp b/native/cocos/editor-support/spine/PathAttachment.cpp index 3bdc71945a1..a4b5a67036f 100644 --- a/native/cocos/editor-support/spine/PathAttachment.cpp +++ b/native/cocos/editor-support/spine/PathAttachment.cpp @@ -40,28 +40,8 @@ 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 = 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/PathAttachment.h b/native/cocos/editor-support/spine/PathAttachment.h index 0c968aff50c..32a6ac2ea73 100644 --- a/native/cocos/editor-support/spine/PathAttachment.h +++ b/native/cocos/editor-support/spine/PathAttachment.h @@ -43,15 +43,17 @@ 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(); +#ifndef __EMSCRIPTEN__ private: +#endif Vector _lengths; bool _closed; bool _constantSpeed; diff --git a/native/cocos/editor-support/spine/PathConstraint.cpp b/native/cocos/editor-support/spine/PathConstraint.cpp index b5aac9ea9c6..90a667d43c8 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( @@ -241,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 f8fb569b3e7..2f5e4eb5103 100644 --- a/native/cocos/editor-support/spine/PathConstraint.h +++ b/native/cocos/editor-support/spine/PathConstraint.h @@ -71,22 +71,23 @@ 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); PathConstraintData& getData(); - bool isActive(); - - void setActive(bool inValue); + virtual bool isActive(); + virtual void setActive(bool inValue);; +#ifndef __EMSCRIPTEN__ private: - static const float EPSILON; - static const int NONE; - static const int BEFORE; - static const int AFTER; +#endif + 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/PathConstraintData.cpp b/native/cocos/editor-support/spine/PathConstraintData.cpp index 607cd9a7fdb..66f37d0f96c 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), @@ -52,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 915d65b09b3..6dbf881f35a 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; @@ -55,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); @@ -84,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.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/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/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..943a5bd75f7 100644 --- a/native/cocos/editor-support/spine/RegionAttachment.cpp +++ b/native/cocos/editor-support/spine/RegionAttachment.cpp @@ -251,20 +251,12 @@ void RegionAttachment::setRegionOriginalHeight(float inValue) { _regionOriginalHeight = inValue; } -Vector &RegionAttachment::getOffset() { - return _vertexOffset; -} - -Vector &RegionAttachment::getUVs() { - return _uvs; -} - spine::Color &RegionAttachment::getColor() { return _color; } 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/RegionAttachment.h b/native/cocos/editor-support/spine/RegionAttachment.h index ae2ee479f3a..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(); @@ -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.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 fc9e4633285..79ed87007e5 100644 --- a/native/cocos/editor-support/spine/RotateTimeline.h +++ b/native/cocos/editor-support/spine/RotateTimeline.h @@ -55,9 +55,10 @@ class SP_API RotateTimeline : public CurveTimeline { int getBoneIndex(); void setBoneIndex(int inValue); - Vector& getFrames(); - + inline Vector& getFrames() { return _frames; } +#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 b2021b9ce1b..7aa575a1209 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), @@ -65,57 +69,63 @@ 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) { - bone = new (__FILE__, __LINE__) Bone(*data, *this, NULL); + auto* dataParent = data->getParent(); + if (dataParent == NULL) { + bone = spine_new Bone(*data, *this, NULL); } else { - Bone *parent = _bones[data->getParent()->getIndex()]; - bone = new (__FILE__, __LINE__) Bone(*data, *this, parent); + Bone *parent = _bones[dataParent->getIndex()]; + bone = spine_new Bone(*data, *this, parent); parent->getChildren().add(bone); } _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 = new (__FILE__, __LINE__) Slot(*data, *bone); + Slot *slot = spine_new Slot(*data, *bone); _slots.add(slot); _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 = new (__FILE__, __LINE__) IkConstraint(*data, *this); + 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 = new (__FILE__, __LINE__) TransformConstraint(*data, *this); + 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 = new (__FILE__, __LINE__) PathConstraint(*data, *this); + PathConstraint *constraint = spine_new PathConstraint(*data, *this); _pathConstraints.add(constraint); } @@ -197,6 +207,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 +220,7 @@ void Skeleton::printUpdateCache() { printf("path constraint %s\n", ((PathConstraint *)updatable)->getData().getName().buffer()); } } +#endif } void Skeleton::updateWorldTransform() { @@ -369,8 +381,9 @@ void Skeleton::setAttachment(const String &slotName, const String &attachmentNam return; } } - +#ifndef __EMSCRIPTEN__ printf("Slot not found: %s", slotName.buffer()); +#endif assert(false); } @@ -473,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; } @@ -509,51 +494,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..cf94bd5c137 100644 --- a/native/cocos/editor-support/spine/Skeleton.h +++ b/native/cocos/editor-support/spine/Skeleton.h @@ -168,47 +168,71 @@ 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(); Color &getColor(); - float getTime(); + inline float getTime() const { + return _time; + } - void setTime(float inValue); + inline void setTime(float inValue) { + _time = inValue; + } - void setPosition(float x, float y); + inline void setPosition(float x, float y) { + _x = x; + _y = y; + } - float getX(); + inline float getX() const { + return _x; + } - void setX(float inValue); + inline void setX(float inValue) { + _x = inValue; + } - float getY(); + inline float getY() const { + return _y; + } - void setY(float inValue); + inline void setY(float inValue) { + _y = inValue; + } - float getScaleX(); + inline float getScaleX() const { + return _scaleX; + } - void setScaleX(float inValue); + inline void setScaleX(float inValue) { + _scaleX = inValue; + } - float getScaleY(); - - void setScaleY(float 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/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/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 b6c75b9f6e0..09cd79181ae 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__); } } @@ -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 7de7d8d3657..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(); @@ -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/SkeletonJson.cpp b/native/cocos/editor-support/spine/SkeletonJson.cpp index a6eb5882479..25db058d251 100644 --- a/native/cocos/editor-support/spine/SkeletonJson.cpp +++ b/native/cocos/editor-support/spine/SkeletonJson.cpp @@ -80,7 +80,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 +105,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 +125,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 +159,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 +207,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 +254,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 +298,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 +350,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 +425,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 +612,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 +714,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 +841,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 +855,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 +870,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 +906,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 +926,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 +957,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 +979,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 +1023,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 +1047,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 +1087,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 +1134,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 +1182,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 +1193,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 +1208,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) { diff --git a/native/cocos/editor-support/spine/Skin.cpp b/native/cocos/editor-support/spine/Skin.cpp index 5a495fb4ef9..7a405d3a581 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; } @@ -188,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 49a60208052..9e0732feb7f 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; } @@ -108,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 5668ae68d83..71ac6ac75ce 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(); @@ -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/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 f64e2dcfff0..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(); @@ -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/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..6f2e3feec29 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 +#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 new file mode 100644 index 00000000000..c86cfc439f2 --- /dev/null +++ b/native/cocos/editor-support/spine/SpineString.cpp @@ -0,0 +1,192 @@ +/****************************************************************************** + * 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, __SPINE_FILE__, __SPINE_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, __SPINE_FILE__, __SPINE_LINE__); + memcpy((void *)_buffer, other._buffer, other._length + 1); + } +} + +void String::own(const String &other) { + if (this == &other) return; + if (_buffer) { + SpineExtension::free(_buffer, __SPINE_FILE__, __SPINE_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, __SPINE_FILE__, __SPINE_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, __SPINE_FILE__, __SPINE_LINE__); + } + if (!other._buffer) { + _length = 0; + _buffer = NULL; + } else { + _length = other._length; + _buffer = SpineExtension::calloc(other._length + 1, __SPINE_FILE__, __SPINE_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, __SPINE_FILE__, __SPINE_LINE__); + } + if (!chars) { + _length = 0; + _buffer = NULL; + } else { + _length = strlen(chars); + _buffer = SpineExtension::calloc(_length + 1, __SPINE_FILE__, __SPINE_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, __SPINE_FILE__, __SPINE_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, __SPINE_FILE__, __SPINE_LINE__); + memcpy((void *)(_buffer + thisLen), (void *)(same ? _buffer : other._buffer), len + 1); + return *this; +} + +#ifndef __EMSCRIPTEN__ +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; +} +#endif + +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, __SPINE_FILE__, __SPINE_LINE__); + } +} + +} // namespace spine + diff --git a/native/cocos/editor-support/spine/SpineString.h b/native/cocos/editor-support/spine/SpineString.h index baa1a12a2f8..c3a4c095aca 100644 --- a/native/cocos/editor-support/spine/SpineString.h +++ b/native/cocos/editor-support/spine/SpineString.h @@ -32,176 +32,47 @@ #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, bool own = false) { - if (!chars) { - _length = 0; - _buffer = NULL; - } else { - _length = strlen(chars); - if (!own) { - _buffer = SpineExtension::calloc(_length + 1, __FILE__, __LINE__); - memcpy((void *)_buffer, chars, _length + 1); - } else { - _buffer = (char *)chars; - } - } - } - - 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 { + 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; } - 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 own(const String &other); + void own(const char *chars); + void unown(); + String &operator=(const String &other); + String &operator=(const 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 &append(const char *chars); + String &append(const String &other); - 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); - } - - ~String() { - if (_buffer) { - SpineExtension::free(_buffer, __FILE__, __LINE__); - } - } +#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); + private: mutable size_t _length; mutable char *_buffer; 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 625dc8ea1f3..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); @@ -73,11 +73,13 @@ class SP_API TransformConstraint : public Updatable { float getShearMix(); void setShearMix(float inValue); - bool isActive(); + virtual bool isActive(); - void setActive(bool inValue); + virtual void setActive(bool inValue);; +#ifndef __EMSCRIPTEN__ private: +#endif TransformConstraintData& _data; Vector _bones; Bone* _target; diff --git a/native/cocos/editor-support/spine/TransformConstraintData.cpp b/native/cocos/editor-support/spine/TransformConstraintData.cpp index 5da407b2b9a..ae8ca3734c5 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), @@ -54,10 +57,6 @@ TransformConstraintData::TransformConstraintData(const String &name) : Constrain _local(false) { } -Vector &TransformConstraintData::getBones() { - return _bones; -} - BoneData *TransformConstraintData::getTarget() { return _target; } @@ -102,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 8da5520c129..32fc76b1ebe 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; @@ -49,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(); @@ -63,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; 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 91ee93f84b5..802db245307 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) { } @@ -56,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)); } @@ -72,14 +75,14 @@ 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; 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++) { @@ -88,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, __FILE__, __LINE__); + _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. @@ -103,26 +106,26 @@ 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); } } - 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; @@ -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; @@ -194,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); @@ -203,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__); } } 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 d522f4a624e..a5f6d3973df 100644 --- a/native/cocos/editor-support/spine/VertexAttachment.h +++ b/native/cocos/editor-support/spine/VertexAttachment.h @@ -63,21 +63,23 @@ 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); +#ifndef __EMSCRIPTEN__ protected: +#endif Vector _bones; Vector _vertices; size_t _worldVerticesLength; 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..3cc2f44a5e5 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); @@ -59,12 +62,15 @@ class SP_API JitterVertexEffect : public VertexEffect { void setJitterY(float jitterY); float getJitterY(); +#ifndef __EMSCRIPTEN__ protected: +#endif float _jitterX; float _jitterY; }; class SP_API SwirlVertexEffect : public VertexEffect { + RTTI_DECL public: SwirlVertexEffect(float radius, Interpolation &interpolation); @@ -90,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; diff --git a/native/external-config.json b/native/external-config.json index 3d75f3e5a05..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-6" + "checkout": "v3.8.5-8" } } \ No newline at end of file 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;