Type hierarchy fixes.

This commit is contained in:
Mario Zechner 2025-06-12 12:52:16 +02:00
parent 90536c3b49
commit 5347aed45a
4 changed files with 28 additions and 48 deletions

View File

@ -40,12 +40,19 @@ namespace spine {
/// An interface for timelines which change the property of a bone. /// An interface for timelines which change the property of a bone.
class SP_API BoneTimeline { class SP_API BoneTimeline {
RTTI_DECL
public: public:
BoneTimeline(); BoneTimeline(int boneIndex) : _boneIndex(boneIndex) {}
virtual ~BoneTimeline(); virtual ~BoneTimeline() {}
/// The index of the bone in Skeleton::getBones() that will be changed when this timeline is applied. /// The index of the bone in Skeleton::getBones() that will be changed when this timeline is applied.
virtual int getBoneIndex() = 0; virtual int getBoneIndex() { return _boneIndex; }
virtual void setBoneIndex(int inValue) { _boneIndex = inValue; }
protected:
int _boneIndex;
}; };
/// Base class for timelines that animate a single bone property. /// Base class for timelines that animate a single bone property.
@ -63,16 +70,10 @@ namespace spine {
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend, apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction, bool appliedPose) override; MixDirection direction, bool appliedPose) override;
virtual int getBoneIndex() override { return _boneIndex; }
void setBoneIndex(int inValue) { _boneIndex = inValue; }
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, virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
MixDirection direction) = 0; MixDirection direction) = 0;
int _boneIndex;
}; };
/// Base class for timelines that animate two bone properties. /// Base class for timelines that animate two bone properties.
@ -90,16 +91,11 @@ namespace spine {
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend, apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction, bool appliedPose) override; MixDirection direction, bool appliedPose) override;
virtual int getBoneIndex() override { return _boneIndex; }
void setBoneIndex(int inValue) { _boneIndex = inValue; }
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, virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
MixDirection direction) = 0; MixDirection direction) = 0;
int _boneIndex;
}; };
} }

View File

@ -36,20 +36,12 @@ namespace spine {
template<class P> template<class P>
class SP_API Pose : public SpineObject { class SP_API Pose : public SpineObject {
public: public:
Pose(); Pose() {};
virtual ~Pose(); virtual ~Pose() {};
/// Sets the pose values. /// Sets the pose values.
virtual void set(P& pose) = 0; virtual void set(P& pose) = 0;
}; };
template<class P>
Pose<P>::Pose() {
}
template<class P>
Pose<P>::~Pose() {
}
} }
#endif #endif

View File

@ -44,7 +44,6 @@ Animation::Animation(const String &name, Vector<Timeline *> &timelines, float du
_bones(), _bones(),
_duration(duration), _duration(duration),
_name(name) { _name(name) {
assert(_name.length() > 0);
setTimelines(timelines); setTimelines(timelines);
} }
@ -106,11 +105,11 @@ int Animation::search(Vector<float> &frames, float target, int step) {
void Animation::setTimelines(Vector<Timeline *> &timelines) { void Animation::setTimelines(Vector<Timeline *> &timelines) {
_timelines = timelines; _timelines = timelines;
size_t n = timelines.size(); size_t n = timelines.size();
_timelineIds.clear(); _timelineIds.clear();
_bones.clear(); _bones.clear();
HashMap<int, bool> boneSet; HashMap<int, bool> boneSet;
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
Timeline *timeline = timelines[i]; Timeline *timeline = timelines[i];
@ -118,14 +117,9 @@ void Animation::setTimelines(Vector<Timeline *> &timelines) {
for (size_t ii = 0; ii < propertyIds.size(); ii++) { for (size_t ii = 0; ii < propertyIds.size(); ii++) {
_timelineIds.put(propertyIds[ii], true); _timelineIds.put(propertyIds[ii], true);
} }
BoneTimeline *boneTimeline = nullptr; BoneTimeline *boneTimeline = timeline->getRTTI().instanceOf(BoneTimeline1::rtti) ?
if (timeline->getRTTI().instanceOf(BoneTimeline1::rtti)) { static_cast<BoneTimeline1 *>(timeline) : NULL;
boneTimeline = static_cast<BoneTimeline1 *>(timeline);
} else if (timeline->getRTTI().instanceOf(BoneTimeline2::rtti)) {
boneTimeline = static_cast<BoneTimeline2 *>(timeline);
}
if (boneTimeline) { if (boneTimeline) {
int boneIndex = boneTimeline->getBoneIndex(); int boneIndex = boneTimeline->getBoneIndex();
if (!boneSet.containsKey(boneIndex)) { if (!boneSet.containsKey(boneIndex)) {

View File

@ -38,16 +38,13 @@
using namespace spine; using namespace spine;
BoneTimeline::BoneTimeline() { RTTI_IMPL(BoneTimeline, BoneTimeline)
}
BoneTimeline::~BoneTimeline() {
}
RTTI_IMPL(BoneTimeline1, CurveTimeline1) RTTI_IMPL(BoneTimeline1, CurveTimeline1)
BoneTimeline1::BoneTimeline1(size_t frameCount, size_t bezierCount, int boneIndex, Property property) : BoneTimeline1::BoneTimeline1(size_t frameCount, size_t bezierCount, int boneIndex, Property property) :
CurveTimeline1(frameCount, bezierCount), _boneIndex(boneIndex) { BoneTimeline(boneIndex),
CurveTimeline1(frameCount, bezierCount) {
PropertyId ids[] = {((PropertyId) property << 32) | boneIndex}; PropertyId ids[] = {((PropertyId) property << 32) | boneIndex};
setPropertyIds(ids, 1); setPropertyIds(ids, 1);
} }
@ -59,14 +56,15 @@ void BoneTimeline1::apply(Skeleton &skeleton, float lastTime, float time, Vector
Bone *bone = skeleton._bones[_boneIndex]; Bone *bone = skeleton._bones[_boneIndex];
if (bone->isActive()) { if (bone->isActive()) {
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);
} }
} }
RTTI_IMPL(BoneTimeline2, CurveTimeline2) RTTI_IMPL(BoneTimeline2, CurveTimeline2)
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), _boneIndex(boneIndex) { BoneTimeline(boneIndex),
CurveTimeline2(frameCount, bezierCount) {
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);
} }
@ -78,6 +76,6 @@ void BoneTimeline2::apply(Skeleton &skeleton, float lastTime, float time, Vector
Bone *bone = skeleton._bones[_boneIndex]; Bone *bone = skeleton._bones[_boneIndex];
if (bone->isActive()) { if (bone->isActive()) {
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);
} }
} }