From 5347aed45a0773f502bb44230817a4ea6e428294 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 12 Jun 2025 12:52:16 +0200 Subject: [PATCH] Type hierarchy fixes. --- .../spine-cpp/include/spine/BoneTimeline.h | 26 ++++++++----------- spine-cpp/spine-cpp/include/spine/Pose.h | 14 +++------- spine-cpp/spine-cpp/src/spine/Animation.cpp | 16 ++++-------- .../spine-cpp/src/spine/BoneTimeline.cpp | 20 +++++++------- 4 files changed, 28 insertions(+), 48 deletions(-) diff --git a/spine-cpp/spine-cpp/include/spine/BoneTimeline.h b/spine-cpp/spine-cpp/include/spine/BoneTimeline.h index f745ca8d0..5c7b2b368 100644 --- a/spine-cpp/spine-cpp/include/spine/BoneTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/BoneTimeline.h @@ -40,12 +40,19 @@ namespace spine { /// An interface for timelines which change the property of a bone. class SP_API BoneTimeline { + RTTI_DECL + public: - BoneTimeline(); - virtual ~BoneTimeline(); - + BoneTimeline(int boneIndex) : _boneIndex(boneIndex) {} + virtual ~BoneTimeline() {} + /// 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. @@ -63,16 +70,10 @@ namespace spine { apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, MixDirection direction, bool appliedPose) override; - virtual int getBoneIndex() override { return _boneIndex; } - - void setBoneIndex(int inValue) { _boneIndex = inValue; } - 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; }; /// Base class for timelines that animate two bone properties. @@ -90,16 +91,11 @@ namespace spine { apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, MixDirection direction, bool appliedPose) override; - virtual int getBoneIndex() override { return _boneIndex; } - - void setBoneIndex(int inValue) { _boneIndex = inValue; } - 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; }; } diff --git a/spine-cpp/spine-cpp/include/spine/Pose.h b/spine-cpp/spine-cpp/include/spine/Pose.h index 819acb317..629e163f6 100644 --- a/spine-cpp/spine-cpp/include/spine/Pose.h +++ b/spine-cpp/spine-cpp/include/spine/Pose.h @@ -36,20 +36,12 @@ namespace spine { template class SP_API Pose : public SpineObject { public: - Pose(); - virtual ~Pose(); - + Pose() {}; + virtual ~Pose() {}; + /// Sets the pose values. virtual void set(P& pose) = 0; }; - - template - Pose

::Pose() { - } - - template - Pose

::~Pose() { - } } #endif \ No newline at end of file diff --git a/spine-cpp/spine-cpp/src/spine/Animation.cpp b/spine-cpp/spine-cpp/src/spine/Animation.cpp index 0319271fa..9d996679a 100644 --- a/spine-cpp/spine-cpp/src/spine/Animation.cpp +++ b/spine-cpp/spine-cpp/src/spine/Animation.cpp @@ -44,7 +44,6 @@ Animation::Animation(const String &name, Vector &timelines, float du _bones(), _duration(duration), _name(name) { - assert(_name.length() > 0); setTimelines(timelines); } @@ -106,11 +105,11 @@ int Animation::search(Vector &frames, float target, int step) { void Animation::setTimelines(Vector &timelines) { _timelines = timelines; - + size_t n = timelines.size(); _timelineIds.clear(); _bones.clear(); - + HashMap boneSet; for (size_t i = 0; i < n; i++) { Timeline *timeline = timelines[i]; @@ -118,14 +117,9 @@ void Animation::setTimelines(Vector &timelines) { for (size_t ii = 0; ii < propertyIds.size(); ii++) { _timelineIds.put(propertyIds[ii], true); } - - BoneTimeline *boneTimeline = nullptr; - if (timeline->getRTTI().instanceOf(BoneTimeline1::rtti)) { - boneTimeline = static_cast(timeline); - } else if (timeline->getRTTI().instanceOf(BoneTimeline2::rtti)) { - boneTimeline = static_cast(timeline); - } - + + BoneTimeline *boneTimeline = timeline->getRTTI().instanceOf(BoneTimeline1::rtti) ? + static_cast(timeline) : NULL; if (boneTimeline) { int boneIndex = boneTimeline->getBoneIndex(); if (!boneSet.containsKey(boneIndex)) { diff --git a/spine-cpp/spine-cpp/src/spine/BoneTimeline.cpp b/spine-cpp/spine-cpp/src/spine/BoneTimeline.cpp index c7a6cf67c..110fd0d72 100644 --- a/spine-cpp/spine-cpp/src/spine/BoneTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/BoneTimeline.cpp @@ -38,16 +38,13 @@ using namespace spine; -BoneTimeline::BoneTimeline() { -} - -BoneTimeline::~BoneTimeline() { -} +RTTI_IMPL(BoneTimeline, BoneTimeline) RTTI_IMPL(BoneTimeline1, CurveTimeline1) -BoneTimeline1::BoneTimeline1(size_t frameCount, size_t bezierCount, int boneIndex, Property property) : - CurveTimeline1(frameCount, bezierCount), _boneIndex(boneIndex) { +BoneTimeline1::BoneTimeline1(size_t frameCount, size_t bezierCount, int boneIndex, Property property) : + BoneTimeline(boneIndex), + CurveTimeline1(frameCount, bezierCount) { PropertyId ids[] = {((PropertyId) property << 32) | boneIndex}; setPropertyIds(ids, 1); } @@ -59,14 +56,15 @@ void BoneTimeline1::apply(Skeleton &skeleton, float lastTime, float time, Vector Bone *bone = skeleton._bones[_boneIndex]; 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) -BoneTimeline2::BoneTimeline2(size_t frameCount, size_t bezierCount, int boneIndex, Property property1, Property property2) : - CurveTimeline2(frameCount, bezierCount), _boneIndex(boneIndex) { +BoneTimeline2::BoneTimeline2(size_t frameCount, size_t bezierCount, int boneIndex, Property property1, Property property2) : + BoneTimeline(boneIndex), + CurveTimeline2(frameCount, bezierCount) { PropertyId ids[] = {((PropertyId) property1 << 32) | boneIndex, ((PropertyId) property2 << 32) | boneIndex}; setPropertyIds(ids, 2); } @@ -78,6 +76,6 @@ void BoneTimeline2::apply(Skeleton &skeleton, float lastTime, float time, Vector Bone *bone = skeleton._bones[_boneIndex]; 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); } } \ No newline at end of file