Ver Fonte

[cpp] Refactored type hierarchy to be single inheritance, multiple interfaces

Mario Zechner há 1 mês atrás
pai
commit
af05f0681d

+ 9 - 0
spine-cpp/include/spine/AttachmentTimeline.h

@@ -71,7 +71,16 @@ namespace spine {
 		/// The attachment name for each frame. May contain null values to clear the attachment.
 		Array<String> &getAttachmentNames();
 
+		virtual int getSlotIndex() override {
+			return _slotIndex;
+		}
+
+		virtual void setSlotIndex(int inValue) override {
+			_slotIndex = inValue;
+		}
+
 	protected:
+		int _slotIndex;
 		Array<String> _attachmentNames;
 
 		void setAttachment(Skeleton &skeleton, SlotPose &pose, String *attachmentName);

+ 7 - 0
spine-cpp/include/spine/ColorTimeline.h

@@ -103,6 +103,13 @@ namespace spine {
 
 		virtual void apply(Skeleton &skeleton, float lastTime, float time, Array<Event *> *pEvents, float alpha, MixBlend blend,
 						   MixDirection direction, bool appliedPose) override;
+
+		virtual int getSlotIndex() override;
+
+		virtual void setSlotIndex(int inValue) override;
+
+	protected:
+		int _slotIndex;
 	};
 
 	/// Changes a slot's SlotPose::getColor() and SlotPose::getDarkColor() for two color tinting.

+ 4 - 12
spine-cpp/include/spine/ConstraintTimeline.h

@@ -39,21 +39,13 @@ namespace spine {
 		RTTI_DECL_NOPARENT
 
 	public:
-		ConstraintTimeline(int constraintIndex);
-		virtual ~ConstraintTimeline() {
-		}
+		ConstraintTimeline();
+		virtual ~ConstraintTimeline();
 
 		/// The index of the constraint in Skeleton::getConstraints() that will be changed when this timeline is applied.
-		virtual int getConstraintIndex() {
-			return _constraintIndex;
-		}
+		virtual int getConstraintIndex() const = 0;
 
-		virtual void setConstraintIndex(int inValue) {
-			_constraintIndex = inValue;
-		}
-
-	protected:
-		int _constraintIndex;
+		virtual void setConstraintIndex(int inValue) = 0;
 	};
 }
 

+ 13 - 3
spine-cpp/include/spine/ConstraintTimeline1.h

@@ -30,9 +30,9 @@
 #ifndef Spine_ConstraintTimeline1_h
 #define Spine_ConstraintTimeline1_h
 
+#include <spine/ConstraintTimeline.h>
 #include <spine/CurveTimeline.h>
 #include <spine/Property.h>
-#include <spine/ConstraintTimeline.h>
 
 namespace spine {
 	/// Base class for single-value constraint timelines.
@@ -41,9 +41,19 @@ namespace spine {
 
 	public:
 		ConstraintTimeline1(size_t frameCount, size_t bezierCount, int constraintIndex, Property property);
-		virtual ~ConstraintTimeline1() {
+		virtual ~ConstraintTimeline1();
+
+		virtual int getConstraintIndex() const override {
+			return _constraintIndex;
 		}
+
+		virtual void setConstraintIndex(int inValue) override {
+			_constraintIndex = inValue;
+		}
+
+	protected:
+		int _constraintIndex;
 	};
-}
+}// namespace spine
 
 #endif /* Spine_ConstraintTimeline1_h */

+ 9 - 0
spine-cpp/include/spine/IkConstraintTimeline.h

