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

This commit is contained in:
Harald Csaszar 2019-09-26 17:04:33 +02:00
parent 134bdf5a44
commit 001373c7de
2 changed files with 11 additions and 9 deletions

View File

@ -37,11 +37,15 @@ namespace Spine {
public class Animation {
internal String name;
internal ExposedList<Timeline> timelines;
internal HashSet<int> timelineIds;
internal float duration;
public Animation (string name, ExposedList<Timeline> timelines, float duration) {
if (name == null) throw new ArgumentNullException("name", "name cannot be null.");
if (timelines == null) throw new ArgumentNullException("timelines", "timelines cannot be null.");
this.timelineIds = new HashSet<int>();
foreach (Timeline timeline in timelines)
timelineIds.Add(timeline.PropertyId);
this.name = name;
this.timelines = timelines;
this.duration = duration;
@ -55,6 +59,11 @@ namespace Spine {
/// <summary>The animation's name, which is unique across all animations in the skeleton.</summary>
public string Name { get { return name; } }
/// <summary>Whether the timeline with the property id is contained in this animation.</summary>
public bool HasTimeline (int id) {
return timelineIds.Contains(id);
}
/// <summary>Applies all the animation's timelines to the specified skeleton.</summary>
/// <seealso cref="Timeline.Apply(Skeleton, float, float, ExposedList, float, MixBlend, MixDirection)"/>
public void Apply (Skeleton skeleton, float lastTime, float time, bool loop, ExposedList<Event> events, float alpha, MixBlend blend,

View File

@ -777,11 +777,11 @@ namespace Spine {
if (!propertyIDs.Add(id))
timelineMode[i] = AnimationState.Subsequent;
else if (to == null || timeline is AttachmentTimeline || timeline is DrawOrderTimeline
|| timeline is EventTimeline || !HasTimeline(to, id)) {
|| timeline is EventTimeline || !to.animation.HasTimeline(id)) {
timelineMode[i] = AnimationState.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] = AnimationState.HoldMix;
timelineHoldMix[i] = next;
@ -809,13 +809,6 @@ namespace Spine {
}
}
static bool HasTimeline (TrackEntry entry, int id) {
var timelines = entry.animation.timelines.Items;
for (int i = 0, n = entry.animation.timelines.Count; i < n; i++)
if (timelines[i].PropertyId == 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>
public TrackEntry GetCurrent (int trackIndex) {
if (trackIndex >= tracks.Count) return null;