mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
Refactoring and clean up.
This commit is contained in:
parent
2cfb6ad980
commit
2d5b2cdb87
@ -42,9 +42,8 @@ namespace Spine {
|
||||
}
|
||||
|
||||
/// <param name="worldVertices">Must have at least the same length as this attachment's vertices.</param>
|
||||
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;
|
||||
|
||||
@ -38,7 +38,7 @@ namespace Spine {
|
||||
internal List<Slot> slots;
|
||||
internal List<Slot> drawOrder;
|
||||
internal List<IkConstraint> ikConstraints = new List<IkConstraint>();
|
||||
private List<List<Bone>> bonesCache = new List<List<Bone>>();
|
||||
private List<List<Bone>> boneCache = new List<List<Bone>>();
|
||||
internal Skin skin;
|
||||
internal float r = 1, g = 1, b = 1, a = 1;
|
||||
internal float time;
|
||||
@ -96,18 +96,18 @@ namespace Spine {
|
||||
/// <summary>Caches information about bones and IK constraints. Must be called if bones or IK constraints are added or
|
||||
/// removed.</summary>
|
||||
public void UpdateCache () {
|
||||
List<List<Bone>> bonesCache = this.bonesCache;
|
||||
List<List<Bone>> boneCache = this.boneCache;
|
||||
List<IkConstraint> 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<Bone>());
|
||||
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<Bone>());
|
||||
|
||||
List<Bone> nonIkBones = bonesCache[0];
|
||||
List<Bone> 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<List<Bone>> bonesCache = this.bonesCache;
|
||||
List<List<Bone>> boneCache = this.boneCache;
|
||||
List<IkConstraint> ikConstraints = this.ikConstraints;
|
||||
int i = 0, last = bonesCache.Count - 1;
|
||||
int i = 0, last = boneCache.Count - 1;
|
||||
while (true) {
|
||||
List<Bone> updateBones = bonesCache[i];
|
||||
List<Bone> updateBones = boneCache[i];
|
||||
for (int ii = 0, nn = updateBones.Count; ii < nn; ii++)
|
||||
updateBones[ii].UpdateWorldTransform();
|
||||
if (i == last) break;
|
||||
|
||||
@ -55,7 +55,6 @@ namespace Spine {
|
||||
List<Polygon> polygons = Polygons;
|
||||
List<Slot> 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();
|
||||
|
||||
@ -93,8 +93,8 @@ namespace Spine {
|
||||
// Skeleton.
|
||||
if (root.ContainsKey("skeleton")) {
|
||||
var skeletonMap = (Dictionary<String, Object>)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);
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ public class Skeleton {
|
||||
final Array<Slot> slots;
|
||||
Array<Slot> drawOrder;
|
||||
final Array<IkConstraint> ikConstraints;
|
||||
private final Array<Array<Bone>> bonesCache = new Array();
|
||||
private final Array<Array<Bone>> 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<Array<Bone>> bonesCache = this.bonesCache;
|
||||
Array<Array<Bone>> boneCache = this.boneCache;
|
||||
Array<IkConstraint> 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<Bone> nonIkBones = bonesCache.first();
|
||||
Array<Bone> 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<Array<Bone>> bonesCache = this.bonesCache;
|
||||
Array<Array<Bone>> boneCache = this.boneCache;
|
||||
Array<IkConstraint> ikConstraints = this.ikConstraints;
|
||||
int i = 0, last = bonesCache.size - 1;
|
||||
int i = 0, last = boneCache.size - 1;
|
||||
while (true) {
|
||||
Array<Bone> updateBones = bonesCache.get(i);
|
||||
Array<Bone> updateBones = boneCache.get(i);
|
||||
for (int ii = 0, nn = updateBones.size; ii < nn; ii++)
|
||||
updateBones.get(ii).updateWorldTransform();
|
||||
if (i == last) break;
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -52,7 +52,6 @@ public class SkeletonBounds {
|
||||
Array<FloatArray> polygons = this.polygons;
|
||||
Array<Slot> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user