Got rid of the "key" in "keyframes".

We only deal with keyframes in all the animation stuff, it's cleaner without. Sorry if this breaks anyone! Easy fix at least.
This commit is contained in:
NathanSweet 2013-03-29 04:10:28 +01:00
parent 40835845be
commit 24538adb1a
3 changed files with 65 additions and 65 deletions

View File

@ -127,26 +127,26 @@ public class Animation {
private final float[] curves; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ... private final float[] curves; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ...
public CurveTimeline (int keyframeCount) { public CurveTimeline (int frameCount) {
curves = new float[(keyframeCount - 1) * 6]; curves = new float[(frameCount - 1) * 6];
} }
public int getKeyframeCount () { public int getFrameCount () {
return curves.length / 6 + 1; return curves.length / 6 + 1;
} }
public void setLinear (int keyframeIndex) { public void setLinear (int frameIndex) {
curves[keyframeIndex * 6] = LINEAR; curves[frameIndex * 6] = LINEAR;
} }
public void setStepped (int keyframeIndex) { public void setStepped (int frameIndex) {
curves[keyframeIndex * 6] = STEPPED; curves[frameIndex * 6] = STEPPED;
} }
/** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. /** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
* cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of
* the difference between the keyframe's values. */ * the difference between the keyframe's values. */
public void setCurve (int keyframeIndex, float cx1, float cy1, float cx2, float cy2) { public void setCurve (int frameIndex, float cx1, float cy1, float cx2, float cy2) {
float subdiv_step = 1f / BEZIER_SEGMENTS; float subdiv_step = 1f / BEZIER_SEGMENTS;
float subdiv_step2 = subdiv_step * subdiv_step; float subdiv_step2 = subdiv_step * subdiv_step;
float subdiv_step3 = subdiv_step2 * subdiv_step; float subdiv_step3 = subdiv_step2 * subdiv_step;
@ -158,7 +158,7 @@ public class Animation {
float tmp1y = -cy1 * 2 + cy2; float tmp1y = -cy1 * 2 + cy2;
float tmp2x = (cx1 - cx2) * 3 + 1; float tmp2x = (cx1 - cx2) * 3 + 1;
float tmp2y = (cy1 - cy2) * 3 + 1; float tmp2y = (cy1 - cy2) * 3 + 1;
int i = keyframeIndex * 6; int i = frameIndex * 6;
float[] curves = this.curves; float[] curves = this.curves;
curves[i] = cx1 * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3; curves[i] = cx1 * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3;
curves[i + 1] = cy1 * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3; curves[i + 1] = cy1 * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3;
@ -168,8 +168,8 @@ public class Animation {
curves[i + 5] = tmp2y * pre5; curves[i + 5] = tmp2y * pre5;
} }
public float getCurvePercent (int keyframeIndex, float percent) { public float getCurvePercent (int frameIndex, float percent) {
int curveIndex = keyframeIndex * 6; int curveIndex = frameIndex * 6;
float[] curves = this.curves; float[] curves = this.curves;
float dfx = curves[curveIndex]; float dfx = curves[curveIndex];
if (dfx == LINEAR) return percent; if (dfx == LINEAR) return percent;
@ -207,9 +207,9 @@ public class Animation {
private int boneIndex; private int boneIndex;
private final float[] frames; // time, value, ... private final float[] frames; // time, value, ...
public RotateTimeline (int keyframeCount) { public RotateTimeline (int frameCount) {
super(keyframeCount); super(frameCount);
frames = new float[keyframeCount * 2]; frames = new float[frameCount * 2];
} }
public void setBoneIndex (int boneIndex) { public void setBoneIndex (int boneIndex) {
@ -220,15 +220,15 @@ public class Animation {
return boneIndex; return boneIndex;
} }
public float[] getKeyframes () { public float[] getFrames () {
return frames; return frames;
} }
/** Sets the time and value of the specified keyframe. */ /** Sets the time and value of the specified keyframe. */
public void setKeyframe (int keyframeIndex, float time, float value) { public void setFrame (int frameIndex, float time, float value) {
keyframeIndex *= 2; frameIndex *= 2;
frames[keyframeIndex] = time; frames[frameIndex] = time;
frames[keyframeIndex + 1] = value; frames[frameIndex + 1] = value;
} }
public void apply (Skeleton skeleton, float time, float alpha) { public void apply (Skeleton skeleton, float time, float alpha) {
@ -276,9 +276,9 @@ public class Animation {
int boneIndex; int boneIndex;
final float[] frames; // time, value, value, ... final float[] frames; // time, value, value, ...
public TranslateTimeline (int keyframeCount) { public TranslateTimeline (int frameCount) {
super(keyframeCount); super(frameCount);
frames = new float[keyframeCount * 3]; frames = new float[frameCount * 3];
} }
public void setBoneIndex (int boneIndex) { public void setBoneIndex (int boneIndex) {
@ -289,16 +289,16 @@ public class Animation {
return boneIndex; return boneIndex;
} }
public float[] getKeyframes () { public float[] getFrames () {
return frames; return frames;
} }
/** Sets the time and value of the specified keyframe. */ /** Sets the time and value of the specified keyframe. */
public void setKeyframe (int keyframeIndex, float time, float x, float y) { public void setFrame (int frameIndex, float time, float x, float y) {
keyframeIndex *= 3; frameIndex *= 3;
frames[keyframeIndex] = time; frames[frameIndex] = time;
frames[keyframeIndex + 1] = x; frames[frameIndex + 1] = x;
frames[keyframeIndex + 2] = y; frames[frameIndex + 2] = y;
} }
public void apply (Skeleton skeleton, float time, float alpha) { public void apply (Skeleton skeleton, float time, float alpha) {
@ -327,8 +327,8 @@ public class Animation {
} }
static public class ScaleTimeline extends TranslateTimeline { static public class ScaleTimeline extends TranslateTimeline {
public ScaleTimeline (int keyframeCount) { public ScaleTimeline (int frameCount) {
super(keyframeCount); super(frameCount);
} }
public void apply (Skeleton skeleton, float time, float alpha) { public void apply (Skeleton skeleton, float time, float alpha) {
@ -367,9 +367,9 @@ public class Animation {
private int slotIndex; private int slotIndex;
private final float[] frames; // time, r, g, b, a, ... private final float[] frames; // time, r, g, b, a, ...
public ColorTimeline (int keyframeCount) { public ColorTimeline (int frameCount) {
super(keyframeCount); super(frameCount);
frames = new float[keyframeCount * 5]; frames = new float[frameCount * 5];
} }
public void setSlotIndex (int slotIndex) { public void setSlotIndex (int slotIndex) {
@ -380,18 +380,18 @@ public class Animation {
return slotIndex; return slotIndex;
} }
public float[] getKeyframes () { public float[] getFrames () {
return frames; return frames;
} }
/** Sets the time and value of the specified keyframe. */ /** Sets the time and value of the specified keyframe. */
public void setKeyframe (int keyframeIndex, 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) {
keyframeIndex *= 5; frameIndex *= 5;
frames[keyframeIndex] = time; frames[frameIndex] = time;
frames[keyframeIndex + 1] = r; frames[frameIndex + 1] = r;
frames[keyframeIndex + 2] = g; frames[frameIndex + 2] = g;
frames[keyframeIndex + 3] = b; frames[frameIndex + 3] = b;
frames[keyframeIndex + 4] = a; frames[frameIndex + 4] = a;
} }
public void apply (Skeleton skeleton, float time, float alpha) { public void apply (Skeleton skeleton, float time, float alpha) {
@ -436,12 +436,12 @@ public class Animation {
private final float[] frames; // time, ... private final float[] frames; // time, ...
private final String[] attachmentNames; private final String[] attachmentNames;
public AttachmentTimeline (int keyframeCount) { public AttachmentTimeline (int frameCount) {
frames = new float[keyframeCount]; frames = new float[frameCount];
attachmentNames = new String[keyframeCount]; attachmentNames = new String[frameCount];
} }
public int getKeyframeCount () { public int getFrameCount () {
return frames.length; return frames.length;
} }
@ -453,7 +453,7 @@ public class Animation {
this.slotIndex = slotIndex; this.slotIndex = slotIndex;
} }
public float[] getKeyframes () { public float[] getFrames () {
return frames; return frames;
} }
@ -462,9 +462,9 @@ public class Animation {
} }
/** Sets the time and value of the specified keyframe. */ /** Sets the time and value of the specified keyframe. */
public void setKeyframe (int keyframeIndex, float time, String attachmentName) { public void setFrame (int frameIndex, float time, String attachmentName) {
frames[keyframeIndex] = time; frames[frameIndex] = time;
attachmentNames[keyframeIndex] = attachmentName; attachmentNames[frameIndex] = attachmentName;
} }
public void apply (Skeleton skeleton, float time, float alpha) { public void apply (Skeleton skeleton, float time, float alpha) {

View File

@ -206,11 +206,11 @@ public class SkeletonBinary {
RotateTimeline timeline = new RotateTimeline(keyCount); RotateTimeline timeline = new RotateTimeline(keyCount);
timeline.setBoneIndex(boneIndex); timeline.setBoneIndex(boneIndex);
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) { for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
timeline.setKeyframe(keyframeIndex, input.readFloat(), input.readFloat()); timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat());
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline); if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
} }
timelines.add(timeline); timelines.add(timeline);
duration = Math.max(duration, timeline.getKeyframes()[keyCount * 2 - 2]); duration = Math.max(duration, timeline.getFrames()[keyCount * 2 - 2]);
break; break;
} }
case TIMELINE_TRANSLATE: case TIMELINE_TRANSLATE:
@ -225,12 +225,12 @@ public class SkeletonBinary {
} }
timeline.setBoneIndex(boneIndex); timeline.setBoneIndex(boneIndex);
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) { for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
timeline.setKeyframe(keyframeIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat() timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat()
* timelineScale); * timelineScale);
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline); if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
} }
timelines.add(timeline); timelines.add(timeline);
duration = Math.max(duration, timeline.getKeyframes()[keyCount * 3 - 3]); duration = Math.max(duration, timeline.getFrames()[keyCount * 3 - 3]);
break; break;
default: default:
throw new RuntimeException("Invalid timeline type for a bone: " + timelineType + " (" + boneName + ")"); throw new RuntimeException("Invalid timeline type for a bone: " + timelineType + " (" + boneName + ")");
@ -253,20 +253,20 @@ public class SkeletonBinary {
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) { for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
float time = input.readFloat(); float time = input.readFloat();
Color.rgba8888ToColor(tempColor, input.readInt()); Color.rgba8888ToColor(tempColor, input.readInt());
timeline.setKeyframe(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a); timeline.setFrame(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline); if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
} }
timelines.add(timeline); timelines.add(timeline);
duration = Math.max(duration, timeline.getKeyframes()[keyCount * 5 - 5]); duration = Math.max(duration, timeline.getFrames()[keyCount * 5 - 5]);
break; break;
} }
case TIMELINE_ATTACHMENT: case TIMELINE_ATTACHMENT:
AttachmentTimeline timeline = new AttachmentTimeline(keyCount); AttachmentTimeline timeline = new AttachmentTimeline(keyCount);
timeline.setSlotIndex(slotIndex); timeline.setSlotIndex(slotIndex);
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++)
timeline.setKeyframe(keyframeIndex, input.readFloat(), input.readString()); timeline.setFrame(keyframeIndex, input.readFloat(), input.readString());
timelines.add(timeline); timelines.add(timeline);
duration = Math.max(duration, timeline.getKeyframes()[keyCount - 1]); duration = Math.max(duration, timeline.getFrames()[keyCount - 1]);
break; break;
default: default:
throw new RuntimeException("Invalid timeline type for a slot: " + timelineType + " (" + slotName + ")"); throw new RuntimeException("Invalid timeline type for a slot: " + timelineType + " (" + slotName + ")");

View File

@ -206,12 +206,12 @@ public class SkeletonJson {
int keyframeIndex = 0; int keyframeIndex = 0;
for (OrderedMap valueMap : values) { for (OrderedMap valueMap : values) {
float time = (Float)valueMap.get("time"); float time = (Float)valueMap.get("time");
timeline.setKeyframe(keyframeIndex, time, (Float)valueMap.get("angle")); timeline.setFrame(keyframeIndex, time, (Float)valueMap.get("angle"));
readCurve(timeline, keyframeIndex, valueMap); readCurve(timeline, keyframeIndex, valueMap);
keyframeIndex++; keyframeIndex++;
} }
timelines.add(timeline); timelines.add(timeline);
duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() * 2 - 2]); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 2 - 2]);
} else if (timelineName.equals(TIMELINE_TRANSLATE) || timelineName.equals(TIMELINE_SCALE)) { } else if (timelineName.equals(TIMELINE_TRANSLATE) || timelineName.equals(TIMELINE_SCALE)) {
TranslateTimeline timeline; TranslateTimeline timeline;
@ -228,13 +228,13 @@ public class SkeletonJson {
for (OrderedMap valueMap : values) { for (OrderedMap valueMap : values) {
float time = (Float)valueMap.get("time"); float time = (Float)valueMap.get("time");
Float x = (Float)valueMap.get("x"), y = (Float)valueMap.get("y"); Float x = (Float)valueMap.get("x"), y = (Float)valueMap.get("y");
timeline.setKeyframe(keyframeIndex, time, x == null ? 0 : (x * timelineScale), y == null ? 0 timeline.setFrame(keyframeIndex, time, x == null ? 0 : (x * timelineScale), y == null ? 0
: (y * timelineScale)); : (y * timelineScale));
readCurve(timeline, keyframeIndex, valueMap); readCurve(timeline, keyframeIndex, valueMap);
keyframeIndex++; keyframeIndex++;
} }
timelines.add(timeline); timelines.add(timeline);
duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() * 3 - 3]); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 3 - 3]);
} else } else
throw new RuntimeException("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"); throw new RuntimeException("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
@ -259,12 +259,12 @@ public class SkeletonJson {
for (OrderedMap valueMap : values) { for (OrderedMap valueMap : values) {
float time = (Float)valueMap.get("time"); float time = (Float)valueMap.get("time");
Color color = Color.valueOf((String)valueMap.get("color")); Color color = Color.valueOf((String)valueMap.get("color"));
timeline.setKeyframe(keyframeIndex, time, color.r, color.g, color.b, color.a); timeline.setFrame(keyframeIndex, time, color.r, color.g, color.b, color.a);
readCurve(timeline, keyframeIndex, valueMap); readCurve(timeline, keyframeIndex, valueMap);
keyframeIndex++; keyframeIndex++;
} }
timelines.add(timeline); timelines.add(timeline);
duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() * 5 - 5]); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 5 - 5]);
} else if (timelineName.equals(TIMELINE_ATTACHMENT)) { } else if (timelineName.equals(TIMELINE_ATTACHMENT)) {
AttachmentTimeline timeline = new AttachmentTimeline(values.size); AttachmentTimeline timeline = new AttachmentTimeline(values.size);
@ -273,10 +273,10 @@ public class SkeletonJson {
int keyframeIndex = 0; int keyframeIndex = 0;
for (OrderedMap valueMap : values) { for (OrderedMap valueMap : values) {
float time = (Float)valueMap.get("time"); float time = (Float)valueMap.get("time");
timeline.setKeyframe(keyframeIndex++, time, (String)valueMap.get("name")); timeline.setFrame(keyframeIndex++, time, (String)valueMap.get("name"));
} }
timelines.add(timeline); timelines.add(timeline);
duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() - 1]); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
} else } else
throw new RuntimeException("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")"); throw new RuntimeException("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");