diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index d3e2412c3..bb9f62e93 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -34,7 +34,6 @@ import static com.esotericsoftware.spine.Animation.MixDirection.*; import static com.esotericsoftware.spine.utils.SpineUtils.*; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.ObjectSet; @@ -115,7 +114,7 @@ public class Animation { } /** Binary search using a stride of 1. - * @return The index of the first value less than or equal to the target, else the first value if none. */ + * @return The index of the first value <= to the target, else the first value if none. */ static int binarySearch (float[] values, float target) { int low = 0, high = values.length - 1, current; while (true) { @@ -130,11 +129,11 @@ public class Animation { /** Binary search using a stride of 2. * @param target >= the first and < the last value. - * @return The index / 2 of the first value less than or equal to the target. */ + * @return The index / 2 of the first value <= to the target. */ static int binarySearch2 (float[] values, float target) { int low = 0, high = (values.length >> 1) - 2, current; while (true) { - if (low >= high) return low; + if (low == high) return low; current = ((low + high) >>> 1) + 1; if (values[current << 1] <= target) low = current; @@ -144,12 +143,12 @@ public class Animation { } /** Binary search using the specified stride. - * @param target After the first and before the last value. - * @return The index / 2 of the first value less than or equal to the target. */ + * @param target >= the first and < the last value. + * @return The index / 2 of the first value <= to the target. */ static int binarySearch (float[] values, float target, int step) { int low = 0, high = values.length / step - 2, current; while (true) { - if (low >= high) return low; + if (low == high) return low; current = ((low + high) >>> 1) + 1; if (values[current * step] <= target) low = current; @@ -159,8 +158,8 @@ public class Animation { } /** Linear search using the specified stride. Not used, but for comparison with binary searches. - * @param target After the first and before the last value. - * @return index of first value greater than the target. */ + * @param target >= the first and < the last value. + * @return The index / 2 of the first value <= to the target. */ static int linearSearch (float[] values, float target, int step) { for (int i = 0, last = values.length - 1; i < last; i += step) if (values[i] > target) return i / step - 1; @@ -218,7 +217,7 @@ public class Animation { final float[] frames; /** @param frameEntries The number of entries stored per frame. - * @param propertyIds Unique identifiers for each property the timeline modifies. */ + * @param propertyIds Unique identifiers for the properties the timeline modifies. */ public Timeline (int frameCount, int frameEntries, String... propertyIds) { if (propertyIds == null) throw new IllegalArgumentException("propertyIds cannot be null."); this.propertyIds = propertyIds; @@ -284,7 +283,7 @@ public class Animation { /** @param frameEntries The number of entries stored per frame. * @param bezierCount The maximum number of frames that will use Bezier curves. See {@link #shrink(int)}. - * @param propertyIds Unique identifiers for each property the timeline modifies. */ + * @param propertyIds Unique identifiers for the properties the timeline modifies. */ public CurveTimeline (int frameCount, int frameEntries, int bezierCount, String... propertyIds) { super(frameCount, frameEntries, propertyIds); curves = new float[frameCount - 1 + bezierCount * BEZIER_SIZE]; @@ -328,10 +327,10 @@ public class Animation { } /** The base class for timelines that use interpolation between key frames for one or more properties using a percentage of the - * difference between values. */ + * difference between key frame values. */ static public abstract class PercentCurveTimeline extends CurveTimeline { /** @param bezierCount The maximum number of frames that will use Bezier curves. See {@link #shrink(int)}. - * @param propertyIds Unique identifiers for each property the timeline modifies. */ + * @param propertyIds Unique identifiers for the properties the timeline modifies. */ public PercentCurveTimeline (int frameCount, int frameEntries, int bezierCount, String... propertyIds) { super(frameCount, frameEntries, bezierCount, propertyIds); } @@ -369,16 +368,14 @@ public class Animation { float[] curves = this.curves; int i = (int)curves[frameIndex]; if (i < BEZIER) { - if (i == LINEAR) { - float time1 = frames[timeIndex]; - return MathUtils.clamp((time - time1) / (frames[timeIndex + entryCount] - time1), 0, 1); - } - return 0; + if (i == STEPPED) return 0; + float x = frames[timeIndex]; + return (time - x) / (frames[timeIndex + entryCount] - x); } i -= BEZIER; if (curves[i] > time) { - float time1 = frames[timeIndex]; - return curves[i + 1] * (time - time1) / (curves[i] - time1); + float x = frames[timeIndex]; + return curves[i + 1] * (time - x) / (curves[i] - x); } int n = i + BEZIER_SIZE; for (i += 2; i < n; i += 2) { @@ -398,7 +395,7 @@ public class Animation { static final int VALUE1 = 1, VALUE2 = 2, NEXT_VALUE1 = 4, NEXT_VALUE2 = 5; /** @param bezierCount The maximum number of frames that will use Bezier curves. See {@link #shrink(int)}. - * @param propertyIds Unique identifiers for each property the timeline modifies. */ + * @param propertyIds Unique identifiers for the properties the timeline modifies. */ public PercentCurveTimeline2 (int frameCount, int bezierCount, String... propertyIds) { super(frameCount, ENTRIES, bezierCount, propertyIds); } @@ -423,7 +420,7 @@ public class Animation { static final int VALUE = 1, NEXT_VALUE = 3; /** @param bezierCount The maximum number of frames that will use Bezier curves. See {@link #shrink(int)}. - * @param propertyIds Unique identifiers for each property the timeline modifies. */ + * @param propertyIds Unique identifiers for the properties the timeline modifies. */ public ValueCurveTimeline (int frameCount, int bezierCount, String... propertyIds) { super(frameCount, 2, bezierCount, propertyIds); } @@ -474,17 +471,15 @@ public class Animation { int i = (int)curves[frameIndex]; if (i < BEZIER) { int frame = frameIndex << 1; - if (i == LINEAR) { - float value1 = frames[frame + VALUE], time1 = frames[frame]; - return value1 + (frames[frame + NEXT_VALUE] - value1) - * MathUtils.clamp((time - time1) / (frames[frame + ENTRIES] - time1), 0, 1); - } - return frames[frame + VALUE]; + if (i == STEPPED) return frames[frame + VALUE]; + float x = frames[frame], y = frames[frame + VALUE]; + return y + (frames[frame + NEXT_VALUE] - y) * (time - x) / (frames[frame + ENTRIES] - x); } i -= BEZIER; if (curves[i] > time) { - float value1 = frames[(frameIndex << 1) + VALUE]; - return value1 + (curves[i + 1] - value1) * (time - value1) / (curves[i] - value1); + int frame = frameIndex << 1; + float x = frames[frame], y = frames[frame + VALUE]; + return y + (curves[i + 1] - y) * (time - x) / (curves[i] - x); } int n = i + BEZIER_SIZE; for (i += 2; i < n; i += 2) {