diff --git a/spine-cpp/spine-cpp/include/spine/DeformTimeline.h b/spine-cpp/spine-cpp/include/spine/DeformTimeline.h index 7319e4b23..faf3f848e 100644 --- a/spine-cpp/spine-cpp/include/spine/DeformTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/DeformTimeline.h @@ -35,155 +35,36 @@ namespace Spine { - class DeformTimeline : CurveTimeline + class VertexAttachment; + + class DeformTimeline : public CurveTimeline { SPINE_RTTI_DECL; + public: + DeformTimeline(int frameCount); + 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; -// internal VertexAttachment attachment; -// -// public int SlotIndex { return slotIndex; } set { slotIndex = inValue; } -// public float[] Frames { return frames; } set { frames = inValue; } // time, ... -// public float[][] Vertices { return frameVertices; } set { frameVertices = inValue; } -// public VertexAttachment Attachment { return attachment; } set { attachment = inValue; } -// -// override public int PropertyId { -// get { return ((int)TimelineType.Deform << 24) + attachment.id + slotIndex; } -// } -// -// public DeformTimeline (int frameCount) -// : base(frameCount) { -// frames = new float[frameCount]; -// frameVertices = new float[frameCount][]; -// } -// -// /// Sets the time and value of the specified keyframe. -// public void SetFrame (int frameIndex, float time, float[] vertices) { -// frames[frameIndex] = time; -// frameVertices[frameIndex] = vertices; -// } -// -// override public void Apply (Skeleton skeleton, float lastTime, float time, Vector firedEvents, float alpha, MixPose pose, MixDirection direction) { -// Slot slot = skeleton.slots.Items[slotIndex]; -// VertexAttachment vertexAttachment = slot.attachment as VertexAttachment; -// if (vertexAttachment == NULL || !vertexAttachment.ApplyDeform(attachment)) return; -// -// var verticesArray = slot.attachmentVertices; -// if (verticesArray.Count == 0) alpha = 1; -// -// float[][] frameVertices = _frameVertices; -// int vertexCount = frameVertices[0].Length; -// float[] frames = _frames; -// float[] vertices; -// -// if (time < frames[0]) { -// -// switch (pose) { -// case MixPose_Setup: -// verticesArray.Clear(); -// return; -// case MixPose_Current: -// if (alpha == 1) { -// verticesArray.Clear(); -// return; -// } -// -// // verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count. -// if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount; -// verticesArray.Count = vertexCount; -// vertices = verticesArray.Items; -// -// if (vertexAttachment.bones == NULL) { -// // Unweighted vertex positions. -// float[] setupVertices = vertexAttachment.vertices; -// for (int i = 0; i < vertexCount; i++) -// vertices[i] += (setupVertices[i] - vertices[i]) * alpha; -// } else { -// // Weighted deform offsets. -// alpha = 1 - alpha; -// for (int i = 0; i < vertexCount; i++) -// vertices[i] *= alpha; -// } -// return; -// default: -// return; -// } -// -// } -// -// // verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count. -// if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount; -// verticesArray.Count = vertexCount; -// vertices = verticesArray.Items; -// -// if (time >= frames[frames.Length - 1]) { // Time is after last frame. -// float[] lastVertices = frameVertices[frames.Length - 1]; -// if (alpha == 1) { -// // Vertex positions or deform offsets, no alpha. -// Array.Copy(lastVertices, 0, vertices, 0, vertexCount); -// } else if (pose == MixPose_Setup) { -// if (vertexAttachment.bones == NULL) { -// // Unweighted vertex positions, with alpha. -// float[] setupVertices = vertexAttachment.vertices; -// for (int i = 0; i < vertexCount; i++) { -// float setup = setupVertices[i]; -// vertices[i] = setup + (lastVertices[i] - setup) * alpha; -// } -// } else { -// // Weighted deform offsets, with alpha. -// for (int i = 0; i < vertexCount; i++) -// vertices[i] = lastVertices[i] * alpha; -// } -// } else { -// // Vertex positions or deform offsets, with alpha. -// for (int i = 0; i < vertexCount; i++) -// vertices[i] += (lastVertices[i] - vertices[i]) * alpha; -// } -// return; -// } -// -// // Interpolate between the previous frame and the current frame. -// int frame = Animation::binarySearch(frames, time); -// float[] prevVertices = frameVertices[frame - 1]; -// float[] nextVertices = frameVertices[frame]; -// float frameTime = frames[frame]; -// float percent = GetCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime)); -// -// if (alpha == 1) { -// // Vertex positions or deform offsets, no alpha. -// for (int i = 0; i < vertexCount; i++) { -// float prev = prevVertices[i]; -// vertices[i] = prev + (nextVertices[i] - prev) * percent; -// } -// } else if (pose == MixPose_Setup) { -// if (vertexAttachment.bones == NULL) { -// // Unweighted vertex positions, with alpha. -// var setupVertices = vertexAttachment.vertices; -// for (int i = 0; i < vertexCount; i++) { -// float prev = prevVertices[i], setup = setupVertices[i]; -// vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; -// } -// } else { -// // Weighted deform offsets, with alpha. -// for (int i = 0; i < vertexCount; i++) { -// float prev = prevVertices[i]; -// vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; -// } -// } -// } else { -// // Vertex positions or deform offsets, with alpha. -// for (int i = 0; i < vertexCount; i++) { -// float prev = prevVertices[i]; -// vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha; -// } -// } -// } + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, Vector& vertices); + + int getSlotIndex(); + void setSlotIndex(int inValue); + Vector& getFrames(); + void setFrames(Vector& inValue); // time, ... + Vector< Vector >& getVertices(); + void setVertices(Vector< Vector >& inValue); + VertexAttachment* getAttachment(); + void setAttachment(VertexAttachment* inValue); + + private: + int _slotIndex; + Vector _frames; + Vector< Vector > _frameVertices; + VertexAttachment* _attachment; }; } diff --git a/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h b/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h index b05fb161b..ac1ea0623 100644 --- a/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h @@ -38,66 +38,27 @@ namespace Spine class DrawOrderTimeline : public Timeline { SPINE_RTTI_DECL; + + public: + DrawOrderTimeline(int frameCount); 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; -// -// public float[] Frames { return frames; } set { frames = inValue; } // time, ... -// public int[][] DrawOrders { return drawOrders; } set { drawOrders = inValue; } -// public int FrameCount { return frames.Length; } -// -// public int PropertyId { -// get { return ((int)TimelineType.DrawOrder << 24); } -// } -// -// public DrawOrderTimeline (int frameCount) { -// frames = new float[frameCount]; -// drawOrders = new int[frameCount][]; -// } -// -// /// Sets the time and value of the specified keyframe. -// /// May be NULL to use bind pose draw order. -// public void SetFrame (int frameIndex, float time, int[] drawOrder) { -// frames[frameIndex] = time; -// drawOrders[frameIndex] = drawOrder; -// } -// -// public void Apply (Skeleton skeleton, float lastTime, float time, Vector firedEvents, float alpha, MixPose pose, MixDirection direction) { -// Vector drawOrder = skeleton.drawOrder; -// Vector slots = skeleton.slots; -// if (direction == MixDirection_Out && pose == MixPose_Setup) { -// Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count); -// return; -// } -// -// float[] frames = _frames; -// if (time < frames[0]) { -// if (pose == MixPose_Setup) Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count); -// return; -// } -// -// int frame; -// if (time >= frames[frames.Length - 1]) // Time is after last frame. -// frame = frames.Length - 1; -// else -// frame = Animation::binarySearch(frames, time) - 1; -// -// int[] drawOrderToSetupIndex = drawOrders[frame]; -// if (drawOrderToSetupIndex == NULL) { -// drawOrder.Clear(); -// for (int i = 0, n = slots.Count; i < n; i++) -// drawOrder.Add(slots.Items[i]); -// } else { -// var drawOrderItems = drawOrder.Items; -// var slotsItems = slots.Items; -// for (int i = 0, n = drawOrderToSetupIndex.Length; i < n; i++) -// drawOrderItems[i] = slotsItems[drawOrderToSetupIndex[i]]; -// } -// } + /// Sets the time and value of the specified keyframe. + /// @param drawOrder May be NULL to use bind pose draw order + void setFrame(int frameIndex, float time, Vector& drawOrder); + + Vector& getFrames(); + void setFrames(Vector& inValue); // time, ... + Vector< Vector >& getDrawOrders(); + void setDrawOrders(Vector< Vector >& inValue); + int getFrameCount(); + + private: + Vector _frames; + Vector< Vector > _drawOrders; }; } diff --git a/spine-cpp/spine-cpp/include/spine/EventTimeline.h b/spine-cpp/spine-cpp/include/spine/EventTimeline.h index e0c2859bc..1013a26e7 100644 --- a/spine-cpp/spine-cpp/include/spine/EventTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/EventTimeline.h @@ -49,10 +49,7 @@ namespace Spine // public float[] Frames { return frames; } set { frames = inValue; } // time, ... // public Event[] Events { return events; } set { events = inValue; } // public int FrameCount { return frames.Length; } -// -// public int PropertyId { -// get { return ((int)TimelineType.Event << 24); } -// } +// // // public EventTimeline (int frameCount) { // frames = new float[frameCount]; @@ -60,7 +57,7 @@ namespace Spine // } // // /// Sets the time and value of the specified keyframe. -// public void SetFrame (int frameIndex, Event e) { +// public void setFrame (int frameIndex, Event e) { // frames[frameIndex] = e.Time; // events[frameIndex] = e; // } diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h b/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h index 69b3a1ac5..7b44c8f04 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h @@ -39,31 +39,29 @@ namespace Spine { SPINE_RTTI_DECL; + public: + static const int ENTRIES; + + IkConstraintTimeline(int frameCount); + 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; -// -// internal int ikConstraintIndex; -// internal float[] frames; -// + private: + static const int PREV_TIME, PREV_MIX, PREV_BEND_DIRECTION; + static const int MIX, BEND_DIRECTION; + + Vector _frames; + int _ikConstraintIndex; + // public int IkConstraintIndex { return ikConstraintIndex; } set { ikConstraintIndex = inValue; } // public float[] Frames { return frames; } set { frames = inValue; } // time, mix, bendDirection, ... -// -// override public int PropertyId { -// get { return ((int)TimelineType.IkConstraint << 24) + ikConstraintIndex; } -// } -// -// public IkConstraintTimeline (int frameCount) -// : base(frameCount) { -// frames = new float[frameCount * ENTRIES]; -// } +// +// // // /// Sets the time, mix and bend direction of the specified keyframe. -// public void SetFrame (int frameIndex, float time, float mix, int bendDirection) { +// public void setFrame (int frameIndex, float time, float mix, int bendDirection) { // frameIndex *= ENTRIES; // frames[frameIndex] = time; // frames[frameIndex + MIX] = mix; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h index 5514ab8f6..030ae5fb3 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h @@ -39,23 +39,23 @@ namespace Spine { SPINE_RTTI_DECL; + public: virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); virtual int getPropertyId(); + private: + int _pathConstraintIndex; + // public const int ENTRIES = 3; // private const int PREV_TIME = -3, PREV_ROTATE = -2, PREV_TRANSLATE = -1; // private const int ROTATE = 1, TRANSLATE = 2; -// -// internal int pathConstraintIndex; +// // internal float[] frames; // // public int PathConstraintIndex { return pathConstraintIndex; } set { pathConstraintIndex = inValue; } // public float[] Frames { return frames; } set { frames = inValue; } // time, rotate mix, translate mix, ... -// -// override public int PropertyId { -// get { return ((int)TimelineType.PathConstraintMix << 24) + pathConstraintIndex; } -// } +// // // public PathConstraintMixTimeline (int frameCount) // : base(frameCount) { @@ -63,7 +63,7 @@ namespace Spine // } // // /// Sets the time and mixes of the specified keyframe. -// public void SetFrame (int frameIndex, float time, float rotateMix, float translateMix) { +// public void setFrame (int frameIndex, float time, float rotateMix, float translateMix) { // frameIndex *= ENTRIES; // frames[frameIndex] = time; // frames[frameIndex + ROTATE] = rotateMix; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h index 91fc2d252..12c0cffa0 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h @@ -39,31 +39,32 @@ namespace Spine { SPINE_RTTI_DECL; + public: + static const int ENTRIES; + + PathConstraintPositionTimeline(int frameCount); + 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; -// -// internal int pathConstraintIndex; -// internal float[] frames; -// -// override public int PropertyId { -// get { return ((int)TimelineType.PathConstraintPosition << 24) + pathConstraintIndex; } -// } -// -// public PathConstraintPositionTimeline (int frameCount) -// : base(frameCount) { -// frames = new float[frameCount * ENTRIES]; -// } + protected: + static const int PREV_TIME, PREV_VALUE; + static const int VALUE; + + Vector _frames; + int _pathConstraintIndex; + + +// +// +// // // public int PathConstraintIndex { return pathConstraintIndex; } set { pathConstraintIndex = inValue; } // public float[] Frames { return frames; } set { frames = inValue; } // time, position, ... // // /// Sets the time and value of the specified keyframe. -// public void SetFrame (int frameIndex, float time, float value) { +// public void setFrame (int frameIndex, float time, float value) { // frameIndex *= ENTRIES; // frames[frameIndex] = time; // frames[frameIndex + VALUE] = inValue; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h index 41c6cf8ce..35c974bff 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h @@ -39,18 +39,13 @@ namespace Spine { SPINE_RTTI_DECL; + public: + PathConstraintSpacingTimeline(int frameCount); + 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; } -// } -// -// public PathConstraintSpacingTimeline (int frameCount) -// : base(frameCount) { -// } -// // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector firedEvents, float alpha, MixPose pose, MixDirection direction) { // PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex]; // float[] frames = _frames; diff --git a/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h b/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h index af06c888c..dd6db7e65 100644 --- a/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h @@ -43,10 +43,6 @@ namespace Spine virtual int getPropertyId(); -// override public int PropertyId { -// get { return ((int)TimelineType.Scale << 24) + boneIndex; } -// } -// // public ScaleTimeline (int frameCount) // : base(frameCount) { // } diff --git a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h index 585c7ed5a..74a440876 100644 --- a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h @@ -39,14 +39,11 @@ namespace Spine { SPINE_RTTI_DECL; + public: 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; } -// } -// // public ShearTimeline (int frameCount) // : base(frameCount) { // } diff --git a/spine-cpp/spine-cpp/include/spine/SpineRTTI.h b/spine-cpp/spine-cpp/include/spine/SpineRTTI.h index 9cf985ae8..4ed9806bc 100644 --- a/spine-cpp/spine-cpp/include/spine/SpineRTTI.h +++ b/spine-cpp/spine-cpp/include/spine/SpineRTTI.h @@ -61,15 +61,15 @@ namespace Spine #define SPINE_RTTI_DECL \ public: \ static const Spine::SPINE_RTTI rtti; \ -virtual const Spine::SPINE_RTTI& getSPINE_RTTI(); +virtual const Spine::SPINE_RTTI& getRTTI(); #define SPINE_RTTI_IMPL_NOPARENT(name) \ const Spine::SPINE_RTTI name::rtti(#name); \ -const Spine::SPINE_RTTI& name::getSPINE_RTTI() { return rtti; } +const Spine::SPINE_RTTI& name::getRTTI() { return rtti; } #define SPINE_RTTI_IMPL(name,parent) \ const Spine::SPINE_RTTI name::rtti(#name, parent::rtti); \ -const Spine::SPINE_RTTI& name::getSPINE_RTTI() { return rtti; } +const Spine::SPINE_RTTI& name::getRTTI() { return rtti; } #endif /* Spine_SPINE_RTTI_h */ diff --git a/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h b/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h index b53d19d76..6990e1aa3 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h @@ -39,30 +39,31 @@ namespace Spine { SPINE_RTTI_DECL; + public: + static const int ENTRIES; + 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; -// -// internal int transformConstraintIndex; + private: + static const int PREV_TIME, PREV_ROTATE, PREV_TRANSLATE, PREV_SCALE, PREV_SHEAR; + static const int ROTATE, TRANSLATE, SCALE, SHEAR; + + int _transformConstraintIndex; + // internal float[] frames; // // public int TransformConstraintIndex { return transformConstraintIndex; } set { transformConstraintIndex = inValue; } // public float[] Frames { return frames; } set { frames = inValue; } // time, rotate mix, translate mix, scale mix, shear mix, ... // -// override public int PropertyId { -// get { return ((int)TimelineType.TransformConstraint << 24) + transformConstraintIndex; } -// } // // public TransformConstraintTimeline (int frameCount) // : base(frameCount) { // frames = new float[frameCount * ENTRIES]; // } // -// public void SetFrame (int frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix) { +// public void setFrame (int frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix) { // frameIndex *= ENTRIES; // frames[frameIndex] = time; // frames[frameIndex + ROTATE] = rotateMix; diff --git a/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h b/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h index 40a5e191c..cd48f40b4 100644 --- a/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h @@ -42,24 +42,23 @@ namespace Spine { SPINE_RTTI_DECL; + public: virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); virtual int getPropertyId(); + protected: + int _boneIndex; + // public const int ENTRIES = 3; // protected const int PREV_TIME = -3, PREV_X = -2, PREV_Y = -1; // protected const int X = 1, Y = 2; // -// internal int boneIndex; // internal float[] frames; // // public int getBoneIndex { return boneIndex; } set { boneIndex = inValue; } // public Vector getFrames { return frames; } set { frames = inValue; } // time, value, value, ... // -// virtual int getPropertyId() -// { -// return ((int)TimelineType_Translate << 24) + boneIndex; -// } // // public TranslateTimeline(int frameCount) : CurveTimeline(frameCount) // { diff --git a/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h b/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h index c855f0586..df61adeb9 100644 --- a/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h @@ -39,10 +39,14 @@ namespace Spine { SPINE_RTTI_DECL; + public: virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction); virtual int getPropertyId(); + private: + int _slotIndex; + // 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; @@ -51,7 +55,6 @@ namespace Spine // internal float[] frames; // time, r, g, b, a, r2, g2, b2, ... // public float[] Frames { return frames; } // -// internal int slotIndex; // public int SlotIndex { // get { return slotIndex; } // set { @@ -60,9 +63,6 @@ namespace Spine // } // } // -// override public int PropertyId { -// get { return ((int)TimelineType.TwoColor << 24) + slotIndex; } -// } // // public TwoColorTimeline (int frameCount) : // base(frameCount) { @@ -70,7 +70,7 @@ namespace Spine // } // // /// Sets the time and value of the specified keyframe. -// public void SetFrame (int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2) { +// public void setFrame (int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2) { // frameIndex *= ENTRIES; // frames[frameIndex] = time; // frames[frameIndex + R] = r; diff --git a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h index 7c7841bd0..935601df3 100644 --- a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h @@ -44,6 +44,8 @@ namespace Spine { SPINE_RTTI_DECL; + friend class DeformTimeline; + public: VertexAttachment(std::string name); diff --git a/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp b/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp index 5535f0242..0fe3f9114 100644 --- a/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp @@ -42,7 +42,7 @@ namespace Spine { SPINE_RTTI_IMPL(AttachmentTimeline, Timeline); - AttachmentTimeline::AttachmentTimeline(int frameCount) + AttachmentTimeline::AttachmentTimeline(int frameCount) : Timeline(), _slotIndex(0) { _frames.reserve(frameCount); _attachmentNames.reserve(frameCount); diff --git a/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp index 13d425d27..6968fbe75 100644 --- a/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp @@ -53,7 +53,7 @@ namespace Spine const int ColorTimeline::B = 3; const int ColorTimeline::A = 4; - ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount) + ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0) { _frames.reserve(frameCount * ENTRIES); } diff --git a/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp b/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp index 34a3c487b..b9fb2c5ef 100644 --- a/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp @@ -33,6 +33,8 @@ #include #include +#include + #include #include #include @@ -42,13 +44,225 @@ namespace Spine { SPINE_RTTI_IMPL(DeformTimeline, CurveTimeline); + DeformTimeline::DeformTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0), _attachment(NULL) + { + _frames.reserve(frameCount); + _frameVertices.reserve(frameCount); + } + void DeformTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) { - // TODO + Slot* slotP = skeleton._slots[_slotIndex]; + Slot& slot = *slotP; + + if (slot._attachment == NULL || !slot._attachment->getRTTI().derivesFrom(VertexAttachment::rtti)) + { + return; + } + + VertexAttachment* vertexAttachment = static_cast(slot._attachment); + if (!vertexAttachment->applyDeform(_attachment)) + { + return; + } + + Vector& vertices = slot._attachmentVertices; + if (vertices.size() == 0) + { + alpha = 1; + } + + int vertexCount = static_cast(_frameVertices[0].size()); + + if (time < _frames[0]) + { + switch (pose) + { + case MixPose_Setup: + vertices.clear(); + return; + case MixPose_Current: + if (alpha == 1) + { + vertices.clear(); + return; + } + + // Ensure size and preemptively set count. + vertices.reserve(vertexCount); + + if (vertexAttachment->_bones.size() == 0) + { + // Unweighted vertex positions. + Vector& setupVertices = vertexAttachment->_vertices; + for (int i = 0; i < vertexCount; ++i) + { + vertices[i] += (setupVertices[i] - vertices[i]) * alpha; + } + } + else + { + // Weighted deform offsets. + alpha = 1 - alpha; + for (int i = 0; i < vertexCount; ++i) + { + vertices[i] *= alpha; + } + } + return; + default: + return; + } + } + + // Ensure size and preemptively set count. + vertices.reserve(vertexCount); + + if (time >= _frames[_frames.size() - 1]) + { + // Time is after last frame. + Vector& lastVertices = _frameVertices[_frames.size() - 1]; + if (alpha == 1) + { + // Vertex positions or deform offsets, no alpha. + vertices.clear(); + for (int i = 0; i < vertexCount; ++i) + { + float vertex = lastVertices[i]; + vertices.push_back(vertex); + } + } + else if (pose == MixPose_Setup) + { + if (vertexAttachment->_bones.size() == 0) + { + // Unweighted vertex positions, with alpha. + Vector& setupVertices = vertexAttachment->_vertices; + for (int i = 0; i < vertexCount; i++) + { + float setup = setupVertices[i]; + vertices[i] = setup + (lastVertices[i] - setup) * alpha; + } + } + else + { + // Weighted deform offsets, with alpha. + for (int i = 0; i < vertexCount; ++i) + { + vertices[i] = lastVertices[i] * alpha; + } + } + } + else + { + // Vertex positions or deform offsets, with alpha. + for (int i = 0; i < vertexCount; ++i) + { + vertices[i] += (lastVertices[i] - vertices[i]) * alpha; + } + } + return; + } + + // Interpolate between the previous frame and the current frame. + int frame = Animation::binarySearch(_frames, time); + Vector& prevVertices = _frameVertices[frame - 1]; + Vector& nextVertices = _frameVertices[frame]; + float frameTime = _frames[frame]; + float percent = getCurvePercent(frame - 1, 1 - (time - frameTime) / (_frames[frame - 1] - frameTime)); + + if (alpha == 1) + { + // Vertex positions or deform offsets, no alpha. + for (int i = 0; i < vertexCount; ++i) + { + float prev = prevVertices[i]; + vertices[i] = prev + (nextVertices[i] - prev) * percent; + } + } + else if (pose == MixPose_Setup) + { + if (vertexAttachment->_bones.size() == 0) + { + // Unweighted vertex positions, with alpha. + Vector& setupVertices = vertexAttachment->_vertices; + for (int i = 0; i < vertexCount; ++i) + { + float prev = prevVertices[i], setup = setupVertices[i]; + vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; + } + } + else + { + // Weighted deform offsets, with alpha. + for (int i = 0; i < vertexCount; ++i) + { + float prev = prevVertices[i]; + vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; + } + } + } + else + { + // Vertex positions or deform offsets, with alpha. + for (int i = 0; i < vertexCount; ++i) + { + float prev = prevVertices[i]; + vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha; + } + } } int DeformTimeline::getPropertyId() { - return 0; + assert(_attachment != NULL); + + return ((int)TimelineType_Deform << 24) + _attachment->_id + _slotIndex; + } + + void DeformTimeline::setFrame(int frameIndex, float time, Vector& vertices) + { + _frames[frameIndex] = time; + _frameVertices[frameIndex] = vertices; + } + + int DeformTimeline::getSlotIndex() + { + return _slotIndex; + } + + void DeformTimeline::setSlotIndex(int inValue) + { + _slotIndex = inValue; + } + + Vector& DeformTimeline::getFrames() + { + return _frames; + } + + void DeformTimeline::setFrames(Vector& inValue) + { + _frames = inValue; + } + + Vector< Vector >& DeformTimeline::getVertices() + { + return _frameVertices; + } + + void DeformTimeline::setVertices(Vector< Vector >& inValue) + { + _frameVertices = inValue; + } + + VertexAttachment* DeformTimeline::getAttachment() + { + return _attachment; + } + + void DeformTimeline::setAttachment(VertexAttachment* inValue) + { + _attachment = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp b/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp index d8eceb2da..bb84bcdf5 100644 --- a/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp @@ -42,13 +42,103 @@ namespace Spine { SPINE_RTTI_IMPL(DrawOrderTimeline, Timeline); + DrawOrderTimeline::DrawOrderTimeline(int frameCount) : Timeline() + { + _frames.reserve(frameCount); + _drawOrders.reserve(frameCount); + } + void DrawOrderTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) { - // TODO + Vector& drawOrder = skeleton._drawOrder; + Vector& slots = skeleton._slots; + if (direction == MixDirection_Out && pose == MixPose_Setup) + { + drawOrder.clear(); + drawOrder.reserve(slots.size()); + for (int i = 0, n = static_cast(slots.size()); i < n; ++i) + { + drawOrder.push_back(slots[i]); + } + return; + } + + if (time < _frames[0]) + { + if (pose == MixPose_Setup) + { + drawOrder.clear(); + drawOrder.reserve(slots.size()); + for (int i = 0, n = static_cast(slots.size()); i < n; ++i) + { + drawOrder.push_back(slots[i]); + } + } + return; + } + + int frame; + if (time >= _frames[_frames.size() - 1]) + { + // Time is after last frame. + frame = static_cast(_frames.size()) - 1; + } + else + { + frame = Animation::binarySearch(_frames, time) - 1; + } + + Vector& drawOrderToSetupIndex = _drawOrders[frame]; + if (drawOrderToSetupIndex.size() == 0) + { + drawOrder.clear(); + for (int i = 0, n = static_cast(slots.size()); i < n; ++i) + { + drawOrder.push_back(slots[i]); + } + } + else + { + for (int i = 0, n = static_cast(drawOrderToSetupIndex.size()); i < n; ++i) + { + drawOrder[i] = slots[drawOrderToSetupIndex[i]]; + } + } } int DrawOrderTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_DrawOrder << 24); + } + + void DrawOrderTimeline::setFrame(int frameIndex, float time, Vector& drawOrder) + { + _frames[frameIndex] = time; + _drawOrders[frameIndex] = drawOrder; + } + + Vector& DrawOrderTimeline::getFrames() + { + return _frames; + } + + void DrawOrderTimeline::setFrames(Vector& inValue) + { + _frames = inValue; + } + + Vector< Vector >& DrawOrderTimeline::getDrawOrders() + { + return _drawOrders; + } + + void DrawOrderTimeline::setDrawOrders(Vector< Vector >& inValue) + { + _drawOrders = inValue; + } + + int DrawOrderTimeline::getFrameCount() + { + return static_cast(_frames.size()); } } diff --git a/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp b/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp index 7d1b0bb9f..bcd78be19 100644 --- a/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp @@ -49,6 +49,6 @@ namespace Spine int EventTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_Event << 24); } } diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp index 71c49bc1f..a2886f8f3 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp @@ -42,6 +42,18 @@ namespace Spine { SPINE_RTTI_IMPL(IkConstraintTimeline, CurveTimeline); + const int IkConstraintTimeline::ENTRIES = 3; + const int IkConstraintTimeline::PREV_TIME = -3; + const int IkConstraintTimeline::PREV_MIX = -2; + const int IkConstraintTimeline::PREV_BEND_DIRECTION = -1; + const int IkConstraintTimeline::MIX = 1; + const int IkConstraintTimeline::BEND_DIRECTION = 2; + + IkConstraintTimeline::IkConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _ikConstraintIndex(0) + { + _frames.reserve(frameCount * ENTRIES); + } + void IkConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) { // TODO @@ -49,6 +61,6 @@ namespace Spine int IkConstraintTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_IkConstraint << 24) + _ikConstraintIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp index c44a495ba..7dbef8438 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp @@ -79,7 +79,7 @@ namespace Spine void PathConstraint::update() { Attachment* baseAttachment = _target->getAttachment(); - if (baseAttachment == NULL || !baseAttachment->getSPINE_RTTI().derivesFrom(PathAttachment::rtti)) + if (baseAttachment == NULL || !baseAttachment->getRTTI().derivesFrom(PathAttachment::rtti)) { return; } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp index 60cc7923c..65c4c2998 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp @@ -49,6 +49,6 @@ namespace Spine int PathConstraintMixTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_PathConstraintMix << 24) + _pathConstraintIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp index ec680b528..4e6f70d66 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp @@ -42,6 +42,16 @@ namespace Spine { SPINE_RTTI_IMPL(PathConstraintPositionTimeline, CurveTimeline); + const int PathConstraintPositionTimeline::ENTRIES = 2; + const int PathConstraintPositionTimeline::PREV_TIME = -2; + const int PathConstraintPositionTimeline::PREV_VALUE = -1; + const int PathConstraintPositionTimeline::VALUE = 1; + + PathConstraintPositionTimeline::PathConstraintPositionTimeline(int frameCount) : CurveTimeline(frameCount) + { + _frames.reserve(frameCount * ENTRIES); + } + void PathConstraintPositionTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) { // TODO @@ -49,6 +59,6 @@ namespace Spine int PathConstraintPositionTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_PathConstraintPosition << 24) + _pathConstraintIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp index 131b9d9cd..17c5ac2aa 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp @@ -42,6 +42,11 @@ namespace Spine { SPINE_RTTI_IMPL(PathConstraintSpacingTimeline, PathConstraintPositionTimeline); + PathConstraintSpacingTimeline::PathConstraintSpacingTimeline(int frameCount) : PathConstraintPositionTimeline(frameCount) + { + // Empty + } + void PathConstraintSpacingTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) { // TODO @@ -49,6 +54,6 @@ namespace Spine int PathConstraintSpacingTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_PathConstraintSpacing << 24) + _pathConstraintIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp index 84e1401d1..3151759eb 100644 --- a/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp @@ -49,6 +49,6 @@ namespace Spine int ScaleTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_Scale << 24) + _boneIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp index 04b8ad8e8..132967ea8 100644 --- a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp @@ -49,6 +49,6 @@ namespace Spine int ShearTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_Shear << 24) + _boneIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp index b295f83d7..0221175f8 100644 --- a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp @@ -484,7 +484,7 @@ namespace Spine int verticesLength = 0; Attachment* attachment = slot->getAttachment(); - if (attachment != NULL && attachment->getSPINE_RTTI().derivesFrom(RegionAttachment::rtti)) + if (attachment != NULL && attachment->getRTTI().derivesFrom(RegionAttachment::rtti)) { RegionAttachment* regionAttachment = static_cast(attachment); @@ -495,7 +495,7 @@ namespace Spine } regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0); } - else if (attachment != NULL && attachment->getSPINE_RTTI().derivesFrom(MeshAttachment::rtti)) + else if (attachment != NULL && attachment->getRTTI().derivesFrom(MeshAttachment::rtti)) { MeshAttachment* mesh = static_cast(attachment); @@ -712,7 +712,7 @@ namespace Spine } Attachment* attachment = slot->_attachment; - if (attachment != NULL && attachment->getSPINE_RTTI().derivesFrom(PathAttachment::rtti)) + if (attachment != NULL && attachment->getRTTI().derivesFrom(PathAttachment::rtti)) { sortPathConstraintAttachment(attachment, slotBone); } @@ -793,7 +793,7 @@ namespace Spine void Skeleton::sortPathConstraintAttachment(Attachment* attachment, Bone& slotBone) { - if (attachment == NULL || attachment->getSPINE_RTTI().derivesFrom(PathAttachment::rtti)) + if (attachment == NULL || attachment->getRTTI().derivesFrom(PathAttachment::rtti)) { return; } diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp index 578734cb8..33335732f 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp @@ -42,6 +42,17 @@ namespace Spine { SPINE_RTTI_IMPL(TransformConstraintTimeline, CurveTimeline); + const int TransformConstraintTimeline::ENTRIES = 5; + const int TransformConstraintTimeline::PREV_TIME = -5; + const int TransformConstraintTimeline::PREV_ROTATE = -4; + const int TransformConstraintTimeline::PREV_TRANSLATE = -3; + const int TransformConstraintTimeline::PREV_SCALE = -2; + const int TransformConstraintTimeline::PREV_SHEAR = -1; + const int TransformConstraintTimeline::ROTATE = 1; + const int TransformConstraintTimeline::TRANSLATE = 2; + const int TransformConstraintTimeline::SCALE = 3; + const int TransformConstraintTimeline::SHEAR = 4; + void TransformConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) { // TODO @@ -49,6 +60,6 @@ namespace Spine int TransformConstraintTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_TransformConstraint << 24) + _transformConstraintIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp index 34d8b1b14..05afdad26 100644 --- a/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp @@ -49,6 +49,6 @@ namespace Spine int TranslateTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_Translate << 24) + _boneIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp index afd005f6e..1062f481a 100644 --- a/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp @@ -49,6 +49,6 @@ namespace Spine int TwoColorTimeline::getPropertyId() { - return 0; + return ((int)TimelineType_TwoColor << 24) + _slotIndex; } }