mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[cpp] 4.3 porting WIP
This commit is contained in:
parent
a1bd7dcd98
commit
1702ff5139
@ -40,7 +40,7 @@ namespace spine {
|
||||
|
||||
/// An interface for timelines which change the property of a bone.
|
||||
class SP_API BoneTimeline {
|
||||
RTTI_DECL
|
||||
RTTI_DECL_NOPARENT
|
||||
|
||||
public:
|
||||
BoneTimeline(int boneIndex) : _boneIndex(boneIndex) {}
|
||||
|
||||
@ -34,8 +34,14 @@
|
||||
#include <type_traits>
|
||||
|
||||
namespace spine {
|
||||
class SP_API Posed {
|
||||
public:
|
||||
Posed() {}
|
||||
virtual ~Posed() {}
|
||||
};
|
||||
|
||||
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 BoneTimeline1;
|
||||
friend class BoneTimeline2;
|
||||
@ -100,7 +106,7 @@ namespace spine {
|
||||
protected:
|
||||
D& _data;
|
||||
A _pose; ///< Stored as A type (concrete pose type) to match Java behavior
|
||||
A _constrained; ///< Stored as A type (concrete pose type) to match Java behavior
|
||||
A _constrained; ///< Stored as A type (concrete pose type) to match Java behavior
|
||||
A* _applied; ///< Points to either _pose or _constrained, reassignable like Java
|
||||
};
|
||||
}
|
||||
|
||||
@ -34,16 +34,11 @@
|
||||
#include <spine/Posed.h>
|
||||
|
||||
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:
|
||||
PosedActive(D& data);
|
||||
virtual ~PosedActive();
|
||||
PosedActive() {}
|
||||
virtual ~PosedActive() {}
|
||||
|
||||
/// Returns false when this constraint won't be updated by
|
||||
/// Skeleton::updateWorldTransform() because a skin is required and the
|
||||
@ -53,21 +48,21 @@ namespace spine {
|
||||
/// @see PosedData::getSkinRequired()
|
||||
/// @see Skeleton::updateCache()
|
||||
bool isActive();
|
||||
|
||||
protected:
|
||||
bool _active;
|
||||
};
|
||||
|
||||
template<class D, class P, class A>
|
||||
PosedActive<D, P, A>::PosedActive(D& data) : Posed<D, P, A>(data), _active(false) {
|
||||
this->setupPose();
|
||||
}
|
||||
class SP_API PosedActiveGeneric : public PosedGeneric<D, P, A> {
|
||||
friend class SlotCurveTimeline;
|
||||
|
||||
template<class D, class P, class A>
|
||||
PosedActive<D, P, A>::~PosedActive() {
|
||||
}
|
||||
|
||||
template<class D, class P, class A>
|
||||
bool PosedActive<D, P, A>::isActive() {
|
||||
return _active;
|
||||
}
|
||||
}
|
||||
public:
|
||||
PosedActive(D &data): PosedGeneric<D, P, A>(data), _active(false) {
|
||||
this->setupPose();
|
||||
}
|
||||
virtual ~PosedActive() {}
|
||||
};
|
||||
}// namespace spine
|
||||
|
||||
#endif /* SPINE_POSEDACTIVE_H_ */
|
||||
@ -43,6 +43,8 @@ namespace spine {
|
||||
|
||||
class Bone;
|
||||
|
||||
class BonePose;
|
||||
|
||||
class Updatable;
|
||||
|
||||
class Slot;
|
||||
@ -51,7 +53,7 @@ namespace spine {
|
||||
|
||||
class PathConstraint;
|
||||
|
||||
class PhysicsConstraint;
|
||||
class PhysicsConstraint;
|
||||
|
||||
class TransformConstraint;
|
||||
|
||||
@ -59,7 +61,7 @@ namespace spine {
|
||||
|
||||
class Attachment;
|
||||
|
||||
class SkeletonClipping;
|
||||
class SkeletonClipping;
|
||||
|
||||
class SP_API Skeleton : public SpineObject {
|
||||
friend class AnimationState;
|
||||
@ -113,6 +115,7 @@ namespace spine {
|
||||
friend class TransformConstraintTimeline;
|
||||
|
||||
friend class BoneTimeline1;
|
||||
|
||||
friend class BoneTimeline2;
|
||||
|
||||
friend class RotateTimeline;
|
||||
@ -129,8 +132,18 @@ namespace spine {
|
||||
|
||||
friend class BonePose;
|
||||
|
||||
friend class IkConstraint;
|
||||
|
||||
friend class PathConstraint;
|
||||
|
||||
friend class PhysicsConstraint;
|
||||
|
||||
friend class TransformConstraint;
|
||||
|
||||
friend class Slider;
|
||||
|
||||
public:
|
||||
explicit Skeleton(SkeletonData *skeletonData);
|
||||
explicit Skeleton(SkeletonData &skeletonData);
|
||||
|
||||
~Skeleton();
|
||||
|
||||
@ -140,28 +153,48 @@ namespace spine {
|
||||
|
||||
void printUpdateCache();
|
||||
|
||||
/// 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 constrained(Posed &object);
|
||||
|
||||
void sortBone(Bone *bone);
|
||||
|
||||
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, Bone *parent);
|
||||
void updateWorldTransform(Physics physics, BonePose *parent);
|
||||
|
||||
/// 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.
|
||||
void setBonesToSetupPose();
|
||||
void setupPoseBones();
|
||||
|
||||
void setSlotsToSetupPose();
|
||||
void setupPoseSlots();
|
||||
|
||||
SkeletonData *getData();
|
||||
|
||||
Vector<Bone *> &getBones();
|
||||
|
||||
Vector<Update *> &getUpdateCache();
|
||||
|
||||
Bone *getRootBone();
|
||||
|
||||
/// @return May be NULL.
|
||||
Bone *findBone(const String &boneName);
|
||||
|
||||
Vector<Slot *> &getSlots();
|
||||
|
||||
/// @return May be NULL.
|
||||
Slot *findSlot(const String &slotName);
|
||||
|
||||
Vector<Slot *> &getDrawOrder();
|
||||
|
||||
Skin *getSkin();
|
||||
|
||||
/// Sets a skin by name (see setSkin).
|
||||
void setSkin(const String &skinName);
|
||||
|
||||
@ -183,17 +216,23 @@ namespace spine {
|
||||
/// @param attachmentName May be empty.
|
||||
void setAttachment(const String &slotName, const String &attachmentName);
|
||||
|
||||
/// @return May be NULL.
|
||||
IkConstraint *findIkConstraint(const String &constraintName);
|
||||
Vector<Constraint *> &getConstraints();
|
||||
|
||||
/// @return May be NULL.
|
||||
TransformConstraint *findTransformConstraint(const String &constraintName);
|
||||
Vector<PhysicsConstraint *> &getPhysicsConstraints();
|
||||
|
||||
/// @return May be NULL.
|
||||
PathConstraint *findPathConstraint(const String &constraintName);
|
||||
|
||||
/// @return May be NULL.
|
||||
PhysicsConstraint *findPhysicsConstraint(const String &constraintName);
|
||||
template<typename T>
|
||||
T *findConstraint(const String &constraintName) {
|
||||
if (constraintName.isEmpty()) return NULL;
|
||||
for (size_t i = 0; i < _constraints.size(); i++) {
|
||||
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.
|
||||
/// @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 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.
|
||||
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);
|
||||
|
||||
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();
|
||||
|
||||
void setPosition(float x, float y);
|
||||
|
||||
float getX();
|
||||
|
||||
void setX(float inValue);
|
||||
|
||||
float getY();
|
||||
|
||||
void setY(float inValue);
|
||||
void setColor(Color &color);
|
||||
|
||||
float getScaleX();
|
||||
|
||||
@ -247,69 +256,65 @@ namespace spine {
|
||||
|
||||
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
|
||||
/// specified point in world space.
|
||||
void physicsTranslate(float x, float y);
|
||||
void setGravityX(float gravityX);
|
||||
|
||||
/// Calls {@link PhysicsConstraint#rotate(float, float, float)} for each physics constraint. */
|
||||
void physicsRotate(float x, float y, float degrees);
|
||||
float getGravityY();
|
||||
|
||||
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:
|
||||
SkeletonData *_data;
|
||||
SkeletonData &_data;
|
||||
Vector<Bone *> _bones;
|
||||
Vector<Slot *> _slots;
|
||||
Vector<Slot *> _drawOrder;
|
||||
Vector<IkConstraint *> _ikConstraints;
|
||||
Vector<TransformConstraint *> _transformConstraints;
|
||||
Vector<PathConstraint *> _pathConstraints;
|
||||
Vector<PhysicsConstraint *> _physicsConstraints;
|
||||
Vector<Update *> _updateCache;
|
||||
Vector<Constraint *> _constraints;
|
||||
Vector<PhysicsConstraint *> _physics;
|
||||
Skin *_skin;
|
||||
Color _color;
|
||||
float _scaleX, _scaleY;
|
||||
float _x, _y;
|
||||
float _time;
|
||||
float _windX, _windY, _gravityX, _gravityY;
|
||||
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);
|
||||
float _time;
|
||||
float _windX, _windY, _gravityX, _gravityY;
|
||||
int _update;
|
||||
};
|
||||
}
|
||||
}// namespace spine
|
||||
|
||||
#endif /* Spine_Skeleton_h */
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
|
||||
#include <spine/Vector.h>
|
||||
#include <spine/SpineString.h>
|
||||
#include <spine/ConstraintData.h>
|
||||
|
||||
namespace spine {
|
||||
class BoneData;
|
||||
|
||||
@ -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
|
||||
/// state for an attachment. State cannot be stored in an attachment itself because attachments are stateless and may be shared
|
||||
/// 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 Skeleton;
|
||||
|
||||
@ -60,13 +60,6 @@
|
||||
#include <spine/EventData.h>
|
||||
#include <spine/EventTimeline.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/HashMap.h>
|
||||
#include <spine/IkConstraint.h>
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
using namespace spine;
|
||||
|
||||
RTTI_IMPL(BoneTimeline, BoneTimeline)
|
||||
RTTI_IMPL_NOPARENT(BoneTimeline)
|
||||
|
||||
RTTI_IMPL(BoneTimeline1, CurveTimeline1)
|
||||
|
||||
|
||||
@ -296,7 +296,7 @@ void IkConstraint::sort(Skeleton& skeleton) {
|
||||
skeleton.sortBone(_target);
|
||||
Bone* parent = _bones[0]->_bone;
|
||||
skeleton.sortBone(parent);
|
||||
skeleton.updateCache.add(this);
|
||||
skeleton._updateCache.add(this);
|
||||
parent->_sorted = false;
|
||||
skeleton.sortReset(parent->_children);
|
||||
skeleton.constrained(parent);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user