[libgdx] Slider resetCache using instanceof.

This commit is contained in:
Nathan Sweet 2025-04-18 16:05:44 -04:00
parent 1f92218c23
commit 328f5a142f
2 changed files with 71 additions and 66 deletions

View File

@ -1135,10 +1135,9 @@ public class Animation {
Slot slot = skeleton.slots.items[slotIndex]; Slot slot = skeleton.slots.items[slotIndex];
if (!slot.bone.active) return; if (!slot.bone.active) return;
SlotPose pose = appliedPose ? slot.applied : slot.pose;
Color color = (appliedPose ? slot.applied : slot.pose).color;
float[] frames = this.frames; float[] frames = this.frames;
Color color = pose.color;
if (time < frames[0]) { if (time < frames[0]) {
Color setup = slot.data.setup.color; Color setup = slot.data.setup.color;
switch (blend) { switch (blend) {
@ -1827,18 +1826,22 @@ public class Animation {
} }
} }
static public interface ConstraintTimeline {
public int getConstraintIndex ();
}
/** Changes an IK constraint's {@link IkConstraintPose#getMix()}, {@link IkConstraintPose#getSoftness()}, /** Changes an IK constraint's {@link IkConstraintPose#getMix()}, {@link IkConstraintPose#getSoftness()},
* {@link IkConstraintPose#getBendDirection()}, {@link IkConstraintPose#getStretch()}, and * {@link IkConstraintPose#getBendDirection()}, {@link IkConstraintPose#getStretch()}, and
* {@link IkConstraintPose#getCompress()}. */ * {@link IkConstraintPose#getCompress()}. */
static public class IkConstraintTimeline extends CurveTimeline { static public class IkConstraintTimeline extends CurveTimeline implements ConstraintTimeline {
static public final int ENTRIES = 6; static public final int ENTRIES = 6;
static private final int MIX = 1, SOFTNESS = 2, BEND_DIRECTION = 3, COMPRESS = 4, STRETCH = 5; static private final int MIX = 1, SOFTNESS = 2, BEND_DIRECTION = 3, COMPRESS = 4, STRETCH = 5;
final int constraintIndex; final int constraintIndex;
public IkConstraintTimeline (int frameCount, int bezierCount, int ikConstraintIndex) { public IkConstraintTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, Property.ikConstraint.ordinal() + "|" + ikConstraintIndex); super(frameCount, bezierCount, Property.ikConstraint.ordinal() + "|" + constraintIndex);
constraintIndex = ikConstraintIndex; this.constraintIndex = constraintIndex;
} }
public int getFrameEntries () { public int getFrameEntries () {
@ -1847,7 +1850,7 @@ public class Animation {
/** The index of the IK constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is /** The index of the IK constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is
* applied. */ * applied. */
public int getIkConstraintIndex () { public int getConstraintIndex () {
return constraintIndex; return constraintIndex;
} }
@ -1942,15 +1945,15 @@ public class Animation {
/** Changes a transform constraint's {@link TransformConstraintPose#getMixRotate()}, {@link TransformConstraintPose#getMixX()}, /** Changes a transform constraint's {@link TransformConstraintPose#getMixRotate()}, {@link TransformConstraintPose#getMixX()},
* {@link TransformConstraintPose#getMixY()}, {@link TransformConstraintPose#getMixScaleX()}, * {@link TransformConstraintPose#getMixY()}, {@link TransformConstraintPose#getMixScaleX()},
* {@link TransformConstraintPose#getMixScaleY()}, and {@link TransformConstraintPose#getMixShearY()}. */ * {@link TransformConstraintPose#getMixScaleY()}, and {@link TransformConstraintPose#getMixShearY()}. */
static public class TransformConstraintTimeline extends CurveTimeline { static public class TransformConstraintTimeline extends CurveTimeline implements ConstraintTimeline {
static public final int ENTRIES = 7; static public final int ENTRIES = 7;
static private final int ROTATE = 1, X = 2, Y = 3, SCALEX = 4, SCALEY = 5, SHEARY = 6; static private final int ROTATE = 1, X = 2, Y = 3, SCALEX = 4, SCALEY = 5, SHEARY = 6;
final int constraintIndex; final int constraintIndex;
public TransformConstraintTimeline (int frameCount, int bezierCount, int transformConstraintIndex) { public TransformConstraintTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, Property.transformConstraint.ordinal() + "|" + transformConstraintIndex); super(frameCount, bezierCount, Property.transformConstraint.ordinal() + "|" + constraintIndex);
constraintIndex = transformConstraintIndex; this.constraintIndex = constraintIndex;
} }
public int getFrameEntries () { public int getFrameEntries () {
@ -1959,7 +1962,7 @@ public class Animation {
/** The index of the transform constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is /** The index of the transform constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is
* applied. */ * applied. */
public int getTransformConstraintIndex () { public int getConstraintIndex () {
return constraintIndex; return constraintIndex;
} }
@ -2064,17 +2067,17 @@ public class Animation {
} }
/** Changes a path constraint's {@link PathConstraintPose#getPosition()}. */ /** Changes a path constraint's {@link PathConstraintPose#getPosition()}. */
static public class PathConstraintPositionTimeline extends CurveTimeline1 { static public class PathConstraintPositionTimeline extends CurveTimeline1 implements ConstraintTimeline {
final int constraintIndex; final int constraintIndex;
public PathConstraintPositionTimeline (int frameCount, int bezierCount, int pathConstraintIndex) { public PathConstraintPositionTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, Property.pathConstraintPosition.ordinal() + "|" + pathConstraintIndex); super(frameCount, bezierCount, Property.pathConstraintPosition.ordinal() + "|" + constraintIndex);
constraintIndex = pathConstraintIndex; this.constraintIndex = constraintIndex;
} }
/** The index of the path constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is /** The index of the path constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is
* applied. */ * applied. */
public int getPathConstraintIndex () { public int getConstraintIndex () {
return constraintIndex; return constraintIndex;
} }
@ -2090,17 +2093,17 @@ public class Animation {
} }
/** Changes a path constraint's {@link PathConstraintPose#getSpacing()}. */ /** Changes a path constraint's {@link PathConstraintPose#getSpacing()}. */
static public class PathConstraintSpacingTimeline extends CurveTimeline1 { static public class PathConstraintSpacingTimeline extends CurveTimeline1 implements ConstraintTimeline {
final int constraintIndex; final int constraintIndex;
public PathConstraintSpacingTimeline (int frameCount, int bezierCount, int pathConstraintIndex) { public PathConstraintSpacingTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, Property.pathConstraintSpacing.ordinal() + "|" + pathConstraintIndex); super(frameCount, bezierCount, Property.pathConstraintSpacing.ordinal() + "|" + constraintIndex);
constraintIndex = pathConstraintIndex; this.constraintIndex = constraintIndex;
} }
/** The index of the path constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is /** The index of the path constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is
* applied. */ * applied. */
public int getPathConstraintIndex () { public int getConstraintIndex () {
return constraintIndex; return constraintIndex;
} }
@ -2117,15 +2120,15 @@ public class Animation {
/** Changes a path constraint's {@link PathConstraintPose#getMixRotate()}, {@link PathConstraintPose#getMixX()}, and /** Changes a path constraint's {@link PathConstraintPose#getMixRotate()}, {@link PathConstraintPose#getMixX()}, and
* {@link PathConstraintPose#getMixY()}. */ * {@link PathConstraintPose#getMixY()}. */
static public class PathConstraintMixTimeline extends CurveTimeline { static public class PathConstraintMixTimeline extends CurveTimeline implements ConstraintTimeline {
static public final int ENTRIES = 4; static public final int ENTRIES = 4;
static private final int ROTATE = 1, X = 2, Y = 3; static private final int ROTATE = 1, X = 2, Y = 3;
final int constraintIndex; final int constraintIndex;
public PathConstraintMixTimeline (int frameCount, int bezierCount, int pathConstraintIndex) { public PathConstraintMixTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, Property.pathConstraintMix.ordinal() + "|" + pathConstraintIndex); super(frameCount, bezierCount, Property.pathConstraintMix.ordinal() + "|" + constraintIndex);
constraintIndex = pathConstraintIndex; this.constraintIndex = constraintIndex;
} }
public int getFrameEntries () { public int getFrameEntries () {
@ -2134,7 +2137,7 @@ public class Animation {
/** The index of the path constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is /** The index of the path constraint in {@link Skeleton#getConstraints()} that will be changed when this timeline is
* applied. */ * applied. */
public int getPathConstraintIndex () { public int getConstraintIndex () {
return constraintIndex; return constraintIndex;
} }
@ -2211,18 +2214,18 @@ public class Animation {
} }
/** The base class for most {@link PhysicsConstraint} timelines. */ /** The base class for most {@link PhysicsConstraint} timelines. */
static abstract public class PhysicsConstraintTimeline extends CurveTimeline1 { static abstract public class PhysicsConstraintTimeline extends CurveTimeline1 implements ConstraintTimeline {
final int constraintIndex; final int constraintIndex;
/** @param physicsConstraintIndex -1 for all physics constraints in the skeleton. */ /** @param constraintIndex -1 for all physics constraints in the skeleton. */
public PhysicsConstraintTimeline (int frameCount, int bezierCount, int physicsConstraintIndex, Property property) { public PhysicsConstraintTimeline (int frameCount, int bezierCount, int constraintIndex, Property property) {
super(frameCount, bezierCount, property.ordinal() + "|" + physicsConstraintIndex); super(frameCount, bezierCount, property.ordinal() + "|" + constraintIndex);
constraintIndex = physicsConstraintIndex; this.constraintIndex = constraintIndex;
} }
/** The index of the physics constraint in {@link Skeleton#getPhysicsConstraints()} that will be changed when this timeline /** The index of the physics constraint in {@link Skeleton#getPhysicsConstraints()} that will be changed when this timeline
* is applied, or -1 if all physics constraints in the skeleton will be changed. */ * is applied, or -1 if all physics constraints in the skeleton will be changed. */
public int getPhysicsConstraintIndex () { public int getConstraintIndex () {
return constraintIndex; return constraintIndex;
} }
@ -2258,8 +2261,8 @@ public class Animation {
/** Changes a physics constraint's {@link PhysicsConstraintPose#getInertia()}. */ /** Changes a physics constraint's {@link PhysicsConstraintPose#getInertia()}. */
static public class PhysicsConstraintInertiaTimeline extends PhysicsConstraintTimeline { static public class PhysicsConstraintInertiaTimeline extends PhysicsConstraintTimeline {
public PhysicsConstraintInertiaTimeline (int frameCount, int bezierCount, int physicsConstraintIndex) { public PhysicsConstraintInertiaTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintInertia); super(frameCount, bezierCount, constraintIndex, Property.physicsConstraintInertia);
} }
protected float get (PhysicsConstraintPose pose) { protected float get (PhysicsConstraintPose pose) {
@ -2277,8 +2280,8 @@ public class Animation {
/** Changes a physics constraint's {@link PhysicsConstraintPose#getStrength()}. */ /** Changes a physics constraint's {@link PhysicsConstraintPose#getStrength()}. */
static public class PhysicsConstraintStrengthTimeline extends PhysicsConstraintTimeline { static public class PhysicsConstraintStrengthTimeline extends PhysicsConstraintTimeline {
public PhysicsConstraintStrengthTimeline (int frameCount, int bezierCount, int physicsConstraintIndex) { public PhysicsConstraintStrengthTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintStrength); super(frameCount, bezierCount, constraintIndex, Property.physicsConstraintStrength);
} }
protected float get (PhysicsConstraintPose pose) { protected float get (PhysicsConstraintPose pose) {
@ -2296,8 +2299,8 @@ public class Animation {
/** Changes a physics constraint's {@link PhysicsConstraintPose#getDamping()}. */ /** Changes a physics constraint's {@link PhysicsConstraintPose#getDamping()}. */
static public class PhysicsConstraintDampingTimeline extends PhysicsConstraintTimeline { static public class PhysicsConstraintDampingTimeline extends PhysicsConstraintTimeline {
public PhysicsConstraintDampingTimeline (int frameCount, int bezierCount, int physicsConstraintIndex) { public PhysicsConstraintDampingTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintDamping); super(frameCount, bezierCount, constraintIndex, Property.physicsConstraintDamping);
} }
protected float get (PhysicsConstraintPose pose) { protected float get (PhysicsConstraintPose pose) {
@ -2315,8 +2318,8 @@ public class Animation {
/** Changes a physics constraint's {@link PhysicsConstraintPose#getMassInverse()}. The timeline values are not inverted. */ /** Changes a physics constraint's {@link PhysicsConstraintPose#getMassInverse()}. The timeline values are not inverted. */
static public class PhysicsConstraintMassTimeline extends PhysicsConstraintTimeline { static public class PhysicsConstraintMassTimeline extends PhysicsConstraintTimeline {
public PhysicsConstraintMassTimeline (int frameCount, int bezierCount, int physicsConstraintIndex) { public PhysicsConstraintMassTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintMass); super(frameCount, bezierCount, constraintIndex, Property.physicsConstraintMass);
} }
protected float get (PhysicsConstraintPose pose) { protected float get (PhysicsConstraintPose pose) {
@ -2334,8 +2337,8 @@ public class Animation {
/** Changes a physics constraint's {@link PhysicsConstraintPose#getWind()}. */ /** Changes a physics constraint's {@link PhysicsConstraintPose#getWind()}. */
static public class PhysicsConstraintWindTimeline extends PhysicsConstraintTimeline { static public class PhysicsConstraintWindTimeline extends PhysicsConstraintTimeline {
public PhysicsConstraintWindTimeline (int frameCount, int bezierCount, int physicsConstraintIndex) { public PhysicsConstraintWindTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintWind); super(frameCount, bezierCount, constraintIndex, Property.physicsConstraintWind);
} }
protected float get (PhysicsConstraintPose pose) { protected float get (PhysicsConstraintPose pose) {
@ -2353,8 +2356,8 @@ public class Animation {
/** Changes a physics constraint's {@link PhysicsConstraintPose#getGravity()}. */ /** Changes a physics constraint's {@link PhysicsConstraintPose#getGravity()}. */
static public class PhysicsConstraintGravityTimeline extends PhysicsConstraintTimeline { static public class PhysicsConstraintGravityTimeline extends PhysicsConstraintTimeline {
public PhysicsConstraintGravityTimeline (int frameCount, int bezierCount, int physicsConstraintIndex) { public PhysicsConstraintGravityTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintGravity); super(frameCount, bezierCount, constraintIndex, Property.physicsConstraintGravity);
} }
protected float get (PhysicsConstraintPose pose) { protected float get (PhysicsConstraintPose pose) {
@ -2372,8 +2375,8 @@ public class Animation {
/** Changes a physics constraint's {@link PhysicsConstraintPose#getMix()}. */ /** Changes a physics constraint's {@link PhysicsConstraintPose#getMix()}. */
static public class PhysicsConstraintMixTimeline extends PhysicsConstraintTimeline { static public class PhysicsConstraintMixTimeline extends PhysicsConstraintTimeline {
public PhysicsConstraintMixTimeline (int frameCount, int bezierCount, int physicsConstraintIndex) { public PhysicsConstraintMixTimeline (int frameCount, int bezierCount, int constraintIndex) {
super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintMix); super(frameCount, bezierCount, constraintIndex, Property.physicsConstraintMix);
} }
protected float get (PhysicsConstraintPose pose) { protected float get (PhysicsConstraintPose pose) {
@ -2390,20 +2393,20 @@ public class Animation {
} }
/** Resets a physics constraint when specific animation times are reached. */ /** Resets a physics constraint when specific animation times are reached. */
static public class PhysicsConstraintResetTimeline extends Timeline { static public class PhysicsConstraintResetTimeline extends Timeline implements ConstraintTimeline {
static private final String[] propertyIds = {Integer.toString(Property.physicsConstraintReset.ordinal())}; static private final String[] propertyIds = {Integer.toString(Property.physicsConstraintReset.ordinal())};
final int constraintIndex; final int constraintIndex;
/** @param physicsConstraintIndex -1 for all physics constraints in the skeleton. */ /** @param constraintIndex -1 for all physics constraints in the skeleton. */
public PhysicsConstraintResetTimeline (int frameCount, int physicsConstraintIndex) { public PhysicsConstraintResetTimeline (int frameCount, int constraintIndex) {
super(frameCount, propertyIds); super(frameCount, propertyIds);
constraintIndex = physicsConstraintIndex; this.constraintIndex = constraintIndex;
} }
/** The index of the physics constraint in {@link Skeleton#getPhysicsConstraints()} that will be reset when this timeline is /** The index of the physics constraint in {@link Skeleton#getPhysicsConstraints()} that will be reset when this timeline is
* applied, or -1 if all physics constraints in the skeleton will be reset. */ * applied, or -1 if all physics constraints in the skeleton will be reset. */
public int getPhysicsConstraintIndex () { public int getConstraintIndex () {
return constraintIndex; return constraintIndex;
} }

View File

@ -30,8 +30,10 @@
package com.esotericsoftware.spine; package com.esotericsoftware.spine;
import com.esotericsoftware.spine.Animation.BoneTimeline; import com.esotericsoftware.spine.Animation.BoneTimeline;
import com.esotericsoftware.spine.Animation.ConstraintTimeline;
import com.esotericsoftware.spine.Animation.MixBlend; import com.esotericsoftware.spine.Animation.MixBlend;
import com.esotericsoftware.spine.Animation.MixDirection; import com.esotericsoftware.spine.Animation.MixDirection;
import com.esotericsoftware.spine.Animation.PhysicsConstraintTimeline;
import com.esotericsoftware.spine.Animation.SlotTimeline; import com.esotericsoftware.spine.Animation.SlotTimeline;
import com.esotericsoftware.spine.Animation.Timeline; import com.esotericsoftware.spine.Animation.Timeline;
@ -66,23 +68,23 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
Slot[] slots = skeleton.slots.items; Slot[] slots = skeleton.slots.items;
for (int i = 0; i < timelineCount; i++) { for (int i = 0; i < timelineCount; i++) {
Timeline timeline = timelines[i]; Timeline t = timelines[i];
if (timeline instanceof BoneTimeline boneTimeline) { if (t instanceof BoneTimeline timeline) {
Bone bone = bones[boneTimeline.getBoneIndex()]; Bone bone = bones[timeline.getBoneIndex()];
skeleton.sortBone(bone); skeleton.sortBone(bone);
skeleton.sortReset(bone.children); skeleton.sortReset(bone.children);
bone.sorted = false; bone.sorted = false;
} else if (timeline instanceof SlotTimeline slotTimeline) // } else if (t instanceof SlotTimeline timeline)
skeleton.resetCache(slots[slotTimeline.getSlotIndex()]); skeleton.resetCache(slots[timeline.getSlotIndex()]);
// BOZO! else if (t instanceof PhysicsConstraintTimeline timeline) {
// skeleton.resetCache(skeleton.constraints.items[constraintIndex]); if (timeline.constraintIndex == -1) {
PhysicsConstraint[] constraints = skeleton.physics.items;
// if (constraintIndex == -1) { for (int ii = 0, nn = skeleton.physics.size; ii < nn; ii++)
// Object[] constraints = skeleton.physics.items; skeleton.resetCache(constraints[ii]);
// for (int i = 0, n = skeleton.physics.size; i < n; i++) } else
// skeleton.resetCache((PhysicsConstraint)constraints[i]); skeleton.resetCache(skeleton.constraints.items[timeline.constraintIndex]);
// } else } else if (t instanceof ConstraintTimeline timeline) //
// skeleton.resetCache(skeleton.constraints.items[constraintIndex]); skeleton.resetCache(skeleton.constraints.items[timeline.getConstraintIndex()]);
} }
for (int i = 0; i < timelineCount; i++) for (int i = 0; i < timelineCount; i++)
if (timelines[i] instanceof BoneTimeline boneTimeline) skeleton.sortBone(bones[boneTimeline.getBoneIndex()]); if (timelines[i] instanceof BoneTimeline boneTimeline) skeleton.sortBone(bones[boneTimeline.getBoneIndex()]);