[cpp] Remove CurveTimeline2, replace with BoneTimeline2.

This commit is contained in:
Mario Zechner 2025-07-24 22:25:23 +02:00
parent 3f1339eb4e
commit 31e0566b7d
10 changed files with 54 additions and 75 deletions

View File

@ -30,6 +30,7 @@
#ifndef Spine_BoneTimeline_h #ifndef Spine_BoneTimeline_h
#define Spine_BoneTimeline_h #define Spine_BoneTimeline_h
#include <cstddef>
#include <spine/dll.h> #include <spine/dll.h>
#include <spine/CurveTimeline.h> #include <spine/CurveTimeline.h>
@ -84,7 +85,7 @@ namespace spine {
}; };
/// Base class for timelines that animate two bone properties. /// Base class for timelines that animate two bone properties.
class SP_API BoneTimeline2 : public CurveTimeline2, public BoneTimeline { class SP_API BoneTimeline2 : public CurveTimeline, public BoneTimeline {
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
friend class AnimationState; friend class AnimationState;
@ -105,11 +106,16 @@ namespace spine {
_boneIndex = inValue; _boneIndex = inValue;
} }
virtual void setFrame(size_t frame, float time, float value1, float value2);
protected: protected:
/// Applies changes to the pose based on the timeline values. /// Applies changes to the pose based on the timeline values.
virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend, MixDirection direction) = 0; virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend, MixDirection direction) = 0;
int _boneIndex; int _boneIndex;
static const int ENTRIES = 3;
static const int VALUE1 = 1, VALUE2 = 2;
}; };
} }

View File

@ -94,24 +94,6 @@ namespace spine {
static const int ENTRIES = 2; static const int ENTRIES = 2;
static const int VALUE = 1; 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);
float getCurveValue(float time);
protected:
static const int ENTRIES = 3;
static const int VALUE1 = 1;
static const int VALUE2 = 2;
};
} }
#endif /* Spine_CurveTimeline_h */ #endif /* Spine_CurveTimeline_h */

View File

@ -61,7 +61,7 @@ namespace spine {
class CurveTimeline1; class CurveTimeline1;
class CurveTimeline2; class BoneTimeline2;
class Sequence; class Sequence;

View File

@ -41,7 +41,7 @@ namespace spine {
class CurveTimeline1; class CurveTimeline1;
class CurveTimeline2; class BoneTimeline2;
class VertexAttachment; class VertexAttachment;
@ -102,7 +102,7 @@ namespace spine {
static void readTimeline(Array<Timeline *> &timelines, Json *keyMap, CurveTimeline1 *timeline, float defaultValue, float scale); static void readTimeline(Array<Timeline *> &timelines, Json *keyMap, CurveTimeline1 *timeline, float defaultValue, float scale);
static void readTimeline(Array<Timeline *> &timelines, Json *keyMap, CurveTimeline2 *timeline, const char *name1, const char *name2, static void readTimeline(Array<Timeline *> &timelines, Json *keyMap, BoneTimeline2 *timeline, const char *name1, const char *name2,
float defaultValue, float scale); float defaultValue, float scale);
Animation *readAnimation(Json *root, SkeletonData *skeletonData); Animation *readAnimation(Json *root, SkeletonData *skeletonData);

View File

@ -59,10 +59,10 @@ void BoneTimeline1::apply(Skeleton &skeleton, float lastTime, float time, Array<
} }
} }
RTTI_IMPL_MULTI(BoneTimeline2, CurveTimeline2, BoneTimeline) RTTI_IMPL_MULTI(BoneTimeline2, CurveTimeline, BoneTimeline)
BoneTimeline2::BoneTimeline2(size_t frameCount, size_t bezierCount, int boneIndex, Property property1, Property property2) BoneTimeline2::BoneTimeline2(size_t frameCount, size_t bezierCount, int boneIndex, Property property1, Property property2)
: CurveTimeline2(frameCount, bezierCount), BoneTimeline(boneIndex), _boneIndex(boneIndex) { : CurveTimeline(frameCount, BoneTimeline2::ENTRIES, bezierCount), BoneTimeline(boneIndex), _boneIndex(boneIndex) {
PropertyId ids[] = {((PropertyId) property1 << 32) | boneIndex, ((PropertyId) property2 << 32) | boneIndex}; PropertyId ids[] = {((PropertyId) property1 << 32) | boneIndex, ((PropertyId) property2 << 32) | boneIndex};
setPropertyIds(ids, 2); setPropertyIds(ids, 2);
} }
@ -77,3 +77,10 @@ void BoneTimeline2::apply(Skeleton &skeleton, float lastTime, float time, Array<
apply(appliedPose ? *bone->_applied : bone->_pose, bone->_data._setup, time, alpha, blend, direction); apply(appliedPose ? *bone->_applied : bone->_pose, bone->_data._setup, time, alpha, blend, direction);
} }
} }
void BoneTimeline2::setFrame(size_t frame, float time, float value1, float value2) {
frame *= ENTRIES;
_frames[frame] = time;
_frames[frame + VALUE1] = value1;
_frames[frame + VALUE2] = value2;
}

