The power of commenting stuff out!

This commit is contained in:
Stephen Gowen 2017-11-16 14:02:39 -05:00
parent 949eb15944
commit c4b7df2c2c
19 changed files with 1167 additions and 1162 deletions

View File

@ -59,22 +59,22 @@ namespace Spine
/// Sets a mix duration when changing from the specified animation to the other. /// Sets a mix duration when changing from the specified animation to the other.
/// See TrackEntry.MixDuration. /// See TrackEntry.MixDuration.
void setMix(Animation& from, Animation& to, float duration); void setMix(Animation* from, Animation* to, float duration);
/// ///
/// The mix duration to use when changing from the specified animation to the other, /// The mix duration to use when changing from the specified animation to the other,
/// or the DefaultMix if no mix duration has been set. /// or the DefaultMix if no mix duration has been set.
/// ///
float getMix(Animation& from, Animation& to); float getMix(Animation* from, Animation* to);
private: private:
class AnimationPair class AnimationPair
{ {
public: public:
Animation& _a1; Animation* _a1;
Animation& _a2; Animation* _a2;
AnimationPair(Animation& a1, Animation& a2); AnimationPair(Animation* a1 = NULL, Animation* a2 = NULL);
bool operator==(const AnimationPair &other) const; bool operator==(const AnimationPair &other) const;
}; };

View File

@ -53,83 +53,83 @@ namespace Spine
// Empty // Empty
} }
RegionAttachment newRegionAttachment(Skin skin, std::string name, std::string path) // RegionAttachment newRegionAttachment(Skin skin, std::string name, std::string path)
{ // {
AtlasRegion* region = findRegion(path); // AtlasRegion* region = findRegion(path);
if (region == NULL) throw new ArgumentException(std::string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name)); // if (region == NULL) throw new ArgumentException(std::string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name));
RegionAttachment attachment = new RegionAttachment(name); // RegionAttachment attachment = new RegionAttachment(name);
attachment.RendererObject = region; // attachment.RendererObject = region;
attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate); // attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
attachment.regionOffsetX = region.offsetX; // attachment.regionOffsetX = region.offsetX;
attachment.regionOffsetY = region.offsetY; // attachment.regionOffsetY = region.offsetY;
attachment.regionWidth = region.width; // attachment.regionWidth = region.width;
attachment.regionHeight = region.height; // attachment.regionHeight = region.height;
attachment.regionOriginalWidth = region.originalWidth; // attachment.regionOriginalWidth = region.originalWidth;
attachment.regionOriginalHeight = region.originalHeight; // attachment.regionOriginalHeight = region.originalHeight;
return attachment; // return attachment;
} // }
//
MeshAttachment newMeshAttachment(Skin skin, std::string name, std::string path) // MeshAttachment newMeshAttachment(Skin skin, std::string name, std::string path)
{ // {
AtlasRegion region = findRegion(path); // AtlasRegion region = findRegion(path);
if (region == NULL) throw new ArgumentException(std::string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name)); // if (region == NULL) throw new ArgumentException(std::string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name));
//
MeshAttachment attachment = new MeshAttachment(name); // MeshAttachment attachment = new MeshAttachment(name);
attachment.RendererObject = region; // attachment.RendererObject = region;
attachment.RegionU = region.u; // attachment.RegionU = region.u;
attachment.RegionV = region.v; // attachment.RegionV = region.v;
attachment.RegionU2 = region.u2; // attachment.RegionU2 = region.u2;
attachment.RegionV2 = region.v2; // attachment.RegionV2 = region.v2;
attachment.RegionRotate = region.rotate; // attachment.RegionRotate = region.rotate;
attachment.regionOffsetX = region.offsetX; // attachment.regionOffsetX = region.offsetX;
attachment.regionOffsetY = region.offsetY; // attachment.regionOffsetY = region.offsetY;
attachment.regionWidth = region.width; // attachment.regionWidth = region.width;
attachment.regionHeight = region.height; // attachment.regionHeight = region.height;
attachment.regionOriginalWidth = region.originalWidth; // attachment.regionOriginalWidth = region.originalWidth;
attachment.regionOriginalHeight = region.originalHeight; // attachment.regionOriginalHeight = region.originalHeight;
//
return attachment; // return attachment;
} // }
//
BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, std::string name) // BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, std::string name)
{ // {
return new BoundingBoxAttachment(name); // return new BoundingBoxAttachment(name);
} // }
//
PathAttachment newPathAttachment(Skin skin, std::string name) // PathAttachment newPathAttachment(Skin skin, std::string name)
{ // {
return new PathAttachment(name); // return new PathAttachment(name);
} // }
//
PointAttachment newPointAttachment(Skin skin, std::string name) // PointAttachment newPointAttachment(Skin skin, std::string name)
{ // {
return new PointAttachment(name); // return new PointAttachment(name);
} // }
//
ClippingAttachment newClippingAttachment(Skin skin, std::string name) // ClippingAttachment newClippingAttachment(Skin skin, std::string name)
{ // {
return new ClippingAttachment(name); // return new ClippingAttachment(name);
} // }
//
AtlasRegion* findRegion(std::string name) // AtlasRegion* findRegion(std::string name)
{ // {
AtlasRegion* ret; // AtlasRegion* ret;
//
for (int i = 0; i < _atlasArray.size(); i++) // for (int i = 0; i < _atlasArray.size(); i++)
{ // {
ret = _atlasArray[i]->findRegion(name); // ret = _atlasArray[i]->findRegion(name);
if (ret != NULL) // if (ret != NULL)
{ // {
return ret; // return ret;
} // }
} // }
//
return NULL; // return NULL;
} // }
private: private:
Vector<Atlas*> _atlasArray; Vector<Atlas*> _atlasArray;
} };
} }
#endif /* Spine_AtlasAttachmentLoader_h */ #endif /* Spine_AtlasAttachmentLoader_h */

View File

@ -64,7 +64,7 @@ namespace Spine
virtual PointAttachment* newPointAttachment(Skin& skin, std::string name) = 0; virtual PointAttachment* newPointAttachment(Skin& skin, std::string name) = 0;
virtual ClippingAttachment* newClippingAttachment(Skin& skin, std::string name) = 0; virtual ClippingAttachment* newClippingAttachment(Skin& skin, std::string name) = 0;
} };
} }
#endif /* Spine_AttachmentLoader_h */ #endif /* Spine_AttachmentLoader_h */

View File

@ -55,68 +55,68 @@ namespace Spine
_attachmentNames.reserve(frameCount); _attachmentNames.reserve(frameCount);
} }
virtual int getPropertyId() // virtual int getPropertyId()
{ // {
return ((int)TimelineType_Attachment << 24) + slotIndex; // return ((int)TimelineType_Attachment << 24) + slotIndex;
} // }
//
/// Sets the time and value of the specified keyframe. // /// Sets the time and value of the specified keyframe.
void setFrame(int frameIndex, float time, std::string attachmentName) // void setFrame(int frameIndex, float time, std::string attachmentName)
{ // {
frames[frameIndex] = time; // frames[frameIndex] = time;
attachmentNames[frameIndex] = attachmentName; // attachmentNames[frameIndex] = attachmentName;
} // }
//
void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*> firedEvents, float alpha, MixPose pose, MixDirection direction) // void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*> firedEvents, float alpha, MixPose pose, MixDirection direction)
{ // {
std::string attachmentName; // std::string attachmentName;
Slot slot = skeleton.slots.Items[slotIndex]; // Slot slot = skeleton.slots.Items[slotIndex];
if (direction == MixDirection_Out && pose == MixPose_Setup) // if (direction == MixDirection_Out && pose == MixPose_Setup)
{ // {
attachmentName = slot.data.attachmentName; // attachmentName = slot.data.attachmentName;
slot.Attachment = attachmentName == NULL ? NULL : skeleton.getAttachment(slotIndex, attachmentName); // slot.Attachment = attachmentName == NULL ? NULL : skeleton.getAttachment(slotIndex, attachmentName);
return; // return;
} // }
//
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) // if (time < frames[0])
{ // {
// Time is before first frame. // // Time is before first frame.
if (pose == MixPose_Setup) // if (pose == MixPose_Setup)
{ // {
attachmentName = slot.data.attachmentName; // attachmentName = slot.data.attachmentName;
slot.Attachment = attachmentName == NULL ? NULL : skeleton.getAttachment(slotIndex, attachmentName); // slot.Attachment = attachmentName == NULL ? NULL : skeleton.getAttachment(slotIndex, attachmentName);
} // }
return; // return;
} // }
//
int frameIndex; // int frameIndex;
if (time >= frames[frames.Length - 1]) // Time is after last frame. // if (time >= frames[frames.Length - 1]) // Time is after last frame.
{ // {
frameIndex = frames.Length - 1; // frameIndex = frames.Length - 1;
} // }
else // else
{ // {
frameIndex = Animation::binarySearch(frames, time, 1) - 1; // frameIndex = Animation::binarySearch(frames, time, 1) - 1;
} // }
//
attachmentName = attachmentNames[frameIndex]; // attachmentName = attachmentNames[frameIndex];
slot.Attachment = attachmentName == NULL ? NULL : skeleton.getAttachment(slotIndex, attachmentName); // slot.Attachment = attachmentName == NULL ? NULL : skeleton.getAttachment(slotIndex, attachmentName);
} // }
//
int getSlotIndex() { return _slotIndex; } // int getSlotIndex() { return _slotIndex; }
void setSlotIndex(int inValue) { _slotIndex = inValue; } // void setSlotIndex(int inValue) { _slotIndex = inValue; }
Vector<float>& getFrames() { return _frames; } // Vector<float>& getFrames() { return _frames; }
void setFrames(Vector<float>& inValue) { _frames = inValue; } // time, ... // void setFrames(Vector<float>& inValue) { _frames = inValue; } // time, ...
Vector<std::string> getAttachmentNames() { return _attachmentNames; } // Vector<std::string> getAttachmentNames() { return _attachmentNames; }
set { attachmentNames = inValue; } // set { attachmentNames = inValue; }
int getFrameCount() { return frames.Length; } // int getFrameCount() { return frames.Length; }
private: private:
int _slotIndex; int _slotIndex;
Vector<float> _frames; Vector<float> _frames;
Vector<std::string> _attachmentNames; Vector<std::string> _attachmentNames;
} };
} }
#endif /* Spine_AttachmentTimeline_h */ #endif /* Spine_AttachmentTimeline_h */

