diff --git a/spine-cpp/include/spine/Animation.h b/spine-cpp/include/spine/Animation.h index 2c3f71444..23674b73f 100644 --- a/spine-cpp/include/spine/Animation.h +++ b/spine-cpp/include/spine/Animation.h @@ -53,10 +53,6 @@ public: virtual ~Timeline () { } - virtual float getDuration () const = 0; - - virtual int getKeyframeCount () const = 0; - virtual void apply (BaseSkeleton *skeleton, float time, float alpha = 1) const = 0; }; @@ -92,8 +88,6 @@ public: RotateTimeline (int keyframeCount); virtual ~RotateTimeline (); - virtual float getDuration () const; - virtual int getKeyframeCount () const; virtual void apply (BaseSkeleton *skeleton, float time, float alpha = 1) const; void setKeyframe (int keyframeIndex, float time, float value); @@ -110,8 +104,6 @@ public: TranslateTimeline (int keyframeCount); virtual ~TranslateTimeline (); - virtual float getDuration () const; - virtual int getKeyframeCount () const; virtual void apply (BaseSkeleton *skeleton, float time, float alpha = 1) const; void setKeyframe (int keyframeIndex, float time, float x, float y); @@ -137,8 +129,6 @@ public: ColorTimeline (int keyframeCount); virtual ~ColorTimeline (); - virtual float getDuration () const; - virtual int getKeyframeCount () const; virtual void apply (BaseSkeleton *skeleton, float time, float alpha = 1) const; void setKeyframe (int keyframeIndex, float time, float r, float g, float b, float a); @@ -156,8 +146,6 @@ public: AttachmentTimeline (int keyframeCount); virtual ~AttachmentTimeline (); - virtual float getDuration () const; - virtual int getKeyframeCount () const; virtual void apply (BaseSkeleton *skeleton, float time, float alpha = 1) const; /** The AttachmentTimeline owns the attachmentName. diff --git a/spine-cpp/src/spine/Animation.cpp b/spine-cpp/src/spine/Animation.cpp index 6ae8a18da..145011734 100644 --- a/spine-cpp/src/spine/Animation.cpp +++ b/spine-cpp/src/spine/Animation.cpp @@ -180,14 +180,6 @@ RotateTimeline::~RotateTimeline () { delete[] frames; } -float RotateTimeline::getDuration () const { - return frames[framesLength - 2]; -} - -int RotateTimeline::getKeyframeCount () const { - return framesLength / 2; -} - void RotateTimeline::setKeyframe (int keyframeIndex, float time, float value) { keyframeIndex *= 2; frames[keyframeIndex] = time; @@ -251,14 +243,6 @@ TranslateTimeline::~TranslateTimeline () { delete[] frames; } -float TranslateTimeline::getDuration () const { - return frames[framesLength - 3]; -} - -int TranslateTimeline::getKeyframeCount () const { - return framesLength / 3; -} - void TranslateTimeline::setKeyframe (int keyframeIndex, float time, float x, float y) { keyframeIndex *= 3; frames[keyframeIndex] = time; @@ -347,14 +331,6 @@ ColorTimeline::~ColorTimeline () { delete[] frames; } -float ColorTimeline::getDuration () const { - return frames[framesLength - 5]; -} - -int ColorTimeline::getKeyframeCount () const { - return framesLength / 5; -} - void ColorTimeline::setKeyframe (int keyframeIndex, float time, float r, float g, float b, float a) { keyframeIndex *= 5; frames[keyframeIndex] = time; @@ -428,14 +404,6 @@ AttachmentTimeline::~AttachmentTimeline () { delete[] attachmentNames; } -float AttachmentTimeline::getDuration () const { - return frames[framesLength - 1]; -} - -int AttachmentTimeline::getKeyframeCount () const { - return framesLength; -} - void AttachmentTimeline::setKeyframe (int keyframeIndex, float time, string *attachmentName) { frames[keyframeIndex] = time; if (attachmentNames[keyframeIndex]) delete attachmentNames[keyframeIndex]; diff --git a/spine-cpp/src/spine/BaseSkeletonJson.cpp b/spine-cpp/src/spine/BaseSkeletonJson.cpp index b81e0b1ab..69680bad6 100644 --- a/spine-cpp/src/spine/BaseSkeletonJson.cpp +++ b/spine-cpp/src/spine/BaseSkeletonJson.cpp @@ -23,11 +23,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ +#include #include #include #include +#include #include -#include #include #include #include @@ -38,6 +39,7 @@ using std::string; using std::vector; +using std::max; using std::runtime_error; using std::invalid_argument; @@ -271,7 +273,7 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end, keyframeIndex++; } timelines.push_back(timeline); - if (timeline->getDuration() > duration) duration = timeline->getDuration(); + duration = max(duration, timeline->frames[values.size() * 2 - 2]); } else if (timelineName == TIMELINE_TRANSLATE || timelineName == TIMELINE_SCALE) { TranslateTimeline *timeline; @@ -296,7 +298,7 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end, keyframeIndex++; } timelines.push_back(timeline); - if (timeline->getDuration() > duration) duration = timeline->getDuration(); + duration = max(duration, timeline->frames[values.size() * 3 - 3]); } else { throw runtime_error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"); @@ -333,7 +335,7 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end, keyframeIndex++; } timelines.push_back(timeline); - if (timeline->getDuration() > duration) duration = timeline->getDuration(); + duration = max(duration, timeline->frames[values.size() * 5 - 5]); } else if (timelineName == TIMELINE_ATTACHMENT) { AttachmentTimeline *timeline = new AttachmentTimeline(values.size()); @@ -348,7 +350,7 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end, nameValue.isNull() ? 0 : new string(nameValue.asString())); } timelines.push_back(timeline); - if (timeline->getDuration() > duration) duration = timeline->getDuration(); + duration = max(duration, timeline->frames[values.size() - 1]); } else { throw runtime_error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")"); diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index 0586f51e2..edad2738f 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -44,8 +44,7 @@ public class Animation { return timelines; } - /** Returns the duration of the animation in seconds. Defaults to the max {@link Timeline#getDuration() duration} of the - * timelines. */ + /** Returns the duration of the animation in seconds. */ public float getDuration () { return duration; } @@ -115,13 +114,7 @@ public class Animation { return -1; } - /** The keyframes for a single animation timeline. */ static public interface Timeline { - /** Returns the time in seconds of the last keyframe. */ - public float getDuration (); - - public int getKeyframeCount (); - /** Sets the value(s) for the specified time. */ public void apply (Skeleton skeleton, float time, float alpha); } @@ -138,6 +131,10 @@ public class Animation { curves = new float[(keyframeCount - 1) * 6]; } + public int getKeyframeCount () { + return curves.length / 6 + 1; + } + public void setLinear (int keyframeIndex) { curves[keyframeIndex * 6] = LINEAR; } @@ -215,14 +212,6 @@ public class Animation { frames = new float[keyframeCount * 2]; } - public float getDuration () { - return frames[frames.length - 2]; - } - - public int getKeyframeCount () { - return frames.length / 2; - } - public void setBoneIndex (int boneIndex) { this.boneIndex = boneIndex; } @@ -292,14 +281,6 @@ public class Animation { frames = new float[keyframeCount * 3]; } - public float getDuration () { - return frames[frames.length - 3]; - } - - public int getKeyframeCount () { - return frames.length / 3; - } - public void setBoneIndex (int boneIndex) { this.boneIndex = boneIndex; } @@ -391,14 +372,6 @@ public class Animation { frames = new float[keyframeCount * 5]; } - public float getDuration () { - return frames[frames.length - 5]; - } - - public int getKeyframeCount () { - return frames.length / 5; - } - public void setSlotIndex (int slotIndex) { this.slotIndex = slotIndex; } @@ -468,10 +441,6 @@ public class Animation { attachmentNames = new String[keyframeCount]; } - public float getDuration () { - return frames[frames.length - 1]; - } - public int getKeyframeCount () { return frames.length; } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index e70e54726..a309026cb 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -57,6 +57,8 @@ public class SkeletonBinary { static public final int CURVE_STEPPED = 1; static public final int CURVE_BEZIER = 2; + static private final Color tempColor = new Color(); + private final AttachmentLoader attachmentLoader; private float scale = 1; @@ -208,7 +210,7 @@ public class SkeletonBinary { if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline); } timelines.add(timeline); - duration = Math.max(duration, timeline.getDuration()); + duration = Math.max(duration, timeline.getKeyframes()[keyCount * 2 - 2]); break; } case TIMELINE_TRANSLATE: @@ -228,7 +230,7 @@ public class SkeletonBinary { if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline); } timelines.add(timeline); - duration = Math.max(duration, timeline.getDuration()); + duration = Math.max(duration, timeline.getKeyframes()[keyCount * 3 - 3]); break; default: throw new RuntimeException("Invalid timeline type for a bone: " + timelineType + " (" + boneName + ")"); @@ -250,12 +252,12 @@ public class SkeletonBinary { timeline.setSlotIndex(slotIndex); for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) { float time = input.readFloat(); - Color.rgba8888ToColor(Color.tmp, input.readInt()); - timeline.setKeyframe(keyframeIndex, time, Color.tmp.r, Color.tmp.g, Color.tmp.b, Color.tmp.a); + Color.rgba8888ToColor(tempColor, input.readInt()); + timeline.setKeyframe(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a); if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline); } timelines.add(timeline); - duration = Math.max(duration, timeline.getDuration()); + duration = Math.max(duration, timeline.getKeyframes()[keyCount * 5 - 5]); break; } case TIMELINE_ATTACHMENT: @@ -264,7 +266,7 @@ public class SkeletonBinary { for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) timeline.setKeyframe(keyframeIndex, input.readFloat(), input.readString()); timelines.add(timeline); - duration = Math.max(duration, timeline.getDuration()); + duration = Math.max(duration, timeline.getKeyframes()[keyCount - 1]); break; default: throw new RuntimeException("Invalid timeline type for a slot: " + timelineType + " (" + slotName + ")"); diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index 39af3e585..46628c02a 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -211,7 +211,7 @@ public class SkeletonJson { keyframeIndex++; } timelines.add(timeline); - duration = Math.max(duration, timeline.getDuration()); + duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() * 2 - 2]); } else if (timelineName.equals(TIMELINE_TRANSLATE) || timelineName.equals(TIMELINE_SCALE)) { TranslateTimeline timeline; @@ -234,7 +234,7 @@ public class SkeletonJson { keyframeIndex++; } timelines.add(timeline); - duration = Math.max(duration, timeline.getDuration()); + duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() * 3 - 3]); } else throw new RuntimeException("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"); @@ -264,7 +264,7 @@ public class SkeletonJson { keyframeIndex++; } timelines.add(timeline); - duration = Math.max(duration, timeline.getDuration()); + duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() * 5 - 5]); } else if (timelineName.equals(TIMELINE_ATTACHMENT)) { AttachmentTimeline timeline = new AttachmentTimeline(values.size); @@ -276,7 +276,7 @@ public class SkeletonJson { timeline.setKeyframe(keyframeIndex++, time, (String)valueMap.get("name")); } timelines.add(timeline); - duration = Math.max(duration, timeline.getDuration()); + duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() - 1]); } else throw new RuntimeException("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");