[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-06-11 16:24:37 +02:00
parent 11435f471a
commit c41da0c788
3 changed files with 51 additions and 110 deletions

View File

@ -47,6 +47,9 @@ namespace spine {
friend class ShearTimeline; friend class ShearTimeline;
friend class ShearXTimeline; friend class ShearXTimeline;
friend class ShearYTimeline; friend class ShearYTimeline;
friend class TranslateTimeline;
friend class TranslateXTimeline;
friend class TranslateYTimeline;
RTTI_DECL RTTI_DECL

View File

@ -30,14 +30,12 @@
#ifndef Spine_TranslateTimeline_h #ifndef Spine_TranslateTimeline_h
#define Spine_TranslateTimeline_h #define Spine_TranslateTimeline_h
#include <spine/CurveTimeline.h> #include <spine/BoneTimeline.h>
#include <spine/Animation.h>
#include <spine/Property.h>
namespace spine { namespace spine {
class SP_API TranslateTimeline : public CurveTimeline2 { /// Changes a bone's local X and Y translation.
class SP_API TranslateTimeline : public BoneTimeline2 {
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
@ -47,21 +45,13 @@ namespace spine {
public: public:
explicit TranslateTimeline(size_t frameCount, size_t bezierCount, int boneIndex); explicit TranslateTimeline(size_t frameCount, size_t bezierCount, int boneIndex);
virtual ~TranslateTimeline(); protected:
virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
virtual void MixDirection direction) override;
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *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 { /// Changes a bone's local X translation.
class SP_API TranslateXTimeline : public BoneTimeline1 {
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
@ -71,21 +61,13 @@ namespace spine {
public: public:
explicit TranslateXTimeline(size_t frameCount, size_t bezierCount, int boneIndex); explicit TranslateXTimeline(size_t frameCount, size_t bezierCount, int boneIndex);
virtual ~TranslateXTimeline(); protected:
virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
virtual void MixDirection direction) override;
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *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 { /// Changes a bone's local Y translation.
class SP_API TranslateYTimeline : public BoneTimeline1 {
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
@ -95,18 +77,9 @@ namespace spine {
public: public:
explicit TranslateYTimeline(size_t frameCount, size_t bezierCount, int boneIndex); explicit TranslateYTimeline(size_t frameCount, size_t bezierCount, int boneIndex);
virtual ~TranslateYTimeline(); protected:
virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
virtual void MixDirection direction) override;
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction);
int getBoneIndex() { return _boneIndex; }
void setBoneIndex(int inValue) { _boneIndex = inValue; }
private:
int _boneIndex;
}; };
} }

View File

@ -31,6 +31,7 @@
#include <spine/Event.h> #include <spine/Event.h>
#include <spine/Skeleton.h> #include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/Bone.h> #include <spine/Bone.h>
#include <spine/BoneData.h> #include <spine/BoneData.h>
@ -39,44 +40,30 @@
using namespace spine; using namespace spine;
RTTI_IMPL(TranslateTimeline, CurveTimeline2) RTTI_IMPL(TranslateTimeline, BoneTimeline2)
TranslateTimeline::TranslateTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline2(frameCount, TranslateTimeline::TranslateTimeline(size_t frameCount, size_t bezierCount, int boneIndex) :
bezierCount), BoneTimeline2(frameCount, bezierCount, boneIndex, Property_X, Property_Y) {
_boneIndex(boneIndex) {
PropertyId ids[] = {((PropertyId) Property_X << 32) | boneIndex,
((PropertyId) Property_Y << 32) | boneIndex};
setPropertyIds(ids, 2);
} }
TranslateTimeline::~TranslateTimeline() { void TranslateTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
} MixDirection direction) {
void TranslateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *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]) { if (time < _frames[0]) {
switch (blend) { switch (blend) {
case MixBlend_Setup: case MixBlend_Setup:
bone->_x = bone->_data._x; pose._x = setup._x;
bone->_y = bone->_data._y; pose._y = setup._y;
return; return;
case MixBlend_First: case MixBlend_First:
bone->_x += (bone->_data._x - bone->_x) * alpha; pose._x += (setup._x - pose._x) * alpha;
bone->_y += (bone->_data._y - bone->_y) * alpha; pose._y += (setup._y - pose._y) * alpha;
default: { default: {
} }
} }
return; return;
} }
float x = 0, y = 0; float x, y;
int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES);
int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; int curveType = (int) _curves[i / CurveTimeline2::ENTRIES];
switch (curveType) { switch (curveType) {
@ -95,68 +82,46 @@ void TranslateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Ve
break; break;
} }
default: { default: {
x = getBezierValue(time, i, CurveTimeline2::VALUE1, curveType - CurveTimeline::BEZIER); x = getBezierValue(time, i, CurveTimeline2::VALUE1, curveType - CurveTimeline2::BEZIER);
y = getBezierValue(time, i, CurveTimeline2::VALUE2, y = getBezierValue(time, i, CurveTimeline2::VALUE2,
curveType + CurveTimeline::BEZIER_SIZE - CurveTimeline::BEZIER); curveType + CurveTimeline2::BEZIER_SIZE - CurveTimeline2::BEZIER);
} }
} }
switch (blend) { switch (blend) {
case MixBlend_Setup: case MixBlend_Setup:
bone->_x = bone->_data._x + x * alpha; pose._x = setup._x + x * alpha;
bone->_y = bone->_data._y + y * alpha; pose._y = setup._y + y * alpha;
break; break;
case MixBlend_First: case MixBlend_First:
case MixBlend_Replace: case MixBlend_Replace:
bone->_x += (bone->_data._x + x - bone->_x) * alpha; pose._x += (setup._x + x - pose._x) * alpha;
bone->_y += (bone->_data._y + y - bone->_y) * alpha; pose._y += (setup._y + y - pose._y) * alpha;
break; break;
case MixBlend_Add: case MixBlend_Add:
bone->_x += x * alpha; pose._x += x * alpha;
bone->_y += y * alpha; pose._y += y * alpha;
} }
} }
RTTI_IMPL(TranslateXTimeline, CurveTimeline1) RTTI_IMPL(TranslateXTimeline, BoneTimeline1)
TranslateXTimeline::TranslateXTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1( TranslateXTimeline::TranslateXTimeline(size_t frameCount, size_t bezierCount, int boneIndex) :
frameCount, bezierCount), BoneTimeline1(frameCount, bezierCount, boneIndex, Property_X) {
_boneIndex(boneIndex) {
PropertyId ids[] = {((PropertyId) Property_X << 32) | boneIndex};
setPropertyIds(ids, 1);
} }
TranslateXTimeline::~TranslateXTimeline() { void TranslateXTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
MixDirection direction) {
pose._x = getRelativeValue(time, alpha, blend, pose._x, setup._x);
} }
void TranslateXTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, RTTI_IMPL(TranslateYTimeline, BoneTimeline1)
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(direction);
Bone *bone = skeleton._bones[_boneIndex]; TranslateYTimeline::TranslateYTimeline(size_t frameCount, size_t bezierCount, int boneIndex) :
if (bone->_active) bone->_x = getRelativeValue(time, alpha, blend, bone->_x, bone->_data._x); BoneTimeline1(frameCount, bezierCount, boneIndex, Property_Y) {
} }
RTTI_IMPL(TranslateYTimeline, CurveTimeline1) void TranslateYTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
MixDirection direction) {
TranslateYTimeline::TranslateYTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1( pose._y = getRelativeValue(time, alpha, blend, pose._y, setup._y);
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<Event *> *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);
} }