From e2ee1ab458ac8cfe31ca438ac7258bed1cbb7001 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Thu, 12 Jun 2025 15:56:13 -0400 Subject: [PATCH] [libgdx] Nicen things up for porting. --- .../src/com/esotericsoftware/spine/Posed.java | 18 ++++++++++-- .../esotericsoftware/spine/PosedActive.java | 2 +- .../com/esotericsoftware/spine/Skeleton.java | 28 +++++++------------ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Posed.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Posed.java index 7b2eb254c..bfe2138ea 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Posed.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Posed.java @@ -7,16 +7,16 @@ abstract public class Posed< // A extends P> { final D data; - final P pose; + final A pose; final A constrained; A applied; - public Posed (D data, P pose, A constrained) { + public Posed (D data, A pose, A constrained) { if (data == null) throw new IllegalArgumentException("data cannot be null."); this.data = data; this.pose = pose; this.constrained = constrained; - applied = (A)pose; + applied = pose; } public void setupPose () { @@ -36,6 +36,18 @@ abstract public class Posed< // return applied; } + void pose () { + applied = pose; + } + + void constrained () { + applied = constrained; + } + + void reset () { + constrained.set(pose); + } + public String toString () { return data.name; } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PosedActive.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PosedActive.java index 388cb8964..578f587ef 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PosedActive.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PosedActive.java @@ -9,7 +9,7 @@ abstract public class PosedActive< // boolean active; - public PosedActive (D data, P pose, A constrained) { + public PosedActive (D data, A pose, A constrained) { super(data, pose, constrained); setupPose(); } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index e877e672f..d7e5b9d53 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -155,10 +155,8 @@ public class Skeleton { resetCache.clear(); Slot[] slots = this.slots.items; - for (int i = 0, n = this.slots.size; i < n; i++) { - Slot slot = slots[i]; - slot.applied = slot.pose; - } + for (int i = 0, n = this.slots.size; i < n; i++) + slots[i].pose(); int boneCount = bones.size; Bone[] bones = this.bones.items; @@ -166,7 +164,7 @@ public class Skeleton { Bone bone = bones[i]; bone.sorted = bone.data.skinRequired; bone.active = !bone.sorted; - bone.applied = (BonePose)bone.pose; + bone.pose(); } if (skin != null) { BoneData[] skinBones = skin.bones.items; @@ -182,10 +180,8 @@ public class Skeleton { Constraint[] constraints = this.constraints.items; int n = this.constraints.size; - for (int i = 0; i < n; i++) { - Constraint constraint = constraints[i]; - constraint.applied = constraint.pose; - } + for (int i = 0; i < n; i++) + constraints[i].pose(); for (int i = 0; i < n; i++) { Constraint constraint = constraints[i]; constraint.active = constraint.isSourceActive() @@ -204,7 +200,7 @@ public class Skeleton { void constrained (Posed object) { if (object.pose == object.applied) { - object.applied = object.constrained; + object.constrained(); resetCache.add(object); } } @@ -236,10 +232,8 @@ public class Skeleton { update++; Posed[] resetCache = this.resetCache.items; - for (int i = 0, n = this.resetCache.size; i < n; i++) { - Posed object = resetCache[i]; - object.applied.set(object.pose); - } + for (int i = 0, n = this.resetCache.size; i < n; i++) + resetCache[i].reset(); Object[] updateCache = this.updateCache.items; for (int i = 0, n = this.updateCache.size; i < n; i++) @@ -257,10 +251,8 @@ public class Skeleton { update++; Posed[] resetCache = this.resetCache.items; - for (int i = 0, n = this.resetCache.size; i < n; i++) { - Posed object = resetCache[i]; - object.applied.set(object.pose); - } + for (int i = 0, n = this.resetCache.size; i < n; i++) + resetCache[i].reset(); // Apply the parent bone transform to the root bone. The root bone always inherits scale, rotation and reflection. BonePose rootBone = getRootBone().applied;