Clean up.

This commit is contained in:
Nathan Sweet 2021-10-02 03:03:22 -10:00
parent 6e938b32ea
commit 3cb04204f4
2 changed files with 16 additions and 17 deletions

View File

@ -2425,17 +2425,18 @@ public class Animation {
} }
/** Changes a slot's {@link Slot#getSequenceIndex()} for an attachment's {@link Sequence}. */ /** Changes a slot's {@link Slot#getSequenceIndex()} for an attachment's {@link Sequence}. */
static public class SequenceTimeline<T extends Attachment & HasTextureRegion> extends Timeline implements SlotTimeline { static public class SequenceTimeline extends Timeline implements SlotTimeline {
static public final int ENTRIES = 3; static public final int ENTRIES = 3;
static private final int MODE = 1, FRAME_TIME = 2; static private final int MODE = 1, DELAY = 2;
final int slotIndex; final int slotIndex;
final T attachment; final HasTextureRegion attachment;
public SequenceTimeline (int frameCount, int slotIndex, T attachment) { public <T extends Attachment & HasTextureRegion> SequenceTimeline (int frameCount, int slotIndex, Attachment attachment) {
super(frameCount, Property.sequence.ordinal() + "|" + slotIndex + "|" + attachment.getSequence().getId()); super(frameCount,
Property.sequence.ordinal() + "|" + slotIndex + "|" + ((HasTextureRegion)attachment).getSequence().getId());
this.slotIndex = slotIndex; this.slotIndex = slotIndex;
this.attachment = attachment; this.attachment = (HasTextureRegion)attachment;
} }
public int getFrameEntries () { public int getFrameEntries () {
@ -2446,18 +2447,18 @@ public class Animation {
return slotIndex; return slotIndex;
} }
public T getAttachment () { public Attachment getAttachment () {
return attachment; return (Attachment)attachment;
} }
/** Sets the time, mode, index, and frame time for the specified frame. /** Sets the time, mode, index, and frame time for the specified frame.
* @param frame Between 0 and <code>frameCount</code>, inclusive. * @param frame Between 0 and <code>frameCount</code>, inclusive.
* @param time The frame time in seconds. */ * @param time Seconds between frames. */
public void setFrame (int frame, float time, SequenceMode mode, int index, float frameTime) { public void setFrame (int frame, float time, SequenceMode mode, int index, float delay) {
frame *= ENTRIES; frame *= ENTRIES;
frames[frame] = time; frames[frame] = time;
frames[frame + MODE] = mode.ordinal() | (index << 4); frames[frame + MODE] = mode.ordinal() | (index << 4);
frames[frame + FRAME_TIME] = frameTime; frames[frame + DELAY] = delay;
} }
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,
@ -2480,12 +2481,12 @@ public class Animation {
int i = search(frames, time, ENTRIES); int i = search(frames, time, ENTRIES);
float before = frames[i]; float before = frames[i];
int modeAndIndex = (int)frames[i + MODE]; int modeAndIndex = (int)frames[i + MODE];
float frameTime = frames[i + FRAME_TIME]; float delay = frames[i + DELAY];
int index = modeAndIndex >> 4, count = attachment.getSequence().getRegions().length; int index = modeAndIndex >> 4, count = attachment.getSequence().getRegions().length;
SequenceMode mode = SequenceMode.values[modeAndIndex & 0xf]; SequenceMode mode = SequenceMode.values[modeAndIndex & 0xf];
if (mode != SequenceMode.stop) { if (mode != SequenceMode.stop) {
index += (time - before) / frameTime; index += (time - before) / delay;
switch (mode) { switch (mode) {
case play: case play:
index = Math.min(count - 1, index); index = Math.min(count - 1, index);

View File

@ -58,10 +58,8 @@ public class Sequence {
public <T extends Attachment & HasTextureRegion> void apply (Slot slot, T attachment) { public <T extends Attachment & HasTextureRegion> void apply (Slot slot, T attachment) {
int index = slot.getSequenceIndex(); int index = slot.getSequenceIndex();
if (index == -1) if (index == -1) index = setupIndex;
index = setupIndex; if (index >= regions.length) index = regions.length - 1;
else if (index >= regions.length) //
index = regions.length - 1;
TextureRegion region = regions[index]; TextureRegion region = regions[index];
if (attachment.getRegion() != region) { if (attachment.getRegion() != region) {
attachment.setRegion(region); attachment.setRegion(region);