[ts] Ported holdPrevious addition in AnimationState. See #1169."

This commit is contained in:
badlogic 2018-09-07 16:37:38 +02:00
parent 97c978a749
commit 519d7a6278
20 changed files with 694 additions and 602 deletions

View File

@ -244,15 +244,14 @@ declare module spine {
static emptyAnimation: Animation; static emptyAnimation: Animation;
static SUBSEQUENT: number; static SUBSEQUENT: number;
static FIRST: number; static FIRST: number;
static DIP: number; static HOLD: number;
static DIP_MIX: number; static HOLD_MIX: number;
data: AnimationStateData; data: AnimationStateData;
tracks: TrackEntry[]; tracks: TrackEntry[];
events: Event[]; events: Event[];
listeners: AnimationStateListener2[]; listeners: AnimationStateListener2[];
queue: EventQueue; queue: EventQueue;
propertyIDs: IntSet; propertyIDs: IntSet;
mixingTo: TrackEntry[];
animationsChanged: boolean; animationsChanged: boolean;
timeScale: number; timeScale: number;
trackEntryPool: Pool<TrackEntry>; trackEntryPool: Pool<TrackEntry>;
@ -277,6 +276,8 @@ declare module spine {
trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry; trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry;
disposeNext(entry: TrackEntry): void; disposeNext(entry: TrackEntry): void;
_animationsChanged(): void; _animationsChanged(): void;
setTimelineModes(entry: TrackEntry): void;
hasTimeline(entry: TrackEntry, id: number): boolean;
getCurrent(trackIndex: number): TrackEntry; getCurrent(trackIndex: number): TrackEntry;
addListener(listener: AnimationStateListener2): void; addListener(listener: AnimationStateListener2): void;
removeListener(listener: AnimationStateListener2): void; removeListener(listener: AnimationStateListener2): void;
@ -287,9 +288,11 @@ declare module spine {
animation: Animation; animation: Animation;
next: TrackEntry; next: TrackEntry;
mixingFrom: TrackEntry; mixingFrom: TrackEntry;
mixingTo: TrackEntry;
listener: AnimationStateListener2; listener: AnimationStateListener2;
trackIndex: number; trackIndex: number;
loop: boolean; loop: boolean;
holdPrevious: boolean;
eventThreshold: number; eventThreshold: number;
attachmentThreshold: number; attachmentThreshold: number;
drawOrderThreshold: number; drawOrderThreshold: number;
@ -309,12 +312,10 @@ declare module spine {
interruptAlpha: number; interruptAlpha: number;
totalAlpha: number; totalAlpha: number;
mixBlend: MixBlend; mixBlend: MixBlend;
timelineData: number[]; timelineMode: number[];
timelineDipMix: TrackEntry[]; timelineHoldMix: TrackEntry[];
timelinesRotation: number[]; timelinesRotation: number[];
reset(): void; reset(): void;
setTimelineData(to: TrackEntry, mixingToArray: Array<TrackEntry>, propertyIDs: IntSet): TrackEntry;
hasTimeline(id: number): boolean;
getAnimationTime(): number; getAnimationTime(): number;
setAnimationLast(animationLast: number): void; setAnimationLast(animationLast: number): void;
isComplete(): boolean; isComplete(): boolean;

View File

@ -1303,7 +1303,6 @@ var spine;
this.listeners = new Array(); this.listeners = new Array();
this.queue = new EventQueue(this); this.queue = new EventQueue(this);
this.propertyIDs = new spine.IntSet(); this.propertyIDs = new spine.IntSet();
this.mixingTo = new Array();
this.animationsChanged = false; this.animationsChanged = false;
this.timeScale = 1; this.timeScale = 1;
this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); }); this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
@ -1350,6 +1349,8 @@ var spine;
if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) { if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
var from = current.mixingFrom; var from = current.mixingFrom;
current.mixingFrom = null; current.mixingFrom = null;
if (from != null)
from.mixingTo = null;
while (from != null) { while (from != null) {
this.queue.end(from); this.queue.end(from);
from = from.mixingFrom; from = from.mixingFrom;
@ -1369,6 +1370,8 @@ var spine;
if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) { if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) {
if (from.totalAlpha == 0 || to.mixDuration == 0) { if (from.totalAlpha == 0 || to.mixDuration == 0) {
to.mixingFrom = from.mixingFrom; to.mixingFrom = from.mixingFrom;
if (from.mixingFrom != null)
from.mixingFrom.mixingTo = to;
to.interruptAlpha = from.interruptAlpha; to.interruptAlpha = from.interruptAlpha;
this.queue.end(from); this.queue.end(from);
} }
@ -1400,19 +1403,19 @@ var spine;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
var timelineCount = current.animation.timelines.length; var timelineCount = current.animation.timelines.length;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1 || blend == spine.MixBlend.add) { if (i == 0 && (mix == 1 || blend == spine.MixBlend.add)) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]); timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]);
} }
else { else {
var timelineData = current.timelineData; var timelineMode = current.timelineMode;
var firstFrame = current.timelinesRotation.length == 0; var firstFrame = current.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var timelineBlend = timelineData[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup; var timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
} }
@ -1452,14 +1455,14 @@ var spine;
var animationLast = from.animationLast, animationTime = from.getAnimationTime(); var animationLast = from.animationLast, animationTime = from.getAnimationTime();
var timelineCount = from.animation.timelines.length; var timelineCount = from.animation.timelines.length;
var timelines = from.animation.timelines; var timelines = from.animation.timelines;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix); var alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
if (blend == spine.MixBlend.add) { if (blend == spine.MixBlend.add) {
for (var i = 0; i < timelineCount; i++) for (var i = 0; i < timelineCount; i++)
timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out); timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out);
} }
else { else {
var timelineData = from.timelineData; var timelineMode = from.timelineMode;
var timelineDipMix = from.timelineDipMix; var timelineHoldMix = from.timelineHoldMix;
var firstFrame = from.timelinesRotation.length == 0; var firstFrame = from.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
@ -1469,7 +1472,7 @@ var spine;
var timeline = timelines[i]; var timeline = timelines[i];
var timelineBlend; var timelineBlend;
var alpha = 0; var alpha = 0;
switch (timelineData[i]) { switch (timelineMode[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
if (!attachments && timeline instanceof spine.AttachmentTimeline) if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue; continue;
@ -1482,14 +1485,14 @@ var spine;
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.HOLD:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaDip; alpha = alphaHold;
break; break;
default: default:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
var dipMix = timelineDipMix[i]; var holdMix = timelineHoldMix[i];
alpha = alphaDip * Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
break; break;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
@ -1619,6 +1622,7 @@ var spine;
break; break;
this.queue.end(from); this.queue.end(from);
entry.mixingFrom = null; entry.mixingFrom = null;
entry.mixingTo = null;
entry = from; entry = from;
} }
this.tracks[current.trackIndex] = null; this.tracks[current.trackIndex] = null;
@ -1631,6 +1635,7 @@ var spine;
if (interrupt) if (interrupt)
this.queue.interrupt(from); this.queue.interrupt(from);
current.mixingFrom = from; current.mixingFrom = from;
from.mixingTo = current;
current.mixTime = 0; current.mixTime = 0;
if (from.mixingFrom != null && from.mixDuration > 0) if (from.mixingFrom != null && from.mixDuration > 0)
current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration); current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
@ -1740,6 +1745,7 @@ var spine;
entry.trackIndex = trackIndex; entry.trackIndex = trackIndex;
entry.animation = animation; entry.animation = animation;
entry.loop = loop; entry.loop = loop;
entry.holdPrevious = false;
entry.eventThreshold = 0; entry.eventThreshold = 0;
entry.attachmentThreshold = 0; entry.attachmentThreshold = 0;
entry.drawOrderThreshold = 0; entry.drawOrderThreshold = 0;
@ -1769,15 +1775,63 @@ var spine;
}; };
AnimationState.prototype._animationsChanged = function () { AnimationState.prototype._animationsChanged = function () {
this.animationsChanged = false; this.animationsChanged = false;
var propertyIDs = this.propertyIDs; this.propertyIDs.clear();
propertyIDs.clear();
var mixingTo = this.mixingTo;
for (var i = 0, n = this.tracks.length; i < n; i++) { for (var i = 0, n = this.tracks.length; i < n; i++) {
var entry = this.tracks[i]; var entry = this.tracks[i];
if (entry != null && (i == 0 || entry.mixBlend != spine.MixBlend.add)) if (entry == null)
entry.setTimelineData(null, mixingTo, propertyIDs); continue;
while (entry.mixingFrom != null)
entry = entry.mixingFrom;
do {
if (entry.mixingFrom == null || entry.mixBlend != spine.MixBlend.add)
this.setTimelineModes(entry);
entry = entry.mixingTo;
} while (entry != null);
} }
}; };
AnimationState.prototype.setTimelineModes = function (entry) {
var to = entry.mixingTo;
var timelines = entry.animation.timelines;
var timelinesCount = entry.animation.timelines.length;
var timelineMode = spine.Utils.setArraySize(entry.timelineMode, timelinesCount);
entry.timelineHoldMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
var propertyIDs = this.propertyIDs;
if (to != null && to.holdPrevious) {
for (var i_16 = 0; i_16 < timelinesCount; i_16++) {
propertyIDs.add(timelines[i_16].getPropertyId());
timelineMode[i_16] = AnimationState.HOLD;
}
return;
}
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineMode[i] = AnimationState.SUBSEQUENT;
else if (to == null || !this.hasTimeline(to, id))
timelineMode[i] = AnimationState.FIRST;
else {
for (var next = to.mixingTo; next != null; next = next.mixingTo) {
if (this.hasTimeline(next, id))
continue;
if (entry.mixDuration > 0) {
timelineMode[i] = AnimationState.HOLD_MIX;
timelineDipMix[i] = next;
continue outer;
}
break;
}
timelineMode[i] = AnimationState.HOLD;
}
}
};
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) { AnimationState.prototype.getCurrent = function (trackIndex) {
if (trackIndex >= this.tracks.length) if (trackIndex >= this.tracks.length)
return null; return null;
@ -1802,16 +1856,16 @@ var spine;
AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0); AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
AnimationState.SUBSEQUENT = 0; AnimationState.SUBSEQUENT = 0;
AnimationState.FIRST = 1; AnimationState.FIRST = 1;
AnimationState.DIP = 2; AnimationState.HOLD = 2;
AnimationState.DIP_MIX = 3; AnimationState.HOLD_MIX = 3;
return AnimationState; return AnimationState;
}()); }());
spine.AnimationState = AnimationState; spine.AnimationState = AnimationState;
var TrackEntry = (function () { var TrackEntry = (function () {
function TrackEntry() { function TrackEntry() {
this.mixBlend = spine.MixBlend.replace; this.mixBlend = spine.MixBlend.replace;
this.timelineData = new Array(); this.timelineMode = new Array();
this.timelineDipMix = new Array(); this.timelineHoldMix = new Array();
this.timelinesRotation = new Array(); this.timelinesRotation = new Array();
} }
TrackEntry.prototype.reset = function () { TrackEntry.prototype.reset = function () {
@ -1819,52 +1873,10 @@ var spine;
this.mixingFrom = null; this.mixingFrom = null;
this.animation = null; this.animation = null;
this.listener = null; this.listener = null;
this.timelineData.length = 0; this.timelineMode.length = 0;
this.timelineDipMix.length = 0; this.timelineHoldMix.length = 0;
this.timelinesRotation.length = 0; this.timelinesRotation.length = 0;
}; };
TrackEntry.prototype.setTimelineData = function (to, mixingToArray, propertyIDs) {
if (to != null)
mixingToArray.push(to);
var lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
if (to != null)
mixingToArray.pop();
var mixingTo = mixingToArray;
var mixingToLast = mixingToArray.length - 1;
var timelines = this.animation.timelines;
var timelinesCount = this.animation.timelines.length;
var timelineData = spine.Utils.setArraySize(this.timelineData, timelinesCount);
this.timelineDipMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(this.timelineDipMix, timelinesCount);
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineData[i] = AnimationState.SUBSEQUENT;
else if (to == null || !to.hasTimeline(id))
timelineData[i] = AnimationState.FIRST;
else {
for (var ii = mixingToLast; ii >= 0; ii--) {
var entry = mixingTo[ii];
if (!entry.hasTimeline(id)) {
if (entry.mixDuration > 0) {
timelineData[i] = AnimationState.DIP_MIX;
timelineDipMix[i] = entry;
continue outer;
}
}
}
timelineData[i] = AnimationState.DIP;
}
}
return lastEntry;
};
TrackEntry.prototype.hasTimeline = function (id) {
var timelines = this.animation.timelines;
for (var i = 0, n = timelines.length; i < n; i++)
if (timelines[i].getPropertyId() == id)
return true;
return false;
};
TrackEntry.prototype.getAnimationTime = function () { TrackEntry.prototype.getAnimationTime = function () {
if (this.loop) { if (this.loop) {
var duration = this.animationEnd - this.animationStart; var duration = this.animationEnd - this.animationStart;
@ -7266,8 +7278,8 @@ var spine;
break; break;
} }
var listeners = _this.listeners; var listeners = _this.listeners;
for (var i_16 = 0; i_16 < listeners.length; i_16++) { for (var i_17 = 0; i_17 < listeners.length; i_17++) {
listeners[i_16].down(_this.currTouch.x, _this.currTouch.y); listeners[i_17].down(_this.currTouch.x, _this.currTouch.y);
} }
console.log("Start " + _this.currTouch.x + ", " + _this.currTouch.y); console.log("Start " + _this.currTouch.x + ", " + _this.currTouch.y);
_this.lastX = _this.currTouch.x; _this.lastX = _this.currTouch.x;
@ -7276,29 +7288,6 @@ var spine;
ev.preventDefault(); ev.preventDefault();
}, false); }, false);
element.addEventListener("touchend", function (ev) { element.addEventListener("touchend", function (ev) {
var touches = ev.changedTouches;
for (var i = 0; i < touches.length; i++) {
var touch = touches[i];
if (_this.currTouch.identifier === touch.identifier) {
var rect = element.getBoundingClientRect();
var x = _this.currTouch.x = touch.clientX - rect.left;
var y = _this.currTouch.y = touch.clientY - rect.top;
_this.touchesPool.free(_this.currTouch);
var listeners = _this.listeners;
for (var i_17 = 0; i_17 < listeners.length; i_17++) {
listeners[i_17].up(x, y);
}
console.log("End " + x + ", " + y);
_this.lastX = x;
_this.lastY = y;
_this.buttonDown = false;
_this.currTouch = null;
break;
}
}
ev.preventDefault();
}, false);
element.addEventListener("touchcancel", function (ev) {
var touches = ev.changedTouches; var touches = ev.changedTouches;
for (var i = 0; i < touches.length; i++) { for (var i = 0; i < touches.length; i++) {
var touch = touches[i]; var touch = touches[i];
@ -7321,6 +7310,29 @@ var spine;
} }
ev.preventDefault(); ev.preventDefault();
}, false); }, false);
element.addEventListener("touchcancel", function (ev) {
var touches = ev.changedTouches;
for (var i = 0; i < touches.length; i++) {
var touch = touches[i];
if (_this.currTouch.identifier === touch.identifier) {
var rect = element.getBoundingClientRect();
var x = _this.currTouch.x = touch.clientX - rect.left;
var y = _this.currTouch.y = touch.clientY - rect.top;
_this.touchesPool.free(_this.currTouch);
var listeners = _this.listeners;
for (var i_19 = 0; i_19 < listeners.length; i_19++) {
listeners[i_19].up(x, y);
}
console.log("End " + x + ", " + y);
_this.lastX = x;
_this.lastY = y;
_this.buttonDown = false;
_this.currTouch = null;
break;
}
}
ev.preventDefault();
}, false);
element.addEventListener("touchmove", function (ev) { element.addEventListener("touchmove", function (ev) {
if (_this.currTouch == null) if (_this.currTouch == null)
return; return;
@ -7332,8 +7344,8 @@ var spine;
var x = touch.clientX - rect.left; var x = touch.clientX - rect.left;
var y = touch.clientY - rect.top; var y = touch.clientY - rect.top;
var listeners = _this.listeners; var listeners = _this.listeners;
for (var i_19 = 0; i_19 < listeners.length; i_19++) { for (var i_20 = 0; i_20 < listeners.length; i_20++) {
listeners[i_19].dragged(x, y); listeners[i_20].dragged(x, y);
} }
console.log("Drag " + x + ", " + y); console.log("Drag " + x + ", " + y);
_this.lastX = _this.currTouch.x = x; _this.lastX = _this.currTouch.x = x;
@ -9183,11 +9195,11 @@ var spine;
var nn = clip.worldVerticesLength; var nn = clip.worldVerticesLength;
var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0); var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
clip.computeWorldVertices(slot, 0, nn, world, 0, 2); clip.computeWorldVertices(slot, 0, nn, world, 0, 2);
for (var i_20 = 0, n_2 = world.length; i_20 < n_2; i_20 += 2) { for (var i_21 = 0, n_2 = world.length; i_21 < n_2; i_21 += 2) {
var x = world[i_20]; var x = world[i_21];
var y = world[i_20 + 1]; var y = world[i_21 + 1];
var x2 = world[(i_20 + 2) % world.length]; var x2 = world[(i_21 + 2) % world.length];
var y2 = world[(i_20 + 3) % world.length]; var y2 = world[(i_21 + 3) % world.length];
shapes.line(x, y, x2, y2); shapes.line(x, y, x2, y2);
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -244,15 +244,14 @@ declare module spine {
static emptyAnimation: Animation; static emptyAnimation: Animation;
static SUBSEQUENT: number; static SUBSEQUENT: number;
static FIRST: number; static FIRST: number;
static DIP: number; static HOLD: number;
static DIP_MIX: number; static HOLD_MIX: number;
data: AnimationStateData; data: AnimationStateData;
tracks: TrackEntry[]; tracks: TrackEntry[];
events: Event[]; events: Event[];
listeners: AnimationStateListener2[]; listeners: AnimationStateListener2[];
queue: EventQueue; queue: EventQueue;
propertyIDs: IntSet; propertyIDs: IntSet;
mixingTo: TrackEntry[];
animationsChanged: boolean; animationsChanged: boolean;
timeScale: number; timeScale: number;
trackEntryPool: Pool<TrackEntry>; trackEntryPool: Pool<TrackEntry>;
@ -277,6 +276,8 @@ declare module spine {
trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry; trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry;
disposeNext(entry: TrackEntry): void; disposeNext(entry: TrackEntry): void;
_animationsChanged(): void; _animationsChanged(): void;
setTimelineModes(entry: TrackEntry): void;
hasTimeline(entry: TrackEntry, id: number): boolean;
getCurrent(trackIndex: number): TrackEntry; getCurrent(trackIndex: number): TrackEntry;
addListener(listener: AnimationStateListener2): void; addListener(listener: AnimationStateListener2): void;
removeListener(listener: AnimationStateListener2): void; removeListener(listener: AnimationStateListener2): void;
@ -287,9 +288,11 @@ declare module spine {
animation: Animation; animation: Animation;
next: TrackEntry; next: TrackEntry;
mixingFrom: TrackEntry; mixingFrom: TrackEntry;
mixingTo: TrackEntry;
listener: AnimationStateListener2; listener: AnimationStateListener2;
trackIndex: number; trackIndex: number;
loop: boolean; loop: boolean;
holdPrevious: boolean;
eventThreshold: number; eventThreshold: number;
attachmentThreshold: number; attachmentThreshold: number;
drawOrderThreshold: number; drawOrderThreshold: number;
@ -309,12 +312,10 @@ declare module spine {
interruptAlpha: number; interruptAlpha: number;
totalAlpha: number; totalAlpha: number;
mixBlend: MixBlend; mixBlend: MixBlend;
timelineData: number[]; timelineMode: number[];
timelineDipMix: TrackEntry[]; timelineHoldMix: TrackEntry[];
timelinesRotation: number[]; timelinesRotation: number[];
reset(): void; reset(): void;
setTimelineData(to: TrackEntry, mixingToArray: Array<TrackEntry>, propertyIDs: IntSet): TrackEntry;
hasTimeline(id: number): boolean;
getAnimationTime(): number; getAnimationTime(): number;
setAnimationLast(animationLast: number): void; setAnimationLast(animationLast: number): void;
isComplete(): boolean; isComplete(): boolean;

View File

@ -1303,7 +1303,6 @@ var spine;
this.listeners = new Array(); this.listeners = new Array();
this.queue = new EventQueue(this); this.queue = new EventQueue(this);
this.propertyIDs = new spine.IntSet(); this.propertyIDs = new spine.IntSet();
this.mixingTo = new Array();
this.animationsChanged = false; this.animationsChanged = false;
this.timeScale = 1; this.timeScale = 1;
this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); }); this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
@ -1350,6 +1349,8 @@ var spine;
if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) { if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
var from = current.mixingFrom; var from = current.mixingFrom;
current.mixingFrom = null; current.mixingFrom = null;
if (from != null)
from.mixingTo = null;
while (from != null) { while (from != null) {
this.queue.end(from); this.queue.end(from);
from = from.mixingFrom; from = from.mixingFrom;
@ -1369,6 +1370,8 @@ var spine;
if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) { if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) {
if (from.totalAlpha == 0 || to.mixDuration == 0) { if (from.totalAlpha == 0 || to.mixDuration == 0) {
to.mixingFrom = from.mixingFrom; to.mixingFrom = from.mixingFrom;
if (from.mixingFrom != null)
from.mixingFrom.mixingTo = to;
to.interruptAlpha = from.interruptAlpha; to.interruptAlpha = from.interruptAlpha;
this.queue.end(from); this.queue.end(from);
} }
@ -1400,19 +1403,19 @@ var spine;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
var timelineCount = current.animation.timelines.length; var timelineCount = current.animation.timelines.length;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1 || blend == spine.MixBlend.add) { if (i == 0 && (mix == 1 || blend == spine.MixBlend.add)) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]); timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]);
} }
else { else {
var timelineData = current.timelineData; var timelineMode = current.timelineMode;
var firstFrame = current.timelinesRotation.length == 0; var firstFrame = current.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var timelineBlend = timelineData[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup; var timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
} }
@ -1452,14 +1455,14 @@ var spine;
var animationLast = from.animationLast, animationTime = from.getAnimationTime(); var animationLast = from.animationLast, animationTime = from.getAnimationTime();
var timelineCount = from.animation.timelines.length; var timelineCount = from.animation.timelines.length;
var timelines = from.animation.timelines; var timelines = from.animation.timelines;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix); var alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
if (blend == spine.MixBlend.add) { if (blend == spine.MixBlend.add) {
for (var i = 0; i < timelineCount; i++) for (var i = 0; i < timelineCount; i++)
timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out); timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out);
} }
else { else {
var timelineData = from.timelineData; var timelineMode = from.timelineMode;
var timelineDipMix = from.timelineDipMix; var timelineHoldMix = from.timelineHoldMix;
var firstFrame = from.timelinesRotation.length == 0; var firstFrame = from.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
@ -1469,7 +1472,7 @@ var spine;
var timeline = timelines[i]; var timeline = timelines[i];
var timelineBlend; var timelineBlend;
var alpha = 0; var alpha = 0;
switch (timelineData[i]) { switch (timelineMode[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
if (!attachments && timeline instanceof spine.AttachmentTimeline) if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue; continue;
@ -1482,14 +1485,14 @@ var spine;
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.HOLD:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaDip; alpha = alphaHold;
break; break;
default: default:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
var dipMix = timelineDipMix[i]; var holdMix = timelineHoldMix[i];
alpha = alphaDip * Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
break; break;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
@ -1619,6 +1622,7 @@ var spine;
break; break;
this.queue.end(from); this.queue.end(from);
entry.mixingFrom = null; entry.mixingFrom = null;
entry.mixingTo = null;
entry = from; entry = from;
} }
this.tracks[current.trackIndex] = null; this.tracks[current.trackIndex] = null;
@ -1631,6 +1635,7 @@ var spine;
if (interrupt) if (interrupt)
this.queue.interrupt(from); this.queue.interrupt(from);
current.mixingFrom = from; current.mixingFrom = from;
from.mixingTo = current;
current.mixTime = 0; current.mixTime = 0;
if (from.mixingFrom != null && from.mixDuration > 0) if (from.mixingFrom != null && from.mixDuration > 0)
current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration); current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
@ -1740,6 +1745,7 @@ var spine;
entry.trackIndex = trackIndex; entry.trackIndex = trackIndex;
entry.animation = animation; entry.animation = animation;
entry.loop = loop; entry.loop = loop;
entry.holdPrevious = false;
entry.eventThreshold = 0; entry.eventThreshold = 0;
entry.attachmentThreshold = 0; entry.attachmentThreshold = 0;
entry.drawOrderThreshold = 0; entry.drawOrderThreshold = 0;
@ -1769,15 +1775,63 @@ var spine;
}; };
AnimationState.prototype._animationsChanged = function () { AnimationState.prototype._animationsChanged = function () {
this.animationsChanged = false; this.animationsChanged = false;
var propertyIDs = this.propertyIDs; this.propertyIDs.clear();
propertyIDs.clear();
var mixingTo = this.mixingTo;
for (var i = 0, n = this.tracks.length; i < n; i++) { for (var i = 0, n = this.tracks.length; i < n; i++) {
var entry = this.tracks[i]; var entry = this.tracks[i];
if (entry != null && (i == 0 || entry.mixBlend != spine.MixBlend.add)) if (entry == null)
entry.setTimelineData(null, mixingTo, propertyIDs); continue;
while (entry.mixingFrom != null)
entry = entry.mixingFrom;
do {
if (entry.mixingFrom == null || entry.mixBlend != spine.MixBlend.add)
this.setTimelineModes(entry);
entry = entry.mixingTo;
} while (entry != null);
} }
}; };
AnimationState.prototype.setTimelineModes = function (entry) {
var to = entry.mixingTo;
var timelines = entry.animation.timelines;
var timelinesCount = entry.animation.timelines.length;
var timelineMode = spine.Utils.setArraySize(entry.timelineMode, timelinesCount);
entry.timelineHoldMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
var propertyIDs = this.propertyIDs;
if (to != null && to.holdPrevious) {
for (var i_16 = 0; i_16 < timelinesCount; i_16++) {
propertyIDs.add(timelines[i_16].getPropertyId());
timelineMode[i_16] = AnimationState.HOLD;
}
return;
}
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineMode[i] = AnimationState.SUBSEQUENT;
else if (to == null || !this.hasTimeline(to, id))
timelineMode[i] = AnimationState.FIRST;
else {
for (var next = to.mixingTo; next != null; next = next.mixingTo) {
if (this.hasTimeline(next, id))
continue;
if (entry.mixDuration > 0) {
timelineMode[i] = AnimationState.HOLD_MIX;
timelineDipMix[i] = next;
continue outer;
}
break;
}
timelineMode[i] = AnimationState.HOLD;
}
}
};
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) { AnimationState.prototype.getCurrent = function (trackIndex) {
if (trackIndex >= this.tracks.length) if (trackIndex >= this.tracks.length)
return null; return null;
@ -1802,16 +1856,16 @@ var spine;
AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0); AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
AnimationState.SUBSEQUENT = 0; AnimationState.SUBSEQUENT = 0;
AnimationState.FIRST = 1; AnimationState.FIRST = 1;
AnimationState.DIP = 2; AnimationState.HOLD = 2;
AnimationState.DIP_MIX = 3; AnimationState.HOLD_MIX = 3;
return AnimationState; return AnimationState;
}()); }());
spine.AnimationState = AnimationState; spine.AnimationState = AnimationState;
var TrackEntry = (function () { var TrackEntry = (function () {
function TrackEntry() { function TrackEntry() {
this.mixBlend = spine.MixBlend.replace; this.mixBlend = spine.MixBlend.replace;
this.timelineData = new Array(); this.timelineMode = new Array();
this.timelineDipMix = new Array(); this.timelineHoldMix = new Array();
this.timelinesRotation = new Array(); this.timelinesRotation = new Array();
} }
TrackEntry.prototype.reset = function () { TrackEntry.prototype.reset = function () {
@ -1819,52 +1873,10 @@ var spine;
this.mixingFrom = null; this.mixingFrom = null;
this.animation = null; this.animation = null;
this.listener = null; this.listener = null;
this.timelineData.length = 0; this.timelineMode.length = 0;
this.timelineDipMix.length = 0; this.timelineHoldMix.length = 0;
this.timelinesRotation.length = 0; this.timelinesRotation.length = 0;
}; };
TrackEntry.prototype.setTimelineData = function (to, mixingToArray, propertyIDs) {
if (to != null)
mixingToArray.push(to);
var lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
if (to != null)
mixingToArray.pop();
var mixingTo = mixingToArray;
var mixingToLast = mixingToArray.length - 1;
var timelines = this.animation.timelines;
var timelinesCount = this.animation.timelines.length;
var timelineData = spine.Utils.setArraySize(this.timelineData, timelinesCount);
this.timelineDipMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(this.timelineDipMix, timelinesCount);
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineData[i] = AnimationState.SUBSEQUENT;
else if (to == null || !to.hasTimeline(id))
timelineData[i] = AnimationState.FIRST;
else {
for (var ii = mixingToLast; ii >= 0; ii--) {
var entry = mixingTo[ii];
if (!entry.hasTimeline(id)) {
if (entry.mixDuration > 0) {
timelineData[i] = AnimationState.DIP_MIX;
timelineDipMix[i] = entry;
continue outer;
}
}
}
timelineData[i] = AnimationState.DIP;
}
}
return lastEntry;
};
TrackEntry.prototype.hasTimeline = function (id) {
var timelines = this.animation.timelines;
for (var i = 0, n = timelines.length; i < n; i++)
if (timelines[i].getPropertyId() == id)
return true;
return false;
};
TrackEntry.prototype.getAnimationTime = function () { TrackEntry.prototype.getAnimationTime = function () {
if (this.loop) { if (this.loop) {
var duration = this.animationEnd - this.animationStart; var duration = this.animationEnd - this.animationStart;

File diff suppressed because one or more lines are too long

View File

@ -244,15 +244,14 @@ declare module spine {
static emptyAnimation: Animation; static emptyAnimation: Animation;
static SUBSEQUENT: number; static SUBSEQUENT: number;
static FIRST: number; static FIRST: number;
static DIP: number; static HOLD: number;
static DIP_MIX: number; static HOLD_MIX: number;
data: AnimationStateData; data: AnimationStateData;
tracks: TrackEntry[]; tracks: TrackEntry[];
events: Event[]; events: Event[];
listeners: AnimationStateListener2[]; listeners: AnimationStateListener2[];
queue: EventQueue; queue: EventQueue;
propertyIDs: IntSet; propertyIDs: IntSet;
mixingTo: TrackEntry[];
animationsChanged: boolean; animationsChanged: boolean;
timeScale: number; timeScale: number;
trackEntryPool: Pool<TrackEntry>; trackEntryPool: Pool<TrackEntry>;
@ -277,6 +276,8 @@ declare module spine {
trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry; trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry;
disposeNext(entry: TrackEntry): void; disposeNext(entry: TrackEntry): void;
_animationsChanged(): void; _animationsChanged(): void;
setTimelineModes(entry: TrackEntry): void;
hasTimeline(entry: TrackEntry, id: number): boolean;
getCurrent(trackIndex: number): TrackEntry; getCurrent(trackIndex: number): TrackEntry;
addListener(listener: AnimationStateListener2): void; addListener(listener: AnimationStateListener2): void;
removeListener(listener: AnimationStateListener2): void; removeListener(listener: AnimationStateListener2): void;
@ -287,9 +288,11 @@ declare module spine {
animation: Animation; animation: Animation;
next: TrackEntry; next: TrackEntry;
mixingFrom: TrackEntry; mixingFrom: TrackEntry;
mixingTo: TrackEntry;
listener: AnimationStateListener2; listener: AnimationStateListener2;
trackIndex: number; trackIndex: number;
loop: boolean; loop: boolean;
holdPrevious: boolean;
eventThreshold: number; eventThreshold: number;
attachmentThreshold: number; attachmentThreshold: number;
drawOrderThreshold: number; drawOrderThreshold: number;
@ -309,12 +312,10 @@ declare module spine {
interruptAlpha: number; interruptAlpha: number;
totalAlpha: number; totalAlpha: number;
mixBlend: MixBlend; mixBlend: MixBlend;
timelineData: number[]; timelineMode: number[];
timelineDipMix: TrackEntry[]; timelineHoldMix: TrackEntry[];
timelinesRotation: number[]; timelinesRotation: number[];
reset(): void; reset(): void;
setTimelineData(to: TrackEntry, mixingToArray: Array<TrackEntry>, propertyIDs: IntSet): TrackEntry;
hasTimeline(id: number): boolean;
getAnimationTime(): number; getAnimationTime(): number;
setAnimationLast(animationLast: number): void; setAnimationLast(animationLast: number): void;
isComplete(): boolean; isComplete(): boolean;

View File

@ -1303,7 +1303,6 @@ var spine;
this.listeners = new Array(); this.listeners = new Array();
this.queue = new EventQueue(this); this.queue = new EventQueue(this);
this.propertyIDs = new spine.IntSet(); this.propertyIDs = new spine.IntSet();
this.mixingTo = new Array();
this.animationsChanged = false; this.animationsChanged = false;
this.timeScale = 1; this.timeScale = 1;
this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); }); this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
@ -1350,6 +1349,8 @@ var spine;
if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) { if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
var from = current.mixingFrom; var from = current.mixingFrom;
current.mixingFrom = null; current.mixingFrom = null;
if (from != null)
from.mixingTo = null;
while (from != null) { while (from != null) {
this.queue.end(from); this.queue.end(from);
from = from.mixingFrom; from = from.mixingFrom;
@ -1369,6 +1370,8 @@ var spine;
if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) { if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) {
if (from.totalAlpha == 0 || to.mixDuration == 0) { if (from.totalAlpha == 0 || to.mixDuration == 0) {
to.mixingFrom = from.mixingFrom; to.mixingFrom = from.mixingFrom;
if (from.mixingFrom != null)
from.mixingFrom.mixingTo = to;
to.interruptAlpha = from.interruptAlpha; to.interruptAlpha = from.interruptAlpha;
this.queue.end(from); this.queue.end(from);
} }
@ -1400,19 +1403,19 @@ var spine;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
var timelineCount = current.animation.timelines.length; var timelineCount = current.animation.timelines.length;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1 || blend == spine.MixBlend.add) { if (i == 0 && (mix == 1 || blend == spine.MixBlend.add)) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]); timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]);
} }
else { else {
var timelineData = current.timelineData; var timelineMode = current.timelineMode;
var firstFrame = current.timelinesRotation.length == 0; var firstFrame = current.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var timelineBlend = timelineData[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup; var timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
} }
@ -1452,14 +1455,14 @@ var spine;
var animationLast = from.animationLast, animationTime = from.getAnimationTime(); var animationLast = from.animationLast, animationTime = from.getAnimationTime();
var timelineCount = from.animation.timelines.length; var timelineCount = from.animation.timelines.length;
var timelines = from.animation.timelines; var timelines = from.animation.timelines;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix); var alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
if (blend == spine.MixBlend.add) { if (blend == spine.MixBlend.add) {
for (var i = 0; i < timelineCount; i++) for (var i = 0; i < timelineCount; i++)
timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out); timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out);
} }
else { else {
var timelineData = from.timelineData; var timelineMode = from.timelineMode;
var timelineDipMix = from.timelineDipMix; var timelineHoldMix = from.timelineHoldMix;
var firstFrame = from.timelinesRotation.length == 0; var firstFrame = from.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
@ -1469,7 +1472,7 @@ var spine;
var timeline = timelines[i]; var timeline = timelines[i];
var timelineBlend; var timelineBlend;
var alpha = 0; var alpha = 0;
switch (timelineData[i]) { switch (timelineMode[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
if (!attachments && timeline instanceof spine.AttachmentTimeline) if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue; continue;
@ -1482,14 +1485,14 @@ var spine;
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.HOLD:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaDip; alpha = alphaHold;
break; break;
default: default:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
var dipMix = timelineDipMix[i]; var holdMix = timelineHoldMix[i];
alpha = alphaDip * Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
break; break;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
@ -1619,6 +1622,7 @@ var spine;
break; break;
this.queue.end(from); this.queue.end(from);
entry.mixingFrom = null; entry.mixingFrom = null;
entry.mixingTo = null;
entry = from; entry = from;
} }
this.tracks[current.trackIndex] = null; this.tracks[current.trackIndex] = null;
@ -1631,6 +1635,7 @@ var spine;
if (interrupt) if (interrupt)
this.queue.interrupt(from); this.queue.interrupt(from);
current.mixingFrom = from; current.mixingFrom = from;
from.mixingTo = current;
current.mixTime = 0; current.mixTime = 0;
if (from.mixingFrom != null && from.mixDuration > 0) if (from.mixingFrom != null && from.mixDuration > 0)
current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration); current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
@ -1740,6 +1745,7 @@ var spine;
entry.trackIndex = trackIndex; entry.trackIndex = trackIndex;
entry.animation = animation; entry.animation = animation;
entry.loop = loop; entry.loop = loop;
entry.holdPrevious = false;
entry.eventThreshold = 0; entry.eventThreshold = 0;
entry.attachmentThreshold = 0; entry.attachmentThreshold = 0;
entry.drawOrderThreshold = 0; entry.drawOrderThreshold = 0;
@ -1769,15 +1775,63 @@ var spine;
}; };
AnimationState.prototype._animationsChanged = function () { AnimationState.prototype._animationsChanged = function () {
this.animationsChanged = false; this.animationsChanged = false;
var propertyIDs = this.propertyIDs; this.propertyIDs.clear();
propertyIDs.clear();
var mixingTo = this.mixingTo;
for (var i = 0, n = this.tracks.length; i < n; i++) { for (var i = 0, n = this.tracks.length; i < n; i++) {
var entry = this.tracks[i]; var entry = this.tracks[i];
if (entry != null && (i == 0 || entry.mixBlend != spine.MixBlend.add)) if (entry == null)
entry.setTimelineData(null, mixingTo, propertyIDs); continue;
while (entry.mixingFrom != null)
entry = entry.mixingFrom;
do {
if (entry.mixingFrom == null || entry.mixBlend != spine.MixBlend.add)
this.setTimelineModes(entry);
entry = entry.mixingTo;
} while (entry != null);
} }
}; };
AnimationState.prototype.setTimelineModes = function (entry) {
var to = entry.mixingTo;
var timelines = entry.animation.timelines;
var timelinesCount = entry.animation.timelines.length;
var timelineMode = spine.Utils.setArraySize(entry.timelineMode, timelinesCount);
entry.timelineHoldMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
var propertyIDs = this.propertyIDs;
if (to != null && to.holdPrevious) {
for (var i_16 = 0; i_16 < timelinesCount; i_16++) {
propertyIDs.add(timelines[i_16].getPropertyId());
timelineMode[i_16] = AnimationState.HOLD;
}
return;
}
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineMode[i] = AnimationState.SUBSEQUENT;
else if (to == null || !this.hasTimeline(to, id))
timelineMode[i] = AnimationState.FIRST;
else {
for (var next = to.mixingTo; next != null; next = next.mixingTo) {
if (this.hasTimeline(next, id))
continue;
if (entry.mixDuration > 0) {
timelineMode[i] = AnimationState.HOLD_MIX;
timelineDipMix[i] = next;
continue outer;
}
break;
}
timelineMode[i] = AnimationState.HOLD;
}
}
};
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) { AnimationState.prototype.getCurrent = function (trackIndex) {
if (trackIndex >= this.tracks.length) if (trackIndex >= this.tracks.length)
return null; return null;
@ -1802,16 +1856,16 @@ var spine;
AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0); AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
AnimationState.SUBSEQUENT = 0; AnimationState.SUBSEQUENT = 0;
AnimationState.FIRST = 1; AnimationState.FIRST = 1;
AnimationState.DIP = 2; AnimationState.HOLD = 2;
AnimationState.DIP_MIX = 3; AnimationState.HOLD_MIX = 3;
return AnimationState; return AnimationState;
}()); }());
spine.AnimationState = AnimationState; spine.AnimationState = AnimationState;
var TrackEntry = (function () { var TrackEntry = (function () {
function TrackEntry() { function TrackEntry() {
this.mixBlend = spine.MixBlend.replace; this.mixBlend = spine.MixBlend.replace;
this.timelineData = new Array(); this.timelineMode = new Array();
this.timelineDipMix = new Array(); this.timelineHoldMix = new Array();
this.timelinesRotation = new Array(); this.timelinesRotation = new Array();
} }
TrackEntry.prototype.reset = function () { TrackEntry.prototype.reset = function () {
@ -1819,52 +1873,10 @@ var spine;
this.mixingFrom = null; this.mixingFrom = null;
this.animation = null; this.animation = null;
this.listener = null; this.listener = null;
this.timelineData.length = 0; this.timelineMode.length = 0;
this.timelineDipMix.length = 0; this.timelineHoldMix.length = 0;
this.timelinesRotation.length = 0; this.timelinesRotation.length = 0;
}; };
TrackEntry.prototype.setTimelineData = function (to, mixingToArray, propertyIDs) {
if (to != null)
mixingToArray.push(to);
var lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
if (to != null)
mixingToArray.pop();
var mixingTo = mixingToArray;
var mixingToLast = mixingToArray.length - 1;
var timelines = this.animation.timelines;
var timelinesCount = this.animation.timelines.length;
var timelineData = spine.Utils.setArraySize(this.timelineData, timelinesCount);
this.timelineDipMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(this.timelineDipMix, timelinesCount);
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineData[i] = AnimationState.SUBSEQUENT;
else if (to == null || !to.hasTimeline(id))
timelineData[i] = AnimationState.FIRST;
else {
for (var ii = mixingToLast; ii >= 0; ii--) {
var entry = mixingTo[ii];
if (!entry.hasTimeline(id)) {
if (entry.mixDuration > 0) {
timelineData[i] = AnimationState.DIP_MIX;
timelineDipMix[i] = entry;
continue outer;
}
}
}
timelineData[i] = AnimationState.DIP;
}
}
return lastEntry;
};
TrackEntry.prototype.hasTimeline = function (id) {
var timelines = this.animation.timelines;
for (var i = 0, n = timelines.length; i < n; i++)
if (timelines[i].getPropertyId() == id)
return true;
return false;
};
TrackEntry.prototype.getAnimationTime = function () { TrackEntry.prototype.getAnimationTime = function () {
if (this.loop) { if (this.loop) {
var duration = this.animationEnd - this.animationStart; var duration = this.animationEnd - this.animationStart;

File diff suppressed because one or more lines are too long

View File

@ -244,15 +244,14 @@ declare module spine {
static emptyAnimation: Animation; static emptyAnimation: Animation;
static SUBSEQUENT: number; static SUBSEQUENT: number;
static FIRST: number; static FIRST: number;
static DIP: number; static HOLD: number;
static DIP_MIX: number; static HOLD_MIX: number;
data: AnimationStateData; data: AnimationStateData;
tracks: TrackEntry[]; tracks: TrackEntry[];
events: Event[]; events: Event[];
listeners: AnimationStateListener2[]; listeners: AnimationStateListener2[];
queue: EventQueue; queue: EventQueue;
propertyIDs: IntSet; propertyIDs: IntSet;
mixingTo: TrackEntry[];
animationsChanged: boolean; animationsChanged: boolean;
timeScale: number; timeScale: number;
trackEntryPool: Pool<TrackEntry>; trackEntryPool: Pool<TrackEntry>;
@ -277,6 +276,8 @@ declare module spine {
trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry; trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry;
disposeNext(entry: TrackEntry): void; disposeNext(entry: TrackEntry): void;
_animationsChanged(): void; _animationsChanged(): void;
setTimelineModes(entry: TrackEntry): void;
hasTimeline(entry: TrackEntry, id: number): boolean;
getCurrent(trackIndex: number): TrackEntry; getCurrent(trackIndex: number): TrackEntry;
addListener(listener: AnimationStateListener2): void; addListener(listener: AnimationStateListener2): void;
removeListener(listener: AnimationStateListener2): void; removeListener(listener: AnimationStateListener2): void;
@ -287,9 +288,11 @@ declare module spine {
animation: Animation; animation: Animation;
next: TrackEntry; next: TrackEntry;
mixingFrom: TrackEntry; mixingFrom: TrackEntry;
mixingTo: TrackEntry;
listener: AnimationStateListener2; listener: AnimationStateListener2;
trackIndex: number; trackIndex: number;
loop: boolean; loop: boolean;
holdPrevious: boolean;
eventThreshold: number; eventThreshold: number;
attachmentThreshold: number; attachmentThreshold: number;
drawOrderThreshold: number; drawOrderThreshold: number;
@ -309,12 +312,10 @@ declare module spine {
interruptAlpha: number; interruptAlpha: number;
totalAlpha: number; totalAlpha: number;
mixBlend: MixBlend; mixBlend: MixBlend;
timelineData: number[]; timelineMode: number[];
timelineDipMix: TrackEntry[]; timelineHoldMix: TrackEntry[];
timelinesRotation: number[]; timelinesRotation: number[];
reset(): void; reset(): void;
setTimelineData(to: TrackEntry, mixingToArray: Array<TrackEntry>, propertyIDs: IntSet): TrackEntry;
hasTimeline(id: number): boolean;
getAnimationTime(): number; getAnimationTime(): number;
setAnimationLast(animationLast: number): void; setAnimationLast(animationLast: number): void;
isComplete(): boolean; isComplete(): boolean;

View File

@ -1303,7 +1303,6 @@ var spine;
this.listeners = new Array(); this.listeners = new Array();
this.queue = new EventQueue(this); this.queue = new EventQueue(this);
this.propertyIDs = new spine.IntSet(); this.propertyIDs = new spine.IntSet();
this.mixingTo = new Array();
this.animationsChanged = false; this.animationsChanged = false;
this.timeScale = 1; this.timeScale = 1;
this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); }); this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
@ -1350,6 +1349,8 @@ var spine;
if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) { if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
var from = current.mixingFrom; var from = current.mixingFrom;
current.mixingFrom = null; current.mixingFrom = null;
if (from != null)
from.mixingTo = null;
while (from != null) { while (from != null) {
this.queue.end(from); this.queue.end(from);
from = from.mixingFrom; from = from.mixingFrom;
@ -1369,6 +1370,8 @@ var spine;
if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) { if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) {
if (from.totalAlpha == 0 || to.mixDuration == 0) { if (from.totalAlpha == 0 || to.mixDuration == 0) {
to.mixingFrom = from.mixingFrom; to.mixingFrom = from.mixingFrom;
if (from.mixingFrom != null)
from.mixingFrom.mixingTo = to;
to.interruptAlpha = from.interruptAlpha; to.interruptAlpha = from.interruptAlpha;
this.queue.end(from); this.queue.end(from);
} }
@ -1400,19 +1403,19 @@ var spine;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
var timelineCount = current.animation.timelines.length; var timelineCount = current.animation.timelines.length;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1 || blend == spine.MixBlend.add) { if (i == 0 && (mix == 1 || blend == spine.MixBlend.add)) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]); timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]);
} }
else { else {
var timelineData = current.timelineData; var timelineMode = current.timelineMode;
var firstFrame = current.timelinesRotation.length == 0; var firstFrame = current.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var timelineBlend = timelineData[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup; var timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
} }
@ -1452,14 +1455,14 @@ var spine;
var animationLast = from.animationLast, animationTime = from.getAnimationTime(); var animationLast = from.animationLast, animationTime = from.getAnimationTime();
var timelineCount = from.animation.timelines.length; var timelineCount = from.animation.timelines.length;
var timelines = from.animation.timelines; var timelines = from.animation.timelines;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix); var alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
if (blend == spine.MixBlend.add) { if (blend == spine.MixBlend.add) {
for (var i = 0; i < timelineCount; i++) for (var i = 0; i < timelineCount; i++)
timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out); timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out);
} }
else { else {
var timelineData = from.timelineData; var timelineMode = from.timelineMode;
var timelineDipMix = from.timelineDipMix; var timelineHoldMix = from.timelineHoldMix;
var firstFrame = from.timelinesRotation.length == 0; var firstFrame = from.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
@ -1469,7 +1472,7 @@ var spine;
var timeline = timelines[i]; var timeline = timelines[i];
var timelineBlend; var timelineBlend;
var alpha = 0; var alpha = 0;
switch (timelineData[i]) { switch (timelineMode[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
if (!attachments && timeline instanceof spine.AttachmentTimeline) if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue; continue;
@ -1482,14 +1485,14 @@ var spine;
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.HOLD:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaDip; alpha = alphaHold;
break; break;
default: default:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
var dipMix = timelineDipMix[i]; var holdMix = timelineHoldMix[i];
alpha = alphaDip * Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
break; break;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
@ -1619,6 +1622,7 @@ var spine;
break; break;
this.queue.end(from); this.queue.end(from);
entry.mixingFrom = null; entry.mixingFrom = null;
entry.mixingTo = null;
entry = from; entry = from;
} }
this.tracks[current.trackIndex] = null; this.tracks[current.trackIndex] = null;
@ -1631,6 +1635,7 @@ var spine;
if (interrupt) if (interrupt)
this.queue.interrupt(from); this.queue.interrupt(from);
current.mixingFrom = from; current.mixingFrom = from;
from.mixingTo = current;
current.mixTime = 0; current.mixTime = 0;
if (from.mixingFrom != null && from.mixDuration > 0) if (from.mixingFrom != null && from.mixDuration > 0)
current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration); current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
@ -1740,6 +1745,7 @@ var spine;
entry.trackIndex = trackIndex; entry.trackIndex = trackIndex;
entry.animation = animation; entry.animation = animation;
entry.loop = loop; entry.loop = loop;
entry.holdPrevious = false;
entry.eventThreshold = 0; entry.eventThreshold = 0;
entry.attachmentThreshold = 0; entry.attachmentThreshold = 0;
entry.drawOrderThreshold = 0; entry.drawOrderThreshold = 0;
@ -1769,15 +1775,63 @@ var spine;
}; };
AnimationState.prototype._animationsChanged = function () { AnimationState.prototype._animationsChanged = function () {
this.animationsChanged = false; this.animationsChanged = false;
var propertyIDs = this.propertyIDs; this.propertyIDs.clear();
propertyIDs.clear();
var mixingTo = this.mixingTo;
for (var i = 0, n = this.tracks.length; i < n; i++) { for (var i = 0, n = this.tracks.length; i < n; i++) {
var entry = this.tracks[i]; var entry = this.tracks[i];
if (entry != null && (i == 0 || entry.mixBlend != spine.MixBlend.add)) if (entry == null)
entry.setTimelineData(null, mixingTo, propertyIDs); continue;
while (entry.mixingFrom != null)
entry = entry.mixingFrom;
do {
if (entry.mixingFrom == null || entry.mixBlend != spine.MixBlend.add)
this.setTimelineModes(entry);
entry = entry.mixingTo;
} while (entry != null);
} }
}; };
AnimationState.prototype.setTimelineModes = function (entry) {
var to = entry.mixingTo;
var timelines = entry.animation.timelines;
var timelinesCount = entry.animation.timelines.length;
var timelineMode = spine.Utils.setArraySize(entry.timelineMode, timelinesCount);
entry.timelineHoldMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
var propertyIDs = this.propertyIDs;
if (to != null && to.holdPrevious) {
for (var i_16 = 0; i_16 < timelinesCount; i_16++) {
propertyIDs.add(timelines[i_16].getPropertyId());
timelineMode[i_16] = AnimationState.HOLD;
}
return;
}
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineMode[i] = AnimationState.SUBSEQUENT;
else if (to == null || !this.hasTimeline(to, id))
timelineMode[i] = AnimationState.FIRST;
else {
for (var next = to.mixingTo; next != null; next = next.mixingTo) {
if (this.hasTimeline(next, id))
continue;
if (entry.mixDuration > 0) {
timelineMode[i] = AnimationState.HOLD_MIX;
timelineDipMix[i] = next;
continue outer;
}
break;
}
timelineMode[i] = AnimationState.HOLD;
}
}
};
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) { AnimationState.prototype.getCurrent = function (trackIndex) {
if (trackIndex >= this.tracks.length) if (trackIndex >= this.tracks.length)
return null; return null;
@ -1802,16 +1856,16 @@ var spine;
AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0); AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
AnimationState.SUBSEQUENT = 0; AnimationState.SUBSEQUENT = 0;
AnimationState.FIRST = 1; AnimationState.FIRST = 1;
AnimationState.DIP = 2; AnimationState.HOLD = 2;
AnimationState.DIP_MIX = 3; AnimationState.HOLD_MIX = 3;
return AnimationState; return AnimationState;
}()); }());
spine.AnimationState = AnimationState; spine.AnimationState = AnimationState;
var TrackEntry = (function () { var TrackEntry = (function () {
function TrackEntry() { function TrackEntry() {
this.mixBlend = spine.MixBlend.replace; this.mixBlend = spine.MixBlend.replace;
this.timelineData = new Array(); this.timelineMode = new Array();
this.timelineDipMix = new Array(); this.timelineHoldMix = new Array();
this.timelinesRotation = new Array(); this.timelinesRotation = new Array();
} }
TrackEntry.prototype.reset = function () { TrackEntry.prototype.reset = function () {
@ -1819,52 +1873,10 @@ var spine;
this.mixingFrom = null; this.mixingFrom = null;
this.animation = null; this.animation = null;
this.listener = null; this.listener = null;
this.timelineData.length = 0; this.timelineMode.length = 0;
this.timelineDipMix.length = 0; this.timelineHoldMix.length = 0;
this.timelinesRotation.length = 0; this.timelinesRotation.length = 0;
}; };
TrackEntry.prototype.setTimelineData = function (to, mixingToArray, propertyIDs) {
if (to != null)
mixingToArray.push(to);
var lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
if (to != null)
mixingToArray.pop();
var mixingTo = mixingToArray;
var mixingToLast = mixingToArray.length - 1;
var timelines = this.animation.timelines;
var timelinesCount = this.animation.timelines.length;
var timelineData = spine.Utils.setArraySize(this.timelineData, timelinesCount);
this.timelineDipMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(this.timelineDipMix, timelinesCount);
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineData[i] = AnimationState.SUBSEQUENT;
else if (to == null || !to.hasTimeline(id))
timelineData[i] = AnimationState.FIRST;
else {
for (var ii = mixingToLast; ii >= 0; ii--) {
var entry = mixingTo[ii];
if (!entry.hasTimeline(id)) {
if (entry.mixDuration > 0) {
timelineData[i] = AnimationState.DIP_MIX;
timelineDipMix[i] = entry;
continue outer;
}
}
}
timelineData[i] = AnimationState.DIP;
}
}
return lastEntry;
};
TrackEntry.prototype.hasTimeline = function (id) {
var timelines = this.animation.timelines;
for (var i = 0, n = timelines.length; i < n; i++)
if (timelines[i].getPropertyId() == id)
return true;
return false;
};
TrackEntry.prototype.getAnimationTime = function () { TrackEntry.prototype.getAnimationTime = function () {
if (this.loop) { if (this.loop) {
var duration = this.animationEnd - this.animationStart; var duration = this.animationEnd - this.animationStart;

File diff suppressed because one or more lines are too long

View File

@ -244,15 +244,14 @@ declare module spine {
static emptyAnimation: Animation; static emptyAnimation: Animation;
static SUBSEQUENT: number; static SUBSEQUENT: number;
static FIRST: number; static FIRST: number;
static DIP: number; static HOLD: number;
static DIP_MIX: number; static HOLD_MIX: number;
data: AnimationStateData; data: AnimationStateData;
tracks: TrackEntry[]; tracks: TrackEntry[];
events: Event[]; events: Event[];
listeners: AnimationStateListener2[]; listeners: AnimationStateListener2[];
queue: EventQueue; queue: EventQueue;
propertyIDs: IntSet; propertyIDs: IntSet;
mixingTo: TrackEntry[];
animationsChanged: boolean; animationsChanged: boolean;
timeScale: number; timeScale: number;
trackEntryPool: Pool<TrackEntry>; trackEntryPool: Pool<TrackEntry>;
@ -277,6 +276,8 @@ declare module spine {
trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry; trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry;
disposeNext(entry: TrackEntry): void; disposeNext(entry: TrackEntry): void;
_animationsChanged(): void; _animationsChanged(): void;
setTimelineModes(entry: TrackEntry): void;
hasTimeline(entry: TrackEntry, id: number): boolean;
getCurrent(trackIndex: number): TrackEntry; getCurrent(trackIndex: number): TrackEntry;
addListener(listener: AnimationStateListener2): void; addListener(listener: AnimationStateListener2): void;
removeListener(listener: AnimationStateListener2): void; removeListener(listener: AnimationStateListener2): void;
@ -287,9 +288,11 @@ declare module spine {
animation: Animation; animation: Animation;
next: TrackEntry; next: TrackEntry;
mixingFrom: TrackEntry; mixingFrom: TrackEntry;
mixingTo: TrackEntry;
listener: AnimationStateListener2; listener: AnimationStateListener2;
trackIndex: number; trackIndex: number;
loop: boolean; loop: boolean;
holdPrevious: boolean;
eventThreshold: number; eventThreshold: number;
attachmentThreshold: number; attachmentThreshold: number;
drawOrderThreshold: number; drawOrderThreshold: number;
@ -309,12 +312,10 @@ declare module spine {
interruptAlpha: number; interruptAlpha: number;
totalAlpha: number; totalAlpha: number;
mixBlend: MixBlend; mixBlend: MixBlend;
timelineData: number[]; timelineMode: number[];
timelineDipMix: TrackEntry[]; timelineHoldMix: TrackEntry[];
timelinesRotation: number[]; timelinesRotation: number[];
reset(): void; reset(): void;
setTimelineData(to: TrackEntry, mixingToArray: Array<TrackEntry>, propertyIDs: IntSet): TrackEntry;
hasTimeline(id: number): boolean;
getAnimationTime(): number; getAnimationTime(): number;
setAnimationLast(animationLast: number): void; setAnimationLast(animationLast: number): void;
isComplete(): boolean; isComplete(): boolean;

View File

@ -1303,7 +1303,6 @@ var spine;
this.listeners = new Array(); this.listeners = new Array();
this.queue = new EventQueue(this); this.queue = new EventQueue(this);
this.propertyIDs = new spine.IntSet(); this.propertyIDs = new spine.IntSet();
this.mixingTo = new Array();
this.animationsChanged = false; this.animationsChanged = false;
this.timeScale = 1; this.timeScale = 1;
this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); }); this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
@ -1350,6 +1349,8 @@ var spine;
if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) { if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
var from = current.mixingFrom; var from = current.mixingFrom;
current.mixingFrom = null; current.mixingFrom = null;
if (from != null)
from.mixingTo = null;
while (from != null) { while (from != null) {
this.queue.end(from); this.queue.end(from);
from = from.mixingFrom; from = from.mixingFrom;
@ -1369,6 +1370,8 @@ var spine;
if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) { if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) {
if (from.totalAlpha == 0 || to.mixDuration == 0) { if (from.totalAlpha == 0 || to.mixDuration == 0) {
to.mixingFrom = from.mixingFrom; to.mixingFrom = from.mixingFrom;
if (from.mixingFrom != null)
from.mixingFrom.mixingTo = to;
to.interruptAlpha = from.interruptAlpha; to.interruptAlpha = from.interruptAlpha;
this.queue.end(from); this.queue.end(from);
} }
@ -1400,19 +1403,19 @@ var spine;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
var timelineCount = current.animation.timelines.length; var timelineCount = current.animation.timelines.length;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1 || blend == spine.MixBlend.add) { if (i == 0 && (mix == 1 || blend == spine.MixBlend.add)) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]); timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]);
} }
else { else {
var timelineData = current.timelineData; var timelineMode = current.timelineMode;
var firstFrame = current.timelinesRotation.length == 0; var firstFrame = current.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var timelineBlend = timelineData[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup; var timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
} }
@ -1452,14 +1455,14 @@ var spine;
var animationLast = from.animationLast, animationTime = from.getAnimationTime(); var animationLast = from.animationLast, animationTime = from.getAnimationTime();
var timelineCount = from.animation.timelines.length; var timelineCount = from.animation.timelines.length;
var timelines = from.animation.timelines; var timelines = from.animation.timelines;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix); var alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
if (blend == spine.MixBlend.add) { if (blend == spine.MixBlend.add) {
for (var i = 0; i < timelineCount; i++) for (var i = 0; i < timelineCount; i++)
timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out); timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out);
} }
else { else {
var timelineData = from.timelineData; var timelineMode = from.timelineMode;
var timelineDipMix = from.timelineDipMix; var timelineHoldMix = from.timelineHoldMix;
var firstFrame = from.timelinesRotation.length == 0; var firstFrame = from.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
@ -1469,7 +1472,7 @@ var spine;
var timeline = timelines[i]; var timeline = timelines[i];
var timelineBlend; var timelineBlend;
var alpha = 0; var alpha = 0;
switch (timelineData[i]) { switch (timelineMode[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
if (!attachments && timeline instanceof spine.AttachmentTimeline) if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue; continue;
@ -1482,14 +1485,14 @@ var spine;
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.HOLD:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaDip; alpha = alphaHold;
break; break;
default: default:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
var dipMix = timelineDipMix[i]; var holdMix = timelineHoldMix[i];
alpha = alphaDip * Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
break; break;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
@ -1619,6 +1622,7 @@ var spine;
break; break;
this.queue.end(from); this.queue.end(from);
entry.mixingFrom = null; entry.mixingFrom = null;
entry.mixingTo = null;
entry = from; entry = from;
} }
this.tracks[current.trackIndex] = null; this.tracks[current.trackIndex] = null;
@ -1631,6 +1635,7 @@ var spine;
if (interrupt) if (interrupt)
this.queue.interrupt(from); this.queue.interrupt(from);
current.mixingFrom = from; current.mixingFrom = from;
from.mixingTo = current;
current.mixTime = 0; current.mixTime = 0;
if (from.mixingFrom != null && from.mixDuration > 0) if (from.mixingFrom != null && from.mixDuration > 0)
current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration); current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
@ -1740,6 +1745,7 @@ var spine;
entry.trackIndex = trackIndex; entry.trackIndex = trackIndex;
entry.animation = animation; entry.animation = animation;
entry.loop = loop; entry.loop = loop;
entry.holdPrevious = false;
entry.eventThreshold = 0; entry.eventThreshold = 0;
entry.attachmentThreshold = 0; entry.attachmentThreshold = 0;
entry.drawOrderThreshold = 0; entry.drawOrderThreshold = 0;
@ -1769,15 +1775,63 @@ var spine;
}; };
AnimationState.prototype._animationsChanged = function () { AnimationState.prototype._animationsChanged = function () {
this.animationsChanged = false; this.animationsChanged = false;
var propertyIDs = this.propertyIDs; this.propertyIDs.clear();
propertyIDs.clear();
var mixingTo = this.mixingTo;
for (var i = 0, n = this.tracks.length; i < n; i++) { for (var i = 0, n = this.tracks.length; i < n; i++) {
var entry = this.tracks[i]; var entry = this.tracks[i];
if (entry != null && (i == 0 || entry.mixBlend != spine.MixBlend.add)) if (entry == null)
entry.setTimelineData(null, mixingTo, propertyIDs); continue;
while (entry.mixingFrom != null)
entry = entry.mixingFrom;
do {
if (entry.mixingFrom == null || entry.mixBlend != spine.MixBlend.add)
this.setTimelineModes(entry);
entry = entry.mixingTo;
} while (entry != null);
} }
}; };
AnimationState.prototype.setTimelineModes = function (entry) {
var to = entry.mixingTo;
var timelines = entry.animation.timelines;
var timelinesCount = entry.animation.timelines.length;
var timelineMode = spine.Utils.setArraySize(entry.timelineMode, timelinesCount);
entry.timelineHoldMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
var propertyIDs = this.propertyIDs;
if (to != null && to.holdPrevious) {
for (var i_16 = 0; i_16 < timelinesCount; i_16++) {
propertyIDs.add(timelines[i_16].getPropertyId());
timelineMode[i_16] = AnimationState.HOLD;
}
return;
}
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineMode[i] = AnimationState.SUBSEQUENT;
else if (to == null || !this.hasTimeline(to, id))
timelineMode[i] = AnimationState.FIRST;
else {
for (var next = to.mixingTo; next != null; next = next.mixingTo) {
if (this.hasTimeline(next, id))
continue;
if (entry.mixDuration > 0) {
timelineMode[i] = AnimationState.HOLD_MIX;
timelineDipMix[i] = next;
continue outer;
}
break;
}
timelineMode[i] = AnimationState.HOLD;
}
}
};
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) { AnimationState.prototype.getCurrent = function (trackIndex) {
if (trackIndex >= this.tracks.length) if (trackIndex >= this.tracks.length)
return null; return null;
@ -1802,16 +1856,16 @@ var spine;
AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0); AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
AnimationState.SUBSEQUENT = 0; AnimationState.SUBSEQUENT = 0;
AnimationState.FIRST = 1; AnimationState.FIRST = 1;
AnimationState.DIP = 2; AnimationState.HOLD = 2;
AnimationState.DIP_MIX = 3; AnimationState.HOLD_MIX = 3;
return AnimationState; return AnimationState;
}()); }());
spine.AnimationState = AnimationState; spine.AnimationState = AnimationState;
var TrackEntry = (function () { var TrackEntry = (function () {
function TrackEntry() { function TrackEntry() {
this.mixBlend = spine.MixBlend.replace; this.mixBlend = spine.MixBlend.replace;
this.timelineData = new Array(); this.timelineMode = new Array();
this.timelineDipMix = new Array(); this.timelineHoldMix = new Array();
this.timelinesRotation = new Array(); this.timelinesRotation = new Array();
} }
TrackEntry.prototype.reset = function () { TrackEntry.prototype.reset = function () {
@ -1819,52 +1873,10 @@ var spine;
this.mixingFrom = null; this.mixingFrom = null;
this.animation = null; this.animation = null;
this.listener = null; this.listener = null;
this.timelineData.length = 0; this.timelineMode.length = 0;
this.timelineDipMix.length = 0; this.timelineHoldMix.length = 0;
this.timelinesRotation.length = 0; this.timelinesRotation.length = 0;
}; };
TrackEntry.prototype.setTimelineData = function (to, mixingToArray, propertyIDs) {
if (to != null)
mixingToArray.push(to);
var lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
if (to != null)
mixingToArray.pop();
var mixingTo = mixingToArray;
var mixingToLast = mixingToArray.length - 1;
var timelines = this.animation.timelines;
var timelinesCount = this.animation.timelines.length;
var timelineData = spine.Utils.setArraySize(this.timelineData, timelinesCount);
this.timelineDipMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(this.timelineDipMix, timelinesCount);
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineData[i] = AnimationState.SUBSEQUENT;
else if (to == null || !to.hasTimeline(id))
timelineData[i] = AnimationState.FIRST;
else {
for (var ii = mixingToLast; ii >= 0; ii--) {
var entry = mixingTo[ii];
if (!entry.hasTimeline(id)) {
if (entry.mixDuration > 0) {
timelineData[i] = AnimationState.DIP_MIX;
timelineDipMix[i] = entry;
continue outer;
}
}
}
timelineData[i] = AnimationState.DIP;
}
}
return lastEntry;
};
TrackEntry.prototype.hasTimeline = function (id) {
var timelines = this.animation.timelines;
for (var i = 0, n = timelines.length; i < n; i++)
if (timelines[i].getPropertyId() == id)
return true;
return false;
};
TrackEntry.prototype.getAnimationTime = function () { TrackEntry.prototype.getAnimationTime = function () {
if (this.loop) { if (this.loop) {
var duration = this.animationEnd - this.animationStart; var duration = this.animationEnd - this.animationStart;
@ -7000,8 +7012,8 @@ var spine;
break; break;
} }
var listeners = _this.listeners; var listeners = _this.listeners;
for (var i_16 = 0; i_16 < listeners.length; i_16++) { for (var i_17 = 0; i_17 < listeners.length; i_17++) {
listeners[i_16].down(_this.currTouch.x, _this.currTouch.y); listeners[i_17].down(_this.currTouch.x, _this.currTouch.y);
} }
console.log("Start " + _this.currTouch.x + ", " + _this.currTouch.y); console.log("Start " + _this.currTouch.x + ", " + _this.currTouch.y);
_this.lastX = _this.currTouch.x; _this.lastX = _this.currTouch.x;
@ -7010,29 +7022,6 @@ var spine;
ev.preventDefault(); ev.preventDefault();
}, false); }, false);
element.addEventListener("touchend", function (ev) { element.addEventListener("touchend", function (ev) {
var touches = ev.changedTouches;
for (var i = 0; i < touches.length; i++) {
var touch = touches[i];
if (_this.currTouch.identifier === touch.identifier) {
var rect = element.getBoundingClientRect();
var x = _this.currTouch.x = touch.clientX - rect.left;
var y = _this.currTouch.y = touch.clientY - rect.top;
_this.touchesPool.free(_this.currTouch);
var listeners = _this.listeners;
for (var i_17 = 0; i_17 < listeners.length; i_17++) {
listeners[i_17].up(x, y);
}
console.log("End " + x + ", " + y);
_this.lastX = x;
_this.lastY = y;
_this.buttonDown = false;
_this.currTouch = null;
break;
}
}
ev.preventDefault();
}, false);
element.addEventListener("touchcancel", function (ev) {
var touches = ev.changedTouches; var touches = ev.changedTouches;
for (var i = 0; i < touches.length; i++) { for (var i = 0; i < touches.length; i++) {
var touch = touches[i]; var touch = touches[i];
@ -7055,6 +7044,29 @@ var spine;
} }
ev.preventDefault(); ev.preventDefault();
}, false); }, false);
element.addEventListener("touchcancel", function (ev) {
var touches = ev.changedTouches;
for (var i = 0; i < touches.length; i++) {
var touch = touches[i];
if (_this.currTouch.identifier === touch.identifier) {
var rect = element.getBoundingClientRect();
var x = _this.currTouch.x = touch.clientX - rect.left;
var y = _this.currTouch.y = touch.clientY - rect.top;
_this.touchesPool.free(_this.currTouch);
var listeners = _this.listeners;
for (var i_19 = 0; i_19 < listeners.length; i_19++) {
listeners[i_19].up(x, y);
}
console.log("End " + x + ", " + y);
_this.lastX = x;
_this.lastY = y;
_this.buttonDown = false;
_this.currTouch = null;
break;
}
}
ev.preventDefault();
}, false);
element.addEventListener("touchmove", function (ev) { element.addEventListener("touchmove", function (ev) {
if (_this.currTouch == null) if (_this.currTouch == null)
return; return;
@ -7066,8 +7078,8 @@ var spine;
var x = touch.clientX - rect.left; var x = touch.clientX - rect.left;
var y = touch.clientY - rect.top; var y = touch.clientY - rect.top;
var listeners = _this.listeners; var listeners = _this.listeners;
for (var i_19 = 0; i_19 < listeners.length; i_19++) { for (var i_20 = 0; i_20 < listeners.length; i_20++) {
listeners[i_19].dragged(x, y); listeners[i_20].dragged(x, y);
} }
console.log("Drag " + x + ", " + y); console.log("Drag " + x + ", " + y);
_this.lastX = _this.currTouch.x = x; _this.lastX = _this.currTouch.x = x;
@ -8917,11 +8929,11 @@ var spine;
var nn = clip.worldVerticesLength; var nn = clip.worldVerticesLength;
var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0); var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
clip.computeWorldVertices(slot, 0, nn, world, 0, 2); clip.computeWorldVertices(slot, 0, nn, world, 0, 2);
for (var i_20 = 0, n_2 = world.length; i_20 < n_2; i_20 += 2) { for (var i_21 = 0, n_2 = world.length; i_21 < n_2; i_21 += 2) {
var x = world[i_20]; var x = world[i_21];
var y = world[i_20 + 1]; var y = world[i_21 + 1];
var x2 = world[(i_20 + 2) % world.length]; var x2 = world[(i_21 + 2) % world.length];
var y2 = world[(i_20 + 3) % world.length]; var y2 = world[(i_21 + 3) % world.length];
shapes.line(x, y, x2, y2); shapes.line(x, y, x2, y2);
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -244,15 +244,14 @@ declare module spine {
static emptyAnimation: Animation; static emptyAnimation: Animation;
static SUBSEQUENT: number; static SUBSEQUENT: number;
static FIRST: number; static FIRST: number;
static DIP: number; static HOLD: number;
static DIP_MIX: number; static HOLD_MIX: number;
data: AnimationStateData; data: AnimationStateData;
tracks: TrackEntry[]; tracks: TrackEntry[];
events: Event[]; events: Event[];
listeners: AnimationStateListener2[]; listeners: AnimationStateListener2[];
queue: EventQueue; queue: EventQueue;
propertyIDs: IntSet; propertyIDs: IntSet;
mixingTo: TrackEntry[];
animationsChanged: boolean; animationsChanged: boolean;
timeScale: number; timeScale: number;
trackEntryPool: Pool<TrackEntry>; trackEntryPool: Pool<TrackEntry>;
@ -277,6 +276,8 @@ declare module spine {
trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry; trackEntry(trackIndex: number, animation: Animation, loop: boolean, last: TrackEntry): TrackEntry;
disposeNext(entry: TrackEntry): void; disposeNext(entry: TrackEntry): void;
_animationsChanged(): void; _animationsChanged(): void;
setTimelineModes(entry: TrackEntry): void;
hasTimeline(entry: TrackEntry, id: number): boolean;
getCurrent(trackIndex: number): TrackEntry; getCurrent(trackIndex: number): TrackEntry;
addListener(listener: AnimationStateListener2): void; addListener(listener: AnimationStateListener2): void;
removeListener(listener: AnimationStateListener2): void; removeListener(listener: AnimationStateListener2): void;
@ -287,9 +288,11 @@ declare module spine {
animation: Animation; animation: Animation;
next: TrackEntry; next: TrackEntry;
mixingFrom: TrackEntry; mixingFrom: TrackEntry;
mixingTo: TrackEntry;
listener: AnimationStateListener2; listener: AnimationStateListener2;
trackIndex: number; trackIndex: number;
loop: boolean; loop: boolean;
holdPrevious: boolean;
eventThreshold: number; eventThreshold: number;
attachmentThreshold: number; attachmentThreshold: number;
drawOrderThreshold: number; drawOrderThreshold: number;
@ -309,12 +312,10 @@ declare module spine {
interruptAlpha: number; interruptAlpha: number;
totalAlpha: number; totalAlpha: number;
mixBlend: MixBlend; mixBlend: MixBlend;
timelineData: number[]; timelineMode: number[];
timelineDipMix: TrackEntry[]; timelineHoldMix: TrackEntry[];
timelinesRotation: number[]; timelinesRotation: number[];
reset(): void; reset(): void;
setTimelineData(to: TrackEntry, mixingToArray: Array<TrackEntry>, propertyIDs: IntSet): TrackEntry;
hasTimeline(id: number): boolean;
getAnimationTime(): number; getAnimationTime(): number;
setAnimationLast(animationLast: number): void; setAnimationLast(animationLast: number): void;
isComplete(): boolean; isComplete(): boolean;

View File

@ -1303,7 +1303,6 @@ var spine;
this.listeners = new Array(); this.listeners = new Array();
this.queue = new EventQueue(this); this.queue = new EventQueue(this);
this.propertyIDs = new spine.IntSet(); this.propertyIDs = new spine.IntSet();
this.mixingTo = new Array();
this.animationsChanged = false; this.animationsChanged = false;
this.timeScale = 1; this.timeScale = 1;
this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); }); this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
@ -1350,6 +1349,8 @@ var spine;
if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) { if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
var from = current.mixingFrom; var from = current.mixingFrom;
current.mixingFrom = null; current.mixingFrom = null;
if (from != null)
from.mixingTo = null;
while (from != null) { while (from != null) {
this.queue.end(from); this.queue.end(from);
from = from.mixingFrom; from = from.mixingFrom;
@ -1369,6 +1370,8 @@ var spine;
if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) { if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) {
if (from.totalAlpha == 0 || to.mixDuration == 0) { if (from.totalAlpha == 0 || to.mixDuration == 0) {
to.mixingFrom = from.mixingFrom; to.mixingFrom = from.mixingFrom;
if (from.mixingFrom != null)
from.mixingFrom.mixingTo = to;
to.interruptAlpha = from.interruptAlpha; to.interruptAlpha = from.interruptAlpha;
this.queue.end(from); this.queue.end(from);
} }
@ -1400,19 +1403,19 @@ var spine;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
var timelineCount = current.animation.timelines.length; var timelineCount = current.animation.timelines.length;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1 || blend == spine.MixBlend.add) { if (i == 0 && (mix == 1 || blend == spine.MixBlend.add)) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]); timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection["in"]);
} }
else { else {
var timelineData = current.timelineData; var timelineMode = current.timelineMode;
var firstFrame = current.timelinesRotation.length == 0; var firstFrame = current.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var timelineBlend = timelineData[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup; var timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
} }
@ -1452,14 +1455,14 @@ var spine;
var animationLast = from.animationLast, animationTime = from.getAnimationTime(); var animationLast = from.animationLast, animationTime = from.getAnimationTime();
var timelineCount = from.animation.timelines.length; var timelineCount = from.animation.timelines.length;
var timelines = from.animation.timelines; var timelines = from.animation.timelines;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix); var alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
if (blend == spine.MixBlend.add) { if (blend == spine.MixBlend.add) {
for (var i = 0; i < timelineCount; i++) for (var i = 0; i < timelineCount; i++)
timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out); timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.out);
} }
else { else {
var timelineData = from.timelineData; var timelineMode = from.timelineMode;
var timelineDipMix = from.timelineDipMix; var timelineHoldMix = from.timelineHoldMix;
var firstFrame = from.timelinesRotation.length == 0; var firstFrame = from.timelinesRotation.length == 0;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
@ -1469,7 +1472,7 @@ var spine;
var timeline = timelines[i]; var timeline = timelines[i];
var timelineBlend; var timelineBlend;
var alpha = 0; var alpha = 0;
switch (timelineData[i]) { switch (timelineMode[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
if (!attachments && timeline instanceof spine.AttachmentTimeline) if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue; continue;
@ -1482,14 +1485,14 @@ var spine;
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.HOLD:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
alpha = alphaDip; alpha = alphaHold;
break; break;
default: default:
timelineBlend = spine.MixBlend.setup; timelineBlend = spine.MixBlend.setup;
var dipMix = timelineDipMix[i]; var holdMix = timelineHoldMix[i];
alpha = alphaDip * Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
break; break;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
@ -1619,6 +1622,7 @@ var spine;
break; break;
this.queue.end(from); this.queue.end(from);
entry.mixingFrom = null; entry.mixingFrom = null;
entry.mixingTo = null;
entry = from; entry = from;
} }
this.tracks[current.trackIndex] = null; this.tracks[current.trackIndex] = null;
@ -1631,6 +1635,7 @@ var spine;
if (interrupt) if (interrupt)
this.queue.interrupt(from); this.queue.interrupt(from);
current.mixingFrom = from; current.mixingFrom = from;
from.mixingTo = current;
current.mixTime = 0; current.mixTime = 0;
if (from.mixingFrom != null && from.mixDuration > 0) if (from.mixingFrom != null && from.mixDuration > 0)
current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration); current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
@ -1740,6 +1745,7 @@ var spine;
entry.trackIndex = trackIndex; entry.trackIndex = trackIndex;
entry.animation = animation; entry.animation = animation;
entry.loop = loop; entry.loop = loop;
entry.holdPrevious = false;
entry.eventThreshold = 0; entry.eventThreshold = 0;
entry.attachmentThreshold = 0; entry.attachmentThreshold = 0;
entry.drawOrderThreshold = 0; entry.drawOrderThreshold = 0;
@ -1769,15 +1775,63 @@ var spine;
}; };
AnimationState.prototype._animationsChanged = function () { AnimationState.prototype._animationsChanged = function () {
this.animationsChanged = false; this.animationsChanged = false;
var propertyIDs = this.propertyIDs; this.propertyIDs.clear();
propertyIDs.clear();
var mixingTo = this.mixingTo;
for (var i = 0, n = this.tracks.length; i < n; i++) { for (var i = 0, n = this.tracks.length; i < n; i++) {
var entry = this.tracks[i]; var entry = this.tracks[i];
if (entry != null && (i == 0 || entry.mixBlend != spine.MixBlend.add)) if (entry == null)
entry.setTimelineData(null, mixingTo, propertyIDs); continue;
while (entry.mixingFrom != null)
entry = entry.mixingFrom;
do {
if (entry.mixingFrom == null || entry.mixBlend != spine.MixBlend.add)
this.setTimelineModes(entry);
entry = entry.mixingTo;
} while (entry != null);
} }
}; };
AnimationState.prototype.setTimelineModes = function (entry) {
var to = entry.mixingTo;
var timelines = entry.animation.timelines;
var timelinesCount = entry.animation.timelines.length;
var timelineMode = spine.Utils.setArraySize(entry.timelineMode, timelinesCount);
entry.timelineHoldMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
var propertyIDs = this.propertyIDs;
if (to != null && to.holdPrevious) {
for (var i_16 = 0; i_16 < timelinesCount; i_16++) {
propertyIDs.add(timelines[i_16].getPropertyId());
timelineMode[i_16] = AnimationState.HOLD;
}
return;
}
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineMode[i] = AnimationState.SUBSEQUENT;
else if (to == null || !this.hasTimeline(to, id))
timelineMode[i] = AnimationState.FIRST;
else {
for (var next = to.mixingTo; next != null; next = next.mixingTo) {
if (this.hasTimeline(next, id))
continue;
if (entry.mixDuration > 0) {
timelineMode[i] = AnimationState.HOLD_MIX;
timelineDipMix[i] = next;
continue outer;
}
break;
}
timelineMode[i] = AnimationState.HOLD;
}
}
};
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) { AnimationState.prototype.getCurrent = function (trackIndex) {
if (trackIndex >= this.tracks.length) if (trackIndex >= this.tracks.length)
return null; return null;
@ -1802,16 +1856,16 @@ var spine;
AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0); AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
AnimationState.SUBSEQUENT = 0; AnimationState.SUBSEQUENT = 0;
AnimationState.FIRST = 1; AnimationState.FIRST = 1;
AnimationState.DIP = 2; AnimationState.HOLD = 2;
AnimationState.DIP_MIX = 3; AnimationState.HOLD_MIX = 3;
return AnimationState; return AnimationState;
}()); }());
spine.AnimationState = AnimationState; spine.AnimationState = AnimationState;
var TrackEntry = (function () { var TrackEntry = (function () {
function TrackEntry() { function TrackEntry() {
this.mixBlend = spine.MixBlend.replace; this.mixBlend = spine.MixBlend.replace;
this.timelineData = new Array(); this.timelineMode = new Array();
this.timelineDipMix = new Array(); this.timelineHoldMix = new Array();
this.timelinesRotation = new Array(); this.timelinesRotation = new Array();
} }
TrackEntry.prototype.reset = function () { TrackEntry.prototype.reset = function () {
@ -1819,52 +1873,10 @@ var spine;
this.mixingFrom = null; this.mixingFrom = null;
this.animation = null; this.animation = null;
this.listener = null; this.listener = null;
this.timelineData.length = 0; this.timelineMode.length = 0;
this.timelineDipMix.length = 0; this.timelineHoldMix.length = 0;
this.timelinesRotation.length = 0; this.timelinesRotation.length = 0;
}; };
TrackEntry.prototype.setTimelineData = function (to, mixingToArray, propertyIDs) {
if (to != null)
mixingToArray.push(to);
var lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
if (to != null)
mixingToArray.pop();
var mixingTo = mixingToArray;
var mixingToLast = mixingToArray.length - 1;
var timelines = this.animation.timelines;
var timelinesCount = this.animation.timelines.length;
var timelineData = spine.Utils.setArraySize(this.timelineData, timelinesCount);
this.timelineDipMix.length = 0;
var timelineDipMix = spine.Utils.setArraySize(this.timelineDipMix, timelinesCount);
outer: for (var i = 0; i < timelinesCount; i++) {
var id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineData[i] = AnimationState.SUBSEQUENT;
else if (to == null || !to.hasTimeline(id))
timelineData[i] = AnimationState.FIRST;
else {
for (var ii = mixingToLast; ii >= 0; ii--) {
var entry = mixingTo[ii];
if (!entry.hasTimeline(id)) {
if (entry.mixDuration > 0) {
timelineData[i] = AnimationState.DIP_MIX;
timelineDipMix[i] = entry;
continue outer;
}
}
}
timelineData[i] = AnimationState.DIP;
}
}
return lastEntry;
};
TrackEntry.prototype.hasTimeline = function (id) {
var timelines = this.animation.timelines;
for (var i = 0, n = timelines.length; i < n; i++)
if (timelines[i].getPropertyId() == id)
return true;
return false;
};
TrackEntry.prototype.getAnimationTime = function () { TrackEntry.prototype.getAnimationTime = function () {
if (this.loop) { if (this.loop) {
var duration = this.animationEnd - this.animationStart; var duration = this.animationEnd - this.animationStart;
@ -7000,8 +7012,8 @@ var spine;
break; break;
} }
var listeners = _this.listeners; var listeners = _this.listeners;
for (var i_16 = 0; i_16 < listeners.length; i_16++) { for (var i_17 = 0; i_17 < listeners.length; i_17++) {
listeners[i_16].down(_this.currTouch.x, _this.currTouch.y); listeners[i_17].down(_this.currTouch.x, _this.currTouch.y);
} }
console.log("Start " + _this.currTouch.x + ", " + _this.currTouch.y); console.log("Start " + _this.currTouch.x + ", " + _this.currTouch.y);
_this.lastX = _this.currTouch.x; _this.lastX = _this.currTouch.x;
@ -7010,29 +7022,6 @@ var spine;
ev.preventDefault(); ev.preventDefault();
}, false); }, false);
element.addEventListener("touchend", function (ev) { element.addEventListener("touchend", function (ev) {
var touches = ev.changedTouches;
for (var i = 0; i < touches.length; i++) {
var touch = touches[i];
if (_this.currTouch.identifier === touch.identifier) {
var rect = element.getBoundingClientRect();
var x = _this.currTouch.x = touch.clientX - rect.left;
var y = _this.currTouch.y = touch.clientY - rect.top;
_this.touchesPool.free(_this.currTouch);
var listeners = _this.listeners;
for (var i_17 = 0; i_17 < listeners.length; i_17++) {
listeners[i_17].up(x, y);
}
console.log("End " + x + ", " + y);
_this.lastX = x;
_this.lastY = y;
_this.buttonDown = false;
_this.currTouch = null;
break;
}
}
ev.preventDefault();
}, false);
element.addEventListener("touchcancel", function (ev) {
var touches = ev.changedTouches; var touches = ev.changedTouches;
for (var i = 0; i < touches.length; i++) { for (var i = 0; i < touches.length; i++) {
var touch = touches[i]; var touch = touches[i];
@ -7055,6 +7044,29 @@ var spine;
} }
ev.preventDefault(); ev.preventDefault();
}, false); }, false);
element.addEventListener("touchcancel", function (ev) {
var touches = ev.changedTouches;
for (var i = 0; i < touches.length; i++) {
var touch = touches[i];
if (_this.currTouch.identifier === touch.identifier) {
var rect = element.getBoundingClientRect();
var x = _this.currTouch.x = touch.clientX - rect.left;
var y = _this.currTouch.y = touch.clientY - rect.top;
_this.touchesPool.free(_this.currTouch);
var listeners = _this.listeners;
for (var i_19 = 0; i_19 < listeners.length; i_19++) {
listeners[i_19].up(x, y);
}
console.log("End " + x + ", " + y);
_this.lastX = x;
_this.lastY = y;
_this.buttonDown = false;
_this.currTouch = null;
break;
}
}
ev.preventDefault();
}, false);
element.addEventListener("touchmove", function (ev) { element.addEventListener("touchmove", function (ev) {
if (_this.currTouch == null) if (_this.currTouch == null)
return; return;
@ -7066,8 +7078,8 @@ var spine;
var x = touch.clientX - rect.left; var x = touch.clientX - rect.left;
var y = touch.clientY - rect.top; var y = touch.clientY - rect.top;
var listeners = _this.listeners; var listeners = _this.listeners;
for (var i_19 = 0; i_19 < listeners.length; i_19++) { for (var i_20 = 0; i_20 < listeners.length; i_20++) {
listeners[i_19].dragged(x, y); listeners[i_20].dragged(x, y);
} }
console.log("Drag " + x + ", " + y); console.log("Drag " + x + ", " + y);
_this.lastX = _this.currTouch.x = x; _this.lastX = _this.currTouch.x = x;
@ -8917,11 +8929,11 @@ var spine;
var nn = clip.worldVerticesLength; var nn = clip.worldVerticesLength;
var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0); var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
clip.computeWorldVertices(slot, 0, nn, world, 0, 2); clip.computeWorldVertices(slot, 0, nn, world, 0, 2);
for (var i_20 = 0, n_2 = world.length; i_20 < n_2; i_20 += 2) { for (var i_21 = 0, n_2 = world.length; i_21 < n_2; i_21 += 2) {
var x = world[i_20]; var x = world[i_21];
var y = world[i_20 + 1]; var y = world[i_21 + 1];
var x2 = world[(i_20 + 2) % world.length]; var x2 = world[(i_21 + 2) % world.length];
var y2 = world[(i_20 + 3) % world.length]; var y2 = world[(i_21 + 3) % world.length];
shapes.line(x, y, x2, y2); shapes.line(x, y, x2, y2);
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -33,8 +33,8 @@ module spine {
static emptyAnimation = new Animation("<empty>", [], 0); static emptyAnimation = new Animation("<empty>", [], 0);
static SUBSEQUENT = 0; static SUBSEQUENT = 0;
static FIRST = 1; static FIRST = 1;
static DIP = 2; static HOLD = 2;
static DIP_MIX = 3; static HOLD_MIX = 3;
data: AnimationStateData; data: AnimationStateData;
tracks = new Array<TrackEntry>(); tracks = new Array<TrackEntry>();
@ -42,7 +42,6 @@ module spine {
listeners = new Array<AnimationStateListener2>(); listeners = new Array<AnimationStateListener2>();
queue = new EventQueue(this); queue = new EventQueue(this);
propertyIDs = new IntSet(); propertyIDs = new IntSet();
mixingTo = new Array<TrackEntry>();
animationsChanged = false; animationsChanged = false;
timeScale = 1; timeScale = 1;
@ -96,6 +95,7 @@ module spine {
// End mixing from entries once all have completed. // End mixing from entries once all have completed.
let from = current.mixingFrom; let from = current.mixingFrom;
current.mixingFrom = null; current.mixingFrom = null;
if (from != null) from.mixingTo = null;
while (from != null) { while (from != null) {
this.queue.end(from); this.queue.end(from);
from = from.mixingFrom; from = from.mixingFrom;
@ -122,6 +122,7 @@ module spine {
// Require totalAlpha == 0 to ensure mixing is complete, unless mixDuration == 0 (the transition is a single frame). // Require totalAlpha == 0 to ensure mixing is complete, unless mixDuration == 0 (the transition is a single frame).
if (from.totalAlpha == 0 || to.mixDuration == 0) { if (from.totalAlpha == 0 || to.mixDuration == 0) {
to.mixingFrom = from.mixingFrom; to.mixingFrom = from.mixingFrom;
if (from.mixingFrom != null) from.mixingFrom.mixingTo = to;
to.interruptAlpha = from.interruptAlpha; to.interruptAlpha = from.interruptAlpha;
this.queue.end(from); this.queue.end(from);
} }
@ -158,11 +159,11 @@ module spine {
let animationLast = current.animationLast, animationTime = current.getAnimationTime(); let animationLast = current.animationLast, animationTime = current.getAnimationTime();
let timelineCount = current.animation.timelines.length; let timelineCount = current.animation.timelines.length;
let timelines = current.animation.timelines; let timelines = current.animation.timelines;
if (mix == 1 || blend == MixBlend.add) { if (i == 0 && (mix == 1 || blend == MixBlend.add)) {
for (let ii = 0; ii < timelineCount; ii++) for (let ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, MixDirection.in); timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, MixDirection.in);
} else { } else {
let timelineData = current.timelineData; let timelineMode = current.timelineMode;
let firstFrame = current.timelinesRotation.length == 0; let firstFrame = current.timelinesRotation.length == 0;
if (firstFrame) Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null); if (firstFrame) Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
@ -170,7 +171,7 @@ module spine {
for (let ii = 0; ii < timelineCount; ii++) { for (let ii = 0; ii < timelineCount; ii++) {
let timeline = timelines[ii]; let timeline = timelines[ii];
let timelineBlend = timelineData[ii] == AnimationState.SUBSEQUENT ? blend : MixBlend.setup; let timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : MixBlend.setup;
if (timeline instanceof RotateTimeline) { if (timeline instanceof RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
} else { } else {
@ -209,13 +210,13 @@ module spine {
let animationLast = from.animationLast, animationTime = from.getAnimationTime(); let animationLast = from.animationLast, animationTime = from.getAnimationTime();
let timelineCount = from.animation.timelines.length; let timelineCount = from.animation.timelines.length;
let timelines = from.animation.timelines; let timelines = from.animation.timelines;
let alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix); let alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
if (blend == MixBlend.add) { if (blend == MixBlend.add) {
for (var i = 0; i < timelineCount; i++) for (var i = 0; i < timelineCount; i++)
timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, MixDirection.out); timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, MixDirection.out);
} else { } else {
let timelineData = from.timelineData; let timelineMode = from.timelineMode;
let timelineDipMix = from.timelineDipMix; let timelineHoldMix = from.timelineHoldMix;
let firstFrame = from.timelinesRotation.length == 0; let firstFrame = from.timelinesRotation.length == 0;
if (firstFrame) Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); if (firstFrame) Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
@ -226,7 +227,7 @@ module spine {
let timeline = timelines[i]; let timeline = timelines[i];
var timelineBlend: MixBlend; var timelineBlend: MixBlend;
var alpha = 0; var alpha = 0;
switch (timelineData[i]) { switch (timelineMode[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
if (!attachments && timeline instanceof AttachmentTimeline) continue; if (!attachments && timeline instanceof AttachmentTimeline) continue;
if (!drawOrder && timeline instanceof DrawOrderTimeline) continue; if (!drawOrder && timeline instanceof DrawOrderTimeline) continue;
@ -237,14 +238,14 @@ module spine {
timelineBlend = MixBlend.setup; timelineBlend = MixBlend.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.HOLD:
timelineBlend = MixBlend.setup; timelineBlend = MixBlend.setup;
alpha = alphaDip; alpha = alphaHold;
break; break;
default: default:
timelineBlend = MixBlend.setup; timelineBlend = MixBlend.setup;
let dipMix = timelineDipMix[i]; let holdMix = timelineHoldMix[i];
alpha = alphaDip * Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
break; break;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
@ -388,6 +389,7 @@ module spine {
if (from == null) break; if (from == null) break;
this.queue.end(from); this.queue.end(from);
entry.mixingFrom = null; entry.mixingFrom = null;
entry.mixingTo = null;
entry = from; entry = from;
} }
@ -403,6 +405,7 @@ module spine {
if (from != null) { if (from != null) {
if (interrupt) this.queue.interrupt(from); if (interrupt) this.queue.interrupt(from);
current.mixingFrom = from; current.mixingFrom = from;
from.mixingTo = current;
current.mixTime = 0; current.mixTime = 0;
// Store the interrupted mix percentage. // Store the interrupted mix percentage.
@ -520,6 +523,7 @@ module spine {
entry.trackIndex = trackIndex; entry.trackIndex = trackIndex;
entry.animation = animation; entry.animation = animation;
entry.loop = loop; entry.loop = loop;
entry.holdPrevious = false;
entry.eventThreshold = 0; entry.eventThreshold = 0;
entry.attachmentThreshold = 0; entry.attachmentThreshold = 0;
@ -556,17 +560,67 @@ module spine {
_animationsChanged () { _animationsChanged () {
this.animationsChanged = false; this.animationsChanged = false;
let propertyIDs = this.propertyIDs; this.propertyIDs.clear();
propertyIDs.clear();
let mixingTo = this.mixingTo;
for (var i = 0, n = this.tracks.length; i < n; i++) { for (var i = 0, n = this.tracks.length; i < n; i++) {
let entry = this.tracks[i]; let entry = this.tracks[i];
if (entry != null && (i == 0 || entry.mixBlend != MixBlend.add)) if (entry == null) continue;
entry.setTimelineData(null, mixingTo, propertyIDs); while (entry.mixingFrom != null)
entry = entry.mixingFrom;
do {
if (entry.mixingFrom == null || entry.mixBlend != MixBlend.add) this.setTimelineModes(entry);
entry = entry.mixingTo;
} while (entry != null)
} }
} }
setTimelineModes (entry: TrackEntry) {
let to = entry.mixingTo;
let timelines = entry.animation.timelines;
let timelinesCount = entry.animation.timelines.length;
let timelineMode = Utils.setArraySize(entry.timelineMode, timelinesCount);
entry.timelineHoldMix.length = 0;
let timelineDipMix = Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
let propertyIDs = this.propertyIDs;
if (to != null && to.holdPrevious) {
for (let i = 0; i < timelinesCount; i++) {
propertyIDs.add(timelines[i].getPropertyId());
timelineMode[i] = AnimationState.HOLD;
}
return;
}
outer:
for (var i = 0; i < timelinesCount; i++) {
let id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineMode[i] = AnimationState.SUBSEQUENT;
else if (to == null || !this.hasTimeline(to, id))
timelineMode[i] = AnimationState.FIRST;
else {
for (let next = to.mixingTo; next != null; next = next.mixingTo) {
if (this.hasTimeline(next, id)) continue;
if (entry.mixDuration > 0) {
timelineMode[i] = AnimationState.HOLD_MIX;
timelineDipMix[i] = next;
continue outer;
}
break;
}
timelineMode[i] = AnimationState.HOLD;
}
}
}
hasTimeline (entry: TrackEntry, id: number) : boolean {
let timelines = entry.animation.timelines;
for (var i = 0, n = timelines.length; i < n; i++)
if (timelines[i].getPropertyId() == id) return true;
return false;
}
getCurrent (trackIndex: number) { getCurrent (trackIndex: number) {
if (trackIndex >= this.tracks.length) return null; if (trackIndex >= this.tracks.length) return null;
return this.tracks[trackIndex]; return this.tracks[trackIndex];
@ -594,17 +648,18 @@ module spine {
export class TrackEntry { export class TrackEntry {
animation: Animation; animation: Animation;
next: TrackEntry; mixingFrom: TrackEntry; next: TrackEntry; mixingFrom: TrackEntry; mixingTo: TrackEntry;
listener: AnimationStateListener2; listener: AnimationStateListener2;
trackIndex: number; trackIndex: number;
loop: boolean; loop: boolean;
holdPrevious: boolean;
eventThreshold: number; attachmentThreshold: number; drawOrderThreshold: number; eventThreshold: number; attachmentThreshold: number; drawOrderThreshold: number;
animationStart: number; animationEnd: number; animationLast: number; nextAnimationLast: number; animationStart: number; animationEnd: number; animationLast: number; nextAnimationLast: number;
delay: number; trackTime: number; trackLast: number; nextTrackLast: number; trackEnd: number; timeScale: number; delay: number; trackTime: number; trackLast: number; nextTrackLast: number; trackEnd: number; timeScale: number;
alpha: number; mixTime: number; mixDuration: number; interruptAlpha: number; totalAlpha: number; alpha: number; mixTime: number; mixDuration: number; interruptAlpha: number; totalAlpha: number;
mixBlend = MixBlend.replace; mixBlend = MixBlend.replace;
timelineData = new Array<number>(); timelineMode = new Array<number>();
timelineDipMix = new Array<TrackEntry>(); timelineHoldMix = new Array<TrackEntry>();
timelinesRotation = new Array<number>(); timelinesRotation = new Array<number>();
reset () { reset () {
@ -612,55 +667,11 @@ module spine {
this.mixingFrom = null; this.mixingFrom = null;
this.animation = null; this.animation = null;
this.listener = null; this.listener = null;
this.timelineData.length = 0; this.timelineMode.length = 0;
this.timelineDipMix.length = 0; this.timelineHoldMix.length = 0;
this.timelinesRotation.length = 0; this.timelinesRotation.length = 0;
} }
setTimelineData (to: TrackEntry, mixingToArray: Array<TrackEntry>, propertyIDs: IntSet) : TrackEntry {
if (to != null) mixingToArray.push(to);
let lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
if (to != null) mixingToArray.pop();
let mixingTo = mixingToArray;
let mixingToLast = mixingToArray.length - 1;
let timelines = this.animation.timelines;
let timelinesCount = this.animation.timelines.length;
let timelineData = Utils.setArraySize(this.timelineData, timelinesCount);
this.timelineDipMix.length = 0;
let timelineDipMix = Utils.setArraySize(this.timelineDipMix, timelinesCount);
outer:
for (var i = 0; i < timelinesCount; i++) {
let id = timelines[i].getPropertyId();
if (!propertyIDs.add(id))
timelineData[i] = AnimationState.SUBSEQUENT;
else if (to == null || !to.hasTimeline(id))
timelineData[i] = AnimationState.FIRST;
else {
for (var ii = mixingToLast; ii >= 0; ii--) {
let entry = mixingTo[ii];
if (!entry.hasTimeline(id)) {
if (entry.mixDuration > 0) {
timelineData[i] = AnimationState.DIP_MIX;
timelineDipMix[i] = entry;
continue outer;
}
}
}
timelineData[i] = AnimationState.DIP;
}
}
return lastEntry;
}
hasTimeline (id: number) : boolean {
let timelines = this.animation.timelines;
for (var i = 0, n = timelines.length; i < n; i++)
if (timelines[i].getPropertyId() == id) return true;
return false;
}
getAnimationTime () { getAnimationTime () {
if (this.loop) { if (this.loop) {
let duration = this.animationEnd - this.animationStart; let duration = this.animationEnd - this.animationStart;

View File

@ -26,6 +26,7 @@ function load () {
var skeletonJson = new spine.SkeletonJson(new spine.AtlasAttachmentLoader(atlas)); var skeletonJson = new spine.SkeletonJson(new spine.AtlasAttachmentLoader(atlas));
var skeletonData = skeletonJson.readSkeletonData(assetManager.get("spineboy-ess.json")); var skeletonData = skeletonJson.readSkeletonData(assetManager.get("spineboy-ess.json"));
var animationStateData = new spine.AnimationStateData(skeletonData); var animationStateData = new spine.AnimationStateData(skeletonData);
animationStateData.defaultMix = 0.3;
skeleton = new spine.Skeleton(skeletonData); skeleton = new spine.Skeleton(skeletonData);
animationState = new spine.AnimationState(animationStateData); animationState = new spine.AnimationState(animationStateData);
@ -38,6 +39,8 @@ function load () {
renderer.camera.zoom = size.x > size.y ? size.x / canvas.width : size.y / canvas.height; renderer.camera.zoom = size.x > size.y ? size.x / canvas.width : size.y / canvas.height;
animationState.setAnimation(0, "walk", true); animationState.setAnimation(0, "walk", true);
animationState.addAnimation(0, "run", true, 1);
animationState.addAnimation(0, "jump", true, 3);
requestAnimationFrame(render); requestAnimationFrame(render);
} else { } else {