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.
/// 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,
/// or the DefaultMix if no mix duration has been set.
///
float getMix(Animation& from, Animation& to);
float getMix(Animation* from, Animation* to);
private:
class AnimationPair
{
public:
Animation& _a1;
Animation& _a2;
Animation* _a1;
Animation* _a2;
AnimationPair(Animation& a1, Animation& a2);
AnimationPair(Animation* a1 = NULL, Animation* a2 = NULL);
bool operator==(const AnimationPair &other) const;
};

View File

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

View File

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

View File

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

View File

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

View File

@ -39,148 +39,148 @@ namespace Spine
{
RTTI_DECL;
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<Event> 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;
}
}
}
}
// 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<Event> 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;
// }
// }
// }
};
}
#endif /* Spine_DeformTimeline_h */

View File

@ -39,61 +39,61 @@ namespace Spine
{
RTTI_DECL;
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.
/// <param name="drawOrder">May be NULL to use bind pose draw order.</param>
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<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
Vector<Slot> drawOrder = skeleton.drawOrder;
Vector<Slot> 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]];
}
}
// 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.
// /// <param name="drawOrder">May be NULL to use bind pose draw order.</param>
// 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<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
// Vector<Slot> drawOrder = skeleton.drawOrder;
// Vector<Slot> 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]];
// }
// }
};
}

View File

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

View File

@ -39,76 +39,76 @@ namespace Spine
{
RTTI_DECL;
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;
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) {
frameIndex *= ENTRIES;
frames[frameIndex] = time;
frames[frameIndex + MIX] = mix;
frames[frameIndex + BEND_DIRECTION] = bendDirection;
}
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];
float[] frames = _frames;
if (time < frames[0]) {
switch (pose) {
case MixPose_Setup:
constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection;
return;
case MixPose_Current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection;
return;
}
return;
}
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
if (pose == MixPose_Setup) {
constraint.mix = constraint.data.mix + (frames[frames.Length + PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = direction == MixDirection_Out ? constraint.data.bendDirection
: (int)frames[frames.Length + PREV_BEND_DIRECTION];
} else {
constraint.mix += (frames[frames.Length + PREV_MIX] - constraint.mix) * alpha;
if (direction == MixDirection_In) constraint.bendDirection = (int)frames[frames.Length + PREV_BEND_DIRECTION];
}
return;
}
// Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES);
float mix = frames[frame + PREV_MIX];
float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
if (pose == MixPose_Setup) {
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];
} else {
constraint.mix += (mix + (frames[frame + MIX] - mix) * percent - constraint.mix) * alpha;
if (direction == MixDirection_In) constraint.bendDirection = (int)frames[frame + PREV_BEND_DIRECTION];
}
}
// 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;
//
// 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) {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + MIX] = mix;
// frames[frameIndex + BEND_DIRECTION] = bendDirection;
// }
//
// 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];
// float[] frames = _frames;
// if (time < frames[0]) {
// switch (pose) {
// case MixPose_Setup:
// constraint.mix = constraint.data.mix;
// constraint.bendDirection = constraint.data.bendDirection;
// return;
// case MixPose_Current:
// constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
// constraint.bendDirection = constraint.data.bendDirection;
// return;
// }
// return;
// }
//
// if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
// if (pose == MixPose_Setup) {
// constraint.mix = constraint.data.mix + (frames[frames.Length + PREV_MIX] - constraint.data.mix) * alpha;
// constraint.bendDirection = direction == MixDirection_Out ? constraint.data.bendDirection
// : (int)frames[frames.Length + PREV_BEND_DIRECTION];
// } else {
// constraint.mix += (frames[frames.Length + PREV_MIX] - constraint.mix) * alpha;
// if (direction == MixDirection_In) constraint.bendDirection = (int)frames[frames.Length + PREV_BEND_DIRECTION];
// }
// return;
// }
//
// // Interpolate between the previous frame and the current frame.
// int frame = Animation.BinarySearch(frames, time, ENTRIES);
// float mix = frames[frame + PREV_MIX];
// float frameTime = frames[frame];
// float percent = GetCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
// if (pose == MixPose_Setup) {
// 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];
// } else {
// constraint.mix += (mix + (frames[frame + MIX] - mix) * percent - constraint.mix) * alpha;
// if (direction == MixDirection_In) constraint.bendDirection = (int)frames[frame + PREV_BEND_DIRECTION];
// }
// }
};
}

