瀏覽代碼

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

badlogic 6 年之前
父節點
當前提交
18eb242df6

+ 2 - 1
spine-ts/build/spine-all.d.ts

@@ -2,8 +2,10 @@ declare module spine {
 	class Animation {
 		name: string;
 		timelines: Array<Timeline>;
+		timelineIds: Array<boolean>;
 		duration: number;
 		constructor(name: string, timelines: Array<Timeline>, duration: number);
+		hasTimeline(id: number): boolean;
 		apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;
 		static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
 		static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
@@ -281,7 +283,6 @@ declare module spine {
 		_animationsChanged(): void;
 		computeHold(entry: TrackEntry): void;
 		computeNotLast(entry: TrackEntry): void;
-		hasTimeline(entry: TrackEntry, id: number): boolean;
 		getCurrent(trackIndex: number): TrackEntry;
 		addListener(listener: AnimationStateListener2): void;
 		removeListener(listener: AnimationStateListener2): void;

+ 8 - 9
spine-ts/build/spine-all.js

@@ -21,8 +21,14 @@ var spine;
 				throw new Error("timelines cannot be null.");
 			this.name = name;
 			this.timelines = timelines;
+			this.timelineIds = [];
+			for (var i = 0; i < timelines.length; i++)
+				this.timelineIds[timelines[i].getPropertyId()] = true;
 			this.duration = duration;
 		}
+		Animation.prototype.hasTimeline = function (id) {
+			return this.timelineIds[id] == true;
+		};
 		Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
 			if (skeleton == null)
 				throw new Error("skeleton cannot be null.");
@@ -1885,12 +1891,12 @@ var spine;
 				if (!propertyIDs.add(id))
 					timelineMode[i] = AnimationState.SUBSEQUENT;
 				else if (to == null || timeline instanceof spine.AttachmentTimeline || timeline instanceof spine.DrawOrderTimeline
-					|| timeline instanceof spine.EventTimeline || !this.hasTimeline(to, id)) {
+					|| timeline instanceof spine.EventTimeline || !to.animation.hasTimeline(id)) {
 					timelineMode[i] = AnimationState.FIRST;
 				}
 				else {
 					for (var next = to.mixingTo; next != null; next = next.mixingTo) {
-						if (this.hasTimeline(next, id))
+						if (next.animation.hasTimeline(id))
 							continue;
 						if (entry.mixDuration > 0) {
 							timelineMode[i] = AnimationState.HOLD_MIX;
@@ -1916,13 +1922,6 @@ var spine;
 				}
 			}
 		};
-		AnimationState.prototype.hasTimeline = function (entry, id) {
-			var timelines = entry.animation.timelines;
-			for (var i = 0, n = timelines.length; i < n; i++)
-				if (timelines[i].getPropertyId() == id)
-					return true;
-			return false;
-		};
 		AnimationState.prototype.getCurrent = function (trackIndex) {
 			if (trackIndex >= this.tracks.length)
 				return null;

文件差異過大導致無法顯示
+ 0 - 0
spine-ts/build/spine-all.js.map


+ 2 - 1
spine-ts/build/spine-canvas.d.ts

@@ -2,8 +2,10 @@ declare module spine {
 	class Animation {
 		name: string;
 		timelines: Array<Timeline>;
+		timelineIds: Array<boolean>;
 		duration: number;
 		constructor(name: string, timelines: Array<Timeline>, duration: number);
+		hasTimeline(id: number): boolean;
 		apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;
 		static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
 		static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
@@ -281,7 +283,6 @@ declare module spine {
 		_animationsChanged(): void;
 		computeHold(entry: TrackEntry): void;
 		computeNotLast(entry: TrackEntry): void;
-		hasTimeline(entry: TrackEntry, id: number): boolean;
 		getCurrent(trackIndex: number): TrackEntry;
 		addListener(listener: AnimationStateListener2): void;
 		removeListener(listener: AnimationStateListener2): void;

+ 8 - 9
spine-ts/build/spine-canvas.js

@@ -21,8 +21,14 @@ var spine;
 				throw new Error("timelines cannot be null.");
 			this.name = name;
 			this.timelines = timelines;
+			this.timelineIds = [];
+			for (var i = 0; i < timelines.length; i++)
+				this.timelineIds[timelines[i].getPropertyId()] = true;
 			this.duration = duration;
 		}
+		Animation.prototype.hasTimeline = function (id) {
+			return this.timelineIds[id] == true;
+		};
 		Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
 			if (skeleton == null)
 				throw new Error("skeleton cannot be null.");
@@ -1885,12 +1891,12 @@ var spine;
 				if (!propertyIDs.add(id))
 					timelineMode[i] = AnimationState.SUBSEQUENT;
 				else if (to == null || timeline instanceof spine.AttachmentTimeline || timeline instanceof spine.DrawOrderTimeline
-					|| timeline instanceof spine.EventTimeline || !this.hasTimeline(to, id)) {
+					|| timeline instanceof spine.EventTimeline || !to.animation.hasTimeline(id)) {
 					timelineMode[i] = AnimationState.FIRST;
 				}
 				else {
 					for (var next = to.mixingTo; next != null; next = next.mixingTo) {
-						if (this.hasTimeline(next, id))
+						if (next.animation.hasTimeline(id))
 							continue;
 						if (entry.mixDuration > 0) {
 							timelineMode[i] = AnimationState.HOLD_MIX;
@@ -1916,13 +1922,6 @@ var spine;
 				}
 			}
 		};
-		AnimationState.prototype.hasTimeline = function (entry, id) {
-			var timelines = entry.animation.timelines;
-			for (var i = 0, n = timelines.length; i < n; i++)
-				if (timelines[i].getPropertyId() == id)
-					return true;
-			return false;
-		};
 		AnimationState.prototype.getCurrent = function (trackIndex) {
 			if (trackIndex >= this.tracks.length)
 				return null;

文件差異過大導致無法顯示
+ 0 - 0
spine-ts/build/spine-canvas.js.map


+ 2 - 1
spine-ts/build/spine-core.d.ts

@@ -2,8 +2,10 @@ declare module spine {
 	class Animation {
 		name: string;
 		timelines: Array<Timeline>;
+		timelineIds: Array<boolean>;
 		duration: number;
 		constructor(name: string, timelines: Array<Timeline>, duration: number);
+		hasTimeline(id: number): boolean;
 		apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;
 		static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
 		static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
@@ -281,7 +283,6 @@ declare module spine {
 		_animationsChanged(): void;
 		computeHold(entry: TrackEntry): void;
 		computeNotLast(entry: TrackEntry): void;
-		hasTimeline(entry: TrackEntry, id: number): boolean;
 		getCurrent(trackIndex: number): TrackEntry;
 		addListener(listener: AnimationStateListener2): void;
 		removeListener(listener: AnimationStateListener2): void;

+ 8 - 9
spine-ts/build/spine-core.js

@@ -21,8 +21,14 @@ var spine;
 				throw new Error("timelines cannot be null.");
 			this.name = name;
 			this.timelines = timelines;
+			this.timelineIds = [];
+			for (var i = 0; i < timelines.length; i++)
+				this.timelineIds[timelines[i].getPropertyId()] = true;
 			this.duration = duration;
 		}
+		Animation.prototype.hasTimeline = function (id) {
+			return this.timelineIds[id] == true;
+		};
 		Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
 			if (skeleton == null)
 				throw new Error("skeleton cannot be null.");
@@ -1885,12 +1891,12 @@ var spine;
 				if (!propertyIDs.add(id))
 					timelineMode[i] = AnimationState.SUBSEQUENT;
 				else if (to == null || timeline instanceof spine.AttachmentTimeline || timeline instanceof spine.DrawOrderTimeline
-					|| timeline instanceof spine.EventTimeline || !this.hasTimeline(to, id)) {
+					|| timeline instanceof spine.EventTimeline || !to.animation.hasTimeline(id)) {
 					timelineMode[i] = AnimationState.FIRST;
 				}
 				else {
 					for (var next = to.mixingTo; next != null; next = next.mixingTo) {
-						if (this.hasTimeline(next, id))
+						if (next.animation.hasTimeline(id))
 							continue;
 						if (entry.mixDuration > 0) {
 							timelineMode[i] = AnimationState.HOLD_MIX;
@@ -1916,13 +1922,6 @@ var spine;
 				}
 			}
 		};
-		AnimationState.prototype.hasTimeline = function (entry, id) {
-			var timelines = entry.animation.timelines;
-			for (var i = 0, n = timelines.length; i < n; i++)
-				if (timelines[i].getPropertyId() == id)
-					return true;
-			return false;
-		};
 		AnimationState.prototype.getCurrent = function (trackIndex) {
 			if (trackIndex >= this.tracks.length)
 				return null;

文件差異過大導致無法顯示
+ 0 - 0
spine-ts/build/spine-core.js.map


+ 2 - 1
spine-ts/build/spine-player.d.ts

@@ -2,8 +2,10 @@ declare module spine {
 	class Animation {
 		name: string;
 		timelines: Array<Timeline>;
+		timelineIds: Array<boolean>;
 		duration: number;
 		constructor(name: string, timelines: Array<Timeline>, duration: number);
+		hasTimeline(id: number): boolean;
 		apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;
 		static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
 		static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
@@ -281,7 +283,6 @@ declare module spine {
 		_animationsChanged(): void;
 		computeHold(entry: TrackEntry): void;
 		computeNotLast(entry: TrackEntry): void;
-		hasTimeline(entry: TrackEntry, id: number): boolean;
 		getCurrent(trackIndex: number): TrackEntry;
 		addListener(listener: AnimationStateListener2): void;
 		removeListener(listener: AnimationStateListener2): void;

+ 8 - 9
spine-ts/build/spine-player.js

@@ -21,8 +21,14 @@ var spine;
 				throw new Error("timelines cannot be null.");
 			this.name = name;
 			this.timelines = timelines;
+			this.timelineIds = [];
+			for (var i = 0; i < timelines.length; i++)
+				this.timelineIds[timelines[i].getPropertyId()] = true;
 			this.duration = duration;
 		}
+		Animation.prototype.hasTimeline = function (id) {
+			return this.timelineIds[id] == true;
+		};
 		Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
 			if (skeleton == null)
 				throw new Error("skeleton cannot be null.");
@@ -1885,12 +1891,12 @@ var spine;
 				if (!propertyIDs.add(id))
 					timelineMode[i] = AnimationState.SUBSEQUENT;
 				else if (to == null || timeline instanceof spine.AttachmentTimeline || timeline instanceof spine.DrawOrderTimeline
-					|| timeline instanceof spine.EventTimeline || !this.hasTimeline(to, id)) {
+					|| timeline instanceof spine.EventTimeline || !to.animation.hasTimeline(id)) {
 					timelineMode[i] = AnimationState.FIRST;
 				}
 				else {
 					for (var next = to.mixingTo; next != null; next = next.mixingTo) {
-						if (this.hasTimeline(next, id))
+						if (next.animation.hasTimeline(id))
 							continue;
 						if (entry.mixDuration > 0) {
 							timelineMode[i] = AnimationState.HOLD_MIX;
@@ -1916,13 +1922,6 @@ var spine;
 				}
 			}
 		};
-		AnimationState.prototype.hasTimeline = function (entry, id) {
-			var timelines = entry.animation.timelines;
-			for (var i = 0, n = timelines.length; i < n; i++)
-				if (timelines[i].getPropertyId() == id)
-					return true;
-			return false;
-		};
 		AnimationState.prototype.getCurrent = function (trackIndex) {
 			if (trackIndex >= this.tracks.length)
 				return null;

文件差異過大導致無法顯示
+ 0 - 0
spine-ts/build/spine-player.js.map


+ 2 - 1
spine-ts/build/spine-threejs.d.ts

@@ -2,8 +2,10 @@ declare module spine {
 	class Animation {
 		name: string;
 		timelines: Array<Timeline>;
+		timelineIds: Array<boolean>;
 		duration: number;
 		constructor(name: string, timelines: Array<Timeline>, duration: number);
+		hasTimeline(id: number): boolean;
 		apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;
 		static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
 		static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
@@ -281,7 +283,6 @@ declare module spine {
 		_animationsChanged(): void;
 		computeHold(entry: TrackEntry): void;
 		computeNotLast(entry: TrackEntry): void;
-		hasTimeline(entry: TrackEntry, id: number): boolean;
 		getCurrent(trackIndex: number): TrackEntry;
 		addListener(listener: AnimationStateListener2): void;
 		removeListener(listener: AnimationStateListener2): void;

+ 8 - 9
spine-ts/build/spine-threejs.js

@@ -21,8 +21,14 @@ var spine;
 				throw new Error("timelines cannot be null.");
 			this.name = name;
 			this.timelines = timelines;
+			this.timelineIds = [];
+			for (var i = 0; i < timelines.length; i++)
+				this.timelineIds[timelines[i].getPropertyId()] = true;
 			this.duration = duration;
 		}
+		Animation.prototype.hasTimeline = function (id) {
+			return this.timelineIds[id] == true;
+		};
 		Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
 			if (skeleton == null)
 				throw new Error("skeleton cannot be null.");
@@ -1885,12 +1891,12 @@ var spine;
 				if (!propertyIDs.add(id))
 					timelineMode[i] = AnimationState.SUBSEQUENT;
 				else if (to == null || timeline instanceof spine.AttachmentTimeline || timeline instanceof spine.DrawOrderTimeline
-					|| timeline instanceof spine.EventTimeline || !this.hasTimeline(to, id)) {
+					|| timeline instanceof spine.EventTimeline || !to.animation.hasTimeline(id)) {
 					timelineMode[i] = AnimationState.FIRST;
 				}
 				else {
 					for (var next = to.mixingTo; next != null; next = next.mixingTo) {
-						if (this.hasTimeline(next, id))
+						if (next.animation.hasTimeline(id))
 							continue;
 						if (entry.mixDuration > 0) {
 							timelineMode[i] = AnimationState.HOLD_MIX;
@@ -1916,13 +1922,6 @@ var spine;
 				}
 			}
 		};
-		AnimationState.prototype.hasTimeline = function (entry, id) {
-			var timelines = entry.animation.timelines;
-			for (var i = 0, n = timelines.length; i < n; i++)
-				if (timelines[i].getPropertyId() == id)
-					return true;
-			return false;
-		};
 		AnimationState.prototype.getCurrent = function (trackIndex) {
 			if (trackIndex >= this.tracks.length)
 				return null;

文件差異過大導致無法顯示
+ 0 - 0
spine-ts/build/spine-threejs.js.map


+ 2 - 1
spine-ts/build/spine-webgl.d.ts

@@ -2,8 +2,10 @@ declare module spine {
 	class Animation {
 		name: string;
 		timelines: Array<Timeline>;
+		timelineIds: Array<boolean>;
 		duration: number;
 		constructor(name: string, timelines: Array<Timeline>, duration: number);
+		hasTimeline(id: number): boolean;
 		apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;
 		static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
 		static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
@@ -281,7 +283,6 @@ declare module spine {
 		_animationsChanged(): void;
 		computeHold(entry: TrackEntry): void;
 		computeNotLast(entry: TrackEntry): void;
-		hasTimeline(entry: TrackEntry, id: number): boolean;
 		getCurrent(trackIndex: number): TrackEntry;
 		addListener(listener: AnimationStateListener2): void;
 		removeListener(listener: AnimationStateListener2): void;

+ 8 - 9
spine-ts/build/spine-webgl.js

@@ -21,8 +21,14 @@ var spine;
 				throw new Error("timelines cannot be null.");
 			this.name = name;
 			this.timelines = timelines;
+			this.timelineIds = [];
+			for (var i = 0; i < timelines.length; i++)
+				this.timelineIds[timelines[i].getPropertyId()] = true;
 			this.duration = duration;
 		}
+		Animation.prototype.hasTimeline = function (id) {
+			return this.timelineIds[id] == true;
+		};
 		Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
 			if (skeleton == null)
 				throw new Error("skeleton cannot be null.");
@@ -1885,12 +1891,12 @@ var spine;
 				if (!propertyIDs.add(id))
 					timelineMode[i] = AnimationState.SUBSEQUENT;
 				else if (to == null || timeline instanceof spine.AttachmentTimeline || timeline instanceof spine.DrawOrderTimeline
-					|| timeline instanceof spine.EventTimeline || !this.hasTimeline(to, id)) {
+					|| timeline instanceof spine.EventTimeline || !to.animation.hasTimeline(id)) {
 					timelineMode[i] = AnimationState.FIRST;
 				}
 				else {
 					for (var next = to.mixingTo; next != null; next = next.mixingTo) {
-						if (this.hasTimeline(next, id))
+						if (next.animation.hasTimeline(id))
 							continue;
 						if (entry.mixDuration > 0) {
 							timelineMode[i] = AnimationState.HOLD_MIX;
@@ -1916,13 +1922,6 @@ var spine;
 				}
 			}
 		};
-		AnimationState.prototype.hasTimeline = function (entry, id) {
-			var timelines = entry.animation.timelines;
-			for (var i = 0, n = timelines.length; i < n; i++)
-				if (timelines[i].getPropertyId() == id)
-					return true;
-			return false;
-		};
 		AnimationState.prototype.getCurrent = function (trackIndex) {
 			if (trackIndex >= this.tracks.length)
 				return null;

文件差異過大導致無法顯示
+ 0 - 0
spine-ts/build/spine-webgl.js.map


+ 8 - 0
spine-ts/core/src/Animation.ts

@@ -31,6 +31,7 @@ module spine {
 	export class Animation {
 		name: string;
 		timelines: Array<Timeline>;
+		timelineIds: Array<boolean>;
 		duration: number;
 
 		constructor (name: string, timelines: Array<Timeline>, duration: number) {
@@ -38,9 +39,16 @@ module spine {
 			if (timelines == null) throw new Error("timelines cannot be null.");
 			this.name = name;
 			this.timelines = timelines;
+			this.timelineIds = [];
+			for (var i = 0; i < timelines.length; i++)
+				this.timelineIds[timelines[i].getPropertyId()] = true;
 			this.duration = duration;
 		}
 
+		hasTimeline (id: number) {
+			return this.timelineIds[id] == true;
+		}
+
 		apply (skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection) {
 			if (skeleton == null) throw new Error("skeleton cannot be null.");
 

+ 2 - 9
spine-ts/core/src/AnimationState.ts

@@ -632,11 +632,11 @@ module spine {
 				if (!propertyIDs.add(id))
 					timelineMode[i] = AnimationState.SUBSEQUENT;
 				else if (to == null || timeline instanceof AttachmentTimeline || timeline instanceof DrawOrderTimeline
-					|| timeline instanceof EventTimeline || !this.hasTimeline(to, id)) {
+					|| timeline instanceof EventTimeline || !to.animation.hasTimeline(id)) {
 					timelineMode[i] = AnimationState.FIRST;
 				} else {
 					for (let next = to.mixingTo; next != null; next = next.mixingTo) {
-						if (this.hasTimeline(next, id)) continue;
+						if (next.animation.hasTimeline(id)) continue;
 						if (entry.mixDuration > 0) {
 							timelineMode[i] = AnimationState.HOLD_MIX;
 							timelineDipMix[i] = next;
@@ -663,13 +663,6 @@ module spine {
 			}
 		}
 
-		hasTimeline (entry: TrackEntry, id: number) : boolean {
-			let timelines = entry.animation.timelines;
-			for (let i = 0, n = timelines.length; i < n; i++)
-				if (timelines[i].getPropertyId() == id) return true;
-			return false;
-		}
-
 		getCurrent (trackIndex: number) {
 			if (trackIndex >= this.tracks.length) return null;
 			return this.tracks[trackIndex];

部分文件因文件數量過多而無法顯示