View File

@ -244,19 +244,3 @@ float CurveTimeline1::getScaleValue(float time, float alpha, MixBlend blend, Mix
} }
return current + (value - setup) * alpha; return current + (value - setup) * alpha;
} }
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;
}

View File

@ -63,26 +63,26 @@ void ScaleTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float a
} }
float x, y; float x, y;
int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); int i = Animation::search(_frames, time, BoneTimeline2::ENTRIES);
int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; int curveType = (int) _curves[i / BoneTimeline2::ENTRIES];
switch (curveType) { switch (curveType) {
case CurveTimeline::LINEAR: { case CurveTimeline::LINEAR: {
float before = _frames[i]; float before = _frames[i];
x = _frames[i + CurveTimeline2::VALUE1]; x = _frames[i + BoneTimeline2::VALUE1];
y = _frames[i + CurveTimeline2::VALUE2]; y = _frames[i + BoneTimeline2::VALUE2];
float t = (time - before) / (_frames[i + CurveTimeline2::ENTRIES] - before); float t = (time - before) / (_frames[i + BoneTimeline2::ENTRIES] - before);
x += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE1] - x) * t; x += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE1] - x) * t;
y += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE2] - y) * t; y += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE2] - y) * t;
break; break;
} }
case CurveTimeline::STEPPED: { case CurveTimeline::STEPPED: {
x = _frames[i + CurveTimeline2::VALUE1]; x = _frames[i + BoneTimeline2::VALUE1];
y = _frames[i + CurveTimeline2::VALUE2]; y = _frames[i + BoneTimeline2::VALUE2];
break; break;
} }
default: { default: {
x = getBezierValue(time, i, CurveTimeline2::VALUE1, curveType - CurveTimeline2::BEZIER); x = getBezierValue(time, i, BoneTimeline2::VALUE1, curveType - BoneTimeline2::BEZIER);
y = getBezierValue(time, i, CurveTimeline2::VALUE2, curveType + CurveTimeline2::BEZIER_SIZE - CurveTimeline2::BEZIER); y = getBezierValue(time, i, BoneTimeline2::VALUE2, curveType + BoneTimeline2::BEZIER_SIZE - BoneTimeline2::BEZIER);
} }
} }
x *= setup._scaleX; x *= setup._scaleX;

View File

