diff --git a/spine-cpp/include/spine/BoneTimeline.h b/spine-cpp/include/spine/BoneTimeline.h index d78ae161c..b09c18de4 100644 --- a/spine-cpp/include/spine/BoneTimeline.h +++ b/spine-cpp/include/spine/BoneTimeline.h @@ -30,6 +30,7 @@ #ifndef Spine_BoneTimeline_h #define Spine_BoneTimeline_h +#include #include #include @@ -84,7 +85,7 @@ namespace spine { }; /// 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 SkeletonJson; friend class AnimationState; @@ -105,11 +106,16 @@ namespace spine { _boneIndex = inValue; } + virtual void setFrame(size_t frame, float time, float value1, float value2); + protected: /// 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; int _boneIndex; + + static const int ENTRIES = 3; + static const int VALUE1 = 1, VALUE2 = 2; }; } diff --git a/spine-cpp/include/spine/CurveTimeline.h b/spine-cpp/include/spine/CurveTimeline.h index 4a39ca47f..e1a03bb2e 100644 --- a/spine-cpp/include/spine/CurveTimeline.h +++ b/spine-cpp/include/spine/CurveTimeline.h @@ -94,24 +94,6 @@ namespace spine { 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); - - float getCurveValue(float time); - - protected: - static const int ENTRIES = 3; - static const int VALUE1 = 1; - static const int VALUE2 = 2; - }; } #endif /* Spine_CurveTimeline_h */ diff --git a/spine-cpp/include/spine/SkeletonBinary.h b/spine-cpp/include/spine/SkeletonBinary.h index ada33a220..6518a2578 100644 --- a/spine-cpp/include/spine/SkeletonBinary.h +++ b/spine-cpp/include/spine/SkeletonBinary.h @@ -61,7 +61,7 @@ namespace spine { class CurveTimeline1; - class CurveTimeline2; + class BoneTimeline2; class Sequence; diff --git a/spine-cpp/include/spine/SkeletonJson.h b/spine-cpp/include/spine/SkeletonJson.h index 34e418d2f..80d1e68e5 100644 --- a/spine-cpp/include/spine/SkeletonJson.h +++ b/spine-cpp/include/spine/SkeletonJson.h @@ -41,7 +41,7 @@ namespace spine { class CurveTimeline1; - class CurveTimeline2; + class BoneTimeline2; class VertexAttachment; @@ -102,7 +102,7 @@ namespace spine { static void readTimeline(Array &timelines, Json *keyMap, CurveTimeline1 *timeline, float defaultValue, float scale); - static void readTimeline(Array &timelines, Json *keyMap, CurveTimeline2 *timeline, const char *name1, const char *name2, + static void readTimeline(Array &timelines, Json *keyMap, BoneTimeline2 *timeline, const char *name1, const char *name2, float defaultValue, float scale); Animation *readAnimation(Json *root, SkeletonData *skeletonData); diff --git a/spine-cpp/src/spine/BoneTimeline.cpp b/spine-cpp/src/spine/BoneTimeline.cpp index d4b55c422..279c135d8 100644 --- a/spine-cpp/src/spine/BoneTimeline.cpp +++ b/spine-cpp/src/spine/BoneTimeline.cpp @@ -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) - : 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}; setPropertyIds(ids, 2); } @@ -76,4 +76,11 @@ void BoneTimeline2::apply(Skeleton &skeleton, float lastTime, float time, Array< if (bone->isActive()) { apply(appliedPose ? *bone->_applied : bone->_pose, bone->_data._setup, time, alpha, blend, direction); } -} \ No newline at end of file +} + +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; +} diff --git a/spine-cpp/src/spine/CurveTimeline.cpp b/spine-cpp/src/spine/CurveTimeline.cpp index 792e7a882..3ceb66341 100644 --- a/spine-cpp/src/spine/CurveTimeline.cpp +++ b/spine-cpp/src/spine/CurveTimeline.cpp @@ -244,19 +244,3 @@ float CurveTimeline1::getScaleValue(float time, float alpha, MixBlend blend, Mix } 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; -} diff --git a/spine-cpp/src/spine/ScaleTimeline.cpp b/spine-cpp/src/spine/ScaleTimeline.cpp index c9b1d3611..dc4c6f6b4 100644 --- a/spine-cpp/src/spine/ScaleTimeline.cpp +++ b/spine-cpp/src/spine/ScaleTimeline.cpp @@ -63,26 +63,26 @@ void ScaleTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float a } float x, y; - int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); - int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; + int i = Animation::search(_frames, time, BoneTimeline2::ENTRIES); + int curveType = (int) _curves[i / BoneTimeline2::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; + x = _frames[i + BoneTimeline2::VALUE1]; + y = _frames[i + BoneTimeline2::VALUE2]; + float t = (time - before) / (_frames[i + BoneTimeline2::ENTRIES] - before); + x += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE1] - x) * t; + y += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE2] - y) * t; break; } case CurveTimeline::STEPPED: { - x = _frames[i + CurveTimeline2::VALUE1]; - y = _frames[i + CurveTimeline2::VALUE2]; + x = _frames[i + BoneTimeline2::VALUE1]; + y = _frames[i + BoneTimeline2::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 = getBezierValue(time, i, BoneTimeline2::VALUE1, curveType - BoneTimeline2::BEZIER); + y = getBezierValue(time, i, BoneTimeline2::VALUE2, curveType + BoneTimeline2::BEZIER_SIZE - BoneTimeline2::BEZIER); } } x *= setup._scaleX; diff --git a/spine-cpp/src/spine/ShearTimeline.cpp b/spine-cpp/src/spine/ShearTimeline.cpp index 5dc4f9640..a76741f7f 100644 --- a/spine-cpp/src/spine/ShearTimeline.cpp +++ b/spine-cpp/src/spine/ShearTimeline.cpp @@ -63,26 +63,26 @@ void ShearTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float a } float x, y; - int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); - int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; + int i = Animation::search(_frames, time, BoneTimeline2::ENTRIES); + int curveType = (int) _curves[i / BoneTimeline2::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; + x = _frames[i + BoneTimeline2::VALUE1]; + y = _frames[i + BoneTimeline2::VALUE2]; + float t = (time - before) / (_frames[i + BoneTimeline2::ENTRIES] - before); + x += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE1] - x) * t; + y += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE2] - y) * t; break; } case CurveTimeline::STEPPED: { - x = _frames[i + CurveTimeline2::VALUE1]; - y = _frames[i + CurveTimeline2::VALUE2]; + x = _frames[i + BoneTimeline2::VALUE1]; + y = _frames[i + BoneTimeline2::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 = getBezierValue(time, i, BoneTimeline2::VALUE1, curveType - BoneTimeline2::BEZIER); + y = getBezierValue(time, i, BoneTimeline2::VALUE2, curveType + BoneTimeline2::BEZIER_SIZE - BoneTimeline2::BEZIER); } } diff --git a/spine-cpp/src/spine/SkeletonJson.cpp b/spine-cpp/src/spine/SkeletonJson.cpp index ab62c1874..cd6a6a63a 100644 --- a/spine-cpp/src/spine/SkeletonJson.cpp +++ b/spine-cpp/src/spine/SkeletonJson.cpp @@ -1407,7 +1407,7 @@ void SkeletonJson::readTimeline(Array &timelines, Json *keyMap, Curv } } -void SkeletonJson::readTimeline(Array &timelines, Json *keyMap, CurveTimeline2 *timeline, const char *name1, const char *name2, +void SkeletonJson::readTimeline(Array &timelines, Json *keyMap, BoneTimeline2 *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, value2 = Json::getFloat(keyMap, name2, defaultValue) * scale; diff --git a/spine-cpp/src/spine/TranslateTimeline.cpp b/spine-cpp/src/spine/TranslateTimeline.cpp index d1aa5b5d2..42937f001 100644 --- a/spine-cpp/src/spine/TranslateTimeline.cpp +++ b/spine-cpp/src/spine/TranslateTimeline.cpp @@ -63,26 +63,26 @@ void TranslateTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, flo } float x, y; - int i = Animation::search(_frames, time, CurveTimeline2::ENTRIES); - int curveType = (int) _curves[i / CurveTimeline2::ENTRIES]; + int i = Animation::search(_frames, time, BoneTimeline2::ENTRIES); + int curveType = (int) _curves[i / BoneTimeline2::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; + x = _frames[i + BoneTimeline2::VALUE1]; + y = _frames[i + BoneTimeline2::VALUE2]; + float t = (time - before) / (_frames[i + BoneTimeline2::ENTRIES] - before); + x += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE1] - x) * t; + y += (_frames[i + BoneTimeline2::ENTRIES + BoneTimeline2::VALUE2] - y) * t; break; } case CurveTimeline::STEPPED: { - x = _frames[i + CurveTimeline2::VALUE1]; - y = _frames[i + CurveTimeline2::VALUE2]; + x = _frames[i + BoneTimeline2::VALUE1]; + y = _frames[i + BoneTimeline2::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 = getBezierValue(time, i, BoneTimeline2::VALUE1, curveType - BoneTimeline2::BEZIER); + y = getBezierValue(time, i, BoneTimeline2::VALUE2, curveType + BoneTimeline2::BEZIER_SIZE - BoneTimeline2::BEZIER); } }