From adfcb434a5428dc62fcc9526c9962edc3db8a0c1 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Sat, 19 Apr 2025 19:12:27 -0400 Subject: [PATCH] [libgdx] Skip bones in update cache when a slider mix is 0. --- .../src/com/esotericsoftware/spine/Bone.java | 7 ++++++ .../com/esotericsoftware/spine/BonePose.java | 23 ++++++++++--------- .../com/esotericsoftware/spine/Skeleton.java | 5 ++++ .../com/esotericsoftware/spine/Slider.java | 8 ++++++- .../spine/TransformConstraint.java | 2 +- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java index 82bffa40c..f01b08cba 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java @@ -65,4 +65,11 @@ public class Bone extends PosedActive { public Array getChildren () { return children; } + + void resetUpdate () { + applied.update = 0; + Bone[] children = this.children.items; + for (int i = 0, n = this.children.size; i < n; i++) + children[i].resetUpdate(); + } } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BonePose.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BonePose.java index 6887b8211..17380efdc 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BonePose.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BonePose.java @@ -15,24 +15,23 @@ public class BonePose extends BoneLocal implements Update { Bone bone; float a, b, worldX; float c, d, worldY; + int update; BonePose () { } - /** Computes the world transform using the parent bone and this bone's local applied transform. */ - public void updateWorldTransform (Skeleton skeleton) { - update(skeleton, null); + /** Called by {@link Skeleton#updateCache()} to compute the world transform, if needed. */ + public void update (Skeleton skeleton, Physics physics) { + if (update != skeleton.update) updateWorldTransform(skeleton); } - /** Computes the world transform using the parent bone and this bone's local transform. - *

- * See {@link #updateWorldTransform(float, float, float, float, float, float, float)}. */ - /** Computes the world transform using the parent bone and the specified local transform. The applied transform is set to the - * specified local transform. Child bones are not updated. + /** Computes the world transform using the parent bone's applied pose and this pose. Child bones are not updated. *

* See World transforms in the Spine * Runtimes Guide. */ - public void update (Skeleton skeleton, Physics physics) { + public void updateWorldTransform (Skeleton skeleton) { + update = skeleton.update; + if (bone.parent == null) { // Root bone. float sx = skeleton.scaleX, sy = skeleton.scaleY; float rx = (rotation + shearX) * degRad; @@ -140,6 +139,8 @@ public class BonePose extends BoneLocal implements Update { * Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. The local transform after * calling this method is equivalent to the local transform used to compute the world transform, but may not be identical. */ public void updateLocalTransform (Skeleton skeleton) { + update = skeleton.update; + if (bone.parent == null) { x = worldX - skeleton.x; y = worldY - skeleton.y; @@ -353,8 +354,8 @@ public class BonePose extends BoneLocal implements Update { /** Rotates the world transform the specified amount. *

- * After changes are made to the world transform, {@link #updateLocalTransform(Skeleton)} should be called and - * {@link #update(Skeleton, Physics)} will need to be called on any child bones, recursively. */ + * After changes are made to the world transform, {@link #updateLocalTransform(Skeleton)} should be called on this bone and any + * child bones, recursively. */ public void rotateWorld (float degrees) { degrees *= degRad; float sin = sin(degrees), cos = cos(degrees); 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 47ce3b518..77dd7b296 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -61,6 +61,7 @@ public class Skeleton { @Null Skin skin; final Color color; float x, y, scaleX = 1, scaleY = 1, time; + int update; public Skeleton (SkeletonData data) { if (data == null) throw new IllegalArgumentException("data cannot be null."); @@ -224,6 +225,8 @@ public class Skeleton { * See World transforms in the Spine * Runtimes Guide. */ public void updateWorldTransform (Physics physics) { + update++; + Posed[] resetCache = this.resetCache.items; for (int i = 0, n = this.resetCache.size; i < n; i++) resetCache[i].resetAppliedPose(); @@ -241,6 +244,8 @@ public class Skeleton { public void updateWorldTransform (Physics physics, BonePose parent) { if (parent == null) throw new IllegalArgumentException("parent cannot be null."); + update++; + Posed[] resetCache = this.resetCache.items; for (int i = 0, n = this.resetCache.size; i < n; i++) resetCache[i].resetAppliedPose(); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slider.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slider.java index 5cbb38a1f..1cb86f57b 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slider.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slider.java @@ -55,12 +55,17 @@ public class Slider extends Constraint { if (pose.mix == 0) return; SliderPose pose = applied; data.animation.apply(skeleton, pose.time, pose.time, false, null, pose.mix, MixBlend.replace, MixDirection.in, true); + + Timeline[] timelines = data.animation.timelines.items; + int timelineCount = data.animation.timelines.size; + Bone[] bones = skeleton.bones.items; + for (int i = 0; i < timelineCount; i++) + if (timelines[i] instanceof BoneTimeline boneTimeline) bones[boneTimeline.getBoneIndex()].resetUpdate(); } void sort (Skeleton skeleton) { Timeline[] timelines = data.animation.timelines.items; int timelineCount = data.animation.timelines.size; - Bone[] bones = skeleton.bones.items; for (int i = 0; i < timelineCount; i++) if (timelines[i] instanceof BoneTimeline boneTimeline) skeleton.sortBone(bones[boneTimeline.getBoneIndex()]); @@ -72,6 +77,7 @@ public class Slider extends Constraint { Timeline t = timelines[i]; if (t instanceof BoneTimeline timeline) { Bone bone = bones[timeline.getBoneIndex()]; + skeleton.resetCache(bone); skeleton.sortReset(bone.children); bone.sorted = false; } else if (t instanceof SlotTimeline timeline) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/TransformConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/TransformConstraint.java index b486c67ab..7d2b65772 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/TransformConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/TransformConstraint.java @@ -94,7 +94,7 @@ public class TransformConstraint extends Constraint