@ -63,26 +63,26 @@ void ShearTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float a
} }
float x, y; float x, y;
int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); int i = Animation::search(_frames, time, BoneTimeline2::ENTRIES);
int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; int curveType = (int) _curves[i / BoneTimeline2::ENTRIES];
switch (curveType) { switch (curveType) {
case CurveTimeline::LINEAR: { case CurveTimeline::LINEAR: {
float before = _frames[i]; float before = _frames[i];
x = _frames[i + CurveTimeline2::VALUE1]; x = _frames[i + BoneTimeline2::VALUE1];
y = _frames[i + CurveTimeline2::VALUE2]; y = _frames[i + BoneTimeline2::VALUE2];
float t = (time - before) / (_frames[i + CurveTimeline2::ENTRIES] - before); float t = (time - before) / (_frames[i + BoneTimeline2::ENTRIES] - before);
x += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE1] - x) * t; x += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE1] - x) * t;
y += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE2] - y) * t; y += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE2] - y) * t;
break; break;
} }
case CurveTimeline::STEPPED: { case CurveTimeline::STEPPED: {
x = _frames[i + CurveTimeline2::VALUE1]; x = _frames[i + BoneTimeline2::VALUE1];
y = _frames[i + CurveTimeline2::VALUE2]; y = _frames[i + BoneTimeline2::VALUE2];
break; break;
} }
default: { default: {
x = getBezierValue(time, i, CurveTimeline2::VALUE1, curveType - CurveTimeline2::BEZIER); x = getBezierValue(time, i, BoneTimeline2::VALUE1, curveType - BoneTimeline2::BEZIER);
y = getBezierValue(time, i, CurveTimeline2::VALUE2, curveType + CurveTimeline2::BEZIER_SIZE - CurveTimeline2::BEZIER); y = getBezierValue(time, i, BoneTimeline2::VALUE2, curveType + BoneTimeline2::BEZIER_SIZE - BoneTimeline2::BEZIER);
} }
} }

View File

@ -1407,7 +1407,7 @@ void SkeletonJson::readTimeline(Array<Timeline *> &timelines, Json *keyMap, Curv
} }
} }
void SkeletonJson::readTimeline(Array<Timeline *> &timelines, Json *keyMap, CurveTimeline2 *timeline, const char *name1, const char *name2, void SkeletonJson::readTimeline(Array<Timeline *> &timelines, Json *keyMap, BoneTimeline2 *timeline, const char *name1, const char *name2,
float defaultValue, float scale) { float defaultValue, float scale) {
float time = Json::getFloat(keyMap, "time", 0); float time = Json::getFloat(keyMap, "time", 0);
float value1 = Json::getFloat(keyMap, name1, defaultValue) * scale, value2 = Json::getFloat(keyMap, name2, defaultValue) * scale; float value1 = Json::getFloat(keyMap, name1, defaultValue) * scale, value2 = Json::getFloat(keyMap, name2, defaultValue) * scale;

View File

@ -63,26 +63,26 @@ void TranslateTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, flo
} }
float x, y; float x, y;
int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); int i = Animation::search(_frames, time, BoneTimeline2::ENTRIES);
int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; int curveType = (int) _curves[i / BoneTimeline2::ENTRIES];
switch (curveType) { switch (curveType) {
case CurveTimeline::LINEAR: { case CurveTimeline::LINEAR: {
float before = _frames[i]; float before = _frames[i];
x = _frames[i + CurveTimeline2::VALUE1]; x = _frames[i + BoneTimeline2::VALUE1];
y = _frames[i + CurveTimeline2::VALUE2]; y = _frames[i + BoneTimeline2::VALUE2];
float t = (time - before) / (_frames[i + CurveTimeline2::ENTRIES] - before); float t = (time - before) / (_frames[i + BoneTimeline2::ENTRIES] - before);
x += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE1] - x) * t; x += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE1] - x) * t;
y += (_frames[i + CurveTimeline2::ENTRIES + CurveTimeline2::VALUE2] - y) * t; y += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE2] - y) * t;
break; break;
} }
case CurveTimeline::STEPPED: { case CurveTimeline::STEPPED: {
x = _frames[i + CurveTimeline2::VALUE1]; x = _frames[i + BoneTimeline2::VALUE1];
y = _frames[i + CurveTimeline2::VALUE2]; y = _frames[i + BoneTimeline2::VALUE2];
break; break;
} }
default: { default: {
x = getBezierValue(time, i, CurveTimeline2::VALUE1, curveType - CurveTimeline2::BEZIER); x = getBezierValue(time, i, BoneTimeline2::VALUE1, curveType - BoneTimeline2::BEZIER);
y = getBezierValue(time, i, CurveTimeline2::VALUE2, curveType + CurveTimeline2::BEZIER_SIZE - CurveTimeline2::BEZIER); y = getBezierValue(time, i, BoneTimeline2::VALUE2, curveType + BoneTimeline2::BEZIER_SIZE - BoneTimeline2::BEZIER);
} }
} }