From 11435f471aa1507693ca77bd8a10ec2a02f65056 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 11 Jun 2025 16:13:17 +0200 Subject: [PATCH] [cpp] 4.3 porting WIP --- spine-cpp/spine-cpp/include/spine/BoneLocal.h | 4 + .../spine-cpp/include/spine/ShearTimeline.h | 56 +++-------- .../spine-cpp/src/spine/ShearTimeline.cpp | 97 ++++++------------- 3 files changed, 51 insertions(+), 106 deletions(-) diff --git a/spine-cpp/spine-cpp/include/spine/BoneLocal.h b/spine-cpp/spine-cpp/include/spine/BoneLocal.h index c13f5347f..8c16ca45a 100644 --- a/spine-cpp/spine-cpp/include/spine/BoneLocal.h +++ b/spine-cpp/spine-cpp/include/spine/BoneLocal.h @@ -39,10 +39,14 @@ namespace spine { /// Stores a bone's local pose. class SP_API BoneLocal : public Pose { friend class BoneTimeline1; + friend class BoneTimeline2; friend class RotateTimeline; friend class ScaleTimeline; friend class ScaleXTimeline; friend class ScaleYTimeline; + friend class ShearTimeline; + friend class ShearXTimeline; + friend class ShearYTimeline; RTTI_DECL diff --git a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h index 6717743df..b4401a9b6 100644 --- a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h @@ -30,10 +30,11 @@ #ifndef Spine_ShearTimeline_h #define Spine_ShearTimeline_h -#include +#include namespace spine { - class SP_API ShearTimeline : public CurveTimeline2 { + /// Changes a bone's local shear X and Y. + class SP_API ShearTimeline : public BoneTimeline2 { friend class SkeletonBinary; friend class SkeletonJson; @@ -43,21 +44,13 @@ namespace spine { 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; + protected: + virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend, + MixDirection direction) override; }; - class SP_API ShearXTimeline : public CurveTimeline1 { + /// Changes a bone's local shear X. + class SP_API ShearXTimeline : public BoneTimeline1 { friend class SkeletonBinary; friend class SkeletonJson; @@ -67,21 +60,13 @@ namespace spine { 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; + protected: + virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend, + MixDirection direction) override; }; - class SP_API ShearYTimeline : public CurveTimeline1 { + /// Changes a bone's local shear Y. + class SP_API ShearYTimeline : public BoneTimeline1 { friend class SkeletonBinary; friend class SkeletonJson; @@ -91,18 +76,9 @@ namespace spine { 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; + protected: + virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend, + MixDirection direction) override; }; } diff --git a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp index 027f70c65..41b1c3185 100644 --- a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -39,37 +40,23 @@ using namespace spine; -RTTI_IMPL(ShearTimeline, CurveTimeline2) +RTTI_IMPL(ShearTimeline, BoneTimeline2) -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(size_t frameCount, size_t bezierCount, int boneIndex) : + BoneTimeline2(frameCount, bezierCount, boneIndex, Property_ShearX, Property_ShearY) { } -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; - +void ShearTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend, + MixDirection direction) { if (time < _frames[0]) { switch (blend) { case MixBlend_Setup: - bone->_shearX = bone->_data._shearX; - bone->_shearY = bone->_data._shearY; + pose._shearX = setup._shearX; + pose._shearY = setup._shearY; return; case MixBlend_First: - bone->_shearX += (bone->_data._shearX - bone->_shearX) * alpha; - bone->_shearY += (bone->_data._shearY - bone->_shearY) * alpha; + pose._shearX += (setup._shearX - pose._shearX) * alpha; + pose._shearY += (setup._shearY - pose._shearY) * alpha; default: { } } @@ -80,7 +67,7 @@ void ShearTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; switch (curveType) { - case CurveTimeline2::LINEAR: { + case CurveTimeline::LINEAR: { float before = _frames[i]; x = _frames[i + CurveTimeline2::VALUE1]; y = _frames[i + CurveTimeline2::VALUE2]; @@ -89,7 +76,7 @@ void ShearTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector y += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE2] - y) * t; break; } - case CurveTimeline2::STEPPED: { + case CurveTimeline::STEPPED: { x = _frames[i + CurveTimeline2::VALUE1]; y = _frames[i + CurveTimeline2::VALUE2]; break; @@ -103,60 +90,38 @@ void ShearTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector switch (blend) { case MixBlend_Setup: - bone->_shearX = bone->_data._shearX + x * alpha; - bone->_shearY = bone->_data._shearY + y * alpha; + pose._shearX = setup._shearX + x * alpha; + pose._shearY = setup._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; + pose._shearX += (setup._shearX + x - pose._shearX) * alpha; + pose._shearY += (setup._shearY + y - pose._shearY) * alpha; break; case MixBlend_Add: - bone->_shearX += x * alpha; - bone->_shearY += y * alpha; + pose._shearX += x * alpha; + pose._shearY += y * alpha; } } -RTTI_IMPL(ShearXTimeline, CurveTimeline1) +RTTI_IMPL(ShearXTimeline, BoneTimeline1) -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(size_t frameCount, size_t bezierCount, int boneIndex) : + BoneTimeline1(frameCount, bezierCount, boneIndex, Property_ShearX) { } -ShearXTimeline::~ShearXTimeline() { +void ShearXTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend, + MixDirection direction) { + pose._shearX = getRelativeValue(time, alpha, blend, pose._shearX, setup._shearX); } -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); +RTTI_IMPL(ShearYTimeline, BoneTimeline1) - Bone *bone = skeleton._bones[_boneIndex]; - if (bone->_active) bone->_shearX = getRelativeValue(time, alpha, blend, bone->_shearX, bone->_data._shearX); +ShearYTimeline::ShearYTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : + BoneTimeline1(frameCount, bezierCount, boneIndex, Property_ShearY) { } -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); -} +void ShearYTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend, + MixDirection direction) { + pose._shearY = getRelativeValue(time, alpha, blend, pose._shearY, setup._shearY); +} \ No newline at end of file