diff --git a/.github/workflows/native-compile-platforms.yml b/.github/workflows/native-compile-platforms.yml index 4dd62ed335..3c6d29b61d 100644 --- a/.github/workflows/native-compile-platforms.yml +++ b/.github/workflows/native-compile-platforms.yml @@ -44,8 +44,6 @@ jobs: echo "set(CC_USE_GLES3 ON)" >> build-win64/proj/cfg.cmake echo "set(CC_USE_VULKAN ON)" >> build-win64/proj/cfg.cmake echo "set(CC_USE_GLES2 ON)" >> build-win64/proj/cfg.cmake - echo "set(USE_SPINE OFF)" >> build-win64/proj/cfg.cmake - echo "set(USE_DRAGONBONES OFF)" >> build-win64/proj/cfg.cmake echo "set(USE_WEBSOCKET_SERVER ON)" >> build-win64/proj/cfg.cmake echo "set(CMAKE_CXX_STANDARD_REQUIRED ON)" >> build-win64/proj/cfg.cmake echo "set(CC_EXECUTABLE_NAME \"\")" >> build-win64/proj/cfg.cmake @@ -193,6 +191,8 @@ jobs: echo "set(USE_BOX2D_JSB ON)" >> build-android/proj/cfg.cmake echo "set(USE_WEBSOCKET_SERVER ON)" >> build-android/proj/cfg.cmake echo "set(CMAKE_CXX_STANDARD_REQUIRED ON)" >> build-android/proj/cfg.cmake + echo "set(USE_SPINE_3_8 OFF)" >> build-android/proj/cfg.cmake + echo "set(USE_SPINE_4_2 ON)" >> build-android/proj/cfg.cmake echo "set(COCOS_X_PATH $NATIVE_ROOT)" >> build-android/proj/cfg.cmake echo "set(CC_EXECUTABLE_NAME \"\")" >> build-android/proj/cfg.cmake diff --git a/.github/workflows/package-size-check.js b/.github/workflows/package-size-check.js index 383b17bf0a..8cfd310037 100644 --- a/.github/workflows/package-size-check.js +++ b/.github/workflows/package-size-check.js @@ -7,8 +7,8 @@ if (args.length == 0) { console.error('Please specify the engine root path'); process.exit(1); } -const engineRoot = args[0]; +const engineRoot = args[0]; console.log(`Engine root: ${engineRoot}`); const features2DCommon = [ @@ -30,7 +30,8 @@ const features2DCommon = [ "physics-2d-box2d-wasm", "profiler", "rich-text", - "spine", + "spine", // Old version uses 'spine' feature + "spine-3.8", // New version uses 'spine-xxx' feature "tiled-map", "tween", "ui", @@ -115,13 +116,24 @@ async function buildEngineForFeatures(options) { const excludeFeatures = [ 'vendor-google', 'xr', + 'spine-3.8', + 'spine-4.2', ]; const allFeatures = statsQuery.getFeatures().filter(feature => !excludeFeatures.includes(feature)); console.log(`all features: [ ${allFeatures.join(', ')} ]`); + const allFeaturesForWeChat = [...allFeatures, 'spine-3.8']; + let allFeaturesForWeb = [...allFeatures, 'spine-4.2']; + + if (!fs.pathExistsSync(ps.join(engineRoot, 'cocos', 'spine', 'lib', 'spine-version-4.2.ts'))) { + console.log(`Doesn't found spine-version-4.2.ts`); + allFeaturesForWeb = allFeaturesForWeChat; + } else { + console.log(`Found spine-version-4.2.ts`); + } await buildEngineForFeatures({ - features: allFeatures, + features: allFeaturesForWeChat, outDir: ps.join(engineRoot, 'build-cc-out-all'), noDeprecatedFeatures: false, platform: "WECHAT", @@ -130,7 +142,7 @@ async function buildEngineForFeatures(options) { }); await buildEngineForFeatures({ - features: allFeatures, + features: allFeaturesForWeb, outDir: ps.join(engineRoot, 'build-cc-out-all-web'), noDeprecatedFeatures: false, platform: "HTML5", diff --git a/.github/workflows/web-interface-check.yml b/.github/workflows/web-interface-check.yml index ea5d7d4999..56d0ebde87 100644 --- a/.github/workflows/web-interface-check.yml +++ b/.github/workflows/web-interface-check.yml @@ -96,6 +96,17 @@ jobs: echo "HEAD LOG:" git --no-pager log -3 + - name: Check for SPINE_VERSION in CMakeLists.txt (BASE) + run: | + cd ./engine/native/cocos/editor-support/spine-wasm + if grep -q "SPINE_VERSION" CMakeLists.txt; then + echo "FOUND_SPINE_VERSION_BASE=true" + echo "FOUND_SPINE_VERSION_BASE=true" >> $GITHUB_ENV + else + echo "FOUND_SPINE_VERSION_BASE=false" + echo "FOUND_SPINE_VERSION_BASE=false" >> $GITHUB_ENV + fi + - run: | echo "EXT_VERSION=$(node ./engine/.github/workflows/get-native-external-version.js)" >> $GITHUB_ENV @@ -116,41 +127,94 @@ jobs: echo "--------------------------------- Apply patches DONE! ---------------------------------" cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp - - name: Build Spine WASM (BASE) - run: | - cd ./engine/native/cocos/editor-support/spine-wasm - mkdir build-wasm - cd build-wasm - emcmake cmake .. -GNinja - ninja - ls -l + # - name: Build Spine 3.8 WASM (BASE) + # run: | + # cd ./engine/native/cocos/editor-support/spine-wasm + # rm -rf build-wasm + # mkdir build-wasm + # cd build-wasm + # emcmake cmake .. -GNinja + # ninja + # ls -l - - name: Build Spine ASMJS (BASE) - run: | - cd ./engine/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: Build Spine 3.8 ASMJS (BASE) + # run: | + # cd ./engine/native/cocos/editor-support/spine-wasm + # sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt + # rm -rf build-asmjs + # mkdir build-asmjs + # cd build-asmjs + # emcmake cmake .. -GNinja + # ninja + # ls -l - - name: Copy files to external directory (BASE) - run: | - rm -rf dist - mkdir dist - cp ./engine/native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./dist/ - cp ./engine/native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./dist/spine.wasm.js - cp ./engine/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./dist/ - cp ./engine/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./dist/spine.asm.js - echo "-------- Before replace spine wasm -----------" - ls -l ./engine/native/external/emscripten/spine/ - cp -f ./dist/* ./engine/native/external/emscripten/spine/ - echo "-------- After replace spine wasm ------------" - ls -l ./engine/native/external/emscripten/spine/ - echo "-----------------------------------------------" - cd ./engine/native/external - git status + # - name: Copy Spine 3.8 files to external directory (BASE) + # run: | + # if [[ $FOUND_SPINE_VERSION_BASE ]]; then + # SPINE_VERSION="3.8" + # fi + # DIST_PATH="dist/3.8" + # rm -rf $DIST_PATH + # mkdir -p $DIST_PATH + # cp ./engine/native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/ + # cp ./engine/native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js + # cp ./engine/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/ + # cp ./engine/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js + # mkdir -p ./engine/native/external/emscripten/spine/$SPINE_VERSION + # echo "-------- Before replace spine wasm -----------" + # ls -l ./engine/native/external/emscripten/spine/$SPINE_VERSION + # cp -f ./$DIST_PATH/* ./engine/native/external/emscripten/spine/$SPINE_VERSION + # echo "-------- After replace spine wasm ------------" + # ls -l ./engine/native/external/emscripten/spine/$SPINE_VERSION + # echo "-----------------------------------------------" + # cd ./engine/native/external + # git status + + # - name: Build Spine 4.2 WASM (BASE) + # if: env.FOUND_SPINE_VERSION_BASE == 'true' + # run: | + # cd ./engine/native/cocos/editor-support/spine-wasm + # sed -i 's/set(BUILD_WASM 0)/set(BUILD_WASM 1)/g' CMakeLists.txt + # sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt + # rm -rf build-wasm + # mkdir build-wasm + # cd build-wasm + # emcmake cmake .. -GNinja + # ninja + # ls -l + + # - name: Build Spine 4.2 ASMJS (BASE) + # if: env.FOUND_SPINE_VERSION_BASE == 'true' + # run: | + # cd ./engine/native/cocos/editor-support/spine-wasm + # sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt + # sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt + # rm -rf build-asmjs + # mkdir build-asmjs + # cd build-asmjs + # emcmake cmake .. -GNinja + # ninja + # ls -l + + # - name: Copy Spine 4.2 files to external directory (BASE) + # if: env.FOUND_SPINE_VERSION_BASE == 'true' + # run: | + # DIST_PATH="dist/4.2" + # rm -rf $DIST_PATH + # mkdir -p $DIST_PATH + # cp ./engine/native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/ + # cp ./engine/native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js + # cp ./engine/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/ + # cp ./engine/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js + # mkdir -p ./engine/native/external/emscripten/spine/4.2/ + # echo "-------- Before replace spine wasm -----------" + # ls -l ./engine/native/external/emscripten/spine/4.2/ + # cp -f ./$DIST_PATH/* ./engine/native/external/emscripten/spine/4.2/ + # echo "-------- After replace spine wasm ------------" + # ls -l ./engine/native/external/emscripten/spine/4.2/ + # echo "-----------------------------------------------" + # cd ./engine/native/external + # git status - name: Build Base Declarations working-directory: . @@ -195,7 +259,7 @@ jobs: echo "--------------------------------- Apply patches DONE! ---------------------------------" cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp - - name: Build Spine WASM (HEAD) + - name: Build Spine 3.8 WASM (HEAD) run: | cd ./engine-HEAD/native/cocos/editor-support/spine-wasm mkdir build-wasm @@ -204,7 +268,7 @@ jobs: ninja ls -l - - name: Build Spine ASMJS (HEAD) + - name: Build Spine 3.8 ASMJS (HEAD) run: | cd ./engine-HEAD/native/cocos/editor-support/spine-wasm sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt @@ -214,19 +278,64 @@ jobs: ninja ls -l - - name: Copy files to external directory (HEAD) + - name: Copy Spine 3.8 files to external directory (HEAD) run: | - rm -rf dist - 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 + DIST_PATH="dist/3.8" + rm -rf $DIST_PATH + mkdir -p $DIST_PATH + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/ + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/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/ + mkdir -p ./engine-HEAD/native/external/emscripten/spine/3.8 + ls -l ./engine-HEAD/native/external/emscripten/spine/3.8 + cp -f ./$DIST_PATH/* ./engine-HEAD/native/external/emscripten/spine/3.8 echo "-------- After replace spine wasm ------------" - ls -l ./engine-HEAD/native/external/emscripten/spine/ + ls -l ./engine-HEAD/native/external/emscripten/spine/3.8 + echo "-----------------------------------------------" + cd ./engine-HEAD/native/external + git status + + - name: Build Spine 4.2 WASM (HEAD) + run: | + cd ./engine-HEAD/native/cocos/editor-support/spine-wasm + sed -i 's/set(BUILD_WASM 0)/set(BUILD_WASM 1)/g' CMakeLists.txt + sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt + rm -rf build-wasm + mkdir build-wasm + cd build-wasm + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Build Spine 4.2 ASMJS (HEAD) + run: | + cd ./engine-HEAD/native/cocos/editor-support/spine-wasm + sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt + sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt + rm -rf build-asmjs + mkdir build-asmjs + cd build-asmjs + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Copy Spine 4.2 files to external directory (HEAD) + run: | + DIST_PATH="dist/4.2" + rm -rf $DIST_PATH + mkdir -p $DIST_PATH + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/ + cp ./engine-HEAD/native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js + echo "-------- Before replace spine wasm -----------" + mkdir -p ./engine-HEAD/native/external/emscripten/spine/4.2/ + ls -l ./engine-HEAD/native/external/emscripten/spine/4.2/ + cp -f ./$DIST_PATH/* ./engine-HEAD/native/external/emscripten/spine/4.2/ + echo "-------- After replace spine wasm ------------" + ls -l ./engine-HEAD/native/external/emscripten/spine/4.2/ echo "-----------------------------------------------" cd ./engine-HEAD/native/external git status diff --git a/.github/workflows/web-npm_test.yml b/.github/workflows/web-npm_test.yml index f65573df49..00722e8a4e 100644 --- a/.github/workflows/web-npm_test.yml +++ b/.github/workflows/web-npm_test.yml @@ -18,12 +18,127 @@ jobs: - uses: actions/setup-node@v4 with: node-version: '18.x' + + - name: Setup emsdk + uses: dumganhar/setup-emsdk@997d2cde2deabda085a11f98e86e842915b0e846 + with: + version: 3.1.41 + actions-cache-folder: 'emsdk-cache-3.1.41' + + - name: Verify + run: | + which emcc + emcc -v + + - name: Install ninja + run: | + if ! command -v ninja &> /dev/null; then + echo "Ninja not found, installing..." + # sudo apt update + sudo apt install ninja-build + else + echo "Ninja is already installed." + fi + which ninja - name: Download external run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external + - 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 ./.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: Build Spine 3.8 WASM + run: | + cd ./native/cocos/editor-support/spine-wasm + rm -rf build-wasm + mkdir build-wasm + cd build-wasm + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Build Spine 3.8 ASMJS + run: | + cd ./native/cocos/editor-support/spine-wasm + sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt + rm -rf build-asmjs + mkdir build-asmjs + cd build-asmjs + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Copy Spine 3.8 files to external directory + run: | + SPINE_VERSION="3.8" + DIST_PATH="dist/3.8" + rm -rf $DIST_PATH + mkdir -p $DIST_PATH + cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/ + cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js + cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/ + cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js + mkdir -p ./native/external/emscripten/spine/$SPINE_VERSION + echo "-------- Before replace spine wasm -----------" + ls -l ./native/external/emscripten/spine/$SPINE_VERSION + cp -f ./$DIST_PATH/* ./native/external/emscripten/spine/$SPINE_VERSION + echo "-------- After replace spine wasm ------------" + ls -l ./native/external/emscripten/spine/$SPINE_VERSION + echo "-----------------------------------------------" + cd ./native/external + git status + + - name: Build Spine 4.2 WASM + run: | + cd ./native/cocos/editor-support/spine-wasm + sed -i 's/set(BUILD_WASM 0)/set(BUILD_WASM 1)/g' CMakeLists.txt + sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt + rm -rf build-wasm + mkdir build-wasm + cd build-wasm + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Build Spine 4.2 ASMJS + run: | + cd ./native/cocos/editor-support/spine-wasm + sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt + sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt + rm -rf build-asmjs + mkdir build-asmjs + cd build-asmjs + emcmake cmake .. -GNinja + ninja + ls -l + + - name: Copy Spine 4.2 files to external directory + run: | + DIST_PATH="dist/4.2" + rm -rf $DIST_PATH + mkdir -p $DIST_PATH + cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/ + cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js + cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/ + cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js + mkdir -p ./native/external/emscripten/spine/4.2/ + echo "-------- Before replace spine wasm -----------" + ls -l ./native/external/emscripten/spine/4.2/ + cp -f ./$DIST_PATH/* ./native/external/emscripten/spine/4.2/ + echo "-------- After replace spine wasm ------------" + ls -l ./native/external/emscripten/spine/4.2/ + echo "-----------------------------------------------" + cd ./native/external + git status + - name: npm install run: | npm install diff --git a/.vscode/settings.json b/.vscode/settings.json index 1c60da72a1..2bc4de1795 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,7 +19,19 @@ "source.fixAll": "explicit", }, "files.associations": { - "iterator": "cpp" + "*.cmake": "makefile", + "iterator": "cpp", + "*.ipp": "cpp", + "filesystem": "cpp", + "chrono": "cpp", + "random": "cpp", + "string": "cpp", + "regex": "cpp", + "xlocale": "cpp", + "xstring": "cpp", + "tuple": "cpp", + "vector": "cpp", + "istream": "c" }, "cmake.configureOnOpen": false, } diff --git a/EngineErrorMap.md b/EngineErrorMap.md index 43718a6770..ff8721296f 100644 --- a/EngineErrorMap.md +++ b/EngineErrorMap.md @@ -277,7 +277,7 @@ Failed to initialize render pipeline. ### 1223 -Custom pipeline and legacy pipeline are all culled. +Custom pipeline and legacy pipeline are all culled. ### 1300 @@ -3471,7 +3471,7 @@ The shadow visible distance is so small that CSM stratification is not effective ### 15004 -The native folder may be generated from older versions, please refer https://docs.cocos.com/creator/manual/en/release-notes/ to upgrade. +The native folder may be generated from older versions, please refer to upgrade. ### 15100 @@ -3495,11 +3495,11 @@ Camera '%s' clear flag is skybox, but skybox is disabled, may cause strange bac ### 16101 -The effect('%s') you are looking for does not exist, please confirm the effect name in the editor. NOTE: Since 3.6, the name of the built-in effect has been changed to its name in the editor, please check it out. More information please refer to https://docs.cocos.com/creator/manual/en/shader/effect-inspector.html +The effect('%s') you are looking for does not exist, please confirm the effect name in the editor. NOTE: Since 3.6, the name of the built-in effect has been changed to its name in the editor, please check it out. More information please refer to ### 16201 -The asset replacing failed, can not found override asset('%s') for '%s' +The asset replacing failed, can not found override asset('%s') for '%s' ### 16301 @@ -3932,3 +3932,47 @@ Spline error: invalid mode ### 16408 [Physics2D] b2PolygonShape failed to decompose polygon into convex polygons, node name: %s + +### 16409 + +setVertexEffectDelegate is deprecated since spine 4.2. + +### 16410 + +Debug bones or slots is invalid in cached mode. + +### 16411 + +Slots visible range can not be modified in cached mode. + +### 16412 + +Track index can not greater than 0 in cached mode. + +### 16413 + +Track index can not greater than 0 in cached mode. + +### 16414 + +'getCurrent' interface can not be invoked in cached mode. + +### 16415 + +cached mode not support setMix!!! + +### 16416 + +'clearTracks' interface can not be invoked in cached mode. + +### 16417 + +'clearTrack' interface can not be invoked in cached mode. + +### 16418 + +Debug bones or slots is invalid in cached mode. + +### 16419 + +Spine version not supported. diff --git a/cc.config.json b/cc.config.json index 4a084047a1..26b3013d49 100644 --- a/cc.config.json +++ b/cc.config.json @@ -193,13 +193,27 @@ "vendor-google": { "modules": ["vendor-google"] }, - "spine": { + "spine-3.8": { "modules": ["spine"], "dependentAssets": [ "c27215d8-6835-4b68-bfbb-bdeac6100c04", "b5d6115f-0370-4d7c-aad3-c194cc71cf98" ], - "dependentModules": ["2d"] + "dependentModules": ["2d"], + "intrinsicFlags": { + "SPINE_3_8": true + } + }, + "spine-4.2": { + "modules": ["spine"], + "dependentAssets": [ + "c27215d8-6835-4b68-bfbb-bdeac6100c04", + "b5d6115f-0370-4d7c-aad3-c194cc71cf98" + ], + "dependentModules": ["2d"], + "intrinsicFlags": { + "SPINE_4_2": true + } }, "dragon-bones": { "modules": ["dragon-bones"], @@ -429,6 +443,22 @@ "overrides": { "cocos/animation/marionette/pose-graph/runtime-exports.ts": "cocos/animation/marionette/pose-graph/runtime-exports-empty.ts" } + }, + { + "test": "context.buildTimeConstants.SPINE_3_8", + "isVirtualModule": false, + "overrides": { + "cocos/spine/lib/spine-version.ts": "cocos/spine/lib/spine-version-3.8.ts", + "cocos/spine/lib/spine-instantiate.ts": "cocos/spine/lib/spine-instantiate-3.8.ts" + } + }, + { + "test": "context.buildTimeConstants.SPINE_4_2", + "isVirtualModule": false, + "overrides": { + "cocos/spine/lib/spine-version.ts": "cocos/spine/lib/spine-version-4.2.ts", + "cocos/spine/lib/spine-instantiate.ts": "cocos/spine/lib/spine-instantiate-4.2.ts" + } } ], "includes": [ diff --git a/cocos/spine/index.jsb.ts b/cocos/spine/index.jsb.ts index 06515f66fe..5bd0f9b750 100644 --- a/cocos/spine/index.jsb.ts +++ b/cocos/spine/index.jsb.ts @@ -25,6 +25,7 @@ import { ccenum } from '../core'; import { legacyCC } from '../core/global-exports'; import spineLib from './lib/spine-core'; +import { SPINE_VERSION } from './lib/spine-version'; /** * @en @@ -47,6 +48,7 @@ import spineLib from './lib/spine-core'; export * from './skeleton'; export * from './skeleton-data'; export * from './assembler'; +export * from './lib/spine-version'; export const spine = globalThis.spine; spine.EventType = spineLib.EventType @@ -111,6 +113,7 @@ export enum AnimationEventType { ccenum(AnimationEventType); legacyCC.internal.SpineAnimationEventType = AnimationEventType; +legacyCC.internal.SPINE_VERSION = SPINE_VERSION; export function loadWasmModuleSpine (): Promise { return Promise.resolve(); diff --git a/cocos/spine/index.ts b/cocos/spine/index.ts index 8bcfb6bb81..fd48de21b3 100644 --- a/cocos/spine/index.ts +++ b/cocos/spine/index.ts @@ -49,6 +49,7 @@ export * from './skeleton'; export * from './skeleton-data'; export * from './vertex-effect-delegate'; export * from './assembler'; +export * from './lib/spine-version'; export { spine }; diff --git a/cocos/spine/lib/instantiated.ts b/cocos/spine/lib/instantiated.ts index 856f059906..8cf02c15c8 100644 --- a/cocos/spine/lib/instantiated.ts +++ b/cocos/spine/lib/instantiated.ts @@ -22,108 +22,15 @@ THE SOFTWARE. */ -import { instantiateWasm, fetchBuffer, ensureWasmModuleReady } from 'pal/wasm'; -import { BUILD, JSB, LOAD_SPINE_MANUALLY, NATIVE_CODE_BUNDLE_MODE } from 'internal:constants'; +import { BUILD, JSB, LOAD_SPINE_MANUALLY } from 'internal:constants'; import { game } from '../../game'; -import { error, sys } from '../../core'; -import { NativeCodeBundleMode } from '../../misc/webassembly-support'; -import { overrideSpineDefine } from './spine-define'; - -const PAGESIZE = 65536; // 64KiB - -// How many pages of the wasm memory -// TODO: let this can be canfiguable by user. -const PAGECOUNT = 32 * 16; - -// How mush memory size of the wasm memory -const MEMORYSIZE = PAGESIZE * PAGECOUNT; // 32 MiB - -let wasmInstance: SpineWasm.instance = null!; -const registerList: any[] = []; - -/////////////////////////////////////////////////////////////////////////////////////////////////// -function initWasm (wasmFactory, wasmUrl: string): Promise { - return new Promise((resolve, reject) => { - const errorMessage = (err: any): string => `[Spine]: Spine wasm load failed: ${err}`; - wasmFactory({ - instantiateWasm ( - importObject: WebAssembly.Imports, - receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void, - ) { - // NOTE: the Promise return by instantiateWasm hook can't be caught. - instantiateWasm(wasmUrl, importObject).then((result) => { - receiveInstance(result.instance, result.module); - }).catch((err) => reject(errorMessage(err))); - }, - }).then((Instance: any) => { - wasmInstance = Instance; - registerList.forEach((cb) => { - cb(wasmInstance); - }); - }).then(resolve).catch((err: any) => reject(errorMessage(err))); - }); -} - -function initAsmJS (asmFactory, asmJsMemUrl: string): Promise { - return new Promise((resolve, reject) => { - fetchBuffer(asmJsMemUrl).then((arrayBuffer) => { - const wasmMemory: any = {}; - wasmMemory.buffer = new ArrayBuffer(MEMORYSIZE); - const module = { - wasmMemory, - memoryInitializerRequest: { - response: arrayBuffer, - status: 200, - } as Partial, - }; - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return asmFactory(module).then((instance: any) => { - wasmInstance = instance; - registerList.forEach((cb) => { - cb(wasmInstance); - }); - }); - }).then(resolve).catch(reject); - }); -} - -function shouldUseWasmModule (): boolean { - if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.BOTH as number)) { - return sys.hasFeature(sys.Feature.WASM); - } else if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.WASM as number)) { - return true; - } else { - return false; - } -} - -export function waitForSpineWasmInstantiation (): Promise { - const errorReport = (msg: any): void => { error(msg); }; - return ensureWasmModuleReady().then(() => { - if (shouldUseWasmModule()) { - return Promise.all([ - import('external:emscripten/spine/spine.wasm.js'), - import('external:emscripten/spine/spine.wasm'), - ]).then(([ - { default: wasmFactory }, - { default: spineWasmUrl }, - ]) => initWasm(wasmFactory, spineWasmUrl)); - } else { - return Promise.all([ - import('external:emscripten/spine/spine.asm.js'), - import('external:emscripten/spine/spine.js.mem'), - ]).then(([ - { default: asmFactory }, - { default: asmJsMemUrl }, - ]) => initAsmJS(asmFactory, asmJsMemUrl)); - } - }).catch(errorReport); -} +import './spine-define'; // Make spine._overrideSpineDefine take effect. +import { waitForSpineWasmInstantiation } from './spine-instantiate'; if (!JSB && (!BUILD || !LOAD_SPINE_MANUALLY)) { game.onPostInfrastructureInitDelegate.add(waitForSpineWasmInstantiation); } -registerList.push(overrideSpineDefine); +export { waitForSpineWasmInstantiation }; export const SPINE_WASM = 1; diff --git a/cocos/spine/lib/spine-core.d.ts b/cocos/spine/lib/spine-core.d.ts index 7fdd2f506d..b838a26ae8 100644 --- a/cocos/spine/lib/spine-core.d.ts +++ b/cocos/spine/lib/spine-core.d.ts @@ -50,10 +50,35 @@ declare namespace spine { apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; hasTimeline(id: number): boolean; } - interface Timeline { + + abstract class Timeline { + /** + * @version 4.2 + */ + frames: ArrayLike; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; + /** + * @version 4.2 + */ + getPropertyIds(): ArrayLike; + /** + * @version 3.8, deprecated in 4.2 + */ getPropertyId(): number; + /** + * @version 4.2 + */ + getFrameCount(): number; + /** + * @version 4.2 + */ + getFrameEntries(): number; + /** + * @version 4.2 + */ + getDuration(): number; } + enum MixBlend { setup = 0, first = 1, @@ -86,9 +111,28 @@ declare namespace spine { static readonly STEPPED: number; static readonly BEZIER: number; static readonly BEZIER_SIZE: number; + /** + * @version 3.8, deprecated in 4.2 + */ abstract getPropertyId(): number; constructor(frameCount: number); getFrameCount(): number; + /** + * @version 4.2 + */ + frames: ArrayLike; + /** + * @version 4.2 + */ + getPropertyIds(): ArrayLike; + /** + * @version 4.2 + */ + getFrameEntries(): number; + /** + * @version 4.2 + */ + getDuration(): number; setLinear(frameIndex: number): void; setStepped(frameIndex: number): void; getCurveType(frameIndex: number): number; @@ -102,16 +146,28 @@ declare namespace spine { static PREV_ROTATION: number; static ROTATION: number; boneIndex: number; + /** + * @version 3.8, deprecated in 4.2 + */ frames: ArrayLike; constructor(frameCount: number); + /** + * @version 3.8, deprecated in 4.2 + */ getPropertyId(): number; setFrame(frameIndex: number, time: number, degrees: number): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; } class TranslateTimeline extends CurveTimeline { static readonly ENTRIES: number; + /** + * @version 3.8, deprecated in 4.2 + */ frames: ArrayLike; constructor(frameCount: number); + /** + * @version 3.8, deprecated in 4.2 + */ getPropertyId(): number; setFrame(frameIndex: number, time: number, x: number, y: number): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; @@ -123,9 +179,16 @@ declare namespace spine { } class ShearTimeline extends TranslateTimeline { constructor(frameCount: number); + /** + * @version 3.8, deprecated in 4.2 + */ getPropertyId(): number; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; } + + /** + * @version 3.8, deprecated in 4.2 + */ class ColorTimeline extends CurveTimeline { static ENTRIES: number; slotIndex: number; @@ -137,6 +200,10 @@ declare namespace spine { setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; } + + /** + * @version 3.8, deprecated in 4.2 + */ class TwoColorTimeline extends CurveTimeline { static readonly ENTRIES: number; slotIndex: number; @@ -148,11 +215,38 @@ declare namespace spine { setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; } + + /** + * @version 4.2 + */ + class RGBATimeline extends CurveTimeline { + static ENTRIES: number; + slotIndex: number; + constructor(frameCount: number, bezierCount: number, slotIndex: number); + getSlotIndex(): number; + getPropertyId(): number; + setSlotIndex(inValue: number): void; + setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; + apply(skeleton: Skeleton, lastTime: number, time: number, events: Array, alpha: number, blend: MixBlend, direction: MixDirection): void; + } + class AttachmentTimeline implements Timeline { slotIndex: number; frames: ArrayLike; attachmentNames: Array; constructor(frameCount: number); + /** + * @version 4.2 + */ + getPropertyIds(): ArrayLike; + /** + * @version 4.2 + */ + getFrameEntries(): number; + /** + * @version 4.2 + */ + getDuration(): number; getPropertyId(): number; getFrameCount(): number; getSlotIndex(): number; @@ -175,6 +269,18 @@ declare namespace spine { frames: ArrayLike; events: Array; constructor(frameCount: number); + /** + * @version 4.2 + */ + getPropertyIds(): ArrayLike; + /** + * @version 4.2 + */ + getFrameEntries(): number; + /** + * @version 4.2 + */ + getDuration(): number; getPropertyId(): number; getFrameCount(): number; setFrame(frameIndex: number, event: Event): void; @@ -184,6 +290,18 @@ declare namespace spine { frames: ArrayLike; drawOrders: Array>; constructor(frameCount: number); + /** + * @version 4.2 + */ + getPropertyIds(): ArrayLike; + /** + * @version 4.2 + */ + getFrameEntries(): number; + /** + * @version 4.2 + */ + getDuration(): number; getPropertyId(): number; getFrameCount(): number; setFrame(frameIndex: number, time: number, drawOrder: Array): void; @@ -528,8 +646,26 @@ declare namespace spine { offsetRotation: number; position: number; spacing: number; + /** + * @version 3.8, deprecated in 4.2 + */ rotateMix: number; + /** + * @version 3.8, deprecated in 4.2 + */ translateMix: number; + /** + * @version 4.2 + */ + mixRotate: number; + /** + * @version 4.2 + */ + mixX: number; + /** + * @version 4.2 + */ + mixY: number; constructor(name: string); } enum PositionMode { @@ -688,6 +824,9 @@ declare namespace spine { findBone(boneName: string): BoneData; findBoneIndex(boneName: string): number; findSlot(slotName: string): SlotData; + /** + * @version 3.8, deprecated in 4.2 + */ findSlotIndex(slotName: string): number; findSkin(skinName: string): Skin; findEvent(eventDataName: string): EventData; diff --git a/cocos/spine/lib/spine-define.ts b/cocos/spine/lib/spine-define.ts index b84e7b8fe8..d5730a467b 100644 --- a/cocos/spine/lib/spine-define.ts +++ b/cocos/spine/lib/spine-define.ts @@ -25,6 +25,7 @@ /* eslint @typescript-eslint/no-unsafe-argument: "off" */ import spine from './spine-core'; +import { SPINE_VERSION } from './spine-version'; import { js } from '../../core'; function resizeArray (array: any[], newSize: number): any[] { @@ -272,9 +273,16 @@ function overrideProperty_ColorTimeline (): void { overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); } +function overrideProperty_Timeline (): void { + const prototype = spine.Timeline.prototype as any; + overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); +} + function overrideProperty_AttachmentTimeline (): void { const prototype = spine.AttachmentTimeline.prototype as any; - overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); + if (SPINE_VERSION === '3.8') { + overrideDefineArrayProp(prototype, prototype.getFrames, 'frames'); + } overrideDefineArrayProp(prototype, prototype.getAttachmentNames, 'attachmentNames'); } @@ -335,7 +343,11 @@ export function overrideSpineDefine (wasm): void { overrideProperty_SkinEntry(); overrideProperty_SkeletonData(); overrideProperty_RotateTimeline(); - overrideProperty_ColorTimeline(); + if (SPINE_VERSION === '3.8') { + overrideProperty_ColorTimeline(); + } else if (SPINE_VERSION === '4.2') { + overrideProperty_Timeline(); + } overrideProperty_AttachmentTimeline(); overrideProperty_DeformTimeline(); overrideProperty_EventTimeline(); diff --git a/cocos/spine/lib/spine-instantiate-3.8.ts b/cocos/spine/lib/spine-instantiate-3.8.ts new file mode 100644 index 0000000000..95668dd5ea --- /dev/null +++ b/cocos/spine/lib/spine-instantiate-3.8.ts @@ -0,0 +1,50 @@ +/* + Copyright (c) 2025 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ +import { ensureWasmModuleReady } from 'pal/wasm'; +import { error } from '../../core'; +import { shouldUseWasmModule, initWasm, initAsmJS } from './spine-wasm-utils'; + +export function waitForSpineWasmInstantiation (): Promise { + const errorReport = (msg: any): void => { error(msg); }; + return ensureWasmModuleReady().then((): Promise => { + //We should use static code here, import operation will cause file copy to cache folder. + if (shouldUseWasmModule()) { + return Promise.all([ + import('external:emscripten/spine/3.8/spine.wasm.js'), + import('external:emscripten/spine/3.8/spine.wasm'), + ]).then(([ + { default: wasmFactory }, + { default: spineWasmUrl }, + ]) => initWasm(wasmFactory, spineWasmUrl)); + } else { + return Promise.all([ + import('external:emscripten/spine/3.8/spine.asm.js'), + import('external:emscripten/spine/3.8/spine.js.mem'), + ]).then(([ + { default: asmFactory }, + { default: asmJsMemUrl }, + ]) => initAsmJS(asmFactory, asmJsMemUrl)); + } + }).catch(errorReport); +} diff --git a/cocos/spine/lib/spine-instantiate-4.2.ts b/cocos/spine/lib/spine-instantiate-4.2.ts new file mode 100644 index 0000000000..f8a4a7ed4a --- /dev/null +++ b/cocos/spine/lib/spine-instantiate-4.2.ts @@ -0,0 +1,51 @@ +/* + Copyright (c) 2025 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +import { ensureWasmModuleReady } from 'pal/wasm'; +import { error } from '../../core'; +import { shouldUseWasmModule, initWasm, initAsmJS } from './spine-wasm-utils'; + +export function waitForSpineWasmInstantiation (): Promise { + const errorReport = (msg: any): void => { error(msg); }; + return ensureWasmModuleReady().then((): Promise => { + //We should use static code here, import operation will cause file copy to cache folder. + if (shouldUseWasmModule()) { + return Promise.all([ + import('external:emscripten/spine/4.2/spine.wasm.js'), + import('external:emscripten/spine/4.2/spine.wasm'), + ]).then(([ + { default: wasmFactory }, + { default: spineWasmUrl }, + ]) => initWasm(wasmFactory, spineWasmUrl)); + } else { + return Promise.all([ + import('external:emscripten/spine/4.2/spine.asm.js'), + import('external:emscripten/spine/4.2/spine.js.mem'), + ]).then(([ + { default: asmFactory }, + { default: asmJsMemUrl }, + ]) => initAsmJS(asmFactory, asmJsMemUrl)); + } + }).catch(errorReport); +} diff --git a/cocos/spine/lib/spine-instantiate.ts b/cocos/spine/lib/spine-instantiate.ts new file mode 100644 index 0000000000..5c79cecc05 --- /dev/null +++ b/cocos/spine/lib/spine-instantiate.ts @@ -0,0 +1,33 @@ +/* + Copyright (c) 2025 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +// Defining the following import to make ts compiler know these files +// spine-instantiate.ts will be overriden by spine-instantiate-3.8.ts or spine-instantiate-4.2.ts while building engine. +// See 'moduleOverrides' section in cc.config.json. +import './spine-instantiate-3.8'; +import './spine-instantiate-4.2'; + +export function waitForSpineWasmInstantiation (): Promise { + return null!; +} diff --git a/cocos/spine/lib/spine-version-3.8.ts b/cocos/spine/lib/spine-version-3.8.ts new file mode 100644 index 0000000000..22921abcf2 --- /dev/null +++ b/cocos/spine/lib/spine-version-3.8.ts @@ -0,0 +1,25 @@ +/* + Copyright (c) 2025 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +export const SPINE_VERSION = '3.8'; diff --git a/cocos/spine/lib/spine-version-4.2.ts b/cocos/spine/lib/spine-version-4.2.ts new file mode 100644 index 0000000000..f1fdb5514c --- /dev/null +++ b/cocos/spine/lib/spine-version-4.2.ts @@ -0,0 +1,25 @@ +/* + Copyright (c) 2025 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +export const SPINE_VERSION = '4.2'; diff --git a/cocos/spine/lib/spine-version.ts b/cocos/spine/lib/spine-version.ts new file mode 100644 index 0000000000..22921abcf2 --- /dev/null +++ b/cocos/spine/lib/spine-version.ts @@ -0,0 +1,25 @@ +/* + Copyright (c) 2025 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +export const SPINE_VERSION = '3.8'; diff --git a/cocos/spine/lib/spine-wasm-utils.ts b/cocos/spine/lib/spine-wasm-utils.ts new file mode 100644 index 0000000000..7b1aabaf07 --- /dev/null +++ b/cocos/spine/lib/spine-wasm-utils.ts @@ -0,0 +1,75 @@ +import { instantiateWasm, fetchBuffer } from 'pal/wasm'; +import { NATIVE_CODE_BUNDLE_MODE } from 'internal:constants'; +import { sys } from '../../core'; +import { NativeCodeBundleMode } from '../../misc/webassembly-support'; +import { overrideSpineDefine } from './spine-define'; + +const PAGESIZE = 65536; // 64KiB + +// How many pages of the wasm memory +// TODO: let this can be canfiguable by user. +const PAGECOUNT = 32 * 16; + +// How mush memory size of the wasm memory +const MEMORYSIZE = PAGESIZE * PAGECOUNT; // 32 MiB + +let wasmInstance: SpineWasm.instance = null!; +const registerList: any[] = []; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +export function initWasm (wasmFactory, wasmUrl: string): Promise { + return new Promise((resolve, reject) => { + const errorMessage = (err: any): string => `[Spine]: Spine wasm load failed: ${err}`; + wasmFactory({ + instantiateWasm ( + importObject: WebAssembly.Imports, + receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void, + ) { + // NOTE: the Promise return by instantiateWasm hook can't be caught. + instantiateWasm(wasmUrl, importObject).then((result) => { + receiveInstance(result.instance, result.module); + }).catch((err) => reject(errorMessage(err))); + }, + }).then((Instance: any) => { + wasmInstance = Instance; + registerList.forEach((cb) => { + cb(wasmInstance); + }); + }).then(resolve).catch((err: any) => reject(errorMessage(err))); + }); +} + +export function initAsmJS (asmFactory, asmJsMemUrl: string): Promise { + return new Promise((resolve, reject) => { + fetchBuffer(asmJsMemUrl).then((arrayBuffer) => { + const wasmMemory: any = {}; + wasmMemory.buffer = new ArrayBuffer(MEMORYSIZE); + const module = { + wasmMemory, + memoryInitializerRequest: { + response: arrayBuffer, + status: 200, + } as Partial, + }; + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return asmFactory(module).then((instance: any) => { + wasmInstance = instance; + registerList.forEach((cb) => { + cb(wasmInstance); + }); + }); + }).then(resolve).catch(reject); + }); +} + +export function shouldUseWasmModule (): boolean { + if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.BOTH as number)) { + return sys.hasFeature(sys.Feature.WASM); + } else if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.WASM as number)) { + return true; + } else { + return false; + } +} + +registerList.push(overrideSpineDefine); diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index ae6b988951..069a64cb9c 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -24,7 +24,7 @@ import { EDITOR_NOT_IN_PREVIEW, JSB } from 'internal:constants'; import { ccclass, executeInEditMode, help, menu, serializable, type, override, displayOrder, editable, visible } from 'cc.decorator'; import { Material, Texture2D } from '../asset/assets'; -import { error, errorID, logID, warn } from '../core/platform/debug'; +import { error, errorID, logID, warnID } from '../core/platform/debug'; import { Enum, EnumType, ccenum } from '../core/value-types/enum'; import { Node, NodeEventType } from '../scene-graph'; import { CCObjectFlags, Color, RecyclePool, js } from '../core'; @@ -45,6 +45,7 @@ import SkeletonCache, { AnimationCache, AnimationFrame, SkeletonCacheItemInfo } import { TrackEntryListeners } from './track-entry-listeners'; import { setPropertyEnumType } from '../core/internal-index'; import { RenderData } from '../2d/renderer/render-data'; +import { SPINE_VERSION } from './lib/spine-version'; const CachedFrameTime = 1 / 60; @@ -783,7 +784,12 @@ export class Skeleton extends UIRenderer { it will cause rendering issues when a prefab with Spine assets is added to the scene node tree. */ if (this.defaultSkin && this.defaultSkin !== '') this.setSkin(this.defaultSkin); - if (this.defaultAnimation) this.animation = this.defaultAnimation.toString(); + if (this.defaultAnimation) { + this.animation = this.defaultAnimation.toString(); + } else if (this._animationName) { + this.animation = this._animationName; + } + this._updateUseTint(); this._indexBoneSockets(); this._updateSocketBindings(); @@ -821,7 +827,7 @@ export class Skeleton extends UIRenderer { } if (this.isAnimationCached()) { if (this.debugBones || this.debugSlots) { - warn('Debug bones or slots is invalid in cached mode'); + warnID(16410); } const skeletonInfo = this._skeletonCache!.getSkeletonInfo(this._skeletonData!); if (this._skeletonInfo !== skeletonInfo) { @@ -848,7 +854,7 @@ export class Skeleton extends UIRenderer { */ public setSlotsRange (startSlotIndex: number, endSlotIndex: number): void { if (this.isAnimationCached()) { - warn('Slots visible range can not be modified in cached mode.'); + warnID(16411); } else { this._startSlotIndex = startSlotIndex; this._endSlotIndex = endSlotIndex; @@ -928,7 +934,7 @@ export class Skeleton extends UIRenderer { this._playTimes = loop ? 0 : 1; if (this.isAnimationCached()) { if (trackIndex !== 0) { - warn('Track index can not greater than 0 in cached mode.'); + warnID(16412); } if (!this._skeletonCache) return null; let cache = this._skeletonCache.getAnimationCache(this._skeletonData!.uuid, name); @@ -970,7 +976,7 @@ export class Skeleton extends UIRenderer { delay = delay || 0; if (this.isAnimationCached()) { if (trackIndex !== 0) { - warn('Track index can not greater than 0 in cached mode.'); + warnID(16413); } this._animationQueue.push({ animationName: name, loop, delay }); return null; @@ -1006,7 +1012,7 @@ export class Skeleton extends UIRenderer { */ public getCurrent (trackIndex: number): spine.TrackEntry | null { if (this.isAnimationCached()) { - warn('\'getCurrent\' interface can not be invoked in cached mode.'); + warnID(16414); } else if (this._state) { return this._state.getCurrent(trackIndex); } @@ -1462,7 +1468,7 @@ export class Skeleton extends UIRenderer { */ public setMix (fromAnimation: string, toAnimation: string, duration: number): void { if (this.isAnimationCached()) { - warn('cached mode not support setMix!!!'); + warnID(16415); return; } if (this._state) { @@ -1477,7 +1483,7 @@ export class Skeleton extends UIRenderer { */ public clearTracks (): void { if (this.isAnimationCached()) { - warn('\'clearTracks\' interface can not be invoked in cached mode.'); + warnID(16416); } else if (this._state) { this._state.clearTracks(); this.setToSetupPose(); @@ -1491,7 +1497,7 @@ export class Skeleton extends UIRenderer { */ public clearTrack (trackIndex: number): void { if (this.isAnimationCached()) { - warn('\'clearTrack\' interface can not be invoked in cached mode.'); + warnID(16417); } else if (this._state) { this._state.clearTrack(trackIndex); if (EDITOR_NOT_IN_PREVIEW) { @@ -1638,7 +1644,7 @@ export class Skeleton extends UIRenderer { } } if (this.isAnimationCached()) { - warn('Debug bones or slots is invalid in cached mode'); + warnID(16418); } else if (!JSB) { this._instance!.setDebugMode(true); } @@ -1699,11 +1705,16 @@ export class Skeleton extends UIRenderer { } /** + * @version 3.8, deprecated since spine 4.2 * @en Sets vertex effect delegate. * @zh 设置顶点特效动画代理。 * @param effectDelegate @en Vertex effect delegate. @zh 顶点特效代理。 */ public setVertexEffectDelegate (effectDelegate: VertexEffectDelegate | null | undefined): void { + if (SPINE_VERSION !== '3.8') { + warnID(16409); + return; + } if (!this._instance) { return; } diff --git a/editor/engine-features/render-config.json b/editor/engine-features/render-config.json index e699b511cb..6c9ff8dc52 100644 --- a/editor/engine-features/render-config.json +++ b/editor/engine-features/render-config.json @@ -375,22 +375,42 @@ "hidden": true }, "spine": { - "default": true, "label": "i18n:ENGINE.features.spine.label", "description": "i18n:ENGINE.features.spine.description", - "cmakeConfig": "USE_SPINE", "isNativeModule": true, - "enginePlugin": true, + "enginePlugin": false, "category": "2d", "dependencies": [ "2d" ], - "flags": { - "LOAD_SPINE_MANUALLY": { - "label": "i18n:ENGINE.features.flags.spine.loadManual.label", - "description": "i18n:ENGINE.features.flags.spine.loadManual.description", - "ui-type": "checkbox", - "default": false + "options": { + "spine-3.8": { + "cmakeConfig": "USE_SPINE_3_8", + "default": true, + "label": "i18n:ENGINE.features.spine_38.label", + "description": "i18n:ENGINE.features.spine_38.description", + "flags": { + "LOAD_SPINE_MANUALLY": { + "label": "i18n:ENGINE.features.flags.spine.loadManual.label", + "description": "i18n:ENGINE.features.flags.spine.loadManual.description", + "ui-type": "checkbox", + "default": false + } + } + }, + "spine-4.2": { + "cmakeConfig": "USE_SPINE_4_2", + "default": false, + "label": "i18n:ENGINE.features.spine_42.label", + "description": "i18n:ENGINE.features.spine_42.description", + "flags": { + "LOAD_SPINE_MANUALLY": { + "label": "i18n:ENGINE.features.flags.spine.loadManual.label", + "description": "i18n:ENGINE.features.flags.spine.loadManual.description", + "ui-type": "checkbox", + "default": false + } + } } } }, diff --git a/editor/i18n/en/localization.js b/editor/i18n/en/localization.js index 25806beb87..81b4d170a1 100755 --- a/editor/i18n/en/localization.js +++ b/editor/i18n/en/localization.js @@ -1075,6 +1075,14 @@ module.exports = link(mixin({ label: "Spine Animation", description: "Spine Animation support.", }, + spine_38: { + label: "Spine 3.8", + description: "Spine 3.8", + }, + spine_42: { + label: "Spine 4.2", + description: "Spine 4.2", + }, dragon_bones: { label: "Dragon Bones", description: "Dragon Bones support.", diff --git a/editor/i18n/zh/localization.js b/editor/i18n/zh/localization.js index 849d99b2b5..baafc971a3 100755 --- a/editor/i18n/zh/localization.js +++ b/editor/i18n/zh/localization.js @@ -1053,6 +1053,14 @@ module.exports = link(mixin({ label: "Spine 动画", description: "Spine 动画支持。", }, + spine_38: { + label: "Spine 3.8", + description: "Spine 3.8", + }, + spine_42: { + label: "Spine 4.2", + description: "Spine 4.2", + }, dragon_bones: { label: "Dragon Bones", description: "Dragon Bones 支持。", diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 3f8c4b914b..8e7e10a004 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -28,6 +28,13 @@ cc_set_if_undefined(USE_VIDEO ON) cc_set_if_undefined(USE_WEBVIEW ON) cc_set_if_undefined(USE_MIDDLEWARE ON) cc_set_if_undefined(USE_DRAGONBONES ON) +cc_set_if_undefined(USE_SPINE_3_8 ON) +cc_set_if_undefined(USE_SPINE_4_2 OFF) +if (USE_SPINE_3_8 OR USE_SPINE_4_2) + cc_set_if_undefined(USE_SPINE ON) +else() + cc_set_if_undefined(USE_SPINE OFF) +endif() cc_set_if_undefined(USE_SPINE ON) cc_set_if_undefined(USE_WEBSOCKET_SERVER OFF) cc_set_if_undefined(USE_JOB_SYSTEM_TASKFLOW OFF) @@ -222,7 +229,8 @@ cc_inspect_values( USE_WEBVIEW USE_MIDDLEWARE USE_DRAGONBONES - USE_SPINE + USE_SPINE_3_8 + USE_SPINE_4_2 USE_WEBSOCKET_SERVER USE_PHYSICS_PHYSX USE_JOB_SYSTEM_TBB @@ -2316,184 +2324,363 @@ if(USE_MIDDLEWARE) ${SWIG_OUTPUT}/jsb_editor_support_auto.h ) - if(USE_SPINE) + if(USE_SPINE_3_8) + include_directories(${CWD}/cocos/editor-support/spine/3.8) cocos_source_files( - NO_WERROR NO_UBUILD cocos/editor-support/spine/Animation.cpp - cocos/editor-support/spine/Animation.h - NO_WERROR NO_UBUILD cocos/editor-support/spine/AnimationState.cpp - cocos/editor-support/spine/AnimationState.h - NO_WERROR cocos/editor-support/spine/AnimationStateData.cpp - cocos/editor-support/spine/AnimationStateData.h - NO_WERROR cocos/editor-support/spine/Atlas.cpp - cocos/editor-support/spine/Atlas.h - NO_WERROR cocos/editor-support/spine/AtlasAttachmentLoader.cpp - cocos/editor-support/spine/AtlasAttachmentLoader.h - NO_WERROR cocos/editor-support/spine/Attachment.cpp - cocos/editor-support/spine/Attachment.h - NO_WERROR cocos/editor-support/spine/AttachmentLoader.cpp - cocos/editor-support/spine/AttachmentLoader.h - NO_WERROR cocos/editor-support/spine/AttachmentTimeline.cpp - cocos/editor-support/spine/AttachmentTimeline.h - cocos/editor-support/spine/AttachmentType.h - cocos/editor-support/spine/BlendMode.h - NO_WERROR cocos/editor-support/spine/Bone.cpp - cocos/editor-support/spine/Bone.h - NO_WERROR cocos/editor-support/spine/BoneData.cpp - cocos/editor-support/spine/BoneData.h - NO_WERROR cocos/editor-support/spine/BoundingBoxAttachment.cpp - cocos/editor-support/spine/BoundingBoxAttachment.h - NO_WERROR cocos/editor-support/spine/ClippingAttachment.cpp - cocos/editor-support/spine/ClippingAttachment.h - cocos/editor-support/spine/Color.h - NO_WERROR cocos/editor-support/spine/ColorTimeline.cpp - cocos/editor-support/spine/ColorTimeline.h - NO_WERROR cocos/editor-support/spine/Constraint.cpp - cocos/editor-support/spine/Constraint.h - NO_WERROR NO_UBUILD cocos/editor-support/spine/ConstraintData.cpp - cocos/editor-support/spine/ConstraintData.h - cocos/editor-support/spine/ContainerUtil.h - NO_WERROR cocos/editor-support/spine/CurveTimeline.cpp - cocos/editor-support/spine/CurveTimeline.h - cocos/editor-support/spine/Debug.h - NO_WERROR cocos/editor-support/spine/DeformTimeline.cpp - cocos/editor-support/spine/DeformTimeline.h - cocos/editor-support/spine/dll.h - NO_WERROR cocos/editor-support/spine/DrawOrderTimeline.cpp - cocos/editor-support/spine/DrawOrderTimeline.h - NO_WERROR cocos/editor-support/spine/Event.cpp - cocos/editor-support/spine/Event.h - NO_WERROR cocos/editor-support/spine/EventData.cpp - cocos/editor-support/spine/EventData.h - NO_WERROR cocos/editor-support/spine/EventTimeline.cpp - cocos/editor-support/spine/EventTimeline.h - NO_WERROR cocos/editor-support/spine/Extension.cpp - cocos/editor-support/spine/Extension.h - cocos/editor-support/spine/HashMap.h - cocos/editor-support/spine/HasRendererObject.h - NO_WERROR cocos/editor-support/spine/IkConstraint.cpp - cocos/editor-support/spine/IkConstraint.h - NO_WERROR cocos/editor-support/spine/IkConstraintData.cpp - cocos/editor-support/spine/IkConstraintData.h - NO_WERROR cocos/editor-support/spine/IkConstraintTimeline.cpp - cocos/editor-support/spine/IkConstraintTimeline.h - NO_WERROR cocos/editor-support/spine/Json.cpp - cocos/editor-support/spine/Json.h - NO_WERROR cocos/editor-support/spine/LinkedMesh.cpp - cocos/editor-support/spine/LinkedMesh.h - NO_WERROR cocos/editor-support/spine/MathUtil.cpp - cocos/editor-support/spine/MathUtil.h - NO_WERROR cocos/editor-support/spine/MeshAttachment.cpp - cocos/editor-support/spine/MeshAttachment.h - cocos/editor-support/spine/MixBlend.h - cocos/editor-support/spine/MixDirection.h - NO_WERROR cocos/editor-support/spine/PathAttachment.cpp - cocos/editor-support/spine/PathAttachment.h - NO_WERROR cocos/editor-support/spine/PathConstraint.cpp - cocos/editor-support/spine/PathConstraint.h - NO_WERROR cocos/editor-support/spine/PathConstraintData.cpp - cocos/editor-support/spine/PathConstraintData.h - NO_WERROR cocos/editor-support/spine/PathConstraintMixTimeline.cpp - cocos/editor-support/spine/PathConstraintMixTimeline.h - NO_WERROR cocos/editor-support/spine/PathConstraintPositionTimeline.cpp - cocos/editor-support/spine/PathConstraintPositionTimeline.h - NO_WERROR cocos/editor-support/spine/PathConstraintSpacingTimeline.cpp - cocos/editor-support/spine/PathConstraintSpacingTimeline.h - NO_WERROR cocos/editor-support/spine/PointAttachment.cpp - cocos/editor-support/spine/PointAttachment.h - cocos/editor-support/spine/Pool.h - cocos/editor-support/spine/PositionMode.h - NO_WERROR cocos/editor-support/spine/RegionAttachment.cpp - cocos/editor-support/spine/RegionAttachment.h - cocos/editor-support/spine/RotateMode.h - NO_WERROR cocos/editor-support/spine/RotateTimeline.cpp - cocos/editor-support/spine/RotateTimeline.h - NO_WERROR cocos/editor-support/spine/RTTI.cpp - cocos/editor-support/spine/RTTI.h - NO_WERROR cocos/editor-support/spine/ScaleTimeline.cpp - cocos/editor-support/spine/ScaleTimeline.h - NO_WERROR cocos/editor-support/spine/ShearTimeline.cpp - cocos/editor-support/spine/ShearTimeline.h - NO_WERROR cocos/editor-support/spine/Skeleton.cpp - cocos/editor-support/spine/Skeleton.h - NO_WERROR cocos/editor-support/spine/SkeletonBinary.cpp - cocos/editor-support/spine/SkeletonBinary.h - NO_WERROR cocos/editor-support/spine/SkeletonBounds.cpp - cocos/editor-support/spine/SkeletonBounds.h - NO_WERROR cocos/editor-support/spine/SkeletonClipping.cpp - cocos/editor-support/spine/SkeletonClipping.h - NO_WERROR cocos/editor-support/spine/SkeletonData.cpp - cocos/editor-support/spine/SkeletonData.h - NO_WERROR cocos/editor-support/spine/SkeletonJson.cpp - cocos/editor-support/spine/SkeletonJson.h - NO_WERROR cocos/editor-support/spine/Skin.cpp - cocos/editor-support/spine/Skin.h - NO_WERROR cocos/editor-support/spine/Slot.cpp - cocos/editor-support/spine/Slot.h - NO_WERROR cocos/editor-support/spine/SlotData.cpp - cocos/editor-support/spine/SlotData.h - cocos/editor-support/spine/SpacingMode.h - 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 - NO_WERROR cocos/editor-support/spine/Timeline.cpp - cocos/editor-support/spine/Timeline.h - cocos/editor-support/spine/TimelineType.h - NO_WERROR cocos/editor-support/spine/TransformConstraint.cpp - cocos/editor-support/spine/TransformConstraint.h - NO_WERROR cocos/editor-support/spine/TransformConstraintData.cpp - cocos/editor-support/spine/TransformConstraintData.h - NO_WERROR cocos/editor-support/spine/TransformConstraintTimeline.cpp - cocos/editor-support/spine/TransformConstraintTimeline.h - cocos/editor-support/spine/TransformMode.h - NO_WERROR cocos/editor-support/spine/TranslateTimeline.cpp - cocos/editor-support/spine/TranslateTimeline.h - NO_WERROR cocos/editor-support/spine/Triangulator.cpp - cocos/editor-support/spine/Triangulator.h - NO_WERROR cocos/editor-support/spine/TwoColorTimeline.cpp - cocos/editor-support/spine/TwoColorTimeline.h - NO_WERROR cocos/editor-support/spine/Updatable.cpp - cocos/editor-support/spine/Updatable.h - cocos/editor-support/spine/Vector.h - NO_WERROR cocos/editor-support/spine/VertexAttachment.cpp - cocos/editor-support/spine/VertexAttachment.h - NO_WERROR cocos/editor-support/spine/VertexEffect.cpp - cocos/editor-support/spine/VertexEffect.h - cocos/editor-support/spine/Vertices.h - NO_WERROR cocos/editor-support/spine-creator-support/AttachmentVertices.cpp - cocos/editor-support/spine-creator-support/AttachmentVertices.h - NO_WERROR cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp - cocos/editor-support/spine-creator-support/SkeletonAnimation.h - NO_WERROR cocos/editor-support/spine-creator-support/SkeletonCache.cpp - cocos/editor-support/spine-creator-support/SkeletonCache.h - NO_WERROR cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp - cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.h - NO_WERROR cocos/editor-support/spine-creator-support/SkeletonCacheMgr.cpp - cocos/editor-support/spine-creator-support/SkeletonCacheMgr.h - NO_WERROR cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp - cocos/editor-support/spine-creator-support/SkeletonDataMgr.h - NO_WERROR NO_UBUILD cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp - cocos/editor-support/spine-creator-support/SkeletonRenderer.h - NO_WERROR cocos/editor-support/spine-creator-support/spine-cocos2dx.cpp - cocos/editor-support/spine-creator-support/spine-cocos2dx.h + NO_WERROR NO_UBUILD cocos/editor-support/spine/3.8/spine/Animation.cpp + cocos/editor-support/spine/3.8/spine/Animation.h + NO_WERROR NO_UBUILD cocos/editor-support/spine/3.8/spine/AnimationState.cpp + cocos/editor-support/spine/3.8/spine/AnimationState.h + NO_WERROR cocos/editor-support/spine/3.8/spine/AnimationStateData.cpp + cocos/editor-support/spine/3.8/spine/AnimationStateData.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Atlas.cpp + cocos/editor-support/spine/3.8/spine/Atlas.h + NO_WERROR cocos/editor-support/spine/3.8/spine/AtlasAttachmentLoader.cpp + cocos/editor-support/spine/3.8/spine/AtlasAttachmentLoader.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Attachment.cpp + cocos/editor-support/spine/3.8/spine/Attachment.h + NO_WERROR cocos/editor-support/spine/3.8/spine/AttachmentLoader.cpp + cocos/editor-support/spine/3.8/spine/AttachmentLoader.h + NO_WERROR cocos/editor-support/spine/3.8/spine/AttachmentTimeline.cpp + cocos/editor-support/spine/3.8/spine/AttachmentTimeline.h + cocos/editor-support/spine/3.8/spine/AttachmentType.h + cocos/editor-support/spine/3.8/spine/BlendMode.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Bone.cpp + cocos/editor-support/spine/3.8/spine/Bone.h + NO_WERROR cocos/editor-support/spine/3.8/spine/BoneData.cpp + cocos/editor-support/spine/3.8/spine/BoneData.h + NO_WERROR cocos/editor-support/spine/3.8/spine/BoundingBoxAttachment.cpp + cocos/editor-support/spine/3.8/spine/BoundingBoxAttachment.h + NO_WERROR cocos/editor-support/spine/3.8/spine/ClippingAttachment.cpp + cocos/editor-support/spine/3.8/spine/ClippingAttachment.h + cocos/editor-support/spine/3.8/spine/Color.h + NO_WERROR cocos/editor-support/spine/3.8/spine/ColorTimeline.cpp + cocos/editor-support/spine/3.8/spine/ColorTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Constraint.cpp + cocos/editor-support/spine/3.8/spine/Constraint.h + NO_WERROR NO_UBUILD cocos/editor-support/spine/3.8/spine/ConstraintData.cpp + cocos/editor-support/spine/3.8/spine/ConstraintData.h + cocos/editor-support/spine/3.8/spine/ContainerUtil.h + NO_WERROR cocos/editor-support/spine/3.8/spine/CurveTimeline.cpp + cocos/editor-support/spine/3.8/spine/CurveTimeline.h + cocos/editor-support/spine/3.8/spine/Debug.h + NO_WERROR cocos/editor-support/spine/3.8/spine/DeformTimeline.cpp + cocos/editor-support/spine/3.8/spine/DeformTimeline.h + cocos/editor-support/spine/3.8/spine/dll.h + NO_WERROR cocos/editor-support/spine/3.8/spine/DrawOrderTimeline.cpp + cocos/editor-support/spine/3.8/spine/DrawOrderTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Event.cpp + cocos/editor-support/spine/3.8/spine/Event.h + NO_WERROR cocos/editor-support/spine/3.8/spine/EventData.cpp + cocos/editor-support/spine/3.8/spine/EventData.h + NO_WERROR cocos/editor-support/spine/3.8/spine/EventTimeline.cpp + cocos/editor-support/spine/3.8/spine/EventTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Extension.cpp + cocos/editor-support/spine/3.8/spine/Extension.h + cocos/editor-support/spine/3.8/spine/HashMap.h + cocos/editor-support/spine/3.8/spine/HasRendererObject.h + NO_WERROR cocos/editor-support/spine/3.8/spine/IkConstraint.cpp + cocos/editor-support/spine/3.8/spine/IkConstraint.h + NO_WERROR cocos/editor-support/spine/3.8/spine/IkConstraintData.cpp + cocos/editor-support/spine/3.8/spine/IkConstraintData.h + NO_WERROR cocos/editor-support/spine/3.8/spine/IkConstraintTimeline.cpp + cocos/editor-support/spine/3.8/spine/IkConstraintTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Json.cpp + cocos/editor-support/spine/3.8/spine/Json.h + NO_WERROR cocos/editor-support/spine/3.8/spine/LinkedMesh.cpp + cocos/editor-support/spine/3.8/spine/LinkedMesh.h + NO_WERROR cocos/editor-support/spine/3.8/spine/MathUtil.cpp + cocos/editor-support/spine/3.8/spine/MathUtil.h + NO_WERROR cocos/editor-support/spine/3.8/spine/MeshAttachment.cpp + cocos/editor-support/spine/3.8/spine/MeshAttachment.h + cocos/editor-support/spine/3.8/spine/MixBlend.h + cocos/editor-support/spine/3.8/spine/MixDirection.h + NO_WERROR cocos/editor-support/spine/3.8/spine/PathAttachment.cpp + cocos/editor-support/spine/3.8/spine/PathAttachment.h + NO_WERROR cocos/editor-support/spine/3.8/spine/PathConstraint.cpp + cocos/editor-support/spine/3.8/spine/PathConstraint.h + NO_WERROR cocos/editor-support/spine/3.8/spine/PathConstraintData.cpp + cocos/editor-support/spine/3.8/spine/PathConstraintData.h + NO_WERROR cocos/editor-support/spine/3.8/spine/PathConstraintMixTimeline.cpp + cocos/editor-support/spine/3.8/spine/PathConstraintMixTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/PathConstraintPositionTimeline.cpp + cocos/editor-support/spine/3.8/spine/PathConstraintPositionTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/PathConstraintSpacingTimeline.cpp + cocos/editor-support/spine/3.8/spine/PathConstraintSpacingTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/PointAttachment.cpp + cocos/editor-support/spine/3.8/spine/PointAttachment.h + cocos/editor-support/spine/3.8/spine/Pool.h + cocos/editor-support/spine/3.8/spine/PositionMode.h + NO_WERROR cocos/editor-support/spine/3.8/spine/RegionAttachment.cpp + cocos/editor-support/spine/3.8/spine/RegionAttachment.h + cocos/editor-support/spine/3.8/spine/RotateMode.h + NO_WERROR cocos/editor-support/spine/3.8/spine/RotateTimeline.cpp + cocos/editor-support/spine/3.8/spine/RotateTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/RTTI.cpp + cocos/editor-support/spine/3.8/spine/RTTI.h + NO_WERROR cocos/editor-support/spine/3.8/spine/ScaleTimeline.cpp + cocos/editor-support/spine/3.8/spine/ScaleTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/ShearTimeline.cpp + cocos/editor-support/spine/3.8/spine/ShearTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Skeleton.cpp + cocos/editor-support/spine/3.8/spine/Skeleton.h + NO_WERROR cocos/editor-support/spine/3.8/spine/SkeletonBinary.cpp + cocos/editor-support/spine/3.8/spine/SkeletonBinary.h + NO_WERROR cocos/editor-support/spine/3.8/spine/SkeletonBounds.cpp + cocos/editor-support/spine/3.8/spine/SkeletonBounds.h + NO_WERROR cocos/editor-support/spine/3.8/spine/SkeletonClipping.cpp + cocos/editor-support/spine/3.8/spine/SkeletonClipping.h + NO_WERROR cocos/editor-support/spine/3.8/spine/SkeletonData.cpp + cocos/editor-support/spine/3.8/spine/SkeletonData.h + NO_WERROR cocos/editor-support/spine/3.8/spine/SkeletonJson.cpp + cocos/editor-support/spine/3.8/spine/SkeletonJson.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Skin.cpp + cocos/editor-support/spine/3.8/spine/Skin.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Slot.cpp + cocos/editor-support/spine/3.8/spine/Slot.h + NO_WERROR cocos/editor-support/spine/3.8/spine/SlotData.cpp + cocos/editor-support/spine/3.8/spine/SlotData.h + cocos/editor-support/spine/3.8/spine/SpacingMode.h + cocos/editor-support/spine/3.8/spine/spine.h + NO_WERROR cocos/editor-support/spine/3.8/spine/SpineObject.cpp + cocos/editor-support/spine/3.8/spine/SpineObject.h + cocos/editor-support/spine/3.8/spine/SpineString.cpp + cocos/editor-support/spine/3.8/spine/SpineString.h + NO_WERROR cocos/editor-support/spine/3.8/spine/TextureLoader.cpp + cocos/editor-support/spine/3.8/spine/TextureLoader.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Timeline.cpp + cocos/editor-support/spine/3.8/spine/Timeline.h + cocos/editor-support/spine/3.8/spine/TimelineType.h + NO_WERROR cocos/editor-support/spine/3.8/spine/TransformConstraint.cpp + cocos/editor-support/spine/3.8/spine/TransformConstraint.h + NO_WERROR cocos/editor-support/spine/3.8/spine/TransformConstraintData.cpp + cocos/editor-support/spine/3.8/spine/TransformConstraintData.h + NO_WERROR cocos/editor-support/spine/3.8/spine/TransformConstraintTimeline.cpp + cocos/editor-support/spine/3.8/spine/TransformConstraintTimeline.h + cocos/editor-support/spine/3.8/spine/TransformMode.h + NO_WERROR cocos/editor-support/spine/3.8/spine/TranslateTimeline.cpp + cocos/editor-support/spine/3.8/spine/TranslateTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Triangulator.cpp + cocos/editor-support/spine/3.8/spine/Triangulator.h + NO_WERROR cocos/editor-support/spine/3.8/spine/TwoColorTimeline.cpp + cocos/editor-support/spine/3.8/spine/TwoColorTimeline.h + NO_WERROR cocos/editor-support/spine/3.8/spine/Updatable.cpp + cocos/editor-support/spine/3.8/spine/Updatable.h + cocos/editor-support/spine/3.8/spine/Vector.h + NO_WERROR cocos/editor-support/spine/3.8/spine/VertexAttachment.cpp + cocos/editor-support/spine/3.8/spine/VertexAttachment.h + NO_WERROR cocos/editor-support/spine/3.8/spine/VertexEffect.cpp + cocos/editor-support/spine/3.8/spine/VertexEffect.h + cocos/editor-support/spine/3.8/spine/Vertices.h NO_WERROR cocos/editor-support/spine-creator-support/VertexEffectDelegate.cpp cocos/editor-support/spine-creator-support/VertexEffectDelegate.h - cocos/editor-support/spine-creator-support/VertexEffectDelegate.h - NO_WERROR cocos/editor-support/spine-creator-support/Vector2.cpp - cocos/editor-support/spine-creator-support/Vector2.h ) cocos_source_files( - NO_WERROR ${SWIG_OUTPUT}/jsb_spine_auto.cpp - ${SWIG_OUTPUT}/jsb_spine_auto.h + NO_WERROR ${SWIG_OUTPUT}/jsb_spine_3_8_auto.cpp + ${SWIG_OUTPUT}/jsb_spine_3_8_auto.h NO_WERROR cocos/bindings/manual/jsb_spine_manual.cpp cocos/bindings/manual/jsb_spine_manual.h ) endif() + if(USE_SPINE_4_2) + include_directories(${CWD}/cocos/editor-support/spine/4.2) + cocos_source_files( + NO_WERROR NO_UBUILD cocos/editor-support/spine/4.2/spine/Animation.cpp + cocos/editor-support/spine/4.2/spine/Animation.h + NO_WERROR NO_UBUILD cocos/editor-support/spine/4.2/spine/AnimationState.cpp + cocos/editor-support/spine/4.2/spine/AnimationState.h + NO_WERROR cocos/editor-support/spine/4.2/spine/AnimationStateData.cpp + cocos/editor-support/spine/4.2/spine/AnimationStateData.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Atlas.cpp + cocos/editor-support/spine/4.2/spine/Atlas.h + NO_WERROR cocos/editor-support/spine/4.2/spine/AtlasAttachmentLoader.cpp + cocos/editor-support/spine/4.2/spine/AtlasAttachmentLoader.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Attachment.cpp + cocos/editor-support/spine/4.2/spine/Attachment.h + NO_WERROR cocos/editor-support/spine/4.2/spine/AttachmentLoader.cpp + cocos/editor-support/spine/4.2/spine/AttachmentLoader.h + NO_WERROR cocos/editor-support/spine/4.2/spine/AttachmentTimeline.cpp + cocos/editor-support/spine/4.2/spine/AttachmentTimeline.h + cocos/editor-support/spine/4.2/spine/AttachmentType.h + cocos/editor-support/spine/4.2/spine/BlendMode.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Bone.cpp + cocos/editor-support/spine/4.2/spine/Bone.h + NO_WERROR cocos/editor-support/spine/4.2/spine/BoneData.cpp + cocos/editor-support/spine/4.2/spine/BoneData.h + NO_WERROR cocos/editor-support/spine/4.2/spine/BoundingBoxAttachment.cpp + cocos/editor-support/spine/4.2/spine/BoundingBoxAttachment.h + NO_WERROR cocos/editor-support/spine/4.2/spine/ClippingAttachment.cpp + cocos/editor-support/spine/4.2/spine/ClippingAttachment.h + cocos/editor-support/spine/4.2/spine/Color.h + NO_WERROR cocos/editor-support/spine/4.2/spine/ColorTimeline.cpp + cocos/editor-support/spine/4.2/spine/ColorTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Constraint.cpp + cocos/editor-support/spine/4.2/spine/Constraint.h + NO_WERROR NO_UBUILD cocos/editor-support/spine/4.2/spine/ConstraintData.cpp + cocos/editor-support/spine/4.2/spine/ConstraintData.h + cocos/editor-support/spine/4.2/spine/ContainerUtil.h + NO_WERROR cocos/editor-support/spine/4.2/spine/CurveTimeline.cpp + cocos/editor-support/spine/4.2/spine/CurveTimeline.h + cocos/editor-support/spine/4.2/spine/Debug.h + NO_WERROR cocos/editor-support/spine/4.2/spine/DeformTimeline.cpp + cocos/editor-support/spine/4.2/spine/DeformTimeline.h + cocos/editor-support/spine/4.2/spine/dll.h + NO_WERROR cocos/editor-support/spine/4.2/spine/DrawOrderTimeline.cpp + cocos/editor-support/spine/4.2/spine/DrawOrderTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Event.cpp + cocos/editor-support/spine/4.2/spine/Event.h + NO_WERROR cocos/editor-support/spine/4.2/spine/EventData.cpp + cocos/editor-support/spine/4.2/spine/EventData.h + NO_WERROR cocos/editor-support/spine/4.2/spine/EventTimeline.cpp + cocos/editor-support/spine/4.2/spine/EventTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Extension.cpp + cocos/editor-support/spine/4.2/spine/Extension.h + cocos/editor-support/spine/4.2/spine/HashMap.h + cocos/editor-support/spine/4.2/spine/HasRendererObject.h + NO_WERROR cocos/editor-support/spine/4.2/spine/IkConstraint.cpp + cocos/editor-support/spine/4.2/spine/IkConstraint.h + NO_WERROR cocos/editor-support/spine/4.2/spine/IkConstraintData.cpp + cocos/editor-support/spine/4.2/spine/IkConstraintData.h + NO_WERROR cocos/editor-support/spine/4.2/spine/IkConstraintTimeline.cpp + cocos/editor-support/spine/4.2/spine/IkConstraintTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Json.cpp + cocos/editor-support/spine/4.2/spine/Json.h + NO_WERROR cocos/editor-support/spine/4.2/spine/LinkedMesh.cpp + cocos/editor-support/spine/4.2/spine/LinkedMesh.h + NO_WERROR cocos/editor-support/spine/4.2/spine/MathUtil.cpp + cocos/editor-support/spine/4.2/spine/MathUtil.h + NO_WERROR cocos/editor-support/spine/4.2/spine/MeshAttachment.cpp + cocos/editor-support/spine/4.2/spine/MeshAttachment.h + cocos/editor-support/spine/4.2/spine/MixBlend.h + cocos/editor-support/spine/4.2/spine/MixDirection.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PathAttachment.cpp + cocos/editor-support/spine/4.2/spine/PathAttachment.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PathConstraint.cpp + cocos/editor-support/spine/4.2/spine/PathConstraint.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PathConstraintData.cpp + cocos/editor-support/spine/4.2/spine/PathConstraintData.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PathConstraintMixTimeline.cpp + cocos/editor-support/spine/4.2/spine/PathConstraintMixTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PathConstraintPositionTimeline.cpp + cocos/editor-support/spine/4.2/spine/PathConstraintPositionTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PathConstraintSpacingTimeline.cpp + cocos/editor-support/spine/4.2/spine/PathConstraintSpacingTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PointAttachment.cpp + cocos/editor-support/spine/4.2/spine/PointAttachment.h + cocos/editor-support/spine/4.2/spine/Pool.h + cocos/editor-support/spine/4.2/spine/Physics.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Sequence.cpp + cocos/editor-support/spine/4.2/spine/Sequence.h + cocos/editor-support/spine/4.2/spine/SequenceTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/SequenceTimeline.cpp + cocos/editor-support/spine/4.2/spine/TextureRegion.h + cocos/editor-support/spine/4.2/spine/BlockAllocator.h + cocos/editor-support/spine/4.2/spine/Inherit.h + NO_WERROR cocos/editor-support/spine/4.2/spine/InheritTimeline.cpp + cocos/editor-support/spine/4.2/spine/InheritTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Log.cpp + cocos/editor-support/spine/4.2/spine/Log.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PhysicsConstraintData.cpp + cocos/editor-support/spine/4.2/spine/PhysicsConstraintData.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PhysicsConstraint.cpp + cocos/editor-support/spine/4.2/spine/PhysicsConstraint.h + NO_WERROR cocos/editor-support/spine/4.2/spine/PhysicsConstraintTimeline.cpp + cocos/editor-support/spine/4.2/spine/PhysicsConstraintTimeline.h + cocos/editor-support/spine/4.2/spine/Property.h + cocos/editor-support/spine/4.2/spine/Version.h + cocos/editor-support/spine/4.2/spine/PositionMode.h + NO_WERROR cocos/editor-support/spine/4.2/spine/RegionAttachment.cpp + cocos/editor-support/spine/4.2/spine/RegionAttachment.h + cocos/editor-support/spine/4.2/spine/RotateMode.h + NO_WERROR cocos/editor-support/spine/4.2/spine/RotateTimeline.cpp + cocos/editor-support/spine/4.2/spine/RotateTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/RTTI.cpp + cocos/editor-support/spine/4.2/spine/RTTI.h + NO_WERROR cocos/editor-support/spine/4.2/spine/ScaleTimeline.cpp + cocos/editor-support/spine/4.2/spine/ScaleTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/ShearTimeline.cpp + cocos/editor-support/spine/4.2/spine/ShearTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Skeleton.cpp + cocos/editor-support/spine/4.2/spine/Skeleton.h + NO_WERROR cocos/editor-support/spine/4.2/spine/SkeletonBinary.cpp + cocos/editor-support/spine/4.2/spine/SkeletonBinary.h + NO_WERROR cocos/editor-support/spine/4.2/spine/SkeletonBounds.cpp + cocos/editor-support/spine/4.2/spine/SkeletonBounds.h + NO_WERROR cocos/editor-support/spine/4.2/spine/SkeletonClipping.cpp + cocos/editor-support/spine/4.2/spine/SkeletonClipping.h + NO_WERROR cocos/editor-support/spine/4.2/spine/SkeletonData.cpp + cocos/editor-support/spine/4.2/spine/SkeletonData.h + NO_WERROR cocos/editor-support/spine/4.2/spine/SkeletonJson.cpp + cocos/editor-support/spine/4.2/spine/SkeletonJson.h + NO_WERROR cocos/editor-support/spine/4.2/spine/SkeletonRenderer.cpp + cocos/editor-support/spine/4.2/spine/SkeletonRenderer.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Skin.cpp + cocos/editor-support/spine/4.2/spine/Skin.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Slot.cpp + cocos/editor-support/spine/4.2/spine/Slot.h + NO_WERROR cocos/editor-support/spine/4.2/spine/SlotData.cpp + cocos/editor-support/spine/4.2/spine/SlotData.h + cocos/editor-support/spine/4.2/spine/SpacingMode.h + cocos/editor-support/spine/4.2/spine/spine.h + NO_WERROR cocos/editor-support/spine/4.2/spine/SpineObject.cpp + cocos/editor-support/spine/4.2/spine/SpineObject.h + cocos/editor-support/spine/4.2/spine/SpineString.cpp + cocos/editor-support/spine/4.2/spine/SpineString.h + NO_WERROR cocos/editor-support/spine/4.2/spine/TextureLoader.cpp + cocos/editor-support/spine/4.2/spine/TextureLoader.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Timeline.cpp + cocos/editor-support/spine/4.2/spine/Timeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/TransformConstraint.cpp + cocos/editor-support/spine/4.2/spine/TransformConstraint.h + NO_WERROR cocos/editor-support/spine/4.2/spine/TransformConstraintData.cpp + cocos/editor-support/spine/4.2/spine/TransformConstraintData.h + NO_WERROR cocos/editor-support/spine/4.2/spine/TransformConstraintTimeline.cpp + cocos/editor-support/spine/4.2/spine/TransformConstraintTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/TranslateTimeline.cpp + cocos/editor-support/spine/4.2/spine/TranslateTimeline.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Triangulator.cpp + cocos/editor-support/spine/4.2/spine/Triangulator.h + NO_WERROR cocos/editor-support/spine/4.2/spine/Updatable.cpp + cocos/editor-support/spine/4.2/spine/Updatable.h + cocos/editor-support/spine/4.2/spine/Vector.h + NO_WERROR cocos/editor-support/spine/4.2/spine/VertexAttachment.cpp + cocos/editor-support/spine/4.2/spine/VertexAttachment.h + cocos/editor-support/spine/4.2/spine/Vertices.h + + ) + cocos_source_files( + NO_WERROR ${SWIG_OUTPUT}/jsb_spine_4_2_auto.cpp + ${SWIG_OUTPUT}/jsb_spine_4_2_auto.h + NO_WERROR cocos/bindings/manual/jsb_spine_manual.cpp + cocos/bindings/manual/jsb_spine_manual.h + ) + endif() + + if(USE_SPINE) + cocos_source_files( + NO_WERROR cocos/editor-support/spine-creator-support/AttachmentVertices.cpp + cocos/editor-support/spine-creator-support/AttachmentVertices.h + NO_WERROR cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp + cocos/editor-support/spine-creator-support/SkeletonAnimation.h + NO_WERROR cocos/editor-support/spine-creator-support/SkeletonCache.cpp + cocos/editor-support/spine-creator-support/SkeletonCache.h + NO_WERROR cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp + cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.h + NO_WERROR cocos/editor-support/spine-creator-support/SkeletonCacheMgr.cpp + cocos/editor-support/spine-creator-support/SkeletonCacheMgr.h + NO_WERROR cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp + cocos/editor-support/spine-creator-support/SkeletonDataMgr.h + NO_WERROR NO_UBUILD cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp + cocos/editor-support/spine-creator-support/SkeletonRenderer.h + NO_WERROR cocos/editor-support/spine-creator-support/spine-cocos2dx.cpp + cocos/editor-support/spine-creator-support/spine-cocos2dx.h + NO_WERROR cocos/editor-support/spine-creator-support/Vector2.cpp + cocos/editor-support/spine-creator-support/Vector2.h + ) + endif() + if(USE_DRAGONBONES) cocos_source_files( cocos/editor-support/dragonbones/DragonBonesHeaders.h @@ -3169,6 +3356,8 @@ function(cc_apply_definations target) $,$>,$>,USE_V8_DEBUGGER=1,USE_V8_DEBUGGER=0> $,CC_USE_MIDDLEWARE=1,CC_USE_MIDDLEWARE=0> $,CC_USE_SPINE=1,CC_USE_SPINE=0> + $,CC_USE_SPINE_3_8=1,CC_USE_SPINE_3_8=0> + $,CC_USE_SPINE_4_2=1,CC_USE_SPINE_4_2=0> $,CC_USE_DRAGONBONES=1,CC_USE_DRAGONBONES=0> $,CC_USE_JOB_SYSTEM_TBB=1,CC_USE_JOB_SYSTEM_TBB=0> $,CC_USE_JOB_SYSTEM_TASKFLOW=1,CC_USE_JOB_SYSTEM_TASKFLOW=0> diff --git a/native/cocos/bindings/manual/jsb_module_register.cpp b/native/cocos/bindings/manual/jsb_module_register.cpp index 4b47dfba35..95f1a54bb5 100644 --- a/native/cocos/bindings/manual/jsb_module_register.cpp +++ b/native/cocos/bindings/manual/jsb_module_register.cpp @@ -114,7 +114,12 @@ #include "cocos/bindings/auto/jsb_editor_support_auto.h" #if CC_USE_SPINE - #include "cocos/bindings/auto/jsb_spine_auto.h" + #if CC_USE_SPINE_3_8 + #include "cocos/bindings/auto/jsb_spine_3_8_auto.h" + #elif CC_USE_SPINE_4_2 + #include "cocos/bindings/auto/jsb_spine_4_2_auto.h" + #endif + #include "cocos/bindings/manual/jsb_spine_manual.h" #endif diff --git a/native/cocos/bindings/manual/jsb_spine_manual.cpp b/native/cocos/bindings/manual/jsb_spine_manual.cpp index 4bc5f5fbb6..ca7f07f5ee 100644 --- a/native/cocos/bindings/manual/jsb_spine_manual.cpp +++ b/native/cocos/bindings/manual/jsb_spine_manual.cpp @@ -25,13 +25,19 @@ #include "jsb_spine_manual.h" #include "base/Data.h" #include "base/memory/Memory.h" -#include "bindings/auto/jsb_spine_auto.h" + #include "bindings/jswrapper/SeApi.h" #include "bindings/manual/jsb_conversions.h" #include "bindings/manual/jsb_global.h" #include "bindings/manual/jsb_helper.h" #include "editor-support/spine-creator-support/spine-cocos2dx.h" -#include "editor-support/spine/spine.h" +#if CC_USE_SPINE_3_8 + #include "bindings/auto/jsb_spine_3_8_auto.h" + #include "editor-support/spine/3.8/spine/spine.h" +#else + #include "bindings/auto/jsb_spine_4_2_auto.h" + #include "editor-support/spine/4.2/spine/spine.h" +#endif #include "middleware-adapter.h" #include "platform/FileUtils.h" #include "spine-creator-support/SkeletonDataMgr.h" @@ -41,7 +47,7 @@ using namespace cc; -static spine::Cocos2dTextureLoader textureLoader; +static cc::Cocos2dTextureLoader textureLoader; static cc::RefMap *_preloadedAtlasTextures = nullptr; static middleware::Texture2D *_getPreloadedAtlasTexture(const char *path) { CC_ASSERT(_preloadedAtlasTextures); @@ -62,7 +68,7 @@ static bool js_register_spine_initSkeletonData(se::State &s) { ok = sevalue_to_native(args[0], &uuid); SE_PRECONDITION2(ok, false, "Invalid uuid content!"); - auto mgr = spine::SkeletonDataMgr::getInstance(); + auto mgr = SkeletonDataMgr::getInstance(); bool hasSkeletonData = mgr->hasSkeletonData(uuid); if (hasSkeletonData) { spine::SkeletonData *skeletonData = mgr->retainByUUID(uuid); @@ -89,14 +95,14 @@ static bool js_register_spine_initSkeletonData(se::State &s) { // create atlas from preloaded texture _preloadedAtlasTextures = &textures; - spine::spAtlasPage_setCustomTextureLoader(_getPreloadedAtlasTexture); + spAtlasPage_setCustomTextureLoader(_getPreloadedAtlasTexture); spine::Atlas *atlas = ccnew_placement(__FILE__, __LINE__) spine::Atlas(atlasText.c_str(), (int)atlasText.size(), "", &textureLoader); _preloadedAtlasTextures = nullptr; - spine::spAtlasPage_setCustomTextureLoader(nullptr); + spAtlasPage_setCustomTextureLoader(nullptr); - spine::AttachmentLoader *attachmentLoader = ccnew_placement(__FILE__, __LINE__) spine::Cocos2dAtlasAttachmentLoader(atlas); + spine::AttachmentLoader *attachmentLoader = ccnew_placement(__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(atlas); spine::SkeletonData *skeletonData = nullptr; std::size_t length = skeletonDataFile.length(); @@ -113,13 +119,15 @@ static bool js_register_spine_initSkeletonData(se::State &s) { spine::SkeletonBinary binary(attachmentLoader); binary.setScale(scale); skeletonData = binary.readSkeletonData(cocos2dData.getBytes(), (int)cocos2dData.getSize()); - CC_ASSERT(skeletonData); // Can use binary.getError() to get error message. + const auto &errorMsg = binary.getError(); + CC_ASSERTF(skeletonData, "Spine parse error: %s", errorMsg.buffer()); } } else { spine::SkeletonJson json(attachmentLoader); json.setScale(scale); skeletonData = json.readSkeletonData(skeletonDataFile.c_str()); - CC_ASSERT(skeletonData); // Can use json.getError() to get error message. + const auto &errorMsg = json.getError(); + CC_ASSERTF(skeletonData, "Spine parse error: %s", errorMsg.buffer()); } if (skeletonData) { @@ -156,7 +164,7 @@ static bool js_register_spine_disposeSkeletonData(se::State &s) { ok = sevalue_to_native(args[0], &uuid); SE_PRECONDITION2(ok, false, "Invalid uuid content!"); - auto mgr = spine::SkeletonDataMgr::getInstance(); + auto mgr = SkeletonDataMgr::getInstance(); bool hasSkeletonData = mgr->hasSkeletonData(uuid); if (!hasSkeletonData) return true; mgr->releaseByUUID(uuid); @@ -174,7 +182,7 @@ static bool js_register_spine_initSkeletonRenderer(se::State &s) { } bool ok = false; - spine::SkeletonRenderer *node = nullptr; + cc::SkeletonRenderer *node = nullptr; ok = seval_to_native_ptr(args[0], &node); SE_PRECONDITION2(ok, false, "Converting SpineRenderer failed!"); @@ -182,7 +190,7 @@ static bool js_register_spine_initSkeletonRenderer(se::State &s) { ok = sevalue_to_native(args[1], &uuid); SE_PRECONDITION2(ok, false, "Invalid uuid content!"); - auto mgr = spine::SkeletonDataMgr::getInstance(); + auto mgr = SkeletonDataMgr::getInstance(); bool hasSkeletonData = mgr->hasSkeletonData(uuid); if (hasSkeletonData) { node->initWithUUID(uuid); @@ -204,7 +212,7 @@ static bool js_register_spine_retainSkeletonData(se::State &s) { ok = sevalue_to_native(args[0], &uuid); SE_PRECONDITION2(ok, false, "Invalid uuid content!"); - auto mgr = spine::SkeletonDataMgr::getInstance(); + auto mgr = SkeletonDataMgr::getInstance(); bool hasSkeletonData = mgr->hasSkeletonData(uuid); if (hasSkeletonData) { spine::SkeletonData *skeletonData = mgr->retainByUUID(uuid); @@ -270,12 +278,20 @@ static bool js_RegionAttachment_computeWorldVertices(se::State &s) { spine::RegionAttachment *regionAttachment = SE_THIS_OBJECT(s); if (nullptr == regionAttachment) return true; +#if CC_USE_SPINE_3_8 spine::Bone *bone = nullptr; +#else + spine::Slot *slot = nullptr; +#endif size_t offset = 0, stride = 0; se::Value worldVerticesVal; bool ok = false; +#if CC_USE_SPINE_3_8 ok = sevalue_to_native(args[0], &bone, s.thisObject()); +#else + ok = sevalue_to_native(args[0], &slot, s.thisObject()); +#endif SE_PRECONDITION2(ok, false, "Error processing arguments"); ok = sevalue_to_native(args[1], &worldVerticesVal, s.thisObject()); @@ -291,12 +307,20 @@ static bool js_RegionAttachment_computeWorldVertices(se::State &s) { uint8_t* ptr = nullptr; size_t len = 0; worldVerticesVal.toObject()->getTypedArrayData(&ptr, &len); - regionAttachment->computeWorldVertices(*bone, reinterpret_cast(ptr), offset, stride); +#if CC_USE_SPINE_3_8 + regionAttachment->computeWorldVertices(*bone, reinterpret_cast(ptr), offset, stride); +#else + regionAttachment->computeWorldVertices(*slot, reinterpret_cast(ptr), offset, stride); +#endif } else if (worldVerticesVal.toObject()->isArray()) { spine::Vector worldVertices; int count = 8; worldVertices.ensureCapacity(count); +#if CC_USE_SPINE_3_8 regionAttachment->computeWorldVertices(*bone, worldVertices, 0); +#else + regionAttachment->computeWorldVertices(*slot, worldVertices, 0); +#endif int curr = offset; worldVerticesVal.toObject()->setArrayElement(curr, se::Value(worldVertices[0])); @@ -444,6 +468,7 @@ static bool js_Skin_findAttachmentsForSlot(se::State &s) { } SE_BIND_FUNC(js_Skin_findAttachmentsForSlot) +#if CC_USE_SPINE_3_8 static bool js_VertexEffect_transform(se::State &s) { const auto &args = s.args(); spine::VertexEffect* effect = SE_THIS_OBJECT(s); @@ -485,6 +510,7 @@ static bool js_JitterVertexEffect_transform(se::State &s) { return true; } SE_BIND_FUNC(js_JitterVertexEffect_transform) +#endif static bool js_spine_Skin_getAttachments(se::State& s) { CC_UNUSED bool ok = true; @@ -577,14 +603,16 @@ bool register_all_spine_manual(se::Object *obj) { __jsb_spine_Bone_proto->defineFunction("worldToLocal", _SE(js_Bone_worldToLocal)); __jsb_spine_Bone_proto->defineFunction("localToWorld", _SE(js_Bone_localToWorld)); __jsb_spine_PointAttachment_proto->defineFunction("computeWorldPosition", _SE(js_PointAttachment_computeWorldPosition)); +#if CC_USE_SPINE_3_8 __jsb_spine_VertexEffect_proto->defineFunction("transform", _SE(js_VertexEffect_transform)); __jsb_spine_SwirlVertexEffect_proto->defineFunction("transform", _SE(js_SwirlVertexEffect_transform)); __jsb_spine_JitterVertexEffect_proto->defineFunction("transform", _SE(js_JitterVertexEffect_transform)); +#endif __jsb_spine_Skin_proto->defineFunction("getAttachments", _SE(js_spine_Skin_getAttachments)); __jsb_spine_Slot_proto->defineFunction("setAttachment", _SE(js_spine_Slot_setAttachment)); __jsb_spine_Slot_proto->defineFunction("getAttachment", _SE(js_spine_Slot_getAttachment)); - spine::setSpineObjectDisposeCallback([](void *spineObj) { + cc::setSpineObjectDisposeCallback([](void *spineObj) { if (!se::NativePtrToObjectMap::isValid()) { return; } @@ -600,7 +628,7 @@ bool register_all_spine_manual(se::Object *obj) { }); se::ScriptEngine::getInstance()->addBeforeCleanupHook([]() { - spine::SkeletonDataMgr::destroyInstance(); + SkeletonDataMgr::destroyInstance(); }); se::ScriptEngine::getInstance()->clearException(); diff --git a/native/cocos/editor-support/spine-creator-support/AttachmentVertices.cpp b/native/cocos/editor-support/spine-creator-support/AttachmentVertices.cpp index e71ae64f0e..80d975390d 100644 --- a/native/cocos/editor-support/spine-creator-support/AttachmentVertices.cpp +++ b/native/cocos/editor-support/spine-creator-support/AttachmentVertices.cpp @@ -31,7 +31,7 @@ using namespace cc; // NOLINT(google-build-using-namespace) -namespace spine { +namespace cc { AttachmentVertices::AttachmentVertices(middleware::Texture2D *texture, int verticesCount, uint16_t *triangles, int trianglesCount) { _texture = texture; @@ -55,4 +55,4 @@ AttachmentVertices *AttachmentVertices::copy() { return atv; } -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/AttachmentVertices.h b/native/cocos/editor-support/spine-creator-support/AttachmentVertices.h index 6d2c5a36ef..fde45f375b 100644 --- a/native/cocos/editor-support/spine-creator-support/AttachmentVertices.h +++ b/native/cocos/editor-support/spine-creator-support/AttachmentVertices.h @@ -32,7 +32,7 @@ #include "base/Macros.h" #include "middleware-adapter.h" -namespace spine { +namespace cc { /** * Store attachment vertex and indice list */ @@ -45,4 +45,4 @@ public: cc::middleware::Texture2D *_texture = nullptr; cc::middleware::Triangles *_triangles = nullptr; }; -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp index 79636f7c87..d3b60c17ba 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp @@ -34,7 +34,7 @@ #include "spine-creator-support/spine-cocos2dx.h" #include "spine/Extension.h" -namespace spine { +namespace cc { struct TrackEntryListeners { StartListener startListener; @@ -53,7 +53,7 @@ void trackEntryCallback(AnimationState *state, EventType type, TrackEntry *entry (static_cast(state->getRendererObject()))->onTrackEntryEvent(entry, type, event); if (type == EventType_Dispose) { if (entry->getRendererObject()) { - delete static_cast(entry->getRendererObject()); + delete static_cast(entry->getRendererObject()); entry->setRendererObject(nullptr); } } @@ -61,7 +61,7 @@ void trackEntryCallback(AnimationState *state, EventType type, TrackEntry *entry static TrackEntryListeners *getListeners(TrackEntry *entry) { if (!entry->getRendererObject()) { - entry->setRendererObject(new spine::TrackEntryListeners()); + entry->setRendererObject(new TrackEntryListeners()); entry->setListener(trackEntryCallback); } return static_cast(entry->getRendererObject()); @@ -127,7 +127,11 @@ void SkeletonAnimation::update(float deltaTime) { if (_ownsSkeleton) _skeleton->update(deltaTime); _state->update(deltaTime); _state->apply(*_skeleton); +#if CC_USE_SPINE_3_8 _skeleton->updateWorldTransform(); +#else + _skeleton->updateWorldTransform(Physics::Physics_Update); +#endif } } @@ -323,4 +327,4 @@ AnimationState *SkeletonAnimation::getState() const { return _state; } -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.h b/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.h index 93eb7ab630..af53afaf60 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.h +++ b/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.h @@ -31,37 +31,37 @@ #include "spine-creator-support/SkeletonRenderer.h" #include "spine/spine.h" -namespace spine { +namespace cc { -typedef std::function StartListener; -typedef std::function InterruptListener; -typedef std::function EndListener; -typedef std::function DisposeListener; -typedef std::function CompleteListener; -typedef std::function EventListener; +typedef std::function StartListener; +typedef std::function InterruptListener; +typedef std::function EndListener; +typedef std::function DisposeListener; +typedef std::function CompleteListener; +typedef std::function EventListener; /** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be * played later. */ -class SkeletonAnimation : public SkeletonRenderer { +class SkeletonAnimation : public cc::SkeletonRenderer { public: static SkeletonAnimation *create(); - static SkeletonAnimation *createWithData(SkeletonData *skeletonData, bool ownsSkeletonData = false); + static SkeletonAnimation *createWithData(spine::SkeletonData *skeletonData, bool ownsSkeletonData = false); static SkeletonAnimation *createWithJsonFile(const std::string &skeletonJsonFile, const std::string &atlasFile, float scale = 1); static SkeletonAnimation *createWithBinaryFile(const std::string &skeletonBinaryFile, const std::string &atlasFile, float scale = 1); static void setGlobalTimeScale(float timeScale); virtual void update(float deltaTime) override; - void setAnimationStateData(AnimationStateData *stateData); + void setAnimationStateData(spine::AnimationStateData *stateData); void setMix(const std::string &fromAnimation, const std::string &toAnimation, float duration); - TrackEntry *setAnimation(int trackIndex, const std::string &name, bool loop); - TrackEntry *addAnimation(int trackIndex, const std::string &name, bool loop, float delay = 0); - TrackEntry *setEmptyAnimation(int trackIndex, float mixDuration); + spine::TrackEntry *setAnimation(int trackIndex, const std::string &name, bool loop); + spine::TrackEntry *addAnimation(int trackIndex, const std::string &name, bool loop, float delay = 0); + spine::TrackEntry *setEmptyAnimation(int trackIndex, float mixDuration); void setEmptyAnimations(float mixDuration); - TrackEntry *addEmptyAnimation(int trackIndex, float mixDuration, float delay = 0); - Animation *findAnimation(const std::string &name) const; - TrackEntry *getCurrent(int trackIndex = 0); + spine::TrackEntry *addEmptyAnimation(int trackIndex, float mixDuration, float delay = 0); + spine::Animation *findAnimation(const std::string &name) const; + spine::TrackEntry *getCurrent(int trackIndex = 0); void clearTracks(); void clearTrack(int trackIndex = 0); @@ -72,17 +72,17 @@ public: void setCompleteListener(const CompleteListener &listener); void setEventListener(const EventListener &listener); - void setTrackStartListener(TrackEntry *entry, const StartListener &listener); - void setTrackInterruptListener(TrackEntry *entry, const InterruptListener &listener); - void setTrackEndListener(TrackEntry *entry, const EndListener &listener); - void setTrackDisposeListener(TrackEntry *entry, const DisposeListener &listener); - void setTrackCompleteListener(TrackEntry *entry, const CompleteListener &listener); - void setTrackEventListener(TrackEntry *entry, const EventListener &listener); + void setTrackStartListener(spine::TrackEntry *entry, const StartListener &listener); + void setTrackInterruptListener(spine::TrackEntry *entry, const InterruptListener &listener); + void setTrackEndListener(spine::TrackEntry *entry, const EndListener &listener); + void setTrackDisposeListener(spine::TrackEntry *entry, const DisposeListener &listener); + void setTrackCompleteListener(spine::TrackEntry *entry, const CompleteListener &listener); + void setTrackEventListener(spine::TrackEntry *entry, const EventListener &listener); - virtual void onAnimationStateEvent(TrackEntry *entry, EventType type, Event *event); - virtual void onTrackEntryEvent(TrackEntry *entry, EventType type, Event *event); + virtual void onAnimationStateEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); + virtual void onTrackEntryEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); - AnimationState *getState() const; + spine::AnimationState *getState() const; SkeletonAnimation(); virtual ~SkeletonAnimation(); @@ -92,7 +92,7 @@ public: static float GlobalTimeScale; protected: - AnimationState *_state = nullptr; + spine::AnimationState *_state = nullptr; bool _ownsAnimationStateData = false; StartListener _startListener = nullptr; InterruptListener _interruptListener = nullptr; @@ -102,7 +102,7 @@ protected: EventListener _eventListener = nullptr; private: - typedef SkeletonRenderer super; + typedef cc::SkeletonRenderer super; }; -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonCache.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonCache.cpp index 703f430924..446bdeb96b 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonCache.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonCache.cpp @@ -33,8 +33,8 @@ USING_NS_MW; // NOLINT(google-build-using-namespace) using namespace cc; // NOLINT(google-build-using-namespace) - -namespace spine { +using namespace spine; +namespace cc { float SkeletonCache::FrameTime = 1.0F / 60.0F; float SkeletonCache::MaxCacheTime = 120.0F; @@ -192,7 +192,11 @@ void SkeletonCache::update(float deltaTime) { if (_ownsSkeleton) _skeleton->update(deltaTime); _state->update(deltaTime); _state->apply(*_skeleton); +#if CC_USE_SPINE_3_8 _skeleton->updateWorldTransform(); +#else + _skeleton->updateWorldTransform(Physics::Physics_Update); +#endif } void SkeletonCache::updateToFrame(const std::string &animationName, int toFrameIdx /*= -1*/) { @@ -325,7 +329,11 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) { spine::Color attachmentColor; if (slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) { auto *attachment = dynamic_cast(slot->getAttachment()); +#if CC_USE_SPINE_3_8 attachmentVertices = static_cast(attachment->getRendererObject()); +#else + attachmentVertices = static_cast(attachment->getRegion()->rendererObject); +#endif // Early exit if attachment is invisible if (attachment->getColor().a == 0) { @@ -340,7 +348,11 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) { for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) { trianglesTwoColor.verts[ii].texCoord = attachmentVertices->_triangles->verts[ii].texCoord; } +#if CC_USE_SPINE_3_8 attachment->computeWorldVertices(slot->getBone(), reinterpret_cast(trianglesTwoColor.verts), 0, vs2); +#else + attachment->computeWorldVertices(*slot, reinterpret_cast(trianglesTwoColor.verts), 0, vs2); +#endif trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount; ibSize = static_cast(trianglesTwoColor.indexCount * sizeof(uint16_t)); @@ -352,7 +364,11 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) { } else if (slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) { auto *attachment = dynamic_cast(slot->getAttachment()); +#if CC_USE_SPINE_3_8 attachmentVertices = static_cast(attachment->getRendererObject()); +#else + attachmentVertices = static_cast(attachment->getRegion()->rendererObject); +#endif // Early exit if attachment is invisible if (attachment->getColor().a == 0) { @@ -543,4 +559,4 @@ void SkeletonCache::resetAnimationData(const std::string &animationName) { } } } -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonCache.h b/native/cocos/editor-support/spine-creator-support/SkeletonCache.h index 424e8cfa9e..b6fc76cf44 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonCache.h +++ b/native/cocos/editor-support/spine-creator-support/SkeletonCache.h @@ -34,7 +34,7 @@ #include "SkeletonAnimation.h" #include "middleware-adapter.h" -namespace spine { +namespace cc { class SkeletonCache : public SkeletonAnimation { public: struct SegmentData { @@ -134,7 +134,7 @@ public: virtual void stopSchedule() override {} virtual void update(float deltaTime) override; virtual void render(float deltaTime) override {} - virtual void onAnimationStateEvent(TrackEntry *entry, EventType type, Event *event) override; + virtual void onAnimationStateEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event) override; void updateToFrame(const std::string &animationName, int toFrameIdx = -1); // if animation data is empty, it will build new one. @@ -154,4 +154,4 @@ private: std::string _curAnimationName = ""; std::map _animationCaches; }; -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp index b65d6a736d..d2c9e8f2cc 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp @@ -43,10 +43,11 @@ USING_NS_MW; // NOLINT(google-build-using-namespace) using namespace cc; // NOLINT(google-build-using-namespace) using namespace cc::gfx; // NOLINT(google-build-using-namespace) +using namespace spine; static const std::string TECH_STAGE = "opaque"; static const std::string TEXTURE_KEY = "texture"; -namespace spine { +namespace cc { SkeletonCacheAnimation::SkeletonCacheAnimation(const std::string &uuid, bool isShare) { if (isShare) { @@ -601,4 +602,4 @@ cc::Material *SkeletonCacheAnimation::requestMaterial(uint16_t blendSrc, uint16_ return _materialCaches[key]; } -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.h b/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.h index 94f247d61b..884691a3b9 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.h +++ b/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.h @@ -41,7 +41,7 @@ class RenderDrawInfo; class Material; }; -namespace spine { +namespace cc { class SkeletonCacheAnimation : public cc::RefCounted, public cc::middleware::IMiddleware { public: @@ -51,20 +51,20 @@ public: void update(float dt) override; void render(float dt) override; - Skeleton *getSkeleton() const; + spine::Skeleton *getSkeleton() const; void setTimeScale(float scale); float getTimeScale() const; void paused(bool value); - Bone *findBone(const std::string &boneName) const; - Slot *findSlot(const std::string &slotName) const; + spine::Bone *findBone(const std::string &boneName) const; + spine::Slot *findSlot(const std::string &slotName) const; void setSkin(const std::string &skinName); void setSkin(const char *skinName); - Attachment *getAttachment(const std::string &slotName, const std::string &attachmentName) const; + spine::Attachment *getAttachment(const std::string &slotName, const std::string &attachmentName) const; bool setAttachment(const std::string &slotName, const std::string &attachmentName); bool setAttachment(const std::string &slotName, const char *attachmentName); void setColor(float r, float g, float b, float a); @@ -82,7 +82,7 @@ public: void setAnimation(const std::string &name, bool loop); void addAnimation(const std::string &name, bool loop, float delay = 0); - Animation *findAnimation(const std::string &name) const; + spine::Animation *findAnimation(const std::string &name) const; using CacheFrameEvent = std::function; void setStartListener(const CacheFrameEvent &listener); @@ -143,4 +143,4 @@ private: ccstd::unordered_map _materialCaches; bool _needClearMaterialCaches = false; }; -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonCacheMgr.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonCacheMgr.cpp index 85bfeca2c7..381bcb547e 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonCacheMgr.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonCacheMgr.cpp @@ -30,7 +30,7 @@ #include "SkeletonCacheMgr.h" #include "base/DeferredReleasePool.h" -namespace spine { +namespace cc { SkeletonCacheMgr *SkeletonCacheMgr::instance = nullptr; SkeletonCache *SkeletonCacheMgr::buildSkeletonCache(const std::string &uuid) { SkeletonCache *animation = _caches.at(uuid); @@ -50,4 +50,4 @@ void SkeletonCacheMgr::removeSkeletonCache(const std::string &uuid) { _caches.erase(it); } } -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonCacheMgr.h b/native/cocos/editor-support/spine-creator-support/SkeletonCacheMgr.h index 12421c1a02..754b5531f9 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonCacheMgr.h +++ b/native/cocos/editor-support/spine-creator-support/SkeletonCacheMgr.h @@ -31,7 +31,7 @@ #include "SkeletonCache.h" #include "base/RefMap.h" -namespace spine { +namespace cc { class SkeletonCacheMgr { public: @@ -50,11 +50,11 @@ public: } void removeSkeletonCache(const std::string &uuid); - SkeletonCache *buildSkeletonCache(const std::string &uuid); + cc::SkeletonCache *buildSkeletonCache(const std::string &uuid); private: static SkeletonCacheMgr *instance; cc::RefMap _caches; }; -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp index 1f02e7df75..ac80cf9cb4 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp @@ -32,8 +32,11 @@ #include using namespace spine; //NOLINT +using namespace cc; //NOLINT -namespace spine { +namespace cc { + +class AttachmentVertices; class SkeletonDataInfo { public: @@ -46,6 +49,17 @@ public: } if (atlas) { +#if CC_USE_SPINE_4_2 + auto ®ions = atlas->getRegions(); + int size = regions.size(); + for (int i = 0; i < size; i++) { + auto *region = regions[i]; + if (region->rendererObject) { + delete static_cast(region->rendererObject); + region->rendererObject = nullptr; + } + } +#endif delete atlas; atlas = nullptr; } @@ -62,7 +76,7 @@ public: std::vector texturesIndex; }; -} // namespace spine +} // namespace cc SkeletonDataMgr *SkeletonDataMgr::instance = nullptr; diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.h b/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.h index 197a881060..8fdba3615a 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.h +++ b/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.h @@ -37,7 +37,8 @@ #include "spine/SkeletonData.h" #include "spine/spine.h" -namespace spine { +using namespace spine; +namespace cc { class SkeletonDataInfo; @@ -81,4 +82,4 @@ private: std::map _dataMap; }; -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp index 21d248e932..02c6864388 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp @@ -55,7 +55,7 @@ using std::min; static const std::string TECH_STAGE = "opaque"; static const std::string TEXTURE_KEY = "texture"; -static spine::Cocos2dTextureLoader textureLoader; +static Cocos2dTextureLoader textureLoader; static std::vector _slotTextureSet{}; enum DebugType { @@ -64,6 +64,8 @@ enum DebugType { MESH, BONES }; + +namespace cc { SkeletonRenderer *SkeletonRenderer::create() { return new SkeletonRenderer(); } @@ -91,7 +93,11 @@ void SkeletonRenderer::initialize() { } _skeleton->setToSetupPose(); +#if CC_USE_SPINE_3_8 _skeleton->updateWorldTransform(); +#else + _skeleton->updateWorldTransform(spine::Physics::Physics_Pose); +#endif } void SkeletonRenderer::beginSchedule() { @@ -138,7 +144,9 @@ SkeletonRenderer::SkeletonRenderer(const std::string &skeletonDataFile, const st } SkeletonRenderer::~SkeletonRenderer() { +#if CC_USE_SPINE_3_8 CC_SAFE_RELEASE(_effectDelegate); +#endif if (_ownsSkeletonData) delete _skeleton->getData(); if (_ownsSkeleton) delete _skeleton; if (_ownsAtlas && _atlas) delete _atlas; @@ -354,8 +362,8 @@ void SkeletonRenderer::render(float /*deltaTime*/) { } auto *material = requestMaterial(curBlendSrc, curBlendDst); curDrawInfo->setMaterial(material); - gfx::Texture *texture = curTexture->getGFXTexture(); - gfx::Sampler *sampler = curTexture->getGFXSampler(); + gfx::Texture *texture = curTexture ? curTexture->getGFXTexture() : nullptr; + gfx::Sampler *sampler = curTexture? curTexture->getGFXSampler() : nullptr; curDrawInfo->setTexture(texture); curDrawInfo->setSampler(sampler); auto *uiMeshBuffer = mb->getUIMeshBuffer(); @@ -371,6 +379,7 @@ void SkeletonRenderer::render(float /*deltaTime*/) { materialLen++; }; +#if CC_USE_SPINE_3_8 VertexEffect *effect = nullptr; if (_effectDelegate) { effect = _effectDelegate->getVertexEffect(); @@ -379,6 +388,9 @@ void SkeletonRenderer::render(float /*deltaTime*/) { if (effect) { effect->begin(*_skeleton); } +#else + void *effect = nullptr; +#endif auto &drawOrder = _skeleton->getDrawOrder(); for (size_t i = 0, n = drawOrder.size(); i < n; ++i) { @@ -412,7 +424,11 @@ void SkeletonRenderer::render(float /*deltaTime*/) { if (slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) { auto *attachment = dynamic_cast(slot->getAttachment()); +#if CC_USE_SPINE_3_8 attachmentVertices = reinterpret_cast(attachment->getRendererObject()); +#else + attachmentVertices = reinterpret_cast(attachment->getRegion()->rendererObject); +#endif // Early exit if attachment is invisible if (attachment->getColor().a == 0) { @@ -426,7 +442,11 @@ void SkeletonRenderer::render(float /*deltaTime*/) { isFull |= vb.checkSpace(vbSize, true); triangles.verts = reinterpret_cast(vb.getCurBuffer()); memcpy(static_cast(triangles.verts), static_cast(attachmentVertices->_triangles->verts), vbSize); +#if CC_USE_SPINE_3_8 attachment->computeWorldVertices(slot->getBone(), reinterpret_cast(triangles.verts), 0, vs1); +#else + attachment->computeWorldVertices(*slot, reinterpret_cast(triangles.verts), 0, vs1); +#endif triangles.indexCount = attachmentVertices->_triangles->indexCount; ibSize = triangles.indexCount * sizeof(uint16_t); @@ -441,7 +461,11 @@ void SkeletonRenderer::render(float /*deltaTime*/) { for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) { trianglesTwoColor.verts[ii].texCoord = attachmentVertices->_triangles->verts[ii].texCoord; } +#if CC_USE_SPINE_3_8 attachment->computeWorldVertices(slot->getBone(), reinterpret_cast(trianglesTwoColor.verts), 0, vs2); +#else + attachment->computeWorldVertices(*slot, reinterpret_cast(trianglesTwoColor.verts), 0, vs2); +#endif trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount; ibSize = trianglesTwoColor.indexCount * sizeof(uint16_t); @@ -469,7 +493,11 @@ void SkeletonRenderer::render(float /*deltaTime*/) { } } else if (slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) { auto *attachment = dynamic_cast(slot->getAttachment()); +#if CC_USE_SPINE_3_8 attachmentVertices = static_cast(attachment->getRendererObject()); +#else + attachmentVertices = static_cast(attachment->getRegion()->rendererObject); +#endif // Early exit if attachment is invisible if (attachment->getColor().a == 0) { @@ -533,6 +561,17 @@ void SkeletonRenderer::render(float /*deltaTime*/) { } } + } else if (slot->getAttachment()->getRTTI().isExactly(PathAttachment::rtti)) { + auto *pathAttachment = dynamic_cast(slot->getAttachment()); +#if CC_USE_SPINE_4_2 + if (pathAttachment->getColor().a == 0) { + _clipper->clipEnd(*slot); + continue; + } +#endif + + // TODO: implement PathAttachment + //auto &transform = slot->getBone().getWorldTransform(); } else if (slot->getAttachment()->getRTTI().isExactly(ClippingAttachment::rtti)) { auto *clip = dynamic_cast(slot->getAttachment()); _clipper->clipStart(*slot, clip); @@ -600,6 +639,7 @@ void SkeletonRenderer::render(float /*deltaTime*/) { float *uvs = _clipper->getClippedUVs().buffer(); if (effect) { +#if CC_USE_SPINE_3_8 for (int v = 0, vn = triangles.vertCount, vv = 0; v < vn; ++v, vv += 2) { V3F_T2F_C4B *vertex = triangles.verts + v; vertex->vertex.x = verts[vv]; @@ -609,6 +649,7 @@ void SkeletonRenderer::render(float /*deltaTime*/) { effect->transform(vertex->vertex.x, vertex->vertex.y); vertex->color = light; } +#endif } else { for (int v = 0, vn = triangles.vertCount, vv = 0; v < vn; ++v, vv += 2) { V3F_T2F_C4B *vertex = triangles.verts + v; @@ -622,11 +663,13 @@ void SkeletonRenderer::render(float /*deltaTime*/) { // No cliping logic } else { if (effect) { +#if CC_USE_SPINE_3_8 for (int v = 0, vn = triangles.vertCount; v < vn; ++v) { V3F_T2F_C4B *vertex = triangles.verts + v; effect->transform(vertex->vertex.x, vertex->vertex.y); vertex->color = light; } +#endif } else { for (int v = 0, vn = triangles.vertCount; v < vn; ++v) { V3F_T2F_C4B *vertex = triangles.verts + v; @@ -669,6 +712,7 @@ void SkeletonRenderer::render(float /*deltaTime*/) { float *uvs = _clipper->getClippedUVs().buffer(); if (effect) { +#if CC_USE_SPINE_3_8 for (int v = 0, vn = trianglesTwoColor.vertCount, vv = 0; v < vn; ++v, vv += 2) { V3F_T2F_C4B_C4B *vertex = trianglesTwoColor.verts + v; vertex->vertex.x = verts[vv]; @@ -679,6 +723,7 @@ void SkeletonRenderer::render(float /*deltaTime*/) { vertex->color = light; vertex->color2 = dark; } +#endif } else { for (int v = 0, vn = trianglesTwoColor.vertCount, vv = 0; v < vn; ++v, vv += 2) { V3F_T2F_C4B_C4B *vertex = trianglesTwoColor.verts + v; @@ -692,12 +737,14 @@ void SkeletonRenderer::render(float /*deltaTime*/) { } } else { if (effect) { +#if CC_USE_SPINE_3_8 for (int v = 0, vn = trianglesTwoColor.vertCount; v < vn; ++v) { V3F_T2F_C4B_C4B *vertex = trianglesTwoColor.verts + v; effect->transform(vertex->vertex.x, vertex->vertex.y); vertex->color = light; vertex->color2 = dark; } +#endif } else { for (int v = 0, vn = trianglesTwoColor.vertCount; v < vn; ++v) { V3F_T2F_C4B_C4B *vertex = trianglesTwoColor.verts + v; @@ -708,7 +755,12 @@ void SkeletonRenderer::render(float /*deltaTime*/) { } } - curTexture = (cc::Texture2D *)attachmentVertices->_texture->getRealTexture(); + if (attachmentVertices) { + curTexture = (cc::Texture2D *)attachmentVertices->_texture->getRealTexture(); + } else { + curTexture = nullptr; + } + // If texture or blendMode change,will change material. if (preTexture != curTexture || preBlendMode != slot->getData().getBlendMode() || isFull) { flush(); @@ -742,7 +794,9 @@ void SkeletonRenderer::render(float /*deltaTime*/) { _clipper->clipEnd(); +#if CC_USE_SPINE_3_8 if (effect) effect->end(); +#endif if (curDrawInfo) curDrawInfo->setIbCount(curISegLen); @@ -807,7 +861,11 @@ cc::Rect SkeletonRenderer::getBoundingBox() const { auto *attachment = dynamic_cast(slot->getAttachment()); buffer.checkSpace(8 * sizeof(float)); worldVertices = reinterpret_cast(buffer.getCurBuffer()); +#if CC_USE_SPINE_3_8 attachment->computeWorldVertices(slot->getBone(), worldVertices, 0, 2); +#else + attachment->computeWorldVertices(*slot, worldVertices, 0, 2); +#endif verticesCount = 8; } else if (slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) { auto *mesh = dynamic_cast(slot->getAttachment()); @@ -833,7 +891,11 @@ cc::Rect SkeletonRenderer::getBoundingBox() const { void SkeletonRenderer::updateWorldTransform() { if (_skeleton) { +#if CC_USE_SPINE_3_8 _skeleton->updateWorldTransform(); +#else + _skeleton->updateWorldTransform(Physics::Physics_Update); +#endif } } @@ -912,6 +974,7 @@ void SkeletonRenderer::setUseTint(bool enabled) { _useTint = enabled; } +#if CC_USE_SPINE_3_8 void SkeletonRenderer::setVertexEffectDelegate(VertexEffectDelegate *effectDelegate) { if (_effectDelegate == effectDelegate) { return; @@ -920,6 +983,7 @@ void SkeletonRenderer::setVertexEffectDelegate(VertexEffectDelegate *effectDeleg _effectDelegate = effectDelegate; CC_SAFE_ADD_REF(_effectDelegate); } +#endif void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) { this->_startSlotIndex = startSlotIndex; @@ -1059,6 +1123,7 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D AttachmentVertices *attachmentVertices = nullptr; if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) { auto region = static_cast(attachment); +#if CC_USE_SPINE_3_8 region->setRegionWidth(width); region->setRegionHeight(height); region->setRegionOriginalWidth(width); @@ -1072,6 +1137,32 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D attachmentVertices = attachmentVertices->copy(); region->setRendererObject(attachmentVertices); } +#else + auto *textureRegion = region->getRegion(); + if (textureRegion) { + textureRegion->width = width; + textureRegion->height = height; + textureRegion->originalWidth = width; + textureRegion->originalHeight = height; + } + region->setWidth(width); + region->setHeight(height); + auto &uvs = region->getUVs(); + uvs[2] = 0; + uvs[3] = 1; + uvs[4] = 0; + uvs[5] = 0; + uvs[6] = 1; + uvs[7] = 0; + uvs[0] = 1; + uvs[1] = 1; + region->updateRegion(); + attachmentVertices = static_cast(textureRegion->rendererObject); + if (createAttachment) { + attachmentVertices = attachmentVertices->copy(); + textureRegion->rendererObject = attachmentVertices; + } +#endif V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; const auto &UVs = region->getUVs(); for (int i = 0, ii = 0; i < 4; ++i, ii += 2) { @@ -1080,6 +1171,7 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D } } else if (attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) { auto mesh = static_cast(attachment); +#if CC_USE_SPINE_3_8 mesh->setRegionWidth(width); mesh->setRegionHeight(height); mesh->setRegionOriginalWidth(width); @@ -1098,6 +1190,28 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D attachmentVertices = attachmentVertices->copy(); mesh->setRendererObject(attachmentVertices); } +#else + auto *region = mesh->getRegion(); + if (region) { + region->width = width; + region->height = height; + region->originalWidth = width; + region->originalHeight = height; + region->u = 0; + region->v = 0; + region->u2 = 1.0f; + region->v2 = 1.0f; + region->degrees = 0; + } + mesh->setWidth(width); + mesh->setHeight(height); + mesh->updateRegion(); + attachmentVertices = static_cast(mesh->getRegion()->rendererObject); + if (createAttachment) { + attachmentVertices = attachmentVertices->copy(); + mesh->getRegion()->rendererObject = attachmentVertices; + } +#endif V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; const auto &UVs = mesh->getUVs(); for (size_t i = 0, ii = 0, nn = mesh->getWorldVerticesLength(); ii < nn; ++i, ii += 2) { @@ -1123,3 +1237,4 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D } attachmentVertices->_texture = middlewareTexture; } +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.h b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.h index 3503ae821e..336210cf18 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.h +++ b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.h @@ -38,16 +38,15 @@ #include "base/RefMap.h" #include "core/assets/Texture2D.h" #include "middleware-adapter.h" +#if CC_USE_SPINE_3_8 #include "spine-creator-support/VertexEffectDelegate.h" +#endif #include "spine/spine.h" namespace cc { class RenderEntity; class RenderDrawInfo; class Material; -}; // namespace cc - -namespace spine { class AttachmentVertices; @@ -56,15 +55,15 @@ class AttachmentVertices; class SkeletonRenderer : public cc::RefCounted, public cc::middleware::IMiddleware { public: static SkeletonRenderer *create(); - static SkeletonRenderer *createWithSkeleton(Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false); - static SkeletonRenderer *createWithData(SkeletonData *skeletonData, bool ownsSkeletonData = false); + static SkeletonRenderer *createWithSkeleton(spine::Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false); + static SkeletonRenderer *createWithData(spine::SkeletonData *skeletonData, bool ownsSkeletonData = false); static SkeletonRenderer *createWithFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale = 1); void update(float deltaTime) override {} void render(float deltaTime) override; virtual cc::Rect getBoundingBox() const; - Skeleton *getSkeleton() const; + spine::Skeleton *getSkeleton() const; void setTimeScale(float scale); float getTimeScale() const; @@ -77,9 +76,9 @@ public: void paused(bool value); /* Returns 0 if the bone was not found. */ - Bone *findBone(const std::string &boneName) const; + spine::Bone *findBone(const std::string &boneName) const; /* Returns 0 if the slot was not found. */ - Slot *findSlot(const std::string &slotName) const; + spine::Slot *findSlot(const std::string &slotName) const; /* Sets the skin used to look up attachments not found in the SkeletonData defaultSkin. Attachments from the new skin are * attached if the corresponding attachment from the old skin was attached. @@ -89,7 +88,7 @@ public: void setSkin(const char *skinName); /* Returns 0 if the slot or attachment was not found. */ - Attachment *getAttachment(const std::string &slotName, const std::string &attachmentName) const; + spine::Attachment *getAttachment(const std::string &slotName, const std::string &attachmentName) const; /* Returns false if the slot or attachment was not found. * @param attachmentName May be empty string ("") for no attachment. */ bool setAttachment(const std::string &slotName, const std::string &attachmentName); @@ -98,9 +97,10 @@ public: /* Enables/disables two color tinting for this instance. May break batching */ void setUseTint(bool enabled); - +#if CC_USE_SPINE_3_8 /* Sets the vertex effect to be used, set to 0 to disable vertex effects */ void setVertexEffectDelegate(VertexEffectDelegate *effectDelegate); +#endif /* Sets the range of slots that should be rendered. Use -1, -1 to clear the range */ void setSlotsRange(int startSlotIndex, int endSlotIndex); @@ -131,18 +131,18 @@ public: void onDisable(); SkeletonRenderer(); - explicit SkeletonRenderer(Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false); - explicit SkeletonRenderer(SkeletonData *skeletonData, bool ownsSkeletonData = false); + explicit SkeletonRenderer(spine::Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false); + explicit SkeletonRenderer(spine::SkeletonData *skeletonData, bool ownsSkeletonData = false); SkeletonRenderer(const std::string &skeletonDataFile, const std::string &atlasFile, float scale = 1); ~SkeletonRenderer() override; void initWithUUID(const std::string &uuid); - void initWithSkeleton(Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false); - void initWithData(SkeletonData *skeletonData, bool ownsSkeletonData = false); - void initWithJsonFile(const std::string &skeletonDataFile, Atlas *atlas, float scale = 1); + void initWithSkeleton(spine::Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false); + void initWithData(spine::SkeletonData *skeletonData, bool ownsSkeletonData = false); + void initWithJsonFile(const std::string &skeletonDataFile, spine::Atlas *atlas, float scale = 1); void initWithJsonFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale = 1); - void initWithBinaryFile(const std::string &skeletonDataFile, Atlas *atlas, float scale = 1); + void initWithBinaryFile(const std::string &skeletonDataFile, spine::Atlas *atlas, float scale = 1); void initWithBinaryFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale = 1); virtual void initialize(); @@ -154,15 +154,17 @@ public: void setSlotTexture(const std::string &slotName, cc::Texture2D *tex2d, bool createAttachment); protected: - void setSkeletonData(SkeletonData *skeletonData, bool ownsSkeletonData); + void setSkeletonData(spine::SkeletonData *skeletonData, bool ownsSkeletonData); bool _ownsSkeletonData = false; bool _ownsSkeleton = false; bool _ownsAtlas = false; - Atlas *_atlas = nullptr; - AttachmentLoader *_attachmentLoader = nullptr; - Skeleton *_skeleton = nullptr; + spine::Atlas *_atlas = nullptr; + spine::AttachmentLoader *_attachmentLoader = nullptr; + spine::Skeleton *_skeleton = nullptr; +#if CC_USE_SPINE_3_8 VertexEffectDelegate *_effectDelegate = nullptr; +#endif float _timeScale = 1; bool _paused = false; @@ -172,7 +174,7 @@ protected: bool _debugBones = false; cc::middleware::Color4F _nodeColor = cc::middleware::Color4F::WHITE; bool _premultipliedAlpha = false; - SkeletonClipping *_clipper = nullptr; + spine::SkeletonClipping *_clipper = nullptr; bool _useTint = false; bool _enableBatch = false; std::string _uuid; @@ -189,5 +191,4 @@ protected: ccstd::unordered_map _materialCaches; bool _needClearMaterialCaches = false; }; - -} // namespace spine +}; // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/VertexEffectDelegate.cpp b/native/cocos/editor-support/spine-creator-support/VertexEffectDelegate.cpp index cf360b8dd8..688261fc13 100644 --- a/native/cocos/editor-support/spine-creator-support/VertexEffectDelegate.cpp +++ b/native/cocos/editor-support/spine-creator-support/VertexEffectDelegate.cpp @@ -1,84 +1,85 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - +/****************************************************************************** + * 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 "VertexEffectDelegate.h" -namespace spine { -VertexEffectDelegate::VertexEffectDelegate() { -} - -VertexEffectDelegate::~VertexEffectDelegate() { - clear(); -} - -void VertexEffectDelegate::clear() { - if (_interpolation) { - delete _interpolation; - _interpolation = nullptr; - } - if (_vertexEffect) { - delete _vertexEffect; - _vertexEffect = nullptr; - } - _effectType = "none"; -} - -JitterVertexEffect *VertexEffectDelegate::initJitter(float jitterX, float jitterY) { - clear(); - _vertexEffect = new JitterVertexEffect(jitterX, jitterY); - _effectType = "jitter"; - return (JitterVertexEffect *)_vertexEffect; -} - -SwirlVertexEffect *VertexEffectDelegate::initSwirlWithPow(float radius, int power) { - clear(); - _interpolation = new PowInterpolation(power); - _vertexEffect = new SwirlVertexEffect(radius, *_interpolation); - _effectType = "swirl"; - return (SwirlVertexEffect *)_vertexEffect; -} - -SwirlVertexEffect *VertexEffectDelegate::initSwirlWithPowOut(float radius, int power) { - clear(); - _interpolation = new PowOutInterpolation(power); - _vertexEffect = new SwirlVertexEffect(radius, *_interpolation); - _effectType = "swirl"; - return (SwirlVertexEffect *)_vertexEffect; -} - -JitterVertexEffect *VertexEffectDelegate::getJitterVertexEffect() { - JitterVertexEffect *jitter = dynamic_cast(_vertexEffect); - return jitter; -} - -SwirlVertexEffect *VertexEffectDelegate::getSwirlVertexEffect() { - SwirlVertexEffect *swirl = dynamic_cast(_vertexEffect); - return swirl; -} -} // namespace spine +namespace cc { + +VertexEffectDelegate::VertexEffectDelegate() { +} + +VertexEffectDelegate::~VertexEffectDelegate() { + clear(); +} + +void VertexEffectDelegate::clear() { + if (_interpolation) { + delete _interpolation; + _interpolation = nullptr; + } + if (_vertexEffect) { + delete _vertexEffect; + _vertexEffect = nullptr; + } + _effectType = "none"; +} + +JitterVertexEffect *VertexEffectDelegate::initJitter(float jitterX, float jitterY) { + clear(); + _vertexEffect = new spine::JitterVertexEffect(jitterX, jitterY); + _effectType = "jitter"; + return (JitterVertexEffect *)_vertexEffect; +} + +SwirlVertexEffect *VertexEffectDelegate::initSwirlWithPow(float radius, int power) { + clear(); + _interpolation = new spine::PowInterpolation(power); + _vertexEffect = new spine::SwirlVertexEffect(radius, *_interpolation); + _effectType = "swirl"; + return (SwirlVertexEffect *)_vertexEffect; +} + +SwirlVertexEffect *VertexEffectDelegate::initSwirlWithPowOut(float radius, int power) { + clear(); + _interpolation = new spine::PowOutInterpolation(power); + _vertexEffect = new spine::SwirlVertexEffect(radius, *_interpolation); + _effectType = "swirl"; + return (SwirlVertexEffect *)_vertexEffect; +} + +JitterVertexEffect *VertexEffectDelegate::getJitterVertexEffect() { + JitterVertexEffect *jitter = dynamic_cast(_vertexEffect); + return jitter; +} + +SwirlVertexEffect *VertexEffectDelegate::getSwirlVertexEffect() { + SwirlVertexEffect *swirl = dynamic_cast(_vertexEffect); + return swirl; +} +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/VertexEffectDelegate.h b/native/cocos/editor-support/spine-creator-support/VertexEffectDelegate.h index a4a077cf93..2ab10813a2 100644 --- a/native/cocos/editor-support/spine-creator-support/VertexEffectDelegate.h +++ b/native/cocos/editor-support/spine-creator-support/VertexEffectDelegate.h @@ -1,59 +1,60 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#pragma once - -#include -#include "base/RefCounted.h" -#include "spine/spine.h" - -namespace spine { -class VertexEffectDelegate : public cc::RefCounted { -public: - VertexEffectDelegate(); - ~VertexEffectDelegate() override; - JitterVertexEffect *initJitter(float jitterX, float jitterY); - SwirlVertexEffect *initSwirlWithPow(float radius, int power); - SwirlVertexEffect *initSwirlWithPowOut(float radius, int power); - VertexEffect *getVertexEffect() { - return _vertexEffect; - } - JitterVertexEffect *getJitterVertexEffect(); - SwirlVertexEffect *getSwirlVertexEffect(); - const std::string &getEffectType() const { - return _effectType; - } - void clear(); - -private: - VertexEffect *_vertexEffect = nullptr; - Interpolation *_interpolation = nullptr; - std::string _effectType = "none"; -}; -} // namespace spine +/****************************************************************************** + * 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. + *****************************************************************************/ + +#pragma once + +#include +#include "base/RefCounted.h" +#include "spine/spine.h" +using namespace spine; +namespace cc { + +class VertexEffectDelegate : public cc::RefCounted { +public: + VertexEffectDelegate(); + ~VertexEffectDelegate() override; + JitterVertexEffect *initJitter(float jitterX, float jitterY); + SwirlVertexEffect *initSwirlWithPow(float radius, int power); + SwirlVertexEffect *initSwirlWithPowOut(float radius, int power); + VertexEffect *getVertexEffect() { + return _vertexEffect; + } + JitterVertexEffect *getJitterVertexEffect(); + SwirlVertexEffect *getSwirlVertexEffect(); + const std::string &getEffectType() const { + return _effectType; + } + void clear(); + +private: + VertexEffect *_vertexEffect = nullptr; + Interpolation *_interpolation = nullptr; + std::string _effectType = "none"; +}; +} // namespace cc diff --git a/native/cocos/editor-support/spine-creator-support/spine-cocos2dx.cpp b/native/cocos/editor-support/spine-creator-support/spine-cocos2dx.cpp index 85cd0f5c8c..f3b01a027f 100644 --- a/native/cocos/editor-support/spine-creator-support/spine-cocos2dx.cpp +++ b/native/cocos/editor-support/spine-creator-support/spine-cocos2dx.cpp @@ -33,7 +33,7 @@ #include "platform/FileUtils.h" #include "spine-creator-support/AttachmentVertices.h" -namespace spine { +namespace cc { static CustomTextureLoader customTextureLoader = nullptr; void spAtlasPage_setCustomTextureLoader(CustomTextureLoader texLoader) { customTextureLoader = texLoader; @@ -43,7 +43,7 @@ static SpineObjectDisposeCallback spineObjectDisposeCallback = nullptr; void setSpineObjectDisposeCallback(SpineObjectDisposeCallback callback) { spineObjectDisposeCallback = callback; } -} // namespace spine +} // namespace cc USING_NS_MW; // NOLINT(google-build-using-namespace) using namespace cc; // NOLINT(google-build-using-namespace) @@ -56,26 +56,45 @@ static void deleteAttachmentVertices(void *vertices) { static uint16_t quadTriangles[6] = {0, 1, 2, 2, 3, 0}; static void setAttachmentVertices(RegionAttachment *attachment) { +#if CC_USE_SPINE_3_8 auto *region = static_cast(attachment->getRendererObject()); auto *attachmentVertices = new AttachmentVertices(static_cast(region->page->getRendererObject()), 4, quadTriangles, 6); +#else + auto *region = static_cast(attachment->getRegion()); + auto *attachmentVertices = new AttachmentVertices(static_cast(region->page->texture), 4, quadTriangles, 6); +#endif V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; for (int i = 0, ii = 0; i < 4; ++i, ii += 2) { vertices[i].texCoord.u = attachment->getUVs()[ii]; vertices[i].texCoord.v = attachment->getUVs()[ii + 1]; } +#if CC_USE_SPINE_3_8 attachment->setRendererObject(attachmentVertices, deleteAttachmentVertices); +#else + attachment->getRegion()->rendererObject = attachmentVertices; +#endif } static void setAttachmentVertices(MeshAttachment *attachment) { +#if CC_USE_SPINE_3_8 auto *region = static_cast(attachment->getRendererObject()); auto *attachmentVertices = new AttachmentVertices(static_cast(region->page->getRendererObject()), static_cast(attachment->getWorldVerticesLength() >> 1), attachment->getTriangles().buffer(), static_cast(attachment->getTriangles().size())); +#else + auto *region = static_cast(attachment->getRegion()); + auto *attachmentVertices = new AttachmentVertices(static_cast(region->page->texture), + static_cast(attachment->getWorldVerticesLength() >> 1), attachment->getTriangles().buffer(), static_cast(attachment->getTriangles().size())); +#endif V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; for (size_t i = 0, ii = 0, nn = attachment->getWorldVerticesLength(); ii < nn; ++i, ii += 2) { vertices[i].texCoord.u = attachment->getUVs()[ii]; vertices[i].texCoord.v = attachment->getUVs()[ii + 1]; } +#if CC_USE_SPINE_3_8 attachment->setRendererObject(attachmentVertices, deleteAttachmentVertices); +#else + attachment->getRegion()->rendererObject = attachmentVertices; +#endif } Cocos2dAtlasAttachmentLoader::Cocos2dAtlasAttachmentLoader(Atlas *atlas) : AtlasAttachmentLoader(atlas) { @@ -104,8 +123,8 @@ Cocos2dTextureLoader::~Cocos2dTextureLoader() = default; void Cocos2dTextureLoader::load(AtlasPage &page, const spine::String &path) { middleware::Texture2D *texture = nullptr; - if (spine::customTextureLoader) { - texture = spine::customTextureLoader(path.buffer()); + if (customTextureLoader) { + texture = customTextureLoader(path.buffer()); } CC_ASSERT_NOT_NULL(texture); @@ -115,7 +134,11 @@ void Cocos2dTextureLoader::load(AtlasPage &page, const spine::String &path) { middleware::Texture2D::TexParams textureParams = {filter(page.minFilter), filter(page.magFilter), wrap(page.uWrap), wrap(page.vWrap)}; texture->setTexParameters(textureParams); +#if CC_USE_SPINE_3_8 page.setRendererObject(texture); +#else + page.texture = texture; +#endif page.width = texture->getPixelsWide(); page.height = texture->getPixelsHigh(); } diff --git a/native/cocos/editor-support/spine-creator-support/spine-cocos2dx.h b/native/cocos/editor-support/spine-creator-support/spine-cocos2dx.h index 56ddce2781..4928c7106b 100644 --- a/native/cocos/editor-support/spine-creator-support/spine-cocos2dx.h +++ b/native/cocos/editor-support/spine-creator-support/spine-cocos2dx.h @@ -37,7 +37,7 @@ #include "spine-creator-support/SkeletonRenderer.h" #include "spine/spine.h" -namespace spine { +namespace cc { typedef cc::middleware::Texture2D *(*CustomTextureLoader)(const char *path); // set custom texture loader for _spAtlasPage_createTexture void spAtlasPage_setCustomTextureLoader(CustomTextureLoader texLoader); @@ -74,4 +74,4 @@ protected: typedef void (*SpineObjectDisposeCallback)(void *); void setSpineObjectDisposeCallback(SpineObjectDisposeCallback callback); -} // namespace spine +} // namespace cc diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/3.8/spine-type-export.cpp similarity index 99% rename from native/cocos/editor-support/spine-wasm/spine-type-export.cpp rename to native/cocos/editor-support/spine-wasm/3.8/spine-type-export.cpp index de2af5ebbf..1b60e13cfb 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/3.8/spine-type-export.cpp @@ -2,9 +2,9 @@ #include #include #include -#include "spine-skeleton-instance.h" -#include "spine-wasm.h" -#include "Vector2.h" +#include "../spine-skeleton-instance.h" +#include "../spine-wasm.h" +#include "../Vector2.h" using namespace spine; diff --git a/native/cocos/editor-support/spine-wasm/4.2/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/4.2/spine-type-export.cpp new file mode 100644 index 0000000000..3f508c71f8 --- /dev/null +++ b/native/cocos/editor-support/spine-wasm/4.2/spine-type-export.cpp @@ -0,0 +1,1417 @@ +#include +#include +#include +#include +#include "../spine-skeleton-instance.h" +#include "../spine-wasm.h" +#include "../Vector2.h" +#include "spine/Vector.h" + +using namespace spine; + +using SPVectorFloat = Vector; +using SPVectorVectorFloat = Vector>; +using SPVectorInt = Vector; +using SPVectorUint = Vector; +using SPVectorVectorInt = Vector>; +using SPVectorSize_t = Vector; +using SPVectorBonePtr = Vector; +using SPVectorBoneDataPtr = Vector; +using SPVectorSlotDataPtr = Vector; +using SPVectorTransformConstraintDataPtr = Vector; +using SPVectorPathConstraintDataPtr = Vector; +using SPVectorPhysicsConstraintDataPtr = Vector; +using SPVectorUnsignedShort = Vector; +using SPVectorSPString = Vector; +using SPVectorConstraintDataPtr = Vector; +using SPVectorSlotPtr = Vector; +using SPVectorSkinPtr = Vector; +using SPVectorEventDataPtr = Vector; +using SPVectorEventPtr = Vector; +using SPVectorAnimationPtr = Vector; +using SPVectorIkConstraintPtr = Vector; +using SPVectorIkConstraintDataPtr = Vector; +using SPVectorTransformConstraintPtr = Vector; +using SPVectorPathConstraintPtr = Vector; +using SPVectorTimelinePtr = Vector; +using SPVectorTrackEntryPtr = Vector; +using SPVectorUpdatablePtr = Vector; +using SPVectorSkinEntryPtr = Vector; +using SPVectorVectorSkinEntryPtr = Vector; +using SPVectorDebugShape = Vector; + +#define DEFINE_ALLOW_RAW_POINTER(type) \ +namespace emscripten { namespace internal { \ + template<> \ + 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(CurveTimeline1) +DEFINE_SPINE_CLASS_TYPEID(CurveTimeline2) +DEFINE_SPINE_CLASS_TYPEID(TranslateTimeline) +DEFINE_SPINE_CLASS_TYPEID(ScaleTimeline) +DEFINE_SPINE_CLASS_TYPEID(ShearTimeline) +DEFINE_SPINE_CLASS_TYPEID(RotateTimeline) +DEFINE_SPINE_CLASS_TYPEID(InheritTimeline) +DEFINE_SPINE_CLASS_TYPEID(RGBATimeline) +DEFINE_SPINE_CLASS_TYPEID(RGBTimeline) +DEFINE_SPINE_CLASS_TYPEID(RGBA2Timeline) +DEFINE_SPINE_CLASS_TYPEID(RGB2Timeline) +DEFINE_SPINE_CLASS_TYPEID(AlphaTimeline) +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(PhysicsConstraintData) +DEFINE_SPINE_CLASS_TYPEID(PhysicsConstraint) + + + +DEFINE_ALLOW_RAW_POINTER(BoneData) +DEFINE_ALLOW_RAW_POINTER(Bone) +DEFINE_ALLOW_RAW_POINTER(Slot) +DEFINE_ALLOW_RAW_POINTER(SlotData) +DEFINE_ALLOW_RAW_POINTER(Attachment) +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) +DEFINE_ALLOW_RAW_POINTER(SPVectorEventPtr) + + +namespace { + +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) \ + 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(MixDirection); + REGISTER_SPINE_ENUM(MixBlend); + REGISTER_SPINE_ENUM(EventType); + REGISTER_SPINE_ENUM(BlendMode); + REGISTER_SPINE_ENUM(PositionMode); + REGISTER_SPINE_ENUM(SpacingMode); + REGISTER_SPINE_ENUM(RotateMode); + REGISTER_SPINE_ENUM(TextureFilter); + REGISTER_SPINE_ENUM(TextureWrap); + REGISTER_SPINE_ENUM(AttachmentType); + + + 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_("TextureRegion") + .property("u", &TextureRegion::u) + .property("v", &TextureRegion::v) + .property("u2", &TextureRegion::u2) + .property("v2", &TextureRegion::v2) + .property("degrees", &TextureRegion::degrees) + .property("offsetX", &TextureRegion::offsetX) + .property("offsetY", &TextureRegion::offsetY) + .property("width", &TextureRegion::width) + .property("height", &TextureRegion::height) + .property("originalWidth", &TextureRegion::originalWidth) + .property("originalHeight", &TextureRegion::originalHeight); + + class_("Vector2") + .constructor<>() + .constructor() + .property("x", &Vector2::x) + .property("y", &Vector2::y) + .function("set", &Vector2::set) + .function("length", &Vector2::length) + .function("normalize", &Vector2::normalize); + + class_("Color") + .constructor<>() + .constructor() + .function("set", select_overload(&Color::set)) + .function("add", select_overload(&Color::add)) + .function("clamp", &Color::clamp) + .property("r", &Color::r) + .property("g", &Color::g) + .property("b", &Color::b) + .property("a", &Color::a); + + class_("Interpolation") + .function("apply", &Interpolation::apply, pure_virtual()); + + class_("HasRendererObject") + .constructor<>(); + + // class_("Triangulator") + // .constructor<>() + // .function("triangulate", &Triangulator::triangulate) + // .function("decompose", &Triangulator::decompose, allow_raw_pointers()); + + class_("ConstraintData") + .constructor() + .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()) + .property("target", &IkConstraintData::_target) + .property("bendDirection", &IkConstraintData::_bendDirection) + .property("compress", &IkConstraintData::_compress) + .property("stretch", &IkConstraintData::_stretch) + .property("uniform", &IkConstraintData::_uniform) + .property("mix", &IkConstraintData::_mix) + .property("softness", &IkConstraintData::_softness); + + class_>("PathConstraintData") + .constructor() + .function("getBones",optional_override([](PathConstraintData &obj) { + return obj.getBones(); }), allow_raw_pointer()) + .property("target", &PathConstraintData::_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("mixRotate", &PathConstraintData::getMixRotate) + .property("mixX", &PathConstraintData::getMixX) + .property("mixY", &PathConstraintData::getMixY); + + + class_("SkeletonBounds") + .constructor<>() + .function("update", &SkeletonBounds::update) + .function("aabbContainsPoint", &SkeletonBounds::aabbcontainsPoint) + .function("aabbIntersectsSegment", &SkeletonBounds::aabbintersectsSegment) + .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("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("getWidth", &SkeletonBounds::getWidth) + .function("getHeight", &SkeletonBounds::getHeight); + + class_("Event") + .constructor() + .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() + .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") + .property("name", &Attachment::getName); + + // pure_virtual and raw pointer + class_>("VertexAttachment") + .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()) + .property("worldVerticesLength", &VertexAttachment::_worldVerticesLength) + .property("timelineAttachment", &VertexAttachment::_timelineAttachment) + .function("computeWorldVertices", select_overload&, size_t, size_t)> + (&VertexAttachment::computeWorldVertices), allow_raw_pointer()) + .function("copyTo", &VertexAttachment::copyTo, allow_raw_pointers()); + + class_>("BoundingBoxAttachment") + .constructor() + .property("name", &BoundingBoxAttachment::getName) + .function("copy", &BoundingBoxAttachment::copy, allow_raw_pointers()); + + class_>("ClippingAttachment") + .constructor() + .property("endSlot", &ClippingAttachment::getEndSlot, &ClippingAttachment::setEndSlot) + .function("copy", &ClippingAttachment::copy, allow_raw_pointers()); + + class_>("MeshAttachment") + .constructor() + .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()) + .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("updateRegion", &MeshAttachment::updateRegion) + .function("getParentMesh", &MeshAttachment::getParentMesh, allow_raw_pointers()) + .function("setParentMesh", &MeshAttachment::setParentMesh, allow_raw_pointers()) + .function("copy", &MeshAttachment::copy, allow_raw_pointers()) + .function("newLinkedMesh", &MeshAttachment::newLinkedMesh, allow_raw_pointers()); + + class_>("PathAttachment") + .constructor() + .function("getLengths", optional_override([](PathAttachment &obj) { + return &obj.getLengths(); }), allow_raw_pointer()) + .property("closed", &PathAttachment::_closed) + .property("constantSpeed", &PathAttachment::_constantSpeed) + .function("copy", &PathAttachment::copy, allow_raw_pointers()); + + class_>("PointAttachment") + .constructor() + .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) + .function("copy", &PointAttachment::copy, allow_raw_pointers()); + + class_>("RegionAttachment") + .constructor() + .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) + .function("getOffset", optional_override([](RegionAttachment &obj) { + return &obj.getOffset(); }), allow_raw_pointer()) + // .function("setUVs", &RegionAttachment::setUVs) + .function("getUVs", optional_override([](RegionAttachment &obj) { + return &obj.getUVs(); }), allow_raw_pointer()) + .function("computeWorldVertices", select_overload&, size_t, size_t)> + (&RegionAttachment::computeWorldVertices), allow_raw_pointer()) + .function("copy", &RegionAttachment::copy, allow_raw_pointer()); + + class_("AttachmentLoader") + //.constructor<>() + .function("newClippingAttachment", &AttachmentLoader::newClippingAttachment, pure_virtual(), allow_raw_pointers()) + .function("newPointAttachment", &AttachmentLoader::newPointAttachment, pure_virtual(), allow_raw_pointers()) + .function("newPathAttachment", &AttachmentLoader::newPathAttachment, pure_virtual(), allow_raw_pointers()) + .function("newBoundingBoxAttachment", &AttachmentLoader::newBoundingBoxAttachment, pure_virtual(), allow_raw_pointers()) + .function("newMeshAttachment", &AttachmentLoader::newMeshAttachment, pure_virtual(), allow_raw_pointers()) + .function("newRegionAttachment", &AttachmentLoader::newRegionAttachment, pure_virtual(), allow_raw_pointers()); + + class_>("AtlasAttachmentLoader") + .constructor() + .function("newRegionAttachment", &AtlasAttachmentLoader::newRegionAttachment, allow_raw_pointer()) + .function("newMeshAttachment", &AtlasAttachmentLoader::newMeshAttachment, allow_raw_pointer()) + .function("newBoundingBoxAttachment", &AtlasAttachmentLoader::newBoundingBoxAttachment, allow_raw_pointer()) + .function("newPathAttachment", &AtlasAttachmentLoader::newPathAttachment, allow_raw_pointer()) + .function("newPointAttachment", &AtlasAttachmentLoader::newPointAttachment, allow_raw_pointer()) + .function("newClippingAttachment", &AtlasAttachmentLoader::newClippingAttachment, allow_raw_pointer()); + + class_("TextureAtlasPage") + .constructor() + .property("name", &AtlasPage::name) + .property("texturePath", &AtlasPage::texturePath) + .property("format", &AtlasPage::format) + .property("pma", &AtlasPage::pma) + .property("index", &AtlasPage::index) + .property("minFilter", &AtlasPage::minFilter) + .property("magFilter", &AtlasPage::magFilter) + .property("uWrap", &AtlasPage::uWrap) + .property("vWrap", &AtlasPage::vWrap) + .property("width", &AtlasPage::width) + .property("height", &AtlasPage::height); + + class_>("TextureAtlasRegion") + // .property("page", &AtlasRegion::page) + .property("name", &AtlasRegion::name) + .property("x", &AtlasRegion::x) + .property("y", &AtlasRegion::y) + .property("index", &AtlasRegion::index); + + class_("TextureLoader"); + + + class_("TextureAtlas") + .constructor() + .function("findRegion", &Atlas::findRegion, allow_raw_pointers()); + + class_>("Pow") + .constructor(); + + + class_>("PowOut") + .constructor(); + + class_("SlotData") + .constructor() + .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()) + .property("active", &Updatable::isActive, &Updatable::setActive) + ; + + class_>("IkConstraint") + .constructor() + .property("data", GETTER_RVAL_TO_PTR(IkConstraint, getData, IkConstraintData*)) + .function("getBones", optional_override([](IkConstraint &obj) { + return &obj.getBones(); }), allow_raw_pointer()) + .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() + .property("data", GETTER_RVAL_TO_PTR(PathConstraint, getData, PathConstraintData*)) + .function("getBones", optional_override([](PathConstraint &obj) { + return &obj.getBones(); }), allow_raw_pointer()) + .property("target", &PathConstraint::_target) + .property("position", &PathConstraint::_position) + .property("spacing", &PathConstraint::_spacing) + .property("mixRotate", &PathConstraint::getMixRotate) + .property("mixX", &PathConstraint::getMixX) + .property("mixY", &PathConstraint::getMixY); + + class_>("TransformConstraintData") + .constructor() + .function("getBones", optional_override([](TransformConstraintData &obj) { + return &obj.getBones(); }), allow_raw_pointer()) + .property("target", &TransformConstraintData::getTarget) + .property("mixRotate", &TransformConstraintData::getMixRotate) + .property("mixX", &TransformConstraintData::getMixX) + .property("mixY", &TransformConstraintData::getMixY) + .property("mixScaleX", &TransformConstraintData::getMixScaleX) + .property("mixScaleY", &TransformConstraintData::getMixScaleY) + .property("mixShearY", &TransformConstraintData::getMixShearY) + .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() + .property("data", GETTER_RVAL_TO_PTR(TransformConstraint, getData, TransformConstraintData*)) + .function("getBones", optional_override([](TransformConstraint &obj) { + return &obj.getBones(); }), allow_raw_pointer()) + .property("target", &TransformConstraint::getTarget) + .property("mixRotate", &TransformConstraint::getMixRotate) + .property("mixX", &TransformConstraint::getMixX) + .property("mixY", &TransformConstraint::getMixY) + .property("mixScaleX", &TransformConstraint::getMixScaleX) + .property("mixScaleY", &TransformConstraint::getMixScaleY) + .property("mixShearY", &TransformConstraint::getMixShearY); + + class_>("Bone") + .constructor() + .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()) + .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("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) + .function("getWorldRotationX", &Bone::getWorldRotationX) + .function("getWorldRotationY", &Bone::getWorldRotationY) + .function("getWorldScaleX", &Bone::getWorldScaleX) + .function("getWorldScaleY", &Bone::getWorldScaleY) + .function("worldToLocal", optional_override([](Bone &obj, Vector2 &vec2) { + float outLocalX, outLocalY; + obj.worldToLocal(vec2.x, vec2.y, outLocalX, outLocalY); + vec2.x = outLocalX; + vec2.y = outLocalY; + }), + allow_raw_pointers() + ) + .function("localToWorld", optional_override([](Bone &obj, Vector2 &vec2) { + float outWorldX, outWorldY; + obj.localToWorld(vec2.x, vec2.y, outWorldX, outWorldY); + vec2.x = outWorldX; + vec2.y = outWorldY; + }), + allow_raw_pointers() + ) + .function("worldToLocalRotation", &Bone::worldToLocalRotation) + .function("localToWorldRotation", &Bone::localToWorldRotation) + .function("rotateWorld", &Bone::rotateWorld); + + class_("BoneData") + .constructor() + .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("icon", &BoneData::getIcon) + .property("visible", &BoneData::isVisible) + .property("skinRequired", &BoneData::_skinRequired); + + + class_("Slot") + .constructor() + .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("setToSetupPose", &Slot::setToSetupPose); + + class_("Skin") + .constructor() + .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", &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) { + Vector vetNames; + auto entries = obj.getAttachments(); + while (entries.hasNext()) { + auto &entry = entries.next(); + if (entry._slotIndex == slotIndex) vetNames.add(entry._name); + } + return vetNames; + }), allow_raw_pointers()) + .function("getAttachment", &Skin::getAttachment, allow_raw_pointers()) + .function("getAttachments", optional_override([](Skin &obj) { + SPVectorSkinEntryPtr entriesVector; + auto entries = obj.getAttachments(); + while (entries.hasNext()) { + entriesVector.add(&entries.next()); + } + return entriesVector; + }),allow_raw_pointers()) + .function("removeAttachment", &Skin::removeAttachment) + .function("getAttachmentsForSlot", optional_override([](Skin &obj, size_t index) { + SPVectorSkinEntryPtr entriesVector; + auto entries = obj.getAttachments(); + while (entries.hasNext()) { + Skin::AttachmentMap::Entry &entry = entries.next(); + if (entry._slotIndex == index) entriesVector.add(&entry); + } + return entriesVector; + }),allow_raw_pointers()); + + class_("SkinEntry") + .constructor() + .property("slotIndex", &Skin::AttachmentMap::Entry::_slotIndex) + .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<>() + .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)) + .function("isClipping", &SkeletonClipping::isClipping); + + class_("SkeletonData") + .constructor<>() + .property("name", &SkeletonData::_name) + .function("getBones", optional_override([](SkeletonData &obj) { + return &obj.getBones(); }), allow_raw_pointer()) + .function("getSlots", optional_override([](SkeletonData &obj) { + return &obj.getSlots(); }), allow_raw_pointer()) + .function("getSkins", optional_override([](SkeletonData &obj) { + return &obj.getSkins(); }), allow_raw_pointer()) + .property("defaultSkin", &SkeletonData::_defaultSkin) + .function("getEvents", optional_override([](SkeletonData &obj) { + return &obj.getEvents(); }), allow_raw_pointer()) + .function("getAnimations", optional_override([](SkeletonData &obj) { + return &obj.getAnimations(); }), allow_raw_pointer()) + .function("getIkConstraints", optional_override([](SkeletonData &obj) { + return &obj.getIkConstraints(); }), allow_raw_pointer()) + .function("getTransformConstraints", optional_override([](SkeletonData &obj) { + return &obj.getTransformConstraints(); }), allow_raw_pointer()) + .function("getPathConstraints", optional_override([](SkeletonData &obj) { + return &obj.getPathConstraints(); }), allow_raw_pointer()) + .function("getPhysicsConstraints", optional_override([](SkeletonData &obj) { + return &obj.getPhysicsConstraints(); }), allow_raw_pointer()) + .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("findSlot", &SkeletonData::findSlot, allow_raw_pointers()) + .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("findPhysicsConstraint", &SkeletonData::findPathConstraint, allow_raw_pointers()) + .function("findPathConstraint", &SkeletonData::findPathConstraint, allow_raw_pointers()); + + class_("Animation") + .constructor(optional_override([](const String &name, const emscripten::val &value, float duration) -> Animation* { + auto length = value["length"].as(); + Vector timelines; + timelines.setSize(length, nullptr); + for (uint32_t i = 0; i < length; ++i) { + timelines[i] = value[i].as(allow_raw_pointers()); + } + return new Animation(name, timelines, duration); + })) + .property("name", &Animation::getName) + .function("getTimelines", optional_override([](Animation &obj) { + return &obj.getTimelines(); }), allow_raw_pointer()) + .function("hasTimeline", &Animation::hasTimeline) + .property("duration", &Animation::_duration); + + class_("Timeline") + .function("getFrameCount", &Timeline::getFrameCount) + .function("getFrameEntries", &Timeline::getFrameEntries) + .function("getDuration", &Timeline::getDuration) + .function("getFrames", GETTER_RVAL_TO_PTR(Timeline, getFrames, SPVectorFloat*), allow_raw_pointer()) + .function("apply", &Timeline::apply, pure_virtual()); + // .function("getPropertyIds", &Timeline::getPropertyIds, pure_virtual()); + + class_>("CurveTimeline") + .function("setLinear", &CurveTimeline::setLinear) + .function("setStepped", &CurveTimeline::setStepped) + .function("setBezier", &CurveTimeline::setBezier) + .function("getBezierValue", &CurveTimeline::getBezierValue) + .function("getCurves", GETTER_RVAL_TO_PTR(CurveTimeline, getCurves, SPVectorFloat*), allow_raw_pointer()); + + class_>("CurveTimeline1") + .function("setFrame", &CurveTimeline1::setFrame) + .function("getCurveValue", &CurveTimeline1::getCurveValue) + //FixMe: multiple impl getAbsoluteValue + //.function("getAbsoluteValue", &CurveTimeline1::getAbsoluteValue) + .function("getRelativeValue", &CurveTimeline1::getRelativeValue) + .function("getScaleValue", &CurveTimeline1::getScaleValue); + + class_>("CurveTimeline2") + .class_property("ENTRIES", &CurveTimeline2::ENTRIES) + .function("setFrame", &CurveTimeline2::setFrame); + // .function("getCurveValue", &CurveTimeline2::getCurveValue); + + class_>("TranslateTimeline") + .constructor() + .class_property("ENTRIES", &TranslateTimeline::ENTRIES) + .function("setFrame", &TranslateTimeline::setFrame); + + class_>("ScaleTimeline") + .constructor() + ; + + class_>("ShearTimeline") + .constructor(); + + class_>("RotateTimeline") + .constructor() + //.class_property("ENTRIES", &RotateTimeline::ENTRIES) not bind + .property("boneIndex", &RotateTimeline::_boneIndex) + .function("getFrames", GETTER_RVAL_TO_PTR(RotateTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) + .function("setFrame", &RotateTimeline::setFrame); + + class_>("RGBATimeline") + .constructor() + .class_property("ENTRIES", &RGBATimeline::ENTRIES) + .property("slotIndex", &RGBATimeline::_slotIndex) + .function("setFrame", &RGBATimeline::setFrame); + + class_>("AttachmentTimeline") + .constructor() + .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", &AttachmentTimeline::setFrame, allow_raw_pointers()); + + class_>("DeformTimeline") + .constructor() + .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("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", GETTER_RVAL_TO_PTR(EventTimeline, getFrames, SPVectorFloat*), allow_raw_pointer()) + .function("getEvents", optional_override([](EventTimeline &obj) { + return &obj.getEvents(); }), allow_raw_pointer()) + .function("getFrameCount", &EventTimeline::getFrameCount) + .function("setFrame", &EventTimeline::setFrame, allow_raw_pointers()); + + class_>("DrawOrderTimeline") + .constructor() + .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()); + + class_>("IkConstraintTimeline") + .constructor() + .class_property("ENTRIES", &IkConstraintTimeline::ENTRIES) + .function("setFrame", &IkConstraintTimeline::setFrame); + + class_>("TransformConstraintTimeline") + .constructor() + .class_property("ENTRIES", &TransformConstraintTimeline::ENTRIES) + .function("setFrame", &TransformConstraintTimeline::setFrame); + + class_>("PathConstraintPositionTimeline") + .constructor() + .class_property("ENTRIES", &TransformConstraintTimeline::ENTRIES) + .function("setFrame", &PathConstraintPositionTimeline::setFrame); + + class_>("PathConstraintMixTimeline") + .constructor() + .class_property("ENTRIES", &PathConstraintMixTimeline::ENTRIES); + + class_("TrackEntry") + .constructor<>() + .property("animation", &TrackEntry::getAnimation) + .property("next", &TrackEntry::getNext) + .property("mixingFrom", &TrackEntry::getMixingFrom) + .property("mixingTo", &TrackEntry::getMixingTo) + //.function("getProp_listener", &TrackEntry::listener) + .property("trackIndex", &TrackEntry::getTrackIndex) + .property("loop", &TrackEntry::_loop) + .property("holdPrevious", &TrackEntry::_holdPrevious) + .property("eventThreshold", &TrackEntry::_eventThreshold) + .property("alphaAttachmentThreshold", &TrackEntry::_alphaAttachmentThreshold) + .property("mixDrawOrderThreshold", &TrackEntry::_mixDrawOrderThreshold) + .property("mixAttachmentThreshold", &TrackEntry::_mixAttachmentThreshold) + .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() + .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() + .property("data", &AnimationState::getData) + .function("getTracks", optional_override([](AnimationState &obj) { + return &obj.getTracks(); }), allow_raw_pointer()) + .property("timeScale", &AnimationState::getTimeScale, &AnimationState::setTimeScale) + .function("update", &AnimationState::update) + .function("apply", &AnimationState::apply) + .function("clearTracks", &AnimationState::clearTracks) + .function("clearTrack", &AnimationState::clearTrack) + .function("setAnimation", select_overload(&AnimationState::setAnimation), allow_raw_pointers()) + .function("setAnimationWith", optional_override([](AnimationState &obj, uint32_t trackIndex, Animation *animation, bool loop) { return obj.setAnimation(trackIndex, animation, loop); }), allow_raw_pointers()) + .function("addAnimation", select_overload(&AnimationState::addAnimation), allow_raw_pointers()) + .function("addAnimationWith", select_overload(&AnimationState::addAnimation), allow_raw_pointers()) + .function("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("disableQueue", &AnimationState::disableQueue) + .function("enableQueue", &AnimationState::enableQueue); + //.function("addListener", &AnimationState::addListener) + //.function("removeListener", &AnimationState::removeListener) + //.function("clearListeners", &AnimationState::clearListeners) // no have clearListeners + + //private + // class_("EventQueue") + // .constructor& >() + // .function("start", &EventQueue::start, allow_raw_pointers()) + // .function("interrupt", &EventQueue::interrupt, allow_raw_pointers()) + // .function("end", &EventQueue::end, allow_raw_pointers()) + // .function("dispose", &EventQueue::dispose, allow_raw_pointers()) + // .function("complete", &EventQueue::complete, allow_raw_pointers()) + // .function("event", &EventQueue::event, allow_raw_pointers()) + // .function("drain", &EventQueue::drain) + // .function("clear"); + + //class_("AnimationStateListener") + + //class_("AnimationStateListenerObject") + // .constructor<>() + // .function("callback", &AnimationStateListenerObject::callback, pure_virtual()); + + //class_("AnimationStateAdapter") + + class_("Skeleton") + .constructor() + .property("data", &Skeleton::getData) + .function("getBones", optional_override([](Skeleton &obj){ + return &obj.getBones(); }), allow_raw_pointer()) + .function("getSlots", optional_override([](Skeleton &obj){ + return &obj.getSlots(); }), allow_raw_pointer()) + .function("getDrawOrder", optional_override([](Skeleton &obj){ + return &obj.getDrawOrder(); }), allow_raw_pointer()) + .function("getIkConstraints", optional_override([](Skeleton &obj){ + return &obj.getIkConstraints(); }), allow_raw_pointer()) + .function("getTransformConstraints", optional_override([](Skeleton &obj){ + return &obj.getTransformConstraints(); }), allow_raw_pointer()) + .function("getPathConstraints", optional_override([](Skeleton &obj){ + return &obj.getPathConstraints(); }), allow_raw_pointer()) + .function("getUpdateCacheList", optional_override([](Skeleton &obj){ + return &obj.getUpdateCacheList(); }), allow_raw_pointer()) + .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", select_overload(&Skeleton::updateWorldTransform)) + .function("updateWorldTransform", select_overload(&Skeleton::updateWorldTransform)) + .function("setToSetupPose", &Skeleton::setToSetupPose) + .function("setBonesToSetupPose", &Skeleton::setBonesToSetupPose) + .function("setSlotsToSetupPose", &Skeleton::setSlotsToSetupPose) + .function("getRootBone", &Skeleton::getRootBone, allow_raw_pointer()) + .function("findBone", &Skeleton::findBone, allow_raw_pointers()) + .function("findSlot", &Skeleton::findSlot, allow_raw_pointers()) + .function("setSkinByName", select_overload(&Skeleton::setSkin)) + .function("setSkin", static_cast(&Skeleton::setSkin), allow_raw_pointer()) + .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); + + //incomplete + // class_("SkeletonBinary") + // .constructor() + // .constructor() + // .function("setScale", &SkeletonBinary::setScale) + // .function("getError", &SkeletonBinary::getError); + //.function("readSkeletonDataFile", optional_override([](SkeletonBinary &obj, const String& path) { return obj.readSkeletonDataFile(path); })); + + // incomplete + //class_("SkeletonJson") + //.constructor() + //.constructor() + //.function("setScale", &SkeletonJson::setScale); + //.function("getError", &SkeletonJson::getError); + + class_("SpineModel") + .property("vCount", &SpineModel::vCount) + .property("iCount", &SpineModel::iCount) + .property("vPtr", &SpineModel::vPtr) + .property("iPtr", &SpineModel::iPtr) + .function("getTextures", &SpineModel::getTextures, allow_raw_pointers()) + .function("getData", &SpineModel::getData, allow_raw_pointer()); + + class_("SpineDebugShape") + .property("type", &SpineDebugShape::type) + .property("vOffset", &SpineDebugShape::vOffset) + .property("vCount", &SpineDebugShape::vCount) + .property("iOffset", &SpineDebugShape::iOffset) + .property("iCount", &SpineDebugShape::iCount); + + class_("SkeletonInstance") + .constructor<>() + .property("isCache", &SpineSkeletonInstance::isCache) + .property("dtRate", &SpineSkeletonInstance::dtRate) + .property("enable", &SpineSkeletonInstance::enable) + .function("initSkeleton", &SpineSkeletonInstance::initSkeleton, allow_raw_pointers()) + .function("setAnimation", &SpineSkeletonInstance::setAnimation, allow_raw_pointers()) + .function("setSkin", &SpineSkeletonInstance::setSkin) + .function("updateAnimation", &SpineSkeletonInstance::updateAnimation) + .function("updateRenderData", &SpineSkeletonInstance::updateRenderData, allow_raw_pointer()) + .function("setPremultipliedAlpha", &SpineSkeletonInstance::setPremultipliedAlpha) + .function("setUseTint", &SpineSkeletonInstance::setUseTint) + .function("setColor", &SpineSkeletonInstance::setColor) + .function("getAnimationState", &SpineSkeletonInstance::getAnimationState, allow_raw_pointer()) + .function("setMix", &SpineSkeletonInstance::setMix) + .function("setListener", &SpineSkeletonInstance::setListener) + .function("setTrackEntryListener", &SpineSkeletonInstance::setTrackEntryListener, allow_raw_pointer()) + .function("setDebugMode", &SpineSkeletonInstance::setDebugMode) + .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) + .class_function("createStoreMemory", &SpineWasmUtil::createStoreMemory) + .class_function("freeStoreMemory", &SpineWasmUtil::freeStoreMemory) + .class_function("querySpineSkeletonDataByUUID", &SpineWasmUtil::querySpineSkeletonDataByUUID, allow_raw_pointers()) + .class_function("createSpineSkeletonDataWithJson", optional_override([](String jsonStr, String atlasStr, emscripten::val nameArray, emscripten::val uuidArray){ + unsigned count = nameArray["length"].as(); + Vector names; + Vector ids; + names.setSize(count, ""); + ids.setSize(count, ""); + for (int i = 0; i < count; i++) { + names[i] = nameArray[i].as(); + ids[i] = uuidArray[i].as(); + } + return SpineWasmUtil::createSpineSkeletonDataWithJson(jsonStr, atlasStr, names, ids); + }), allow_raw_pointers()) + .class_function("createSpineSkeletonDataWithBinary", optional_override([](uint32_t byteSize, String atlasStr, emscripten::val nameArray, emscripten::val uuidArray){ + unsigned count = nameArray["length"].as(); + Vector names; + Vector ids; + names.setSize(count, ""); + ids.setSize(count, ""); + for (int i = 0; i < count; i++) { + names[i] = nameArray[i].as(); + ids[i] = uuidArray[i].as(); + } + return SpineWasmUtil::createSpineSkeletonDataWithBinary(byteSize, atlasStr, names, ids); + }), allow_raw_pointers()) + .class_function("registerSpineSkeletonDataWithUUID", &SpineWasmUtil::registerSpineSkeletonDataWithUUID, allow_raw_pointers()) + .class_function("destroySpineSkeletonDataWithUUID", &SpineWasmUtil::destroySpineSkeletonDataWithUUID) + .class_function("destroySpineSkeleton", &SpineWasmUtil::destroySpineSkeleton, allow_raw_pointers()) + .class_function("getCurrentListenerID", &SpineWasmUtil::getCurrentListenerID) + .class_function("getCurrentEventType", &SpineWasmUtil::getCurrentEventType) + .class_function("getCurrentTrackEntry", &SpineWasmUtil::getCurrentTrackEntry, allow_raw_pointers()) + .class_function("getCurrentEvent", &SpineWasmUtil::getCurrentEvent, allow_raw_pointers()); +} diff --git a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp index f41e3d92dd..1961d0b800 100644 --- a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp +++ b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp @@ -3,15 +3,26 @@ //#include "LogUtil.h" using namespace spine; +#include +#include +using namespace spine; + +static void wasmLog(const char* message) { + EM_ASM({ + console.log(UTF8ToString($0)); + }, message); +} + + static uint16_t quadTriangles[6] = {0, 1, 2, 2, 3, 0}; -AttachmentVertices::AttachmentVertices(int verticesCount, uint16_t *triangles, int trianglesCount, const spine::String& textureUUID) { +AttachmentVertices::AttachmentVertices(int verticesCount, uint16_t *triangles, int trianglesCount, const spine::String& textureName) { _triangles = new Triangles(); _triangles->verts = new V3F_T2F_C4B[verticesCount]; _triangles->vertCount = verticesCount; _triangles->indices = triangles; _triangles->indexCount = trianglesCount; - _textureId = textureUUID; + _textureName = textureName; } AttachmentVertices::~AttachmentVertices() { @@ -20,13 +31,16 @@ AttachmentVertices::~AttachmentVertices() { } AttachmentVertices *AttachmentVertices::copy() { - AttachmentVertices *atv = new AttachmentVertices(_triangles->vertCount, _triangles->indices, _triangles->indexCount, _textureId); + AttachmentVertices *atv = new AttachmentVertices(_triangles->vertCount, _triangles->indices, _triangles->indexCount, _textureName); + atv->_textureUUID = _textureUUID; return atv; } +#ifdef CC_SPINE_VERSION_3_8 static void deleteAttachmentVertices(void *vertices) { delete static_cast(vertices); } +#endif AtlasAttachmentLoaderExtension::AtlasAttachmentLoaderExtension(Atlas *atlas) : AtlasAttachmentLoader(atlas), _atlasCache(atlas) { } @@ -37,7 +51,11 @@ void AtlasAttachmentLoaderExtension::configureAttachment(Attachment *attachment) if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { auto *regionAttachment = static_cast(attachment); auto &pages = _atlasCache->getPages(); +#ifdef CC_SPINE_VERSION_3_8 auto *region = static_cast(regionAttachment->getRendererObject()); +#else + auto *region = static_cast(regionAttachment->getRegion()); +#endif auto *attachmentVertices = new AttachmentVertices(4, quadTriangles, 6, region->page->name); V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; const auto &uvs = regionAttachment->getUVs(); @@ -45,11 +63,19 @@ void AtlasAttachmentLoaderExtension::configureAttachment(Attachment *attachment) vertices[i].texCoord.u = uvs[ii]; vertices[i].texCoord.v = uvs[ii + 1]; } +#ifdef CC_SPINE_VERSION_3_8 regionAttachment->setRendererObject(attachmentVertices, deleteAttachmentVertices); +#else + regionAttachment->getRegion()->rendererObject = attachmentVertices; +#endif } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { auto *meshAttachment = static_cast(attachment); auto &pages = _atlasCache->getPages(); +#ifdef CC_SPINE_VERSION_3_8 auto *region = static_cast(meshAttachment->getRendererObject()); +#else + auto *region = static_cast(meshAttachment->getRegion()); +#endif auto *attachmentVertices = new AttachmentVertices( static_cast(meshAttachment->getWorldVerticesLength() >> 1), meshAttachment->getTriangles().buffer(), static_cast(meshAttachment->getTriangles().size()), region->page->name); V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; @@ -58,6 +84,12 @@ void AtlasAttachmentLoaderExtension::configureAttachment(Attachment *attachment) vertices[i].texCoord.u = uvs[ii]; vertices[i].texCoord.v = uvs[ii + 1]; } +#ifdef CC_SPINE_VERSION_3_8 meshAttachment->setRendererObject(attachmentVertices, deleteAttachmentVertices); +#else + meshAttachment->getRegion()->rendererObject = attachmentVertices; +#endif + } else { + wasmLog(attachment->getName().buffer()); } } \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h index 0e6c415de3..d2e0064156 100644 --- a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h +++ b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h @@ -9,7 +9,8 @@ public: virtual ~AttachmentVertices(); AttachmentVertices *copy(); Triangles *_triangles = nullptr; - spine::String _textureId; + spine::String _textureUUID; + spine::String _textureName; }; class AtlasAttachmentLoaderExtension : public spine::AtlasAttachmentLoader { diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index 578c32a5c1..e1b90f05ac 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.8) set(APP_NAME "spine") +set(SPINE_VERSION "3.8") +# set(SPINE_VERSION "4.2") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -56,9 +58,28 @@ 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") -file(GLOB COCOS_ADAPTER_SRC "${CMAKE_CURRENT_LIST_DIR}/*.cpp") + + + +if(SPINE_VERSION STREQUAL "3.8") + include_directories(${CMAKE_CURRENT_LIST_DIR}/../spine/3.8/) + file(GLOB SPINE_CORE_SRC "${CMAKE_CURRENT_LIST_DIR}/../spine/3.8/spine/*.cpp") + file(GLOB COCOS_ADAPTER_SRC + "${CMAKE_CURRENT_LIST_DIR}/*.cpp" + "${CMAKE_CURRENT_LIST_DIR}/3.8/*.cpp" + ) + add_definitions(-DCC_SPINE_VERSION_3_8) +elseif(SPINE_VERSION STREQUAL "4.2") + include_directories(${CMAKE_CURRENT_LIST_DIR}/../spine/4.2/) + file(GLOB SPINE_CORE_SRC "${CMAKE_CURRENT_LIST_DIR}/../spine/4.2/spine/*.cpp") + file(GLOB COCOS_ADAPTER_SRC + "${CMAKE_CURRENT_LIST_DIR}/*.cpp" + "${CMAKE_CURRENT_LIST_DIR}/4.2/*.cpp" + ) + add_definitions(-DCC_SPINE_VERSION_4_2) +else() + message(FATAL_ERROR "Unsupported SPINE_VERSION: ${SPINE_VERSION}") +endif() add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC}) 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 48d60da09e..142b0f61d2 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -58,7 +58,11 @@ Skeleton *SpineSkeletonInstance::initSkeleton(SkeletonData *data) { _animState = new AnimationState(_animStateData); _clipper = new SkeletonClipping(); _skeleton->setToSetupPose(); +#ifdef CC_SPINE_VERSION_3_8 _skeleton->updateWorldTransform(); +#else + _skeleton->updateWorldTransform(Physics::Physics_Reset); +#endif _animState->setRendererObject(this); _animState->setListener(animationCallback); return _skeleton; @@ -74,7 +78,11 @@ TrackEntry *SpineSkeletonInstance::setAnimation(float trackIndex, const spine::S } auto *trackEntry = _animState->setAnimation(trackIndex, animation, loop); _animState->apply(*_skeleton); +#ifdef CC_SPINE_VERSION_3_8 _skeleton->updateWorldTransform(); +#else + _skeleton->updateWorldTransform(Physics::Physics_Update); +#endif return trackEntry; } @@ -96,7 +104,11 @@ SpineModel *SpineSkeletonInstance::updateRenderData() { if (_userData.debugMode) { _debugShapes.clear(); } +#ifdef CC_SPINE_VERSION_3_8 _skeleton->updateWorldTransform(); +#else + _skeleton->updateWorldTransform(Physics::Physics_Update); +#endif SpineMeshData::reset(); _model->clearMeshes(); if (_userData.useTint) { @@ -126,9 +138,13 @@ void SpineSkeletonInstance::collectMeshData() { DEBUG_SHAPE_TYPE debugShapeType = DEBUG_SHAPE_TYPE::DEBUG_REGION; SlotMesh currMesh = globalMesh; +#ifdef CC_SPINE_VERSION_3_8 if (_effect) { _effect->begin(*_skeleton); } +#else + void* _effect = nullptr; +#endif const Color& skeletonColor = _skeleton->getColor(); for (uint32_t drawIdx = 0; drawIdx < slotCount; ++drawIdx) { auto* slot = slotArray[drawIdx]; @@ -150,8 +166,12 @@ void SpineSkeletonInstance::collectMeshData() { if (attachmentRTTI.isExactly(spine::RegionAttachment::rtti)) { debugShapeType = DEBUG_SHAPE_TYPE::DEBUG_REGION; auto *attachment = static_cast(attachmentSlot); +#ifdef CC_SPINE_VERSION_3_8 auto *attachmentVertices = reinterpret_cast(attachment->getRendererObject()); - +#else + auto *attachmentVertices = reinterpret_cast(attachment->getRegion()->rendererObject); +#endif + auto& triangles = attachmentVertices->_triangles; auto vertCount = triangles->vertCount; auto indexCount = triangles->indexCount; @@ -170,18 +190,26 @@ void SpineSkeletonInstance::collectMeshData() { } } memcpy(indices, triangles->indices, ibSize); +#ifdef CC_SPINE_VERSION_3_8 attachment->computeWorldVertices(bone, (float *)vertices, 0, strideColor); +#else + attachment->computeWorldVertices(*slot, (float *)vertices, 0, strideColor); +#endif currMesh.set((uint8_t *)vertices, indices, vertCount, indexCount); const Color& attachmentColor = attachment->getColor(); color.r *= attachmentColor.r; color.g *= attachmentColor.g; color.b *= attachmentColor.b; color.a *= attachmentColor.a; - currMesh.textureID = attachmentVertices->_textureId; + currMesh.textureID = attachmentVertices->_textureUUID; } else if (attachmentRTTI.isExactly(spine::MeshAttachment::rtti)) { debugShapeType = DEBUG_SHAPE_TYPE::DEBUG_MESH; auto *attachment = static_cast(attachmentSlot); +#ifdef CC_SPINE_VERSION_3_8 auto *attachmentVertices = static_cast(attachment->getRendererObject()); +#else + auto *attachmentVertices = static_cast(attachment->getRegion()->rendererObject); +#endif auto& triangles = attachmentVertices->_triangles; auto vertCount = triangles->vertCount; @@ -207,7 +235,7 @@ void SpineSkeletonInstance::collectMeshData() { color.g *= attachmentColor.g; color.b *= attachmentColor.b; color.a *= attachmentColor.a; - currMesh.textureID = attachmentVertices->_textureId; + currMesh.textureID = attachmentVertices->_textureUUID; } else if (attachmentRTTI.isExactly(spine::ClippingAttachment::rtti)) { auto *clip = static_cast(attachmentSlot); _clipper->clipStart(*slot, clip); @@ -264,7 +292,9 @@ void SpineSkeletonInstance::collectMeshData() { vertices[v].vertex.y = verts[vv + 1]; vertices[v].texCoord.u = uvs[vv]; vertices[v].texCoord.v = uvs[vv + 1]; +#ifdef CC_SPINE_VERSION_3_8 _effect->transform(vertices[v].vertex.x, vertices[v].vertex.y); +#endif *((uint32_t *)&vertices[v].color) = light; } } else { @@ -281,7 +311,9 @@ void SpineSkeletonInstance::collectMeshData() { V3F_T2F_C4B *vertex = (V3F_T2F_C4B *)currMesh.vBuf; if (_effect) { for (int v = 0; v < vertCount; ++v) { +#ifdef CC_SPINE_VERSION_3_8 _effect->transform(vertex[v].vertex.x, vertex[v].vertex.y); +#endif *((uint32_t *)&vertex[v].color) = light; } } else { @@ -317,7 +349,9 @@ void SpineSkeletonInstance::collectMeshData() { vertices[v].vertex.y = verts[vv + 1]; vertices[v].texCoord.u = uvs[vv]; vertices[v].texCoord.v = uvs[vv + 1]; +#ifdef CC_SPINE_VERSION_3_8 _effect->transform(vertices[v].vertex.x, vertices[v].vertex.y); +#endif *((uint32_t *)&vertices[v].color) = light; *((uint32_t *)&vertices[v].color2) = dark; } @@ -333,10 +367,12 @@ void SpineSkeletonInstance::collectMeshData() { } } else { auto vertCount = currMesh.vCount; - V3F_T2F_C4B_C4B *vertex = (V3F_T2F_C4B_C4B *)currMesh.vBuf; + V3F_T2F_C4B_C4B *vertex = (V3F_T2F_C4B_C4B *)currMesh.vBuf; if (_effect) { for (int v = 0; v < vertCount; ++v) { +#ifdef CC_SPINE_VERSION_3_8 _effect->transform(vertex[v].vertex.x, vertex[v].vertex.y); +#endif *((uint32_t *)&vertex[v].color) = light; *((uint32_t *)&vertex[v].color2) = dark; } @@ -374,7 +410,9 @@ void SpineSkeletonInstance::collectMeshData() { } _clipper->clipEnd(); +#ifdef CC_SPINE_VERSION_3_8 if (_effect) _effect->end(); +#endif } void SpineSkeletonInstance::setPremultipliedAlpha(bool val) { @@ -388,6 +426,7 @@ void SpineSkeletonInstance::setColor(float r, float g, float b, float a) { _userData.color.a = a; } +#ifdef CC_SPINE_VERSION_3_8 void SpineSkeletonInstance::setJitterEffect(JitterVertexEffect *effect) { _effect = effect; } @@ -399,6 +438,7 @@ void SpineSkeletonInstance::setSwirlEffect(SwirlVertexEffect *effect) { void SpineSkeletonInstance::clearEffect() { _effect = nullptr; } +#endif AnimationState *SpineSkeletonInstance::getAnimationState() { return _animState; @@ -455,6 +495,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint } if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) { auto *region = static_cast(attachment); +#ifdef CC_SPINE_VERSION_3_8 region->setRegionWidth(width); region->setRegionHeight(height); region->setRegionOriginalWidth(width); @@ -468,14 +509,41 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint attachmentVertices = attachmentVertices->copy(); region->setRendererObject(attachmentVertices); } +#else + auto *textureRegion = region->getRegion(); + if (textureRegion) { + textureRegion->width = width; + textureRegion->height = height; + textureRegion->originalWidth = width; + textureRegion->originalHeight = height; + } + region->setWidth(width); + region->setHeight(height); + auto &uvs = region->getUVs(); + uvs[2] = 0; + uvs[3] = 1; + uvs[4] = 0; + uvs[5] = 0; + uvs[6] = 1; + uvs[7] = 0; + uvs[0] = 1; + uvs[1] = 1; + region->updateRegion(); + auto *attachmentVertices = static_cast(region->getRegion()->rendererObject); + if (createNew) { + attachmentVertices = attachmentVertices->copy(); + region->getRegion()->rendererObject = attachmentVertices; + } +#endif V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; - const auto &UVs = region->getUVs(); + 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); +#ifdef CC_SPINE_VERSION_3_8 mesh->setRegionWidth(width); mesh->setRegionHeight(height); mesh->setRegionOriginalWidth(width); @@ -494,6 +562,28 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint attachmentVertices = attachmentVertices->copy(); mesh->setRendererObject(attachmentVertices); } +#else + auto *region = mesh->getRegion(); + if (region) { + region->width = width; + region->height = height; + region->originalWidth = width; + region->originalHeight = height; + region->u = 0; + region->v = 0; + region->u2 = 1.0f; + region->v2 = 1.0f; + region->degrees = 0; + } + mesh->setWidth(width); + mesh->setHeight(height); + mesh->updateRegion(); + auto *attachmentVertices = static_cast(mesh->getRegion()->rendererObject); + if (createNew) { + attachmentVertices = attachmentVertices->copy(); + mesh->getRegion()->rendererObject = attachmentVertices; + } +#endif V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts; const auto &UVs = mesh->getUVs(); for (size_t i = 0, ii = 0, nn = mesh->getWorldVerticesLength(); ii < nn; ++i, ii += 2) { 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 f370bd1932..4f66bdadf3 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -43,9 +43,11 @@ public: void setUseTint(bool useTint); void setDebugMode(bool debug); void setColor(float r, float g, float b, float a); +#ifdef CC_SPINE_VERSION_3_8 void setJitterEffect(spine::JitterVertexEffect *effect); void setSwirlEffect(spine::SwirlVertexEffect *effect); void clearEffect(); +#endif spine::AnimationState *getAnimationState(); void setMix(const spine::String &from, const spine::String &to, float duration); inline void setListener(uint32_t listenerID) { _eventListenerID = listenerID;} @@ -68,7 +70,9 @@ private: spine::AnimationStateData *_animStateData = nullptr; spine::AnimationState *_animState = nullptr; spine::SkeletonClipping *_clipper = nullptr; +#ifdef CC_SPINE_VERSION_3_8 spine::VertexEffect *_effect = nullptr; +#endif SpineModel *_model = nullptr; uint32_t _eventListenerID = 0; uint32_t _trackEntryListenerID = 0; diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index 18024fa31e..bcb6a96d65 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -37,18 +37,26 @@ namespace { AttachmentVertices* attachmentVertices; auto* attachment = entry._attachment; if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { - auto* meshAttachment = static_cast(attachment); + auto* meshAttachment = static_cast(attachment); +#ifdef CC_SPINE_VERSION_3_8 attachmentVertices = static_cast(meshAttachment->getRendererObject()); - } else { - auto* regionAttachment = static_cast(attachment); +#else + attachmentVertices = static_cast(meshAttachment->getRegion()->rendererObject); +#endif + } else if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { + auto* regionAttachment = static_cast(attachment); +#ifdef CC_SPINE_VERSION_3_8 attachmentVertices = static_cast(regionAttachment->getRendererObject()); +#else + attachmentVertices = static_cast(regionAttachment->getRegion()->rendererObject); +#endif } if (attachmentVertices) { - auto& textureName = attachmentVertices->_textureId; + auto& textureName = attachmentVertices->_textureName; if (textureMap.containsKey(textureName)) { - attachmentVertices->_textureId = textureMap[textureName]; + attachmentVertices->_textureUUID = textureMap[textureName]; } else { - spine::String logInfo(attachment->getName()); + spine::String logInfo(textureName); logInfo.append(" attachment's texture doesn`t exist "); logInfo.append(textureName); logToConsole(logInfo.buffer()); @@ -97,9 +105,17 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const String& jsonS return nullptr; } AttachmentLoader* attachmentLoader = new AtlasAttachmentLoaderExtension(atlas); + #ifdef CC_SPINE_VERSION_3_8 SkeletonJson json(attachmentLoader); + #else + SkeletonJson json(attachmentLoader, true); + #endif json.setScale(1.0F); SkeletonData* skeletonData = json.readSkeletonData(jsonStr.buffer()); + auto& errorMsg = json.getError(); + if (!errorMsg.isEmpty()) { + logToConsole(errorMsg.buffer()); + } updateAttachmentVerticesTextureId(skeletonData, textureNames, textureUUIDs); @@ -116,9 +132,17 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize return nullptr; } AttachmentLoader* attachmentLoader = new AtlasAttachmentLoaderExtension(atlas); + #ifdef CC_SPINE_VERSION_3_8 SkeletonBinary binary(attachmentLoader); + #else + SkeletonBinary binary(attachmentLoader, true); + #endif binary.setScale(1.0F); SkeletonData* skeletonData = binary.readSkeletonData(s_mem, byteSize); + auto& errorMsg = binary.getError(); + if (!errorMsg.isEmpty()) { + logToConsole(errorMsg.buffer()); + } updateAttachmentVerticesTextureId(skeletonData, textureNames, textureUUIDs); @@ -137,6 +161,30 @@ void SpineWasmUtil::registerSpineSkeletonDataWithUUID(SkeletonData* data, const void SpineWasmUtil::destroySpineSkeletonDataWithUUID(const String& uuid) { if (skeletonDataMap.containsKey(uuid)) { auto* data = skeletonDataMap[uuid]; +#if CC_USE_SPINE_4_2 + auto& skins = data->getSkins(); + auto skinSize = skins.size(); + // release AttachmentVertices + for (int i = 0; i < skinSize; ++i) { + auto* skin = skins[i]; + auto entries = skin->getAttachments(); + while (entries.hasNext()) { + Skin::AttachmentMap::Entry& entry = entries.next(); + AttachmentVertices* attachmentVertices; + auto* attachment = entry._attachment; + if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { + auto* meshAttachment = static_cast(attachment); + attachmentVertices = static_cast(meshAttachment->getRegion()->rendererObject); + } else if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { + auto* regionAttachment = static_cast(attachment); + attachmentVertices = static_cast(regionAttachment->getRegion()->rendererObject); + } + if (attachmentVertices) { + delete attachmentVertices; + } + } + } +#endif delete data; skeletonDataMap.remove(uuid); } diff --git a/native/cocos/editor-support/spine/Animation.cpp b/native/cocos/editor-support/spine/3.8/spine/Animation.cpp similarity index 100% rename from native/cocos/editor-support/spine/Animation.cpp rename to native/cocos/editor-support/spine/3.8/spine/Animation.cpp diff --git a/native/cocos/editor-support/spine/Animation.h b/native/cocos/editor-support/spine/3.8/spine/Animation.h similarity index 100% rename from native/cocos/editor-support/spine/Animation.h rename to native/cocos/editor-support/spine/3.8/spine/Animation.h diff --git a/native/cocos/editor-support/spine/AnimationState.cpp b/native/cocos/editor-support/spine/3.8/spine/AnimationState.cpp similarity index 100% rename from native/cocos/editor-support/spine/AnimationState.cpp rename to native/cocos/editor-support/spine/3.8/spine/AnimationState.cpp diff --git a/native/cocos/editor-support/spine/AnimationState.h b/native/cocos/editor-support/spine/3.8/spine/AnimationState.h similarity index 100% rename from native/cocos/editor-support/spine/AnimationState.h rename to native/cocos/editor-support/spine/3.8/spine/AnimationState.h diff --git a/native/cocos/editor-support/spine/AnimationStateData.cpp b/native/cocos/editor-support/spine/3.8/spine/AnimationStateData.cpp similarity index 100% rename from native/cocos/editor-support/spine/AnimationStateData.cpp rename to native/cocos/editor-support/spine/3.8/spine/AnimationStateData.cpp diff --git a/native/cocos/editor-support/spine/AnimationStateData.h b/native/cocos/editor-support/spine/3.8/spine/AnimationStateData.h similarity index 100% rename from native/cocos/editor-support/spine/AnimationStateData.h rename to native/cocos/editor-support/spine/3.8/spine/AnimationStateData.h diff --git a/native/cocos/editor-support/spine/Atlas.cpp b/native/cocos/editor-support/spine/3.8/spine/Atlas.cpp similarity index 100% rename from native/cocos/editor-support/spine/Atlas.cpp rename to native/cocos/editor-support/spine/3.8/spine/Atlas.cpp diff --git a/native/cocos/editor-support/spine/Atlas.h b/native/cocos/editor-support/spine/3.8/spine/Atlas.h similarity index 100% rename from native/cocos/editor-support/spine/Atlas.h rename to native/cocos/editor-support/spine/3.8/spine/Atlas.h diff --git a/native/cocos/editor-support/spine/AtlasAttachmentLoader.cpp b/native/cocos/editor-support/spine/3.8/spine/AtlasAttachmentLoader.cpp similarity index 100% rename from native/cocos/editor-support/spine/AtlasAttachmentLoader.cpp rename to native/cocos/editor-support/spine/3.8/spine/AtlasAttachmentLoader.cpp diff --git a/native/cocos/editor-support/spine/AtlasAttachmentLoader.h b/native/cocos/editor-support/spine/3.8/spine/AtlasAttachmentLoader.h similarity index 100% rename from native/cocos/editor-support/spine/AtlasAttachmentLoader.h rename to native/cocos/editor-support/spine/3.8/spine/AtlasAttachmentLoader.h diff --git a/native/cocos/editor-support/spine/Attachment.cpp b/native/cocos/editor-support/spine/3.8/spine/Attachment.cpp similarity index 100% rename from native/cocos/editor-support/spine/Attachment.cpp rename to native/cocos/editor-support/spine/3.8/spine/Attachment.cpp diff --git a/native/cocos/editor-support/spine/Attachment.h b/native/cocos/editor-support/spine/3.8/spine/Attachment.h similarity index 100% rename from native/cocos/editor-support/spine/Attachment.h rename to native/cocos/editor-support/spine/3.8/spine/Attachment.h diff --git a/native/cocos/editor-support/spine/AttachmentLoader.cpp b/native/cocos/editor-support/spine/3.8/spine/AttachmentLoader.cpp similarity index 100% rename from native/cocos/editor-support/spine/AttachmentLoader.cpp rename to native/cocos/editor-support/spine/3.8/spine/AttachmentLoader.cpp diff --git a/native/cocos/editor-support/spine/AttachmentLoader.h b/native/cocos/editor-support/spine/3.8/spine/AttachmentLoader.h similarity index 97% rename from native/cocos/editor-support/spine/AttachmentLoader.h rename to native/cocos/editor-support/spine/3.8/spine/AttachmentLoader.h index d3d4f433e3..b3374795e7 100644 --- a/native/cocos/editor-support/spine/AttachmentLoader.h +++ b/native/cocos/editor-support/spine/3.8/spine/AttachmentLoader.h @@ -1,75 +1,75 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_AttachmentLoader_h -#define Spine_AttachmentLoader_h - -#include -#include -#include - -namespace spine { -class Skin; -class Attachment; -class RegionAttachment; -class MeshAttachment; -class BoundingBoxAttachment; -class PathAttachment; -class PointAttachment; -class ClippingAttachment; - -class SP_API AttachmentLoader : public SpineObject { -public: - RTTI_DECL - - AttachmentLoader(); - - virtual ~AttachmentLoader(); - - /// @return May be NULL to not load any attachment. - virtual RegionAttachment* newRegionAttachment(Skin& skin, const String& name, const String& path) = 0; - - /// @return May be NULL to not load any attachment. - virtual MeshAttachment* newMeshAttachment(Skin& skin, const String& name, const String& path) = 0; - - /// @return May be NULL to not load any attachment. - virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, const String& name) = 0; - - /// @return May be NULL to not load any attachment - virtual PathAttachment* newPathAttachment(Skin& skin, const String& name) = 0; - - virtual PointAttachment* newPointAttachment(Skin& skin, const String& name) = 0; - - virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name) = 0; - - virtual void configureAttachment(Attachment* attachment) = 0; -}; -} // namespace spine - -#endif /* Spine_AttachmentLoader_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_AttachmentLoader_h +#define Spine_AttachmentLoader_h + +#include +#include +#include + +namespace spine { +class Skin; +class Attachment; +class RegionAttachment; +class MeshAttachment; +class BoundingBoxAttachment; +class PathAttachment; +class PointAttachment; +class ClippingAttachment; + +class SP_API AttachmentLoader : public SpineObject { +public: + RTTI_DECL + + AttachmentLoader(); + + virtual ~AttachmentLoader(); + + /// @return May be NULL to not load any attachment. + virtual RegionAttachment* newRegionAttachment(Skin& skin, const String& name, const String& path) = 0; + + /// @return May be NULL to not load any attachment. + virtual MeshAttachment* newMeshAttachment(Skin& skin, const String& name, const String& path) = 0; + + /// @return May be NULL to not load any attachment. + virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, const String& name) = 0; + + /// @return May be NULL to not load any attachment + virtual PathAttachment* newPathAttachment(Skin& skin, const String& name) = 0; + + virtual PointAttachment* newPointAttachment(Skin& skin, const String& name) = 0; + + virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name) = 0; + + virtual void configureAttachment(Attachment* attachment) = 0; +}; +} // namespace spine + +#endif /* Spine_AttachmentLoader_h */ diff --git a/native/cocos/editor-support/spine/AttachmentTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/AttachmentTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/AttachmentTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/AttachmentTimeline.cpp diff --git a/native/cocos/editor-support/spine/AttachmentTimeline.h b/native/cocos/editor-support/spine/3.8/spine/AttachmentTimeline.h similarity index 100% rename from native/cocos/editor-support/spine/AttachmentTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/AttachmentTimeline.h diff --git a/native/cocos/editor-support/spine/AttachmentType.h b/native/cocos/editor-support/spine/3.8/spine/AttachmentType.h similarity index 97% rename from native/cocos/editor-support/spine/AttachmentType.h rename to native/cocos/editor-support/spine/3.8/spine/AttachmentType.h index b4d12c10ad..814d397d1c 100644 --- a/native/cocos/editor-support/spine/AttachmentType.h +++ b/native/cocos/editor-support/spine/3.8/spine/AttachmentType.h @@ -1,45 +1,45 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_AttachmentType_h -#define Spine_AttachmentType_h - -namespace spine { -enum AttachmentType { - AttachmentType_Region, - AttachmentType_Boundingbox, - AttachmentType_Mesh, - AttachmentType_Linkedmesh, - AttachmentType_Path, - AttachmentType_Point, - AttachmentType_Clipping -}; -} - -#endif /* Spine_AttachmentType_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_AttachmentType_h +#define Spine_AttachmentType_h + +namespace spine { +enum AttachmentType { + AttachmentType_Region, + AttachmentType_Boundingbox, + AttachmentType_Mesh, + AttachmentType_Linkedmesh, + AttachmentType_Path, + AttachmentType_Point, + AttachmentType_Clipping +}; +} + +#endif /* Spine_AttachmentType_h */ diff --git a/native/cocos/editor-support/spine/BlendMode.h b/native/cocos/editor-support/spine/3.8/spine/BlendMode.h similarity index 97% rename from native/cocos/editor-support/spine/BlendMode.h rename to native/cocos/editor-support/spine/3.8/spine/BlendMode.h index 5c6cbda228..781e2ed282 100644 --- a/native/cocos/editor-support/spine/BlendMode.h +++ b/native/cocos/editor-support/spine/3.8/spine/BlendMode.h @@ -1,42 +1,42 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_BlendMode_h -#define Spine_BlendMode_h - -namespace spine { -enum BlendMode { - BlendMode_Normal = 0, - BlendMode_Additive, - BlendMode_Multiply, - BlendMode_Screen -}; -} - -#endif /* Spine_BlendMode_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_BlendMode_h +#define Spine_BlendMode_h + +namespace spine { +enum BlendMode { + BlendMode_Normal = 0, + BlendMode_Additive, + BlendMode_Multiply, + BlendMode_Screen +}; +} + +#endif /* Spine_BlendMode_h */ diff --git a/native/cocos/editor-support/spine/Bone.cpp b/native/cocos/editor-support/spine/3.8/spine/Bone.cpp similarity index 100% rename from native/cocos/editor-support/spine/Bone.cpp rename to native/cocos/editor-support/spine/3.8/spine/Bone.cpp diff --git a/native/cocos/editor-support/spine/Bone.h b/native/cocos/editor-support/spine/3.8/spine/Bone.h similarity index 100% rename from native/cocos/editor-support/spine/Bone.h rename to native/cocos/editor-support/spine/3.8/spine/Bone.h diff --git a/native/cocos/editor-support/spine/BoneData.cpp b/native/cocos/editor-support/spine/3.8/spine/BoneData.cpp similarity index 96% rename from native/cocos/editor-support/spine/BoneData.cpp rename to native/cocos/editor-support/spine/3.8/spine/BoneData.cpp index c6720b7a12..a037e679a1 100644 --- a/native/cocos/editor-support/spine/BoneData.cpp +++ b/native/cocos/editor-support/spine/3.8/spine/BoneData.cpp @@ -1,147 +1,147 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifdef SPINE_UE4 - #include "SpinePluginPrivatePCH.h" -#endif - -#include - -#include - -using namespace spine; - -BoneData::BoneData(int index, const String &name, BoneData *parent) : _index(index), - _name(name), - _parent(parent), - _length(0), - _x(0), - _y(0), - _rotation(0), - _scaleX(1), - _scaleY(1), - _shearX(0), - _shearY(0), - _transformMode(TransformMode_Normal), - _skinRequired(false) { - assert(index >= 0); - assert(_name.length() > 0); -} - -int BoneData::getIndex() { - return _index; -} - -const String &BoneData::getName() { - return _name; -} - -BoneData *BoneData::getParent() { - return _parent; -} - -float BoneData::getLength() { - return _length; -} - -void BoneData::setLength(float inValue) { - _length = inValue; -} - -float BoneData::getX() { - return _x; -} - -void BoneData::setX(float inValue) { - _x = inValue; -} - -float BoneData::getY() { - return _y; -} - -void BoneData::setY(float inValue) { - _y = inValue; -} - -float BoneData::getRotation() { - return _rotation; -} - -void BoneData::setRotation(float inValue) { - _rotation = inValue; -} - -float BoneData::getScaleX() { - return _scaleX; -} - -void BoneData::setScaleX(float inValue) { - _scaleX = inValue; -} - -float BoneData::getScaleY() { - return _scaleY; -} - -void BoneData::setScaleY(float inValue) { - _scaleY = inValue; -} - -float BoneData::getShearX() { - return _shearX; -} - -void BoneData::setShearX(float inValue) { - _shearX = inValue; -} - -float BoneData::getShearY() { - return _shearY; -} - -void BoneData::setShearY(float inValue) { - _shearY = inValue; -} - -TransformMode BoneData::getTransformMode() { - return _transformMode; -} - -void BoneData::setTransformMode(TransformMode inValue) { - _transformMode = inValue; -} - -bool BoneData::isSkinRequired() { - return _skinRequired; -} - -void BoneData::setSkinRequired(bool inValue) { - _skinRequired = inValue; -} +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include + +#include + +using namespace spine; + +BoneData::BoneData(int index, const String &name, BoneData *parent) : _index(index), + _name(name), + _parent(parent), + _length(0), + _x(0), + _y(0), + _rotation(0), + _scaleX(1), + _scaleY(1), + _shearX(0), + _shearY(0), + _transformMode(TransformMode_Normal), + _skinRequired(false) { + assert(index >= 0); + assert(_name.length() > 0); +} + +int BoneData::getIndex() { + return _index; +} + +const String &BoneData::getName() { + return _name; +} + +BoneData *BoneData::getParent() { + return _parent; +} + +float BoneData::getLength() { + return _length; +} + +void BoneData::setLength(float inValue) { + _length = inValue; +} + +float BoneData::getX() { + return _x; +} + +void BoneData::setX(float inValue) { + _x = inValue; +} + +float BoneData::getY() { + return _y; +} + +void BoneData::setY(float inValue) { + _y = inValue; +} + +float BoneData::getRotation() { + return _rotation; +} + +void BoneData::setRotation(float inValue) { + _rotation = inValue; +} + +float BoneData::getScaleX() { + return _scaleX; +} + +void BoneData::setScaleX(float inValue) { + _scaleX = inValue; +} + +float BoneData::getScaleY() { + return _scaleY; +} + +void BoneData::setScaleY(float inValue) { + _scaleY = inValue; +} + +float BoneData::getShearX() { + return _shearX; +} + +void BoneData::setShearX(float inValue) { + _shearX = inValue; +} + +float BoneData::getShearY() { + return _shearY; +} + +void BoneData::setShearY(float inValue) { + _shearY = inValue; +} + +TransformMode BoneData::getTransformMode() { + return _transformMode; +} + +void BoneData::setTransformMode(TransformMode inValue) { + _transformMode = inValue; +} + +bool BoneData::isSkinRequired() { + return _skinRequired; +} + +void BoneData::setSkinRequired(bool inValue) { + _skinRequired = inValue; +} diff --git a/native/cocos/editor-support/spine/BoneData.h b/native/cocos/editor-support/spine/3.8/spine/BoneData.h similarity index 100% rename from native/cocos/editor-support/spine/BoneData.h rename to native/cocos/editor-support/spine/3.8/spine/BoneData.h diff --git a/native/cocos/editor-support/spine/BoundingBoxAttachment.cpp b/native/cocos/editor-support/spine/3.8/spine/BoundingBoxAttachment.cpp similarity index 100% rename from native/cocos/editor-support/spine/BoundingBoxAttachment.cpp rename to native/cocos/editor-support/spine/3.8/spine/BoundingBoxAttachment.cpp diff --git a/native/cocos/editor-support/spine/BoundingBoxAttachment.h b/native/cocos/editor-support/spine/3.8/spine/BoundingBoxAttachment.h similarity index 100% rename from native/cocos/editor-support/spine/BoundingBoxAttachment.h rename to native/cocos/editor-support/spine/3.8/spine/BoundingBoxAttachment.h diff --git a/native/cocos/editor-support/spine/ClippingAttachment.cpp b/native/cocos/editor-support/spine/3.8/spine/ClippingAttachment.cpp similarity index 100% rename from native/cocos/editor-support/spine/ClippingAttachment.cpp rename to native/cocos/editor-support/spine/3.8/spine/ClippingAttachment.cpp diff --git a/native/cocos/editor-support/spine/ClippingAttachment.h b/native/cocos/editor-support/spine/3.8/spine/ClippingAttachment.h similarity index 97% rename from native/cocos/editor-support/spine/ClippingAttachment.h rename to native/cocos/editor-support/spine/3.8/spine/ClippingAttachment.h index bd21e223ea..282f78f6e4 100644 --- a/native/cocos/editor-support/spine/ClippingAttachment.h +++ b/native/cocos/editor-support/spine/3.8/spine/ClippingAttachment.h @@ -1,59 +1,59 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_ClippingAttachment_h -#define Spine_ClippingAttachment_h - -#include - -namespace spine { -class SlotData; - -class SP_API ClippingAttachment : public VertexAttachment { - friend class SkeletonBinary; - friend class SkeletonJson; - - friend class SkeletonClipping; - - RTTI_DECL - -public: - explicit ClippingAttachment(const String& name); - - SlotData* getEndSlot(); - void setEndSlot(SlotData* inValue); - - virtual Attachment* copy(); - -private: - SlotData* _endSlot; -}; -} // namespace spine - -#endif /* Spine_ClippingAttachment_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_ClippingAttachment_h +#define Spine_ClippingAttachment_h + +#include + +namespace spine { +class SlotData; + +class SP_API ClippingAttachment : public VertexAttachment { + friend class SkeletonBinary; + friend class SkeletonJson; + + friend class SkeletonClipping; + + RTTI_DECL + +public: + explicit ClippingAttachment(const String& name); + + SlotData* getEndSlot(); + void setEndSlot(SlotData* inValue); + + virtual Attachment* copy(); + +private: + SlotData* _endSlot; +}; +} // namespace spine + +#endif /* Spine_ClippingAttachment_h */ diff --git a/native/cocos/editor-support/spine/Color.h b/native/cocos/editor-support/spine/3.8/spine/Color.h similarity index 100% rename from native/cocos/editor-support/spine/Color.h rename to native/cocos/editor-support/spine/3.8/spine/Color.h diff --git a/native/cocos/editor-support/spine/ColorTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/ColorTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/ColorTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/ColorTimeline.cpp diff --git a/native/cocos/editor-support/spine/ColorTimeline.h b/native/cocos/editor-support/spine/3.8/spine/ColorTimeline.h similarity index 100% rename from native/cocos/editor-support/spine/ColorTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/ColorTimeline.h diff --git a/native/cocos/editor-support/spine/3.8/spine/Constraint.cpp b/native/cocos/editor-support/spine/3.8/spine/Constraint.cpp new file mode 100644 index 0000000000..60eb7f0f68 --- /dev/null +++ b/native/cocos/editor-support/spine/3.8/spine/Constraint.cpp @@ -0,0 +1,45 @@ +/****************************************************************************** + * Spine Runtimes Software License v2.5 + * + * Copyright (c) 2013-2016, Esoteric Software + * All rights reserved. + * + * You are granted a perpetual, non-exclusive, non-sublicensable, and + * non-transferable license to use, install, execute, and perform the Spine + * Runtimes software and derivative works solely for personal or internal + * use. Without the written permission of Esoteric Software (see Section 2 of + * the Spine Software License Agreement), you may not (a) modify, translate, + * adapt, or develop new applications using the Spine Runtimes or otherwise + * create derivative works or improvements of the Spine Runtimes or (b) remove, + * delete, alter, or obscure any trademarks or any copyright, trademark, patent, + * or other intellectual property or proprietary rights notices on or in the + * Software, including any copy thereof. Redistributions in binary or source + * form must include this license and terms. + * + * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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 THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include + +using namespace spine; + +RTTI_IMPL(Constraint, Updatable) + +Constraint::Constraint() { +} + +Constraint::~Constraint() { +} diff --git a/native/cocos/editor-support/spine/Constraint.h b/native/cocos/editor-support/spine/3.8/spine/Constraint.h similarity index 100% rename from native/cocos/editor-support/spine/Constraint.h rename to native/cocos/editor-support/spine/3.8/spine/Constraint.h diff --git a/native/cocos/editor-support/spine/ConstraintData.cpp b/native/cocos/editor-support/spine/3.8/spine/ConstraintData.cpp similarity index 100% rename from native/cocos/editor-support/spine/ConstraintData.cpp rename to native/cocos/editor-support/spine/3.8/spine/ConstraintData.cpp diff --git a/native/cocos/editor-support/spine/ConstraintData.h b/native/cocos/editor-support/spine/3.8/spine/ConstraintData.h similarity index 100% rename from native/cocos/editor-support/spine/ConstraintData.h rename to native/cocos/editor-support/spine/3.8/spine/ConstraintData.h diff --git a/native/cocos/editor-support/spine/ContainerUtil.h b/native/cocos/editor-support/spine/3.8/spine/ContainerUtil.h similarity index 100% rename from native/cocos/editor-support/spine/ContainerUtil.h rename to native/cocos/editor-support/spine/3.8/spine/ContainerUtil.h diff --git a/native/cocos/editor-support/spine/CurveTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/CurveTimeline.cpp similarity index 97% rename from native/cocos/editor-support/spine/CurveTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/CurveTimeline.cpp index 8149465ca7..22212b8743 100644 --- a/native/cocos/editor-support/spine/CurveTimeline.cpp +++ b/native/cocos/editor-support/spine/3.8/spine/CurveTimeline.cpp @@ -1,127 +1,127 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifdef SPINE_UE4 - #include "SpinePluginPrivatePCH.h" -#endif - -#include - -#include - -using namespace spine; - -RTTI_IMPL(CurveTimeline, Timeline) - -const float CurveTimeline::LINEAR = 0; -const float CurveTimeline::STEPPED = 1; -const float CurveTimeline::BEZIER = 2; -const int CurveTimeline::BEZIER_SIZE = 10 * 2 - 1; - -CurveTimeline::CurveTimeline(int frameCount) { - assert(frameCount > 0); - - _curves.setSize((frameCount - 1) * BEZIER_SIZE, 0); -} - -CurveTimeline::~CurveTimeline() { -} - -size_t CurveTimeline::getFrameCount() { - return _curves.size() / BEZIER_SIZE + 1; -} - -void CurveTimeline::setLinear(size_t frameIndex) { - _curves[frameIndex * BEZIER_SIZE] = LINEAR; -} - -void CurveTimeline::setStepped(size_t frameIndex) { - _curves[frameIndex * BEZIER_SIZE] = STEPPED; -} - -void CurveTimeline::setCurve(size_t frameIndex, float cx1, float cy1, float cx2, float cy2) { - float tmpx = (-cx1 * 2 + cx2) * 0.03f, tmpy = (-cy1 * 2 + cy2) * 0.03f; - float dddfx = ((cx1 - cx2) * 3 + 1) * 0.006f, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006f; - float ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy; - float dfx = cx1 * 0.3f + tmpx + dddfx * 0.16666667f, dfy = cy1 * 0.3f + tmpy + dddfy * 0.16666667f; - - size_t i = frameIndex * BEZIER_SIZE; - _curves[i++] = BEZIER; - - float x = dfx, y = dfy; - for (size_t n = i + BEZIER_SIZE - 1; i < n; i += 2) { - _curves[i] = x; - _curves[i + 1] = y; - dfx += ddfx; - dfy += ddfy; - ddfx += dddfx; - ddfy += dddfy; - x += dfx; - y += dfy; - } -} - -float CurveTimeline::getCurvePercent(size_t frameIndex, float percent) { - percent = MathUtil::clamp(percent, 0, 1); - size_t i = frameIndex * BEZIER_SIZE; - float type = _curves[i]; - - if (type == LINEAR) { - return percent; - } - - if (type == STEPPED) { - return 0; - } - - i++; - float x = 0; - for (size_t start = i, n = i + BEZIER_SIZE - 1; i < n; i += 2) { - x = _curves[i]; - if (x >= percent) { - float prevX, prevY; - if (i == start) { - prevX = 0; - prevY = 0; - } else { - prevX = _curves[i - 2]; - prevY = _curves[i - 1]; - } - return prevY + (_curves[i + 1] - prevY) * (percent - prevX) / (x - prevX); - } - } - - float y = _curves[i - 1]; - - return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1. -} - -float CurveTimeline::getCurveType(size_t frameIndex) { - return _curves[frameIndex * BEZIER_SIZE]; -} +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include + +#include + +using namespace spine; + +RTTI_IMPL(CurveTimeline, Timeline) + +const float CurveTimeline::LINEAR = 0; +const float CurveTimeline::STEPPED = 1; +const float CurveTimeline::BEZIER = 2; +const int CurveTimeline::BEZIER_SIZE = 10 * 2 - 1; + +CurveTimeline::CurveTimeline(int frameCount) { + assert(frameCount > 0); + + _curves.setSize((frameCount - 1) * BEZIER_SIZE, 0); +} + +CurveTimeline::~CurveTimeline() { +} + +size_t CurveTimeline::getFrameCount() { + return _curves.size() / BEZIER_SIZE + 1; +} + +void CurveTimeline::setLinear(size_t frameIndex) { + _curves[frameIndex * BEZIER_SIZE] = LINEAR; +} + +void CurveTimeline::setStepped(size_t frameIndex) { + _curves[frameIndex * BEZIER_SIZE] = STEPPED; +} + +void CurveTimeline::setCurve(size_t frameIndex, float cx1, float cy1, float cx2, float cy2) { + float tmpx = (-cx1 * 2 + cx2) * 0.03f, tmpy = (-cy1 * 2 + cy2) * 0.03f; + float dddfx = ((cx1 - cx2) * 3 + 1) * 0.006f, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006f; + float ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy; + float dfx = cx1 * 0.3f + tmpx + dddfx * 0.16666667f, dfy = cy1 * 0.3f + tmpy + dddfy * 0.16666667f; + + size_t i = frameIndex * BEZIER_SIZE; + _curves[i++] = BEZIER; + + float x = dfx, y = dfy; + for (size_t n = i + BEZIER_SIZE - 1; i < n; i += 2) { + _curves[i] = x; + _curves[i + 1] = y; + dfx += ddfx; + dfy += ddfy; + ddfx += dddfx; + ddfy += dddfy; + x += dfx; + y += dfy; + } +} + +float CurveTimeline::getCurvePercent(size_t frameIndex, float percent) { + percent = MathUtil::clamp(percent, 0, 1); + size_t i = frameIndex * BEZIER_SIZE; + float type = _curves[i]; + + if (type == LINEAR) { + return percent; + } + + if (type == STEPPED) { + return 0; + } + + i++; + float x = 0; + for (size_t start = i, n = i + BEZIER_SIZE - 1; i < n; i += 2) { + x = _curves[i]; + if (x >= percent) { + float prevX, prevY; + if (i == start) { + prevX = 0; + prevY = 0; + } else { + prevX = _curves[i - 2]; + prevY = _curves[i - 1]; + } + return prevY + (_curves[i + 1] - prevY) * (percent - prevX) / (x - prevX); + } + } + + float y = _curves[i - 1]; + + return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1. +} + +float CurveTimeline::getCurveType(size_t frameIndex) { + return _curves[frameIndex * BEZIER_SIZE]; +} diff --git a/native/cocos/editor-support/spine/CurveTimeline.h b/native/cocos/editor-support/spine/3.8/spine/CurveTimeline.h similarity index 100% rename from native/cocos/editor-support/spine/CurveTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/CurveTimeline.h diff --git a/native/cocos/editor-support/spine/Debug.h b/native/cocos/editor-support/spine/3.8/spine/Debug.h similarity index 97% rename from native/cocos/editor-support/spine/Debug.h rename to native/cocos/editor-support/spine/3.8/spine/Debug.h index fcdd10654a..656f851234 100644 --- a/native/cocos/editor-support/spine/Debug.h +++ b/native/cocos/editor-support/spine/3.8/spine/Debug.h @@ -1,126 +1,126 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef SPINE_DEBUG_H -#define SPINE_DEBUG_H - -#include - -#include - -namespace spine { -class SP_API DebugExtension : public SpineExtension { - struct Allocation { - void *address; - size_t size; - const char *fileName; - int line; - - Allocation() : address(NULL), size(0), fileName(NULL), line(0) { - } - - Allocation(void *a, size_t s, const char *f, int l) : address(a), size(s), fileName(f), line(l) { - } - }; - -public: - DebugExtension(SpineExtension *extension) : _extension(extension), _allocations(0), _reallocations(0), _frees(0) { - } - - void reportLeaks() { - for (std::map::iterator it = _allocated.begin(); it != _allocated.end(); it++) { - printf("\"%s:%i (%zu bytes at %p)\n", it->second.fileName, it->second.line, it->second.size, it->second.address); - } - printf("allocations: %zu, reallocations: %zu, frees: %zu\n", _allocations, _reallocations, _frees); - if (_allocated.empty()) printf("No leaks detected"); - } - - void clearAllocations() { - _allocated.clear(); - _usedMemory = 0; - } - - virtual void *_alloc(size_t size, const char *file, int line) { - void *result = _extension->_alloc(size, file, line); - _allocated[result] = Allocation(result, size, file, line); - _allocations++; - _usedMemory += size; - return result; - } - - virtual void *_calloc(size_t size, const char *file, int line) { - void *result = _extension->_calloc(size, file, line); - _allocated[result] = Allocation(result, size, file, line); - _allocations++; - _usedMemory += size; - return result; - } - - virtual void *_realloc(void *ptr, size_t size, const char *file, int line) { - if (_allocated.count(ptr)) _usedMemory -= _allocated[ptr].size; - _allocated.erase(ptr); - void *result = _extension->_realloc(ptr, size, file, line); - _reallocations++; - _allocated[result] = Allocation(result, size, file, line); - _usedMemory += size; - return result; - } - - virtual void _free(void *mem, const char *file, int line) { - if (_allocated.count(mem)) { - _extension->_free(mem, file, line); - _frees++; - _usedMemory -= _allocated[mem].size; - _allocated.erase(mem); - return; - } - - printf("%s:%i (address %p): Double free or not allocated through SpineExtension\n", file, line, mem); - _extension->_free(mem, file, line); - } - - virtual char *_readFile(const String &path, int *length) { - return _extension->_readFile(path, length); - } - - size_t getUsedMemory() { - return _usedMemory; - } - -private: - SpineExtension *_extension; - std::map _allocated; - size_t _allocations; - size_t _reallocations; - size_t _frees; - size_t _usedMemory; -}; -} // namespace spine - -#endif //SPINE_DEBUG_H +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef SPINE_DEBUG_H +#define SPINE_DEBUG_H + +#include + +#include + +namespace spine { +class SP_API DebugExtension : public SpineExtension { + struct Allocation { + void *address; + size_t size; + const char *fileName; + int line; + + Allocation() : address(NULL), size(0), fileName(NULL), line(0) { + } + + Allocation(void *a, size_t s, const char *f, int l) : address(a), size(s), fileName(f), line(l) { + } + }; + +public: + DebugExtension(SpineExtension *extension) : _extension(extension), _allocations(0), _reallocations(0), _frees(0) { + } + + void reportLeaks() { + for (std::map::iterator it = _allocated.begin(); it != _allocated.end(); it++) { + printf("\"%s:%i (%zu bytes at %p)\n", it->second.fileName, it->second.line, it->second.size, it->second.address); + } + printf("allocations: %zu, reallocations: %zu, frees: %zu\n", _allocations, _reallocations, _frees); + if (_allocated.empty()) printf("No leaks detected"); + } + + void clearAllocations() { + _allocated.clear(); + _usedMemory = 0; + } + + virtual void *_alloc(size_t size, const char *file, int line) { + void *result = _extension->_alloc(size, file, line); + _allocated[result] = Allocation(result, size, file, line); + _allocations++; + _usedMemory += size; + return result; + } + + virtual void *_calloc(size_t size, const char *file, int line) { + void *result = _extension->_calloc(size, file, line); + _allocated[result] = Allocation(result, size, file, line); + _allocations++; + _usedMemory += size; + return result; + } + + virtual void *_realloc(void *ptr, size_t size, const char *file, int line) { + if (_allocated.count(ptr)) _usedMemory -= _allocated[ptr].size; + _allocated.erase(ptr); + void *result = _extension->_realloc(ptr, size, file, line); + _reallocations++; + _allocated[result] = Allocation(result, size, file, line); + _usedMemory += size; + return result; + } + + virtual void _free(void *mem, const char *file, int line) { + if (_allocated.count(mem)) { + _extension->_free(mem, file, line); + _frees++; + _usedMemory -= _allocated[mem].size; + _allocated.erase(mem); + return; + } + + printf("%s:%i (address %p): Double free or not allocated through SpineExtension\n", file, line, mem); + _extension->_free(mem, file, line); + } + + virtual char *_readFile(const String &path, int *length) { + return _extension->_readFile(path, length); + } + + size_t getUsedMemory() { + return _usedMemory; + } + +private: + SpineExtension *_extension; + std::map _allocated; + size_t _allocations; + size_t _reallocations; + size_t _frees; + size_t _usedMemory; +}; +} // namespace spine + +#endif //SPINE_DEBUG_H diff --git a/native/cocos/editor-support/spine/DeformTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/DeformTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/DeformTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/DeformTimeline.cpp diff --git a/native/cocos/editor-support/spine/DeformTimeline.h b/native/cocos/editor-support/spine/3.8/spine/DeformTimeline.h similarity index 100% rename from native/cocos/editor-support/spine/DeformTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/DeformTimeline.h diff --git a/native/cocos/editor-support/spine/DrawOrderTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/DrawOrderTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/DrawOrderTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/DrawOrderTimeline.cpp diff --git a/native/cocos/editor-support/spine/DrawOrderTimeline.h b/native/cocos/editor-support/spine/3.8/spine/DrawOrderTimeline.h similarity index 100% rename from native/cocos/editor-support/spine/DrawOrderTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/DrawOrderTimeline.h diff --git a/native/cocos/editor-support/spine/Event.cpp b/native/cocos/editor-support/spine/3.8/spine/Event.cpp similarity index 97% rename from native/cocos/editor-support/spine/Event.cpp rename to native/cocos/editor-support/spine/3.8/spine/Event.cpp index 3e3b4a6be3..1fc185b226 100644 --- a/native/cocos/editor-support/spine/Event.cpp +++ b/native/cocos/editor-support/spine/3.8/spine/Event.cpp @@ -1,93 +1,93 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifdef SPINE_UE4 - #include "SpinePluginPrivatePCH.h" -#endif - -#include - -#include - -spine::Event::Event(float time, const spine::EventData &data) : _data(data), - _time(time), - _intValue(0), - _floatValue(0), - _stringValue(), - _volume(1), - _balance(0) { -} - -const spine::EventData &spine::Event::getData() { - return _data; -} - -float spine::Event::getTime() { - return _time; -} - -int spine::Event::getIntValue() { - return _intValue; -} - -void spine::Event::setIntValue(int inValue) { - _intValue = inValue; -} - -float spine::Event::getFloatValue() { - return _floatValue; -} - -void spine::Event::setFloatValue(float inValue) { - _floatValue = inValue; -} - -const spine::String &spine::Event::getStringValue() { - return _stringValue; -} - -void spine::Event::setStringValue(const spine::String &inValue) { - _stringValue = inValue; -} - -float spine::Event::getVolume() { - return _volume; -} - -void spine::Event::setVolume(float inValue) { - _volume = inValue; -} - -float spine::Event::getBalance() { - return _balance; -} - -void spine::Event::setBalance(float inValue) { - _balance = inValue; -} +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include + +#include + +spine::Event::Event(float time, const spine::EventData &data) : _data(data), + _time(time), + _intValue(0), + _floatValue(0), + _stringValue(), + _volume(1), + _balance(0) { +} + +const spine::EventData &spine::Event::getData() { + return _data; +} + +float spine::Event::getTime() { + return _time; +} + +int spine::Event::getIntValue() { + return _intValue; +} + +void spine::Event::setIntValue(int inValue) { + _intValue = inValue; +} + +float spine::Event::getFloatValue() { + return _floatValue; +} + +void spine::Event::setFloatValue(float inValue) { + _floatValue = inValue; +} + +const spine::String &spine::Event::getStringValue() { + return _stringValue; +} + +void spine::Event::setStringValue(const spine::String &inValue) { + _stringValue = inValue; +} + +float spine::Event::getVolume() { + return _volume; +} + +void spine::Event::setVolume(float inValue) { + _volume = inValue; +} + +float spine::Event::getBalance() { + return _balance; +} + +void spine::Event::setBalance(float inValue) { + _balance = inValue; +} diff --git a/native/cocos/editor-support/spine/Event.h b/native/cocos/editor-support/spine/3.8/spine/Event.h similarity index 100% rename from native/cocos/editor-support/spine/Event.h rename to native/cocos/editor-support/spine/3.8/spine/Event.h diff --git a/native/cocos/editor-support/spine/EventData.cpp b/native/cocos/editor-support/spine/3.8/spine/EventData.cpp similarity index 97% rename from native/cocos/editor-support/spine/EventData.cpp rename to native/cocos/editor-support/spine/3.8/spine/EventData.cpp index ea0ebfb190..b75ae73e7c 100644 --- a/native/cocos/editor-support/spine/EventData.cpp +++ b/native/cocos/editor-support/spine/3.8/spine/EventData.cpp @@ -1,99 +1,99 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifdef SPINE_UE4 - #include "SpinePluginPrivatePCH.h" -#endif - -#include - -#include - -spine::EventData::EventData(const spine::String &name) : _name(name), - _intValue(0), - _floatValue(0), - _stringValue(), - _audioPath(), - _volume(1), - _balance(0) { - assert(_name.length() > 0); -} - -/// The name of the event, which is unique within the skeleton. -const spine::String &spine::EventData::getName() const { - return _name; -} - -int spine::EventData::getIntValue() { - return _intValue; -} - -void spine::EventData::setIntValue(int inValue) { - _intValue = inValue; -} - -float spine::EventData::getFloatValue() { - return _floatValue; -} - -void spine::EventData::setFloatValue(float inValue) { - _floatValue = inValue; -} - -const spine::String &spine::EventData::getStringValue() { - return _stringValue; -} - -void spine::EventData::setStringValue(const spine::String &inValue) { - this->_stringValue = inValue; -} - -const spine::String &spine::EventData::getAudioPath() { - return _audioPath; -} - -void spine::EventData::setAudioPath(const spine::String &inValue) { - _audioPath = inValue; -} - -float spine::EventData::getVolume() { - return _volume; -} - -void spine::EventData::setVolume(float inValue) { - _volume = inValue; -} - -float spine::EventData::getBalance() { - return _balance; -} - -void spine::EventData::setBalance(float inValue) { - _balance = inValue; -} +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include + +#include + +spine::EventData::EventData(const spine::String &name) : _name(name), + _intValue(0), + _floatValue(0), + _stringValue(), + _audioPath(), + _volume(1), + _balance(0) { + assert(_name.length() > 0); +} + +/// The name of the event, which is unique within the skeleton. +const spine::String &spine::EventData::getName() const { + return _name; +} + +int spine::EventData::getIntValue() { + return _intValue; +} + +void spine::EventData::setIntValue(int inValue) { + _intValue = inValue; +} + +float spine::EventData::getFloatValue() { + return _floatValue; +} + +void spine::EventData::setFloatValue(float inValue) { + _floatValue = inValue; +} + +const spine::String &spine::EventData::getStringValue() { + return _stringValue; +} + +void spine::EventData::setStringValue(const spine::String &inValue) { + this->_stringValue = inValue; +} + +const spine::String &spine::EventData::getAudioPath() { + return _audioPath; +} + +void spine::EventData::setAudioPath(const spine::String &inValue) { + _audioPath = inValue; +} + +float spine::EventData::getVolume() { + return _volume; +} + +void spine::EventData::setVolume(float inValue) { + _volume = inValue; +} + +float spine::EventData::getBalance() { + return _balance; +} + +void spine::EventData::setBalance(float inValue) { + _balance = inValue; +} diff --git a/native/cocos/editor-support/spine/EventData.h b/native/cocos/editor-support/spine/3.8/spine/EventData.h similarity index 100% rename from native/cocos/editor-support/spine/EventData.h rename to native/cocos/editor-support/spine/3.8/spine/EventData.h diff --git a/native/cocos/editor-support/spine/EventTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/EventTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/EventTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/EventTimeline.cpp diff --git a/native/cocos/editor-support/spine/EventTimeline.h b/native/cocos/editor-support/spine/3.8/spine/EventTimeline.h similarity index 100% rename from native/cocos/editor-support/spine/EventTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/EventTimeline.h diff --git a/native/cocos/editor-support/spine/Extension.cpp b/native/cocos/editor-support/spine/3.8/spine/Extension.cpp similarity index 100% rename from native/cocos/editor-support/spine/Extension.cpp rename to native/cocos/editor-support/spine/3.8/spine/Extension.cpp diff --git a/native/cocos/editor-support/spine/Extension.h b/native/cocos/editor-support/spine/3.8/spine/Extension.h similarity index 100% rename from native/cocos/editor-support/spine/Extension.h rename to native/cocos/editor-support/spine/3.8/spine/Extension.h diff --git a/native/cocos/editor-support/spine/HasRendererObject.h b/native/cocos/editor-support/spine/3.8/spine/HasRendererObject.h similarity index 100% rename from native/cocos/editor-support/spine/HasRendererObject.h rename to native/cocos/editor-support/spine/3.8/spine/HasRendererObject.h diff --git a/native/cocos/editor-support/spine/HashMap.h b/native/cocos/editor-support/spine/3.8/spine/HashMap.h similarity index 100% rename from native/cocos/editor-support/spine/HashMap.h rename to native/cocos/editor-support/spine/3.8/spine/HashMap.h diff --git a/native/cocos/editor-support/spine/IkConstraint.cpp b/native/cocos/editor-support/spine/3.8/spine/IkConstraint.cpp similarity index 100% rename from native/cocos/editor-support/spine/IkConstraint.cpp rename to native/cocos/editor-support/spine/3.8/spine/IkConstraint.cpp diff --git a/native/cocos/editor-support/spine/IkConstraint.h b/native/cocos/editor-support/spine/3.8/spine/IkConstraint.h similarity index 100% rename from native/cocos/editor-support/spine/IkConstraint.h rename to native/cocos/editor-support/spine/3.8/spine/IkConstraint.h diff --git a/native/cocos/editor-support/spine/IkConstraintData.cpp b/native/cocos/editor-support/spine/3.8/spine/IkConstraintData.cpp similarity index 100% rename from native/cocos/editor-support/spine/IkConstraintData.cpp rename to native/cocos/editor-support/spine/3.8/spine/IkConstraintData.cpp diff --git a/native/cocos/editor-support/spine/IkConstraintData.h b/native/cocos/editor-support/spine/3.8/spine/IkConstraintData.h similarity index 100% rename from native/cocos/editor-support/spine/IkConstraintData.h rename to native/cocos/editor-support/spine/3.8/spine/IkConstraintData.h diff --git a/native/cocos/editor-support/spine/IkConstraintTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/IkConstraintTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/IkConstraintTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/IkConstraintTimeline.cpp diff --git a/native/cocos/editor-support/spine/IkConstraintTimeline.h b/native/cocos/editor-support/spine/3.8/spine/IkConstraintTimeline.h similarity index 97% rename from native/cocos/editor-support/spine/IkConstraintTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/IkConstraintTimeline.h index c5ceffadea..e05866b1d2 100644 --- a/native/cocos/editor-support/spine/IkConstraintTimeline.h +++ b/native/cocos/editor-support/spine/3.8/spine/IkConstraintTimeline.h @@ -1,73 +1,73 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_IkConstraintTimeline_h -#define Spine_IkConstraintTimeline_h - -#include - -namespace spine { - -class SP_API IkConstraintTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - -public: - static const int ENTRIES; - - explicit IkConstraintTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time, mix and bend direction of the specified keyframe. - void setFrame(int frameIndex, float time, float mix, float softness, int bendDirection, bool compress, bool stretch); - -private: - static const int PREV_TIME; - static const int PREV_MIX; - static const int PREV_SOFTNESS; - static const int PREV_BEND_DIRECTION; - static const int PREV_COMPRESS; - static const int PREV_STRETCH; - static const int MIX; - static const int SOFTNESS; - static const int BEND_DIRECTION; - static const int COMPRESS; - static const int STRETCH; - - Vector _frames; - int _ikConstraintIndex; -}; -} // namespace spine - -#endif /* Spine_IkConstraintTimeline_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_IkConstraintTimeline_h +#define Spine_IkConstraintTimeline_h + +#include + +namespace spine { + +class SP_API IkConstraintTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + +public: + static const int ENTRIES; + + explicit IkConstraintTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time, mix and bend direction of the specified keyframe. + void setFrame(int frameIndex, float time, float mix, float softness, int bendDirection, bool compress, bool stretch); + +private: + static const int PREV_TIME; + static const int PREV_MIX; + static const int PREV_SOFTNESS; + static const int PREV_BEND_DIRECTION; + static const int PREV_COMPRESS; + static const int PREV_STRETCH; + static const int MIX; + static const int SOFTNESS; + static const int BEND_DIRECTION; + static const int COMPRESS; + static const int STRETCH; + + Vector _frames; + int _ikConstraintIndex; +}; +} // namespace spine + +#endif /* Spine_IkConstraintTimeline_h */ diff --git a/native/cocos/editor-support/spine/Json.cpp b/native/cocos/editor-support/spine/3.8/spine/Json.cpp similarity index 100% rename from native/cocos/editor-support/spine/Json.cpp rename to native/cocos/editor-support/spine/3.8/spine/Json.cpp diff --git a/native/cocos/editor-support/spine/Json.h b/native/cocos/editor-support/spine/3.8/spine/Json.h similarity index 97% rename from native/cocos/editor-support/spine/Json.h rename to native/cocos/editor-support/spine/3.8/spine/Json.h index 478d84b43b..f998346925 100644 --- a/native/cocos/editor-support/spine/Json.h +++ b/native/cocos/editor-support/spine/3.8/spine/Json.h @@ -1,113 +1,113 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_Json_h -#define Spine_Json_h - -#include - -#ifndef SPINE_JSON_HAVE_PREV - /* spine doesn't use the "prev" link in the Json sibling lists. */ - #define SPINE_JSON_HAVE_PREV 0 -#endif - -namespace spine { -class SP_API Json { - friend class SkeletonJson; - -public: - /* Json Types: */ - static const int JSON_FALSE; - static const int JSON_TRUE; - static const int JSON_NULL; - static const int JSON_NUMBER; - static const int JSON_STRING; - static const int JSON_ARRAY; - static const int JSON_OBJECT; - - /* Get item "string" from object. Case insensitive. */ - static Json *getItem(Json *object, const char *string); - - static const char *getString(Json *object, const char *name, const char *defaultValue); - - static float getFloat(Json *object, const char *name, float defaultValue); - - static int getInt(Json *object, const char *name, int defaultValue); - - static bool getBoolean(Json *object, const char *name, bool defaultValue); - - /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when Json_create() returns 0. 0 when Json_create() succeeds. */ - static const char *getError(); - - /* Supply a block of JSON, and this returns a Json object you can interrogate. Call Json_dispose when finished. */ - explicit Json(const char *value); - - ~Json(); - -private: - static const char *_error; - - Json *_next; -#if SPINE_JSON_HAVE_PREV - Json *_prev; /* next/prev allow you to walk array/object chains. Alternatively, use getSize/getItem */ -#endif - Json *_child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ - - int _type; /* The type of the item, as above. */ - int _size; /* The number of children. */ - - const char *_valueString; /* The item's string, if type==JSON_STRING */ - int _valueInt; /* The item's number, if type==JSON_NUMBER */ - float _valueFloat; /* The item's number, if type==JSON_NUMBER */ - - const char *_name; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ - - /* Utility to jump whitespace and cr/lf */ - static const char *skip(const char *inValue); - - /* Parser core - when encountering text, process appropriately. */ - static const char *parseValue(Json *item, const char *value); - - /* Parse the input text into an unescaped cstring, and populate item. */ - static const char *parseString(Json *item, const char *str); - - /* Parse the input text to generate a number, and populate the result into item. */ - static const char *parseNumber(Json *item, const char *num); - - /* Build an array from input text. */ - static const char *parseArray(Json *item, const char *value); - - /* Build an object from the text. */ - static const char *parseObject(Json *item, const char *value); - - static int json_strcasecmp(const char *s1, const char *s2); -}; -} // namespace spine - -#endif /* Spine_Json_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_Json_h +#define Spine_Json_h + +#include + +#ifndef SPINE_JSON_HAVE_PREV + /* spine doesn't use the "prev" link in the Json sibling lists. */ + #define SPINE_JSON_HAVE_PREV 0 +#endif + +namespace spine { +class SP_API Json { + friend class SkeletonJson; + +public: + /* Json Types: */ + static const int JSON_FALSE; + static const int JSON_TRUE; + static const int JSON_NULL; + static const int JSON_NUMBER; + static const int JSON_STRING; + static const int JSON_ARRAY; + static const int JSON_OBJECT; + + /* Get item "string" from object. Case insensitive. */ + static Json *getItem(Json *object, const char *string); + + static const char *getString(Json *object, const char *name, const char *defaultValue); + + static float getFloat(Json *object, const char *name, float defaultValue); + + static int getInt(Json *object, const char *name, int defaultValue); + + static bool getBoolean(Json *object, const char *name, bool defaultValue); + + /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when Json_create() returns 0. 0 when Json_create() succeeds. */ + static const char *getError(); + + /* Supply a block of JSON, and this returns a Json object you can interrogate. Call Json_dispose when finished. */ + explicit Json(const char *value); + + ~Json(); + +private: + static const char *_error; + + Json *_next; +#if SPINE_JSON_HAVE_PREV + Json *_prev; /* next/prev allow you to walk array/object chains. Alternatively, use getSize/getItem */ +#endif + Json *_child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + + int _type; /* The type of the item, as above. */ + int _size; /* The number of children. */ + + const char *_valueString; /* The item's string, if type==JSON_STRING */ + int _valueInt; /* The item's number, if type==JSON_NUMBER */ + float _valueFloat; /* The item's number, if type==JSON_NUMBER */ + + const char *_name; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + + /* Utility to jump whitespace and cr/lf */ + static const char *skip(const char *inValue); + + /* Parser core - when encountering text, process appropriately. */ + static const char *parseValue(Json *item, const char *value); + + /* Parse the input text into an unescaped cstring, and populate item. */ + static const char *parseString(Json *item, const char *str); + + /* Parse the input text to generate a number, and populate the result into item. */ + static const char *parseNumber(Json *item, const char *num); + + /* Build an array from input text. */ + static const char *parseArray(Json *item, const char *value); + + /* Build an object from the text. */ + static const char *parseObject(Json *item, const char *value); + + static int json_strcasecmp(const char *s1, const char *s2); +}; +} // namespace spine + +#endif /* Spine_Json_h */ diff --git a/native/cocos/editor-support/spine/LinkedMesh.cpp b/native/cocos/editor-support/spine/3.8/spine/LinkedMesh.cpp similarity index 98% rename from native/cocos/editor-support/spine/LinkedMesh.cpp rename to native/cocos/editor-support/spine/3.8/spine/LinkedMesh.cpp index 861a102a5a..8e56f5a843 100644 --- a/native/cocos/editor-support/spine/LinkedMesh.cpp +++ b/native/cocos/editor-support/spine/3.8/spine/LinkedMesh.cpp @@ -1,45 +1,45 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifdef SPINE_UE4 - #include "SpinePluginPrivatePCH.h" -#endif - -#include - -#include - -using namespace spine; - -LinkedMesh::LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritDeform) : _mesh(mesh), - _skin(skin), - _slotIndex(slotIndex), - _parent(parent), - _inheritDeform(inheritDeform) { -} +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include + +#include + +using namespace spine; + +LinkedMesh::LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritDeform) : _mesh(mesh), + _skin(skin), + _slotIndex(slotIndex), + _parent(parent), + _inheritDeform(inheritDeform) { +} diff --git a/native/cocos/editor-support/spine/LinkedMesh.h b/native/cocos/editor-support/spine/3.8/spine/LinkedMesh.h similarity index 97% rename from native/cocos/editor-support/spine/LinkedMesh.h rename to native/cocos/editor-support/spine/3.8/spine/LinkedMesh.h index accd83a66a..23eb86c924 100644 --- a/native/cocos/editor-support/spine/LinkedMesh.h +++ b/native/cocos/editor-support/spine/3.8/spine/LinkedMesh.h @@ -1,56 +1,56 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_LinkedMesh_h -#define Spine_LinkedMesh_h - -#include -#include - -namespace spine { -class MeshAttachment; - -class SP_API LinkedMesh : public SpineObject { - friend class SkeletonBinary; - - friend class SkeletonJson; - -public: - LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritDeform); - -private: - MeshAttachment *_mesh; - String _skin; - size_t _slotIndex; - String _parent; - bool _inheritDeform; -}; -} // namespace spine - -#endif /* Spine_LinkedMesh_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_LinkedMesh_h +#define Spine_LinkedMesh_h + +#include +#include + +namespace spine { +class MeshAttachment; + +class SP_API LinkedMesh : public SpineObject { + friend class SkeletonBinary; + + friend class SkeletonJson; + +public: + LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritDeform); + +private: + MeshAttachment *_mesh; + String _skin; + size_t _slotIndex; + String _parent; + bool _inheritDeform; +}; +} // namespace spine + +#endif /* Spine_LinkedMesh_h */ diff --git a/native/cocos/editor-support/spine/MathUtil.cpp b/native/cocos/editor-support/spine/3.8/spine/MathUtil.cpp similarity index 100% rename from native/cocos/editor-support/spine/MathUtil.cpp rename to native/cocos/editor-support/spine/3.8/spine/MathUtil.cpp diff --git a/native/cocos/editor-support/spine/MathUtil.h b/native/cocos/editor-support/spine/3.8/spine/MathUtil.h similarity index 100% rename from native/cocos/editor-support/spine/MathUtil.h rename to native/cocos/editor-support/spine/3.8/spine/MathUtil.h diff --git a/native/cocos/editor-support/spine/MeshAttachment.cpp b/native/cocos/editor-support/spine/3.8/spine/MeshAttachment.cpp similarity index 100% rename from native/cocos/editor-support/spine/MeshAttachment.cpp rename to native/cocos/editor-support/spine/3.8/spine/MeshAttachment.cpp diff --git a/native/cocos/editor-support/spine/MeshAttachment.h b/native/cocos/editor-support/spine/3.8/spine/MeshAttachment.h similarity index 100% rename from native/cocos/editor-support/spine/MeshAttachment.h rename to native/cocos/editor-support/spine/3.8/spine/MeshAttachment.h diff --git a/native/cocos/editor-support/spine/MixBlend.h b/native/cocos/editor-support/spine/3.8/spine/MixBlend.h similarity index 97% rename from native/cocos/editor-support/spine/MixBlend.h rename to native/cocos/editor-support/spine/3.8/spine/MixBlend.h index a0824ea31b..a4c1ced993 100644 --- a/native/cocos/editor-support/spine/MixBlend.h +++ b/native/cocos/editor-support/spine/3.8/spine/MixBlend.h @@ -1,45 +1,45 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_MixPose_h -#define Spine_MixPose_h - -namespace spine { - -/// Controls how a timeline is mixed with the setup or current pose. -/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, Blend, MixDirection) -enum MixBlend { - MixBlend_Setup = 0, - MixBlend_First, - MixBlend_Replace, - MixBlend_Add -}; -} // namespace spine - -#endif /* Spine_MixPose_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_MixPose_h +#define Spine_MixPose_h + +namespace spine { + +/// Controls how a timeline is mixed with the setup or current pose. +/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, Blend, MixDirection) +enum MixBlend { + MixBlend_Setup = 0, + MixBlend_First, + MixBlend_Replace, + MixBlend_Add +}; +} // namespace spine + +#endif /* Spine_MixPose_h */ diff --git a/native/cocos/editor-support/spine/MixDirection.h b/native/cocos/editor-support/spine/3.8/spine/MixDirection.h similarity index 97% rename from native/cocos/editor-support/spine/MixDirection.h rename to native/cocos/editor-support/spine/3.8/spine/MixDirection.h index 1f9920b2f7..830c773c33 100644 --- a/native/cocos/editor-support/spine/MixDirection.h +++ b/native/cocos/editor-support/spine/3.8/spine/MixDirection.h @@ -1,44 +1,44 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_MixDirection_h -#define Spine_MixDirection_h - -namespace spine { - -/// Indicates whether a timeline's alpha is mixing out over time toward 0 (the setup or current pose) or mixing in toward 1 (the timeline's pose). -/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, MixPose, MixDirection) -enum MixDirection { - MixDirection_In = 0, - MixDirection_Out -}; - -} // namespace spine - -#endif /* Spine_MixDirection_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_MixDirection_h +#define Spine_MixDirection_h + +namespace spine { + +/// Indicates whether a timeline's alpha is mixing out over time toward 0 (the setup or current pose) or mixing in toward 1 (the timeline's pose). +/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, MixPose, MixDirection) +enum MixDirection { + MixDirection_In = 0, + MixDirection_Out +}; + +} // namespace spine + +#endif /* Spine_MixDirection_h */ diff --git a/native/cocos/editor-support/spine/PathAttachment.cpp b/native/cocos/editor-support/spine/3.8/spine/PathAttachment.cpp similarity index 100% rename from native/cocos/editor-support/spine/PathAttachment.cpp rename to native/cocos/editor-support/spine/3.8/spine/PathAttachment.cpp diff --git a/native/cocos/editor-support/spine/PathAttachment.h b/native/cocos/editor-support/spine/3.8/spine/PathAttachment.h similarity index 100% rename from native/cocos/editor-support/spine/PathAttachment.h rename to native/cocos/editor-support/spine/3.8/spine/PathAttachment.h diff --git a/native/cocos/editor-support/spine/PathConstraint.cpp b/native/cocos/editor-support/spine/3.8/spine/PathConstraint.cpp similarity index 100% rename from native/cocos/editor-support/spine/PathConstraint.cpp rename to native/cocos/editor-support/spine/3.8/spine/PathConstraint.cpp diff --git a/native/cocos/editor-support/spine/PathConstraint.h b/native/cocos/editor-support/spine/3.8/spine/PathConstraint.h similarity index 100% rename from native/cocos/editor-support/spine/PathConstraint.h rename to native/cocos/editor-support/spine/3.8/spine/PathConstraint.h diff --git a/native/cocos/editor-support/spine/PathConstraintData.cpp b/native/cocos/editor-support/spine/3.8/spine/PathConstraintData.cpp similarity index 100% rename from native/cocos/editor-support/spine/PathConstraintData.cpp rename to native/cocos/editor-support/spine/3.8/spine/PathConstraintData.cpp diff --git a/native/cocos/editor-support/spine/PathConstraintData.h b/native/cocos/editor-support/spine/3.8/spine/PathConstraintData.h similarity index 100% rename from native/cocos/editor-support/spine/PathConstraintData.h rename to native/cocos/editor-support/spine/3.8/spine/PathConstraintData.h diff --git a/native/cocos/editor-support/spine/PathConstraintMixTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/PathConstraintMixTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/PathConstraintMixTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/PathConstraintMixTimeline.cpp diff --git a/native/cocos/editor-support/spine/PathConstraintMixTimeline.h b/native/cocos/editor-support/spine/3.8/spine/PathConstraintMixTimeline.h similarity index 97% rename from native/cocos/editor-support/spine/PathConstraintMixTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/PathConstraintMixTimeline.h index 4e5141ade5..80ca46af85 100644 --- a/native/cocos/editor-support/spine/PathConstraintMixTimeline.h +++ b/native/cocos/editor-support/spine/3.8/spine/PathConstraintMixTimeline.h @@ -1,68 +1,68 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_PathConstraintMixTimeline_h -#define Spine_PathConstraintMixTimeline_h - -#include - -namespace spine { -#define SP_PATHCONSTRAINTMIXTIMELINE_ENTRIES 5 - -class SP_API PathConstraintMixTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - -public: - static const int ENTRIES; - - explicit PathConstraintMixTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - -private: - static const int PREV_TIME; - static const int PREV_ROTATE; - static const int PREV_TRANSLATE; - static const int ROTATE; - static const int TRANSLATE; - - Vector _frames; - int _pathConstraintIndex; - - /// Sets the time and mixes of the specified keyframe. - void setFrame(int frameIndex, float time, float rotateMix, float translateMix); -}; -} // namespace spine - -#endif /* Spine_PathConstraintMixTimeline_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_PathConstraintMixTimeline_h +#define Spine_PathConstraintMixTimeline_h + +#include + +namespace spine { +#define SP_PATHCONSTRAINTMIXTIMELINE_ENTRIES 5 + +class SP_API PathConstraintMixTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + +public: + static const int ENTRIES; + + explicit PathConstraintMixTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + +private: + static const int PREV_TIME; + static const int PREV_ROTATE; + static const int PREV_TRANSLATE; + static const int ROTATE; + static const int TRANSLATE; + + Vector _frames; + int _pathConstraintIndex; + + /// Sets the time and mixes of the specified keyframe. + void setFrame(int frameIndex, float time, float rotateMix, float translateMix); +}; +} // namespace spine + +#endif /* Spine_PathConstraintMixTimeline_h */ diff --git a/native/cocos/editor-support/spine/PathConstraintPositionTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/PathConstraintPositionTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/PathConstraintPositionTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/PathConstraintPositionTimeline.cpp diff --git a/native/cocos/editor-support/spine/PathConstraintPositionTimeline.h b/native/cocos/editor-support/spine/3.8/spine/PathConstraintPositionTimeline.h similarity index 97% rename from native/cocos/editor-support/spine/PathConstraintPositionTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/PathConstraintPositionTimeline.h index 986cc2143f..69fed3cb82 100644 --- a/native/cocos/editor-support/spine/PathConstraintPositionTimeline.h +++ b/native/cocos/editor-support/spine/3.8/spine/PathConstraintPositionTimeline.h @@ -1,67 +1,67 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_PathConstraintPositionTimeline_h -#define Spine_PathConstraintPositionTimeline_h - -#include - -namespace spine { - -class SP_API PathConstraintPositionTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - -public: - static const int ENTRIES; - - explicit PathConstraintPositionTimeline(int frameCount); - - virtual ~PathConstraintPositionTimeline(); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(int frameIndex, float time, float value); - -protected: - static const int PREV_TIME; - static const int PREV_VALUE; - static const int VALUE; - - Vector _frames; - int _pathConstraintIndex; -}; -} // namespace spine - -#endif /* Spine_PathConstraintPositionTimeline_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_PathConstraintPositionTimeline_h +#define Spine_PathConstraintPositionTimeline_h + +#include + +namespace spine { + +class SP_API PathConstraintPositionTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + +public: + static const int ENTRIES; + + explicit PathConstraintPositionTimeline(int frameCount); + + virtual ~PathConstraintPositionTimeline(); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, float value); + +protected: + static const int PREV_TIME; + static const int PREV_VALUE; + static const int VALUE; + + Vector _frames; + int _pathConstraintIndex; +}; +} // namespace spine + +#endif /* Spine_PathConstraintPositionTimeline_h */ diff --git a/native/cocos/editor-support/spine/PathConstraintSpacingTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/PathConstraintSpacingTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/PathConstraintSpacingTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/PathConstraintSpacingTimeline.cpp diff --git a/native/cocos/editor-support/spine/PathConstraintSpacingTimeline.h b/native/cocos/editor-support/spine/3.8/spine/PathConstraintSpacingTimeline.h similarity index 97% rename from native/cocos/editor-support/spine/PathConstraintSpacingTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/PathConstraintSpacingTimeline.h index ee88e72abe..e6c01c0690 100644 --- a/native/cocos/editor-support/spine/PathConstraintSpacingTimeline.h +++ b/native/cocos/editor-support/spine/3.8/spine/PathConstraintSpacingTimeline.h @@ -1,51 +1,51 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_PathConstraintSpacingTimeline_h -#define Spine_PathConstraintSpacingTimeline_h - -#include - -namespace spine { -class SP_API PathConstraintSpacingTimeline : public PathConstraintPositionTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - -public: - explicit PathConstraintSpacingTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); -}; -} // namespace spine - -#endif /* Spine_PathConstraintSpacingTimeline_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_PathConstraintSpacingTimeline_h +#define Spine_PathConstraintSpacingTimeline_h + +#include + +namespace spine { +class SP_API PathConstraintSpacingTimeline : public PathConstraintPositionTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + +public: + explicit PathConstraintSpacingTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); +}; +} // namespace spine + +#endif /* Spine_PathConstraintSpacingTimeline_h */ diff --git a/native/cocos/editor-support/spine/PointAttachment.cpp b/native/cocos/editor-support/spine/3.8/spine/PointAttachment.cpp similarity index 100% rename from native/cocos/editor-support/spine/PointAttachment.cpp rename to native/cocos/editor-support/spine/3.8/spine/PointAttachment.cpp diff --git a/native/cocos/editor-support/spine/PointAttachment.h b/native/cocos/editor-support/spine/3.8/spine/PointAttachment.h similarity index 100% rename from native/cocos/editor-support/spine/PointAttachment.h rename to native/cocos/editor-support/spine/3.8/spine/PointAttachment.h diff --git a/native/cocos/editor-support/spine/Pool.h b/native/cocos/editor-support/spine/3.8/spine/Pool.h similarity index 100% rename from native/cocos/editor-support/spine/Pool.h rename to native/cocos/editor-support/spine/3.8/spine/Pool.h diff --git a/native/cocos/editor-support/spine/PositionMode.h b/native/cocos/editor-support/spine/3.8/spine/PositionMode.h similarity index 97% rename from native/cocos/editor-support/spine/PositionMode.h rename to native/cocos/editor-support/spine/3.8/spine/PositionMode.h index fe828d32fe..c0aaf99428 100644 --- a/native/cocos/editor-support/spine/PositionMode.h +++ b/native/cocos/editor-support/spine/3.8/spine/PositionMode.h @@ -1,40 +1,40 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_PositionMode_h -#define Spine_PositionMode_h - -namespace spine { -enum PositionMode { - PositionMode_Fixed = 0, - PositionMode_Percent -}; -} - -#endif /* Spine_PositionMode_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_PositionMode_h +#define Spine_PositionMode_h + +namespace spine { +enum PositionMode { + PositionMode_Fixed = 0, + PositionMode_Percent +}; +} + +#endif /* Spine_PositionMode_h */ diff --git a/native/cocos/editor-support/spine/RTTI.cpp b/native/cocos/editor-support/spine/3.8/spine/RTTI.cpp similarity index 97% rename from native/cocos/editor-support/spine/RTTI.cpp rename to native/cocos/editor-support/spine/3.8/spine/RTTI.cpp index fa7e8fde6c..47d521bfab 100644 --- a/native/cocos/editor-support/spine/RTTI.cpp +++ b/native/cocos/editor-support/spine/3.8/spine/RTTI.cpp @@ -1,60 +1,60 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifdef SPINE_UE4 - #include "SpinePluginPrivatePCH.h" -#endif - -#include -#include - -using namespace spine; - -RTTI::RTTI(const char *className) : _className(className), _pBaseRTTI(NULL) { -} - -RTTI::RTTI(const char *className, const RTTI &baseRTTI) : _className(className), _pBaseRTTI(&baseRTTI) { -} - -const char *RTTI::getClassName() const { - return _className; -} - -bool RTTI::isExactly(const RTTI &rtti) const { - return !strcmp(this->_className, rtti._className); -} - -bool RTTI::instanceOf(const RTTI &rtti) const { - const RTTI *pCompare = this; - while (pCompare) { - if (!strcmp(pCompare->_className, rtti._className)) return true; - pCompare = pCompare->_pBaseRTTI; - } - return false; -} +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include +#include + +using namespace spine; + +RTTI::RTTI(const char *className) : _className(className), _pBaseRTTI(NULL) { +} + +RTTI::RTTI(const char *className, const RTTI &baseRTTI) : _className(className), _pBaseRTTI(&baseRTTI) { +} + +const char *RTTI::getClassName() const { + return _className; +} + +bool RTTI::isExactly(const RTTI &rtti) const { + return !strcmp(this->_className, rtti._className); +} + +bool RTTI::instanceOf(const RTTI &rtti) const { + const RTTI *pCompare = this; + while (pCompare) { + if (!strcmp(pCompare->_className, rtti._className)) return true; + pCompare = pCompare->_pBaseRTTI; + } + return false; +} diff --git a/native/cocos/editor-support/spine/RTTI.h b/native/cocos/editor-support/spine/3.8/spine/RTTI.h similarity index 97% rename from native/cocos/editor-support/spine/RTTI.h rename to native/cocos/editor-support/spine/3.8/spine/RTTI.h index d4744431fb..0952601a1e 100644 --- a/native/cocos/editor-support/spine/RTTI.h +++ b/native/cocos/editor-support/spine/3.8/spine/RTTI.h @@ -1,72 +1,72 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_RTTI_h -#define Spine_RTTI_h - -#include - -namespace spine { -class SP_API RTTI : public SpineObject { -public: - explicit RTTI(const char *className); - - RTTI(const char *className, const RTTI &baseRTTI); - - const char *getClassName() const; - - bool isExactly(const RTTI &rtti) const; - - bool instanceOf(const RTTI &rtti) const; - -private: - // Prevent copying - RTTI(const RTTI &obj); - - RTTI &operator=(const RTTI &obj); - - const char *_className; - const RTTI *_pBaseRTTI; -}; -} // namespace spine - -#define RTTI_DECL \ -public: \ - static const spine::RTTI rtti; \ - virtual const spine::RTTI &getRTTI() const; - -#define RTTI_IMPL_NOPARENT(name) \ - const spine::RTTI name::rtti(#name); \ - const spine::RTTI &name::getRTTI() const { return rtti; } - -#define RTTI_IMPL(name, parent) \ - const spine::RTTI name::rtti(#name, parent::rtti); \ - const spine::RTTI &name::getRTTI() const { return rtti; } - -#endif /* Spine_RTTI_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_RTTI_h +#define Spine_RTTI_h + +#include + +namespace spine { +class SP_API RTTI : public SpineObject { +public: + explicit RTTI(const char *className); + + RTTI(const char *className, const RTTI &baseRTTI); + + const char *getClassName() const; + + bool isExactly(const RTTI &rtti) const; + + bool instanceOf(const RTTI &rtti) const; + +private: + // Prevent copying + RTTI(const RTTI &obj); + + RTTI &operator=(const RTTI &obj); + + const char *_className; + const RTTI *_pBaseRTTI; +}; +} // namespace spine + +#define RTTI_DECL \ +public: \ + static const spine::RTTI rtti; \ + virtual const spine::RTTI &getRTTI() const; + +#define RTTI_IMPL_NOPARENT(name) \ + const spine::RTTI name::rtti(#name); \ + const spine::RTTI &name::getRTTI() const { return rtti; } + +#define RTTI_IMPL(name, parent) \ + const spine::RTTI name::rtti(#name, parent::rtti); \ + const spine::RTTI &name::getRTTI() const { return rtti; } + +#endif /* Spine_RTTI_h */ diff --git a/native/cocos/editor-support/spine/RegionAttachment.cpp b/native/cocos/editor-support/spine/3.8/spine/RegionAttachment.cpp similarity index 100% rename from native/cocos/editor-support/spine/RegionAttachment.cpp rename to native/cocos/editor-support/spine/3.8/spine/RegionAttachment.cpp diff --git a/native/cocos/editor-support/spine/RegionAttachment.h b/native/cocos/editor-support/spine/3.8/spine/RegionAttachment.h similarity index 100% rename from native/cocos/editor-support/spine/RegionAttachment.h rename to native/cocos/editor-support/spine/3.8/spine/RegionAttachment.h diff --git a/native/cocos/editor-support/spine/RotateMode.h b/native/cocos/editor-support/spine/3.8/spine/RotateMode.h similarity index 97% rename from native/cocos/editor-support/spine/RotateMode.h rename to native/cocos/editor-support/spine/3.8/spine/RotateMode.h index 3a76863260..e802c6369a 100644 --- a/native/cocos/editor-support/spine/RotateMode.h +++ b/native/cocos/editor-support/spine/3.8/spine/RotateMode.h @@ -1,41 +1,41 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_RotateMode_h -#define Spine_RotateMode_h - -namespace spine { -enum RotateMode { - RotateMode_Tangent = 0, - RotateMode_Chain, - RotateMode_ChainScale -}; -} - -#endif /* Spine_RotateMode_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_RotateMode_h +#define Spine_RotateMode_h + +namespace spine { +enum RotateMode { + RotateMode_Tangent = 0, + RotateMode_Chain, + RotateMode_ChainScale +}; +} + +#endif /* Spine_RotateMode_h */ diff --git a/native/cocos/editor-support/spine/RotateTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/RotateTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/RotateTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/RotateTimeline.cpp diff --git a/native/cocos/editor-support/spine/RotateTimeline.h b/native/cocos/editor-support/spine/3.8/spine/RotateTimeline.h similarity index 100% rename from native/cocos/editor-support/spine/RotateTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/RotateTimeline.h diff --git a/native/cocos/editor-support/spine/ScaleTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/ScaleTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/ScaleTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/ScaleTimeline.cpp diff --git a/native/cocos/editor-support/spine/ScaleTimeline.h b/native/cocos/editor-support/spine/3.8/spine/ScaleTimeline.h similarity index 97% rename from native/cocos/editor-support/spine/ScaleTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/ScaleTimeline.h index 01a85c89f1..fda8b05874 100644 --- a/native/cocos/editor-support/spine/ScaleTimeline.h +++ b/native/cocos/editor-support/spine/3.8/spine/ScaleTimeline.h @@ -1,51 +1,51 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_ScaleTimeline_h -#define Spine_ScaleTimeline_h - -#include - -namespace spine { -class SP_API ScaleTimeline : public TranslateTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - -public: - explicit ScaleTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); -}; -} // namespace spine - -#endif /* Spine_ScaleTimeline_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_ScaleTimeline_h +#define Spine_ScaleTimeline_h + +#include + +namespace spine { +class SP_API ScaleTimeline : public TranslateTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + +public: + explicit ScaleTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); +}; +} // namespace spine + +#endif /* Spine_ScaleTimeline_h */ diff --git a/native/cocos/editor-support/spine/ShearTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/ShearTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/ShearTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/ShearTimeline.cpp diff --git a/native/cocos/editor-support/spine/ShearTimeline.h b/native/cocos/editor-support/spine/3.8/spine/ShearTimeline.h similarity index 97% rename from native/cocos/editor-support/spine/ShearTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/ShearTimeline.h index de00885826..5e961156e3 100644 --- a/native/cocos/editor-support/spine/ShearTimeline.h +++ b/native/cocos/editor-support/spine/3.8/spine/ShearTimeline.h @@ -1,51 +1,51 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_ShearTimeline_h -#define Spine_ShearTimeline_h - -#include - -namespace spine { -class SP_API ShearTimeline : public TranslateTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - -public: - explicit ShearTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); -}; -} // namespace spine - -#endif /* Spine_ShearTimeline_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_ShearTimeline_h +#define Spine_ShearTimeline_h + +#include + +namespace spine { +class SP_API ShearTimeline : public TranslateTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + +public: + explicit ShearTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); +}; +} // namespace spine + +#endif /* Spine_ShearTimeline_h */ diff --git a/native/cocos/editor-support/spine/Skeleton.cpp b/native/cocos/editor-support/spine/3.8/spine/Skeleton.cpp similarity index 100% rename from native/cocos/editor-support/spine/Skeleton.cpp rename to native/cocos/editor-support/spine/3.8/spine/Skeleton.cpp diff --git a/native/cocos/editor-support/spine/Skeleton.h b/native/cocos/editor-support/spine/3.8/spine/Skeleton.h similarity index 100% rename from native/cocos/editor-support/spine/Skeleton.h rename to native/cocos/editor-support/spine/3.8/spine/Skeleton.h diff --git a/native/cocos/editor-support/spine/SkeletonBinary.cpp b/native/cocos/editor-support/spine/3.8/spine/SkeletonBinary.cpp similarity index 100% rename from native/cocos/editor-support/spine/SkeletonBinary.cpp rename to native/cocos/editor-support/spine/3.8/spine/SkeletonBinary.cpp diff --git a/native/cocos/editor-support/spine/SkeletonBinary.h b/native/cocos/editor-support/spine/3.8/spine/SkeletonBinary.h similarity index 100% rename from native/cocos/editor-support/spine/SkeletonBinary.h rename to native/cocos/editor-support/spine/3.8/spine/SkeletonBinary.h diff --git a/native/cocos/editor-support/spine/SkeletonBounds.cpp b/native/cocos/editor-support/spine/3.8/spine/SkeletonBounds.cpp similarity index 100% rename from native/cocos/editor-support/spine/SkeletonBounds.cpp rename to native/cocos/editor-support/spine/3.8/spine/SkeletonBounds.cpp diff --git a/native/cocos/editor-support/spine/SkeletonBounds.h b/native/cocos/editor-support/spine/3.8/spine/SkeletonBounds.h similarity index 100% rename from native/cocos/editor-support/spine/SkeletonBounds.h rename to native/cocos/editor-support/spine/3.8/spine/SkeletonBounds.h diff --git a/native/cocos/editor-support/spine/SkeletonClipping.cpp b/native/cocos/editor-support/spine/3.8/spine/SkeletonClipping.cpp similarity index 100% rename from native/cocos/editor-support/spine/SkeletonClipping.cpp rename to native/cocos/editor-support/spine/3.8/spine/SkeletonClipping.cpp diff --git a/native/cocos/editor-support/spine/SkeletonClipping.h b/native/cocos/editor-support/spine/3.8/spine/SkeletonClipping.h similarity index 100% rename from native/cocos/editor-support/spine/SkeletonClipping.h rename to native/cocos/editor-support/spine/3.8/spine/SkeletonClipping.h diff --git a/native/cocos/editor-support/spine/SkeletonData.cpp b/native/cocos/editor-support/spine/3.8/spine/SkeletonData.cpp similarity index 100% rename from native/cocos/editor-support/spine/SkeletonData.cpp rename to native/cocos/editor-support/spine/3.8/spine/SkeletonData.cpp diff --git a/native/cocos/editor-support/spine/SkeletonData.h b/native/cocos/editor-support/spine/3.8/spine/SkeletonData.h similarity index 100% rename from native/cocos/editor-support/spine/SkeletonData.h rename to native/cocos/editor-support/spine/3.8/spine/SkeletonData.h diff --git a/native/cocos/editor-support/spine/SkeletonJson.cpp b/native/cocos/editor-support/spine/3.8/spine/SkeletonJson.cpp similarity index 100% rename from native/cocos/editor-support/spine/SkeletonJson.cpp rename to native/cocos/editor-support/spine/3.8/spine/SkeletonJson.cpp diff --git a/native/cocos/editor-support/spine/SkeletonJson.h b/native/cocos/editor-support/spine/3.8/spine/SkeletonJson.h similarity index 100% rename from native/cocos/editor-support/spine/SkeletonJson.h rename to native/cocos/editor-support/spine/3.8/spine/SkeletonJson.h diff --git a/native/cocos/editor-support/spine/Skin.cpp b/native/cocos/editor-support/spine/3.8/spine/Skin.cpp similarity index 100% rename from native/cocos/editor-support/spine/Skin.cpp rename to native/cocos/editor-support/spine/3.8/spine/Skin.cpp diff --git a/native/cocos/editor-support/spine/Skin.h b/native/cocos/editor-support/spine/3.8/spine/Skin.h similarity index 100% rename from native/cocos/editor-support/spine/Skin.h rename to native/cocos/editor-support/spine/3.8/spine/Skin.h diff --git a/native/cocos/editor-support/spine/Slot.cpp b/native/cocos/editor-support/spine/3.8/spine/Slot.cpp similarity index 100% rename from native/cocos/editor-support/spine/Slot.cpp rename to native/cocos/editor-support/spine/3.8/spine/Slot.cpp diff --git a/native/cocos/editor-support/spine/Slot.h b/native/cocos/editor-support/spine/3.8/spine/Slot.h similarity index 100% rename from native/cocos/editor-support/spine/Slot.h rename to native/cocos/editor-support/spine/3.8/spine/Slot.h diff --git a/native/cocos/editor-support/spine/SlotData.cpp b/native/cocos/editor-support/spine/3.8/spine/SlotData.cpp similarity index 100% rename from native/cocos/editor-support/spine/SlotData.cpp rename to native/cocos/editor-support/spine/3.8/spine/SlotData.cpp diff --git a/native/cocos/editor-support/spine/SlotData.h b/native/cocos/editor-support/spine/3.8/spine/SlotData.h similarity index 100% rename from native/cocos/editor-support/spine/SlotData.h rename to native/cocos/editor-support/spine/3.8/spine/SlotData.h diff --git a/native/cocos/editor-support/spine/SpacingMode.h b/native/cocos/editor-support/spine/3.8/spine/SpacingMode.h similarity index 97% rename from native/cocos/editor-support/spine/SpacingMode.h rename to native/cocos/editor-support/spine/3.8/spine/SpacingMode.h index c84ea5ed40..649c278078 100644 --- a/native/cocos/editor-support/spine/SpacingMode.h +++ b/native/cocos/editor-support/spine/3.8/spine/SpacingMode.h @@ -1,41 +1,41 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_SpacingMode_h -#define Spine_SpacingMode_h - -namespace spine { -enum SpacingMode { - SpacingMode_Length = 0, - SpacingMode_Fixed, - SpacingMode_Percent -}; -} - -#endif /* Spine_SpacingMode_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_SpacingMode_h +#define Spine_SpacingMode_h + +namespace spine { +enum SpacingMode { + SpacingMode_Length = 0, + SpacingMode_Fixed, + SpacingMode_Percent +}; +} + +#endif /* Spine_SpacingMode_h */ diff --git a/native/cocos/editor-support/spine/SpineObject.cpp b/native/cocos/editor-support/spine/3.8/spine/SpineObject.cpp similarity index 100% rename from native/cocos/editor-support/spine/SpineObject.cpp rename to native/cocos/editor-support/spine/3.8/spine/SpineObject.cpp diff --git a/native/cocos/editor-support/spine/SpineObject.h b/native/cocos/editor-support/spine/3.8/spine/SpineObject.h similarity index 100% rename from native/cocos/editor-support/spine/SpineObject.h rename to native/cocos/editor-support/spine/3.8/spine/SpineObject.h diff --git a/native/cocos/editor-support/spine/SpineString.cpp b/native/cocos/editor-support/spine/3.8/spine/SpineString.cpp similarity index 100% rename from native/cocos/editor-support/spine/SpineString.cpp rename to native/cocos/editor-support/spine/3.8/spine/SpineString.cpp diff --git a/native/cocos/editor-support/spine/SpineString.h b/native/cocos/editor-support/spine/3.8/spine/SpineString.h similarity index 100% rename from native/cocos/editor-support/spine/SpineString.h rename to native/cocos/editor-support/spine/3.8/spine/SpineString.h diff --git a/native/cocos/editor-support/spine/TextureLoader.cpp b/native/cocos/editor-support/spine/3.8/spine/TextureLoader.cpp similarity index 97% rename from native/cocos/editor-support/spine/TextureLoader.cpp rename to native/cocos/editor-support/spine/3.8/spine/TextureLoader.cpp index 9039834fbf..bf0f51254f 100644 --- a/native/cocos/editor-support/spine/TextureLoader.cpp +++ b/native/cocos/editor-support/spine/3.8/spine/TextureLoader.cpp @@ -1,42 +1,42 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifdef SPINE_UE4 - #include "SpinePluginPrivatePCH.h" -#endif - -#include - -namespace spine { -TextureLoader::TextureLoader() { -} - -TextureLoader::~TextureLoader() { -} -} // namespace spine +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include + +namespace spine { +TextureLoader::TextureLoader() { +} + +TextureLoader::~TextureLoader() { +} +} // namespace spine diff --git a/native/cocos/editor-support/spine/TextureLoader.h b/native/cocos/editor-support/spine/3.8/spine/TextureLoader.h similarity index 97% rename from native/cocos/editor-support/spine/TextureLoader.h rename to native/cocos/editor-support/spine/3.8/spine/TextureLoader.h index 0b54c333a0..a5e39e6d3d 100644 --- a/native/cocos/editor-support/spine/TextureLoader.h +++ b/native/cocos/editor-support/spine/3.8/spine/TextureLoader.h @@ -1,51 +1,51 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_TextureLoader_h -#define Spine_TextureLoader_h - -#include -#include - -namespace spine { -class AtlasPage; - -class SP_API TextureLoader : public SpineObject { -public: - TextureLoader(); - - virtual ~TextureLoader(); - - virtual void load(AtlasPage& page, const String& path) = 0; - - virtual void unload(void* texture) = 0; -}; -} // namespace spine - -#endif /* Spine_TextureLoader_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_TextureLoader_h +#define Spine_TextureLoader_h + +#include +#include + +namespace spine { +class AtlasPage; + +class SP_API TextureLoader : public SpineObject { +public: + TextureLoader(); + + virtual ~TextureLoader(); + + virtual void load(AtlasPage& page, const String& path) = 0; + + virtual void unload(void* texture) = 0; +}; +} // namespace spine + +#endif /* Spine_TextureLoader_h */ diff --git a/native/cocos/editor-support/spine/Timeline.cpp b/native/cocos/editor-support/spine/3.8/spine/Timeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/Timeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/Timeline.cpp diff --git a/native/cocos/editor-support/spine/Timeline.h b/native/cocos/editor-support/spine/3.8/spine/Timeline.h similarity index 100% rename from native/cocos/editor-support/spine/Timeline.h rename to native/cocos/editor-support/spine/3.8/spine/Timeline.h diff --git a/native/cocos/editor-support/spine/TimelineType.h b/native/cocos/editor-support/spine/3.8/spine/TimelineType.h similarity index 97% rename from native/cocos/editor-support/spine/TimelineType.h rename to native/cocos/editor-support/spine/3.8/spine/TimelineType.h index a86c0fa094..af0d561d54 100644 --- a/native/cocos/editor-support/spine/TimelineType.h +++ b/native/cocos/editor-support/spine/3.8/spine/TimelineType.h @@ -1,53 +1,53 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_TimelineType_h -#define Spine_TimelineType_h - -namespace spine { -enum TimelineType { - TimelineType_Rotate = 0, - TimelineType_Translate, - TimelineType_Scale, - TimelineType_Shear, - TimelineType_Attachment, - TimelineType_Color, - TimelineType_Deform, - TimelineType_Event, - TimelineType_DrawOrder, - TimelineType_IkConstraint, - TimelineType_TransformConstraint, - TimelineType_PathConstraintPosition, - TimelineType_PathConstraintSpacing, - TimelineType_PathConstraintMix, - TimelineType_TwoColor -}; -} - -#endif /* Spine_TimelineType_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_TimelineType_h +#define Spine_TimelineType_h + +namespace spine { +enum TimelineType { + TimelineType_Rotate = 0, + TimelineType_Translate, + TimelineType_Scale, + TimelineType_Shear, + TimelineType_Attachment, + TimelineType_Color, + TimelineType_Deform, + TimelineType_Event, + TimelineType_DrawOrder, + TimelineType_IkConstraint, + TimelineType_TransformConstraint, + TimelineType_PathConstraintPosition, + TimelineType_PathConstraintSpacing, + TimelineType_PathConstraintMix, + TimelineType_TwoColor +}; +} + +#endif /* Spine_TimelineType_h */ diff --git a/native/cocos/editor-support/spine/TransformConstraint.cpp b/native/cocos/editor-support/spine/3.8/spine/TransformConstraint.cpp similarity index 100% rename from native/cocos/editor-support/spine/TransformConstraint.cpp rename to native/cocos/editor-support/spine/3.8/spine/TransformConstraint.cpp diff --git a/native/cocos/editor-support/spine/TransformConstraint.h b/native/cocos/editor-support/spine/3.8/spine/TransformConstraint.h similarity index 100% rename from native/cocos/editor-support/spine/TransformConstraint.h rename to native/cocos/editor-support/spine/3.8/spine/TransformConstraint.h diff --git a/native/cocos/editor-support/spine/TransformConstraintData.cpp b/native/cocos/editor-support/spine/3.8/spine/TransformConstraintData.cpp similarity index 100% rename from native/cocos/editor-support/spine/TransformConstraintData.cpp rename to native/cocos/editor-support/spine/3.8/spine/TransformConstraintData.cpp diff --git a/native/cocos/editor-support/spine/TransformConstraintData.h b/native/cocos/editor-support/spine/3.8/spine/TransformConstraintData.h similarity index 100% rename from native/cocos/editor-support/spine/TransformConstraintData.h rename to native/cocos/editor-support/spine/3.8/spine/TransformConstraintData.h diff --git a/native/cocos/editor-support/spine/TransformConstraintTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/TransformConstraintTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/TransformConstraintTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/TransformConstraintTimeline.cpp diff --git a/native/cocos/editor-support/spine/TransformConstraintTimeline.h b/native/cocos/editor-support/spine/3.8/spine/TransformConstraintTimeline.h similarity index 97% rename from native/cocos/editor-support/spine/TransformConstraintTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/TransformConstraintTimeline.h index 5e3047afc9..85335e38d8 100644 --- a/native/cocos/editor-support/spine/TransformConstraintTimeline.h +++ b/native/cocos/editor-support/spine/3.8/spine/TransformConstraintTimeline.h @@ -1,70 +1,70 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_TransformConstraintTimeline_h -#define Spine_TransformConstraintTimeline_h - -#include - -namespace spine { - -class SP_API TransformConstraintTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - -public: - static const int ENTRIES; - - explicit TransformConstraintTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - void setFrame(size_t frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix); - -private: - static const int PREV_TIME; - static const int PREV_ROTATE; - static const int PREV_TRANSLATE; - static const int PREV_SCALE; - static const int PREV_SHEAR; - static const int ROTATE; - static const int TRANSLATE; - static const int SCALE; - static const int SHEAR; - - Vector _frames; - int _transformConstraintIndex; -}; -} // namespace spine - -#endif /* Spine_TransformConstraintTimeline_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_TransformConstraintTimeline_h +#define Spine_TransformConstraintTimeline_h + +#include + +namespace spine { + +class SP_API TransformConstraintTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + +public: + static const int ENTRIES; + + explicit TransformConstraintTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + void setFrame(size_t frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix); + +private: + static const int PREV_TIME; + static const int PREV_ROTATE; + static const int PREV_TRANSLATE; + static const int PREV_SCALE; + static const int PREV_SHEAR; + static const int ROTATE; + static const int TRANSLATE; + static const int SCALE; + static const int SHEAR; + + Vector _frames; + int _transformConstraintIndex; +}; +} // namespace spine + +#endif /* Spine_TransformConstraintTimeline_h */ diff --git a/native/cocos/editor-support/spine/TransformMode.h b/native/cocos/editor-support/spine/3.8/spine/TransformMode.h similarity index 97% rename from native/cocos/editor-support/spine/TransformMode.h rename to native/cocos/editor-support/spine/3.8/spine/TransformMode.h index c827b4ec4d..a7d589b176 100644 --- a/native/cocos/editor-support/spine/TransformMode.h +++ b/native/cocos/editor-support/spine/3.8/spine/TransformMode.h @@ -1,43 +1,43 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_TransformMode_h -#define Spine_TransformMode_h - -namespace spine { -enum TransformMode { - TransformMode_Normal = 0, - TransformMode_OnlyTranslation, - TransformMode_NoRotationOrReflection, - TransformMode_NoScale, - TransformMode_NoScaleOrReflection -}; -} - -#endif /* Spine_TransformMode_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_TransformMode_h +#define Spine_TransformMode_h + +namespace spine { +enum TransformMode { + TransformMode_Normal = 0, + TransformMode_OnlyTranslation, + TransformMode_NoRotationOrReflection, + TransformMode_NoScale, + TransformMode_NoScaleOrReflection +}; +} + +#endif /* Spine_TransformMode_h */ diff --git a/native/cocos/editor-support/spine/TranslateTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/TranslateTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/TranslateTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/TranslateTimeline.cpp diff --git a/native/cocos/editor-support/spine/TranslateTimeline.h b/native/cocos/editor-support/spine/3.8/spine/TranslateTimeline.h similarity index 97% rename from native/cocos/editor-support/spine/TranslateTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/TranslateTimeline.h index 68b8102291..355d0f36d5 100644 --- a/native/cocos/editor-support/spine/TranslateTimeline.h +++ b/native/cocos/editor-support/spine/3.8/spine/TranslateTimeline.h @@ -1,72 +1,72 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_TranslateTimeline_h -#define Spine_TranslateTimeline_h - -#include - -#include -#include - -namespace spine { - -class SP_API TranslateTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - -public: - static const int ENTRIES; - - explicit TranslateTimeline(int frameCount); - - virtual ~TranslateTimeline(); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(int frameIndex, float time, float x, float y); - -protected: - static const int PREV_TIME; - static const int PREV_X; - static const int PREV_Y; - static const int X; - static const int Y; - - Vector _frames; - int _boneIndex; -}; -} // namespace spine - -#endif /* Spine_TranslateTimeline_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_TranslateTimeline_h +#define Spine_TranslateTimeline_h + +#include + +#include +#include + +namespace spine { + +class SP_API TranslateTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + +public: + static const int ENTRIES; + + explicit TranslateTimeline(int frameCount); + + virtual ~TranslateTimeline(); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, float x, float y); + +protected: + static const int PREV_TIME; + static const int PREV_X; + static const int PREV_Y; + static const int X; + static const int Y; + + Vector _frames; + int _boneIndex; +}; +} // namespace spine + +#endif /* Spine_TranslateTimeline_h */ diff --git a/native/cocos/editor-support/spine/Triangulator.cpp b/native/cocos/editor-support/spine/3.8/spine/Triangulator.cpp similarity index 97% rename from native/cocos/editor-support/spine/Triangulator.cpp rename to native/cocos/editor-support/spine/3.8/spine/Triangulator.cpp index 291f73196f..416e6e657f 100644 --- a/native/cocos/editor-support/spine/Triangulator.cpp +++ b/native/cocos/editor-support/spine/3.8/spine/Triangulator.cpp @@ -1,289 +1,289 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifdef SPINE_UE4 - #include "SpinePluginPrivatePCH.h" -#endif - -#include - -#include - -using namespace spine; - -Triangulator::~Triangulator() { - ContainerUtil::cleanUpVectorOfPointers(_convexPolygons); - ContainerUtil::cleanUpVectorOfPointers(_convexPolygonsIndices); -} - -Vector &Triangulator::triangulate(Vector &vertices) { - size_t vertexCount = vertices.size() >> 1; - - Vector &indices = _indices; - indices.clear(); - indices.ensureCapacity(vertexCount); - indices.setSize(vertexCount, 0); - for (size_t i = 0; i < vertexCount; ++i) { - indices[i] = i; - } - - Vector &isConcaveArray = _isConcaveArray; - isConcaveArray.ensureCapacity(vertexCount); - isConcaveArray.setSize(vertexCount, 0); - for (size_t i = 0, n = vertexCount; i < n; ++i) { - isConcaveArray[i] = isConcave(i, vertexCount, vertices, indices); - } - - Vector &triangles = _triangles; - triangles.clear(); - triangles.ensureCapacity(MathUtil::max((int)0, (int)vertexCount - 2) << 2); - - while (vertexCount > 3) { - // Find ear tip. - size_t previous = vertexCount - 1, i = 0, next = 1; - - // outer: - while (true) { - if (!isConcaveArray[i]) { - int p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1; - float p1x = vertices[p1], p1y = vertices[p1 + 1]; - float p2x = vertices[p2], p2y = vertices[p2 + 1]; - float p3x = vertices[p3], p3y = vertices[p3 + 1]; - for (size_t ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) { - if (!isConcaveArray[ii]) continue; - - int v = indices[ii] << 1; - float &vx = vertices[v], vy = vertices[v + 1]; - if (positiveArea(p3x, p3y, p1x, p1y, vx, vy)) { - if (positiveArea(p1x, p1y, p2x, p2y, vx, vy)) { - if (positiveArea(p2x, p2y, p3x, p3y, vx, vy)) { - goto break_outer; // break outer; - } - } - } - } - break; - } - break_outer: - - if (next == 0) { - do { - if (!isConcaveArray[i]) break; - i--; - } while (i > 0); - break; - } - - previous = i; - i = next; - next = (next + 1) % vertexCount; - } - - // Cut ear tip. - triangles.add(indices[(vertexCount + i - 1) % vertexCount]); - triangles.add(indices[i]); - triangles.add(indices[(i + 1) % vertexCount]); - indices.removeAt(i); - isConcaveArray.removeAt(i); - vertexCount--; - - int previousIndex = (vertexCount + i - 1) % vertexCount; - int nextIndex = i == vertexCount ? 0 : i; - isConcaveArray[previousIndex] = isConcave(previousIndex, vertexCount, vertices, indices); - isConcaveArray[nextIndex] = isConcave(nextIndex, vertexCount, vertices, indices); - } - - if (vertexCount == 3) { - triangles.add(indices[2]); - triangles.add(indices[0]); - triangles.add(indices[1]); - } - - return triangles; -} - -Vector *> &Triangulator::decompose(Vector &vertices, Vector &triangles) { - Vector *> &convexPolygons = _convexPolygons; - for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) - _polygonPool.free(convexPolygons[i]); - convexPolygons.clear(); - - Vector *> &convexPolygonsIndices = _convexPolygonsIndices; - for (size_t i = 0, n = convexPolygonsIndices.size(); i < n; ++i) - _polygonIndicesPool.free(convexPolygonsIndices[i]); - convexPolygonsIndices.clear(); - - Vector *polygonIndices = _polygonIndicesPool.obtain(); - polygonIndices->clear(); - - Vector *polygon = _polygonPool.obtain(); - polygon->clear(); - - // Merge subsequent triangles if they form a triangle fan. - int fanBaseIndex = -1, lastwinding = 0; - for (size_t i = 0, n = triangles.size(); i < n; i += 3) { - int t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1; - float x1 = vertices[t1], y1 = vertices[t1 + 1]; - float x2 = vertices[t2], y2 = vertices[t2 + 1]; - float x3 = vertices[t3], y3 = vertices[t3 + 1]; - - // If the base of the last triangle is the same as this triangle, check if they form a convex polygon (triangle fan). - bool merged = false; - if (fanBaseIndex == t1) { - size_t o = polygon->size() - 4; - Vector &p = *polygon; - int winding1 = winding(p[o], p[o + 1], p[o + 2], p[o + 3], x3, y3); - int winding2 = winding(x3, y3, p[0], p[1], p[2], p[3]); - if (winding1 == lastwinding && winding2 == lastwinding) { - polygon->add(x3); - polygon->add(y3); - polygonIndices->add(t3); - merged = true; - } - } - - // Otherwise make this triangle the new base. - if (!merged) { - if (polygon->size() > 0) { - convexPolygons.add(polygon); - convexPolygonsIndices.add(polygonIndices); - } else { - _polygonPool.free(polygon); - _polygonIndicesPool.free(polygonIndices); - } - - polygon = _polygonPool.obtain(); - polygon->clear(); - polygon->add(x1); - polygon->add(y1); - polygon->add(x2); - polygon->add(y2); - polygon->add(x3); - polygon->add(y3); - polygonIndices = _polygonIndicesPool.obtain(); - polygonIndices->clear(); - polygonIndices->add(t1); - polygonIndices->add(t2); - polygonIndices->add(t3); - lastwinding = winding(x1, y1, x2, y2, x3, y3); - fanBaseIndex = t1; - } - } - - if (polygon->size() > 0) { - convexPolygons.add(polygon); - convexPolygonsIndices.add(polygonIndices); - } - - // Go through the list of polygons and try to merge the remaining triangles with the found triangle fans. - for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) { - polygonIndices = convexPolygonsIndices[i]; - - if (polygonIndices->size() == 0) continue; - int firstIndex = (*polygonIndices)[0]; - int lastIndex = (*polygonIndices)[polygonIndices->size() - 1]; - - polygon = convexPolygons[i]; - size_t o = polygon->size() - 4; - Vector &p = *polygon; - float prevPrevX = p[o], prevPrevY = p[o + 1]; - float prevX = p[o + 2], prevY = p[o + 3]; - float firstX = p[0], firstY = p[1]; - float secondX = p[2], secondY = p[3]; - int winding0 = winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY); - - for (size_t ii = 0; ii < n; ++ii) { - if (ii == i) continue; - - Vector *otherIndicesP = convexPolygonsIndices[ii]; - Vector &otherIndices = *otherIndicesP; - - if (otherIndices.size() != 3) continue; - - int otherFirstIndex = otherIndices[0]; - int otherSecondIndex = otherIndices[1]; - int otherLastIndex = otherIndices[2]; - - Vector *otherPolyP = convexPolygons[ii]; - Vector &otherPoly = *otherPolyP; - - float x3 = otherPoly[otherPoly.size() - 2], y3 = otherPoly[otherPoly.size() - 1]; - - if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue; - - int winding1 = winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3); - int winding2 = winding(x3, y3, firstX, firstY, secondX, secondY); - if (winding1 == winding0 && winding2 == winding0) { - otherPoly.clear(); - otherIndices.clear(); - polygon->add(x3); - polygon->add(y3); - polygonIndices->add(otherLastIndex); - prevPrevX = prevX; - prevPrevY = prevY; - prevX = x3; - prevY = y3; - ii = 0; - } - } - } - - // Remove empty polygons that resulted from the merge step above. - for (int i = (int)convexPolygons.size() - 1; i >= 0; --i) { - polygon = convexPolygons[i]; - if (polygon->size() == 0) { - convexPolygons.removeAt(i); - _polygonPool.free(polygon); - polygonIndices = convexPolygonsIndices[i]; - convexPolygonsIndices.removeAt(i); - _polygonIndicesPool.free(polygonIndices); - } - } - - return convexPolygons; -} - -bool Triangulator::isConcave(int index, int vertexCount, Vector &vertices, Vector &indices) { - int previous = indices[(vertexCount + index - 1) % vertexCount] << 1; - int current = indices[index] << 1; - int next = indices[(index + 1) % vertexCount] << 1; - - return !positiveArea(vertices[previous], vertices[previous + 1], - vertices[current], vertices[current + 1], - vertices[next], vertices[next + 1]); -} - -bool Triangulator::positiveArea(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { - return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0; -} - -int Triangulator::winding(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { - float px = p2x - p1x, py = p2y - p1y; - return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1; -} +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include + +#include + +using namespace spine; + +Triangulator::~Triangulator() { + ContainerUtil::cleanUpVectorOfPointers(_convexPolygons); + ContainerUtil::cleanUpVectorOfPointers(_convexPolygonsIndices); +} + +Vector &Triangulator::triangulate(Vector &vertices) { + size_t vertexCount = vertices.size() >> 1; + + Vector &indices = _indices; + indices.clear(); + indices.ensureCapacity(vertexCount); + indices.setSize(vertexCount, 0); + for (size_t i = 0; i < vertexCount; ++i) { + indices[i] = i; + } + + Vector &isConcaveArray = _isConcaveArray; + isConcaveArray.ensureCapacity(vertexCount); + isConcaveArray.setSize(vertexCount, 0); + for (size_t i = 0, n = vertexCount; i < n; ++i) { + isConcaveArray[i] = isConcave(i, vertexCount, vertices, indices); + } + + Vector &triangles = _triangles; + triangles.clear(); + triangles.ensureCapacity(MathUtil::max((int)0, (int)vertexCount - 2) << 2); + + while (vertexCount > 3) { + // Find ear tip. + size_t previous = vertexCount - 1, i = 0, next = 1; + + // outer: + while (true) { + if (!isConcaveArray[i]) { + int p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1; + float p1x = vertices[p1], p1y = vertices[p1 + 1]; + float p2x = vertices[p2], p2y = vertices[p2 + 1]; + float p3x = vertices[p3], p3y = vertices[p3 + 1]; + for (size_t ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) { + if (!isConcaveArray[ii]) continue; + + int v = indices[ii] << 1; + float &vx = vertices[v], vy = vertices[v + 1]; + if (positiveArea(p3x, p3y, p1x, p1y, vx, vy)) { + if (positiveArea(p1x, p1y, p2x, p2y, vx, vy)) { + if (positiveArea(p2x, p2y, p3x, p3y, vx, vy)) { + goto break_outer; // break outer; + } + } + } + } + break; + } + break_outer: + + if (next == 0) { + do { + if (!isConcaveArray[i]) break; + i--; + } while (i > 0); + break; + } + + previous = i; + i = next; + next = (next + 1) % vertexCount; + } + + // Cut ear tip. + triangles.add(indices[(vertexCount + i - 1) % vertexCount]); + triangles.add(indices[i]); + triangles.add(indices[(i + 1) % vertexCount]); + indices.removeAt(i); + isConcaveArray.removeAt(i); + vertexCount--; + + int previousIndex = (vertexCount + i - 1) % vertexCount; + int nextIndex = i == vertexCount ? 0 : i; + isConcaveArray[previousIndex] = isConcave(previousIndex, vertexCount, vertices, indices); + isConcaveArray[nextIndex] = isConcave(nextIndex, vertexCount, vertices, indices); + } + + if (vertexCount == 3) { + triangles.add(indices[2]); + triangles.add(indices[0]); + triangles.add(indices[1]); + } + + return triangles; +} + +Vector *> &Triangulator::decompose(Vector &vertices, Vector &triangles) { + Vector *> &convexPolygons = _convexPolygons; + for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) + _polygonPool.free(convexPolygons[i]); + convexPolygons.clear(); + + Vector *> &convexPolygonsIndices = _convexPolygonsIndices; + for (size_t i = 0, n = convexPolygonsIndices.size(); i < n; ++i) + _polygonIndicesPool.free(convexPolygonsIndices[i]); + convexPolygonsIndices.clear(); + + Vector *polygonIndices = _polygonIndicesPool.obtain(); + polygonIndices->clear(); + + Vector *polygon = _polygonPool.obtain(); + polygon->clear(); + + // Merge subsequent triangles if they form a triangle fan. + int fanBaseIndex = -1, lastwinding = 0; + for (size_t i = 0, n = triangles.size(); i < n; i += 3) { + int t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1; + float x1 = vertices[t1], y1 = vertices[t1 + 1]; + float x2 = vertices[t2], y2 = vertices[t2 + 1]; + float x3 = vertices[t3], y3 = vertices[t3 + 1]; + + // If the base of the last triangle is the same as this triangle, check if they form a convex polygon (triangle fan). + bool merged = false; + if (fanBaseIndex == t1) { + size_t o = polygon->size() - 4; + Vector &p = *polygon; + int winding1 = winding(p[o], p[o + 1], p[o + 2], p[o + 3], x3, y3); + int winding2 = winding(x3, y3, p[0], p[1], p[2], p[3]); + if (winding1 == lastwinding && winding2 == lastwinding) { + polygon->add(x3); + polygon->add(y3); + polygonIndices->add(t3); + merged = true; + } + } + + // Otherwise make this triangle the new base. + if (!merged) { + if (polygon->size() > 0) { + convexPolygons.add(polygon); + convexPolygonsIndices.add(polygonIndices); + } else { + _polygonPool.free(polygon); + _polygonIndicesPool.free(polygonIndices); + } + + polygon = _polygonPool.obtain(); + polygon->clear(); + polygon->add(x1); + polygon->add(y1); + polygon->add(x2); + polygon->add(y2); + polygon->add(x3); + polygon->add(y3); + polygonIndices = _polygonIndicesPool.obtain(); + polygonIndices->clear(); + polygonIndices->add(t1); + polygonIndices->add(t2); + polygonIndices->add(t3); + lastwinding = winding(x1, y1, x2, y2, x3, y3); + fanBaseIndex = t1; + } + } + + if (polygon->size() > 0) { + convexPolygons.add(polygon); + convexPolygonsIndices.add(polygonIndices); + } + + // Go through the list of polygons and try to merge the remaining triangles with the found triangle fans. + for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) { + polygonIndices = convexPolygonsIndices[i]; + + if (polygonIndices->size() == 0) continue; + int firstIndex = (*polygonIndices)[0]; + int lastIndex = (*polygonIndices)[polygonIndices->size() - 1]; + + polygon = convexPolygons[i]; + size_t o = polygon->size() - 4; + Vector &p = *polygon; + float prevPrevX = p[o], prevPrevY = p[o + 1]; + float prevX = p[o + 2], prevY = p[o + 3]; + float firstX = p[0], firstY = p[1]; + float secondX = p[2], secondY = p[3]; + int winding0 = winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY); + + for (size_t ii = 0; ii < n; ++ii) { + if (ii == i) continue; + + Vector *otherIndicesP = convexPolygonsIndices[ii]; + Vector &otherIndices = *otherIndicesP; + + if (otherIndices.size() != 3) continue; + + int otherFirstIndex = otherIndices[0]; + int otherSecondIndex = otherIndices[1]; + int otherLastIndex = otherIndices[2]; + + Vector *otherPolyP = convexPolygons[ii]; + Vector &otherPoly = *otherPolyP; + + float x3 = otherPoly[otherPoly.size() - 2], y3 = otherPoly[otherPoly.size() - 1]; + + if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue; + + int winding1 = winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3); + int winding2 = winding(x3, y3, firstX, firstY, secondX, secondY); + if (winding1 == winding0 && winding2 == winding0) { + otherPoly.clear(); + otherIndices.clear(); + polygon->add(x3); + polygon->add(y3); + polygonIndices->add(otherLastIndex); + prevPrevX = prevX; + prevPrevY = prevY; + prevX = x3; + prevY = y3; + ii = 0; + } + } + } + + // Remove empty polygons that resulted from the merge step above. + for (int i = (int)convexPolygons.size() - 1; i >= 0; --i) { + polygon = convexPolygons[i]; + if (polygon->size() == 0) { + convexPolygons.removeAt(i); + _polygonPool.free(polygon); + polygonIndices = convexPolygonsIndices[i]; + convexPolygonsIndices.removeAt(i); + _polygonIndicesPool.free(polygonIndices); + } + } + + return convexPolygons; +} + +bool Triangulator::isConcave(int index, int vertexCount, Vector &vertices, Vector &indices) { + int previous = indices[(vertexCount + index - 1) % vertexCount] << 1; + int current = indices[index] << 1; + int next = indices[(index + 1) % vertexCount] << 1; + + return !positiveArea(vertices[previous], vertices[previous + 1], + vertices[current], vertices[current + 1], + vertices[next], vertices[next + 1]); +} + +bool Triangulator::positiveArea(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { + return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0; +} + +int Triangulator::winding(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { + float px = p2x - p1x, py = p2y - p1y; + return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1; +} diff --git a/native/cocos/editor-support/spine/Triangulator.h b/native/cocos/editor-support/spine/3.8/spine/Triangulator.h similarity index 100% rename from native/cocos/editor-support/spine/Triangulator.h rename to native/cocos/editor-support/spine/3.8/spine/Triangulator.h diff --git a/native/cocos/editor-support/spine/TwoColorTimeline.cpp b/native/cocos/editor-support/spine/3.8/spine/TwoColorTimeline.cpp similarity index 100% rename from native/cocos/editor-support/spine/TwoColorTimeline.cpp rename to native/cocos/editor-support/spine/3.8/spine/TwoColorTimeline.cpp diff --git a/native/cocos/editor-support/spine/TwoColorTimeline.h b/native/cocos/editor-support/spine/3.8/spine/TwoColorTimeline.h similarity index 97% rename from native/cocos/editor-support/spine/TwoColorTimeline.h rename to native/cocos/editor-support/spine/3.8/spine/TwoColorTimeline.h index ee8dcc9d2a..a59b7e9ad0 100644 --- a/native/cocos/editor-support/spine/TwoColorTimeline.h +++ b/native/cocos/editor-support/spine/3.8/spine/TwoColorTimeline.h @@ -1,80 +1,80 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_TwoColorTimeline_h -#define Spine_TwoColorTimeline_h - -#include - -namespace spine { - -class SP_API TwoColorTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - -public: - static const int ENTRIES; - - explicit TwoColorTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2); - - int getSlotIndex(); - void setSlotIndex(int inValue); - -private: - static const int PREV_TIME; - static const int PREV_R; - static const int PREV_G; - static const int PREV_B; - static const int PREV_A; - static const int PREV_R2; - static const int PREV_G2; - static const int PREV_B2; - static const int R; - static const int G; - static const int B; - static const int A; - static const int R2; - static const int G2; - static const int B2; - - Vector _frames; // time, r, g, b, a, r2, g2, b2, ... - int _slotIndex; -}; -} // namespace spine - -#endif /* Spine_TwoColorTimeline_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_TwoColorTimeline_h +#define Spine_TwoColorTimeline_h + +#include + +namespace spine { + +class SP_API TwoColorTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + +public: + static const int ENTRIES; + + explicit TwoColorTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2); + + int getSlotIndex(); + void setSlotIndex(int inValue); + +private: + static const int PREV_TIME; + static const int PREV_R; + static const int PREV_G; + static const int PREV_B; + static const int PREV_A; + static const int PREV_R2; + static const int PREV_G2; + static const int PREV_B2; + static const int R; + static const int G; + static const int B; + static const int A; + static const int R2; + static const int G2; + static const int B2; + + Vector _frames; // time, r, g, b, a, r2, g2, b2, ... + int _slotIndex; +}; +} // namespace spine + +#endif /* Spine_TwoColorTimeline_h */ diff --git a/native/cocos/editor-support/spine/Updatable.cpp b/native/cocos/editor-support/spine/3.8/spine/Updatable.cpp similarity index 97% rename from native/cocos/editor-support/spine/Updatable.cpp rename to native/cocos/editor-support/spine/3.8/spine/Updatable.cpp index 2aae06552f..571721aab4 100644 --- a/native/cocos/editor-support/spine/Updatable.cpp +++ b/native/cocos/editor-support/spine/3.8/spine/Updatable.cpp @@ -1,44 +1,44 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifdef SPINE_UE4 - #include "SpinePluginPrivatePCH.h" -#endif - -#include - -using namespace spine; - -RTTI_IMPL_NOPARENT(Updatable) - -Updatable::Updatable() { -} - -Updatable::~Updatable() { -} +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifdef SPINE_UE4 + #include "SpinePluginPrivatePCH.h" +#endif + +#include + +using namespace spine; + +RTTI_IMPL_NOPARENT(Updatable) + +Updatable::Updatable() { +} + +Updatable::~Updatable() { +} diff --git a/native/cocos/editor-support/spine/Updatable.h b/native/cocos/editor-support/spine/3.8/spine/Updatable.h similarity index 97% rename from native/cocos/editor-support/spine/Updatable.h rename to native/cocos/editor-support/spine/3.8/spine/Updatable.h index 98d8cd0bc9..7f6fba7461 100644 --- a/native/cocos/editor-support/spine/Updatable.h +++ b/native/cocos/editor-support/spine/3.8/spine/Updatable.h @@ -1,53 +1,53 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_Updatable_h -#define Spine_Updatable_h - -#include -#include - -namespace spine { -class SP_API Updatable : public SpineObject { - RTTI_DECL - -public: - Updatable(); - - virtual ~Updatable(); - - virtual void update() = 0; - - virtual bool isActive() = 0; - - virtual void setActive(bool inValue) = 0; -}; -} // namespace spine - -#endif /* Spine_Updatable_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_Updatable_h +#define Spine_Updatable_h + +#include +#include + +namespace spine { +class SP_API Updatable : public SpineObject { + RTTI_DECL + +public: + Updatable(); + + virtual ~Updatable(); + + virtual void update() = 0; + + virtual bool isActive() = 0; + + virtual void setActive(bool inValue) = 0; +}; +} // namespace spine + +#endif /* Spine_Updatable_h */ diff --git a/native/cocos/editor-support/spine/Vector.h b/native/cocos/editor-support/spine/3.8/spine/Vector.h similarity index 100% rename from native/cocos/editor-support/spine/Vector.h rename to native/cocos/editor-support/spine/3.8/spine/Vector.h diff --git a/native/cocos/editor-support/spine/VertexAttachment.cpp b/native/cocos/editor-support/spine/3.8/spine/VertexAttachment.cpp similarity index 100% rename from native/cocos/editor-support/spine/VertexAttachment.cpp rename to native/cocos/editor-support/spine/3.8/spine/VertexAttachment.cpp diff --git a/native/cocos/editor-support/spine/VertexAttachment.h b/native/cocos/editor-support/spine/3.8/spine/VertexAttachment.h similarity index 100% rename from native/cocos/editor-support/spine/VertexAttachment.h rename to native/cocos/editor-support/spine/3.8/spine/VertexAttachment.h diff --git a/native/cocos/editor-support/spine/VertexEffect.cpp b/native/cocos/editor-support/spine/3.8/spine/VertexEffect.cpp similarity index 100% rename from native/cocos/editor-support/spine/VertexEffect.cpp rename to native/cocos/editor-support/spine/3.8/spine/VertexEffect.cpp diff --git a/native/cocos/editor-support/spine/VertexEffect.h b/native/cocos/editor-support/spine/3.8/spine/VertexEffect.h similarity index 100% rename from native/cocos/editor-support/spine/VertexEffect.h rename to native/cocos/editor-support/spine/3.8/spine/VertexEffect.h diff --git a/native/cocos/editor-support/spine/Vertices.h b/native/cocos/editor-support/spine/3.8/spine/Vertices.h similarity index 97% rename from native/cocos/editor-support/spine/Vertices.h rename to native/cocos/editor-support/spine/3.8/spine/Vertices.h index 903f8d2df9..d42639c0e5 100644 --- a/native/cocos/editor-support/spine/Vertices.h +++ b/native/cocos/editor-support/spine/3.8/spine/Vertices.h @@ -1,43 +1,43 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef Spine_Vertices_h -#define Spine_Vertices_h - -#include - -namespace spine { -class SP_API Vertices : public SpineObject { -public: - Vector _bones; - Vector _vertices; -}; -} // namespace spine - -#endif /* Spine_Vertices_h */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef Spine_Vertices_h +#define Spine_Vertices_h + +#include + +namespace spine { +class SP_API Vertices : public SpineObject { +public: + Vector _bones; + Vector _vertices; +}; +} // namespace spine + +#endif /* Spine_Vertices_h */ diff --git a/native/cocos/editor-support/spine/dll.h b/native/cocos/editor-support/spine/3.8/spine/dll.h similarity index 97% rename from native/cocos/editor-support/spine/dll.h rename to native/cocos/editor-support/spine/3.8/spine/dll.h index 5f500f5d3a..2e69c6284f 100644 --- a/native/cocos/editor-support/spine/dll.h +++ b/native/cocos/editor-support/spine/3.8/spine/dll.h @@ -1,51 +1,51 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef SPINE_SHAREDLIB_H -#define SPINE_SHAREDLIB_H - -#ifdef _WIN32 - #define DLLIMPORT __declspec(dllimport) - #define DLLEXPORT __declspec(dllexport) -#else - #ifndef DLLIMPORT - #define DLLIMPORT - #endif - #ifndef DLLEXPORT - #define DLLEXPORT - #endif -#endif - -#ifdef SPINEPLUGIN_API - #define SP_API SPINEPLUGIN_API -#else - #define SP_API -#endif - -#endif /* SPINE_SHAREDLIB_H */ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef SPINE_SHAREDLIB_H +#define SPINE_SHAREDLIB_H + +#ifdef _WIN32 + #define DLLIMPORT __declspec(dllimport) + #define DLLEXPORT __declspec(dllexport) +#else + #ifndef DLLIMPORT + #define DLLIMPORT + #endif + #ifndef DLLEXPORT + #define DLLEXPORT + #endif +#endif + +#ifdef SPINEPLUGIN_API + #define SP_API SPINEPLUGIN_API +#else + #define SP_API +#endif + +#endif /* SPINE_SHAREDLIB_H */ diff --git a/native/cocos/editor-support/spine/spine.h b/native/cocos/editor-support/spine/3.8/spine/spine.h similarity index 97% rename from native/cocos/editor-support/spine/spine.h rename to native/cocos/editor-support/spine/3.8/spine/spine.h index 39d989bef0..6e6ae5ba6a 100644 --- a/native/cocos/editor-support/spine/spine.h +++ b/native/cocos/editor-support/spine/3.8/spine/spine.h @@ -1,112 +1,112 @@ -/****************************************************************************** - * 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. - *****************************************************************************/ - -#ifndef SPINE_SPINE_H_ -#define SPINE_SPINE_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef SPINE_SPINE_H_ +#define SPINE_SPINE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/native/cocos/editor-support/spine/4.2/spine/Animation.cpp b/native/cocos/editor-support/spine/4.2/spine/Animation.cpp new file mode 100644 index 0000000000..a5c03230f6 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Animation.cpp @@ -0,0 +1,107 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include +#include +#include + +#include + +#include + +using namespace spine; + +Animation::Animation(const String &name, Vector &timelines, float duration) : _timelines(timelines), + _timelineIds(), + _duration(duration), + _name(name) { + assert(_name.length() > 0); + for (size_t i = 0; i < timelines.size(); i++) { + Vector propertyIds = timelines[i]->getPropertyIds(); + for (size_t ii = 0; ii < propertyIds.size(); ii++) + _timelineIds.put(propertyIds[ii], true); + } +} + +bool Animation::hasTimeline(Vector &ids) { + for (size_t i = 0; i < ids.size(); i++) { + if (_timelineIds.containsKey(ids[i])) return true; + } + return false; +} + +Animation::~Animation() { + ContainerUtil::cleanUpVectorOfPointers(_timelines); +} + +void Animation::apply(Skeleton &skeleton, float lastTime, float time, bool loop, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + if (loop && _duration != 0) { + time = MathUtil::fmod(time, _duration); + if (lastTime > 0) { + lastTime = MathUtil::fmod(lastTime, _duration); + } + } + + for (size_t i = 0, n = _timelines.size(); i < n; ++i) { + _timelines[i]->apply(skeleton, lastTime, time, pEvents, alpha, blend, direction); + } +} + +const String &Animation::getName() { + return _name; +} + +Vector &Animation::getTimelines() { + return _timelines; +} + +float Animation::getDuration() { + return _duration; +} + +void Animation::setDuration(float inValue) { + _duration = inValue; +} + +int Animation::search(Vector &frames, float target) { + size_t n = (int) frames.size(); + for (size_t i = 1; i < n; i++) { + if (frames[i] > target) return (int) (i - 1); + } + return (int) (n - 1); +} + +int Animation::search(Vector &frames, float target, int step) { + size_t n = frames.size(); + for (size_t i = step; i < n; i += step) + if (frames[i] > target) return (int) (i - step); + return (int) (n - step); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Animation.h b/native/cocos/editor-support/spine/4.2/spine/Animation.h new file mode 100644 index 0000000000..9fb61b15c2 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Animation.h @@ -0,0 +1,133 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Animation_h +#define Spine_Animation_h + +#include +#include +#include +#include +#include +#include +#include + +namespace spine { + class Timeline; + + class Skeleton; + + class Event; + + class AnimationState; + + class SP_API Animation : public SpineObject { + friend class AnimationState; + + friend class TrackEntry; + + friend class AnimationStateData; + + friend class AttachmentTimeline; + + friend class RGBATimeline; + + friend class RGBTimeline; + + friend class AlphaTimeline; + + friend class RGBA2Timeline; + + friend class RGB2Timeline; + + friend class DeformTimeline; + + friend class DrawOrderTimeline; + + friend class EventTimeline; + + friend class IkConstraintTimeline; + + friend class PathConstraintMixTimeline; + + friend class PathConstraintPositionTimeline; + + friend class PathConstraintSpacingTimeline; + + friend class RotateTimeline; + + friend class ScaleTimeline; + + friend class ShearTimeline; + + friend class TransformConstraintTimeline; + + friend class TranslateTimeline; + + friend class TranslateXTimeline; + + friend class TranslateYTimeline; + + friend class TwoColorTimeline; + + public: + Animation(const String &name, Vector &timelines, float duration); + + ~Animation(); + + /// Applies all the animation's timelines to the specified skeleton. + /// See also Timeline::apply(Skeleton&, float, float, Vector, float, MixPose, MixDirection) + void apply(Skeleton &skeleton, float lastTime, float time, bool loop, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction); + + const String &getName(); + + Vector &getTimelines(); + + bool hasTimeline(Vector &ids); + + float getDuration(); + + void setDuration(float inValue); + + /// @param target After the first and before the last entry. + static int search(Vector &values, float target); + + static int search(Vector &values, float target, int step); + #ifndef __EMSCRIPTEN__ + private: + #endif + Vector _timelines; + HashMap _timelineIds; + float _duration; + String _name; + }; +} + +#endif /* Spine_Animation_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/AnimationState.cpp b/native/cocos/editor-support/spine/4.2/spine/AnimationState.cpp new file mode 100644 index 0000000000..ed8126d2a1 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AnimationState.cpp @@ -0,0 +1,1100 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace spine; + +void dummyOnAnimationEventFunc(AnimationState *state, spine::EventType type, TrackEntry *entry, Event *event = NULL) { + SP_UNUSED(state); + SP_UNUSED(type); + SP_UNUSED(entry); + SP_UNUSED(event); +} + +TrackEntry::TrackEntry() : _animation(NULL), _previous(NULL), _next(NULL), _mixingFrom(NULL), _mixingTo(0), + _trackIndex(0), _loop(false), _holdPrevious(false), _reverse(false), + _shortestRotation(false), + _eventThreshold(0), _mixAttachmentThreshold(0), _alphaAttachmentThreshold(0), _mixDrawOrderThreshold(0), _animationStart(0), + _animationEnd(0), _animationLast(0), _nextAnimationLast(0), _delay(0), _trackTime(0), + _trackLast(0), _nextTrackLast(0), _trackEnd(0), _timeScale(1.0f), _alpha(0), _mixTime(0), + _mixDuration(0), _interruptAlpha(0), _totalAlpha(0), _mixBlend(MixBlend_Replace), + _listener(dummyOnAnimationEventFunc), _listenerObject(NULL) { +} + +TrackEntry::~TrackEntry() {} + +int TrackEntry::getTrackIndex() { return _trackIndex; } + +Animation *TrackEntry::getAnimation() { return _animation; } + +TrackEntry *TrackEntry::getPrevious() { return _previous; } + +bool TrackEntry::getLoop() { return _loop; } + +void TrackEntry::setLoop(bool inValue) { _loop = inValue; } + +bool TrackEntry::getHoldPrevious() { return _holdPrevious; } + +void TrackEntry::setHoldPrevious(bool inValue) { _holdPrevious = inValue; } + +bool TrackEntry::getReverse() { return _reverse; } + +void TrackEntry::setReverse(bool inValue) { _reverse = inValue; } + +bool TrackEntry::getShortestRotation() { return _shortestRotation; } + +void TrackEntry::setShortestRotation(bool inValue) { _shortestRotation = inValue; } + +float TrackEntry::getDelay() { return _delay; } + +void TrackEntry::setDelay(float inValue) { _delay = inValue; } + +float TrackEntry::getTrackTime() { return _trackTime; } + +void TrackEntry::setTrackTime(float inValue) { _trackTime = inValue; } + +float TrackEntry::getTrackEnd() { return _trackEnd; } + +void TrackEntry::setTrackEnd(float inValue) { _trackEnd = inValue; } + +float TrackEntry::getAnimationStart() { return _animationStart; } + +void TrackEntry::setAnimationStart(float inValue) { _animationStart = inValue; } + +float TrackEntry::getAnimationEnd() { return _animationEnd; } + +void TrackEntry::setAnimationEnd(float inValue) { _animationEnd = inValue; } + +float TrackEntry::getAnimationLast() { return _animationLast; } + +void TrackEntry::setAnimationLast(float inValue) { + _animationLast = inValue; + _nextAnimationLast = inValue; +} + +float TrackEntry::getAnimationTime() { + if (_loop) { + float duration = _animationEnd - _animationStart; + if (duration == 0) return _animationStart; + return MathUtil::fmod(_trackTime, duration) + _animationStart; + } + + return MathUtil::min(_trackTime + _animationStart, _animationEnd); +} + +float TrackEntry::getTimeScale() { return _timeScale; } + +void TrackEntry::setTimeScale(float inValue) { _timeScale = inValue; } + +float TrackEntry::getAlpha() { return _alpha; } + +void TrackEntry::setAlpha(float inValue) { _alpha = inValue; } + +float TrackEntry::getEventThreshold() { return _eventThreshold; } + +void TrackEntry::setEventThreshold(float inValue) { _eventThreshold = inValue; } + +float TrackEntry::getMixAttachmentThreshold() { return _mixAttachmentThreshold; } + +void TrackEntry::setMixAttachmentThreshold(float inValue) { _mixAttachmentThreshold = inValue; } + +float TrackEntry::getAlphaAttachmentThreshold() { return _alphaAttachmentThreshold; } + +void TrackEntry::setAlphaAttachmentThreshold(float inValue) { _alphaAttachmentThreshold = inValue; } + +float TrackEntry::getMixDrawOrderThreshold() { return _mixDrawOrderThreshold; } + +void TrackEntry::setMixDrawOrderThreshold(float inValue) { _mixDrawOrderThreshold = inValue; } + +TrackEntry *TrackEntry::getNext() { return _next; } + +bool TrackEntry::isComplete() { + return _trackTime >= _animationEnd - _animationStart; +} + +float TrackEntry::getMixTime() { return _mixTime; } + +void TrackEntry::setMixTime(float inValue) { _mixTime = inValue; } + +float TrackEntry::getMixDuration() { return _mixDuration; } + +void TrackEntry::setMixDuration(float inValue) { _mixDuration = inValue; } + +void TrackEntry::setMixDuration(float mixDuration, float delay) { + _mixDuration = mixDuration; + if (_previous && delay <= 0) delay += _previous->getTrackComplete() - mixDuration; + this->_delay = delay; +} + +TrackEntry *TrackEntry::getMixingFrom() { return _mixingFrom; } + +TrackEntry *TrackEntry::getMixingTo() { return _mixingTo; } + +void TrackEntry::setMixBlend(MixBlend blend) { _mixBlend = blend; } + +MixBlend TrackEntry::getMixBlend() { return _mixBlend; } + +void TrackEntry::resetRotationDirections() { + _timelinesRotation.clear(); +} + +void TrackEntry::setListener(AnimationStateListener inValue) { + _listener = inValue; + _listenerObject = NULL; +} + +void TrackEntry::setListener(AnimationStateListenerObject *inValue) { + _listener = dummyOnAnimationEventFunc; + _listenerObject = inValue; +} + +void TrackEntry::reset() { + _animation = NULL; + _previous = NULL; + _next = NULL; + _mixingFrom = NULL; + _mixingTo = NULL; + + setRendererObject(NULL); + + _timelineMode.clear(); + _timelineHoldMix.clear(); + _timelinesRotation.clear(); + + _listener = dummyOnAnimationEventFunc; + _listenerObject = NULL; +} + +float TrackEntry::getTrackComplete() { + float duration = _animationEnd - _animationStart; + if (duration != 0) { + if (_loop) return duration * (1 + (int) (_trackTime / duration));// Completion of next loop. + if (_trackTime < duration) return duration; // Before duration. + } + return _trackTime;// Next update. +} + +bool TrackEntry::wasApplied() { + return _nextTrackLast != -1; +} + +EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Event *event) : _type(eventType), + _entry(trackEntry), + _event(event) { +} + +EventQueue *EventQueue::newEventQueue(AnimationState &state) { + return new (__FILE__, __LINE__) EventQueue(state); +} + +EventQueueEntry EventQueue::newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event) { + return EventQueueEntry(eventType, entry, event); +} + +EventQueue::EventQueue(AnimationState &state) : _state(state), + _drainDisabled(false) { +} + +EventQueue::~EventQueue() { +} + +void EventQueue::start(TrackEntry *entry) { + _eventQueueEntries.add(newEventQueueEntry(EventType_Start, entry)); + _state._animationsChanged = true; +} + +void EventQueue::interrupt(TrackEntry *entry) { + _eventQueueEntries.add(newEventQueueEntry(EventType_Interrupt, entry)); +} + +void EventQueue::end(TrackEntry *entry) { + _eventQueueEntries.add(newEventQueueEntry(EventType_End, entry)); + _state._animationsChanged = true; +} + +void EventQueue::dispose(TrackEntry *entry) { + _eventQueueEntries.add(newEventQueueEntry(EventType_Dispose, entry)); +} + +void EventQueue::complete(TrackEntry *entry) { + _eventQueueEntries.add(newEventQueueEntry(EventType_Complete, entry)); +} + +void EventQueue::event(TrackEntry *entry, Event *event) { + _eventQueueEntries.add(newEventQueueEntry(EventType_Event, entry, event)); +} + +/// Raises all events in the queue and drains the queue. +void EventQueue::drain() { + if (_drainDisabled) { + return; + } + + _drainDisabled = true; + + AnimationState &state = _state; + + // Don't cache _eventQueueEntries.size() so callbacks can queue their own events (eg, call setAnimation in AnimationState_Complete). + for (size_t i = 0; i < _eventQueueEntries.size(); ++i) { + EventQueueEntry queueEntry = _eventQueueEntries[i]; + TrackEntry *trackEntry = queueEntry._entry; + + switch (queueEntry._type) { + case EventType_Start: + case EventType_Interrupt: + case EventType_Complete: + if (!trackEntry->_listenerObject) trackEntry->_listener(&state, queueEntry._type, trackEntry, NULL); + else + trackEntry->_listenerObject->callback(&state, queueEntry._type, trackEntry, NULL); + if (!state._listenerObject) state._listener(&state, queueEntry._type, trackEntry, NULL); + else + state._listenerObject->callback(&state, queueEntry._type, trackEntry, NULL); + break; + case EventType_End: + if (!trackEntry->_listenerObject) trackEntry->_listener(&state, queueEntry._type, trackEntry, NULL); + else + trackEntry->_listenerObject->callback(&state, queueEntry._type, trackEntry, NULL); + if (!state._listenerObject) state._listener(&state, queueEntry._type, trackEntry, NULL); + else + state._listenerObject->callback(&state, queueEntry._type, trackEntry, NULL); + /* Fall through. */ + case EventType_Dispose: + if (!trackEntry->_listenerObject) trackEntry->_listener(&state, EventType_Dispose, trackEntry, NULL); + else + trackEntry->_listenerObject->callback(&state, EventType_Dispose, trackEntry, NULL); + if (!state._listenerObject) state._listener(&state, EventType_Dispose, trackEntry, NULL); + else + state._listenerObject->callback(&state, EventType_Dispose, trackEntry, NULL); + + if (!_state.getManualTrackEntryDisposal()) _state.disposeTrackEntry(trackEntry); + break; + case EventType_Event: + if (!trackEntry->_listenerObject) + trackEntry->_listener(&state, queueEntry._type, trackEntry, queueEntry._event); + else + trackEntry->_listenerObject->callback(&state, queueEntry._type, trackEntry, queueEntry._event); + if (!state._listenerObject) state._listener(&state, queueEntry._type, trackEntry, queueEntry._event); + else + state._listenerObject->callback(&state, queueEntry._type, trackEntry, queueEntry._event); + break; + } + } + _eventQueueEntries.clear(); + + _drainDisabled = false; +} + +AnimationState::AnimationState(AnimationStateData *data) : _data(data), + _queue(EventQueue::newEventQueue(*this)), + _animationsChanged(false), + _listener(dummyOnAnimationEventFunc), + _listenerObject(NULL), + _unkeyedState(0), + _timeScale(1), + _manualTrackEntryDisposal(false) { +} + +AnimationState::~AnimationState() { + for (size_t i = 0; i < _tracks.size(); i++) { + TrackEntry *entry = _tracks[i]; + if (entry) { + TrackEntry *from = entry->_mixingFrom; + while (from) { + TrackEntry *curr = from; + from = curr->_mixingFrom; + delete curr; + } + TrackEntry *next = entry->_next; + while (next) { + TrackEntry *curr = next; + next = curr->_next; + delete curr; + } + delete entry; + } + } + delete _queue; +} + +void AnimationState::update(float delta) { + delta *= _timeScale; + for (size_t i = 0, n = _tracks.size(); i < n; ++i) { + TrackEntry *currentP = _tracks[i]; + if (currentP == NULL) { + continue; + } + + TrackEntry ¤t = *currentP; + + current._animationLast = current._nextAnimationLast; + current._trackLast = current._nextTrackLast; + + float currentDelta = delta * current._timeScale; + + if (current._delay > 0) { + current._delay -= currentDelta; + if (current._delay > 0) { + continue; + } + currentDelta = -current._delay; + current._delay = 0; + } + + TrackEntry *next = current._next; + if (next != NULL) { + // When the next entry's delay is passed, change to the next entry, preserving leftover time. + float nextTime = current._trackLast - next->_delay; + if (nextTime >= 0) { + next->_delay = 0; + next->_trackTime += + current._timeScale == 0 ? 0 : (nextTime / current._timeScale + delta) * next->_timeScale; + current._trackTime += currentDelta; + setCurrent(i, next, true); + while (next->_mixingFrom != NULL) { + next->_mixTime += delta; + next = next->_mixingFrom; + } + continue; + } + } else if (current._trackLast >= current._trackEnd && current._mixingFrom == NULL) { + // clear the track when there is no next entry, the track end time is reached, and there is no mixingFrom. + _tracks[i] = NULL; + + _queue->end(currentP); + clearNext(currentP); + continue; + } + + if (current._mixingFrom != NULL && updateMixingFrom(currentP, delta)) { + // End mixing from entries once all have completed. + TrackEntry *from = current._mixingFrom; + current._mixingFrom = NULL; + if (from != NULL) from->_mixingTo = NULL; + while (from != NULL) { + _queue->end(from); + from = from->_mixingFrom; + } + } + + current._trackTime += currentDelta; + } + + _queue->drain(); +} + +bool AnimationState::apply(Skeleton &skeleton) { + if (_animationsChanged) { + animationsChanged(); + } + + bool applied = false; + for (size_t i = 0, n = _tracks.size(); i < n; ++i) { + TrackEntry *currentP = _tracks[i]; + if (currentP == NULL || currentP->_delay > 0) { + continue; + } + + TrackEntry ¤t = *currentP; + + applied = true; + MixBlend blend = i == 0 ? MixBlend_First : current._mixBlend; + + // apply mixing from entries first. + float alpha = current._alpha; + if (current._mixingFrom != NULL) { + alpha *= applyMixingFrom(currentP, skeleton, blend); + } else if (current._trackTime >= current._trackEnd && current._next == NULL) { + alpha = 0;// Set to setup pose the last time the entry will be applied. + } + bool attachments = alpha >= current._alphaAttachmentThreshold; + + + // apply current entry. + float animationLast = current._animationLast, animationTime = current.getAnimationTime(); + float applyTime = animationTime; + Vector *applyEvents = &_events; + if (current._reverse) { + applyTime = current._animation->getDuration() - applyTime; + applyEvents = NULL; + } + size_t timelineCount = current._animation->_timelines.size(); + Vector &timelines = current._animation->_timelines; + if ((i == 0 && alpha == 1) || blend == MixBlend_Add) { + if (i == 0) attachments = true; + for (size_t ii = 0; ii < timelineCount; ++ii) { + Timeline *timeline = timelines[ii]; + if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti)) + applyAttachmentTimeline(static_cast(timeline), skeleton, applyTime, blend, + attachments); + else + timeline->apply(skeleton, animationLast, applyTime, applyEvents, alpha, blend, MixDirection_In); + } + } else { + Vector &timelineMode = current._timelineMode; + + bool shortestRotation = current._shortestRotation; + bool firstFrame = !shortestRotation && current._timelinesRotation.size() != timelines.size() << 1; + if (firstFrame) current._timelinesRotation.setSize(timelines.size() << 1, 0); + Vector &timelinesRotation = current._timelinesRotation; + + for (size_t ii = 0; ii < timelineCount; ++ii) { + Timeline *timeline = timelines[ii]; + assert(timeline); + + MixBlend timelineBlend = timelineMode[ii] == Subsequent ? blend : MixBlend_Setup; + + if (!shortestRotation && timeline->getRTTI().isExactly(RotateTimeline::rtti)) + applyRotateTimeline(static_cast(timeline), skeleton, applyTime, alpha, + timelineBlend, timelinesRotation, ii << 1, firstFrame); + else if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti)) + applyAttachmentTimeline(static_cast(timeline), skeleton, applyTime, + blend, attachments); + else + timeline->apply(skeleton, animationLast, applyTime, applyEvents, alpha, timelineBlend, + MixDirection_In); + } + } + + queueEvents(currentP, animationTime); + _events.clear(); + current._nextAnimationLast = animationTime; + current._nextTrackLast = current._trackTime; + } + + int setupState = _unkeyedState + Setup; + Vector &slots = skeleton.getSlots(); + for (int i = 0, n = (int) slots.size(); i < n; i++) { + Slot *slot = slots[i]; + if (slot->getAttachmentState() == setupState) { + const String &attachmentName = slot->getData().getAttachmentName(); + slot->setAttachment(attachmentName.isEmpty() ? NULL : skeleton.getAttachment(slot->getData().getIndex(), attachmentName)); + } + } + _unkeyedState += 2; + + _queue->drain(); + return applied; +} + +void AnimationState::clearTracks() { + bool oldDrainDisabled = _queue->_drainDisabled; + _queue->_drainDisabled = true; + for (size_t i = 0, n = _tracks.size(); i < n; ++i) + clearTrack(i); + _tracks.clear(); + _queue->_drainDisabled = oldDrainDisabled; + _queue->drain(); +} + +void AnimationState::clearTrack(size_t trackIndex) { + if (trackIndex >= _tracks.size()) return; + + TrackEntry *current = _tracks[trackIndex]; + if (current == NULL) return; + + _queue->end(current); + + clearNext(current); + + TrackEntry *entry = current; + while (true) { + TrackEntry *from = entry->_mixingFrom; + if (from == NULL) break; + + _queue->end(from); + entry->_mixingFrom = NULL; + entry->_mixingTo = NULL; + entry = from; + } + + _tracks[current->_trackIndex] = NULL; + + _queue->drain(); +} + +TrackEntry *AnimationState::setAnimation(size_t trackIndex, const String &animationName, bool loop) { + Animation *animation = _data->_skeletonData->findAnimation(animationName); + assert(animation != NULL); + return setAnimation(trackIndex, animation, loop); +} + +TrackEntry *AnimationState::setAnimation(size_t trackIndex, Animation *animation, bool loop) { + assert(animation != NULL); + + bool interrupt = true; + TrackEntry *current = expandToIndex(trackIndex); + if (current != NULL) { + if (current->_nextTrackLast == -1) { + // Don't mix from an entry that was never applied. + _tracks[trackIndex] = current->_mixingFrom; + _queue->interrupt(current); + _queue->end(current); + clearNext(current); + current = current->_mixingFrom; + interrupt = false; + } else { + clearNext(current); + } + } + + TrackEntry *entry = newTrackEntry(trackIndex, animation, loop, current); + setCurrent(trackIndex, entry, interrupt); + _queue->drain(); + + return entry; +} + +TrackEntry *AnimationState::addAnimation(size_t trackIndex, const String &animationName, bool loop, float delay) { + Animation *animation = _data->_skeletonData->findAnimation(animationName); + assert(animation != NULL); + return addAnimation(trackIndex, animation, loop, delay); +} + +TrackEntry *AnimationState::addAnimation(size_t trackIndex, Animation *animation, bool loop, float delay) { + assert(animation != NULL); + + TrackEntry *last = expandToIndex(trackIndex); + if (last != NULL) { + while (last->_next != NULL) + last = last->_next; + } + + TrackEntry *entry = newTrackEntry(trackIndex, animation, loop, last); + + if (last == NULL) { + setCurrent(trackIndex, entry, true); + _queue->drain(); + } else { + last->_next = entry; + entry->_previous = last; + if (delay <= 0) delay += last->getTrackComplete() - entry->_mixDuration; + } + + entry->_delay = delay; + return entry; +} + +TrackEntry *AnimationState::setEmptyAnimation(size_t trackIndex, float mixDuration) { + TrackEntry *entry = setAnimation(trackIndex, AnimationState::getEmptyAnimation(), false); + entry->_mixDuration = mixDuration; + entry->_trackEnd = mixDuration; + return entry; +} + +TrackEntry *AnimationState::addEmptyAnimation(size_t trackIndex, float mixDuration, float delay) { + TrackEntry *entry = addAnimation(trackIndex, AnimationState::getEmptyAnimation(), false, delay); + if (delay <= 0) entry->_delay += entry->_mixDuration - mixDuration; + entry->_mixDuration = mixDuration; + entry->_trackEnd = mixDuration; + return entry; +} + +void AnimationState::setEmptyAnimations(float mixDuration) { + bool oldDrainDisabled = _queue->_drainDisabled; + _queue->_drainDisabled = true; + for (size_t i = 0, n = _tracks.size(); i < n; ++i) { + TrackEntry *current = _tracks[i]; + if (current != NULL) { + setEmptyAnimation(i, mixDuration); + } + } + _queue->_drainDisabled = oldDrainDisabled; + _queue->drain(); +} + +TrackEntry *AnimationState::getCurrent(size_t trackIndex) { + return trackIndex >= _tracks.size() ? NULL : _tracks[trackIndex]; +} + +AnimationStateData *AnimationState::getData() { + return _data; +} + +Vector &AnimationState::getTracks() { + return _tracks; +} + +float AnimationState::getTimeScale() { + return _timeScale; +} + +void AnimationState::setTimeScale(float inValue) { + _timeScale = inValue; +} + +void AnimationState::setListener(AnimationStateListener inValue) { + _listener = inValue; + _listenerObject = NULL; +} + +void AnimationState::setListener(AnimationStateListenerObject *inValue) { + _listener = dummyOnAnimationEventFunc; + _listenerObject = inValue; +} + +void AnimationState::disableQueue() { + _queue->_drainDisabled = true; +} + +void AnimationState::enableQueue() { + _queue->_drainDisabled = false; +} + +void AnimationState::setManualTrackEntryDisposal(bool inValue) { + _manualTrackEntryDisposal = inValue; +} + +bool AnimationState::getManualTrackEntryDisposal() { + return _manualTrackEntryDisposal; +} + +void AnimationState::disposeTrackEntry(TrackEntry *entry) { + entry->reset(); + _trackEntryPool.free(entry); +} + +Animation *AnimationState::getEmptyAnimation() { + static Vector timelines; + static Animation ret(String(""), timelines, 0); + return &ret; +} + +void AnimationState::applyAttachmentTimeline(AttachmentTimeline *attachmentTimeline, Skeleton &skeleton, float time, + MixBlend blend, bool attachments) { + Slot *slot = skeleton.getSlots()[attachmentTimeline->getSlotIndex()]; + if (!slot->getBone().isActive()) return; + + Vector &frames = attachmentTimeline->getFrames(); + if (time < frames[0]) { + if (blend == MixBlend_Setup || blend == MixBlend_First) + setAttachment(skeleton, *slot, slot->getData().getAttachmentName(), attachments); + } else { + setAttachment(skeleton, *slot, attachmentTimeline->getAttachmentNames()[Animation::search(frames, time)], + attachments); + } + + /* If an attachment wasn't set (ie before the first frame or attachments is false), set the setup attachment later.*/ + if (slot->getAttachmentState() <= _unkeyedState) slot->setAttachmentState(_unkeyedState + Setup); +} + + +void AnimationState::applyRotateTimeline(RotateTimeline *rotateTimeline, Skeleton &skeleton, float time, float alpha, + MixBlend blend, Vector &timelinesRotation, size_t i, bool firstFrame) { + if (firstFrame) timelinesRotation[i] = 0; + + if (alpha == 1) { + rotateTimeline->apply(skeleton, 0, time, NULL, 1, blend, MixDirection_In); + return; + } + + Bone *bone = skeleton._bones[rotateTimeline->_boneIndex]; + if (!bone->isActive()) return; + Vector &frames = rotateTimeline->_frames; + float r1, r2; + if (time < frames[0]) { + switch (blend) { + case MixBlend_Setup: + bone->_rotation = bone->_data._rotation; + default: + return; + case MixBlend_First: + r1 = bone->_rotation; + r2 = bone->_data._rotation; + } + } else { + r1 = blend == MixBlend_Setup ? bone->_data._rotation : bone->_rotation; + r2 = bone->_data._rotation + rotateTimeline->getCurveValue(time); + } + + // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. + float total, diff = r2 - r1; + diff -= MathUtil::ceil(diff / 360 - 0.5) * 360; + if (diff == 0) { + total = timelinesRotation[i]; + } else { + float lastTotal, lastDiff; + if (firstFrame) { + lastTotal = 0; + lastDiff = diff; + } else { + lastTotal = timelinesRotation[i]; + lastDiff = timelinesRotation[i + 1]; + } + float loops = lastTotal - MathUtil::fmod(lastTotal, 360.f); + total = diff + loops; + bool current = diff >= 0, dir = lastTotal >= 0; + if (MathUtil::abs(lastDiff) <= 90 && MathUtil::sign(lastDiff) != MathUtil::sign(diff)) { + if (MathUtil::abs(lastTotal - loops) > 180) { + total += 360.f * MathUtil::sign(lastTotal); + dir = current; + } else if (loops != 0) + total -= 360.f * MathUtil::sign(lastTotal); + else + dir = current; + } + if (dir != current) { + total += 360 * MathUtil::sign(lastTotal); + } + timelinesRotation[i] = total; + } + timelinesRotation[i + 1] = diff; + bone->_rotation = r1 + total * alpha; +} + +bool AnimationState::updateMixingFrom(TrackEntry *to, float delta) { + TrackEntry *from = to->_mixingFrom; + if (from == NULL) { + return true; + } + + bool finished = updateMixingFrom(from, delta); + + from->_animationLast = from->_nextAnimationLast; + from->_trackLast = from->_nextTrackLast; + + if (to->_nextTrackLast != -1) { // The from entry was applied at least once. + bool discard = to->_mixTime == 0 && from->_mixTime == 0;// Discard the from entry when neither have advanced yet. + if (to->_mixTime >= to->_mixDuration || discard) { + // Require totalAlpha == 0 to ensure mixing is complete or the transition is a single frame or discarded. + if (from->_totalAlpha == 0 || to->_mixDuration == 0 || discard) { + to->_mixingFrom = from->_mixingFrom; + if (from->_mixingFrom) from->_mixingFrom->_mixingTo = to; + to->_interruptAlpha = from->_interruptAlpha; + _queue->end(from); + } + return finished; + } + } + + from->_trackTime += delta * from->_timeScale; + to->_mixTime += delta; + + return false; +} + +float AnimationState::applyMixingFrom(TrackEntry *to, Skeleton &skeleton, MixBlend blend) { + TrackEntry *from = to->_mixingFrom; + if (from->_mixingFrom != NULL) applyMixingFrom(from, skeleton, blend); + + float mix; + if (to->_mixDuration == 0) { + // Single frame mix to undo mixingFrom changes. + mix = 1; + if (blend == MixBlend_First) blend = MixBlend_Setup; + } else { + mix = to->_mixTime / to->_mixDuration; + if (mix > 1) { + mix = 1; + } + if (blend != MixBlend_First) blend = from->_mixBlend; + } + + bool attachments = mix < from->_mixAttachmentThreshold, drawOrder = mix < from->_mixDrawOrderThreshold; + Vector &timelines = from->_animation->_timelines; + size_t timelineCount = timelines.size(); + float alphaHold = from->_alpha * to->_interruptAlpha, alphaMix = alphaHold * (1 - mix); + float animationLast = from->_animationLast, animationTime = from->getAnimationTime(); + float applyTime = animationTime; + Vector *events = NULL; + if (from->_reverse) { + applyTime = from->_animation->_duration - applyTime; + } else { + if (mix < from->_eventThreshold) events = &_events; + } + + if (blend == MixBlend_Add) { + for (size_t i = 0; i < timelineCount; i++) + timelines[i]->apply(skeleton, animationLast, applyTime, events, alphaMix, blend, MixDirection_Out); + } else { + Vector &timelineMode = from->_timelineMode; + Vector &timelineHoldMix = from->_timelineHoldMix; + + bool shortestRotation = from->_shortestRotation; + bool firstFrame = !shortestRotation && from->_timelinesRotation.size() != timelines.size() << 1; + if (firstFrame) from->_timelinesRotation.setSize(timelines.size() << 1, 0); + + Vector &timelinesRotation = from->_timelinesRotation; + + from->_totalAlpha = 0; + for (size_t i = 0; i < timelineCount; i++) { + Timeline *timeline = timelines[i]; + MixDirection direction = MixDirection_Out; + MixBlend timelineBlend; + float alpha; + switch (timelineMode[i]) { + case Subsequent: + if (!drawOrder && (timeline->getRTTI().isExactly(DrawOrderTimeline::rtti))) continue; + timelineBlend = blend; + alpha = alphaMix; + break; + case First: + timelineBlend = MixBlend_Setup; + alpha = alphaMix; + break; + case HoldSubsequent: + timelineBlend = blend; + alpha = alphaHold; + break; + case HoldFirst: + timelineBlend = MixBlend_Setup; + alpha = alphaHold; + break; + default: + timelineBlend = MixBlend_Setup; + TrackEntry *holdMix = timelineHoldMix[i]; + alpha = alphaHold * MathUtil::max(0.0f, 1.0f - holdMix->_mixTime / holdMix->_mixDuration); + break; + } + from->_totalAlpha += alpha; + if (!shortestRotation && (timeline->getRTTI().isExactly(RotateTimeline::rtti))) { + applyRotateTimeline((RotateTimeline *) timeline, skeleton, applyTime, alpha, timelineBlend, + timelinesRotation, i << 1, firstFrame); + } else if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti)) { + applyAttachmentTimeline(static_cast(timeline), skeleton, applyTime, timelineBlend, + attachments && alpha >= from->_alphaAttachmentThreshold); + } else { + if (drawOrder && timeline->getRTTI().isExactly(DrawOrderTimeline::rtti) && + timelineBlend == MixBlend_Setup) + direction = MixDirection_In; + timeline->apply(skeleton, animationLast, applyTime, events, alpha, timelineBlend, direction); + } + } + } + + if (to->_mixDuration > 0) { + queueEvents(from, animationTime); + } + + _events.clear(); + from->_nextAnimationLast = animationTime; + from->_nextTrackLast = from->_trackTime; + + return mix; +} + +void AnimationState::setAttachment(Skeleton &skeleton, Slot &slot, const String &attachmentName, bool attachments) { + slot.setAttachment( + attachmentName.isEmpty() ? NULL : skeleton.getAttachment(slot.getData().getIndex(), attachmentName)); + if (attachments) slot.setAttachmentState(_unkeyedState + Current); +} + +void AnimationState::queueEvents(TrackEntry *entry, float animationTime) { + float animationStart = entry->_animationStart, animationEnd = entry->_animationEnd; + float duration = animationEnd - animationStart; + float trackLastWrapped = duration != 0 ? MathUtil::fmod(entry->_trackLast, duration) : MathUtil::quietNan(); + + // Queue events before complete. + size_t i = 0, n = _events.size(); + for (; i < n; ++i) { + Event *e = _events[i]; + if (e->_time < trackLastWrapped) break; + if (e->_time > animationEnd) continue;// Discard events outside animation start/end. + _queue->event(entry, e); + } + + // Queue complete if completed a loop iteration or the animation. + bool complete = false; + if (entry->_loop) { + if (duration == 0) + complete = true; + else { + int cycles = (int) (entry->_trackTime / duration); + complete = cycles > 0 && cycles > (int) (entry->_trackLast / duration); + } + } else { + complete = animationTime >= animationEnd && entry->_animationLast < animationEnd; + } + if (complete) _queue->complete(entry); + + // Queue events after complete. + for (; i < n; ++i) { + Event *e = _events[i]; + if (e->_time < animationStart) continue;// Discard events outside animation start/end. + _queue->event(entry, e); + } +} + +void AnimationState::setCurrent(size_t index, TrackEntry *current, bool interrupt) { + TrackEntry *from = expandToIndex(index); + _tracks[index] = current; + current->_previous = NULL; + + if (from != NULL) { + if (interrupt) _queue->interrupt(from); + + current->_mixingFrom = from; + from->_mixingTo = current; + current->_mixTime = 0; + + // Store interrupted mix percentage. + if (from->_mixingFrom != NULL && from->_mixDuration > 0) { + current->_interruptAlpha *= MathUtil::min(1.0f, from->_mixTime / from->_mixDuration); + } + + from->_timelinesRotation.clear();// Reset rotation for mixing out, in case entry was mixed in. + } + + _queue->start(current);// triggers animationsChanged +} + +TrackEntry *AnimationState::expandToIndex(size_t index) { + if (index < _tracks.size()) return _tracks[index]; + while (index >= _tracks.size()) + _tracks.add(NULL); + return NULL; +} + +TrackEntry *AnimationState::newTrackEntry(size_t trackIndex, Animation *animation, bool loop, TrackEntry *last) { + TrackEntry *entryP = _trackEntryPool.obtain();// Pooling + TrackEntry &entry = *entryP; + + entry._trackIndex = (int) trackIndex; + entry._animation = animation; + entry._loop = loop; + entry._holdPrevious = 0; + + entry._reverse = false; + entry._shortestRotation = false; + + entry._eventThreshold = 0; + entry._alphaAttachmentThreshold = 0; + entry._mixAttachmentThreshold = 0; + entry._mixDrawOrderThreshold = 0; + + entry._animationStart = 0; + entry._animationEnd = animation->getDuration(); + entry._animationLast = -1; + entry._nextAnimationLast = -1; + + entry._delay = 0; + entry._trackTime = 0; + entry._trackLast = -1; + entry._nextTrackLast = -1;// nextTrackLast == -1 signifies a TrackEntry that wasn't applied yet. + entry._trackEnd = FLT_MAX;// loop ? float.MaxValue : animation.Duration; + entry._timeScale = 1; + + entry._alpha = 1; + entry._mixTime = 0; + entry._mixDuration = (last == NULL) ? 0 : _data->getMix(last->_animation, animation); + entry._interruptAlpha = 1; + entry._totalAlpha = 0; + entry._mixBlend = MixBlend_Replace; + + return entryP; +} + +void AnimationState::clearNext(TrackEntry *entry) { + TrackEntry *next = entry->_next; + while (next != NULL) { + _queue->dispose(next); + next = next->_next; + } + entry->_next = NULL; +} + +void AnimationState::animationsChanged() { + _animationsChanged = false; + + _propertyIDs.clear(); + + for (size_t i = 0, n = _tracks.size(); i < n; ++i) { + TrackEntry *entry = _tracks[i]; + if (!entry) continue; + + while (entry->_mixingFrom != NULL) + entry = entry->_mixingFrom; + + do { + if (entry->_mixingTo == NULL || entry->_mixBlend != MixBlend_Add) computeHold(entry); + entry = entry->_mixingTo; + } while (entry != NULL); + } +} + +void AnimationState::computeHold(TrackEntry *entry) { + TrackEntry *to = entry->_mixingTo; + Vector &timelines = entry->_animation->_timelines; + size_t timelinesCount = timelines.size(); + Vector &timelineMode = entry->_timelineMode; + timelineMode.setSize(timelinesCount, 0); + Vector &timelineHoldMix = entry->_timelineHoldMix; + timelineHoldMix.setSize(timelinesCount, 0); + + if (to != NULL && to->_holdPrevious) { + for (size_t i = 0; i < timelinesCount; i++) { + timelineMode[i] = _propertyIDs.addAll(timelines[i]->getPropertyIds(), true) ? HoldFirst : HoldSubsequent; + } + return; + } + + // outer: + size_t i = 0; +continue_outer: + for (; i < timelinesCount; ++i) { + Timeline *timeline = timelines[i]; + Vector &ids = timeline->getPropertyIds(); + if (!_propertyIDs.addAll(ids, true)) { + timelineMode[i] = Subsequent; + } else { + if (to == NULL || timeline->getRTTI().isExactly(AttachmentTimeline::rtti) || + timeline->getRTTI().isExactly(DrawOrderTimeline::rtti) || + timeline->getRTTI().isExactly(EventTimeline::rtti) || !to->_animation->hasTimeline(ids)) { + timelineMode[i] = First; + } else { + for (TrackEntry *next = to->_mixingTo; next != NULL; next = next->_mixingTo) { + if (next->_animation->hasTimeline(ids)) continue; + if (next->_mixDuration > 0) { + timelineMode[i] = HoldMix; + timelineHoldMix[i] = next; + i++; + goto continue_outer;// continue outer; + } + break; + } + timelineMode[i] = HoldFirst; + } + } + } +} diff --git a/native/cocos/editor-support/spine/4.2/spine/AnimationState.h b/native/cocos/editor-support/spine/4.2/spine/AnimationState.h new file mode 100644 index 0000000000..a35e2b660a --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AnimationState.h @@ -0,0 +1,522 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_AnimationState_h +#define Spine_AnimationState_h + +#include +#include +#include +#include +#include +#include +#include +#include "Slot.h" + +#ifdef SPINE_USE_STD_FUNCTION +#include +#endif + +namespace spine { + enum EventType { + EventType_Start = 0, + EventType_Interrupt, + EventType_End, + EventType_Complete, + EventType_Dispose, + EventType_Event + }; + + class AnimationState; + + class TrackEntry; + + class Animation; + + class Event; + + class AnimationStateData; + + class Skeleton; + + class RotateTimeline; + + class AttachmentTimeline; + +#ifdef SPINE_USE_STD_FUNCTION + typedef std::function AnimationStateListener; +#else + + typedef void (*AnimationStateListener)(AnimationState *state, EventType type, TrackEntry *entry, Event *event); + +#endif + + /// Abstract class to inherit from to create a callback object + class SP_API AnimationStateListenerObject { + public: + AnimationStateListenerObject() {}; + + virtual ~AnimationStateListenerObject() {}; + public: + /// The callback function to be called + virtual void callback(AnimationState *state, EventType type, TrackEntry *entry, Event *event) = 0; + }; + + /// State for the playback of an animation + class SP_API TrackEntry : public SpineObject, public HasRendererObject { + friend class EventQueue; + + friend class AnimationState; + + public: + TrackEntry(); + + virtual ~TrackEntry(); + + /// The index of the track where this entry is either current or queued. + int getTrackIndex(); + + /// The animation to apply for this track entry. + Animation *getAnimation(); + + TrackEntry *getPrevious(); + + /// If true, the animation will repeat. If false, it will not, instead its last frame is applied if played beyond its duration. + bool getLoop(); + + void setLoop(bool inValue); + + /// If true, when mixing from the previous animation to this animation, the previous animation is applied as normal instead + /// of being mixed out. + /// + /// When mixing between animations that key the same property, if a lower track also keys that property then the value will + /// briefly dip toward the lower track value during the mix. This happens because the first animation mixes from 100% to 0% + /// while the second animation mixes from 0% to 100%. Setting holdPrevious to true applies the first animation + /// at 100% during the mix so the lower track value is overwritten. Such dipping does not occur on the lowest track which + /// keys the property, only when a higher track also keys the property. + /// + /// Snapping will occur if holdPrevious is true and this animation does not key all the same properties as the + /// previous animation. + bool getHoldPrevious(); + + void setHoldPrevious(bool inValue); + + bool getReverse(); + + void setReverse(bool inValue); + + bool getShortestRotation(); + + void setShortestRotation(bool inValue); + + /// Seconds to postpone playing the animation. When a track entry is the current track entry, delay postpones incrementing + /// the track time. When a track entry is queued, delay is the time from the start of the previous animation to when the + /// track entry will become the current track entry. + float getDelay(); + + void setDelay(float inValue); + + /// Current time in seconds this track entry has been the current track entry. The track time determines + /// TrackEntry.AnimationTime. The track time can be set to start the animation at a time other than 0, without affecting looping. + float getTrackTime(); + + void setTrackTime(float inValue); + + /// The track time in seconds when this animation will be removed from the track. Defaults to the animation duration for + /// non-looping animations and to int.MaxValue for looping animations. If the track end time is reached and no + /// other animations are queued for playback, and mixing from any previous animations is complete, properties keyed by the animation, + /// are set to the setup pose and the track is cleared. + /// + /// It may be desired to use AnimationState.addEmptyAnimation(int, float, float) to mix the properties back to the + /// setup pose over time, rather than have it happen instantly. + float getTrackEnd(); + + void setTrackEnd(float inValue); + + /// Seconds when this animation starts, both initially and after looping. Defaults to 0. + /// + /// When changing the animation start time, it often makes sense to set TrackEntry.AnimationLast to the same value to + /// prevent timeline keys before the start time from triggering. + float getAnimationStart(); + + void setAnimationStart(float inValue); + + /// Seconds for the last frame of this animation. Non-looping animations won't play past this time. Looping animations will + /// loop back to TrackEntry.AnimationStart at this time. Defaults to the animation duration. + float getAnimationEnd(); + + void setAnimationEnd(float inValue); + + /// The time in seconds this animation was last applied. Some timelines use this for one-time triggers. Eg, when this + /// animation is applied, event timelines will fire all events between the animation last time (exclusive) and animation time + /// (inclusive). Defaults to -1 to ensure triggers on frame 0 happen the first time this animation is applied. + float getAnimationLast(); + + void setAnimationLast(float inValue); + + /// Uses TrackEntry.TrackTime to compute the animation time between TrackEntry.AnimationStart. and + /// TrackEntry.AnimationEnd. When the track time is 0, the animation time is equal to the animation start time. + float getAnimationTime(); + + /// Multiplier for the delta time when the animation state is updated, causing time for this animation to play slower or + /// faster. Defaults to 1. + float getTimeScale(); + + void setTimeScale(float inValue); + + /// Values less than 1 mix this animation with the last skeleton pose. Defaults to 1, which overwrites the last skeleton pose with + /// this animation. + /// + /// Typically track 0 is used to completely pose the skeleton, then alpha can be used on higher tracks. It doesn't make sense + /// to use alpha on track 0 if the skeleton pose is from the last frame render. + float getAlpha(); + + void setAlpha(float inValue); + + /// + /// When the mix percentage (mix time / mix duration) is less than the event threshold, event timelines for the animation + /// being mixed out will be applied. Defaults to 0, so event timelines are not applied for an animation being mixed out. + float getEventThreshold(); + + void setEventThreshold(float inValue); + + /// When the mix percentage (mix time / mix duration) is less than the attachment threshold, attachment timelines for the + /// animation being mixed out will be applied. Defaults to 0, so attachment timelines are not applied for an animation being + /// mixed out. + float getMixAttachmentThreshold(); + + void setMixAttachmentThreshold(float inValue); + + /// When getAlpha() is greater than alphaAttachmentThreshold, attachment timelines are applied. + /// Defaults to 0, so attachment timelines are always applied. */ + float getAlphaAttachmentThreshold(); + + void setAlphaAttachmentThreshold(float inValue); + + /// When the mix percentage (mix time / mix duration) is less than the draw order threshold, draw order timelines for the + /// animation being mixed out will be applied. Defaults to 0, so draw order timelines are not applied for an animation being + /// mixed out. + float getMixDrawOrderThreshold(); + + void setMixDrawOrderThreshold(float inValue); + + /// The animation queued to start after this animation, or NULL. + TrackEntry *getNext(); + + /// Returns true if at least one loop has been completed. + bool isComplete(); + + /// Seconds from 0 to the mix duration when mixing from the previous animation to this animation. May be slightly more than + /// TrackEntry.MixDuration when the mix is complete. + float getMixTime(); + + void setMixTime(float inValue); + + /// Seconds for mixing from the previous animation to this animation. Defaults to the value provided by + /// AnimationStateData based on the animation before this animation (if any). + /// + /// The mix duration can be set manually rather than use the value from AnimationStateData.GetMix. + /// In that case, the mixDuration must be set before AnimationState.update(float) is next called. + /// + /// When using AnimationState::addAnimation(int, Animation, bool, float) with a delay + /// less than or equal to 0, note the Delay is set using the mix duration from the AnimationStateData + float getMixDuration(); + + void setMixDuration(float inValue); + + void setMixDuration(float mixDuration, float delay); + + MixBlend getMixBlend(); + + void setMixBlend(MixBlend blend); + + /// The track entry for the previous animation when mixing from the previous animation to this animation, or NULL if no + /// mixing is currently occuring. When mixing from multiple animations, MixingFrom makes up a double linked list with MixingTo. + TrackEntry *getMixingFrom(); + + /// The track entry for the next animation when mixing from this animation, or NULL if no mixing is currently occuring. + /// When mixing from multiple animations, MixingTo makes up a double linked list with MixingFrom. + TrackEntry *getMixingTo(); + + /// Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the + /// long way around when using alpha and starting animations on other tracks. + /// + /// Mixing involves finding a rotation between two others, which has two possible solutions: the short way or the long way around. + /// The two rotations likely change over time, so which direction is the short or long way also changes. + /// If the short way was always chosen, bones would flip to the other side when that direction became the long way. + /// TrackEntry chooses the short way the first time it is applied and remembers that direction. + void resetRotationDirections(); + + float getTrackComplete(); + + void setListener(AnimationStateListener listener); + + void setListener(AnimationStateListenerObject *listener); + + /// Returns true if this track entry has been applied at least once. + /// + /// See AnimationState::apply(Skeleton). + bool wasApplied(); + + /// Returns true if there is a getNext() track entry that is ready to become the current track entry during the + /// next AnimationState::update(float)} + bool isNextReady () { + return _next != NULL && _nextTrackLast - _next->_delay >= 0; + } + #ifndef __EMSCRIPTEN__ + private: + #endif + Animation *_animation; + TrackEntry *_previous; + TrackEntry *_next; + TrackEntry *_mixingFrom; + TrackEntry *_mixingTo; + int _trackIndex; + + bool _loop, _holdPrevious, _reverse, _shortestRotation; + float _eventThreshold, _mixAttachmentThreshold, _alphaAttachmentThreshold, _mixDrawOrderThreshold; + float _animationStart, _animationEnd, _animationLast, _nextAnimationLast; + float _delay, _trackTime, _trackLast, _nextTrackLast, _trackEnd, _timeScale; + float _alpha, _mixTime, _mixDuration, _interruptAlpha, _totalAlpha; + MixBlend _mixBlend; + Vector _timelineMode; + Vector _timelineHoldMix; + Vector _timelinesRotation; + AnimationStateListener _listener; + AnimationStateListenerObject *_listenerObject; + + void reset(); + }; + + class SP_API EventQueueEntry : public SpineObject { + friend class EventQueue; + + public: + EventType _type; + TrackEntry *_entry; + Event *_event; + + EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Event *event = NULL); + }; + + class SP_API EventQueue : public SpineObject { + friend class AnimationState; + + private: + Vector _eventQueueEntries; + AnimationState &_state; + bool _drainDisabled; + + static EventQueue *newEventQueue(AnimationState &state); + + static EventQueueEntry newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event = NULL); + + EventQueue(AnimationState &state); + + ~EventQueue(); + + void start(TrackEntry *entry); + + void interrupt(TrackEntry *entry); + + void end(TrackEntry *entry); + + void dispose(TrackEntry *entry); + + void complete(TrackEntry *entry); + + void event(TrackEntry *entry, Event *event); + + /// Raises all events in the queue and drains the queue. + void drain(); + }; + + class SP_API AnimationState : public SpineObject, public HasRendererObject { + friend class TrackEntry; + + friend class EventQueue; + + public: + explicit AnimationState(AnimationStateData *data); + + ~AnimationState(); + + /// Increments the track entry times, setting queued animations as current if needed + /// @param delta delta time + void update(float delta); + + /// Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the + /// animation state can be applied to multiple skeletons to pose them identically. + bool apply(Skeleton &skeleton); + + /// Removes all animations from all tracks, leaving skeletons in their previous pose. + /// It may be desired to use AnimationState.setEmptyAnimations(float) to mix the skeletons back to the setup pose, + /// rather than leaving them in their previous pose. + void clearTracks(); + + /// Removes all animations from the tracks, leaving skeletons in their previous pose. + /// It may be desired to use AnimationState.setEmptyAnimations(float) to mix the skeletons back to the setup pose, + /// rather than leaving them in their previous pose. + void clearTrack(size_t trackIndex); + + /// Sets an animation by name. setAnimation(int, Animation, bool) + TrackEntry *setAnimation(size_t trackIndex, const String &animationName, bool loop); + + /// Sets the current animation for a track, discarding any queued animations. + /// @param loop If true, the animation will repeat. + /// If false, it will not, instead its last frame is applied if played beyond its duration. + /// In either case TrackEntry.TrackEnd determines when the track is cleared. + /// @return + /// A track entry to allow further customization of animation playback. References to the track entry must not be kept + /// after AnimationState.Dispose. + TrackEntry *setAnimation(size_t trackIndex, Animation *animation, bool loop); + + /// Queues an animation by name. + /// addAnimation(int, Animation, bool, float) + TrackEntry *addAnimation(size_t trackIndex, const String &animationName, bool loop, float delay); + + /// Adds an animation to be played delay seconds after the current or last queued animation + /// for a track. If the track is empty, it is equivalent to calling setAnimation. + /// @param delay + /// Seconds to begin this animation after the start of the previous animation. May be <= 0 to use the animation + /// duration of the previous track minus any mix duration plus the negative delay. + /// + /// @return A track entry to allow further customization of animation playback. References to the track entry must not be kept + /// after AnimationState.Dispose + TrackEntry *addAnimation(size_t trackIndex, Animation *animation, bool loop, float delay); + + /// Sets an empty animation for a track, discarding any queued animations, and mixes to it over the specified mix duration. + TrackEntry *setEmptyAnimation(size_t trackIndex, float mixDuration); + + /// Adds an empty animation to be played after the current or last queued animation for a track, and mixes to it over the + /// specified mix duration. + /// @return + /// A track entry to allow further customization of animation playback. References to the track entry must not be kept after AnimationState.Dispose. + /// + /// @param trackIndex Track number. + /// @param mixDuration Mix duration. + /// @param delay Seconds to begin this animation after the start of the previous animation. May be <= 0 to use the animation + /// duration of the previous track minus any mix duration plus the negative delay. + TrackEntry *addEmptyAnimation(size_t trackIndex, float mixDuration, float delay); + + /// Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix duration. + void setEmptyAnimations(float mixDuration); + + /// @return The track entry for the animation currently playing on the track, or NULL if no animation is currently playing. + TrackEntry *getCurrent(size_t trackIndex); + + AnimationStateData *getData(); + + /// A list of tracks that have animations, which may contain NULLs. + Vector &getTracks(); + + float getTimeScale(); + + void setTimeScale(float inValue); + + void setListener(AnimationStateListener listener); + + void setListener(AnimationStateListenerObject *listener); + + void disableQueue(); + + void enableQueue(); + + void setManualTrackEntryDisposal(bool inValue); + + bool getManualTrackEntryDisposal(); + + void disposeTrackEntry(TrackEntry *entry); + + private: + static const int Subsequent = 0; + static const int First = 1; + static const int HoldSubsequent = 2; + static const int HoldFirst = 3; + static const int HoldMix = 4; + + static const int Setup = 1; + static const int Current = 2; + + AnimationStateData *_data; + + Pool _trackEntryPool; + Vector _tracks; + Vector _events; + EventQueue *_queue; + + HashMap _propertyIDs; + bool _animationsChanged; + + AnimationStateListener _listener; + AnimationStateListenerObject *_listenerObject; + + int _unkeyedState; + + float _timeScale; + + bool _manualTrackEntryDisposal; + + static Animation *getEmptyAnimation(); + + static void + applyRotateTimeline(RotateTimeline *rotateTimeline, Skeleton &skeleton, float time, float alpha, MixBlend pose, + Vector &timelinesRotation, size_t i, bool firstFrame); + + void applyAttachmentTimeline(AttachmentTimeline *attachmentTimeline, Skeleton &skeleton, float animationTime, + MixBlend pose, bool firstFrame); + + /// Returns true when all mixing from entries are complete. + bool updateMixingFrom(TrackEntry *to, float delta); + + float applyMixingFrom(TrackEntry *to, Skeleton &skeleton, MixBlend currentPose); + + void queueEvents(TrackEntry *entry, float animationTime); + + /// Sets the active TrackEntry for a given track number. + void setCurrent(size_t index, TrackEntry *current, bool interrupt); + + /// Removes the next entry and all entries after it for the specified entry. */ + void clearNext(TrackEntry *entry); + + TrackEntry *expandToIndex(size_t index); + + /// Object-pooling version of new TrackEntry. Obtain an unused TrackEntry from the pool and clear/initialize its values. + /// @param last May be NULL. + TrackEntry *newTrackEntry(size_t trackIndex, Animation *animation, bool loop, TrackEntry *last); + + void animationsChanged(); + + void computeHold(TrackEntry *entry); + + void setAttachment(Skeleton &skeleton, spine::Slot &slot, const String &attachmentName, bool attachments); + }; +} + +#endif /* Spine_AnimationState_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/AnimationStateData.cpp b/native/cocos/editor-support/spine/4.2/spine/AnimationStateData.cpp new file mode 100644 index 0000000000..67dfbbee57 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AnimationStateData.cpp @@ -0,0 +1,86 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include +#include + +using namespace spine; + +AnimationStateData::AnimationStateData(SkeletonData *skeletonData) : _skeletonData(skeletonData), _defaultMix(0) { +} + +void AnimationStateData::setMix(const String &fromName, const String &toName, float duration) { + Animation *from = _skeletonData->findAnimation(fromName); + Animation *to = _skeletonData->findAnimation(toName); + + setMix(from, to, duration); +} + +void AnimationStateData::setMix(Animation *from, Animation *to, float duration) { + assert(from != NULL); + assert(to != NULL); + + AnimationPair key(from, to); + _animationToMixTime.put(key, duration); +} + +float AnimationStateData::getMix(Animation *from, Animation *to) { + assert(from != NULL); + assert(to != NULL); + + AnimationPair key(from, to); + + if (_animationToMixTime.containsKey(key)) return _animationToMixTime[key]; + return _defaultMix; +} + +SkeletonData *AnimationStateData::getSkeletonData() { + return _skeletonData; +} + +float AnimationStateData::getDefaultMix() { + return _defaultMix; +} + +void AnimationStateData::setDefaultMix(float inValue) { + _defaultMix = inValue; +} + +void AnimationStateData::clear() { + _defaultMix = 0; + _animationToMixTime.clear(); +} + +AnimationStateData::AnimationPair::AnimationPair(Animation *a1, Animation *a2) : _a1(a1), _a2(a2) { +} + +bool AnimationStateData::AnimationPair::operator==(const AnimationPair &other) const { + return _a1->_name == other._a1->_name && _a2->_name == other._a2->_name; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/AnimationStateData.h b/native/cocos/editor-support/spine/4.2/spine/AnimationStateData.h new file mode 100644 index 0000000000..93aa697536 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AnimationStateData.h @@ -0,0 +1,91 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_AnimationStateData_h +#define Spine_AnimationStateData_h + +#include +#include +#include + +#include + +namespace spine { + class SkeletonData; + + class Animation; + + /// Stores mix (crossfade) durations to be applied when AnimationState animations are changed. + class SP_API AnimationStateData : public SpineObject { + friend class AnimationState; + + public: + explicit AnimationStateData(SkeletonData *skeletonData); + + /// The SkeletonData to look up animations when they are specified by name. + SkeletonData *getSkeletonData(); + + /// The mix duration to use when no mix duration has been specifically defined between two animations. + float getDefaultMix(); + + void setDefaultMix(float inValue); + + /// Sets a mix duration by animation names. + void setMix(const String &fromName, const String &toName, float duration); + + /// Sets a mix duration when changing from the specified animation to the other. + /// See TrackEntry.MixDuration. + void setMix(Animation *from, Animation *to, float duration); + + /// 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); + + /// Removes all mixes and sets the default mix to 0. + void clear(); + #ifndef __EMSCRIPTEN__ + private: + #endif + class AnimationPair : public SpineObject { + public: + Animation *_a1; + Animation *_a2; + + explicit AnimationPair(Animation *a1 = NULL, Animation *a2 = NULL); + + bool operator==(const AnimationPair &other) const; + }; + + SkeletonData *_skeletonData; + float _defaultMix; + HashMap _animationToMixTime; + }; +} + +#endif /* Spine_AnimationStateData_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Atlas.cpp b/native/cocos/editor-support/spine/4.2/spine/Atlas.cpp new file mode 100644 index 0000000000..c2421cb656 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Atlas.cpp @@ -0,0 +1,350 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include +#include + +#include + +using namespace spine; + +Atlas::Atlas(const String &path, TextureLoader *textureLoader, bool createTexture) : _textureLoader(textureLoader) { + int dirLength; + char *dir; + int length; + const char *data; + + /* Get directory from atlas path. */ + const char *lastForwardSlash = strrchr(path.buffer(), '/'); + const char *lastBackwardSlash = strrchr(path.buffer(), '\\'); + 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__); + memcpy(dir, path.buffer(), dirLength); + dir[dirLength] = '\0'; + + data = SpineExtension::readFile(path, &length); + if (data) { + load(data, length, dir, createTexture); + } + + SpineExtension::free(data, __FILE__, __LINE__); + SpineExtension::free(dir, __FILE__, __LINE__); +} + +Atlas::Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader, bool createTexture) + : _textureLoader( + textureLoader) { + load(data, length, dir, createTexture); +} + +Atlas::~Atlas() { + if (_textureLoader) { + for (size_t i = 0, n = _pages.size(); i < n; ++i) { + _textureLoader->unload(_pages[i]->texture); + } + } + ContainerUtil::cleanUpVectorOfPointers(_pages); + ContainerUtil::cleanUpVectorOfPointers(_regions); +} + +void Atlas::flipV() { + for (size_t i = 0, n = _regions.size(); i < n; ++i) { + AtlasRegion *regionP = _regions[i]; + AtlasRegion ®ion = *regionP; + region.v = 1 - region.v; + region.v2 = 1 - region.v2; + } +} + +AtlasRegion *Atlas::findRegion(const String &name) { + for (size_t i = 0, n = _regions.size(); i < n; ++i) + if (_regions[i]->name == name) return _regions[i]; + return NULL; +} + +Vector &Atlas::getPages() { + return _pages; +} + +Vector &Atlas::getRegions() { + return _regions; +} + +struct SimpleString { + char *start; + char *end; + int length; + + SimpleString trim() { + while (isspace((unsigned char) *start) && start < end) + start++; + if (start == end) { + length = (int) (end - start); + return *this; + } + end--; + while (((unsigned char) *end == '\r') && end >= start) + end--; + end++; + length = (int) (end - start); + return *this; + } + + int indexOf(char needle) { + char *c = start; + while (c < end) { + if (*c == needle) return (int) (c - start); + c++; + } + return -1; + } + + int indexOf(char needle, int at) { + char *c = start + at; + while (c < end) { + if (*c == needle) return (int) (c - start); + c++; + } + return -1; + } + + SimpleString substr(int s, int e) { + e = s + e; + SimpleString result; + result.start = start + s; + result.end = start + e; + result.length = e - s; + return result; + } + + SimpleString substr(int s) { + SimpleString result; + result.start = start + s; + result.end = end; + result.length = (int) (result.end - result.start); + return result; + } + + bool equals(const char *str) { + int otherLen = (int) strlen(str); + if (length != otherLen) return false; + for (int i = 0; i < length; i++) { + if (start[i] != str[i]) return false; + } + return true; + } + + char *copy() { + char *string = SpineExtension::calloc(length + 1, __FILE__, __LINE__); + memcpy(string, start, length); + string[length] = '\0'; + return string; + } + + int toInt() { + return (int) strtol(start, &end, 10); + } +}; + +struct AtlasInput { + const char *start; + const char *end; + char *index; + int length; + SimpleString line; + + AtlasInput(const char *data, int length) : start(data), end(data + length), index((char *) data), length(length) {} + + SimpleString *readLine() { + if (index >= end) return 0; + line.start = index; + while (index < end && *index != '\n') + index++; + line.end = index; + if (index != end) index++; + line = line.trim(); + line.length = (int) (end - start); + return &line; + } + + static int readEntry(SimpleString entry[5], SimpleString *line) { + if (line == NULL) return 0; + line->trim(); + if (line->length == 0) return 0; + + int colon = line->indexOf(':'); + if (colon == -1) return 0; + entry[0] = line->substr(0, colon).trim(); + for (int i = 1, lastMatch = colon + 1;; i++) { + int comma = line->indexOf(',', lastMatch); + if (comma == -1) { + entry[i] = line->substr(lastMatch).trim(); + return i; + } + entry[i] = line->substr(lastMatch, comma - lastMatch).trim(); + lastMatch = comma + 1; + if (i == 4) return 4; + } + } +}; + +int indexOf(const char **array, int count, SimpleString *str) { + for (int i = 0; i < count; i++) + if (str->equals(array[i])) return i; + return 0; +} + +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", + "MipMapNearestLinear", "MipMapLinearLinear"}; + + int dirLength = (int) strlen(dir); + int needsSlash = dirLength > 0 && dir[dirLength - 1] != '/' && dir[dirLength - 1] != '\\'; + AtlasInput reader(begin, length); + SimpleString entry[5]; + AtlasPage *page = NULL; + + SimpleString *line = reader.readLine(); + while (line != NULL && line->length == 0) + line = reader.readLine(); + + while (true) { + if (line == NULL || line->length == 0) break; + if (reader.readEntry(entry, line) == 0) break; + line = reader.readLine(); + } + + while (true) { + if (line == NULL) break; + if (line->trim().length == 0) { + page = NULL; + line = reader.readLine(); + } else if (page == NULL) { + char *name = line->copy(); + char *path = SpineExtension::calloc(dirLength + needsSlash + strlen(name) + 1, __FILE__, __LINE__); + memcpy(path, dir, dirLength); + if (needsSlash) path[dirLength] = '/'; + strcpy(path + dirLength + needsSlash, name); + page = new (__FILE__, __LINE__) AtlasPage(String(name, true)); + + while (true) { + line = reader.readLine(); + if (reader.readEntry(entry, line) == 0) break; + if (entry[0].equals("size")) { + page->width = entry[1].toInt(); + page->height = entry[2].toInt(); + } else if (entry[0].equals("format")) { + page->format = (Format) indexOf(formatNames, 8, &entry[1]); + } else if (entry[0].equals("filter")) { + page->minFilter = (TEXTURE_FILTER_ENUM) indexOf(textureFilterNames, 8, &entry[1]); + page->magFilter = (TEXTURE_FILTER_ENUM) indexOf(textureFilterNames, 8, &entry[2]); + } else if (entry[0].equals("repeat")) { + page->uWrap = TextureWrap_ClampToEdge; + page->vWrap = TextureWrap_ClampToEdge; + if (entry[1].indexOf('x') != -1) page->uWrap = TextureWrap_Repeat; + if (entry[1].indexOf('y') != -1) page->vWrap = TextureWrap_Repeat; + } else if (entry[0].equals("pma")) { + page->pma = entry[1].equals("true"); + } + } + + page->index = (int) _pages.size(); + if (createTexture && _textureLoader) _textureLoader->load(*page, String(path)); + page->texturePath = String(path, true); + _pages.add(page); + } else { + AtlasRegion *region = new (__FILE__, __LINE__) AtlasRegion(); + region->page = page; + region->rendererObject = page->texture; + region->name = String(line->copy(), true); + while (true) { + line = reader.readLine(); + int count = reader.readEntry(entry, line); + if (count == 0) break; + if (entry[0].equals("xy")) { + region->x = entry[1].toInt(); + region->y = entry[2].toInt(); + } else if (entry[0].equals("size")) { + region->width = entry[1].toInt(); + region->height = entry[2].toInt(); + } else if (entry[0].equals("bounds")) { + region->x = entry[1].toInt(); + region->y = entry[2].toInt(); + region->width = entry[3].toInt(); + region->height = entry[4].toInt(); + } else if (entry[0].equals("offset")) { + region->offsetX = entry[1].toInt(); + region->offsetY = entry[2].toInt(); + } else if (entry[0].equals("orig")) { + region->originalWidth = entry[1].toInt(); + region->originalHeight = entry[2].toInt(); + } else if (entry[0].equals("offsets")) { + region->offsetX = entry[1].toInt(); + region->offsetY = entry[2].toInt(); + region->originalWidth = entry[3].toInt(); + region->originalHeight = entry[4].toInt(); + } else if (entry[0].equals("rotate")) { + if (entry[1].equals("true")) { + region->degrees = 90; + } else if (!entry[1].equals("false")) { + region->degrees = entry[1].toInt(); + } + } else if (entry[0].equals("index")) { + region->index = entry[1].toInt(); + } else { + region->names.add(String(entry[0].copy())); + for (int i = 0; i < count; i++) { + region->values.add(entry[i + 1].toInt()); + } + } + } + if (region->originalWidth == 0 && region->originalHeight == 0) { + region->originalWidth = region->width; + region->originalHeight = region->height; + } + + region->u = (float) region->x / page->width; + region->v = (float) region->y / page->height; + if (region->degrees == 90) { + region->u2 = (float) (region->x + region->height) / page->width; + region->v2 = (float) (region->y + region->width) / page->height; + } else { + region->u2 = (float) (region->x + region->width) / page->width; + region->v2 = (float) (region->y + region->height) / page->height; + } + _regions.add(region); + } + } +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Atlas.h b/native/cocos/editor-support/spine/4.2/spine/Atlas.h new file mode 100644 index 0000000000..bccaa270fe --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Atlas.h @@ -0,0 +1,139 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Atlas_h +#define Spine_Atlas_h + +#include +#include +#include +#include +#include +#include "TextureRegion.h" + +namespace spine { + enum Format { + Format_Alpha, + Format_Intensity, + Format_LuminanceAlpha, + Format_RGB565, + Format_RGBA4444, + Format_RGB888, + Format_RGBA8888 + }; + + // Our TextureFilter collides with UE4's TextureFilter in unity builds. We rename + // TextureFilter to SpineTextureFilter in UE4. +#ifdef SPINE_UE4 + #define TEXTURE_FILTER_ENUM SpineTextureFilter +#else + #define TEXTURE_FILTER_ENUM TextureFilter +#endif + + enum TEXTURE_FILTER_ENUM { + TextureFilter_Unknown, + TextureFilter_Nearest, + TextureFilter_Linear, + TextureFilter_MipMap, + TextureFilter_MipMapNearestNearest, + TextureFilter_MipMapLinearNearest, + TextureFilter_MipMapNearestLinear, + TextureFilter_MipMapLinearLinear + }; + + enum TextureWrap { + TextureWrap_MirroredRepeat, + TextureWrap_ClampToEdge, + TextureWrap_Repeat + }; + + class SP_API AtlasPage : public SpineObject { + public: + String name; + String texturePath; + Format format; + TEXTURE_FILTER_ENUM minFilter; + TEXTURE_FILTER_ENUM magFilter; + TextureWrap uWrap; + TextureWrap vWrap; + int width, height; + bool pma; + int index; + void *texture; + + explicit AtlasPage(const String &inName) : name(inName), format(Format_RGBA8888), + minFilter(TextureFilter_Nearest), + magFilter(TextureFilter_Nearest), uWrap(TextureWrap_ClampToEdge), + vWrap(TextureWrap_ClampToEdge), width(0), height(0), pma(false), index(0), texture(NULL) { + } + }; + + class SP_API AtlasRegion : public TextureRegion { + public: + AtlasPage *page; + String name; + int index; + int x, y; + Vector splits; + Vector pads; + Vector names; + Vector values; + }; + + class TextureLoader; + + class SP_API Atlas : public SpineObject { + public: + Atlas(const String &path, TextureLoader *textureLoader, bool createTexture = true); + + Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader, bool createTexture = true); + + ~Atlas(); + + void flipV(); + + /// Returns the first region found with the specified name. This method uses String comparison to find the region, so the result + /// should be cached rather than calling this method multiple times. + /// @return The region, or NULL. + AtlasRegion *findRegion(const String &name); + + Vector &getPages(); + + Vector &getRegions(); + + private: + Vector _pages; + Vector _regions; + TextureLoader *_textureLoader; + + void load(const char *begin, int length, const char *dir, bool createTexture); + }; +} + +#endif /* Spine_Atlas_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/AtlasAttachmentLoader.cpp b/native/cocos/editor-support/spine/4.2/spine/AtlasAttachmentLoader.cpp new file mode 100644 index 0000000000..1de76a7bc0 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AtlasAttachmentLoader.cpp @@ -0,0 +1,112 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace spine { + RTTI_IMPL(AtlasAttachmentLoader, AttachmentLoader) + + AtlasAttachmentLoader::AtlasAttachmentLoader(Atlas *atlas) : AttachmentLoader(), _atlas(atlas) { + } + + bool loadSequence(Atlas *atlas, const String &basePath, Sequence *sequence) { + Vector ®ions = sequence->getRegions(); + for (int i = 0, n = (int) regions.size(); i < n; i++) { + String path = sequence->getPath(basePath, i); + regions[i] = atlas->findRegion(path); + if (!regions[i]) return false; + } + return true; + } + + RegionAttachment *AtlasAttachmentLoader::newRegionAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence) { + SP_UNUSED(skin); + RegionAttachment *attachment = new (__FILE__, __LINE__) RegionAttachment(name); + if (sequence) { + if (!loadSequence(_atlas, path, sequence)) return NULL; + } else { + AtlasRegion *region = findRegion(path); + if (!region) return NULL; + attachment->setRegion(region); + } + return attachment; + } + + MeshAttachment *AtlasAttachmentLoader::newMeshAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence) { + SP_UNUSED(skin); + MeshAttachment *attachment = new (__FILE__, __LINE__) MeshAttachment(name); + + if (sequence) { + if (!loadSequence(_atlas, path, sequence)) return NULL; + } else { + AtlasRegion *region = findRegion(path); + if (!region) return NULL; + attachment->setRegion(region); + } + return attachment; + } + + BoundingBoxAttachment *AtlasAttachmentLoader::newBoundingBoxAttachment(Skin &skin, const String &name) { + SP_UNUSED(skin); + return new (__FILE__, __LINE__) BoundingBoxAttachment(name); + } + + PathAttachment *AtlasAttachmentLoader::newPathAttachment(Skin &skin, const String &name) { + SP_UNUSED(skin); + return new (__FILE__, __LINE__) PathAttachment(name); + } + + PointAttachment *AtlasAttachmentLoader::newPointAttachment(Skin &skin, const String &name) { + SP_UNUSED(skin); + return new (__FILE__, __LINE__) PointAttachment(name); + } + + ClippingAttachment *AtlasAttachmentLoader::newClippingAttachment(Skin &skin, const String &name) { + SP_UNUSED(skin); + return new (__FILE__, __LINE__) ClippingAttachment(name); + } + + void AtlasAttachmentLoader::configureAttachment(Attachment *attachment) { + SP_UNUSED(attachment); + } + + AtlasRegion *AtlasAttachmentLoader::findRegion(const String &name) { + return _atlas->findRegion(name); + } + +}// namespace spine diff --git a/native/cocos/editor-support/spine/4.2/spine/AtlasAttachmentLoader.h b/native/cocos/editor-support/spine/4.2/spine/AtlasAttachmentLoader.h new file mode 100644 index 0000000000..674e025535 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AtlasAttachmentLoader.h @@ -0,0 +1,72 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_AtlasAttachmentLoader_h +#define Spine_AtlasAttachmentLoader_h + +#include +#include +#include + + +namespace spine { + class Atlas; + + class AtlasRegion; + + /// An AttachmentLoader that configures attachments using texture regions from an Atlas. + /// See http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data about Loading Skeleton Data in the Spine Runtimes Guide. + class SP_API AtlasAttachmentLoader : public AttachmentLoader { + public: + RTTI_DECL + + explicit AtlasAttachmentLoader(Atlas *atlas); + + virtual RegionAttachment *newRegionAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence); + + virtual MeshAttachment *newMeshAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence); + + virtual BoundingBoxAttachment *newBoundingBoxAttachment(Skin &skin, const String &name); + + virtual PathAttachment *newPathAttachment(Skin &skin, const String &name); + + virtual PointAttachment *newPointAttachment(Skin &skin, const String &name); + + virtual ClippingAttachment *newClippingAttachment(Skin &skin, const String &name); + + virtual void configureAttachment(Attachment *attachment); + + AtlasRegion *findRegion(const String &name); + + private: + Atlas *_atlas; + }; +} + +#endif /* Spine_AtlasAttachmentLoader_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Attachment.cpp b/native/cocos/editor-support/spine/4.2/spine/Attachment.cpp new file mode 100644 index 0000000000..72eb8be7bf --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Attachment.cpp @@ -0,0 +1,59 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +using namespace spine; + +RTTI_IMPL_NOPARENT(Attachment) + +Attachment::Attachment(const String &name) : _name(name), _refCount(0) { + assert(_name.length() > 0); +} + +Attachment::~Attachment() { +} + +const String &Attachment::getName() const { + return _name; +} + +int Attachment::getRefCount() { + return _refCount; +} + +void Attachment::reference() { + _refCount++; +} + +void Attachment::dereference() { + _refCount--; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Attachment.h b/native/cocos/editor-support/spine/4.2/spine/Attachment.h new file mode 100644 index 0000000000..578fc82d89 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Attachment.h @@ -0,0 +1,62 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Attachment_h +#define Spine_Attachment_h + +#include +#include +#include + +namespace spine { + class SP_API Attachment : public SpineObject { + RTTI_DECL + + public: + explicit Attachment(const String &name); + + virtual ~Attachment(); + + const String &getName() const; + + virtual Attachment *copy() = 0; + + int getRefCount(); + + void reference(); + + void dereference(); + + private: + const String _name; + int _refCount; + }; +} + +#endif /* Spine_Attachment_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/AttachmentLoader.cpp b/native/cocos/editor-support/spine/4.2/spine/AttachmentLoader.cpp new file mode 100644 index 0000000000..0ded24b842 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AttachmentLoader.cpp @@ -0,0 +1,48 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL_NOPARENT(AttachmentLoader) + +AttachmentLoader::AttachmentLoader() { +} + +AttachmentLoader::~AttachmentLoader() { +} diff --git a/native/cocos/editor-support/spine/4.2/spine/AttachmentLoader.h b/native/cocos/editor-support/spine/4.2/spine/AttachmentLoader.h new file mode 100644 index 0000000000..fb5c0cb319 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AttachmentLoader.h @@ -0,0 +1,84 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_AttachmentLoader_h +#define Spine_AttachmentLoader_h + +#include +#include +#include + +namespace spine { + class Skin; + + class Attachment; + + class RegionAttachment; + + class MeshAttachment; + + class BoundingBoxAttachment; + + class PathAttachment; + + class PointAttachment; + + class ClippingAttachment; + + class Sequence; + + class SP_API AttachmentLoader : public SpineObject { + public: + RTTI_DECL + + AttachmentLoader(); + + virtual ~AttachmentLoader(); + + /// @return May be NULL to not load any attachment. + virtual RegionAttachment *newRegionAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence) = 0; + + /// @return May be NULL to not load any attachment. + virtual MeshAttachment *newMeshAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence) = 0; + + /// @return May be NULL to not load any attachment. + virtual BoundingBoxAttachment *newBoundingBoxAttachment(Skin &skin, const String &name) = 0; + + /// @return May be NULL to not load any attachment + virtual PathAttachment *newPathAttachment(Skin &skin, const String &name) = 0; + + virtual PointAttachment *newPointAttachment(Skin &skin, const String &name) = 0; + + virtual ClippingAttachment *newClippingAttachment(Skin &skin, const String &name) = 0; + + virtual void configureAttachment(Attachment *attachment) = 0; + }; +} + +#endif /* Spine_AttachmentLoader_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/AttachmentTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/AttachmentTimeline.cpp new file mode 100644 index 0000000000..a49c102f14 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AttachmentTimeline.cpp @@ -0,0 +1,100 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(AttachmentTimeline, Timeline) + +AttachmentTimeline::AttachmentTimeline(size_t frameCount, int slotIndex) : Timeline(frameCount, 1), + _slotIndex(slotIndex) { + PropertyId ids[] = {((PropertyId) Property_Attachment << 32) | slotIndex}; + setPropertyIds(ids, 1); + + _attachmentNames.ensureCapacity(frameCount); + for (size_t i = 0; i < frameCount; ++i) { + _attachmentNames.add(String()); + } +} + +AttachmentTimeline::~AttachmentTimeline() {} + +void AttachmentTimeline::setAttachment(Skeleton &skeleton, Slot &slot, String *attachmentName) { + slot.setAttachment(attachmentName == NULL || attachmentName->isEmpty() ? NULL : skeleton.getAttachment(_slotIndex, *attachmentName)); +} + +void AttachmentTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(alpha); + + Slot *slot = skeleton._slots[_slotIndex]; + if (!slot->_bone._active) return; + + if (direction == MixDirection_Out) { + if (blend == MixBlend_Setup) setAttachment(skeleton, *slot, &slot->_data._attachmentName); + return; + } + + if (time < _frames[0]) { + // Time is before first frame. + if (blend == MixBlend_Setup || blend == MixBlend_First) { + setAttachment(skeleton, *slot, &slot->_data._attachmentName); + } + return; + } + + if (time < _frames[0]) { + if (blend == MixBlend_Setup || blend == MixBlend_First) + setAttachment(skeleton, *slot, &slot->_data._attachmentName); + return; + } + + setAttachment(skeleton, *slot, &_attachmentNames[Animation::search(_frames, time)]); +} + +void AttachmentTimeline::setFrame(int frame, float time, const String &attachmentName) { + _frames[frame] = time; + _attachmentNames[frame] = attachmentName; +} + +Vector &AttachmentTimeline::getAttachmentNames() { + return _attachmentNames; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/AttachmentTimeline.h b/native/cocos/editor-support/spine/4.2/spine/AttachmentTimeline.h new file mode 100644 index 0000000000..cde3f92cb0 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AttachmentTimeline.h @@ -0,0 +1,83 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_AttachmentTimeline_h +#define Spine_AttachmentTimeline_h + +#include +#include +#include +#include +#include +#include + +namespace spine { + + class Skeleton; + + class Slot; + + class Event; + + class SP_API AttachmentTimeline : public Timeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit AttachmentTimeline(size_t frameCount, int slotIndex); + + virtual ~AttachmentTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frame, float time, const String &attachmentName); + + Vector &getAttachmentNames(); + + int getSlotIndex() { return _slotIndex; } + + void setSlotIndex(int inValue) { _slotIndex = inValue; } + #ifndef __EMSCRIPTEN__ + protected: + #endif + int _slotIndex; + + Vector _attachmentNames; + + void setAttachment(Skeleton &skeleton, Slot &slot, String *attachmentName); + }; +} + +#endif /* Spine_AttachmentTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/AttachmentType.h b/native/cocos/editor-support/spine/4.2/spine/AttachmentType.h new file mode 100644 index 0000000000..9a625aa218 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/AttachmentType.h @@ -0,0 +1,45 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_AttachmentType_h +#define Spine_AttachmentType_h + +namespace spine { + enum AttachmentType { + AttachmentType_Region, + AttachmentType_Boundingbox, + AttachmentType_Mesh, + AttachmentType_Linkedmesh, + AttachmentType_Path, + AttachmentType_Point, + AttachmentType_Clipping + }; +} + +#endif /* Spine_AttachmentType_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/BlendMode.h b/native/cocos/editor-support/spine/4.2/spine/BlendMode.h new file mode 100644 index 0000000000..266c3eca37 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/BlendMode.h @@ -0,0 +1,42 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_BlendMode_h +#define Spine_BlendMode_h + +namespace spine { + enum BlendMode { + BlendMode_Normal = 0, + BlendMode_Additive, + BlendMode_Multiply, + BlendMode_Screen + }; +} + +#endif /* Spine_BlendMode_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/BlockAllocator.h b/native/cocos/editor-support/spine/4.2/spine/BlockAllocator.h new file mode 100644 index 0000000000..b1c56c5de2 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/BlockAllocator.h @@ -0,0 +1,110 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ +#ifndef Spine_BlockAllocator_h +#define Spine_BlockAllocator_h + +#include +#include +#include +#include +#include + +namespace spine { + struct Block { + int size; + int allocated; + uint8_t *memory; + + int free() { + return size - allocated; + } + + bool canFit(int numBytes) { + return free() >= numBytes; + } + + uint8_t *allocate(int numBytes) { + uint8_t *ptr = memory + allocated; + allocated += numBytes; + return ptr; + } + }; + + class BlockAllocator : public SpineObject { + int initialBlockSize; + Vector blocks; + + public: + BlockAllocator(int initialBlockSize) : initialBlockSize(initialBlockSize) { + blocks.add(newBlock(initialBlockSize)); + } + + ~BlockAllocator() { + for (int i = 0, n = (int) blocks.size(); i < n; i++) { + SpineExtension::free(blocks[i].memory, __FILE__, __LINE__); + } + } + + template + T *allocate(size_t num) { + return (T *) _allocate((int) (sizeof(T) * num)); + } + + void compress() { + if (blocks.size() == 1) return; + int totalSize = 0; + for (int i = 0, n = (int)blocks.size(); i < n; i++) { + totalSize += blocks[i].size; + SpineExtension::free(blocks[i].memory, __FILE__, __LINE__); + } + blocks.clear(); + blocks.add(newBlock(totalSize)); + } + + private: + void *_allocate(int numBytes) { + // 16-byte align allocations + int alignedNumBytes = numBytes + (numBytes % 16 != 0 ? 16 - (numBytes % 16) : 0); + Block *block = &blocks[blocks.size() - 1]; + if (!block->canFit(alignedNumBytes)) { + blocks.add(newBlock(MathUtil::max(initialBlockSize, alignedNumBytes))); + block = &blocks[blocks.size() - 1]; + } + return block->allocate(alignedNumBytes); + } + + Block newBlock(int numBytes) { + Block block = {MathUtil::max(initialBlockSize, numBytes), 0, nullptr}; + block.memory = SpineExtension::alloc(block.size, __FILE__, __LINE__); + return block; + } + }; +} + +#endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine/4.2/spine/Bone.cpp b/native/cocos/editor-support/spine/4.2/spine/Bone.cpp new file mode 100644 index 0000000000..3c673d9cef --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Bone.cpp @@ -0,0 +1,595 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +using namespace spine; + +RTTI_IMPL(Bone, Updatable) + +bool Bone::yDown = false; + +void Bone::setYDown(bool inValue) { + yDown = inValue; +} + +bool Bone::isYDown() { + return yDown; +} + +Bone::Bone(BoneData &data, Skeleton &skeleton, Bone *parent) : Updatable(), + _data(data), + _skeleton(skeleton), + _parent(parent), + _x(0), + _y(0), + _rotation(0), + _scaleX(0), + _scaleY(0), + _shearX(0), + _shearY(0), + _ax(0), + _ay(0), + _arotation(0), + _ascaleX(0), + _ascaleY(0), + _ashearX(0), + _ashearY(0), + _a(1), + _b(0), + _worldX(0), + _c(0), + _d(1), + _worldY(0), + _sorted(false), + _active(false), + _inherit(Inherit_Normal) { + setToSetupPose(); +} + +void Bone::update(Physics) { + updateWorldTransform(_ax, _ay, _arotation, _ascaleX, _ascaleY, _ashearX, _ashearY); +} + +void Bone::updateWorldTransform() { + updateWorldTransform(_x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY); +} + +void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY) { + float pa, pb, pc, pd; + Bone *parent = _parent; + + _ax = x; + _ay = y; + _arotation = rotation; + _ascaleX = scaleX; + _ascaleY = scaleY; + _ashearX = shearX; + _ashearY = shearY; + + if (!parent) { /* Root bone. */ + Skeleton &skeleton = this->_skeleton; + float sx = skeleton.getScaleX(); + float sy = skeleton.getScaleY(); + float rx = (rotation + shearX) * MathUtil::Deg_Rad; + float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad; + _a = MathUtil::cos(rx) * scaleX * sx; + _b = MathUtil::cos(ry) * scaleY * sx; + _c = MathUtil::sin(rx) * scaleX * sy; + _d = MathUtil::sin(ry) * scaleY * sy; + _worldX = x * sx + _skeleton.getX(); + _worldY = y * sy + _skeleton.getY(); + return; + } + + pa = parent->_a; + pb = parent->_b; + pc = parent->_c; + pd = parent->_d; + + _worldX = pa * x + pb * y + parent->_worldX; + _worldY = pc * x + pd * y + parent->_worldY; + + switch (_inherit) { + case Inherit_Normal: { + float rx = (rotation + shearX) * MathUtil::Deg_Rad; + float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad; + float la = MathUtil::cos(rx) * scaleX; + float lb = MathUtil::cos(ry) * scaleY; + float lc = MathUtil::sin(rx) * scaleX; + float ld = MathUtil::sin(ry) * scaleY; + _a = pa * la + pb * lc; + _b = pa * lb + pb * ld; + _c = pc * la + pd * lc; + _d = pc * lb + pd * ld; + return; + } + case Inherit_OnlyTranslation: { + float rx = (rotation + shearX) * MathUtil::Deg_Rad; + float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad; + _a = MathUtil::cos(rx) * scaleX; + _b = MathUtil::cos(ry) * scaleY; + _c = MathUtil::sin(rx) * scaleX; + _d = MathUtil::sin(ry) * scaleY; + break; + } + case Inherit_NoRotationOrReflection: { + float s = pa * pa + pc * pc; + float prx; + if (s > 0.0001f) { + s = MathUtil::abs(pa * pd - pb * pc) / s; + pa /= _skeleton.getScaleX(); + pc /= _skeleton.getScaleY(); + pb = pc * s; + pd = pa * s; + prx = MathUtil::atan2Deg(pc, pa); + } else { + pa = 0; + pc = 0; + prx = 90 - MathUtil::atan2Deg(pd, pb); + } + float rx = (rotation + shearX - prx) * MathUtil::Deg_Rad; + float ry = (rotation + shearY - prx + 90) * MathUtil::Deg_Rad; + float la = MathUtil::cos(rx) * scaleX; + float lb = MathUtil::cos(ry) * scaleY; + float lc = MathUtil::sin(rx) * scaleX; + float ld = MathUtil::sin(ry) * scaleY; + _a = pa * la - pb * lc; + _b = pa * lb - pb * ld; + _c = pc * la + pd * lc; + _d = pc * lb + pd * ld; + break; + } + case Inherit_NoScale: + case Inherit_NoScaleOrReflection: { + rotation *= MathUtil::Deg_Rad; + float cosine = MathUtil::cos(rotation); + float sine = MathUtil::sin(rotation); + float za = (pa * cosine + pb * sine) / _skeleton.getScaleX(); + float zc = (pc * cosine + pd * sine) / _skeleton.getScaleY(); + float 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 (_inherit == Inherit_NoScale && + (pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) + s = -s; + rotation = MathUtil::Pi / 2 + MathUtil::atan2(zc, za); + float zb = MathUtil::cos(rotation) * s; + float zd = MathUtil::sin(rotation) * s; + shearX *= MathUtil::Deg_Rad; + shearY = (90 + shearY) * MathUtil::Deg_Rad; + float la = MathUtil::cos(shearX) * scaleX; + float lb = MathUtil::cos(shearY) * scaleY; + float lc = MathUtil::sin(shearX) * scaleX; + float ld = MathUtil::sin(shearY) * scaleY; + _a = za * la + zb * lc; + _b = za * lb + zb * ld; + _c = zc * la + zd * lc; + _d = zc * lb + zd * ld; + } + } + _a *= _skeleton.getScaleX(); + _b *= _skeleton.getScaleX(); + _c *= _skeleton.getScaleY(); + _d *= _skeleton.getScaleY(); +} + +void Bone::setToSetupPose() { + BoneData &data = _data; + _x = data.getX(); + _y = data.getY(); + _rotation = data.getRotation(); + _scaleX = data.getScaleX(); + _scaleY = data.getScaleY(); + _shearX = data.getShearX(); + _shearY = data.getShearY(); + _inherit = data.getInherit(); +} + +void Bone::worldToLocal(float worldX, float worldY, float &outLocalX, float &outLocalY) { + float a = _a; + float b = _b; + float c = _c; + float d = _d; + + float invDet = 1 / (a * d - b * c); + float x = worldX - _worldX; + float y = worldY - _worldY; + + outLocalX = (x * d * invDet - y * b * invDet); + outLocalY = (y * a * invDet - x * c * invDet); +} + +void Bone::worldToParent(float worldX, float worldY, float &outParentX, float &outParentY) { + if (!_parent) { + outParentX = worldX; + outParentY = worldY; + } else { + _parent->worldToLocal(worldX, worldY, outParentX, outParentY); + } +} + +void Bone::localToWorld(float localX, float localY, float &outWorldX, float &outWorldY) { + outWorldX = localX * _a + localY * _b + _worldX; + outWorldY = localX * _c + localY * _d + _worldY; +} + +void Bone::parentToWorld(float worldX, float worldY, float &outX, float &outY) { + if (!_parent) { + outX = worldX; + outY = worldY; + } else { + _parent->localToWorld(worldX, worldY, outX, outY); + } +} + +float Bone::worldToLocalRotation(float worldRotation) { + worldRotation *= MathUtil::Deg_Rad; + float sine = MathUtil::sin(worldRotation), cosine = MathUtil::cos(worldRotation); + return MathUtil::atan2Deg(_a * sine - _c * cosine, _d * cosine - _b * sine) + _rotation - _shearX; +} + +float Bone::localToWorldRotation(float localRotation) { + localRotation = (localRotation - _rotation - _shearX) * MathUtil::Deg_Rad; + float sine = MathUtil::sin(localRotation), cosine = MathUtil::cos(localRotation); + return MathUtil::atan2Deg(cosine * _c + sine * _d, cosine * _a + sine * _b); +} + +void Bone::rotateWorld(float degrees) { + degrees *= MathUtil::Deg_Rad; + float sine = MathUtil::sin(degrees), cosine = MathUtil::cos(degrees); + float ra = _a, rb = _b; + _a = cosine * ra - sine * _c; + _b = cosine * rb - sine * _d; + _c = sine * ra + cosine * _c; + _d = sine * rb + cosine * _d; +} + +float Bone::getWorldToLocalRotationX() { + Bone *parent = _parent; + if (!parent) { + return _arotation; + } + + float pa = parent->_a; + float pb = parent->_b; + float pc = parent->_c; + float pd = parent->_d; + float a = _a; + float c = _c; + + return MathUtil::atan2(pa * c - pc * a, pd * a - pb * c) * MathUtil::Rad_Deg; +} + +float Bone::getWorldToLocalRotationY() { + Bone *parent = _parent; + if (!parent) { + return _arotation; + } + + float pa = parent->_a; + float pb = parent->_b; + float pc = parent->_c; + float pd = parent->_d; + float b = _b; + float d = _d; + + return MathUtil::atan2(pa * d - pc * b, pd * b - pb * d) * MathUtil::Rad_Deg; +} + +BoneData &Bone::getData() { + return _data; +} + +Skeleton &Bone::getSkeleton() { + return _skeleton; +} + +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() { + return MathUtil::atan2Deg(_c, _a); +} + +float Bone::getWorldRotationY() { + return MathUtil::atan2Deg(_d, _b); +} + +float Bone::getWorldScaleX() { + return MathUtil::sqrt(_a * _a + _c * _c); +} + +float Bone::getWorldScaleY() { + return MathUtil::sqrt(_b * _b + _d * _d); +} + +void Bone::updateAppliedTransform() { + Bone *parent = _parent; + if (!parent) { + _ax = _worldX - _skeleton.getX(); + _ay = _worldY - _skeleton.getY(); + _arotation = MathUtil::atan2Deg(_c, _a); + _ascaleX = MathUtil::sqrt(_a * _a + _c * _c); + _ascaleY = MathUtil::sqrt(_b * _b + _d * _d); + _ashearX = 0; + _ashearY = MathUtil::atan2Deg(_a * _b + _c * _d, _a * _d - _b * _c); + } + float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d; + float pid = 1 / (pa * pd - pb * pc); + float ia = pd * pid, ib = pb * pid, ic = pc * pid, id = pa * pid; + float dx = _worldX - parent->_worldX, dy = _worldY - parent->_worldY; + _ax = (dx * ia - dy * ib); + _ay = (dy * id - dx * ic); + + float ra, rb, rc, rd; + if (_inherit == Inherit_OnlyTranslation) { + ra = _a; + rb = _b; + rc = _c; + rd = _d; + } else { + switch (_inherit) { + case Inherit_NoRotationOrReflection: { + float s = MathUtil::abs(pa * pd - pb * pc) / (pa * pa + pc * pc); + float sa = pa / _skeleton.getScaleX(); + float sc = pc / _skeleton.getScaleY(); + pb = -sc * s * _skeleton.getScaleX(); + pd = sa * s * _skeleton.getScaleY(); + pid = 1 / (pa * pd - pb * pc); + ia = pd * pid; + ib = pb * pid; + break; + } + case Inherit_NoScale: + case Inherit_NoScaleOrReflection: { + float r = _rotation * MathUtil::Deg_Rad; + float cos = MathUtil::cos(r), sin = MathUtil::sin(r); + pa = (pa * cos + pb * sin) / _skeleton.getScaleX(); + pc = (pc * cos + pd * sin) / _skeleton.getScaleY(); + float s = MathUtil::sqrt(pa * pa + pc * pc); + if (s > 0.00001) s = 1 / s; + pa *= s; + pc *= s; + s = MathUtil::sqrt(pa * pa + pc * pc); + if (_inherit == Inherit_NoScale && + pid < 0 != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) + s = -s; + r = MathUtil::Pi / 2 + MathUtil::atan2(pc, pa); + pb = MathUtil::cos(r) * s; + pd = MathUtil::sin(r) * s; + pid = 1 / (pa * pd - pb * pc); + ia = pd * pid; + ib = pb * pid; + ic = pc * pid; + id = pa * pid; + break; + } + case Inherit_Normal: + case Inherit_OnlyTranslation: + break; + } + ra = ia * _a - ib * _c; + rb = ia * _b - ib * _d; + rc = id * _c - ic * _a; + rd = id * _d - ic * _b; + } + + _ashearX = 0; + _ascaleX = MathUtil::sqrt(ra * ra + rc * rc); + if (_ascaleX > 0.0001f) { + float det = ra * rd - rb * rc; + _ascaleY = det / _ascaleX; + _ashearY = -MathUtil::atan2Deg(ra * rb + rc * rd, det); + _arotation = MathUtil::atan2Deg(rc, ra); + } else { + _ascaleX = 0; + _ascaleY = MathUtil::sqrt(rb * rb + rd * rd); + _ashearY = 0; + _arotation = 90 - MathUtil::atan2Deg(rd, rb); + } +} + +bool Bone::isActive() { + return _active; +} + +void Bone::setActive(bool inValue) { + _active = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Bone.h b/native/cocos/editor-support/spine/4.2/spine/Bone.h new file mode 100644 index 0000000000..0e7849131c --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Bone.h @@ -0,0 +1,288 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Bone_h +#define Spine_Bone_h + +#include +#include +#include +#include + +namespace spine { + class BoneData; + + class Skeleton; + +/// Stores a bone's current pose. +/// +/// A bone has a local transform which is used to compute its world transform. A bone also has an applied transform, which is a +/// local transform that can be applied to compute the world transform. The local transform and applied transform may differ if a +/// constraint or application code modifies the world transform after it was computed from the local transform. + class SP_API Bone : public Updatable { + friend class AnimationState; + + friend class RotateTimeline; + + friend class IkConstraint; + + friend class TransformConstraint; + + friend class VertexAttachment; + + friend class PathConstraint; + + friend class PhysicsConstraint; + + friend class Skeleton; + + friend class RegionAttachment; + + friend class PointAttachment; + + friend class AttachmentTimeline; + + friend class RGBATimeline; + + friend class RGBTimeline; + + friend class AlphaTimeline; + + friend class RGBA2Timeline; + + friend class RGB2Timeline; + + friend class ScaleTimeline; + + friend class ScaleXTimeline; + + friend class ScaleYTimeline; + + friend class ShearTimeline; + + friend class ShearXTimeline; + + friend class ShearYTimeline; + + friend class TranslateTimeline; + + friend class TranslateXTimeline; + + friend class TranslateYTimeline; + + friend class InheritTimeline; + + RTTI_DECL + + public: + static void setYDown(bool inValue); + + static bool isYDown(); + + /// @param parent May be NULL. + Bone(BoneData &data, Skeleton &skeleton, Bone *parent = NULL); + + /// Same as updateWorldTransform. This method exists for Bone to implement Spine::Updatable. + virtual void update(Physics physics); + + /// Computes the world transform using the parent bone and this bone's local transform. + void updateWorldTransform(); + + /// Computes the world transform using the parent bone and the specified local transform. + void + updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY); + + /// Computes the individual applied transform values from the world transform. This can be useful to perform processing using + /// the applied transform after the world transform has been modified directly (eg, by a constraint).. + /// + /// Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. + void updateAppliedTransform(); + + void setToSetupPose(); + + void worldToLocal(float worldX, float worldY, float &outLocalX, float &outLocalY); + + void worldToParent(float worldX, float worldY, float &outParentX, float &outParentY); + + void localToWorld(float localX, float localY, float &outWorldX, float &outWorldY); + + void parentToWorld(float worldX, float worldY, float &outX, float &outY); + + float worldToLocalRotation(float worldRotation); + + float localToWorldRotation(float localRotation); + + /// Rotates the world transform the specified amount and sets isAppliedValid to false. + /// @param degrees Degrees. + void rotateWorld(float degrees); + + float getWorldToLocalRotationX(); + + float getWorldToLocalRotationY(); + + BoneData &getData(); + + Skeleton &getSkeleton(); + + Bone *getParent(); + + Vector &getChildren(); + + /// The local X translation. + float getX(); + + void setX(float inValue); + + /// The local Y translation. + float getY(); + + void setY(float inValue); + + /// The local rotation. + float getRotation(); + + void setRotation(float inValue); + + /// The local scaleX. + float getScaleX(); + + void setScaleX(float inValue); + + /// The local scaleY. + float getScaleY(); + + void setScaleY(float inValue); + + /// The local shearX. + float getShearX(); + + void setShearX(float inValue); + + /// The local shearY. + float getShearY(); + + void setShearY(float inValue); + + /// The rotation, as calculated by any constraints. + float getAppliedRotation(); + + void setAppliedRotation(float inValue); + + /// The applied local x translation. + float getAX(); + + void setAX(float inValue); + + /// The applied local y translation. + float getAY(); + + void setAY(float inValue); + + /// The applied local scaleX. + float getAScaleX(); + + void setAScaleX(float inValue); + + /// The applied local scaleY. + float getAScaleY(); + + void setAScaleY(float inValue); + + /// The applied local shearX. + float getAShearX(); + + void setAShearX(float inValue); + + /// The applied local shearY. + float getAShearY(); + + void setAShearY(float inValue); + + float getA(); + + void setA(float inValue); + + float getB(); + + void setB(float inValue); + + float getC(); + + void setC(float inValue); + + float getD(); + + void setD(float inValue); + + float getWorldX(); + + void setWorldX(float inValue); + + float getWorldY(); + + void setWorldY(float inValue); + + float getWorldRotationX(); + + float getWorldRotationY(); + + /// Returns the magnitide (always positive) of the world scale X. + float getWorldScaleX(); + + /// Returns the magnitide (always positive) of the world scale Y. + float getWorldScaleY(); + + bool isActive(); + + void setActive(bool inValue); + + Inherit getInherit() { return _inherit; } + + void setInherit(Inherit inValue) { _inherit = inValue; } + + #ifndef __EMSCRIPTEN__ + private: + #endif + static bool yDown; + + BoneData &_data; + Skeleton &_skeleton; + Bone *_parent; + Vector _children; + float _x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY; + float _ax, _ay, _arotation, _ascaleX, _ascaleY, _ashearX, _ashearY; + float _a, _b, _worldX; + float _c, _d, _worldY; + bool _sorted; + bool _active; + Inherit _inherit; + }; +} + +#endif /* Spine_Bone_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/BoneData.cpp b/native/cocos/editor-support/spine/4.2/spine/BoneData.cpp new file mode 100644 index 0000000000..3c909fe79e --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/BoneData.cpp @@ -0,0 +1,166 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +using namespace spine; + +BoneData::BoneData(int index, const String &name, BoneData *parent) : _index(index), + _name(name), + _parent(parent), + _length(0), + _x(0), + _y(0), + _rotation(0), + _scaleX(1), + _scaleY(1), + _shearX(0), + _shearY(0), + _inherit(Inherit_Normal), + _skinRequired(false), + _color(), + _icon(), + _visible(true) { + assert(index >= 0); + assert(_name.length() > 0); +} + +int BoneData::getIndex() { + return _index; +} + +const String &BoneData::getName() { + return _name; +} + +BoneData *BoneData::getParent() { + return _parent; +} + +float BoneData::getLength() { + return _length; +} + +void BoneData::setLength(float inValue) { + _length = inValue; +} + +float BoneData::getX() { + return _x; +} + +void BoneData::setX(float inValue) { + _x = inValue; +} + +float BoneData::getY() { + return _y; +} + +void BoneData::setY(float inValue) { + _y = inValue; +} + +float BoneData::getRotation() { + return _rotation; +} + +void BoneData::setRotation(float inValue) { + _rotation = inValue; +} + +float BoneData::getScaleX() { + return _scaleX; +} + +void BoneData::setScaleX(float inValue) { + _scaleX = inValue; +} + +float BoneData::getScaleY() { + return _scaleY; +} + +void BoneData::setScaleY(float inValue) { + _scaleY = inValue; +} + +float BoneData::getShearX() { + return _shearX; +} + +void BoneData::setShearX(float inValue) { + _shearX = inValue; +} + +float BoneData::getShearY() { + return _shearY; +} + +void BoneData::setShearY(float inValue) { + _shearY = inValue; +} + +Inherit BoneData::getInherit() { + return _inherit; +} + +void BoneData::setInherit(Inherit inValue) { + _inherit = inValue; +} + +bool BoneData::isSkinRequired() { + return _skinRequired; +} + +void BoneData::setSkinRequired(bool inValue) { + _skinRequired = inValue; +} + +Color &BoneData::getColor() { + return _color; +} + +const String &BoneData::getIcon() { + return _icon; +} + +void BoneData::setIcon(const String &icon) { + this->_icon = icon; +} + +bool BoneData::isVisible() { + return _visible; +} + +void BoneData::setVisible(bool inValue) { + this->_visible = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/BoneData.h b/native/cocos/editor-support/spine/4.2/spine/BoneData.h new file mode 100644 index 0000000000..df1990de98 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/BoneData.h @@ -0,0 +1,152 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_BoneData_h +#define Spine_BoneData_h + +#include +#include +#include +#include + +namespace spine { + class SP_API BoneData : public SpineObject { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class AnimationState; + + friend class RotateTimeline; + + friend class ScaleTimeline; + + friend class ScaleXTimeline; + + friend class ScaleYTimeline; + + friend class ShearTimeline; + + friend class ShearXTimeline; + + friend class ShearYTimeline; + + friend class TranslateTimeline; + + friend class TranslateXTimeline; + + friend class TranslateYTimeline; + + public: + BoneData(int index, const String &name, BoneData *parent = NULL); + + /// The index of the bone in Skeleton.Bones + int getIndex(); + + /// The name of the bone, which is unique within the skeleton. + const String &getName(); + + /// May be NULL. + BoneData *getParent(); + + float getLength(); + + void setLength(float inValue); + + /// Local X translation. + float getX(); + + void setX(float inValue); + + /// Local Y translation. + float getY(); + + void setY(float inValue); + + /// Local rotation. + float getRotation(); + + void setRotation(float inValue); + + /// Local scaleX. + float getScaleX(); + + void setScaleX(float inValue); + + /// Local scaleY. + float getScaleY(); + + void setScaleY(float inValue); + + /// Local shearX. + float getShearX(); + + void setShearX(float inValue); + + /// Local shearY. + float getShearY(); + + void setShearY(float inValue); + + /// The transform mode for how parent world transforms affect this bone. + Inherit getInherit(); + + void setInherit(Inherit inValue); + + bool isSkinRequired(); + + void setSkinRequired(bool inValue); + + Color &getColor(); + + const String &getIcon(); + + void setIcon(const String &icon); + + bool isVisible(); + + void setVisible(bool inValue); + + #ifndef __EMSCRIPTEN__ + private: + #endif + const int _index; + const String _name; + BoneData *_parent; + float _length; + float _x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY; + Inherit _inherit; + bool _skinRequired; + Color _color; + String _icon; + bool _visible; + }; +} + +#endif /* Spine_BoneData_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/BoundingBoxAttachment.cpp b/native/cocos/editor-support/spine/4.2/spine/BoundingBoxAttachment.cpp new file mode 100644 index 0000000000..9c84241d2e --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/BoundingBoxAttachment.cpp @@ -0,0 +1,47 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +using namespace spine; + +RTTI_IMPL(BoundingBoxAttachment, VertexAttachment) + +BoundingBoxAttachment::BoundingBoxAttachment(const String &name) : VertexAttachment(name), _color() { +} + +Color &BoundingBoxAttachment::getColor() { + return _color; +} + +Attachment *BoundingBoxAttachment::copy() { + BoundingBoxAttachment *copy = new (__FILE__, __LINE__) BoundingBoxAttachment(getName()); + copyTo(copy); + return copy; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/BoundingBoxAttachment.h b/native/cocos/editor-support/spine/4.2/spine/BoundingBoxAttachment.h new file mode 100644 index 0000000000..ce066578db --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/BoundingBoxAttachment.h @@ -0,0 +1,54 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_BoundingBoxAttachment_h +#define Spine_BoundingBoxAttachment_h + +#include +#include +#include + +namespace spine { + /// Attachment that has a polygon for bounds checking. + class SP_API BoundingBoxAttachment : public VertexAttachment { + RTTI_DECL + + public: + explicit BoundingBoxAttachment(const String &name); + + Color &getColor(); + + virtual Attachment *copy(); + + private: + Color _color; + }; +} + +#endif /* Spine_BoundingBoxAttachment_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/ClippingAttachment.cpp b/native/cocos/editor-support/spine/4.2/spine/ClippingAttachment.cpp new file mode 100644 index 0000000000..60b01f1c18 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ClippingAttachment.cpp @@ -0,0 +1,58 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +using namespace spine; + +RTTI_IMPL(ClippingAttachment, VertexAttachment) + +ClippingAttachment::ClippingAttachment(const String &name) : VertexAttachment(name), _endSlot(NULL), _color() { +} + +SlotData *ClippingAttachment::getEndSlot() { + return _endSlot; +} + +void ClippingAttachment::setEndSlot(SlotData *inValue) { + _endSlot = inValue; +} + +Color &ClippingAttachment::getColor() { + return _color; +} + +Attachment *ClippingAttachment::copy() { + ClippingAttachment *copy = new (__FILE__, __LINE__) ClippingAttachment(getName()); + copyTo(copy); + copy->_endSlot = _endSlot; + return copy; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/ClippingAttachment.h b/native/cocos/editor-support/spine/4.2/spine/ClippingAttachment.h new file mode 100644 index 0000000000..87462a78b0 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ClippingAttachment.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_ClippingAttachment_h +#define Spine_ClippingAttachment_h + +#include +#include + +namespace spine { + class SlotData; + + class SP_API ClippingAttachment : public VertexAttachment { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class SkeletonClipping; + + RTTI_DECL + + public: + explicit ClippingAttachment(const String &name); + + SlotData *getEndSlot(); + + void setEndSlot(SlotData *inValue); + + Color &getColor(); + + virtual Attachment *copy(); + + private: + SlotData *_endSlot; + Color _color; + }; +} + +#endif /* Spine_ClippingAttachment_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Color.h b/native/cocos/editor-support/spine/4.2/spine/Color.h new file mode 100644 index 0000000000..c00d581678 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Color.h @@ -0,0 +1,110 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef SPINE_COLOR_H +#define SPINE_COLOR_H + +#include + +namespace spine { + class SP_API Color : public SpineObject { + public: + Color() : r(0), g(0), b(0), a(0) { + } + + Color(float r, float g, float b, float a) : r(r), g(g), b(b), a(a) { + clamp(); + } + + inline Color &set(float _r, float _g, float _b, float _a) { + this->r = _r; + this->g = _g; + this->b = _b; + this->a = _a; + clamp(); + return *this; + } + + inline Color &set(float _r, float _g, float _b) { + this->r = _r; + this->g = _g; + this->b = _b; + clamp(); + return *this; + } + + inline Color &set(const Color &other) { + r = other.r; + g = other.g; + b = other.b; + a = other.a; + clamp(); + return *this; + } + + inline Color &add(float _r, float _g, float _b, float _a) { + this->r += _r; + this->g += _g; + this->b += _b; + this->a += _a; + clamp(); + return *this; + } + + inline Color &add(float _r, float _g, float _b) { + this->r += _r; + this->g += _g; + this->b += _b; + clamp(); + return *this; + } + + inline Color &add(const Color &other) { + r += other.r; + g += other.g; + b += other.b; + a += other.a; + clamp(); + return *this; + } + + inline Color &clamp() { + r = MathUtil::clamp(this->r, 0, 1); + g = MathUtil::clamp(this->g, 0, 1); + b = MathUtil::clamp(this->b, 0, 1); + a = MathUtil::clamp(this->a, 0, 1); + return *this; + } + + float r, g, b, a; + }; +} + + +#endif //SPINE_COLOR_H diff --git a/native/cocos/editor-support/spine/4.2/spine/ColorTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/ColorTimeline.cpp new file mode 100644 index 0000000000..f5567c57a5 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ColorTimeline.cpp @@ -0,0 +1,495 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include +#include + +using namespace spine; + +const int RGBATimeline::ENTRIES = 5; + +RTTI_IMPL(RGBATimeline, CurveTimeline) + +RGBATimeline::RGBATimeline(size_t frameCount, size_t bezierCount, int slotIndex) : CurveTimeline(frameCount, + RGBATimeline::ENTRIES, + bezierCount), + _slotIndex(slotIndex) { + PropertyId ids[] = {((PropertyId) Property_Rgb << 32) | slotIndex, + ((PropertyId) Property_Alpha << 32) | slotIndex}; + setPropertyIds(ids, 2); +} + +RGBATimeline::~RGBATimeline() { +} + +void RGBATimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Slot *slot = skeleton._slots[_slotIndex]; + if (!slot->_bone._active) return; + + if (time < _frames[0]) { + Color &color = slot->_color, &setup = slot->_data._color; + switch (blend) { + case MixBlend_Setup: + color.set(setup); + return; + case MixBlend_First: + color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, + (setup.a - color.a) * alpha); + default: { + } + } + return; + } + + float r = 0, g = 0, b = 0, a = 0; + int i = Animation::search(_frames, time, RGBATimeline::ENTRIES); + int curveType = (int) _curves[i / RGBATimeline::ENTRIES]; + switch (curveType) { + case RGBATimeline::LINEAR: { + float before = _frames[i]; + r = _frames[i + RGBATimeline::R]; + g = _frames[i + RGBATimeline::G]; + b = _frames[i + RGBATimeline::B]; + a = _frames[i + RGBATimeline::A]; + float t = (time - before) / (_frames[i + RGBATimeline::ENTRIES] - before); + r += (_frames[i + RGBATimeline::ENTRIES + RGBATimeline::R] - r) * t; + g += (_frames[i + RGBATimeline::ENTRIES + RGBATimeline::G] - g) * t; + b += (_frames[i + RGBATimeline::ENTRIES + RGBATimeline::B] - b) * t; + a += (_frames[i + RGBATimeline::ENTRIES + RGBATimeline::A] - a) * t; + break; + } + case RGBATimeline::STEPPED: { + r = _frames[i + RGBATimeline::R]; + g = _frames[i + RGBATimeline::G]; + b = _frames[i + RGBATimeline::B]; + a = _frames[i + RGBATimeline::A]; + break; + } + default: { + r = getBezierValue(time, i, RGBATimeline::R, curveType - RGBATimeline::BEZIER); + g = getBezierValue(time, i, RGBATimeline::G, + curveType + RGBATimeline::BEZIER_SIZE - RGBATimeline::BEZIER); + b = getBezierValue(time, i, RGBATimeline::B, + curveType + RGBATimeline::BEZIER_SIZE * 2 - RGBATimeline::BEZIER); + a = getBezierValue(time, i, RGBATimeline::A, + curveType + RGBATimeline::BEZIER_SIZE * 3 - RGBATimeline::BEZIER); + } + } + Color &color = slot->_color; + if (alpha == 1) + color.set(r, g, b, a); + else { + if (blend == MixBlend_Setup) color.set(slot->_data._color); + color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); + } +} + +void RGBATimeline::setFrame(int frame, float time, float r, float g, float b, float a) { + frame *= ENTRIES; + _frames[frame] = time; + _frames[frame + R] = r; + _frames[frame + G] = g; + _frames[frame + B] = b; + _frames[frame + A] = a; +} + +RTTI_IMPL(RGBTimeline, CurveTimeline) + +RGBTimeline::RGBTimeline(size_t frameCount, size_t bezierCount, int slotIndex) : CurveTimeline(frameCount, + RGBTimeline::ENTRIES, + bezierCount), + _slotIndex(slotIndex) { + PropertyId ids[] = {((PropertyId) Property_Rgb << 32) | slotIndex}; + setPropertyIds(ids, 1); +} + +RGBTimeline::~RGBTimeline() { +} + +void RGBTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Slot *slot = skeleton._slots[_slotIndex]; + if (!slot->_bone._active) return; + + if (time < _frames[0]) { + Color &color = slot->_color, &setup = slot->_data._color; + switch (blend) { + case MixBlend_Setup: + color.set(setup); + return; + case MixBlend_First: + color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, + (setup.a - color.a) * alpha); + default: { + } + } + return; + } + + float r = 0, g = 0, b = 0; + int i = Animation::search(_frames, time, RGBTimeline::ENTRIES); + int curveType = (int) _curves[i / RGBTimeline::ENTRIES]; + switch (curveType) { + case RGBTimeline::LINEAR: { + float before = _frames[i]; + r = _frames[i + RGBTimeline::R]; + g = _frames[i + RGBTimeline::G]; + b = _frames[i + RGBTimeline::B]; + float t = (time - before) / (_frames[i + RGBTimeline::ENTRIES] - before); + r += (_frames[i + RGBTimeline::ENTRIES + RGBTimeline::R] - r) * t; + g += (_frames[i + RGBTimeline::ENTRIES + RGBTimeline::G] - g) * t; + b += (_frames[i + RGBTimeline::ENTRIES + RGBTimeline::B] - b) * t; + break; + } + case RGBTimeline::STEPPED: { + r = _frames[i + RGBTimeline::R]; + g = _frames[i + RGBTimeline::G]; + b = _frames[i + RGBTimeline::B]; + break; + } + default: { + r = getBezierValue(time, i, RGBTimeline::R, curveType - RGBTimeline::BEZIER); + g = getBezierValue(time, i, RGBTimeline::G, + curveType + RGBTimeline::BEZIER_SIZE - RGBTimeline::BEZIER); + b = getBezierValue(time, i, RGBTimeline::B, + curveType + RGBTimeline::BEZIER_SIZE * 2 - RGBTimeline::BEZIER); + } + } + Color &color = slot->_color; + if (alpha == 1) + color.set(r, g, b); + else { + Color &setup = slot->_data._color; + if (blend == MixBlend_Setup) color.set(setup.r, setup.g, setup.b); + color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha); + } +} + +void RGBTimeline::setFrame(int frame, float time, float r, float g, float b) { + frame *= ENTRIES; + _frames[frame] = time; + _frames[frame + R] = r; + _frames[frame + G] = g; + _frames[frame + B] = b; +} + +RTTI_IMPL(AlphaTimeline, CurveTimeline1) + +AlphaTimeline::AlphaTimeline(size_t frameCount, size_t bezierCount, int slotIndex) : CurveTimeline1(frameCount, + bezierCount), + _slotIndex(slotIndex) { + PropertyId ids[] = {((PropertyId) Property_Alpha << 32) | slotIndex}; + setPropertyIds(ids, 1); +} + +AlphaTimeline::~AlphaTimeline() { +} + +void AlphaTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Slot *slot = skeleton._slots[_slotIndex]; + if (!slot->_bone._active) return; + + if (time < _frames[0]) {// Time is before first frame. + Color &color = slot->_color, &setup = slot->_data._color; + switch (blend) { + case MixBlend_Setup: + color.a = setup.a; + return; + case MixBlend_First: + color.a += (setup.a - color.a) * alpha; + default: { + } + } + return; + } + + float a = getCurveValue(time); + if (alpha == 1) + slot->_color.a = a; + else { + if (blend == MixBlend_Setup) slot->_color.a = slot->_data._color.a; + slot->_color.a += (a - slot->_color.a) * alpha; + } +} + +RTTI_IMPL(RGBA2Timeline, CurveTimeline) + +RGBA2Timeline::RGBA2Timeline(size_t frameCount, size_t bezierCount, int slotIndex) : CurveTimeline(frameCount, + RGBA2Timeline::ENTRIES, + bezierCount), + _slotIndex(slotIndex) { + PropertyId ids[] = {((PropertyId) Property_Rgb << 32) | slotIndex, + ((PropertyId) Property_Alpha << 32) | slotIndex, + ((PropertyId) Property_Rgb2 << 32) | slotIndex}; + setPropertyIds(ids, 3); +} + +RGBA2Timeline::~RGBA2Timeline() { +} + +void RGBA2Timeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Slot *slot = skeleton._slots[_slotIndex]; + if (!slot->_bone._active) return; + + if (time < _frames[0]) { + Color &light = slot->_color, &dark = slot->_darkColor, &setupLight = slot->_data._color, &setupDark = slot->_data._darkColor; + switch (blend) { + case MixBlend_Setup: + light.set(setupLight); + dark.set(setupDark.r, setupDark.g, setupDark.b); + return; + case MixBlend_First: + light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, + (setupLight.b - light.b) * alpha, + (setupLight.a - light.a) * alpha); + dark.r += (setupDark.r - dark.r) * alpha; + dark.g += (setupDark.g - dark.g) * alpha; + dark.b += (setupDark.b - dark.b) * alpha; + default: { + } + } + return; + } + + float r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0; + int i = Animation::search(_frames, time, RGBA2Timeline::ENTRIES); + int curveType = (int) _curves[i / RGBA2Timeline::ENTRIES]; + switch (curveType) { + case RGBA2Timeline::LINEAR: { + float before = _frames[i]; + r = _frames[i + RGBA2Timeline::R]; + g = _frames[i + RGBA2Timeline::G]; + b = _frames[i + RGBA2Timeline::B]; + a = _frames[i + RGBA2Timeline::A]; + r2 = _frames[i + RGBA2Timeline::R2]; + g2 = _frames[i + RGBA2Timeline::G2]; + b2 = _frames[i + RGBA2Timeline::B2]; + float t = (time - before) / (_frames[i + RGBA2Timeline::ENTRIES] - before); + r += (_frames[i + RGBA2Timeline::ENTRIES + RGBA2Timeline::R] - r) * t; + g += (_frames[i + RGBA2Timeline::ENTRIES + RGBA2Timeline::G] - g) * t; + b += (_frames[i + RGBA2Timeline::ENTRIES + RGBA2Timeline::B] - b) * t; + a += (_frames[i + RGBA2Timeline::ENTRIES + RGBA2Timeline::A] - a) * t; + r2 += (_frames[i + RGBA2Timeline::ENTRIES + RGBA2Timeline::R2] - r2) * t; + g2 += (_frames[i + RGBA2Timeline::ENTRIES + RGBA2Timeline::G2] - g2) * t; + b2 += (_frames[i + RGBA2Timeline::ENTRIES + RGBA2Timeline::B2] - b2) * t; + break; + } + case RGBA2Timeline::STEPPED: { + r = _frames[i + RGBA2Timeline::R]; + g = _frames[i + RGBA2Timeline::G]; + b = _frames[i + RGBA2Timeline::B]; + a = _frames[i + RGBA2Timeline::A]; + r2 = _frames[i + RGBA2Timeline::R2]; + g2 = _frames[i + RGBA2Timeline::G2]; + b2 = _frames[i + RGBA2Timeline::B2]; + break; + } + default: { + r = getBezierValue(time, i, RGBA2Timeline::R, curveType - RGBA2Timeline::BEZIER); + g = getBezierValue(time, i, RGBA2Timeline::G, + curveType + RGBA2Timeline::BEZIER_SIZE - RGBA2Timeline::BEZIER); + b = getBezierValue(time, i, RGBA2Timeline::B, + curveType + RGBA2Timeline::BEZIER_SIZE * 2 - RGBA2Timeline::BEZIER); + a = getBezierValue(time, i, RGBA2Timeline::A, + curveType + RGBA2Timeline::BEZIER_SIZE * 3 - RGBA2Timeline::BEZIER); + r2 = getBezierValue(time, i, RGBA2Timeline::R2, + curveType + RGBA2Timeline::BEZIER_SIZE * 4 - RGBA2Timeline::BEZIER); + g2 = getBezierValue(time, i, RGBA2Timeline::G2, + curveType + RGBA2Timeline::BEZIER_SIZE * 5 - RGBA2Timeline::BEZIER); + b2 = getBezierValue(time, i, RGBA2Timeline::B2, + curveType + RGBA2Timeline::BEZIER_SIZE * 6 - RGBA2Timeline::BEZIER); + } + } + Color &light = slot->_color, &dark = slot->_darkColor; + if (alpha == 1) { + light.set(r, g, b, a); + dark.set(r2, g2, b2); + } else { + if (blend == MixBlend_Setup) { + light.set(slot->_data._color); + dark.set(slot->_data._darkColor); + } + light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha); + dark.r += (r2 - dark.r) * alpha; + dark.g += (g2 - dark.g) * alpha; + dark.b += (b2 - dark.b) * alpha; + } +} + +void RGBA2Timeline::setFrame(int frame, float time, float r, float g, float b, float a, float r2, float g2, float b2) { + frame *= ENTRIES; + _frames[frame] = time; + _frames[frame + R] = r; + _frames[frame + G] = g; + _frames[frame + B] = b; + _frames[frame + A] = a; + _frames[frame + R2] = r2; + _frames[frame + G2] = g2; + _frames[frame + B2] = b2; +} + +RTTI_IMPL(RGB2Timeline, CurveTimeline) + +RGB2Timeline::RGB2Timeline(size_t frameCount, size_t bezierCount, int slotIndex) : CurveTimeline(frameCount, + RGB2Timeline::ENTRIES, + bezierCount), + _slotIndex(slotIndex) { + PropertyId ids[] = {((PropertyId) Property_Rgb << 32) | slotIndex, + ((PropertyId) Property_Rgb2 << 32) | slotIndex}; + setPropertyIds(ids, 2); +} + +RGB2Timeline::~RGB2Timeline() { +} + +void RGB2Timeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Slot *slot = skeleton._slots[_slotIndex]; + if (!slot->_bone._active) return; + + if (time < _frames[0]) { + Color &light = slot->_color, &dark = slot->_darkColor, &setupLight = slot->_data._color, &setupDark = slot->_data._darkColor; + switch (blend) { + case MixBlend_Setup: + light.set(setupLight.r, setupLight.g, setupLight.b); + dark.set(setupDark.r, setupDark.g, setupDark.b); + return; + case MixBlend_First: + light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, + (setupLight.b - light.b) * alpha); + dark.r += (setupDark.r - dark.r) * alpha; + dark.g += (setupDark.g - dark.g) * alpha; + dark.b += (setupDark.b - dark.b) * alpha; + default: { + } + } + return; + } + + float r = 0, g = 0, b = 0, r2 = 0, g2 = 0, b2 = 0; + int i = Animation::search(_frames, time, RGB2Timeline::ENTRIES); + int curveType = (int) _curves[i / RGB2Timeline::ENTRIES]; + switch (curveType) { + case RGB2Timeline::LINEAR: { + float before = _frames[i]; + r = _frames[i + RGB2Timeline::R]; + g = _frames[i + RGB2Timeline::G]; + b = _frames[i + RGB2Timeline::B]; + r2 = _frames[i + RGB2Timeline::R2]; + g2 = _frames[i + RGB2Timeline::G2]; + b2 = _frames[i + RGB2Timeline::B2]; + float t = (time - before) / (_frames[i + RGB2Timeline::ENTRIES] - before); + r += (_frames[i + RGB2Timeline::ENTRIES + RGB2Timeline::R] - r) * t; + g += (_frames[i + RGB2Timeline::ENTRIES + RGB2Timeline::G] - g) * t; + b += (_frames[i + RGB2Timeline::ENTRIES + RGB2Timeline::B] - b) * t; + r2 += (_frames[i + RGB2Timeline::ENTRIES + RGB2Timeline::R2] - r2) * t; + g2 += (_frames[i + RGB2Timeline::ENTRIES + RGB2Timeline::G2] - g2) * t; + b2 += (_frames[i + RGB2Timeline::ENTRIES + RGB2Timeline::B2] - b2) * t; + break; + } + case RGB2Timeline::STEPPED: { + r = _frames[i + RGB2Timeline::R]; + g = _frames[i + RGB2Timeline::G]; + b = _frames[i + RGB2Timeline::B]; + r2 = _frames[i + RGB2Timeline::R2]; + g2 = _frames[i + RGB2Timeline::G2]; + b2 = _frames[i + RGB2Timeline::B2]; + break; + } + default: { + r = getBezierValue(time, i, RGB2Timeline::R, curveType - RGB2Timeline::BEZIER); + g = getBezierValue(time, i, RGB2Timeline::G, + curveType + RGB2Timeline::BEZIER_SIZE - RGB2Timeline::BEZIER); + b = getBezierValue(time, i, RGB2Timeline::B, + curveType + RGB2Timeline::BEZIER_SIZE * 2 - RGB2Timeline::BEZIER); + r2 = getBezierValue(time, i, RGB2Timeline::R2, + curveType + RGB2Timeline::BEZIER_SIZE * 4 - RGB2Timeline::BEZIER); + g2 = getBezierValue(time, i, RGB2Timeline::G2, + curveType + RGB2Timeline::BEZIER_SIZE * 5 - RGB2Timeline::BEZIER); + b2 = getBezierValue(time, i, RGB2Timeline::B2, + curveType + RGB2Timeline::BEZIER_SIZE * 6 - RGB2Timeline::BEZIER); + } + } + Color &light = slot->_color, &dark = slot->_darkColor; + if (alpha == 1) { + light.set(r, g, b); + dark.set(r2, g2, b2); + } else { + if (blend == MixBlend_Setup) { + light.set(slot->_data._color.r, slot->_data._color.g, slot->_data._color.b); + dark.set(slot->_data._darkColor); + } + light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha); + dark.r += (r2 - dark.r) * alpha; + dark.g += (g2 - dark.g) * alpha; + dark.b += (b2 - dark.b) * alpha; + } +} + +void RGB2Timeline::setFrame(int frame, float time, float r, float g, float b, float r2, float g2, float b2) { + frame *= ENTRIES; + _frames[frame] = time; + _frames[frame + R] = r; + _frames[frame + G] = g; + _frames[frame + B] = b; + _frames[frame + R2] = r2; + _frames[frame + G2] = g2; + _frames[frame + B2] = b2; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/ColorTimeline.h b/native/cocos/editor-support/spine/4.2/spine/ColorTimeline.h new file mode 100644 index 0000000000..7d643d8b70 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ColorTimeline.h @@ -0,0 +1,204 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_ColorTimeline_h +#define Spine_ColorTimeline_h + +#include + +namespace spine { + class SP_API RGBATimeline : public CurveTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit RGBATimeline(size_t frameCount, size_t bezierCount, int slotIndex); + + virtual ~RGBATimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frame, float time, float r, float g, float b, float a); + + int getSlotIndex() { return _slotIndex; }; + + void setSlotIndex(int inValue) { _slotIndex = inValue; } + #ifndef __EMSCRIPTEN__ + protected: + #endif + int _slotIndex; + + static const int ENTRIES; + static const int R = 1; + static const int G = 2; + static const int B = 3; + static const int A = 4; + }; + + class SP_API RGBTimeline : public CurveTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit RGBTimeline(size_t frameCount, size_t bezierCount, int slotIndex); + + virtual ~RGBTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frame, float time, float r, float g, float b); + + int getSlotIndex() { return _slotIndex; }; + + void setSlotIndex(int inValue) { _slotIndex = inValue; } + #ifndef __EMSCRIPTEN__ + protected: + #endif + int _slotIndex; + + static const int ENTRIES = 4; + static const int R = 1; + static const int G = 2; + static const int B = 3; + }; + + class SP_API AlphaTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit AlphaTimeline(size_t frameCount, size_t bezierCount, int slotIndex); + + virtual ~AlphaTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getSlotIndex() { return _slotIndex; }; + + void setSlotIndex(int inValue) { _slotIndex = inValue; } + #ifndef __EMSCRIPTEN__ + protected: + #endif + int _slotIndex; + }; + + class SP_API RGBA2Timeline : public CurveTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit RGBA2Timeline(size_t frameCount, size_t bezierCount, int slotIndex); + + virtual ~RGBA2Timeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frame, float time, float r, float g, float b, float a, float r2, float g2, float b2); + + int getSlotIndex() { return _slotIndex; }; + + void setSlotIndex(int inValue) { _slotIndex = inValue; } + #ifndef __EMSCRIPTEN__ + protected: + #endif + + int _slotIndex; + + static const int ENTRIES = 8; + static const int R = 1; + static const int G = 2; + static const int B = 3; + static const int A = 4; + static const int R2 = 5; + static const int G2 = 6; + static const int B2 = 7; + }; + + class SP_API RGB2Timeline : public CurveTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit RGB2Timeline(size_t frameCount, size_t bezierCount, int slotIndex); + + virtual ~RGB2Timeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frame, float time, float r, float g, float b, float r2, float g2, float b2); + + int getSlotIndex() { return _slotIndex; }; + + void setSlotIndex(int inValue) { _slotIndex = inValue; } + #ifndef __EMSCRIPTEN__ + protected: + #endif + + int _slotIndex; + + static const int ENTRIES = 7; + static const int R = 1; + static const int G = 2; + static const int B = 3; + static const int R2 = 4; + static const int G2 = 5; + static const int B2 = 6; + }; +} + +#endif /* Spine_ColorTimeline_h */ diff --git a/native/cocos/editor-support/spine/Constraint.cpp b/native/cocos/editor-support/spine/4.2/spine/Constraint.cpp similarity index 100% rename from native/cocos/editor-support/spine/Constraint.cpp rename to native/cocos/editor-support/spine/4.2/spine/Constraint.cpp diff --git a/native/cocos/editor-support/spine/4.2/spine/Constraint.h b/native/cocos/editor-support/spine/4.2/spine/Constraint.h new file mode 100644 index 0000000000..462a4b2ae0 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Constraint.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * Spine Runtimes Software License v2.5 + * + * Copyright (c) 2013-2016, Esoteric Software + * All rights reserved. + * + * You are granted a perpetual, non-exclusive, non-sublicensable, and + * non-transferable license to use, install, execute, and perform the Spine + * Runtimes software and derivative works solely for personal or internal + * use. Without the written permission of Esoteric Software (see Section 2 of + * the Spine Software License Agreement), you may not (a) modify, translate, + * adapt, or develop new applications using the Spine Runtimes or otherwise + * create derivative works or improvements of the Spine Runtimes or (b) remove, + * delete, alter, or obscure any trademarks or any copyright, trademark, patent, + * or other intellectual property or proprietary rights notices on or in the + * Software, including any copy thereof. Redistributions in binary or source + * form must include this license and terms. + * + * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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 THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#ifndef Spine_Constraint_h +#define Spine_Constraint_h + +#include + +namespace spine { +/// The interface for all constraints. +class SP_API Constraint : public Updatable { + RTTI_DECL + +public: + Constraint(); + + virtual ~Constraint(); + + /// The ordinal for the order a skeleton's constraints will be applied. + virtual int getOrder() = 0; +}; +} // namespace spine + +#endif /* Spine_Constraint_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/ConstraintData.cpp b/native/cocos/editor-support/spine/4.2/spine/ConstraintData.cpp new file mode 100644 index 0000000000..6e48325950 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ConstraintData.cpp @@ -0,0 +1,60 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +using namespace spine; + +RTTI_IMPL_NOPARENT(ConstraintData) + +ConstraintData::ConstraintData(const String &name) : _name(name), _order(0), _skinRequired(false) { +} + +ConstraintData::~ConstraintData() { +} + +const String &ConstraintData::getName() { + return _name; +} + +size_t ConstraintData::getOrder() { + return _order; +} + +void ConstraintData::setOrder(size_t inValue) { + _order = inValue; +} + +bool ConstraintData::isSkinRequired() { + return _skinRequired; +} + +void ConstraintData::setSkinRequired(bool inValue) { + _skinRequired = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/ConstraintData.h b/native/cocos/editor-support/spine/4.2/spine/ConstraintData.h new file mode 100644 index 0000000000..91c618ab42 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ConstraintData.h @@ -0,0 +1,69 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Constraint_h +#define Spine_Constraint_h + +#include +#include + +namespace spine { + /// The interface for all constraints. + class SP_API ConstraintData : public SpineObject { + + friend class SkeletonBinary; + + RTTI_DECL + + public: + ConstraintData(const String &name); + + virtual ~ConstraintData(); + + /// The IK constraint's name, which is unique within the skeleton. + const String &getName(); + + /// The ordinal for the order a skeleton's constraints will be applied. + size_t getOrder(); + + void setOrder(size_t inValue); + + /// Whether the constraint is only active for a specific skin. + bool isSkinRequired(); + + void setSkinRequired(bool inValue); + + public: + const String _name; + size_t _order; + bool _skinRequired; + }; +} + +#endif /* Spine_Constraint_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/ContainerUtil.h b/native/cocos/editor-support/spine/4.2/spine/ContainerUtil.h new file mode 100644 index 0000000000..04fc24bbd5 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ContainerUtil.h @@ -0,0 +1,129 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_ContainerUtil_h +#define Spine_ContainerUtil_h + +#include +#include +#include +#include +#include + +#include + +namespace spine { + class SP_API ContainerUtil : public SpineObject { + public: + /// Finds an item by comparing each item's name. + /// It is more efficient to cache the results of this method than to call it multiple times. + /// @return May be NULL. + template + static T *findWithName(Vector &items, const String &name) { + assert(name.length() > 0); + + for (size_t i = 0; i < items.size(); ++i) { + T *item = items[i]; + if (item->getName() == name) { + return item; + } + } + + return NULL; + } + + /// @return -1 if the item was not found. + template + static int findIndexWithName(Vector &items, const String &name) { + assert(name.length() > 0); + + for (size_t i = 0, len = items.size(); i < len; ++i) { + T *item = items[i]; + if (item->getName() == name) { + return static_cast(i); + } + } + + return -1; + } + + /// Finds an item by comparing each item's name. + /// It is more efficient to cache the results of this method than to call it multiple times. + /// @return May be NULL. + template + static T *findWithDataName(Vector &items, const String &name) { + assert(name.length() > 0); + + for (size_t i = 0; i < items.size(); ++i) { + T *item = items[i]; + if (item->getData().getName() == name) { + return item; + } + } + + return NULL; + } + + /// @return -1 if the item was not found. + template + static int findIndexWithDataName(Vector &items, const String &name) { + assert(name.length() > 0); + + for (size_t i = 0, len = items.size(); i < len; ++i) { + T *item = items[i]; + if (item->getData().getName() == name) { + return static_cast(i); + } + } + + return -1; + } + + template + static void cleanUpVectorOfPointers(Vector &items) { + for (int i = (int) items.size() - 1; i >= 0; i--) { + T *item = items[i]; + + delete item; + + items.removeAt(i); + } + } + + private: + // ctor, copy ctor, and assignment should be private in a Singleton + ContainerUtil(); + + ContainerUtil(const ContainerUtil &); + + ContainerUtil &operator=(const ContainerUtil &); + }; +} + +#endif /* Spine_ContainerUtil_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/CurveTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/CurveTimeline.cpp new file mode 100644 index 0000000000..84b12742a5 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/CurveTimeline.cpp @@ -0,0 +1,253 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +using namespace spine; + +RTTI_IMPL(CurveTimeline, Timeline) + +CurveTimeline::CurveTimeline(size_t frameCount, size_t frameEntries, size_t bezierCount) : Timeline(frameCount, + frameEntries) { + _curves.setSize(frameCount + bezierCount * BEZIER_SIZE, 0); + _curves[frameCount - 1] = STEPPED; +} + +CurveTimeline::~CurveTimeline() { +} + +void CurveTimeline::setLinear(size_t frame) { + _curves[frame] = LINEAR; +} + +void CurveTimeline::setStepped(size_t frame) { + _curves[frame] = STEPPED; +} + +void CurveTimeline::setBezier(size_t bezier, size_t frame, float value, float time1, float value1, float cx1, float cy1, + float cx2, float cy2, float time2, float value2) { + size_t i = getFrameCount() + bezier * BEZIER_SIZE; + if (value == 0) _curves[frame] = BEZIER + i; + float tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = (value1 - cy1 * 2 + cy2) * 0.03; + float dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = ((cy1 - cy2) * 3 - value1 + value2) * 0.006; + float ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy; + float dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = (cy1 - value1) * 0.3 + tmpy + dddy * 0.16666667; + float x = time1 + dx, y = value1 + dy; + for (size_t n = i + BEZIER_SIZE; i < n; i += 2) { + _curves[i] = x; + _curves[i + 1] = y; + dx += ddx; + dy += ddy; + ddx += dddx; + ddy += dddy; + x += dx; + y += dy; + } +} + +float CurveTimeline::getBezierValue(float time, size_t frameIndex, size_t valueOffset, size_t i) { + if (_curves[i] > time) { + float x = _frames[frameIndex], y = _frames[frameIndex + valueOffset]; + return y + (time - x) / (_curves[i] - x) * (_curves[i + 1] - y); + } + size_t n = i + BEZIER_SIZE; + for (i += 2; i < n; i += 2) { + if (_curves[i] >= time) { + float x = _curves[i - 2], y = _curves[i - 1]; + return y + (time - x) / (_curves[i] - x) * (_curves[i + 1] - y); + } + } + frameIndex += getFrameEntries(); + float x = _curves[n - 2], y = _curves[n - 1]; + return y + (time - x) / (_frames[frameIndex] - x) * (_frames[frameIndex + valueOffset] - y); +} + +Vector &CurveTimeline::getCurves() { + return _curves; +} + +RTTI_IMPL(CurveTimeline1, CurveTimeline) + +CurveTimeline1::CurveTimeline1(size_t frameCount, size_t bezierCount) : CurveTimeline(frameCount, + CurveTimeline1::ENTRIES, + bezierCount) { +} + +CurveTimeline1::~CurveTimeline1() { +} + +void CurveTimeline1::setFrame(size_t frame, float time, float value) { + frame <<= 1; + _frames[frame] = time; + _frames[frame + CurveTimeline1::VALUE] = value; +} + +float CurveTimeline1::getCurveValue(float time) { + int i = (int) _frames.size() - 2; + for (int ii = 2; ii <= i; ii += 2) { + if (_frames[ii] > time) { + i = ii - 2; + break; + } + } + + int curveType = (int) _curves[i >> 1]; + switch (curveType) { + case CurveTimeline::LINEAR: { + float before = _frames[i], value = _frames[i + CurveTimeline1::VALUE]; + return value + (time - before) / (_frames[i + CurveTimeline1::ENTRIES] - before) * + (_frames[i + CurveTimeline1::ENTRIES + CurveTimeline1::VALUE] - value); + } + case CurveTimeline::STEPPED: + return _frames[i + CurveTimeline1::VALUE]; + } + return getBezierValue(time, i, CurveTimeline1::VALUE, curveType - CurveTimeline1::BEZIER); +} + +float CurveTimeline1::getRelativeValue(float time, float alpha, MixBlend blend, float current, float setup) { + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + return setup; + case MixBlend_First: + return current + (setup - current) * alpha; + default: + return current; + } + } + float value = getCurveValue(time); + switch (blend) { + case MixBlend_Setup: + return setup + value * alpha; + case MixBlend_First: + case MixBlend_Replace: + value += setup - current; + break; + case MixBlend_Add: + break; + } + return current + value * alpha; +} + +float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup) { + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + return setup; + case MixBlend_First: + return current + (setup - current) * alpha; + default: + return current; + } + } + float value = getCurveValue(time); + if (blend == MixBlend_Setup) return setup + (value - setup) * alpha; + return current + (value - current) * alpha; +} + +float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup, float value) { + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + return setup; + case MixBlend_First: + return current + (setup - current) * alpha; + default: + return current; + } + } + if (blend == MixBlend_Setup) return setup + (value - setup) * alpha; + return current + (value - current) * alpha; +} + +float CurveTimeline1::getScaleValue(float time, float alpha, MixBlend blend, MixDirection direction, float current, + float setup) { + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + return setup; + case MixBlend_First: + return current + (setup - current) * alpha; + default: + return current; + } + } + float value = getCurveValue(time) * setup; + if (alpha == 1) { + if (blend == MixBlend_Add) return current + value - setup; + return value; + } + // Mixing out uses sign of setup or current pose, else use sign of key. + if (direction == MixDirection_Out) { + switch (blend) { + case MixBlend_Setup: + return setup + (MathUtil::abs(value) * MathUtil::sign(setup) - setup) * alpha; + case MixBlend_First: + case MixBlend_Replace: + return current + (MathUtil::abs(value) * MathUtil::sign(current) - current) * alpha; + default: + break; + } + } else { + float s; + switch (blend) { + case MixBlend_Setup: + s = MathUtil::abs(setup) * MathUtil::sign(value); + return s + (value - s) * alpha; + case MixBlend_First: + case MixBlend_Replace: + s = MathUtil::abs(current) * MathUtil::sign(value); + return s + (value - s) * alpha; + default: + break; + } + } + return current + (value - setup) * alpha; +} + +const int CurveTimeline2::ENTRIES = 3; + +RTTI_IMPL(CurveTimeline2, CurveTimeline) + +CurveTimeline2::CurveTimeline2(size_t frameCount, size_t bezierCount) : CurveTimeline(frameCount, + CurveTimeline2::ENTRIES, + bezierCount) { +} + +CurveTimeline2::~CurveTimeline2() { +} + +void CurveTimeline2::setFrame(size_t frame, float time, float value1, float value2) { + frame *= CurveTimeline2::ENTRIES; + _frames[frame] = time; + _frames[frame + CurveTimeline2::VALUE1] = value1; + _frames[frame + CurveTimeline2::VALUE2] = value2; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/CurveTimeline.h b/native/cocos/editor-support/spine/4.2/spine/CurveTimeline.h new file mode 100644 index 0000000000..5b575d1251 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/CurveTimeline.h @@ -0,0 +1,114 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_CurveTimeline_h +#define Spine_CurveTimeline_h + +#include +#include + +namespace spine { + /// Base class for frames that use an interpolation bezier curve. + class SP_API CurveTimeline : public Timeline { + RTTI_DECL + + public: + explicit CurveTimeline(size_t frameCount, size_t frameEntries, size_t bezierCount); + + virtual ~CurveTimeline(); + + void setLinear(size_t frame); + + void setStepped(size_t frame); + + virtual void + setBezier(size_t bezier, size_t frame, float value, float time1, float value1, float cx1, float cy1, float cx2, + float cy2, float time2, float value2); + + float getBezierValue(float time, size_t frame, size_t valueOffset, size_t i); + + Vector &getCurves(); + + #ifndef __EMSCRIPTEN__ + protected: + #endif + static const int LINEAR = 0; + static const int STEPPED = 1; + static const int BEZIER = 2; + static const int BEZIER_SIZE = 18; + + Vector _curves; // type, x, y, ... + }; + + class SP_API CurveTimeline1 : public CurveTimeline { + RTTI_DECL + + public: + explicit CurveTimeline1(size_t frameCount, size_t bezierCount); + + virtual ~CurveTimeline1(); + + void setFrame(size_t frame, float time, float value); + + float getCurveValue(float time); + + float getRelativeValue(float time, float alpha, MixBlend blend, float current, float setup); + + float getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup); + + float getAbsoluteValue (float time, float alpha, MixBlend blend, float current, float setup, float value); + + float getScaleValue (float time, float alpha, MixBlend blend, MixDirection direction, float current, float setup); + #ifndef __EMSCRIPTEN__ + protected: + #endif + static const int ENTRIES = 2; + static const int VALUE = 1; + }; + + class SP_API CurveTimeline2 : public CurveTimeline { + RTTI_DECL + + public: + explicit CurveTimeline2(size_t frameCount, size_t bezierCount); + + virtual ~CurveTimeline2(); + + void setFrame(size_t frame, float time, float value1, float value2); + + #ifndef __EMSCRIPTEN__ + protected: + #endif + static const int ENTRIES; + static const int VALUE1 = 1; + static const int VALUE2 = 2; + }; +} + +#endif /* Spine_CurveTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Debug.h b/native/cocos/editor-support/spine/4.2/spine/Debug.h new file mode 100644 index 0000000000..68baf3870d --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Debug.h @@ -0,0 +1,139 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef SPINE_LOG_H +#define SPINE_LOG_H + +#include +#include + +#include + +namespace spine { + + class SP_API DebugExtension : public SpineExtension { + struct Allocation { + void *address; + size_t size; + const char *fileName; + int line; + + Allocation() : address(NULL), size(0), fileName(NULL), line(0) { + } + + Allocation(void *a, size_t s, const char *f, int l) : address(a), size(s), fileName(f), line(l) { + } + }; + + public: + DebugExtension(SpineExtension *extension) : _extension(extension), _allocations(0), _reallocations(0), + _frees(0) { + } + + void reportLeaks() { + for (std::map::iterator it = _allocated.begin(); it != _allocated.end(); it++) { + printf("\"%s:%i (%zu bytes at %p)\n", it->second.fileName, it->second.line, it->second.size, + it->second.address); + } + printf("allocations: %zu, reallocations: %zu, frees: %zu\n", _allocations, _reallocations, _frees); + if (_allocated.empty()) printf("No leaks detected\n"); + } + + void clearAllocations() { + _allocated.clear(); + _usedMemory = 0; + } + + virtual void *_alloc(size_t size, const char *file, int line) { + void *result = _extension->_alloc(size, file, line); + _allocated[result] = Allocation(result, size, file, line); + _allocations++; + _usedMemory += size; + return result; + } + + virtual void *_calloc(size_t size, const char *file, int line) { + void *result = _extension->_calloc(size, file, line); + _allocated[result] = Allocation(result, size, file, line); + _allocations++; + _usedMemory += size; + return result; + } + + virtual void *_realloc(void *ptr, size_t size, const char *file, int line) { + if (_allocated.count(ptr)) _usedMemory -= _allocated[ptr].size; + _allocated.erase(ptr); + void *result = _extension->_realloc(ptr, size, file, line); + _reallocations++; + _allocated[result] = Allocation(result, size, file, line); + _usedMemory += size; + return result; + } + + virtual void _free(void *mem, const char *file, int line) { + if (_allocated.count(mem)) { + _extension->_free(mem, file, line); + _frees++; + _usedMemory -= _allocated[mem].size; + _allocated.erase(mem); + return; + } + + printf("%s:%i (address %p): Double free or not allocated through SpineExtension\n", file, line, mem); + _extension->_free(mem, file, line); + } + + virtual char *_readFile(const String &path, int *length) { + auto data = _extension->_readFile(path, length); + + if (_allocated.count(data) == 0) { + _allocated[data] = Allocation(data, sizeof(char) * (*length), nullptr, 0); + _allocations++; + _usedMemory += sizeof(char) * (*length); + } + + return data; + } + + size_t getUsedMemory() { + return _usedMemory; + } + + private: + SpineExtension *_extension; + std::map _allocated; + size_t _allocations; + size_t _reallocations; + size_t _frees; + size_t _usedMemory; + }; +} + + +#endif //SPINE_LOG_H diff --git a/native/cocos/editor-support/spine/4.2/spine/DeformTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/DeformTimeline.cpp new file mode 100644 index 0000000000..92aabd416d --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/DeformTimeline.cpp @@ -0,0 +1,328 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include + +#include +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(DeformTimeline, CurveTimeline) + +DeformTimeline::DeformTimeline(size_t frameCount, size_t bezierCount, int slotIndex, VertexAttachment *attachment) + : CurveTimeline(frameCount, 1, bezierCount), _slotIndex(slotIndex), _attachment(attachment) { + PropertyId ids[] = {((PropertyId) Property_Deform << 32) | ((slotIndex << 16 | attachment->_id) & 0xffffffff)}; + setPropertyIds(ids, 1); + + _vertices.ensureCapacity(frameCount); + for (size_t i = 0; i < frameCount; ++i) { + Vector vec; + _vertices.add(vec); + } +} + +void DeformTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Slot *slotP = skeleton._slots[_slotIndex]; + Slot &slot = *slotP; + if (!slot._bone.isActive()) return; + + Attachment *slotAttachment = slot.getAttachment(); + if (slotAttachment == NULL || !slotAttachment->getRTTI().instanceOf(VertexAttachment::rtti)) { + return; + } + + VertexAttachment *attachment = static_cast(slotAttachment); + if (attachment->_timelineAttachment != _attachment) { + return; + } + + Vector &deformArray = slot._deform; + if (deformArray.size() == 0) { + blend = MixBlend_Setup; + } + + Vector> &vertices = _vertices; + size_t vertexCount = vertices[0].size(); + + Vector &frames = _frames; + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + deformArray.clear(); + return; + case MixBlend_First: { + if (alpha == 1) { + deformArray.clear(); + return; + } + deformArray.setSize(vertexCount, 0); + Vector &deform = deformArray; + if (attachment->getBones().size() == 0) { + // Unweighted vertex positions. + Vector &setupVertices = attachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) + deform[i] += (setupVertices[i] - deform[i]) * alpha; + } else { + // Weighted deform offsets. + alpha = 1 - alpha; + for (size_t i = 0; i < vertexCount; i++) + deform[i] *= alpha; + } + } + case MixBlend_Replace: + case MixBlend_Add: { + } + } + return; + } + + deformArray.setSize(vertexCount, 0); + Vector &deform = deformArray; + + if (time >= frames[frames.size() - 1]) {// Time is after last frame. + Vector &lastVertices = vertices[frames.size() - 1]; + if (alpha == 1) { + if (blend == MixBlend_Add) { + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, no alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) + deform[i] += lastVertices[i] - setupVertices[i]; + } else { + // Weighted deform offsets, no alpha. + for (size_t i = 0; i < vertexCount; i++) + deform[i] += lastVertices[i]; + } + } else { + // Vertex positions or deform offsets, no alpha. + memcpy(deform.buffer(), lastVertices.buffer(), vertexCount * sizeof(float)); + } + } else { + switch (blend) { + case MixBlend_Setup: { + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, with alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) { + float setup = setupVertices[i]; + deform[i] = setup + (lastVertices[i] - setup) * alpha; + } + } else { + // Weighted deform offsets, with alpha. + for (size_t i = 0; i < vertexCount; i++) + deform[i] = lastVertices[i] * alpha; + } + break; + } + case MixBlend_First: + case MixBlend_Replace: + // Vertex positions or deform offsets, with alpha. + for (size_t i = 0; i < vertexCount; i++) + deform[i] += (lastVertices[i] - deform[i]) * alpha; + break; + case MixBlend_Add: + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, no alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) + deform[i] += (lastVertices[i] - setupVertices[i]) * alpha; + } else { + // Weighted deform offsets, alpha. + for (size_t i = 0; i < vertexCount; i++) + deform[i] += lastVertices[i] * alpha; + } + } + } + return; + } + + // Interpolate between the previous frame and the current frame. + int frame = Animation::search(frames, time); + float percent = getCurvePercent(time, frame); + Vector &prevVertices = vertices[frame]; + Vector &nextVertices = vertices[frame + 1]; + + if (alpha == 1) { + if (blend == MixBlend_Add) { + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, no alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i]; + } + } else { + // Weighted deform offsets, no alpha. + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] += prev + (nextVertices[i] - prev) * percent; + } + } + } else { + // Vertex positions or deform offsets, no alpha. + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] = prev + (nextVertices[i] - prev) * percent; + } + } + } else { + switch (blend) { + case MixBlend_Setup: { + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, with alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i], setup = setupVertices[i]; + deform[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; + } + } else { + // Weighted deform offsets, with alpha. + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; + } + } + break; + } + case MixBlend_First: + case MixBlend_Replace: + // Vertex positions or deform offsets, with alpha. + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] += (prev + (nextVertices[i] - prev) * percent - deform[i]) * alpha; + } + break; + case MixBlend_Add: + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, with alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; + } + } else { + // Weighted deform offsets, with alpha. + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; + } + } + } + } +} + +void DeformTimeline::setBezier(size_t bezier, size_t frame, float value, float time1, float value1, float cx1, float cy1, + float cx2, float cy2, float time2, float value2) { + SP_UNUSED(value1); + SP_UNUSED(value2); + size_t i = getFrameCount() + bezier * DeformTimeline::BEZIER_SIZE; + if (value == 0) _curves[frame] = DeformTimeline::BEZIER + i; + float tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = cy2 * 0.03 - cy1 * 0.06; + float dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = (cy1 - cy2 + 0.33333333) * 0.018; + float ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy; + float dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = cy1 * 0.3 + tmpy + dddy * 0.16666667; + float x = time1 + dx, y = dy; + for (size_t n = i + DeformTimeline::BEZIER_SIZE; i < n; i += 2) { + _curves[i] = x; + _curves[i + 1] = y; + dx += ddx; + dy += ddy; + ddx += dddx; + ddy += dddy; + x += dx; + y += dy; + } +} + +float DeformTimeline::getCurvePercent(float time, int frame) { + int i = (int) _curves[frame]; + switch (i) { + case DeformTimeline::LINEAR: { + float x = _frames[frame]; + return (time - x) / (_frames[frame + getFrameEntries()] - x); + } + case DeformTimeline::STEPPED: { + return 0; + } + default: { + } + } + i -= DeformTimeline::BEZIER; + if (_curves[i] > time) { + float x = _frames[frame]; + return _curves[i + 1] * (time - x) / (_curves[i] - x); + } + int n = i + DeformTimeline::BEZIER_SIZE; + for (i += 2; i < n; i += 2) { + if (_curves[i] >= time) { + float x = _curves[i - 2], y = _curves[i - 1]; + return y + (time - x) / (_curves[i] - x) * (_curves[i + 1] - y); + } + } + float x = _curves[n - 2], y = _curves[n - 1]; + return y + (1 - y) * (time - x) / (_frames[frame + getFrameEntries()] - x); +} + +void DeformTimeline::setFrame(int frame, float time, Vector &vertices) { + _frames[frame] = time; + _vertices[frame].clear(); + _vertices[frame].addAll(vertices); +} + +Vector> &DeformTimeline::getVertices() { + return _vertices; +} + +VertexAttachment *DeformTimeline::getAttachment() { + return _attachment; +} + +void DeformTimeline::setAttachment(VertexAttachment *inValue) { + _attachment = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/DeformTimeline.h b/native/cocos/editor-support/spine/4.2/spine/DeformTimeline.h new file mode 100644 index 0000000000..278eccf32b --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/DeformTimeline.h @@ -0,0 +1,81 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_DeformTimeline_h +#define Spine_DeformTimeline_h + +#include + +namespace spine { + class VertexAttachment; + + class SP_API DeformTimeline : public CurveTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit DeformTimeline(size_t frameCount, size_t bezierCount, int slotIndex, VertexAttachment *attachment); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, Vector &vertices); + + Vector > &getVertices(); + + VertexAttachment *getAttachment(); + + void setAttachment(VertexAttachment *inValue); + + virtual void + setBezier(size_t bezier, size_t frame, float value, float time1, float value1, float cx1, float cy1, float cx2, + float cy2, float time2, float value2); + + float getCurvePercent(float time, int frame); + + int getSlotIndex() { return _slotIndex; } + + void setSlotIndex(int inValue) { _slotIndex = inValue; } + #ifndef __EMSCRIPTEN__ + protected: + #endif + int _slotIndex; + + Vector > _vertices; + + VertexAttachment *_attachment; + }; +} + +#endif /* Spine_DeformTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/DrawOrderTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/DrawOrderTimeline.cpp new file mode 100644 index 0000000000..04671a30d0 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/DrawOrderTimeline.cpp @@ -0,0 +1,102 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(DrawOrderTimeline, Timeline) + +DrawOrderTimeline::DrawOrderTimeline(size_t frameCount) : Timeline(frameCount, 1) { + PropertyId ids[] = {((PropertyId) Property_DrawOrder << 32)}; + setPropertyIds(ids, 1); + + _drawOrders.ensureCapacity(frameCount); + for (size_t i = 0; i < frameCount; ++i) { + Vector vec; + _drawOrders.add(vec); + } +} + +void DrawOrderTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(alpha); + + Vector &drawOrder = skeleton._drawOrder; + Vector &slots = skeleton._slots; + if (direction == MixDirection_Out) { + if (blend == MixBlend_Setup) { + drawOrder.clear(); + drawOrder.ensureCapacity(slots.size()); + for (size_t i = 0, n = slots.size(); i < n; ++i) + drawOrder.add(slots[i]); + } + return; + } + + if (time < _frames[0]) { + if (blend == MixBlend_Setup || blend == MixBlend_First) { + drawOrder.clear(); + drawOrder.ensureCapacity(slots.size()); + for (size_t i = 0, n = slots.size(); i < n; ++i) + drawOrder.add(slots[i]); + } + return; + } + + Vector &drawOrderToSetupIndex = _drawOrders[Animation::search(_frames, time)]; + if (drawOrderToSetupIndex.size() == 0) { + drawOrder.clear(); + for (size_t i = 0, n = slots.size(); i < n; ++i) + drawOrder.add(slots[i]); + } else { + for (size_t i = 0, n = drawOrderToSetupIndex.size(); i < n; ++i) + drawOrder[i] = slots[drawOrderToSetupIndex[i]]; + } +} + +void DrawOrderTimeline::setFrame(size_t frame, float time, Vector &drawOrder) { + _frames[frame] = time; + _drawOrders[frame].clear(); + _drawOrders[frame].addAll(drawOrder); +} + +Vector> &DrawOrderTimeline::getDrawOrders() { + return _drawOrders; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/DrawOrderTimeline.h b/native/cocos/editor-support/spine/4.2/spine/DrawOrderTimeline.h new file mode 100644 index 0000000000..67220d0d82 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/DrawOrderTimeline.h @@ -0,0 +1,61 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_DrawOrderTimeline_h +#define Spine_DrawOrderTimeline_h + +#include + +namespace spine { + class SP_API DrawOrderTimeline : public Timeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit DrawOrderTimeline(size_t frameCount); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time and value of the specified keyframe. + /// @param drawOrder May be NULL to use bind pose draw order + void setFrame(size_t frame, float time, Vector &drawOrder); + + Vector > &getDrawOrders(); + + private: + Vector > _drawOrders; + }; +} + +#endif /* Spine_DrawOrderTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Event.cpp b/native/cocos/editor-support/spine/4.2/spine/Event.cpp new file mode 100644 index 0000000000..ae4eac0bc9 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Event.cpp @@ -0,0 +1,90 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +spine::Event::Event(float time, const spine::EventData &data) : _data(data), + _time(time), + _intValue(0), + _floatValue(0), + _stringValue(), + _volume(1), + _balance(0) { +} + +const spine::EventData &spine::Event::getData() { + return _data; +} + +float spine::Event::getTime() { + return _time; +} + +int spine::Event::getIntValue() { + return _intValue; +} + +void spine::Event::setIntValue(int inValue) { + _intValue = inValue; +} + +float spine::Event::getFloatValue() { + return _floatValue; +} + +void spine::Event::setFloatValue(float inValue) { + _floatValue = inValue; +} + +const spine::String &spine::Event::getStringValue() { + return _stringValue; +} + +void spine::Event::setStringValue(const spine::String &inValue) { + _stringValue = inValue; +} + + +float spine::Event::getVolume() { + return _volume; +} + +void spine::Event::setVolume(float inValue) { + _volume = inValue; +} + +float spine::Event::getBalance() { + return _balance; +} + +void spine::Event::setBalance(float inValue) { + _balance = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Event.h b/native/cocos/editor-support/spine/4.2/spine/Event.h new file mode 100644 index 0000000000..aa79ffcb7d --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Event.h @@ -0,0 +1,88 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Event_h +#define Spine_Event_h + +#include +#include + +namespace spine { + class EventData; + +/// Stores the current pose values for an Event. + class SP_API Event : public SpineObject { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class AnimationState; + + public: + Event(float time, const EventData &data); + + const EventData &getData(); + + /// The animation time this event was keyed. + float getTime(); + + int getIntValue(); + + void setIntValue(int inValue); + + float getFloatValue(); + + void setFloatValue(float inValue); + + const String &getStringValue(); + + void setStringValue(const String &inValue); + + float getVolume(); + + void setVolume(float inValue); + + float getBalance(); + + void setBalance(float inValue); + + #ifndef __EMSCRIPTEN__ + private: + #endif + const EventData &_data; + const float _time; + int _intValue; + float _floatValue; + String _stringValue; + float _volume; + float _balance; + }; +} + +#endif /* Spine_Event_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/EventData.cpp b/native/cocos/editor-support/spine/4.2/spine/EventData.cpp new file mode 100644 index 0000000000..16d75fd74a --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/EventData.cpp @@ -0,0 +1,96 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +spine::EventData::EventData(const spine::String &name) : _name(name), + _intValue(0), + _floatValue(0), + _stringValue(), + _audioPath(), + _volume(1), + _balance(0) { + assert(_name.length() > 0); +} + +/// The name of the event, which is unique within the skeleton. +const spine::String &spine::EventData::getName() const { + return _name; +} + +int spine::EventData::getIntValue() const { + return _intValue; +} + +void spine::EventData::setIntValue(int inValue) { + _intValue = inValue; +} + +float spine::EventData::getFloatValue() const { + return _floatValue; +} + +void spine::EventData::setFloatValue(float inValue) { + _floatValue = inValue; +} + +const spine::String &spine::EventData::getStringValue() const { + return _stringValue; +} + +void spine::EventData::setStringValue(const spine::String &inValue) { + this->_stringValue = inValue; +} + +const spine::String &spine::EventData::getAudioPath() const { + return _audioPath; +} + +void spine::EventData::setAudioPath(const spine::String &inValue) { + _audioPath = inValue; +} + + +float spine::EventData::getVolume() const { + return _volume; +} + +void spine::EventData::setVolume(float inValue) { + _volume = inValue; +} + +float spine::EventData::getBalance() const { + return _balance; +} + +void spine::EventData::setBalance(float inValue) { + _balance = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/EventData.h b/native/cocos/editor-support/spine/4.2/spine/EventData.h new file mode 100644 index 0000000000..f734eb6292 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/EventData.h @@ -0,0 +1,88 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_EventData_h +#define Spine_EventData_h + +#include +#include + +namespace spine { +/// Stores the setup pose values for an Event. + class SP_API EventData : public SpineObject { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class Event; + + public: + explicit EventData(const String &name); + + /// The name of the event, which is unique within the skeleton. + const String &getName() const; + + int getIntValue() const; + + void setIntValue(int inValue); + + float getFloatValue() const; + + void setFloatValue(float inValue); + + const String &getStringValue() const; + + void setStringValue(const String &inValue); + + const String &getAudioPath() const; + + void setAudioPath(const String &inValue); + + float getVolume() const; + + void setVolume(float inValue); + + float getBalance() const; + + void setBalance(float inValue); + + #ifndef __EMSCRIPTEN__ + private: + #endif + const String _name; + int _intValue; + float _floatValue; + String _stringValue; + String _audioPath; + float _volume; + float _balance; + }; +} + +#endif /* Spine_EventData_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/EventTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/EventTimeline.cpp new file mode 100644 index 0000000000..a588608765 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/EventTimeline.cpp @@ -0,0 +1,99 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace spine; + +RTTI_IMPL(EventTimeline, Timeline) + +EventTimeline::EventTimeline(size_t frameCount) : Timeline(frameCount, 1) { + PropertyId ids[] = {((PropertyId) Property_Event << 32)}; + setPropertyIds(ids, 1); + _events.setSize(frameCount, NULL); +} + +EventTimeline::~EventTimeline() { + ContainerUtil::cleanUpVectorOfPointers(_events); +} + +void EventTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + if (pEvents == NULL) return; + + Vector &events = *pEvents; + + size_t frameCount = _frames.size(); + + if (lastTime > time) { + // Fire events after last time for looped animations. + apply(skeleton, lastTime, FLT_MAX, pEvents, alpha, blend, direction); + lastTime = -1.0f; + } else if (lastTime >= _frames[frameCount - 1]) { + // Last time is after last i. + return; + } + + if (time < _frames[0]) return;// Time is before first i. + + int i; + if (lastTime < _frames[0]) { + i = 0; + } else { + i = Animation::search(_frames, lastTime) + 1; + float frameTime = _frames[i]; + while (i > 0) { + // Fire multiple events with the same i. + if (_frames[i - 1] != frameTime) break; + i--; + } + } + + for (; (size_t) i < frameCount && time >= _frames[i]; i++) + events.add(_events[i]); +} + +void EventTimeline::setFrame(size_t frame, Event *event) { + _frames[frame] = event->getTime(); + _events[frame] = event; +} + +Vector &EventTimeline::getEvents() { return _events; } diff --git a/native/cocos/editor-support/spine/4.2/spine/EventTimeline.h b/native/cocos/editor-support/spine/4.2/spine/EventTimeline.h new file mode 100644 index 0000000000..ca1f6ef0b5 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/EventTimeline.h @@ -0,0 +1,62 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_EventTimeline_h +#define Spine_EventTimeline_h + +#include + +namespace spine { + class SP_API EventTimeline : public Timeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit EventTimeline(size_t frameCount); + + ~EventTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time and value of the specified keyframe. + void setFrame(size_t frame, Event *event); + + Vector &getEvents(); + + private: + Vector _events; + }; +} + +#endif /* Spine_EventTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Extension.cpp b/native/cocos/editor-support/spine/4.2/spine/Extension.cpp new file mode 100644 index 0000000000..3793e523d1 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Extension.cpp @@ -0,0 +1,127 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include + +#include + +using namespace spine; + +SpineExtension *SpineExtension::_instance = NULL; + +void SpineExtension::setInstance(SpineExtension *inValue) { + assert(inValue); + + _instance = inValue; +} + +SpineExtension *SpineExtension::getInstance() { + if (!_instance) _instance = spine::getDefaultExtension(); + assert(_instance); + + return _instance; +} + +SpineExtension::~SpineExtension() { +} + +SpineExtension::SpineExtension() { +} + +DefaultSpineExtension::~DefaultSpineExtension() { +} + +void *DefaultSpineExtension::_alloc(size_t size, const char *file, int line) { + SP_UNUSED(file); + SP_UNUSED(line); + + if (size == 0) + return 0; + void *ptr = ::malloc(size); + return ptr; +} + +void *DefaultSpineExtension::_calloc(size_t size, const char *file, int line) { + SP_UNUSED(file); + SP_UNUSED(line); + + if (size == 0) + return 0; + + void *ptr = ::malloc(size); + if (ptr) { + memset(ptr, 0, size); + } + return ptr; +} + +void *DefaultSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line) { + SP_UNUSED(file); + SP_UNUSED(line); + + void *mem = NULL; + if (size == 0) + return 0; + if (ptr == NULL) + mem = ::malloc(size); + else + mem = ::realloc(ptr, size); + return mem; +} + +void DefaultSpineExtension::_free(void *mem, const char *file, int line) { + SP_UNUSED(file); + SP_UNUSED(line); + + ::free(mem); +} + +char *DefaultSpineExtension::_readFile(const String &path, int *length) { +#ifndef __EMSCRIPTEN__ + char *data; + FILE *file = fopen(path.buffer(), "rb"); + if (!file) return 0; + + fseek(file, 0, SEEK_END); + *length = (int) ftell(file); + fseek(file, 0, SEEK_SET); + + data = SpineExtension::alloc(*length, __FILE__, __LINE__); + fread(data, 1, *length, file); + fclose(file); + + return data; +#else + return nullptr; +#endif +} + +DefaultSpineExtension::DefaultSpineExtension() : SpineExtension() { +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Extension.h b/native/cocos/editor-support/spine/4.2/spine/Extension.h new file mode 100644 index 0000000000..01b280641a --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Extension.h @@ -0,0 +1,125 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Extension_h +#define Spine_Extension_h + + +#include +#include + +#define SP_UNUSED(x) (void)(x) + +namespace spine { + class String; + + class SP_API SpineExtension { + public: + template + static T *alloc(size_t num, const char *file, int line) { + return (T *) getInstance()->_alloc(sizeof(T) * num, file, line); + } + + template + static T *calloc(size_t num, const char *file, int line) { + return (T *) getInstance()->_calloc(sizeof(T) * num, file, line); + } + + template + static T *realloc(T *ptr, size_t num, const char *file, int line) { + return (T *) getInstance()->_realloc(ptr, sizeof(T) * num, file, line); + } + + template + static void free(T *ptr, const char *file, int line) { + getInstance()->_free((void *) ptr, file, line); + } + + template + static void beforeFree(T *ptr) { + getInstance()->_beforeFree((void *) ptr); + } + + static char *readFile(const String &path, int *length) { + return getInstance()->_readFile(path, length); + } + + static void setInstance(SpineExtension *inSpineExtension); + + static SpineExtension *getInstance(); + + virtual ~SpineExtension(); + + /// Implement this function to use your own memory allocator + virtual void *_alloc(size_t size, const char *file, int line) = 0; + + virtual void *_calloc(size_t size, const char *file, int line) = 0; + + virtual void *_realloc(void *ptr, size_t size, const char *file, int line) = 0; + + /// If you provide a spineAllocFunc, you should also provide a spineFreeFunc + virtual void _free(void *mem, const char *file, int line) = 0; + + virtual char *_readFile(const String &path, int *length) = 0; + + virtual void _beforeFree(void *ptr) { SP_UNUSED(ptr); } + + protected: + SpineExtension(); + + private: + static SpineExtension *_instance; + }; + + class SP_API DefaultSpineExtension : public SpineExtension { + public: + DefaultSpineExtension(); + + virtual ~DefaultSpineExtension(); + + protected: + virtual void *_alloc(size_t size, const char *file, int line) override; + + virtual void *_calloc(size_t size, const char *file, int line) override; + + virtual void *_realloc(void *ptr, size_t size, const char *file, int line) override; + + virtual void _free(void *mem, const char *file, int line) override; + + virtual char *_readFile(const String &path, int *length) override; + }; + +// 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(); +} + +#endif /* Spine_Extension_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/HasRendererObject.h b/native/cocos/editor-support/spine/4.2/spine/HasRendererObject.h new file mode 100644 index 0000000000..8859a79e33 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/HasRendererObject.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_HasRendererObject_h +#define Spine_HasRendererObject_h + +#include + +namespace spine { + + typedef void (*DisposeRendererObject)(void *rendererObject); + + class SP_API HasRendererObject { + public: + explicit HasRendererObject() : _rendererObject(0), _dispose(0) {}; + + virtual ~HasRendererObject() { + if (_dispose && _rendererObject) + _dispose(_rendererObject); + } + + void *getRendererObject() { return _rendererObject; } + + void setRendererObject(void *rendererObject, DisposeRendererObject dispose = 0) { + if (_dispose && _rendererObject && _rendererObject != rendererObject) + _dispose(_rendererObject); + + _rendererObject = rendererObject; + _dispose = dispose; + } + + private: + void *_rendererObject; + DisposeRendererObject _dispose; + }; + +} + +#endif diff --git a/native/cocos/editor-support/spine/4.2/spine/HashMap.h b/native/cocos/editor-support/spine/4.2/spine/HashMap.h new file mode 100644 index 0000000000..71c4a9c020 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/HashMap.h @@ -0,0 +1,200 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_HashMap_h +#define Spine_HashMap_h + +#include +#include + +// Required for new with line number and file name in MSVC +#ifdef _MSC_VER +#pragma warning(disable:4291) + +#pragma warning(disable:4251) + +#endif + +namespace spine { + template + class SP_API HashMap : public SpineObject { + private: + class Entry; + + public: + class SP_API Pair { + public: + explicit Pair(K &k, V &v) : key(k), value(v) {} + + K &key; + V &value; + }; + + class SP_API Entries { + public: + friend class HashMap; + + explicit Entries(Entry *entry) : _entry(NULL), _hasChecked(false) { + _start.next = entry; + _entry = &_start; + } + + Pair next() { + assert(_entry); + assert(_hasChecked); + _entry = _entry->next; + Pair pair(_entry->_key, _entry->_value); + _hasChecked = false; + return pair; + } + + bool hasNext() { + _hasChecked = true; + return _entry->next; + } + + private: + bool _hasChecked; + Entry _start; + Entry *_entry; + }; + + HashMap() : + _head(NULL), + _size(0) { + } + + ~HashMap() { + clear(); + } + + void clear() { + for (Entry *entry = _head; entry != NULL;) { + Entry *next = entry->next; + delete entry; + entry = next; + } + _head = NULL; + _size = 0; + } + + size_t size() { + return _size; + } + + void put(const K &key, const V &value) { + Entry *entry = find(key); + if (entry) { + entry->_key = key; + entry->_value = value; + } else { + entry = new(__FILE__, __LINE__) Entry(); + entry->_key = key; + entry->_value = value; + + Entry *oldHead = _head; + + if (oldHead) { + _head = entry; + oldHead->prev = entry; + entry->next = oldHead; + } else { + _head = entry; + } + _size++; + } + } + + bool addAll(Vector &keys, const V &value) { + size_t oldSize = _size; + for (size_t i = 0; i < keys.size(); i++) { + put(keys[i], value); + } + return _size != oldSize; + } + + bool containsKey(const K &key) { + return find(key) != NULL; + } + + bool remove(const K &key) { + Entry *entry = find(key); + if (!entry) return false; + + Entry *prev = entry->prev; + Entry *next = entry->next; + + if (prev) prev->next = next; + else _head = next; + if (next) next->prev = entry->prev; + + delete entry; + _size--; + + return true; + } + + V operator[](const K &key) { + Entry *entry = find(key); + if (entry) return entry->_value; + else { + assert(false); + return 0; + } + } + + Entries getEntries() const { + return Entries(_head); + } + + private: + Entry *find(const K &key) { + for (Entry *entry = _head; entry != NULL; entry = entry->next) { + if (entry->_key == key) + return entry; + } + return NULL; + } + + class SP_API Entry : public SpineObject { + public: + K _key; + V _value; + Entry *next; + Entry *prev; + + Entry() : next(NULL), prev(NULL) {} + }; + + Entry *_head; + size_t _size; + }; +} + +#endif /* Spine_HashMap_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/IkConstraint.cpp b/native/cocos/editor-support/spine/4.2/spine/IkConstraint.cpp new file mode 100644 index 0000000000..6b92491d07 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/IkConstraint.cpp @@ -0,0 +1,379 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include + +#include + +using namespace spine; + +RTTI_IMPL(IkConstraint, Updatable) + +void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha) { + Bone *p = bone.getParent(); + float pa = p->_a, pb = p->_b, pc = p->_c, pd = p->_d; + float rotationIK = -bone._ashearX - bone._arotation; + float tx = 0, ty = 0; + + switch (bone._inherit) { + case Inherit_OnlyTranslation: + tx = (targetX - bone._worldX) * MathUtil::sign(bone.getSkeleton().getScaleX()); + ty = (targetY - bone._worldY) * MathUtil::sign(bone.getSkeleton().getScaleY()); + break; + case Inherit_NoRotationOrReflection: { + float s = MathUtil::abs(pa * pd - pb * pc) / MathUtil::max(0.0001f, pa * pa + pc * pc); + float sa = pa / bone._skeleton.getScaleX(); + float sc = pc / bone._skeleton.getScaleY(); + pb = -sc * s * bone._skeleton.getScaleX(); + pd = sa * s * bone._skeleton.getScaleY(); + rotationIK += MathUtil::atan2Deg(sc, sa); + } + default: + float x = targetX - p->_worldX, y = targetY - p->_worldY; + float d = pa * pd - pb * pc; + if (MathUtil::abs(d) <= 0.0001f) { + tx = 0; + ty = 0; + } else { + tx = (x * pd - y * pb) / d - bone._ax; + ty = (y * pa - x * pc) / d - bone._ay; + } + } + rotationIK += MathUtil::atan2Deg(ty, tx); + if (bone._ascaleX < 0) rotationIK += 180; + if (rotationIK > 180) rotationIK -= 360; + else if (rotationIK < -180) + rotationIK += 360; + float sx = bone._ascaleX; + float sy = bone._ascaleY; + if (compress || stretch) { + switch (bone._inherit) { + case Inherit_NoScale: + case Inherit_NoScaleOrReflection: + tx = targetX - bone._worldX; + ty = targetY - bone._worldY; + default:; + } + + float b = bone._data.getLength() * sx; + if (b > 0.0001) { + float dd = tx * tx + ty * ty; + if ((compress && dd < b * b) || (stretch && dd > b * b)) { + float s = (MathUtil::sqrt(dd) / b - 1) * alpha + 1; + sx *= s; + if (uniform) sy *= s; + } + } + } + bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx, sy, bone._ashearX, + bone._ashearY); +} + +void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY, int bendDir, bool stretch, bool uniform, + float softness, + float alpha) { + float a, b, c, d; + float px, py, psx, psy, sx, sy; + float cx, cy, csx, cwx, cwy; + int o1, o2, s2, u; + Bone *pp = parent.getParent(); + float tx, ty, dx, dy, dd, l1, l2, a1, a2, r, td, sd, p; + float id, x, y; + if (parent._inherit != Inherit_Normal || child._inherit != Inherit_Normal) return; + px = parent._ax; + py = parent._ay; + psx = parent._ascaleX; + psy = parent._ascaleY; + sx = psx; + sy = psy; + csx = child._ascaleX; + if (psx < 0) { + psx = -psx; + o1 = 180; + s2 = -1; + } else { + o1 = 0; + s2 = 1; + } + if (psy < 0) { + psy = -psy; + s2 = -s2; + } + if (csx < 0) { + csx = -csx; + o2 = 180; + } else + o2 = 0; + r = psx - psy; + cx = child._ax; + u = (r < 0 ? -r : r) <= 0.0001f; + if (!u || stretch) { + cy = 0; + cwx = parent._a * cx + parent._worldX; + cwy = parent._c * cx + parent._worldY; + } else { + cy = child._ay; + cwx = parent._a * cx + parent._b * cy + parent._worldX; + cwy = parent._c * cx + parent._d * cy + parent._worldY; + } + a = pp->_a; + b = pp->_b; + c = pp->_c; + d = pp->_d; + id = a * d - b * c; + id = MathUtil::abs(id) <= 0.0001f ? 0 : 1 / id; + x = cwx - pp->_worldX; + y = cwy - pp->_worldY; + dx = (x * d - y * b) * id - px; + dy = (y * a - x * c) * id - py; + l1 = MathUtil::sqrt(dx * dx + dy * dy); + l2 = child._data.getLength() * csx; + if (l1 < 0.0001) { + apply(parent, targetX, targetY, false, stretch, false, alpha); + child.updateWorldTransform(cx, cy, 0, child._ascaleX, child._ascaleY, child._ashearX, child._ashearY); + return; + } + x = targetX - pp->_worldX; + y = targetY - pp->_worldY; + tx = (x * d - y * b) * id - px; + ty = (y * a - x * c) * id - py; + dd = tx * tx + ty * ty; + if (softness != 0) { + softness *= psx * (csx + 1) * 0.5f; + td = MathUtil::sqrt(dd); + sd = td - l1 - l2 * psx + softness; + if (sd > 0) { + p = MathUtil::min(1.0f, sd / (softness * 2)) - 1; + p = (sd - softness * (1 - p * p)) / td; + tx -= p * tx; + ty -= p * ty; + dd = tx * tx + ty * ty; + } + } + if (u) { + float cosine; + l2 *= psx; + cosine = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2); + if (cosine < -1) { + cosine = -1; + a2 = MathUtil::Pi * bendDir; + } else if (cosine > 1) { + cosine = 1; + a2 = 0; + if (stretch) { + a = (MathUtil::sqrt(dd) / (l1 + l2) - 1) * alpha + 1; + sx *= a; + if (uniform) sy *= a; + } + } else + a2 = MathUtil::acos(cosine) * bendDir; + a = l1 + l2 * cosine; + b = l2 * MathUtil::sin(a2); + a1 = MathUtil::atan2(ty * a - tx * b, tx * a + ty * b); + } else { + a = psx * l2; + b = psy * l2; + float aa = a * a, bb = b * b, ll = l1 * l1, ta = MathUtil::atan2(ty, tx); + float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa; + d = c1 * c1 - 4 * c2 * c0; + if (d >= 0) { + float q = MathUtil::sqrt(d), r0, r1; + if (c1 < 0) q = -q; + q = -(c1 + q) * 0.5f; + r0 = q / c2; + r1 = c0 / q; + r = MathUtil::abs(r0) < MathUtil::abs(r1) ? r0 : r1; + if (dd - r * r >= 0) { + y = MathUtil::sqrt(dd - r * r) * bendDir; + a1 = ta - MathUtil::atan2(y, r); + a2 = MathUtil::atan2(y / psy, (r - l1) / psx); + goto break_outer; + } + } + { + float minAngle = MathUtil::Pi, minX = l1 - a, minDist = minX * minX, minY = 0; + float maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0; + c0 = -a * l1 / (aa - bb); + if (c0 >= -1 && c0 <= 1) { + c0 = MathUtil::acos(c0); + x = a * MathUtil::cos(c0) + l1; + y = b * MathUtil::sin(c0); + d = x * x + y * y; + if (d < minDist) { + minAngle = c0; + minDist = d; + minX = x; + minY = y; + } + if (d > maxDist) { + maxAngle = c0; + maxDist = d; + maxX = x; + maxY = y; + } + } + if (dd <= (minDist + maxDist) * 0.5f) { + a1 = ta - MathUtil::atan2(minY * bendDir, minX); + a2 = minAngle * bendDir; + } else { + a1 = ta - MathUtil::atan2(maxY * bendDir, maxX); + a2 = maxAngle * bendDir; + } + } + } +break_outer : { + float os = MathUtil::atan2(cy, cx) * s2; + a1 = (a1 - os) * MathUtil::Rad_Deg + o1 - parent._arotation; + if (a1 > 180) a1 -= 360; + else if (a1 < -180) + a1 += 360; + parent.updateWorldTransform(px, py, parent._arotation + a1 * alpha, sx, sy, 0, 0); + a2 = ((a2 + os) * MathUtil::Rad_Deg - child._ashearX) * s2 + o2 - child._arotation; + if (a2 > 180) a2 -= 360; + else if (a2 < -180) + a2 += 360; + child.updateWorldTransform(cx, cy, child._arotation + a2 * alpha, child._ascaleX, child._ascaleY, + child._ashearX, child._ashearY); +} +} + +IkConstraint::IkConstraint(IkConstraintData &data, Skeleton &skeleton) : Updatable(), + _data(data), + _bendDirection(data.getBendDirection()), + _compress(data.getCompress()), + _stretch(data.getStretch()), + _mix(data.getMix()), + _softness(data.getSoftness()), + _target(skeleton.findBone( + data.getTarget()->getName())), + _active(false) { + _bones.ensureCapacity(_data.getBones().size()); + for (size_t i = 0; i < _data.getBones().size(); i++) { + BoneData *boneData = _data.getBones()[i]; + _bones.add(skeleton.findBone(boneData->getName())); + } +} + +void IkConstraint::update(Physics) { + if (_mix == 0) return; + switch (_bones.size()) { + case 1: { + Bone *bone0 = _bones[0]; + apply(*bone0, _target->getWorldX(), _target->getWorldY(), _compress, _stretch, _data._uniform, _mix); + } break; + case 2: { + Bone *bone0 = _bones[0]; + Bone *bone1 = _bones[1]; + apply(*bone0, *bone1, _target->getWorldX(), _target->getWorldY(), _bendDirection, _stretch, _data._uniform, + _softness, + _mix); + } break; + } +} + +int IkConstraint::getOrder() { + return (int) _data.getOrder(); +} + +IkConstraintData &IkConstraint::getData() { + return _data; +} + +Vector &IkConstraint::getBones() { + return _bones; +} + +Bone *IkConstraint::getTarget() { + return _target; +} + +void IkConstraint::setTarget(Bone *inValue) { + _target = inValue; +} + +int IkConstraint::getBendDirection() { + return _bendDirection; +} + +void IkConstraint::setBendDirection(int inValue) { + _bendDirection = inValue; +} + +float IkConstraint::getMix() { + return _mix; +} + +void IkConstraint::setMix(float inValue) { + _mix = inValue; +} + +bool IkConstraint::getStretch() { + return _stretch; +} + +void IkConstraint::setStretch(bool inValue) { + _stretch = inValue; +} + +bool IkConstraint::getCompress() { + return _compress; +} + +void IkConstraint::setCompress(bool inValue) { + _compress = inValue; +} + +bool IkConstraint::isActive() { + return _active; +} + +void IkConstraint::setActive(bool inValue) { + _active = inValue; +} + +float IkConstraint::getSoftness() { + return _softness; +} + +void IkConstraint::setSoftness(float inValue) { + _softness = inValue; +} + +void IkConstraint::setToSetupPose() { + IkConstraintData &data = this->_data; + this->_mix = data._mix; + this->_softness = data._softness; + this->_bendDirection = data._bendDirection; + this->_compress = data._compress; + this->_stretch = data._stretch; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/IkConstraint.h b/native/cocos/editor-support/spine/4.2/spine/IkConstraint.h new file mode 100644 index 0000000000..152287ac3b --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/IkConstraint.h @@ -0,0 +1,120 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_IkConstraint_h +#define Spine_IkConstraint_h + +#include + +#include + +namespace spine { + class IkConstraintData; + + class Skeleton; + + class Bone; + + class SP_API IkConstraint : public Updatable { + friend class Skeleton; + + friend class IkConstraintTimeline; + + RTTI_DECL + + public: + /// Adjusts the bone rotation so the tip is as close to the target position as possible. The target is specified + /// in the world coordinate system. + static void + apply(Bone &bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha); + + /// Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as + /// possible. The target is specified in the world coordinate system. + /// @param child A direct descendant of the parent bone. + static void + apply(Bone &parent, Bone &child, float targetX, float targetY, int bendDir, bool stretch, bool uniform, + float softness, + float alpha); + + IkConstraint(IkConstraintData &data, Skeleton &skeleton); + + virtual void update(Physics physics); + + virtual int getOrder(); + + IkConstraintData &getData(); + + Vector &getBones(); + + Bone *getTarget(); + + void setTarget(Bone *inValue); + + int getBendDirection(); + + void setBendDirection(int inValue); + + bool getCompress(); + + void setCompress(bool inValue); + + bool getStretch(); + + void setStretch(bool inValue); + + float getMix(); + + void setMix(float inValue); + + float getSoftness(); + + void setSoftness(float inValue); + + bool isActive(); + + void setActive(bool inValue); + + void setToSetupPose(); + + #ifndef __EMSCRIPTEN__ + private: + #endif + IkConstraintData &_data; + Vector _bones; + int _bendDirection; + bool _compress; + bool _stretch; + float _mix; + float _softness; + Bone *_target; + bool _active; + }; +} + +#endif /* Spine_IkConstraint_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/IkConstraintData.cpp b/native/cocos/editor-support/spine/4.2/spine/IkConstraintData.cpp new file mode 100644 index 0000000000..eb8c6039b4 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/IkConstraintData.cpp @@ -0,0 +1,107 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +using namespace spine; + +RTTI_IMPL(IkConstraintData, ConstraintData) + +IkConstraintData::IkConstraintData(const String &name) : ConstraintData(name), + _target(NULL), + _bendDirection(0), + _compress(false), + _stretch(false), + _uniform(false), + _mix(0), + _softness(0) { +} + +Vector &IkConstraintData::getBones() { + return _bones; +} + +BoneData *IkConstraintData::getTarget() { + return _target; +} + +void IkConstraintData::setTarget(BoneData *inValue) { + _target = inValue; +} + +int IkConstraintData::getBendDirection() { + return _bendDirection; +} + +void IkConstraintData::setBendDirection(int inValue) { + _bendDirection = inValue; +} + +float IkConstraintData::getMix() { + return _mix; +} + +void IkConstraintData::setMix(float inValue) { + _mix = inValue; +} + +bool IkConstraintData::getStretch() { + return _stretch; +} + +void IkConstraintData::setStretch(bool inValue) { + _stretch = inValue; +} + +bool IkConstraintData::getCompress() { + return _compress; +} + +void IkConstraintData::setCompress(bool inValue) { + _compress = inValue; +} + + +bool IkConstraintData::getUniform() { + return _uniform; +} + +void IkConstraintData::setUniform(bool inValue) { + _uniform = inValue; +} + +float IkConstraintData::getSoftness() { + return _softness; +} + +void IkConstraintData::setSoftness(float inValue) { + _softness = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/IkConstraintData.h b/native/cocos/editor-support/spine/4.2/spine/IkConstraintData.h new file mode 100644 index 0000000000..81e1de0364 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/IkConstraintData.h @@ -0,0 +1,104 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_IkConstraintData_h +#define Spine_IkConstraintData_h + +#include +#include +#include +#include + +namespace spine { + class BoneData; + + class SP_API IkConstraintData : public ConstraintData { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class IkConstraint; + + friend class Skeleton; + + friend class IkConstraintTimeline; + + public: + RTTI_DECL + + explicit IkConstraintData(const String &name); + + /// The bones that are constrained by this IK Constraint. + Vector &getBones(); + + /// The bone that is the IK target. + BoneData *getTarget(); + + void setTarget(BoneData *inValue); + + /// Controls the bend direction of the IK bones, either 1 or -1. + int getBendDirection(); + + void setBendDirection(int inValue); + + bool getCompress(); + + void setCompress(bool inValue); + + bool getStretch(); + + void setStretch(bool inValue); + + bool getUniform(); + + void setUniform(bool inValue); + + float getMix(); + + void setMix(float inValue); + + float getSoftness(); + + void setSoftness(float inValue); + + #ifndef __EMSCRIPTEN__ + private: + #endif + Vector _bones; + BoneData *_target; + int _bendDirection; + bool _compress; + bool _stretch; + bool _uniform; + float _mix; + float _softness; + }; +} + +#endif /* Spine_IkConstraintData_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/IkConstraintTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/IkConstraintTimeline.cpp new file mode 100644 index 0000000000..c00711d5f9 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/IkConstraintTimeline.cpp @@ -0,0 +1,142 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace spine; +const int IkConstraintTimeline::ENTRIES = 6; + +RTTI_IMPL(IkConstraintTimeline, CurveTimeline) + +IkConstraintTimeline::IkConstraintTimeline(size_t frameCount, size_t bezierCount, int ikConstraintIndex) + : CurveTimeline(frameCount, IkConstraintTimeline::ENTRIES, bezierCount), _constraintIndex(ikConstraintIndex) { + PropertyId ids[] = {((PropertyId) Property_IkConstraint << 32) | ikConstraintIndex}; + setPropertyIds(ids, 1); +} + +void IkConstraintTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + + IkConstraint *constraintP = skeleton._ikConstraints[_constraintIndex]; + IkConstraint &constraint = *constraintP; + if (!constraint.isActive()) return; + + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + constraint._mix = constraint._data._mix; + constraint._softness = constraint._data._softness; + constraint._bendDirection = constraint._data._bendDirection; + constraint._compress = constraint._data._compress; + constraint._stretch = constraint._data._stretch; + return; + case MixBlend_First: + constraint._mix += (constraint._data._mix - constraint._mix) * alpha; + constraint._softness += (constraint._data._softness - constraint._softness) * alpha; + constraint._bendDirection = constraint._data._bendDirection; + constraint._compress = constraint._data._compress; + constraint._stretch = constraint._data._stretch; + return; + default: + return; + } + } + + float mix = 0, softness = 0; + int i = Animation::search(_frames, time, IkConstraintTimeline::ENTRIES); + int curveType = (int) _curves[i / IkConstraintTimeline::ENTRIES]; + switch (curveType) { + case IkConstraintTimeline::LINEAR: { + float before = _frames[i]; + mix = _frames[i + IkConstraintTimeline::MIX]; + softness = _frames[i + IkConstraintTimeline::SOFTNESS]; + float t = (time - before) / (_frames[i + IkConstraintTimeline::ENTRIES] - before); + mix += (_frames[i + IkConstraintTimeline::ENTRIES + IkConstraintTimeline::MIX] - mix) * t; + softness += (_frames[i + IkConstraintTimeline::ENTRIES + IkConstraintTimeline::SOFTNESS] - softness) * t; + break; + } + case IkConstraintTimeline::STEPPED: { + mix = _frames[i + IkConstraintTimeline::MIX]; + softness = _frames[i + IkConstraintTimeline::SOFTNESS]; + break; + } + default: { + mix = getBezierValue(time, i, IkConstraintTimeline::MIX, curveType - IkConstraintTimeline::BEZIER); + softness = getBezierValue(time, i, IkConstraintTimeline::SOFTNESS, + curveType + IkConstraintTimeline::BEZIER_SIZE - + IkConstraintTimeline::BEZIER); + } + } + + if (blend == MixBlend_Setup) { + constraint._mix = constraint._data._mix + (mix - constraint._data._mix) * alpha; + constraint._softness = constraint._data._softness + (softness - constraint._data._softness) * alpha; + + if (direction == MixDirection_Out) { + constraint._bendDirection = constraint._data._bendDirection; + constraint._compress = constraint._data._compress; + constraint._stretch = constraint._data._stretch; + } else { + constraint._bendDirection = _frames[i + IkConstraintTimeline::BEND_DIRECTION]; + constraint._compress = _frames[i + IkConstraintTimeline::COMPRESS] != 0; + constraint._stretch = _frames[i + IkConstraintTimeline::STRETCH] != 0; + } + } else { + constraint._mix += (mix - constraint._mix) * alpha; + constraint._softness += (softness - constraint._softness) * alpha; + if (direction == MixDirection_In) { + constraint._bendDirection = _frames[i + IkConstraintTimeline::BEND_DIRECTION]; + constraint._compress = _frames[i + IkConstraintTimeline::COMPRESS] != 0; + constraint._stretch = _frames[i + IkConstraintTimeline::STRETCH] != 0; + } + } +} + +void IkConstraintTimeline::setFrame(int frame, float time, float mix, float softness, int bendDirection, bool compress, + bool stretch) { + frame *= ENTRIES; + _frames[frame] = time; + _frames[frame + MIX] = mix; + _frames[frame + SOFTNESS] = softness; + _frames[frame + BEND_DIRECTION] = (float) bendDirection; + _frames[frame + COMPRESS] = compress ? 1 : 0; + _frames[frame + STRETCH] = stretch ? 1 : 0; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/IkConstraintTimeline.h b/native/cocos/editor-support/spine/4.2/spine/IkConstraintTimeline.h new file mode 100644 index 0000000000..5b9a5def37 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/IkConstraintTimeline.h @@ -0,0 +1,71 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_IkConstraintTimeline_h +#define Spine_IkConstraintTimeline_h + +#include + +namespace spine { + + class SP_API IkConstraintTimeline : public CurveTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit IkConstraintTimeline(size_t frameCount, size_t bezierCount, int ikConstraintIndex); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time, mix and bend direction of the specified keyframe. + void setFrame(int frame, float time, float mix, float softness, int bendDirection, bool compress, bool stretch); + + int getIkConstraintIndex() { return _constraintIndex; } + + void setIkConstraintIndex(int inValue) { _constraintIndex = inValue; } + #ifndef __EMSCRIPTEN__ + private: + #endif + int _constraintIndex; + + static const int ENTRIES; + static const int MIX = 1; + static const int SOFTNESS = 2; + static const int BEND_DIRECTION = 3; + static const int COMPRESS = 4; + static const int STRETCH = 5; + }; +} + +#endif /* Spine_IkConstraintTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Inherit.h b/native/cocos/editor-support/spine/4.2/spine/Inherit.h new file mode 100644 index 0000000000..86c94e3b47 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Inherit.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_TransformMode_h +#define Spine_TransformMode_h + +namespace spine { + enum Inherit { + Inherit_Normal = 0, + Inherit_OnlyTranslation, + Inherit_NoRotationOrReflection, + Inherit_NoScale, + Inherit_NoScaleOrReflection + }; +} + +#endif /* Spine_TransformMode_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/InheritTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/InheritTimeline.cpp new file mode 100644 index 0000000000..685c3302b2 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/InheritTimeline.cpp @@ -0,0 +1,81 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(InheritTimeline, Timeline) + +InheritTimeline::InheritTimeline(size_t frameCount, int boneIndex) : Timeline(frameCount, ENTRIES), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_Inherit << 32) | boneIndex}; + setPropertyIds(ids, 1); +} + +InheritTimeline::~InheritTimeline() { +} + +void InheritTimeline::setFrame(int frame, float time, Inherit inherit) { + frame *= ENTRIES; + _frames[frame] = time; + _frames[frame + INHERIT] = inherit; +} + + +void InheritTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + SP_UNUSED(alpha); + + Bone *bone = skeleton.getBones()[_boneIndex]; + if (!bone->isActive()) return; + + if (direction == MixDirection_Out) { + if (blend == MixBlend_Setup) bone->setInherit(bone->_data.getInherit()); + return; + } + + if (time < _frames[0]) { + if (blend == MixBlend_Setup || blend == MixBlend_First) bone->_inherit = bone->_data.getInherit(); + return; + } + int idx = Animation::search(_frames, time, ENTRIES) + INHERIT; + bone->_inherit = static_cast(_frames[idx]); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/InheritTimeline.h b/native/cocos/editor-support/spine/4.2/spine/InheritTimeline.h new file mode 100644 index 0000000000..8e20ec2ae0 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/InheritTimeline.h @@ -0,0 +1,71 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_InheritTimeline_h +#define Spine_InheritTimeline_h + +#include + +#include +#include +#include + +namespace spine { + + class SP_API InheritTimeline : public Timeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit InheritTimeline(size_t frameCount, int boneIndex); + + virtual ~InheritTimeline(); + + void setFrame(int frame, float time, Inherit inherit); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + + static const int ENTRIES = 2; + static const int INHERIT = 1; + }; +} + +#endif /* Spine_InheritTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Json.cpp b/native/cocos/editor-support/spine/4.2/spine/Json.cpp new file mode 100644 index 0000000000..e131cb4d10 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Json.cpp @@ -0,0 +1,559 @@ +/* +Copyright (c) 2009, Dave Gamble +Copyright (c) 2013, Esoteric Software + +Permission is hereby granted, dispose of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/* Json */ +/* JSON parser in CPP, from json.c in the spine-c runtime */ + +#ifndef _DEFAULT_SOURCE +/* Bring strings.h definitions into string.h, where appropriate */ +#define _DEFAULT_SOURCE +#endif + +#ifndef _BSD_SOURCE +/* Bring strings.h definitions into string.h, where appropriate */ +#define _BSD_SOURCE +#endif + +#include +#include +#include + +#include +#include + +using namespace spine; + +const int Json::JSON_FALSE = 0; +const int Json::JSON_TRUE = 1; +const int Json::JSON_NULL = 2; +const int Json::JSON_NUMBER = 3; +const int Json::JSON_STRING = 4; +const int Json::JSON_ARRAY = 5; +const int Json::JSON_OBJECT = 6; + +const char *Json::_error = NULL; + +Json *Json::getItem(Json *object, const char *string) { + Json *c = object->_child; + while (c && json_strcasecmp(c->_name, string)) { + c = c->_next; + } + return c; +} + +Json *Json::getItem(Json *object, int childIndex) { + Json *current = object->_child; + while (current != NULL && childIndex > 0) { + childIndex--; + current = current->_next; + } + return current; +} + +const char *Json::getString(Json *object, const char *name, const char *defaultValue) { + object = getItem(object, name); + if (object) { + return object->_valueString; + } + + return defaultValue; +} + +float Json::getFloat(Json *value, const char *name, float defaultValue) { + value = getItem(value, name); + return value ? value->_valueFloat : defaultValue; +} + +int Json::getInt(Json *value, const char *name, int defaultValue) { + value = getItem(value, name); + return value ? value->_valueInt : defaultValue; +} + +bool Json::getBoolean(spine::Json *value, const char *name, bool defaultValue) { + value = getItem(value, name); + if (value) { + if (value->_valueString) return strcmp(value->_valueString, "true") == 0; + if (value->_type == JSON_NULL) return false; + if (value->_type == JSON_NUMBER) return value->_valueFloat != 0; + if (value->_type == JSON_FALSE) return false; + if (value->_type == JSON_TRUE) return true; + return defaultValue; + } else { + return defaultValue; + } +} + +const char *Json::getError() { + return _error; +} + +Json::Json(const char *value) : _next(NULL), +#if SPINE_JSON_HAVE_PREV + _prev(NULL), +#endif + _child(NULL), + _type(0), + _size(0), + _valueString(NULL), + _valueInt(0), + _valueFloat(0), + _name(NULL) { + if (value) { + value = parseValue(this, skip(value)); + + assert(value); + } +} + +Json::~Json() { + spine::Json *curr = NULL; + spine::Json *next = _child; + do { + curr = next; + if (curr) { + next = curr->_next; + } + delete curr; + } while (next); + + if (_valueString) { + SpineExtension::free(_valueString, __FILE__, __LINE__); + } + + if (_name) { + SpineExtension::free(_name, __FILE__, __LINE__); + } +} + +const char *Json::skip(const char *inValue) { + if (!inValue) { + /* must propagate NULL since it's often called in skip(f(...)) form */ + return NULL; + } + + while (*inValue && (unsigned char) *inValue <= 32) { + inValue++; + } + + return inValue; +} + +const char *Json::parseValue(Json *item, const char *value) { + /* Referenced by constructor, parseArray(), and parseObject(). */ + /* Always called with the result of skip(). */ +#ifdef SPINE_JSON_DEBUG /* Checked at entry to graph, constructor, and after every parse call. */ + if (!value) { + /* Fail on null. */ + return NULL; + } +#endif + + switch (*value) { + case 'n': { + if (!strncmp(value + 1, "ull", 3)) { + item->_type = JSON_NULL; + return value + 4; + } + break; + } + case 'f': { + if (!strncmp(value + 1, "alse", 4)) { + item->_type = JSON_FALSE; + /* calloc prevents us needing item->_type = JSON_FALSE or valueInt = 0 here */ + return value + 5; + } + break; + } + case 't': { + if (!strncmp(value + 1, "rue", 3)) { + item->_type = JSON_TRUE; + item->_valueInt = 1; + return value + 4; + } + break; + } + case '\"': + return parseString(item, value); + case '[': + return parseArray(item, value); + case '{': + return parseObject(item, value); + case '-': /* fallthrough */ + case '0': /* fallthrough */ + case '1': /* fallthrough */ + case '2': /* fallthrough */ + case '3': /* fallthrough */ + case '4': /* fallthrough */ + case '5': /* fallthrough */ + case '6': /* fallthrough */ + case '7': /* fallthrough */ + case '8': /* fallthrough */ + case '9': + return parseNumber(item, value); + default: + break; + } + + _error = value; + return NULL; /* failure. */ +} + +static const unsigned char firstByteMark[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC}; + +const char *Json::parseString(Json *item, const char *str) { + const char *ptr = str + 1; + char *ptr2; + char *out; + int len = 0; + unsigned uc, uc2; + if (*str != '\"') { + /* TODO: don't need this check when called from parseValue, but do need from parseObject */ + _error = str; + return 0; + } /* not a string! */ + + while (*ptr != '\"' && *ptr && ++len) { + if (*ptr++ == '\\') { + ptr++; /* Skip escaped quotes. */ + } + } + + out = SpineExtension::alloc(len + 1, __FILE__, __LINE__); /* The length needed for the string, roughly. */ + if (!out) { + return 0; + } + + ptr = str + 1; + ptr2 = out; + while (*ptr != '\"' && *ptr) { + if (*ptr != '\\') { + *ptr2++ = *ptr++; + } else { + ptr++; + switch (*ptr) { + case 'b': + *ptr2++ = '\b'; + break; + case 'f': + *ptr2++ = '\f'; + break; + case 'n': + *ptr2++ = '\n'; + break; + case 'r': + *ptr2++ = '\r'; + break; + case 't': + *ptr2++ = '\t'; + break; + case 'u': { + /* transcode utf16 to utf8. */ + sscanf(ptr + 1, "%4x", &uc); + ptr += 4; /* get the unicode char. */ + + if ((uc >= 0xDC00 && uc <= 0xDFFF) || uc == 0) { + break; /* check for invalid. */ + } + + /* TODO provide an option to ignore surrogates, use unicode replacement character? */ + if (uc >= 0xD800 && uc <= 0xDBFF) /* UTF16 surrogate pairs. */ { + if (ptr[1] != '\\' || ptr[2] != 'u') { + break; /* missing second-half of surrogate. */ + } + sscanf(ptr + 3, "%4x", &uc2); + ptr += 6; + if (uc2 < 0xDC00 || uc2 > 0xDFFF) { + break; /* invalid second-half of surrogate. */ + } + uc = 0x10000 + (((uc & 0x3FF) << 10) | (uc2 & 0x3FF)); + } + + len = 4; + if (uc < 0x80) { + len = 1; + } else if (uc < 0x800) { + len = 2; + } else if (uc < 0x10000) { + len = 3; + } + ptr2 += len; + + switch (len) { + case 4: + *--ptr2 = ((uc | 0x80) & 0xBF); + uc >>= 6; + /* fallthrough */ + case 3: + *--ptr2 = ((uc | 0x80) & 0xBF); + uc >>= 6; + /* fallthrough */ + case 2: + *--ptr2 = ((uc | 0x80) & 0xBF); + uc >>= 6; + /* fallthrough */ + case 1: + *--ptr2 = (uc | firstByteMark[len]); + } + ptr2 += len; + break; + } + default: + *ptr2++ = *ptr; + break; + } + ptr++; + } + } + + *ptr2 = 0; + + if (*ptr == '\"') { + ptr++; /* TODO error handling if not \" or \0 ? */ + } + + item->_valueString = out; + item->_type = JSON_STRING; + + return ptr; +} + +const char *Json::parseNumber(Json *item, const char *num) { + double result = 0.0; + int negative = 0; + char *ptr = (char *) num; + + if (*ptr == '-') { + negative = -1; + ++ptr; + } + + while (*ptr >= '0' && *ptr <= '9') { + result = result * 10.0 + (*ptr - '0'); + ++ptr; + } + + if (*ptr == '.') { + double fraction = 0.0; + int n = 0; + ++ptr; + + while (*ptr >= '0' && *ptr <= '9') { + fraction = (fraction * 10.0) + (*ptr - '0'); + ++ptr; + ++n; + } + result += fraction / pow(10.0, n); + } + + if (negative) { + result = -result; + } + + if (*ptr == 'e' || *ptr == 'E') { + double exponent = 0; + int expNegative = 0; + ++ptr; + + if (*ptr == '-') { + expNegative = -1; + ++ptr; + } else if (*ptr == '+') { + ++ptr; + } + + while (*ptr >= '0' && *ptr <= '9') { + exponent = (exponent * 10.0) + (*ptr - '0'); + ++ptr; + } + + if (expNegative) { + result = result / pow(10, exponent); + } else { + result = result * pow(10, exponent); + } + } + + if (ptr != num) { + /* Parse success, number found. */ + item->_valueFloat = (float) result; + item->_valueInt = (int) result; + item->_type = JSON_NUMBER; + return ptr; + } else { + /* Parse failure, _error is set. */ + _error = num; + return NULL; + } +} + +const char *Json::parseArray(Json *item, const char *value) { + Json *child; + +#ifdef SPINE_JSON_DEBUG /* unnecessary, only callsite (parse_value) verifies this */ + if (*value != '[') { + ep = value; + return 0; + } /* not an array! */ +#endif + + item->_type = JSON_ARRAY; + value = skip(value + 1); + if (*value == ']') { + return value + 1; /* empty array. */ + } + + item->_child = child = new (__FILE__, __LINE__) Json(NULL); + if (!item->_child) { + return NULL; /* memory fail */ + } + + value = skip(parseValue(child, skip(value))); /* skip any spacing, get the value. */ + + if (!value) { + return NULL; + } + + item->_size = 1; + + while (*value == ',') { + Json *new_item = new (__FILE__, __LINE__) Json(NULL); + if (!new_item) { + return NULL; /* memory fail */ + } + child->_next = new_item; +#if SPINE_JSON_HAVE_PREV + new_item->prev = child; +#endif + child = new_item; + value = skip(parseValue(child, skip(value + 1))); + if (!value) { + return NULL; /* parse fail */ + } + item->_size++; + } + + if (*value == ']') { + return value + 1; /* end of array */ + } + + _error = value; + + return NULL; /* malformed. */ +} + +/* Build an object from the text. */ +const char *Json::parseObject(Json *item, const char *value) { + Json *child; + +#ifdef SPINE_JSON_DEBUG /* unnecessary, only callsite (parse_value) verifies this */ + if (*value != '{') { + ep = value; + return 0; + } /* not an object! */ +#endif + + item->_type = JSON_OBJECT; + value = skip(value + 1); + if (*value == '}') { + return value + 1; /* empty array. */ + } + + item->_child = child = new (__FILE__, __LINE__) Json(NULL); + if (!item->_child) { + return NULL; + } + value = skip(parseString(child, skip(value))); + if (!value) { + return NULL; + } + child->_name = child->_valueString; + child->_valueString = 0; + if (*value != ':') { + _error = value; + return NULL; + } /* fail! */ + + value = skip(parseValue(child, skip(value + 1))); /* skip any spacing, get the value. */ + if (!value) { + return NULL; + } + + item->_size = 1; + + while (*value == ',') { + Json *new_item = new (__FILE__, __LINE__) Json(NULL); + if (!new_item) { + return NULL; /* memory fail */ + } + child->_next = new_item; +#if SPINE_JSON_HAVE_PREV + new_item->prev = child; +#endif + child = new_item; + value = skip(parseString(child, skip(value + 1))); + if (!value) { + return NULL; + } + child->_name = child->_valueString; + child->_valueString = 0; + if (*value != ':') { + _error = value; + return NULL; + } /* fail! */ + + value = skip(parseValue(child, skip(value + 1))); /* skip any spacing, get the value. */ + if (!value) { + return NULL; + } + item->_size++; + } + + if (*value == '}') { + return value + 1; /* end of array */ + } + + _error = value; + + return NULL; /* malformed. */ +} + +int Json::json_strcasecmp(const char *s1, const char *s2) { + /* TODO we may be able to elide these NULL checks if we can prove + * the graph and input (only callsite is Json_getItem) should not have NULLs + */ + if (s1 && s2) { +#if defined(_WIN32) + return _stricmp(s1, s2); +#else + return strcasecmp(s1, s2); +#endif + } else { + if (s1 < s2) { + return -1; /* s1 is null, s2 is not */ + } else if (s1 == s2) { + return 0; /* both are null */ + } else { + return 1; /* s2 is nul s1 is not */ + } + } +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Json.h b/native/cocos/editor-support/spine/4.2/spine/Json.h new file mode 100644 index 0000000000..d9ea23a95c --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Json.h @@ -0,0 +1,116 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Json_h +#define Spine_Json_h + +#include + +#ifndef SPINE_JSON_HAVE_PREV +/* spine doesn't use the "prev" link in the Json sibling lists. */ +#define SPINE_JSON_HAVE_PREV 0 +#endif + +namespace spine { + class SP_API Json : public SpineObject { + friend class SkeletonJson; + + public: + /* Json Types: */ + static const int JSON_FALSE; + static const int JSON_TRUE; + static const int JSON_NULL; + static const int JSON_NUMBER; + static const int JSON_STRING; + static const int JSON_ARRAY; + static const int JSON_OBJECT; + + /* Get item "string" from object. Case insensitive. */ + static Json *getItem(Json *object, const char *string); + + static Json *getItem(Json *object, int childIndex); + + static const char *getString(Json *object, const char *name, const char *defaultValue); + + static float getFloat(Json *object, const char *name, float defaultValue); + + static int getInt(Json *object, const char *name, int defaultValue); + + static bool getBoolean(Json *object, const char *name, bool defaultValue); + + /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when Json_create() returns 0. 0 when Json_create() succeeds. */ + static const char *getError(); + + /* Supply a block of JSON, and this returns a Json object you can interrogate. Call Json_dispose when finished. */ + explicit Json(const char *value); + + ~Json(); + + + private: + static const char *_error; + + Json *_next; +#if SPINE_JSON_HAVE_PREV + Json* _prev; /* next/prev allow you to walk array/object chains. Alternatively, use getSize/getItem */ +#endif + Json *_child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + + int _type; /* The type of the item, as above. */ + int _size; /* The number of children. */ + + const char *_valueString; /* The item's string, if type==JSON_STRING */ + int _valueInt; /* The item's number, if type==JSON_NUMBER */ + float _valueFloat; /* The item's number, if type==JSON_NUMBER */ + + const char *_name; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + + /* Utility to jump whitespace and cr/lf */ + static const char *skip(const char *inValue); + + /* Parser core - when encountering text, process appropriately. */ + static const char *parseValue(Json *item, const char *value); + + /* Parse the input text into an unescaped cstring, and populate item. */ + static const char *parseString(Json *item, const char *str); + + /* Parse the input text to generate a number, and populate the result into item. */ + static const char *parseNumber(Json *item, const char *num); + + /* Build an array from input text. */ + static const char *parseArray(Json *item, const char *value); + + /* Build an object from the text. */ + static const char *parseObject(Json *item, const char *value); + + static int json_strcasecmp(const char *s1, const char *s2); + }; +} + +#endif /* Spine_Json_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/LinkedMesh.cpp b/native/cocos/editor-support/spine/4.2/spine/LinkedMesh.cpp new file mode 100644 index 0000000000..8442f2bf40 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/LinkedMesh.cpp @@ -0,0 +1,52 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +using namespace spine; + +LinkedMesh::LinkedMesh(MeshAttachment *mesh, const int skinIndex, size_t slotIndex, const String &parent, + bool inheritTimeline) : _mesh(mesh), + _skinIndex(skinIndex), + _skin(""), + _slotIndex(slotIndex), + _parent(parent), + _inheritTimeline(inheritTimeline) { +} + +LinkedMesh::LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, + bool inheritTimeline) : _mesh(mesh), + _skinIndex(-1), + _skin(skin), + _slotIndex(slotIndex), + _parent(parent), + _inheritTimeline(inheritTimeline) { +} diff --git a/native/cocos/editor-support/spine/4.2/spine/LinkedMesh.h b/native/cocos/editor-support/spine/4.2/spine/LinkedMesh.h new file mode 100644 index 0000000000..c62f3ab852 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/LinkedMesh.h @@ -0,0 +1,61 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_LinkedMesh_h +#define Spine_LinkedMesh_h + +#include +#include + +namespace spine { + class MeshAttachment; + + class SP_API LinkedMesh : public SpineObject { + friend class SkeletonBinary; + + friend class SkeletonJson; + + public: + LinkedMesh(MeshAttachment *mesh, const int skinIndex, size_t slotIndex, const String &parent, + bool inheritTimeline); + + LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, + bool inheritTimeline); + + private: + MeshAttachment *_mesh; + int _skinIndex; + String _skin; + size_t _slotIndex; + String _parent; + bool _inheritTimeline; + }; +} + +#endif /* Spine_LinkedMesh_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Log.cpp b/native/cocos/editor-support/spine/4.2/spine/Log.cpp new file mode 100644 index 0000000000..c5524fc237 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Log.cpp @@ -0,0 +1,123 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +using namespace spine; + +void spine::spDebug_printSkeletonData(SkeletonData *skeletonData) { + int i, n; + spDebug_printBoneDatas(skeletonData->getBones()); + + for (i = 0, n = (int) skeletonData->getAnimations().size(); i < n; i++) { + spDebug_printAnimation(skeletonData->getAnimations()[i]); + } +} + +void _spDebug_printTimelineBase(Timeline *timeline) { + printf(" Timeline %s:\n", timeline->getRTTI().getClassName()); + printf(" frame count: %zu\n", timeline->getFrameCount()); + printf(" frame entries: %zu\n", timeline->getFrameEntries()); + printf(" frames: "); + spDebug_printFloats(timeline->getFrames()); + printf("\n"); +} + +void _spDebug_printCurveTimeline(CurveTimeline *timeline) { + _spDebug_printTimelineBase(timeline); + printf(" curves: "); + spDebug_printFloats(timeline->getCurves()); + printf("\n"); +} + +void spine::spDebug_printTimeline(Timeline *timeline) { + if (timeline->getRTTI().instanceOf(CurveTimeline::rtti)) + _spDebug_printCurveTimeline(static_cast(timeline)); + else + _spDebug_printTimelineBase(timeline); +} + +void spine::spDebug_printAnimation(Animation *animation) { + int i, n; + printf("Animation %s: %zu timelines\n", animation->getName().buffer(), animation->getTimelines().size()); + + for (i = 0, n = (int) animation->getTimelines().size(); i < n; i++) { + Timeline *timeline = animation->getTimelines()[i]; + spDebug_printTimeline(timeline); + } +} + +void spine::spDebug_printBoneDatas(Vector &boneDatas) { + int i, n; + for (i = 0, n = (int) boneDatas.size(); i < n; i++) { + spDebug_printBoneData(boneDatas[i]); + } +} + +void spine::spDebug_printBoneData(BoneData *boneData) { + printf("Bone data %s: %f, %f, %f, %f, %f, %f %f\n", boneData->getName().buffer(), boneData->getRotation(), + boneData->getScaleX(), boneData->getScaleY(), boneData->getX(), boneData->getY(), boneData->getShearX(), + boneData->getShearY()); +} + +void spine::spDebug_printSkeleton(Skeleton *skeleton) { + spDebug_printBones(skeleton->getBones()); +} + +void spine::spDebug_printBones(Vector &bones) { + int i, n; + for (i = 0, n = (int) bones.size(); i < n; i++) { + spDebug_printBone(bones[i]); + } +} + +void spine::spDebug_printBone(Bone *bone) { + printf("Bone %s: %f, %f, %f, %f, %f, %f\n", bone->getData().getName().buffer(), bone->getA(), bone->getB(), + bone->getC(), bone->getD(), bone->getWorldX(), bone->getWorldY()); +} + +void spine::spDebug_printFloats(float *values, int numFloats) { + int i; + printf("(%i) [", numFloats); + for (i = 0; i < numFloats; i++) { + printf("%f, ", values[i]); + } + printf("]"); +} + +void spine::spDebug_printFloats(Vector &values) { + int i, n; + printf("(%zu) [", values.size()); + for (i = 0, n = (int) values.size(); i < n; i++) { + printf("%f, ", values[i]); + } + printf("]"); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Log.h b/native/cocos/editor-support/spine/4.2/spine/Log.h new file mode 100644 index 0000000000..1567068c39 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Log.h @@ -0,0 +1,57 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef SPINE_DEBUG_LOG_H +#define SPINE_DEBUG_LOG_H + +#include + +namespace spine { + SP_API void spDebug_printSkeletonData(SkeletonData *skeletonData); + + SP_API void spDebug_printAnimation(Animation *animation); + + SP_API void spDebug_printTimeline(Timeline *timeline); + + SP_API void spDebug_printBoneDatas(Vector &boneDatas); + + SP_API void spDebug_printBoneData(BoneData *boneData); + + SP_API void spDebug_printSkeleton(Skeleton *skeleton); + + SP_API void spDebug_printBones(Vector &bones); + + SP_API void spDebug_printBone(Bone *bone); + + SP_API void spDebug_printFloats(float *values, int numFloats); + + SP_API void spDebug_printFloats(Vector &values); +} + +#endif diff --git a/native/cocos/editor-support/spine/4.2/spine/MathUtil.cpp b/native/cocos/editor-support/spine/4.2/spine/MathUtil.cpp new file mode 100644 index 0000000000..61ec3b7681 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/MathUtil.cpp @@ -0,0 +1,136 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include +#include +#include + +// Required for division by 0 in _isNaN on MSVC +#ifdef _MSC_VER +#pragma warning(disable : 4723) +#endif + +using namespace spine; + +RTTI_IMPL_NOPARENT(Interpolation) +RTTI_IMPL(PowInterpolation, Interpolation) +RTTI_IMPL(PowOutInterpolation, Interpolation) + +const float MathUtil::Pi = 3.1415926535897932385f; +const float MathUtil::Pi_2 = 3.1415926535897932385f * 2; +const float MathUtil::InvPi_2 = 1 / MathUtil::Pi_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)); +} + +float MathUtil::sign(float v) { + return ((v) < 0 ? -1.0f : (v) > 0 ? 1.0f + : 0.0f); +} + +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); +} + +float MathUtil::atan2Deg(float y, float x) { + return MathUtil::atan2(y, x) * MathUtil::Rad_Deg; +} + +/// 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); +} + +bool MathUtil::isNan(float v) { + return std::isnan(v); +} + +float MathUtil::quietNan() { + return std::nan(""); +} + +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; + if (u <= (mode - min) / d) return min + sqrt(u * d * (mode - min)); + return max - sqrt((1 - u) * d * (max - mode)); +} + +float MathUtil::pow(float a, float b) { + return (float) ::pow(a, b); +} + +float MathUtil::ceil(float v) { + return ::ceil(v); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/MathUtil.h b/native/cocos/editor-support/spine/4.2/spine/MathUtil.h new file mode 100644 index 0000000000..c97ccb4ed3 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/MathUtil.h @@ -0,0 +1,142 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_MathUtil_h +#define Spine_MathUtil_h + +#include +#include +#include +// Needed for older MSVC versions +#undef min +#undef max + +namespace spine { + + class SP_API MathUtil : public SpineObject { + private: + MathUtil(); + + public: + static const float Pi; + static const float Pi_2; + static const float InvPi_2; + static const float Deg_Rad; + static const float Rad_Deg; + + template + static inline T min(T a, T b) { return a < b ? a : b; } + + template + static inline T max(T a, T b) { return a > b ? a : b; } + + static float sign(float val); + + static float clamp(float x, float lower, float upper); + + static float abs(float v); + + /// Returns the sine in radians from a lookup table. + static float sin(float radians); + + /// Returns the cosine in radians from a lookup table. + static float cos(float radians); + + /// Returns the sine in radians from a lookup table. + static float sinDeg(float degrees); + + /// Returns the cosine in radians from a lookup table. + static float cosDeg(float degrees); + + /// 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 float atan2Deg(float x, float y); + + static float acos(float v); + + static float sqrt(float v); + + static float fmod(float a, float b); + + static bool isNan(float v); + + static float quietNan(); + + static float random(); + + static float randomTriangular(float min, float max); + + static float randomTriangular(float min, float max, float mode); + + static float pow(float a, float b); + + static float ceil(float v); + }; + + struct SP_API Interpolation { + RTTI_DECL + virtual float apply(float a) = 0; + + virtual float interpolate(float start, float end, float a) { + return start + (end - start) * apply(a); + } + + virtual ~Interpolation() {}; + }; + + struct SP_API PowInterpolation : public Interpolation { + RTTI_DECL + PowInterpolation(int power) : power(power) { + } + + float apply(float a) { + if (a <= 0.5f) return MathUtil::pow(a * 2.0f, (float) power) / 2.0f; + return MathUtil::pow((a - 1.0f) * 2.0f, (float) power) / (power % 2 == 0 ? -2.0f : 2.0f) + 1.0f; + } + + int power; + }; + + struct SP_API PowOutInterpolation : public Interpolation { + RTTI_DECL + PowOutInterpolation(int power) : power(power) { + } + + float apply(float a) { + return MathUtil::pow(a - 1, (float) power) * (power % 2 == 0 ? -1.0f : 1.0f) + 1.0f; + } + + int power; + }; + +} + +#endif /* Spine_MathUtil_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/MeshAttachment.cpp b/native/cocos/editor-support/spine/4.2/spine/MeshAttachment.cpp new file mode 100644 index 0000000000..8753760ae4 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/MeshAttachment.cpp @@ -0,0 +1,241 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +using namespace spine; + +RTTI_IMPL(MeshAttachment, VertexAttachment) + +MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), + _parentMesh(NULL), + _path(), + _color(1, 1, 1, 1), + _hullLength(0), + _width(0), + _height(0), + _region(NULL), + _sequence(NULL) {} + +MeshAttachment::~MeshAttachment() { + if (_sequence) delete _sequence; +} + +void MeshAttachment::updateRegion() { + if (_uvs.size() != _regionUVs.size()) { + _uvs.setSize(_regionUVs.size(), 0); + } + + if (_region == nullptr) { + return; + } + + int i = 0, n = (int) _regionUVs.size(); + float u = _region->u, v = _region->v; + float width = 0, height = 0; + switch (_region->degrees) { + case 90: { + float textureWidth = _region->height / (_region->u2 - _region->u); + float textureHeight = _region->width / (_region->v2 - _region->v); + u -= (_region->originalHeight - _region->offsetY - _region->height) / textureWidth; + v -= (_region->originalWidth - _region->offsetX - _region->width) / textureHeight; + width = _region->originalHeight / textureWidth; + height = _region->originalWidth / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + _regionUVs[i + 1] * width; + _uvs[i + 1] = v + (1 - _regionUVs[i]) * height; + } + return; + } + case 180: { + float textureWidth = _region->width / (_region->u2 - _region->u); + float textureHeight = _region->height / (_region->v2 - _region->v); + u -= (_region->originalWidth - _region->offsetX - _region->width) / textureWidth; + v -= _region->offsetY / textureHeight; + width = _region->originalWidth / textureWidth; + height = _region->originalHeight / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + (1 - _regionUVs[i]) * width; + _uvs[i + 1] = v + (1 - _regionUVs[i + 1]) * height; + } + return; + } + case 270: { + float textureHeight = _region->height / (_region->v2 - _region->v); + float textureWidth = _region->width / (_region->u2 - _region->u); + u -= _region->offsetY / textureWidth; + v -= _region->offsetX / textureHeight; + width = _region->originalHeight / textureWidth; + height = _region->originalWidth / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + (1 - _regionUVs[i + 1]) * width; + _uvs[i + 1] = v + _regionUVs[i] * height; + } + return; + } + default: { + float textureWidth = _region->width / (_region->u2 - _region->u); + float textureHeight = _region->height / (_region->v2 - _region->v); + u -= _region->offsetX / textureWidth; + v -= (_region->originalHeight - _region->offsetY - _region->height) / textureHeight; + width = _region->originalWidth / textureWidth; + height = _region->originalHeight / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + _regionUVs[i] * width; + _uvs[i + 1] = v + _regionUVs[i + 1] * height; + } + } + } +} + +int MeshAttachment::getHullLength() { + return _hullLength; +} + +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; +} + +void MeshAttachment::setPath(const String &inValue) { + _path = inValue; +} + +TextureRegion *MeshAttachment::getRegion() { + return _region; +} + +void MeshAttachment::setRegion(TextureRegion *region) { + _region = region; +} + +Sequence *MeshAttachment::getSequence() { + return _sequence; +} + +void MeshAttachment::setSequence(Sequence *sequence) { + _sequence = sequence; +} + +MeshAttachment *MeshAttachment::getParentMesh() { + return _parentMesh; +} + +void MeshAttachment::setParentMesh(MeshAttachment *inValue) { + _parentMesh = inValue; + if (inValue != NULL) { + _bones.clearAndAddAll(inValue->_bones); + _vertices.clearAndAddAll(inValue->_vertices); + _worldVerticesLength = inValue->_worldVerticesLength; + _regionUVs.clearAndAddAll(inValue->_regionUVs); + _triangles.clearAndAddAll(inValue->_triangles); + _hullLength = inValue->_hullLength; + _edges.clearAndAddAll(inValue->_edges); + _width = inValue->_width; + _height = inValue->_height; + } +} + +Vector &MeshAttachment::getEdges() { + return _edges; +} + +float MeshAttachment::getWidth() { + return _width; +} + +void MeshAttachment::setWidth(float inValue) { + _width = inValue; +} + +float MeshAttachment::getHeight() { + return _height; +} + +void MeshAttachment::setHeight(float inValue) { + _height = inValue; +} + +spine::Color &MeshAttachment::getColor() { + return _color; +} + +Attachment *MeshAttachment::copy() { + if (_parentMesh) return newLinkedMesh(); + + MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); + copy->setRegion(_region); + copy->setSequence(_sequence != NULL ? _sequence->copy() : NULL); + copy->_path = _path; + copy->_color.set(_color); + + copyTo(copy); + copy->_regionUVs.clearAndAddAll(_regionUVs); + copy->_uvs.clearAndAddAll(_uvs); + copy->_triangles.clearAndAddAll(_triangles); + copy->_hullLength = _hullLength; + + // Nonessential. + copy->_edges.clearAndAddAll(copy->_edges); + copy->_width = _width; + copy->_height = _height; + return copy; +} + +MeshAttachment *MeshAttachment::newLinkedMesh() { + MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); + copy->setRegion(_region); + copy->_path = _path; + copy->_color.set(_color); + copy->_timelineAttachment = this->_timelineAttachment; + copy->setParentMesh(_parentMesh ? _parentMesh : this); + if (copy->_region) copy->updateRegion(); + return copy; +} + +void MeshAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, + size_t stride) { + if (_sequence) _sequence->apply(&slot, this); + VertexAttachment::computeWorldVertices(slot, start, count, worldVertices, offset, stride); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/MeshAttachment.h b/native/cocos/editor-support/spine/4.2/spine/MeshAttachment.h new file mode 100644 index 0000000000..ae8da460ac --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/MeshAttachment.h @@ -0,0 +1,124 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_MeshAttachment_h +#define Spine_MeshAttachment_h + +#include +#include +#include +#include +#include +#include + +namespace spine { + /// Attachment that displays a texture region using a mesh. + class SP_API MeshAttachment : public VertexAttachment { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class AtlasAttachmentLoader; + + RTTI_DECL + + public: + explicit MeshAttachment(const String &name); + + virtual ~MeshAttachment(); + + using VertexAttachment::computeWorldVertices; + + virtual void computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, + size_t stride = 2); + + void updateRegion(); + + int getHullLength(); + + void setHullLength(int inValue); + + Vector &getRegionUVs(); + + /// The UV pair for each vertex, normalized within the entire texture. See also MeshAttachment::updateRegion + Vector &getUVs(); + + Vector &getTriangles(); + + Color &getColor(); + + const String &getPath(); + + void setPath(const String &inValue); + + TextureRegion *getRegion(); + + void setRegion(TextureRegion *region); + + Sequence *getSequence(); + + void setSequence(Sequence *sequence); + + MeshAttachment *getParentMesh(); + + void setParentMesh(MeshAttachment *inValue); + + // Nonessential. + Vector &getEdges(); + + float getWidth(); + + void setWidth(float inValue); + + float getHeight(); + + void setHeight(float inValue); + + virtual Attachment *copy(); + + MeshAttachment *newLinkedMesh(); + + #ifndef __EMSCRIPTEN__ + private: + #endif + MeshAttachment *_parentMesh; + Vector _uvs; + Vector _regionUVs; + Vector _triangles; + Vector _edges; + String _path; + Color _color; + int _hullLength; + int _width, _height; + TextureRegion *_region; + Sequence *_sequence; + }; +} + +#endif /* Spine_MeshAttachment_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/MixBlend.h b/native/cocos/editor-support/spine/4.2/spine/MixBlend.h new file mode 100644 index 0000000000..b6d536714d --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/MixBlend.h @@ -0,0 +1,45 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_MixPose_h +#define Spine_MixPose_h + +namespace spine { + +/// Controls how a timeline is mixed with the setup or current pose. +/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, Blend, MixDirection) + enum MixBlend { + MixBlend_Setup = 0, + MixBlend_First, + MixBlend_Replace, + MixBlend_Add + }; +} + +#endif /* Spine_MixPose_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/MixDirection.h b/native/cocos/editor-support/spine/4.2/spine/MixDirection.h new file mode 100644 index 0000000000..d4ead1c84b --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/MixDirection.h @@ -0,0 +1,44 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_MixDirection_h +#define Spine_MixDirection_h + +namespace spine { + +/// Indicates whether a timeline's alpha is mixing out over time toward 0 (the setup or current pose) or mixing in toward 1 (the timeline's pose). +/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, MixPose, MixDirection) + enum MixDirection { + MixDirection_In = 0, + MixDirection_Out + }; + +} + +#endif /* Spine_MixDirection_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PathAttachment.cpp b/native/cocos/editor-support/spine/4.2/spine/PathAttachment.cpp new file mode 100644 index 0000000000..b6fa54da44 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathAttachment.cpp @@ -0,0 +1,71 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +using namespace spine; + +RTTI_IMPL(PathAttachment, VertexAttachment) + +PathAttachment::PathAttachment(const String &name) : VertexAttachment(name), _closed(false), _constantSpeed(false), + _color() { +} + +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; +} + +Color &PathAttachment::getColor() { + return _color; +} + +Attachment *PathAttachment::copy() { + PathAttachment *copy = new (__FILE__, __LINE__) PathAttachment(getName()); + copyTo(copy); + copy->_lengths.clearAndAddAll(_lengths); + copy->_closed = _closed; + copy->_constantSpeed = _constantSpeed; + return copy; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/PathAttachment.h b/native/cocos/editor-support/spine/4.2/spine/PathAttachment.h new file mode 100644 index 0000000000..0afbba849a --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathAttachment.h @@ -0,0 +1,72 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PathAttachment_h +#define Spine_PathAttachment_h + +#include +#include + +namespace spine { + class SP_API PathAttachment : public VertexAttachment { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + 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); + + Color &getColor(); + + virtual Attachment *copy(); + + #ifndef __EMSCRIPTEN__ + private: + #endif + Vector _lengths; + bool _closed; + bool _constantSpeed; + Color _color; + }; +} + +#endif /* Spine_PathAttachment_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraint.cpp b/native/cocos/editor-support/spine/4.2/spine/PathConstraint.cpp new file mode 100644 index 0000000000..61344fb2ce --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraint.cpp @@ -0,0 +1,588 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include +#include +#include + +#include +#include + +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( + data.getTarget()->getName())), + _position(data.getPosition()), + _spacing(data.getSpacing()), + _mixRotate(data.getMixRotate()), + _mixX(data.getMixX()), + _mixY(data.getMixY()), + _active(false) { + _bones.ensureCapacity(_data.getBones().size()); + for (size_t i = 0; i < _data.getBones().size(); i++) { + BoneData *boneData = _data.getBones()[i]; + _bones.add(skeleton.findBone(boneData->getName())); + } + + _segments.setSize(10, 0); +} + +void PathConstraint::update(Physics) { + Attachment *baseAttachment = _target->getAttachment(); + if (baseAttachment == NULL || !baseAttachment->getRTTI().instanceOf(PathAttachment::rtti)) { + return; + } + PathAttachment *attachment = static_cast(baseAttachment); + + float mixRotate = _mixRotate, mixX = _mixX, mixY = _mixY; + if (mixRotate == 0 && mixX == 0 && mixY == 0) return; + + PathConstraintData &data = _data; + bool tangents = data._rotateMode == RotateMode_Tangent, scale = data._rotateMode == RotateMode_ChainScale; + size_t boneCount = _bones.size(); + size_t spacesCount = tangents ? boneCount : boneCount + 1; + _spaces.setSize(spacesCount, 0); + if (scale) _lengths.setSize(boneCount, 0); + float spacing = _spacing; + + switch (data._spacingMode) { + case SpacingMode_Percent: { + if (scale) { + for (size_t i = 0, n = spacesCount - 1; i < n; i++) { + Bone *boneP = _bones[i]; + Bone &bone = *boneP; + float setupLength = bone._data.getLength(); + float x = setupLength * bone._a; + float y = setupLength * bone._c; + _lengths[i] = MathUtil::sqrt(x * x + y * y); + } + } + for (size_t i = 1; i < spacesCount; ++i) { + _spaces[i] = spacing; + } + break; + } + case SpacingMode_Proportional: { + float sum = 0; + for (size_t i = 0, n = spacesCount - 1; i < n;) { + Bone *boneP = _bones[i]; + Bone &bone = *boneP; + float setupLength = bone._data.getLength(); + if (setupLength < PathConstraint::EPSILON) { + if (scale) _lengths[i] = 0; + _spaces[++i] = spacing; + } else { + float x = setupLength * bone._a, y = setupLength * bone._c; + float length = MathUtil::sqrt(x * x + y * y); + if (scale) _lengths[i] = length; + _spaces[++i] = length; + sum += length; + } + } + if (sum > 0) { + sum = spacesCount / sum * spacing; + for (size_t i = 1; i < spacesCount; i++) { + _spaces[i] *= sum; + } + } + break; + } + default: { + bool lengthSpacing = data._spacingMode == SpacingMode_Length; + for (size_t i = 0, n = spacesCount - 1; i < n;) { + Bone *boneP = _bones[i]; + Bone &bone = *boneP; + float setupLength = bone._data.getLength(); + if (setupLength < PathConstraint::EPSILON) { + if (scale) _lengths[i] = 0; + _spaces[++i] = spacing; + } else { + float x = setupLength * bone._a, y = setupLength * bone._c; + float length = MathUtil::sqrt(x * x + y * y); + if (scale) _lengths[i] = length; + _spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength; + } + } + } + } + + Vector &positions = computeWorldPositions(*attachment, (int) spacesCount, tangents); + float boneX = positions[0]; + float boneY = positions[1]; + float offsetRotation = data.getOffsetRotation(); + bool tip; + if (offsetRotation == 0) { + tip = data._rotateMode == RotateMode_Chain; + } else { + tip = false; + Bone &p = _target->getBone(); + offsetRotation *= p.getA() * p.getD() - p.getB() * p.getC() > 0 ? MathUtil::Deg_Rad : -MathUtil::Deg_Rad; + } + + for (size_t i = 0, p = 3; i < boneCount; i++, p += 3) { + Bone *boneP = _bones[i]; + Bone &bone = *boneP; + bone._worldX += (boneX - bone._worldX) * mixX; + bone._worldY += (boneY - bone._worldY) * mixY; + float x = positions[p]; + float y = positions[p + 1]; + float dx = x - boneX; + float dy = y - boneY; + if (scale) { + float length = _lengths[i]; + if (length >= PathConstraint::EPSILON) { + float s = (MathUtil::sqrt(dx * dx + dy * dy) / length - 1) * mixRotate + 1; + bone._a *= s; + bone._c *= s; + } + } + + boneX = x; + boneY = y; + + if (mixRotate > 0) { + float a = bone._a, b = bone._b, c = bone._c, d = bone._d, r, cos, sin; + if (tangents) + r = positions[p - 1]; + else if (_spaces[i + 1] < PathConstraint::EPSILON) + r = positions[p + 2]; + else + r = MathUtil::atan2(dy, dx); + + r -= MathUtil::atan2(c, a); + + if (tip) { + cos = MathUtil::cos(r); + sin = MathUtil::sin(r); + float length = bone._data.getLength(); + boneX += (length * (cos * a - sin * c) - dx) * mixRotate; + boneY += (length * (sin * a + cos * c) - dy) * mixRotate; + } else + r += offsetRotation; + + if (r > MathUtil::Pi) + r -= MathUtil::Pi_2; + else if (r < -MathUtil::Pi) + r += MathUtil::Pi_2; + + r *= mixRotate; + cos = MathUtil::cos(r); + sin = MathUtil::sin(r); + bone._a = cos * a - sin * c; + bone._b = cos * b - sin * d; + bone._c = sin * a + cos * c; + bone._d = sin * b + cos * d; + } + + bone.updateAppliedTransform(); + } +} + +int PathConstraint::getOrder() { + return (int) _data.getOrder(); +} + +float PathConstraint::getPosition() { + return _position; +} + +void PathConstraint::setPosition(float inValue) { + _position = inValue; +} + +float PathConstraint::getSpacing() { + return _spacing; +} + +void PathConstraint::setSpacing(float inValue) { + _spacing = inValue; +} + +float PathConstraint::getMixRotate() { + return _mixRotate; +} + +void PathConstraint::setMixRotate(float inValue) { + _mixRotate = inValue; +} + +float PathConstraint::getMixX() { + return _mixX; +} + +void PathConstraint::setMixX(float inValue) { + _mixX = inValue; +} + +float PathConstraint::getMixY() { + return _mixY; +} + +void PathConstraint::setMixY(float inValue) { + _mixY = inValue; +} + +Vector &PathConstraint::getBones() { + return _bones; +} + +Slot *PathConstraint::getTarget() { + return _target; +} + +void PathConstraint::setTarget(Slot *inValue) { + _target = inValue; +} + +PathConstraintData &PathConstraint::getData() { + return _data; +} + +Vector & +PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, bool tangents) { + Slot &target = *_target; + float position = _position; + _positions.setSize(spacesCount * 3 + 2, 0); + Vector &out = _positions; + Vector &world = _world; + bool closed = path.isClosed(); + int verticesLength = (int) path.getWorldVerticesLength(); + int curveCount = verticesLength / 6; + int prevCurve = NONE; + + float pathLength; + if (!path.isConstantSpeed()) { + Vector &lengths = path.getLengths(); + curveCount -= closed ? 1 : 2; + pathLength = lengths[curveCount]; + if (_data._positionMode == PositionMode_Percent) position *= pathLength; + + float multiplier = 0; + switch (_data._spacingMode) { + case SpacingMode_Percent: + multiplier = pathLength; + break; + case SpacingMode_Proportional: + multiplier = pathLength / spacesCount; + break; + default: + multiplier = 1; + } + + world.setSize(8, 0); + for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) { + float space = _spaces[i] * multiplier; + position += space; + float p = position; + + if (closed) { + p = MathUtil::fmod(p, pathLength); + if (p < 0) p += pathLength; + curve = 0; + } else if (p < 0) { + if (prevCurve != BEFORE) { + prevCurve = BEFORE; + path.computeWorldVertices(target, 2, 4, world, 0); + } + + addBeforePosition(p, world, 0, out, o); + + continue; + } else if (p > pathLength) { + if (prevCurve != AFTER) { + prevCurve = AFTER; + path.computeWorldVertices(target, verticesLength - 6, 4, world, 0); + } + + addAfterPosition(p - pathLength, world, 0, out, o); + + continue; + } + + // Determine curve containing position. + for (;; curve++) { + float length = lengths[curve]; + if (p > length) continue; + + if (curve == 0) + p /= length; + else { + float prev = lengths[curve - 1]; + p = (p - prev) / (length - prev); + } + break; + } + + if (curve != prevCurve) { + prevCurve = curve; + if (closed && curve == curveCount) { + path.computeWorldVertices(target, verticesLength - 4, 4, world, 0); + path.computeWorldVertices(target, 0, 4, world, 4); + } else + path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0); + } + + addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], + out, o, tangents || (i > 0 && space < EPSILON)); + } + return out; + } + + // World vertices. + if (closed) { + verticesLength += 2; + world.setSize(verticesLength, 0); + path.computeWorldVertices(target, 2, verticesLength - 4, world, 0); + path.computeWorldVertices(target, 0, 2, world, verticesLength - 4); + world[verticesLength - 2] = world[0]; + world[verticesLength - 1] = world[1]; + } else { + curveCount--; + verticesLength -= 4; + world.setSize(verticesLength, 0); + path.computeWorldVertices(target, 2, verticesLength, world, 0); + } + + // Curve lengths. + _curves.setSize(curveCount, 0); + pathLength = 0; + float x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0; + float tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy; + for (int i = 0, w = 2; i < curveCount; i++, w += 6) { + cx1 = world[w]; + cy1 = world[w + 1]; + cx2 = world[w + 2]; + cy2 = world[w + 3]; + x2 = world[w + 4]; + y2 = world[w + 5]; + tmpx = (x1 - cx1 * 2 + cx2) * 0.1875f; + tmpy = (y1 - cy1 * 2 + cy2) * 0.1875f; + dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375f; + dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375f; + ddfx = tmpx * 2 + dddfx; + ddfy = tmpy * 2 + dddfy; + dfx = (cx1 - x1) * 0.75f + tmpx + dddfx * 0.16666667f; + dfy = (cy1 - y1) * 0.75f + tmpy + dddfy * 0.16666667f; + pathLength += MathUtil::sqrt(dfx * dfx + dfy * dfy); + dfx += ddfx; + dfy += ddfy; + ddfx += dddfx; + ddfy += dddfy; + pathLength += MathUtil::sqrt(dfx * dfx + dfy * dfy); + dfx += ddfx; + dfy += ddfy; + pathLength += MathUtil::sqrt(dfx * dfx + dfy * dfy); + dfx += ddfx + dddfx; + dfy += ddfy + dddfy; + pathLength += MathUtil::sqrt(dfx * dfx + dfy * dfy); + _curves[i] = pathLength; + x1 = x2; + y1 = y2; + } + + if (_data._positionMode == PositionMode_Percent) position *= pathLength; + + float multiplier = 0; + switch (_data._spacingMode) { + case SpacingMode_Percent: + multiplier = pathLength; + break; + case SpacingMode_Proportional: + multiplier = pathLength / spacesCount; + break; + default: + multiplier = 1; + } + + float curveLength = 0; + for (int i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) { + float space = _spaces[i] * multiplier; + position += space; + float p = position; + + if (closed) { + p = MathUtil::fmod(p, pathLength); + if (p < 0) p += pathLength; + curve = 0; + } else if (p < 0) { + addBeforePosition(p, world, 0, out, o); + continue; + } else if (p > pathLength) { + addAfterPosition(p - pathLength, world, verticesLength - 4, out, o); + continue; + } + + // Determine curve containing position. + for (;; curve++) { + float length = _curves[curve]; + if (p > length) continue; + if (curve == 0) + p /= length; + else { + float prev = _curves[curve - 1]; + p = (p - prev) / (length - prev); + } + break; + } + + // Curve segment lengths. + if (curve != prevCurve) { + prevCurve = curve; + int ii = curve * 6; + x1 = world[ii]; + y1 = world[ii + 1]; + cx1 = world[ii + 2]; + cy1 = world[ii + 3]; + cx2 = world[ii + 4]; + cy2 = world[ii + 5]; + x2 = world[ii + 6]; + y2 = world[ii + 7]; + tmpx = (x1 - cx1 * 2 + cx2) * 0.03f; + tmpy = (y1 - cy1 * 2 + cy2) * 0.03f; + dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006f; + dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006f; + ddfx = tmpx * 2 + dddfx; + ddfy = tmpy * 2 + dddfy; + dfx = (cx1 - x1) * 0.3f + tmpx + dddfx * 0.16666667f; + dfy = (cy1 - y1) * 0.3f + tmpy + dddfy * 0.16666667f; + curveLength = MathUtil::sqrt(dfx * dfx + dfy * dfy); + _segments[0] = curveLength; + for (ii = 1; ii < 8; ii++) { + dfx += ddfx; + dfy += ddfy; + ddfx += dddfx; + ddfy += dddfy; + curveLength += MathUtil::sqrt(dfx * dfx + dfy * dfy); + _segments[ii] = curveLength; + } + dfx += ddfx; + dfy += ddfy; + curveLength += MathUtil::sqrt(dfx * dfx + dfy * dfy); + _segments[8] = curveLength; + dfx += ddfx + dddfx; + dfy += ddfy + dddfy; + curveLength += MathUtil::sqrt(dfx * dfx + dfy * dfy); + _segments[9] = curveLength; + segment = 0; + } + + // Weight by segment length. + p *= curveLength; + for (;; segment++) { + float length = _segments[segment]; + if (p > length) continue; + if (segment == 0) + p /= length; + else { + float prev = _segments[segment - 1]; + p = segment + (p - prev) / (length - prev); + } + break; + } + addCurvePosition(p * 0.1f, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, + tangents || (i > 0 && space < EPSILON)); + } + + return out; +} + +void PathConstraint::addBeforePosition(float p, Vector &temp, int i, Vector &output, int o) { + float x1 = temp[i]; + float y1 = temp[i + 1]; + float dx = temp[i + 2] - x1; + float dy = temp[i + 3] - y1; + float r = MathUtil::atan2(dy, dx); + output[o] = x1 + p * MathUtil::cos(r); + output[o + 1] = y1 + p * MathUtil::sin(r); + output[o + 2] = r; +} + +void PathConstraint::addAfterPosition(float p, Vector &temp, int i, Vector &output, int o) { + float x1 = temp[i + 2]; + float y1 = temp[i + 3]; + float dx = x1 - temp[i]; + float dy = y1 - temp[i + 1]; + float r = MathUtil::atan2(dy, dx); + output[o] = x1 + p * MathUtil::cos(r); + output[o + 1] = y1 + p * MathUtil::sin(r); + output[o + 2] = r; +} + +void PathConstraint::addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, + float y2, Vector &output, int o, bool tangents) { + if (p < EPSILON || MathUtil::isNan(p)) { + output[o] = x1; + output[o + 1] = y1; + output[o + 2] = MathUtil::atan2(cy1 - y1, cx1 - x1); + return; + } + + float tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u; + float ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p; + float x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt; + output[o] = x; + output[o + 1] = y; + if (tangents) { + if (p < 0.001) + output[o + 2] = MathUtil::atan2(cy1 - y1, cx1 - x1); + else + output[o + 2] = MathUtil::atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), + x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)); + } +} + +bool PathConstraint::isActive() { + return _active; +} + +void PathConstraint::setActive(bool inValue) { + _active = inValue; +} + +void PathConstraint::setToSetupPose() { + PathConstraintData &data = this->_data; + this->_position = data._position; + this->_spacing = data._spacing; + this->_mixRotate = data._mixRotate; + this->_mixX = data._mixX; + this->_mixY = data._mixY; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraint.h b/native/cocos/editor-support/spine/4.2/spine/PathConstraint.h new file mode 100644 index 0000000000..082800b700 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraint.h @@ -0,0 +1,135 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PathConstraint_h +#define Spine_PathConstraint_h + +#include + +#include + +namespace spine { + class PathConstraintData; + + class Skeleton; + + class PathAttachment; + + class Bone; + + class Slot; + + class SP_API PathConstraint : public Updatable { + friend class Skeleton; + + friend class PathConstraintMixTimeline; + + friend class PathConstraintPositionTimeline; + + friend class PathConstraintSpacingTimeline; + + RTTI_DECL + + public: + PathConstraint(PathConstraintData &data, Skeleton &skeleton); + + virtual void update(Physics physics); + + virtual int getOrder(); + + PathConstraintData &getData(); + + Vector &getBones(); + + Slot *getTarget(); + + void setTarget(Slot *inValue); + + float getPosition(); + + void setPosition(float inValue); + + float getSpacing(); + + void setSpacing(float inValue); + + float getMixRotate(); + + void setMixRotate(float inValue); + + float getMixX(); + + void setMixX(float inValue); + + float getMixY(); + + void setMixY(float inValue); + + bool isActive(); + + void setActive(bool inValue); + + void setToSetupPose(); + + #ifndef __EMSCRIPTEN__ + private: + #endif + static const float EPSILON; + static const int NONE; + static const int BEFORE; + static const int AFTER; + + PathConstraintData &_data; + Vector _bones; + Slot *_target; + float _position, _spacing; + float _mixRotate, _mixX, _mixY; + + Vector _spaces; + Vector _positions; + Vector _world; + Vector _curves; + Vector _lengths; + Vector _segments; + + bool _active; + + Vector &computeWorldPositions(PathAttachment &path, int spacesCount, bool tangents); + + static void addBeforePosition(float p, Vector &temp, int i, Vector &output, int o); + + static void addAfterPosition(float p, Vector &temp, int i, Vector &output, int o); + + static void + addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, + Vector &output, int o, bool tangents); + }; +} + +#endif /* Spine_PathConstraint_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraintData.cpp b/native/cocos/editor-support/spine/4.2/spine/PathConstraintData.cpp new file mode 100644 index 0000000000..17a53fd73c --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraintData.cpp @@ -0,0 +1,136 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include + +using namespace spine; + +RTTI_IMPL(PathConstraintData, ConstraintData) + +PathConstraintData::PathConstraintData(const String &name) : ConstraintData(name), + _target(NULL), + _positionMode(PositionMode_Fixed), + _spacingMode(SpacingMode_Length), + _rotateMode(RotateMode_Tangent), + _offsetRotation(0), + _position(0), + _spacing(0), + _mixRotate(0), + _mixX(0), + _mixY(0) { +} + +Vector &PathConstraintData::getBones() { + return _bones; +} + +SlotData *PathConstraintData::getTarget() { + return _target; +} + +void PathConstraintData::setTarget(SlotData *inValue) { + _target = inValue; +} + +PositionMode PathConstraintData::getPositionMode() { + return _positionMode; +} + +void PathConstraintData::setPositionMode(PositionMode inValue) { + _positionMode = inValue; +} + +SpacingMode PathConstraintData::getSpacingMode() { + return _spacingMode; +} + +void PathConstraintData::setSpacingMode(SpacingMode inValue) { + _spacingMode = inValue; +} + +RotateMode PathConstraintData::getRotateMode() { + return _rotateMode; +} + +void PathConstraintData::setRotateMode(RotateMode inValue) { + _rotateMode = inValue; +} + +float PathConstraintData::getOffsetRotation() { + return _offsetRotation; +} + +void PathConstraintData::setOffsetRotation(float inValue) { + _offsetRotation = inValue; +} + +float PathConstraintData::getPosition() { + return _position; +} + +void PathConstraintData::setPosition(float inValue) { + _position = inValue; +} + +float PathConstraintData::getSpacing() { + return _spacing; +} + +void PathConstraintData::setSpacing(float inValue) { + _spacing = inValue; +} + +float PathConstraintData::getMixRotate() { + return _mixRotate; +} + +void PathConstraintData::setMixRotate(float inValue) { + _mixRotate = inValue; +} + +float PathConstraintData::getMixX() { + return _mixX; +} + +void PathConstraintData::setMixX(float inValue) { + _mixX = inValue; +} + +float PathConstraintData::getMixY() { + return _mixY; +} + +void PathConstraintData::setMixY(float inValue) { + _mixY = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraintData.h b/native/cocos/editor-support/spine/4.2/spine/PathConstraintData.h new file mode 100644 index 0000000000..fc78c40a3a --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraintData.h @@ -0,0 +1,121 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PathConstraintData_h +#define Spine_PathConstraintData_h + +#include +#include +#include +#include +#include +#include +#include + +namespace spine { + class BoneData; + + class SlotData; + + class SP_API PathConstraintData : public ConstraintData { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class PathConstraint; + + friend class Skeleton; + + friend class PathConstraintMixTimeline; + + friend class PathConstraintPositionTimeline; + + friend class PathConstraintSpacingTimeline; + public: + RTTI_DECL + + explicit PathConstraintData(const String &name); + + Vector &getBones(); + + SlotData *getTarget(); + + void setTarget(SlotData *inValue); + + PositionMode getPositionMode(); + + void setPositionMode(PositionMode inValue); + + SpacingMode getSpacingMode(); + + void setSpacingMode(SpacingMode inValue); + + RotateMode getRotateMode(); + + void setRotateMode(RotateMode inValue); + + float getOffsetRotation(); + + void setOffsetRotation(float inValue); + + float getPosition(); + + void setPosition(float inValue); + + float getSpacing(); + + void setSpacing(float inValue); + + float getMixRotate(); + + void setMixRotate(float inValue); + + float getMixX(); + + void setMixX(float inValue); + + float getMixY(); + + void setMixY(float inValue); + + #ifndef __EMSCRIPTEN__ + private: + #endif + Vector _bones; + SlotData *_target; + PositionMode _positionMode; + SpacingMode _spacingMode; + RotateMode _rotateMode; + float _offsetRotation; + float _position, _spacing; + float _mixRotate, _mixX, _mixY; + }; +} + +#endif /* Spine_PathConstraintData_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraintMixTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/PathConstraintMixTimeline.cpp new file mode 100644 index 0000000000..1b8008693d --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraintMixTimeline.cpp @@ -0,0 +1,127 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace spine; +const int PathConstraintMixTimeline::ENTRIES = 4; + +RTTI_IMPL(PathConstraintMixTimeline, CurveTimeline) + +PathConstraintMixTimeline::PathConstraintMixTimeline(size_t frameCount, size_t bezierCount, int pathConstraintIndex) + : CurveTimeline(frameCount, PathConstraintMixTimeline::ENTRIES, bezierCount), + _constraintIndex(pathConstraintIndex) { + PropertyId ids[] = {((PropertyId) Property_PathConstraintMix << 32) | pathConstraintIndex}; + setPropertyIds(ids, 1); +} + +void PathConstraintMixTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + PathConstraint *constraintP = skeleton._pathConstraints[_constraintIndex]; + PathConstraint &constraint = *constraintP; + if (!constraint.isActive()) return; + + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + constraint._mixRotate = constraint._data._mixRotate; + constraint._mixX = constraint._data._mixX; + constraint._mixY = constraint._data._mixY; + return; + case MixBlend_First: + constraint._mixRotate += (constraint._data._mixRotate - constraint._mixRotate) * alpha; + constraint._mixX += (constraint._data._mixX - constraint._mixX) * alpha; + constraint._mixY += (constraint._data._mixY - constraint._mixY) * alpha; + default: { + } + } + return; + } + + float rotate, x, y; + int i = Animation::search(_frames, time, PathConstraintMixTimeline::ENTRIES); + int curveType = (int) _curves[i >> 2]; + switch (curveType) { + case LINEAR: { + float before = _frames[i]; + rotate = _frames[i + ROTATE]; + x = _frames[i + X]; + y = _frames[i + Y]; + float t = (time - before) / (_frames[i + ENTRIES] - before); + rotate += (_frames[i + ENTRIES + ROTATE] - rotate) * t; + x += (_frames[i + ENTRIES + X] - x) * t; + y += (_frames[i + ENTRIES + Y] - y) * t; + break; + } + case STEPPED: { + rotate = _frames[i + ROTATE]; + x = _frames[i + X]; + y = _frames[i + Y]; + break; + } + default: { + rotate = getBezierValue(time, i, ROTATE, curveType - BEZIER); + x = getBezierValue(time, i, X, curveType + BEZIER_SIZE - BEZIER); + y = getBezierValue(time, i, Y, curveType + BEZIER_SIZE * 2 - BEZIER); + } + } + + if (blend == MixBlend_Setup) { + PathConstraintData data = constraint._data; + constraint._mixRotate = data._mixRotate + (rotate - data._mixRotate) * alpha; + constraint._mixX = data._mixX + (x - data._mixX) * alpha; + constraint._mixY = data._mixY + (y - data._mixY) * alpha; + } else { + constraint._mixRotate += (rotate - constraint._mixRotate) * alpha; + constraint._mixX += (x - constraint._mixX) * alpha; + constraint._mixY += (y - constraint._mixY) * alpha; + } +} + +void PathConstraintMixTimeline::setFrame(int frame, float time, float mixRotate, float mixX, float mixY) { + frame *= ENTRIES; + _frames[frame] = time; + _frames[frame + ROTATE] = mixRotate; + _frames[frame + X] = mixX; + _frames[frame + Y] = mixY; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraintMixTimeline.h b/native/cocos/editor-support/spine/4.2/spine/PathConstraintMixTimeline.h new file mode 100644 index 0000000000..22dea07630 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraintMixTimeline.h @@ -0,0 +1,69 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PathConstraintMixTimeline_h +#define Spine_PathConstraintMixTimeline_h + +#include + +namespace spine { + + class SP_API PathConstraintMixTimeline : public CurveTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PathConstraintMixTimeline(size_t frameCount, size_t bezierCount, int pathConstraintIndex); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + /// Sets the time and mixes of the specified keyframe. + void setFrame(int frameIndex, float time, float mixRotate, float mixX, float mixY); + + int getPathConstraintIndex() { return _constraintIndex; } + + void setPathConstraintIndex(int inValue) { _constraintIndex = inValue; } + #ifndef __EMSCRIPTEN__ + private: + #endif + int _constraintIndex; + + static const int ENTRIES; + static const int ROTATE = 1; + static const int X = 2; + static const int Y = 2; + }; +} + +#endif /* Spine_PathConstraintMixTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraintPositionTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/PathConstraintPositionTimeline.cpp new file mode 100644 index 0000000000..60bf8a5025 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraintPositionTimeline.cpp @@ -0,0 +1,66 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(PathConstraintPositionTimeline, CurveTimeline1) + +PathConstraintPositionTimeline::PathConstraintPositionTimeline(size_t frameCount, size_t bezierCount, + int pathConstraintIndex) : CurveTimeline1(frameCount, + bezierCount), + _constraintIndex( + pathConstraintIndex) { + PropertyId ids[] = {((PropertyId) Property_PathConstraintPosition << 32) | pathConstraintIndex}; + setPropertyIds(ids, 1); +} + +PathConstraintPositionTimeline::~PathConstraintPositionTimeline() { +} + +void PathConstraintPositionTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, + float alpha, MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + PathConstraint *constraint = skeleton._pathConstraints[_constraintIndex]; + if (constraint->_active) constraint->_position = getAbsoluteValue(time, alpha, blend, constraint->_position, constraint->_data._position); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraintPositionTimeline.h b/native/cocos/editor-support/spine/4.2/spine/PathConstraintPositionTimeline.h new file mode 100644 index 0000000000..55d72177f9 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraintPositionTimeline.h @@ -0,0 +1,64 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PathConstraintPositionTimeline_h +#define Spine_PathConstraintPositionTimeline_h + +#include + +namespace spine { + + class SP_API PathConstraintPositionTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + static const int ENTRIES; + + explicit PathConstraintPositionTimeline(size_t frameCount, size_t bezierCount, int pathConstraintIndex); + + virtual ~PathConstraintPositionTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getPathConstraintIndex() { return _constraintIndex; } + + void setPathConstraintIndex(int inValue) { _constraintIndex = inValue; } + + protected: + int _constraintIndex; + }; +} + +#endif /* Spine_PathConstraintPositionTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraintSpacingTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/PathConstraintSpacingTimeline.cpp new file mode 100644 index 0000000000..3c4e83cc4c --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraintSpacingTimeline.cpp @@ -0,0 +1,64 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(PathConstraintSpacingTimeline, PathConstraintPositionTimeline) + +PathConstraintSpacingTimeline::PathConstraintSpacingTimeline(size_t frameCount, size_t bezierCount, + int pathConstraintIndex) : CurveTimeline1(frameCount, + bezierCount), + _pathConstraintIndex( + pathConstraintIndex) { + PropertyId ids[] = {((PropertyId) Property_PathConstraintSpacing << 32) | pathConstraintIndex}; + setPropertyIds(ids, 1); +} + +void PathConstraintSpacingTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, + float alpha, MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + PathConstraint *constraint = skeleton._pathConstraints[_pathConstraintIndex]; + if (constraint->_active) + constraint->_spacing = getAbsoluteValue(time, alpha, blend, constraint->_spacing, constraint->_data._spacing); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/PathConstraintSpacingTimeline.h b/native/cocos/editor-support/spine/4.2/spine/PathConstraintSpacingTimeline.h new file mode 100644 index 0000000000..52b4e8ade1 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PathConstraintSpacingTimeline.h @@ -0,0 +1,59 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PathConstraintSpacingTimeline_h +#define Spine_PathConstraintSpacingTimeline_h + +#include + +namespace spine { + class SP_API PathConstraintSpacingTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PathConstraintSpacingTimeline(size_t frameCount, size_t bezierCount, int pathConstraintIndex); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getPathConstraintIndex() { return _pathConstraintIndex; } + + void setPathConstraintIndex(int inValue) { _pathConstraintIndex = inValue; } + + protected: + int _pathConstraintIndex; + }; +} + +#endif /* Spine_PathConstraintSpacingTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Physics.h b/native/cocos/editor-support/spine/4.2/spine/Physics.h new file mode 100644 index 0000000000..310e3ba616 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Physics.h @@ -0,0 +1,49 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ +#ifndef Spine_Physics_h +#define Spine_Physics_h + +/** Determines how physics and other non-deterministic updates are applied. */ +namespace spine { + enum Physics { + /** Physics are not updated or applied. */ + Physics_None, + + /** Physics are reset to the current pose. */ + Physics_Reset, + + /** Physics are updated and the pose from physics is applied. */ + Physics_Update, + + /** Physics are not updated but the pose from physics is applied. */ + Physics_Pose + }; +} + +#endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraint.cpp b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraint.cpp new file mode 100644 index 0000000000..c04f76d198 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraint.cpp @@ -0,0 +1,493 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include + +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(PhysicsConstraint, Updatable) + +PhysicsConstraint::PhysicsConstraint(PhysicsConstraintData &data, Skeleton &skeleton) + : _data(data), _skeleton(skeleton) { + _bone = skeleton.getBones()[data.getBone()->getIndex()]; + _inertia = data.getInertia(); + _strength = data.getStrength(); + _damping = data.getDamping(); + _massInverse = data.getMassInverse(); + _wind = data.getWind(); + _gravity = data.getGravity(); + _mix = data.getMix(); + + _reset = true; + _ux = 0; + _uy = 0; + _cx = 0; + _cy = 0; + _tx = 0; + _ty = 0; + _xOffset = 0; + _xVelocity = 0; + _yOffset = 0; + _yVelocity = 0; + _rotateOffset = 0; + _rotateVelocity = 0; + _scaleOffset = 0; + _scaleVelocity = 0; + _active = false; + _remaining = 0; + _lastTime = 0; +} + +PhysicsConstraintData &PhysicsConstraint::getData() { + return _data; +} + +void PhysicsConstraint::setBone(Bone *bone) { + _bone = bone; +} + +Bone *PhysicsConstraint::getBone() { + return _bone; +} + +void PhysicsConstraint::setInertia(float value) { + _inertia = value; +} + +float PhysicsConstraint::getInertia() { + return _inertia; +} + +void PhysicsConstraint::setStrength(float value) { + _strength = value; +} + +float PhysicsConstraint::getStrength() { + return _strength; +} + +void PhysicsConstraint::setDamping(float value) { + _damping = value; +} + +float PhysicsConstraint::getDamping() { + return _damping; +} + +void PhysicsConstraint::setMassInverse(float value) { + _massInverse = value; +} + +float PhysicsConstraint::getMassInverse() { + return _massInverse; +} + +void PhysicsConstraint::setWind(float value) { + _wind = value; +} + +float PhysicsConstraint::getWind() { + return _wind; +} + +void PhysicsConstraint::setGravity(float value) { + _gravity = value; +} + +float PhysicsConstraint::getGravity() { + return _gravity; +} + +void PhysicsConstraint::setMix(float value) { + _mix = value; +} + +float PhysicsConstraint::getMix() { + return _mix; +} + +void PhysicsConstraint::setReset(bool value) { + _reset = value; +} + +bool PhysicsConstraint::getReset() { + return _reset; +} + +void PhysicsConstraint::setUx(float value) { + _ux = value; +} + +float PhysicsConstraint::getUx() { + return _ux; +} + +void PhysicsConstraint::setUy(float value) { + _uy = value; +} + +float PhysicsConstraint::getUy() { + return _uy; +} + +void PhysicsConstraint::setCx(float value) { + _cx = value; +} + +float PhysicsConstraint::getCx() { + return _cx; +} + +void PhysicsConstraint::setCy(float value) { + _cy = value; +} + +float PhysicsConstraint::getCy() { + return _cy; +} + +void PhysicsConstraint::setTx(float value) { + _tx = value; +} + +float PhysicsConstraint::getTx() { + return _tx; +} + +void PhysicsConstraint::setTy(float value) { + _ty = value; +} + +float PhysicsConstraint::getTy() { + return _ty; +} + +void PhysicsConstraint::setXOffset(float value) { + _xOffset = value; +} + +float PhysicsConstraint::getXOffset() { + return _xOffset; +} + +void PhysicsConstraint::setXVelocity(float value) { + _xVelocity = value; +} + +float PhysicsConstraint::getXVelocity() { + return _xVelocity; +} + +void PhysicsConstraint::setYOffset(float value) { + _yOffset = value; +} + +float PhysicsConstraint::getYOffset() { + return _yOffset; +} + +void PhysicsConstraint::setYVelocity(float value) { + _yVelocity = value; +} + +float PhysicsConstraint::getYVelocity() { + return _yVelocity; +} + +void PhysicsConstraint::setRotateOffset(float value) { + _rotateOffset = value; +} + +float PhysicsConstraint::getRotateOffset() { + return _rotateOffset; +} + +void PhysicsConstraint::setRotateVelocity(float value) { + _rotateVelocity = value; +} + +float PhysicsConstraint::getRotateVelocity() { + return _rotateVelocity; +} + +void PhysicsConstraint::setScaleOffset(float value) { + _scaleOffset = value; +} + +float PhysicsConstraint::getScaleOffset() { + return _scaleOffset; +} + +void PhysicsConstraint::setScaleVelocity(float value) { + _scaleVelocity = value; +} + +float PhysicsConstraint::getScaleVelocity() { + return _scaleVelocity; +} + +void PhysicsConstraint::setActive(bool value) { + _active = value; +} + +bool PhysicsConstraint::isActive() { + return _active; +} + +void PhysicsConstraint::setRemaining(float value) { + _remaining = value; +} + +float PhysicsConstraint::getRemaining() { + return _remaining; +} + +void PhysicsConstraint::setLastTime(float value) { + _lastTime = value; +} + +float PhysicsConstraint::getLastTime() { + return _lastTime; +} + +void PhysicsConstraint::reset() { + _remaining = 0; + _lastTime = _skeleton.getTime(); + _reset = true; + _xOffset = 0; + _xVelocity = 0; + _yOffset = 0; + _yVelocity = 0; + _rotateOffset = 0; + _rotateVelocity = 0; + _scaleOffset = 0; + _scaleVelocity = 0; +} + +void PhysicsConstraint::setToSetupPose() { + _inertia = _data.getInertia(); + _strength = _data.getStrength(); + _damping = _data.getDamping(); + _massInverse = _data.getMassInverse(); + _wind = _data.getWind(); + _gravity = _data.getGravity(); + _mix = _data.getMix(); +} +void PhysicsConstraint::update(Physics physics) { + float mix = _mix; + if (mix == 0) return; + + bool x = _data._x > 0; + bool y = _data._y > 0; + bool rotateOrShearX = _data._rotate > 0 || _data._shearX > 0; + bool scaleX = _data._scaleX > 0; + + Bone *bone = _bone; + float l = bone->_data.getLength(); + + switch (physics) { + case Physics::Physics_None: + return; + case Physics::Physics_Reset: + reset(); + // Fall through. + case Physics::Physics_Update: { + float delta = MathUtil::max(_skeleton.getTime() - _lastTime, 0.0f); + _remaining += delta; + _lastTime = _skeleton.getTime(); + + float bx = bone->_worldX, by = bone->_worldY; + if (_reset) { + _reset = false; + _ux = bx; + _uy = by; + } else { + float a = _remaining, i = _inertia, t = _data._step, f = _skeleton.getData()->getReferenceScale(); + float qx = _data._limit * delta, qy = qx * MathUtil::abs(_skeleton.getScaleX()); + qx *= MathUtil::abs(_skeleton.getScaleY()); + if (x || y) { + if (x) { + float u = (_ux - bx) * i; + _xOffset += u > qx ? qx : u < -qx ? -qx + : u; + _ux = bx; + } + if (y) { + float u = (_uy - by) * i; + _yOffset += u > qy ? qy : u < -qy ? -qy + : u; + _uy = by; + } + if (a >= t) { + float d = MathUtil::pow(_damping, 60 * t); + float m = _massInverse * t, e = _strength, w = _wind * f, g = _gravity * f * (Bone::yDown ? -1 : 1); + do { + if (x) { + _xVelocity += (w - _xOffset * e) * m; + _xOffset += _xVelocity * t; + _xVelocity *= d; + } + if (y) { + _yVelocity -= (g + _yOffset * e) * m; + _yOffset += _yVelocity * t; + _yVelocity *= d; + } + a -= t; + } while (a >= t); + } + if (x) bone->_worldX += _xOffset * mix * _data._x; + if (y) bone->_worldY += _yOffset * mix * _data._y; + } + + if (rotateOrShearX || scaleX) { + float ca = MathUtil::atan2(bone->_c, bone->_a), c, s, mr = 0; + float dx = _cx - bone->_worldX, dy = _cy - bone->_worldY; + if (dx > qx) + dx = qx; + else if (dx < -qx)// + dx = -qx; + if (dy > qy) + dy = qy; + else if (dy < -qy)// + dy = -qy; + if (rotateOrShearX) { + mr = (_data._rotate + _data._shearX) * mix; + float r = MathUtil::atan2(dy + _ty, dx + _tx) - ca - _rotateOffset * mr; + _rotateOffset += (r - MathUtil::ceil(r * MathUtil::InvPi_2 - 0.5f) * MathUtil::Pi_2) * i; + r = _rotateOffset * mr + ca; + c = MathUtil::cos(r); + s = MathUtil::sin(r); + if (scaleX) { + r = l * bone->getWorldScaleX(); + if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r; + } + } else { + c = MathUtil::cos(ca); + s = MathUtil::sin(ca); + float r = l * bone->getWorldScaleX(); + if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r; + } + a = _remaining; + if (a >= t) { + float m = _massInverse * t, e = _strength, w = _wind, g = _gravity * (Bone::yDown ? -1 : 1), h = l / f; + float d = MathUtil::pow(_damping, 60 * t); + while (true) { + a -= t; + if (scaleX) { + _scaleVelocity += (w * c - g * s - _scaleOffset * e) * m; + _scaleOffset += _scaleVelocity * t; + _scaleVelocity *= d; + } + if (rotateOrShearX) { + _rotateVelocity -= ((w * s + g * c) * h + _rotateOffset * e) * m; + _rotateOffset += _rotateVelocity * t; + _rotateVelocity *= d; + if (a < t) break; + float r = _rotateOffset * mr + ca; + c = MathUtil::cos(r); + s = MathUtil::sin(r); + } else if (a < t)// + break; + } + } + } + _remaining = a; + } + + _cx = bone->_worldX; + _cy = bone->_worldY; + break; + } + case Physics::Physics_Pose: { + if (x) bone->_worldX += _xOffset * mix * _data._x; + if (y) bone->_worldY += _yOffset * mix * _data._y; + break; + } + } + + if (rotateOrShearX) { + float o = _rotateOffset * mix, s = 0, c = 0, a = 0; + if (_data._shearX > 0) { + float r = 0; + if (_data._rotate > 0) { + r = o * _data._rotate; + s = MathUtil::sin(r); + c = MathUtil::cos(r); + a = bone->_b; + bone->_b = c * a - s * bone->_d; + bone->_d = s * a + c * bone->_d; + } + r += o * _data._shearX; + s = MathUtil::sin(r); + c = MathUtil::cos(r); + a = bone->_a; + bone->_a = c * a - s * bone->_c; + bone->_c = s * a + c * bone->_c; + } else { + o *= _data._rotate; + s = MathUtil::sin(o); + c = MathUtil::cos(o); + a = bone->_a; + bone->_a = c * a - s * bone->_c; + bone->_c = s * a + c * bone->_c; + a = bone->_b; + bone->_b = c * a - s * bone->_d; + bone->_d = s * a + c * bone->_d; + } + } + if (scaleX) { + float s = 1 + _scaleOffset * mix * _data._scaleX; + bone->_a *= s; + bone->_c *= s; + } + if (physics != Physics::Physics_Pose) { + _tx = l * bone->_a; + _ty = l * bone->_c; + } + bone->updateAppliedTransform(); +} + +void PhysicsConstraint::rotate(float x, float y, float degrees) { + float r = degrees * MathUtil::Deg_Rad, cos = MathUtil::cos(r), sin = MathUtil::sin(r); + float dx = _cx - x, dy = _cy - y; + translate(dx * cos - dy * sin - dx, dx * sin + dy * cos - dy); +} + +void PhysicsConstraint::translate(float x, float y) { + _ux -= x; + _uy -= y; + _cx -= x; + _cy -= y; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraint.h b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraint.h new file mode 100644 index 0000000000..113ba7e2ed --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraint.h @@ -0,0 +1,197 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PhysicsConstraint_h +#define Spine_PhysicsConstraint_h + +#include + +#include + +namespace spine { + class PhysicsConstraintData; + + class Skeleton; + + class Bone; + + class SP_API PhysicsConstraint : public Updatable { + + friend class Skeleton; + + friend class PhysicsConstraintTimeline; + + friend class PhysicsConstraintInertiaTimeline; + + friend class PhysicsConstraintStrengthTimeline; + + friend class PhysicsConstraintDampingTimeline; + + friend class PhysicsConstraintMassTimeline; + + friend class PhysicsConstraintWindTimeline; + + friend class PhysicsConstraintGravityTimeline; + + friend class PhysicsConstraintMixTimeline; + + friend class PhysicsConstraintResetTimeline; + + RTTI_DECL + + public: + PhysicsConstraint(PhysicsConstraintData& data, Skeleton& skeleton); + + PhysicsConstraintData &getData(); + + void setBone(Bone* bone); + Bone* getBone(); + + void setInertia(float value); + float getInertia(); + + void setStrength(float value); + float getStrength(); + + void setDamping(float value); + float getDamping(); + + void setMassInverse(float value); + float getMassInverse(); + + void setWind(float value); + float getWind(); + + void setGravity(float value); + float getGravity(); + + void setMix(float value); + float getMix(); + + void setReset(bool value); + bool getReset(); + + void setUx(float value); + float getUx(); + + void setUy(float value); + float getUy(); + + void setCx(float value); + float getCx(); + + void setCy(float value); + float getCy(); + + void setTx(float value); + float getTx(); + + void setTy(float value); + float getTy(); + + void setXOffset(float value); + float getXOffset(); + + void setXVelocity(float value); + float getXVelocity(); + + void setYOffset(float value); + float getYOffset(); + + void setYVelocity(float value); + float getYVelocity(); + + void setRotateOffset(float value); + float getRotateOffset(); + + void setRotateVelocity(float value); + float getRotateVelocity(); + + void setScaleOffset(float value); + float getScaleOffset(); + + void setScaleVelocity(float value); + float getScaleVelocity(); + + void setActive(bool value); + bool isActive(); + + void setRemaining(float value); + float getRemaining(); + + void setLastTime(float value); + float getLastTime(); + + void reset(); + + void setToSetupPose(); + + virtual void update(Physics physics); + + void translate(float x, float y); + + void rotate(float x, float y, float degrees); + + private: + PhysicsConstraintData& _data; + Bone* _bone; + + float _inertia; + float _strength; + float _damping; + float _massInverse; + float _wind; + float _gravity; + float _mix; + + bool _reset; + float _ux; + float _uy; + float _cx; + float _cy; + float _tx; + float _ty; + float _xOffset; + float _xVelocity; + float _yOffset; + float _yVelocity; + float _rotateOffset; + float _rotateVelocity; + float _scaleOffset; + float _scaleVelocity; + + bool _active; + + Skeleton& _skeleton; + float _remaining; + float _lastTime; + }; +} + +#endif /* Spine_PhysicsConstraint_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintData.cpp b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintData.cpp new file mode 100644 index 0000000000..9bcedab5ea --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintData.cpp @@ -0,0 +1,223 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +#include + +using namespace spine; + +RTTI_IMPL(PhysicsConstraintData, ConstraintData) + +PhysicsConstraintData::PhysicsConstraintData(const String &name) : ConstraintData(name), + _bone(nullptr), + _x(0), _y(0), _rotate(0), _scaleX(0), _shearX(0), _limit(0), + _step(0), _inertia(0), _strength(0), _damping(0), _massInverse(0), _wind(0), _gravity(0), _mix(0), + _inertiaGlobal(false), _strengthGlobal(false), _dampingGlobal(false), _massGlobal(false), + _windGlobal(false), _gravityGlobal(false), _mixGlobal(false) { +} + + +void PhysicsConstraintData::setBone(BoneData *bone) { + _bone = bone; +} + +BoneData *PhysicsConstraintData::getBone() const { + return _bone; +} + +void PhysicsConstraintData::setX(float x) { + _x = x; +} + +float PhysicsConstraintData::getX() const { + return _x; +} + +void PhysicsConstraintData::setY(float y) { + _y = y; +} + +float PhysicsConstraintData::getY() const { + return _y; +} + +void PhysicsConstraintData::setRotate(float rotate) { + _rotate = rotate; +} + +float PhysicsConstraintData::getRotate() const { + return _rotate; +} + +void PhysicsConstraintData::setScaleX(float scaleX) { + _scaleX = scaleX; +} + +float PhysicsConstraintData::getScaleX() const { + return _scaleX; +} + +void PhysicsConstraintData::setShearX(float shearX) { + _shearX = shearX; +} + +float PhysicsConstraintData::getShearX() const { + return _shearX; +} + +void PhysicsConstraintData::setLimit(float limit) { + _limit = limit; +} + +float PhysicsConstraintData::getLimit() const { + return _limit; +} + +void PhysicsConstraintData::setStep(float step) { + _step = step; +} + +float PhysicsConstraintData::getStep() const { + return _step; +} + +void PhysicsConstraintData::setInertia(float inertia) { + _inertia = inertia; +} + +float PhysicsConstraintData::getInertia() const { + return _inertia; +} + +void PhysicsConstraintData::setStrength(float strength) { + _strength = strength; +} + +float PhysicsConstraintData::getStrength() const { + return _strength; +} + +void PhysicsConstraintData::setDamping(float damping) { + _damping = damping; +} + +float PhysicsConstraintData::getDamping() const { + return _damping; +} + +void PhysicsConstraintData::setMassInverse(float massInverse) { + _massInverse = massInverse; +} + +float PhysicsConstraintData::getMassInverse() const { + return _massInverse; +} + +void PhysicsConstraintData::setWind(float wind) { + _wind = wind; +} + +float PhysicsConstraintData::getWind() const { + return _wind; +} + +void PhysicsConstraintData::setGravity(float gravity) { + _gravity = gravity; +} + +float PhysicsConstraintData::getGravity() const { + return _gravity; +} + +void PhysicsConstraintData::setMix(float mix) { + _mix = mix; +} + +float PhysicsConstraintData::getMix() const { + return _mix; +} + +void PhysicsConstraintData::setInertiaGlobal(bool inertiaGlobal) { + _inertiaGlobal = inertiaGlobal; +} + +bool PhysicsConstraintData::isInertiaGlobal() const { + return _inertiaGlobal; +} + +void PhysicsConstraintData::setStrengthGlobal(bool strengthGlobal) { + _strengthGlobal = strengthGlobal; +} + +bool PhysicsConstraintData::isStrengthGlobal() const { + return _strengthGlobal; +} + +void PhysicsConstraintData::setDampingGlobal(bool dampingGlobal) { + _dampingGlobal = dampingGlobal; +} + +bool PhysicsConstraintData::isDampingGlobal() const { + return _dampingGlobal; +} + +void PhysicsConstraintData::setMassGlobal(bool massGlobal) { + _massGlobal = massGlobal; +} + +bool PhysicsConstraintData::isMassGlobal() const { + return _massGlobal; +} + +void PhysicsConstraintData::setWindGlobal(bool windGlobal) { + _windGlobal = windGlobal; +} + +bool PhysicsConstraintData::isWindGlobal() const { + return _windGlobal; +} + +void PhysicsConstraintData::setGravityGlobal(bool gravityGlobal) { + _gravityGlobal = gravityGlobal; +} + +bool PhysicsConstraintData::isGravityGlobal() const { + return _gravityGlobal; +} + +void PhysicsConstraintData::setMixGlobal(bool mixGlobal) { + _mixGlobal = mixGlobal; +} + +bool PhysicsConstraintData::isMixGlobal() const { + return _mixGlobal; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintData.h b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintData.h new file mode 100644 index 0000000000..3b1d177c3f --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintData.h @@ -0,0 +1,151 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PhysicsConstraintData_h +#define Spine_PhysicsConstraintData_h + +#include +#include +#include +#include + +namespace spine { + class BoneData; + + class SP_API PhysicsConstraintData : public ConstraintData { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class Skeleton; + + friend class PhysicsConstraint; + + public: + RTTI_DECL + + explicit PhysicsConstraintData(const String &name); + + void setBone(BoneData* bone); + + BoneData* getBone() const; + + void setX(float x); + + float getX() const; + + void setY(float y); + + float getY() const; + + void setRotate(float rotate); + + float getRotate() const; + + void setScaleX(float scaleX); + + float getScaleX() const; + + void setShearX(float shearX); + + float getShearX() const; + + void setLimit(float limit); + + float getLimit() const; + + void setStep(float step); + + float getStep() const; + + void setInertia(float inertia); + + float getInertia() const; + + void setStrength(float strength); + + float getStrength() const; + + void setDamping(float damping); + + float getDamping() const; + + void setMassInverse(float massInverse); + + float getMassInverse() const; + + void setWind(float wind); + + float getWind() const; + + void setGravity(float gravity); + + float getGravity() const; + + void setMix(float mix); + + float getMix() const; + + void setInertiaGlobal(bool inertiaGlobal); + + bool isInertiaGlobal() const; + + void setStrengthGlobal(bool strengthGlobal); + + bool isStrengthGlobal() const; + + void setDampingGlobal(bool dampingGlobal); + + bool isDampingGlobal() const; + + void setMassGlobal(bool massGlobal); + + bool isMassGlobal() const; + + void setWindGlobal(bool windGlobal); + + bool isWindGlobal() const; + + void setGravityGlobal(bool gravityGlobal); + + bool isGravityGlobal() const; + + void setMixGlobal(bool mixGlobal); + + bool isMixGlobal() const; + + private: + BoneData *_bone; + float _x, _y, _rotate, _scaleX, _shearX, _limit; + float _step, _inertia, _strength, _damping, _massInverse, _wind, _gravity, _mix; + bool _inertiaGlobal, _strengthGlobal, _dampingGlobal, _massGlobal, _windGlobal, _gravityGlobal, _mixGlobal; + }; +} + +#endif /* Spine_PhysicsConstraintData_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintTimeline.cpp new file mode 100644 index 0000000000..32f202cd35 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintTimeline.cpp @@ -0,0 +1,102 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(PhysicsConstraintTimeline, CurveTimeline) +RTTI_IMPL(PhysicsConstraintInertiaTimeline, PhysicsConstraintTimeline) +RTTI_IMPL(PhysicsConstraintStrengthTimeline, PhysicsConstraintTimeline) +RTTI_IMPL(PhysicsConstraintDampingTimeline, PhysicsConstraintTimeline) +RTTI_IMPL(PhysicsConstraintMassTimeline, PhysicsConstraintTimeline) +RTTI_IMPL(PhysicsConstraintWindTimeline, PhysicsConstraintTimeline) +RTTI_IMPL(PhysicsConstraintGravityTimeline, PhysicsConstraintTimeline) +RTTI_IMPL(PhysicsConstraintMixTimeline, PhysicsConstraintTimeline) +RTTI_IMPL(PhysicsConstraintResetTimeline, Timeline) + +PhysicsConstraintTimeline::PhysicsConstraintTimeline(size_t frameCount, size_t bezierCount, + int constraintIndex, Property property) : CurveTimeline1(frameCount, bezierCount), + _constraintIndex(constraintIndex) { + PropertyId ids[] = {((PropertyId) property << 32) | constraintIndex}; + setPropertyIds(ids, 1); +} + +void PhysicsConstraintTimeline::apply(Skeleton &skeleton, float, float time, Vector *, + float alpha, MixBlend blend, MixDirection) { + if (_constraintIndex == -1) { + float value = time >= _frames[0] ? getCurveValue(time) : 0; + + Vector &physicsConstraints = skeleton.getPhysicsConstraints(); + for (size_t i = 0; i < physicsConstraints.size(); i++) { + PhysicsConstraint *constraint = physicsConstraints[i]; + if (constraint->_active && global(constraint->_data)) + set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint), value)); + } + } else { + PhysicsConstraint *constraint = skeleton.getPhysicsConstraints()[_constraintIndex]; + if (constraint->_active) set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint))); + } +} + +void PhysicsConstraintResetTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *, float alpha, MixBlend blend, MixDirection direction) { + PhysicsConstraint *constraint = nullptr; + if (_constraintIndex != -1) { + constraint = skeleton.getPhysicsConstraints()[_constraintIndex]; + if (!constraint->_active) return; + } + + if (lastTime > time) {// Apply after lastTime for looped animations. + apply(skeleton, lastTime, FLT_MAX, nullptr, alpha, blend, direction); + lastTime = -1; + } else if (lastTime >= _frames[_frames.size() - 1])// Last time is after last frame. + return; + if (time < _frames[0]) return; + + if (lastTime < _frames[0] || time >= _frames[Animation::search(_frames, lastTime) + 1]) { + if (constraint != nullptr) + constraint->reset(); + else { + Vector &physicsConstraints = skeleton.getPhysicsConstraints(); + for (size_t i = 0; i < physicsConstraints.size(); i++) { + if (constraint->_active) constraint->reset(); + } + } + } +} \ No newline at end of file diff --git a/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintTimeline.h b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintTimeline.h new file mode 100644 index 0000000000..5a60b036a9 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PhysicsConstraintTimeline.h @@ -0,0 +1,288 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PhysicsConstraintTimeline_h +#define Spine_PhysicsConstraintTimeline_h + +#include +#include +#include + +namespace spine { + + class SP_API PhysicsConstraintTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PhysicsConstraintTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex, Property property); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getPhysicsConstraintIndex() { return _constraintIndex; } + + void setPhysicsConstraintIndex(int inValue) { _constraintIndex = inValue; } + + protected: + virtual float setup(PhysicsConstraint *constraint) = 0; + virtual float get(PhysicsConstraint *constraint) = 0; + virtual void set(PhysicsConstraint *constraint, float value) = 0; + virtual bool global(PhysicsConstraintData &constraintData) = 0; + + private: + int _constraintIndex; + }; + + class SP_API PhysicsConstraintInertiaTimeline : public PhysicsConstraintTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PhysicsConstraintInertiaTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintInertia) {}; + + protected: + float setup(PhysicsConstraint *constraint) { + return constraint->_data.getInertia(); + } + + float get(PhysicsConstraint *constraint) { + return constraint->_inertia; + } + + void set(PhysicsConstraint *constraint, float value) { + constraint->_inertia = value; + } + + bool global(PhysicsConstraintData &constraintData) { + return constraintData.isInertiaGlobal(); + } + }; + + class SP_API PhysicsConstraintStrengthTimeline : public PhysicsConstraintTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PhysicsConstraintStrengthTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintStrength) {}; + + protected: + float setup(PhysicsConstraint *constraint) { + return constraint->_data.getStrength(); + } + + float get(PhysicsConstraint *constraint) { + return constraint->_strength; + } + + void set(PhysicsConstraint *constraint, float value) { + constraint->_strength = value; + } + + bool global(PhysicsConstraintData &constraintData) { + return constraintData.isStrengthGlobal(); + } + }; + + class SP_API PhysicsConstraintDampingTimeline : public PhysicsConstraintTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PhysicsConstraintDampingTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintDamping) {}; + + protected: + float setup(PhysicsConstraint *constraint) { + return constraint->_data.getDamping(); + } + + float get(PhysicsConstraint *constraint) { + return constraint->_damping; + } + + void set(PhysicsConstraint *constraint, float value) { + constraint->_damping = value; + } + + bool global(PhysicsConstraintData &constraintData) { + return constraintData.isDampingGlobal(); + } + }; + + class SP_API PhysicsConstraintMassTimeline : public PhysicsConstraintTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PhysicsConstraintMassTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintMass) {}; + + protected: + float setup(PhysicsConstraint *constraint) { + return 1 / constraint->_data.getMassInverse(); + } + + float get(PhysicsConstraint *constraint) { + return 1 / constraint->_massInverse; + } + + void set(PhysicsConstraint *constraint, float value) { + constraint->_massInverse = 1 / value; + } + + bool global(PhysicsConstraintData &constraintData) { + return constraintData.isMassGlobal(); + } + }; + + class SP_API PhysicsConstraintWindTimeline : public PhysicsConstraintTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PhysicsConstraintWindTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintWind) {}; + + protected: + float setup(PhysicsConstraint *constraint) { + return constraint->_data.getWind(); + } + + float get(PhysicsConstraint *constraint) { + return constraint->_wind; + } + + void set(PhysicsConstraint *constraint, float value) { + constraint->_wind = value; + } + + bool global(PhysicsConstraintData &constraintData) { + return constraintData.isWindGlobal(); + } + }; + + class SP_API PhysicsConstraintGravityTimeline : public PhysicsConstraintTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PhysicsConstraintGravityTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintGravity) {}; + + protected: + float setup(PhysicsConstraint *constraint) { + return constraint->_data.getGravity(); + } + + float get(PhysicsConstraint *constraint) { + return constraint->_gravity; + } + + void set(PhysicsConstraint *constraint, float value) { + constraint->_gravity = value; + } + + bool global(PhysicsConstraintData &constraintData) { + return constraintData.isGravityGlobal(); + } + }; + + class SP_API PhysicsConstraintMixTimeline : public PhysicsConstraintTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PhysicsConstraintMixTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintMix) {}; + + protected: + float setup(PhysicsConstraint *constraint) { + return constraint->_data.getMix(); + } + + float get(PhysicsConstraint *constraint) { + return constraint->_mix; + } + + void set(PhysicsConstraint *constraint, float value) { + constraint->_mix = value; + } + + bool global(PhysicsConstraintData &constraintData) { + return constraintData.isMixGlobal(); + } + }; + + class SP_API PhysicsConstraintResetTimeline : public Timeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PhysicsConstraintResetTimeline(size_t frameCount, int physicsConstraintIndex): Timeline(frameCount, 1), _constraintIndex(physicsConstraintIndex) { + PropertyId ids[] = {((PropertyId)Property_PhysicsConstraintReset) << 32}; + setPropertyIds(ids, 1); + } + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + void setFrame(int frame, float time) { + _frames[frame] = time; + } + private: + int _constraintIndex; + }; +} + +#endif /* Spine_PhysicsConstraintTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PointAttachment.cpp b/native/cocos/editor-support/spine/4.2/spine/PointAttachment.cpp new file mode 100644 index 0000000000..598ce62ba3 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PointAttachment.cpp @@ -0,0 +1,88 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +#include + +using namespace spine; + +RTTI_IMPL(PointAttachment, Attachment) + +PointAttachment::PointAttachment(const String &name) : Attachment(name), _x(0), _y(0), _rotation(0), _color() { +} + +void PointAttachment::computeWorldPosition(Bone &bone, float &ox, float &oy) { + bone.localToWorld(_x, _y, ox, oy); +} + +float PointAttachment::computeWorldRotation(Bone &bone) { + float r = _rotation * MathUtil::Deg_Rad, cosine = MathUtil::cos(r), sine = MathUtil::sin(r); + float x = cosine * bone._a + sine * bone._b; + float y = cosine * bone._c + sine * bone._d; + return MathUtil::atan2Deg(y, x); +} + +float PointAttachment::getX() { + return _x; +} + +void PointAttachment::setX(float inValue) { + _x = inValue; +} + +float PointAttachment::getY() { + return _y; +} + +void PointAttachment::setY(float inValue) { + _y = inValue; +} + +float PointAttachment::getRotation() { + return _rotation; +} + +void PointAttachment::setRotation(float inValue) { + _rotation = inValue; +} + +Color &PointAttachment::getColor() { + return _color; +} + +Attachment *PointAttachment::copy() { + PointAttachment *copy = new (__FILE__, __LINE__) PointAttachment(getName()); + copy->_x = _x; + copy->_y = _y; + copy->_rotation = _rotation; + return copy; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/PointAttachment.h b/native/cocos/editor-support/spine/4.2/spine/PointAttachment.h new file mode 100644 index 0000000000..853f049600 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PointAttachment.h @@ -0,0 +1,83 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PointAttachment_h +#define Spine_PointAttachment_h + +#include +#include + +namespace spine { + class Bone; + + /// An attachment which is a single point and a rotation. This can be used to spawn projectiles, particles, etc. A bone can be + /// used in similar ways, but a PointAttachment is slightly less expensive to compute and can be hidden, shown, and placed in a + /// skin. + /// + /// See http://esotericsoftware.com/spine-point-attachments for Point Attachments in the Spine User Guide. + /// + class SP_API PointAttachment : public Attachment { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PointAttachment(const String &name); + + void computeWorldPosition(Bone &bone, float &ox, float &oy); + + float computeWorldRotation(Bone &bone); + + float getX(); + + void setX(float inValue); + + float getY(); + + void setY(float inValue); + + float getRotation(); + + void setRotation(float inValue); + + Color &getColor(); + + virtual Attachment *copy(); + + #ifndef __EMSCRIPTEN__ + private: + #endif + float _x, _y, _rotation; + Color _color; + }; +} + +#endif /* Spine_PointAttachment_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Pool.h b/native/cocos/editor-support/spine/4.2/spine/Pool.h new file mode 100644 index 0000000000..6a3dceb1e0 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Pool.h @@ -0,0 +1,74 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Pool_h +#define Spine_Pool_h + +#include +#include +#include +#include + +namespace spine { + template + class SP_API Pool : public SpineObject { + public: + Pool() { + } + + ~Pool() { + ContainerUtil::cleanUpVectorOfPointers(_objects); + } + + T *obtain() { + if (_objects.size() > 0) { + T **object = &_objects[_objects.size() - 1]; + T *ret = *object; + _objects.removeAt(_objects.size() - 1); + + return ret; + } else { + T *ret = new(__FILE__, __LINE__) T(); + + return ret; + } + } + + void free(T *object) { + if (!_objects.contains(object)) { + _objects.add(object); + } + } + + private: + Vector _objects; + }; +} + +#endif /* Spine_Pool_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/PositionMode.h b/native/cocos/editor-support/spine/4.2/spine/PositionMode.h new file mode 100644 index 0000000000..dcd6276a69 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/PositionMode.h @@ -0,0 +1,40 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_PositionMode_h +#define Spine_PositionMode_h + +namespace spine { + enum PositionMode { + PositionMode_Fixed = 0, + PositionMode_Percent + }; +} + +#endif /* Spine_PositionMode_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Property.h b/native/cocos/editor-support/spine/4.2/spine/Property.h new file mode 100644 index 0000000000..5955171f45 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Property.h @@ -0,0 +1,68 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Property_h +#define Spine_Property_h + +namespace spine { + typedef long long PropertyId; + enum Property { + Property_Rotate = 1 << 0, + Property_X = 1 << 1, + Property_Y = 1 << 2, + Property_ScaleX = 1 << 3, + Property_ScaleY = 1 << 4, + Property_ShearX = 1 << 5, + Property_ShearY = 1 << 6, + Property_Inherit = 1 << 7, + Property_Rgb = 1 << 8, + Property_Alpha = 1 << 9, + Property_Rgb2 = 1 << 10, + Property_Attachment = 1 << 11, + Property_Deform = 1 << 12, + Property_Event = 1 << 13, + Property_DrawOrder = 1 << 14, + Property_IkConstraint = 1 << 15, + Property_TransformConstraint = 1 << 16, + Property_PathConstraintPosition = 1 << 17, + Property_PathConstraintSpacing = 1 << 18, + Property_PathConstraintMix = 1 << 19, + Property_PhysicsConstraintInertia = 1 << 20, + Property_PhysicsConstraintStrength = 1 << 21, + Property_PhysicsConstraintDamping = 1 << 22, + Property_PhysicsConstraintMass = 1 << 23, + Property_PhysicsConstraintWind = 1 << 24, + Property_PhysicsConstraintGravity = 1 << 25, + Property_PhysicsConstraintMix = 1 << 26, + Property_PhysicsConstraintReset = 1 << 27, + Property_Sequence = 1 << 28 + }; +} + +#endif /* Spine_Property_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/RTTI.cpp b/native/cocos/editor-support/spine/4.2/spine/RTTI.cpp new file mode 100644 index 0000000000..010442a7d9 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/RTTI.cpp @@ -0,0 +1,56 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include + +using namespace spine; + +RTTI::RTTI(const char *className) : _className(className), _pBaseRTTI(NULL) { +} + +RTTI::RTTI(const char *className, const RTTI &baseRTTI) : _className(className), _pBaseRTTI(&baseRTTI) { +} + +const char *RTTI::getClassName() const { + return _className; +} + +bool RTTI::isExactly(const RTTI &rtti) const { + return !strcmp(this->_className, rtti._className); +} + +bool RTTI::instanceOf(const RTTI &rtti) const { + const RTTI *pCompare = this; + while (pCompare) { + if (!strcmp(pCompare->_className, rtti._className)) return true; + pCompare = pCompare->_pBaseRTTI; + } + return false; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/RTTI.h b/native/cocos/editor-support/spine/4.2/spine/RTTI.h new file mode 100644 index 0000000000..8740ab3ff3 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/RTTI.h @@ -0,0 +1,73 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_RTTI_h +#define Spine_RTTI_h + +#include + +namespace spine { + class SP_API RTTI { + public: + explicit RTTI(const char *className); + + RTTI(const char *className, const RTTI &baseRTTI); + + const char *getClassName() const; + + bool isExactly(const RTTI &rtti) const; + + bool instanceOf(const RTTI &rtti) const; + + private: + // Prevent copying + RTTI(const RTTI &obj); + + RTTI &operator=(const RTTI &obj); + + const char *_className; + const RTTI *_pBaseRTTI; + }; +} + + +#define RTTI_DECL \ +public: \ + static const spine::RTTI rtti; \ + virtual const spine::RTTI &getRTTI() const; + +#define RTTI_IMPL_NOPARENT(name) \ + const spine::RTTI name::rtti(#name); \ + const spine::RTTI &name::getRTTI() const { return rtti; } + +#define RTTI_IMPL(name, parent) \ + const spine::RTTI name::rtti(#name, parent::rtti); \ + const spine::RTTI &name::getRTTI() const { return rtti; } + +#endif /* Spine_RTTI_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/RegionAttachment.cpp b/native/cocos/editor-support/spine/4.2/spine/RegionAttachment.cpp new file mode 100644 index 0000000000..58d2a75be9 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/RegionAttachment.cpp @@ -0,0 +1,275 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include + +using namespace spine; + +RTTI_IMPL(RegionAttachment, Attachment) + +const int RegionAttachment::BLX = 0; +const int RegionAttachment::BLY = 1; +const int RegionAttachment::ULX = 2; +const int RegionAttachment::ULY = 3; +const int RegionAttachment::URX = 4; +const int RegionAttachment::URY = 5; +const int RegionAttachment::BRX = 6; +const int RegionAttachment::BRY = 7; + +RegionAttachment::RegionAttachment(const String &name) : Attachment(name), + _x(0), + _y(0), + _rotation(0), + _scaleX(1), + _scaleY(1), + _width(0), + _height(0), + _path(), + _color(1, 1, 1, 1), + _region(NULL), + _sequence(NULL) { + _vertexOffset.setSize(NUM_UVS, 0); + _uvs.setSize(NUM_UVS, 0); +} + +RegionAttachment::~RegionAttachment() { + if (_sequence) delete _sequence; +} + +void RegionAttachment::updateRegion() { + if (_region == NULL) { + _uvs[BLX] = 0; + _uvs[BLY] = 0; + _uvs[ULX] = 0; + _uvs[ULY] = 1; + _uvs[URX] = 1; + _uvs[URY] = 1; + _uvs[BRX] = 1; + _uvs[BRY] = 0; + return; + } + + float regionScaleX = _width / _region->originalWidth * _scaleX; + float regionScaleY = _height / _region->originalHeight * _scaleY; + float localX = -_width / 2 * _scaleX + _region->offsetX * regionScaleX; + float localY = -_height / 2 * _scaleY + _region->offsetY * regionScaleY; + float localX2 = localX + _region->width * regionScaleX; + float localY2 = localY + _region->height * regionScaleY; + float cos = MathUtil::cosDeg(_rotation); + float sin = MathUtil::sinDeg(_rotation); + float localXCos = localX * cos + _x; + float localXSin = localX * sin; + float localYCos = localY * cos + _y; + float localYSin = localY * sin; + float localX2Cos = localX2 * cos + _x; + float localX2Sin = localX2 * sin; + float localY2Cos = localY2 * cos + _y; + float localY2Sin = localY2 * sin; + + _vertexOffset[BLX] = localXCos - localYSin; + _vertexOffset[BLY] = localYCos + localXSin; + _vertexOffset[ULX] = localXCos - localY2Sin; + _vertexOffset[ULY] = localY2Cos + localXSin; + _vertexOffset[URX] = localX2Cos - localY2Sin; + _vertexOffset[URY] = localY2Cos + localX2Sin; + _vertexOffset[BRX] = localX2Cos - localYSin; + _vertexOffset[BRY] = localYCos + localX2Sin; + + if (_region->degrees == 90) { + _uvs[URX] = _region->u; + _uvs[URY] = _region->v2; + _uvs[BRX] = _region->u; + _uvs[BRY] = _region->v; + _uvs[BLX] = _region->u2; + _uvs[BLY] = _region->v; + _uvs[ULX] = _region->u2; + _uvs[ULY] = _region->v2; + } else { + _uvs[ULX] = _region->u; + _uvs[ULY] = _region->v2; + _uvs[URX] = _region->u; + _uvs[URY] = _region->v; + _uvs[BRX] = _region->u2; + _uvs[BRY] = _region->v; + _uvs[BLX] = _region->u2; + _uvs[BLY] = _region->v2; + } +} + +void RegionAttachment::computeWorldVertices(Slot &slot, Vector &worldVertices, size_t offset, size_t stride) { + assert(worldVertices.size() >= (offset + 8)); + computeWorldVertices(slot, worldVertices.buffer(), offset, stride); +} + +void RegionAttachment::computeWorldVertices(Slot &slot, float *worldVertices, size_t offset, size_t stride) { + if (_sequence) _sequence->apply(&slot, this); + + Bone &bone = slot.getBone(); + float x = bone.getWorldX(), y = bone.getWorldY(); + float a = bone.getA(), b = bone.getB(), c = bone.getC(), d = bone.getD(); + float offsetX, offsetY; + + offsetX = _vertexOffset[BRX]; + offsetY = _vertexOffset[BRY]; + worldVertices[offset] = offsetX * a + offsetY * b + x;// br + worldVertices[offset + 1] = offsetX * c + offsetY * d + y; + offset += stride; + + offsetX = _vertexOffset[BLX]; + offsetY = _vertexOffset[BLY]; + worldVertices[offset] = offsetX * a + offsetY * b + x;// bl + worldVertices[offset + 1] = offsetX * c + offsetY * d + y; + offset += stride; + + offsetX = _vertexOffset[ULX]; + offsetY = _vertexOffset[ULY]; + worldVertices[offset] = offsetX * a + offsetY * b + x;// ul + worldVertices[offset + 1] = offsetX * c + offsetY * d + y; + offset += stride; + + offsetX = _vertexOffset[URX]; + offsetY = _vertexOffset[URY]; + worldVertices[offset] = offsetX * a + offsetY * b + x;// ur + worldVertices[offset + 1] = offsetX * c + offsetY * d + y; +} + +float RegionAttachment::getX() { + return _x; +} + +void RegionAttachment::setX(float inValue) { + _x = inValue; +} + +float RegionAttachment::getY() { + return _y; +} + +void RegionAttachment::setY(float inValue) { + _y = inValue; +} + +float RegionAttachment::getRotation() { + return _rotation; +} + +void RegionAttachment::setRotation(float inValue) { + _rotation = inValue; +} + +float RegionAttachment::getScaleX() { + return _scaleX; +} + +void RegionAttachment::setScaleX(float inValue) { + _scaleX = inValue; +} + +float RegionAttachment::getScaleY() { + return _scaleY; +} + +void RegionAttachment::setScaleY(float inValue) { + _scaleY = inValue; +} + +float RegionAttachment::getWidth() { + return _width; +} + +void RegionAttachment::setWidth(float inValue) { + _width = inValue; +} + +float RegionAttachment::getHeight() { + return _height; +} + +void RegionAttachment::setHeight(float inValue) { + _height = inValue; +} + +const String &RegionAttachment::getPath() { + return _path; +} + +void RegionAttachment::setPath(const String &inValue) { + _path = inValue; +} + +TextureRegion *RegionAttachment::getRegion() { + return _region; +} + +void RegionAttachment::setRegion(TextureRegion *region) { + _region = region; +} + +Sequence *RegionAttachment::getSequence() { + return _sequence; +} + +void RegionAttachment::setSequence(Sequence *sequence) { + _sequence = sequence; +} + +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()); + copy->_region = _region; + copy->_path = _path; + copy->_x = _x; + copy->_y = _y; + copy->_scaleX = _scaleX; + copy->_scaleY = _scaleY; + copy->_rotation = _rotation; + copy->_width = _width; + copy->_height = _height; + copy->_uvs.clearAndAddAll(_uvs); + copy->_vertexOffset.clearAndAddAll(_vertexOffset); + copy->_color.set(_color); + copy->_sequence = _sequence != NULL ? _sequence->copy() : NULL; + return copy; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/RegionAttachment.h b/native/cocos/editor-support/spine/4.2/spine/RegionAttachment.h new file mode 100644 index 0000000000..f853aebced --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/RegionAttachment.h @@ -0,0 +1,142 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_RegionAttachment_h +#define Spine_RegionAttachment_h + +#include +#include +#include +#include +#include + +#include + +#define NUM_UVS 8 + +namespace spine { + class Bone; + + /// Attachment that displays a texture region. + class SP_API RegionAttachment : public Attachment { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class AtlasAttachmentLoader; + + RTTI_DECL + + public: + explicit RegionAttachment(const String &name); + + virtual ~RegionAttachment(); + + void updateRegion(); + + /// Transforms the attachment's four vertices to world coordinates. + /// @param slot The parent slot. + /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + 8. + /// @param offset The worldVertices index to begin writing values. + /// @param stride The number of worldVertices entries between the value pairs written. + void computeWorldVertices(Slot &slot, float *worldVertices, size_t offset, size_t stride = 2); + + void computeWorldVertices(Slot &slot, Vector &worldVertices, size_t offset, size_t stride = 2); + + float getX(); + + void setX(float inValue); + + float getY(); + + void setY(float inValue); + + float getRotation(); + + void setRotation(float inValue); + + float getScaleX(); + + void setScaleX(float inValue); + + float getScaleY(); + + void setScaleY(float inValue); + + float getWidth(); + + void setWidth(float inValue); + + float getHeight(); + + void setHeight(float inValue); + + Color &getColor(); + + const String &getPath(); + + void setPath(const String &inValue); + + TextureRegion *getRegion(); + + void setRegion(TextureRegion *region); + + Sequence *getSequence(); + + void setSequence(Sequence *sequence); + + Vector &getOffset(); + + Vector &getUVs(); + + virtual Attachment *copy(); + + #ifndef __EMSCRIPTEN__ + private: + #endif + static const int BLX; + static const int BLY; + static const int ULX; + static const int ULY; + static const int URX; + static const int URY; + static const int BRX; + static const int BRY; + + float _x, _y, _rotation, _scaleX, _scaleY, _width, _height; + Vector _vertexOffset; + Vector _uvs; + String _path; + Color _color; + TextureRegion *_region; + Sequence *_sequence; + }; +} + +#endif /* Spine_RegionAttachment_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/RotateMode.h b/native/cocos/editor-support/spine/4.2/spine/RotateMode.h new file mode 100644 index 0000000000..32c317a281 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/RotateMode.h @@ -0,0 +1,41 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_RotateMode_h +#define Spine_RotateMode_h + +namespace spine { + enum RotateMode { + RotateMode_Tangent = 0, + RotateMode_Chain, + RotateMode_ChainScale + }; +} + +#endif /* Spine_RotateMode_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/RotateTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/RotateTimeline.cpp new file mode 100644 index 0000000000..3560349f01 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/RotateTimeline.cpp @@ -0,0 +1,59 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(RotateTimeline, CurveTimeline1) + +RotateTimeline::RotateTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1(frameCount, + bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_Rotate << 32) | boneIndex}; + setPropertyIds(ids, 1); +} + +void RotateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Bone *bone = skeleton._bones[_boneIndex]; + if (bone->isActive()) bone->_rotation = getRelativeValue(time, alpha, blend, bone->_rotation, bone->getData()._rotation); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/RotateTimeline.h b/native/cocos/editor-support/spine/4.2/spine/RotateTimeline.h new file mode 100644 index 0000000000..9c268c1456 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/RotateTimeline.h @@ -0,0 +1,62 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_RotateTimeline_h +#define Spine_RotateTimeline_h + +#include + +namespace spine { + class SP_API RotateTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class AnimationState; + + RTTI_DECL + + public: + explicit RotateTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + #ifndef __EMSCRIPTEN__ + private: + #endif + int _boneIndex; + }; +} + +#endif /* Spine_RotateTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/ScaleTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/ScaleTimeline.cpp new file mode 100644 index 0000000000..bb76be0b76 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ScaleTimeline.cpp @@ -0,0 +1,194 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(ScaleTimeline, CurveTimeline2) + +ScaleTimeline::ScaleTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline2(frameCount, + bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_ScaleX << 32) | boneIndex, + ((PropertyId) Property_ScaleY << 32) | boneIndex}; + setPropertyIds(ids, 2); +} + +ScaleTimeline::~ScaleTimeline() {} + +void ScaleTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + + Bone *bone = skeleton._bones[_boneIndex]; + if (!bone->_active) return; + + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + bone->_scaleX = bone->_data._scaleX; + bone->_scaleY = bone->_data._scaleY; + return; + case MixBlend_First: + bone->_scaleX += (bone->_data._scaleX - bone->_scaleX) * alpha; + bone->_scaleY += (bone->_data._scaleY - bone->_scaleY) * alpha; + default: { + } + } + return; + } + + float x, y; + int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); + int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; + switch (curveType) { + case CurveTimeline::LINEAR: { + float before = _frames[i]; + x = _frames[i + CurveTimeline2::VALUE1]; + y = _frames[i + CurveTimeline2::VALUE2]; + float t = (time - before) / (_frames[i + CurveTimeline2::ENTRIES] - before); + x += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE1] - x) * t; + y += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE2] - y) * t; + break; + } + case CurveTimeline::STEPPED: { + x = _frames[i + CurveTimeline2::VALUE1]; + y = _frames[i + CurveTimeline2::VALUE2]; + break; + } + default: { + x = getBezierValue(time, i, CurveTimeline2::VALUE1, curveType - CurveTimeline2::BEZIER); + y = getBezierValue(time, i, CurveTimeline2::VALUE2, + curveType + CurveTimeline2::BEZIER_SIZE - CurveTimeline2::BEZIER); + } + } + x *= bone->_data._scaleX; + y *= bone->_data._scaleY; + + if (alpha == 1) { + if (blend == MixBlend_Add) { + bone->_scaleX += x - bone->_data._scaleX; + bone->_scaleY += y - bone->_data._scaleY; + } else { + bone->_scaleX = x; + bone->_scaleY = y; + } + } else { + float bx, by; + if (direction == MixDirection_Out) { + switch (blend) { + case MixBlend_Setup: + bx = bone->_data._scaleX; + by = bone->_data._scaleY; + bone->_scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bx) * alpha; + bone->_scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - by) * alpha; + break; + case MixBlend_First: + case MixBlend_Replace: + bx = bone->_scaleX; + by = bone->_scaleY; + bone->_scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bx) * alpha; + bone->_scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - by) * alpha; + break; + case MixBlend_Add: + bone->_scaleX += (x - bone->_data._scaleX) * alpha; + bone->_scaleY += (y - bone->_data._scaleY) * alpha; + } + } else { + switch (blend) { + case MixBlend_Setup: + bx = MathUtil::abs(bone->_data._scaleX) * MathUtil::sign(x); + by = MathUtil::abs(bone->_data._scaleY) * MathUtil::sign(y); + bone->_scaleX = bx + (x - bx) * alpha; + bone->_scaleY = by + (y - by) * alpha; + break; + case MixBlend_First: + case MixBlend_Replace: + bx = MathUtil::abs(bone->_scaleX) * MathUtil::sign(x); + by = MathUtil::abs(bone->_scaleY) * MathUtil::sign(y); + bone->_scaleX = bx + (x - bx) * alpha; + bone->_scaleY = by + (y - by) * alpha; + break; + case MixBlend_Add: + bone->_scaleX += (x - bone->_data._scaleX) * alpha; + bone->_scaleY += (y - bone->_data._scaleY) * alpha; + } + } + } +} + +RTTI_IMPL(ScaleXTimeline, CurveTimeline1) + +ScaleXTimeline::ScaleXTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1(frameCount, + bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_ScaleX << 32) | boneIndex}; + setPropertyIds(ids, 1); +} + +ScaleXTimeline::~ScaleXTimeline() {} + +void ScaleXTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + + Bone *bone = skeleton._bones[_boneIndex]; + if (bone->_active) bone->_scaleX = getScaleValue(time, alpha, blend, direction, bone->_scaleX, bone->_data._scaleX); +} + +RTTI_IMPL(ScaleYTimeline, CurveTimeline1) + +ScaleYTimeline::ScaleYTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1(frameCount, + bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_ScaleY << 32) | boneIndex}; + setPropertyIds(ids, 1); +} + +ScaleYTimeline::~ScaleYTimeline() {} + +void ScaleYTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + + Bone *bone = skeleton._bones[_boneIndex]; + if (bone->_active) bone->_scaleY = getScaleValue(time, alpha, blend, direction, bone->_scaleX, bone->_data._scaleY); +} \ No newline at end of file diff --git a/native/cocos/editor-support/spine/4.2/spine/ScaleTimeline.h b/native/cocos/editor-support/spine/4.2/spine/ScaleTimeline.h new file mode 100644 index 0000000000..3a010dd192 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ScaleTimeline.h @@ -0,0 +1,109 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_ScaleTimeline_h +#define Spine_ScaleTimeline_h + +#include + +namespace spine { + class SP_API ScaleTimeline : public CurveTimeline2 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit ScaleTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual ~ScaleTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + }; + + class SP_API ScaleXTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit ScaleXTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual ~ScaleXTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + }; + + class SP_API ScaleYTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit ScaleYTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual ~ScaleYTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + }; +} + +#endif /* Spine_ScaleTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Sequence.cpp b/native/cocos/editor-support/spine/4.2/spine/Sequence.cpp new file mode 100644 index 0000000000..6147b5b18d --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Sequence.cpp @@ -0,0 +1,96 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include +#include +#include +#include + +using namespace spine; + +Sequence::Sequence(int count) : _id(Sequence::getNextID()), + _regions(), + _start(0), + _digits(0), + _setupIndex(0) { + _regions.setSize(count, NULL); +} + +Sequence::~Sequence() { +} + +Sequence *Sequence::copy() { + Sequence *copy = new (__FILE__, __LINE__) Sequence((int) _regions.size()); + for (size_t i = 0; i < _regions.size(); i++) { + copy->_regions[i] = _regions[i]; + } + copy->_start = _start; + copy->_digits = _digits; + copy->_setupIndex = _setupIndex; + return copy; +} + +void Sequence::apply(Slot *slot, Attachment *attachment) { + int index = slot->getSequenceIndex(); + if (index == -1) index = _setupIndex; + if (index >= (int) _regions.size()) index = (int) _regions.size() - 1; + TextureRegion *region = _regions[index]; + + if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { + RegionAttachment *regionAttachment = static_cast(attachment); + if (regionAttachment->getRegion() != region) { + regionAttachment->setRegion(region); + regionAttachment->updateRegion(); + } + } + + if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { + MeshAttachment *meshAttachment = static_cast(attachment); + if (meshAttachment->getRegion() != region) { + meshAttachment->setRegion(region); + meshAttachment->updateRegion(); + } + } +} + +String Sequence::getPath(const String &basePath, int index) { + String result(basePath); + String frame; + frame.append(_start + index); + for (int i = _digits - (int) frame.length(); i > 0; i--) + result.append("0"); + result.append(frame); + return result; +} + +int Sequence::getNextID() { + static int _nextID = 0; + return _nextID; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Sequence.h b/native/cocos/editor-support/spine/4.2/spine/Sequence.h new file mode 100644 index 0000000000..14a8f875ac --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Sequence.h @@ -0,0 +1,98 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Sequence_h +#define Spine_Sequence_h + +#include +#include +#include + +namespace spine { + class Slot; + + class Attachment; + + class SkeletonBinary; + class SkeletonJson; + + class SP_API Sequence : public SpineObject { + friend class SkeletonBinary; + friend class SkeletonJson; + public: + Sequence(int count); + + ~Sequence(); + + Sequence *copy(); + + void apply(Slot *slot, Attachment *attachment); + + String getPath(const String &basePath, int index); + + int getId() { return _id; } + + void setId(int id) { _id = id; } + + int getStart() { return _start; } + + void setStart(int start) { _start = start; } + + int getDigits() { return _digits; } + + void setDigits(int digits) { _digits = digits; } + + int getSetupIndex() { return _setupIndex; } + + void setSetupIndex(int setupIndex) { _setupIndex = setupIndex; } + + Vector &getRegions() { return _regions; } + + private: + int _id; + Vector _regions; + int _start; + int _digits; + int _setupIndex; + + int getNextID(); + }; + + enum SequenceMode { + hold = 0, + once = 1, + loop = 2, + pingpong = 3, + onceReverse = 4, + loopReverse = 5, + pingpongReverse = 6 + }; +} + +#endif diff --git a/native/cocos/editor-support/spine/4.2/spine/SequenceTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/SequenceTimeline.cpp new file mode 100644 index 0000000000..e60b018347 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SequenceTimeline.cpp @@ -0,0 +1,129 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(SequenceTimeline, Timeline) + +SequenceTimeline::SequenceTimeline(size_t frameCount, int slotIndex, Attachment *attachment) : Timeline(frameCount, ENTRIES), _slotIndex(slotIndex), _attachment(attachment) { + int sequenceId = 0; + if (attachment->getRTTI().instanceOf(RegionAttachment::rtti)) sequenceId = ((RegionAttachment *) attachment)->getSequence()->getId(); + if (attachment->getRTTI().instanceOf(MeshAttachment::rtti)) sequenceId = ((MeshAttachment *) attachment)->getSequence()->getId(); + PropertyId ids[] = {((PropertyId) Property_Sequence << 32) | ((slotIndex << 16 | sequenceId) & 0xffffffff)}; + setPropertyIds(ids, 1); +} + +SequenceTimeline::~SequenceTimeline() { +} + +void SequenceTimeline::setFrame(int frame, float time, SequenceMode mode, int index, float delay) { + Vector &frames = this->_frames; + frame *= ENTRIES; + frames[frame] = time; + frames[frame + MODE] = mode | (index << 4); + frames[frame + DELAY] = delay; +} + +void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, + float alpha, MixBlend blend, MixDirection direction) { + SP_UNUSED(alpha); + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Slot *slot = skeleton.getSlots()[_slotIndex]; + if (!slot->getBone().isActive()) return; + Attachment *slotAttachment = slot->getAttachment(); + if (slotAttachment != _attachment) { + if (slotAttachment == NULL || !slotAttachment->getRTTI().instanceOf(VertexAttachment::rtti) || ((VertexAttachment *) slotAttachment)->getTimelineAttachment() != _attachment) return; + } + Sequence *sequence = NULL; + if (_attachment->getRTTI().instanceOf(RegionAttachment::rtti)) sequence = ((RegionAttachment *) _attachment)->getSequence(); + if (_attachment->getRTTI().instanceOf(MeshAttachment::rtti)) sequence = ((MeshAttachment *) _attachment)->getSequence(); + if (!sequence) return; + + if (direction == MixDirection_Out) { + if (blend == MixBlend_Setup) slot->setSequenceIndex(-1); + return; + } + + Vector &frames = this->_frames; + if (time < frames[0]) {// Time is before first frame. + if (blend == MixBlend_Setup || blend == MixBlend_First) slot->setSequenceIndex(-1); + return; + } + + int i = Animation::search(frames, time, ENTRIES); + float before = frames[i]; + int modeAndIndex = (int) frames[i + MODE]; + float delay = frames[i + DELAY]; + + int index = modeAndIndex >> 4, count = (int) sequence->getRegions().size(); + int mode = modeAndIndex & 0xf; + if (mode != SequenceMode::hold) { + index += (int) (((time - before) / delay + 0.0001)); + switch (mode) { + case SequenceMode::once: + index = MathUtil::min(count - 1, index); + break; + case SequenceMode::loop: + index %= count; + break; + case SequenceMode::pingpong: { + int n = (count << 1) - 2; + index = n == 0 ? 0 : index % n; + if (index >= count) index = n - index; + break; + } + case SequenceMode::onceReverse: + index = MathUtil::max(count - 1 - index, 0); + break; + case SequenceMode::loopReverse: + index = count - 1 - (index % count); + break; + case SequenceMode::pingpongReverse: { + int n = (count << 1) - 2; + index = n == 0 ? 0 : (index + count - 1) % n; + if (index >= count) index = n - index; + } + } + } + slot->setSequenceIndex(index); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/SequenceTimeline.h b/native/cocos/editor-support/spine/4.2/spine/SequenceTimeline.h new file mode 100644 index 0000000000..0b44ce972a --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SequenceTimeline.h @@ -0,0 +1,73 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_SequenceTimeline_h +#define Spine_SequenceTimeline_h + +#include +#include + +namespace spine { + class Attachment; + + class SP_API SequenceTimeline : public Timeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit SequenceTimeline(size_t frameCount, int slotIndex, spine::Attachment *attachment); + + virtual ~SequenceTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + void setFrame(int frame, float time, SequenceMode mode, int index, float delay); + + int getSlotIndex() { return _slotIndex; }; + + void setSlotIndex(int inValue) { _slotIndex = inValue; } + + Attachment *getAttachment() { return _attachment; } + + protected: + int _slotIndex; + Attachment *_attachment; + + static const int ENTRIES = 3; + static const int MODE = 1; + static const int DELAY = 2; + }; +} + +#endif /* Spine_SequenceTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/ShearTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/ShearTimeline.cpp new file mode 100644 index 0000000000..73207e4d80 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ShearTimeline.cpp @@ -0,0 +1,162 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(ShearTimeline, CurveTimeline2) + +ShearTimeline::ShearTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline2(frameCount, + bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_ShearX << 32) | boneIndex, + ((PropertyId) Property_ShearY << 32) | boneIndex}; + setPropertyIds(ids, 2); +} + +ShearTimeline::~ShearTimeline() { +} + +void ShearTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Bone *bone = skeleton._bones[_boneIndex]; + if (!bone->_active) return; + + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + bone->_shearX = bone->_data._shearX; + bone->_shearY = bone->_data._shearY; + return; + case MixBlend_First: + bone->_shearX += (bone->_data._shearX - bone->_shearX) * alpha; + bone->_shearY += (bone->_data._shearY - bone->_shearY) * alpha; + default: { + } + } + return; + } + + float x, y; + int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); + int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; + switch (curveType) { + case CurveTimeline2::LINEAR: { + float before = _frames[i]; + x = _frames[i + CurveTimeline2::VALUE1]; + y = _frames[i + CurveTimeline2::VALUE2]; + float t = (time - before) / (_frames[i + CurveTimeline2::ENTRIES] - before); + x += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE1] - x) * t; + y += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE2] - y) * t; + break; + } + case CurveTimeline2::STEPPED: { + x = _frames[i + CurveTimeline2::VALUE1]; + y = _frames[i + CurveTimeline2::VALUE2]; + break; + } + default: { + x = getBezierValue(time, i, CurveTimeline2::VALUE1, curveType - CurveTimeline2::BEZIER); + y = getBezierValue(time, i, CurveTimeline2::VALUE2, + curveType + CurveTimeline2::BEZIER_SIZE - CurveTimeline2::BEZIER); + } + } + + switch (blend) { + case MixBlend_Setup: + bone->_shearX = bone->_data._shearX + x * alpha; + bone->_shearY = bone->_data._shearY + y * alpha; + break; + case MixBlend_First: + case MixBlend_Replace: + bone->_shearX += (bone->_data._shearX + x - bone->_shearX) * alpha; + bone->_shearY += (bone->_data._shearY + y - bone->_shearY) * alpha; + break; + case MixBlend_Add: + bone->_shearX += x * alpha; + bone->_shearY += y * alpha; + } +} + +RTTI_IMPL(ShearXTimeline, CurveTimeline1) + +ShearXTimeline::ShearXTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1(frameCount, + bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_ShearX << 32) | boneIndex}; + setPropertyIds(ids, 1); +} + +ShearXTimeline::~ShearXTimeline() { +} + +void ShearXTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Bone *bone = skeleton._bones[_boneIndex]; + if (bone->_active) bone->_shearX = getRelativeValue(time, alpha, blend, bone->_shearX, bone->_data._shearX); +} + +RTTI_IMPL(ShearYTimeline, CurveTimeline1) + +ShearYTimeline::ShearYTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1(frameCount, + bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_ShearX << 32) | boneIndex}; + setPropertyIds(ids, 1); +} + +ShearYTimeline::~ShearYTimeline() { +} + +void ShearYTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Bone *bone = skeleton._bones[_boneIndex]; + if (bone->_active) bone->_shearY = getRelativeValue(time, alpha, blend, bone->_shearY, bone->_data._shearY); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/ShearTimeline.h b/native/cocos/editor-support/spine/4.2/spine/ShearTimeline.h new file mode 100644 index 0000000000..5c3caf9a6a --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/ShearTimeline.h @@ -0,0 +1,109 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_ShearTimeline_h +#define Spine_ShearTimeline_h + +#include + +namespace spine { + class SP_API ShearTimeline : public CurveTimeline2 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit ShearTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual ~ShearTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + }; + + class SP_API ShearXTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit ShearXTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual ~ShearXTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + }; + + class SP_API ShearYTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit ShearYTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual ~ShearYTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + }; +} + +#endif /* Spine_ShearTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Skeleton.cpp b/native/cocos/editor-support/spine/4.2/spine/Skeleton.cpp new file mode 100644 index 0000000000..bde7af17cf --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Skeleton.cpp @@ -0,0 +1,773 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace spine; + +Skeleton::Skeleton(SkeletonData *skeletonData) + : _data(skeletonData), _skin(NULL), _color(1, 1, 1, 1), _scaleX(1), + _scaleY(1), _x(0), _y(0), _time(0) { + _bones.ensureCapacity(_data->getBones().size()); + for (size_t i = 0; i < _data->getBones().size(); ++i) { + BoneData *data = _data->getBones()[i]; + + Bone *bone; + if (data->getParent() == NULL) { + bone = new (__FILE__, __LINE__) Bone(*data, *this, NULL); + } else { + Bone *parent = _bones[data->getParent()->getIndex()]; + bone = new (__FILE__, __LINE__) 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]; + + Bone *bone = _bones[data->getBoneData().getIndex()]; + Slot *slot = new (__FILE__, __LINE__) 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]; + + IkConstraint *constraint = + new (__FILE__, __LINE__) 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]; + + TransformConstraint *constraint = + new (__FILE__, __LINE__) 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]; + + PathConstraint *constraint = + new (__FILE__, __LINE__) PathConstraint(*data, *this); + + _pathConstraints.add(constraint); + } + + _physicsConstraints.ensureCapacity(_data->getPhysicsConstraints().size()); + for (size_t i = 0; i < _data->getPhysicsConstraints().size(); ++i) { + PhysicsConstraintData *data = _data->getPhysicsConstraints()[i]; + + PhysicsConstraint *constraint = + new (__FILE__, __LINE__) PhysicsConstraint(*data, *this); + + _physicsConstraints.add(constraint); + } + + updateCache(); +} + +Skeleton::~Skeleton() { + ContainerUtil::cleanUpVectorOfPointers(_bones); + ContainerUtil::cleanUpVectorOfPointers(_slots); + ContainerUtil::cleanUpVectorOfPointers(_ikConstraints); + ContainerUtil::cleanUpVectorOfPointers(_transformConstraints); + ContainerUtil::cleanUpVectorOfPointers(_pathConstraints); + ContainerUtil::cleanUpVectorOfPointers(_physicsConstraints); +} + +void Skeleton::updateCache() { + _updateCache.clear(); + + for (size_t i = 0, n = _bones.size(); i < n; ++i) { + Bone *bone = _bones[i]; + bone->_sorted = bone->_data.isSkinRequired(); + bone->_active = !bone->_sorted; + } + + if (_skin) { + Vector &skinBones = _skin->getBones(); + for (size_t i = 0, n = skinBones.size(); i < n; i++) { + Bone *bone = _bones[skinBones[i]->getIndex()]; + do { + bone->_sorted = false; + bone->_active = true; + bone = bone->_parent; + } while (bone); + } + } + + size_t ikCount = _ikConstraints.size(); + size_t transformCount = _transformConstraints.size(); + size_t pathCount = _pathConstraints.size(); + size_t physicsCount = _physicsConstraints.size(); + size_t constraintCount = ikCount + transformCount + pathCount + physicsCount; + + size_t i = 0; +continue_outer: + for (; i < constraintCount; ++i) { + for (size_t ii = 0; ii < ikCount; ++ii) { + IkConstraint *constraint = _ikConstraints[ii]; + if (constraint->getData().getOrder() == i) { + sortIkConstraint(constraint); + i++; + goto continue_outer; + } + } + + for (size_t ii = 0; ii < transformCount; ++ii) { + TransformConstraint *constraint = _transformConstraints[ii]; + if (constraint->getData().getOrder() == i) { + sortTransformConstraint(constraint); + i++; + goto continue_outer; + } + } + + for (size_t ii = 0; ii < pathCount; ++ii) { + PathConstraint *constraint = _pathConstraints[ii]; + if (constraint->getData().getOrder() == i) { + sortPathConstraint(constraint); + i++; + goto continue_outer; + } + } + + for (size_t ii = 0; ii < physicsCount; ++ii) { + PhysicsConstraint *constraint = _physicsConstraints[ii]; + if (constraint->getData().getOrder() == i) { + sortPhysicsConstraint(constraint); + i++; + goto continue_outer; + } + } + } + + size_t n = _bones.size(); + for (i = 0; i < n; ++i) { + sortBone(_bones[i]); + } +} + +void Skeleton::printUpdateCache() { + for (size_t i = 0; i < _updateCache.size(); i++) { + Updatable *updatable = _updateCache[i]; + if (updatable->getRTTI().isExactly(Bone::rtti)) { + printf("bone %s\n", ((Bone *) updatable)->getData().getName().buffer()); + } else if (updatable->getRTTI().isExactly(TransformConstraint::rtti)) { + printf("transform constraint %s\n", + ((TransformConstraint *) updatable)->getData().getName().buffer()); + } else if (updatable->getRTTI().isExactly(IkConstraint::rtti)) { + printf("ik constraint %s\n", + ((IkConstraint *) updatable)->getData().getName().buffer()); + } else if (updatable->getRTTI().isExactly(PathConstraint::rtti)) { + printf("path constraint %s\n", + ((PathConstraint *) updatable)->getData().getName().buffer()); + } else if (updatable->getRTTI().isExactly(PhysicsConstraint::rtti)) { + printf("physics constraint %s\n", + ((PhysicsConstraint *) updatable)->getData().getName().buffer()); + } + } +} + +void Skeleton::updateWorldTransform(Physics physics) { + for (size_t i = 0, n = _bones.size(); i < n; i++) { + Bone *bone = _bones[i]; + bone->_ax = bone->_x; + bone->_ay = bone->_y; + bone->_arotation = bone->_rotation; + bone->_ascaleX = bone->_scaleX; + bone->_ascaleY = bone->_scaleY; + bone->_ashearX = bone->_shearX; + bone->_ashearY = bone->_shearY; + } + + for (size_t i = 0, n = _updateCache.size(); i < n; ++i) { + Updatable *updatable = _updateCache[i]; + updatable->update(physics); + } +} + +void Skeleton::updateWorldTransform(Physics physics, Bone *parent) { + // Apply the parent bone transform to the root bone. The root bone always + // inherits scale, rotation and reflection. + Bone *rootBone = getRootBone(); + float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d; + rootBone->_worldX = pa * _x + pb * _y + parent->_worldX; + rootBone->_worldY = pc * _x + pd * _y + parent->_worldY; + + float rx = (rootBone->_rotation + rootBone->_shearX) * MathUtil::Deg_Rad; + float ry = (rootBone->_rotation + 90 + rootBone->_shearY) * MathUtil::Deg_Rad; + float la = MathUtil::cos(rx) * rootBone->_scaleX; + float lb = MathUtil::cos(ry) * rootBone->_scaleY; + float lc = MathUtil::sin(rx) * rootBone->_scaleX; + float ld = MathUtil::sin(ry) * rootBone->_scaleY; + rootBone->_a = (pa * la + pb * lc) * _scaleX; + rootBone->_b = (pa * lb + pb * ld) * _scaleX; + rootBone->_c = (pc * la + pd * lc) * _scaleY; + rootBone->_d = (pc * lb + pd * ld) * _scaleY; + + // Update everything except root bone. + Bone *rb = getRootBone(); + for (size_t i = 0, n = _updateCache.size(); i < n; i++) { + Updatable *updatable = _updateCache[i]; + if (updatable != rb) + updatable->update(physics); + } +} + +void Skeleton::setToSetupPose() { + setBonesToSetupPose(); + setSlotsToSetupPose(); +} + +void Skeleton::setBonesToSetupPose() { + for (size_t i = 0, n = _bones.size(); i < n; ++i) { + _bones[i]->setToSetupPose(); + } + + for (size_t i = 0, n = _ikConstraints.size(); i < n; ++i) { + _ikConstraints[i]->setToSetupPose(); + } + + for (size_t i = 0, n = _transformConstraints.size(); i < n; ++i) { + _transformConstraints[i]->setToSetupPose(); + } + + for (size_t i = 0, n = _pathConstraints.size(); i < n; ++i) { + _pathConstraints[i]->setToSetupPose(); + } + + for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) { + _physicsConstraints[i]->setToSetupPose(); + } +} + +void Skeleton::setSlotsToSetupPose() { + _drawOrder.clear(); + for (size_t i = 0, n = _slots.size(); i < n; ++i) { + _drawOrder.add(_slots[i]); + } + + for (size_t i = 0, n = _slots.size(); i < n; ++i) { + _slots[i]->setToSetupPose(); + } +} + +Bone *Skeleton::findBone(const String &boneName) { + return ContainerUtil::findWithDataName(_bones, boneName); +} + +Slot *Skeleton::findSlot(const String &slotName) { + return ContainerUtil::findWithDataName(_slots, slotName); +} + +void Skeleton::setSkin(const String &skinName) { + Skin *foundSkin = skinName.isEmpty() ? NULL : _data->findSkin(skinName); + setSkin(foundSkin); +} + +void Skeleton::setSkin(Skin *newSkin) { + if (_skin == newSkin) + return; + if (newSkin != NULL) { + if (_skin != NULL) { + Skeleton &thisRef = *this; + newSkin->attachAll(thisRef, *_skin); + } else { + for (size_t i = 0, n = _slots.size(); i < n; ++i) { + Slot *slotP = _slots[i]; + Slot &slot = *slotP; + const String &name = slot._data.getAttachmentName(); + if (name.length() > 0) { + Attachment *attachment = newSkin->getAttachment(i, name); + if (attachment != NULL) { + slot.setAttachment(attachment); + } + } + } + } + } + + _skin = newSkin; + updateCache(); +} + +Attachment *Skeleton::getAttachment(const String &slotName, + const String &attachmentName) { + return getAttachment(_data->findSlot(slotName)->getIndex(), attachmentName); +} + +Attachment *Skeleton::getAttachment(int slotIndex, + const String &attachmentName) { + if (attachmentName.isEmpty()) + return NULL; + + if (_skin != NULL) { + Attachment *attachment = _skin->getAttachment(slotIndex, attachmentName); + if (attachment != NULL) { + return attachment; + } + } + + return _data->getDefaultSkin() != NULL + ? _data->getDefaultSkin()->getAttachment(slotIndex, attachmentName) + : NULL; +} + +void Skeleton::setAttachment(const String &slotName, + const String &attachmentName) { + assert(slotName.length() > 0); + + for (size_t i = 0, n = _slots.size(); i < n; ++i) { + Slot *slot = _slots[i]; + if (slot->_data.getName() == slotName) { + Attachment *attachment = NULL; + if (attachmentName.length() > 0) { + attachment = getAttachment((int) i, attachmentName); + + assert(attachment != NULL); + } + + slot->setAttachment(attachment); + + return; + } + } + + printf("Slot not found: %s", slotName.buffer()); + + assert(false); +} + +IkConstraint *Skeleton::findIkConstraint(const String &constraintName) { + assert(constraintName.length() > 0); + + for (size_t i = 0, n = _ikConstraints.size(); i < n; ++i) { + IkConstraint *ikConstraint = _ikConstraints[i]; + if (ikConstraint->_data.getName() == constraintName) { + return ikConstraint; + } + } + return NULL; +} + +TransformConstraint * +Skeleton::findTransformConstraint(const String &constraintName) { + assert(constraintName.length() > 0); + + for (size_t i = 0, n = _transformConstraints.size(); i < n; ++i) { + TransformConstraint *transformConstraint = _transformConstraints[i]; + if (transformConstraint->_data.getName() == constraintName) { + return transformConstraint; + } + } + + return NULL; +} + +PathConstraint *Skeleton::findPathConstraint(const String &constraintName) { + assert(constraintName.length() > 0); + + for (size_t i = 0, n = _pathConstraints.size(); i < n; ++i) { + PathConstraint *constraint = _pathConstraints[i]; + if (constraint->_data.getName() == constraintName) { + return constraint; + } + } + + return NULL; +} + +PhysicsConstraint * +Skeleton::findPhysicsConstraint(const String &constraintName) { + assert(constraintName.length() > 0); + + for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) { + PhysicsConstraint *constraint = _physicsConstraints[i]; + if (constraint->_data.getName() == constraintName) { + return constraint; + } + } + + return NULL; +} + +void Skeleton::getBounds(float &outX, float &outY, float &outWidth, + float &outHeight, Vector &outVertexBuffer) { + getBounds(outX, outY, outWidth, outHeight, outVertexBuffer, NULL); +} + +void Skeleton::getBounds(float &outX, float &outY, float &outWidth, + float &outHeight, Vector &outVertexBuffer, SkeletonClipping *clipper) { + static unsigned short quadIndices[] = {0, 1, 2, 2, 3, 0}; + float minX = FLT_MAX; + float minY = FLT_MAX; + float maxX = -FLT_MAX; + float maxY = -FLT_MAX; + + for (size_t i = 0; i < _drawOrder.size(); ++i) { + Slot *slot = _drawOrder[i]; + if (!slot->_bone._active) + continue; + size_t verticesLength = 0; + Attachment *attachment = slot->getAttachment(); + unsigned short *triangles = NULL; + size_t trianglesLength = 0; + + if (attachment != NULL && + attachment->getRTTI().instanceOf(RegionAttachment::rtti)) { + RegionAttachment *regionAttachment = + static_cast(attachment); + + verticesLength = 8; + if (outVertexBuffer.size() < 8) { + outVertexBuffer.setSize(8, 0); + } + regionAttachment->computeWorldVertices(*slot, outVertexBuffer, 0); + triangles = quadIndices; + trianglesLength = 6; + } else if (attachment != NULL && + attachment->getRTTI().instanceOf(MeshAttachment::rtti)) { + MeshAttachment *mesh = static_cast(attachment); + + verticesLength = mesh->getWorldVerticesLength(); + if (outVertexBuffer.size() < verticesLength) { + outVertexBuffer.setSize(verticesLength, 0); + } + + mesh->computeWorldVertices(*slot, 0, verticesLength, + outVertexBuffer.buffer(), 0); + triangles = mesh->getTriangles().buffer(); + trianglesLength = mesh->getTriangles().size(); + } else if (attachment != NULL && + attachment->getRTTI().instanceOf(ClippingAttachment::rtti) && clipper != NULL) { + clipper->clipStart(*slot, static_cast(attachment)); + } + + if (verticesLength > 0) { + float *vertices = outVertexBuffer.buffer(); + if (clipper != NULL && clipper->isClipping()) { + clipper->clipTriangles(outVertexBuffer.buffer(), triangles, trianglesLength); + vertices = clipper->getClippedVertices().buffer(); + verticesLength = clipper->getClippedVertices().size(); + } + for (size_t ii = 0; ii < verticesLength; ii += 2) { + float vx = vertices[ii]; + float vy = vertices[ii + 1]; + + minX = MathUtil::min(minX, vx); + minY = MathUtil::min(minY, vy); + maxX = MathUtil::max(maxX, vx); + maxY = MathUtil::max(maxY, vy); + } + } + if (clipper != NULL) clipper->clipEnd(*slot); + } + if (clipper != NULL) clipper->clipEnd(); + + outX = minX; + outY = minY; + outWidth = maxX - minX; + outHeight = maxY - minY; +} + +Bone *Skeleton::getRootBone() { return _bones.size() == 0 ? NULL : _bones[0]; } + +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; +} + +Vector &Skeleton::getPhysicsConstraints() { + return _physicsConstraints; +} + +Skin *Skeleton::getSkin() { return _skin; } + +Color &Skeleton::getColor() { return _color; } + +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; + + Bone *target = constraint->getTarget(); + sortBone(target); + + Vector &constrained = constraint->getBones(); + Bone *parent = constrained[0]; + sortBone(parent); + + if (constrained.size() == 1) { + _updateCache.add(constraint); + sortReset(parent->_children); + } else { + Bone *child = constrained[constrained.size() - 1]; + sortBone(child); + + _updateCache.add(constraint); + + sortReset(parent->_children); + child->_sorted = true; + } +} + +void Skeleton::sortPathConstraint(PathConstraint *constraint) { + constraint->_active = + constraint->_target->_bone._active && + (!constraint->_data.isSkinRequired() || + (_skin && _skin->_constraints.contains(&constraint->_data))); + if (!constraint->_active) + return; + + Slot *slot = constraint->getTarget(); + int slotIndex = slot->getData().getIndex(); + Bone &slotBone = slot->getBone(); + if (_skin != NULL) + sortPathConstraintAttachment(_skin, slotIndex, slotBone); + if (_data->_defaultSkin != NULL && _data->_defaultSkin != _skin) + sortPathConstraintAttachment(_data->_defaultSkin, slotIndex, slotBone); + for (size_t ii = 0, nn = _data->_skins.size(); ii < nn; ii++) + sortPathConstraintAttachment(_data->_skins[ii], slotIndex, slotBone); + + Attachment *attachment = slot->getAttachment(); + if (attachment != NULL && + attachment->getRTTI().instanceOf(PathAttachment::rtti)) + sortPathConstraintAttachment(attachment, slotBone); + + Vector &constrained = constraint->getBones(); + size_t boneCount = constrained.size(); + for (size_t i = 0; i < boneCount; ++i) { + sortBone(constrained[i]); + } + + _updateCache.add(constraint); + + for (size_t i = 0; i < boneCount; i++) + sortReset(constrained[i]->getChildren()); + for (size_t i = 0; i < boneCount; i++) + constrained[i]->_sorted = true; +} + +void Skeleton::sortTransformConstraint(TransformConstraint *constraint) { + constraint->_active = + constraint->_target->_active && + (!constraint->_data.isSkinRequired() || + (_skin && _skin->_constraints.contains(&constraint->_data))); + if (!constraint->_active) + return; + + sortBone(constraint->getTarget()); + + Vector &constrained = constraint->getBones(); + size_t boneCount = constrained.size(); + if (constraint->_data.isLocal()) { + for (size_t i = 0; i < boneCount; i++) { + Bone *child = constrained[i]; + sortBone(child->getParent()); + sortBone(child); + } + } else { + for (size_t i = 0; i < boneCount; ++i) { + sortBone(constrained[i]); + } + } + + _updateCache.add(constraint); + + for (size_t i = 0; i < boneCount; ++i) + sortReset(constrained[i]->getChildren()); + for (size_t i = 0; i < boneCount; ++i) + constrained[i]->_sorted = true; +} + +void Skeleton::sortPhysicsConstraint(PhysicsConstraint *constraint) { + Bone *bone = constraint->getBone(); + constraint->_active = + bone->_active && + (!constraint->_data.isSkinRequired() || + (_skin && _skin->_constraints.contains(&constraint->_data))); + if (!constraint->_active) + return; + + sortBone(bone); + _updateCache.add(constraint); + sortReset(bone->getChildren()); + bone->_sorted = true; +} + +void Skeleton::sortPathConstraintAttachment(Skin *skin, size_t slotIndex, + Bone &slotBone) { + Skin::AttachmentMap::Entries attachments = skin->getAttachments(); + + while (attachments.hasNext()) { + Skin::AttachmentMap::Entry entry = attachments.next(); + if (entry._slotIndex == slotIndex) { + Attachment *value = entry._attachment; + sortPathConstraintAttachment(value, slotBone); + } + } +} + +void Skeleton::sortPathConstraintAttachment(Attachment *attachment, + Bone &slotBone) { + if (attachment == NULL || + !attachment->getRTTI().instanceOf(PathAttachment::rtti)) + return; + Vector &pathBones = + static_cast(attachment)->getBones(); + if (pathBones.size() == 0) + sortBone(&slotBone); + else { + for (size_t i = 0, n = pathBones.size(); i < n;) { + size_t nn = pathBones[i++]; + nn += i; + while (i < nn) { + sortBone(_bones[pathBones[i++]]); + } + } + } +} + +void Skeleton::sortBone(Bone *bone) { + if (bone->_sorted) + return; + Bone *parent = bone->_parent; + if (parent != NULL) + sortBone(parent); + bone->_sorted = true; + _updateCache.add(bone); +} + +void Skeleton::sortReset(Vector &bones) { + for (size_t i = 0, n = bones.size(); i < n; ++i) { + Bone *bone = bones[i]; + if (!bone->_active) + continue; + if (bone->_sorted) + sortReset(bone->getChildren()); + bone->_sorted = false; + } +} + +float Skeleton::getTime() { return _time; } + +void Skeleton::setTime(float time) { _time = time; } + +void Skeleton::update(float delta) { _time += delta; } + +void Skeleton::physicsTranslate(float x, float y) { + for (int i = 0; i < (int) _physicsConstraints.size(); i++) { + _physicsConstraints[i]->translate(x, y); + } +} + +void Skeleton::physicsRotate(float x, float y, float degrees) { + for (int i = 0; i < (int) _physicsConstraints.size(); i++) { + _physicsConstraints[i]->rotate(x, y, degrees); + } +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Skeleton.h b/native/cocos/editor-support/spine/4.2/spine/Skeleton.h new file mode 100644 index 0000000000..1f5ccde7fe --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Skeleton.h @@ -0,0 +1,286 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Skeleton_h +#define Spine_Skeleton_h + +#include +#include +#include +#include +#include +#include + +namespace spine { + class SkeletonData; + + class Bone; + + class Updatable; + + class Slot; + + class IkConstraint; + + class PathConstraint; + + class PhysicsConstraint; + + class TransformConstraint; + + class Skin; + + class Attachment; + + class SkeletonClipping; + + class SP_API Skeleton : public SpineObject { + friend class AnimationState; + + friend class SkeletonBounds; + + friend class SkeletonClipping; + + friend class AttachmentTimeline; + + friend class RGBATimeline; + + friend class RGBTimeline; + + friend class AlphaTimeline; + + friend class RGBA2Timeline; + + friend class RGB2Timeline; + + friend class DeformTimeline; + + friend class DrawOrderTimeline; + + friend class EventTimeline; + + friend class IkConstraintTimeline; + + friend class PathConstraintMixTimeline; + + friend class PathConstraintPositionTimeline; + + friend class PathConstraintSpacingTimeline; + + friend class ScaleTimeline; + + friend class ScaleXTimeline; + + friend class ScaleYTimeline; + + friend class ShearTimeline; + + friend class ShearXTimeline; + + friend class ShearYTimeline; + + friend class TransformConstraintTimeline; + + friend class RotateTimeline; + + friend class TranslateTimeline; + + friend class TranslateXTimeline; + + friend class TranslateYTimeline; + + friend class TwoColorTimeline; + + public: + explicit Skeleton(SkeletonData *skeletonData); + + ~Skeleton(); + + /// Caches information about bones and constraints. Must be called if bones, constraints or weighted path attachments are added + /// or removed. + void updateCache(); + + void printUpdateCache(); + + /// Updates the world transform for each bone and applies all constraints. + /// + /// See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine + /// Runtimes Guide. + void updateWorldTransform(Physics physics); + + void updateWorldTransform(Physics physics, Bone *parent); + + /// Sets the bones, constraints, and slots to their setup pose values. + void setToSetupPose(); + + /// Sets the bones and constraints to their setup pose values. + void setBonesToSetupPose(); + + void setSlotsToSetupPose(); + + /// @return May be NULL. + Bone *findBone(const String &boneName); + + /// @return May be NULL. + Slot *findSlot(const String &slotName); + + /// Sets a skin by name (see setSkin). + void setSkin(const String &skinName); + + /// Attachments from the new skin are attached if the corresponding attachment from the old skin was attached. + /// If there was no old skin, each slot's setup mode attachment is attached from the new skin. + /// After changing the skin, the visible attachments can be reset to those attached in the setup pose by calling + /// See Skeleton::setSlotsToSetupPose() + /// Also, often AnimationState::apply(Skeleton&) is called before the next time the + /// skeleton is rendered to allow any attachment keys in the current animation(s) to hide or show attachments from the new skin. + /// @param newSkin May be NULL. + void setSkin(Skin *newSkin); + + /// @return May be NULL. + Attachment *getAttachment(const String &slotName, const String &attachmentName); + + /// @return May be NULL. + Attachment *getAttachment(int slotIndex, const String &attachmentName); + + /// @param attachmentName May be empty. + void setAttachment(const String &slotName, const String &attachmentName); + + /// @return May be NULL. + IkConstraint *findIkConstraint(const String &constraintName); + + /// @return May be NULL. + TransformConstraint *findTransformConstraint(const String &constraintName); + + /// @return May be NULL. + PathConstraint *findPathConstraint(const String &constraintName); + + /// @return May be NULL. + PhysicsConstraint *findPhysicsConstraint(const String &constraintName); + + /// Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose. + /// @param outX The horizontal distance between the skeleton origin and the left side of the AABB. + /// @param outY The vertical distance between the skeleton origin and the bottom side of the AABB. + /// @param outWidth The width of the AABB + /// @param outHeight The height of the AABB. + /// @param outVertexBuffer Reference to hold a Vector of floats. This method will assign it with new floats as needed. + // @param clipping Pointer to a SkeletonClipping instance or NULL. If a clipper is given, clipping attachments will be taken into account. + void getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector &outVertexBuffer); + void getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector &outVertexBuffer, SkeletonClipping *clipper); + + Bone *getRootBone(); + + SkeletonData *getData(); + + Vector &getBones(); + + Vector &getUpdateCacheList(); + + Vector &getSlots(); + + Vector &getDrawOrder(); + + Vector &getIkConstraints(); + + Vector &getPathConstraints(); + + Vector &getTransformConstraints(); + + Vector &getPhysicsConstraints(); + + Skin *getSkin(); + + Color &getColor(); + + void setPosition(float x, float y); + + float getX(); + + void setX(float inValue); + + float getY(); + + void setY(float inValue); + + float getScaleX(); + + void setScaleX(float inValue); + + float getScaleY(); + + void setScaleY(float inValue); + + float getTime(); + + void setTime(float time); + + void update(float delta); + + /// Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated around the + /// specified point in world space. + void physicsTranslate(float x, float y); + + /// Calls {@link PhysicsConstraint#rotate(float, float, float)} for each physics constraint. */ + void physicsRotate(float x, float y, float degrees); + #ifndef __EMSCRIPTEN__ + private: + #endif + SkeletonData *_data; + Vector _bones; + Vector _slots; + Vector _drawOrder; + Vector _ikConstraints; + Vector _transformConstraints; + Vector _pathConstraints; + Vector _physicsConstraints; + Vector _updateCache; + Skin *_skin; + Color _color; + float _scaleX, _scaleY; + float _x, _y; + float _time; + + void sortIkConstraint(IkConstraint *constraint); + + void sortPathConstraint(PathConstraint *constraint); + + void sortPhysicsConstraint(PhysicsConstraint *constraint); + + void sortTransformConstraint(TransformConstraint *constraint); + + void sortPathConstraintAttachment(Skin *skin, size_t slotIndex, Bone &slotBone); + + void sortPathConstraintAttachment(Attachment *attachment, Bone &slotBone); + + void sortBone(Bone *bone); + + static void sortReset(Vector &bones); + }; +} + +#endif /* Spine_Skeleton_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonBinary.cpp b/native/cocos/editor-support/spine/4.2/spine/SkeletonBinary.cpp new file mode 100644 index 0000000000..a1a9392d54 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonBinary.cpp @@ -0,0 +1,1490 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace spine; + +SkeletonBinary::SkeletonBinary(Atlas *atlasArray) : _attachmentLoader( + new (__FILE__, __LINE__) AtlasAttachmentLoader(atlasArray)), + _error(), _scale(1), _ownsLoader(true) { +} + +SkeletonBinary::SkeletonBinary(AttachmentLoader *attachmentLoader, bool ownsLoader) : _attachmentLoader( + attachmentLoader), + _error(), + _scale(1), + _ownsLoader(ownsLoader) { + assert(_attachmentLoader != NULL); +} + +SkeletonBinary::~SkeletonBinary() { + ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes); + _linkedMeshes.clear(); + + if (_ownsLoader) delete _attachmentLoader; +} + +SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, const int length) { + bool nonessential; + SkeletonData *skeletonData; + + DataInput *input = new (__FILE__, __LINE__) DataInput(); + input->cursor = binary; + input->end = binary + length; + + _linkedMeshes.clear(); + + skeletonData = new (__FILE__, __LINE__) SkeletonData(); + + char buffer[16] = {0}; + int lowHash = readInt(input); + int hightHash = readInt(input); + String hashString; + snprintf(buffer, 16, "%x", hightHash); + hashString.append(buffer); + snprintf(buffer, 16, "%x", lowHash); + hashString.append(buffer); + skeletonData->_hash = hashString; + + char *skeletonDataVersion = readString(input); + skeletonData->_version.own(skeletonDataVersion); + + if (!skeletonData->_version.startsWith(SPINE_VERSION_STRING)) { + char errorMsg[255]; + snprintf(errorMsg, 255, "Skeleton version %s does not match runtime version %s", skeletonData->_version.buffer(), SPINE_VERSION_STRING); + setError(errorMsg, ""); + delete input; + delete skeletonData; + return NULL; + } + + skeletonData->_x = readFloat(input); + skeletonData->_y = readFloat(input); + skeletonData->_width = readFloat(input); + skeletonData->_height = readFloat(input); + skeletonData->_referenceScale = readFloat(input) * this->_scale; + + nonessential = readBoolean(input); + + if (nonessential) { + skeletonData->_fps = readFloat(input); + skeletonData->_imagesPath.own(readString(input)); + skeletonData->_audioPath.own(readString(input)); + } + + int numStrings = readVarint(input, true); + for (int i = 0; i < numStrings; i++) + skeletonData->_strings.add(readString(input)); + + /* Bones. */ + int numBones = readVarint(input, true); + skeletonData->_bones.setSize(numBones, 0); + 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); + data->_rotation = readFloat(input); + data->_x = readFloat(input) * _scale; + data->_y = readFloat(input) * _scale; + data->_scaleX = readFloat(input); + data->_scaleY = readFloat(input); + data->_shearX = readFloat(input); + data->_shearY = readFloat(input); + data->_length = readFloat(input) * _scale; + data->_inherit = static_cast(readVarint(input, true)); + data->_skinRequired = readBoolean(input); + if (nonessential) { + readColor(input, data->getColor()); + data->_icon.own(readString(input)); + data->_visible = readBoolean(input); + } + skeletonData->_bones[i] = data; + } + + /* Slots. */ + int slotsCount = readVarint(input, true); + skeletonData->_slots.setSize(slotsCount, 0); + for (int i = 0; i < slotsCount; ++i) { + String slotName = String(readString(input), true); + BoneData *boneData = skeletonData->_bones[readVarint(input, true)]; + SlotData *slotData = new (__FILE__, __LINE__) SlotData(i, slotName, *boneData); + + readColor(input, slotData->getColor()); + unsigned char a = readByte(input); + unsigned char r = readByte(input); + unsigned char g = readByte(input); + unsigned char b = readByte(input); + if (!(r == 0xff && g == 0xff && b == 0xff && a == 0xff)) { + slotData->getDarkColor().set(r / 255.0f, g / 255.0f, b / 255.0f, 1); + slotData->setHasDarkColor(true); + } + slotData->_attachmentName = readStringRef(input, skeletonData); + slotData->_blendMode = static_cast(readVarint(input, true)); + if (nonessential) { + slotData->_visible = readBoolean(input); + } + skeletonData->_slots[i] = slotData; + } + + /* IK constraints. */ + int ikConstraintsCount = readVarint(input, true); + 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)); + data->setOrder(readVarint(input, true)); + int bonesCount = readVarint(input, true); + data->_bones.setSize(bonesCount, 0); + for (int ii = 0; ii < bonesCount; ++ii) + data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; + data->_target = skeletonData->_bones[readVarint(input, true)]; + int flags = readByte(input); + data->_skinRequired = (flags & 1) != 0; + data->_bendDirection = (flags & 2) != 0 ? 1 : -1; + data->_compress = (flags & 4) != 0; + data->_stretch = (flags & 8) != 0; + data->_uniform = (flags & 16) != 0; + if ((flags & 32) != 0) data->_mix = (flags & 64) != 0 ? readFloat(input) : 1; + if ((flags & 128) != 0) data->_softness = readFloat(input) * _scale; + + skeletonData->_ikConstraints[i] = data; + } + + /* Transform constraints. */ + int transformConstraintsCount = readVarint(input, true); + 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)); + data->setOrder(readVarint(input, true)); + int bonesCount = readVarint(input, true); + data->_bones.setSize(bonesCount, 0); + for (int ii = 0; ii < bonesCount; ++ii) + data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; + data->_target = skeletonData->_bones[readVarint(input, true)]; + int flags = readByte(input); + data->_skinRequired = (flags & 1) != 0; + data->_local = (flags & 2) != 0; + data->_relative = (flags & 4) != 0; + if ((flags & 8) != 0) data->_offsetRotation = readFloat(input); + if ((flags & 16) != 0) data->_offsetX = readFloat(input) * _scale; + if ((flags & 32) != 0) data->_offsetY = readFloat(input) * _scale; + if ((flags & 64) != 0) data->_offsetScaleX = readFloat(input); + if ((flags & 128) != 0) data->_offsetScaleY = readFloat(input); + flags = readByte(input); + if ((flags & 1) != 0) data->_offsetShearY = readFloat(input); + if ((flags & 2) != 0) data->_mixRotate = readFloat(input); + if ((flags & 4) != 0) data->_mixX = readFloat(input); + if ((flags & 8) != 0) data->_mixY = readFloat(input); + if ((flags & 16) != 0) data->_mixScaleX = readFloat(input); + if ((flags & 32) != 0) data->_mixScaleY = readFloat(input); + if ((flags & 64) != 0) data->_mixShearY = readFloat(input); + + skeletonData->_transformConstraints[i] = data; + } + + /* Path constraints */ + int pathConstraintsCount = readVarint(input, true); + 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)); + data->setOrder(readVarint(input, true)); + data->setSkinRequired(readBoolean(input)); + int bonesCount = readVarint(input, true); + data->_bones.setSize(bonesCount, 0); + for (int ii = 0; ii < bonesCount; ++ii) + data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; + data->_target = skeletonData->_slots[readVarint(input, true)]; + int flags = readByte(input); + data->_positionMode = (PositionMode) (flags & 1); + data->_spacingMode = (SpacingMode) ((flags >> 1) & 3); + data->_rotateMode = (RotateMode) ((flags >> 3) & 3); + if ((flags & 128) != 0) data->_offsetRotation = readFloat(input); + data->_position = readFloat(input); + if (data->_positionMode == PositionMode_Fixed) data->_position *= _scale; + data->_spacing = readFloat(input); + if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) + data->_spacing *= _scale; + data->_mixRotate = readFloat(input); + data->_mixX = readFloat(input); + data->_mixY = readFloat(input); + skeletonData->_pathConstraints[i] = data; + } + + // Physics constraints. + int physicsConstraintsCount = readVarint(input, true); + skeletonData->_physicsConstraints.setSize(physicsConstraintsCount, 0); + for (int i = 0; i < physicsConstraintsCount; i++) { + const char *name = readString(input); + PhysicsConstraintData *data = new (__FILE__, __LINE__) PhysicsConstraintData(String(name, true)); + data->_order = readVarint(input, true); + data->_bone = skeletonData->_bones[readVarint(input, true)]; + int flags = readByte(input); + data->_skinRequired = (flags & 1) != 0; + if ((flags & 2) != 0) data->_x = readFloat(input); + if ((flags & 4) != 0) data->_y = readFloat(input); + if ((flags & 8) != 0) data->_rotate = readFloat(input); + if ((flags & 16) != 0) data->_scaleX = readFloat(input); + if ((flags & 32) != 0) data->_shearX = readFloat(input); + data->_limit = ((flags & 64) != 0 ? readFloat(input) : 5000) * _scale; + data->_step = 1.f / readByte(input); + data->_inertia = readFloat(input); + data->_strength = readFloat(input); + data->_damping = readFloat(input); + data->_massInverse = (flags & 128) != 0 ? readFloat(input) : 1; + data->_wind = readFloat(input); + data->_gravity = readFloat(input); + flags = readByte(input); + if ((flags & 1) != 0) data->_inertiaGlobal = true; + if ((flags & 2) != 0) data->_strengthGlobal = true; + if ((flags & 4) != 0) data->_dampingGlobal = true; + if ((flags & 8) != 0) data->_massGlobal = true; + if ((flags & 16) != 0) data->_windGlobal = true; + if ((flags & 32) != 0) data->_gravityGlobal = true; + if ((flags & 64) != 0) data->_mixGlobal = true; + data->_mix = (flags & 128) != 0 ? readFloat(input) : 1; + skeletonData->_physicsConstraints[i] = data; + } + + /* Default skin. */ + Skin *defaultSkin = readSkin(input, true, skeletonData, nonessential); + if (defaultSkin) { + skeletonData->_defaultSkin = defaultSkin; + skeletonData->_skins.add(defaultSkin); + } + + if (!this->getError().isEmpty()) { + delete input; + delete skeletonData; + return NULL; + } + + /* Skins. */ + for (size_t i = 0, n = (size_t) readVarint(input, true); i < n; ++i) { + Skin *skin = readSkin(input, false, skeletonData, nonessential); + if (skin) + skeletonData->_skins.add(skin); + else { + delete input; + delete skeletonData; + return NULL; + } + } + + /* Linked meshes. */ + for (int i = 0, n = (int) _linkedMeshes.size(); i < n; ++i) { + LinkedMesh *linkedMesh = _linkedMeshes[i]; + Skin *skin = skeletonData->_skins[linkedMesh->_skinIndex]; + Attachment *parent = skin->getAttachment(linkedMesh->_slotIndex, linkedMesh->_parent); + if (parent == NULL) { + delete input; + delete skeletonData; + setError("Parent mesh not found: ", linkedMesh->_parent.buffer()); + return NULL; + } + linkedMesh->_mesh->_timelineAttachment = linkedMesh->_inheritTimeline ? static_cast(parent) + : linkedMesh->_mesh; + linkedMesh->_mesh->setParentMesh(static_cast(parent)); + if (linkedMesh->_mesh->_region) linkedMesh->_mesh->updateRegion(); + _attachmentLoader->configureAttachment(linkedMesh->_mesh); + } + ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes); + _linkedMeshes.clear(); + + /* Events. */ + int eventsCount = readVarint(input, true); + skeletonData->_events.setSize(eventsCount, 0); + for (int i = 0; i < eventsCount; ++i) { + const char *name = readString(input); + EventData *eventData = new (__FILE__, __LINE__) EventData(String(name, true)); + eventData->_intValue = readVarint(input, false); + eventData->_floatValue = readFloat(input); + eventData->_stringValue.own(readString(input)); + eventData->_audioPath.own(readString(input)); + if (!eventData->_audioPath.isEmpty()) { + eventData->_volume = readFloat(input); + eventData->_balance = readFloat(input); + } + skeletonData->_events[i] = eventData; + } + + /* Animations. */ + int animationsCount = readVarint(input, true); + skeletonData->_animations.setSize(animationsCount, 0); + for (int i = 0; i < animationsCount; ++i) { + String name(readString(input), true); + Animation *animation = readAnimation(name, input, skeletonData); + if (!animation) { + delete input; + delete skeletonData; + return NULL; + } + skeletonData->_animations[i] = animation; + } + + delete input; + return skeletonData; +} + +SkeletonData *SkeletonBinary::readSkeletonDataFile(const String &path) { + int length; + SkeletonData *skeletonData; + const char *binary = SpineExtension::readFile(path.buffer(), &length); + if (length == 0 || !binary) { + setError("Unable to read skeleton file: ", path.buffer()); + return NULL; + } + skeletonData = readSkeletonData((unsigned char *) binary, length); + SpineExtension::free(binary, __FILE__, __LINE__); + return skeletonData; +} + +void SkeletonBinary::setError(const char *value1, const char *value2) { + char message[256]; + int length; + strcpy(message, value1); + length = (int) strlen(value1); + if (value2) strncat(message + length, value2, 255 - length); + _error = String(message); +} + +char *SkeletonBinary::readString(DataInput *input) { + int length = readVarint(input, true); + char *string; + if (length == 0) return NULL; + string = SpineExtension::alloc(length, __FILE__, __LINE__); + memcpy(string, input->cursor, length - 1); + input->cursor += length - 1; + string[length - 1] = '\0'; + return string; +} + +char *SkeletonBinary::readStringRef(DataInput *input, SkeletonData *skeletonData) { + int index = readVarint(input, true); + return index == 0 ? NULL : skeletonData->_strings[index - 1]; +} + +float SkeletonBinary::readFloat(DataInput *input) { + union { + int intValue; + float floatValue; + } intToFloat; + intToFloat.intValue = readInt(input); + return intToFloat.floatValue; +} + +unsigned char SkeletonBinary::readByte(DataInput *input) { + return *input->cursor++; +} + +signed char SkeletonBinary::readSByte(DataInput *input) { + return (signed char) readByte(input); +} + +bool SkeletonBinary::readBoolean(DataInput *input) { + return readByte(input) != 0; +} + +int SkeletonBinary::readInt(DataInput *input) { + int result = readByte(input); + result <<= 8; + result |= readByte(input); + result <<= 8; + result |= readByte(input); + result <<= 8; + result |= readByte(input); + return result; +} + +void SkeletonBinary::readColor(DataInput *input, Color &color) { + color.r = readByte(input) / 255.0f; + color.g = readByte(input) / 255.0f; + color.b = readByte(input) / 255.0f; + color.a = readByte(input) / 255.0f; +} + +int SkeletonBinary::readVarint(DataInput *input, bool optimizePositive) { + unsigned char b = readByte(input); + int value = b & 0x7F; + if (b & 0x80) { + b = readByte(input); + value |= (b & 0x7F) << 7; + if (b & 0x80) { + b = readByte(input); + value |= (b & 0x7F) << 14; + if (b & 0x80) { + b = readByte(input); + value |= (b & 0x7F) << 21; + if (b & 0x80) value |= (readByte(input) & 0x7F) << 28; + } + } + } + if (!optimizePositive) value = (((unsigned int) value >> 1) ^ -(value & 1)); + return value; +} + +Skin *SkeletonBinary::readSkin(DataInput *input, bool defaultSkin, SkeletonData *skeletonData, bool nonessential) { + Skin *skin; + int slotCount = 0; + if (defaultSkin) { + slotCount = readVarint(input, true); + if (slotCount == 0) return NULL; + skin = new (__FILE__, __LINE__) Skin("default"); + } else { + skin = new (__FILE__, __LINE__) Skin(String(readString(input), true)); + + if (nonessential) readColor(input, skin->getColor()); + + for (int i = 0, n = readVarint(input, true); i < n; i++) { + int boneIndex = readVarint(input, true); + if (boneIndex >= (int) skeletonData->_bones.size()) return NULL; + skin->getBones().add(skeletonData->_bones[boneIndex]); + } + + for (int i = 0, n = readVarint(input, true); i < n; i++) { + int ikIndex = readVarint(input, true); + if (ikIndex >= (int) skeletonData->_ikConstraints.size()) return NULL; + skin->getConstraints().add(skeletonData->_ikConstraints[ikIndex]); + } + + for (int i = 0, n = readVarint(input, true); i < n; i++) { + int transformIndex = readVarint(input, true); + if (transformIndex >= (int) skeletonData->_transformConstraints.size()) return NULL; + skin->getConstraints().add(skeletonData->_transformConstraints[transformIndex]); + } + + for (int i = 0, n = readVarint(input, true); i < n; i++) { + int pathIndex = readVarint(input, true); + if (pathIndex >= (int) skeletonData->_pathConstraints.size()) return NULL; + skin->getConstraints().add(skeletonData->_pathConstraints[pathIndex]); + } + + for (int i = 0, n = readVarint(input, true); i < n; i++) { + int physicsIndex = readVarint(input, true); + if (physicsIndex >= (int) skeletonData->_physicsConstraints.size()) return NULL; + skin->getConstraints().add(skeletonData->_physicsConstraints[physicsIndex]); + } + slotCount = readVarint(input, true); + } + + for (int i = 0; i < slotCount; ++i) { + int slotIndex = readVarint(input, true); + for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) { + String name(readStringRef(input, skeletonData)); + Attachment *attachment = readAttachment(input, skin, slotIndex, name, skeletonData, nonessential); + if (attachment) + skin->setAttachment(slotIndex, String(name), attachment); + else { + delete skin; + return NULL; + } + } + } + return skin; +} + +Sequence *SkeletonBinary::readSequence(DataInput *input) { + Sequence *sequence = new (__FILE__, __LINE__) Sequence(readVarint(input, true)); + sequence->_start = readVarint(input, true); + sequence->_digits = readVarint(input, true); + sequence->_setupIndex = readVarint(input, true); + return sequence; +} + +Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slotIndex, const String &attachmentName, + SkeletonData *skeletonData, bool nonessential) { + + int flags = readByte(input); + String name = (flags & 8) != 0 ? readStringRef(input, skeletonData) : attachmentName; + AttachmentType type = static_cast(flags & 0x7); + switch (type) { + case AttachmentType_Region: { + String path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : name; + Color color(1, 1, 1, 1); + if ((flags & 32) != 0) readColor(input, color); + Sequence *sequence = (flags & 64) != 0 ? readSequence(input) : nullptr; + float rotation = (flags & 128) != 0 ? readFloat(input) : 0; + float x = readFloat(input) * _scale; + float y = readFloat(input) * _scale; + float scaleX = readFloat(input); + float scaleY = readFloat(input); + float width = readFloat(input) * _scale; + float height = readFloat(input) * _scale; + RegionAttachment *region = _attachmentLoader->newRegionAttachment(*skin, String(name), String(path), sequence); + if (!region) { + setError("Error reading attachment: ", name.buffer()); + return NULL; + } + region->_path = path; + region->_rotation = rotation; + region->_x = x; + region->_y = y; + region->_scaleX = scaleX; + region->_scaleY = scaleY; + region->_width = width; + region->_height = height; + region->getColor().set(color); + region->_sequence = sequence; + if (sequence == NULL) region->updateRegion(); + _attachmentLoader->configureAttachment(region); + return region; + } + case AttachmentType_Boundingbox: { + BoundingBoxAttachment *box = _attachmentLoader->newBoundingBoxAttachment(*skin, String(name)); + if (!box) { + setError("Error reading attachment: ", name.buffer()); + return NULL; + } + int verticesLength = readVertices(input, box->getVertices(), box->getBones(), (flags & 16) != 0); + box->setWorldVerticesLength(verticesLength); + if (nonessential) { + readColor(input, box->getColor()); + } + _attachmentLoader->configureAttachment(box); + return box; + } + case AttachmentType_Mesh: { + Vector uvs; + Vector triangles; + Vector vertices; + Vector bones; + int hullLength; + float width = 0; + float height = 0; + Vector edges; + + String path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : name; + Color color(1, 1, 1, 1); + if ((flags & 32) != 0) readColor(input, color); + Sequence *sequence = (flags & 64) != 0 ? readSequence(input) : nullptr; + hullLength = readVarint(input, true); + int verticesLength = readVertices(input, vertices, bones, (flags & 128) != 0); + readFloatArray(input, verticesLength, 1, uvs); + readShortArray(input, triangles, (verticesLength - hullLength - 2) * 3); + + if (nonessential) { + readShortArray(input, edges, readVarint(input, true)); + width = readFloat(input); + height = readFloat(input); + } + + MeshAttachment *mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path), sequence); + if (!mesh) { + setError("Error reading attachment: ", name.buffer()); + return NULL; + } + mesh->_path = path; + mesh->_color.set(color); + mesh->_bones.addAll(bones); + mesh->_vertices.addAll(vertices); + mesh->setWorldVerticesLength(verticesLength); + mesh->_triangles.addAll(triangles); + mesh->_regionUVs.addAll(uvs); + if (sequence == NULL) mesh->updateRegion(); + mesh->_hullLength = hullLength; + mesh->_sequence = sequence; + if (nonessential) { + mesh->_edges.addAll(edges); + mesh->_width = width; + mesh->_height = height; + } + _attachmentLoader->configureAttachment(mesh); + return mesh; + } + case AttachmentType_Linkedmesh: { + String path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : name; + Color color(1, 1, 1, 1); + if ((flags & 32) != 0) readColor(input, color); + Sequence *sequence = (flags & 64) != 0 ? readSequence(input) : nullptr; + bool inheritTimelines = (flags & 128) != 0; + int skinIndex = readVarint(input, true); + String parent(readStringRef(input, skeletonData)); + float width = 0, height = 0; + if (nonessential) { + width = readFloat(input) * _scale; + height = readFloat(input) * _scale; + } + + MeshAttachment *mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path), sequence); + if (!mesh) { + setError("Error reading attachment: ", name.buffer()); + return NULL; + } + mesh->_path = path; + mesh->_color.set(color); + mesh->_sequence = sequence; + if (nonessential) { + mesh->_width = width; + mesh->_height = height; + } + + LinkedMesh *linkedMesh = new (__FILE__, __LINE__) LinkedMesh(mesh, skinIndex, slotIndex, + String(parent), inheritTimelines); + _linkedMeshes.add(linkedMesh); + return mesh; + } + case AttachmentType_Path: { + PathAttachment *path = _attachmentLoader->newPathAttachment(*skin, String(name)); + if (!path) { + setError("Error reading attachment: ", name.buffer()); + return NULL; + } + path->_closed = (flags & 16) != 0; + path->_constantSpeed = (flags & 32) != 0; + int verticesLength = readVertices(input, path->getVertices(), path->getBones(), (flags & 64) != 0); + path->setWorldVerticesLength(verticesLength); + int lengthsLength = verticesLength / 6; + path->_lengths.setSize(lengthsLength, 0); + for (int i = 0; i < lengthsLength; ++i) { + path->_lengths[i] = readFloat(input) * _scale; + } + if (nonessential) { + readColor(input, path->getColor()); + } + _attachmentLoader->configureAttachment(path); + return path; + } + case AttachmentType_Point: { + PointAttachment *point = _attachmentLoader->newPointAttachment(*skin, String(name)); + if (!point) { + setError("Error reading attachment: ", name.buffer()); + return NULL; + } + point->_rotation = readFloat(input); + point->_x = readFloat(input) * _scale; + point->_y = readFloat(input) * _scale; + + if (nonessential) { + readColor(input, point->getColor()); + } + _attachmentLoader->configureAttachment(point); + return point; + } + case AttachmentType_Clipping: { + int endSlotIndex = readVarint(input, true); + ClippingAttachment *clip = _attachmentLoader->newClippingAttachment(*skin, name); + if (!clip) { + setError("Error reading attachment: ", name.buffer()); + return NULL; + } + int verticesLength = readVertices(input, clip->getVertices(), clip->getBones(), (flags & 16) != 0); + clip->setWorldVerticesLength(verticesLength); + clip->_endSlot = skeletonData->_slots[endSlotIndex]; + if (nonessential) { + readColor(input, clip->getColor()); + } + _attachmentLoader->configureAttachment(clip); + return clip; + } + } + return NULL; +} + +int SkeletonBinary::readVertices(DataInput *input, Vector &vertices, Vector &bones, bool weighted) { + float scale = _scale; + int vertexCount = readVarint(input, true); + int verticesLength = vertexCount << 1; + if (!weighted) { + readFloatArray(input, verticesLength, scale, vertices); + return verticesLength; + } + vertices.ensureCapacity(verticesLength * 3 * 3); + bones.ensureCapacity(verticesLength * 3); + for (int i = 0; i < vertexCount; ++i) { + int boneCount = readVarint(input, true); + bones.add(boneCount); + for (int ii = 0; ii < boneCount; ++ii) { + bones.add(readVarint(input, true)); + vertices.add(readFloat(input) * scale); + vertices.add(readFloat(input) * scale); + vertices.add(readFloat(input)); + } + } + return verticesLength; +} + +void SkeletonBinary::readFloatArray(DataInput *input, int n, float scale, Vector &array) { + array.setSize(n, 0); + + int i; + if (scale == 1) { + for (i = 0; i < n; ++i) { + array[i] = readFloat(input); + } + } else { + for (i = 0; i < n; ++i) { + array[i] = readFloat(input) * scale; + } + } +} + +void SkeletonBinary::readShortArray(DataInput *input, Vector &array, int n) { + array.setSize(n, 0); + for (int i = 0; i < n; ++i) { + array[i] = (short) readVarint(input, true); + } +} + +void SkeletonBinary::setBezier(DataInput *input, CurveTimeline *timeline, int bezier, int frame, int value, float time1, + float time2, + float value1, float value2, float scale) { + float cx1 = readFloat(input); + float cy1 = readFloat(input); + float cx2 = readFloat(input); + float cy2 = readFloat(input); + timeline->setBezier(bezier, frame, value, time1, value1, cx1, cy1 * scale, cx2, cy2 * scale, time2, value2); +} + +void SkeletonBinary::readTimeline(DataInput *input, Vector &timelines, CurveTimeline1 *timeline, float scale) { + float time = readFloat(input); + float value = readFloat(input) * scale; + for (int frame = 0, bezier = 0, frameLast = (int) timeline->getFrameCount() - 1;; frame++) { + timeline->setFrame(frame, time, value); + if (frame == frameLast) break; + float time2 = readFloat(input); + float value2 = readFloat(input) * scale; + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, scale); + } + time = time2; + value = value2; + } + timelines.add(timeline); +} + +void SkeletonBinary::readTimeline2(DataInput *input, Vector &timelines, CurveTimeline2 *timeline, float scale) { + float time = readFloat(input); + float value1 = readFloat(input) * scale; + float value2 = readFloat(input) * scale; + for (int frame = 0, bezier = 0, frameLast = (int) timeline->getFrameCount() - 1;; frame++) { + timeline->setFrame(frame, time, value1, value2); + if (frame == frameLast) break; + float time2 = readFloat(input); + float nvalue1 = readFloat(input) * scale; + float nvalue2 = readFloat(input) * scale; + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale); + setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale); + } + time = time2; + value1 = nvalue1; + value2 = nvalue2; + } + timelines.add(timeline); +} + +Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, SkeletonData *skeletonData) { + Vector timelines; + float scale = _scale; + int numTimelines = readVarint(input, true); + SP_UNUSED(numTimelines); + // Slot timelines. + for (int i = 0, n = readVarint(input, true); i < n; ++i) { + int slotIndex = readVarint(input, true); + for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) { + unsigned char timelineType = readByte(input); + int frameCount = readVarint(input, true); + int frameLast = frameCount - 1; + switch (timelineType) { + case SLOT_ATTACHMENT: { + AttachmentTimeline *timeline = new (__FILE__, __LINE__) AttachmentTimeline(frameCount, slotIndex); + for (int frame = 0; frame < frameCount; ++frame) { + float time = readFloat(input); + String attachmentName(readStringRef(input, skeletonData)); + timeline->setFrame(frame, time, attachmentName); + } + timelines.add(timeline); + break; + } + case SLOT_RGBA: { + int bezierCount = readVarint(input, true); + RGBATimeline *timeline = new (__FILE__, __LINE__) RGBATimeline(frameCount, bezierCount, slotIndex); + + float time = readFloat(input); + float r = readByte(input) / 255.0; + float g = readByte(input) / 255.0; + float b = readByte(input) / 255.0; + float a = readByte(input) / 255.0; + + for (int frame = 0, bezier = 0;; frame++) { + timeline->setFrame(frame, time, r, g, b, a); + if (frame == frameLast) break; + + float time2 = readFloat(input); + float r2 = readByte(input) / 255.0; + float g2 = readByte(input) / 255.0; + float b2 = readByte(input) / 255.0; + float a2 = readByte(input) / 255.0; + + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1); + setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1); + setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1); + setBezier(input, timeline, bezier++, frame, 3, time, time2, a, a2, 1); + } + time = time2; + r = r2; + g = g2; + b = b2; + a = a2; + } + timelines.add(timeline); + break; + } + case SLOT_RGB: { + int bezierCount = readVarint(input, true); + RGBTimeline *timeline = new (__FILE__, __LINE__) RGBTimeline(frameCount, bezierCount, slotIndex); + + float time = readFloat(input); + float r = readByte(input) / 255.0; + float g = readByte(input) / 255.0; + float b = readByte(input) / 255.0; + + for (int frame = 0, bezier = 0;; frame++) { + timeline->setFrame(frame, time, r, g, b); + if (frame == frameLast) break; + + float time2 = readFloat(input); + float r2 = readByte(input) / 255.0; + float g2 = readByte(input) / 255.0; + float b2 = readByte(input) / 255.0; + + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1); + setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1); + setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1); + } + time = time2; + r = r2; + g = g2; + b = b2; + } + timelines.add(timeline); + break; + } + case SLOT_RGBA2: { + int bezierCount = readVarint(input, true); + RGBA2Timeline *timeline = new (__FILE__, __LINE__) RGBA2Timeline(frameCount, bezierCount, slotIndex); + + float time = readFloat(input); + float r = readByte(input) / 255.0; + float g = readByte(input) / 255.0; + float b = readByte(input) / 255.0; + float a = readByte(input) / 255.0; + float r2 = readByte(input) / 255.0; + float g2 = readByte(input) / 255.0; + float b2 = readByte(input) / 255.0; + + for (int frame = 0, bezier = 0;; frame++) { + timeline->setFrame(frame, time, r, g, b, a, r2, g2, b2); + if (frame == frameLast) break; + float time2 = readFloat(input); + float nr = readByte(input) / 255.0; + float ng = readByte(input) / 255.0; + float nb = readByte(input) / 255.0; + float na = readByte(input) / 255.0; + float nr2 = readByte(input) / 255.0; + float ng2 = readByte(input) / 255.0; + float nb2 = readByte(input) / 255.0; + + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1); + setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1); + setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1); + setBezier(input, timeline, bezier++, frame, 3, time, time2, a, na, 1); + setBezier(input, timeline, bezier++, frame, 4, time, time2, r2, nr2, 1); + setBezier(input, timeline, bezier++, frame, 5, time, time2, g2, ng2, 1); + setBezier(input, timeline, bezier++, frame, 6, time, time2, b2, nb2, 1); + } + time = time2; + r = nr; + g = ng; + b = nb; + a = na; + r2 = nr2; + g2 = ng2; + b2 = nb2; + } + timelines.add(timeline); + break; + } + case SLOT_RGB2: { + int bezierCount = readVarint(input, true); + RGB2Timeline *timeline = new (__FILE__, __LINE__) RGB2Timeline(frameCount, bezierCount, slotIndex); + + float time = readFloat(input); + float r = readByte(input) / 255.0; + float g = readByte(input) / 255.0; + float b = readByte(input) / 255.0; + float r2 = readByte(input) / 255.0; + float g2 = readByte(input) / 255.0; + float b2 = readByte(input) / 255.0; + + for (int frame = 0, bezier = 0;; frame++) { + timeline->setFrame(frame, time, r, g, b, r2, g2, b2); + if (frame == frameLast) break; + float time2 = readFloat(input); + float nr = readByte(input) / 255.0; + float ng = readByte(input) / 255.0; + float nb = readByte(input) / 255.0; + float nr2 = readByte(input) / 255.0; + float ng2 = readByte(input) / 255.0; + float nb2 = readByte(input) / 255.0; + + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1); + setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1); + setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1); + setBezier(input, timeline, bezier++, frame, 3, time, time2, r2, nr2, 1); + setBezier(input, timeline, bezier++, frame, 4, time, time2, g2, ng2, 1); + setBezier(input, timeline, bezier++, frame, 5, time, time2, b2, nb2, 1); + } + time = time2; + r = nr; + g = ng; + b = nb; + r2 = nr2; + g2 = ng2; + b2 = nb2; + } + timelines.add(timeline); + break; + } + case SLOT_ALPHA: { + int bezierCount = readVarint(input, true); + AlphaTimeline *timeline = new (__FILE__, __LINE__) AlphaTimeline(frameCount, bezierCount, slotIndex); + float time = readFloat(input); + float a = readByte(input) / 255.0; + for (int frame = 0, bezier = 0;; frame++) { + timeline->setFrame(frame, time, a); + if (frame == frameLast) break; + float time2 = readFloat(input); + float a2 = readByte(input) / 255.0; + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, a, a2, 1); + } + time = time2; + a = a2; + } + timelines.add(timeline); + break; + } + default: { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError("Invalid timeline type for a slot: ", skeletonData->_slots[slotIndex]->_name.buffer()); + return NULL; + } + } + } + } + + // Bone timelines. + for (int i = 0, n = readVarint(input, true); i < n; ++i) { + int boneIndex = readVarint(input, true); + for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) { + unsigned char timelineType = readByte(input); + int frameCount = readVarint(input, true); + if (timelineType == BONE_INHERIT) { + InheritTimeline *timeline = new (__FILE__, __LINE__) InheritTimeline(frameCount, boneIndex); + for (int frame = 0; frame < frameCount; frame++) { + float time = readFloat(input); + Inherit inherit = (Inherit) readByte(input); + timeline->setFrame(frame, time, inherit); + } + timelines.add(timeline); + continue; + } + int bezierCount = readVarint(input, true); + switch (timelineType) { + case BONE_ROTATE: + readTimeline(input, timelines, + new (__FILE__, __LINE__) RotateTimeline(frameCount, bezierCount, boneIndex), + 1); + break; + case BONE_TRANSLATE: + readTimeline2(input, timelines, new (__FILE__, __LINE__) TranslateTimeline(frameCount, bezierCount, boneIndex), scale); + break; + case BONE_TRANSLATEX: + readTimeline(input, timelines, new (__FILE__, __LINE__) TranslateXTimeline(frameCount, bezierCount, boneIndex), scale); + break; + case BONE_TRANSLATEY: + readTimeline(input, timelines, new (__FILE__, __LINE__) TranslateYTimeline(frameCount, bezierCount, boneIndex), scale); + break; + case BONE_SCALE: + readTimeline2(input, timelines, + new (__FILE__, __LINE__) ScaleTimeline(frameCount, bezierCount, boneIndex), + 1); + break; + case BONE_SCALEX: + readTimeline(input, timelines, + new (__FILE__, __LINE__) ScaleXTimeline(frameCount, bezierCount, boneIndex), + 1); + break; + case BONE_SCALEY: + readTimeline(input, timelines, + new (__FILE__, __LINE__) ScaleYTimeline(frameCount, bezierCount, boneIndex), + 1); + break; + case BONE_SHEAR: + readTimeline2(input, timelines, + new (__FILE__, __LINE__) ShearTimeline(frameCount, bezierCount, boneIndex), + 1); + break; + case BONE_SHEARX: + readTimeline(input, timelines, + new (__FILE__, __LINE__) ShearXTimeline(frameCount, bezierCount, boneIndex), + 1); + break; + case BONE_SHEARY: + readTimeline(input, timelines, + new (__FILE__, __LINE__) ShearYTimeline(frameCount, bezierCount, boneIndex), + 1); + break; + default: { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError("Invalid timeline type for a bone: ", skeletonData->_bones[boneIndex]->_name.buffer()); + return NULL; + } + } + } + } + + // IK timelines. + for (int i = 0, n = readVarint(input, true); i < n; ++i) { + int index = readVarint(input, true); + int frameCount = readVarint(input, true); + int frameLast = frameCount - 1; + int bezierCount = readVarint(input, true); + IkConstraintTimeline *timeline = new (__FILE__, __LINE__) IkConstraintTimeline(frameCount, bezierCount, index); + int flags = readByte(input); + float time = readFloat(input), mix = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0; + float softness = (flags & 4) != 0 ? readFloat(input) * scale : 0; + for (int frame = 0, bezier = 0;; frame++) { + timeline->setFrame(frame, time, mix, softness, (flags & 8) != 0 ? 1 : -1, (flags & 16) != 0, (flags & 32) != 0); + if (frame == frameLast) break; + flags = readByte(input); + float time2 = readFloat(input), mix2 = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0; + float softness2 = (flags & 4) != 0 ? readFloat(input) * scale : 0; + if ((flags & 64) != 0) + timeline->setStepped(frame); + else if ((flags & 128) != 0) { + setBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1); + setBezier(input, timeline, bezier++, frame, 1, time, time2, softness, softness2, scale); + } + time = time2; + mix = mix2; + softness = softness2; + } + timelines.add(timeline); + } + + // Transform constraint timelines. + for (int i = 0, n = readVarint(input, true); i < n; ++i) { + int index = readVarint(input, true); + int frameCount = readVarint(input, true); + int frameLast = frameCount - 1; + int bezierCount = readVarint(input, true); + TransformConstraintTimeline *timeline = new TransformConstraintTimeline(frameCount, bezierCount, index); + float time = readFloat(input); + float mixRotate = readFloat(input); + float mixX = readFloat(input); + float mixY = readFloat(input); + float mixScaleX = readFloat(input); + float mixScaleY = readFloat(input); + float mixShearY = readFloat(input); + for (int frame = 0, bezier = 0;; frame++) { + timeline->setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY); + if (frame == frameLast) break; + float time2 = readFloat(input); + float mixRotate2 = readFloat(input); + float mixX2 = readFloat(input); + float mixY2 = readFloat(input); + float mixScaleX2 = readFloat(input); + float mixScaleY2 = readFloat(input); + float mixShearY2 = readFloat(input); + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1); + setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1); + setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1); + setBezier(input, timeline, bezier++, frame, 3, time, time2, mixScaleX, mixScaleX2, 1); + setBezier(input, timeline, bezier++, frame, 4, time, time2, mixScaleY, mixScaleY2, 1); + setBezier(input, timeline, bezier++, frame, 5, time, time2, mixShearY, mixShearY2, 1); + } + time = time2; + mixRotate = mixRotate2; + mixX = mixX2; + mixY = mixY2; + mixScaleX = mixScaleX2; + mixScaleY = mixScaleY2; + mixShearY = mixShearY2; + } + timelines.add(timeline); + } + + // Path constraint timelines. + for (int i = 0, n = readVarint(input, true); i < n; ++i) { + int index = readVarint(input, true); + PathConstraintData *data = skeletonData->_pathConstraints[index]; + for (int ii = 0, nn = readVarint(input, true); ii < nn; ii++) { + int type = readByte(input); + int frameCount = readVarint(input, true); + int bezierCount = readVarint(input, true); + switch (type) { + case PATH_POSITION: { + readTimeline(input, timelines, new PathConstraintPositionTimeline(frameCount, bezierCount, index), + data->_positionMode == PositionMode_Fixed ? scale : 1); + break; + } + case PATH_SPACING: { + readTimeline(input, timelines, + new PathConstraintSpacingTimeline(frameCount, + bezierCount, + index), + data->_spacingMode == SpacingMode_Length || + data->_spacingMode == SpacingMode_Fixed + ? scale + : 1); + break; + } + case PATH_MIX: + PathConstraintMixTimeline *timeline = new PathConstraintMixTimeline(frameCount, bezierCount, index); + float time = readFloat(input); + float mixRotate = readFloat(input); + float mixX = readFloat(input); + float mixY = readFloat(input); + for (int frame = 0, bezier = 0, frameLast = (int) timeline->getFrameCount() - 1;; frame++) { + timeline->setFrame(frame, time, mixRotate, mixX, mixY); + if (frame == frameLast) break; + float time2 = readFloat(input); + float mixRotate2 = readFloat(input); + float mixX2 = readFloat(input); + float mixY2 = readFloat(input); + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1); + setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1); + setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1); + } + time = time2; + mixRotate = mixRotate2; + mixX = mixX2; + mixY = mixY2; + } + timelines.add(timeline); + } + } + } + + // Physics timelines. + for (int i = 0, n = readVarint(input, true); i < n; i++) { + int index = readVarint(input, true) - 1; + for (int ii = 0, nn = readVarint(input, true); ii < nn; ii++) { + int type = readByte(input); + int frameCount = readVarint(input, true); + if (type == PHYSICS_RESET) { + PhysicsConstraintResetTimeline *timeline = new (__FILE__, __LINE__) PhysicsConstraintResetTimeline(frameCount, index); + for (int frame = 0; frame < frameCount; frame++) + timeline->setFrame(frame, readFloat(input)); + timelines.add(timeline); + continue; + } + int bezierCount = readVarint(input, true); + switch (type) { + case PHYSICS_INERTIA: + readTimeline(input, timelines, new PhysicsConstraintInertiaTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_STRENGTH: + readTimeline(input, timelines, new PhysicsConstraintStrengthTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_DAMPING: + readTimeline(input, timelines, new PhysicsConstraintDampingTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_MASS: + readTimeline(input, timelines, new PhysicsConstraintMassTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_WIND: + readTimeline(input, timelines, new PhysicsConstraintWindTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_GRAVITY: + readTimeline(input, timelines, new PhysicsConstraintGravityTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_MIX: + readTimeline(input, timelines, new PhysicsConstraintMixTimeline(frameCount, bezierCount, index), 1); + } + } + } + + // Attachment timelines. + for (int i = 0, n = readVarint(input, true); i < n; ++i) { + Skin *skin = skeletonData->_skins[readVarint(input, true)]; + for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) { + int slotIndex = readVarint(input, true); + for (int iii = 0, nnn = readVarint(input, true); iii < nnn; iii++) { + const char *attachmentName = readStringRef(input, skeletonData); + Attachment *baseAttachment = skin->getAttachment(slotIndex, String(attachmentName)); + if (!baseAttachment) { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError("Attachment not found: ", attachmentName); + return NULL; + } + unsigned int timelineType = readByte(input); + int frameCount = readVarint(input, true); + int frameLast = frameCount - 1; + + switch (timelineType) { + case ATTACHMENT_DEFORM: { + VertexAttachment *attachment = static_cast(baseAttachment); + bool weighted = attachment->_bones.size() > 0; + Vector &vertices = attachment->_vertices; + int deformLength = weighted ? (int) vertices.size() / 3 * 2 : (int) vertices.size(); + + int bezierCount = readVarint(input, true); + DeformTimeline *timeline = new (__FILE__, __LINE__) DeformTimeline(frameCount, bezierCount, slotIndex, + attachment); + + float time = readFloat(input); + for (int frame = 0, bezier = 0;; ++frame) { + Vector deform; + size_t end = (size_t) readVarint(input, true); + if (end == 0) { + if (weighted) { + deform.setSize(deformLength, 0); + for (int iiii = 0; iiii < deformLength; ++iiii) + deform[iiii] = 0; + } else { + deform.clearAndAddAll(vertices); + } + } else { + deform.setSize(deformLength, 0); + size_t start = (size_t) readVarint(input, true); + end += start; + if (scale == 1) { + for (size_t v = start; v < end; ++v) + deform[v] = readFloat(input); + } else { + for (size_t v = start; v < end; ++v) + deform[v] = readFloat(input) * scale; + } + + if (!weighted) { + for (size_t v = 0, vn = deform.size(); v < vn; ++v) + deform[v] += vertices[v]; + } + } + + timeline->setFrame(frame, time, deform); + if (frame == frameLast) break; + float time2 = readFloat(input); + switch (readSByte(input)) { + case CURVE_STEPPED: + timeline->setStepped(frame); + break; + case CURVE_BEZIER: + setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1); + } + time = time2; + } + + timelines.add(timeline); + break; + } + case ATTACHMENT_SEQUENCE: { + SequenceTimeline *timeline = new (__FILE__, __LINE__) SequenceTimeline(frameCount, slotIndex, baseAttachment); + for (int frame = 0; frame < frameCount; frame++) { + float time = readFloat(input); + int modeAndIndex = readInt(input); + float delay = readFloat(input); + timeline->setFrame(frame, time, (spine::SequenceMode)(modeAndIndex & 0xf), modeAndIndex >> 4, delay); + } + timelines.add(timeline); + break; + } + } + } + } + } + + // Draw order timeline. + size_t drawOrderCount = (size_t) readVarint(input, true); + if (drawOrderCount > 0) { + DrawOrderTimeline *timeline = new (__FILE__, __LINE__) DrawOrderTimeline(drawOrderCount); + + size_t slotCount = skeletonData->_slots.size(); + for (size_t i = 0; i < drawOrderCount; ++i) { + float time = readFloat(input); + size_t offsetCount = (size_t) readVarint(input, true); + + Vector drawOrder; + drawOrder.setSize(slotCount, 0); + for (int ii = (int) slotCount - 1; ii >= 0; --ii) + drawOrder[ii] = -1; + + Vector unchanged; + unchanged.setSize(slotCount - offsetCount, 0); + size_t originalIndex = 0, unchangedIndex = 0; + for (size_t ii = 0; ii < offsetCount; ++ii) { + size_t slotIndex = (size_t) readVarint(input, true); + // Collect unchanged items. + while (originalIndex != slotIndex) + unchanged[unchangedIndex++] = (int) originalIndex++; + // Set changed items. + size_t index = originalIndex; + drawOrder[index + (size_t) readVarint(input, true)] = (int) originalIndex++; + } + + // Collect remaining unchanged items. + while (originalIndex < slotCount) { + unchanged[unchangedIndex++] = (int) originalIndex++; + } + + // Fill in unchanged items. + for (int ii = (int) slotCount - 1; ii >= 0; --ii) + if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex]; + timeline->setFrame(i, time, drawOrder); + } + timelines.add(timeline); + } + + // Event timeline. + int eventCount = readVarint(input, true); + if (eventCount > 0) { + EventTimeline *timeline = new (__FILE__, __LINE__) 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->_intValue = readVarint(input, false); + event->_floatValue = readFloat(input); + const char *event_stringValue = readString(input); + if (event_stringValue == nullptr) { + event->_stringValue = eventData->_stringValue; + } else { + event->_stringValue = String(event_stringValue); + SpineExtension::free(event_stringValue, __FILE__, __LINE__); + } + + if (!eventData->_audioPath.isEmpty()) { + event->_volume = readFloat(input); + event->_balance = readFloat(input); + } + timeline->setFrame(i, event); + } + timelines.add(timeline); + } + + float duration = 0; + for (int i = 0, n = (int) timelines.size(); i < n; i++) { + duration = MathUtil::max(duration, (timelines[i])->getDuration()); + } + return new (__FILE__, __LINE__) Animation(String(name), timelines, duration); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonBinary.h b/native/cocos/editor-support/spine/4.2/spine/SkeletonBinary.h new file mode 100644 index 0000000000..93c8e81160 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonBinary.h @@ -0,0 +1,179 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_SkeletonBinary_h +#define Spine_SkeletonBinary_h + +#include +#include +#include +#include +#include + + +namespace spine { +class SkeletonData; + +class Atlas; + +class AttachmentLoader; + +class LinkedMesh; + +class Skin; + +class Attachment; + +class VertexAttachment; + +class Animation; + +class Timeline; + +class CurveTimeline; + +class CurveTimeline1; + +class CurveTimeline2; + +class Sequence; + +class SP_API SkeletonBinary : public SpineObject { +public: + static const int BONE_ROTATE = 0; + static const int BONE_TRANSLATE = 1; + static const int BONE_TRANSLATEX = 2; + static const int BONE_TRANSLATEY = 3; + static const int BONE_SCALE = 4; + static const int BONE_SCALEX = 5; + static const int BONE_SCALEY = 6; + static const int BONE_SHEAR = 7; + static const int BONE_SHEARX = 8; + static const int BONE_SHEARY = 9; + static const int BONE_INHERIT = 10; + + static const int SLOT_ATTACHMENT = 0; + static const int SLOT_RGBA = 1; + static const int SLOT_RGB = 2; + static const int SLOT_RGBA2 = 3; + static const int SLOT_RGB2 = 4; + static const int SLOT_ALPHA = 5; + + static const int ATTACHMENT_DEFORM = 0; + static const int ATTACHMENT_SEQUENCE = 1; + + static const int PATH_POSITION = 0; + static const int PATH_SPACING = 1; + static const int PATH_MIX = 2; + + static const int PHYSICS_INERTIA = 0; + static const int PHYSICS_STRENGTH = 1; + static const int PHYSICS_DAMPING = 2; + static const int PHYSICS_MASS = 4; + static const int PHYSICS_WIND = 5; + static const int PHYSICS_GRAVITY = 6; + static const int PHYSICS_MIX = 7; + static const int PHYSICS_RESET = 8; + + static const int CURVE_LINEAR = 0; + static const int CURVE_STEPPED = 1; + static const int CURVE_BEZIER = 2; + + explicit SkeletonBinary(Atlas *atlasArray); + + explicit SkeletonBinary(AttachmentLoader *attachmentLoader, bool ownsLoader = false); + + ~SkeletonBinary(); + + SkeletonData *readSkeletonData(const unsigned char *binary, int length); + + SkeletonData *readSkeletonDataFile(const String &path); + + void setScale(float scale) { _scale = scale; } + + String &getError() { return _error; } + +private: + struct DataInput : public SpineObject { + const unsigned char *cursor; + const unsigned char *end; + }; + + AttachmentLoader *_attachmentLoader; + Vector _linkedMeshes; + String _error; + float _scale; + const bool _ownsLoader; + + void setError(const char *value1, const char *value2); + + char *readString(DataInput *input); + + char *readStringRef(DataInput *input, SkeletonData *skeletonData); + + float readFloat(DataInput *input); + + unsigned char readByte(DataInput *input); + + signed char readSByte(DataInput *input); + + bool readBoolean(DataInput *input); + + int readInt(DataInput *input); + + void readColor(DataInput *input, Color &color); + + int readVarint(DataInput *input, bool optimizePositive); + + Skin *readSkin(DataInput *input, bool defaultSkin, SkeletonData *skeletonData, bool nonessential); + + Sequence *readSequence(DataInput *input); + + Attachment *readAttachment(DataInput *input, Skin *skin, int slotIndex, const String &attachmentName, + SkeletonData *skeletonData, bool nonessential); + + int readVertices(DataInput *input, Vector &vertices, Vector &bones, bool weighted); + + void readFloatArray(DataInput *input, int n, float scale, Vector &array); + + void readShortArray(DataInput *input, Vector &array, int n); + + Animation *readAnimation(const String &name, DataInput *input, SkeletonData *skeletonData); + + void + setBezier(DataInput *input, CurveTimeline *timeline, int bezier, int frame, int value, float time1, float time2, + float value1, float value2, float scale); + + void readTimeline(DataInput *input, Vector &timelines, CurveTimeline1 *timeline, float scale); + + void readTimeline2(DataInput *input, Vector &timelines, CurveTimeline2 *timeline, float scale); +}; +} // namespace spine + +#endif /* Spine_SkeletonBinary_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonBounds.cpp b/native/cocos/editor-support/spine/4.2/spine/SkeletonBounds.cpp new file mode 100644 index 0000000000..239faf6215 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonBounds.cpp @@ -0,0 +1,231 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include + +#include + +#include + +using namespace spine; + +SkeletonBounds::SkeletonBounds() : _minX(0), _minY(0), _maxX(0), _maxY(0) { +} + +SkeletonBounds::~SkeletonBounds() { + for (size_t i = 0, n = _polygons.size(); i < n; i++) + _polygonPool.free(_polygons[i]); + _polygons.clear(); +} + +void SkeletonBounds::update(Skeleton &skeleton, bool updateAabb) { + Vector &slots = skeleton.getSlots(); + size_t slotCount = slots.size(); + + _boundingBoxes.clear(); + for (size_t i = 0, n = _polygons.size(); i < n; ++i) { + _polygonPool.free(_polygons[i]); + } + + _polygons.clear(); + + for (size_t i = 0; i < slotCount; i++) { + Slot *slot = slots[i]; + if (!slot->getBone().isActive()) continue; + + Attachment *attachment = slot->getAttachment(); + if (attachment == NULL || !attachment->getRTTI().instanceOf(BoundingBoxAttachment::rtti)) continue; + BoundingBoxAttachment *boundingBox = static_cast(attachment); + _boundingBoxes.add(boundingBox); + + spine::Polygon *polygonP = _polygonPool.obtain(); + _polygons.add(polygonP); + + Polygon &polygon = *polygonP; + + size_t count = boundingBox->getWorldVerticesLength(); + polygon._count = (int) count; + if (polygon._vertices.size() < count) { + polygon._vertices.setSize(count, 0); + } + boundingBox->computeWorldVertices(*slot, polygon._vertices); + } + + if (updateAabb) + aabbCompute(); + else { + _minX = FLT_MIN; + _minY = FLT_MIN; + _maxX = FLT_MAX; + _maxY = FLT_MAX; + } +} + +bool SkeletonBounds::aabbcontainsPoint(float x, float y) { + return x >= _minX && x <= _maxX && y >= _minY && y <= _maxY; +} + +bool SkeletonBounds::aabbintersectsSegment(float x1, float y1, float x2, float y2) { + float minX = _minX; + float minY = _minY; + float maxX = _maxX; + float maxY = _maxY; + + if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || + (y1 >= maxY && y2 >= maxY)) { + return false; + } + + float m = (y2 - y1) / (x2 - x1); + float y = m * (minX - x1) + y1; + if (y > minY && y < maxY) return true; + y = m * (maxX - x1) + y1; + if (y > minY && y < maxY) return true; + float x = (minY - y1) / m + x1; + if (x > minX && x < maxX) return true; + x = (maxY - y1) / m + x1; + if (x > minX && x < maxX) return true; + return false; +} + +bool SkeletonBounds::aabbIntersectsSkeleton(SkeletonBounds &bounds) { + return _minX < bounds._maxX && _maxX > bounds._minX && _minY < bounds._maxY && _maxY > bounds._minY; +} + +bool SkeletonBounds::containsPoint(spine::Polygon *polygon, float x, float y) { + Vector &vertices = polygon->_vertices; + int nn = polygon->_count; + + int prevIndex = nn - 2; + bool inside = false; + for (int ii = 0; ii < nn; ii += 2) { + float vertexY = vertices[ii + 1]; + float prevY = vertices[prevIndex + 1]; + if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) { + float vertexX = vertices[ii]; + if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x) { + inside = !inside; + } + } + prevIndex = ii; + } + return inside; +} + +BoundingBoxAttachment *SkeletonBounds::containsPoint(float x, float y) { + for (size_t i = 0, n = _polygons.size(); i < n; ++i) + if (containsPoint(_polygons[i], x, y)) return _boundingBoxes[i]; + return NULL; +} + +BoundingBoxAttachment *SkeletonBounds::intersectsSegment(float x1, float y1, float x2, float y2) { + for (size_t i = 0, n = _polygons.size(); i < n; ++i) + if (intersectsSegment(_polygons[i], x1, y1, x2, y2)) return _boundingBoxes[i]; + return NULL; +} + +bool SkeletonBounds::intersectsSegment(spine::Polygon *polygon, float x1, float y1, float x2, float y2) { + Vector &vertices = polygon->_vertices; + size_t nn = polygon->_count; + + float width12 = x1 - x2, height12 = y1 - y2; + float det1 = x1 * y2 - y1 * x2; + float x3 = vertices[nn - 2], y3 = vertices[nn - 1]; + for (size_t ii = 0; ii < nn; ii += 2) { + float x4 = vertices[ii], y4 = vertices[ii + 1]; + float det2 = x3 * y4 - y3 * x4; + float width34 = x3 - x4, height34 = y3 - y4; + float det3 = width12 * height34 - height12 * width34; + float x = (det1 * width34 - width12 * det2) / det3; + if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) { + float y = (det1 * height34 - height12 * det2) / det3; + if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) { + return true; + } + } + x3 = x4; + y3 = y4; + } + + return false; +} + +spine::Polygon *SkeletonBounds::getPolygon(BoundingBoxAttachment *attachment) { + int index = _boundingBoxes.indexOf(attachment); + return index == -1 ? NULL : _polygons[index]; +} + +BoundingBoxAttachment *SkeletonBounds::getBoundingBox(Polygon *polygon) { + int index = _polygons.indexOf(polygon); + return index == -1 ? NULL : _boundingBoxes[index]; +} + +Vector &SkeletonBounds::getPolygons() { + return _polygons; +} + +Vector &SkeletonBounds::getBoundingBoxes() { + return _boundingBoxes; +} + +float SkeletonBounds::getWidth() { + return _maxX - _minX; +} + +float SkeletonBounds::getHeight() { + return _maxY - _minY; +} + +void SkeletonBounds::aabbCompute() { + float minX = FLT_MAX; + float minY = FLT_MAX; + float maxX = FLT_MIN; + float maxY = FLT_MIN; + + for (size_t i = 0, n = _polygons.size(); i < n; ++i) { + spine::Polygon *polygon = _polygons[i]; + Vector &vertices = polygon->_vertices; + for (int ii = 0, nn = polygon->_count; ii < nn; ii += 2) { + float x = vertices[ii]; + float y = vertices[ii + 1]; + minX = MathUtil::min(minX, x); + minY = MathUtil::min(minY, y); + maxX = MathUtil::max(maxX, x); + maxY = MathUtil::max(maxY, y); + } + } + _minX = minX; + _minY = minY; + _maxX = maxX; + _maxY = maxY; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonBounds.h b/native/cocos/editor-support/spine/4.2/spine/SkeletonBounds.h new file mode 100644 index 0000000000..be1aa79781 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonBounds.h @@ -0,0 +1,121 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_SkeletonBounds_h +#define Spine_SkeletonBounds_h + +#include +#include +#include + +namespace spine { + class Skeleton; + + class BoundingBoxAttachment; + + class Polygon; + + /// Collects each BoundingBoxAttachment that is visible and computes the world vertices for its polygon. + /// The polygon vertices are provided along with convenience methods for doing hit detection. + class SP_API SkeletonBounds : public SpineObject { + public: + SkeletonBounds(); + + ~SkeletonBounds(); + + /// Clears any previous polygons, finds all visible bounding box attachments, + /// and computes the world vertices for each bounding box's polygon. + /// @param skeleton The skeleton. + /// @param updateAabb + /// If true, the axis aligned bounding box containing all the polygons is computed. + /// If false, the SkeletonBounds AABB methods will always return true. + /// + void update(Skeleton &skeleton, bool updateAabb); + + /// Returns true if the axis aligned bounding box contains the point. + bool aabbcontainsPoint(float x, float y); + + /// Returns true if the axis aligned bounding box intersects the line segment. + bool aabbintersectsSegment(float x1, float y1, float x2, float y2); + + /// Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. + bool aabbIntersectsSkeleton(SkeletonBounds &bounds); + + /// Returns true if the polygon contains the point. + bool containsPoint(Polygon *polygon, float x, float y); + + /// Returns the first bounding box attachment that contains the point, or NULL. When doing many checks, it is usually more + /// efficient to only call this method if {@link #aabbcontainsPoint(float, float)} returns true. + BoundingBoxAttachment *containsPoint(float x, float y); + + /// Returns the first bounding box attachment that contains the line segment, or NULL. When doing many checks, it is usually + /// more efficient to only call this method if {@link #aabbintersectsSegment(float, float, float, float)} returns true. + BoundingBoxAttachment *intersectsSegment(float x1, float y1, float x2, float y2); + + /// Returns true if the polygon contains the line segment. + bool intersectsSegment(Polygon *polygon, float x1, float y1, float x2, float y2); + + /// Returns the polygon for the given bounding box attachment or null if no + /// polygon can be found for the attachment. Requires a call to update() first. + Polygon *getPolygon(BoundingBoxAttachment *attachment); + + /// Returns the bounding box for the given polygon or null. Requires a call to update() first. + BoundingBoxAttachment * getBoundingBox(Polygon *polygon); + + /// Returns all polygons or an empty vector. Requires a call to update() first. + Vector &getPolygons(); + + /// Returns all bounding boxes. Requires a call to update() first. + Vector &getBoundingBoxes(); + + float getWidth(); + + float getHeight(); + + private: + Pool _polygonPool; + Vector _boundingBoxes; + Vector _polygons; + float _minX, _minY, _maxX, _maxY; + + void aabbCompute(); + }; + + class Polygon : public SpineObject { + public: + Vector _vertices; + int _count; + + Polygon() : _count(0) { + _vertices.ensureCapacity(16); + } + }; +} + +#endif /* Spine_SkeletonBounds_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonClipping.cpp b/native/cocos/editor-support/spine/4.2/spine/SkeletonClipping.cpp new file mode 100644 index 0000000000..30b1b9baa6 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonClipping.cpp @@ -0,0 +1,397 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +using namespace spine; + +SkeletonClipping::SkeletonClipping() : _clipAttachment(NULL) { + _clipOutput.ensureCapacity(128); + _clippedVertices.ensureCapacity(128); + _clippedTriangles.ensureCapacity(128); + _clippedUVs.ensureCapacity(128); +} + +size_t SkeletonClipping::clipStart(Slot &slot, ClippingAttachment *clip) { + if (_clipAttachment != NULL) { + return 0; + } + + _clipAttachment = clip; + + int n = (int) clip->getWorldVerticesLength(); + _clippingPolygon.setSize(n, 0); + clip->computeWorldVertices(slot, 0, n, _clippingPolygon, 0, 2); + makeClockwise(_clippingPolygon); + _clippingPolygons = &_triangulator.decompose(_clippingPolygon, _triangulator.triangulate(_clippingPolygon)); + + for (size_t i = 0; i < _clippingPolygons->size(); ++i) { + Vector *polygonP = (*_clippingPolygons)[i]; + Vector &polygon = *polygonP; + makeClockwise(polygon); + polygon.add(polygon[0]); + polygon.add(polygon[1]); + } + + return (*_clippingPolygons).size(); +} + +void SkeletonClipping::clipEnd(Slot &slot) { + if (_clipAttachment != NULL && _clipAttachment->_endSlot == &slot._data) { + clipEnd(); + } +} + +void SkeletonClipping::clipEnd() { + if (_clipAttachment == NULL) return; + + _clipAttachment = NULL; + _clippingPolygons = NULL; + _clippedVertices.clear(); + _clippedUVs.clear(); + _clippedTriangles.clear(); + _clippingPolygon.clear(); +} + +void SkeletonClipping::clipTriangles(float *vertices, unsigned short *triangles, + size_t trianglesLength) { + Vector &clipOutput = _clipOutput; + Vector &clippedVertices = _clippedVertices; + Vector &clippedTriangles = _clippedTriangles; + Vector *> &polygons = *_clippingPolygons; + size_t polygonsCount = (*_clippingPolygons).size(); + + size_t index = 0; + clippedVertices.clear(); + _clippedUVs.clear(); + clippedTriangles.clear(); + + int stride = 2; + size_t i = 0; +continue_outer: + for (; i < trianglesLength; i += 3) { + int vertexOffset = triangles[i] * stride; + float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1]; + + vertexOffset = triangles[i + 1] * stride; + float x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1]; + + vertexOffset = triangles[i + 2] * stride; + float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1]; + + for (size_t p = 0; p < polygonsCount; p++) { + size_t s = clippedVertices.size(); + if (clip(x1, y1, x2, y2, x3, y3, &(*polygons[p]), &clipOutput)) { + size_t clipOutputLength = clipOutput.size(); + if (clipOutputLength == 0) continue; + + size_t clipOutputCount = clipOutputLength >> 1; + clippedVertices.setSize(s + clipOutputCount * 2, 0); + for (size_t ii = 0; ii < clipOutputLength; ii += 2) { + float x = clipOutput[ii], y = clipOutput[ii + 1]; + clippedVertices[s] = x; + clippedVertices[s + 1] = y; + s += 2; + } + + s = clippedTriangles.size(); + clippedTriangles.setSize(s + 3 * (clipOutputCount - 2), 0); + clipOutputCount--; + for (size_t ii = 1; ii < clipOutputCount; ii++) { + clippedTriangles[s] = (unsigned short) (index); + clippedTriangles[s + 1] = (unsigned short) (index + ii); + clippedTriangles[s + 2] = (unsigned short) (index + ii + 1); + s += 3; + } + index += clipOutputCount + 1; + } else { + clippedVertices.setSize(s + 3 * 2, 0); + clippedVertices[s] = x1; + clippedVertices[s + 1] = y1; + clippedVertices[s + 2] = x2; + clippedVertices[s + 3] = y2; + clippedVertices[s + 4] = x3; + clippedVertices[s + 5] = y3; + + s = clippedTriangles.size(); + clippedTriangles.setSize(s + 3, 0); + clippedTriangles[s] = (unsigned short) index; + clippedTriangles[s + 1] = (unsigned short) (index + 1); + clippedTriangles[s + 2] = (unsigned short) (index + 2); + index += 3; + i += 3; + goto continue_outer; + } + } + } +} + +void SkeletonClipping::clipTriangles(Vector &vertices, Vector &triangles, Vector &uvs, + size_t stride) { + clipTriangles(vertices.buffer(), triangles.buffer(), triangles.size(), uvs.buffer(), stride); +} + +void SkeletonClipping::clipTriangles(float *vertices, unsigned short *triangles, + size_t trianglesLength, float *uvs, size_t stride) { + Vector &clipOutput = _clipOutput; + Vector &clippedVertices = _clippedVertices; + Vector &clippedTriangles = _clippedTriangles; + Vector *> &polygons = *_clippingPolygons; + size_t polygonsCount = (*_clippingPolygons).size(); + + size_t index = 0; + clippedVertices.clear(); + _clippedUVs.clear(); + clippedTriangles.clear(); + + size_t i = 0; +continue_outer: + for (; i < trianglesLength; i += 3) { + int vertexOffset = triangles[i] * (int) stride; + float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1]; + float u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1]; + + vertexOffset = triangles[i + 1] * (int) stride; + float x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1]; + float u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1]; + + vertexOffset = triangles[i + 2] * (int) stride; + float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1]; + float u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1]; + + for (size_t p = 0; p < polygonsCount; p++) { + size_t s = clippedVertices.size(); + if (clip(x1, y1, x2, y2, x3, y3, &(*polygons[p]), &clipOutput)) { + size_t clipOutputLength = clipOutput.size(); + if (clipOutputLength == 0) continue; + float d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1; + float d = 1 / (d0 * d2 + d1 * (y1 - y3)); + + size_t clipOutputCount = clipOutputLength >> 1; + clippedVertices.setSize(s + clipOutputCount * 2, 0); + _clippedUVs.setSize(s + clipOutputCount * 2, 0); + for (size_t ii = 0; ii < clipOutputLength; ii += 2) { + float x = clipOutput[ii], y = clipOutput[ii + 1]; + clippedVertices[s] = x; + clippedVertices[s + 1] = y; + float c0 = x - x3, c1 = y - y3; + float a = (d0 * c0 + d1 * c1) * d; + float b = (d4 * c0 + d2 * c1) * d; + float c = 1 - a - b; + _clippedUVs[s] = u1 * a + u2 * b + u3 * c; + _clippedUVs[s + 1] = v1 * a + v2 * b + v3 * c; + s += 2; + } + + s = clippedTriangles.size(); + clippedTriangles.setSize(s + 3 * (clipOutputCount - 2), 0); + clipOutputCount--; + for (size_t ii = 1; ii < clipOutputCount; ii++) { + clippedTriangles[s] = (unsigned short) (index); + clippedTriangles[s + 1] = (unsigned short) (index + ii); + clippedTriangles[s + 2] = (unsigned short) (index + ii + 1); + s += 3; + } + index += clipOutputCount + 1; + } else { + clippedVertices.setSize(s + 3 * 2, 0); + _clippedUVs.setSize(s + 3 * 2, 0); + clippedVertices[s] = x1; + clippedVertices[s + 1] = y1; + clippedVertices[s + 2] = x2; + clippedVertices[s + 3] = y2; + clippedVertices[s + 4] = x3; + clippedVertices[s + 5] = y3; + + _clippedUVs[s] = u1; + _clippedUVs[s + 1] = v1; + _clippedUVs[s + 2] = u2; + _clippedUVs[s + 3] = v2; + _clippedUVs[s + 4] = u3; + _clippedUVs[s + 5] = v3; + + s = clippedTriangles.size(); + clippedTriangles.setSize(s + 3, 0); + clippedTriangles[s] = (unsigned short) index; + clippedTriangles[s + 1] = (unsigned short) (index + 1); + clippedTriangles[s + 2] = (unsigned short) (index + 2); + index += 3; + i += 3; + goto continue_outer; + } + } + } +} + +bool SkeletonClipping::isClipping() { + return _clipAttachment != NULL; +} + +Vector &SkeletonClipping::getClippedVertices() { + return _clippedVertices; +} + +Vector &SkeletonClipping::getClippedTriangles() { + return _clippedTriangles; +} + +Vector &SkeletonClipping::getClippedUVs() { + return _clippedUVs; +} + +bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector *clippingArea, + Vector *output) { + Vector *originalOutput = output; + bool clipped = false; + + // Avoid copy at the end. + Vector *input; + if (clippingArea->size() % 4 >= 2) { + input = output; + output = &_scratch; + } else + input = &_scratch; + + input->clear(); + input->add(x1); + input->add(y1); + input->add(x2); + input->add(y2); + input->add(x3); + input->add(y3); + input->add(x1); + input->add(y1); + output->clear(); + + size_t clippingVerticesLast = clippingArea->size() - 4; + Vector &clippingVertices = *clippingArea; + for (size_t i = 0;; i += 2) { + float edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1]; + float ex = edgeX - clippingVertices[i + 2], ey = edgeY - clippingVertices[i + 3]; + + size_t outputStart = output->size(); + Vector &inputVertices = *input; + for (size_t ii = 0, nn = input->size() - 2; ii < nn;) { + float inputX = inputVertices[ii], inputY = inputVertices[ii + 1]; + ii += 2; + float inputX2 = inputVertices[ii], inputY2 = inputVertices[ii + 1]; + float s2 = ey * (edgeX - inputX2) > ex * (edgeY - inputY2); + float s1 = ey * (edgeX - inputX) - ex * (edgeY - inputY); + if (s1 > 0) { + if (s2) {// v1 inside, v2 inside + output->add(inputX2); + output->add(inputY2); + continue; + } + // v1 inside, v2 outside + float ix = inputX2 - inputX, iy = inputY2 - inputY, t = s1 / (ix * ey - iy * ex); + if (t >= 0 && t <= 1) { + output->add(inputX + ix * t); + output->add(inputY + iy * t); + } else { + output->add(inputX2); + output->add(inputY2); + } + } else if (s2) {// v1 outside, v2 inside + float ix = inputX2 - inputX, iy = inputY2 - inputY, t = s1 / (ix * ey - iy * ex); + if (t >= 0 && t <= 1) { + output->add(inputX + ix * t); + output->add(inputY + iy * t); + output->add(inputX2); + output->add(inputY2); + } else { + output->add(inputX2); + output->add(inputY2); + continue; + } + } + clipped = true; + } + + + if (outputStart == output->size()) { + // All edges outside. + originalOutput->clear(); + return true; + } + + output->add((*output)[0]); + output->add((*output)[1]); + + if (i == clippingVerticesLast) { + break; + } + Vector *temp = output; + output = input; + output->clear(); + input = temp; + } + + if (originalOutput != output) { + originalOutput->clear(); + for (size_t i = 0, n = output->size() - 2; i < n; ++i) + originalOutput->add((*output)[i]); + } else + originalOutput->setSize(originalOutput->size() - 2, 0); + + if (originalOutput->size() < 6) { + originalOutput->clear(); + return false; + } + return clipped; +} + +void SkeletonClipping::makeClockwise(Vector &polygon) { + size_t verticeslength = polygon.size(); + + float area = polygon[verticeslength - 2] * polygon[1] - polygon[0] * polygon[verticeslength - 1]; + float p1x, p1y, p2x, p2y; + + for (size_t i = 0, n = verticeslength - 3; i < n; i += 2) { + p1x = polygon[i]; + p1y = polygon[i + 1]; + p2x = polygon[i + 2]; + p2y = polygon[i + 3]; + area += p1x * p2y - p2x * p1y; + } + + if (area < 0) return; + + for (size_t i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) { + float x = polygon[i], y = polygon[i + 1]; + int other = (int) (lastX - i); + polygon[i] = polygon[other]; + polygon[i + 1] = polygon[other + 1]; + polygon[other] = x; + polygon[other + 1] = y; + } +} diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonClipping.h b/native/cocos/editor-support/spine/4.2/spine/SkeletonClipping.h new file mode 100644 index 0000000000..096a677967 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonClipping.h @@ -0,0 +1,88 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_SkeletonClipping_h +#define Spine_SkeletonClipping_h + +#include +#include + +namespace spine { + class Slot; + + class ClippingAttachment; + + class SP_API SkeletonClipping : public SpineObject { + public: + SkeletonClipping(); + + size_t clipStart(Slot &slot, ClippingAttachment *clip); + + void clipEnd(Slot &slot); + + void clipEnd(); + + void + clipTriangles(float *vertices, unsigned short *triangles, size_t trianglesLength); + + void + clipTriangles(float *vertices, unsigned short *triangles, size_t trianglesLength, float *uvs, size_t stride); + + void + clipTriangles(Vector &vertices, Vector &triangles, Vector &uvs, size_t stride); + + bool isClipping(); + + Vector &getClippedVertices(); + + Vector &getClippedTriangles(); + + Vector &getClippedUVs(); + + private: + Triangulator _triangulator; + Vector _clippingPolygon; + Vector _clipOutput; + Vector _clippedVertices; + Vector _clippedTriangles; + Vector _clippedUVs; + Vector _scratch; + ClippingAttachment *_clipAttachment; + Vector *> *_clippingPolygons; + + /** Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping + * area, false is returned. The clipping area must duplicate the first vertex at the end of the vertices list. */ + bool clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector *clippingArea, + Vector *output); + + static void makeClockwise(Vector &polygon); + }; +} + +#endif /* Spine_SkeletonClipping_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonData.cpp b/native/cocos/editor-support/spine/4.2/spine/SkeletonData.cpp new file mode 100644 index 0000000000..6b9f7498ab --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonData.cpp @@ -0,0 +1,244 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace spine; + +SkeletonData::SkeletonData() : _name(), + _defaultSkin(NULL), + _x(0), + _y(0), + _width(0), + _height(0), + _referenceScale(100), + _version(), + _hash(), + _fps(0), + _imagesPath() { +} + +SkeletonData::~SkeletonData() { + ContainerUtil::cleanUpVectorOfPointers(_bones); + ContainerUtil::cleanUpVectorOfPointers(_slots); + ContainerUtil::cleanUpVectorOfPointers(_skins); + + _defaultSkin = NULL; + + ContainerUtil::cleanUpVectorOfPointers(_events); + ContainerUtil::cleanUpVectorOfPointers(_animations); + ContainerUtil::cleanUpVectorOfPointers(_ikConstraints); + ContainerUtil::cleanUpVectorOfPointers(_transformConstraints); + ContainerUtil::cleanUpVectorOfPointers(_pathConstraints); + ContainerUtil::cleanUpVectorOfPointers(_physicsConstraints); + for (size_t i = 0; i < _strings.size(); i++) { + SpineExtension::free(_strings[i], __FILE__, __LINE__); + } +} + +BoneData *SkeletonData::findBone(const String &boneName) { + return ContainerUtil::findWithName(_bones, boneName); +} + +SlotData *SkeletonData::findSlot(const String &slotName) { + return ContainerUtil::findWithName(_slots, slotName); +} + +Skin *SkeletonData::findSkin(const String &skinName) { + return ContainerUtil::findWithName(_skins, skinName); +} + +spine::EventData *SkeletonData::findEvent(const String &eventDataName) { + return ContainerUtil::findWithName(_events, eventDataName); +} + +Animation *SkeletonData::findAnimation(const String &animationName) { + return ContainerUtil::findWithName(_animations, animationName); +} + +IkConstraintData *SkeletonData::findIkConstraint(const String &constraintName) { + return ContainerUtil::findWithName(_ikConstraints, constraintName); +} + +TransformConstraintData *SkeletonData::findTransformConstraint(const String &constraintName) { + return ContainerUtil::findWithName(_transformConstraints, constraintName); +} + +PathConstraintData *SkeletonData::findPathConstraint(const String &constraintName) { + return ContainerUtil::findWithName(_pathConstraints, constraintName); +} + +PhysicsConstraintData *SkeletonData::findPhysicsConstraint(const String &constraintName) { + return ContainerUtil::findWithName(_physicsConstraints, constraintName); +} + +const String &SkeletonData::getName() { + return _name; +} + +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; +} + +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; +} + +Vector &SkeletonData::getPhysicsConstraints() { + return _physicsConstraints; +} + +float SkeletonData::getX() { + return _x; +} + +void SkeletonData::setX(float inValue) { + _x = inValue; +} + +float SkeletonData::getY() { + return _y; +} + +void SkeletonData::setY(float inValue) { + _y = inValue; +} + +float SkeletonData::getWidth() { + return _width; +} + +void SkeletonData::setWidth(float inValue) { + _width = inValue; +} + +float SkeletonData::getHeight() { + return _height; +} + +void SkeletonData::setHeight(float inValue) { + _height = inValue; +} + +float SkeletonData::getReferenceScale() { + return _referenceScale; +} + +void SkeletonData::setReferenceScale(float inValue) { + _referenceScale = inValue; +} + +const String &SkeletonData::getVersion() { + return _version; +} + +void SkeletonData::setVersion(const String &inValue) { + _version = inValue; +} + +const String &SkeletonData::getHash() { + return _hash; +} + +void SkeletonData::setHash(const String &inValue) { + _hash = inValue; +} + +const String &SkeletonData::getImagesPath() { + return _imagesPath; +} + +void SkeletonData::setImagesPath(const String &inValue) { + _imagesPath = inValue; +} + + +const String &SkeletonData::getAudioPath() { + return _audioPath; +} + +void SkeletonData::setAudioPath(const String &inValue) { + _audioPath = inValue; +} + +float SkeletonData::getFps() { + return _fps; +} + +void SkeletonData::setFps(float inValue) { + _fps = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonData.h b/native/cocos/editor-support/spine/4.2/spine/SkeletonData.h new file mode 100644 index 0000000000..a1ae815548 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonData.h @@ -0,0 +1,196 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_SkeletonData_h +#define Spine_SkeletonData_h + +#include +#include + +namespace spine { + class BoneData; + + class SlotData; + + class Skin; + + class EventData; + + class Animation; + + class IkConstraintData; + + class TransformConstraintData; + + class PathConstraintData; + + class PhysicsConstraintData; + +/// Stores the setup pose and all of the stateless data for a skeleton. + class SP_API SkeletonData : public SpineObject { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class Skeleton; + + public: + SkeletonData(); + + ~SkeletonData(); + + /// Finds a bone by comparing each bone's name. + /// It is more efficient to cache the results of this method than to call it multiple times. + /// @return May be NULL. + BoneData *findBone(const String &boneName); + + /// @return May be NULL. + SlotData *findSlot(const String &slotName); + + /// @return May be NULL. + Skin *findSkin(const String &skinName); + + /// @return May be NULL. + spine::EventData *findEvent(const String &eventDataName); + + /// @return May be NULL. + Animation *findAnimation(const String &animationName); + + /// @return May be NULL. + IkConstraintData *findIkConstraint(const String &constraintName); + + /// @return May be NULL. + TransformConstraintData *findTransformConstraint(const String &constraintName); + + /// @return May be NULL. + PathConstraintData *findPathConstraint(const String &constraintName); + + /// @return May be NULL. + PhysicsConstraintData *findPhysicsConstraint(const String &constraintName); + + const String &getName(); + + void setName(const String &inValue); + + /// The skeleton's bones, sorted parent first. The root bone is always the first bone. + Vector &getBones(); + + Vector &getSlots(); + + /// All skins, including the default skin. + Vector &getSkins(); + + /// The skeleton's default skin. + /// By default this skin contains all attachments that were not in a skin in Spine. + /// @return May be NULL. + Skin *getDefaultSkin(); + + void setDefaultSkin(Skin *inValue); + + Vector &getEvents(); + + Vector &getAnimations(); + + Vector &getIkConstraints(); + + Vector &getTransformConstraints(); + + Vector &getPathConstraints(); + + Vector &getPhysicsConstraints(); + + float getX(); + + void setX(float inValue); + + float getY(); + + void setY(float inValue); + + float getWidth(); + + void setWidth(float inValue); + + float getHeight(); + + void setHeight(float inValue); + + float getReferenceScale(); + + void setReferenceScale(float inValue); + + /// The Spine version used to export this data, or NULL. + const String &getVersion(); + + void setVersion(const String &inValue); + + const String &getHash(); + + void setHash(const String &inValue); + + const String &getImagesPath(); + + void setImagesPath(const String &inValue); + + const String &getAudioPath(); + + void setAudioPath(const String &inValue); + + /// The dopesheet FPS in Spine. Available only when nonessential data was exported. + float getFps(); + + void setFps(float inValue); + #ifndef __EMSCRIPTEN__ + private: + #endif + String _name; + Vector _bones; // Ordered parents first + Vector _slots; // Setup pose draw order. + Vector _skins; + Skin *_defaultSkin; + Vector _events; + Vector _animations; + Vector _ikConstraints; + Vector _transformConstraints; + Vector _pathConstraints; + Vector _physicsConstraints; + float _x, _y, _width, _height; + float _referenceScale; + String _version; + String _hash; + Vector _strings; + + // Nonessential. + float _fps; + String _imagesPath; + String _audioPath; + }; +} + +#endif /* Spine_SkeletonData_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonJson.cpp b/native/cocos/editor-support/spine/4.2/spine/SkeletonJson.cpp new file mode 100644 index 0000000000..8ae68f1522 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonJson.cpp @@ -0,0 +1,1617 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace spine; + +static float toColor(const char *value, size_t index) { + char digits[3]; + char *error; + int color; + + if (index >= strlen(value) / 2) return -1; + + value += index * 2; + + digits[0] = *value; + digits[1] = *(value + 1); + digits[2] = '\0'; + color = (int) strtoul(digits, &error, 16); + if (*error != 0) return -1; + + return color / (float) 255; +} + +static void toColor(Color &color, const char *value, bool hasAlpha) { + color.r = toColor(value, 0); + color.g = toColor(value, 1); + color.b = toColor(value, 2); + if (hasAlpha) color.a = toColor(value, 3); +} + +SkeletonJson::SkeletonJson(Atlas *atlas) : _attachmentLoader(new (__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), + _scale(1), _ownsLoader(true) {} + +SkeletonJson::SkeletonJson(AttachmentLoader *attachmentLoader, bool ownsLoader) : _attachmentLoader(attachmentLoader), + _scale(1), + _ownsLoader(ownsLoader) { + assert(_attachmentLoader != NULL); +} + +SkeletonJson::~SkeletonJson() { + ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes); + + if (_ownsLoader) delete _attachmentLoader; +} + +SkeletonData *SkeletonJson::readSkeletonDataFile(const String &path) { + int length; + SkeletonData *skeletonData; + const char *json = SpineExtension::readFile(path, &length); + if (length == 0 || !json) { + setError(NULL, "Unable to read skeleton file: ", path); + return NULL; + } + + skeletonData = readSkeletonData(json); + + SpineExtension::free(json, __FILE__, __LINE__); + + return skeletonData; +} + +SkeletonData *SkeletonJson::readSkeletonData(const char *json) { + int i, ii; + SkeletonData *skeletonData; + Json *root, *skeleton, *bones, *boneMap, *ik, *transform, *path, *physics, *slots, *skins, *animations, *events; + + _error = ""; + _linkedMeshes.clear(); + + root = new (__FILE__, __LINE__) Json(json); + + if (!root) { + setError(NULL, "Invalid skeleton JSON: ", Json::getError()); + return NULL; + } + + skeletonData = new (__FILE__, __LINE__) SkeletonData(); + + skeleton = Json::getItem(root, "skeleton"); + if (skeleton) { + skeletonData->_hash = Json::getString(skeleton, "hash", 0); + skeletonData->_version = Json::getString(skeleton, "spine", 0); + if (!skeletonData->_version.startsWith(SPINE_VERSION_STRING)) { + char errorMsg[255]; + snprintf(errorMsg, 255, "Skeleton version %s does not match runtime version %s", skeletonData->_version.buffer(), SPINE_VERSION_STRING); + delete skeletonData; + setError(NULL, errorMsg, ""); + return NULL; + } + skeletonData->_x = Json::getFloat(skeleton, "x", 0); + skeletonData->_y = Json::getFloat(skeleton, "y", 0); + skeletonData->_width = Json::getFloat(skeleton, "width", 0); + skeletonData->_height = Json::getFloat(skeleton, "height", 0); + skeletonData->_referenceScale = Json::getFloat(skeleton, "referenceScale", 100) * _scale; + skeletonData->_fps = Json::getFloat(skeleton, "fps", 30); + skeletonData->_audioPath = Json::getString(skeleton, "audio", 0); + skeletonData->_imagesPath = Json::getString(skeleton, "images", 0); + } + + /* Bones. */ + bones = Json::getItem(root, "bones"); + skeletonData->_bones.setSize(bones->_size, 0); + int bonesCount = 0; + for (boneMap = bones->_child, i = 0; boneMap; boneMap = boneMap->_next, ++i) { + BoneData *data; + const char *inherit; + + BoneData *parent = 0; + const char *parentName = Json::getString(boneMap, "parent", 0); + if (parentName) { + parent = skeletonData->findBone(parentName); + if (!parent) { + delete skeletonData; + setError(root, "Parent bone not found: ", parentName); + return NULL; + } + } + + data = new (__FILE__, __LINE__) BoneData(bonesCount, Json::getString(boneMap, "name", 0), parent); + + data->_length = Json::getFloat(boneMap, "length", 0) * _scale; + data->_x = Json::getFloat(boneMap, "x", 0) * _scale; + data->_y = Json::getFloat(boneMap, "y", 0) * _scale; + data->_rotation = Json::getFloat(boneMap, "rotation", 0); + data->_scaleX = Json::getFloat(boneMap, "scaleX", 1); + data->_scaleY = Json::getFloat(boneMap, "scaleY", 1); + data->_shearX = Json::getFloat(boneMap, "shearX", 0); + data->_shearY = Json::getFloat(boneMap, "shearY", 0); + inherit = Json::getString(boneMap, "inherit", "normal"); + data->_inherit = Inherit_Normal; + if (strcmp(inherit, "normal") == 0) data->_inherit = Inherit_Normal; + else if (strcmp(inherit, "onlyTranslation") == 0) + data->_inherit = Inherit_OnlyTranslation; + else if (strcmp(inherit, "noRotationOrReflection") == 0) + data->_inherit = Inherit_NoRotationOrReflection; + else if (strcmp(inherit, "noScale") == 0) + data->_inherit = Inherit_NoScale; + else if (strcmp(inherit, "noScaleOrReflection") == 0) + data->_inherit = Inherit_NoScaleOrReflection; + data->_skinRequired = Json::getBoolean(boneMap, "skin", false); + + const char *color = Json::getString(boneMap, "color", NULL); + if (color) toColor(data->getColor(), color, true); + + data->_icon = Json::getString(boneMap, "icon", ""); + data->_visible = Json::getBoolean(boneMap, "visible", true); + + skeletonData->_bones[i] = data; + bonesCount++; + } + + /* Slots. */ + slots = Json::getItem(root, "slots"); + if (slots) { + Json *slotMap; + skeletonData->_slots.ensureCapacity(slots->_size); + skeletonData->_slots.setSize(slots->_size, 0); + for (slotMap = slots->_child, i = 0; slotMap; slotMap = slotMap->_next, ++i) { + SlotData *data; + const char *color; + const char *dark; + Json *item; + + const char *boneName = Json::getString(slotMap, "bone", 0); + BoneData *boneData = skeletonData->findBone(boneName); + if (!boneData) { + delete skeletonData; + setError(root, "Slot bone not found: ", boneName); + return NULL; + } + + String slotName = String(Json::getString(slotMap, "name", 0)); + data = new (__FILE__, __LINE__) SlotData(i, slotName, *boneData); + + color = Json::getString(slotMap, "color", 0); + if (color) { + Color &c = data->getColor(); + c.r = toColor(color, 0); + c.g = toColor(color, 1); + c.b = toColor(color, 2); + c.a = toColor(color, 3); + } + + dark = Json::getString(slotMap, "dark", 0); + if (dark) { + Color &darkColor = data->getDarkColor(); + darkColor.r = toColor(dark, 0); + darkColor.g = toColor(dark, 1); + darkColor.b = toColor(dark, 2); + darkColor.a = 1; + data->setHasDarkColor(true); + } + + item = Json::getItem(slotMap, "attachment"); + if (item) data->setAttachmentName(item->_valueString); + + item = Json::getItem(slotMap, "blend"); + if (item) { + if (strcmp(item->_valueString, "additive") == 0) data->_blendMode = BlendMode_Additive; + else if (strcmp(item->_valueString, "multiply") == 0) + data->_blendMode = BlendMode_Multiply; + else if (strcmp(item->_valueString, "screen") == 0) + data->_blendMode = BlendMode_Screen; + } + data->_visible = Json::getBoolean(slotMap, "visible", true); + skeletonData->_slots[i] = data; + } + } + + /* IK constraints. */ + ik = Json::getItem(root, "ik"); + if (ik) { + Json *constraintMap; + skeletonData->_ikConstraints.ensureCapacity(ik->_size); + skeletonData->_ikConstraints.setSize(ik->_size, 0); + 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)); + data->setOrder(Json::getInt(constraintMap, "order", 0)); + data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); + + boneMap = Json::getItem(constraintMap, "bones"); + data->_bones.ensureCapacity(boneMap->_size); + data->_bones.setSize(boneMap->_size, 0); + for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii) { + data->_bones[ii] = skeletonData->findBone(boneMap->_valueString); + if (!data->_bones[ii]) { + delete skeletonData; + setError(root, "IK bone not found: ", boneMap->_valueString); + return NULL; + } + } + + targetName = Json::getString(constraintMap, "target", 0); + data->_target = skeletonData->findBone(targetName); + if (!data->_target) { + delete skeletonData; + setError(root, "Target bone not found: ", targetName); + return NULL; + } + + data->_mix = Json::getFloat(constraintMap, "mix", 1); + data->_softness = Json::getFloat(constraintMap, "softness", 0) * _scale; + data->_bendDirection = Json::getInt(constraintMap, "bendPositive", 1) ? 1 : -1; + data->_compress = Json::getInt(constraintMap, "compress", 0) ? true : false; + data->_stretch = Json::getInt(constraintMap, "stretch", 0) ? true : false; + data->_uniform = Json::getInt(constraintMap, "uniform", 0) ? true : false; + + skeletonData->_ikConstraints[i] = data; + } + } + + /* Transform constraints. */ + transform = Json::getItem(root, "transform"); + if (transform) { + Json *constraintMap; + skeletonData->_transformConstraints.ensureCapacity(transform->_size); + skeletonData->_transformConstraints.setSize(transform->_size, 0); + 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)); + data->setOrder(Json::getInt(constraintMap, "order", 0)); + data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); + + boneMap = Json::getItem(constraintMap, "bones"); + data->_bones.ensureCapacity(boneMap->_size); + data->_bones.setSize(boneMap->_size, 0); + for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii) { + data->_bones[ii] = skeletonData->findBone(boneMap->_valueString); + if (!data->_bones[ii]) { + delete skeletonData; + setError(root, "Transform bone not found: ", boneMap->_valueString); + return NULL; + } + } + + name = Json::getString(constraintMap, "target", 0); + data->_target = skeletonData->findBone(name); + if (!data->_target) { + delete skeletonData; + setError(root, "Target bone not found: ", name); + return NULL; + } + + data->_local = Json::getInt(constraintMap, "local", 0) ? true : false; + data->_relative = Json::getInt(constraintMap, "relative", 0) ? true : false; + data->_offsetRotation = Json::getFloat(constraintMap, "rotation", 0); + data->_offsetX = Json::getFloat(constraintMap, "x", 0) * _scale; + data->_offsetY = Json::getFloat(constraintMap, "y", 0) * _scale; + data->_offsetScaleX = Json::getFloat(constraintMap, "scaleX", 0); + data->_offsetScaleY = Json::getFloat(constraintMap, "scaleY", 0); + data->_offsetShearY = Json::getFloat(constraintMap, "shearY", 0); + + data->_mixRotate = Json::getFloat(constraintMap, "mixRotate", 1); + data->_mixX = Json::getFloat(constraintMap, "mixX", 1); + data->_mixY = Json::getFloat(constraintMap, "mixY", data->_mixX); + data->_mixScaleX = Json::getFloat(constraintMap, "mixScaleX", 1); + data->_mixScaleY = Json::getFloat(constraintMap, "mixScaleY", data->_mixScaleX); + data->_mixShearY = Json::getFloat(constraintMap, "mixShearY", 1); + + skeletonData->_transformConstraints[i] = data; + } + } + + /* Path constraints */ + path = Json::getItem(root, "path"); + if (path) { + Json *constraintMap; + skeletonData->_pathConstraints.ensureCapacity(path->_size); + skeletonData->_pathConstraints.setSize(path->_size, 0); + for (constraintMap = path->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { + const char *name; + const char *item; + + PathConstraintData *data = new (__FILE__, __LINE__) PathConstraintData( + Json::getString(constraintMap, "name", 0)); + data->setOrder(Json::getInt(constraintMap, "order", 0)); + data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); + + boneMap = Json::getItem(constraintMap, "bones"); + data->_bones.ensureCapacity(boneMap->_size); + data->_bones.setSize(boneMap->_size, 0); + for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii) { + data->_bones[ii] = skeletonData->findBone(boneMap->_valueString); + if (!data->_bones[ii]) { + delete skeletonData; + setError(root, "Path bone not found: ", boneMap->_valueString); + return NULL; + } + } + + name = Json::getString(constraintMap, "target", 0); + data->_target = skeletonData->findSlot(name); + if (!data->_target) { + delete skeletonData; + setError(root, "Target slot not found: ", name); + return NULL; + } + + item = Json::getString(constraintMap, "positionMode", "percent"); + if (strcmp(item, "fixed") == 0) { + data->_positionMode = PositionMode_Fixed; + } else if (strcmp(item, "percent") == 0) { + data->_positionMode = PositionMode_Percent; + } + + item = Json::getString(constraintMap, "spacingMode", "length"); + if (strcmp(item, "length") == 0) data->_spacingMode = SpacingMode_Length; + else if (strcmp(item, "fixed") == 0) + data->_spacingMode = SpacingMode_Fixed; + else if (strcmp(item, "percent") == 0) + data->_spacingMode = SpacingMode_Percent; + else + data->_spacingMode = SpacingMode_Proportional; + + item = Json::getString(constraintMap, "rotateMode", "tangent"); + if (strcmp(item, "tangent") == 0) data->_rotateMode = RotateMode_Tangent; + else if (strcmp(item, "chain") == 0) + data->_rotateMode = RotateMode_Chain; + else if (strcmp(item, "chainScale") == 0) + data->_rotateMode = RotateMode_ChainScale; + + data->_offsetRotation = Json::getFloat(constraintMap, "rotation", 0); + data->_position = Json::getFloat(constraintMap, "position", 0); + if (data->_positionMode == PositionMode_Fixed) data->_position *= _scale; + data->_spacing = Json::getFloat(constraintMap, "spacing", 0); + if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) + data->_spacing *= _scale; + data->_mixRotate = Json::getFloat(constraintMap, "mixRotate", 1); + data->_mixX = Json::getFloat(constraintMap, "mixX", 1); + data->_mixY = Json::getFloat(constraintMap, "mixY", data->_mixX); + + skeletonData->_pathConstraints[i] = data; + } + } + + /* Physics constraints */ + physics = Json::getItem(root, "physics"); + if (physics) { + Json *constraintMap; + skeletonData->_physicsConstraints.ensureCapacity(physics->_size); + skeletonData->_physicsConstraints.setSize(physics->_size, 0); + for (constraintMap = physics->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { + const char *name; + + PhysicsConstraintData *data = new (__FILE__, __LINE__) PhysicsConstraintData( + Json::getString(constraintMap, "name", 0)); + data->setOrder(Json::getInt(constraintMap, "order", 0)); + data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); + + name = Json::getString(constraintMap, "bone", 0); + data->_bone = skeletonData->findBone(name); + if (!data->_bone) { + delete skeletonData; + setError(root, "Physics bone not found: ", name); + return NULL; + } + + data->_x = Json::getFloat(constraintMap, "x", 0); + data->_y = Json::getFloat(constraintMap, "y", 0); + data->_rotate = Json::getFloat(constraintMap, "rotate", 0); + data->_scaleX = Json::getFloat(constraintMap, "scaleX", 0); + data->_shearX = Json::getFloat(constraintMap, "shearX", 0); + data->_limit = Json::getFloat(constraintMap, "limit", 5000) * _scale; + data->_step = 1.0f / Json::getInt(constraintMap, "fps", 60); + data->_inertia = Json::getFloat(constraintMap, "inertia", 1); + data->_strength = Json::getFloat(constraintMap, "strength", 100); + data->_damping = Json::getFloat(constraintMap, "damping", 1); + data->_massInverse = 1.0f / Json::getFloat(constraintMap, "mass", 1); + data->_wind = Json::getFloat(constraintMap, "wind", 0); + data->_gravity = Json::getFloat(constraintMap, "gravity", 0); + data->_mix = Json::getFloat(constraintMap, "mix", 1); + data->_inertiaGlobal = Json::getBoolean(constraintMap, "inertiaGlobal", false); + data->_strengthGlobal = Json::getBoolean(constraintMap, "strengthGlobal", false); + data->_dampingGlobal = Json::getBoolean(constraintMap, "dampingGlobal", false); + data->_massGlobal = Json::getBoolean(constraintMap, "massGlobal", false); + data->_windGlobal = Json::getBoolean(constraintMap, "windGlobal", false); + data->_gravityGlobal = Json::getBoolean(constraintMap, "gravityGlobal", false); + data->_mixGlobal = Json::getBoolean(constraintMap, "mixGlobal", false); + + skeletonData->_physicsConstraints[i] = data; + } + } + + /* Skins. */ + skins = Json::getItem(root, "skins"); + if (skins) { + Json *skinMap; + skeletonData->_skins.ensureCapacity(skins->_size); + skeletonData->_skins.setSize(skins->_size, 0); + int skinsIndex = 0; + for (skinMap = skins->_child, i = 0; skinMap; skinMap = skinMap->_next, ++i) { + Json *attachmentsMap; + Json *curves; + + Skin *skin = new (__FILE__, __LINE__) Skin(Json::getString(skinMap, "name", "")); + + Json *item = Json::getItem(skinMap, "bones"); + if (item) { + for (item = item->_child; item; item = item->_next) { + BoneData *data = skeletonData->findBone(item->_valueString); + if (!data) { + delete skeletonData; + setError(root, String("Skin bone not found: "), item->_valueString); + return NULL; + } + skin->getBones().add(data); + } + } + + item = Json::getItem(skinMap, "ik"); + if (item) { + for (item = item->_child; item; item = item->_next) { + IkConstraintData *data = skeletonData->findIkConstraint(item->_valueString); + if (!data) { + delete skeletonData; + setError(root, String("Skin IK constraint not found: "), item->_valueString); + return NULL; + } + skin->getConstraints().add(data); + } + } + + item = Json::getItem(skinMap, "transform"); + if (item) { + for (item = item->_child; item; item = item->_next) { + TransformConstraintData *data = skeletonData->findTransformConstraint(item->_valueString); + if (!data) { + delete skeletonData; + setError(root, String("Skin transform constraint not found: "), item->_valueString); + return NULL; + } + skin->getConstraints().add(data); + } + } + + item = Json::getItem(skinMap, "path"); + if (item) { + for (item = item->_child; item; item = item->_next) { + PathConstraintData *data = skeletonData->findPathConstraint(item->_valueString); + if (!data) { + delete skeletonData; + setError(root, String("Skin path constraint not found: "), item->_valueString); + return NULL; + } + skin->getConstraints().add(data); + } + } + + item = Json::getItem(skinMap, "physics"); + if (item) { + for (item = item->_child; item; item = item->_next) { + PhysicsConstraintData *data = skeletonData->findPhysicsConstraint(item->_valueString); + if (!data) { + delete skeletonData; + setError(root, String("Skin physics constraint not found: "), item->_valueString); + return NULL; + } + skin->getConstraints().add(data); + } + } + + skeletonData->_skins[skinsIndex++] = skin; + if (strcmp(Json::getString(skinMap, "name", ""), "default") == 0) { + skeletonData->_defaultSkin = skin; + } + + Json *attachments = Json::getItem(skinMap, "attachments"); + if (attachments) + for (attachmentsMap = attachments->_child; + attachmentsMap; attachmentsMap = attachmentsMap->_next) { + SlotData *slot = skeletonData->findSlot(attachmentsMap->_name); + Json *attachmentMap; + + for (attachmentMap = attachmentsMap->_child; attachmentMap; attachmentMap = attachmentMap->_next) { + Attachment *attachment = NULL; + const char *skinAttachmentName = attachmentMap->_name; + const char *attachmentName = Json::getString(attachmentMap, "name", skinAttachmentName); + const char *attachmentPath = Json::getString(attachmentMap, "path", attachmentName); + const char *color; + Json *entry; + + const char *typeString = Json::getString(attachmentMap, "type", "region"); + AttachmentType type; + if (strcmp(typeString, "region") == 0) type = AttachmentType_Region; + else if (strcmp(typeString, "mesh") == 0) + type = AttachmentType_Mesh; + else if (strcmp(typeString, "linkedmesh") == 0) + type = AttachmentType_Linkedmesh; + else if (strcmp(typeString, "boundingbox") == 0) + type = AttachmentType_Boundingbox; + else if (strcmp(typeString, "path") == 0) + type = AttachmentType_Path; + else if (strcmp(typeString, "clipping") == 0) + type = AttachmentType_Clipping; + else if (strcmp(typeString, "point") == 0) + type = AttachmentType_Point; + else { + delete skeletonData; + setError(root, "Unknown attachment type: ", typeString); + return NULL; + } + + switch (type) { + case AttachmentType_Region: { + Sequence *sequence = readSequence(Json::getItem(attachmentMap, "sequence")); + attachment = _attachmentLoader->newRegionAttachment(*skin, attachmentName, attachmentPath, sequence); + if (!attachment) { + delete skeletonData; + setError(root, "Error reading attachment: ", skinAttachmentName); + return NULL; + } + + RegionAttachment *region = static_cast(attachment); + region->_path = attachmentPath; + + region->_x = Json::getFloat(attachmentMap, "x", 0) * _scale; + region->_y = Json::getFloat(attachmentMap, "y", 0) * _scale; + region->_scaleX = Json::getFloat(attachmentMap, "scaleX", 1); + region->_scaleY = Json::getFloat(attachmentMap, "scaleY", 1); + region->_rotation = Json::getFloat(attachmentMap, "rotation", 0); + region->_width = Json::getFloat(attachmentMap, "width", 32) * _scale; + region->_height = Json::getFloat(attachmentMap, "height", 32) * _scale; + region->_sequence = sequence; + + color = Json::getString(attachmentMap, "color", 0); + if (color) toColor(region->getColor(), color, true); + + if (region->_region != NULL) region->updateRegion(); + _attachmentLoader->configureAttachment(region); + break; + } + case AttachmentType_Mesh: + case AttachmentType_Linkedmesh: { + Sequence *sequence = readSequence(Json::getItem(attachmentMap, "sequence")); + attachment = _attachmentLoader->newMeshAttachment(*skin, attachmentName, attachmentPath, sequence); + + if (!attachment) { + delete skeletonData; + setError(root, "Error reading attachment: ", skinAttachmentName); + return NULL; + } + + MeshAttachment *mesh = static_cast(attachment); + mesh->_path = attachmentPath; + + color = Json::getString(attachmentMap, "color", 0); + if (color) toColor(mesh->getColor(), color, true); + + mesh->_width = Json::getFloat(attachmentMap, "width", 32) * _scale; + mesh->_height = Json::getFloat(attachmentMap, "height", 32) * _scale; + mesh->_sequence = sequence; + + entry = Json::getItem(attachmentMap, "parent"); + if (!entry) { + int verticesLength; + entry = Json::getItem(attachmentMap, "triangles"); + mesh->_triangles.ensureCapacity(entry->_size); + mesh->_triangles.setSize(entry->_size, 0); + for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) + mesh->_triangles[ii] = (unsigned short) entry->_valueInt; + + entry = Json::getItem(attachmentMap, "uvs"); + verticesLength = entry->_size; + mesh->_regionUVs.ensureCapacity(verticesLength); + mesh->_regionUVs.setSize(verticesLength, 0); + for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) + mesh->_regionUVs[ii] = entry->_valueFloat; + + readVertices(attachmentMap, mesh, verticesLength); + + if (mesh->_region != NULL) mesh->updateRegion(); + + mesh->_hullLength = Json::getInt(attachmentMap, "hull", 0); + + entry = Json::getItem(attachmentMap, "edges"); + if (entry) { + mesh->_edges.ensureCapacity(entry->_size); + mesh->_edges.setSize(entry->_size, 0); + for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) + mesh->_edges[ii] = entry->_valueInt; + } + _attachmentLoader->configureAttachment(mesh); + } else { + bool inheritTimelines = Json::getInt(attachmentMap, "timelines", 1) ? true : false; + LinkedMesh *linkedMesh = new (__FILE__, __LINE__) LinkedMesh(mesh, + String(Json::getString( + attachmentMap, + "skin", 0)), + slot->getIndex(), + String(entry->_valueString), + inheritTimelines); + _linkedMeshes.add(linkedMesh); + } + break; + } + case AttachmentType_Boundingbox: { + attachment = _attachmentLoader->newBoundingBoxAttachment(*skin, attachmentName); + + BoundingBoxAttachment *box = static_cast(attachment); + + int vertexCount = Json::getInt(attachmentMap, "vertexCount", 0) << 1; + readVertices(attachmentMap, box, vertexCount); + color = Json::getString(attachmentMap, "color", NULL); + if (color) toColor(box->getColor(), color, true); + _attachmentLoader->configureAttachment(attachment); + break; + } + case AttachmentType_Path: { + attachment = _attachmentLoader->newPathAttachment(*skin, attachmentName); + + PathAttachment *pathAttatchment = static_cast(attachment); + + int vertexCount = 0; + pathAttatchment->_closed = Json::getInt(attachmentMap, "closed", 0) ? true : false; + pathAttatchment->_constantSpeed = Json::getInt(attachmentMap, "constantSpeed", 1) ? true + : false; + vertexCount = Json::getInt(attachmentMap, "vertexCount", 0); + readVertices(attachmentMap, pathAttatchment, vertexCount << 1); + + pathAttatchment->_lengths.ensureCapacity(vertexCount / 3); + pathAttatchment->_lengths.setSize(vertexCount / 3, 0); + + curves = Json::getItem(attachmentMap, "lengths"); + for (curves = curves->_child, ii = 0; curves; curves = curves->_next, ++ii) + pathAttatchment->_lengths[ii] = curves->_valueFloat * _scale; + color = Json::getString(attachmentMap, "color", NULL); + if (color) toColor(pathAttatchment->getColor(), color, true); + _attachmentLoader->configureAttachment(attachment); + break; + } + case AttachmentType_Point: { + attachment = _attachmentLoader->newPointAttachment(*skin, attachmentName); + + PointAttachment *point = static_cast(attachment); + + point->_x = Json::getFloat(attachmentMap, "x", 0) * _scale; + point->_y = Json::getFloat(attachmentMap, "y", 0) * _scale; + point->_rotation = Json::getFloat(attachmentMap, "rotation", 0); + color = Json::getString(attachmentMap, "color", NULL); + if (color) toColor(point->getColor(), color, true); + _attachmentLoader->configureAttachment(attachment); + break; + } + case AttachmentType_Clipping: { + attachment = _attachmentLoader->newClippingAttachment(*skin, attachmentName); + + ClippingAttachment *clip = static_cast(attachment); + + int vertexCount = 0; + const char *end = Json::getString(attachmentMap, "end", 0); + if (end) clip->_endSlot = skeletonData->findSlot(end); + vertexCount = Json::getInt(attachmentMap, "vertexCount", 0) << 1; + readVertices(attachmentMap, clip, vertexCount); + color = Json::getString(attachmentMap, "color", NULL); + if (color) toColor(clip->getColor(), color, true); + _attachmentLoader->configureAttachment(attachment); + break; + } + } + + skin->setAttachment(slot->getIndex(), skinAttachmentName, attachment); + } + } + } + } + + /* Linked meshes. */ + int n = (int) _linkedMeshes.size(); + for (i = 0; i < n; ++i) { + LinkedMesh *linkedMesh = _linkedMeshes[i]; + Skin *skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin(linkedMesh->_skin); + if (skin == NULL) { + delete skeletonData; + setError(root, "Skin not found: ", linkedMesh->_skin.buffer()); + return NULL; + } + Attachment *parent = skin->getAttachment(linkedMesh->_slotIndex, linkedMesh->_parent); + if (parent == NULL) { + delete skeletonData; + setError(root, "Parent mesh not found: ", linkedMesh->_parent.buffer()); + return NULL; + } + linkedMesh->_mesh->_timelineAttachment = linkedMesh->_inheritTimeline ? static_cast(parent) + : linkedMesh->_mesh; + linkedMesh->_mesh->setParentMesh(static_cast(parent)); + if (linkedMesh->_mesh->_region != NULL) linkedMesh->_mesh->updateRegion(); + _attachmentLoader->configureAttachment(linkedMesh->_mesh); + } + ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes); + _linkedMeshes.clear(); + + /* Events. */ + events = Json::getItem(root, "events"); + if (events) { + Json *eventMap; + 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->_intValue = Json::getInt(eventMap, "int", 0); + eventData->_floatValue = Json::getFloat(eventMap, "float", 0); + const char *stringValue = Json::getString(eventMap, "string", 0); + eventData->_stringValue = stringValue; + const char *audioPath = Json::getString(eventMap, "audio", 0); + eventData->_audioPath = audioPath; + if (audioPath) { + eventData->_volume = Json::getFloat(eventMap, "volume", 1); + eventData->_balance = Json::getFloat(eventMap, "balance", 0); + } + skeletonData->_events[i] = eventData; + } + } + + /* Animations. */ + animations = Json::getItem(root, "animations"); + if (animations) { + Json *animationMap; + skeletonData->_animations.ensureCapacity(animations->_size); + skeletonData->_animations.setSize(animations->_size, 0); + int animationsIndex = 0; + for (animationMap = animations->_child; animationMap; animationMap = animationMap->_next) { + Animation *animation = readAnimation(animationMap, skeletonData); + if (!animation) { + delete skeletonData; + delete root; + return NULL; + } + skeletonData->_animations[animationsIndex++] = animation; + } + } + + delete root; + + return skeletonData; +} + +Sequence *SkeletonJson::readSequence(Json *item) { + if (item == NULL) return NULL; + Sequence *sequence = new Sequence(Json::getInt(item, "count", 0)); + sequence->_start = Json::getInt(item, "start", 1); + sequence->_digits = Json::getInt(item, "digits", 0); + sequence->_setupIndex = Json::getInt(item, "setupIndex", 0); + return sequence; +} + +void SkeletonJson::setBezier(CurveTimeline *timeline, int frame, int value, int bezier, float time1, float value1, float cx1, + float cy1, + float cx2, float cy2, float time2, float value2) { + timeline->setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2); +} + +int SkeletonJson::readCurve(Json *curve, CurveTimeline *timeline, int bezier, int frame, int value, float time1, + float time2, + float value1, float value2, float scale) { + if (curve->_type == Json::JSON_STRING && strcmp(curve->_valueString, "stepped") == 0) { + timeline->setStepped(frame); + return bezier; + } + curve = Json::getItem(curve, value << 2); + float cx1 = curve->_valueFloat; + curve = curve->_next; + float cy1 = curve->_valueFloat * scale; + curve = curve->_next; + float cx2 = curve->_valueFloat; + curve = curve->_next; + float cy2 = curve->_valueFloat * scale; + setBezier(timeline, frame, value, bezier, time1, value1, cx1, cy1, cx2, cy2, time2, value2); + return bezier + 1; +} + +Timeline *SkeletonJson::readTimeline(Json *keyMap, CurveTimeline1 *timeline, float defaultValue, float scale) { + float time = Json::getFloat(keyMap, "time", 0); + float value = Json::getFloat(keyMap, "value", defaultValue) * scale; + int bezier = 0; + for (int frame = 0;; frame++) { + timeline->setFrame(frame, time, value); + Json *nextMap = keyMap->_next; + if (!nextMap) break; + float time2 = Json::getFloat(nextMap, "time", 0); + float value2 = Json::getFloat(nextMap, "value", defaultValue) * scale; + Json *curve = Json::getItem(keyMap, "curve"); + if (curve != NULL) bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value, value2, scale); + time = time2; + value = value2; + keyMap = nextMap; + } + // timeline.shrink(); // BOZO + return timeline; +} + +Timeline *SkeletonJson::readTimeline(Json *keyMap, CurveTimeline2 *timeline, const char *name1, const char *name2, + float defaultValue, float scale) { + float time = Json::getFloat(keyMap, "time", 0); + float value1 = Json::getFloat(keyMap, name1, defaultValue) * scale; + float value2 = Json::getFloat(keyMap, name2, defaultValue) * scale; + int bezier = 0; + for (int frame = 0;; frame++) { + timeline->setFrame(frame, time, value1, value2); + Json *nextMap = keyMap->_next; + if (!nextMap) break; + float time2 = Json::getFloat(nextMap, "time", 0); + float nvalue1 = Json::getFloat(nextMap, name1, defaultValue) * scale; + float nvalue2 = Json::getFloat(nextMap, name2, defaultValue) * scale; + Json *curve = Json::getItem(keyMap, "curve"); + if (curve != NULL) { + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value1, nvalue1, scale); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, value2, nvalue2, scale); + } + time = time2; + value1 = nvalue1; + value2 = nvalue2; + keyMap = nextMap; + } + // timeline.shrink(); // BOZO + return timeline; +} + +int SkeletonJson::findSlotIndex(SkeletonData *skeletonData, const String &slotName, Vector timelines) { + int slotIndex = ContainerUtil::findIndexWithName(skeletonData->getSlots(), slotName); + if (slotIndex == -1) { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError(NULL, "Slot not found: ", slotName); + } + return slotIndex; +} + +Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { + Vector timelines; + Json *bones = Json::getItem(root, "bones"); + Json *slots = Json::getItem(root, "slots"); + Json *ik = Json::getItem(root, "ik"); + Json *transform = Json::getItem(root, "transform"); + Json *paths = Json::getItem(root, "path"); + Json *physics = Json::getItem(root, "physics"); + Json *attachments = Json::getItem(root, "attachments"); + Json *drawOrder = Json::getItem(root, "drawOrder"); + Json *events = Json::getItem(root, "events"); + Json *boneMap, *slotMap, *keyMap, *nextMap, *curve; + int frame, bezier; + Color color, color2, newColor, newColor2; + + /** Slot timelines. */ + for (slotMap = slots ? slots->_child : 0; slotMap; slotMap = slotMap->_next) { + int slotIndex = findSlotIndex(skeletonData, slotMap->_name, timelines); + if (slotIndex == -1) return NULL; + + for (Json *timelineMap = slotMap->_child; timelineMap; timelineMap = timelineMap->_next) { + int frames = timelineMap->_size; + if (strcmp(timelineMap->_name, "attachment") == 0) { + AttachmentTimeline *timeline = new (__FILE__, __LINE__) AttachmentTimeline(frames, slotIndex); + for (keyMap = timelineMap->_child, frame = 0; keyMap; keyMap = keyMap->_next, ++frame) { + timeline->setFrame(frame, Json::getFloat(keyMap, "time", 0), + Json::getItem(keyMap, "name") ? Json::getItem(keyMap, "name")->_valueString : NULL); + } + timelines.add(timeline); + + } else if (strcmp(timelineMap->_name, "rgba") == 0) { + RGBATimeline *timeline = new (__FILE__, __LINE__) RGBATimeline(frames, frames << 2, slotIndex); + keyMap = timelineMap->_child; + float time = Json::getFloat(keyMap, "time", 0); + toColor(color, Json::getString(keyMap, "color", 0), true); + + for (frame = 0, bezier = 0;; ++frame) { + timeline->setFrame(frame, time, color.r, color.g, color.b, color.a); + nextMap = keyMap->_next; + if (!nextMap) { + // timeline.shrink(); // BOZO + break; + } + float time2 = Json::getFloat(nextMap, "time", 0); + toColor(newColor, Json::getString(nextMap, "color", 0), true); + curve = Json::getItem(keyMap, "curve"); + if (curve) { + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); + bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1); + } + time = time2; + color = newColor; + keyMap = nextMap; + } + timelines.add(timeline); + } else if (strcmp(timelineMap->_name, "rgb") == 0) { + RGBTimeline *timeline = new (__FILE__, __LINE__) RGBTimeline(frames, frames * 3, slotIndex); + keyMap = timelineMap->_child; + float time = Json::getFloat(keyMap, "time", 0); + toColor(color, Json::getString(keyMap, "color", 0), false); + + for (frame = 0, bezier = 0;; ++frame) { + timeline->setFrame(frame, time, color.r, color.g, color.b); + nextMap = keyMap->_next; + if (!nextMap) { + // timeline.shrink(); // BOZO + break; + } + float time2 = Json::getFloat(nextMap, "time", 0); + toColor(newColor, Json::getString(nextMap, "color", 0), false); + curve = Json::getItem(keyMap, "curve"); + if (curve) { + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); + } + time = time2; + color = newColor; + keyMap = nextMap; + } + timelines.add(timeline); + } else if (strcmp(timelineMap->_name, "alpha") == 0) { + timelines.add(readTimeline(timelineMap->_child, + new (__FILE__, __LINE__) AlphaTimeline(frames, frames, slotIndex), + 0, 1)); + } else if (strcmp(timelineMap->_name, "rgba2") == 0) { + RGBA2Timeline *timeline = new (__FILE__, __LINE__) RGBA2Timeline(frames, frames * 7, slotIndex); + keyMap = timelineMap->_child; + float time = Json::getFloat(keyMap, "time", 0); + toColor(color, Json::getString(keyMap, "light", 0), true); + toColor(color2, Json::getString(keyMap, "dark", 0), false); + + for (frame = 0, bezier = 0;; ++frame) { + timeline->setFrame(frame, time, color.r, color.g, color.b, color.a, color2.r, color2.g, color2.b); + nextMap = keyMap->_next; + if (!nextMap) { + // timeline.shrink(); // BOZO + break; + } + float time2 = Json::getFloat(nextMap, "time", 0); + toColor(newColor, Json::getString(nextMap, "light", 0), true); + toColor(newColor2, Json::getString(nextMap, "dark", 0), false); + curve = Json::getItem(keyMap, "curve"); + if (curve) { + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); + bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1); + bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.r, newColor2.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.g, newColor2.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 6, time, time2, color2.b, newColor2.b, 1); + } + time = time2; + color = newColor; + color2 = newColor2; + keyMap = nextMap; + } + timelines.add(timeline); + } else if (strcmp(timelineMap->_name, "rgb2") == 0) { + RGBA2Timeline *timeline = new (__FILE__, __LINE__) RGBA2Timeline(frames, frames * 6, slotIndex); + keyMap = timelineMap->_child; + float time = Json::getFloat(keyMap, "time", 0); + toColor(color, Json::getString(keyMap, "light", 0), false); + toColor(color2, Json::getString(keyMap, "dark", 0), false); + + for (frame = 0, bezier = 0;; ++frame) { + timeline->setFrame(frame, time, color.r, color.g, color.b, color.a, color2.r, color2.g, color2.b); + nextMap = keyMap->_next; + if (!nextMap) { + // timeline.shrink(); // BOZO + break; + } + float time2 = Json::getFloat(nextMap, "time", 0); + toColor(newColor, Json::getString(nextMap, "light", 0), false); + toColor(newColor2, Json::getString(nextMap, "dark", 0), false); + curve = Json::getItem(keyMap, "curve"); + if (curve) { + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); + bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color2.r, newColor2.r, 1); + bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.g, newColor2.g, 1); + bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.b, newColor2.b, 1); + } + time = time2; + color = newColor; + color2 = newColor2; + keyMap = nextMap; + } + timelines.add(timeline); + } else { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError(NULL, "Invalid timeline type for a slot: ", timelineMap->_name); + return NULL; + } + } + } + + /** Bone timelines. */ + for (boneMap = bones ? bones->_child : 0; boneMap; boneMap = boneMap->_next) { + int boneIndex = ContainerUtil::findIndexWithName(skeletonData->_bones, boneMap->_name); + if (boneIndex == -1) { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError(NULL, "Bone not found: ", boneMap->_name); + return NULL; + } + + for (Json *timelineMap = boneMap->_child; timelineMap; timelineMap = timelineMap->_next) { + int frames = timelineMap->_size; + if (frames == 0) continue; + + if (strcmp(timelineMap->_name, "rotate") == 0) { + timelines.add(readTimeline(timelineMap->_child, + new RotateTimeline(frames, frames, boneIndex), 0, + 1)); + } else if (strcmp(timelineMap->_name, "translate") == 0) { + TranslateTimeline *timeline = new TranslateTimeline(frames, frames << 1, + boneIndex); + timelines.add(readTimeline(timelineMap->_child, timeline, "x", "y", 0, _scale)); + } else if (strcmp(timelineMap->_name, "translatex") == 0) { + TranslateXTimeline *timeline = new TranslateXTimeline(frames, frames, + boneIndex); + timelines.add(readTimeline(timelineMap->_child, timeline, 0, _scale)); + } else if (strcmp(timelineMap->_name, "translatey") == 0) { + TranslateYTimeline *timeline = new TranslateYTimeline(frames, frames, + boneIndex); + timelines.add(readTimeline(timelineMap->_child, timeline, 0, _scale)); + } else if (strcmp(timelineMap->_name, "scale") == 0) { + ScaleTimeline *timeline = new (__FILE__, __LINE__) ScaleTimeline(frames, + frames << 1, boneIndex); + timelines.add(readTimeline(timelineMap->_child, timeline, "x", "y", 1, 1)); + } else if (strcmp(timelineMap->_name, "scalex") == 0) { + ScaleXTimeline *timeline = new (__FILE__, __LINE__) ScaleXTimeline(frames, + frames, boneIndex); + timelines.add(readTimeline(timelineMap->_child, timeline, 1, 1)); + } else if (strcmp(timelineMap->_name, "scaley") == 0) { + ScaleYTimeline *timeline = new (__FILE__, __LINE__) ScaleYTimeline(frames, + frames, boneIndex); + timelines.add(readTimeline(timelineMap->_child, timeline, 1, 1)); + } else if (strcmp(timelineMap->_name, "shear") == 0) { + ShearTimeline *timeline = new (__FILE__, __LINE__) ShearTimeline(frames, + frames << 1, boneIndex); + timelines.add(readTimeline(timelineMap->_child, timeline, "x", "y", 0, 1)); + } else if (strcmp(timelineMap->_name, "shearx") == 0) { + ShearXTimeline *timeline = new (__FILE__, __LINE__) ShearXTimeline(frames, + frames, boneIndex); + timelines.add(readTimeline(timelineMap->_child, timeline, 0, 1)); + } else if (strcmp(timelineMap->_name, "sheary") == 0) { + ShearYTimeline *timeline = new (__FILE__, __LINE__) ShearYTimeline(frames, + frames, boneIndex); + timelines.add(readTimeline(timelineMap->_child, timeline, 0, 1)); + } else if (strcmp(timelineMap->_name, "inherit") == 0) { + InheritTimeline *timeline = new (__FILE__, __LINE__) InheritTimeline(frames, boneIndex); + keyMap = timelineMap->_child; + for (frame = 0;; frame++) { + float time = Json::getFloat(keyMap, "time", 0); + const char *value = Json::getString(keyMap, "inherit", "normal"); + Inherit inherit = Inherit_Normal; + if (strcmp(value, "normal") == 0) inherit = Inherit_Normal; + else if (strcmp(value, "onlyTranslation") == 0) + inherit = Inherit_OnlyTranslation; + else if (strcmp(value, "noRotationOrReflection") == 0) + inherit = Inherit_NoRotationOrReflection; + else if (strcmp(value, "noScale") == 0) + inherit = Inherit_NoScale; + else if (strcmp(value, "noScaleOrReflection") == 0) + inherit = Inherit_NoScaleOrReflection; + timeline->setFrame(frame, time, inherit); + nextMap = keyMap->_next; + if (!nextMap) break; + keyMap = nextMap; + } + timelines.add(timeline); + } else { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError(NULL, "Invalid timeline type for a bone: ", timelineMap->_name); + return NULL; + } + } + } + + /** IK constraint timelines. */ + for (Json *constraintMap = ik ? ik->_child : 0; constraintMap; constraintMap = constraintMap->_next) { + keyMap = constraintMap->_child; + if (keyMap == NULL) continue; + + IkConstraintData *constraint = skeletonData->findIkConstraint(constraintMap->_name); + int constraintIndex = skeletonData->_ikConstraints.indexOf(constraint); + IkConstraintTimeline *timeline = new (__FILE__, __LINE__) IkConstraintTimeline(constraintMap->_size, + constraintMap->_size << 1, + constraintIndex); + + float time = Json::getFloat(keyMap, "time", 0); + float mix = Json::getFloat(keyMap, "mix", 1); + float softness = Json::getFloat(keyMap, "softness", 0) * _scale; + + for (frame = 0, bezier = 0;; frame++) { + int bendDirection = Json::getBoolean(keyMap, "bendPositive", true) ? 1 : -1; + timeline->setFrame(frame, time, mix, softness, bendDirection, Json::getBoolean(keyMap, "compress", false), + Json::getBoolean(keyMap, "stretch", false)); + nextMap = keyMap->_next; + if (!nextMap) { + // timeline.shrink(); // BOZO + break; + } + + float time2 = Json::getFloat(nextMap, "time", 0); + float mix2 = Json::getFloat(nextMap, "mix", 1); + float softness2 = Json::getFloat(nextMap, "softness", 0) * _scale; + curve = Json::getItem(keyMap, "curve"); + if (curve) { + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mix, mix2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, softness, softness2, _scale); + } + + time = time2; + mix = mix2; + softness = softness2; + keyMap = nextMap; + } + + timelines.add(timeline); + } + + /** Transform constraint timelines. */ + for (Json *constraintMap = transform ? transform->_child : 0; constraintMap; constraintMap = constraintMap->_next) { + keyMap = constraintMap->_child; + if (keyMap == NULL) continue; + + TransformConstraintData *constraint = skeletonData->findTransformConstraint(constraintMap->_name); + int constraintIndex = skeletonData->_transformConstraints.indexOf(constraint); + TransformConstraintTimeline *timeline = new (__FILE__, __LINE__) TransformConstraintTimeline( + constraintMap->_size, constraintMap->_size * 6, constraintIndex); + + float time = Json::getFloat(keyMap, "time", 0); + float mixRotate = Json::getFloat(keyMap, "mixRotate", 1); + float mixShearY = Json::getFloat(keyMap, "mixShearY", 1); + float mixX = Json::getFloat(keyMap, "mixX", 1); + float mixY = Json::getFloat(keyMap, "mixY", mixX); + float mixScaleX = Json::getFloat(keyMap, "mixScaleX", 1); + float mixScaleY = Json::getFloat(keyMap, "mixScaleY", mixScaleX); + + for (frame = 0, bezier = 0;; frame++) { + timeline->setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY); + nextMap = keyMap->_next; + if (!nextMap) { + // timeline.shrink(); // BOZO + break; + } + + float time2 = Json::getFloat(nextMap, "time", 0); + float mixRotate2 = Json::getFloat(nextMap, "mixRotate", 1); + float mixShearY2 = Json::getFloat(nextMap, "mixShearY", 1); + float mixX2 = Json::getFloat(nextMap, "mixX", 1); + float mixY2 = Json::getFloat(nextMap, "mixY", mixX2); + float mixScaleX2 = Json::getFloat(nextMap, "mixScaleX", 1); + float mixScaleY2 = Json::getFloat(nextMap, "mixScaleY", mixScaleX2); + curve = Json::getItem(keyMap, "curve"); + if (curve) { + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, mixScaleX, mixScaleX2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, mixScaleY, mixScaleY2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, mixShearY, mixShearY2, 1); + } + + time = time2; + mixRotate = mixRotate2; + mixX = mixX2; + mixY = mixY2; + mixScaleX = mixScaleX2; + mixScaleY = mixScaleY2; + mixScaleX = mixScaleX2; + keyMap = nextMap; + } + + timelines.add(timeline); + } + + /** Path constraint timelines. */ + for (Json *constraintMap = paths ? paths->_child : 0; constraintMap; constraintMap = constraintMap->_next) { + PathConstraintData *constraint = skeletonData->findPathConstraint(constraintMap->_name); + if (!constraint) { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError(NULL, "Path constraint not found: ", constraintMap->_name); + return NULL; + } + int constraintIndex = skeletonData->_pathConstraints.indexOf(constraint); + for (Json *timelineMap = constraintMap->_child; timelineMap; timelineMap = timelineMap->_next) { + keyMap = timelineMap->_child; + if (keyMap == NULL) continue; + const char *timelineName = timelineMap->_name; + int frames = timelineMap->_size; + if (strcmp(timelineName, "position") == 0) { + PathConstraintPositionTimeline *timeline = new (__FILE__, __LINE__) PathConstraintPositionTimeline( + frames, frames, constraintIndex); + timelines.add( + readTimeline(keyMap, timeline, 0, constraint->_positionMode == PositionMode_Fixed ? _scale : 1)); + } else if (strcmp(timelineName, "spacing") == 0) { + CurveTimeline1 *timeline = new PathConstraintSpacingTimeline(frames, frames, + constraintIndex); + timelines.add(readTimeline(keyMap, timeline, 0, + constraint->_spacingMode == SpacingMode_Length || + constraint->_spacingMode == SpacingMode_Fixed + ? _scale + : 1)); + } else if (strcmp(timelineName, "mix") == 0) { + PathConstraintMixTimeline *timeline = new PathConstraintMixTimeline(frames, + frames * 3, constraintIndex); + float time = Json::getFloat(keyMap, "time", 0); + float mixRotate = Json::getFloat(keyMap, "mixRotate", 1); + float mixX = Json::getFloat(keyMap, "mixX", 1); + float mixY = Json::getFloat(keyMap, "mixY", mixX); + for (frame = 0, bezier = 0;; frame++) { + timeline->setFrame(frame, time, mixRotate, mixX, mixY); + nextMap = keyMap->_next; + if (!nextMap) { + // timeline.shrink(); // BOZO + break; + } + float time2 = Json::getFloat(nextMap, "time", 0); + float mixRotate2 = Json::getFloat(nextMap, "mixRotate", 1); + float mixX2 = Json::getFloat(nextMap, "mixX", 1); + float mixY2 = Json::getFloat(nextMap, "mixY", mixX2); + curve = Json::getItem(keyMap, "curve"); + if (curve != NULL) { + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1); + bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1); + } + time = time2; + mixRotate = mixRotate2; + mixX = mixX2; + mixY = mixY2; + keyMap = nextMap; + } + timelines.add(timeline); + } + } + } + + /** Physics constraint timelines. */ + for (Json *constraintMap = physics ? physics->_child : 0; constraintMap; constraintMap = constraintMap->_next) { + int index = -1; + if (constraintMap->_name && strlen(constraintMap->_name) > 0) { + PhysicsConstraintData *constraint = skeletonData->findPhysicsConstraint(constraintMap->_name); + if (!constraint) { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError(NULL, "Physics constraint not found: ", constraintMap->_name); + return NULL; + } + index = skeletonData->_physicsConstraints.indexOf(constraint); + } + for (Json *timelineMap = constraintMap->_child; timelineMap; timelineMap = timelineMap->_next) { + keyMap = timelineMap->_child; + if (keyMap == NULL) continue; + const char *timelineName = timelineMap->_name; + int frames = timelineMap->_size; + if (strcmp(timelineName, "reset") == 0) { + PhysicsConstraintResetTimeline *timeline = new (__FILE__, __LINE__) PhysicsConstraintResetTimeline(frames, index); + for (frame = 0; keyMap != nullptr; keyMap = keyMap->_next, frame++) { + timeline->setFrame(frame, Json::getFloat(keyMap, "time", 0)); + } + timelines.add(timeline); + continue; + } + + CurveTimeline1 *timeline = nullptr; + if (strcmp(timelineName, "inertia") == 0) { + timeline = new PhysicsConstraintInertiaTimeline(frames, frames, index); + } else if (strcmp(timelineName, "strength") == 0) { + timeline = new PhysicsConstraintStrengthTimeline(frames, frames, index); + } else if (strcmp(timelineName, "damping") == 0) { + timeline = new PhysicsConstraintDampingTimeline(frames, frames, index); + } else if (strcmp(timelineName, "mass") == 0) { + timeline = new PhysicsConstraintMassTimeline(frames, frames, index); + } else if (strcmp(timelineName, "wind") == 0) { + timeline = new PhysicsConstraintWindTimeline(frames, frames, index); + } else if (strcmp(timelineName, "gravity") == 0) { + timeline = new PhysicsConstraintGravityTimeline(frames, frames, index); + } else if (strcmp(timelineName, "mix") == 0) { + timeline = new PhysicsConstraintMixTimeline(frames, frames, index); + } else { + continue; + } + timelines.add(readTimeline(keyMap, timeline, 0, 1)); + } + } + + /** Attachment timelines. */ + for (Json *attachmenstMap = attachments ? attachments->_child : NULL; attachmenstMap; attachmenstMap = attachmenstMap->_next) { + Skin *skin = skeletonData->findSkin(attachmenstMap->_name); + for (slotMap = attachmenstMap->_child; slotMap; slotMap = slotMap->_next) { + int slotIndex = findSlotIndex(skeletonData, slotMap->_name, timelines); + if (slotIndex == -1) return NULL; + + for (Json *attachmentMap = slotMap->_child; attachmentMap; attachmentMap = attachmentMap->_next) { + Attachment *attachment = skin->getAttachment(slotIndex, attachmentMap->_name); + if (!attachment) { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError(NULL, "Attachment not found: ", attachmentMap->_name); + return NULL; + } + + for (Json *timelineMap = attachmentMap->_child; timelineMap; timelineMap = timelineMap->_next) { + keyMap = timelineMap->_child; + if (keyMap == NULL) continue; + int frames = timelineMap->_size; + String timelineName = timelineMap->_name; + if (timelineName == "deform") { + VertexAttachment *vertexAttachment = static_cast(attachment); + bool weighted = vertexAttachment->_bones.size() != 0; + Vector &verts = vertexAttachment->_vertices; + int deformLength = weighted ? (int) verts.size() / 3 * 2 : (int) verts.size(); + + DeformTimeline *timeline = new (__FILE__, __LINE__) DeformTimeline(frames, + frames, slotIndex, vertexAttachment); + float time = Json::getFloat(keyMap, "time", 0); + for (frame = 0, bezier = 0;; frame++) { + Json *vertices = Json::getItem(keyMap, "vertices"); + Vector deformed; + if (!vertices) { + if (weighted) { + deformed.setSize(deformLength, 0); + } else { + deformed.clearAndAddAll(vertexAttachment->_vertices); + } + } else { + deformed.setSize(deformLength, 0); + int v, start = Json::getInt(keyMap, "offset", 0); + Json *vertex; + if (_scale == 1) { + for (vertex = vertices->_child, v = start; vertex; vertex = vertex->_next, ++v) { + deformed[v] = vertex->_valueFloat; + } + } else { + for (vertex = vertices->_child, v = start; vertex; vertex = vertex->_next, ++v) { + deformed[v] = vertex->_valueFloat * _scale; + } + } + if (!weighted) { + Vector &verticesAttachment = vertexAttachment->_vertices; + for (v = 0; v < deformLength; ++v) { + deformed[v] += verticesAttachment[v]; + } + } + } + timeline->setFrame(frame, time, deformed); + nextMap = keyMap->_next; + if (!nextMap) { + // timeline.shrink(); // BOZO + break; + } + float time2 = Json::getFloat(nextMap, "time", 0); + curve = Json::getItem(keyMap, "curve"); + if (curve) { + bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1); + } + time = time2; + keyMap = nextMap; + } + timelines.add(timeline); + } else if (timelineName == "sequence") { + SequenceTimeline *timeline = new SequenceTimeline(frames, slotIndex, attachment); + float lastDelay = 0; + for (frame = 0; keyMap != NULL; keyMap = keyMap->_next, frame++) { + float delay = Json::getFloat(keyMap, "delay", lastDelay); + float time = Json::getFloat(keyMap, "time", 0); + String modeString = Json::getString(keyMap, "mode", "hold"); + int index = Json::getInt(keyMap, "index", 0); + SequenceMode mode = SequenceMode::hold; + if (modeString == "once") mode = SequenceMode::once; + if (modeString == "loop") mode = SequenceMode::loop; + if (modeString == "pingpong") mode = SequenceMode::pingpong; + if (modeString == "onceReverse") mode = SequenceMode::onceReverse; + if (modeString == "loopReverse") mode = SequenceMode::loopReverse; + if (modeString == "pingpongReverse") mode = SequenceMode::pingpongReverse; + timeline->setFrame(frame, time, mode, index, delay); + lastDelay = delay; + } + timelines.add(timeline); + } + } + } + } + } + + /** Draw order timeline. */ + if (drawOrder) { + DrawOrderTimeline *timeline = new (__FILE__, __LINE__) DrawOrderTimeline(drawOrder->_size); + + for (keyMap = drawOrder->_child, frame = 0; keyMap; keyMap = keyMap->_next, ++frame) { + int ii; + Vector drawOrder2; + Json *offsets = Json::getItem(keyMap, "offsets"); + if (offsets) { + Json *offsetMap; + Vector unchanged; + unchanged.ensureCapacity(skeletonData->_slots.size() - offsets->_size); + unchanged.setSize(skeletonData->_slots.size() - offsets->_size, 0); + size_t originalIndex = 0, unchangedIndex = 0; + + drawOrder2.ensureCapacity(skeletonData->_slots.size()); + drawOrder2.setSize(skeletonData->_slots.size(), 0); + for (ii = (int) skeletonData->_slots.size() - 1; ii >= 0; --ii) + drawOrder2[ii] = -1; + + for (offsetMap = offsets->_child; offsetMap; offsetMap = offsetMap->_next) { + int slotIndex = findSlotIndex(skeletonData, Json::getString(offsetMap, "slot", 0), timelines); + if (slotIndex == -1) return NULL; + + /* Collect unchanged items. */ + while (originalIndex != (size_t) slotIndex) + unchanged[unchangedIndex++] = (int) originalIndex++; + /* Set changed items. */ + drawOrder2[originalIndex + Json::getInt(offsetMap, "offset", 0)] = (int) originalIndex; + originalIndex++; + } + /* Collect remaining unchanged items. */ + while ((int) originalIndex < (int) skeletonData->_slots.size()) + unchanged[unchangedIndex++] = (int) originalIndex++; + /* Fill in unchanged items. */ + for (ii = (int) skeletonData->_slots.size() - 1; ii >= 0; ii--) + if (drawOrder2[ii] == -1) drawOrder2[ii] = unchanged[--unchangedIndex]; + } + timeline->setFrame(frame, Json::getFloat(keyMap, "time", 0), drawOrder2); + } + timelines.add(timeline); + } + + /** Event timeline. */ + if (events) { + EventTimeline *timeline = new (__FILE__, __LINE__) EventTimeline(events->_size); + + for (keyMap = events->_child, frame = 0; keyMap; keyMap = keyMap->_next, ++frame) { + Event *event; + EventData *eventData = skeletonData->findEvent(Json::getString(keyMap, "name", 0)); + if (!eventData) { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError(NULL, "Event not found: ", Json::getString(keyMap, "name", 0)); + return NULL; + } + + event = new (__FILE__, __LINE__) Event(Json::getFloat(keyMap, "time", 0), *eventData); + event->_intValue = Json::getInt(keyMap, "int", eventData->_intValue); + event->_floatValue = Json::getFloat(keyMap, "float", eventData->_floatValue); + event->_stringValue = Json::getString(keyMap, "string", eventData->_stringValue.buffer()); + if (!eventData->_audioPath.isEmpty()) { + event->_volume = Json::getFloat(keyMap, "volume", 1); + event->_balance = Json::getFloat(keyMap, "balance", 0); + } + timeline->setFrame(frame, event); + } + timelines.add(timeline); + } + + float duration = 0; + for (size_t i = 0; i < timelines.size(); i++) + duration = MathUtil::max(duration, timelines[i]->getDuration()); + return new (__FILE__, __LINE__) Animation(String(root->_name), timelines, duration); +} + +void SkeletonJson::readVertices(Json *attachmentMap, VertexAttachment *attachment, size_t verticesLength) { + Json *entry; + size_t i, n, nn, entrySize; + Vector vertices; + + attachment->setWorldVerticesLength(verticesLength); + + entry = Json::getItem(attachmentMap, "vertices"); + entrySize = entry->_size; + vertices.ensureCapacity(entrySize); + vertices.setSize(entrySize, 0); + for (entry = entry->_child, i = 0; entry; entry = entry->_next, ++i) + vertices[i] = entry->_valueFloat; + + if (verticesLength == entrySize) { + if (_scale != 1) { + for (i = 0; i < entrySize; ++i) + vertices[i] *= _scale; + } + + attachment->getVertices().clearAndAddAll(vertices); + return; + } + + Vertices bonesAndWeights; + bonesAndWeights._bones.ensureCapacity(verticesLength * 3); + bonesAndWeights._vertices.ensureCapacity(verticesLength * 3 * 3); + + for (i = 0, n = entrySize; i < n;) { + int boneCount = (int) vertices[i++]; + bonesAndWeights._bones.add(boneCount); + for (nn = i + boneCount * 4; i < nn; i += 4) { + bonesAndWeights._bones.add((int) vertices[i]); + bonesAndWeights._vertices.add(vertices[i + 1] * _scale); + bonesAndWeights._vertices.add(vertices[i + 2] * _scale); + bonesAndWeights._vertices.add(vertices[i + 3]); + } + } + + attachment->getVertices().clearAndAddAll(bonesAndWeights._vertices); + attachment->getBones().clearAndAddAll(bonesAndWeights._bones); +} + +void SkeletonJson::setError(Json *root, const String &value1, const String &value2) { + _error = String(value1).append(value2); + delete root; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonJson.h b/native/cocos/editor-support/spine/4.2/spine/SkeletonJson.h new file mode 100644 index 0000000000..94c6a55109 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonJson.h @@ -0,0 +1,114 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_SkeletonJson_h +#define Spine_SkeletonJson_h + +#include +#include +#include + +namespace spine { + class Timeline; + + class CurveTimeline; + + class CurveTimeline1; + + class CurveTimeline2; + + class VertexAttachment; + + class Animation; + + class Json; + + class SkeletonData; + + class Atlas; + + class AttachmentLoader; + + class LinkedMesh; + + class String; + + class Sequence; + + class SP_API SkeletonJson : public SpineObject { + public: + explicit SkeletonJson(Atlas *atlas); + + explicit SkeletonJson(AttachmentLoader *attachmentLoader, bool ownsLoader = false); + + ~SkeletonJson(); + + SkeletonData *readSkeletonDataFile(const String &path); + + SkeletonData *readSkeletonData(const char *json); + + void setScale(float scale) { _scale = scale; } + + String &getError() { return _error; } + + private: + AttachmentLoader *_attachmentLoader; + Vector _linkedMeshes; + float _scale; + const bool _ownsLoader; + String _error; + + static Sequence *readSequence(Json *sequence); + + static void + setBezier(CurveTimeline *timeline, int frame, int value, int bezier, float time1, float value1, float cx1, + float cy1, + float cx2, float cy2, float time2, float value2); + + static int + readCurve(Json *curve, CurveTimeline *timeline, int bezier, int frame, int value, float time1, float time2, + float value1, float value2, float scale); + + static Timeline *readTimeline(Json *keyMap, CurveTimeline1 *timeline, float defaultValue, float scale); + + static Timeline * + readTimeline(Json *keyMap, CurveTimeline2 *timeline, const char *name1, const char *name2, float defaultValue, + float scale); + + Animation *readAnimation(Json *root, SkeletonData *skeletonData); + + void readVertices(Json *attachmentMap, VertexAttachment *attachment, size_t verticesLength); + + void setError(Json *root, const String &value1, const String &value2); + + int findSlotIndex(SkeletonData *skeletonData, const String &slotName, Vector timelines); + }; +} + +#endif /* Spine_SkeletonJson_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonRenderer.cpp b/native/cocos/editor-support/spine/4.2/spine/SkeletonRenderer.cpp new file mode 100644 index 0000000000..01195a980f --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonRenderer.cpp @@ -0,0 +1,246 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include +#include +#include +#include +#include +#include +#include + +using namespace spine; + +SkeletonRenderer::SkeletonRenderer() : _allocator(4096), _worldVertices(), _quadIndices(), _clipping(), _renderCommands() { + _quadIndices.add(0); + _quadIndices.add(1); + _quadIndices.add(2); + _quadIndices.add(2); + _quadIndices.add(3); + _quadIndices.add(0); +} + +SkeletonRenderer::~SkeletonRenderer() { +} + +static RenderCommand *createRenderCommand(BlockAllocator &allocator, int numVertices, int32_t numIndices, BlendMode blendMode, void *texture) { + RenderCommand *cmd = allocator.allocate(1); + cmd->positions = allocator.allocate(numVertices << 1); + cmd->uvs = allocator.allocate(numVertices << 1); + cmd->colors = allocator.allocate(numVertices); + cmd->darkColors = allocator.allocate(numVertices); + cmd->numVertices = numVertices; + cmd->indices = allocator.allocate(numIndices); + cmd->numIndices = numIndices; + cmd->blendMode = blendMode; + cmd->texture = texture; + cmd->next = nullptr; + return cmd; +} + +static RenderCommand *batchSubCommands(BlockAllocator &allocator, Vector &commands, int first, int last, int numVertices, int numIndices) { + RenderCommand *batched = createRenderCommand(allocator, numVertices, numIndices, commands[first]->blendMode, commands[first]->texture); + float *positions = batched->positions; + float *uvs = batched->uvs; + uint32_t *colors = batched->colors; + uint32_t *darkColors = batched->darkColors; + uint16_t *indices = batched->indices; + int indicesOffset = 0; + for (int i = first; i <= last; i++) { + RenderCommand *cmd = commands[i]; + memcpy(positions, cmd->positions, sizeof(float) * 2 * cmd->numVertices); + memcpy(uvs, cmd->uvs, sizeof(float) * 2 * cmd->numVertices); + memcpy(colors, cmd->colors, sizeof(int32_t) * cmd->numVertices); + memcpy(darkColors, cmd->darkColors, sizeof(int32_t) * cmd->numVertices); + for (int ii = 0; ii < cmd->numIndices; ii++) + indices[ii] = cmd->indices[ii] + indicesOffset; + indicesOffset += cmd->numVertices; + positions += 2 * cmd->numVertices; + uvs += 2 * cmd->numVertices; + colors += cmd->numVertices; + darkColors += cmd->numVertices; + indices += cmd->numIndices; + } + return batched; +} + +static RenderCommand *batchCommands(BlockAllocator &allocator, Vector &commands) { + if (commands.size() == 0) return nullptr; + + RenderCommand *root = nullptr; + RenderCommand *last = nullptr; + + RenderCommand *first = commands[0]; + int startIndex = 0; + int i = 1; + int numVertices = first->numVertices; + int numIndices = first->numIndices; + while (i <= (int) commands.size()) { + RenderCommand *cmd = i < (int) commands.size() ? commands[i] : nullptr; + + if (cmd && cmd->numVertices == 0 && cmd->numIndices == 0) { + i++; + continue; + } + + if (cmd != nullptr && cmd->texture == first->texture && + cmd->blendMode == first->blendMode && + cmd->colors[0] == first->colors[0] && + cmd->darkColors[0] == first->darkColors[0] && + numIndices + cmd->numIndices < 0xffff) { + numVertices += cmd->numVertices; + numIndices += cmd->numIndices; + } else { + RenderCommand *batched = batchSubCommands(allocator, commands, startIndex, i - 1, numVertices, numIndices); + if (!last) { + root = last = batched; + } else { + last->next = batched; + last = batched; + } + if (i == (int) commands.size()) break; + first = commands[i]; + startIndex = i; + numVertices = first->numVertices; + numIndices = first->numIndices; + } + i++; + } + return root; +} + +RenderCommand *SkeletonRenderer::render(Skeleton &skeleton) { + _allocator.compress(); + _renderCommands.clear(); + + SkeletonClipping &clipper = _clipping; + + for (unsigned i = 0; i < skeleton.getSlots().size(); ++i) { + Slot &slot = *skeleton.getDrawOrder()[i]; + Attachment *attachment = slot.getAttachment(); + if (!attachment) { + clipper.clipEnd(slot); + continue; + } + + // Early out if the slot color is 0 or the bone is not active + if ((slot.getColor().a == 0 || !slot.getBone().isActive()) && !attachment->getRTTI().isExactly(ClippingAttachment::rtti)) { + clipper.clipEnd(slot); + continue; + } + + Vector *worldVertices = &_worldVertices; + Vector *quadIndices = &_quadIndices; + Vector *vertices = worldVertices; + int32_t verticesCount; + Vector *uvs; + Vector *indices; + int32_t indicesCount; + Color *attachmentColor; + void *texture; + + if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { + RegionAttachment *regionAttachment = (RegionAttachment *) attachment; + attachmentColor = ®ionAttachment->getColor(); + + // Early out if the slot color is 0 + if (attachmentColor->a == 0) { + clipper.clipEnd(slot); + continue; + } + + worldVertices->setSize(8, 0); + regionAttachment->computeWorldVertices(slot, *worldVertices, 0, 2); + verticesCount = 4; + uvs = ®ionAttachment->getUVs(); + indices = quadIndices; + indicesCount = 6; + texture = regionAttachment->getRegion()->rendererObject; + + } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { + MeshAttachment *mesh = (MeshAttachment *) attachment; + attachmentColor = &mesh->getColor(); + + // Early out if the slot color is 0 + if (attachmentColor->a == 0) { + clipper.clipEnd(slot); + continue; + } + + worldVertices->setSize(mesh->getWorldVerticesLength(), 0); + mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices->buffer(), 0, 2); + verticesCount = (int32_t) (mesh->getWorldVerticesLength() >> 1); + uvs = &mesh->getUVs(); + indices = &mesh->getTriangles(); + indicesCount = (int32_t) indices->size(); + texture = mesh->getRegion()->rendererObject; + + } else if (attachment->getRTTI().isExactly(ClippingAttachment::rtti)) { + ClippingAttachment *clip = (ClippingAttachment *) slot.getAttachment(); + clipper.clipStart(slot, clip); + continue; + } else + continue; + + uint8_t r = static_cast(skeleton.getColor().r * slot.getColor().r * attachmentColor->r * 255); + uint8_t g = static_cast(skeleton.getColor().g * slot.getColor().g * attachmentColor->g * 255); + uint8_t b = static_cast(skeleton.getColor().b * slot.getColor().b * attachmentColor->b * 255); + uint8_t a = static_cast(skeleton.getColor().a * slot.getColor().a * attachmentColor->a * 255); + uint32_t color = (a << 24) | (r << 16) | (g << 8) | b; + uint32_t darkColor = 0xff000000; + if (slot.hasDarkColor()) { + Color &slotDarkColor = slot.getDarkColor(); + darkColor = 0xff000000 | (static_cast(slotDarkColor.r * 255) << 16) | (static_cast(slotDarkColor.g * 255) << 8) | static_cast(slotDarkColor.b * 255); + } + + if (clipper.isClipping()) { + clipper.clipTriangles(*worldVertices, *indices, *uvs, 2); + vertices = &clipper.getClippedVertices(); + verticesCount = (int32_t) (clipper.getClippedVertices().size() >> 1); + uvs = &clipper.getClippedUVs(); + indices = &clipper.getClippedTriangles(); + indicesCount = (int32_t) (clipper.getClippedTriangles().size()); + } + + RenderCommand *cmd = createRenderCommand(_allocator, verticesCount, indicesCount, slot.getData().getBlendMode(), texture); + _renderCommands.add(cmd); + memcpy(cmd->positions, vertices->buffer(), (verticesCount << 1) * sizeof(float)); + memcpy(cmd->uvs, uvs->buffer(), (verticesCount << 1) * sizeof(float)); + for (int ii = 0; ii < verticesCount; ii++) { + cmd->colors[ii] = color; + cmd->darkColors[ii] = darkColor; + } + memcpy(cmd->indices, indices->buffer(), indices->size() * sizeof(uint16_t)); + clipper.clipEnd(slot); + } + clipper.clipEnd(); + + return batchCommands(_allocator, _renderCommands); +} \ No newline at end of file diff --git a/native/cocos/editor-support/spine/4.2/spine/SkeletonRenderer.h b/native/cocos/editor-support/spine/4.2/spine/SkeletonRenderer.h new file mode 100644 index 0000000000..6ccb2b351d --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SkeletonRenderer.h @@ -0,0 +1,68 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ +#ifndef Spine_SkeletonRenderer_h +#define Spine_SkeletonRenderer_h + +#include +#include +#include + +namespace spine { + class Skeleton; + + struct SP_API RenderCommand { + float *positions; + float *uvs; + uint32_t *colors; + uint32_t *darkColors; + int32_t numVertices; + uint16_t *indices; + int32_t numIndices; + BlendMode blendMode; + void *texture; + RenderCommand *next; + }; + + class SP_API SkeletonRenderer: public SpineObject { + public: + explicit SkeletonRenderer(); + + ~SkeletonRenderer(); + + RenderCommand *render(Skeleton &skeleton); + private: + BlockAllocator _allocator; + Vector _worldVertices; + Vector _quadIndices; + SkeletonClipping _clipping; + Vector _renderCommands; + }; +} + +#endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine/4.2/spine/Skin.cpp b/native/cocos/editor-support/spine/4.2/spine/Skin.cpp new file mode 100644 index 0000000000..8d39ffe18e --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Skin.cpp @@ -0,0 +1,195 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include + +#include +#include + +#include + +using namespace spine; + +Skin::AttachmentMap::AttachmentMap() { +} + +static void disposeAttachment(Attachment *attachment) { + if (!attachment) return; + attachment->dereference(); + if (attachment->getRefCount() == 0) delete attachment; +} + +void Skin::AttachmentMap::put(size_t slotIndex, const String &attachmentName, Attachment *attachment) { + if (slotIndex >= _buckets.size()) + _buckets.setSize(slotIndex + 1, Vector()); + Vector &bucket = _buckets[slotIndex]; + int existing = findInBucket(bucket, attachmentName); + attachment->reference(); + if (existing >= 0) { + disposeAttachment(bucket[existing]._attachment); + bucket[existing]._attachment = attachment; + } else { + bucket.add(Entry(slotIndex, attachmentName, attachment)); + } +} + +Attachment *Skin::AttachmentMap::get(size_t slotIndex, const String &attachmentName) { + if (slotIndex >= _buckets.size()) return NULL; + int existing = findInBucket(_buckets[slotIndex], attachmentName); + return existing >= 0 ? _buckets[slotIndex][existing]._attachment : NULL; +} + +void Skin::AttachmentMap::remove(size_t slotIndex, const String &attachmentName) { + if (slotIndex >= _buckets.size()) return; + int existing = findInBucket(_buckets[slotIndex], attachmentName); + if (existing >= 0) { + disposeAttachment(_buckets[slotIndex][existing]._attachment); + _buckets[slotIndex].removeAt(existing); + } +} + +int Skin::AttachmentMap::findInBucket(Vector &bucket, const String &attachmentName) { + for (size_t i = 0; i < bucket.size(); i++) + if (bucket[i]._name == attachmentName) return (int) i; + return -1; +} + +Skin::AttachmentMap::Entries Skin::AttachmentMap::getEntries() { + return Skin::AttachmentMap::Entries(_buckets); +} + +Skin::Skin(const String &name) : _name(name), _attachments(), _color(0.99607843f, 0.61960787f, 0.30980393f, 1) { + assert(_name.length() > 0); +} + +Skin::~Skin() { + Skin::AttachmentMap::Entries entries = _attachments.getEntries(); + while (entries.hasNext()) { + Skin::AttachmentMap::Entry entry = entries.next(); + disposeAttachment(entry._attachment); + } +} + +void Skin::setAttachment(size_t slotIndex, const String &name, Attachment *attachment) { + assert(attachment); + _attachments.put(slotIndex, name, attachment); +} + +Attachment *Skin::getAttachment(size_t slotIndex, const String &name) { + return _attachments.get(slotIndex, name); +} + +void Skin::removeAttachment(size_t slotIndex, const String &name) { + _attachments.remove(slotIndex, name); +} + +void Skin::findNamesForSlot(size_t slotIndex, Vector &names) { + Skin::AttachmentMap::Entries entries = _attachments.getEntries(); + while (entries.hasNext()) { + Skin::AttachmentMap::Entry &entry = entries.next(); + if (entry._slotIndex == slotIndex) { + names.add(entry._name); + } + } +} + +void Skin::findAttachmentsForSlot(size_t slotIndex, Vector &attachments) { + Skin::AttachmentMap::Entries entries = _attachments.getEntries(); + while (entries.hasNext()) { + Skin::AttachmentMap::Entry &entry = entries.next(); + if (entry._slotIndex == slotIndex) attachments.add(entry._attachment); + } +} + +const String &Skin::getName() { + return _name; +} + +Skin::AttachmentMap::Entries Skin::getAttachments() { + return _attachments.getEntries(); +} + +void Skin::attachAll(Skeleton &skeleton, Skin &oldSkin) { + Vector &slots = skeleton.getSlots(); + Skin::AttachmentMap::Entries entries = oldSkin.getAttachments(); + while (entries.hasNext()) { + Skin::AttachmentMap::Entry &entry = entries.next(); + int slotIndex = (int) entry._slotIndex; + Slot *slot = slots[slotIndex]; + + if (slot->getAttachment() == entry._attachment) { + Attachment *attachment = getAttachment(slotIndex, entry._name); + if (attachment) slot->setAttachment(attachment); + } + } +} + +void Skin::addSkin(Skin *other) { + for (size_t i = 0; i < other->getBones().size(); i++) + if (!_bones.contains(other->getBones()[i])) _bones.add(other->getBones()[i]); + + for (size_t i = 0; i < other->getConstraints().size(); i++) + if (!_constraints.contains(other->getConstraints()[i])) _constraints.add(other->getConstraints()[i]); + + AttachmentMap::Entries entries = other->getAttachments(); + while (entries.hasNext()) { + AttachmentMap::Entry &entry = entries.next(); + setAttachment(entry._slotIndex, entry._name, entry._attachment); + } +} + +void Skin::copySkin(Skin *other) { + for (size_t i = 0; i < other->getBones().size(); i++) + if (!_bones.contains(other->getBones()[i])) _bones.add(other->getBones()[i]); + + for (size_t i = 0; i < other->getConstraints().size(); i++) + if (!_constraints.contains(other->getConstraints()[i])) _constraints.add(other->getConstraints()[i]); + + AttachmentMap::Entries entries = other->getAttachments(); + while (entries.hasNext()) { + AttachmentMap::Entry &entry = entries.next(); + if (entry._attachment->getRTTI().isExactly(MeshAttachment::rtti)) + setAttachment(entry._slotIndex, entry._name, + static_cast(entry._attachment)->newLinkedMesh()); + else + 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/4.2/spine/Skin.h b/native/cocos/editor-support/spine/4.2/spine/Skin.h new file mode 100644 index 0000000000..b6de051764 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Skin.h @@ -0,0 +1,171 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Skin_h +#define Spine_Skin_h + +#include +#include +#include + +namespace spine { + class Attachment; + + class Skeleton; + + class BoneData; + + class ConstraintData; + +/// Stores attachments by slot index and attachment name. +/// See SkeletonData::getDefaultSkin, Skeleton::getSkin, and +/// http://esotericsoftware.com/spine-runtime-skins in the Spine Runtimes Guide. + class SP_API Skin : public SpineObject { + friend class Skeleton; + + public: + class SP_API AttachmentMap : public SpineObject { + friend class Skin; + + public: + struct SP_API Entry { + size_t _slotIndex; + String _name; + Attachment *_attachment; + + Entry(size_t slotIndex, const String &name, Attachment *attachment) : + _slotIndex(slotIndex), + _name(name), + _attachment(attachment) { + } + }; + + class SP_API Entries { + friend class AttachmentMap; + + public: + bool hasNext() { + while (true) { + if (_slotIndex >= _buckets.size()) return false; + if (_bucketIndex >= _buckets[_slotIndex].size()) { + _bucketIndex = 0; + ++_slotIndex; + continue; + }; + return true; + } + } + + Entry &next() { + Entry &result = _buckets[_slotIndex][_bucketIndex]; + ++_bucketIndex; + return result; + } + + protected: + Entries(Vector > &buckets) : _buckets(buckets), _slotIndex(0), _bucketIndex(0) { + } + + private: + Vector > &_buckets; + size_t _slotIndex; + size_t _bucketIndex; + }; + + void put(size_t slotIndex, const String &attachmentName, Attachment *attachment); + + Attachment *get(size_t slotIndex, const String &attachmentName); + + void remove(size_t slotIndex, const String &attachmentName); + + Entries getEntries(); + + protected: + AttachmentMap(); + + private: + + int findInBucket(Vector &, const String &attachmentName); + + Vector > _buckets; + }; + + explicit Skin(const String &name); + + ~Skin(); + + /// Adds an attachment to the skin for the specified slot index and name. + /// If the name already exists for the slot, the previous value is replaced. + void setAttachment(size_t slotIndex, const String &name, Attachment *attachment); + + /// Returns the attachment for the specified slot index and name, or NULL. + Attachment *getAttachment(size_t slotIndex, const String &name); + + // Removes the attachment from the skin. + void removeAttachment(size_t slotIndex, const String &name); + + /// Finds the skin keys for a given slot. The results are added to the passed array of names. + /// @param slotIndex The target slotIndex. To find the slot index, use SkeletonData::findSlot and SlotData::getIndex. + /// @param names Found skin key names will be added to this array. + void findNamesForSlot(size_t slotIndex, Vector &names); + + /// Finds the attachments for a given slot. The results are added to the passed array of Attachments. + /// @param slotIndex The target slotIndex. To find the slot index, use SkeletonData::findSlot and SlotData::getIndex. + /// @param attachments Found Attachments will be added to this array. + void findAttachmentsForSlot(size_t slotIndex, Vector &attachments); + + const String &getName(); + + /// Adds all attachments, bones, and constraints from the specified skin to this skin. + void addSkin(Skin *other); + + /// Adds all attachments, bones, and constraints from the specified skin to this skin. Attachments are deep copied. + void copySkin(Skin *other); + + AttachmentMap::Entries getAttachments(); + + Vector &getBones(); + + Vector &getConstraints(); + + Color &getColor() { return _color; } + + private: + const String _name; + AttachmentMap _attachments; + Vector _bones; + Vector _constraints; + Color _color; + + /// Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached. + void attachAll(Skeleton &skeleton, Skin &oldSkin); + }; +} + +#endif /* Spine_Skin_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Slot.cpp b/native/cocos/editor-support/spine/4.2/spine/Slot.cpp new file mode 100644 index 0000000000..e770b55b0c --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Slot.cpp @@ -0,0 +1,129 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include +#include +#include + +using namespace spine; + +Slot::Slot(SlotData &data, Bone &bone) : _data(data), + _bone(bone), + _skeleton(bone.getSkeleton()), + _color(1, 1, 1, 1), + _darkColor(0, 0, 0, 0), + _hasDarkColor(data.hasDarkColor()), + _attachment(NULL), + _attachmentState(0), + _sequenceIndex(0) { + setToSetupPose(); +} + +void Slot::setToSetupPose() { + _color.set(_data.getColor()); + if (_hasDarkColor) _darkColor.set(_data.getDarkColor()); + + const String &attachmentName = _data.getAttachmentName(); + if (attachmentName.length() > 0) { + _attachment = NULL; + setAttachment(_skeleton.getAttachment(_data.getIndex(), attachmentName)); + } else { + setAttachment(NULL); + } +} + +SlotData &Slot::getData() { + return _data; +} + +Bone &Slot::getBone() { + return _bone; +} + +Skeleton &Slot::getSkeleton() { + return _skeleton; +} + +Color &Slot::getColor() { + return _color; +} + +Color &Slot::getDarkColor() { + return _darkColor; +} + +bool Slot::hasDarkColor() { + return _hasDarkColor; +} + +Attachment *Slot::getAttachment() { + return _attachment; +} + +void Slot::setAttachment(Attachment *inValue) { + if (_attachment == inValue) { + return; + } + + if (!inValue || + !_attachment || + !inValue->getRTTI().instanceOf(VertexAttachment::rtti) || + !_attachment->getRTTI().instanceOf(VertexAttachment::rtti) || + static_cast(inValue)->getTimelineAttachment() != + static_cast(_attachment)->getTimelineAttachment()) { + _deform.clear(); + } + + _attachment = inValue; + _sequenceIndex = -1; +} + +int Slot::getAttachmentState() { + return _attachmentState; +} + +void Slot::setAttachmentState(int state) { + _attachmentState = state; +} + +Vector &Slot::getDeform() { + return _deform; +} + +int Slot::getSequenceIndex() { + return _sequenceIndex; +} + +void Slot::setSequenceIndex(int index) { + _sequenceIndex = index; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Slot.h b/native/cocos/editor-support/spine/4.2/spine/Slot.h new file mode 100644 index 0000000000..1f48efc798 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Slot.h @@ -0,0 +1,137 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Slot_h +#define Spine_Slot_h + +#include +#include +#include + +namespace spine { + class SlotData; + + class Bone; + + class Skeleton; + + class Attachment; + + class SP_API Slot : public SpineObject { + friend class VertexAttachment; + + friend class Skeleton; + + friend class SkeletonBounds; + + friend class SkeletonClipping; + + friend class AttachmentTimeline; + + friend class RGBATimeline; + + friend class RGBTimeline; + + friend class AlphaTimeline; + + friend class RGBA2Timeline; + + friend class RGB2Timeline; + + friend class DeformTimeline; + + friend class DrawOrderTimeline; + + friend class EventTimeline; + + friend class IkConstraintTimeline; + + friend class PathConstraintMixTimeline; + + friend class PathConstraintPositionTimeline; + + friend class PathConstraintSpacingTimeline; + + friend class ScaleTimeline; + + friend class ShearTimeline; + + friend class TransformConstraintTimeline; + + friend class TranslateTimeline; + + friend class TwoColorTimeline; + + public: + Slot(SlotData &data, Bone &bone); + + void setToSetupPose(); + + SlotData &getData(); + + Bone &getBone(); + + Skeleton &getSkeleton(); + + Color &getColor(); + + Color &getDarkColor(); + + bool hasDarkColor(); + + /// May be NULL. + Attachment *getAttachment(); + + void setAttachment(Attachment *inValue); + + int getAttachmentState(); + + void setAttachmentState(int state); + + Vector &getDeform(); + + int getSequenceIndex(); + + void setSequenceIndex(int index); + + private: + SlotData &_data; + Bone &_bone; + Skeleton &_skeleton; + Color _color; + Color _darkColor; + bool _hasDarkColor; + Attachment *_attachment; + int _attachmentState; + int _sequenceIndex; + Vector _deform; + }; +} + +#endif /* Spine_Slot_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/SlotData.cpp b/native/cocos/editor-support/spine/4.2/spine/SlotData.cpp new file mode 100644 index 0000000000..77dc5d037f --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SlotData.cpp @@ -0,0 +1,99 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +using namespace spine; + +SlotData::SlotData(int index, const String &name, BoneData &boneData) : _index(index), + _name(name), + _boneData(boneData), + _color(1, 1, 1, 1), + _darkColor(0, 0, 0, 0), + _hasDarkColor(false), + _attachmentName(), + _blendMode(BlendMode_Normal), + _visible(true) { + assert(_index >= 0); + assert(_name.length() > 0); +} + +int SlotData::getIndex() { + return _index; +} + +const String &SlotData::getName() { + return _name; +} + +BoneData &SlotData::getBoneData() { + return _boneData; +} + +Color &SlotData::getColor() { + return _color; +} + +Color &SlotData::getDarkColor() { + return _darkColor; +} + +bool SlotData::hasDarkColor() { + return _hasDarkColor; +} + +void SlotData::setHasDarkColor(bool inValue) { + _hasDarkColor = inValue; +} + +const String &SlotData::getAttachmentName() { + return _attachmentName; +} + +void SlotData::setAttachmentName(const String &inValue) { + _attachmentName = inValue; +} + +BlendMode SlotData::getBlendMode() { + return _blendMode; +} + +void SlotData::setBlendMode(BlendMode inValue) { + _blendMode = inValue; +} + +bool SlotData::isVisible() { + return _visible; +} + +void SlotData::setVisible(bool inValue) { + this->_visible = inValue; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/SlotData.h b/native/cocos/editor-support/spine/4.2/spine/SlotData.h new file mode 100644 index 0000000000..1ca9087959 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SlotData.h @@ -0,0 +1,128 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_SlotData_h +#define Spine_SlotData_h + +#include +#include +#include +#include + +namespace spine { + class BoneData; + + class SP_API SlotData : public SpineObject { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class AttachmentTimeline; + + friend class RGBATimeline; + + friend class RGBTimeline; + + friend class AlphaTimeline; + + friend class RGBA2Timeline; + + friend class RGB2Timeline; + + friend class DeformTimeline; + + friend class DrawOrderTimeline; + + friend class EventTimeline; + + friend class IkConstraintTimeline; + + friend class PathConstraintMixTimeline; + + friend class PathConstraintPositionTimeline; + + friend class PathConstraintSpacingTimeline; + + friend class ScaleTimeline; + + friend class ShearTimeline; + + friend class TransformConstraintTimeline; + + friend class TranslateTimeline; + + friend class TwoColorTimeline; + + public: + SlotData(int index, const String &name, BoneData &boneData); + + int getIndex(); + + const String &getName(); + + BoneData &getBoneData(); + + Color &getColor(); + + Color &getDarkColor(); + + bool hasDarkColor(); + + void setHasDarkColor(bool inValue); + + /// May be empty. + const String &getAttachmentName(); + + void setAttachmentName(const String &inValue); + + BlendMode getBlendMode(); + + void setBlendMode(BlendMode inValue); + + bool isVisible(); + + void setVisible(bool inValue); + + #ifndef __EMSCRIPTEN__ + private: + #endif + const int _index; + String _name; + BoneData &_boneData; + Color _color; + Color _darkColor; + + bool _hasDarkColor; + String _attachmentName; + BlendMode _blendMode; + bool _visible; + }; +} + +#endif /* Spine_SlotData_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/SpacingMode.h b/native/cocos/editor-support/spine/4.2/spine/SpacingMode.h new file mode 100644 index 0000000000..3685a5f770 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SpacingMode.h @@ -0,0 +1,42 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_SpacingMode_h +#define Spine_SpacingMode_h + +namespace spine { + enum SpacingMode { + SpacingMode_Length = 0, + SpacingMode_Fixed, + SpacingMode_Percent, + SpacingMode_Proportional + }; +} + +#endif /* Spine_SpacingMode_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/SpineObject.cpp b/native/cocos/editor-support/spine/4.2/spine/SpineObject.cpp new file mode 100644 index 0000000000..cc13e5ed31 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SpineObject.cpp @@ -0,0 +1,63 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 +#include + +using namespace spine; + +void *SpineObject::operator new(size_t sz) { + return SpineExtension::getInstance()->_calloc(sz, __FILE__, __LINE__); +} + +void *SpineObject::operator new(size_t sz, const char *file, int line) { + return SpineExtension::getInstance()->_calloc(sz, file, line); +} + +void *SpineObject::operator new(size_t sz, void *ptr) { + SP_UNUSED(sz); + return ptr; +} + +void SpineObject::operator delete(void *p, const char *file, int line) { + SpineExtension::free(p, file, line); +} + +void SpineObject::operator delete(void *p, void *mem) { + SP_UNUSED(mem); + SpineExtension::free(p, __FILE__, __LINE__); +} + +void SpineObject::operator delete(void *p) { + SpineExtension::free(p, __FILE__, __LINE__); +} + +SpineObject::~SpineObject() { + SpineExtension::beforeFree(this); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/SpineObject.h b/native/cocos/editor-support/spine/4.2/spine/SpineObject.h new file mode 100644 index 0000000000..f6571cee31 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SpineObject.h @@ -0,0 +1,69 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Object_h +#define Spine_Object_h + +#include +#include + +#include + +namespace spine { + class String; + + class SP_API SpineObject { + public: + void *operator new(size_t sz); + + void *operator new(size_t sz, const char *file, int line); + + void *operator new(size_t sz, void *ptr); + + void operator delete(void *p, const char *file, int line); + + void operator delete(void *p, void *mem); + + void operator delete(void *p); + + virtual ~SpineObject(); + }; +} + +#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/4.2/spine/SpineString.cpp b/native/cocos/editor-support/spine/4.2/spine/SpineString.cpp new file mode 100644 index 0000000000..4c613d129f --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SpineString.cpp @@ -0,0 +1,228 @@ +/****************************************************************************** + * 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), _tempowner(true) { +} + +String::String(const char *chars, size_t len, bool own) { + _tempowner = true; + 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*/, bool tofree /* = true*/) : String(chars, nullptr == chars ? 0 : strlen(chars), own) { + _tempowner = tofree; +} + + +String::String(const String &other) { + _tempowner = true; + 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 && _tempowner) { + 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 && _tempowner) { + 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 && _tempowner) { + 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 && _tempowner) { + 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; +} + +String &String::append(int other) { + char str[100]; + sprintf(str, "%i", other); + append(str); + return *this; +} + +String &String::append(float other) { + char str[100]; + sprintf(str, "%f", other); + append(str); + return *this; +} + +bool operator==(const String &a, const String &b) { + if (a._buffer == b._buffer) return true; + if (a._length != b._length) return false; + if (a._buffer && b._buffer) { + return strcmp(a._buffer, b._buffer) == 0; + } else { + return false; + } +} + +bool operator!=(const String &a, const String &b) { + return !(a == b); +} + +String::~String() { + if (_buffer && _tempowner) { + SpineExtension::free(_buffer, __SPINE_FILE__, __SPINE_LINE__); + } +} + +String String::substring(int startIndex, int length) const { + if (startIndex < 0 || startIndex >= (int)_length || length < 0 || startIndex + length > (int)_length) { + return String(); + } + char *subStr = SpineExtension::calloc(length + 1, __FILE__, __LINE__); + memcpy(subStr, _buffer + startIndex, length); + subStr[length] = '\0'; + return String(subStr, true, true); +} + +String String::substring(int startIndex) const { + if (startIndex < 0 || startIndex >= (int)_length) { + return String(); + } + int length = (int)_length - startIndex; + char *subStr = SpineExtension::calloc(length + 1, __FILE__, __LINE__); + memcpy(subStr, _buffer + startIndex, length); + subStr[length] = '\0'; + return String(subStr, true, true); +} + +int String::lastIndexOf(const char c) const { + for (int i = (int)length() - 1; i >= 0; i--) { + if (buffer()[i] == c) return i; + } + return -1; +} + +bool String::startsWith(const String &needle) const { + if (needle.length() > length()) return false; + for (int i = 0; i < (int)needle.length(); i++) { + if (buffer()[i] != needle.buffer()[i]) return false; + } + return true; +} + +} // namespace spine diff --git a/native/cocos/editor-support/spine/4.2/spine/SpineString.h b/native/cocos/editor-support/spine/4.2/spine/SpineString.h new file mode 100644 index 0000000000..66ea3be7e5 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/SpineString.h @@ -0,0 +1,87 @@ +/****************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef SPINE_STRING_H +#define SPINE_STRING_H + +#include +#include +#include +#include + +namespace spine { +class SP_API String : public SpineObject { +public: + String(); + String(const char *chars, size_t len, bool own); + String(const char *chars, bool own = false, bool tofree = true); + String(const String &other); + ~String(); + + inline size_t length() const { + return _length; + } + + inline bool isEmpty() const { + return _length == 0; + } + + inline const char *buffer() const { + return _buffer; + } + + String substring(int startIndex, int length) const; + String substring(int startIndex) const; + int lastIndexOf(const char c) const; + bool startsWith(const String &needle) const; + + + void own(const String &other); + void own(const char *chars); + void unown(); + String &operator=(const String &other); + String &operator=(const char *chars); + + String &append(const char *chars); + String &append(const String &other); + + String &append(int other); + String &append(float other); + + friend bool operator==(const String &a, const String &b); + friend bool operator!=(const String &a, const String &b); + +private: + mutable size_t _length; + mutable char *_buffer; + mutable bool _tempowner; +}; +} // namespace spine + +#endif //SPINE_STRING_H diff --git a/native/cocos/editor-support/spine/4.2/spine/TextureLoader.cpp b/native/cocos/editor-support/spine/4.2/spine/TextureLoader.cpp new file mode 100644 index 0000000000..fc96cdc0d2 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TextureLoader.cpp @@ -0,0 +1,38 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +namespace spine { + TextureLoader::TextureLoader() { + } + + TextureLoader::~TextureLoader() { + } +}// namespace spine diff --git a/native/cocos/editor-support/spine/4.2/spine/TextureLoader.h b/native/cocos/editor-support/spine/4.2/spine/TextureLoader.h new file mode 100644 index 0000000000..057fd55797 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TextureLoader.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_TextureLoader_h +#define Spine_TextureLoader_h + +#include +#include + +namespace spine { + class AtlasPage; + + class SP_API TextureLoader : public SpineObject { + public: + TextureLoader(); + + virtual ~TextureLoader(); + + virtual void load(AtlasPage &page, const String &path) = 0; + + virtual void unload(void *texture) = 0; + }; +} + +#endif /* Spine_TextureLoader_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/TextureRegion.h b/native/cocos/editor-support/spine/4.2/spine/TextureRegion.h new file mode 100644 index 0000000000..19ed111678 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TextureRegion.h @@ -0,0 +1,50 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_TextureRegion_h +#define Spine_TextureRegion_h + +#include + +namespace spine { + class SP_API TextureRegion : public SpineObject { + public: + void *rendererObject; + float u, v, u2, v2; + int degrees; + float offsetX, offsetY; + int width, height; + int originalWidth, originalHeight; + + TextureRegion(): rendererObject(NULL), u(0), v(0), u2(0), v2(0), degrees(0), offsetX(0), offsetY(0), width(0), height(0), originalWidth(0), originalHeight(0) {}; + ~TextureRegion() {}; + }; +} + +#endif diff --git a/native/cocos/editor-support/spine/4.2/spine/Timeline.cpp b/native/cocos/editor-support/spine/4.2/spine/Timeline.cpp new file mode 100644 index 0000000000..9a110b93d2 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Timeline.cpp @@ -0,0 +1,73 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +namespace spine { + RTTI_IMPL_NOPARENT(Timeline) + + Timeline::Timeline(size_t frameCount, size_t frameEntries) + : _propertyIds(), _frames(), _frameEntries(frameEntries) { + _frames.setSize(frameCount * frameEntries, 0); + } + + Timeline::~Timeline() { + } + + Vector &Timeline::getPropertyIds() { + return _propertyIds; + } + + void Timeline::setPropertyIds(PropertyId propertyIds[], size_t propertyIdsCount) { + _propertyIds.clear(); + _propertyIds.ensureCapacity(propertyIdsCount); + for (size_t i = 0; i < propertyIdsCount; i++) { + _propertyIds.add(propertyIds[i]); + } + } + + size_t Timeline::getFrameCount() { + return _frames.size() / _frameEntries; + } + + Vector &Timeline::getFrames() { + return _frames; + } + + size_t Timeline::getFrameEntries() { + return _frameEntries; + } + + float Timeline::getDuration() { + return _frames[_frames.size() - getFrameEntries()]; + } +}// namespace spine diff --git a/native/cocos/editor-support/spine/4.2/spine/Timeline.h b/native/cocos/editor-support/spine/4.2/spine/Timeline.h new file mode 100644 index 0000000000..c2acdf51a8 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Timeline.h @@ -0,0 +1,86 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Timeline_h +#define Spine_Timeline_h + +#include +#include +#include +#include +#include +#include + +namespace spine { + class Skeleton; + + class Event; + + class SP_API Timeline : public SpineObject { + RTTI_DECL + + public: + Timeline(size_t frameCount, size_t frameEntries); + + virtual ~Timeline(); + + /// Sets the value(s) for the specified time. + /// @param skeleton The skeleton the timeline is being applied to. This provides access to the bones, slots, and other skeleton components the timeline may change. + /// @param lastTime lastTime The time this timeline was last applied. Timelines such as EventTimeline trigger only at specific times rather than every frame. In that case, the timeline triggers everything between lastTime (exclusive) and time (inclusive). + /// @param time The time within the animation. Most timelines find the key before and the key after this time so they can interpolate between the keys. + /// @param pEvents If any events are fired, they are added to this array. Can be NULL to ignore firing events or if the timeline does not fire events. May be NULL. + /// @param alpha alpha 0 applies the current or setup pose value (depending on pose parameter). 1 applies the timeline + /// value. Between 0 and 1 applies a value between the current or setup pose and the timeline value. By adjusting alpha over + /// time, an animation can be mixed in or out. alpha can also be useful to apply animations on top of each other (layered). + /// @param blend Controls how mixing is applied when alpha is than 1. + /// @param direction Indicates whether the timeline is mixing in or out. Used by timelines which perform instant transitions such as DrawOrderTimeline and AttachmentTimeline. + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction) = 0; + + size_t getFrameEntries(); + + size_t getFrameCount(); + + Vector &getFrames(); + + float getDuration(); + + virtual Vector &getPropertyIds(); + + protected: + void setPropertyIds(PropertyId propertyIds[], size_t propertyIdsCount); + + Vector _propertyIds; + Vector _frames; + size_t _frameEntries; + }; +} + +#endif /* Spine_Timeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/TransformConstraint.cpp b/native/cocos/editor-support/spine/4.2/spine/TransformConstraint.cpp new file mode 100644 index 0000000000..fb848cc63e --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TransformConstraint.cpp @@ -0,0 +1,350 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include +#include + +#include + +using namespace spine; + +RTTI_IMPL(TransformConstraint, Updatable) + +TransformConstraint::TransformConstraint(TransformConstraintData &data, Skeleton &skeleton) : Updatable(), + _data(data), + _target(skeleton.findBone( + data.getTarget()->getName())), + _mixRotate( + data.getMixRotate()), + _mixX(data.getMixX()), + _mixY(data.getMixY()), + _mixScaleX( + data.getMixScaleX()), + _mixScaleY( + data.getMixScaleY()), + _mixShearY( + data.getMixShearY()), + _active(false) { + _bones.ensureCapacity(_data.getBones().size()); + for (size_t i = 0; i < _data.getBones().size(); ++i) { + BoneData *boneData = _data.getBones()[i]; + _bones.add(skeleton.findBone(boneData->getName())); + } +} + +void TransformConstraint::update(Physics) { + if (_mixRotate == 0 && _mixX == 0 && _mixY == 0 && _mixScaleX == 0 && _mixScaleY == 0 && _mixShearY == 0) return; + + if (_data.isLocal()) { + if (_data.isRelative()) + applyRelativeLocal(); + else + applyAbsoluteLocal(); + } else { + if (_data.isRelative()) + applyRelativeWorld(); + else + applyAbsoluteWorld(); + } +} + +int TransformConstraint::getOrder() { + return (int) _data.getOrder(); +} + +TransformConstraintData &TransformConstraint::getData() { + return _data; +} + +Vector &TransformConstraint::getBones() { + return _bones; +} + +Bone *TransformConstraint::getTarget() { + return _target; +} + +void TransformConstraint::setTarget(Bone *inValue) { + _target = inValue; +} + +float TransformConstraint::getMixRotate() { + return _mixRotate; +} + +void TransformConstraint::setMixRotate(float inValue) { + _mixRotate = inValue; +} + +float TransformConstraint::getMixX() { + return _mixX; +} + +void TransformConstraint::setMixX(float inValue) { + _mixX = inValue; +} + +float TransformConstraint::getMixY() { + return _mixY; +} + +void TransformConstraint::setMixY(float inValue) { + _mixY = inValue; +} + +void TransformConstraint::setMixScaleX(float inValue) { + _mixScaleX = inValue; +} + +float TransformConstraint::getMixScaleX() { + return _mixScaleX; +} + +float TransformConstraint::getMixScaleY() { + return _mixScaleY; +} + +void TransformConstraint::setMixScaleY(float inValue) { + _mixScaleY = inValue; +} + +float TransformConstraint::getMixShearY() { + return _mixShearY; +} + +void TransformConstraint::setMixShearY(float inValue) { + _mixShearY = inValue; +} + +void TransformConstraint::applyAbsoluteWorld() { + float mixRotate = _mixRotate, mixX = _mixX, mixY = _mixY, mixScaleX = _mixScaleX, mixScaleY = _mixScaleY, mixShearY = _mixShearY; + bool translate = mixX != 0 || mixY != 0; + Bone &target = *_target; + float ta = target._a, tb = target._b, tc = target._c, td = target._d; + float degRadReflect = ta * td - tb * tc > 0 ? MathUtil::Deg_Rad : -MathUtil::Deg_Rad; + float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect; + + for (size_t i = 0; i < _bones.size(); ++i) { + Bone *item = _bones[i]; + Bone &bone = *item; + + if (mixRotate != 0) { + float a = bone._a, b = bone._b, c = bone._c, d = bone._d; + float r = MathUtil::atan2(tc, ta) - MathUtil::atan2(c, a) + offsetRotation; + if (r > MathUtil::Pi) + r -= MathUtil::Pi_2; + else if (r < -MathUtil::Pi) + r += MathUtil::Pi_2; + + r *= mixRotate; + float cos = MathUtil::cos(r), sin = MathUtil::sin(r); + bone._a = cos * a - sin * c; + bone._b = cos * b - sin * d; + bone._c = sin * a + cos * c; + bone._d = sin * b + cos * d; + } + + if (translate) { + float tx, ty; + target.localToWorld(_data._offsetX, _data._offsetY, tx, ty); + bone._worldX += (tx - bone._worldX) * mixX; + bone._worldY += (ty - bone._worldY) * mixY; + } + + if (mixScaleX > 0) { + float s = MathUtil::sqrt(bone._a * bone._a + bone._c * bone._c); + if (s != 0) s = (s + (MathUtil::sqrt(ta * ta + tc * tc) - s + _data._offsetScaleX) * mixScaleX) / s; + bone._a *= s; + bone._c *= s; + } + + if (mixScaleY > 0) { + float s = MathUtil::sqrt(bone._b * bone._b + bone._d * bone._d); + if (s != 0) s = (s + (MathUtil::sqrt(tb * tb + td * td) - s + _data._offsetScaleY) * mixScaleY) / s; + bone._b *= s; + bone._d *= s; + } + + if (mixShearY > 0) { + float b = bone._b, d = bone._d; + float by = MathUtil::atan2(d, b); + float r = MathUtil::atan2(td, tb) - MathUtil::atan2(tc, ta) - (by - MathUtil::atan2(bone._c, bone._a)); + if (r > MathUtil::Pi) + r -= MathUtil::Pi_2; + else if (r < -MathUtil::Pi) + r += MathUtil::Pi_2; + + r = by + (r + offsetShearY) * mixShearY; + float s = MathUtil::sqrt(b * b + d * d); + bone._b = MathUtil::cos(r) * s; + bone._d = MathUtil::sin(r) * s; + } + + bone.updateAppliedTransform(); + } +} + +void TransformConstraint::applyRelativeWorld() { + float mixRotate = _mixRotate, mixX = _mixX, mixY = _mixY, mixScaleX = _mixScaleX, mixScaleY = _mixScaleY, mixShearY = _mixShearY; + bool translate = mixX != 0 || mixY != 0; + Bone &target = *_target; + float ta = target._a, tb = target._b, tc = target._c, td = target._d; + float degRadReflect = ta * td - tb * tc > 0 ? MathUtil::Deg_Rad : -MathUtil::Deg_Rad; + float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect; + for (size_t i = 0; i < _bones.size(); ++i) { + Bone *item = _bones[i]; + Bone &bone = *item; + + if (mixRotate != 0) { + float a = bone._a, b = bone._b, c = bone._c, d = bone._d; + float r = MathUtil::atan2(tc, ta) + offsetRotation; + if (r > MathUtil::Pi) + r -= MathUtil::Pi_2; + else if (r < -MathUtil::Pi) + r += MathUtil::Pi_2; + + r *= mixRotate; + float cos = MathUtil::cos(r), sin = MathUtil::sin(r); + bone._a = cos * a - sin * c; + bone._b = cos * b - sin * d; + bone._c = sin * a + cos * c; + bone._d = sin * b + cos * d; + } + + if (translate) { + float tx, ty; + target.localToWorld(_data._offsetX, _data._offsetY, tx, ty); + bone._worldX += tx * mixX; + bone._worldY += ty * mixY; + } + + if (mixScaleX != 0) { + float s = (MathUtil::sqrt(ta * ta + tc * tc) - 1 + _data._offsetScaleX) * mixScaleX + 1; + bone._a *= s; + bone._c *= s; + } + if (mixScaleY != 0) { + float s = (MathUtil::sqrt(tb * tb + td * td) - 1 + _data._offsetScaleY) * mixScaleY + 1; + bone._b *= s; + bone._d *= s; + } + + if (mixShearY > 0) { + float r = MathUtil::atan2(td, tb) - MathUtil::atan2(tc, ta); + if (r > MathUtil::Pi) + r -= MathUtil::Pi_2; + else if (r < -MathUtil::Pi) + r += MathUtil::Pi_2; + + float b = bone._b, d = bone._d; + r = MathUtil::atan2(d, b) + (r - MathUtil::Pi / 2 + offsetShearY) * mixShearY; + float s = MathUtil::sqrt(b * b + d * d); + bone._b = MathUtil::cos(r) * s; + bone._d = MathUtil::sin(r) * s; + } + + bone.updateAppliedTransform(); + } +} + +void TransformConstraint::applyAbsoluteLocal() { + float mixRotate = _mixRotate, mixX = _mixX, mixY = _mixY, mixScaleX = _mixScaleX, mixScaleY = _mixScaleY, mixShearY = _mixShearY; + Bone &target = *_target; + + for (size_t i = 0; i < _bones.size(); ++i) { + Bone *item = _bones[i]; + Bone &bone = *item; + + float rotation = bone._arotation; + if (mixRotate != 0) { + float r = target._arotation - rotation + _data._offsetRotation; + r -= MathUtil::ceil(r / 360 - 0.5) * 360; + rotation += r * mixRotate; + } + + float x = bone._ax, y = bone._ay; + x += (target._ax - x + _data._offsetX) * mixX; + y += (target._ay - y + _data._offsetY) * mixY; + + float scaleX = bone._ascaleX, scaleY = bone._ascaleY; + if (mixScaleX != 0 && scaleX != 0) + scaleX = (scaleX + (target._ascaleX - scaleX + _data._offsetScaleX) * mixScaleX) / scaleX; + if (mixScaleY != 0 && scaleY != 0) + scaleY = (scaleY + (target._ascaleY - scaleY + _data._offsetScaleY) * mixScaleY) / scaleY; + + float shearY = bone._ashearY; + if (mixShearY != 0) { + float r = target._ashearY - shearY + _data._offsetShearY; + r -= MathUtil::ceil(r / 360 - 0.5) * 360; + bone._shearY += r * mixShearY; + } + + bone.updateWorldTransform(x, y, rotation, scaleX, scaleY, bone._ashearX, shearY); + } +} + +void TransformConstraint::applyRelativeLocal() { + float mixRotate = _mixRotate, mixX = _mixX, mixY = _mixY, mixScaleX = _mixScaleX, mixScaleY = _mixScaleY, mixShearY = _mixShearY; + Bone &target = *_target; + + for (size_t i = 0; i < _bones.size(); ++i) { + Bone *item = _bones[i]; + Bone &bone = *item; + + float rotation = bone._arotation + (target._arotation + _data._offsetRotation) * mixRotate; + float x = bone._ax + (target._ax + _data._offsetX) * mixX; + float y = bone._ay + (target._ay + _data._offsetY) * mixY; + float scaleX = bone._ascaleX * (((target._ascaleX - 1 + _data._offsetScaleX) * mixScaleX) + 1); + float scaleY = bone._ascaleY * (((target._ascaleY - 1 + _data._offsetScaleY) * mixScaleY) + 1); + float shearY = bone._ashearY + (target._ashearY + _data._offsetShearY) * mixShearY; + + bone.updateWorldTransform(x, y, rotation, scaleX, scaleY, bone._ashearX, shearY); + } +} + +bool TransformConstraint::isActive() { + return _active; +} + +void TransformConstraint::setActive(bool inValue) { + _active = inValue; +} + +void TransformConstraint::setToSetupPose() { + TransformConstraintData &data = this->_data; + this->_mixRotate = data._mixRotate; + this->_mixX = data._mixX; + this->_mixY = data._mixY; + this->_mixScaleX = data._mixScaleX; + this->_mixScaleY = data._mixScaleY; + this->_mixShearY = data._mixShearY; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/TransformConstraint.h b/native/cocos/editor-support/spine/4.2/spine/TransformConstraint.h new file mode 100644 index 0000000000..92efafa995 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TransformConstraint.h @@ -0,0 +1,115 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_TransformConstraint_h +#define Spine_TransformConstraint_h + +#include + +#include + +namespace spine { + class TransformConstraintData; + + class Skeleton; + + class Bone; + + class SP_API TransformConstraint : public Updatable { + friend class Skeleton; + + friend class TransformConstraintTimeline; + + RTTI_DECL + + public: + TransformConstraint(TransformConstraintData &data, Skeleton &skeleton); + + virtual void update(Physics physics); + + virtual int getOrder(); + + TransformConstraintData &getData(); + + Vector &getBones(); + + Bone *getTarget(); + + void setTarget(Bone *inValue); + + float getMixRotate(); + + void setMixRotate(float inValue); + + float getMixX(); + + void setMixX(float inValue); + + float getMixY(); + + void setMixY(float inValue); + + float getMixScaleX(); + + void setMixScaleX(float inValue); + + float getMixScaleY(); + + void setMixScaleY(float inValue); + + float getMixShearY(); + + void setMixShearY(float inValue); + + bool isActive(); + + void setActive(bool inValue); + + void setToSetupPose(); + + #ifndef __EMSCRIPTEN__ + private: + #endif + TransformConstraintData &_data; + Vector _bones; + Bone *_target; + float _mixRotate, _mixX, _mixY, _mixScaleX, _mixScaleY, _mixShearY; + bool _active; + + void applyAbsoluteWorld(); + + void applyRelativeWorld(); + + void applyAbsoluteLocal(); + + void applyRelativeLocal(); + }; +} + +#endif /* Spine_TransformConstraint_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/TransformConstraintData.cpp b/native/cocos/editor-support/spine/4.2/spine/TransformConstraintData.cpp new file mode 100644 index 0000000000..a6645241d3 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TransformConstraintData.cpp @@ -0,0 +1,180 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +#include + +using namespace spine; + +RTTI_IMPL(TransformConstraintData, ConstraintData) + +TransformConstraintData::TransformConstraintData(const String &name) : ConstraintData(name), + _target(NULL), + _mixRotate(0), + _mixX(0), + _mixY(0), + _mixScaleX(0), + _mixScaleY(0), + _mixShearY(0), + _offsetRotation(0), + _offsetX(0), + _offsetY(0), + _offsetScaleX(0), + _offsetScaleY(0), + _offsetShearY(0), + _relative(false), + _local(false) { +} + +Vector &TransformConstraintData::getBones() { + return _bones; +} + +BoneData *TransformConstraintData::getTarget() { + return _target; +} + +float TransformConstraintData::getMixRotate() { + return _mixRotate; +} + +float TransformConstraintData::getMixX() { + return _mixX; +} + +float TransformConstraintData::getMixY() { + return _mixY; +} + +float TransformConstraintData::getMixScaleX() { + return _mixScaleX; +} + +float TransformConstraintData::getMixScaleY() { + return _mixScaleY; +} + +float TransformConstraintData::getMixShearY() { + return _mixShearY; +} + +float TransformConstraintData::getOffsetRotation() { + return _offsetRotation; +} + +float TransformConstraintData::getOffsetX() { + return _offsetX; +} + +float TransformConstraintData::getOffsetY() { + return _offsetY; +} + +float TransformConstraintData::getOffsetScaleX() { + return _offsetScaleX; +} + +float TransformConstraintData::getOffsetScaleY() { + return _offsetScaleY; +} + +float TransformConstraintData::getOffsetShearY() { + return _offsetShearY; +} + +bool TransformConstraintData::isRelative() { + return _relative; +} + +bool TransformConstraintData::isLocal() { + return _local; +} + +void TransformConstraintData::setTarget(BoneData *target) { + _target = target; +} + +void TransformConstraintData::setMixRotate(float mixRotate) { + _mixRotate = mixRotate; +} + +void TransformConstraintData::setMixX(float mixX) { + _mixX = mixX; +} + +void TransformConstraintData::setMixY(float mixY) { + _mixY = mixY; +} + +void TransformConstraintData::setMixScaleX(float mixScaleX) { + _mixScaleX = mixScaleX; +} + +void TransformConstraintData::setMixScaleY(float mixScaleY) { + _mixScaleY = mixScaleY; +} + +void TransformConstraintData::setMixShearY(float mixShearY) { + _mixShearY = mixShearY; +} + +void TransformConstraintData::setOffsetRotation(float offsetRotation) { + _offsetRotation = offsetRotation; +} + +void TransformConstraintData::setOffsetX(float offsetX) { + _offsetX = offsetX; +} + +void TransformConstraintData::setOffsetY(float offsetY) { + _offsetY = offsetY; +} + +void TransformConstraintData::setOffsetScaleX(float offsetScaleX) { + _offsetScaleX = offsetScaleX; +} + +void TransformConstraintData::setOffsetScaleY(float offsetScaleY) { + _offsetScaleY = offsetScaleY; +} + +void TransformConstraintData::setOffsetShearY(float offsetShearY) { + _offsetShearY = offsetShearY; +} + +void TransformConstraintData::setRelative(bool isRelative) { + _relative = isRelative; +} + +void TransformConstraintData::setLocal(bool isLocal) { + _local = isLocal; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/TransformConstraintData.h b/native/cocos/editor-support/spine/4.2/spine/TransformConstraintData.h new file mode 100644 index 0000000000..46d5013b30 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TransformConstraintData.h @@ -0,0 +1,128 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_TransformConstraintData_h +#define Spine_TransformConstraintData_h + +#include +#include +#include +#include + +namespace spine { + class BoneData; + + class SP_API TransformConstraintData : public ConstraintData { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class TransformConstraint; + + friend class Skeleton; + + friend class TransformConstraintTimeline; + + public: + RTTI_DECL + + explicit TransformConstraintData(const String &name); + + Vector &getBones(); + + BoneData *getTarget(); + + void setTarget(BoneData *target); + + float getMixRotate(); + + void setMixRotate(float mixRotate); + + float getMixX(); + + void setMixX(float mixX); + + float getMixY(); + + void setMixY(float mixY); + + float getMixScaleX(); + + void setMixScaleX(float mixScaleX); + + float getMixScaleY(); + + void setMixScaleY(float mixScaleY); + + float getMixShearY(); + + void setMixShearY(float mixShearY); + + float getOffsetRotation(); + + void setOffsetRotation(float offsetRotation); + + float getOffsetX(); + + void setOffsetX(float offsetX); + + float getOffsetY(); + + void setOffsetY(float offsetY); + + float getOffsetScaleX(); + + void setOffsetScaleX(float offsetScaleX); + + float getOffsetScaleY(); + + void setOffsetScaleY(float offsetScaleY); + + float getOffsetShearY(); + + void setOffsetShearY(float offsetShearY); + + bool isRelative(); + + void setRelative(bool isRelative); + + bool isLocal(); + + void setLocal(bool isLocal); + + private: + Vector _bones; + BoneData *_target; + float _mixRotate, _mixX, _mixY, _mixScaleX, _mixScaleY, _mixShearY; + float _offsetRotation, _offsetX, _offsetY, _offsetScaleX, _offsetScaleY, _offsetShearY; + bool _relative, _local; + }; +} + +#endif /* Spine_TransformConstraintData_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/TransformConstraintTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/TransformConstraintTimeline.cpp new file mode 100644 index 0000000000..c0d6a05856 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TransformConstraintTimeline.cpp @@ -0,0 +1,157 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace spine; +const int TransformConstraintTimeline::ENTRIES = 7; +RTTI_IMPL(TransformConstraintTimeline, CurveTimeline) + +TransformConstraintTimeline::TransformConstraintTimeline(size_t frameCount, size_t bezierCount, + int transformConstraintIndex) : CurveTimeline(frameCount, + TransformConstraintTimeline::ENTRIES, + bezierCount), + _constraintIndex( + transformConstraintIndex) { + PropertyId ids[] = {((PropertyId) Property_TransformConstraint << 32) | transformConstraintIndex}; + setPropertyIds(ids, 1); +} + +void TransformConstraintTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, + float alpha, MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + TransformConstraint *constraintP = skeleton._transformConstraints[_constraintIndex]; + TransformConstraint &constraint = *constraintP; + if (!constraint.isActive()) return; + + TransformConstraintData &data = constraint._data; + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + constraint._mixRotate = data._mixRotate; + constraint._mixX = data._mixX; + constraint._mixY = data._mixY; + constraint._mixScaleX = data._mixScaleX; + constraint._mixScaleY = data._mixScaleY; + constraint._mixShearY = data._mixShearY; + return; + case MixBlend_First: + constraint._mixRotate += (data._mixRotate - constraint._mixRotate) * alpha; + constraint._mixX += (data._mixX - constraint._mixX) * alpha; + constraint._mixY += (data._mixY - constraint._mixY) * alpha; + constraint._mixScaleX += (data._mixScaleX - constraint._mixScaleX) * alpha; + constraint._mixScaleY += (data._mixScaleY - constraint._mixScaleY) * alpha; + constraint._mixShearY += (data._mixShearY - constraint._mixShearY) * alpha; + return; + default: + return; + } + } + + float rotate, x, y, scaleX, scaleY, shearY; + int i = Animation::search(_frames, time, TransformConstraintTimeline::ENTRIES); + int curveType = (int) _curves[i / TransformConstraintTimeline::ENTRIES]; + switch (curveType) { + case TransformConstraintTimeline::LINEAR: { + float before = _frames[i]; + rotate = _frames[i + ROTATE]; + x = _frames[i + X]; + y = _frames[i + Y]; + scaleX = _frames[i + SCALEX]; + scaleY = _frames[i + SCALEY]; + shearY = _frames[i + SHEARY]; + float t = (time - before) / (_frames[i + ENTRIES] - before); + rotate += (_frames[i + ENTRIES + ROTATE] - rotate) * t; + x += (_frames[i + ENTRIES + X] - x) * t; + y += (_frames[i + ENTRIES + Y] - y) * t; + scaleX += (_frames[i + ENTRIES + SCALEX] - scaleX) * t; + scaleY += (_frames[i + ENTRIES + SCALEY] - scaleY) * t; + shearY += (_frames[i + ENTRIES + SHEARY] - shearY) * t; + break; + } + case TransformConstraintTimeline::STEPPED: { + rotate = _frames[i + ROTATE]; + x = _frames[i + X]; + y = _frames[i + Y]; + scaleX = _frames[i + SCALEX]; + scaleY = _frames[i + SCALEY]; + shearY = _frames[i + SHEARY]; + break; + } + default: { + rotate = getBezierValue(time, i, ROTATE, curveType - BEZIER); + x = getBezierValue(time, i, X, curveType + BEZIER_SIZE - BEZIER); + y = getBezierValue(time, i, Y, curveType + BEZIER_SIZE * 2 - BEZIER); + scaleX = getBezierValue(time, i, SCALEX, curveType + BEZIER_SIZE * 3 - BEZIER); + scaleY = getBezierValue(time, i, SCALEY, curveType + BEZIER_SIZE * 4 - BEZIER); + shearY = getBezierValue(time, i, SHEARY, curveType + BEZIER_SIZE * 5 - BEZIER); + } + } + + if (blend == MixBlend_Setup) { + constraint._mixRotate = data._mixRotate + (rotate - data._mixRotate) * alpha; + constraint._mixX = data._mixX + (x - data._mixX) * alpha; + constraint._mixY = data._mixY + (y - data._mixY) * alpha; + constraint._mixScaleX = data._mixScaleX + (scaleX - data._mixScaleX) * alpha; + constraint._mixScaleY = data._mixScaleY + (scaleY - data._mixScaleY) * alpha; + constraint._mixShearY = data._mixShearY + (shearY - data._mixShearY) * alpha; + } else { + constraint._mixRotate += (rotate - constraint._mixRotate) * alpha; + constraint._mixX += (x - constraint._mixX) * alpha; + constraint._mixY += (y - constraint._mixY) * alpha; + constraint._mixScaleX += (scaleX - constraint._mixScaleX) * alpha; + constraint._mixScaleY += (scaleY - constraint._mixScaleY) * alpha; + constraint._mixShearY += (shearY - constraint._mixShearY) * alpha; + } +} + +void TransformConstraintTimeline::setFrame(size_t frame, float time, float mixRotate, float mixX, float mixY, + float mixScaleX, float mixScaleY, float mixShearY) { + frame *= ENTRIES; + _frames[frame] = time; + _frames[frame + ROTATE] = mixRotate; + _frames[frame + X] = mixX; + _frames[frame + Y] = mixY; + _frames[frame + SCALEX] = mixScaleX; + _frames[frame + SCALEY] = mixScaleY; + _frames[frame + SHEARY] = mixShearY; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/TransformConstraintTimeline.h b/native/cocos/editor-support/spine/4.2/spine/TransformConstraintTimeline.h new file mode 100644 index 0000000000..49cc407120 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TransformConstraintTimeline.h @@ -0,0 +1,72 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_TransformConstraintTimeline_h +#define Spine_TransformConstraintTimeline_h + +#include + +namespace spine { + + class SP_API TransformConstraintTimeline : public CurveTimeline { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit TransformConstraintTimeline(size_t frameCount, size_t bezierCount, int transformConstraintIndex); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + void setFrame(size_t frameIndex, float time, float mixRotate, float mixX, float mixY, float mixScaleX, + float mixScaleY, float mixShearY); + + int getTransformConstraintIndex() { return _constraintIndex; } + + void setTransformConstraintIndex(int inValue) { _constraintIndex = inValue; } + #ifndef __EMSCRIPTEN__ + private: + #endif + int _constraintIndex; + + static const int ENTRIES; + static const int ROTATE = 1; + static const int X = 2; + static const int Y = 3; + static const int SCALEX = 4; + static const int SCALEY = 5; + static const int SHEARY = 6; + }; +} + +#endif /* Spine_TransformConstraintTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/TranslateTimeline.cpp b/native/cocos/editor-support/spine/4.2/spine/TranslateTimeline.cpp new file mode 100644 index 0000000000..262a477c3b --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TranslateTimeline.cpp @@ -0,0 +1,162 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include +#include + +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(TranslateTimeline, CurveTimeline2) + +TranslateTimeline::TranslateTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline2(frameCount, + bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_X << 32) | boneIndex, + ((PropertyId) Property_Y << 32) | boneIndex}; + setPropertyIds(ids, 2); +} + +TranslateTimeline::~TranslateTimeline() { +} + +void TranslateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Bone *bone = skeleton._bones[_boneIndex]; + if (!bone->_active) return; + + if (time < _frames[0]) { + switch (blend) { + case MixBlend_Setup: + bone->_x = bone->_data._x; + bone->_y = bone->_data._y; + return; + case MixBlend_First: + bone->_x += (bone->_data._x - bone->_x) * alpha; + bone->_y += (bone->_data._y - bone->_y) * alpha; + default: { + } + } + return; + } + + float x = 0, y = 0; + int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); + int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; + switch (curveType) { + case CurveTimeline::LINEAR: { + float before = _frames[i]; + x = _frames[i + CurveTimeline2::VALUE1]; + y = _frames[i + CurveTimeline2::VALUE2]; + float t = (time - before) / (_frames[i + CurveTimeline2::ENTRIES] - before); + x += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE1] - x) * t; + y += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE2] - y) * t; + break; + } + case CurveTimeline::STEPPED: { + x = _frames[i + CurveTimeline2::VALUE1]; + y = _frames[i + CurveTimeline2::VALUE2]; + break; + } + default: { + x = getBezierValue(time, i, CurveTimeline2::VALUE1, curveType - CurveTimeline::BEZIER); + y = getBezierValue(time, i, CurveTimeline2::VALUE2, + curveType + CurveTimeline::BEZIER_SIZE - CurveTimeline::BEZIER); + } + } + + switch (blend) { + case MixBlend_Setup: + bone->_x = bone->_data._x + x * alpha; + bone->_y = bone->_data._y + y * alpha; + break; + case MixBlend_First: + case MixBlend_Replace: + bone->_x += (bone->_data._x + x - bone->_x) * alpha; + bone->_y += (bone->_data._y + y - bone->_y) * alpha; + break; + case MixBlend_Add: + bone->_x += x * alpha; + bone->_y += y * alpha; + } +} + +RTTI_IMPL(TranslateXTimeline, CurveTimeline1) + +TranslateXTimeline::TranslateXTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1( + frameCount, bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_X << 32) | boneIndex}; + setPropertyIds(ids, 1); +} + +TranslateXTimeline::~TranslateXTimeline() { +} + +void TranslateXTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Bone *bone = skeleton._bones[_boneIndex]; + if (bone->_active) bone->_x = getRelativeValue(time, alpha, blend, bone->_x, bone->_data._x); +} + +RTTI_IMPL(TranslateYTimeline, CurveTimeline1) + +TranslateYTimeline::TranslateYTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1( + frameCount, bezierCount), + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_Y << 32) | boneIndex}; + setPropertyIds(ids, 1); +} + +TranslateYTimeline::~TranslateYTimeline() { +} + +void TranslateYTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction) { + SP_UNUSED(lastTime); + SP_UNUSED(pEvents); + SP_UNUSED(direction); + + Bone *bone = skeleton._bones[_boneIndex]; + if (bone->_active) bone->_y = getRelativeValue(time, alpha, blend, bone->_y, bone->_data._y); +} diff --git a/native/cocos/editor-support/spine/4.2/spine/TranslateTimeline.h b/native/cocos/editor-support/spine/4.2/spine/TranslateTimeline.h new file mode 100644 index 0000000000..65598c35e2 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/TranslateTimeline.h @@ -0,0 +1,113 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_TranslateTimeline_h +#define Spine_TranslateTimeline_h + +#include + +#include +#include + +namespace spine { + + class SP_API TranslateTimeline : public CurveTimeline2 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit TranslateTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual ~TranslateTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + }; + + class SP_API TranslateXTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit TranslateXTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual ~TranslateXTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + }; + + class SP_API TranslateYTimeline : public CurveTimeline1 { + friend class SkeletonBinary; + + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit TranslateYTimeline(size_t frameCount, size_t bezierCount, int boneIndex); + + virtual ~TranslateYTimeline(); + + virtual void + apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, + MixDirection direction); + + int getBoneIndex() { return _boneIndex; } + + void setBoneIndex(int inValue) { _boneIndex = inValue; } + + private: + int _boneIndex; + }; +} + +#endif /* Spine_TranslateTimeline_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Triangulator.cpp b/native/cocos/editor-support/spine/4.2/spine/Triangulator.cpp new file mode 100644 index 0000000000..5f924ecb35 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Triangulator.cpp @@ -0,0 +1,285 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +using namespace spine; + +Triangulator::~Triangulator() { + ContainerUtil::cleanUpVectorOfPointers(_convexPolygons); + ContainerUtil::cleanUpVectorOfPointers(_convexPolygonsIndices); +} + +Vector &Triangulator::triangulate(Vector &vertices) { + size_t vertexCount = vertices.size() >> 1; + + Vector &indices = _indices; + indices.clear(); + indices.ensureCapacity(vertexCount); + indices.setSize(vertexCount, 0); + for (int i = 0; i < (int) vertexCount; ++i) { + indices[i] = i; + } + + Vector &isConcaveArray = _isConcaveArray; + isConcaveArray.ensureCapacity(vertexCount); + isConcaveArray.setSize(vertexCount, 0); + for (int i = 0, n = (int) vertexCount; i < n; ++i) { + isConcaveArray[i] = isConcave(i, (int) vertexCount, vertices, indices); + } + + Vector &triangles = _triangles; + triangles.clear(); + triangles.ensureCapacity(MathUtil::max((int) 0, (int) vertexCount - 2) << 2); + + while (vertexCount > 3) { + // Find ear tip. + size_t previous = vertexCount - 1, i = 0, next = 1; + + // outer: + while (true) { + if (!isConcaveArray[i]) { + int p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1; + float p1x = vertices[p1], p1y = vertices[p1 + 1]; + float p2x = vertices[p2], p2y = vertices[p2 + 1]; + float p3x = vertices[p3], p3y = vertices[p3 + 1]; + for (size_t ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) { + if (!isConcaveArray[ii]) continue; + + int v = indices[ii] << 1; + float &vx = vertices[v], vy = vertices[v + 1]; + if (positiveArea(p3x, p3y, p1x, p1y, vx, vy)) { + if (positiveArea(p1x, p1y, p2x, p2y, vx, vy)) { + if (positiveArea(p2x, p2y, p3x, p3y, vx, vy)) { + goto break_outer;// break outer; + } + } + } + } + break; + } + break_outer: + + if (next == 0) { + do { + if (!isConcaveArray[i]) break; + i--; + } while (i > 0); + break; + } + + previous = i; + i = next; + next = (next + 1) % vertexCount; + } + + // Cut ear tip. + triangles.add(indices[(vertexCount + i - 1) % vertexCount]); + triangles.add(indices[i]); + triangles.add(indices[(i + 1) % vertexCount]); + indices.removeAt(i); + isConcaveArray.removeAt(i); + vertexCount--; + + int previousIndex = (int) ((vertexCount + i - 1) % vertexCount); + int nextIndex = (int) (i == vertexCount ? 0 : i); + isConcaveArray[previousIndex] = isConcave(previousIndex, (int) vertexCount, vertices, indices); + isConcaveArray[nextIndex] = isConcave(nextIndex, (int) vertexCount, vertices, indices); + } + + if (vertexCount == 3) { + triangles.add(indices[2]); + triangles.add(indices[0]); + triangles.add(indices[1]); + } + + return triangles; +} + +Vector *> &Triangulator::decompose(Vector &vertices, Vector &triangles) { + Vector *> &convexPolygons = _convexPolygons; + for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) + _polygonPool.free(convexPolygons[i]); + convexPolygons.clear(); + + Vector *> &convexPolygonsIndices = _convexPolygonsIndices; + for (size_t i = 0, n = convexPolygonsIndices.size(); i < n; ++i) + _polygonIndicesPool.free(convexPolygonsIndices[i]); + convexPolygonsIndices.clear(); + + Vector *polygonIndices = _polygonIndicesPool.obtain(); + polygonIndices->clear(); + + Vector *polygon = _polygonPool.obtain(); + polygon->clear(); + + // Merge subsequent triangles if they form a triangle fan. + int fanBaseIndex = -1, lastwinding = 0; + for (size_t i = 0, n = triangles.size(); i < n; i += 3) { + int t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1; + float x1 = vertices[t1], y1 = vertices[t1 + 1]; + float x2 = vertices[t2], y2 = vertices[t2 + 1]; + float x3 = vertices[t3], y3 = vertices[t3 + 1]; + + // If the base of the last triangle is the same as this triangle, check if they form a convex polygon (triangle fan). + bool merged = false; + if (fanBaseIndex == t1) { + size_t o = polygon->size() - 4; + Vector &p = *polygon; + int winding1 = winding(p[o], p[o + 1], p[o + 2], p[o + 3], x3, y3); + int winding2 = winding(x3, y3, p[0], p[1], p[2], p[3]); + if (winding1 == lastwinding && winding2 == lastwinding) { + polygon->add(x3); + polygon->add(y3); + polygonIndices->add(t3); + merged = true; + } + } + + // Otherwise make this triangle the new base. + if (!merged) { + if (polygon->size() > 0) { + convexPolygons.add(polygon); + convexPolygonsIndices.add(polygonIndices); + } else { + _polygonPool.free(polygon); + _polygonIndicesPool.free(polygonIndices); + } + + polygon = _polygonPool.obtain(); + polygon->clear(); + polygon->add(x1); + polygon->add(y1); + polygon->add(x2); + polygon->add(y2); + polygon->add(x3); + polygon->add(y3); + polygonIndices = _polygonIndicesPool.obtain(); + polygonIndices->clear(); + polygonIndices->add(t1); + polygonIndices->add(t2); + polygonIndices->add(t3); + lastwinding = winding(x1, y1, x2, y2, x3, y3); + fanBaseIndex = t1; + } + } + + if (polygon->size() > 0) { + convexPolygons.add(polygon); + convexPolygonsIndices.add(polygonIndices); + } + + // Go through the list of polygons and try to merge the remaining triangles with the found triangle fans. + for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) { + polygonIndices = convexPolygonsIndices[i]; + + if (polygonIndices->size() == 0) continue; + int firstIndex = (*polygonIndices)[0]; + int lastIndex = (*polygonIndices)[polygonIndices->size() - 1]; + + polygon = convexPolygons[i]; + size_t o = polygon->size() - 4; + Vector &p = *polygon; + float prevPrevX = p[o], prevPrevY = p[o + 1]; + float prevX = p[o + 2], prevY = p[o + 3]; + float firstX = p[0], firstY = p[1]; + float secondX = p[2], secondY = p[3]; + int winding0 = winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY); + + for (size_t ii = 0; ii < n; ++ii) { + if (ii == i) continue; + + Vector *otherIndicesP = convexPolygonsIndices[ii]; + Vector &otherIndices = *otherIndicesP; + + if (otherIndices.size() != 3) continue; + + int otherFirstIndex = otherIndices[0]; + int otherSecondIndex = otherIndices[1]; + int otherLastIndex = otherIndices[2]; + + Vector *otherPolyP = convexPolygons[ii]; + Vector &otherPoly = *otherPolyP; + + float x3 = otherPoly[otherPoly.size() - 2], y3 = otherPoly[otherPoly.size() - 1]; + + if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue; + + int winding1 = winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3); + int winding2 = winding(x3, y3, firstX, firstY, secondX, secondY); + if (winding1 == winding0 && winding2 == winding0) { + otherPoly.clear(); + otherIndices.clear(); + polygon->add(x3); + polygon->add(y3); + polygonIndices->add(otherLastIndex); + prevPrevX = prevX; + prevPrevY = prevY; + prevX = x3; + prevY = y3; + ii = 0; + } + } + } + + // Remove empty polygons that resulted from the merge step above. + for (int i = (int) convexPolygons.size() - 1; i >= 0; --i) { + polygon = convexPolygons[i]; + if (polygon->size() == 0) { + convexPolygons.removeAt(i); + _polygonPool.free(polygon); + polygonIndices = convexPolygonsIndices[i]; + convexPolygonsIndices.removeAt(i); + _polygonIndicesPool.free(polygonIndices); + } + } + + return convexPolygons; +} + +bool Triangulator::isConcave(int index, int vertexCount, Vector &vertices, Vector &indices) { + int previous = indices[(vertexCount + index - 1) % vertexCount] << 1; + int current = indices[index] << 1; + int next = indices[(index + 1) % vertexCount] << 1; + + return !positiveArea(vertices[previous], vertices[previous + 1], + vertices[current], vertices[current + 1], + vertices[next], vertices[next + 1]); +} + +bool Triangulator::positiveArea(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { + return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0; +} + +int Triangulator::winding(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { + float px = p2x - p1x, py = p2y - p1y; + return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Triangulator.h b/native/cocos/editor-support/spine/4.2/spine/Triangulator.h new file mode 100644 index 0000000000..53bbe49e68 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Triangulator.h @@ -0,0 +1,70 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Triangulator_h +#define Spine_Triangulator_h + +#include +#include + +namespace spine { + class SP_API Triangulator : public SpineObject { + public: + ~Triangulator(); + + Vector &triangulate(Vector &vertices); + + Vector* > & + decompose(Vector + &vertices, + Vector &triangles + ); + + private: + Vector* > + _convexPolygons; + Vector* > + _convexPolygonsIndices; + + Vector _indices; + Vector _isConcaveArray; + Vector _triangles; + + Pool > _polygonPool; + Pool > _polygonIndicesPool; + + static bool isConcave(int index, int vertexCount, Vector &vertices, Vector &indices); + + static bool positiveArea(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y); + + static int winding(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y); + }; +} + +#endif /* Spine_Triangulator_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Updatable.cpp b/native/cocos/editor-support/spine/4.2/spine/Updatable.cpp new file mode 100644 index 0000000000..799e1f67d1 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Updatable.cpp @@ -0,0 +1,40 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +using namespace spine; + +RTTI_IMPL_NOPARENT(Updatable) + +Updatable::Updatable() { +} + +Updatable::~Updatable() { +} diff --git a/native/cocos/editor-support/spine/4.2/spine/Updatable.h b/native/cocos/editor-support/spine/4.2/spine/Updatable.h new file mode 100644 index 0000000000..2396c6322b --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Updatable.h @@ -0,0 +1,54 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Updatable_h +#define Spine_Updatable_h + +#include +#include +#include + +namespace spine { + class SP_API Updatable : public SpineObject { + RTTI_DECL + + public: + Updatable(); + + virtual ~Updatable(); + + virtual void update(Physics physics) = 0; + + virtual bool isActive() = 0; + + virtual void setActive(bool inValue) = 0; + }; +} + +#endif /* Spine_Updatable_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Vector.h b/native/cocos/editor-support/spine/4.2/spine/Vector.h new file mode 100644 index 0000000000..2dfae01e28 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Vector.h @@ -0,0 +1,230 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Vector_h +#define Spine_Vector_h + +#include +#include +#include +#include + +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) { + } + + Vector(const Vector &inVector) : _size(inVector._size), _capacity(inVector._capacity), _buffer(NULL) { + if (_capacity > 0) { + _buffer = allocate(_capacity); + for (size_t i = 0; i < _size; ++i) { + construct(_buffer + i, inVector._buffer[i]); + } + } + } + + ~Vector() { + clear(); + deallocate(_buffer); + } + + inline void clear() { + for (size_t i = 0; i < _size; ++i) { + destroy(_buffer + (_size - 1 - i)); + } + + _size = 0; + } + + inline size_t getCapacity() const { + return _capacity; + } + + inline size_t size() const { + return _size; + } + + inline 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__); + } + if (oldSize < _size) { + for (size_t i = oldSize; i < _size; i++) { + construct(_buffer + i, defaultValue); + } + } + } + + inline void ensureCapacity(size_t newCapacity = 0) { + if (_capacity >= newCapacity) return; + _capacity = newCapacity; + _buffer = SpineExtension::realloc(_buffer, newCapacity, __FILE__, __LINE__); + } + + inline void add(const T &inValue) { + if (_size == _capacity) { + // inValue might reference an element in this buffer + // When we reallocate, the reference becomes invalid. + // We thus need to create a defensive copy before + // reallocating. + T valueCopy = inValue; + _capacity = (int) (_size * 1.75f); + if (_capacity < 8) _capacity = 8; + _buffer = spine::SpineExtension::realloc(_buffer, _capacity, __FILE__, __LINE__); + construct(_buffer + _size++, valueCopy); + } else { + construct(_buffer + _size++, inValue); + } + } + + inline 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) { + this->clear(); + this->addAll(inValue); + } + + inline void removeAt(size_t inIndex) { + assert(inIndex < _size); + + --_size; + + if (inIndex != _size) { + for (size_t i = inIndex; i < _size; ++i) { + T tmp(_buffer[i]); + _buffer[i] = _buffer[i + 1]; + _buffer[i + 1] = tmp; + } + } + + destroy(_buffer + _size); + } + + inline bool contains(const T &inValue) { + for (size_t i = 0; i < _size; ++i) { + if (_buffer[i] == inValue) { + return true; + } + } + + return false; + } + + inline int indexOf(const T &inValue) { + for (size_t i = 0; i < _size; ++i) { + if (_buffer[i] == inValue) { + return (int) i; + } + } + + return -1; + } + + inline T &operator[](size_t inIndex) { + assert(inIndex < _size); + + 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; + } + + for (size_t i = 0, n = lhs.size(); i < n; ++i) { + if (lhs[i] != rhs[i]) { + return false; + } + } + + return true; + } + + inline friend bool operator!=(Vector &lhs, Vector &rhs) { + return !(lhs == rhs); + } + + inline T *buffer() { + return _buffer; + } + + private: + size_t _size; + size_t _capacity; + T *_buffer; + + inline T *allocate(size_t n) { + assert(n > 0); + + T *ptr = SpineExtension::calloc(n, __FILE__, __LINE__); + + assert(ptr); + + return ptr; + } + + inline void deallocate(T *buffer) { + if (_buffer) { + SpineExtension::free(buffer, __FILE__, __LINE__); + } + } + + inline void construct(T *buffer, const T &val) { + new(buffer) T(val); + } + + inline void destroy(T *buffer) { + buffer->~T(); + } + + // Vector &operator=(const Vector &inVector) {}; + }; +} + +#endif /* Spine_Vector_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Version.h b/native/cocos/editor-support/spine/4.2/spine/Version.h new file mode 100644 index 0000000000..f53cb26806 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Version.h @@ -0,0 +1,37 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef SPINE_VERSION_H_ +#define SPINE_VERSION_H_ + +#define SPINE_MAJOR_VERSION 4 +#define SPINE_MINOR_VERSION 2 +#define SPINE_VERSION_STRING "4.2" + +#endif diff --git a/native/cocos/editor-support/spine/4.2/spine/VertexAttachment.cpp b/native/cocos/editor-support/spine/4.2/spine/VertexAttachment.cpp new file mode 100644 index 0000000000..0c79b95113 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/VertexAttachment.cpp @@ -0,0 +1,167 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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 + +#include + +#include +#include + +using namespace spine; + +RTTI_IMPL(VertexAttachment, Attachment) + +VertexAttachment::VertexAttachment(const String &name) : Attachment(name), _worldVerticesLength(0), + _timelineAttachment(this), _id(getNextID()) { +} + +VertexAttachment::~VertexAttachment() { +} + +void VertexAttachment::computeWorldVertices(Slot &slot, Vector &worldVertices) { + computeWorldVertices(slot, 0, _worldVerticesLength, worldVertices, 0); +} + +void VertexAttachment::computeWorldVertices(Slot &slot, float *worldVertices) { + computeWorldVertices(slot, 0, _worldVerticesLength, worldVertices, 0); +} + +void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, Vector &worldVertices, + size_t offset, size_t stride) { + computeWorldVertices(slot, start, count, worldVertices.buffer(), offset, stride); +} + +void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, + size_t stride) { + count = offset + (count >> 1) * stride; + Skeleton &skeleton = slot._bone._skeleton; + Vector *deformArray = &slot.getDeform(); + Vector *vertices = &_vertices; + Vector &bones = _bones; + if (bones.size() == 0) { + if (deformArray->size() > 0) vertices = deformArray; + + Bone &bone = slot._bone; + float x = bone._worldX; + float y = bone._worldY; + float a = bone._a, b = bone._b, c = bone._c, d = bone._d; + for (size_t vv = start, w = offset; w < count; vv += 2, w += stride) { + float vx = (*vertices)[vv]; + float vy = (*vertices)[vv + 1]; + worldVertices[w] = vx * a + vy * b + x; + worldVertices[w + 1] = vx * c + vy * d + y; + } + return; + } + + int v = 0, skip = 0; + for (size_t i = 0; i < start; i += 2) { + int n = (int) bones[v]; + v += n + 1; + skip += n; + } + + Vector &skeletonBones = skeleton.getBones(); + if (deformArray->size() == 0) { + for (size_t w = offset, b = skip * 3; w < count; w += stride) { + float wx = 0, wy = 0; + int n = (int) bones[v++]; + n += v; + for (; v < n; v++, b += 3) { + Bone *boneP = skeletonBones[bones[v]]; + Bone &bone = *boneP; + float vx = (*vertices)[b]; + float vy = (*vertices)[b + 1]; + float weight = (*vertices)[b + 2]; + wx += (vx * bone._a + vy * bone._b + bone._worldX) * weight; + wy += (vx * bone._c + vy * bone._d + bone._worldY) * weight; + } + worldVertices[w] = wx; + worldVertices[w + 1] = wy; + } + } else { + for (size_t w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) { + float wx = 0, wy = 0; + int n = (int) bones[v++]; + n += v; + for (; v < n; v++, b += 3, f += 2) { + Bone *boneP = skeletonBones[bones[v]]; + Bone &bone = *boneP; + float vx = (*vertices)[b] + (*deformArray)[f]; + float vy = (*vertices)[b + 1] + (*deformArray)[f + 1]; + float weight = (*vertices)[b + 2]; + wx += (vx * bone._a + vy * bone._b + bone._worldX) * weight; + wy += (vx * bone._c + vy * bone._d + bone._worldY) * weight; + } + worldVertices[w] = wx; + worldVertices[w + 1] = wy; + } + } +} + +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; +} + +Attachment *VertexAttachment::getTimelineAttachment() { + return _timelineAttachment; +} + +void VertexAttachment::setTimelineAttachment(Attachment *attachment) { + _timelineAttachment = attachment; +} + +int VertexAttachment::getNextID() { + static int nextID = 0; + return nextID++; +} + +void VertexAttachment::copyTo(VertexAttachment *other) { + other->_bones.clearAndAddAll(this->_bones); + other->_vertices.clearAndAddAll(this->_vertices); + other->_worldVerticesLength = this->_worldVerticesLength; + other->_timelineAttachment = this->_timelineAttachment; +} diff --git a/native/cocos/editor-support/spine/4.2/spine/VertexAttachment.h b/native/cocos/editor-support/spine/4.2/spine/VertexAttachment.h new file mode 100644 index 0000000000..57faa2509b --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/VertexAttachment.h @@ -0,0 +1,102 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_VertexAttachment_h +#define Spine_VertexAttachment_h + +#include + +#include + +namespace spine { + class Slot; + + /// An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices. + class SP_API VertexAttachment : public Attachment { + friend class SkeletonBinary; + + friend class SkeletonJson; + + friend class DeformTimeline; + + RTTI_DECL + + public: + explicit VertexAttachment(const String &name); + + virtual ~VertexAttachment(); + + void computeWorldVertices(Slot &slot, float *worldVertices); + + void computeWorldVertices(Slot &slot, Vector &worldVertices); + + /// Transforms local vertices to world coordinates. + /// @param start The index of the first Vertices value to transform. Each vertex has 2 values, x and y. + /// @param count The number of world vertex values to output. Must be less than or equal to WorldVerticesLength - start. + /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + count. + /// @param offset The worldVertices index to begin writing values. + /// @param stride The number of worldVertices entries between the value pairs written. + virtual void computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, + size_t stride = 2); + + virtual 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(); + + Vector &getBones(); + + Vector &getVertices(); + + size_t getWorldVerticesLength(); + + void setWorldVerticesLength(size_t inValue); + + Attachment * getTimelineAttachment(); + + void setTimelineAttachment(Attachment *attachment); + + void copyTo(VertexAttachment *other); + #ifndef __EMSCRIPTEN__ + protected: + #endif + Vector _bones; + Vector _vertices; + size_t _worldVerticesLength; + Attachment *_timelineAttachment; + + private: + const int _id; + + static int getNextID(); + }; +} + +#endif /* Spine_VertexAttachment_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/Vertices.h b/native/cocos/editor-support/spine/4.2/spine/Vertices.h new file mode 100644 index 0000000000..a98eae64c6 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/Vertices.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef Spine_Vertices_h +#define Spine_Vertices_h + +#include + +namespace spine { + class SP_API Vertices : public SpineObject { + public: + Vector _bones; + Vector _vertices; + }; +} + +#endif /* Spine_Vertices_h */ diff --git a/native/cocos/editor-support/spine/4.2/spine/dll.h b/native/cocos/editor-support/spine/4.2/spine/dll.h new file mode 100644 index 0000000000..7cc14cc205 --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/dll.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef SPINE_SHAREDLIB_H +#define SPINE_SHAREDLIB_H + +#ifdef _WIN32 +#define DLLIMPORT __declspec(dllimport) +#define DLLEXPORT __declspec(dllexport) +#else +#ifndef DLLIMPORT +#define DLLIMPORT +#endif +#ifndef DLLEXPORT +#define DLLEXPORT +#endif +#endif + +#ifdef SPINEPLUGIN_API +#define SP_API SPINEPLUGIN_API +#else +#define SP_API +#endif + +#endif /* SPINE_SHAREDLIB_H */ diff --git a/native/cocos/editor-support/spine/4.2/spine/spine.h b/native/cocos/editor-support/spine/4.2/spine/spine.h new file mode 100644 index 0000000000..9bb1d081eb --- /dev/null +++ b/native/cocos/editor-support/spine/4.2/spine/spine.h @@ -0,0 +1,115 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated July 28, 2023. Replaces all prior versions. + * + * Copyright (c) 2013-2023, 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. + *****************************************************************************/ + +#ifndef SPINE_SPINE_H_ +#define SPINE_SPINE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/native/cocos/engine/Engine.cpp b/native/cocos/engine/Engine.cpp index 09cfb0e49e..1731edb035 100644 --- a/native/cocos/engine/Engine.cpp +++ b/native/cocos/engine/Engine.cpp @@ -200,7 +200,7 @@ void Engine::destroy() { #endif #if CC_USE_SPINE - spine::SkeletonCacheMgr::destroyInstance(); + cc::SkeletonCacheMgr::destroyInstance(); #endif #if CC_USE_MIDDLEWARE diff --git a/native/external-config.json b/native/external-config.json index c25bfd28d3..c2f846c095 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.6-4" + "checkout": "v3.8.6-5" } } \ No newline at end of file diff --git a/native/tools/license-upgrader/generate.js b/native/tools/license-upgrader/generate.js index 7f0d4b96b8..f92a468674 100644 --- a/native/tools/license-upgrader/generate.js +++ b/native/tools/license-upgrader/generate.js @@ -12,7 +12,8 @@ const ignoreList = [ 'cocos/platform/win32/inet_pton_mingw.cpp', // directories 'cocos/editor-support/dragonbones', - 'cocos/editor-support/spine', + 'cocos/editor-support/spine/3.8', + 'cocos/editor-support/spine/4.2', 'cocos/audio/android/', 'cocos/math/', 'cocos/renderer/pipeline/deferred/', diff --git a/native/tools/swig-config/spine.i b/native/tools/swig-config/spine_3_8.i similarity index 87% rename from native/tools/swig-config/spine.i rename to native/tools/swig-config/spine_3_8.i index 82e9a0e521..f0fc3c6ade 100644 --- a/native/tools/swig-config/spine.i +++ b/native/tools/swig-config/spine_3_8.i @@ -21,7 +21,7 @@ #include "bindings/auto/jsb_2d_auto.h" #include "bindings/auto/jsb_assets_auto.h" #include "bindings/auto/jsb_cocos_auto.h" -#include "bindings/auto/jsb_spine_auto.h" +#include "bindings/auto/jsb_spine_3_8_auto.h" using namespace spine; #define SWIGINTERN static @@ -42,28 +42,28 @@ using namespace spine; // %ignore cc::RefCounted; %ignore *::rtti; -%ignore spine::SkeletonCache::SegmentData; -%ignore spine::SkeletonCache::BoneData; -%ignore spine::SkeletonCache::FrameData; -%ignore spine::SkeletonCache::AnimationData; +%ignore cc::SkeletonCache::SegmentData; +%ignore cc::SkeletonCache::BoneData; +%ignore cc::SkeletonCache::FrameData; +%ignore cc::SkeletonCache::AnimationData; %ignore spine::Skin::AttachmentMap::getEntries; %ignore spine::AttachmentLoader::getRTTI; %ignore spine::Polygon::Polygon; %ignore spine::Polygon::_vertices; -%ignore spine::SkeletonRenderer::create; -%ignore spine::SkeletonRenderer::initWithJsonFile; -%ignore spine::SkeletonRenderer::initWithBinaryFile; -%ignore spine::SkeletonRenderer::createWithData; -%ignore spine::SkeletonRenderer::initWithData; -%ignore spine::SkeletonRenderer::createWithSkeleton; -%ignore spine::SkeletonRenderer::createWithFile; -%ignore spine::SkeletonRenderer::requestDrawInfo; -%ignore spine::SkeletonRenderer::requestMaterial; -%ignore spine::SkeletonAnimation::createWithData; -%ignore spine::SkeletonAnimation::onTrackEntryEvent; -%ignore spine::SkeletonAnimation::onAnimationStateEvent; +%ignore cc::SkeletonRenderer::create; +%ignore cc::SkeletonRenderer::initWithJsonFile; +%ignore cc::SkeletonRenderer::initWithBinaryFile; +%ignore cc::SkeletonRenderer::createWithData; +%ignore cc::SkeletonRenderer::initWithData; +%ignore cc::SkeletonRenderer::createWithSkeleton; +%ignore cc::SkeletonRenderer::createWithFile; +%ignore cc::SkeletonRenderer::requestDrawInfo; +%ignore cc::SkeletonRenderer::requestMaterial; +%ignore cc::SkeletonAnimation::createWithData; +%ignore cc::SkeletonAnimation::onTrackEntryEvent; +%ignore cc::SkeletonAnimation::onAnimationStateEvent; %ignore spine::TrackEntry::setListener; %ignore spine::AnimationState::setListener; %ignore spine::Attachment::getRTTI; @@ -106,14 +106,14 @@ using namespace spine; %ignore spine::VertexEffect::getRTTI; %ignore spine::ConstraintData::getRTTI; -%ignore spine::SkeletonDataMgr::destroyInstance; -%ignore spine::SkeletonDataMgr::hasSkeletonData; -%ignore spine::SkeletonDataMgr::setSkeletonData; -%ignore spine::SkeletonDataMgr::retainByUUID; -%ignore spine::SkeletonDataMgr::releaseByUUID; -%ignore spine::SkeletonCacheAnimation::render; -%ignore spine::SkeletonCacheAnimation::requestDrawInfo; -%ignore spine::SkeletonCacheAnimation::requestMaterial; +%ignore cc::SkeletonDataMgr::destroyInstance; +%ignore cc::SkeletonDataMgr::hasSkeletonData; +%ignore cc::SkeletonDataMgr::setSkeletonData; +%ignore cc::SkeletonDataMgr::retainByUUID; +%ignore cc::SkeletonDataMgr::releaseByUUID; +%ignore cc::SkeletonCacheAnimation::render; +%ignore cc::SkeletonCacheAnimation::requestDrawInfo; +%ignore cc::SkeletonCacheAnimation::requestMaterial; %ignore spine::Timeline::apply(Skeleton&, float, float, Vector*, float, MixBlend, MixDirection); %ignore spine::AnimationState::apply(Skeleton&); %ignore spine::Animation::apply(Skeleton&, float, float, bool, Vector*, float, MixBlend, MixDirection); @@ -161,10 +161,10 @@ using namespace spine; // Note: // 1. 'Rename Section' should be placed before attribute definition and %import/%include // 2. namespace is needed -%rename(create) spine::SkeletonAnimation::createWithFile; -%rename(setCompleteListenerNative) spine::SkeletonAnimation::setCompleteListener; -%rename(setTrackCompleteListenerNative) spine::SkeletonAnimation::setTrackCompleteListener; -%rename(create) spine::SkeletonRenderer::createWithFile; +%rename(create) cc::SkeletonAnimation::createWithFile; +%rename(setCompleteListenerNative) cc::SkeletonAnimation::setCompleteListener; +%rename(setTrackCompleteListenerNative) cc::SkeletonAnimation::setTrackCompleteListener; +%rename(create) cc::SkeletonRenderer::createWithFile; %rename(frames) spine::TranslateTimeline::_frames; %rename(boneIndex) spine::TranslateTimeline::_boneIndex; @@ -547,75 +547,76 @@ using namespace spine; // Note: // %import "your_header_file.h" will not generate code for that header file // +#define CC_USE_SPINE_3_8 1 %import "base/Macros.h" %import "base/RefCounted.h" -%import "editor-support/spine/dll.h" -%import "editor-support/spine/RTTI.h" -%import "editor-support/spine/SpineString.h" -%import "editor-support/spine/Vector.h" +%import "editor-support/spine/3.8/spine/dll.h" +%import "editor-support/spine/3.8/spine/RTTI.h" +%import "editor-support/spine/3.8/spine/SpineString.h" +%import "editor-support/spine/3.8/spine/Vector.h" // ----- Include Section ------ // Brief: Include header files in which classes and methods will be bound -%include "editor-support/spine/MathUtil.h" -%include "editor-support/spine/MixBlend.h" -%include "editor-support/spine/MixDirection.h" -%include "editor-support/spine/TransformMode.h" -%include "editor-support/spine/PositionMode.h" -%include "editor-support/spine/SpacingMode.h" -%include "editor-support/spine/RotateMode.h" -%include "editor-support/spine/BlendMode.h" -%include "editor-support/spine/Timeline.h" -%include "editor-support/spine/Animation.h" -%include "editor-support/spine/AnimationState.h" -%include "editor-support/spine/AnimationStateData.h" -%include "editor-support/spine/Attachment.h" -%include "editor-support/spine/AttachmentTimeline.h" -%include "editor-support/spine/VertexAttachment.h" -%include "editor-support/spine/BoundingBoxAttachment.h" -%include "editor-support/spine/Bone.h" -%include "editor-support/spine/BoneData.h" -%include "editor-support/spine/ClippingAttachment.h" -%include "editor-support/spine/Color.h" -%include "editor-support/spine/CurveTimeline.h" -%include "editor-support/spine/ColorTimeline.h" -%include "editor-support/spine/DeformTimeline.h" -%include "editor-support/spine/DrawOrderTimeline.h" -%include "editor-support/spine/Event.h" -%include "editor-support/spine/EventData.h" -%include "editor-support/spine/EventTimeline.h" -%include "editor-support/spine/ConstraintData.h" -%include "editor-support/spine/IkConstraint.h" -%include "editor-support/spine/IkConstraintData.h" -%include "editor-support/spine/IkConstraintTimeline.h" -%include "editor-support/spine/MeshAttachment.h" -%include "editor-support/spine/PathAttachment.h" -%include "editor-support/spine/PathConstraint.h" -%include "editor-support/spine/PathConstraintData.h" -%include "editor-support/spine/PathConstraintMixTimeline.h" -%include "editor-support/spine/PathConstraintPositionTimeline.h" -%include "editor-support/spine/PathConstraintSpacingTimeline.h" -%include "editor-support/spine/PointAttachment.h" -%include "editor-support/spine/RegionAttachment.h" -%include "editor-support/spine/TranslateTimeline.h" -%include "editor-support/spine/TwoColorTimeline.h" -%include "editor-support/spine/RotateTimeline.h" -%include "editor-support/spine/ScaleTimeline.h" -%include "editor-support/spine/ShearTimeline.h" -%include "editor-support/spine/Skeleton.h" -%include "editor-support/spine/Slot.h" -%include "editor-support/spine/Skin.h" -%include "editor-support/spine/SkeletonBounds.h" -%include "editor-support/spine/SkeletonData.h" -%include "editor-support/spine/SlotData.h" -%include "editor-support/spine/SkeletonBinary.h" -%include "editor-support/spine/AttachmentLoader.h" -%include "editor-support/spine/Atlas.h" -%include "editor-support/spine/TextureLoader.h" +%include "editor-support/spine/3.8/spine/MathUtil.h" +%include "editor-support/spine/3.8/spine/MixBlend.h" +%include "editor-support/spine/3.8/spine/MixDirection.h" +%include "editor-support/spine/3.8/spine/TransformMode.h" +%include "editor-support/spine/3.8/spine/PositionMode.h" +%include "editor-support/spine/3.8/spine/SpacingMode.h" +%include "editor-support/spine/3.8/spine/RotateMode.h" +%include "editor-support/spine/3.8/spine/BlendMode.h" +%include "editor-support/spine/3.8/spine/Timeline.h" +%include "editor-support/spine/3.8/spine/Animation.h" +%include "editor-support/spine/3.8/spine/AnimationState.h" +%include "editor-support/spine/3.8/spine/AnimationStateData.h" +%include "editor-support/spine/3.8/spine/Attachment.h" +%include "editor-support/spine/3.8/spine/AttachmentTimeline.h" +%include "editor-support/spine/3.8/spine/VertexAttachment.h" +%include "editor-support/spine/3.8/spine/BoundingBoxAttachment.h" +%include "editor-support/spine/3.8/spine/Bone.h" +%include "editor-support/spine/3.8/spine/BoneData.h" +%include "editor-support/spine/3.8/spine/ClippingAttachment.h" +%include "editor-support/spine/3.8/spine/Color.h" +%include "editor-support/spine/3.8/spine/CurveTimeline.h" +%include "editor-support/spine/3.8/spine/ColorTimeline.h" +%include "editor-support/spine/3.8/spine/DeformTimeline.h" +%include "editor-support/spine/3.8/spine/DrawOrderTimeline.h" +%include "editor-support/spine/3.8/spine/Event.h" +%include "editor-support/spine/3.8/spine/EventData.h" +%include "editor-support/spine/3.8/spine/EventTimeline.h" +%include "editor-support/spine/3.8/spine/ConstraintData.h" +%include "editor-support/spine/3.8/spine/IkConstraint.h" +%include "editor-support/spine/3.8/spine/IkConstraintData.h" +%include "editor-support/spine/3.8/spine/IkConstraintTimeline.h" +%include "editor-support/spine/3.8/spine/MeshAttachment.h" +%include "editor-support/spine/3.8/spine/PathAttachment.h" +%include "editor-support/spine/3.8/spine/PathConstraint.h" +%include "editor-support/spine/3.8/spine/PathConstraintData.h" +%include "editor-support/spine/3.8/spine/PathConstraintMixTimeline.h" +%include "editor-support/spine/3.8/spine/PathConstraintPositionTimeline.h" +%include "editor-support/spine/3.8/spine/PathConstraintSpacingTimeline.h" +%include "editor-support/spine/3.8/spine/PointAttachment.h" +%include "editor-support/spine/3.8/spine/RegionAttachment.h" +%include "editor-support/spine/3.8/spine/TranslateTimeline.h" +%include "editor-support/spine/3.8/spine/TwoColorTimeline.h" +%include "editor-support/spine/3.8/spine/RotateTimeline.h" +%include "editor-support/spine/3.8/spine/ScaleTimeline.h" +%include "editor-support/spine/3.8/spine/ShearTimeline.h" +%include "editor-support/spine/3.8/spine/Skeleton.h" +%include "editor-support/spine/3.8/spine/Slot.h" +%include "editor-support/spine/3.8/spine/Skin.h" +%include "editor-support/spine/3.8/spine/SkeletonBounds.h" +%include "editor-support/spine/3.8/spine/SkeletonData.h" +%include "editor-support/spine/3.8/spine/SlotData.h" +%include "editor-support/spine/3.8/spine/SkeletonBinary.h" +%include "editor-support/spine/3.8/spine/AttachmentLoader.h" +%include "editor-support/spine/3.8/spine/Atlas.h" +%include "editor-support/spine/3.8/spine/TextureLoader.h" -%include "editor-support/spine/TransformConstraint.h" -%include "editor-support/spine/TransformConstraintData.h" -%include "editor-support/spine/TransformConstraintTimeline.h" -%include "editor-support/spine/VertexEffect.h" +%include "editor-support/spine/3.8/spine/TransformConstraint.h" +%include "editor-support/spine/3.8/spine/TransformConstraintData.h" +%include "editor-support/spine/3.8/spine/TransformConstraintTimeline.h" +%include "editor-support/spine/3.8/spine/VertexEffect.h" %include "editor-support/spine-creator-support/VertexEffectDelegate.h" %include "editor-support/spine-creator-support/SkeletonRenderer.h" diff --git a/native/tools/swig-config/spine_4_2.i b/native/tools/swig-config/spine_4_2.i new file mode 100644 index 0000000000..961674ba51 --- /dev/null +++ b/native/tools/swig-config/spine_4_2.i @@ -0,0 +1,730 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// spine at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="spine") spine + +// Disable some swig warnings, find warning number reference here ( https://www.swig.org/Doc4.1/Warnings.html ) +#pragma SWIG nowarn=503,302,401,317,402 + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "editor-support/spine-creator-support/spine-cocos2dx.h" +#include "editor-support/spine-creator-support/Vector2.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_2d_auto.h" +#include "bindings/auto/jsb_assets_auto.h" +#include "bindings/auto/jsb_cocos_auto.h" +#include "bindings/auto/jsb_spine_4_2_auto.h" +using namespace spine; + +#define SWIGINTERN static +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// +%ignore cc::RefCounted; +%ignore *::rtti; +%ignore cc::SkeletonCache::SegmentData; +%ignore cc::SkeletonCache::BoneData; +%ignore cc::SkeletonCache::FrameData; +%ignore cc::SkeletonCache::AnimationData; +%ignore spine::Skin::AttachmentMap::getEntries; + +%ignore spine::Polygon::Polygon; +%ignore spine::Polygon::_vertices; + +%ignore cc::SkeletonRenderer::create; +%ignore cc::SkeletonRenderer::initWithJsonFile; +%ignore cc::SkeletonRenderer::initWithBinaryFile; +%ignore cc::SkeletonRenderer::createWithData; +%ignore cc::SkeletonRenderer::initWithData; +%ignore cc::SkeletonRenderer::createWithSkeleton; +%ignore cc::SkeletonRenderer::createWithFile; +%ignore cc::SkeletonRenderer::requestDrawInfo; +%ignore cc::SkeletonRenderer::requestMaterial; +%ignore cc::SkeletonAnimation::createWithData; +%ignore cc::SkeletonAnimation::onTrackEntryEvent; +%ignore cc::SkeletonAnimation::onAnimationStateEvent; +%ignore spine::TrackEntry::setListener; +%ignore spine::AnimationState::setListener; +%ignore spine::Attachment::getRTTI; +%ignore spine::AttachmentTimeline::getRTTI; +%ignore spine::BoundingBoxAttachment::getRTTI; +%ignore spine::Bone::getRTTI; +%ignore spine::Bone::worldToLocal(float, float, float&, float&); +%ignore spine::Bone::localToWorld(float, float, float&, float&); +%ignore spine::ClippingAttachment::getRTTI; +%ignore spine::ColorTimeline::getRTTI; +%ignore spine::CurveTimeline::getRTTI; +%ignore spine::DeformTimeline::getVertices; +%ignore spine::DeformTimeline::getRTTI; +%ignore spine::DrawOrderTimeline::getRTTI; +%ignore spine::EventTimeline::getRTTI; +%ignore spine::IkConstraint::getRTTI; +%ignore spine::IkConstraint::apply(Bone&, float, float, bool, bool, bool, float); +%ignore spine::IkConstraint::apply(Bone&, Bone&, float, float, int, bool, bool, float, float); +%ignore spine::IkConstraintTimeline::getRTTI; +%ignore spine::MeshAttachment::getRTTI; +%ignore spine::PathAttachment::getRTTI; +%ignore spine::PathConstraint::getRTTI; +%ignore spine::PathConstraintMixTimeline::getRTTI; +%ignore spine::PathConstraintPositionTimeline::getRTTI; +%ignore spine::PathConstraintSpacingTimeline::getRTTI; +%ignore spine::PointAttachment::getRTTI; +%ignore spine::RegionAttachment::getRTTI; +%ignore spine::RotateTimeline::getRTTI; +%ignore spine::ScaleTimeline::getRTTI; +%ignore spine::ShearTimeline::getRTTI; +%ignore spine::Skin::findNamesForSlot; +%ignore spine::Skin::getAttachments; +%ignore spine::Timeline::getRTTI; +%ignore spine::TransformConstraint::getRTTI; +%ignore spine::TransformConstraintTimeline::getRTTI; +%ignore spine::TranslateTimeline::getRTTI; +%ignore spine::VertexAttachment::getRTTI; +%ignore spine::Interpolation::getRTTI; +%ignore spine::VertexEffect::getRTTI; +%ignore spine::ConstraintData::getRTTI; + +%ignore cc::SkeletonDataMgr::destroyInstance; +%ignore cc::SkeletonDataMgr::hasSkeletonData; +%ignore cc::SkeletonDataMgr::setSkeletonData; +%ignore cc::SkeletonDataMgr::retainByUUID; +%ignore cc::SkeletonDataMgr::releaseByUUID; +%ignore cc::SkeletonCacheAnimation::render; +%ignore cc::SkeletonCacheAnimation::requestDrawInfo; +%ignore cc::SkeletonCacheAnimation::requestMaterial; +%ignore spine::Timeline::apply(Skeleton&, float, float, Vector*, float, MixBlend, MixDirection); +%ignore spine::AnimationState::apply(Skeleton&); +%ignore spine::Animation::apply(Skeleton&, float, float, bool, Vector*, float, MixBlend, MixDirection); +%ignore spine::VertexAttachment::computeWorldVertices; +%ignore spine::Bone::Bone(BoneData&, Skeleton&, Bone*); +%ignore spine::Bone::Bone(BoneData&, Skeleton&); +%ignore spine::Event::Event(float, const EventData&); +%ignore spine::IkConstraint::IkConstraint(IkConstraintData&, Skeleton&); +%ignore spine::PathConstraint::PathConstraint(PathConstraintData&, Skeleton&); +%ignore spine::PointAttachment::computeWorldPosition; +%ignore spine::PointAttachment::computeWorldRotation(Bone&); +%ignore spine::RegionAttachment::computeWorldVertices; +%ignore spine::Slot::Slot(SlotData&, Bone&); +%ignore spine::VertexEffect::begin(Skeleton &); +%ignore spine::TransformConstraint::TransformConstraint(TransformConstraintData&, Skeleton&); +%ignore spine::SkeletonBounds::update(Skeleton&, bool); +%ignore spine::SlotData::SlotData(int, const String&, BoneData&); +%ignore spine::DeformTimeline::setFrame(int, float, Vector&); +%ignore spine::DrawOrderTimeline::setFrame(size_t, float, Vector&); +%ignore spine::Skeleton::getBounds; +%ignore spine::Bone::updateWorldTransform(float, float, float, float, float, float, float); +%ignore spine::Skin::findAttachmentsForSlot; +%ignore spine::TextureLoader::load(AtlasPage&, const String&); + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +%rename(create) cc::SkeletonAnimation::createWithFile; +%rename(setCompleteListenerNative) cc::SkeletonAnimation::setCompleteListener; +%rename(setTrackCompleteListenerNative) cc::SkeletonAnimation::setTrackCompleteListener; +%rename(create) cc::SkeletonRenderer::createWithFile; + +%rename(frames) spine::TranslateTimeline::_frames; +%rename(boneIndex) spine::TranslateTimeline::_boneIndex; +%rename(frames) spine::IkConstraintTimeline::_frames; +%rename(ikConstraintIndex) spine::IkConstraintTimeline::_ikConstraintIndex; +%rename(frames) spine::TransformConstraintTimeline::_frames; +%rename(transformConstraintIndex) spine::TransformConstraintTimeline::_transformConstraintIndex; +%rename(frames) spine::PathConstraintPositionTimeline::_frames; +%rename(pathConstraintIndex) spine::PathConstraintPositionTimeline::_pathConstraintIndex; +%rename(frames) spine::PathConstraintMixTimeline::_frames; +%rename(pathConstraintIndex) spine::PathConstraintMixTimeline::_pathConstraintIndex; +%rename(events) spine::AnimationState::_events; +%rename(queue) spine::AnimationState::_queue; +%rename(animationsChanged) spine::AnimationState::_animationsChanged; +%rename(trackEntryPool) spine::AnimationState::_trackEntryPool; +%rename(listener) spine::TrackEntry::_listener; +%rename(nextAnimationLast) spine::TrackEntry::_nextAnimationLast; +%rename(trackLast) spine::TrackEntry::_trackLast; +%rename(nextTrackLast) spine::TrackEntry::_nextTrackLast; +%rename(interruptAlpha) spine::TrackEntry::_interruptAlpha; +%rename(totalAlpha) spine::TrackEntry::_totalAlpha; +%rename(timelineMode) spine::TrackEntry::_timelineMode; +%rename(timelineHoldMix) spine::TrackEntry::_timelineHoldMix; +%rename(timelinesRotation) spine::TrackEntry::_timelinesRotation; +%rename(drainDisabled) spine::EventQueue::_drainDisabled; +%rename(animState) spine::EventQueue::_state; +%rename(setMixWith) spine::AnimationStateData::setMix; +%rename(TextureAtlas) spine::Atlas; +%rename(sorted) spine::Bone::_sorted; +%rename(spaces) spine::PathConstraint::_spaces; +%rename(positions) spine::PathConstraint::_positions; +%rename(world) spine::PathConstraint::_world; +%rename(curves) spine::PathConstraint::_curves; +%rename(lengths) spine::PathConstraint::_lengths; +%rename(segments) spine::PathConstraint::_segments; +%rename(minX) spine::SkeletonBounds::_minX; +%rename(minY) spine::SkeletonBounds::_minY; +%rename(maxX) spine::SkeletonBounds::_maxX; +%rename(maxY) spine::SkeletonBounds::_maxY; +%rename(boundingBoxes) spine::SkeletonBounds::_boundingBoxes; +%rename(polygons) spine::SkeletonBounds::_polygons; +%rename(setSkinByName) spine::Skeleton::setSkin(const String &); +%rename(slotIndex) spine::Skin::AttachmentMap::Entry::_slotIndex; +%rename(name) spine::Skin::AttachmentMap::Entry::_name; +%rename(attachment) spine::Skin::AttachmentMap::Entry::_attachment; +%rename(signum) spine::MathUtil::sign(float); +%rename(TextureAtlasPage) spine::AtlasPage; +%rename(TextureAtlasRegion) spine::AtlasRegion; + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + +%attribute(spine::Animation, spine::String&, name, getName); +%attribute(spine::Animation, spine::Vector&, timelines, getTimelines); +%attribute(spine::Animation, float, duration, getDuration, setDuration); + +%attribute(spine::RotateTimeline, int, boneIndex, getBoneIndex, setBoneIndex); +%attribute(spine::RotateTimeline, spine::Vector&, frames, getFrames); + +%attribute(spine::RGBATimeline, int, slotIndex, getSlotIndex, setSlotIndex); +%attribute(spine::RGBTimeline, int, slotIndex, getSlotIndex, setSlotIndex); +%attribute(spine::AlphaTimeline, int, slotIndex, getSlotIndex, setSlotIndex); +%attribute(spine::RGBA2Timeline, int, slotIndex, getSlotIndex, setSlotIndex); +%attribute(spine::RGB2Timeline, int, slotIndex, getSlotIndex, setSlotIndex); + + +%attribute(spine::AttachmentTimeline, size_t, slotIndex, getSlotIndex, setSlotIndex); +%attribute(spine::AttachmentTimeline, spine::Vector&, frames, getFrames); +%attribute(spine::AttachmentTimeline, spine::Vector&, attachmentNames, getAttachmentNames); + +%attribute(spine::DeformTimeline, int, slotIndex, getSlotIndex, setSlotIndex); +%attribute(spine::DeformTimeline, spine::Vector&, frames, getFrames); +%attribute(spine::DeformTimeline, spine::Vector&, frameVertices, getVertices); +%attribute(spine::DeformTimeline, spine::VertexAttachment*, attachment, getAttachment); + +%attribute(spine::EventTimeline, spine::Vector, frames, getFrames); +%attribute(spine::EventTimeline, spine::Vector&, events, getEvents); + +%attribute(spine::DrawOrderTimeline, spine::Vector&, frames, getFrames); +%attribute(spine::DrawOrderTimeline, spine::Vector>&, drawOrders, getDrawOrders); + +%attribute(spine::AnimationState, spine::AnimationStateData*, data, getData); +%attribute(spine::AnimationState, spine::Vector&, tracks, getTracks); +%attribute(spine::AnimationState, float, timeScale, getTimeScale, setTimeScale); + +%attribute(spine::TrackEntry, spine::Animation*, animation, getAnimation); +%attribute(spine::TrackEntry, spine::TrackEntry*, next, getNext); +%attribute(spine::TrackEntry, spine::TrackEntry*, mixingFrom, getMixingFrom); +%attribute(spine::TrackEntry, spine::TrackEntry*, mixingTo, getMixingTo); +%attribute(spine::TrackEntry, int, trackIndex, getTrackIndex); +%attribute(spine::TrackEntry, bool, loop, getLoop, setLoop); +%attribute(spine::TrackEntry, bool, holdPrevious, getHoldPrevious, setHoldPrevious); +%attribute(spine::TrackEntry, float, eventThreshold, getEventThreshold, setEventThreshold); +%attribute(spine::TrackEntry, float, mixAttachmentThreshold, getMixAttachmentThreshold, setMixAttachmentThreshold); +%attribute(spine::TrackEntry, float, mixDrawOrderThreshold, getMixDrawOrderThreshold, setMixDrawOrderThreshold); +%attribute(spine::TrackEntry, float, alphaAttachmentThreshold, getAlphaAttachmentThreshold, setAlphaAttachmentThreshold); +%attribute(spine::TrackEntry, float, animationStart, getAnimationStart, setAnimationStart); +%attribute(spine::TrackEntry, float, animationEnd, getAnimationEnd, setAnimationEnd); +%attribute(spine::TrackEntry, float, animationLast, getAnimationLast, setAnimationLast); +%attribute(spine::TrackEntry, float, delay, getDelay, setDelay); +%attribute(spine::TrackEntry, float, trackTime, getTrackTime, setTrackTime); +%attribute(spine::TrackEntry, float, trackEnd, getTrackEnd, setTrackEnd); +%attribute(spine::TrackEntry, float, timeScale, getTimeScale, setTimeScale); +%attribute(spine::TrackEntry, float, alpha, getAlpha, setAlpha); +%attribute(spine::TrackEntry, float, mixTime, getMixTime, setMixTime); +%attribute(spine::TrackEntry, float, mixDuration, getMixDuration, setMixDuration); +%attribute(spine::TrackEntry, spine::MixBlend, mixBlend, getMixBlend, setMixBlend); + +%attribute(spine::AnimationStateData, spine::SkeletonData*, skeletonData, getSkeletonData); +%attribute(spine::AnimationStateData, float, defaultMix, getDefaultMix, setDefaultMix); + +%attribute(spine::Bone, spine::BoneData&, data, getData); +%attribute(spine::Bone, spine::Skeleton&, skeleton, getSkeleton); +%attribute(spine::Bone, spine::Bone*, parent, getParent); +%attribute(spine::Bone, spine::Vector&, children, getChildren); +%attribute(spine::Bone, float, x, getX, setX); +%attribute(spine::Bone, float, y, getY, setY); +%attribute(spine::Bone, float, rotation, getRotation, setRotation); +%attribute(spine::Bone, float, scaleX, getScaleX, setScaleX); +%attribute(spine::Bone, float, scaleY, getScaleY, setScaleY); +%attribute(spine::Bone, float, shearX, getShearX, setShearX); +%attribute(spine::Bone, float, shearY, getShearY, setShearY); +%attribute(spine::Bone, float, ax, getAX, setAX); +%attribute(spine::Bone, float, ay, getAY, setAY); +%attribute(spine::Bone, float, arotation, getAppliedRotation, setAppliedRotation); +%attribute(spine::Bone, float, ascaleX, getAScaleX, setAScaleX); +%attribute(spine::Bone, float, ascaleY, getAScaleY, setAScaleY); +%attribute(spine::Bone, float, ashearX, getAShearX, setAShearX); +%attribute(spine::Bone, float, ashearY, getAShearY, setAShearY); +%attribute(spine::Bone, float, a, getA, setA); +%attribute(spine::Bone, float, b, getB, setB); +%attribute(spine::Bone, float, c, getC, setC); +%attribute(spine::Bone, float, d, getD, setD); +%attribute(spine::Bone, float, worldX, getWorldX, setWorldX); +%attribute(spine::Bone, float, worldY, getWorldY, setWorldY); +%attribute(spine::Bone, bool, active, isActive, setActive); + +%attribute(spine::BoneData, int, index, getIndex); +%attribute(spine::BoneData, spine::String&, name, getName); +%attribute(spine::BoneData, spine::BoneData*, parent, getParent); +%attribute(spine::BoneData, float, length, getLength, setLength); +%attribute(spine::BoneData, float, x, getX, setX); +%attribute(spine::BoneData, float, y, getY, setY); +%attribute(spine::BoneData, float, rotation, getRotation, setRotation); +%attribute(spine::BoneData, float, scaleX, getScaleX, setScaleX); +%attribute(spine::BoneData, float, scaleY, getScaleY, setScaleY); +%attribute(spine::BoneData, float, shearX, getShearX, setShearX); +%attribute(spine::BoneData, float, shearY, getShearY, setShearY); +%attribute(spine::BoneData, bool, skinRequired, isSkinRequired, setSkinRequired); +%attribute(spine::BoneData, spine::String&, icon, getIcon, setIcon); +%attribute(spine::BoneData, bool, visible, isVisible, setVisible); + +%attribute(spine::ConstraintData, spine::String&, name, getName); +%attribute(spine::ConstraintData, size_t, order, getOrder, setOrder); +%attribute(spine::ConstraintData, bool, skinRequired, isSkinRequired, setSkinRequired); + +%attribute(spine::Event, spine::EventData&, data, getData); +%attribute(spine::Event, int, intValue, getIntValue, setIntValue); +%attribute(spine::Event, float, floatValue, getFloatValue, setFloatValue); +%attribute(spine::Event, spine::String&, stringValue, getStringValue, setStringValue); +%attribute(spine::Event, float, time, getTime); +%attribute(spine::Event, float, volume, getVolume, setVolume); +%attribute(spine::Event, float, balance, getBalance, setBalance); + +%attribute(spine::EventData, spine::String&, name, getName); +%attribute(spine::EventData, int, intValue, getIntValue, setIntValue); +%attribute(spine::EventData, float, floatValue, getFloatValue, setFloatValue); +%attribute(spine::EventData, spine::String&, stringValue, getStringValue, setStringValue); +%attribute(spine::EventData, float, volume, getVolume, setVolume); +%attribute(spine::EventData, float, balance, getBalance, setBalance); +%attribute(spine::EventData, spine::String&, audioPath, getAudioPath, setAudioPath); + +%attribute(spine::IkConstraint, spine::IkConstraintData&, data, getData); +%attribute(spine::IkConstraint, spine::Vector&, bones, getBones); +%attribute(spine::IkConstraint, spine::Bone*, target, getTarget, setTarget); +%attribute(spine::IkConstraint, int, bendDirection, getBendDirection, setBendDirection); +%attribute(spine::IkConstraint, bool, compress, getCompress, setCompress); +%attribute(spine::IkConstraint, bool, stretch, getStretch, setStretch); +%attribute(spine::IkConstraint, float, mix, getMix, setMix); +%attribute(spine::IkConstraint, float, softness, getSoftness, setSoftness); +%attribute(spine::IkConstraint, bool, active, isActive, setActive); + +%attribute(spine::IkConstraintData, spine::Vector&, bones, getBones); +%attribute(spine::IkConstraintData, spine::BoneData*, target, getTarget); +%attribute(spine::IkConstraintData, int, bendDirection, getBendDirection, setBendDirection); +%attribute(spine::IkConstraintData, bool, compress, getCompress, setCompress); +%attribute(spine::IkConstraintData, bool, stretch, getStretch, setStretch); +%attribute(spine::IkConstraintData, bool, uniform, getUniform, setUniform); +%attribute(spine::IkConstraintData, float, mix, getMix, setMix); +%attribute(spine::IkConstraintData, float, softness, getSoftness, setSoftness); + +%attribute(spine::PathConstraint, spine::PathConstraintData&, data, getData); +%attribute(spine::PathConstraint, spine::Vector&, bones, getBones); +%attribute(spine::PathConstraint, spine::Slot*, target, getTarget, setTarget); +%attribute(spine::PathConstraint, float, position, getPosition, setPosition); +%attribute(spine::PathConstraint, float, spacing, getSpacing, setSpacing); +%attribute(spine::PathConstraint, float, mixRotate, getMixRotate, setMixRotate); +%attribute(spine::PathConstraint, float, mixX, getMixX, setMixX); +%attribute(spine::PathConstraint, float, mixY, getMixY, setMixY); +%attribute(spine::PathConstraint, bool, active, isActive, setActive); + +%attribute(spine::PathConstraintData, spine::Vector&, bones, getBones); +%attribute(spine::PathConstraintData, spine::SlotData*, target, getTarget, setTarget); +%attribute(spine::PathConstraintData, spine::PositionMode, positionMode, getPositionMode, setPositionMode); +%attribute(spine::PathConstraintData, spine::SpacingMode, spacingMode, getSpacingMode, setSpacingMode); +%attribute(spine::PathConstraintData, spine::RotateMode, rotateMode, getRotateMode, setRotateMode); +%attribute(spine::PathConstraintData, float, offsetRotation, getOffsetRotation, setOffsetRotation); +%attribute(spine::PathConstraintData, float, position, getPosition, setPosition); +%attribute(spine::PathConstraintData, float, spacing, getSpacing, setSpacing); +%attribute(spine::PathConstraintData, float, mixRotate, getMixRotate, setMixRotate); +%attribute(spine::PathConstraintData, float, mixX, getMixX, setMixX); +%attribute(spine::PathConstraintData, float, mixY, getMixY, setMixY); + +%attribute(spine::Skeleton, spine::SkeletonData*, data, getData); +%attribute(spine::Skeleton, spine::Vector&, bones, getBones); +%attribute(spine::Skeleton, spine::Vector&, slots, getSlots); +%attribute(spine::Skeleton, spine::Vector&, drawOrder, getDrawOrder); +%attribute(spine::Skeleton, spine::Vector&, ikConstraints, getIkConstraints); +%attribute(spine::Skeleton, spine::Vector&, transformConstraints, getTransformConstraints); +%attribute(spine::Skeleton, spine::Vector&, pathConstraints, getPathConstraints); +%attribute(spine::Skeleton, spine::Vector&, _updateCache, getUpdateCacheList); +%attribute(spine::Skeleton, spine::Skin*, skin, getSkin, setSkin); +%attribute(spine::Skeleton, spine::Color&, color, getColor); +%attribute(spine::Skeleton, float, time, getTime, setTime); +%attribute(spine::Skeleton, float, scaleX, getScaleX, setScaleX); +%attribute(spine::Skeleton, float, scaleY, getScaleY, setScaleY); +%attribute(spine::Skeleton, float, x, getX, setX); +%attribute(spine::Skeleton, float, y, getY, setY); + +%attribute(spine::SkeletonData, spine::String&, name, getName, setName); +%attribute(spine::SkeletonData, spine::Vector&, bones, getBones); +%attribute(spine::SkeletonData, spine::Vector&, slots, getSlots); +%attribute(spine::SkeletonData, spine::Vector&, skins, getSkins); +%attribute(spine::SkeletonData, spine::Skin*, defaultSkin, getDefaultSkin, setDefaultSkin); +%attribute(spine::SkeletonData, spine::Vector&, events, getEvents); +%attribute(spine::SkeletonData, spine::Vector&, animations, getAnimations); +%attribute(spine::SkeletonData, spine::Vector&, ikConstraints, getIkConstraints); +%attribute(spine::SkeletonData, spine::Vector&, transformConstraints, getTransformConstraints); +%attribute(spine::SkeletonData, spine::Vector&, pathConstraints, getPathConstraints); +%attribute(spine::SkeletonData, float, x, getX, setX); +%attribute(spine::SkeletonData, float, y, getY, setY); +%attribute(spine::SkeletonData, float, width, getWidth, setWidth); +%attribute(spine::SkeletonData, float, height, getHeight, setHeight); +%attribute(spine::SkeletonData, spine::String&, version, getVersion, setVersion); +%attribute(spine::SkeletonData, spine::String&, hash, getHash, setHash); +%attribute(spine::SkeletonData, float, fps, getFps, setFps); +%attribute(spine::SkeletonData, spine::String&, imagesPath, getImagesPath, setImagesPath); +%attribute(spine::SkeletonData, spine::String&, audioPath, getAudioPath, setAudioPath); + +%attribute(spine::Skin, spine::String&, name, getName); +%attribute(spine::Skin, spine::Vector&, bones, getBones); +%attribute(spine::Skin, spine::Vector&, constraints, getConstraints); + +%attribute(spine::Slot, spine::SlotData&, data, getData); +%attribute(spine::Slot, spine::Bone&, bone, getBone); +%attribute(spine::Slot, spine::Color&, color, getColor); +%attribute(spine::Slot, spine::Color&, darkColor, getDarkColor); +%attribute(spine::Slot, spine::Attachment*, attachment, getAttachment, setAttachment); +%attribute(spine::Slot, spine::Vector&, deform, getDeform); + +%attribute(spine::SlotData, int, index, getIndex); +%attribute(spine::SlotData, spine::String&, name, getName); +%attribute(spine::SlotData, spine::BoneData&, boneData, getBoneData); +%attribute(spine::SlotData, spine::Color&, color, getColor); +%attribute(spine::SlotData, spine::Color&, darkColor, getDarkColor); +%attribute(spine::SlotData, spine::String&, attachmentName, getAttachmentName, setAttachmentName); +%attribute(spine::SlotData, spine::BlendMode, blendMode, getBlendMode, setBlendMode); + +%attribute(spine::TransformConstraint, spine::TransformConstraintData&, data, getData); +%attribute(spine::TransformConstraint, spine::Vector&, bones, getBones); +%attribute(spine::TransformConstraint, spine::Bone*, target, getTarget, setTarget); +%attribute(spine::TransformConstraint, float, mixRotate, getMixRotate, setMixRotate); +%attribute(spine::TransformConstraint, float, mixX, getMixX, setMixX); +%attribute(spine::TransformConstraint, float, mixY, getMixY, setMixY); +%attribute(spine::TransformConstraint, float, mixScaleX, getMixScaleX, setMixScaleX); +%attribute(spine::TransformConstraint, float, mixScaleY, getMixScaleY, setMixScaleY); +%attribute(spine::TransformConstraint, float, mixShearY, getMixShearY, setMixShearY); +%attribute(spine::TransformConstraint, bool, active, isActive, setActive); + +%attribute(spine::TransformConstraintData, spine::Vector&, bones, getBones); +%attribute(spine::TransformConstraintData, spine::BoneData*, target, getTarget); +%attribute(spine::TransformConstraintData, float, mixX, getMixX); +%attribute(spine::TransformConstraintData, float, mixY, getMixY); +%attribute(spine::TransformConstraintData, float, mixRotate, getMixRotate); +%attribute(spine::TransformConstraintData, float, mixScaleX, getMixScaleX); +%attribute(spine::TransformConstraintData, float, mixScaleY, getMixScaleY); +%attribute(spine::TransformConstraintData, float, mixShearY, getMixShearY); +%attribute(spine::TransformConstraintData, float, offsetRotation, getOffsetRotation); +%attribute(spine::TransformConstraintData, float, offsetX, getOffsetX); +%attribute(spine::TransformConstraintData, float, offsetY, getOffsetY); +%attribute(spine::TransformConstraintData, float, offsetScaleX, getOffsetScaleX); +%attribute(spine::TransformConstraintData, float, offsetScaleY, getOffsetScaleY); +%attribute(spine::TransformConstraintData, float, offsetShearY, getOffsetShearY); +%attribute(spine::TransformConstraintData, bool, relative, isRelative); +%attribute(spine::TransformConstraintData, bool, local, isLocal); + +%attribute(spine::Attachment, spine::String&, name, getName); + +%attribute(spine::VertexAttachment, int, id, getId); +%attribute(spine::VertexAttachment, spine::Vector&, bones, getBones); +%attribute(spine::VertexAttachment, spine::Vector&, vertices, getVertices); +%attribute(spine::VertexAttachment, size_t, worldVerticesLength, getWorldVerticesLength, setWorldVerticesLength); +%attribute(spine::VertexAttachment, spine::Attachment*, timelineAttachment, getTimelineAttachment, setTimelineAttachment); + +%attribute(spine::ClippingAttachment, spine::SlotData*, endSlot, getEndSlot, setEndSlot); + +%attribute(spine::MeshAttachment, spine::String&, path, getPath, setPath); +%attribute(spine::MeshAttachment, spine::Vector&, regionUVs, getRegionUVs); +%attribute(spine::MeshAttachment, spine::Vector&, uvs, getUVs); +%attribute(spine::MeshAttachment, spine::Vector&, triangles, getTriangles); +%attribute(spine::MeshAttachment, spine::Color&, color, getColor); +%attribute(spine::MeshAttachment, float, width, getWidth, setWidth); +%attribute(spine::MeshAttachment, float, height, getHeight, setHeight); +%attribute(spine::MeshAttachment, int, hullLength, getHullLength, setHullLength); +%attribute(spine::MeshAttachment, spine::Vector&, edges, getEdges); + +%attribute(spine::PathAttachment, spine::Vector&, lengths, getLengths); +%attribute(spine::PathAttachment, bool, closed, isClosed, setClosed); +%attribute(spine::PathAttachment, bool, constantSpeed, isConstantSpeed, setConstantSpeed); + +%attribute(spine::PointAttachment, float, x, getX, setX); +%attribute(spine::PointAttachment, float, y, getY, setY); +%attribute(spine::PointAttachment, float, rotation, getRotation, setRotation); + +%attribute(spine::RegionAttachment, float, x, getX, setX); +%attribute(spine::RegionAttachment, float, y, getY, setY); +%attribute(spine::RegionAttachment, float, scaleX, getScaleX, setScaleX); +%attribute(spine::RegionAttachment, float, scaleY, getScaleY, setScaleY); +%attribute(spine::RegionAttachment, float, rotation, getRotation, setRotation); +%attribute(spine::RegionAttachment, float, width, getWidth, setWidth); +%attribute(spine::RegionAttachment, float, height, getHeight, setHeight); +%attribute(spine::RegionAttachment, spine::Color&, color, getColor); +%attribute(spine::RegionAttachment, spine::String&, path, getPath, setPath); +%attribute(spine::RegionAttachment, spine::Vector&, offset, getOffset); +%attribute(spine::RegionAttachment, spine::Vector&, uvs, getUVs); + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +#define CC_USE_SPINE_4_2 1 +%import "base/Macros.h" +%import "base/RefCounted.h" +%import "editor-support/spine/4.2/spine/dll.h" +%import "editor-support/spine/4.2/spine/RTTI.h" +%import "editor-support/spine/4.2/spine/SpineString.h" +%import "editor-support/spine/4.2/spine/Vector.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "editor-support/spine/4.2/spine/MathUtil.h" +%include "editor-support/spine/4.2/spine/MixBlend.h" +%include "editor-support/spine/4.2/spine/MixDirection.h" +%include "editor-support/spine/4.2/spine/PositionMode.h" +%include "editor-support/spine/4.2/spine/SpacingMode.h" +%include "editor-support/spine/4.2/spine/RotateMode.h" +%include "editor-support/spine/4.2/spine/BlendMode.h" +%include "editor-support/spine/4.2/spine/Timeline.h" +%include "editor-support/spine/4.2/spine/Animation.h" +%include "editor-support/spine/4.2/spine/AnimationState.h" +%include "editor-support/spine/4.2/spine/AnimationStateData.h" +%include "editor-support/spine/4.2/spine/Attachment.h" +%include "editor-support/spine/4.2/spine/AttachmentTimeline.h" +%include "editor-support/spine/4.2/spine/VertexAttachment.h" +%include "editor-support/spine/4.2/spine/BoundingBoxAttachment.h" +%include "editor-support/spine/4.2/spine/Bone.h" +%include "editor-support/spine/4.2/spine/BoneData.h" +%include "editor-support/spine/4.2/spine/ClippingAttachment.h" +%include "editor-support/spine/4.2/spine/Color.h" +%include "editor-support/spine/4.2/spine/CurveTimeline.h" +%include "editor-support/spine/4.2/spine/ColorTimeline.h" +%include "editor-support/spine/4.2/spine/DeformTimeline.h" +%include "editor-support/spine/4.2/spine/DrawOrderTimeline.h" +%include "editor-support/spine/4.2/spine/Event.h" +%include "editor-support/spine/4.2/spine/EventData.h" +%include "editor-support/spine/4.2/spine/EventTimeline.h" +%include "editor-support/spine/4.2/spine/ConstraintData.h" +%include "editor-support/spine/4.2/spine/IkConstraint.h" +%include "editor-support/spine/4.2/spine/IkConstraintData.h" +%include "editor-support/spine/4.2/spine/IkConstraintTimeline.h" +%include "editor-support/spine/4.2/spine/MeshAttachment.h" +%include "editor-support/spine/4.2/spine/PathAttachment.h" +%include "editor-support/spine/4.2/spine/PathConstraint.h" +%include "editor-support/spine/4.2/spine/PathConstraintData.h" +%include "editor-support/spine/4.2/spine/PathConstraintMixTimeline.h" +%include "editor-support/spine/4.2/spine/PathConstraintPositionTimeline.h" +%include "editor-support/spine/4.2/spine/PathConstraintSpacingTimeline.h" +%include "editor-support/spine/4.2/spine/PointAttachment.h" +%include "editor-support/spine/4.2/spine/RegionAttachment.h" +%include "editor-support/spine/4.2/spine/TranslateTimeline.h" +%include "editor-support/spine/4.2/spine/RotateTimeline.h" +%include "editor-support/spine/4.2/spine/ScaleTimeline.h" +%include "editor-support/spine/4.2/spine/ShearTimeline.h" +%include "editor-support/spine/4.2/spine/Skeleton.h" +%include "editor-support/spine/4.2/spine/Slot.h" +%include "editor-support/spine/4.2/spine/Skin.h" +%include "editor-support/spine/4.2/spine/SkeletonBounds.h" +%include "editor-support/spine/4.2/spine/SkeletonData.h" +%include "editor-support/spine/4.2/spine/SlotData.h" +%include "editor-support/spine/4.2/spine/Sequence.h" +%include "editor-support/spine/4.2/spine/Atlas.h" +%include "editor-support/spine/4.2/spine/TextureLoader.h" +%include "editor-support/spine/4.2/spine/TextureRegion.h" + +%include "editor-support/spine/4.2/spine/TransformConstraint.h" +%include "editor-support/spine/4.2/spine/TransformConstraintData.h" +%include "editor-support/spine/4.2/spine/TransformConstraintTimeline.h" + +%include "editor-support/spine-creator-support/SkeletonRenderer.h" +%include "editor-support/spine-creator-support/SkeletonAnimation.h" +%include "editor-support/spine-creator-support/SkeletonDataMgr.h" +%include "editor-support/spine-creator-support/SkeletonCacheAnimation.h" +%include "editor-support/spine-creator-support/SkeletonCacheMgr.h" + +%extend spine::IkConstraint { + void apply1(Bone *bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha) { + IkConstraint::apply(*bone, targetX, targetY, compress, stretch, uniform, alpha); + } + + void apply2(Bone *parent, Bone *child, float targetX, float targetY, int bendDir, bool stretch, bool uniform, float softness, float alpha) { + IkConstraint::apply(*parent, *child, targetX, targetY, bendDir, stretch, uniform, softness, alpha); + } +}; + +%extend spine::Bone { + Bone(spine::BoneData *data, spine::Skeleton *skeleton, spine::Bone *parent) { + return new Bone(*data, *skeleton, parent); + } + + void updateWorldTransformWith(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY) { + $self->updateWorldTransform(x, y, rotation, scaleX, scaleY, shearX, shearY); + } +} + +%extend spine::Slot { + Slot(spine::SlotData *data, spine::Bone *bone) { + return new Slot(*data, *bone); + } +} + +%extend spine::Timeline { + void apply(spine::Skeleton *skeleton, float lastTime, float time, const ccstd::vector& events, float alpha, spine::MixBlend blend, spine::MixDirection direction) { + spine::Vector spEvents; + for (int i = 0; i < events.size(); ++i) { + spEvents.add(events[i]); + } + $self->apply(*skeleton, lastTime, time, &spEvents, alpha, blend, direction); + } +} + +%extend spine::AnimationState { + void apply(spine::Skeleton* skeleton) { + $self->apply(*skeleton); + } +} + +%extend spine::Animation { + void apply(spine::Skeleton *skeleton, float lastTime, float time, bool loop, const ccstd::vector& events, float alpha, spine::MixBlend blend, spine::MixDirection direction) { + spine::Vector spEvents; + for (int i = 0; i < events.size(); ++i) { + spEvents.add(events[i]); + } + $self->apply(*skeleton, lastTime, time, loop, &spEvents, alpha, blend, direction); + } +} + +%extend spine::Event { + Event(float time, spine::EventData *data) { + return new Event(time, *data); + } +} + +%extend spine::IkConstraint { + IkConstraint(spine::IkConstraintData *data, spine::Skeleton *skeleton) { + return new IkConstraint(*data, *skeleton); + } +} + +%extend spine::PathConstraint { + PathConstraint(spine::PathConstraintData* data, spine::Skeleton* skeleton) { + return new PathConstraint(*data, *skeleton); + } +} + +%extend spine::PointAttachment { + float computeWorldRotation(spine::Bone* bone) { + return $self->computeWorldRotation(*bone); + } +} + +%extend spine::SkeletonBounds { + void update(spine::Skeleton* skeleton, bool updateAabb) { + $self->update(*skeleton, updateAabb); + } +} + +%extend spine::TransformConstraint { + TransformConstraint(spine::TransformConstraintData* data, spine::Skeleton* skeleton) { + return new TransformConstraint(*data, *skeleton); + } +} + +%extend spine::SlotData { + SlotData(int index, const ccstd::string *name, spine::BoneData *boneData) { + spine::String spName(name->data()); + return new SlotData(index, spName, *boneData); + } +} + +%extend spine::DeformTimeline { + void setFrame(int frameIndex, float time, const ccstd::vector& vertices) { + spine::Vector spVertices; + for (int i = 0; i < vertices.size(); ++i) { + spVertices.add(vertices[i]); + } + $self->setFrame(frameIndex, time, spVertices); + } +} + +%extend spine::DrawOrderTimeline { + void setFrame(size_t frameIndex, float time, const ccstd::vector& drawOrder) { + spine::Vector spDrawOrder; + spDrawOrder.ensureCapacity(drawOrder.size()); + for (int i = 0; i < drawOrder.size(); ++i) { + spDrawOrder.add(drawOrder[i]); + } + $self->setFrame(frameIndex, time, spDrawOrder); + } +} + +%extend spine::Color { + spine::Color &setFromColor(const spine::Color &other) { + return $self->set(other); + } +} + +%extend spine::Skeleton { + spine::Attachment &getAttachmentByName(const std::string &slotName, const std::string &attachmentName) { + spine::String slot(slotName.data()); + spine::String attachment(attachmentName.data()); + return *($self->getAttachment(slot, attachment)); + } +} + +%extend spine::TextureLoader { + void load(spine::AtlasPage* page, const spine::String& path) { + $self->load(*page, path); + } +} diff --git a/platforms/native/engine/jsb-spine-skeleton.js b/platforms/native/engine/jsb-spine-skeleton.js index 1f3ba21486..28f83a1de5 100644 --- a/platforms/native/engine/jsb-spine-skeleton.js +++ b/platforms/native/engine/jsb-spine-skeleton.js @@ -174,8 +174,7 @@ const cacheManager = require('./jsb-cache-manager'); this._target = target; this._callback = callback; - // eslint-disable-next-line no-undef - const AnimationEventType = legacyCC.internal.SpineAnimationEventType; + const AnimationEventType = cc.internal.SpineAnimationEventType; this.setStartListener(function (trackEntry) { if (this._target && this._callback) { @@ -405,6 +404,10 @@ const cacheManager = require('./jsb-cache-manager'); }; skeleton.setVertexEffectDelegate = function (effectDelegate) { + if (cc.internal.SPINE_VERSION === '4.2') { + cc.warn('setVertexEffectDelegate is deprecated since spine 4.2'); + return; + } if (this._nativeSkeleton && !this.isAnimationCached()) { this._nativeSkeleton.setVertexEffectDelegate(effectDelegate); } @@ -696,7 +699,11 @@ const cacheManager = require('./jsb-cache-manager'); this._preCacheMode = this._cacheMode; this.defaultSkin && this._nativeSkeleton.setSkin(this.defaultSkin); - this.animation = this.defaultAnimation; + if (this.defaultAnimation) { + this.animation = this.defaultAnimation; + } else if (this._animationName) { + this.animation = this._animationName; + } } else if (this._nativeSkeleton) { this._nativeSkeleton.stopSchedule(); this._nativeSkeleton._comp = null; diff --git a/tests/init.ts b/tests/init.ts index d508f38439..53aaac0463 100644 --- a/tests/init.ts +++ b/tests/init.ts @@ -79,7 +79,8 @@ jest.mock( 'external:emscripten/webgpu/webgpu_wasm.wasm', 'external:emscripten/webgpu/glslang.wasm', 'external:emscripten/physx/physx.release.wasm.wasm', - 'external:emscripten/spine/spine.wasm', + 'external:emscripten/spine/3.8/spine.wasm', + 'external:emscripten/spine/4.2/spine.wasm', 'external:emscripten/box2d/box2d.release.wasm.wasm', 'external:emscripten/meshopt/meshopt_decoder.wasm.wasm', ].forEach(mockModuleId => {