View File

@ -39,76 +39,76 @@ namespace Spine
{
RTTI_DECL;
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) {
frames = new float[frameCount * ENTRIES];
}
/// Sets the time and mixes of the specified keyframe.
public void SetFrame (int frameIndex, float time, float rotateMix, float translateMix) {
frameIndex *= ENTRIES;
frames[frameIndex] = time;
frames[frameIndex + ROTATE] = rotateMix;
frames[frameIndex + TRANSLATE] = translateMix;
}
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];
float[] frames = _frames;
if (time < frames[0]) {
switch (pose) {
case MixPose_Setup:
constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix;
return;
case MixPose_Current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
return;
}
return;
}
float rotate, translate;
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
rotate = frames[frames.Length + PREV_ROTATE];
translate = frames[frames.Length + PREV_TRANSLATE];
} else {
// Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES);
rotate = frames[frame + PREV_ROTATE];
translate = frames[frame + PREV_TRANSLATE];
float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
rotate += (frames[frame + ROTATE] - rotate) * percent;
translate += (frames[frame + TRANSLATE] - translate) * percent;
}
if (pose == MixPose_Setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} else {
constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
constraint.translateMix += (translate - constraint.translateMix) * alpha;
}
}
}
// 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) {
// frames = new float[frameCount * ENTRIES];
// }
//
// /// Sets the time and mixes of the specified keyframe.
// public void SetFrame (int frameIndex, float time, float rotateMix, float translateMix) {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + ROTATE] = rotateMix;
// frames[frameIndex + TRANSLATE] = translateMix;
// }
//
// 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];
// float[] frames = _frames;
// if (time < frames[0]) {
// switch (pose) {
// case MixPose_Setup:
// constraint.rotateMix = constraint.data.rotateMix;
// constraint.translateMix = constraint.data.translateMix;
// return;
// case MixPose_Current:
// constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
// constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
// return;
// }
// return;
// }
//
// float rotate, translate;
// if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
// rotate = frames[frames.Length + PREV_ROTATE];
// translate = frames[frames.Length + PREV_TRANSLATE];
// } else {
// // Interpolate between the previous frame and the current frame.
// int frame = Animation.BinarySearch(frames, time, ENTRIES);
// rotate = frames[frame + PREV_ROTATE];
// translate = frames[frame + PREV_TRANSLATE];
// float frameTime = frames[frame];
// float percent = GetCurvePercent(frame / ENTRIES - 1,
// 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
// rotate += (frames[frame + ROTATE] - rotate) * percent;
// translate += (frames[frame + TRANSLATE] - translate) * percent;
// }
//
// if (pose == MixPose_Setup) {
// constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
// constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
// } else {
// constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
// constraint.translateMix += (translate - constraint.translateMix) * alpha;
// }
// }
};
}
#endif /* Spine_PathConstraintMixTimeline_h */

View File

