[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-06-23 18:10:38 +02:00
parent 2868c79f7c
commit d22ada68e5
17 changed files with 115 additions and 76 deletions

View File

@ -30,6 +30,7 @@
#ifndef Spine_Bone_h #ifndef Spine_Bone_h
#define Spine_Bone_h #define Spine_Bone_h
#include <spine/Posed.h>
#include <spine/PosedActive.h> #include <spine/PosedActive.h>
#include <spine/BoneData.h> #include <spine/BoneData.h>
#include <spine/BoneLocal.h> #include <spine/BoneLocal.h>
@ -42,7 +43,7 @@ namespace spine {
/// A bone has a local transform which is used to compute its world transform. A bone also has an applied transform, which is a /// A bone has a local transform which is used to compute its world transform. A bone also has an applied transform, which is a
/// local transform that can be applied to compute the world transform. The local transform and applied transform may differ if a /// local transform that can be applied to compute the world transform. The local transform and applied transform may differ if a
/// constraint or application code modifies the world transform after it was computed from the local transform. /// constraint or application code modifies the world transform after it was computed from the local transform.
class SP_API Bone : public PosedActiveGeneric<BoneData, BoneLocal, BonePose> { class SP_API Bone : public PosedGeneric<BoneData, BoneLocal, BonePose>, public PosedActive {
friend class AnimationState; friend class AnimationState;
friend class RotateTimeline; friend class RotateTimeline;
friend class IkConstraint; friend class IkConstraint;

View File

@ -30,6 +30,7 @@
#ifndef Spine_Constraint_h #ifndef Spine_Constraint_h
#define Spine_Constraint_h #define Spine_Constraint_h
#include <spine/Posed.h>
#include <spine/PosedActive.h> #include <spine/PosedActive.h>
#include <spine/Update.h> #include <spine/Update.h>
#include <spine/RTTI.h> #include <spine/RTTI.h>
@ -38,35 +39,50 @@
namespace spine { namespace spine {
class Skeleton; class Skeleton;
class SP_API Constraint: public Update { class SP_API Constraint : public Update {
RTTI_DECL_NOPARENT RTTI_DECL_NOPARENT
public: friend class Skeleton;
Constraint();
virtual ~Constraint();
ConstraintData &getData();
};
template<class T, class D, class P>
class SP_API ConstraintGeneric : public PosedActiveGeneric<D, P, P>, public Constraint {
RTTI_DECL
public: public:
ConstraintGeneric(D& data) : PosedActiveGeneric<D, P, P>(data), Constraint() { Constraint();
} virtual ~Constraint();
virtual ~ConstraintGeneric() { virtual ConstraintData &getData() = 0;
}
virtual void sort(Skeleton& skeleton) = 0; virtual void sort(Skeleton &skeleton) = 0;
virtual bool isSourceActive() { virtual bool isSourceActive() {
return true; return true;
} }
virtual void pose() = 0;
// Inherited from Update // Inherited from Update
virtual void update(Skeleton& skeleton, Physics physics) override = 0; virtual void update(Skeleton &skeleton, Physics physics) override = 0;
protected:
bool _active;
}; };
}
template<class T, class D, class P>
class SP_API ConstraintGeneric : public PosedGeneric<D, P, P>, public PosedActive, public Constraint {
RTTI_DECL
public:
ConstraintGeneric(D &data) : PosedGeneric<D, P, P>(data), PosedActive(), Constraint() {
}
virtual ~ConstraintGeneric() {
}
virtual ConstraintData &getData() override {
return PosedGeneric<D, P, P>::getData();
}
virtual void pose() override {
PosedGeneric<D, P, P>::pose();
}
};
}// namespace spine
#endif /* Spine_Constraint_h */ #endif /* Spine_Constraint_h */

View File

@ -30,12 +30,13 @@
#ifndef Spine_ConstraintData_h #ifndef Spine_ConstraintData_h
#define Spine_ConstraintData_h #define Spine_ConstraintData_h
#include <spine/PosedData.h>
#include <spine/SpineString.h> #include <spine/SpineString.h>
#include <spine/SpineObject.h>
#include <spine/RTTI.h> #include <spine/RTTI.h>
namespace spine { namespace spine {
class Skeleton; class Skeleton;
class Constraint;
/// Base class for all constraint data types. /// Base class for all constraint data types.
class SP_API ConstraintData : public SpineObject { class SP_API ConstraintData : public SpineObject {
@ -44,25 +45,12 @@ namespace spine {
ConstraintData(const String &name); ConstraintData(const String &name);
virtual ~ConstraintData(); virtual ~ConstraintData();
const String &getName() const; const String &getName() const;
virtual Constraint* create(Skeleton& skeleton) = 0;
private: private:
String _name; String _name;
}; };
/// Generic base class for all constraint data.
template<class T, class P>
class SP_API ConstraintDataGeneric : public PosedDataGeneric<P>, public ConstraintData {
friend class SkeletonBinary;
friend class SkeletonJson;
public:
ConstraintDataGeneric(const String &name) : PosedDataGeneric<P>(name), ConstraintData(name) {
}
virtual ~ConstraintDataGeneric() {
}
/// Creates a constraint instance.
virtual T* create(Skeleton& skeleton) = 0;
};
} }
#endif /* Spine_ConstraintData_h */ #endif /* Spine_ConstraintData_h */

View File

@ -34,13 +34,14 @@
#include <spine/SpineObject.h> #include <spine/SpineObject.h>
#include <spine/SpineString.h> #include <spine/SpineString.h>
#include <spine/ConstraintData.h> #include <spine/ConstraintData.h>
#include <spine/PosedData.h>
#include <spine/IkConstraintPose.h> #include <spine/IkConstraintPose.h>
namespace spine { namespace spine {
class BoneData; class BoneData;
class IkConstraint; class IkConstraint;
class SP_API IkConstraintData : public ConstraintDataGeneric<IkConstraint, IkConstraintPose> { class SP_API IkConstraintData : public ConstraintData, public PosedDataGeneric<IkConstraintPose> {
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
@ -56,6 +57,8 @@ namespace spine {
public: public:
explicit IkConstraintData(const String &name); explicit IkConstraintData(const String &name);
virtual Constraint* create(Skeleton& skeleton) override;
/// The bones that are constrained by this IK Constraint. /// The bones that are constrained by this IK Constraint.
Vector<BoneData *> &getBones(); Vector<BoneData *> &getBones();

View File

@ -31,6 +31,7 @@
#define Spine_PathConstraintData_h #define Spine_PathConstraintData_h
#include <spine/ConstraintData.h> #include <spine/ConstraintData.h>
#include <spine/PosedData.h>
#include <spine/Vector.h> #include <spine/Vector.h>
#include <spine/PathConstraintPose.h> #include <spine/PathConstraintPose.h>
#include <spine/dll.h> #include <spine/dll.h>
@ -47,7 +48,7 @@ namespace spine {
/// Stores the setup pose for a PathConstraint. /// Stores the setup pose for a PathConstraint.
/// ///
/// See https://esotericsoftware.com/spine-path-constraints Path constraints in the Spine User Guide. /// See https://esotericsoftware.com/spine-path-constraints Path constraints in the Spine User Guide.
class SP_API PathConstraintData : public ConstraintDataGeneric<PathConstraint, PathConstraintPose> { class SP_API PathConstraintData : public ConstraintData, public PosedDataGeneric<PathConstraintPose> {
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
@ -67,6 +68,8 @@ namespace spine {
explicit PathConstraintData(const String &name); explicit PathConstraintData(const String &name);
virtual Constraint* create(Skeleton& skeleton) override;
/// The bones that will be modified by this path constraint. /// The bones that will be modified by this path constraint.
Vector<BoneData *> &getBones(); Vector<BoneData *> &getBones();

View File

@ -31,6 +31,7 @@
#define Spine_PhysicsConstraintData_h #define Spine_PhysicsConstraintData_h
#include <spine/ConstraintData.h> #include <spine/ConstraintData.h>
#include <spine/PosedData.h>
#include <spine/PhysicsConstraintPose.h> #include <spine/PhysicsConstraintPose.h>
namespace spine { namespace spine {
@ -40,7 +41,7 @@ namespace spine {
/// Stores the setup pose for a PhysicsConstraint. /// Stores the setup pose for a PhysicsConstraint.
/// ///
/// See https://esotericsoftware.com/spine-physics-constraints Physics constraints in the Spine User Guide. /// See https://esotericsoftware.com/spine-physics-constraints Physics constraints in the Spine User Guide.
class SP_API PhysicsConstraintData : public ConstraintDataGeneric<PhysicsConstraint, PhysicsConstraintPose> { class SP_API PhysicsConstraintData : public ConstraintData, public PosedDataGeneric<PhysicsConstraintPose> {
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
friend class PhysicsConstraint; friend class PhysicsConstraint;
@ -50,6 +51,8 @@ namespace spine {
public: public:
explicit PhysicsConstraintData(const String &name); explicit PhysicsConstraintData(const String &name);
virtual Constraint* create(Skeleton& skeleton) override;
/// The bone constrained by this physics constraint. /// The bone constrained by this physics constraint.
BoneData* getBone(); BoneData* getBone();
void setBone(BoneData* bone); void setBone(BoneData* bone);

View File

@ -1,8 +1,8 @@
/****************************************************************************** /******************************************************************************
* Spine Runtimes License Agreement * Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions. * Last updated April 5, 2025. Replaces all prior versions.
* *
* Copyright (c) 2013-2020, Esoteric Software LLC * Copyright (c) 2013-2025, Esoteric Software LLC
* *
* Integration of the Spine Runtimes into software or otherwise creating * Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and * derivative works of the Spine Runtimes is permitted under the terms and
@ -27,31 +27,24 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#ifndef SPINE_POSEDACTIVE_H_ #ifndef Spine_PosedActive_h
#define SPINE_POSEDACTIVE_H_ #define Spine_PosedActive_h
#include <spine/dll.h> #include <spine/dll.h>
#include <spine/Posed.h>
namespace spine { namespace spine {
/// Simple mixin class that adds active state tracking
template<class D, class P, class A> class SP_API PosedActive {
class SP_API PosedActiveGeneric : public PosedGeneric<D, P, A> {
friend class SlotCurveTimeline;
public:
PosedActiveGeneric(D &data): PosedGeneric<D, P, A>(data), _active(false) {
this->setupPose();
}
virtual ~PosedActiveGeneric() {}
bool isActive() {
return _active;
}
protected: protected:
bool _active; bool _active;
};
}// namespace spine
#endif /* SPINE_POSEDACTIVE_H_ */ public:
PosedActive() : _active(true) {}
virtual ~PosedActive() {}
bool isActive() const { return _active; }
void setActive(bool active) { _active = active; }
};
}
#endif /* Spine_PosedActive_h */

View File

@ -71,7 +71,7 @@ namespace spine {
/// contains this constraint. /// contains this constraint.
/// ///
/// See Skin::getConstraints(). /// See Skin::getConstraints().
bool getSkinRequired() { return _skinRequired; }; bool isSkinRequired() { return _skinRequired; };
void setSkinRequired(bool skinRequired) { _skinRequired = skinRequired; }; void setSkinRequired(bool skinRequired) { _skinRequired = skinRequired; };
protected: protected:

View File

@ -31,6 +31,7 @@
#define Spine_SliderData_h #define Spine_SliderData_h
#include <spine/ConstraintData.h> #include <spine/ConstraintData.h>
#include <spine/PosedData.h>
#include <spine/SliderPose.h> #include <spine/SliderPose.h>
#include <spine/SpineString.h> #include <spine/SpineString.h>
@ -44,7 +45,7 @@ namespace spine {
/// Stores the setup pose for a PhysicsConstraint. /// Stores the setup pose for a PhysicsConstraint.
/// ///
/// See https://esotericsoftware.com/spine-physics-constraints Physics constraints in the Spine User Guide. /// See https://esotericsoftware.com/spine-physics-constraints Physics constraints in the Spine User Guide.
class SP_API SliderData : public ConstraintDataGeneric<Slider, SliderPose> { class SP_API SliderData : public ConstraintData, public PosedDataGeneric<SliderPose> {
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
friend class Slider; friend class Slider;
@ -55,7 +56,7 @@ namespace spine {
explicit SliderData(const String &name); explicit SliderData(const String &name);
/// Creates a slider instance. /// Creates a slider instance.
virtual Slider* create(Skeleton& skeleton) override; virtual Constraint* create(Skeleton& skeleton) override;
Animation* getAnimation(); Animation* getAnimation();
void setAnimation(Animation* animation); void setAnimation(Animation* animation);

View File

@ -31,6 +31,7 @@
#define Spine_TransformConstraintData_h #define Spine_TransformConstraintData_h
#include <spine/ConstraintData.h> #include <spine/ConstraintData.h>
#include <spine/PosedData.h>
#include <spine/Vector.h> #include <spine/Vector.h>
#include <spine/TransformConstraintPose.h> #include <spine/TransformConstraintPose.h>
@ -149,7 +150,7 @@ namespace spine {
/// Stores the setup pose for a TransformConstraint. /// Stores the setup pose for a TransformConstraint.
/// ///
/// See https://esotericsoftware.com/spine-transform-constraints Transform constraints in the Spine User Guide. /// See https://esotericsoftware.com/spine-transform-constraints Transform constraints in the Spine User Guide.
class SP_API TransformConstraintData : public ConstraintDataGeneric<TransformConstraint, TransformConstraintPose> { class SP_API TransformConstraintData : public ConstraintData, public PosedDataGeneric<TransformConstraintPose> {
public: public:
RTTI_DECL RTTI_DECL
static const int ROTATION = 0, X = 1, Y = 2, SCALEX = 3, SCALEY = 4, SHEARY = 5; static const int ROTATION = 0, X = 1, Y = 2, SCALEX = 3, SCALEY = 4, SHEARY = 5;
@ -163,6 +164,8 @@ namespace spine {
explicit TransformConstraintData(const String &name); explicit TransformConstraintData(const String &name);
~TransformConstraintData(); ~TransformConstraintData();
virtual Constraint* create(Skeleton& skeleton) override;
/// The bones that will be modified by this transform constraint. /// The bones that will be modified by this transform constraint.
Vector<BoneData*>& getBones(); Vector<BoneData*>& getBones();

View File

@ -36,7 +36,8 @@ using namespace spine;
RTTI_IMPL_NOPARENT(Bone) RTTI_IMPL_NOPARENT(Bone)
Bone::Bone(BoneData &data, Bone *parent) : PosedActiveGeneric(data), Bone::Bone(BoneData &data, Bone *parent) : PosedGeneric<BoneData, BoneLocal, BonePose>(data),
PosedActive(),
_parent(parent), _parent(parent),
_children(), _children(),
_sorted(false) { _sorted(false) {

View File

@ -28,14 +28,16 @@
*****************************************************************************/ *****************************************************************************/
#include <spine/IkConstraintData.h> #include <spine/IkConstraintData.h>
#include <spine/IkConstraint.h>
#include <spine/BoneData.h> #include <spine/BoneData.h>
#include <spine/Skeleton.h>
using namespace spine; using namespace spine;
RTTI_IMPL(IkConstraintData, ConstraintData) RTTI_IMPL(IkConstraintData, ConstraintData)
IkConstraintData::IkConstraintData(const String &name) : ConstraintDataGeneric<IkConstraint, IkConstraintPose>(name), IkConstraintData::IkConstraintData(const String &name) : ConstraintData(name),
PosedDataGeneric<IkConstraintPose>(name),
_target(NULL), _target(NULL),
_uniform(false) { _uniform(false) {
} }
@ -59,3 +61,7 @@ bool IkConstraintData::getUniform() {
void IkConstraintData::setUniform(bool uniform) { void IkConstraintData::setUniform(bool uniform) {
_uniform = uniform; _uniform = uniform;
} }
Constraint* IkConstraintData::create(Skeleton& skeleton) {
return new (__FILE__, __LINE__) IkConstraint(*this, skeleton);
}

View File

@ -28,6 +28,7 @@
*****************************************************************************/ *****************************************************************************/
#include <spine/PathConstraintData.h> #include <spine/PathConstraintData.h>
#include <spine/PathConstraint.h>
#include <spine/BoneData.h> #include <spine/BoneData.h>
#include <spine/SlotData.h> #include <spine/SlotData.h>
#include <spine/Skeleton.h> #include <spine/Skeleton.h>
@ -36,7 +37,8 @@ using namespace spine;
RTTI_IMPL(PathConstraintData, ConstraintData) RTTI_IMPL(PathConstraintData, ConstraintData)
PathConstraintData::PathConstraintData(const String &name) : ConstraintDataGeneric<PathConstraint, PathConstraintPose>(name), PathConstraintData::PathConstraintData(const String &name) : ConstraintData(name),
PosedDataGeneric<PathConstraintPose>(name),
_slot(NULL), _slot(NULL),
_positionMode(PositionMode_Fixed), _positionMode(PositionMode_Fixed),
_spacingMode(SpacingMode_Length), _spacingMode(SpacingMode_Length),
@ -88,3 +90,7 @@ float PathConstraintData::getOffsetRotation() {
void PathConstraintData::setOffsetRotation(float offsetRotation) { void PathConstraintData::setOffsetRotation(float offsetRotation) {
_offsetRotation = offsetRotation; _offsetRotation = offsetRotation;
} }
Constraint* PathConstraintData::create(Skeleton& skeleton) {
return new (__FILE__, __LINE__) PathConstraint(*this, skeleton);
}

View File

@ -28,13 +28,16 @@
*****************************************************************************/ *****************************************************************************/
#include <spine/PhysicsConstraintData.h> #include <spine/PhysicsConstraintData.h>
#include <spine/PhysicsConstraint.h>
#include <spine/BoneData.h> #include <spine/BoneData.h>
#include <spine/Skeleton.h>
using namespace spine; using namespace spine;
RTTI_IMPL(PhysicsConstraintData, ConstraintData) RTTI_IMPL(PhysicsConstraintData, ConstraintData)
PhysicsConstraintData::PhysicsConstraintData(const String &name) : ConstraintDataGeneric<PhysicsConstraint, PhysicsConstraintPose>(name), PhysicsConstraintData::PhysicsConstraintData(const String &name) : ConstraintData(name),
PosedDataGeneric<PhysicsConstraintPose>(name),
_bone(NULL), _bone(NULL),
_x(0), _y(0), _rotate(0), _scaleX(0), _shearX(0), _limit(0), _step(0), _x(0), _y(0), _rotate(0), _scaleX(0), _shearX(0), _limit(0), _step(0),
_inertiaGlobal(false), _strengthGlobal(false), _dampingGlobal(false), _massGlobal(false), _inertiaGlobal(false), _strengthGlobal(false), _dampingGlobal(false), _massGlobal(false),
@ -160,3 +163,7 @@ bool PhysicsConstraintData::getMixGlobal() {
void PhysicsConstraintData::setMixGlobal(bool mixGlobal) { void PhysicsConstraintData::setMixGlobal(bool mixGlobal) {
_mixGlobal = mixGlobal; _mixGlobal = mixGlobal;
} }
Constraint* PhysicsConstraintData::create(Skeleton& skeleton) {
return new (__FILE__, __LINE__) PhysicsConstraint(*this, skeleton);
}

View File

@ -35,7 +35,8 @@ using namespace spine;
RTTI_IMPL(SliderData, ConstraintData) RTTI_IMPL(SliderData, ConstraintData)
SliderData::SliderData(const String &name) : ConstraintDataGeneric<Slider, SliderPose>(name), SliderData::SliderData(const String &name) : ConstraintData(name),
PosedDataGeneric<SliderPose>(name),
_animation(NULL), _animation(NULL),
_additive(false), _additive(false),
_loop(false), _loop(false),
@ -45,7 +46,7 @@ SliderData::SliderData(const String &name) : ConstraintDataGeneric<Slider, Slide
_local(false) { _local(false) {
} }
Slider *SliderData::create(Skeleton &skeleton) { Constraint *SliderData::create(Skeleton &skeleton) {
return new (__FILE__, __LINE__) Slider(*this, skeleton); return new (__FILE__, __LINE__) Slider(*this, skeleton);
} }

View File

@ -52,5 +52,5 @@ void SlotCurveTimeline::apply(Skeleton &skeleton, float lastTime, float time, Ve
SP_UNUSED(direction); SP_UNUSED(direction);
Slot *slot = skeleton._slots[_slotIndex]; Slot *slot = skeleton._slots[_slotIndex];
if (slot->_bone._active) apply(*slot, appliedPose ? *slot->_applied : slot->_pose, time, alpha, blend); if (slot->_bone.isActive()) apply(*slot, appliedPose ? *slot->_applied : slot->_pose, time, alpha, blend);
} }

View File

@ -28,17 +28,20 @@
*****************************************************************************/ *****************************************************************************/
#include <spine/TransformConstraintData.h> #include <spine/TransformConstraintData.h>
#include <spine/TransformConstraint.h>
#include <spine/BoneData.h> #include <spine/BoneData.h>
#include <spine/BonePose.h> #include <spine/BonePose.h>
#include <spine/TransformConstraintPose.h> #include <spine/TransformConstraintPose.h>
#include <spine/MathUtil.h> #include <spine/MathUtil.h>
#include <spine/ContainerUtil.h> #include <spine/ContainerUtil.h>
#include <spine/Skeleton.h>
using namespace spine; using namespace spine;
RTTI_IMPL(TransformConstraintData, ConstraintData) RTTI_IMPL(TransformConstraintData, ConstraintData)
TransformConstraintData::TransformConstraintData(const String &name) : ConstraintDataGeneric<TransformConstraint, TransformConstraintPose>(name), TransformConstraintData::TransformConstraintData(const String &name) : ConstraintData(name),
PosedDataGeneric<TransformConstraintPose>(name),
_source(NULL), _source(NULL),
_localSource(false), _localSource(false),
_localTarget(false), _localTarget(false),
@ -354,3 +357,7 @@ TransformConstraintData::~TransformConstraintData() {
} }
_properties.clear(); _properties.clear();
} }
Constraint* TransformConstraintData::create(Skeleton& skeleton) {
return new (__FILE__, __LINE__) TransformConstraint(*this, skeleton);
}