mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[libgdx] Store timeline ids inside set in Animation for O(1) lookup. See #1462.
This commit is contained in:
parent
b7da7fc6d7
commit
ecd1d67c25
@ -37,7 +37,7 @@ import com.badlogic.gdx.graphics.Color;
|
|||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.FloatArray;
|
import com.badlogic.gdx.utils.FloatArray;
|
||||||
|
import com.badlogic.gdx.utils.IntSet;
|
||||||
import com.esotericsoftware.spine.attachments.Attachment;
|
import com.esotericsoftware.spine.attachments.Attachment;
|
||||||
import com.esotericsoftware.spine.attachments.VertexAttachment;
|
import com.esotericsoftware.spine.attachments.VertexAttachment;
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ import com.esotericsoftware.spine.attachments.VertexAttachment;
|
|||||||
public class Animation {
|
public class Animation {
|
||||||
final String name;
|
final String name;
|
||||||
final Array<Timeline> timelines;
|
final Array<Timeline> timelines;
|
||||||
|
final IntSet timelineIds;
|
||||||
float duration;
|
float duration;
|
||||||
|
|
||||||
public Animation (String name, Array<Timeline> timelines, float duration) {
|
public Animation (String name, Array<Timeline> timelines, float duration) {
|
||||||
@ -52,6 +53,9 @@ public class Animation {
|
|||||||
if (timelines == null) throw new IllegalArgumentException("timelines cannot be null.");
|
if (timelines == null) throw new IllegalArgumentException("timelines cannot be null.");
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.timelines = timelines;
|
this.timelines = timelines;
|
||||||
|
this.timelineIds = new IntSet();
|
||||||
|
for (Timeline timeline : timelines)
|
||||||
|
timelineIds.add(timeline.getPropertyId());
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +63,11 @@ public class Animation {
|
|||||||
return timelines;
|
return timelines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether the timeline with the property id is contained in this animation **/
|
||||||
|
boolean hasTimeline (int id) {
|
||||||
|
return timelineIds.contains(id);
|
||||||
|
}
|
||||||
|
|
||||||
/** The duration of the animation in seconds, which is the highest time of all keys in the timeline. */
|
/** The duration of the animation in seconds, which is the highest time of all keys in the timeline. */
|
||||||
public float getDuration () {
|
public float getDuration () {
|
||||||
return duration;
|
return duration;
|
||||||
|
|||||||
@ -745,11 +745,11 @@ public class AnimationState {
|
|||||||
if (!propertyIDs.add(id))
|
if (!propertyIDs.add(id))
|
||||||
timelineMode[i] = SUBSEQUENT;
|
timelineMode[i] = SUBSEQUENT;
|
||||||
else if (to == null || timeline instanceof AttachmentTimeline || timeline instanceof DrawOrderTimeline
|
else if (to == null || timeline instanceof AttachmentTimeline || timeline instanceof DrawOrderTimeline
|
||||||
|| timeline instanceof EventTimeline || !hasTimeline(to, id)) {
|
|| timeline instanceof EventTimeline || !to.animation.hasTimeline(id)) {
|
||||||
timelineMode[i] = FIRST;
|
timelineMode[i] = FIRST;
|
||||||
} else {
|
} else {
|
||||||
for (TrackEntry next = to.mixingTo; next != null; next = next.mixingTo) {
|
for (TrackEntry next = to.mixingTo; next != null; next = next.mixingTo) {
|
||||||
if (hasTimeline(next, id)) continue;
|
if (next.animation.hasTimeline(id)) continue;
|
||||||
if (next.mixDuration > 0) {
|
if (next.mixDuration > 0) {
|
||||||
timelineMode[i] = HOLD_MIX;
|
timelineMode[i] = HOLD_MIX;
|
||||||
timelineHoldMix[i] = next;
|
timelineHoldMix[i] = next;
|
||||||
@ -776,13 +776,6 @@ public class AnimationState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasTimeline (TrackEntry entry, int id) {
|
|
||||||
Object[] timelines = entry.animation.timelines.items;
|
|
||||||
for (int i = 0, n = entry.animation.timelines.size; i < n; i++)
|
|
||||||
if (((Timeline)timelines[i]).getPropertyId() == id) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the track entry for the animation currently playing on the track, or null if no animation is currently playing. */
|
/** Returns the track entry for the animation currently playing on the track, or null if no animation is currently playing. */
|
||||||
public TrackEntry getCurrent (int trackIndex) {
|
public TrackEntry getCurrent (int trackIndex) {
|
||||||
if (trackIndex < 0) throw new IllegalArgumentException("trackIndex must be >= 0.");
|
if (trackIndex < 0) throw new IllegalArgumentException("trackIndex must be >= 0.");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user