View File

@ -39,105 +39,105 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
public const int ENTRIES = 5; // 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 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; // protected const int R = 1, G = 2, B = 3, A = 4;
//
internal int slotIndex; // internal int slotIndex;
internal float[] frames; // internal float[] frames;
//
public int SlotIndex { return slotIndex; } set { slotIndex = inValue; } // public int SlotIndex { return slotIndex; } set { slotIndex = inValue; }
public float[] Frames { return frames; } set { frames = inValue; } // time, r, g, b, a, ... // public float[] Frames { return frames; } set { frames = inValue; } // time, r, g, b, a, ...
//
override public int PropertyId { // override public int PropertyId {
get { return ((int)TimelineType.Color << 24) + slotIndex; } // get { return ((int)TimelineType.Color << 24) + slotIndex; }
} // }
//
public ColorTimeline (int frameCount) // public ColorTimeline (int frameCount)
: base(frameCount) { // : base(frameCount) {
frames = new float[frameCount * ENTRIES]; // frames = new float[frameCount * ENTRIES];
} // }
//
/// Sets the time and value of the specified keyframe. // /// Sets the time and value of the specified keyframe.
public void SetFrame (int frameIndex, float time, float r, float g, float b, float a) { // public void SetFrame (int frameIndex, float time, float r, float g, float b, float a) {
frameIndex *= ENTRIES; // frameIndex *= ENTRIES;
frames[frameIndex] = time; // frames[frameIndex] = time;
frames[frameIndex + R] = r; // frames[frameIndex + R] = r;
frames[frameIndex + G] = g; // frames[frameIndex + G] = g;
frames[frameIndex + B] = b; // frames[frameIndex + B] = b;
frames[frameIndex + A] = a; // frames[frameIndex + A] = a;
} // }
//
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
Slot slot = skeleton.slots.Items[slotIndex]; // Slot slot = skeleton.slots.Items[slotIndex];
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) { // if (time < frames[0]) {
var slotData = slot.data; // var slotData = slot.data;
switch (pose) { // switch (pose) {
case MixPose_Setup: // case MixPose_Setup:
slot.r = slotData.r; // slot.r = slotData.r;
slot.g = slotData.g; // slot.g = slotData.g;
slot.b = slotData.b; // slot.b = slotData.b;
slot.a = slotData.a; // slot.a = slotData.a;
return; // return;
case MixPose_Current: // case MixPose_Current:
slot.r += (slot.r - slotData.r) * alpha; // slot.r += (slot.r - slotData.r) * alpha;
slot.g += (slot.g - slotData.g) * alpha; // slot.g += (slot.g - slotData.g) * alpha;
slot.b += (slot.b - slotData.b) * alpha; // slot.b += (slot.b - slotData.b) * alpha;
slot.a += (slot.a - slotData.a) * alpha; // slot.a += (slot.a - slotData.a) * alpha;
return; // return;
} // }
return; // return;
} // }
//
float r, g, b, a; // float r, g, b, a;
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame. // if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
int i = frames.Length; // int i = frames.Length;
r = frames[i + PREV_R]; // r = frames[i + PREV_R];
g = frames[i + PREV_G]; // g = frames[i + PREV_G];
b = frames[i + PREV_B]; // b = frames[i + PREV_B];
a = frames[i + PREV_A]; // a = frames[i + PREV_A];
} else { // } else {
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES); // int frame = Animation.BinarySearch(frames, time, ENTRIES);
r = frames[frame + PREV_R]; // r = frames[frame + PREV_R];
g = frames[frame + PREV_G]; // g = frames[frame + PREV_G];
b = frames[frame + PREV_B]; // b = frames[frame + PREV_B];
a = frames[frame + PREV_A]; // a = frames[frame + PREV_A];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, // float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
r += (frames[frame + R] - r) * percent; // r += (frames[frame + R] - r) * percent;
g += (frames[frame + G] - g) * percent; // g += (frames[frame + G] - g) * percent;
b += (frames[frame + B] - b) * percent; // b += (frames[frame + B] - b) * percent;
a += (frames[frame + A] - a) * percent; // a += (frames[frame + A] - a) * percent;
} // }
if (alpha == 1) { // if (alpha == 1) {
slot.r = r; // slot.r = r;
slot.g = g; // slot.g = g;
slot.b = b; // slot.b = b;
slot.a = a; // slot.a = a;
} else { // } else {
float br, bg, bb, ba; // float br, bg, bb, ba;
if (pose == MixPose_Setup) { // if (pose == MixPose_Setup) {
br = slot.data.r; // br = slot.data.r;
bg = slot.data.g; // bg = slot.data.g;
bb = slot.data.b; // bb = slot.data.b;
ba = slot.data.a; // ba = slot.data.a;
} else { // } else {
br = slot.r; // br = slot.r;
bg = slot.g; // bg = slot.g;
bb = slot.b; // bb = slot.b;
ba = slot.a; // ba = slot.a;
} // }
slot.r = br + ((r - br) * alpha); // slot.r = br + ((r - br) * alpha);
slot.g = bg + ((g - bg) * alpha); // slot.g = bg + ((g - bg) * alpha);
slot.b = bb + ((b - bb) * alpha); // slot.b = bb + ((b - bb) * alpha);
slot.a = ba + ((a - ba) * alpha); // slot.a = ba + ((a - ba) * alpha);
} // }
} // }
} };
} }
#endif /* Spine_ColorTimeline_h */ #endif /* Spine_ColorTimeline_h */

View File