@ -37,66 +37,68 @@ namespace Spine
{
class PathConstraintPositionTimeline : public CurveTimeline
{
public const int ENTRIES = 2;
protected const int PREV_TIME = -2, PREV_VALUE = -1;
protected const int VALUE = 1;
RTTI_DECL;
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];
}
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) {
frameIndex *= ENTRIES;
frames[frameIndex] = time;
frames[frameIndex + VALUE] = inValue;
}
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];
float[] frames = _frames;
if (time < frames[0]) {
switch (pose) {
case MixPose_Setup:
constraint.position = constraint.data.position;
return;
case MixPose_Current:
constraint.position += (constraint.data.position - constraint.position) * alpha;
return;
}
return;
}
float position;
if (time >= frames[frames.Length - ENTRIES]) // Time is after last frame.
position = frames[frames.Length + PREV_VALUE];
else {
// Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES);
position = frames[frame + PREV_VALUE];
float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
position += (frames[frame + VALUE] - position) * percent;
}
if (pose == MixPose_Setup)
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
else
constraint.position += (position - constraint.position) * alpha;
}
}
// 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];
// }
//
// 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) {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + VALUE] = inValue;
// }
//
// 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];
// float[] frames = _frames;
// if (time < frames[0]) {
// switch (pose) {
// case MixPose_Setup:
// constraint.position = constraint.data.position;
// return;
// case MixPose_Current:
// constraint.position += (constraint.data.position - constraint.position) * alpha;
// return;
// }
// return;
// }
//
// float position;
// if (time >= frames[frames.Length - ENTRIES]) // Time is after last frame.
// position = frames[frames.Length + PREV_VALUE];
// else {
// // Interpolate between the previous frame and the current frame.
// int frame = Animation.BinarySearch(frames, time, ENTRIES);
// position = frames[frame + PREV_VALUE];
// float frameTime = frames[frame];
// float percent = GetCurvePercent(frame / ENTRIES - 1,
// 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
// position += (frames[frame + VALUE] - position) * percent;
// }
// 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 */

View File

@ -39,49 +39,49 @@ namespace Spine
{
RTTI_DECL;
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<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex];
float[] frames = _frames;
if (time < frames[0]) {
switch (pose) {
case MixPose_Setup:
constraint.spacing = constraint.data.spacing;
return;
case MixPose_Current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
return;
}
return;
}
float spacing;
if (time >= frames[frames.Length - ENTRIES]) // Time is after last frame.
spacing = frames[frames.Length + PREV_VALUE];
else {
// Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES);
spacing = frames[frame + PREV_VALUE];
float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
spacing += (frames[frame + VALUE] - spacing) * percent;
}
if (pose == MixPose_Setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else
constraint.spacing += (spacing - constraint.spacing) * alpha;
}
}
// 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<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
// PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex];
// float[] frames = _frames;
// if (time < frames[0]) {
// switch (pose) {
// case MixPose_Setup:
// constraint.spacing = constraint.data.spacing;
// return;
// case MixPose_Current:
// constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
// return;
// }
// return;
// }
//
// float spacing;
// if (time >= frames[frames.Length - ENTRIES]) // Time is after last frame.
// spacing = frames[frames.Length + PREV_VALUE];
// else {
// // Interpolate between the previous frame and the current frame.
// int frame = Animation.BinarySearch(frames, time, ENTRIES);
// spacing = frames[frame + PREV_VALUE];
// float frameTime = frames[frame];
// float percent = GetCurvePercent(frame / ENTRIES - 1,
// 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
// spacing += (frames[frame + VALUE] - spacing) * percent;
// }
//
// if (pose == MixPose_Setup)
// constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
// else
// constraint.spacing += (spacing - constraint.spacing) * alpha;
// }
};
}
#endif /* Spine_PathConstraintSpacingTimeline_h */

View File

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

View File

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

View File

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

View File

