From 8d19504bd7d3788380a0b09ff35358a221f1bf5a Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Thu, 9 Jun 2016 19:31:05 +0200 Subject: [PATCH] Fixed binary path loading. --- .../spine/PathConstraint.java | 28 ++++++++----------- .../spine/SkeletonBinary.java | 13 +++++---- .../esotericsoftware/spine/SkeletonJson.java | 3 +- .../spine/attachments/PathAttachment.java | 9 ++++-- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java index a0253d870..1d519d6b2 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java @@ -144,18 +144,14 @@ public class PathConstraint implements Updatable { boolean percentSpacing) { Slot target = this.target; float position = this.position; - int verticesLength = path.getWorldVerticesLength(), curveCount = verticesLength / 6, lastCurve = NONE; float[] spaces = this.spaces.items, out = this.positions.setSize(spacesCount * 3 + 2), world; boolean closed = path.getClosed(); + int verticesLength = path.getWorldVerticesLength(), curveCount = verticesLength / 6, prevCurve = NONE; if (!path.getConstantSpeed()) { - float[] lengths = path.getLengths().items; - float pathLength; - if (closed) { - curveCount--; - pathLength = lengths[curveCount]; - } else - pathLength = lengths[curveCount - 2]; + float[] lengths = path.getLengths(); + curveCount -= closed ? 1 : 2; + float pathLength = lengths[curveCount]; if (percentPosition) position *= pathLength; if (percentSpacing) { for (int i = 0; i < spacesCount; i++) @@ -172,15 +168,15 @@ public class PathConstraint implements Updatable { if (p < 0) p += pathLength; curve = 0; } else if (p < 0) { - if (lastCurve != BEFORE) { - lastCurve = BEFORE; + if (prevCurve != BEFORE) { + prevCurve = BEFORE; path.computeWorldVertices(target, 2, 4, world, 0); } addBeforePosition(p, world, 0, out, o); continue; } else if (p > pathLength) { - if (lastCurve != AFTER) { - lastCurve = AFTER; + if (prevCurve != AFTER) { + prevCurve = AFTER; path.computeWorldVertices(target, verticesLength - 6, 4, world, 0); } addAfterPosition(p - pathLength, world, 0, out, o); @@ -199,8 +195,8 @@ public class PathConstraint implements Updatable { } break; } - if (curve != lastCurve) { - lastCurve = curve; + if (curve != prevCurve) { + prevCurve = curve; if (closed && curve == curveCount) { path.computeWorldVertices(target, verticesLength - 4, 4, world, 0); path.computeWorldVertices(target, 0, 4, world, 4); @@ -303,8 +299,8 @@ public class PathConstraint implements Updatable { } // Curve segment lengths. - if (curve != lastCurve) { - lastCurve = curve; + if (curve != prevCurve) { + prevCurve = curve; int ii = curve * 6; x1 = world[ii]; y1 = world[ii + 1]; diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index 1a556c90c..36e54b601 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -31,6 +31,7 @@ package com.esotericsoftware.spine; +import java.io.EOFException; import java.io.IOException; import com.badlogic.gdx.files.FileHandle; @@ -138,6 +139,8 @@ public class SkeletonBinary { for (int i = 0; i < byteCount;) { int b = read(); switch (b >> 4) { + case -1: + throw new EOFException(); case 12: case 13: chars[charCount++] = (char)((b & 0x1F) << 6 | read() & 0x3F); @@ -442,7 +445,7 @@ public class SkeletonBinary { path.setWorldVerticesLength(vertexCount << 1); path.setVertices(vertices.vertices); path.setBones(vertices.bones); - path.getLengths().addAll(lengths); + path.setLengths(lengths); if (nonessential) Color.rgba8888ToColor(path.getColor(), color); return path; } @@ -632,6 +635,7 @@ public class SkeletonBinary { } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[(frameCount - 1) * PathConstraintPositionTimeline.ENTRIES]); + break; } case PATH_MIX: { PathConstraintMixTimeline timeline = new PathConstraintMixTimeline(frameCount); @@ -642,6 +646,7 @@ public class SkeletonBinary { } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[(frameCount - 1) * PathConstraintMixTimeline.ENTRIES]); + break; } } } @@ -744,11 +749,7 @@ public class SkeletonBinary { timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[eventCount - 1]); } - } catch ( - - IOException ex) - - { + } catch (IOException ex) { throw new SerializationException("Error reading skeleton file.", ex); } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index 95c0a2918..b966f3cc7 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -359,10 +359,11 @@ public class SkeletonJson { int vertexCount = map.getInt("vertexCount"); readVertices(map, path, vertexCount << 1); - float[] lengths = path.getLengths().setSize(vertexCount / 3); + float[] lengths = new float[vertexCount / 3]; int i = 0; for (JsonValue curves = map.require("lengths").child; curves != null; curves = curves.next) lengths[i++] = curves.asFloat() * scale; + path.setLengths(lengths); String color = map.getString("color", null); if (color != null) path.getColor().set(Color.valueOf(color)); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/PathAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/PathAttachment.java index 43c4f3e0a..229be6d47 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/PathAttachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/PathAttachment.java @@ -32,11 +32,10 @@ package com.esotericsoftware.spine.attachments; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.utils.FloatArray; import com.esotericsoftware.spine.Slot; public class PathAttachment extends VertexAttachment { - final FloatArray lengths = new FloatArray(); + float[] lengths; boolean closed, constantSpeed; // Nonessential. @@ -71,10 +70,14 @@ public class PathAttachment extends VertexAttachment { } /** Returns the length in the setup pose from the start of the path to the end of each curve. */ - public FloatArray getLengths () { + public float[] getLengths () { return lengths; } + public void setLengths (float[] lengths) { + this.lengths = lengths; + } + public Color getColor () { return color; }