@ -39,148 +39,148 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
internal int slotIndex; // internal int slotIndex;
internal float[] frames; // internal float[] frames;
internal float[][] frameVertices; // internal float[][] frameVertices;
internal VertexAttachment attachment; // internal VertexAttachment attachment;
//
public int SlotIndex { return slotIndex; } set { slotIndex = inValue; } // public int SlotIndex { return slotIndex; } set { slotIndex = inValue; }
public float[] Frames { return frames; } set { frames = inValue; } // time, ... // public float[] Frames { return frames; } set { frames = inValue; } // time, ...
public float[][] Vertices { return frameVertices; } set { frameVertices = inValue; } // public float[][] Vertices { return frameVertices; } set { frameVertices = inValue; }
public VertexAttachment Attachment { return attachment; } set { attachment = inValue; } // public VertexAttachment Attachment { return attachment; } set { attachment = inValue; }
//
override public int PropertyId { // override public int PropertyId {
get { return ((int)TimelineType.Deform << 24) + attachment.id + slotIndex; } // get { return ((int)TimelineType.Deform << 24) + attachment.id + slotIndex; }
} // }
//
public DeformTimeline (int frameCount) // public DeformTimeline (int frameCount)
: base(frameCount) { // : base(frameCount) {
frames = new float[frameCount]; // frames = new float[frameCount];
frameVertices = new float[frameCount][]; // frameVertices = new float[frameCount][];
} // }
//
/// Sets the time and value of the specified keyframe. // /// Sets the time and value of the specified keyframe.
public void SetFrame (int frameIndex, float time, float[] vertices) { // public void SetFrame (int frameIndex, float time, float[] vertices) {
frames[frameIndex] = time; // frames[frameIndex] = time;
frameVertices[frameIndex] = vertices; // frameVertices[frameIndex] = vertices;
} // }
//
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
Slot slot = skeleton.slots.Items[slotIndex]; // Slot slot = skeleton.slots.Items[slotIndex];
VertexAttachment vertexAttachment = slot.attachment as VertexAttachment; // VertexAttachment vertexAttachment = slot.attachment as VertexAttachment;
if (vertexAttachment == NULL || !vertexAttachment.ApplyDeform(attachment)) return; // if (vertexAttachment == NULL || !vertexAttachment.ApplyDeform(attachment)) return;
//
var verticesArray = slot.attachmentVertices; // var verticesArray = slot.attachmentVertices;
if (verticesArray.Count == 0) alpha = 1; // if (verticesArray.Count == 0) alpha = 1;
//
float[][] frameVertices = _frameVertices; // float[][] frameVertices = _frameVertices;
int vertexCount = frameVertices[0].Length; // int vertexCount = frameVertices[0].Length;
float[] frames = _frames; // float[] frames = _frames;
float[] vertices; // float[] vertices;
//
if (time < frames[0]) { // if (time < frames[0]) {
//
switch (pose) { // switch (pose) {
case MixPose_Setup: // case MixPose_Setup:
verticesArray.Clear(); // verticesArray.Clear();
return; // return;
case MixPose_Current: // case MixPose_Current:
if (alpha == 1) { // if (alpha == 1) {
verticesArray.Clear(); // verticesArray.Clear();
return; // return;
} // }
//
// verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count. // // verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count.
if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount; // if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount;
verticesArray.Count = vertexCount; // verticesArray.Count = vertexCount;
vertices = verticesArray.Items; // vertices = verticesArray.Items;
//
if (vertexAttachment.bones == NULL) { // if (vertexAttachment.bones == NULL) {
// Unweighted vertex positions. // // Unweighted vertex positions.
float[] setupVertices = vertexAttachment.vertices; // float[] setupVertices = vertexAttachment.vertices;
for (int i = 0; i < vertexCount; i++) // for (int i = 0; i < vertexCount; i++)
vertices[i] += (setupVertices[i] - vertices[i]) * alpha; // vertices[i] += (setupVertices[i] - vertices[i]) * alpha;
} else { // } else {
// Weighted deform offsets. // // Weighted deform offsets.
alpha = 1 - alpha; // alpha = 1 - alpha;
for (int i = 0; i < vertexCount; i++) // for (int i = 0; i < vertexCount; i++)
vertices[i] *= alpha; // vertices[i] *= alpha;
} // }
return; // return;
default: // default:
return; // return;
} // }
//
} // }
//
// verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count. // // verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count.
if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount; // if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount;
verticesArray.Count = vertexCount; // verticesArray.Count = vertexCount;
vertices = verticesArray.Items; // vertices = verticesArray.Items;
//
if (time >= frames[frames.Length - 1]) { // Time is after last frame. // if (time >= frames[frames.Length - 1]) { // Time is after last frame.
float[] lastVertices = frameVertices[frames.Length - 1]; // float[] lastVertices = frameVertices[frames.Length - 1];
if (alpha == 1) { // if (alpha == 1) {
// Vertex positions or deform offsets, no alpha. // // Vertex positions or deform offsets, no alpha.
Array.Copy(lastVertices, 0, vertices, 0, vertexCount); // Array.Copy(lastVertices, 0, vertices, 0, vertexCount);
} else if (pose == MixPose_Setup) { // } else if (pose == MixPose_Setup) {
if (vertexAttachment.bones == NULL) { // if (vertexAttachment.bones == NULL) {
// Unweighted vertex positions, with alpha. // // Unweighted vertex positions, with alpha.
float[] setupVertices = vertexAttachment.vertices; // float[] setupVertices = vertexAttachment.vertices;
for (int i = 0; i < vertexCount; i++) { // for (int i = 0; i < vertexCount; i++) {
float setup = setupVertices[i]; // float setup = setupVertices[i];
vertices[i] = setup + (lastVertices[i] - setup) * alpha; // vertices[i] = setup + (lastVertices[i] - setup) * alpha;
} // }
} else { // } else {
// Weighted deform offsets, with alpha. // // Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) // for (int i = 0; i < vertexCount; i++)
vertices[i] = lastVertices[i] * alpha; // vertices[i] = lastVertices[i] * alpha;
} // }
} else { // } else {
// Vertex positions or deform offsets, with alpha. // // Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) // for (int i = 0; i < vertexCount; i++)
vertices[i] += (lastVertices[i] - vertices[i]) * alpha; // vertices[i] += (lastVertices[i] - vertices[i]) * alpha;
} // }
return; // return;
} // }
//
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time); // int frame = Animation.BinarySearch(frames, time);
float[] prevVertices = frameVertices[frame - 1]; // float[] prevVertices = frameVertices[frame - 1];
float[] nextVertices = frameVertices[frame]; // float[] nextVertices = frameVertices[frame];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime)); // float percent = GetCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
//
if (alpha == 1) { // if (alpha == 1) {
// Vertex positions or deform offsets, no alpha. // // Vertex positions or deform offsets, no alpha.
for (int i = 0; i < vertexCount; i++) { // for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; // float prev = prevVertices[i];
vertices[i] = prev + (nextVertices[i] - prev) * percent; // vertices[i] = prev + (nextVertices[i] - prev) * percent;
} // }
} else if (pose == MixPose_Setup) { // } else if (pose == MixPose_Setup) {
if (vertexAttachment.bones == NULL) { // if (vertexAttachment.bones == NULL) {
// Unweighted vertex positions, with alpha. // // Unweighted vertex positions, with alpha.
var setupVertices = vertexAttachment.vertices; // var setupVertices = vertexAttachment.vertices;
for (int i = 0; i < vertexCount; i++) { // for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i], setup = setupVertices[i]; // float prev = prevVertices[i], setup = setupVertices[i];
vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; // vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
} // }
} else { // } else {
// Weighted deform offsets, with alpha. // // Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) { // for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; // float prev = prevVertices[i];
vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; // vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
} // }
} // }
} else { // } else {
// Vertex positions or deform offsets, with alpha. // // Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) { // for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; // float prev = prevVertices[i];
vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha; // vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
} // }
} // }
} // }
} };
} }
#endif /* Spine_DeformTimeline_h */ #endif /* Spine_DeformTimeline_h */

View File

@ -39,61 +39,61 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
internal float[] frames; // internal float[] frames;
private int[][] drawOrders; // private int[][] drawOrders;
//
public float[] Frames { return frames; } set { frames = inValue; } // time, ... // public float[] Frames { return frames; } set { frames = inValue; } // time, ...
public int[][] DrawOrders { return drawOrders; } set { drawOrders = inValue; } // public int[][] DrawOrders { return drawOrders; } set { drawOrders = inValue; }
public int FrameCount { return frames.Length; } // public int FrameCount { return frames.Length; }
//
public int PropertyId { // public int PropertyId {
get { return ((int)TimelineType.DrawOrder << 24); } // get { return ((int)TimelineType.DrawOrder << 24); }
} // }
//
public DrawOrderTimeline (int frameCount) { // public DrawOrderTimeline (int frameCount) {
frames = new float[frameCount]; // frames = new float[frameCount];
drawOrders = new int[frameCount][]; // drawOrders = new int[frameCount][];
} // }
//
/// Sets the time and value of the specified keyframe. // /// Sets the time and value of the specified keyframe.
/// <param name="drawOrder">May be NULL to use bind pose draw order.</param> // /// <param name="drawOrder">May be NULL to use bind pose draw order.</param>
public void SetFrame (int frameIndex, float time, int[] drawOrder) { // public void SetFrame (int frameIndex, float time, int[] drawOrder) {
frames[frameIndex] = time; // frames[frameIndex] = time;
drawOrders[frameIndex] = drawOrder; // drawOrders[frameIndex] = drawOrder;
} // }
//
public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
Vector<Slot> drawOrder = skeleton.drawOrder; // Vector<Slot> drawOrder = skeleton.drawOrder;
Vector<Slot> slots = skeleton.slots; // Vector<Slot> slots = skeleton.slots;
if (direction == MixDirection_Out && pose == MixPose_Setup) { // if (direction == MixDirection_Out && pose == MixPose_Setup) {
Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count); // Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count);
return; // return;
} // }
//
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) { // if (time < frames[0]) {
if (pose == MixPose_Setup) Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count); // if (pose == MixPose_Setup) Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count);
return; // return;
} // }
//
int frame; // int frame;
if (time >= frames[frames.Length - 1]) // Time is after last frame. // if (time >= frames[frames.Length - 1]) // Time is after last frame.
frame = frames.Length - 1; // frame = frames.Length - 1;
else // else
frame = Animation.BinarySearch(frames, time) - 1; // frame = Animation.BinarySearch(frames, time) - 1;
//
int[] drawOrderToSetupIndex = drawOrders[frame]; // int[] drawOrderToSetupIndex = drawOrders[frame];
if (drawOrderToSetupIndex == NULL) { // if (drawOrderToSetupIndex == NULL) {
drawOrder.Clear(); // drawOrder.Clear();
for (int i = 0, n = slots.Count; i < n; i++) // for (int i = 0, n = slots.Count; i < n; i++)
drawOrder.Add(slots.Items[i]); // drawOrder.Add(slots.Items[i]);
} else { // } else {
var drawOrderItems = drawOrder.Items; // var drawOrderItems = drawOrder.Items;
var slotsItems = slots.Items; // var slotsItems = slots.Items;
for (int i = 0, n = drawOrderToSetupIndex.Length; i < n; i++) // for (int i = 0, n = drawOrderToSetupIndex.Length; i < n; i++)
drawOrderItems[i] = slotsItems[drawOrderToSetupIndex[i]]; // drawOrderItems[i] = slotsItems[drawOrderToSetupIndex[i]];
} // }
} // }
}; };
} }