@@ -58,7 +58,16 @@ namespace spine {
 		/// @param bendDirection 1 or -1.
 		void setFrame(int frame, float time, float mix, float softness, int bendDirection, bool compress, bool stretch);
 
+		virtual int getConstraintIndex() const override {
+			return _constraintIndex;
+		}
+
+		virtual void setConstraintIndex(int inValue) override {
+			_constraintIndex = inValue;
+		}
 	private:
+		int _constraintIndex;
+
 		static const int ENTRIES = 6;
 		static const int MIX = 1;
 		static const int SOFTNESS = 2;

+ 9 - 0
spine-cpp/include/spine/PathConstraintMixTimeline.h

@@ -57,7 +57,16 @@ namespace spine {
 		/// @param time The frame time in seconds.
 		void setFrame(int frame, float time, float mixRotate, float mixX, float mixY);
 
+		virtual int getConstraintIndex() const override {
+			return _constraintIndex;
+		}
+
+		virtual void setConstraintIndex(int inValue) override {
+			_constraintIndex = inValue;
+		}
 	private:
+		int _constraintIndex;
+
 		static const int ENTRIES = 4;
 		static const int ROTATE = 1;
 		static const int X = 2;

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

@@ -52,6 +52,6 @@ namespace spine {
 		virtual void apply(Skeleton &skeleton, float lastTime, float time, Array<Event *> *pEvents, float alpha, MixBlend blend,
 						   MixDirection direction, bool appliedPose) override;
 	};
-}
+}// namespace spine
 
 #endif /* Spine_PathConstraintPositionTimeline_h */

+ 18 - 8
spine-cpp/include/spine/PhysicsConstraintTimeline.h

@@ -30,11 +30,11 @@
 #ifndef Spine_PhysicsConstraintTimeline_h
 #define Spine_PhysicsConstraintTimeline_h
 
+#include <spine/ConstraintTimeline.h>
 #include <spine/CurveTimeline.h>
 #include <spine/PhysicsConstraint.h>
 #include <spine/PhysicsConstraintData.h>
 #include <spine/PhysicsConstraintPose.h>
-#include <spine/ConstraintTimeline.h>
 
 namespace spine {
 
@@ -53,12 +53,19 @@ namespace spine {
 		virtual void apply(Skeleton &skeleton, float lastTime, float time, Array<Event *> *pEvents, float alpha, MixBlend blend,
 						   MixDirection direction, bool appliedPose) override;
 
+						   		virtual int getConstraintIndex() const override {
+			return _constraintIndex;
+		}
+
+		virtual void setConstraintIndex(int inValue) override {
+			_constraintIndex = inValue;
+		}
+
 	protected:
 		virtual float get(PhysicsConstraintPose &pose) = 0;
 		virtual void set(PhysicsConstraintPose &pose, float value) = 0;
 		virtual bool global(PhysicsConstraintData &constraintData) = 0;
 
-	private:
 		int _constraintIndex;
 	};
 
@@ -140,7 +147,8 @@ namespace spine {
 		}
 	};
 
