[as3] Store timeline ids inside set in Animation for O(1) lookup. See #1462.

This commit is contained in:
badlogic 2019-09-26 16:16:41 +02:00
parent 18eb242df6
commit 06089630fb
5 changed files with 10 additions and 9 deletions

View File

@ -30,10 +30,12 @@
package spine.animation {
import spine.Event;
import spine.Skeleton;
import flash.utils.Dictionary;
public class Animation {
internal var _name : String;
public var _timelines : Vector.<Timeline>;
internal var _timelineIds : Dictionary = new Dictionary();
public var duration : Number;
public function Animation(name : String, timelines : Vector.<Timeline>, duration : Number) {
@ -41,8 +43,14 @@ package spine.animation {
if (timelines == null) throw new ArgumentError("timelines cannot be null.");
_name = name;
_timelines = timelines;
for (var i : Number = 0; i < timelines.length; i++)
_timelineIds[timelines[i].getPropertyId()] = true;
this.duration = duration;
}
public function hasTimeline(id: Number) : Boolean {
return _timelineIds[id] == true;
}
public function get timelines() : Vector.<Timeline> {
return _timelines;

View File

@ -664,11 +664,11 @@ package spine.animation {
if (contained != null) {
timelineMode[i] = AnimationState.SUBSEQUENT;
} else if (to == null || timeline is AttachmentTimeline || timeline is DrawOrderTimeline
|| timeline is EventTimeline || !hasTimeline(to, intId)) {
|| timeline is EventTimeline || !to.animation.hasTimeline(intId)) {
timelineMode[i] = AnimationState.FIRST;
} else {
for (var next : TrackEntry = to.mixingTo; next != null; next = next.mixingTo) {
if (hasTimeline(next, intId)) continue;
if (next.animation.hasTimeline(intId)) continue;
if (entry.mixDuration > 0) {
timelineMode[i] = AnimationState.HOLD_MIX;
timelineHoldMix[i] = entry;
@ -681,13 +681,6 @@ package spine.animation {
}
}
private static function hasTimeline (entry: TrackEntry, id : int) : Boolean {
var timelines : Vector.<Timeline> = entry.animation.timelines;
for (var i : int = 0, n : int = entry.animation.timelines.length; i < n; i++)
if (timelines[i].getPropertyId() == id) return true;
return false;
}
public function getCurrent(trackIndex : int) : TrackEntry {
if (trackIndex >= tracks.length) return null;
return tracks[trackIndex];