View File

@ -39,55 +39,55 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
internal float[] frames; // internal float[] frames;
private Event[] events; // private Event[] events;
//
public float[] Frames { return frames; } set { frames = inValue; } // time, ... // public float[] Frames { return frames; } set { frames = inValue; } // time, ...
public Event[] Events { return events; } set { events = inValue; } // public Event[] Events { return events; } set { events = inValue; }
public int FrameCount { return frames.Length; } // public int FrameCount { return frames.Length; }
//
public int PropertyId { // public int PropertyId {
get { return ((int)TimelineType.Event << 24); } // get { return ((int)TimelineType.Event << 24); }
} // }
//
public EventTimeline (int frameCount) { // public EventTimeline (int frameCount) {
frames = new float[frameCount]; // frames = new float[frameCount];
events = new Event[frameCount]; // events = new Event[frameCount];
} // }
//
/// Sets the time and value of the specified keyframe. // /// 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; // frames[frameIndex] = e.Time;
events[frameIndex] = e; // events[frameIndex] = e;
} // }
//
/// Fires events for frames &gt; lastTime and &lt;= time. // /// Fires events for frames &gt; lastTime and &lt;= time.
public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
if (firedEvents == NULL) return; // if (firedEvents == NULL) return;
float[] frames = _frames; // float[] frames = _frames;
int frameCount = frames.Length; // int frameCount = frames.Length;
//
if (lastTime > time) { // Fire events after last time for looped animations. // if (lastTime > time) { // Fire events after last time for looped animations.
Apply(skeleton, lastTime, int.MaxValue, firedEvents, alpha, pose, direction); // Apply(skeleton, lastTime, int.MaxValue, firedEvents, alpha, pose, direction);
lastTime = -1f; // lastTime = -1f;
} else if (lastTime >= frames[frameCount - 1]) // Last time is after last frame. // } else if (lastTime >= frames[frameCount - 1]) // Last time is after last frame.
return; // return;
if (time < frames[0]) return; // Time is before first frame. // if (time < frames[0]) return; // Time is before first frame.
//
int frame; // int frame;
if (lastTime < frames[0]) // if (lastTime < frames[0])
frame = 0; // frame = 0;
else { // else {
frame = Animation.BinarySearch(frames, lastTime); // frame = Animation.BinarySearch(frames, lastTime);
float frameTime = frames[frame]; // float frameTime = frames[frame];
while (frame > 0) { // Fire multiple events with the same frame. // while (frame > 0) { // Fire multiple events with the same frame.
if (frames[frame - 1] != frameTime) break; // if (frames[frame - 1] != frameTime) break;
frame--; // frame--;
} // }
} // }
for (; frame < frameCount && time >= frames[frame]; frame++) // for (; frame < frameCount && time >= frames[frame]; frame++)
firedEvents.Add(events[frame]); // firedEvents.Add(events[frame]);
} // }
}; };
} }

View File

@ -39,76 +39,76 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
public const int ENTRIES = 3; // public const int ENTRIES = 3;
private const int PREV_TIME = -3, PREV_MIX = -2, PREV_BEND_DIRECTION = -1; // private const int PREV_TIME = -3, PREV_MIX = -2, PREV_BEND_DIRECTION = -1;
private const int MIX = 1, BEND_DIRECTION = 2; // private const int MIX = 1, BEND_DIRECTION = 2;
//
internal int ikConstraintIndex; // internal int ikConstraintIndex;
internal float[] frames; // internal float[] frames;
//
public int IkConstraintIndex { return ikConstraintIndex; } set { ikConstraintIndex = inValue; } // public int IkConstraintIndex { return ikConstraintIndex; } set { ikConstraintIndex = inValue; }
public float[] Frames { return frames; } set { frames = inValue; } // time, mix, bendDirection, ... // public float[] Frames { return frames; } set { frames = inValue; } // time, mix, bendDirection, ...
//
override public int PropertyId { // override public int PropertyId {
get { return ((int)TimelineType.IkConstraint << 24) + ikConstraintIndex; } // get { return ((int)TimelineType.IkConstraint << 24) + ikConstraintIndex; }
} // }
//
public IkConstraintTimeline (int frameCount) // public IkConstraintTimeline (int frameCount)
: base(frameCount) { // : base(frameCount) {
frames = new float[frameCount * ENTRIES]; // frames = new float[frameCount * ENTRIES];
} // }
//
/// Sets the time, mix and bend direction of the specified keyframe. // /// 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; // frameIndex *= ENTRIES;
frames[frameIndex] = time; // frames[frameIndex] = time;
frames[frameIndex + MIX] = mix; // frames[frameIndex + MIX] = mix;
frames[frameIndex + BEND_DIRECTION] = bendDirection; // frames[frameIndex + BEND_DIRECTION] = bendDirection;
} // }
//
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
IkConstraint constraint = skeleton.ikConstraints.Items[ikConstraintIndex]; // IkConstraint constraint = skeleton.ikConstraints.Items[ikConstraintIndex];
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) { // if (time < frames[0]) {
switch (pose) { // switch (pose) {
case MixPose_Setup: // case MixPose_Setup:
constraint.mix = constraint.data.mix; // constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection; // constraint.bendDirection = constraint.data.bendDirection;
return; // return;
case MixPose_Current: // case MixPose_Current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha; // constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection; // constraint.bendDirection = constraint.data.bendDirection;
return; // return;
} // }
return; // return;
} // }
//
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame. // if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
if (pose == MixPose_Setup) { // if (pose == MixPose_Setup) {
constraint.mix = constraint.data.mix + (frames[frames.Length + PREV_MIX] - constraint.data.mix) * alpha; // constraint.mix = constraint.data.mix + (frames[frames.Length + PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = direction == MixDirection_Out ? constraint.data.bendDirection // constraint.bendDirection = direction == MixDirection_Out ? constraint.data.bendDirection
: (int)frames[frames.Length + PREV_BEND_DIRECTION]; // : (int)frames[frames.Length + PREV_BEND_DIRECTION];
} else { // } else {
constraint.mix += (frames[frames.Length + PREV_MIX] - constraint.mix) * alpha; // constraint.mix += (frames[frames.Length + PREV_MIX] - constraint.mix) * alpha;
if (direction == MixDirection_In) constraint.bendDirection = (int)frames[frames.Length + PREV_BEND_DIRECTION]; // if (direction == MixDirection_In) constraint.bendDirection = (int)frames[frames.Length + PREV_BEND_DIRECTION];
} // }
return; // return;
} // }
//
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES); // int frame = Animation.BinarySearch(frames, time, ENTRIES);
float mix = frames[frame + PREV_MIX]; // float mix = frames[frame + PREV_MIX];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // float percent = GetCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
if (pose == MixPose_Setup) { // if (pose == MixPose_Setup) {
constraint.mix = constraint.data.mix + (mix + (frames[frame + MIX] - mix) * percent - constraint.data.mix) * alpha; // constraint.mix = constraint.data.mix + (mix + (frames[frame + MIX] - mix) * percent - constraint.data.mix) * alpha;
constraint.bendDirection = direction == MixDirection_Out ? constraint.data.bendDirection : (int)frames[frame + PREV_BEND_DIRECTION]; // constraint.bendDirection = direction == MixDirection_Out ? constraint.data.bendDirection : (int)frames[frame + PREV_BEND_DIRECTION];
} else { // } else {
constraint.mix += (mix + (frames[frame + MIX] - mix) * percent - constraint.mix) * alpha; // constraint.mix += (mix + (frames[frame + MIX] - mix) * percent - constraint.mix) * alpha;
if (direction == MixDirection_In) constraint.bendDirection = (int)frames[frame + PREV_BEND_DIRECTION]; // if (direction == MixDirection_In) constraint.bendDirection = (int)frames[frame + PREV_BEND_DIRECTION];
} // }
} // }
}; };
} }

View File

