[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-06-12 18:19:28 +02:00
parent a1bd7dcd98
commit 1702ff5139
9 changed files with 127 additions and 127 deletions

View File

@ -40,7 +40,7 @@ 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 RTTI_DECL_NOPARENT
public: public:
BoneTimeline(int boneIndex) : _boneIndex(boneIndex) {} BoneTimeline(int boneIndex) : _boneIndex(boneIndex) {}

View File

@ -34,8 +34,14 @@
#include <type_traits> #include <type_traits>
namespace spine { namespace spine {
class SP_API Posed {
public:
Posed() {}
virtual ~Posed() {}
};
template<class D, class P, class A> template<class D, class P, class A>
class SP_API Posed : public SpineObject { class SP_API PosedGeneric : public Posed, public SpineObject {
friend class AnimationState; friend class AnimationState;
friend class BoneTimeline1; friend class BoneTimeline1;
friend class BoneTimeline2; friend class BoneTimeline2;

View File

@ -34,16 +34,11 @@
#include <spine/Posed.h> #include <spine/Posed.h>
namespace spine { namespace spine {
template<class D, class P, class A>
class SP_API PosedActive : public Posed<D, P, A> {
friend class SlotCurveTimeline;
protected:
bool _active;
class SP_API PosedActive {
public: public:
PosedActive(D& data); PosedActive() {}
virtual ~PosedActive(); virtual ~PosedActive() {}
/// Returns false when this constraint won't be updated by /// Returns false when this constraint won't be updated by
/// Skeleton::updateWorldTransform() because a skin is required and the /// Skeleton::updateWorldTransform() because a skin is required and the
@ -53,21 +48,21 @@ namespace spine {
/// @see PosedData::getSkinRequired() /// @see PosedData::getSkinRequired()
/// @see Skeleton::updateCache() /// @see Skeleton::updateCache()
bool isActive(); bool isActive();
protected:
bool _active;
}; };
template<class D, class P, class A> template<class D, class P, class A>
PosedActive<D, P, A>::PosedActive(D& data) : Posed<D, P, A>(data), _active(false) { class SP_API PosedActiveGeneric : public PosedGeneric<D, P, A> {
this->setupPose(); friend class SlotCurveTimeline;
}
template<class D, class P, class A> public:
PosedActive<D, P, A>::~PosedActive() { PosedActive(D &data): PosedGeneric<D, P, A>(data), _active(false) {
} this->setupPose();
}
template<class D, class P, class A> virtual ~PosedActive() {}
bool PosedActive<D, P, A>::isActive() { };
return _active; }// namespace spine
}
}
#endif /* SPINE_POSEDACTIVE_H_ */ #endif /* SPINE_POSEDACTIVE_H_ */

View File

@ -43,6 +43,8 @@ namespace spine {
class Bone; class Bone;
class BonePose;
class Updatable; class Updatable;
class Slot; class Slot;
@ -51,7 +53,7 @@ namespace spine {
class PathConstraint; class PathConstraint;
class PhysicsConstraint; class PhysicsConstraint;
class TransformConstraint; class TransformConstraint;
@ -59,7 +61,7 @@ namespace spine {
class Attachment; class Attachment;
class SkeletonClipping; class SkeletonClipping;
class SP_API Skeleton : public SpineObject { class SP_API Skeleton : public SpineObject {
friend class AnimationState; friend class AnimationState;
@ -113,6 +115,7 @@ namespace spine {
friend class TransformConstraintTimeline; friend class TransformConstraintTimeline;
friend class BoneTimeline1; friend class BoneTimeline1;
friend class BoneTimeline2; friend class BoneTimeline2;
friend class RotateTimeline; friend class RotateTimeline;
@ -129,8 +132,18 @@ namespace spine {
friend class BonePose; friend class BonePose;
friend class IkConstraint;
friend class PathConstraint;
friend class PhysicsConstraint;
friend class TransformConstraint;
friend class Slider;
public: public:
explicit Skeleton(SkeletonData *skeletonData); explicit Skeleton(SkeletonData &skeletonData);
~Skeleton(); ~Skeleton();
@ -140,28 +153,48 @@ namespace spine {
void printUpdateCache(); void printUpdateCache();
/// Updates the world transform for each bone and applies all constraints. void constrained(Posed &object);
///
/// See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine void sortBone(Bone *bone);
/// Runtimes Guide.
static void sortReset(Vector<Bone *> &bones);
/// Updates the world transform for each bone and applies all constraints.
///
/// See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
/// Runtimes Guide.
void updateWorldTransform(Physics physics); void updateWorldTransform(Physics physics);
void updateWorldTransform(Physics physics, Bone *parent); void updateWorldTransform(Physics physics, BonePose *parent);
/// Sets the bones, constraints, and slots to their setup pose values. /// Sets the bones, constraints, and slots to their setup pose values.
void setToSetupPose(); void setupPose();
/// Sets the bones and constraints to their setup pose values. /// Sets the bones and constraints to their setup pose values.
void setBonesToSetupPose(); void setupPoseBones();
void setSlotsToSetupPose(); void setupPoseSlots();
SkeletonData *getData();
Vector<Bone *> &getBones();
Vector<Update *> &getUpdateCache();
Bone *getRootBone();
/// @return May be NULL. /// @return May be NULL.
Bone *findBone(const String &boneName); Bone *findBone(const String &boneName);
Vector<Slot *> &getSlots();
/// @return May be NULL. /// @return May be NULL.
Slot *findSlot(const String &slotName); Slot *findSlot(const String &slotName);
Vector<Slot *> &getDrawOrder();
Skin *getSkin();
/// Sets a skin by name (see setSkin). /// Sets a skin by name (see setSkin).
void setSkin(const String &skinName); void setSkin(const String &skinName);
@ -183,17 +216,23 @@ namespace spine {
/// @param attachmentName May be empty. /// @param attachmentName May be empty.
void setAttachment(const String &slotName, const String &attachmentName); void setAttachment(const String &slotName, const String &attachmentName);
/// @return May be NULL. Vector<Constraint *> &getConstraints();
IkConstraint *findIkConstraint(const String &constraintName);
/// @return May be NULL. Vector<PhysicsConstraint *> &getPhysicsConstraints();
TransformConstraint *findTransformConstraint(const String &constraintName);
/// @return May be NULL. template<typename T>
PathConstraint *findPathConstraint(const String &constraintName); T *findConstraint(const String &constraintName) {
if (constraintName.isEmpty()) return NULL;
/// @return May be NULL. for (size_t i = 0; i < _constraints.size(); i++) {
PhysicsConstraint *findPhysicsConstraint(const String &constraintName); Constraint *constraint = _constraints[i];
if (constraint->getRTTI().isExactly(T::RTTI)) {
if (constraint->getData().getName() == constraintName) {
return (T *) constraint;
}
}
}
return NULL;
}
/// Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose. /// Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
/// @param outX The horizontal distance between the skeleton origin and the left side of the AABB. /// @param outX The horizontal distance between the skeleton origin and the left side of the AABB.
@ -202,42 +241,12 @@ namespace spine {
/// @param outHeight The height of the AABB. /// @param outHeight The height of the AABB.
/// @param outVertexBuffer Reference to hold a Vector of floats. This method will assign it with new floats as needed. /// @param outVertexBuffer Reference to hold a Vector of floats. This method will assign it with new floats as needed.
// @param clipping Pointer to a SkeletonClipping instance or NULL. If a clipper is given, clipping attachments will be taken into account. // @param clipping Pointer to a SkeletonClipping instance or NULL. If a clipper is given, clipping attachments will be taken into account.
void getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector<float> &outVertexBuffer); void getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector<float> &outVertexBuffer);
void getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector<float> &outVertexBuffer, SkeletonClipping *clipper); void getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector<float> &outVertexBuffer, SkeletonClipping *clipper);
Bone *getRootBone();
SkeletonData *getData();
Vector<Bone *> &getBones();
Vector<Update *> &getUpdateCacheList();
Vector<Slot *> &getSlots();
Vector<Slot *> &getDrawOrder();
Vector<IkConstraint *> &getIkConstraints();
Vector<PathConstraint *> &getPathConstraints();
Vector<TransformConstraint *> &getTransformConstraints();
Vector<PhysicsConstraint *> &getPhysicsConstraints();
Skin *getSkin();
Color &getColor(); Color &getColor();
void setPosition(float x, float y); void setColor(Color &color);
float getX();
void setX(float inValue);
float getY();
void setY(float inValue);
float getScaleX(); float getScaleX();
@ -247,69 +256,65 @@ namespace spine {
void setScaleY(float inValue); void setScaleY(float inValue);
float getTime(); void setScale(float scaleX, float scaleY);
void setTime(float time); float getX();
void update(float delta); void setX(float inValue);
float getWindX(); float getY();
void setWindX(float windX); void setY(float inValue);
float getWindY(); void setPosition(float x, float y);
void setWindY(float windY); float getWindX();
float getGravityX(); void setWindX(float windX);
void setGravityX(float gravityX); float getWindY();
float getGravityY(); void setWindY(float windY);
void setGravityY(float gravityY); float getGravityX();
/// Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated around the void setGravityX(float gravityX);
/// specified point in world space.
void physicsTranslate(float x, float y);
/// Calls {@link PhysicsConstraint#rotate(float, float, float)} for each physics constraint. */ float getGravityY();
void physicsRotate(float x, float y, float degrees);
void setGravityY(float gravityY);
/// Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated around the
/// specified point in world space.
void physicsTranslate(float x, float y);
/// Calls {@link PhysicsConstraint#rotate(float, float, float)} for each physics constraint. */
void physicsRotate(float x, float y, float degrees);
float getTime();
void setTime(float time);
void update(float delta);
protected:
Vector<Update *> _updateCache;
private: private:
SkeletonData *_data; SkeletonData &_data;
Vector<Bone *> _bones; Vector<Bone *> _bones;
Vector<Slot *> _slots; Vector<Slot *> _slots;
Vector<Slot *> _drawOrder; Vector<Slot *> _drawOrder;
Vector<IkConstraint *> _ikConstraints; Vector<Constraint *> _constraints;
Vector<TransformConstraint *> _transformConstraints; Vector<PhysicsConstraint *> _physics;
Vector<PathConstraint *> _pathConstraints;
Vector<PhysicsConstraint *> _physicsConstraints;
Vector<Update *> _updateCache;
Skin *_skin; Skin *_skin;
Color _color; Color _color;
float _scaleX, _scaleY; float _scaleX, _scaleY;
float _x, _y; float _x, _y;
float _time; float _time;
float _windX, _windY, _gravityX, _gravityY; float _windX, _windY, _gravityX, _gravityY;
int _update; int _update;
void sortIkConstraint(IkConstraint *constraint);
void sortPathConstraint(PathConstraint *constraint);
void sortPhysicsConstraint(PhysicsConstraint *constraint);
void sortTransformConstraint(TransformConstraint *constraint);
void sortPathConstraintAttachment(Skin *skin, size_t slotIndex, Bone &slotBone);
void sortPathConstraintAttachment(Attachment *attachment, Bone &slotBone);
void sortBone(Bone *bone);
static void sortReset(Vector<Bone *> &bones);
}; };
} }// namespace spine
#endif /* Spine_Skeleton_h */ #endif /* Spine_Skeleton_h */

View File

@ -32,6 +32,7 @@
#include <spine/Vector.h> #include <spine/Vector.h>
#include <spine/SpineString.h> #include <spine/SpineString.h>
#include <spine/ConstraintData.h>
namespace spine { namespace spine {
class BoneData; class BoneData;

View File

@ -44,7 +44,7 @@ namespace spine {
/// Stores a slot's current pose. Slots organize attachments for Skeleton drawOrder purposes and provide a place to store /// Stores a slot's current pose. Slots organize attachments for Skeleton drawOrder purposes and provide a place to store
/// state for an attachment. State cannot be stored in an attachment itself because attachments are stateless and may be shared /// state for an attachment. State cannot be stored in an attachment itself because attachments are stateless and may be shared
/// across multiple skeletons. /// across multiple skeletons.
class SP_API Slot : public Posed<SlotData, SlotPose, SlotPose> { class SP_API Slot : public PosedGeneric<SlotData, SlotPose, SlotPose> {
friend class VertexAttachment; friend class VertexAttachment;
friend class Skeleton; friend class Skeleton;

View File

@ -60,13 +60,6 @@
#include <spine/EventData.h> #include <spine/EventData.h>
#include <spine/EventTimeline.h> #include <spine/EventTimeline.h>
#include <spine/Extension.h> #include <spine/Extension.h>
#include <spine/FromProperty.h>
#include <spine/FromRotate.h>
#include <spine/FromScaleX.h>
#include <spine/FromScaleY.h>
#include <spine/FromShearY.h>
#include <spine/FromX.h>
#include <spine/FromY.h>
#include <spine/HasRendererObject.h> #include <spine/HasRendererObject.h>
#include <spine/HashMap.h> #include <spine/HashMap.h>
#include <spine/IkConstraint.h> #include <spine/IkConstraint.h>

View File

@ -38,7 +38,7 @@
using namespace spine; using namespace spine;
RTTI_IMPL(BoneTimeline, BoneTimeline) RTTI_IMPL_NOPARENT(BoneTimeline)
RTTI_IMPL(BoneTimeline1, CurveTimeline1) RTTI_IMPL(BoneTimeline1, CurveTimeline1)

View File

@ -296,7 +296,7 @@ void IkConstraint::sort(Skeleton& skeleton) {
skeleton.sortBone(_target); skeleton.sortBone(_target);
Bone* parent = _bones[0]->_bone; Bone* parent = _bones[0]->_bone;
skeleton.sortBone(parent); skeleton.sortBone(parent);
skeleton.updateCache.add(this); skeleton._updateCache.add(this);
parent->_sorted = false; parent->_sorted = false;
skeleton.sortReset(parent->_children); skeleton.sortReset(parent->_children);
skeleton.constrained(parent); skeleton.constrained(parent);