From 2d5b2cdb87504e02c706a98e321cdf9930df52c9 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sun, 31 Aug 2014 15:21:47 +0200 Subject: [PATCH] Refactoring and clean up. --- .../src/Attachments/BoundingBoxAttachment.cs | 5 ++-- spine-csharp/src/Skeleton.cs | 26 +++++++++---------- spine-csharp/src/SkeletonBounds.cs | 3 +-- spine-csharp/src/SkeletonJson.cs | 2 +- .../com/esotericsoftware/spine/Skeleton.java | 26 +++++++++---------- .../spine/SkeletonBinary.java | 2 +- .../spine/SkeletonBounds.java | 3 +-- .../esotericsoftware/spine/SkeletonJson.java | 2 +- .../attachments/BoundingBoxAttachment.java | 7 ++--- 9 files changed, 37 insertions(+), 39 deletions(-) diff --git a/spine-csharp/src/Attachments/BoundingBoxAttachment.cs b/spine-csharp/src/Attachments/BoundingBoxAttachment.cs index 838dbeb55..16c670670 100644 --- a/spine-csharp/src/Attachments/BoundingBoxAttachment.cs +++ b/spine-csharp/src/Attachments/BoundingBoxAttachment.cs @@ -42,9 +42,8 @@ namespace Spine { } /// Must have at least the same length as this attachment's vertices. - public void ComputeWorldVertices (float x, float y, Bone bone, float[] worldVertices) { - x += bone.worldX; - y += bone.worldY; + public void ComputeWorldVertices (Bone bone, float[] worldVertices) { + float x = bone.skeleton.x + bone.worldX, y = bone.skeleton.y + bone.worldY; float m00 = bone.m00; float m01 = bone.m01; float m10 = bone.m10; diff --git a/spine-csharp/src/Skeleton.cs b/spine-csharp/src/Skeleton.cs index 52b63d055..ab6d4d610 100644 --- a/spine-csharp/src/Skeleton.cs +++ b/spine-csharp/src/Skeleton.cs @@ -38,7 +38,7 @@ namespace Spine { internal List slots; internal List drawOrder; internal List ikConstraints = new List(); - private List> bonesCache = new List>(); + private List> boneCache = new List>(); internal Skin skin; internal float r = 1, g = 1, b = 1, a = 1; internal float time; @@ -96,18 +96,18 @@ namespace Spine { /// Caches information about bones and IK constraints. Must be called if bones or IK constraints are added or /// removed. public void UpdateCache () { - List> bonesCache = this.bonesCache; + List> boneCache = this.boneCache; List ikConstraints = this.ikConstraints; int ikConstraintsCount = ikConstraints.Count; int arrayCount = ikConstraintsCount + 1; - if (bonesCache.Count > arrayCount) bonesCache.RemoveRange(arrayCount, bonesCache.Count - arrayCount); - for (int i = 0, n = bonesCache.Count; i < n; i++) - bonesCache[i].Clear(); - while (bonesCache.Count < arrayCount) - bonesCache.Add(new List()); + if (boneCache.Count > arrayCount) boneCache.RemoveRange(arrayCount, boneCache.Count - arrayCount); + for (int i = 0, n = boneCache.Count; i < n; i++) + boneCache[i].Clear(); + while (boneCache.Count < arrayCount) + boneCache.Add(new List()); - List nonIkBones = bonesCache[0]; + List nonIkBones = boneCache[0]; for (int i = 0, n = bones.Count; i < n; i++) { Bone bone = bones[i]; @@ -119,8 +119,8 @@ namespace Spine { Bone child = ikConstraint.bones[ikConstraint.bones.Count - 1]; while (true) { if (current == child) { - bonesCache[ii].Add(bone); - bonesCache[ii + 1].Add(bone); + boneCache[ii].Add(bone); + boneCache[ii + 1].Add(bone); goto outer; } if (child == parent) break; @@ -141,11 +141,11 @@ namespace Spine { Bone bone = bones[ii]; bone.rotationIK = bone.rotation; } - List> bonesCache = this.bonesCache; + List> boneCache = this.boneCache; List ikConstraints = this.ikConstraints; - int i = 0, last = bonesCache.Count - 1; + int i = 0, last = boneCache.Count - 1; while (true) { - List updateBones = bonesCache[i]; + List updateBones = boneCache[i]; for (int ii = 0, nn = updateBones.Count; ii < nn; ii++) updateBones[ii].UpdateWorldTransform(); if (i == last) break; diff --git a/spine-csharp/src/SkeletonBounds.cs b/spine-csharp/src/SkeletonBounds.cs index 3e434a8f4..4c546d76c 100644 --- a/spine-csharp/src/SkeletonBounds.cs +++ b/spine-csharp/src/SkeletonBounds.cs @@ -55,7 +55,6 @@ namespace Spine { List polygons = Polygons; List slots = skeleton.slots; int slotCount = slots.Count; - float x = skeleton.x, y = skeleton.y; boundingBoxes.Clear(); foreach (Polygon polygon in polygons) @@ -80,7 +79,7 @@ namespace Spine { int count = boundingBox.Vertices.Length; polygon.Count = count; if (polygon.Vertices.Length < count) polygon.Vertices = new float[count]; - boundingBox.ComputeWorldVertices(x, y, slot.bone, polygon.Vertices); + boundingBox.ComputeWorldVertices(slot.bone, polygon.Vertices); } if (updateAabb) aabbCompute(); diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index 59283314b..8ad08bb6e 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -93,8 +93,8 @@ namespace Spine { // Skeleton. if (root.ContainsKey("skeleton")) { var skeletonMap = (Dictionary)root["skeleton"]; - skeletonData.version = (String)skeletonMap["spine"]; skeletonData.hash = (String)skeletonMap["hash"]; + skeletonData.version = (String)skeletonMap["spine"]; skeletonData.width = GetFloat(skeletonMap, "width", 0); skeletonData.height = GetFloat(skeletonMap, "width", 1); } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index 427bf7d9d..1961d7e9b 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -41,7 +41,7 @@ public class Skeleton { final Array slots; Array drawOrder; final Array ikConstraints; - private final Array> bonesCache = new Array(); + private final Array> boneCache = new Array(); Skin skin; final Color color; float time; @@ -117,18 +117,18 @@ public class Skeleton { /** Caches information about bones and IK constraints. Must be called if bones or IK constraints are added or removed. */ public void updateCache () { - Array> bonesCache = this.bonesCache; + Array> boneCache = this.boneCache; Array ikConstraints = this.ikConstraints; int ikConstraintsCount = ikConstraints.size; int arrayCount = ikConstraintsCount + 1; - bonesCache.truncate(arrayCount); - for (int i = 0, n = bonesCache.size; i < n; i++) - bonesCache.get(i).clear(); - while (bonesCache.size < arrayCount) - bonesCache.add(new Array()); + boneCache.truncate(arrayCount); + for (int i = 0, n = boneCache.size; i < n; i++) + boneCache.get(i).clear(); + while (boneCache.size < arrayCount) + boneCache.add(new Array()); - Array nonIkBones = bonesCache.first(); + Array nonIkBones = boneCache.first(); outer: for (int i = 0, n = bones.size; i < n; i++) { @@ -141,8 +141,8 @@ public class Skeleton { Bone child = ikConstraint.bones.peek(); while (true) { if (current == child) { - bonesCache.get(ii).add(bone); - bonesCache.get(ii + 1).add(bone); + boneCache.get(ii).add(bone); + boneCache.get(ii + 1).add(bone); continue outer; } if (child == parent) break; @@ -162,11 +162,11 @@ public class Skeleton { Bone bone = bones.get(i); bone.rotationIK = bone.rotation; } - Array> bonesCache = this.bonesCache; + Array> boneCache = this.boneCache; Array ikConstraints = this.ikConstraints; - int i = 0, last = bonesCache.size - 1; + int i = 0, last = boneCache.size - 1; while (true) { - Array updateBones = bonesCache.get(i); + Array updateBones = boneCache.get(i); for (int ii = 0, nn = updateBones.size; ii < nn; ii++) updateBones.get(ii).updateWorldTransform(); if (i == last) break; diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index 33d2e8d1e..e42849a9b 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -107,8 +107,8 @@ public class SkeletonBinary { DataInput input = new DataInput(file.read(512)); try { - skeletonData.version = input.readString(); skeletonData.hash = input.readString(); + skeletonData.version = input.readString(); skeletonData.width = input.readFloat(); skeletonData.height = input.readFloat(); diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBounds.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBounds.java index 11394e17f..d3dd4444c 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBounds.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBounds.java @@ -52,7 +52,6 @@ public class SkeletonBounds { Array polygons = this.polygons; Array slots = skeleton.slots; int slotCount = slots.size; - float x = skeleton.getX(), y = skeleton.getY(); boundingBoxes.clear(); polygonPool.freeAll(polygons); @@ -71,7 +70,7 @@ public class SkeletonBounds { polygon.ensureCapacity(vertexCount); polygon.size = vertexCount; - boundingBox.computeWorldVertices(x, y, slot.bone, polygon.items); + boundingBox.computeWorldVertices(slot.bone, polygon.items); } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index e137b9a85..28b33db70 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -93,8 +93,8 @@ public class SkeletonJson { // Skeleton. JsonValue skeletonMap = root.get("skeleton"); if (skeletonMap != null) { - skeletonData.version = skeletonMap.getString("spine"); skeletonData.hash = skeletonMap.getString("hash"); + skeletonData.version = skeletonMap.getString("spine"); skeletonData.width = skeletonMap.getFloat("width"); skeletonData.height = skeletonMap.getFloat("height"); } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/BoundingBoxAttachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/BoundingBoxAttachment.java index f6b01ba38..e55390181 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/BoundingBoxAttachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/BoundingBoxAttachment.java @@ -31,6 +31,7 @@ package com.esotericsoftware.spine.attachments; import com.esotericsoftware.spine.Bone; +import com.esotericsoftware.spine.Skeleton; public class BoundingBoxAttachment extends Attachment { private float[] vertices; @@ -39,9 +40,9 @@ public class BoundingBoxAttachment extends Attachment { super(name); } - public void computeWorldVertices (float x, float y, Bone bone, float[] worldVertices) { - x += bone.getWorldX(); - y += bone.getWorldY(); + public void computeWorldVertices (Bone bone, float[] worldVertices) { + Skeleton skeleton = bone.getSkeleton(); + float x = skeleton.getX() + bone.getWorldX(), y = skeleton.getY() + bone.getWorldY(); float m00 = bone.getM00(); float m01 = bone.getM01(); float m10 = bone.getM10();