@ -39,76 +39,76 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
public const int ENTRIES = 3; // public const int ENTRIES = 3;
private const int PREV_TIME = -3, PREV_ROTATE = -2, PREV_TRANSLATE = -1; // private const int PREV_TIME = -3, PREV_ROTATE = -2, PREV_TRANSLATE = -1;
private const int ROTATE = 1, TRANSLATE = 2; // private const int ROTATE = 1, TRANSLATE = 2;
//
internal int pathConstraintIndex; // internal int pathConstraintIndex;
internal float[] frames; // internal float[] frames;
//
public int PathConstraintIndex { return pathConstraintIndex; } set { pathConstraintIndex = inValue; } // public int PathConstraintIndex { return pathConstraintIndex; } set { pathConstraintIndex = inValue; }
public float[] Frames { return frames; } set { frames = inValue; } // time, rotate mix, translate mix, ... // public float[] Frames { return frames; } set { frames = inValue; } // time, rotate mix, translate mix, ...
//
override public int PropertyId { // override public int PropertyId {
get { return ((int)TimelineType.PathConstraintMix << 24) + pathConstraintIndex; } // get { return ((int)TimelineType.PathConstraintMix << 24) + pathConstraintIndex; }
} // }
//
public PathConstraintMixTimeline (int frameCount) // public PathConstraintMixTimeline (int frameCount)
: base(frameCount) { // : base(frameCount) {
frames = new float[frameCount * ENTRIES]; // frames = new float[frameCount * ENTRIES];
} // }
//
/// Sets the time and mixes of the specified keyframe. // /// 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; // frameIndex *= ENTRIES;
frames[frameIndex] = time; // frames[frameIndex] = time;
frames[frameIndex + ROTATE] = rotateMix; // frames[frameIndex + ROTATE] = rotateMix;
frames[frameIndex + TRANSLATE] = translateMix; // frames[frameIndex + TRANSLATE] = translateMix;
} // }
//
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex]; // PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex];
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) { // if (time < frames[0]) {
switch (pose) { // switch (pose) {
case MixPose_Setup: // case MixPose_Setup:
constraint.rotateMix = constraint.data.rotateMix; // constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix; // constraint.translateMix = constraint.data.translateMix;
return; // return;
case MixPose_Current: // case MixPose_Current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha; // constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha; // constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
return; // return;
} // }
return; // return;
} // }
//
float rotate, translate; // float rotate, translate;
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame. // if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
rotate = frames[frames.Length + PREV_ROTATE]; // rotate = frames[frames.Length + PREV_ROTATE];
translate = frames[frames.Length + PREV_TRANSLATE]; // translate = frames[frames.Length + PREV_TRANSLATE];
} else { // } else {
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES); // int frame = Animation.BinarySearch(frames, time, ENTRIES);
rotate = frames[frame + PREV_ROTATE]; // rotate = frames[frame + PREV_ROTATE];
translate = frames[frame + PREV_TRANSLATE]; // translate = frames[frame + PREV_TRANSLATE];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, // float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
rotate += (frames[frame + ROTATE] - rotate) * percent; // rotate += (frames[frame + ROTATE] - rotate) * percent;
translate += (frames[frame + TRANSLATE] - translate) * percent; // translate += (frames[frame + TRANSLATE] - translate) * percent;
} // }
//
if (pose == MixPose_Setup) { // if (pose == MixPose_Setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; // constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; // constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} else { // } else {
constraint.rotateMix += (rotate - constraint.rotateMix) * alpha; // constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
constraint.translateMix += (translate - constraint.translateMix) * alpha; // constraint.translateMix += (translate - constraint.translateMix) * alpha;
} // }
} // }
} };
} }
#endif /* Spine_PathConstraintMixTimeline_h */ #endif /* Spine_PathConstraintMixTimeline_h */

View File

@ -37,66 +37,68 @@ namespace Spine
{ {
class PathConstraintPositionTimeline : public CurveTimeline class PathConstraintPositionTimeline : public CurveTimeline
{ {
public const int ENTRIES = 2; RTTI_DECL;
protected const int PREV_TIME = -2, PREV_VALUE = -1;
protected const int VALUE = 1;
internal int pathConstraintIndex; // public const int ENTRIES = 2;
internal float[] frames; // protected const int PREV_TIME = -2, PREV_VALUE = -1;
// protected const int VALUE = 1;
override public int PropertyId { //
get { return ((int)TimelineType.PathConstraintPosition << 24) + pathConstraintIndex; } // internal int pathConstraintIndex;
} // internal float[] frames;
//
public PathConstraintPositionTimeline (int frameCount) // override public int PropertyId {
: base(frameCount) { // get { return ((int)TimelineType.PathConstraintPosition << 24) + pathConstraintIndex; }
frames = new float[frameCount * ENTRIES]; // }
} //
// public PathConstraintPositionTimeline (int frameCount)
public int PathConstraintIndex { return pathConstraintIndex; } set { pathConstraintIndex = inValue; } // : base(frameCount) {
public float[] Frames { return frames; } set { frames = inValue; } // time, position, ... // frames = new float[frameCount * ENTRIES];
// }
/// Sets the time and value of the specified keyframe. //
public void SetFrame (int frameIndex, float time, float value) { // public int PathConstraintIndex { return pathConstraintIndex; } set { pathConstraintIndex = inValue; }
frameIndex *= ENTRIES; // public float[] Frames { return frames; } set { frames = inValue; } // time, position, ...
frames[frameIndex] = time; //
frames[frameIndex + VALUE] = inValue; // /// Sets the time and value of the specified keyframe.
} // public void SetFrame (int frameIndex, float time, float value) {
// frameIndex *= ENTRIES;
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // frames[frameIndex] = time;
PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex]; // frames[frameIndex + VALUE] = inValue;
float[] frames = _frames; // }
if (time < frames[0]) { //
switch (pose) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
case MixPose_Setup: // PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex];
constraint.position = constraint.data.position; // float[] frames = _frames;
return; // if (time < frames[0]) {
case MixPose_Current: // switch (pose) {
constraint.position += (constraint.data.position - constraint.position) * alpha; // case MixPose_Setup:
return; // constraint.position = constraint.data.position;
} // return;
return; // case MixPose_Current:
} // constraint.position += (constraint.data.position - constraint.position) * alpha;
// return;
float position; // }
if (time >= frames[frames.Length - ENTRIES]) // Time is after last frame. // return;
position = frames[frames.Length + PREV_VALUE]; // }
else { //
// Interpolate between the previous frame and the current frame. // float position;
int frame = Animation.BinarySearch(frames, time, ENTRIES); // if (time >= frames[frames.Length - ENTRIES]) // Time is after last frame.
position = frames[frame + PREV_VALUE]; // position = frames[frames.Length + PREV_VALUE];
float frameTime = frames[frame]; // else {
float percent = GetCurvePercent(frame / ENTRIES - 1, // // Interpolate between the previous frame and the current frame.
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // int frame = Animation.BinarySearch(frames, time, ENTRIES);
// position = frames[frame + PREV_VALUE];
position += (frames[frame + VALUE] - position) * percent; // float frameTime = frames[frame];
} // float percent = GetCurvePercent(frame / ENTRIES - 1,
if (pose == MixPose_Setup) // 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; //
else // position += (frames[frame + VALUE] - position) * percent;
constraint.position += (position - constraint.position) * alpha; // }
} // if (pose == MixPose_Setup)
} // constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
// else
// constraint.position += (position - constraint.position) * alpha;
// }
};
} }
#endif /* Spine_PathConstraintPositionTimeline_h */ #endif /* Spine_PathConstraintPositionTimeline_h */

View File

@ -39,49 +39,49 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
override public int PropertyId { // override public int PropertyId {
get { return ((int)TimelineType.PathConstraintSpacing << 24) + pathConstraintIndex; } // get { return ((int)TimelineType.PathConstraintSpacing << 24) + pathConstraintIndex; }
} // }
//
public PathConstraintSpacingTimeline (int frameCount) // public PathConstraintSpacingTimeline (int frameCount)
: base(frameCount) { // : base(frameCount) {
} // }
//
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex]; // PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex];
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) { // if (time < frames[0]) {
switch (pose) { // switch (pose) {
case MixPose_Setup: // case MixPose_Setup:
constraint.spacing = constraint.data.spacing; // constraint.spacing = constraint.data.spacing;
return; // return;
case MixPose_Current: // case MixPose_Current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha; // constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
return; // return;
} // }
return; // return;
} // }
//
float spacing; // float spacing;
if (time >= frames[frames.Length - ENTRIES]) // Time is after last frame. // if (time >= frames[frames.Length - ENTRIES]) // Time is after last frame.
spacing = frames[frames.Length + PREV_VALUE]; // spacing = frames[frames.Length + PREV_VALUE];
else { // else {
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES); // int frame = Animation.BinarySearch(frames, time, ENTRIES);
spacing = frames[frame + PREV_VALUE]; // spacing = frames[frame + PREV_VALUE];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, // float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
spacing += (frames[frame + VALUE] - spacing) * percent; // spacing += (frames[frame + VALUE] - spacing) * percent;
} // }
//
if (pose == MixPose_Setup) // if (pose == MixPose_Setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; // constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else // else
constraint.spacing += (spacing - constraint.spacing) * alpha; // constraint.spacing += (spacing - constraint.spacing) * alpha;
} // }
} };
} }
#endif /* Spine_PathConstraintSpacingTimeline_h */ #endif /* Spine_PathConstraintSpacingTimeline_h */

View File

@ -48,6 +48,7 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
public:
PointAttachment(std::string name); PointAttachment(std::string name);
void computeWorldPosition(Bone& bone, float& ox, float& oy); void computeWorldPosition(Bone& bone, float& ox, float& oy);
@ -65,7 +66,7 @@ namespace Spine
private: private:
float _x, _y, _rotation; float _x, _y, _rotation;
} };
} }
#endif /* Spine_PointAttachment_h */ #endif /* Spine_PointAttachment_h */

