[libgdx] Prefer direct array access.

Already did it some places, might as well do it everywhere.
This commit is contained in:
Nathan Sweet 2020-04-02 00:11:24 +02:00
parent a28f490c45
commit adc3bbb774
13 changed files with 218 additions and 208 deletions

View File

@ -66,8 +66,9 @@ public class Animation {
this.timelines = timelines; this.timelines = timelines;
timelineIds.clear(); timelineIds.clear();
Object[] items = timelines.items;
for (int i = 0, n = timelines.size; i < n; i++) for (int i = 0, n = timelines.size; i < n; i++)
timelineIds.addAll(timelines.get(i).getPropertyIds()); timelineIds.addAll(((Timeline)items[i]).getPropertyIds());
} }
/** Returns true if this animation contains a timeline with any of the specified property IDs. */ /** Returns true if this animation contains a timeline with any of the specified property IDs. */
@ -1361,25 +1362,25 @@ public class Animation {
public void apply (Skeleton skeleton, float lastTime, float time, @Null Array<Event> events, float alpha, MixBlend blend, public void apply (Skeleton skeleton, float lastTime, float time, @Null Array<Event> events, float alpha, MixBlend blend,
MixDirection direction) { MixDirection direction) {
Array<Slot> drawOrder = skeleton.drawOrder; Object[] drawOrder = skeleton.drawOrder.items;
Array<Slot> slots = skeleton.slots;
if (direction == out) { if (direction == out) {
if (blend == setup) arraycopy(slots.items, 0, drawOrder.items, 0, slots.size); if (blend == setup) arraycopy(skeleton.slots.items, 0, drawOrder, 0, skeleton.slots.size);
return; return;
} }
float[] frames = this.frames; float[] frames = this.frames;
if (time < frames[0]) { // Time is before first frame. if (time < frames[0]) { // Time is before first frame.
if (blend == setup || blend == first) arraycopy(slots.items, 0, drawOrder.items, 0, slots.size); if (blend == setup || blend == first) arraycopy(skeleton.slots.items, 0, drawOrder, 0, skeleton.slots.size);
return; return;
} }
int[] drawOrderToSetupIndex = drawOrders[search(frames, time)]; int[] drawOrderToSetupIndex = drawOrders[search(frames, time)];
if (drawOrderToSetupIndex == null) if (drawOrderToSetupIndex == null)
arraycopy(slots.items, 0, drawOrder.items, 0, slots.size); arraycopy(skeleton.slots.items, 0, drawOrder, 0, skeleton.slots.size);
else { else {
Object[] slots = skeleton.slots.items;
for (int i = 0, n = drawOrderToSetupIndex.length; i < n; i++) for (int i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
drawOrder.set(i, slots.get(drawOrderToSetupIndex[i])); drawOrder[i] = slots[drawOrderToSetupIndex[i]];
} }
} }
} }

View File

