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

This commit is contained in:
Mario Zechner 2025-07-24 14:16:19 +02:00
parent 04f0aca8b8
commit af05f0681d
23 changed files with 134 additions and 49 deletions

View File

@ -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);

View File

@ -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.

View File

@ -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;
};
}

View File

@ -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 */

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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 */

View File

@ -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;

View File

@ -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;
};
}

View File

@ -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;
};
}

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

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

View File

@ -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() {
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}