diff --git a/spine-cpp/spine-cpp/include/spine/BoneTimeline.h b/spine-cpp/spine-cpp/include/spine/BoneTimeline.h index 5c7b2b368..17cd84258 100644 --- a/spine-cpp/spine-cpp/include/spine/BoneTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/BoneTimeline.h @@ -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) {} diff --git a/spine-cpp/spine-cpp/include/spine/Posed.h b/spine-cpp/spine-cpp/include/spine/Posed.h index eb8b4784d..029106e7a 100644 --- a/spine-cpp/spine-cpp/include/spine/Posed.h +++ b/spine-cpp/spine-cpp/include/spine/Posed.h @@ -34,8 +34,14 @@ #include namespace spine { + class SP_API Posed { + public: + Posed() {} + virtual ~Posed() {} + }; + template - 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 }; } diff --git a/spine-cpp/spine-cpp/include/spine/PosedActive.h b/spine-cpp/spine-cpp/include/spine/PosedActive.h index 71c328f66..9747fb5f3 100644 --- a/spine-cpp/spine-cpp/include/spine/PosedActive.h +++ b/spine-cpp/spine-cpp/include/spine/PosedActive.h @@ -34,16 +34,11 @@ #include namespace spine { - template - class SP_API PosedActive : public Posed { - 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 - PosedActive::PosedActive(D& data) : Posed(data), _active(false) { - this->setupPose(); - } + class SP_API PosedActiveGeneric : public PosedGeneric { + friend class SlotCurveTimeline; - template - PosedActive::~PosedActive() { - } - - template - bool PosedActive::isActive() { - return _active; - } -} + public: + PosedActive(D &data): PosedGeneric(data), _active(false) { + this->setupPose(); + } + virtual ~PosedActive() {} + }; +}// namespace spine #endif /* SPINE_POSEDACTIVE_H_ */ \ No newline at end of file diff --git a/spine-cpp/spine-cpp/include/spine/Skeleton.h b/spine-cpp/spine-cpp/include/spine/Skeleton.h index b749c150f..376cd6f67 100644 --- a/spine-cpp/spine-cpp/include/spine/Skeleton.h +++ b/spine-cpp/spine-cpp/include/spine/Skeleton.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 &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 &getBones(); + + Vector &getUpdateCache(); + + Bone *getRootBone(); /// @return May be NULL. Bone *findBone(const String &boneName); + Vector &getSlots(); + /// @return May be NULL. Slot *findSlot(const String &slotName); + Vector &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 &getConstraints(); - /// @return May be NULL. - TransformConstraint *findTransformConstraint(const String &constraintName); + Vector &getPhysicsConstraints(); - /// @return May be NULL. - PathConstraint *findPathConstraint(const String &constraintName); - - /// @return May be NULL. - PhysicsConstraint *findPhysicsConstraint(const String &constraintName); + template + 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 &outVertexBuffer); + void getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector &outVertexBuffer); void getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector &outVertexBuffer, SkeletonClipping *clipper); - Bone *getRootBone(); - - SkeletonData *getData(); - - Vector &getBones(); - - Vector &getUpdateCacheList(); - - Vector &getSlots(); - - Vector &getDrawOrder(); - - Vector &getIkConstraints(); - - Vector &getPathConstraints(); - - Vector &getTransformConstraints(); - - Vector &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 _updateCache; private: - SkeletonData *_data; + SkeletonData &_data; Vector _bones; Vector _slots; Vector _drawOrder; - Vector _ikConstraints; - Vector _transformConstraints; - Vector _pathConstraints; - Vector _physicsConstraints; - Vector _updateCache; + Vector _constraints; + Vector _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 &bones); + float _time; + float _windX, _windY, _gravityX, _gravityY; + int _update; }; -} +}// namespace spine #endif /* Spine_Skeleton_h */ diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonData.h b/spine-cpp/spine-cpp/include/spine/SkeletonData.h index 4021e690d..2362ce620 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonData.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonData.h @@ -32,6 +32,7 @@ #include #include +#include namespace spine { class BoneData; diff --git a/spine-cpp/spine-cpp/include/spine/Slot.h b/spine-cpp/spine-cpp/include/spine/Slot.h index fd731260d..3cc2a50eb 100644 --- a/spine-cpp/spine-cpp/include/spine/Slot.h +++ b/spine-cpp/spine-cpp/include/spine/Slot.h @@ -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 { + class SP_API Slot : public PosedGeneric { friend class VertexAttachment; friend class Skeleton; diff --git a/spine-cpp/spine-cpp/include/spine/spine.h b/spine-cpp/spine-cpp/include/spine/spine.h index 78a98254a..8ffa8c6dd 100644 --- a/spine-cpp/spine-cpp/include/spine/spine.h +++ b/spine-cpp/spine-cpp/include/spine/spine.h @@ -60,13 +60,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include #include #include #include diff --git a/spine-cpp/spine-cpp/src/spine/BoneTimeline.cpp b/spine-cpp/spine-cpp/src/spine/BoneTimeline.cpp index 110fd0d72..14856da1c 100644 --- a/spine-cpp/spine-cpp/src/spine/BoneTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/BoneTimeline.cpp @@ -38,7 +38,7 @@ using namespace spine; -RTTI_IMPL(BoneTimeline, BoneTimeline) +RTTI_IMPL_NOPARENT(BoneTimeline) RTTI_IMPL(BoneTimeline1, CurveTimeline1) diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index 9f7895001..c4e8e7962 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -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);