Explorar el Código

[cpp] Remove CurveTimeline2, replace with BoneTimeline2.

Mario Zechner hace 1 mes
padre
commit
31e0566b7d

+ 7 - 1
spine-cpp/include/spine/BoneTimeline.h

@@ -30,6 +30,7 @@
 #ifndef Spine_BoneTimeline_h
 #define Spine_BoneTimeline_h
 
+#include <cstddef>
 #include <spine/dll.h>
 #include <spine/CurveTimeline.h>
 
@@ -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;
 	};
 }
 

+ 0 - 18
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 */

+ 1 - 1
spine-cpp/include/spine/SkeletonBinary.h

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

+ 2 - 2
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<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);
 
 		Animation *readAnimation(Json *root, SkeletonData *skeletonData);

+ 10 - 3
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);
 	}
-}
+}
+
+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;
+}

+ 0 - 16
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;
-}

+ 11 - 11
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;

+ 11 - 11
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);
 		}
 	}
 

+ 1 - 1
spine-cpp/src/spine/SkeletonJson.cpp

@@ -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 time = Json::getFloat(keyMap, "time", 0);
 	float value1 = Json::getFloat(keyMap, name1, defaultValue) * scale, value2 = Json::getFloat(keyMap, name2, defaultValue) * scale;

+ 11 - 11
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);
 		}
 	}