View File

@ -39,73 +39,73 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
override public int PropertyId { // override public int PropertyId {
get { return ((int)TimelineType.Scale << 24) + boneIndex; } // get { return ((int)TimelineType.Scale << 24) + boneIndex; }
} // }
//
public ScaleTimeline (int frameCount) // public ScaleTimeline (int frameCount)
: base(frameCount) { // : base(frameCount) {
} // }
//
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
Bone bone = skeleton.bones.Items[boneIndex]; // Bone bone = skeleton.bones.Items[boneIndex];
//
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) { // if (time < frames[0]) {
switch (pose) { // switch (pose) {
case MixPose_Setup: // case MixPose_Setup:
bone.scaleX = bone.data.scaleX; // bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY; // bone.scaleY = bone.data.scaleY;
return; // return;
case MixPose_Current: // case MixPose_Current:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha; // bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha; // bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
return; // return;
} // }
return; // return;
} // }
//
float x, y; // float x, y;
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame. // if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
x = frames[frames.Length + PREV_X] * bone.data.scaleX; // x = frames[frames.Length + PREV_X] * bone.data.scaleX;
y = frames[frames.Length + PREV_Y] * bone.data.scaleY; // y = frames[frames.Length + PREV_Y] * bone.data.scaleY;
} else { // } else {
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES); // int frame = Animation.BinarySearch(frames, time, ENTRIES);
x = frames[frame + PREV_X]; // x = frames[frame + PREV_X];
y = frames[frame + PREV_Y]; // y = frames[frame + PREV_Y];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, // float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
x = (x + (frames[frame + X] - x) * percent) * bone.data.scaleX; // x = (x + (frames[frame + X] - x) * percent) * bone.data.scaleX;
y = (y + (frames[frame + Y] - y) * percent) * bone.data.scaleY; // y = (y + (frames[frame + Y] - y) * percent) * bone.data.scaleY;
} // }
if (alpha == 1) { // if (alpha == 1) {
bone.scaleX = x; // bone.scaleX = x;
bone.scaleY = y; // bone.scaleY = y;
} else { // } else {
float bx, by; // float bx, by;
if (pose == MixPose_Setup) { // if (pose == MixPose_Setup) {
bx = bone.data.scaleX; // bx = bone.data.scaleX;
by = bone.data.scaleY; // by = bone.data.scaleY;
} else { // } else {
bx = bone.scaleX; // bx = bone.scaleX;
by = bone.scaleY; // by = bone.scaleY;
} // }
// Mixing out uses sign of setup or current pose, else use sign of key. // // Mixing out uses sign of setup or current pose, else use sign of key.
if (direction == MixDirection_Out) { // if (direction == MixDirection_Out) {
x = (x >= 0 ? x : -x) * (bx >= 0 ? 1 : -1); // x = (x >= 0 ? x : -x) * (bx >= 0 ? 1 : -1);
y = (y >= 0 ? y : -y) * (by >= 0 ? 1 : -1); // y = (y >= 0 ? y : -y) * (by >= 0 ? 1 : -1);
} else { // } else {
bx = (bx >= 0 ? bx : -bx) * (x >= 0 ? 1 : -1); // bx = (bx >= 0 ? bx : -bx) * (x >= 0 ? 1 : -1);
by = (by >= 0 ? by : -by) * (y >= 0 ? 1 : -1); // by = (by >= 0 ? by : -by) * (y >= 0 ? 1 : -1);
} // }
bone.scaleX = bx + (x - bx) * alpha; // bone.scaleX = bx + (x - bx) * alpha;
bone.scaleY = by + (y - by) * alpha; // bone.scaleY = by + (y - by) * alpha;
} // }
} // }
} };
} }
#endif /* Spine_ScaleTimeline_h */ #endif /* Spine_ScaleTimeline_h */

View File

@ -39,56 +39,56 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
override public int PropertyId { // override public int PropertyId {
get { return ((int)TimelineType.Shear << 24) + boneIndex; } // get { return ((int)TimelineType.Shear << 24) + boneIndex; }
} // }
//
public ShearTimeline (int frameCount) // public ShearTimeline (int frameCount)
: base(frameCount) { // : base(frameCount) {
} // }
//
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
Bone bone = skeleton.bones.Items[boneIndex]; // Bone bone = skeleton.bones.Items[boneIndex];
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) { // if (time < frames[0]) {
switch (pose) { // switch (pose) {
case MixPose_Setup: // case MixPose_Setup:
bone.shearX = bone.data.shearX; // bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY; // bone.shearY = bone.data.shearY;
return; // return;
case MixPose_Current: // case MixPose_Current:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha; // bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha; // bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
return; // return;
} // }
return; // return;
} // }
//
float x, y; // float x, y;
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame. // if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
x = frames[frames.Length + PREV_X]; // x = frames[frames.Length + PREV_X];
y = frames[frames.Length + PREV_Y]; // y = frames[frames.Length + PREV_Y];
} else { // } else {
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES); // int frame = Animation.BinarySearch(frames, time, ENTRIES);
x = frames[frame + PREV_X]; // x = frames[frame + PREV_X];
y = frames[frame + PREV_Y]; // y = frames[frame + PREV_Y];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, // float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
x = x + (frames[frame + X] - x) * percent; // x = x + (frames[frame + X] - x) * percent;
y = y + (frames[frame + Y] - y) * percent; // y = y + (frames[frame + Y] - y) * percent;
} // }
if (pose == MixPose_Setup) { // if (pose == MixPose_Setup) {
bone.shearX = bone.data.shearX + x * alpha; // bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha; // bone.shearY = bone.data.shearY + y * alpha;
} else { // } else {
bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha; // bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha; // bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
} // }
} // }
} };
} }
#endif /* Spine_ShearTimeline_h */ #endif /* Spine_ShearTimeline_h */

View File

@ -39,93 +39,93 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
public const int ENTRIES = 5; // 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 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; // private const int ROTATE = 1, TRANSLATE = 2, SCALE = 3, SHEAR = 4;
//
internal int transformConstraintIndex; // internal int transformConstraintIndex;
internal float[] frames; // internal float[] frames;
//
public int TransformConstraintIndex { return transformConstraintIndex; } set { transformConstraintIndex = inValue; } // 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, ... // public float[] Frames { return frames; } set { frames = inValue; } // time, rotate mix, translate mix, scale mix, shear mix, ...
//
override public int PropertyId { // override public int PropertyId {
get { return ((int)TimelineType.TransformConstraint << 24) + transformConstraintIndex; } // get { return ((int)TimelineType.TransformConstraint << 24) + transformConstraintIndex; }
} // }
//
public TransformConstraintTimeline (int frameCount) // public TransformConstraintTimeline (int frameCount)
: base(frameCount) { // : base(frameCount) {
frames = new float[frameCount * ENTRIES]; // 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; // frameIndex *= ENTRIES;
frames[frameIndex] = time; // frames[frameIndex] = time;
frames[frameIndex + ROTATE] = rotateMix; // frames[frameIndex + ROTATE] = rotateMix;
frames[frameIndex + TRANSLATE] = translateMix; // frames[frameIndex + TRANSLATE] = translateMix;
frames[frameIndex + SCALE] = scaleMix; // frames[frameIndex + SCALE] = scaleMix;
frames[frameIndex + SHEAR] = shearMix; // frames[frameIndex + SHEAR] = shearMix;
} // }
//
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
TransformConstraint constraint = skeleton.transformConstraints.Items[transformConstraintIndex]; // TransformConstraint constraint = skeleton.transformConstraints.Items[transformConstraintIndex];
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) { // if (time < frames[0]) {
var data = constraint.data; // var data = constraint.data;
switch (pose) { // switch (pose) {
case MixPose_Setup: // case MixPose_Setup:
constraint.rotateMix = data.rotateMix; // constraint.rotateMix = data.rotateMix;
constraint.translateMix = data.translateMix; // constraint.translateMix = data.translateMix;
constraint.scaleMix = data.scaleMix; // constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix; // constraint.shearMix = data.shearMix;
return; // return;
case MixPose_Current: // case MixPose_Current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha; // constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha; // constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha; // constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha; // constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
return; // return;
} // }
return; // return;
} // }
//
float rotate, translate, scale, shear; // float rotate, translate, scale, shear;
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame. // if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
int i = frames.Length; // int i = frames.Length;
rotate = frames[i + PREV_ROTATE]; // rotate = frames[i + PREV_ROTATE];
translate = frames[i + PREV_TRANSLATE]; // translate = frames[i + PREV_TRANSLATE];
scale = frames[i + PREV_SCALE]; // scale = frames[i + PREV_SCALE];
shear = frames[i + PREV_SHEAR]; // shear = frames[i + PREV_SHEAR];
} else { // } else {
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES); // int frame = Animation.BinarySearch(frames, time, ENTRIES);
rotate = frames[frame + PREV_ROTATE]; // rotate = frames[frame + PREV_ROTATE];
translate = frames[frame + PREV_TRANSLATE]; // translate = frames[frame + PREV_TRANSLATE];
scale = frames[frame + PREV_SCALE]; // scale = frames[frame + PREV_SCALE];
shear = frames[frame + PREV_SHEAR]; // shear = frames[frame + PREV_SHEAR];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, // float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
rotate += (frames[frame + ROTATE] - rotate) * percent; // rotate += (frames[frame + ROTATE] - rotate) * percent;
translate += (frames[frame + TRANSLATE] - translate) * percent; // translate += (frames[frame + TRANSLATE] - translate) * percent;
scale += (frames[frame + SCALE] - scale) * percent; // scale += (frames[frame + SCALE] - scale) * percent;
shear += (frames[frame + SHEAR] - shear) * percent; // shear += (frames[frame + SHEAR] - shear) * percent;
} // }
if (pose == MixPose_Setup) { // if (pose == MixPose_Setup) {
TransformConstraintData data = constraint.data; // TransformConstraintData data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; // constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; // constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha; // constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha; // constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
} else { // } else {
constraint.rotateMix += (rotate - constraint.rotateMix) * alpha; // constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
constraint.translateMix += (translate - constraint.translateMix) * alpha; // constraint.translateMix += (translate - constraint.translateMix) * alpha;
constraint.scaleMix += (scale - constraint.scaleMix) * alpha; // constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
constraint.shearMix += (shear - constraint.shearMix) * alpha; // constraint.shearMix += (shear - constraint.shearMix) * alpha;
} // }
} // }
} };
} }
#endif /* Spine_TransformConstraintTimeline_h */ #endif /* Spine_TransformConstraintTimeline_h */