-	/// Changes a physics constraint's PhysicsConstraintPose::getMassInverse(). The timeline values are not inverted.
+	/// Changes a physics constraint's PhysicsConstraintPose::getMassInverse(). The
+	/// timeline values are not inverted.
 	class SP_API PhysicsConstraintMassTimeline : public PhysicsConstraintTimeline {
 		friend class SkeletonBinary;
 
@@ -255,7 +263,7 @@ namespace spine {
 	public:
 		/// @param constraintIndex -1 for all physics constraints in the skeleton.
 		explicit PhysicsConstraintResetTimeline(size_t frameCount, int constraintIndex)
-			: Timeline(frameCount, 1), ConstraintTimeline(constraintIndex) {
+			: Timeline(frameCount, 1), ConstraintTimeline(), _constraintIndex(constraintIndex) {
 			PropertyId ids[] = {((PropertyId) Property_PhysicsConstraintReset) << 32};
 			setPropertyIds(ids, 1);
 		}
@@ -267,12 +275,14 @@ namespace spine {
 			return (int) _frames.size();
 		}
 
-		/// The index of the physics constraint in Skeleton::getConstraints() that will be reset when this timeline is
-		/// applied, or -1 if all physics constraints in the skeleton will be reset.
-		virtual int getConstraintIndex() override {
+		virtual int getConstraintIndex() const override {
 			return _constraintIndex;
 		}
 
+		virtual void setConstraintIndex(int inValue) override {
+			_constraintIndex = inValue;
+		}
+
 		/// Sets the time for the specified frame.
 		void setFrame(int frame, float time) {
 			_frames[frame] = time;
@@ -281,6 +291,6 @@ namespace spine {
 	private:
 		int _constraintIndex;
 	};
-}
+}// namespace spine
 
 #endif /* Spine_PhysicsConstraintTimeline_h */

+ 5 - 0
spine-cpp/include/spine/SequenceTimeline.h

@@ -63,7 +63,12 @@ namespace spine {
 			return (Attachment *) _attachment;
 		}
 
+		virtual int getSlotIndex() override;
+
+		virtual void setSlotIndex(int inValue) override;
+
 	protected:
+		int _slotIndex;
 		HasTextureRegion *_attachment;
 
 		static const int ENTRIES = 3;

+ 6 - 0
spine-cpp/include/spine/SlotCurveTimeline.h

@@ -52,9 +52,15 @@ namespace spine {
 		virtual void apply(Skeleton &skeleton, float lastTime, float time, Array<Event *> *pEvents, float alpha, MixBlend blend,
 						   MixDirection direction, bool appliedPose) override;
 
+		virtual int getSlotIndex() override;
+
+		virtual void setSlotIndex(int inValue) override;
+
 	protected:
 		/// Applies the timeline to the slot pose.
 		virtual void apply(Slot &slot, SlotPose &pose, float time, float alpha, MixBlend blend) = 0;
+
+		int _slotIndex;
 	};
 }
 

+ 3 - 6
spine-cpp/include/spine/SlotTimeline.h

@@ -45,16 +45,13 @@ namespace spine {
 		friend class SlotCurveTimeline;
 
 	public:
-		SlotTimeline(int slotIndex);
+		SlotTimeline();
 		virtual ~SlotTimeline();
 
 		/// The index of the slot in Skeleton::getSlots() that will be changed when this timeline is applied.
-		virtual int getSlotIndex();
+		virtual int getSlotIndex() = 0;
 
-		virtual void setSlotIndex(int inValue);
-
-	protected:
-		int _slotIndex;
+		virtual void setSlotIndex(int inValue) = 0;
 	};
 }
 

+ 9 - 0
spine-cpp/include/spine/TransformConstraintTimeline.h

@@ -58,7 +58,16 @@ namespace spine {
 		/// @param time The frame time in seconds.
 		void setFrame(int frame, float time, float mixRotate, float mixX, float mixY, float mixScaleX, float mixScaleY, float mixShearY);
 
+		virtual int getConstraintIndex() const override {
+			return _constraintIndex;
+		}
+
+		virtual void setConstraintIndex(int inValue) override {
+			_constraintIndex = inValue;
+		}
 	private:
+		int _constraintIndex;
+
 		static const int ENTRIES = 7;
 		static const int ROTATE = 1;
 		static const int X = 2;

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

@@ -43,7 +43,7 @@ using namespace spine;
 
 RTTI_IMPL_MULTI(AttachmentTimeline, Timeline, SlotTimeline)
 
-AttachmentTimeline::AttachmentTimeline(size_t frameCount, int slotIndex) : Timeline(frameCount, 1), SlotTimeline(slotIndex) {
+AttachmentTimeline::AttachmentTimeline(size_t frameCount, int slotIndex) : Timeline(frameCount, 1), SlotTimeline(), _slotIndex(slotIndex) {
 	PropertyId ids[] = {((PropertyId) Property_Attachment << 32) | slotIndex};
 	setPropertyIds(ids, 1);
 

+ 9 - 1
spine-cpp/src/spine/ColorTimeline.cpp

@@ -203,7 +203,7 @@ void RGBTimeline::apply(Slot &slot, SlotPose &pose, float time, float alpha, Mix
 RTTI_IMPL(AlphaTimeline, SlotCurveTimeline)
 
 AlphaTimeline::AlphaTimeline(size_t frameCount, size_t bezierCount, int slotIndex)
-	: CurveTimeline1(frameCount, bezierCount), SlotTimeline(slotIndex) {
+	: CurveTimeline1(frameCount, bezierCount), SlotTimeline(), _slotIndex(slotIndex) {
 	PropertyId ids[] = {((PropertyId) Property_Alpha << 32) | slotIndex};
 	setPropertyIds(ids, 1);
 }
@@ -211,6 +211,14 @@ AlphaTimeline::AlphaTimeline(size_t frameCount, size_t bezierCount, int slotInde
 AlphaTimeline::~AlphaTimeline() {
 }
 
+int AlphaTimeline::getSlotIndex() {
+	return _slotIndex;
+}
+
+void AlphaTimeline::setSlotIndex(int inValue) {
+	_slotIndex = inValue;
+}
+
 void AlphaTimeline::apply(Skeleton &skeleton, float lastTime, float time, Array<Event *> *pEvents, float alpha, MixBlend blend,
 						  MixDirection direction, bool appliedPose) {
 	SP_UNUSED(lastTime);

+ 4 - 1
spine-cpp/src/spine/ConstraintTimeline.cpp

@@ -33,5 +33,8 @@ using namespace spine;
 
 RTTI_IMPL_NOPARENT(ConstraintTimeline)
 
-ConstraintTimeline::ConstraintTimeline(int constraintIndex) : _constraintIndex(constraintIndex) {
+ConstraintTimeline::ConstraintTimeline() {
+}
+
+ConstraintTimeline::~ConstraintTimeline() {
 }

+ 4 - 1
spine-cpp/src/spine/ConstraintTimeline1.cpp

@@ -34,7 +34,10 @@ using namespace spine;
 RTTI_IMPL_MULTI(ConstraintTimeline1, CurveTimeline1, ConstraintTimeline)
 
 ConstraintTimeline1::ConstraintTimeline1(size_t frameCount, size_t bezierCount, int constraintIndex, Property property)
-	: CurveTimeline1(frameCount, bezierCount), ConstraintTimeline(constraintIndex) {
+	: CurveTimeline1(frameCount, bezierCount), ConstraintTimeline(), _constraintIndex(constraintIndex) {
 	PropertyId ids[] = {((PropertyId) property << 32) | constraintIndex};
 	setPropertyIds(ids, 1);
+}
+
+ConstraintTimeline1::~ConstraintTimeline1() {
 }

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

@@ -45,7 +45,7 @@ using namespace spine;
 RTTI_IMPL_MULTI(IkConstraintTimeline, CurveTimeline, ConstraintTimeline)
 
 IkConstraintTimeline::IkConstraintTimeline(size_t frameCount, size_t bezierCount, int constraintIndex)
-	: CurveTimeline(frameCount, IkConstraintTimeline::ENTRIES, bezierCount), ConstraintTimeline(constraintIndex) {
+	: CurveTimeline(frameCount, IkConstraintTimeline::ENTRIES, bezierCount), ConstraintTimeline(), _constraintIndex(constraintIndex) {
 	PropertyId ids[] = {((PropertyId) Property_IkConstraint << 32) | constraintIndex};
 	setPropertyIds(ids, 1);
 }

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

@@ -45,7 +45,7 @@ using namespace spine;
 RTTI_IMPL_MULTI(PathConstraintMixTimeline, CurveTimeline, ConstraintTimeline)
 
 PathConstraintMixTimeline::PathConstraintMixTimeline(size_t frameCount, size_t bezierCount, int constraintIndex)
-	: CurveTimeline(frameCount, PathConstraintMixTimeline::ENTRIES, bezierCount), ConstraintTimeline(constraintIndex) {
+	: CurveTimeline(frameCount, PathConstraintMixTimeline::ENTRIES, bezierCount), ConstraintTimeline(), _constraintIndex(constraintIndex) {
 	PropertyId ids[] = {((PropertyId) Property_PathConstraintMix << 32) | constraintIndex};
 	setPropertyIds(ids, 1);
 }

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

@@ -52,7 +52,7 @@ RTTI_IMPL(PhysicsConstraintMixTimeline, PhysicsConstraintTimeline)
 RTTI_IMPL_MULTI(PhysicsConstraintResetTimeline, Timeline, ConstraintTimeline)
 
 PhysicsConstraintTimeline::PhysicsConstraintTimeline(size_t frameCount, size_t bezierCount, int constraintIndex, Property property)
-	: CurveTimeline1(frameCount, bezierCount), ConstraintTimeline(constraintIndex) {
+	: CurveTimeline1(frameCount, bezierCount), ConstraintTimeline(), _constraintIndex(constraintIndex) {
 	PropertyId ids[] = {((PropertyId) property << 32) | constraintIndex};
 	setPropertyIds(ids, 1);
 }

+ 9 - 1
spine-cpp/src/spine/SequenceTimeline.cpp

@@ -44,7 +44,7 @@ using namespace spine;
 RTTI_IMPL_MULTI(SequenceTimeline, Timeline, SlotTimeline)
 
 SequenceTimeline::SequenceTimeline(size_t frameCount, int slotIndex, Attachment *attachment)
-	: Timeline(frameCount, ENTRIES), SlotTimeline(slotIndex), _attachment((HasTextureRegion *) attachment) {
+	: Timeline(frameCount, ENTRIES), SlotTimeline(), _slotIndex(slotIndex), _attachment((HasTextureRegion *) attachment) {
 	int sequenceId = 0;
 	if (attachment->getRTTI().instanceOf(RegionAttachment::rtti)) sequenceId = ((RegionAttachment *) attachment)->getSequence()->getId();
 	if (attachment->getRTTI().instanceOf(MeshAttachment::rtti)) sequenceId = ((MeshAttachment *) attachment)->getSequence()->getId();
@@ -63,6 +63,14 @@ void SequenceTimeline::setFrame(int frame, float time, SequenceMode mode, int in
 	frames[frame + DELAY] = delay;
 }
 
+int SequenceTimeline::getSlotIndex() {
+	return _slotIndex;
+}
+
+void SequenceTimeline::setSlotIndex(int inValue) {
+	_slotIndex = inValue;
+}
+
 void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Array<Event *> *pEvents, float alpha, MixBlend blend,
 							 MixDirection direction, bool appliedPose) {
 	SP_UNUSED(alpha);

+ 9 - 1
spine-cpp/src/spine/SlotCurveTimeline.cpp

@@ -39,12 +39,20 @@ using namespace spine;
 RTTI_IMPL_MULTI(SlotCurveTimeline, CurveTimeline, SlotTimeline)
 
 SlotCurveTimeline::SlotCurveTimeline(size_t frameCount, size_t frameEntries, size_t bezierCount, int slotIndex)
-	: CurveTimeline(frameCount, frameEntries, bezierCount), SlotTimeline(slotIndex) {
+	: CurveTimeline(frameCount, frameEntries, bezierCount), SlotTimeline(), _slotIndex(slotIndex) {
 }
 
 SlotCurveTimeline::~SlotCurveTimeline() {
 }
 
+int SlotCurveTimeline::getSlotIndex() {
+	return _slotIndex;
+}
+
+void SlotCurveTimeline::setSlotIndex(int inValue) {
+	_slotIndex = inValue;
+}
+
 void SlotCurveTimeline::apply(Skeleton &skeleton, float lastTime, float time, Array<Event *> *pEvents, float alpha, MixBlend blend,
 							  MixDirection direction, bool appliedPose) {
 	SP_UNUSED(lastTime);

+ 1 - 9
spine-cpp/src/spine/SlotTimeline.cpp

@@ -33,16 +33,8 @@ using namespace spine;
 
 RTTI_IMPL_NOPARENT(SlotTimeline)
 
-SlotTimeline::SlotTimeline(int slotIndex) : _slotIndex(slotIndex) {
+SlotTimeline::SlotTimeline() {
 }
 
 SlotTimeline::~SlotTimeline() {
-}
-
-int SlotTimeline::getSlotIndex() {
-	return _slotIndex;
-}
-
-void SlotTimeline::setSlotIndex(int inValue) {
-	_slotIndex = inValue;
 }

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

@@ -45,7 +45,7 @@ using namespace spine;
 RTTI_IMPL_MULTI(TransformConstraintTimeline, CurveTimeline, ConstraintTimeline)
 
 TransformConstraintTimeline::TransformConstraintTimeline(size_t frameCount, size_t bezierCount, int transformConstraintIndex)
-	: CurveTimeline(frameCount, TransformConstraintTimeline::ENTRIES, bezierCount), ConstraintTimeline(transformConstraintIndex) {
+	: CurveTimeline(frameCount, TransformConstraintTimeline::ENTRIES, bezierCount), ConstraintTimeline(), _constraintIndex(transformConstraintIndex) {
 	PropertyId ids[] = {((PropertyId) Property_TransformConstraint << 32) | transformConstraintIndex};
 	setPropertyIds(ids, 1);
 }