@ -39,93 +39,93 @@ namespace Spine
{
RTTI_DECL;
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;
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) {
frameIndex *= ENTRIES;
frames[frameIndex] = time;
frames[frameIndex + ROTATE] = rotateMix;
frames[frameIndex + TRANSLATE] = translateMix;
frames[frameIndex + SCALE] = scaleMix;
frames[frameIndex + SHEAR] = shearMix;
}
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];
float[] frames = _frames;
if (time < frames[0]) {
var data = constraint.data;
switch (pose) {
case MixPose_Setup:
constraint.rotateMix = data.rotateMix;
constraint.translateMix = data.translateMix;
constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix;
return;
case MixPose_Current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
return;
}
return;
}
float rotate, translate, scale, shear;
if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
int i = frames.Length;
rotate = frames[i + PREV_ROTATE];
translate = frames[i + PREV_TRANSLATE];
scale = frames[i + PREV_SCALE];
shear = frames[i + PREV_SHEAR];
} else {
// Interpolate between the previous frame and the current frame.
int frame = Animation.BinarySearch(frames, time, ENTRIES);
rotate = frames[frame + PREV_ROTATE];
translate = frames[frame + PREV_TRANSLATE];
scale = frames[frame + PREV_SCALE];
shear = frames[frame + PREV_SHEAR];
float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
rotate += (frames[frame + ROTATE] - rotate) * percent;
translate += (frames[frame + TRANSLATE] - translate) * percent;
scale += (frames[frame + SCALE] - scale) * percent;
shear += (frames[frame + SHEAR] - shear) * percent;
}
if (pose == MixPose_Setup) {
TransformConstraintData data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
} else {
constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
constraint.translateMix += (translate - constraint.translateMix) * alpha;
constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
constraint.shearMix += (shear - constraint.shearMix) * alpha;
}
}
}
// 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;
// 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) {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + ROTATE] = rotateMix;
// frames[frameIndex + TRANSLATE] = translateMix;
// frames[frameIndex + SCALE] = scaleMix;
// frames[frameIndex + SHEAR] = shearMix;
// }
//
// 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];
// float[] frames = _frames;
// if (time < frames[0]) {
// var data = constraint.data;
// switch (pose) {
// case MixPose_Setup:
// constraint.rotateMix = data.rotateMix;
// constraint.translateMix = data.translateMix;
// constraint.scaleMix = data.scaleMix;
// constraint.shearMix = data.shearMix;
// return;
// case MixPose_Current:
// constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
// constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
// constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
// constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
// return;
// }
// return;
// }
//
// float rotate, translate, scale, shear;
// if (time >= frames[frames.Length - ENTRIES]) { // Time is after last frame.
// int i = frames.Length;
// rotate = frames[i + PREV_ROTATE];
// translate = frames[i + PREV_TRANSLATE];
// scale = frames[i + PREV_SCALE];
// shear = frames[i + PREV_SHEAR];
// } else {
// // Interpolate between the previous frame and the current frame.
// int frame = Animation.BinarySearch(frames, time, ENTRIES);
// rotate = frames[frame + PREV_ROTATE];
// translate = frames[frame + PREV_TRANSLATE];
// scale = frames[frame + PREV_SCALE];
// shear = frames[frame + PREV_SHEAR];
// float frameTime = frames[frame];
// float percent = GetCurvePercent(frame / ENTRIES - 1,
// 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
// rotate += (frames[frame + ROTATE] - rotate) * percent;
// translate += (frames[frame + TRANSLATE] - translate) * percent;
// scale += (frames[frame + SCALE] - scale) * percent;
// shear += (frames[frame + SHEAR] - shear) * percent;
// }
// if (pose == MixPose_Setup) {
// TransformConstraintData data = constraint.data;
// constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
// constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
// constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
// constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
// } else {
// constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
// constraint.translateMix += (translate - constraint.translateMix) * alpha;
// constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
// constraint.shearMix += (shear - constraint.shearMix) * alpha;
// }
// }
};
}
#endif /* Spine_TransformConstraintTimeline_h */

View File

