[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-06-12 22:26:25 +02:00
parent f2e6b9095f
commit a574de1202
16 changed files with 57 additions and 86 deletions

View File

@ -46,7 +46,7 @@ namespace spine {
virtual void
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction, bool appliedPose);
MixDirection direction, bool appliedPose) override;
size_t getFrameCount();

View File

@ -49,7 +49,7 @@ namespace spine {
/// Fires events for frames > lastTime and <= time.
virtual void
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction, bool appliedPose);
MixDirection direction, bool appliedPose) override;
size_t getFrameCount();

View File

@ -46,7 +46,7 @@ namespace spine {
virtual void
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction);
MixDirection direction) override;
/// Sets the time, mix and bend direction of the specified keyframe.
void setFrame(int frame, float time, float mix, float softness, int bendDirection, bool compress, bool stretch);

View File

@ -34,6 +34,9 @@
#include <spine/Vector.h>
#include <spine/PathConstraintPose.h>
#include <spine/dll.h>
#include <spine/PositionMode.h>
#include <spine/SpacingMode.h>
#include <spine/RotateMode.h>
namespace spine {
class BoneData;
@ -41,35 +44,6 @@ namespace spine {
class PathConstraint;
class Skeleton;
/// 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.

View File

@ -37,6 +37,7 @@ namespace spine {
/// Stores a pose for a physics constraint.
class SP_API PhysicsConstraintPose : public Pose<PhysicsConstraintPose> {
friend class PhysicsConstraint;
friend class PhysicsConstraintTimeline;
private:
float _inertia;

View File

@ -49,7 +49,7 @@ namespace spine {
virtual void
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction, bool appliedPose);
MixDirection direction, bool appliedPose) override;
int getPhysicsConstraintIndex() { return _constraintIndex; }
@ -75,16 +75,16 @@ namespace spine {
explicit PhysicsConstraintInertiaTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintInertia) {};
protected:
float get(PhysicsConstraintPose &pose) {
float get(PhysicsConstraintPose &pose) override {
return pose.getInertia();
}
void set(PhysicsConstraintPose &pose, float value) {
void set(PhysicsConstraintPose &pose, float value) override {
pose.setInertia(value);
}
bool global(PhysicsConstraintData &constraintData) {
return constraintData.isInertiaGlobal();
bool global(PhysicsConstraintData &constraintData) override {
return constraintData.getInertiaGlobal();
}
};
@ -99,16 +99,16 @@ namespace spine {
explicit PhysicsConstraintStrengthTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintStrength) {};
protected:
float get(PhysicsConstraintPose &pose) {
float get(PhysicsConstraintPose &pose) override {
return pose.getStrength();
}
void set(PhysicsConstraintPose &pose, float value) {
void set(PhysicsConstraintPose &pose, float value) override {
pose.setStrength(value);
}
bool global(PhysicsConstraintData &constraintData) {
return constraintData.isStrengthGlobal();
bool global(PhysicsConstraintData &constraintData) override {
return constraintData.getStrengthGlobal();
}
};
@ -123,16 +123,16 @@ namespace spine {
explicit PhysicsConstraintDampingTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintDamping) {};
protected:
float get(PhysicsConstraintPose &pose) {
float get(PhysicsConstraintPose &pose) override {
return pose.getDamping();
}
void set(PhysicsConstraintPose &pose, float value) {
void set(PhysicsConstraintPose &pose, float value) override {
pose.setDamping(value);
}
bool global(PhysicsConstraintData &constraintData) {
return constraintData.isDampingGlobal();
bool global(PhysicsConstraintData &constraintData) override {
return constraintData.getDampingGlobal();
}
};
@ -147,16 +147,16 @@ namespace spine {
explicit PhysicsConstraintMassTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintMass) {};
protected:
float get(PhysicsConstraintPose &pose) {
float get(PhysicsConstraintPose &pose) override {
return 1 / pose.getMassInverse();
}
void set(PhysicsConstraintPose &pose, float value) {
void set(PhysicsConstraintPose &pose, float value) override {
pose.setMassInverse(1 / value);
}
bool global(PhysicsConstraintData &constraintData) {
return constraintData.isMassGlobal();
bool global(PhysicsConstraintData &constraintData) override {
return constraintData.getMassGlobal();
}
};
@ -171,16 +171,16 @@ namespace spine {
explicit PhysicsConstraintWindTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintWind) {};
protected:
float get(PhysicsConstraintPose &pose) {
float get(PhysicsConstraintPose &pose) override {
return pose.getWind();
}
void set(PhysicsConstraintPose &pose, float value) {
void set(PhysicsConstraintPose &pose, float value) override {
pose.setWind(value);
}
bool global(PhysicsConstraintData &constraintData) {
return constraintData.isWindGlobal();
bool global(PhysicsConstraintData &constraintData) override {
return constraintData.getWindGlobal();
}
};
@ -195,16 +195,16 @@ namespace spine {
explicit PhysicsConstraintGravityTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintGravity) {};
protected:
float get(PhysicsConstraintPose &pose) {
float get(PhysicsConstraintPose &pose) override {
return pose.getGravity();
}
void set(PhysicsConstraintPose &pose, float value) {
void set(PhysicsConstraintPose &pose, float value) override {
pose.setGravity(value);
}
bool global(PhysicsConstraintData &constraintData) {
return constraintData.isGravityGlobal();
bool global(PhysicsConstraintData &constraintData) override {
return constraintData.getGravityGlobal();
}
};
@ -219,16 +219,16 @@ namespace spine {
explicit PhysicsConstraintMixTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintMix) {};
protected:
float get(PhysicsConstraintPose &pose) {
float get(PhysicsConstraintPose &pose) override {
return pose.getMix();
}
void set(PhysicsConstraintPose &pose, float value) {
void set(PhysicsConstraintPose &pose, float value) override {
pose.setMix(value);
}
bool global(PhysicsConstraintData &constraintData) {
return constraintData.isMixGlobal();
bool global(PhysicsConstraintData &constraintData) override {
return constraintData.getMixGlobal();
}
};
@ -247,7 +247,7 @@ namespace spine {
virtual void
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction, bool appliedPose);
MixDirection direction, bool appliedPose) override;
/// The index of the physics constraint that will be reset when this timeline is applied, or -1 if all physics constraints in the skeleton will be reset.
int getConstraintIndex() { return _constraintIndex; }

View File

@ -39,7 +39,7 @@ namespace spine {
Posed() {}
virtual ~Posed() {}
virtual void resetApplied() = 0;
virtual void resetConstrained() = 0;
virtual void pose() = 0;
@ -103,7 +103,7 @@ namespace spine {
return *_applied;
}
virtual void resetApplied() {
virtual void resetConstrained() {
_constrained.set(_pose);
}

View File

@ -62,7 +62,7 @@ namespace spine {
friend class TranslateYTimeline;
friend class InheritTimeline;
private:
protected:
spine::String _name;
P _setup;
bool _skinRequired;
@ -78,7 +78,7 @@ namespace spine {
/// When true, Skeleton::updateWorldTransform(Physics) only updates this constraint if the Skeleton::getSkin()
/// contains this constraint.
///
///
/// See Skin::getConstraints().
bool getSkinRequired();
void setSkinRequired(bool skinRequired);

View File

@ -37,6 +37,8 @@
#include <spine/Color.h>
#include <spine/Physics.h>
#include <spine/Update.h>
#include <spine/Posed.h>
#include <spine/Constraint.h>
namespace spine {
class SkeletonData;

View File

@ -121,13 +121,6 @@
#include <spine/SpineString.h>
#include <spine/TextureLoader.h>
#include <spine/Timeline.h>
#include <spine/ToProperty.h>
#include <spine/ToRotate.h>
#include <spine/ToScaleX.h>
#include <spine/ToScaleY.h>
#include <spine/ToShearY.h>
#include <spine/ToX.h>
#include <spine/ToY.h>
#include <spine/TransformConstraint.h>
#include <spine/TransformConstraintData.h>
#include <spine/TransformConstraintPose.h>

View File

@ -42,8 +42,7 @@ RTTI_IMPL_NOPARENT(BoneTimeline)
RTTI_IMPL(BoneTimeline1, CurveTimeline1)
BoneTimeline1::BoneTimeline1(size_t frameCount, size_t bezierCount, int boneIndex, Property property) : BoneTimeline(boneIndex),
CurveTimeline1(frameCount, bezierCount) {
BoneTimeline1::BoneTimeline1(size_t frameCount, size_t bezierCount, int boneIndex, Property property) : CurveTimeline1(frameCount, bezierCount), BoneTimeline(boneIndex) {
PropertyId ids[] = {((PropertyId) property << 32) | boneIndex};
setPropertyIds(ids, 1);
}
@ -61,8 +60,7 @@ void BoneTimeline1::apply(Skeleton &skeleton, float lastTime, float time, Vector
RTTI_IMPL(BoneTimeline2, CurveTimeline2)
BoneTimeline2::BoneTimeline2(size_t frameCount, size_t bezierCount, int boneIndex, Property property1, Property property2) : BoneTimeline(boneIndex),
CurveTimeline2(frameCount, bezierCount) {
BoneTimeline2::BoneTimeline2(size_t frameCount, size_t bezierCount, int boneIndex, Property property1, Property property2) : CurveTimeline2(frameCount, bezierCount), BoneTimeline(boneIndex) {
PropertyId ids[] = {((PropertyId) property1 << 32) | boneIndex, ((PropertyId) property2 << 32) | boneIndex};
setPropertyIds(ids, 2);
}

View File

@ -54,7 +54,7 @@ void IkConstraintTimeline::apply(Skeleton &skeleton, float lastTime, float time,
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
IkConstraint *constraintP = skeleton._ikConstraints[_constraintIndex];
IkConstraint *constraintP = (IkConstraint *)skeleton._constraints[_constraintIndex];
IkConstraint &constraint = *constraintP;
if (!constraint.isActive()) return;

View File

@ -83,9 +83,10 @@ void spine::spDebug_printBoneDatas(Vector<BoneData *> &boneDatas) {
}
void spine::spDebug_printBoneData(BoneData *boneData) {
printf("Bone data %s: %f, %f, %f, %f, %f, %f %f\n", boneData->getName().buffer(), boneData->getRotation(),
boneData->getScaleX(), boneData->getScaleY(), boneData->getX(), boneData->getY(), boneData->getShearX(),
boneData->getShearY());
BoneLocal &setupPose = boneData->getSetupPose();
printf("Bone data %s: %f, %f, %f, %f, %f, %f %f\n", boneData->getName().buffer(), setupPose.getRotation(),
setupPose.getScaleX(), setupPose.getScaleY(), setupPose.getX(), setupPose.getY(), setupPose.getShearX(),
setupPose.getShearY());
}
void spine::spDebug_printSkeleton(Skeleton *skeleton) {
@ -100,8 +101,9 @@ void spine::spDebug_printBones(Vector<Bone *> &bones) {
}
void spine::spDebug_printBone(Bone *bone) {
printf("Bone %s: %f, %f, %f, %f, %f, %f\n", bone->getData().getName().buffer(), bone->getA(), bone->getB(),
bone->getC(), bone->getD(), bone->getWorldX(), bone->getWorldY());
BonePose &pose = bone->getAppliedPose();
printf("Bone %s: %f, %f, %f, %f, %f, %f, %f\n", bone->getData().getName().buffer(), pose.getRotation(), pose.getScaleX(),
pose.getScaleY(), pose.getX(), pose.getY(), pose.getShearX(), pose.getShearY());
}
void spine::spDebug_printFloats(float *values, int numFloats) {

View File

@ -28,6 +28,7 @@
*****************************************************************************/
#include <spine/MeshAttachment.h>
#include <spine/Slot.h>
using namespace spine;
@ -236,6 +237,6 @@ MeshAttachment *MeshAttachment::newLinkedMesh() {
void MeshAttachment::computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset,
size_t stride) {
if (_sequence) _sequence->apply(slot.getAppliedPose(), this);
if (_sequence) _sequence->apply(&slot.getAppliedPose(), this);
VertexAttachment::computeWorldVertices(skeleton, slot, start, count, worldVertices, offset, stride);
}

View File

@ -56,7 +56,7 @@ void PathConstraintMixTimeline::apply(Skeleton &skeleton, float lastTime, float
SP_UNUSED(pEvents);
SP_UNUSED(direction);
PathConstraint *constraintP = skeleton._pathConstraints[_constraintIndex];
PathConstraint *constraintP = skeleton._cons[_constraintIndex];
PathConstraint &constraint = *constraintP;
if (!constraint.isActive()) return;

View File

@ -67,7 +67,7 @@ void PhysicsConstraintTimeline::apply(Skeleton &skeleton, float, float time, Vec
for (size_t i = 0; i < physicsConstraints.size(); i++) {
PhysicsConstraint *constraint = physicsConstraints[i];
if (constraint->_active && global(constraint->_data)) {
PhysicsConstraintPose &pose = appliedPose ? constraint->_applied : constraint->_pose;
PhysicsConstraintPose &pose = appliedPose ? *constraint->_applied : constraint->_pose;
PhysicsConstraintPose &setupPose = constraint->_data._setup;
set(pose, getAbsoluteValue(time, alpha, blend, get(pose), get(setupPose), value));
}