From dfa1c2ecebfe141c6cf0f09f7e4446c8ee8d090f Mon Sep 17 00:00:00 2001 From: Stephen Gowen Date: Sat, 25 Nov 2017 12:29:10 -0500 Subject: [PATCH] Getting some boiler plate out of the way. --- spine-cpp/spine-cpp/include/spine/Animation.h | 15 ++ .../include/spine/AttachmentTimeline.h | 76 ++------- .../spine-cpp/include/spine/ColorTimeline.h | 122 +++------------ .../spine-cpp/include/spine/DeformTimeline.h | 4 + .../include/spine/DrawOrderTimeline.h | 4 + .../spine-cpp/include/spine/EventTimeline.h | 4 + .../include/spine/IkConstraintTimeline.h | 4 + .../include/spine/PathConstraintMixTimeline.h | 4 + .../spine/PathConstraintPositionTimeline.h | 4 + .../spine/PathConstraintSpacingTimeline.h | 4 + .../spine-cpp/include/spine/ScaleTimeline.h | 4 + .../spine-cpp/include/spine/ShearTimeline.h | 4 + spine-cpp/spine-cpp/include/spine/Skeleton.h | 15 ++ spine-cpp/spine-cpp/include/spine/Slot.h | 15 ++ spine-cpp/spine-cpp/include/spine/SlotData.h | 15 ++ .../spine/TransformConstraintTimeline.h | 4 + .../include/spine/TranslateTimeline.h | 4 + .../include/spine/TwoColorTimeline.h | 4 + .../src/spine/AttachmentTimeline.cpp | 93 +++++++++++ .../spine-cpp/src/spine/ColorTimeline.cpp | 144 ++++++++++++++++++ .../spine-cpp/src/spine/DeformTimeline.cpp | 18 +++ .../spine-cpp/src/spine/DrawOrderTimeline.cpp | 18 +++ .../spine-cpp/src/spine/EventTimeline.cpp | 18 +++ .../src/spine/IkConstraintTimeline.cpp | 18 +++ .../src/spine/PathConstraintMixTimeline.cpp | 18 +++ .../spine/PathConstraintPositionTimeline.cpp | 18 +++ .../spine/PathConstraintSpacingTimeline.cpp | 18 +++ .../spine-cpp/src/spine/ScaleTimeline.cpp | 18 +++ .../spine-cpp/src/spine/ShearTimeline.cpp | 18 +++ .../src/spine/TransformConstraintTimeline.cpp | 19 ++- .../spine-cpp/src/spine/TranslateTimeline.cpp | 18 +++ .../spine-cpp/src/spine/TwoColorTimeline.cpp | 18 +++ 32 files changed, 600 insertions(+), 160 deletions(-) diff --git a/spine-cpp/spine-cpp/include/spine/Animation.h b/spine-cpp/spine-cpp/include/spine/Animation.h index 39196235c..06a8ec4bf 100644 --- a/spine-cpp/spine-cpp/include/spine/Animation.h +++ b/spine-cpp/spine-cpp/include/spine/Animation.h @@ -49,6 +49,21 @@ namespace Spine friend class TranslateTimeline; friend class AnimationStateData; + friend class AttachmentTimeline; + friend class ColorTimeline; + friend class DeformTimeline; + friend class DrawOrderTimeline; + friend class EventTimeline; + friend class IkConstraintTimeline; + friend class PathConstraintMixTimeline; + friend class PathConstraintPositionTimeline; + friend class PathConstraintSpacingTimeline; + friend class ScaleTimeline; + friend class ShearTimeline; + friend class TransformConstraintTimeline; + friend class TranslateTimeline; + friend class TwoColorTimeline; + public: Animation(std::string name, Vector& timelines, float duration); diff --git a/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h b/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h index 31267ada8..b43daf303 100644 --- a/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h @@ -49,68 +49,22 @@ namespace Spine SPINE_RTTI_DECL; public: - AttachmentTimeline(int frameCount) - { - _frames.reserve(frameCount); - _attachmentNames.reserve(frameCount); - } + AttachmentTimeline(int frameCount); -// virtual int getPropertyId() -// { -// return ((int)TimelineType_Attachment << 24) + slotIndex; -// } -// -// /// Sets the time and value of the specified keyframe. -// void setFrame(int frameIndex, float time, std::string attachmentName) -// { -// frames[frameIndex] = time; -// attachmentNames[frameIndex] = attachmentName; -// } -// -// void apply(Skeleton& skeleton, float lastTime, float time, Vector firedEvents, float alpha, MixPose pose, MixDirection direction) -// { -// std::string attachmentName; -// Slot slot = skeleton.slots.Items[slotIndex]; -// if (direction == MixDirection_Out && pose == MixPose_Setup) -// { -// attachmentName = slot.data.attachmentName; -// slot.Attachment = attachmentName == NULL ? NULL : skeleton.getAttachment(slotIndex, attachmentName); -// return; -// } -// -// float[] frames = _frames; -// if (time < frames[0]) -// { -// // Time is before first frame. -// if (pose == MixPose_Setup) -// { -// attachmentName = slot.data.attachmentName; -// slot.Attachment = attachmentName == NULL ? NULL : skeleton.getAttachment(slotIndex, attachmentName); -// } -// return; -// } -// -// int frameIndex; -// if (time >= frames[frames.Length - 1]) // Time is after last frame. -// { -// frameIndex = frames.Length - 1; -// } -// else -// { -// frameIndex = Animation::binarySearch(frames, time, 1) - 1; -// } -// -// attachmentName = attachmentNames[frameIndex]; -// slot.Attachment = attachmentName == NULL ? NULL : skeleton.getAttachment(slotIndex, attachmentName); -// } -// -// int getSlotIndex() { return _slotIndex; } -// void setSlotIndex(int inValue) { _slotIndex = inValue; } -// Vector& getFrames() { return _frames; } -// void setFrames(Vector& inValue) { _frames = inValue; } // time, ... -// Vector getAttachmentNames() { return _attachmentNames; } -// set { attachmentNames = inValue; } -// int getFrameCount() { return frames.Length; } + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, std::string attachmentName); + + int getSlotIndex(); + void setSlotIndex(int inValue); + Vector& getFrames(); + void setFrames(Vector& inValue); // time, ... + Vector getAttachmentNames(); + void setAttachmentNames(Vector& inValue); + int getFrameCount(); private: int _slotIndex; diff --git a/spine-cpp/spine-cpp/include/spine/ColorTimeline.h b/spine-cpp/spine-cpp/include/spine/ColorTimeline.h index c12c54f1c..268e619c2 100644 --- a/spine-cpp/spine-cpp/include/spine/ColorTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ColorTimeline.h @@ -39,104 +39,30 @@ namespace Spine { SPINE_RTTI_DECL; -// public const int ENTRIES = 5; -// protected const int PREV_TIME = -5, PREV_R = -4, PREV_G = -3, PREV_B = -2, PREV_A = -1; -// protected const int R = 1, G = 2, B = 3, A = 4; -// -// internal int slotIndex; -// internal float[] frames; -// -// public int SlotIndex { return slotIndex; } set { slotIndex = inValue; } -// public float[] Frames { return frames; } set { frames = inValue; } // time, r, g, b, a, ... -// -// override public int PropertyId { -// get { return ((int)TimelineType.Color << 24) + slotIndex; } -// } -// -// public ColorTimeline (int frameCount) -// : base(frameCount) { -// frames = new float[frameCount * ENTRIES]; -// } -// -// /// Sets the time and value of the specified keyframe. -// public void SetFrame (int frameIndex, float time, float r, float g, float b, float a) { -// frameIndex *= ENTRIES; -// frames[frameIndex] = time; -// frames[frameIndex + R] = r; -// frames[frameIndex + G] = g; -// frames[frameIndex + B] = b; -// frames[frameIndex + A] = a; -// } -// -// override public void Apply (Skeleton skeleton, float lastTime, float time, Vector firedEvents, float alpha, MixPose pose, MixDirection direction) { -// Slot slot = skeleton.slots.Items[slotIndex]; -// float[] frames = _frames; -// if (time < frames[0]) { -// var slotData = slot.data; -// switch (pose) { -// case MixPose_Setup: -// slot.r = slotData.r; -// slot.g = slotData.g; -// slot.b = slotData.b; -// slot.a = slotData.a; -// return; -// case MixPose_Current: -// slot.r += (slot.r - slotData.r) * alpha; -// slot.g += (slot.g - slotData.g) * alpha; -// slot.b += (slot.b - slotData.b) * alpha; -// slot.a += (slot.a - slotData.a) * alpha; -// return; -// } -// return; -// } -// -// float r, g, b, a; -// if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame. -// int i = frames.Length; -// r = frames[i + PREV_R]; -// g = frames[i + PREV_G]; -// b = frames[i + PREV_B]; -// a = frames[i + PREV_A]; -// } else { -// // Interpolate between the previous frame and the current frame. -// int frame = Animation.BinarySearch(frames, time, ENTRIES); -// r = frames[frame + PREV_R]; -// g = frames[frame + PREV_G]; -// b = frames[frame + PREV_B]; -// a = frames[frame + PREV_A]; -// float frameTime = frames[frame]; -// float percent = GetCurvePercent(frame / ENTRIES - 1, -// 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); -// -// r += (frames[frame + R] - r) * percent; -// g += (frames[frame + G] - g) * percent; -// b += (frames[frame + B] - b) * percent; -// a += (frames[frame + A] - a) * percent; -// } -// if (alpha == 1) { -// slot.r = r; -// slot.g = g; -// slot.b = b; -// slot.a = a; -// } else { -// float br, bg, bb, ba; -// if (pose == MixPose_Setup) { -// br = slot.data.r; -// bg = slot.data.g; -// bb = slot.data.b; -// ba = slot.data.a; -// } else { -// br = slot.r; -// bg = slot.g; -// bb = slot.b; -// ba = slot.a; -// } -// slot.r = br + ((r - br) * alpha); -// slot.g = bg + ((g - bg) * alpha); -// slot.b = bb + ((b - bb) * alpha); -// slot.a = ba + ((a - ba) * alpha); -// } -// } + public: + static const int ENTRIES; + + ColorTimeline (int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, float r, float g, float b, float a); + + int getSlotIndex(); + void setSlotIndex(int inValue); + Vector& getFrames(); + void setFrames(Vector& inValue); // time, r, g, b, a, ... + + protected: + static const int PREV_TIME, PREV_R, PREV_G, PREV_B, PREV_A; + static const int R, G, B, A; + + private: + int _slotIndex; + Vector _frames; }; } diff --git a/spine-cpp/spine-cpp/include/spine/DeformTimeline.h b/spine-cpp/spine-cpp/include/spine/DeformTimeline.h index 6e4aa3512..db7fe976b 100644 --- a/spine-cpp/spine-cpp/include/spine/DeformTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/DeformTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // internal int slotIndex; // internal float[] frames; // internal float[][] frameVertices; diff --git a/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h b/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h index 97648b8a7..cf72ff56b 100644 --- a/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // internal float[] frames; // private int[][] drawOrders; // diff --git a/spine-cpp/spine-cpp/include/spine/EventTimeline.h b/spine-cpp/spine-cpp/include/spine/EventTimeline.h index 67313e7dc..72b071fdf 100644 --- a/spine-cpp/spine-cpp/include/spine/EventTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/EventTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // internal float[] frames; // private Event[] events; // diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h b/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h index ac04b035d..204efcc6f 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // public const int ENTRIES = 3; // private const int PREV_TIME = -3, PREV_MIX = -2, PREV_BEND_DIRECTION = -1; // private const int MIX = 1, BEND_DIRECTION = 2; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h index c27619e0a..199a26e76 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // public const int ENTRIES = 3; // private const int PREV_TIME = -3, PREV_ROTATE = -2, PREV_TRANSLATE = -1; // private const int ROTATE = 1, TRANSLATE = 2; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h index 5d58d5eb6..1f85a96eb 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // public const int ENTRIES = 2; // protected const int PREV_TIME = -2, PREV_VALUE = -1; // protected const int VALUE = 1; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h index 5ff6892a5..210326437 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // override public int PropertyId { // get { return ((int)TimelineType.PathConstraintSpacing << 24) + pathConstraintIndex; } // } diff --git a/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h b/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h index 075fb9b9c..f369890df 100644 --- a/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // override public int PropertyId { // get { return ((int)TimelineType.Scale << 24) + boneIndex; } // } diff --git a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h index b04c4156d..ddf02f09d 100644 --- a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // override public int PropertyId { // get { return ((int)TimelineType.Shear << 24) + boneIndex; } // } diff --git a/spine-cpp/spine-cpp/include/spine/Skeleton.h b/spine-cpp/spine-cpp/include/spine/Skeleton.h index 9e3eb9583..03ff33d5c 100644 --- a/spine-cpp/spine-cpp/include/spine/Skeleton.h +++ b/spine-cpp/spine-cpp/include/spine/Skeleton.h @@ -51,6 +51,21 @@ namespace Spine class Skeleton { + friend class AttachmentTimeline; + friend class ColorTimeline; + friend class DeformTimeline; + friend class DrawOrderTimeline; + friend class EventTimeline; + friend class IkConstraintTimeline; + friend class PathConstraintMixTimeline; + friend class PathConstraintPositionTimeline; + friend class PathConstraintSpacingTimeline; + friend class ScaleTimeline; + friend class ShearTimeline; + friend class TransformConstraintTimeline; + friend class TranslateTimeline; + friend class TwoColorTimeline; + public: Skeleton(SkeletonData& data); diff --git a/spine-cpp/spine-cpp/include/spine/Slot.h b/spine-cpp/spine-cpp/include/spine/Slot.h index 07af110d5..26fd37f9a 100644 --- a/spine-cpp/spine-cpp/include/spine/Slot.h +++ b/spine-cpp/spine-cpp/include/spine/Slot.h @@ -47,6 +47,21 @@ namespace Spine friend class VertexAttachment; friend class Skeleton; + friend class AttachmentTimeline; + friend class ColorTimeline; + friend class DeformTimeline; + friend class DrawOrderTimeline; + friend class EventTimeline; + friend class IkConstraintTimeline; + friend class PathConstraintMixTimeline; + friend class PathConstraintPositionTimeline; + friend class PathConstraintSpacingTimeline; + friend class ScaleTimeline; + friend class ShearTimeline; + friend class TransformConstraintTimeline; + friend class TranslateTimeline; + friend class TwoColorTimeline; + public: Slot(SlotData& data, Bone& bone); diff --git a/spine-cpp/spine-cpp/include/spine/SlotData.h b/spine-cpp/spine-cpp/include/spine/SlotData.h index 0fe231984..02dbaac4a 100644 --- a/spine-cpp/spine-cpp/include/spine/SlotData.h +++ b/spine-cpp/spine-cpp/include/spine/SlotData.h @@ -41,6 +41,21 @@ namespace Spine class SlotData { + friend class AttachmentTimeline; + friend class ColorTimeline; + friend class DeformTimeline; + friend class DrawOrderTimeline; + friend class EventTimeline; + friend class IkConstraintTimeline; + friend class PathConstraintMixTimeline; + friend class PathConstraintPositionTimeline; + friend class PathConstraintSpacingTimeline; + friend class ScaleTimeline; + friend class ShearTimeline; + friend class TransformConstraintTimeline; + friend class TranslateTimeline; + friend class TwoColorTimeline; + public: SlotData(int index, std::string name, BoneData& boneData); diff --git a/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h b/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h index 00debb06d..4df5190ba 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // public const int ENTRIES = 5; // private const int PREV_TIME = -5, PREV_ROTATE = -4, PREV_TRANSLATE = -3, PREV_SCALE = -2, PREV_SHEAR = -1; // private const int ROTATE = 1, TRANSLATE = 2, SCALE = 3, SHEAR = 4; diff --git a/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h b/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h index 8abccc9e2..40a5e191c 100644 --- a/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h @@ -42,6 +42,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // public const int ENTRIES = 3; // protected const int PREV_TIME = -3, PREV_X = -2, PREV_Y = -1; // protected const int X = 1, Y = 2; diff --git a/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h b/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h index 8d814439f..0943967e5 100644 --- a/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h @@ -39,6 +39,10 @@ namespace Spine { SPINE_RTTI_DECL; + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); + + virtual int getPropertyId(); + // public const int ENTRIES = 8; // protected const int PREV_TIME = -8, PREV_R = -7, PREV_G = -6, PREV_B = -5, PREV_A = -4; // protected const int PREV_R2 = -3, PREV_G2 = -2, PREV_B2 = -1; diff --git a/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp b/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp index cc562fd80..5535f0242 100644 --- a/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp @@ -35,8 +35,101 @@ #include #include +#include +#include namespace Spine { SPINE_RTTI_IMPL(AttachmentTimeline, Timeline); + + AttachmentTimeline::AttachmentTimeline(int frameCount) + { + _frames.reserve(frameCount); + _attachmentNames.reserve(frameCount); + } + + void AttachmentTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + assert(_slotIndex < skeleton._slots.size()); + + std::string attachmentName; + Slot* slotP = skeleton._slots[_slotIndex]; + Slot& slot = *slotP; + if (direction == MixDirection_Out && pose == MixPose_Setup) + { + attachmentName = slot._data._attachmentName; + slot._attachment = attachmentName.length() == 0 ? NULL : skeleton.getAttachment(_slotIndex, attachmentName); + return; + } + + if (time < _frames[0]) + { + // Time is before first frame. + if (pose == MixPose_Setup) + { + attachmentName = slot._data._attachmentName; + slot._attachment = attachmentName.length() == 0 ? NULL : skeleton.getAttachment(_slotIndex, attachmentName); + } + return; + } + + int frameIndex; + if (time >= _frames[_frames.size() - 1]) // Time is after last frame. + { + frameIndex = static_cast(_frames.size()) - 1; + } + else + { + frameIndex = Animation::binarySearch(_frames, time, 1) - 1; + } + + attachmentName = _attachmentNames[frameIndex]; + slot._attachment = attachmentName.length() == 0 ? NULL : skeleton.getAttachment(_slotIndex, attachmentName); + } + + int AttachmentTimeline::getPropertyId() + { + return ((int)TimelineType_Attachment << 24) + _slotIndex; + } + + void AttachmentTimeline::setFrame(int frameIndex, float time, std::string attachmentName) + { + _frames[frameIndex] = time; + _attachmentNames[frameIndex] = attachmentName; + } + + int AttachmentTimeline::getSlotIndex() + { + return _slotIndex; + } + + void AttachmentTimeline::setSlotIndex(int inValue) + { + _slotIndex = inValue; + } + + Vector& AttachmentTimeline::getFrames() + { + return _frames; + } + + void AttachmentTimeline::setFrames(Vector& inValue) + { + _frames = inValue; + } + + Vector AttachmentTimeline::getAttachmentNames() + { + return _attachmentNames; + } + + void AttachmentTimeline::setAttachmentNames(Vector& inValue) + { + _attachmentNames = inValue; + } + + int AttachmentTimeline::getFrameCount() + { + return static_cast(_frames.size()); + } } diff --git a/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp index e53c26b97..13d425d27 100644 --- a/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp @@ -30,7 +30,151 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(ColorTimeline, CurveTimeline); + + const int ColorTimeline::ENTRIES = 5; + const int ColorTimeline::PREV_TIME = -5; + const int ColorTimeline::PREV_R = -4; + const int ColorTimeline::PREV_G = -3; + const int ColorTimeline::PREV_B = -2; + const int ColorTimeline::PREV_A = -1; + const int ColorTimeline::R = 1; + const int ColorTimeline::G = 2; + const int ColorTimeline::B = 3; + const int ColorTimeline::A = 4; + + ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount) + { + _frames.reserve(frameCount * ENTRIES); + } + + void ColorTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + Slot* slotP = skeleton._slots[_slotIndex]; + Slot& slot = *slotP; + if (time < _frames[0]) + { + SlotData& slotData = slot._data; + switch (pose) + { + case MixPose_Setup: + slot._r = slotData._r; + slot._g = slotData._g; + slot._b = slotData._b; + slot._a = slotData._a; + return; + case MixPose_Current: + slot._r += (slot._r - slotData._r) * alpha; + slot._g += (slot._g - slotData._g) * alpha; + slot._b += (slot._b - slotData._b) * alpha; + slot._a += (slot._a - slotData._a) * alpha; + return; + case MixPose_CurrentLayered: + default: + return; + } + } + + float r, g, b, a; + if (time >= _frames[_frames.size() - ENTRIES]) + { + // Time is after last frame. + int i = static_cast(_frames.size()); + r = _frames[i + PREV_R]; + g = _frames[i + PREV_G]; + b = _frames[i + PREV_B]; + a = _frames[i + PREV_A]; + } + else + { + // Interpolate between the previous frame and the current frame. + int frame = Animation::binarySearch(_frames, time, ENTRIES); + r = _frames[frame + PREV_R]; + g = _frames[frame + PREV_G]; + b = _frames[frame + PREV_B]; + a = _frames[frame + PREV_A]; + float frameTime = _frames[frame]; + float percent = getCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + + r += (_frames[frame + R] - r) * percent; + g += (_frames[frame + G] - g) * percent; + b += (_frames[frame + B] - b) * percent; + a += (_frames[frame + A] - a) * percent; + } + + if (alpha == 1) + { + slot._r = r; + slot._g = g; + slot._b = b; + slot._a = a; + } + else + { + float br, bg, bb, ba; + if (pose == MixPose_Setup) + { + br = slot._data._r; + bg = slot._data._g; + bb = slot._data._b; + ba = slot._data._a; + } + else + { + br = slot._r; + bg = slot._g; + bb = slot._b; + ba = slot._a; + } + slot._r = br + ((r - br) * alpha); + slot._g = bg + ((g - bg) * alpha); + slot._b = bb + ((b - bb) * alpha); + slot._a = ba + ((a - ba) * alpha); + } + } + + int ColorTimeline::getPropertyId() + { + return ((int)TimelineType_Color << 24) + _slotIndex; + } + + void ColorTimeline::setFrame(int frameIndex, float time, float r, float g, float b, float a) + { + frameIndex *= ENTRIES; + _frames[frameIndex] = time; + _frames[frameIndex + R] = r; + _frames[frameIndex + G] = g; + _frames[frameIndex + B] = b; + _frames[frameIndex + A] = a; + } + + int ColorTimeline::getSlotIndex() + { + return _slotIndex; + } + + void ColorTimeline::setSlotIndex(int inValue) + { + _slotIndex = inValue; + } + + Vector& ColorTimeline::getFrames() + { + return _frames; + } + + void ColorTimeline::setFrames(Vector& inValue) + { + _frames = inValue; + } } diff --git a/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp b/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp index fb99c6d33..34a3c487b 100644 --- a/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(DeformTimeline, CurveTimeline); + + void DeformTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int DeformTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp b/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp index 34f9c9b14..d8eceb2da 100644 --- a/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(DrawOrderTimeline, Timeline); + + void DrawOrderTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int DrawOrderTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp b/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp index dc6ee5246..7d1b0bb9f 100644 --- a/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(EventTimeline, Timeline); + + void EventTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int EventTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp index 603b48c06..71c49bc1f 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(IkConstraintTimeline, CurveTimeline); + + void IkConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int IkConstraintTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp index 515c7bf17..60cc7923c 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(PathConstraintMixTimeline, CurveTimeline); + + void PathConstraintMixTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int PathConstraintMixTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp index ca033cd55..ec680b528 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(PathConstraintPositionTimeline, CurveTimeline); + + void PathConstraintPositionTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int PathConstraintPositionTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp index 7a9f5567f..131b9d9cd 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(PathConstraintSpacingTimeline, PathConstraintPositionTimeline); + + void PathConstraintSpacingTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int PathConstraintSpacingTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp index 2da55b080..84e1401d1 100644 --- a/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(ScaleTimeline, TranslateTimeline); + + void ScaleTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int ScaleTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp index 13d19abda..04b8ad8e8 100644 --- a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(ShearTimeline, TranslateTimeline); + + void ShearTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int ShearTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp index daceecc8a..578734cb8 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp @@ -30,8 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(TransformConstraintTimeline, CurveTimeline); + + void TransformConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int TransformConstraintTimeline::getPropertyId() + { + return 0; + } } - diff --git a/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp index 97c43cfce..34d8b1b14 100644 --- a/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(TranslateTimeline, CurveTimeline); + + void TranslateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int TranslateTimeline::getPropertyId() + { + return 0; + } } diff --git a/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp index 45adf3def..afd005f6e 100644 --- a/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp @@ -30,7 +30,25 @@ #include +#include +#include + +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL(TwoColorTimeline, CurveTimeline); + + void TwoColorTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) + { + // TODO + } + + int TwoColorTimeline::getPropertyId() + { + return 0; + } }