@ -42,88 +42,88 @@ namespace Spine
{
RTTI_DECL;
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<float> getFrames { return frames; } set { frames = inValue; } // time, value, value, ...
virtual int getPropertyId()
{
return ((int)TimelineType_Translate << 24) + boneIndex;
}
public TranslateTimeline(int frameCount) : CurveTimeline(frameCount)
{
frames = new float[frameCount * ENTRIES];
}
/// Sets the time and value of the specified keyframe.
public void setFrame(int frameIndex, float time, float x, float y)
{
frameIndex *= ENTRIES;
frames[frameIndex] = time;
frames[frameIndex + X] = x;
frames[frameIndex + Y] = y;
}
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];
float[] frames = _frames;
if (time < frames[0])
{
switch (pose)
{
case MixPose_Setup:
bone.x = bone.data.x;
bone.y = bone.data.y;
return;
case MixPose_Current:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
return;
}
return;
}
float x, y;
if (time >= frames[frames.Length - ENTRIES])
{
// Time is after last frame.
x = frames[frames.Length + PREV_X];
y = frames[frames.Length + PREV_Y];
}
else
{
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(frames, time, ENTRIES);
x = frames[frame + PREV_X];
y = frames[frame + PREV_Y];
float frameTime = frames[frame];
float percent = GetCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
x += (frames[frame + X] - x) * percent;
y += (frames[frame + Y] - y) * percent;
}
if (pose == MixPose_Setup)
{
bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha;
}
else
{
bone.x += (bone.data.x + x - bone.x) * alpha;
bone.y += (bone.data.y + y - bone.y) * alpha;
}
}
}
// 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<float> getFrames { return frames; } set { frames = inValue; } // time, value, value, ...
//
// virtual int getPropertyId()
// {
// return ((int)TimelineType_Translate << 24) + boneIndex;
// }
//
// public TranslateTimeline(int frameCount) : CurveTimeline(frameCount)
// {
// frames = new float[frameCount * ENTRIES];
// }
//
// /// Sets the time and value of the specified keyframe.
// public void setFrame(int frameIndex, float time, float x, float y)
// {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + X] = x;
// frames[frameIndex + Y] = y;
// }
//
// 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];
//
// float[] frames = _frames;
// if (time < frames[0])
// {
// switch (pose)
// {
// case MixPose_Setup:
// bone.x = bone.data.x;
// bone.y = bone.data.y;
// return;
// case MixPose_Current:
// bone.x += (bone.data.x - bone.x) * alpha;
// bone.y += (bone.data.y - bone.y) * alpha;
// return;
// }
// return;
// }
//
// float x, y;
// if (time >= frames[frames.Length - ENTRIES])
// {
// // Time is after last frame.
// x = frames[frames.Length + PREV_X];
// y = frames[frames.Length + PREV_Y];
// }
// else
// {
// // Interpolate between the previous frame and the current frame.
// int frame = Animation::binarySearch(frames, time, ENTRIES);
// x = frames[frame + PREV_X];
// y = frames[frame + PREV_Y];
// float frameTime = frames[frame];
// float percent = GetCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
//
// x += (frames[frame + X] - x) * percent;
// y += (frames[frame + Y] - y) * percent;
// }
//
// if (pose == MixPose_Setup)
// {
// bone.x = bone.data.x + x * alpha;
// bone.y = bone.data.y + y * alpha;
// }
// else
// {
// bone.x += (bone.data.x + x - bone.x) * alpha;
// bone.y += (bone.data.y + y - bone.y) * alpha;
// }
// }
};
}
#endif /* Spine_TranslateTimeline_h */

View File

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

View File

@ -43,24 +43,27 @@ namespace Spine
void AnimationStateData::setMix(std::string fromName, std::string toName, float duration)
{
Animation* from = _skeletonData.findAnimation(fromName);
assert(from != NULL);
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);
HashMap<AnimationPair, float, HashAnimationPair>::Iterator i = _animationToMixTime.find(key);
_animationToMixTime.erase(i);
_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);
HashMap<AnimationPair, float, HashAnimationPair>::Iterator i = _animationToMixTime.find(key);
@ -88,30 +91,30 @@ namespace Spine
_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
}
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 h1 = 7;
size_t strlen = val._a1._name.length();
size_t strlen = val._a1->_name.length();
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;
strlen = val._a2._name.length();
strlen = val._a2->_name.length();
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);