View File

@ -42,88 +42,88 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
public const int ENTRIES = 3; // public const int ENTRIES = 3;
protected const int PREV_TIME = -3, PREV_X = -2, PREV_Y = -1; // protected const int PREV_TIME = -3, PREV_X = -2, PREV_Y = -1;
protected const int X = 1, Y = 2; // protected const int X = 1, Y = 2;
//
internal int boneIndex; // internal int boneIndex;
internal float[] frames; // internal float[] frames;
//
public int getBoneIndex { return boneIndex; } set { boneIndex = inValue; } // public int getBoneIndex { return boneIndex; } set { boneIndex = inValue; }
public Vector<float> getFrames { return frames; } set { frames = inValue; } // time, value, value, ... // public Vector<float> getFrames { return frames; } set { frames = inValue; } // time, value, value, ...
//
virtual int getPropertyId() // virtual int getPropertyId()
{ // {
return ((int)TimelineType_Translate << 24) + boneIndex; // return ((int)TimelineType_Translate << 24) + boneIndex;
} // }
//
public TranslateTimeline(int frameCount) : CurveTimeline(frameCount) // public TranslateTimeline(int frameCount) : CurveTimeline(frameCount)
{ // {
frames = new float[frameCount * ENTRIES]; // frames = new float[frameCount * ENTRIES];
} // }
//
/// Sets the time and value of the specified keyframe. // /// Sets the time and value of the specified keyframe.
public void setFrame(int frameIndex, float time, float x, float y) // public void setFrame(int frameIndex, float time, float x, float y)
{ // {
frameIndex *= ENTRIES; // frameIndex *= ENTRIES;
frames[frameIndex] = time; // frames[frameIndex] = time;
frames[frameIndex + X] = x; // frames[frameIndex + X] = x;
frames[frameIndex + Y] = y; // frames[frameIndex + Y] = y;
} // }
//
override public void apply(Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) // override public void apply(Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
{ // {
Bone bone = skeleton.bones.Items[boneIndex]; // Bone bone = skeleton.bones.Items[boneIndex];
//
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) // if (time < frames[0])
{ // {
switch (pose) // switch (pose)
{ // {
case MixPose_Setup: // case MixPose_Setup:
bone.x = bone.data.x; // bone.x = bone.data.x;
bone.y = bone.data.y; // bone.y = bone.data.y;
return; // return;
case MixPose_Current: // case MixPose_Current:
bone.x += (bone.data.x - bone.x) * alpha; // bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha; // bone.y += (bone.data.y - bone.y) * alpha;
return; // return;
} // }
return; // return;
} // }
//
float x, y; // float x, y;
if (time >= frames[frames.Length - ENTRIES]) // if (time >= frames[frames.Length - ENTRIES])
{ // {
// Time is after last frame. // // Time is after last frame.
x = frames[frames.Length + PREV_X]; // x = frames[frames.Length + PREV_X];
y = frames[frames.Length + PREV_Y]; // y = frames[frames.Length + PREV_Y];
} // }
else // else
{ // {
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(frames, time, ENTRIES); // int frame = Animation::binarySearch(frames, time, ENTRIES);
x = frames[frame + PREV_X]; // x = frames[frame + PREV_X];
y = frames[frame + PREV_Y]; // y = frames[frame + PREV_Y];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // float percent = GetCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
x += (frames[frame + X] - x) * percent; // x += (frames[frame + X] - x) * percent;
y += (frames[frame + Y] - y) * percent; // y += (frames[frame + Y] - y) * percent;
} // }
//
if (pose == MixPose_Setup) // if (pose == MixPose_Setup)
{ // {
bone.x = bone.data.x + x * alpha; // bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha; // bone.y = bone.data.y + y * alpha;
} // }
else // else
{ // {
bone.x += (bone.data.x + x - bone.x) * alpha; // bone.x += (bone.data.x + x - bone.x) * alpha;
bone.y += (bone.data.y + y - bone.y) * alpha; // bone.y += (bone.data.y + y - bone.y) * alpha;
} // }
} // }
} };
} }
#endif /* Spine_TranslateTimeline_h */ #endif /* Spine_TranslateTimeline_h */

View File

