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

This commit is contained in:
badlogic 2019-09-26 15:13:19 +02:00
parent ecd1d67c25
commit 67650c9b79
20 changed files with 76 additions and 20 deletions

View File

@ -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;

View File

@ -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;

File diff suppressed because one or more lines are too long

View File

@ -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;

View File

@ -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;

File diff suppressed because one or more lines are too long

View File

@ -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;

View File

@ -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;

File diff suppressed because one or more lines are too long

View File

@ -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;

View File

@ -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;

File diff suppressed because one or more lines are too long

View File

@ -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;

View File

@ -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;

File diff suppressed because one or more lines are too long

View File

@ -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;

View File

@ -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;

File diff suppressed because one or more lines are too long

View File

@ -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.");

View File

@ -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;