ソースを参照

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

Harald Csaszar 6 年 前
コミット
570f8df178
2 ファイル変更11 行追加9 行削除
  1. 9 0
      spine-csharp/src/Animation.cs
  2. 2 9
      spine-csharp/src/AnimationState.cs

+ 9 - 0
spine-csharp/src/Animation.cs

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

+ 2 - 9
spine-csharp/src/AnimationState.cs

@@ -777,11 +777,11 @@ namespace Spine {
 				if (!propertyIDs.Add(id))
 				if (!propertyIDs.Add(id))
 					timelineMode[i] = AnimationState.Subsequent;
 					timelineMode[i] = AnimationState.Subsequent;
 				else if (to == null || timeline is AttachmentTimeline || timeline is DrawOrderTimeline
 				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;
 					timelineMode[i] = AnimationState.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] = AnimationState.HoldMix;
 							timelineMode[i] = AnimationState.HoldMix;
 							timelineHoldMix[i] = next;
 							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>
 		/// <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) {
 		public TrackEntry GetCurrent (int trackIndex) {
 			if (trackIndex >= tracks.Count) return null;
 			if (trackIndex >= tracks.Count) return null;