[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-06-11 16:13:17 +02:00
parent b605f0ccac
commit 11435f471a
3 changed files with 51 additions and 106 deletions

View File

@ -39,10 +39,14 @@ namespace spine {
/// Stores a bone's local pose.
class SP_API BoneLocal : public Pose<BoneLocal> {
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

View File

@ -30,10 +30,11 @@
#ifndef Spine_ShearTimeline_h
#define Spine_ShearTimeline_h
#include <spine/TranslateTimeline.h>
#include <spine/BoneTimeline.h>
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<Event *> *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<Event *> *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<Event *> *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;
};
}

View File

@ -31,6 +31,7 @@
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/Bone.h>
#include <spine/BoneData.h>
@ -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<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;
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<Event *> *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<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->_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);
}