mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-09 08:38:43 +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.utils.Array;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import com.badlogic.gdx.utils.IntSet;
|
||||
import com.esotericsoftware.spine.attachments.Attachment;
|
||||
import com.esotericsoftware.spine.attachments.VertexAttachment;
|
||||
|
||||
@ -45,6 +45,7 @@ import com.esotericsoftware.spine.attachments.VertexAttachment;
|
||||
public class Animation {
|
||||
final String name;
|
||||
final Array<Timeline> timelines;
|
||||
final IntSet timelineIds;
|
||||
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.");
|
||||
this.name = name;
|
||||
this.timelines = timelines;
|
||||
this.timelineIds = new IntSet();
|
||||
for (Timeline timeline : timelines)
|
||||
timelineIds.add(timeline.getPropertyId());
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@ -59,6 +63,11 @@ public class Animation {
|
||||
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. */
|
||||
public float getDuration () {
|
||||
return duration;
|
||||
|
||||
@ -745,11 +745,11 @@ public class AnimationState {
|
||||
if (!propertyIDs.add(id))
|
||||
timelineMode[i] = SUBSEQUENT;
|
||||
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;
|
||||
} else {
|
||||
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) {
|
||||
timelineMode[i] = HOLD_MIX;
|
||||
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. */
|
||||
public TrackEntry getCurrent (int trackIndex) {
|
||||
if (trackIndex < 0) throw new IllegalArgumentException("trackIndex must be >= 0.");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user