mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[cpp] 4.3 porting WIP
This commit is contained in:
parent
65f29abc32
commit
878403d271
@ -33,6 +33,7 @@
|
|||||||
#include <spine/CurveTimeline.h>
|
#include <spine/CurveTimeline.h>
|
||||||
#include <spine/PhysicsConstraint.h>
|
#include <spine/PhysicsConstraint.h>
|
||||||
#include <spine/PhysicsConstraintData.h>
|
#include <spine/PhysicsConstraintData.h>
|
||||||
|
#include <spine/PhysicsConstraintPose.h>
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
@ -48,16 +49,15 @@ namespace spine {
|
|||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
|
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
|
||||||
MixDirection direction);
|
MixDirection direction, bool appliedPose);
|
||||||
|
|
||||||
int getPhysicsConstraintIndex() { return _constraintIndex; }
|
int getPhysicsConstraintIndex() { return _constraintIndex; }
|
||||||
|
|
||||||
void setPhysicsConstraintIndex(int inValue) { _constraintIndex = inValue; }
|
void setPhysicsConstraintIndex(int inValue) { _constraintIndex = inValue; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual float setup(PhysicsConstraint *constraint) = 0;
|
virtual float get(PhysicsConstraintPose &pose) = 0;
|
||||||
virtual float get(PhysicsConstraint *constraint) = 0;
|
virtual void set(PhysicsConstraintPose &pose, float value) = 0;
|
||||||
virtual void set(PhysicsConstraint *constraint, float value) = 0;
|
|
||||||
virtual bool global(PhysicsConstraintData &constraintData) = 0;
|
virtual bool global(PhysicsConstraintData &constraintData) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -75,16 +75,12 @@ namespace spine {
|
|||||||
explicit PhysicsConstraintInertiaTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintInertia) {};
|
explicit PhysicsConstraintInertiaTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintInertia) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float setup(PhysicsConstraint *constraint) {
|
float get(PhysicsConstraintPose &pose) {
|
||||||
return constraint->_data.getInertia();
|
return pose.getInertia();
|
||||||
}
|
}
|
||||||
|
|
||||||
float get(PhysicsConstraint *constraint) {
|
void set(PhysicsConstraintPose &pose, float value) {
|
||||||
return constraint->_inertia;
|
pose.setInertia(value);
|
||||||
}
|
|
||||||
|
|
||||||
void set(PhysicsConstraint *constraint, float value) {
|
|
||||||
constraint->_inertia = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool global(PhysicsConstraintData &constraintData) {
|
bool global(PhysicsConstraintData &constraintData) {
|
||||||
@ -103,16 +99,12 @@ namespace spine {
|
|||||||
explicit PhysicsConstraintStrengthTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintStrength) {};
|
explicit PhysicsConstraintStrengthTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintStrength) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float setup(PhysicsConstraint *constraint) {
|
float get(PhysicsConstraintPose &pose) {
|
||||||
return constraint->_data.getStrength();
|
return pose.getStrength();
|
||||||
}
|
}
|
||||||
|
|
||||||
float get(PhysicsConstraint *constraint) {
|
void set(PhysicsConstraintPose &pose, float value) {
|
||||||
return constraint->_strength;
|
pose.setStrength(value);
|
||||||
}
|
|
||||||
|
|
||||||
void set(PhysicsConstraint *constraint, float value) {
|
|
||||||
constraint->_strength = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool global(PhysicsConstraintData &constraintData) {
|
bool global(PhysicsConstraintData &constraintData) {
|
||||||
@ -131,16 +123,12 @@ namespace spine {
|
|||||||
explicit PhysicsConstraintDampingTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintDamping) {};
|
explicit PhysicsConstraintDampingTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintDamping) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float setup(PhysicsConstraint *constraint) {
|
float get(PhysicsConstraintPose &pose) {
|
||||||
return constraint->_data.getDamping();
|
return pose.getDamping();
|
||||||
}
|
}
|
||||||
|
|
||||||
float get(PhysicsConstraint *constraint) {
|
void set(PhysicsConstraintPose &pose, float value) {
|
||||||
return constraint->_damping;
|
pose.setDamping(value);
|
||||||
}
|
|
||||||
|
|
||||||
void set(PhysicsConstraint *constraint, float value) {
|
|
||||||
constraint->_damping = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool global(PhysicsConstraintData &constraintData) {
|
bool global(PhysicsConstraintData &constraintData) {
|
||||||
@ -159,16 +147,12 @@ namespace spine {
|
|||||||
explicit PhysicsConstraintMassTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintMass) {};
|
explicit PhysicsConstraintMassTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintMass) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float setup(PhysicsConstraint *constraint) {
|
float get(PhysicsConstraintPose &pose) {
|
||||||
return 1 / constraint->_data.getMassInverse();
|
return 1 / pose.getMassInverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
float get(PhysicsConstraint *constraint) {
|
void set(PhysicsConstraintPose &pose, float value) {
|
||||||
return 1 / constraint->_massInverse;
|
pose.setMassInverse(1 / value);
|
||||||
}
|
|
||||||
|
|
||||||
void set(PhysicsConstraint *constraint, float value) {
|
|
||||||
constraint->_massInverse = 1 / value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool global(PhysicsConstraintData &constraintData) {
|
bool global(PhysicsConstraintData &constraintData) {
|
||||||
@ -187,16 +171,12 @@ namespace spine {
|
|||||||
explicit PhysicsConstraintWindTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintWind) {};
|
explicit PhysicsConstraintWindTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintWind) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float setup(PhysicsConstraint *constraint) {
|
float get(PhysicsConstraintPose &pose) {
|
||||||
return constraint->_data.getWind();
|
return pose.getWind();
|
||||||
}
|
}
|
||||||
|
|
||||||
float get(PhysicsConstraint *constraint) {
|
void set(PhysicsConstraintPose &pose, float value) {
|
||||||
return constraint->_wind;
|
pose.setWind(value);
|
||||||
}
|
|
||||||
|
|
||||||
void set(PhysicsConstraint *constraint, float value) {
|
|
||||||
constraint->_wind = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool global(PhysicsConstraintData &constraintData) {
|
bool global(PhysicsConstraintData &constraintData) {
|
||||||
@ -215,16 +195,12 @@ namespace spine {
|
|||||||
explicit PhysicsConstraintGravityTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintGravity) {};
|
explicit PhysicsConstraintGravityTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintGravity) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float setup(PhysicsConstraint *constraint) {
|
float get(PhysicsConstraintPose &pose) {
|
||||||
return constraint->_data.getGravity();
|
return pose.getGravity();
|
||||||
}
|
}
|
||||||
|
|
||||||
float get(PhysicsConstraint *constraint) {
|
void set(PhysicsConstraintPose &pose, float value) {
|
||||||
return constraint->_gravity;
|
pose.setGravity(value);
|
||||||
}
|
|
||||||
|
|
||||||
void set(PhysicsConstraint *constraint, float value) {
|
|
||||||
constraint->_gravity = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool global(PhysicsConstraintData &constraintData) {
|
bool global(PhysicsConstraintData &constraintData) {
|
||||||
@ -243,16 +219,12 @@ namespace spine {
|
|||||||
explicit PhysicsConstraintMixTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintMix) {};
|
explicit PhysicsConstraintMixTimeline(size_t frameCount, size_t bezierCount, int physicsConstraintIndex): PhysicsConstraintTimeline(frameCount, bezierCount, physicsConstraintIndex, Property_PhysicsConstraintMix) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float setup(PhysicsConstraint *constraint) {
|
float get(PhysicsConstraintPose &pose) {
|
||||||
return constraint->_data.getMix();
|
return pose.getMix();
|
||||||
}
|
}
|
||||||
|
|
||||||
float get(PhysicsConstraint *constraint) {
|
void set(PhysicsConstraintPose &pose, float value) {
|
||||||
return constraint->_mix;
|
pose.setMix(value);
|
||||||
}
|
|
||||||
|
|
||||||
void set(PhysicsConstraint *constraint, float value) {
|
|
||||||
constraint->_mix = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool global(PhysicsConstraintData &constraintData) {
|
bool global(PhysicsConstraintData &constraintData) {
|
||||||
@ -275,8 +247,14 @@ namespace spine {
|
|||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
|
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
|
||||||
MixDirection direction);
|
MixDirection direction, bool appliedPose);
|
||||||
|
|
||||||
|
/// 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; }
|
||||||
|
|
||||||
|
int getFrameCount() { return (int)_frames.size(); }
|
||||||
|
|
||||||
|
/// Sets the time for the specified frame.
|
||||||
void setFrame(int frame, float time) {
|
void setFrame(int frame, float time) {
|
||||||
_frames[frame] = time;
|
_frames[frame] = time;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,6 +92,7 @@
|
|||||||
#include <spine/PhysicsConstraint.h>
|
#include <spine/PhysicsConstraint.h>
|
||||||
#include <spine/PhysicsConstraintData.h>
|
#include <spine/PhysicsConstraintData.h>
|
||||||
#include <spine/PhysicsConstraintPose.h>
|
#include <spine/PhysicsConstraintPose.h>
|
||||||
|
#include <spine/PhysicsConstraintTimeline.h>
|
||||||
#include <spine/Pose.h>
|
#include <spine/Pose.h>
|
||||||
#include <spine/Posed.h>
|
#include <spine/Posed.h>
|
||||||
#include <spine/PosedActive.h>
|
#include <spine/PosedActive.h>
|
||||||
|
|||||||
@ -59,23 +59,30 @@ PhysicsConstraintTimeline::PhysicsConstraintTimeline(size_t frameCount, size_t b
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsConstraintTimeline::apply(Skeleton &skeleton, float, float time, Vector<Event *> *,
|
void PhysicsConstraintTimeline::apply(Skeleton &skeleton, float, float time, Vector<Event *> *,
|
||||||
float alpha, MixBlend blend, MixDirection) {
|
float alpha, MixBlend blend, MixDirection direction, bool appliedPose) {
|
||||||
if (_constraintIndex == -1) {
|
if (_constraintIndex == -1) {
|
||||||
float value = time >= _frames[0] ? getCurveValue(time) : 0;
|
float value = time >= _frames[0] ? getCurveValue(time) : 0;
|
||||||
|
|
||||||
Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
|
Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
|
||||||
for (size_t i = 0; i < physicsConstraints.size(); i++) {
|
for (size_t i = 0; i < physicsConstraints.size(); i++) {
|
||||||
PhysicsConstraint *constraint = physicsConstraints[i];
|
PhysicsConstraint *constraint = physicsConstraints[i];
|
||||||
if (constraint->_active && global(constraint->_data))
|
if (constraint->_active && global(constraint->_data)) {
|
||||||
set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint), value));
|
PhysicsConstraintPose &pose = appliedPose ? constraint->_applied : constraint->_pose;
|
||||||
|
PhysicsConstraintPose &setupPose = constraint->_data._setup;
|
||||||
|
set(pose, getAbsoluteValue(time, alpha, blend, get(pose), get(setupPose), value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PhysicsConstraint *constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
|
PhysicsConstraint *constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
|
||||||
if (constraint->_active) set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint)));
|
if (constraint->_active) {
|
||||||
|
PhysicsConstraintPose &pose = appliedPose ? constraint->_applied : constraint->_pose;
|
||||||
|
PhysicsConstraintPose &setupPose = constraint->_data._setup;
|
||||||
|
set(pose, getAbsoluteValue(time, alpha, blend, get(pose), get(setupPose)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsConstraintResetTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *, float alpha, MixBlend blend, MixDirection direction) {
|
void PhysicsConstraintResetTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *, float alpha, MixBlend blend, MixDirection direction, bool appliedPose) {
|
||||||
PhysicsConstraint *constraint = nullptr;
|
PhysicsConstraint *constraint = nullptr;
|
||||||
if (_constraintIndex != -1) {
|
if (_constraintIndex != -1) {
|
||||||
constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
|
constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
|
||||||
@ -83,7 +90,7 @@ void PhysicsConstraintResetTimeline::apply(Skeleton &skeleton, float lastTime, f
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lastTime > time) {// Apply after lastTime for looped animations.
|
if (lastTime > time) {// Apply after lastTime for looped animations.
|
||||||
apply(skeleton, lastTime, FLT_MAX, nullptr, alpha, blend, direction);
|
apply(skeleton, lastTime, FLT_MAX, nullptr, alpha, blend, direction, appliedPose);
|
||||||
lastTime = -1;
|
lastTime = -1;
|
||||||
} else if (lastTime >= _frames[_frames.size() - 1])// Last time is after last frame.
|
} else if (lastTime >= _frames[_frames.size() - 1])// Last time is after last frame.
|
||||||
return;
|
return;
|
||||||
@ -91,12 +98,12 @@ void PhysicsConstraintResetTimeline::apply(Skeleton &skeleton, float lastTime, f
|
|||||||
|
|
||||||
if (lastTime < _frames[0] || time >= _frames[Animation::search(_frames, lastTime) + 1]) {
|
if (lastTime < _frames[0] || time >= _frames[Animation::search(_frames, lastTime) + 1]) {
|
||||||
if (constraint != nullptr)
|
if (constraint != nullptr)
|
||||||
constraint->reset();
|
constraint->reset(skeleton);
|
||||||
else {
|
else {
|
||||||
Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
|
Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
|
||||||
for (size_t i = 0; i < physicsConstraints.size(); i++) {
|
for (size_t i = 0; i < physicsConstraints.size(); i++) {
|
||||||
constraint = physicsConstraints[i];
|
constraint = physicsConstraints[i];
|
||||||
if (constraint->_active) constraint->reset();
|
if (constraint->_active) constraint->reset(skeleton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user