@ -112,8 +112,9 @@ public class AnimationState {
/** Increments each track entry {@link TrackEntry#getTrackTime()}, setting queued animations as current if needed. */ /** Increments each track entry {@link TrackEntry#getTrackTime()}, setting queued animations as current if needed. */
public void update (float delta) { public void update (float delta) {
delta *= timeScale; delta *= timeScale;
for (int i = 0, n = tracks.size; i < n; i++) { Object[] tracks = this.tracks.items;
TrackEntry current = tracks.get(i); for (int i = 0, n = this.tracks.size; i < n; i++) {
TrackEntry current = (TrackEntry)tracks[i];
if (current == null) continue; if (current == null) continue;
current.animationLast = current.nextAnimationLast; current.animationLast = current.nextAnimationLast;
@ -145,7 +146,7 @@ public class AnimationState {
} }
} else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) { } else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
// Clear the track when there is no next entry, the track end time is reached, and there is no mixingFrom. // Clear the track when there is no next entry, the track end time is reached, and there is no mixingFrom.
tracks.set(i, null); tracks[i] = null;
queue.end(current); queue.end(current);
disposeNext(current); disposeNext(current);
continue; continue;
@ -203,8 +204,9 @@ public class AnimationState {
Array<Event> events = this.events; Array<Event> events = this.events;
boolean applied = false; boolean applied = false;
for (int i = 0, n = tracks.size; i < n; i++) { Object[] tracks = this.tracks.items;
TrackEntry current = tracks.get(i); for (int i = 0, n = this.tracks.size; i < n; i++) {
TrackEntry current = (TrackEntry)tracks[i];
if (current == null || current.delay > 0) continue; if (current == null || current.delay > 0) continue;
applied = true; applied = true;
@ -459,10 +461,10 @@ public class AnimationState {
float trackLastWrapped = entry.trackLast % duration; float trackLastWrapped = entry.trackLast % duration;
// Queue events before complete. // Queue events before complete.
Array<Event> events = this.events; Object[] events = this.events.items;
int i = 0, n = events.size; int i = 0, n = this.events.size;
for (; i < n; i++) { for (; i < n; i++) {
Event event = events.get(i); Event event = (Event)events[i];
if (event.time < trackLastWrapped) break; if (event.time < trackLastWrapped) break;
if (event.time > animationEnd) continue; // Discard events outside animation start/end. if (event.time > animationEnd) continue; // Discard events outside animation start/end.
queue.event(entry, event); queue.event(entry, event);
@ -478,9 +480,9 @@ public class AnimationState {
// Queue events after complete. // Queue events after complete.
for (; i < n; i++) { for (; i < n; i++) {
Event event = events.get(i); Event event = (Event)events[i];
if (event.time < animationStart) continue; // Discard events outside animation start/end. if (event.time < animationStart) continue; // Discard events outside animation start/end.
queue.event(entry, events.get(i)); queue.event(entry, event);
} }
} }
@ -681,8 +683,9 @@ public class AnimationState {
public void setEmptyAnimations (float mixDuration) { public void setEmptyAnimations (float mixDuration) {
boolean oldDrainDisabled = queue.drainDisabled; boolean oldDrainDisabled = queue.drainDisabled;
queue.drainDisabled = true; queue.drainDisabled = true;
for (int i = 0, n = tracks.size; i < n; i++) { Object[] tracks = this.tracks.items;
TrackEntry current = tracks.get(i); for (int i = 0, n = this.tracks.size; i < n; i++) {
TrackEntry current = (TrackEntry)tracks[i];
if (current != null) setEmptyAnimation(current.trackIndex, mixDuration); if (current != null) setEmptyAnimation(current.trackIndex, mixDuration);
} }
queue.drainDisabled = oldDrainDisabled; queue.drainDisabled = oldDrainDisabled;
@ -740,8 +743,10 @@ public class AnimationState {
// Process in the order that animations are applied. // Process in the order that animations are applied.
propertyIds.clear(2048); propertyIds.clear(2048);
for (int i = 0, n = tracks.size; i < n; i++) { int n = tracks.size;
TrackEntry entry = tracks.get(i); Object[] tracks = this.tracks.items;
for (int i = 0; i < n; i++) {
TrackEntry entry = (TrackEntry)tracks[i];
if (entry == null) continue; if (entry == null) continue;
while (entry.mixingFrom != null) // Move to last entry, then iterate in reverse. while (entry.mixingFrom != null) // Move to last entry, then iterate in reverse.
entry = entry.mixingFrom; entry = entry.mixingFrom;
@ -753,8 +758,8 @@ public class AnimationState {
// Process in the reverse order that animations are applied. // Process in the reverse order that animations are applied.
propertyIds.clear(2048); propertyIds.clear(2048);
for (int i = tracks.size - 1; i >= 0; i--) { for (int i = n - 1; i >= 0; i--) {
TrackEntry entry = tracks.get(i); TrackEntry entry = (TrackEntry)tracks[i];
while (entry != null) { while (entry != null) {
computeNotLast(entry); computeNotLast(entry);
entry = entry.mixingFrom; entry = entry.mixingFrom;
@ -877,8 +882,9 @@ public class AnimationState {
public String toString () { public String toString () {
StringBuilder buffer = new StringBuilder(64); StringBuilder buffer = new StringBuilder(64);
for (int i = 0, n = tracks.size; i < n; i++) { Object[] tracks = this.tracks.items;
TrackEntry entry = tracks.get(i); for (int i = 0, n = this.tracks.size; i < n; i++) {
TrackEntry entry = (TrackEntry)tracks[i];
if (entry == null) continue; if (entry == null) continue;
if (buffer.length() > 0) buffer.append(", "); if (buffer.length() > 0) buffer.append(", ");
buffer.append(entry.toString()); buffer.append(entry.toString());
@ -1269,11 +1275,11 @@ public class AnimationState {
if (drainDisabled) return; // Not reentrant. if (drainDisabled) return; // Not reentrant.
drainDisabled = true; drainDisabled = true;
Array objects = this.objects; Object[] objects = this.objects.items;
SnapshotArray<AnimationStateListener> listenersArray = AnimationState.this.listeners; SnapshotArray<AnimationStateListener> listenersArray = AnimationState.this.listeners;
for (int i = 0; i < objects.size; i += 2) { for (int i = 0; i < this.objects.size; i += 2) {
EventType type = (EventType)objects.get(i); EventType type = (EventType)objects[i];
TrackEntry entry = (TrackEntry)objects.get(i + 1); TrackEntry entry = (TrackEntry)objects[i + 1];
int listenersCount = listenersArray.size; int listenersCount = listenersArray.size;
Object[] listeners = listenersArray.begin(); Object[] listeners = listenersArray.begin();
switch (type) { switch (type) {
@ -1304,7 +1310,7 @@ public class AnimationState {
((AnimationStateListener)listeners[ii]).complete(entry); ((AnimationStateListener)listeners[ii]).complete(entry);
break; break;
case event: case event:
Event event = (Event)objects.get(i++ + 2); Event event = (Event)objects[i++ + 2];
if (entry.listener != null) entry.listener.event(entry, event); if (entry.listener != null) entry.listener.event(entry, event);
for (int ii = 0; ii < listenersCount; ii++) for (int ii = 0; ii < listenersCount; ii++)
((AnimationStateListener)listeners[ii]).event(entry, event); ((AnimationStateListener)listeners[ii]).event(entry, event);

View File

@ -86,13 +86,13 @@ public class IkConstraint implements Updatable {
public void update () { public void update () {
Bone target = this.target; Bone target = this.target;
Array<Bone> bones = this.bones; Object[] bones = this.bones.items;
switch (bones.size) { switch (this.bones.size) {
case 1: case 1:
apply(bones.first(), target.worldX, target.worldY, compress, stretch, data.uniform, mix); apply((Bone)bones[0], target.worldX, target.worldY, compress, stretch, data.uniform, mix);
break; break;
case 2: case 2:
apply(bones.first(), bones.get(1), target.worldX, target.worldY, bendDirection, stretch, softness, mix); apply((Bone)bones[0], (Bone)bones[1], target.worldX, target.worldY, bendDirection, stretch, softness, mix);
break; break;
} }
} }

View File

@ -68,22 +68,23 @@ public class Skeleton {
this.data = data; this.data = data;
bones = new Array(data.bones.size); bones = new Array(data.bones.size);
Object[] bones = this.bones.items;
for (BoneData boneData : data.bones) { for (BoneData boneData : data.bones) {
Bone bone; Bone bone;
if (boneData.parent == null) if (boneData.parent == null)
bone = new Bone(boneData, this, null); bone = new Bone(boneData, this, null);
else { else {
Bone parent = bones.get(boneData.parent.index); Bone parent = (Bone)bones[boneData.parent.index];
bone = new Bone(boneData, this, parent); bone = new Bone(boneData, this, parent);
parent.children.add(bone); parent.children.add(bone);
} }
bones.add(bone); this.bones.add(bone);
} }
slots = new Array(data.slots.size); slots = new Array(data.slots.size);
drawOrder = new Array(data.slots.size); drawOrder = new Array(data.slots.size);
for (SlotData slotData : data.slots) { for (SlotData slotData : data.slots) {
Bone bone = bones.get(slotData.boneData.index); Bone bone = (Bone)bones[slotData.boneData.index];
Slot slot = new Slot(slotData, bone); Slot slot = new Slot(slotData, bone);
slots.add(slot); slots.add(slot);
drawOrder.add(slot); drawOrder.add(slot);
@ -253,17 +254,17 @@ public class Skeleton {
Attachment attachment = slot.attachment; Attachment attachment = slot.attachment;
if (attachment instanceof PathAttachment) sortPathConstraintAttachment(attachment, slotBone); if (attachment instanceof PathAttachment) sortPathConstraintAttachment(attachment, slotBone);
Array<Bone> constrained = constraint.bones; Object[] constrained = constraint.bones.items;
int boneCount = constrained.size; int boneCount = constraint.bones.size;
for (int i = 0; i < boneCount; i++) for (int i = 0; i < boneCount; i++)
sortBone(constrained.get(i)); sortBone((Bone)constrained[i]);
updateCache.add(constraint); updateCache.add(constraint);
for (int i = 0; i < boneCount; i++) for (int i = 0; i < boneCount; i++)
sortReset(constrained.get(i).children); sortReset(((Bone)constrained[i]).children);
for (int i = 0; i < boneCount; i++) for (int i = 0; i < boneCount; i++)
constrained.get(i).sorted = true; ((Bone)constrained[i]).sorted = true;
} }
private void sortTransformConstraint (TransformConstraint constraint) { private void sortTransformConstraint (TransformConstraint constraint) {
@ -273,25 +274,25 @@ public class Skeleton {
sortBone(constraint.target); sortBone(constraint.target);
Array<Bone> constrained = constraint.bones; Object[] constrained = constraint.bones.items;
int boneCount = constrained.size; int boneCount = constraint.bones.size;
if (constraint.data.local) { if (constraint.data.local) {
for (int i = 0; i < boneCount; i++) { for (int i = 0; i < boneCount; i++) {
Bone child = constrained.get(i); Bone child = (Bone)constrained[i];
sortBone(child.parent); sortBone(child.parent);
if (!updateCache.contains(child, true)) updateCacheReset.add(child); if (!updateCache.contains(child, true)) updateCacheReset.add(child);
} }
} else { } else {
for (int i = 0; i < boneCount; i++) for (int i = 0; i < boneCount; i++)
sortBone(constrained.get(i)); sortBone((Bone)constrained[i]);
} }
updateCache.add(constraint); updateCache.add(constraint);
for (int i = 0; i < boneCount; i++) for (int i = 0; i < boneCount; i++)
sortReset(constrained.get(i).children); sortReset(((Bone)constrained[i]).children);
for (int i = 0; i < boneCount; i++) for (int i = 0; i < boneCount; i++)
constrained.get(i).sorted = true; ((Bone)constrained[i]).sorted = true;
} }
private void sortPathConstraintAttachment (Skin skin, int slotIndex, Bone slotBone) { private void sortPathConstraintAttachment (Skin skin, int slotIndex, Bone slotBone) {
@ -308,12 +309,12 @@ public class Skeleton {
if (pathBones == null) if (pathBones == null)
sortBone(slotBone); sortBone(slotBone);
else { else {
Array<Bone> bones = this.bones; Object[] bones = this.bones.items;
for (int i = 0, n = pathBones.length; i < n;) { for (int i = 0, n = pathBones.length; i < n;) {
int nn = pathBones[i++]; int nn = pathBones[i++];
nn += i; nn += i;
while (i < nn) while (i < nn)
sortBone(bones.get(pathBones[i++])); sortBone((Bone)bones[pathBones[i++]]);
} }
} }
} }
@ -327,8 +328,9 @@ public class Skeleton {
} }
private void sortReset (Array<Bone> bones) { private void sortReset (Array<Bone> bones) {
Object[] items = bones.items;
for (int i = 0, n = bones.size; i < n; i++) { for (int i = 0, n = bones.size; i < n; i++) {
Bone bone = bones.get(i); Bone bone = (Bone)items[i];
if (!bone.active) continue; if (!bone.active) continue;
if (bone.sorted) sortReset(bone.children); if (bone.sorted) sortReset(bone.children);
bone.sorted = false; bone.sorted = false;
@ -343,9 +345,9 @@ public class Skeleton {
// This partial update avoids computing the world transform for constrained bones when 1) the bone is not updated // This partial update avoids computing the world transform for constrained bones when 1) the bone is not updated
// before the constraint, 2) the constraint only needs to access the applied local transform, and 3) the constraint calls // before the constraint, 2) the constraint only needs to access the applied local transform, and 3) the constraint calls
// updateWorldTransform. // updateWorldTransform.
Array<Bone> updateCacheReset = this.updateCacheReset; Object[] updateCacheReset = this.updateCacheReset.items;
for (int i = 0, n = updateCacheReset.size; i < n; i++) { for (int i = 0, n = this.updateCacheReset.size; i < n; i++) {
Bone bone = updateCacheReset.get(i); Bone bone = (Bone)updateCacheReset[i];
bone.ax = bone.x; bone.ax = bone.x;
bone.ay = bone.y; bone.ay = bone.y;
bone.arotation = bone.rotation; bone.arotation = bone.rotation;
@ -355,9 +357,9 @@ public class Skeleton {
bone.ashearY = bone.shearY; bone.ashearY = bone.shearY;
bone.appliedValid = true; bone.appliedValid = true;
} }
Array<Updatable> updateCache = this.updateCache; Object[] updateCache = this.updateCache.items;
for (int i = 0, n = updateCache.size; i < n; i++) for (int i = 0, n = this.updateCache.size; i < n; i++)
updateCache.get(i).update(); ((Updatable)updateCache[i]).update();
} }
/** Temporarily sets the root bone as a child of the specified bone, then updates the world transform for each bone and applies /** Temporarily sets the root bone as a child of the specified bone, then updates the world transform for each bone and applies
@ -367,12 +369,13 @@ public class Skeleton {
* Runtimes Guide. */ * Runtimes Guide. */
public void updateWorldTransform (Bone parent) { public void updateWorldTransform (Bone parent) {
if (parent == null) throw new IllegalArgumentException("parent cannot be null."); if (parent == null) throw new IllegalArgumentException("parent cannot be null.");
// This partial update avoids computing the world transform for constrained bones when 1) the bone is not updated // This partial update avoids computing the world transform for constrained bones when:
// before the constraint, 2) the constraint only needs to access the applied local transform, and 3) the constraint calls // 1) the bone is not updated before the constraint,
// updateWorldTransform. // 2) the constraint only needs to access the applied local transform, and
Array<Bone> updateCacheReset = this.updateCacheReset; // 3) the constraint calls updateWorldTransform.
for (int i = 0, n = updateCacheReset.size; i < n; i++) { Object[] updateCacheReset = this.updateCacheReset.items;
Bone bone = updateCacheReset.get(i); for (int i = 0, n = this.updateCacheReset.size; i < n; i++) {
Bone bone = (Bone)updateCacheReset[i];
bone.ax = bone.x; bone.ax = bone.x;
bone.ay = bone.y; bone.ay = bone.y;
bone.arotation = bone.rotation; bone.arotation = bone.rotation;
@ -400,9 +403,9 @@ public class Skeleton {
rootBone.d = (pc * lb + pd * ld) * scaleY; rootBone.d = (pc * lb + pd * ld) * scaleY;
// Update everything except root bone. // Update everything except root bone.
Array<Updatable> updateCache = this.updateCache; Object[] updateCache = this.updateCache.items;
for (int i = 0, n = updateCache.size; i < n; i++) { for (int i = 0, n = this.updateCache.size; i < n; i++) {
Updatable updatable = updateCache.get(i); Updatable updatable = (Updatable)updateCache[i];
if (updatable != rootBone) updatable.update(); if (updatable != rootBone) updatable.update();
} }
} }
@ -415,13 +418,13 @@ public class Skeleton {
/** Sets the bones and constraints to their setup pose values. */ /** Sets the bones and constraints to their setup pose values. */
public void setBonesToSetupPose () { public void setBonesToSetupPose () {
Array<Bone> bones = this.bones; Object[] bones = this.bones.items;
for (int i = 0, n = bones.size; i < n; i++) for (int i = 0, n = this.bones.size; i < n; i++)
bones.get(i).setToSetupPose(); ((Bone)bones[i]).setToSetupPose();
Array<IkConstraint> ikConstraints = this.ikConstraints; Object[] ikConstraints = this.ikConstraints.items;
for (int i = 0, n = ikConstraints.size; i < n; i++) { for (int i = 0, n = this.ikConstraints.size; i < n; i++) {
IkConstraint constraint = ikConstraints.get(i); IkConstraint constraint = (IkConstraint)ikConstraints[i];
constraint.mix = constraint.data.mix; constraint.mix = constraint.data.mix;
constraint.softness = constraint.data.softness; constraint.softness = constraint.data.softness;
constraint.bendDirection = constraint.data.bendDirection; constraint.bendDirection = constraint.data.bendDirection;
@ -429,9 +432,9 @@ public class Skeleton {
constraint.stretch = constraint.data.stretch; constraint.stretch = constraint.data.stretch;
} }
Array<TransformConstraint> transformConstraints = this.transformConstraints; Object[] transformConstraints = this.transformConstraints.items;
for (int i = 0, n = transformConstraints.size; i < n; i++) { for (int i = 0, n = this.transformConstraints.size; i < n; i++) {
TransformConstraint constraint = transformConstraints.get(i); TransformConstraint constraint = (TransformConstraint)transformConstraints[i];
TransformConstraintData data = constraint.data; TransformConstraintData data = constraint.data;
constraint.rotateMix = data.rotateMix; constraint.rotateMix = data.rotateMix;
constraint.translateMix = data.translateMix; constraint.translateMix = data.translateMix;
@ -439,9 +442,9 @@ public class Skeleton {
constraint.shearMix = data.shearMix; constraint.shearMix = data.shearMix;
} }
Array<PathConstraint> pathConstraints = this.pathConstraints; Object[] pathConstraints = this.pathConstraints.items;
for (int i = 0, n = pathConstraints.size; i < n; i++) { for (int i = 0, n = this.pathConstraints.size; i < n; i++) {
PathConstraint constraint = pathConstraints.get(i); PathConstraint constraint = (PathConstraint)pathConstraints[i];
PathConstraintData data = constraint.data; PathConstraintData data = constraint.data;
constraint.position = data.position; constraint.position = data.position;
constraint.spacing = data.spacing; constraint.spacing = data.spacing;
@ -452,10 +455,11 @@ public class Skeleton {
/** Sets the slots and draw order to their setup pose values. */ /** Sets the slots and draw order to their setup pose values. */
public void setSlotsToSetupPose () { public void setSlotsToSetupPose () {
Array<Slot> slots = this.slots; Object[] slots = this.slots.items;
arraycopy(slots.items, 0, drawOrder.items, 0, slots.size); int n = this.slots.size;
for (int i = 0, n = slots.size; i < n; i++) arraycopy(slots, 0, drawOrder.items, 0, n);
slots.get(i).setToSetupPose(); for (int i = 0; i < n; i++)
((Slot)slots[i]).setToSetupPose();
} }
/** The skeleton's setup pose data. */ /** The skeleton's setup pose data. */
@ -483,9 +487,9 @@ public class Skeleton {
@Null @Null
public Bone findBone (String boneName) { public Bone findBone (String boneName) {
if (boneName == null) throw new IllegalArgumentException("boneName cannot be null."); if (boneName == null) throw new IllegalArgumentException("boneName cannot be null.");
Array<Bone> bones = this.bones; Object[] bones = this.bones.items;
for (int i = 0, n = bones.size; i < n; i++) { for (int i = 0, n = this.bones.size; i < n; i++) {
Bone bone = bones.get(i); Bone bone = (Bone)bones[i];
if (bone.data.name.equals(boneName)) return bone; if (bone.data.name.equals(boneName)) return bone;
} }
return null; return null;
@ -501,9 +505,9 @@ public class Skeleton {
@Null @Null
public Slot findSlot (String slotName) { public Slot findSlot (String slotName) {
if (slotName == null) throw new IllegalArgumentException("slotName cannot be null."); if (slotName == null) throw new IllegalArgumentException("slotName cannot be null.");
Array<Slot> slots = this.slots; Object[] slots = this.slots.items;
for (int i = 0, n = slots.size; i < n; i++) { for (int i = 0, n = this.slots.size; i < n; i++) {
Slot slot = slots.get(i); Slot slot = (Slot)slots[i];
if (slot.data.name.equals(slotName)) return slot; if (slot.data.name.equals(slotName)) return slot;
} }
return null; return null;
@ -550,9 +554,9 @@ public class Skeleton {
if (skin != null) if (skin != null)
newSkin.attachAll(this, skin); newSkin.attachAll(this, skin);
else { else {
Array<Slot> slots = this.slots; Object[] slots = this.slots.items;
for (int i = 0, n = slots.size; i < n; i++) { for (int i = 0, n = this.slots.size; i < n; i++) {
Slot slot = slots.get(i); Slot slot = (Slot)slots[i];
String name = slot.data.attachmentName; String name = slot.data.attachmentName;
if (name != null) { if (name != null) {
Attachment attachment = newSkin.getAttachment(i, name); Attachment attachment = newSkin.getAttachment(i, name);
@ -617,9 +621,9 @@ public class Skeleton {
@Null @Null
public IkConstraint findIkConstraint (String constraintName) { public IkConstraint findIkConstraint (String constraintName) {
if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null."); if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null.");
Array<IkConstraint> ikConstraints = this.ikConstraints; Object[] ikConstraints = this.ikConstraints.items;
for (int i = 0, n = ikConstraints.size; i < n; i++) { for (int i = 0, n = this.ikConstraints.size; i < n; i++) {
IkConstraint ikConstraint = ikConstraints.get(i); IkConstraint ikConstraint = (IkConstraint)ikConstraints[i];
if (ikConstraint.data.name.equals(constraintName)) return ikConstraint; if (ikConstraint.data.name.equals(constraintName)) return ikConstraint;
} }
return null; return null;
@ -635,9 +639,9 @@ public class Skeleton {
@Null @Null
public TransformConstraint findTransformConstraint (String constraintName) { public TransformConstraint findTransformConstraint (String constraintName) {
if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null."); if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null.");
Array<TransformConstraint> transformConstraints = this.transformConstraints; Object[] transformConstraints = this.transformConstraints.items;
for (int i = 0, n = transformConstraints.size; i < n; i++) { for (int i = 0, n = this.transformConstraints.size; i < n; i++) {
TransformConstraint constraint = transformConstraints.get(i); TransformConstraint constraint = (TransformConstraint)transformConstraints[i];
if (constraint.data.name.equals(constraintName)) return constraint; if (constraint.data.name.equals(constraintName)) return constraint;
} }
return null; return null;
@ -653,9 +657,9 @@ public class Skeleton {
@Null @Null
public PathConstraint findPathConstraint (String constraintName) { public PathConstraint findPathConstraint (String constraintName) {
if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null."); if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null.");
Array<PathConstraint> pathConstraints = this.pathConstraints; Object[] pathConstraints = this.pathConstraints.items;
for (int i = 0, n = pathConstraints.size; i < n; i++) { for (int i = 0, n = this.pathConstraints.size; i < n; i++) {
PathConstraint constraint = pathConstraints.get(i); PathConstraint constraint = (PathConstraint)pathConstraints[i];
if (constraint.data.name.equals(constraintName)) return constraint; if (constraint.data.name.equals(constraintName)) return constraint;
} }
return null; return null;
@ -669,10 +673,10 @@ public class Skeleton {
if (offset == null) throw new IllegalArgumentException("offset cannot be null."); if (offset == null) throw new IllegalArgumentException("offset cannot be null.");
if (size == null) throw new IllegalArgumentException("size cannot be null."); if (size == null) throw new IllegalArgumentException("size cannot be null.");
if (temp == null) throw new IllegalArgumentException("temp cannot be null."); if (temp == null) throw new IllegalArgumentException("temp cannot be null.");
Array<Slot> drawOrder = this.drawOrder; Object[] drawOrder = this.drawOrder.items;
float minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE; float minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
for (int i = 0, n = drawOrder.size; i < n; i++) { for (int i = 0, n = this.drawOrder.size; i < n; i++) {
Slot slot = drawOrder.get(i); Slot slot = (Slot)drawOrder[i];
if (!slot.bone.active) continue; if (!slot.bone.active) continue;
int verticesLength = 0; int verticesLength = 0;
float[] vertices = null; float[] vertices = null;

View File

@ -163,16 +163,15 @@ public class SkeletonBinary {
Object[] o; Object[] o;
// Strings. // Strings.
input.strings = new Array(n = input.readInt(true)); o = input.strings = new String[n = input.readInt(true)];
o = input.strings.setSize(n);
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
o[i] = input.readString(); o[i] = input.readString();
// Bones. // Bones.
o = skeletonData.bones.setSize(n = input.readInt(true)); Object[] bones = skeletonData.bones.setSize(n = input.readInt(true));
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
String name = input.readString(); String name = input.readString();
BoneData parent = i == 0 ? null : skeletonData.bones.get(input.readInt(true)); BoneData parent = i == 0 ? null : (BoneData)bones[input.readInt(true)];
BoneData data = new BoneData(i, name, parent); BoneData data = new BoneData(i, name, parent);
data.rotation = input.readFloat(); data.rotation = input.readFloat();
data.x = input.readFloat() * scale; data.x = input.readFloat() * scale;
@ -185,14 +184,14 @@ public class SkeletonBinary {
data.transformMode = TransformMode.values[input.readInt(true)]; data.transformMode = TransformMode.values[input.readInt(true)];
data.skinRequired = input.readBoolean(); data.skinRequired = input.readBoolean();
if (nonessential) Color.rgba8888ToColor(data.color, input.readInt()); if (nonessential) Color.rgba8888ToColor(data.color, input.readInt());
o[i] = data; bones[i] = data;
} }
// Slots. // Slots.
o = skeletonData.slots.setSize(n = input.readInt(true)); Object[] slots = skeletonData.slots.setSize(n = input.readInt(true));
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
String slotName = input.readString(); String slotName = input.readString();
BoneData boneData = skeletonData.bones.get(input.readInt(true)); BoneData boneData = (BoneData)bones[input.readInt(true)];
SlotData data = new SlotData(i, slotName, boneData); SlotData data = new SlotData(i, slotName, boneData);
Color.rgba8888ToColor(data.color, input.readInt()); Color.rgba8888ToColor(data.color, input.readInt());
@ -201,7 +200,7 @@ public class SkeletonBinary {
data.attachmentName = input.readStringRef(); data.attachmentName = input.readStringRef();
data.blendMode = BlendMode.values[input.readInt(true)]; data.blendMode = BlendMode.values[input.readInt(true)];
o[i] = data; slots[i] = data;
} }
// IK constraints. // IK constraints.
@ -210,10 +209,10 @@ public class SkeletonBinary {
IkConstraintData data = new IkConstraintData(input.readString()); IkConstraintData data = new IkConstraintData(input.readString());
data.order = input.readInt(true); data.order = input.readInt(true);
data.skinRequired = input.readBoolean(); data.skinRequired = input.readBoolean();
Object[] bones = data.bones.setSize(nn = input.readInt(true)); Object[] constraintBones = data.bones.setSize(nn = input.readInt(true));
for (int ii = 0; ii < nn; ii++) for (int ii = 0; ii < nn; ii++)
bones[ii] = skeletonData.bones.get(input.readInt(true)); constraintBones[ii] = bones[input.readInt(true)];
data.target = skeletonData.bones.get(input.readInt(true)); data.target = (BoneData)bones[input.readInt(true)];
data.mix = input.readFloat(); data.mix = input.readFloat();
data.softness = input.readFloat() * scale; data.softness = input.readFloat() * scale;
data.bendDirection = input.readByte(); data.bendDirection = input.readByte();
@ -229,10 +228,10 @@ public class SkeletonBinary {
TransformConstraintData data = new TransformConstraintData(input.readString()); TransformConstraintData data = new TransformConstraintData(input.readString());
data.order = input.readInt(true); data.order = input.readInt(true);
data.skinRequired = input.readBoolean(); data.skinRequired = input.readBoolean();
Object[] bones = data.bones.setSize(nn = input.readInt(true)); Object[] constraintBones = data.bones.setSize(nn = input.readInt(true));
for (int ii = 0; ii < nn; ii++) for (int ii = 0; ii < nn; ii++)
bones[ii] = skeletonData.bones.get(input.readInt(true)); constraintBones[ii] = bones[input.readInt(true)];
data.target = skeletonData.bones.get(input.readInt(true)); data.target = (BoneData)bones[input.readInt(true)];
data.local = input.readBoolean(); data.local = input.readBoolean();
data.relative = input.readBoolean(); data.relative = input.readBoolean();
data.offsetRotation = input.readFloat(); data.offsetRotation = input.readFloat();
@ -254,10 +253,10 @@ public class SkeletonBinary {
PathConstraintData data = new PathConstraintData(input.readString()); PathConstraintData data = new PathConstraintData(input.readString());
data.order = input.readInt(true); data.order = input.readInt(true);
data.skinRequired = input.readBoolean(); data.skinRequired = input.readBoolean();
Object[] bones = data.bones.setSize(nn = input.readInt(true)); Object[] constraintBones = data.bones.setSize(nn = input.readInt(true));
for (int ii = 0; ii < nn; ii++) for (int ii = 0; ii < nn; ii++)
bones[ii] = skeletonData.bones.get(input.readInt(true)); constraintBones[ii] = bones[input.readInt(true)];
data.target = skeletonData.slots.get(input.readInt(true)); data.target = (SlotData)slots[input.readInt(true)];
data.positionMode = PositionMode.values[input.readInt(true)]; data.positionMode = PositionMode.values[input.readInt(true)];
data.spacingMode = SpacingMode.values[input.readInt(true)]; data.spacingMode = SpacingMode.values[input.readInt(true)];
data.rotateMode = RotateMode.values[input.readInt(true)]; data.rotateMode = RotateMode.values[input.readInt(true)];
@ -288,8 +287,9 @@ public class SkeletonBinary {
// Linked meshes. // Linked meshes.
n = linkedMeshes.size; n = linkedMeshes.size;
Object[] items = linkedMeshes.items;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
LinkedMesh linkedMesh = linkedMeshes.get(i); LinkedMesh linkedMesh = (LinkedMesh)items[i];
Skin skin = linkedMesh.skin == null ? skeletonData.getDefaultSkin() : skeletonData.findSkin(linkedMesh.skin); Skin skin = linkedMesh.skin == null ? skeletonData.getDefaultSkin() : skeletonData.findSkin(linkedMesh.skin);
if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin); if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin);
Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent); Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
@ -343,16 +343,19 @@ public class SkeletonBinary {
skin = new Skin("default"); skin = new Skin("default");
} else { } else {
skin = new Skin(input.readStringRef()); skin = new Skin(input.readStringRef());
Object[] bones = skin.bones.setSize(input.readInt(true)); Object[] bones = skin.bones.setSize(input.readInt(true)), items = skeletonData.bones.items;
for (int i = 0, n = skin.bones.size; i < n; i++) for (int i = 0, n = skin.bones.size; i < n; i++)
bones[i] = skeletonData.bones.get(input.readInt(true)); bones[i] = items[input.readInt(true)];
items = skeletonData.ikConstraints.items;
for (int i = 0, n = input.readInt(true); i < n; i++) for (int i = 0, n = input.readInt(true); i < n; i++)
skin.constraints.add(skeletonData.ikConstraints.get(input.readInt(true))); skin.constraints.add((ConstraintData)items[input.readInt(true)]);
items = skeletonData.transformConstraints.items;
for (int i = 0, n = input.readInt(true); i < n; i++) for (int i = 0, n = input.readInt(true); i < n; i++)
skin.constraints.add(skeletonData.transformConstraints.get(input.readInt(true))); skin.constraints.add((ConstraintData)items[input.readInt(true)]);
items = skeletonData.pathConstraints.items;
for (int i = 0, n = input.readInt(true); i < n; i++) for (int i = 0, n = input.readInt(true); i < n; i++)
skin.constraints.add(skeletonData.pathConstraints.get(input.readInt(true))); skin.constraints.add((ConstraintData)items[input.readInt(true)]);
skin.constraints.shrink(); skin.constraints.shrink();
slotCount = input.readInt(true); slotCount = input.readInt(true);
@ -871,8 +874,9 @@ public class SkeletonBinary {
} }
float duration = 0; float duration = 0;
Object[] items = timelines.items;
for (int i = 0, n = timelines.size; i < n; i++) for (int i = 0, n = timelines.size; i < n; i++)
duration = Math.max(duration, timelines.get(i).getDuration()); duration = Math.max(duration, ((Timeline)items[i]).getDuration());
return new Animation(name, timelines, duration); return new Animation(name, timelines, duration);
} }
@ -929,7 +933,7 @@ public class SkeletonBinary {
static class SkeletonInput extends DataInput { static class SkeletonInput extends DataInput {
private char[] chars = new char[32]; private char[] chars = new char[32];
Array<String> strings; String[] strings;
public SkeletonInput (FileHandle file) { public SkeletonInput (FileHandle file) {
super(file.read(512)); super(file.read(512));
@ -938,7 +942,7 @@ public class SkeletonBinary {
@Null @Null
public String readStringRef () throws IOException { public String readStringRef () throws IOException {
int index = readInt(true); int index = readInt(true);
return index == 0 ? null : strings.get(index - 1); return index == 0 ? null : strings[index - 1];
} }
public String readString () throws IOException { public String readString () throws IOException {

View File

@ -57,15 +57,15 @@ public class SkeletonBounds {
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null."); if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
Array<BoundingBoxAttachment> boundingBoxes = this.boundingBoxes; Array<BoundingBoxAttachment> boundingBoxes = this.boundingBoxes;
Array<FloatArray> polygons = this.polygons; Array<FloatArray> polygons = this.polygons;
Array<Slot> slots = skeleton.slots; Object[] slots = skeleton.slots.items;
int slotCount = slots.size; int slotCount = skeleton.slots.size;
boundingBoxes.clear(); boundingBoxes.clear();
polygonPool.freeAll(polygons); polygonPool.freeAll(polygons);
polygons.clear(); polygons.clear();
for (int i = 0; i < slotCount; i++) { for (int i = 0; i < slotCount; i++) {
Slot slot = slots.get(i); Slot slot = (Slot)slots[i];
if (!slot.bone.active) continue; if (!slot.bone.active) continue;
Attachment attachment = slot.attachment; Attachment attachment = slot.attachment;
if (attachment instanceof BoundingBoxAttachment) { if (attachment instanceof BoundingBoxAttachment) {
@ -91,9 +91,9 @@ public class SkeletonBounds {
private void aabbCompute () { private void aabbCompute () {
float minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE; float minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
Array<FloatArray> polygons = this.polygons; Object[] polygons = this.polygons.items;
for (int i = 0, n = polygons.size; i < n; i++) { for (int i = 0, n = this.polygons.size; i < n; i++) {
FloatArray polygon = polygons.get(i); FloatArray polygon = (FloatArray)polygons[i];
float[] vertices = polygon.items; float[] vertices = polygon.items;
for (int ii = 0, nn = polygon.size; ii < nn; ii += 2) { for (int ii = 0, nn = polygon.size; ii < nn; ii += 2) {
float x = vertices[ii]; float x = vertices[ii];
@ -145,9 +145,9 @@ public class SkeletonBounds {
* efficient to only call this method if {@link #aabbContainsPoint(float, float)} returns true. */ * efficient to only call this method if {@link #aabbContainsPoint(float, float)} returns true. */
@Null @Null
public BoundingBoxAttachment containsPoint (float x, float y) { public BoundingBoxAttachment containsPoint (float x, float y) {
Array<FloatArray> polygons = this.polygons; Object[] polygons = this.polygons.items;
for (int i = 0, n = polygons.size; i < n; i++) for (int i = 0, n = this.polygons.size; i < n; i++)
if (containsPoint(polygons.get(i), x, y)) return boundingBoxes.get(i); if (containsPoint((FloatArray)polygons[i], x, y)) return boundingBoxes.get(i);
return null; return null;
} }
@ -176,9 +176,9 @@ public class SkeletonBounds {
* true. */ * true. */
@Null @Null
public BoundingBoxAttachment intersectsSegment (float x1, float y1, float x2, float y2) { public BoundingBoxAttachment intersectsSegment (float x1, float y1, float x2, float y2) {
Array<FloatArray> polygons = this.polygons; Object[] polygons = this.polygons.items;
for (int i = 0, n = polygons.size; i < n; i++) for (int i = 0, n = this.polygons.size; i < n; i++)
if (intersectsSegment(polygons.get(i), x1, y1, x2, y2)) return boundingBoxes.get(i); if (intersectsSegment((FloatArray)polygons[i], x1, y1, x2, y2)) return boundingBoxes.get(i);
return null; return null;
} }

View File

@ -70,9 +70,9 @@ public class SkeletonData {
@Null @Null
public BoneData findBone (String boneName) { public BoneData findBone (String boneName) {
if (boneName == null) throw new IllegalArgumentException("boneName cannot be null."); if (boneName == null) throw new IllegalArgumentException("boneName cannot be null.");
Array<BoneData> bones = this.bones; Object[] bones = this.bones.items;
for (int i = 0, n = bones.size; i < n; i++) { for (int i = 0, n = this.bones.size; i < n; i++) {
BoneData bone = bones.get(i); BoneData bone = (BoneData)bones[i];
if (bone.name.equals(boneName)) return bone; if (bone.name.equals(boneName)) return bone;
} }
return null; return null;
@ -90,9 +90,9 @@ public class SkeletonData {
@Null @Null
public SlotData findSlot (String slotName) { public SlotData findSlot (String slotName) {
if (slotName == null) throw new IllegalArgumentException("slotName cannot be null."); if (slotName == null) throw new IllegalArgumentException("slotName cannot be null.");
Array<SlotData> slots = this.slots; Object[] slots = this.slots.items;
for (int i = 0, n = slots.size; i < n; i++) { for (int i = 0, n = this.slots.size; i < n; i++) {
SlotData slot = slots.get(i); SlotData slot = (SlotData)slots[i];
if (slot.name.equals(slotName)) return slot; if (slot.name.equals(slotName)) return slot;
} }
return null; return null;
@ -156,9 +156,9 @@ public class SkeletonData {
@Null @Null
public Animation findAnimation (String animationName) { public Animation findAnimation (String animationName) {
if (animationName == null) throw new IllegalArgumentException("animationName cannot be null."); if (animationName == null) throw new IllegalArgumentException("animationName cannot be null.");
Array<Animation> animations = this.animations; Object[] animations = this.animations.items;
for (int i = 0, n = animations.size; i < n; i++) { for (int i = 0, n = this.animations.size; i < n; i++) {
Animation animation = animations.get(i); Animation animation = (Animation)animations[i];
if (animation.name.equals(animationName)) return animation; if (animation.name.equals(animationName)) return animation;
} }
return null; return null;
@ -176,9 +176,9 @@ public class SkeletonData {
@Null @Null
public IkConstraintData findIkConstraint (String constraintName) { public IkConstraintData findIkConstraint (String constraintName) {
if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null."); if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null.");
Array<IkConstraintData> ikConstraints = this.ikConstraints; Object[] ikConstraints = this.ikConstraints.items;
for (int i = 0, n = ikConstraints.size; i < n; i++) { for (int i = 0, n = this.ikConstraints.size; i < n; i++) {
IkConstraintData constraint = ikConstraints.get(i); IkConstraintData constraint = (IkConstraintData)ikConstraints[i];
if (constraint.name.equals(constraintName)) return constraint; if (constraint.name.equals(constraintName)) return constraint;
} }
return null; return null;
@ -196,9 +196,9 @@ public class SkeletonData {
@Null @Null
public TransformConstraintData findTransformConstraint (String constraintName) { public TransformConstraintData findTransformConstraint (String constraintName) {
if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null."); if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null.");
Array<TransformConstraintData> transformConstraints = this.transformConstraints; Object[] transformConstraints = this.transformConstraints.items;
for (int i = 0, n = transformConstraints.size; i < n; i++) { for (int i = 0, n = this.transformConstraints.size; i < n; i++) {
TransformConstraintData constraint = transformConstraints.get(i); TransformConstraintData constraint = (TransformConstraintData)transformConstraints[i];
if (constraint.name.equals(constraintName)) return constraint; if (constraint.name.equals(constraintName)) return constraint;
} }
return null; return null;
@ -216,9 +216,9 @@ public class SkeletonData {
@Null @Null
public PathConstraintData findPathConstraint (String constraintName) { public PathConstraintData findPathConstraint (String constraintName) {
if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null."); if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null.");
Array<PathConstraintData> pathConstraints = this.pathConstraints; Object[] pathConstraints = this.pathConstraints.items;
for (int i = 0, n = pathConstraints.size; i < n; i++) { for (int i = 0, n = this.pathConstraints.size; i < n; i++) {
PathConstraintData constraint = pathConstraints.get(i); PathConstraintData constraint = (PathConstraintData)pathConstraints[i];
if (constraint.name.equals(constraintName)) return constraint; if (constraint.name.equals(constraintName)) return constraint;
} }
return null; return null;

View File

@ -316,8 +316,9 @@ public class SkeletonJson {
} }
// Linked meshes. // Linked meshes.
Object[] items = linkedMeshes.items;
for (int i = 0, n = linkedMeshes.size; i < n; i++) { for (int i = 0, n = linkedMeshes.size; i < n; i++) {
LinkedMesh linkedMesh = linkedMeshes.get(i); LinkedMesh linkedMesh = (LinkedMesh)items[i];
Skin skin = linkedMesh.skin == null ? skeletonData.getDefaultSkin() : skeletonData.findSkin(linkedMesh.skin); Skin skin = linkedMesh.skin == null ? skeletonData.getDefaultSkin() : skeletonData.findSkin(linkedMesh.skin);
if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin); if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin);
Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent); Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
@ -845,8 +846,9 @@ public class SkeletonJson {
timelines.shrink(); timelines.shrink();
float duration = 0; float duration = 0;
Object[] items = timelines.items;
for (int i = 0, n = timelines.size; i < n; i++) for (int i = 0, n = timelines.size; i < n; i++)
duration = Math.max(duration, timelines.get(i).getDuration()); duration = Math.max(duration, ((Timeline)items[i]).getDuration());
skeletonData.animations.add(new Animation(name, timelines, duration)); skeletonData.animations.add(new Animation(name, timelines, duration));
} }

View File

@ -34,7 +34,6 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.FloatArray;
import com.badlogic.gdx.utils.Null; import com.badlogic.gdx.utils.Null;
import com.badlogic.gdx.utils.NumberUtils; import com.badlogic.gdx.utils.NumberUtils;
@ -89,9 +88,9 @@ public class SkeletonRenderer {
float[] vertices = this.vertices.items; float[] vertices = this.vertices.items;
Color skeletonColor = skeleton.color; Color skeletonColor = skeleton.color;
float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a; float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a;
Array<Slot> drawOrder = skeleton.drawOrder; Object[] drawOrder = skeleton.drawOrder.items;
for (int i = 0, n = drawOrder.size; i < n; i++) { for (int i = 0, n = skeleton.drawOrder.size; i < n; i++) {
Slot slot = drawOrder.get(i); Slot slot = (Slot)drawOrder[i];
if (!slot.bone.active) continue; if (!slot.bone.active) continue;
Attachment attachment = slot.attachment; Attachment attachment = slot.attachment;
if (attachment instanceof RegionAttachment) { if (attachment instanceof RegionAttachment) {
@ -167,9 +166,9 @@ public class SkeletonRenderer {
short[] triangles = null; short[] triangles = null;
Color color = null, skeletonColor = skeleton.color; Color color = null, skeletonColor = skeleton.color;
float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a; float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a;
Array<Slot> drawOrder = skeleton.drawOrder; Object[] drawOrder = skeleton.drawOrder.items;
for (int i = 0, n = drawOrder.size; i < n; i++) { for (int i = 0, n = skeleton.drawOrder.size; i < n; i++) {
Slot slot = drawOrder.get(i); Slot slot = (Slot)drawOrder[i];
if (!slot.bone.active) continue; if (!slot.bone.active) continue;
Texture texture = null; Texture texture = null;
int vertexSize = clipper.isClipping() ? 2 : 5; int vertexSize = clipper.isClipping() ? 2 : 5;
@ -290,9 +289,9 @@ public class SkeletonRenderer {
short[] triangles = null; short[] triangles = null;
Color color = null, skeletonColor = skeleton.color; Color color = null, skeletonColor = skeleton.color;
float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a; float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a;
Array<Slot> drawOrder = skeleton.drawOrder; Object[] drawOrder = skeleton.drawOrder.items;
for (int i = 0, n = drawOrder.size; i < n; i++) { for (int i = 0, n = skeleton.drawOrder.size; i < n; i++) {
Slot slot = drawOrder.get(i); Slot slot = (Slot)drawOrder[i];
if (!slot.bone.active) continue; if (!slot.bone.active) continue;
Texture texture = null; Texture texture = null;
int vertexSize = clipper.isClipping() ? 2 : 6; int vertexSize = clipper.isClipping() ? 2 : 6;

View File

@ -146,9 +146,10 @@ public class Skin {
/** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */ /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */
void attachAll (Skeleton skeleton, Skin oldSkin) { void attachAll (Skeleton skeleton, Skin oldSkin) {
Object[] slots = skeleton.slots.items;
for (SkinEntry entry : oldSkin.attachments.orderedItems()) { for (SkinEntry entry : oldSkin.attachments.orderedItems()) {
int slotIndex = entry.slotIndex; int slotIndex = entry.slotIndex;
Slot slot = skeleton.slots.get(slotIndex); Slot slot = (Slot)slots[slotIndex];
if (slot.attachment == entry.attachment) { if (slot.attachment == entry.attachment) {
Attachment attachment = getAttachment(slotIndex, entry.name); Attachment attachment = getAttachment(slotIndex, entry.name);
if (attachment != null) slot.setAttachment(attachment); if (attachment != null) slot.setAttachment(attachment);

View File

@ -97,14 +97,14 @@ public class TransformConstraint implements Updatable {
private void applyAbsoluteWorld () { private void applyAbsoluteWorld () {
float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix; float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
if (rotateMix == 0 && translateMix == 0 && scaleMix == 0 && shearMix == 0) return;
Bone target = this.target; Bone target = this.target;
float ta = target.a, tb = target.b, tc = target.c, td = target.d; float ta = target.a, tb = target.b, tc = target.c, td = target.d;
float degRadReflect = ta * td - tb * tc > 0 ? degRad : -degRad; float degRadReflect = ta * td - tb * tc > 0 ? degRad : -degRad;
float offsetRotation = data.offsetRotation * degRadReflect, offsetShearY = data.offsetShearY * degRadReflect; float offsetRotation = data.offsetRotation * degRadReflect, offsetShearY = data.offsetShearY * degRadReflect;
Array<Bone> bones = this.bones; Object[] bones = this.bones.items;
for (int i = 0, n = bones.size; i < n; i++) { for (int i = 0, n = this.bones.size; i < n; i++) {
Bone bone = bones.get(i); Bone bone = (Bone)bones[i];
boolean modified = false;
if (rotateMix != 0) { if (rotateMix != 0) {
float a = bone.a, b = bone.b, c = bone.c, d = bone.d; float a = bone.a, b = bone.b, c = bone.c, d = bone.d;
@ -118,7 +118,6 @@ public class TransformConstraint implements Updatable {
bone.b = cos * b - sin * d; bone.b = cos * b - sin * d;
bone.c = sin * a + cos * c; bone.c = sin * a + cos * c;
bone.d = sin * b + cos * d; bone.d = sin * b + cos * d;
modified = true;
} }
if (translateMix != 0) { if (translateMix != 0) {
@ -126,7 +125,6 @@ public class TransformConstraint implements Updatable {
target.localToWorld(temp.set(data.offsetX, data.offsetY)); target.localToWorld(temp.set(data.offsetX, data.offsetY));
bone.worldX += (temp.x - bone.worldX) * translateMix; bone.worldX += (temp.x - bone.worldX) * translateMix;
bone.worldY += (temp.y - bone.worldY) * translateMix; bone.worldY += (temp.y - bone.worldY) * translateMix;
modified = true;
} }
if (scaleMix > 0) { if (scaleMix > 0) {
@ -138,7 +136,6 @@ public class TransformConstraint implements Updatable {
if (s != 0) s = (s + ((float)Math.sqrt(tb * tb + td * td) - s + data.offsetScaleY) * scaleMix) / s; if (s != 0) s = (s + ((float)Math.sqrt(tb * tb + td * td) - s + data.offsetScaleY) * scaleMix) / s;
bone.b *= s; bone.b *= s;
bone.d *= s; bone.d *= s;
modified = true;
} }
if (shearMix > 0) { if (shearMix > 0) {
@ -152,23 +149,22 @@ public class TransformConstraint implements Updatable {
float s = (float)Math.sqrt(b * b + d * d); float s = (float)Math.sqrt(b * b + d * d);
bone.b = cos(r) * s; bone.b = cos(r) * s;
bone.d = sin(r) * s; bone.d = sin(r) * s;
modified = true;
} }
if (modified) bone.appliedValid = false; bone.appliedValid = false;
} }
} }
private void applyRelativeWorld () { private void applyRelativeWorld () {
float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix; float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
if (rotateMix == 0 && translateMix == 0 && scaleMix == 0 && shearMix == 0) return;
Bone target = this.target; Bone target = this.target;
float ta = target.a, tb = target.b, tc = target.c, td = target.d; float ta = target.a, tb = target.b, tc = target.c, td = target.d;
float degRadReflect = ta * td - tb * tc > 0 ? degRad : -degRad; float degRadReflect = ta * td - tb * tc > 0 ? degRad : -degRad;
float offsetRotation = data.offsetRotation * degRadReflect, offsetShearY = data.offsetShearY * degRadReflect; float offsetRotation = data.offsetRotation * degRadReflect, offsetShearY = data.offsetShearY * degRadReflect;
Array<Bone> bones = this.bones; Object[] bones = this.bones.items;
for (int i = 0, n = bones.size; i < n; i++) { for (int i = 0, n = this.bones.size; i < n; i++) {
Bone bone = bones.get(i); Bone bone = (Bone)bones[i];
boolean modified = false;
if (rotateMix != 0) { if (rotateMix != 0) {
float a = bone.a, b = bone.b, c = bone.c, d = bone.d; float a = bone.a, b = bone.b, c = bone.c, d = bone.d;
@ -182,7 +178,6 @@ public class TransformConstraint implements Updatable {
bone.b = cos * b - sin * d; bone.b = cos * b - sin * d;
bone.c = sin * a + cos * c; bone.c = sin * a + cos * c;
bone.d = sin * b + cos * d; bone.d = sin * b + cos * d;
modified = true;
} }
if (translateMix != 0) { if (translateMix != 0) {
@ -190,7 +185,6 @@ public class TransformConstraint implements Updatable {
target.localToWorld(temp.set(data.offsetX, data.offsetY)); target.localToWorld(temp.set(data.offsetX, data.offsetY));
bone.worldX += temp.x * translateMix; bone.worldX += temp.x * translateMix;
bone.worldY += temp.y * translateMix; bone.worldY += temp.y * translateMix;
modified = true;
} }
if (scaleMix > 0) { if (scaleMix > 0) {
@ -200,7 +194,6 @@ public class TransformConstraint implements Updatable {
s = ((float)Math.sqrt(tb * tb + td * td) - 1 + data.offsetScaleY) * scaleMix + 1; s = ((float)Math.sqrt(tb * tb + td * td) - 1 + data.offsetScaleY) * scaleMix + 1;
bone.b *= s; bone.b *= s;
bone.d *= s; bone.d *= s;
modified = true;
} }
if (shearMix > 0) { if (shearMix > 0) {
@ -213,10 +206,9 @@ public class TransformConstraint implements Updatable {
float s = (float)Math.sqrt(b * b + d * d); float s = (float)Math.sqrt(b * b + d * d);
bone.b = cos(r) * s; bone.b = cos(r) * s;
bone.d = sin(r) * s; bone.d = sin(r) * s;
modified = true;
} }
if (modified) bone.appliedValid = false; bone.appliedValid = false;
} }
} }
@ -224,9 +216,9 @@ public class TransformConstraint implements Updatable {
float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix; float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
Bone target = this.target; Bone target = this.target;
if (!target.appliedValid) target.updateAppliedTransform(); if (!target.appliedValid) target.updateAppliedTransform();
Array<Bone> bones = this.bones; Object[] bones = this.bones.items;
for (int i = 0, n = bones.size; i < n; i++) { for (int i = 0, n = this.bones.size; i < n; i++) {
Bone bone = bones.get(i); Bone bone = (Bone)bones[i];
if (!bone.appliedValid) bone.updateAppliedTransform(); if (!bone.appliedValid) bone.updateAppliedTransform();
float rotation = bone.arotation; float rotation = bone.arotation;
@ -263,9 +255,9 @@ public class TransformConstraint implements Updatable {
float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix; float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
Bone target = this.target; Bone target = this.target;
if (!target.appliedValid) target.updateAppliedTransform(); if (!target.appliedValid) target.updateAppliedTransform();
Array<Bone> bones = this.bones; Object[] bones = this.bones.items;
for (int i = 0, n = bones.size; i < n; i++) { for (int i = 0, n = this.bones.size; i < n; i++) {
Bone bone = bones.get(i); Bone bone = (Bone)bones[i];
if (!bone.appliedValid) bone.updateAppliedTransform(); if (!bone.appliedValid) bone.updateAppliedTransform();
float rotation = bone.arotation; float rotation = bone.arotation;

View File

@ -91,10 +91,10 @@ public class SkeletonActorPool extends Pool<SkeletonActor> {
/** Each obtained skeleton actor that is no longer playing an animation is removed from the stage and returned to the pool. */ /** Each obtained skeleton actor that is no longer playing an animation is removed from the stage and returned to the pool. */
public void freeComplete () { public void freeComplete () {
Array<SkeletonActor> obtained = this.obtained; Object[] obtained = this.obtained.items;
outer: outer:
for (int i = obtained.size - 1; i >= 0; i--) { for (int i = this.obtained.size - 1; i >= 0; i--) {
SkeletonActor actor = obtained.get(i); SkeletonActor actor = (SkeletonActor)obtained[i];
Array<TrackEntry> tracks = actor.state.getTracks(); Array<TrackEntry> tracks = actor.state.getTracks();
for (int ii = 0, nn = tracks.size; ii < nn; ii++) for (int ii = 0, nn = tracks.size; ii < nn; ii++)
if (tracks.get(ii) != null) continue outer; if (tracks.get(ii) != null) continue outer;

View File

@ -207,13 +207,14 @@ class Triangulator {
} }
// Go through the list of polygons and try to merge the remaining triangles with the found triangle fans. // Go through the list of polygons and try to merge the remaining triangles with the found triangle fans.
Object[] convexPolygonsIndicesItems = convexPolygonsIndices.items, convexPolygonsItems = convexPolygons.items;
for (int i = 0, n = convexPolygons.size; i < n; i++) { for (int i = 0, n = convexPolygons.size; i < n; i++) {
polygonIndices = convexPolygonsIndices.get(i); polygonIndices = (ShortArray)convexPolygonsIndicesItems[i];
if (polygonIndices.size == 0) continue; if (polygonIndices.size == 0) continue;
int firstIndex = polygonIndices.get(0); int firstIndex = polygonIndices.first();
int lastIndex = polygonIndices.get(polygonIndices.size - 1); int lastIndex = polygonIndices.get(polygonIndices.size - 1);
polygon = convexPolygons.get(i); polygon = (FloatArray)convexPolygonsItems[i];
int o = polygon.size - 4; int o = polygon.size - 4;
float[] p = polygon.items; float[] p = polygon.items;
float prevPrevX = p[o], prevPrevY = p[o + 1]; float prevPrevX = p[o], prevPrevY = p[o + 1];
@ -224,13 +225,13 @@ class Triangulator {
for (int ii = 0; ii < n; ii++) { for (int ii = 0; ii < n; ii++) {
if (ii == i) continue; if (ii == i) continue;
ShortArray otherIndices = convexPolygonsIndices.get(ii); ShortArray otherIndices = (ShortArray)convexPolygonsIndicesItems[ii];
if (otherIndices.size != 3) continue; if (otherIndices.size != 3) continue;
int otherFirstIndex = otherIndices.get(0); int otherFirstIndex = otherIndices.first();
int otherSecondIndex = otherIndices.get(1); int otherSecondIndex = otherIndices.get(1);
int otherLastIndex = otherIndices.get(2); int otherLastIndex = otherIndices.get(2);
FloatArray otherPoly = convexPolygons.get(ii); FloatArray otherPoly = (FloatArray)convexPolygonsItems[ii];
float x3 = otherPoly.get(otherPoly.size - 2), y3 = otherPoly.get(otherPoly.size - 1); float x3 = otherPoly.get(otherPoly.size - 2), y3 = otherPoly.get(otherPoly.size - 1);
if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue; if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue;
@ -253,7 +254,7 @@ class Triangulator {
// Remove empty polygons that resulted from the merge step above. // Remove empty polygons that resulted from the merge step above.
for (int i = convexPolygons.size - 1; i >= 0; i--) { for (int i = convexPolygons.size - 1; i >= 0; i--) {
polygon = convexPolygons.get(i); polygon = (FloatArray)convexPolygonsItems[i];
if (polygon.size == 0) { if (polygon.size == 0) {
convexPolygons.removeIndex(i); convexPolygons.removeIndex(i);
polygonPool.free(polygon); polygonPool.free(polygon);