[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-06-11 20:09:55 +02:00
parent 5cd55f83c9
commit df13ca0815
4 changed files with 79 additions and 110 deletions

View File

@ -45,7 +45,7 @@ namespace spine {
friend class SkeletonJson; friend class SkeletonJson;
public: public:
ConstraintData(const String &name, P* setup); ConstraintData(const String &name);
virtual ~ConstraintData(); virtual ~ConstraintData();
/// Creates a constraint instance. /// Creates a constraint instance.
@ -53,7 +53,7 @@ namespace spine {
}; };
template<class T, class P> template<class T, class P>
ConstraintData<T, P>::ConstraintData(const String &name, P* setup) : PosedData<P>(name, setup) { ConstraintData<T, P>::ConstraintData(const String &name) : PosedData<P>(name) {
} }
template<class T, class P> template<class T, class P>

View File

@ -30,20 +30,49 @@
#ifndef Spine_PathConstraintData_h #ifndef Spine_PathConstraintData_h
#define Spine_PathConstraintData_h #define Spine_PathConstraintData_h
#include <spine/PositionMode.h>
#include <spine/SpacingMode.h>
#include <spine/RotateMode.h>
#include <spine/Vector.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/ConstraintData.h> #include <spine/ConstraintData.h>
#include <spine/Vector.h>
namespace spine { namespace spine {
class BoneData; class BoneData;
class SlotData; class SlotData;
class PathConstraint;
class PathConstraintPose;
class Skeleton;
class SP_API PathConstraintData : public ConstraintData { /// Controls how the first bone is positioned along the path.
///
/// See https://esotericsoftware.com/spine-path-constraints#Position-mode Position mode in the Spine User Guide.
enum PositionMode {
PositionMode_Fixed,
PositionMode_Percent
};
/// Controls how bones after the first bone are positioned along the path.
///
/// See https://esotericsoftware.com/spine-path-constraints#Spacing-mode Spacing mode in the Spine User Guide.
enum SpacingMode {
SpacingMode_Length,
SpacingMode_Fixed,
SpacingMode_Percent,
SpacingMode_Proportional
};
/// Controls how bones are rotated, translated, and scaled to match the path.
///
/// See https://esotericsoftware.com/spine-path-constraints#Rotate-Mix Rotate mode in the Spine User Guide.
enum RotateMode {
RotateMode_Tangent,
RotateMode_Chain,
/// When chain scale, constrained bones should all have the same parent. That way when the path constraint scales a bone, it
/// doesn't affect other constrained bones.
RotateMode_ChainScale
};
/// Stores the setup pose for a PathConstraint.
///
/// See https://esotericsoftware.com/spine-path-constraints Path constraints in the Spine User Guide.
class SP_API PathConstraintData : public ConstraintData<PathConstraint, PathConstraintPose> {
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
@ -62,57 +91,42 @@ namespace spine {
explicit PathConstraintData(const String &name); explicit PathConstraintData(const String &name);
/// The bones that will be modified by this path constraint.
Vector<BoneData *> &getBones(); Vector<BoneData *> &getBones();
SlotData *getTarget(); /// The slot whose path attachment will be used to constrained the bones.
SlotData *getSlot();
void setTarget(SlotData *inValue); void setSlot(SlotData *slot);
/// The mode for positioning the first bone on the path.
PositionMode getPositionMode(); PositionMode getPositionMode();
void setPositionMode(PositionMode inValue); void setPositionMode(PositionMode positionMode);
/// The mode for positioning the bones after the first bone on the path.
SpacingMode getSpacingMode(); SpacingMode getSpacingMode();
void setSpacingMode(SpacingMode inValue); void setSpacingMode(SpacingMode spacingMode);
/// The mode for adjusting the rotation of the bones.
RotateMode getRotateMode(); RotateMode getRotateMode();
void setRotateMode(RotateMode inValue); void setRotateMode(RotateMode rotateMode);
/// An offset added to the constrained bone rotation.
float getOffsetRotation(); float getOffsetRotation();
void setOffsetRotation(float inValue); void setOffsetRotation(float offsetRotation);
float getPosition();
void setPosition(float inValue);
float getSpacing();
void setSpacing(float inValue);
float getMixRotate();
void setMixRotate(float inValue);
float getMixX();
void setMixX(float inValue);
float getMixY();
void setMixY(float inValue);
private: private:
Vector<BoneData *> _bones; Vector<BoneData *> _bones;
SlotData *_target; SlotData *_slot;
PositionMode _positionMode; PositionMode _positionMode;
SpacingMode _spacingMode; SpacingMode _spacingMode;
RotateMode _rotateMode; RotateMode _rotateMode;
float _offsetRotation; float _offsetRotation;
float _position, _spacing;
float _mixRotate, _mixX, _mixY;
}; };
} }

View File

@ -64,17 +64,17 @@ namespace spine {
private: private:
spine::String _name; spine::String _name;
P* _setup; P _setup;
bool _skinRequired; bool _skinRequired;
public: public:
PosedData(const spine::String& name, P* setup); PosedData(const spine::String& name);
virtual ~PosedData(); virtual ~PosedData();
/// The constraint's name, which is unique across all constraints in the skeleton of the same type. /// The constraint's name, which is unique across all constraints in the skeleton of the same type.
const spine::String& getName(); const spine::String& getName();
P* getSetupPose(); P& getSetupPose();
/// When true, Skeleton::updateWorldTransform(Physics) only updates this constraint if the Skeleton::getSkin() /// When true, Skeleton::updateWorldTransform(Physics) only updates this constraint if the Skeleton::getSkin()
/// contains this constraint. /// contains this constraint.
@ -87,12 +87,11 @@ namespace spine {
}; };
template<class P> template<class P>
PosedData<P>::PosedData(const spine::String& name, P* setup) : _name(name), _setup(setup), _skinRequired(false) { PosedData<P>::PosedData(const spine::String& name) : _name(name), _setup(), _skinRequired(false) {
} }
template<class P> template<class P>
PosedData<P>::~PosedData() { PosedData<P>::~PosedData() {
delete _setup;
} }
template<class P> template<class P>
@ -101,7 +100,7 @@ namespace spine {
} }
template<class P> template<class P>
P* PosedData<P>::getSetupPose() { P& PosedData<P>::getSetupPose() {
return _setup; return _setup;
} }

View File

@ -28,109 +28,65 @@
*****************************************************************************/ *****************************************************************************/
#include <spine/PathConstraintData.h> #include <spine/PathConstraintData.h>
#include <spine/PathConstraint.h>
#include <spine/PathConstraintPose.h>
#include <spine/BoneData.h> #include <spine/BoneData.h>
#include <spine/SlotData.h> #include <spine/SlotData.h>
#include <spine/Skeleton.h>
#include <assert.h>
using namespace spine; using namespace spine;
RTTI_IMPL(PathConstraintData, ConstraintData) RTTI_IMPL_NOPARENT(PathConstraintData)
PathConstraintData::PathConstraintData(const String &name) : ConstraintData(name), PathConstraintData::PathConstraintData(const String &name) : ConstraintData<PathConstraint, PathConstraintPose>(name),
_target(NULL), _slot(NULL),
_positionMode(PositionMode_Fixed), _positionMode(PositionMode_Fixed),
_spacingMode(SpacingMode_Length), _spacingMode(SpacingMode_Length),
_rotateMode(RotateMode_Tangent), _rotateMode(RotateMode_Tangent),
_offsetRotation(0), _offsetRotation(0) {
_position(0),
_spacing(0),
_mixRotate(0),
_mixX(0),
_mixY(0) {
} }
Vector<BoneData *> &PathConstraintData::getBones() { Vector<BoneData *> &PathConstraintData::getBones() {
return _bones; return _bones;
} }
SlotData *PathConstraintData::getTarget() { SlotData *PathConstraintData::getSlot() {
return _target; return _slot;
} }
void PathConstraintData::setTarget(SlotData *inValue) { void PathConstraintData::setSlot(SlotData *slot) {
_target = inValue; _slot = slot;
} }
PositionMode PathConstraintData::getPositionMode() { PositionMode PathConstraintData::getPositionMode() {
return _positionMode; return _positionMode;
} }
void PathConstraintData::setPositionMode(PositionMode inValue) { void PathConstraintData::setPositionMode(PositionMode positionMode) {
_positionMode = inValue; _positionMode = positionMode;
} }
SpacingMode PathConstraintData::getSpacingMode() { SpacingMode PathConstraintData::getSpacingMode() {
return _spacingMode; return _spacingMode;
} }
void PathConstraintData::setSpacingMode(SpacingMode inValue) { void PathConstraintData::setSpacingMode(SpacingMode spacingMode) {
_spacingMode = inValue; _spacingMode = spacingMode;
} }
RotateMode PathConstraintData::getRotateMode() { RotateMode PathConstraintData::getRotateMode() {
return _rotateMode; return _rotateMode;
} }
void PathConstraintData::setRotateMode(RotateMode inValue) { void PathConstraintData::setRotateMode(RotateMode rotateMode) {
_rotateMode = inValue; _rotateMode = rotateMode;
} }
float PathConstraintData::getOffsetRotation() { float PathConstraintData::getOffsetRotation() {
return _offsetRotation; return _offsetRotation;
} }
void PathConstraintData::setOffsetRotation(float inValue) { void PathConstraintData::setOffsetRotation(float offsetRotation) {
_offsetRotation = inValue; _offsetRotation = offsetRotation;
}
float PathConstraintData::getPosition() {
return _position;
}
void PathConstraintData::setPosition(float inValue) {
_position = inValue;
}
float PathConstraintData::getSpacing() {
return _spacing;
}
void PathConstraintData::setSpacing(float inValue) {
_spacing = inValue;
}
float PathConstraintData::getMixRotate() {
return _mixRotate;
}
void PathConstraintData::setMixRotate(float inValue) {
_mixRotate = inValue;
}
float PathConstraintData::getMixX() {
return _mixX;
}
void PathConstraintData::setMixX(float inValue) {
_mixX = inValue;
}
float PathConstraintData::getMixY() {
return _mixY;
}
void PathConstraintData::setMixY(float inValue) {
_mixY = inValue;
} }