@ -39,145 +39,144 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
public const int ENTRIES = 8; // 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_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; // protected const int PREV_R2 = -3, PREV_G2 = -2, PREV_B2 = -1;
protected const int R = 1, G = 2, B = 3, A = 4, R2 = 5, G2 = 6, B2 = 7; // protected const int R = 1, G = 2, B = 3, A = 4, R2 = 5, G2 = 6, B2 = 7;
//
internal float[] frames; // time, r, g, b, a, r2, g2, b2, ... // internal float[] frames; // time, r, g, b, a, r2, g2, b2, ...
public float[] Frames { return frames; } // public float[] Frames { return frames; }
//
internal int slotIndex; // internal int slotIndex;
public int SlotIndex { // public int SlotIndex {
get { return slotIndex; } // get { return slotIndex; }
set { // set {
if (value < 0) throw new ArgumentOutOfRangeException("index must be >= 0."); // if (value < 0) throw new ArgumentOutOfRangeException("index must be >= 0.");
slotIndex = inValue; // slotIndex = inValue;
} // }
} // }
//
override public int PropertyId { // override public int PropertyId {
get { return ((int)TimelineType.TwoColor << 24) + slotIndex; } // get { return ((int)TimelineType.TwoColor << 24) + slotIndex; }
} // }
//
public TwoColorTimeline (int frameCount) : // public TwoColorTimeline (int frameCount) :
base(frameCount) { // base(frameCount) {
frames = new float[frameCount * ENTRIES]; // frames = new float[frameCount * ENTRIES];
} // }
//
/// Sets the time and value of the specified keyframe. // /// 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; // frameIndex *= ENTRIES;
frames[frameIndex] = time; // frames[frameIndex] = time;
frames[frameIndex + R] = r; // frames[frameIndex + R] = r;
frames[frameIndex + G] = g; // frames[frameIndex + G] = g;
frames[frameIndex + B] = b; // frames[frameIndex + B] = b;
frames[frameIndex + A] = a; // frames[frameIndex + A] = a;
frames[frameIndex + R2] = r2; // frames[frameIndex + R2] = r2;
frames[frameIndex + G2] = g2; // frames[frameIndex + G2] = g2;
frames[frameIndex + B2] = b2; // frames[frameIndex + B2] = b2;
} // }
//
override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) { // override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
Slot slot = skeleton.slots.Items[slotIndex]; // Slot slot = skeleton.slots.Items[slotIndex];
float[] frames = _frames; // float[] frames = _frames;
if (time < frames[0]) { // Time is before first frame. // if (time < frames[0]) { // Time is before first frame.
var slotData = slot.data; // var slotData = slot.data;
switch (pose) { // switch (pose) {
case MixPose_Setup: // case MixPose_Setup:
// slot.color.set(slot.data.color); // // slot.color.set(slot.data.color);
// slot.darkColor.set(slot.data.darkColor); // // slot.darkColor.set(slot.data.darkColor);
slot.r = slotData.r; // slot.r = slotData.r;
slot.g = slotData.g; // slot.g = slotData.g;
slot.b = slotData.b; // slot.b = slotData.b;
slot.a = slotData.a; // slot.a = slotData.a;
slot.r2 = slotData.r2; // slot.r2 = slotData.r2;
slot.g2 = slotData.g2; // slot.g2 = slotData.g2;
slot.b2 = slotData.b2; // slot.b2 = slotData.b2;
return; // return;
case MixPose_Current: // case MixPose_Current:
slot.r += (slot.r - slotData.r) * alpha; // slot.r += (slot.r - slotData.r) * alpha;
slot.g += (slot.g - slotData.g) * alpha; // slot.g += (slot.g - slotData.g) * alpha;
slot.b += (slot.b - slotData.b) * alpha; // slot.b += (slot.b - slotData.b) * alpha;
slot.a += (slot.a - slotData.a) * alpha; // slot.a += (slot.a - slotData.a) * alpha;
slot.r2 += (slot.r2 - slotData.r2) * alpha; // slot.r2 += (slot.r2 - slotData.r2) * alpha;
slot.g2 += (slot.g2 - slotData.g2) * alpha; // slot.g2 += (slot.g2 - slotData.g2) * alpha;
slot.b2 += (slot.b2 - slotData.b2) * alpha; // slot.b2 += (slot.b2 - slotData.b2) * alpha;
return; // return;
} // }
return; // return;
} // }
//
float r, g, b, a, r2, g2, b2; // float r, g, b, a, r2, g2, b2;
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame. // if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
int i = frames.Length; // int i = frames.Length;
r = frames[i + PREV_R]; // r = frames[i + PREV_R];
g = frames[i + PREV_G]; // g = frames[i + PREV_G];
b = frames[i + PREV_B]; // b = frames[i + PREV_B];
a = frames[i + PREV_A]; // a = frames[i + PREV_A];
r2 = frames[i + PREV_R2]; // r2 = frames[i + PREV_R2];
g2 = frames[i + PREV_G2]; // g2 = frames[i + PREV_G2];
b2 = frames[i + PREV_B2]; // b2 = frames[i + PREV_B2];
} else { // } else {
// Interpolate between the previous frame and the current frame. // // Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES); // int frame = Animation.BinarySearch(frames, time, ENTRIES);
r = frames[frame + PREV_R]; // r = frames[frame + PREV_R];
g = frames[frame + PREV_G]; // g = frames[frame + PREV_G];
b = frames[frame + PREV_B]; // b = frames[frame + PREV_B];
a = frames[frame + PREV_A]; // a = frames[frame + PREV_A];
r2 = frames[frame + PREV_R2]; // r2 = frames[frame + PREV_R2];
g2 = frames[frame + PREV_G2]; // g2 = frames[frame + PREV_G2];
b2 = frames[frame + PREV_B2]; // b2 = frames[frame + PREV_B2];
float frameTime = frames[frame]; // float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, // float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); // 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
r += (frames[frame + R] - r) * percent; // r += (frames[frame + R] - r) * percent;
g += (frames[frame + G] - g) * percent; // g += (frames[frame + G] - g) * percent;
b += (frames[frame + B] - b) * percent; // b += (frames[frame + B] - b) * percent;
a += (frames[frame + A] - a) * percent; // a += (frames[frame + A] - a) * percent;
r2 += (frames[frame + R2] - r2) * percent; // r2 += (frames[frame + R2] - r2) * percent;
g2 += (frames[frame + G2] - g2) * percent; // g2 += (frames[frame + G2] - g2) * percent;
b2 += (frames[frame + B2] - b2) * percent; // b2 += (frames[frame + B2] - b2) * percent;
} // }
if (alpha == 1) { // if (alpha == 1) {
slot.r = r; // slot.r = r;
slot.g = g; // slot.g = g;
slot.b = b; // slot.b = b;
slot.a = a; // slot.a = a;
slot.r2 = r2; // slot.r2 = r2;
slot.g2 = g2; // slot.g2 = g2;
slot.b2 = b2; // slot.b2 = b2;
} else { // } else {
float br, bg, bb, ba, br2, bg2, bb2; // float br, bg, bb, ba, br2, bg2, bb2;
if (pose == MixPose_Setup) { // if (pose == MixPose_Setup) {
br = slot.data.r; // br = slot.data.r;
bg = slot.data.g; // bg = slot.data.g;
bb = slot.data.b; // bb = slot.data.b;
ba = slot.data.a; // ba = slot.data.a;
br2 = slot.data.r2; // br2 = slot.data.r2;
bg2 = slot.data.g2; // bg2 = slot.data.g2;
bb2 = slot.data.b2; // bb2 = slot.data.b2;
} else { // } else {
br = slot.r; // br = slot.r;
bg = slot.g; // bg = slot.g;
bb = slot.b; // bb = slot.b;
ba = slot.a; // ba = slot.a;
br2 = slot.r2; // br2 = slot.r2;
bg2 = slot.g2; // bg2 = slot.g2;
bb2 = slot.b2; // bb2 = slot.b2;
} // }
slot.r = br + ((r - br) * alpha); // slot.r = br + ((r - br) * alpha);
slot.g = bg + ((g - bg) * alpha); // slot.g = bg + ((g - bg) * alpha);
slot.b = bb + ((b - bb) * alpha); // slot.b = bb + ((b - bb) * alpha);
slot.a = ba + ((a - ba) * alpha); // slot.a = ba + ((a - ba) * alpha);
slot.r2 = br2 + ((r2 - br2) * alpha); // slot.r2 = br2 + ((r2 - br2) * alpha);
slot.g2 = bg2 + ((g2 - bg2) * alpha); // slot.g2 = bg2 + ((g2 - bg2) * alpha);
slot.b2 = bb2 + ((b2 - bb2) * alpha); // slot.b2 = bb2 + ((b2 - bb2) * alpha);
} // }
} // }
};
}
} }
#endif /* Spine_TwoColorTimeline_h */ #endif /* Spine_TwoColorTimeline_h */

View File

@ -43,24 +43,27 @@ namespace Spine
void AnimationStateData::setMix(std::string fromName, std::string toName, float duration) void AnimationStateData::setMix(std::string fromName, std::string toName, float duration)
{ {
Animation* from = _skeletonData.findAnimation(fromName); Animation* from = _skeletonData.findAnimation(fromName);
assert(from != NULL);
Animation* to = _skeletonData.findAnimation(toName); Animation* to = _skeletonData.findAnimation(toName);
assert(to != NULL);
setMix(*from, *to, duration); setMix(from, to, duration);
} }
void AnimationStateData::setMix(Animation& from, Animation& to, float duration) void AnimationStateData::setMix(Animation* from, Animation* to, float duration)
{ {
assert(from != NULL);
assert(to != NULL);
AnimationPair key(from, to); AnimationPair key(from, to);
HashMap<AnimationPair, float, HashAnimationPair>::Iterator i = _animationToMixTime.find(key); HashMap<AnimationPair, float, HashAnimationPair>::Iterator i = _animationToMixTime.find(key);
_animationToMixTime.erase(i); _animationToMixTime.erase(i);
_animationToMixTime.insert(key, duration); _animationToMixTime.insert(key, duration);
} }
float AnimationStateData::getMix(Animation& from, Animation& to) float AnimationStateData::getMix(Animation* from, Animation* to)
{ {
assert(from != NULL);
assert(to != NULL);
AnimationPair key(from, to); AnimationPair key(from, to);
HashMap<AnimationPair, float, HashAnimationPair>::Iterator i = _animationToMixTime.find(key); HashMap<AnimationPair, float, HashAnimationPair>::Iterator i = _animationToMixTime.find(key);
@ -88,30 +91,30 @@ namespace Spine
_defaultMix = inValue; _defaultMix = inValue;
} }
AnimationStateData::AnimationPair::AnimationPair(Animation& a1, Animation& a2) : _a1(a1), _a2(a2) AnimationStateData::AnimationPair::AnimationPair(Animation* a1, Animation* a2) : _a1(a1), _a2(a2)
{ {
// Empty // Empty
} }
bool AnimationStateData::AnimationPair::operator==(const AnimationPair &other) const bool AnimationStateData::AnimationPair::operator==(const AnimationPair &other) const
{ {
return _a1._name == other._a1._name && _a2._name == other._a2._name; return _a1->_name == other._a1->_name && _a2->_name == other._a2->_name;
} }
std::size_t AnimationStateData::HashAnimationPair::operator()(const Spine::AnimationStateData::AnimationPair& val) const std::size_t AnimationStateData::HashAnimationPair::operator()(const Spine::AnimationStateData::AnimationPair& val) const
{ {
std::size_t h1 = 7; std::size_t h1 = 7;
size_t strlen = val._a1._name.length(); size_t strlen = val._a1->_name.length();
for (int i = 0; i < strlen; ++i) for (int i = 0; i < strlen; ++i)
{ {
h1 = h1 * 31 + val._a1._name.at(i); h1 = h1 * 31 + val._a1->_name.at(i);
} }
std::size_t h2 = 7; std::size_t h2 = 7;
strlen = val._a2._name.length(); strlen = val._a2->_name.length();
for (int i = 0; i < strlen; ++i) for (int i = 0; i < strlen; ++i)
{ {
h2 = h2 * 31 + val._a2._name.at(i); h2 = h2 * 31 + val._a2->_name.at(i);
} }
return (((h1 << 5) + h1) ^ h2); return (((h1 << 5) + h1) ^ h2);