From c3b91baa82e2326de5d5fda30b88a3c808a763e5 Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Tue, 15 Dec 2015 18:35:18 +0100 Subject: [PATCH 01/15] notes and fixes from code review --- src/anm/animation/animation.js | 7 +++---- src/anm/animation/element.js | 7 ++++--- src/anm/animation/timeline.js | 8 ++++---- src/anm/animation/tween.js | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/anm/animation/animation.js b/src/anm/animation/animation.js index 335e13e4..d407b5e8 100644 --- a/src/anm/animation/animation.js +++ b/src/anm/animation/animation.js @@ -329,15 +329,14 @@ Animation.prototype.tick = function(dt) { Animation.prototype._changeToNextScene = function(dt) { var nextScene = (this.currentSceneIdx < this.scenes.length) ? this.scenes[this.currentSceneIdx + 1] : null; + var currentSceneTime = this.currentScene.time; + var left = (currentSceneTime.duration - currentSceneTime.pos); + this.currentScene.tick(left); if (nextScene) { - var currentSceneTime = this.currentScene.time; - var left = (currentSceneTime.duration - currentSceneTime.pos); - this.currentScene.tick(left); this.currentSceneIdx++; this.currentScene = nextScene; this.currentScene.tick(dt - left); // tick the remainder in the next scene } else { - this.currentScene.tick(dt); if (this.endOnLastScene) this.time.endNow(); } }; diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 3921fbef..16e08156 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -719,11 +719,11 @@ Element.prototype.render = function(ctx) { var ltime = this.time.pos, dt = this.time.getLastDelta(); - var mask = this.$mask, + var mask = this.$mask, // FIXME: mask could tick and render several times renderMasked = false, mask_ltime; - if (mask) { mask_ltime = mask.tick(dt); }; + if (mask) { mask_ltime = mask.tick(dt); }; // FIXME: move to element.tick if (!Timeline.isKnownTime(ltime)) return; @@ -748,7 +748,7 @@ Element.prototype.render = function(ctx) { this.transform(ctx); this.painters(ctx); this.each(function(child) { - child.tick(dt); + child.tick(dt); // FIXME: move to element.tick child.render(ctx); }); } else { @@ -809,6 +809,7 @@ Element.prototype.render = function(ctx) { child.render(bctx, dt); }); + // FIXME: this should be performed one time for all masked elements! mask.transform(mctx); mask.painters(mctx); mask.each(function(child) { diff --git a/src/anm/animation/timeline.js b/src/anm/animation/timeline.js index 4b89538e..e58168e0 100644 --- a/src/anm/animation/timeline.js +++ b/src/anm/animation/timeline.js @@ -22,14 +22,14 @@ function Timeline(owner) { this.start = 0; this.duration = Infinity; - this.end = C.R_ONCE; + this.end = C.R_ONCE; // TODO: rename to endAction this.nrep = Infinity; this.actions = []; this.paused = false; this.pos = -this.start || 0; this.actualPos = -this.start || 0; this.easing = null; - this.speed = 1; + this.speed = 1; // TODO: use speed this.lastDelta = 0; this.passedStart = false; @@ -63,7 +63,7 @@ Timeline.prototype.tick = function(dt) { if (this.paused) { this.lastDelta = 0; return this.pos; } var next = (this.pos !== NO_TIME) ? (this.pos + dt) : NO_TIME; - next = this._checkSwitcher(next); + next = this._checkSwitcher(next); // FIXME: move to Element.checkSwitcher if (next !== NO_TIME) { @@ -113,7 +113,7 @@ Timeline.prototype.tick = function(dt) { } //console.log('tick', this.owner.name, this.pos, dt, next); - this.pos = next; + this.pos = next; // FIXME: if actions changed time, this OVERWRITES the position return this.pos; }; diff --git a/src/anm/animation/tween.js b/src/anm/animation/tween.js index f56441ba..b1d2da59 100644 --- a/src/anm/animation/tween.js +++ b/src/anm/animation/tween.js @@ -351,7 +351,7 @@ Tween.register(C.T_DISPLAY, { Tween.register(C.T_SWITCH, { func: function(value, tween) { return function(t) { this.switch_band = tween.$band; - this.switch = value; } + this.switch = value; } // value is the name of the sub-child to switch to }, from: nop, to: nop }); From de9be2afd4a6124f0c287cdae55cfcbfb2d1f77a Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Wed, 16 Dec 2015 12:51:15 +0100 Subject: [PATCH 02/15] fix rewriting next position after the jumps --- src/anm/animation/timeline.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/anm/animation/timeline.js b/src/anm/animation/timeline.js index e58168e0..eae26e94 100644 --- a/src/anm/animation/timeline.js +++ b/src/anm/animation/timeline.js @@ -98,10 +98,12 @@ Timeline.prototype.tick = function(dt) { var prev = this.pos; + var positionAdjusted = false; // this will be true if user manually changed time position with actions (i.e. with jump) if (next !== NO_TIME) { this._performActionsBetween(prev, next, dt); // actions could change this.pos + if (this.pos !=== prev) positionAdjusted = true; - if (this.pos === prev) { // there were no jumps in time, so this.pos stayed + if (!positionAdjusted) { // there were no jumps in time, so this.pos stayed if ((prev <= 0) && (next > 0) && (next <= this.duration) && !this.passedStart) { this.fire(C.X_START, next); this.passedStart = true; } @@ -113,7 +115,7 @@ Timeline.prototype.tick = function(dt) { } //console.log('tick', this.owner.name, this.pos, dt, next); - this.pos = next; // FIXME: if actions changed time, this OVERWRITES the position + if (!positionAdjusted) this.pos = next; return this.pos; }; From 7d9635a238f0ea14bfe9744c4fa6189df118bbc0 Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Wed, 16 Dec 2015 16:30:48 +0100 Subject: [PATCH 03/15] massive renamings in Timeline class, p.1 --- src/anm/animation/element.js | 2 +- src/anm/animation/timeline.js | 98 +++++++++++++++++------------------ src/anm/render.js | 4 +- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 16e08156..5b7ffdf7 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -716,7 +716,7 @@ Element.prototype.render = function(ctx) { this.rendering = true; - var ltime = this.time.pos, + var ltime = this.time.getLastPosition(), dt = this.time.getLastDelta(); var mask = this.$mask, // FIXME: mask could tick and render several times diff --git a/src/anm/animation/timeline.js b/src/anm/animation/timeline.js index eae26e94..f36cd7d3 100644 --- a/src/anm/animation/timeline.js +++ b/src/anm/animation/timeline.js @@ -22,12 +22,12 @@ function Timeline(owner) { this.start = 0; this.duration = Infinity; - this.end = C.R_ONCE; // TODO: rename to endAction - this.nrep = Infinity; + this.endAction = C.R_ONCE; + this.repetitionCount = Infinity; this.actions = []; this.paused = false; - this.pos = -this.start || 0; - this.actualPos = -this.start || 0; + this.position = -this.start || 0; + this.actualPosition = -this.start || 0; this.easing = null; this.speed = 1; // TODO: use speed this.lastDelta = 0; @@ -43,8 +43,8 @@ Timeline.isKnownTime = isKnownTime; Timeline.prototype.reset = function() { this.paused = false; - this.pos = -this.start; - this.actualPos = -this.start; + this.position = -this.start; + this.actualPosition = -this.start; this.passedStart = false; this.passedEnd = false; this.lastDelta = 0; @@ -58,11 +58,11 @@ Timeline.prototype.addAction = function(t, f) { }; Timeline.prototype.tick = function(dt) { - this.actualPos += dt; + this.actualPosition += dt; - if (this.paused) { this.lastDelta = 0; return this.pos; } + if (this.paused) { this.lastDelta = 0; return this.position; } - var next = (this.pos !== NO_TIME) ? (this.pos + dt) : NO_TIME; + var next = (this.position !== NO_TIME) ? (this.position + dt) : NO_TIME; next = this._checkSwitcher(next); // FIXME: move to Element.checkSwitcher if (next !== NO_TIME) { @@ -81,12 +81,12 @@ Timeline.prototype.tick = function(dt) { if (!wasPaused) this.fire(C.X_PAUSE, next); } else if (this.mode === C.R_LOOP) { var fits = Math.floor(next / this.duration); - if ((fits < 0) || (fits > this.nrep)) { next = NO_TIME; } + if ((fits < 0) || (fits > this.repetitionCount)) { next = NO_TIME; } else { next = next - (fits * this.duration); } this.fire(C.X_JUMP, next); this.fire(C.X_ITER); } else if (this.mode === C.R_BOUNCE) { var fits = Math.floor(next / this.duration); - if ((fits < 0) || (fits > this.nrep)) { next = NO_TIME; } + if ((fits < 0) || (fits > this.repetitionCount)) { next = NO_TIME; } else { next = next - (fits * this.duration); next = ((fits % 2) === 0) ? next : (this.duration - next); @@ -96,49 +96,49 @@ Timeline.prototype.tick = function(dt) { } } else { this.lastDelta = 0; } - var prev = this.pos; + var previous = this.position; var positionAdjusted = false; // this will be true if user manually changed time position with actions (i.e. with jump) if (next !== NO_TIME) { - this._performActionsBetween(prev, next, dt); // actions could change this.pos - if (this.pos !=== prev) positionAdjusted = true; + this._performActionsBetween(previous, next, dt); // actions could change this.position + if (this.position !=== previous) positionAdjusted = true; - if (!positionAdjusted) { // there were no jumps in time, so this.pos stayed - if ((prev <= 0) && (next > 0) && (next <= this.duration) && !this.passedStart) { + if (!positionAdjusted) { // there were no jumps in time, so this.position stayed + if ((previous <= 0) && (next > 0) && (next <= this.duration) && !this.passedStart) { this.fire(C.X_START, next); this.passedStart = true; } - if ((prev >= 0) && (prev <= this.duration) && (next >= this.duration) && !this.passedEnd) { + if ((previous >= 0) && (previous <= this.duration) && (next >= this.duration) && !this.passedEnd) { this.fire(C.X_END, next); this.passedEnd = true; } } } - //console.log('tick', this.owner.name, this.pos, dt, next); - if (!positionAdjusted) this.pos = next; + //console.log('tick', this.owner.name, this.position, dt, next); + if (!positionAdjusted) this.position = next; - return this.pos; + return this.position; }; Timeline.prototype.tickRelative = function(other, dt) { - if (!other || !is.defined(other.pos)) { /*this.endNow();*/ return NO_TIME; } - this.pos = other.pos - this.start - dt; // we subtract dt to add it later in this.tick - this.actualPos = this.pos; + if (!other || !is.defined(other.position)) { /*this.endNow();*/ return NO_TIME; } + this.position = other.position - this.start - dt; // we subtract dt to add it later in this.tick + this.actualPosition = this.position; return this.tick(dt); }; Timeline.prototype.endNow = function() { - this.fire(C.X_END, this.pos); this.passedEnd = true; - this.pos = NO_TIME; + this.fire(C.X_END, this.position); this.passedEnd = true; + this.position = NO_TIME; }; Timeline.prototype.fits = function() { - return (this.pos !== NO_TIME) && (this.pos >= 0) && (this.pos <= this.duration); + return (this.position !== NO_TIME) && (this.position >= 0) && (this.position <= this.duration); }; Timeline.prototype.setEndAction = function(type, nrep) { - this.end = type; - this.nrep = is.num(nrep) ? nrep : Infinity; + this.endAction = type; + this.repetitionCount = is.num(nrep) ? nrep : Infinity; }; Timeline.prototype.changeBand = function(start, stop) { @@ -175,7 +175,7 @@ Timeline.prototype.getGlobalBand = function(parent) { }; Timeline.prototype.getLastPosition = function() { - return this.pos; + return this.position; }; Timeline.prototype.getLastDelta = function() { @@ -193,13 +193,13 @@ Timeline.prototype.getGlobalStart = function() { }; Timeline.prototype.getGlobalTime = function() { - return (this.pos !== NO_TIME) ? (this.getGlobalStart() + this.pos) : NO_TIME; + return (this.position !== NO_TIME) ? (this.getGlobalStart() + this.position) : NO_TIME; }; Timeline.prototype.pause = function() { - //console.log('pause', this.owner.name, this.pos); + //console.log('pause', this.owner.name, this.position); if (this.paused) return; - this.paused = true; this.fire(C.X_PAUSE, this.pos); + this.paused = true; this.fire(C.X_PAUSE, this.position); }; Timeline.prototype.pauseAt = function(at) { @@ -207,9 +207,9 @@ Timeline.prototype.pauseAt = function(at) { }; Timeline.prototype.continue = function() { - //console.log('continue', this.owner.name, this.pos); + //console.log('continue', this.owner.name, this.position); if (!this.paused) return; - this.fire(C.X_CONTINUE, this.pos); + this.fire(C.X_CONTINUE, this.position); this.paused = false; }; @@ -218,8 +218,8 @@ Timeline.prototype.countinueAt = function(at) { }; Timeline.prototype.jump = function(t) { - //console.log('jump', this.owner.name, this.pos, t); - this.pos = t; this.fire(C.X_JUMP, t); + //console.log('jump', this.owner.name, this.position, t); + this.position = t; this.fire(C.X_JUMP, t); }; Timeline.prototype.jumpAt = function(at, t) { @@ -237,18 +237,18 @@ Timeline.prototype.jumpTo = function(child) { }; Timeline.prototype.jumpToStart = function() { - this.actualPos = this.duration; - this.pos = 0; this.fire(C.X_JUMP, 0); + this.actualPosition = this.duration; + this.position = 0; this.fire(C.X_JUMP, 0); }; Timeline.prototype.jumpToEnd = function() { - this.actualPos = this.duration; - this.pos = this.duration; - this.fire(C.X_JUMP, this.pos); this.fire(C.X_END); + this.actualPosition = this.duration; + this.position = this.duration; + this.fire(C.X_JUMP, this.position); this.fire(C.X_END); }; Timeline.prototype.changeTrack = function(other, dt) { - var left = (this.duration - this.pos); + var left = (this.duration - this.position); //if (dt < left) throw new Error('') this.tick(left); other.tick(dt - left); @@ -260,8 +260,8 @@ Timeline.prototype.isFinished = function() { Timeline.prototype.easing = function(f) { this.easing = f; }; -Timeline.prototype.isBefore = function(t) { return (this.pos < t); }; -Timeline.prototype.isAfter = function(t) { return (this.pos > t); }; +Timeline.prototype.isBefore = function(t) { return (this.position < t); }; +Timeline.prototype.isAfter = function(t) { return (this.position > t); }; Timeline.prototype.fireMessage = function(message) { this.fire(C.X_MESSAGE, message); @@ -286,20 +286,20 @@ Timeline.prototype._checkSwitcher = function(next) { } else return NO_TIME; }; -Timeline.prototype._performActionsBetween = function(prev, next, dt) { +Timeline.prototype._performActionsBetween = function(previous, next, dt) { if (!this.actions.length) return; var actionsPos = 0; var curAction = this.actions[actionsPos]; // scroll to current time (this.time) forward first, if we're not there already while (curAction && (actionsPos < this.actions.length) && - (curAction.time < prev)) { + (curAction.time < previous)) { actionsPos++; curAction = this.actions[actionsPos]; } // then perform everything before `next` time while (curAction && (actionsPos < this.actions.length) && (curAction.time <= next) && - ((curAction.time > prev) || - ((dt > 0) && (curAction.time == prev)))) { + ((curAction.time > previous) || + ((dt > 0) && (curAction.time == previous)))) { curAction.func(next); actionsPos++; curAction = this.actions[actionsPos]; } @@ -308,7 +308,7 @@ Timeline.prototype._performActionsBetween = function(prev, next, dt) { Timeline.prototype.clone = function(owner) { var trg = new Timeline(owner || this.owner); trg.start = this.start; trg.duration = this.duration; - trg.end = this.end; trg.nrep = this.nrep; + trg.endAction = this.endAction; trg.repetitionCount = this.repetitionCount; trg.easing = this.easing; //trg.actions = this.actions.concat([]) return trg; diff --git a/src/anm/render.js b/src/anm/render.js index e73a5c10..67c6e35b 100644 --- a/src/anm/render.js +++ b/src/anm/render.js @@ -98,7 +98,7 @@ function r_next(dt, ctx, anim, width, height, zoom, rib_color, before, after) { if (zoom != 1) { ctx.scale(zoom, zoom); } anim.tick(dt); anim.render(ctx); - if (after) after(anim.time.pos, ctx); + if (after) after(anim.time.getLastPosition(), ctx); ctx.restore(); } else { r_with_ribbons(ctx, anim, @@ -111,7 +111,7 @@ function r_next(dt, ctx, anim, width, height, zoom, rib_color, before, after) { if (zoom != 1) { ctx.scale(zoom, zoom); } anim.tick(dt); anim.render(ctx); - if (after) after(anim.time.pos, ctx); + if (after) after(anim.time.getLastPosition(), ctx); ctx.restore(); }); } From d528e8393e824ed9cf5a38bc97d06a1456ac64db Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Wed, 16 Dec 2015 16:41:22 +0100 Subject: [PATCH 04/15] massive renamings in Timeline class, p.2 --- src/anm/render.js | 6 +++--- src/import/animatron-importer.js | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/anm/render.js b/src/anm/render.js index 67c6e35b..582e4827 100644 --- a/src/anm/render.js +++ b/src/anm/render.js @@ -98,7 +98,7 @@ function r_next(dt, ctx, anim, width, height, zoom, rib_color, before, after) { if (zoom != 1) { ctx.scale(zoom, zoom); } anim.tick(dt); anim.render(ctx); - if (after) after(anim.time.getLastPosition(), ctx); + if (after) after(anim.getTime(), ctx); ctx.restore(); } else { r_with_ribbons(ctx, anim, @@ -111,7 +111,7 @@ function r_next(dt, ctx, anim, width, height, zoom, rib_color, before, after) { if (zoom != 1) { ctx.scale(zoom, zoom); } anim.tick(dt); anim.render(ctx); - if (after) after(anim.time.getLastPosition(), ctx); + if (after) after(anim.getTime(), ctx); ctx.restore(); }); } @@ -260,7 +260,7 @@ Render.p_drawName = new Painter(function(ctx, name) { }, C.PNT_DEBUG); Render.p_drawTime = new Painter(function(ctx, time) { - if (!(time = time || this.time.getLastPosition())) return; + if (!(time = time || this.getTime())) return; ctx.save(); ctx.fillStyle = '#600'; ctx.font = '10px sans-serif'; diff --git a/src/import/animatron-importer.js b/src/import/animatron-importer.js index da0122a9..3916f329 100644 --- a/src/import/animatron-importer.js +++ b/src/import/animatron-importer.js @@ -318,12 +318,9 @@ Import.branch = function(type, src, parent_src, parent_band, all, anim) { */ // transfer repetition data if (layer_src[5]) { - layer_trg.time.mode = Import.mode(layer_src[5][0]); - if (layer_src[5].length > 1) { - layer_trg.time.nrep = layer_src[5][1] || Infinity; - } + layer_trg.time.setEndAction(Import.mode(layer_src[5][0], layer_src[5][1])); } else { - layer_trg.time.mode = Import.mode(null); + layer_trg.time.setEndAction(Import.mode(null)); } // if do not masks any layers, just add to target From 751bd9e81d219490a40ec0c6fa529c9044f5ab4b Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Wed, 16 Dec 2015 17:02:20 +0100 Subject: [PATCH 05/15] massive renamings in Timeline class, p.3 (.time -> .timeline) --- src/anm/animation/animation.js | 44 ++++++++++---------- src/anm/animation/element.js | 75 +++++++++++++++++++--------------- src/anm/animation/scene.js | 34 +++++++-------- src/anm/animation/timeline.js | 10 ----- src/anm/player.js | 12 +++--- src/module/audio-export.js | 2 +- 6 files changed, 89 insertions(+), 88 deletions(-) diff --git a/src/anm/animation/animation.js b/src/anm/animation/animation.js index d407b5e8..6418d330 100644 --- a/src/anm/animation/animation.js +++ b/src/anm/animation/animation.js @@ -72,7 +72,7 @@ function Animation() { //this.fps = undefined; this.__lastOverElm = null; this._laters = []; - this.time = new Timeline(this); + this.timeline = new Timeline(this); var defaultScene = new Scene(this, '', 0); this.scenes = []; @@ -139,7 +139,7 @@ Animation.prototype.addScene = function(name, duration) { }; Animation.prototype.getDuration = function() { - return this.time.getDuration(); + return this.timeline.getDuration(); }; /*Animation.prototype.getTotalDurationFromScenes = function() { @@ -202,9 +202,9 @@ Animation.prototype.traverse = function(visitor, data) { * @param {Object} [data] */ Animation.prototype.traverseVisible = function(visitor, data) { - if (this.currentScene && this.currentScene.time.fits()) { + if (this.currentScene && this.currentScene.timeline.fits()) { this.currentScene.traverse(function(child) { - return (child.time.fits() && (visitor(child, data) === false)) ? false : true; + return (child.timeline.fits() && (visitor(child, data) === false)) ? false : true; }); } return this; @@ -225,9 +225,9 @@ Animation.prototype.traverseVisible = function(visitor, data) { * @param {Object} [data] */ Animation.prototype.reverseTraverseVisible = function(visitor, data) { - if (this.currentScene && this.currentScene.time.fits()) { + if (this.currentScene && this.currentScene.timeline.fits()) { this.currentScene.reverseTraverse(function(child) { - return (child.time.fits() && (visitor(child, data) === false)) ? false : true; + return (child.timeline.fits() && (visitor(child, data) === false)) ? false : true; }); } return this; @@ -317,10 +317,10 @@ Animation.prototype.render = function(ctx) { }; Animation.prototype.tick = function(dt) { - var curSceneTime = this.currentScene.time; + var curSceneTime = this.currentScene.timeline; if ((curSceneTime.pos + dt) < curSceneTime.duration) { this.currentScene.tick(dt); - this.time.tick(dt); + this.timeline.tick(dt); } else { this._changeToNextScene(dt); } @@ -329,7 +329,7 @@ Animation.prototype.tick = function(dt) { Animation.prototype._changeToNextScene = function(dt) { var nextScene = (this.currentSceneIdx < this.scenes.length) ? this.scenes[this.currentSceneIdx + 1] : null; - var currentSceneTime = this.currentScene.time; + var currentSceneTime = this.currentScene.timeline; var left = (currentSceneTime.duration - currentSceneTime.pos); this.currentScene.tick(left); if (nextScene) { @@ -337,17 +337,17 @@ Animation.prototype._changeToNextScene = function(dt) { this.currentScene = nextScene; this.currentScene.tick(dt - left); // tick the remainder in the next scene } else { - if (this.endOnLastScene) this.time.endNow(); + if (this.endOnLastScene) this.timeline.endNow(); } }; Animation.prototype.pause = function() { - this.time.pause(); + this.timeline.pause(); this.currentScene.pause(); }; Animation.prototype.continue = function() { - this.time.continue(); + this.timeline.continue(); this.currentScene.continue(); }; @@ -362,7 +362,7 @@ Animation.prototype.continue = function() { */ Animation.prototype.jump = function(t) { var prev_time = this.getTime(); - this.time.jump(t); + this.timeline.jump(t); this.goToSceneAt(t); }; @@ -378,31 +378,31 @@ Animation.prototype.jump = function(t) { Animation.prototype.jumpTo = function(selector) { var elm = is.str(selector) ? this.find(selector) : selector; if (!elm) return; - //this.jump(elm.time.getGlobalStart()); + //this.jump(elm.timeline.getGlobalStart()); if (elm instanceof Scene) { this.goToScene(elm); } else { - this.time.jumpTo(elm); + this.timeline.jumpTo(elm); this.goToSceneAt(this.getTime()); } }; Animation.prototype.jumpToStart = function() { - this.time.jumpToStart(); + this.timeline.jumpToStart(); this.setCurrentScene(0); this.currentScene.jumpToStart(); }; Animation.prototype.getTime = function() { - return this.time.getLastPosition(); + return this.timeline.getLastPosition(); }; Animation.prototype.setDuration = function(duration) { - this.time.setDuration(duration); + this.timeline.setDuration(duration); }; Animation.prototype.setSpeed = function(speed) { - this.time.setSpeed(speed); + this.timeline.setSpeed(speed); }; Animation.prototype.goToScene = function(scene) { @@ -420,8 +420,8 @@ Animation.prototype.goToSceneAt = function(t) { var loc_t = t; var i = 0, cursor = this.scenes[i]; - while (/*(i < this.scenes.length) && */cursor && (loc_t > cursor.time.duration)) { - loc_t = loc_t - cursor.time.duration; + while (/*(i < this.scenes.length) && */cursor && (loc_t > cursor.timeline.getDuration())) { + loc_t = loc_t - cursor.timeline.getDuration(); i++; cursor = this.scenes[i]; } if (cursor) { @@ -444,7 +444,7 @@ Animation.prototype.goToSceneAt = function(t) { * Reset all render-related data for itself, and the data of all the elements. */ Animation.prototype.reset = function() { - this.time.reset(); + this.timeline.reset(); this.eachScene(function(scene) { scene.reset(); }); diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 5b7ffdf7..350ecfee 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -287,7 +287,7 @@ Element.prototype.initTime = function() { /** @property {anm.Timeline} timeline instance @readonly */ - this.time = new Timeline(this); + this.timeline = new Timeline(this); /** @property {String} switch (name of the child to render in current moment) */ @@ -297,7 +297,7 @@ Element.prototype.initTime = function() { }; Element.prototype.resetTime = function() { - this.time.reset(); + this.timeline.reset(); this.switch = null; }; @@ -716,8 +716,8 @@ Element.prototype.render = function(ctx) { this.rendering = true; - var ltime = this.time.getLastPosition(), - dt = this.time.getLastDelta(); + var ltime = this.timeline.getLastPosition(), + dt = this.timeline.getLastDelta(); var mask = this.$mask, // FIXME: mask could tick and render several times renderMasked = false, @@ -727,7 +727,7 @@ Element.prototype.render = function(ctx) { if (!Timeline.isKnownTime(ltime)) return; - var drawMe = this.time.fits() && + var drawMe = this.timeline.fits() && this.modifiers(ltime, dt) && this.visible; // modifiers should be applied even if element isn't visible if (drawMe) { @@ -738,7 +738,7 @@ Element.prototype.render = function(ctx) { // which is even better, make all these checks to be modifiers // FIXME: call modifiers once for one moment of time. If there are several // masked elements, they will be called that number of times - renderMasked = mask.time.fits() && + renderMasked = mask.timeline.fits() && mask.modifiers(mask_ltime, dt) && mask.visible; } @@ -838,15 +838,26 @@ Element.prototype.render = function(ctx) { }; Element.prototype.tick = function(dt) { + // TODO: check switcher if (!this.parent && this.scene && this.scene.affectsChildren) { - return this.time.tickRelative(this.scene.time, dt); + return this.timeline.tickRelative(this.scene.timeline, dt); } else if (this.parent && this.parent.affectsChildren) { - return this.time.tickRelative(this.parent.time, dt); + return this.timeline.tickRelative(this.parent.timeline, dt); } else { - return this.time.tick(dt); + return this.timeline.tick(dt); } }; +Element.prototype._checkSwitcher = function(next) { + var parent = this.parent; + if (!parent || !parent.switch) return next; + if (parent.switch === C.SWITCH_OFF) return NO_TIME; + if ((parent.switch === this.name) && parent.switch_band) { + if (next === NO_TIME) return NO_TIME; + return next - parent.switch_band[0]; + } else return NO_TIME; +}; + /** * @method pivot * @chainable @@ -1015,7 +1026,7 @@ Element.prototype.skew = function(hx, hy) { * @return {anm.Element} itself */ Element.prototype.repeat = function(mode, nrep) { - this.time.setEndAction(mode, nrep); + this.timeline.setEndAction(mode, nrep); return this; }; @@ -1033,7 +1044,7 @@ Element.prototype.repeat = function(mode, nrep) { * @return {anm.Element} itself */ Element.prototype.once = function() { - this.time.setEndAction(C.R_ONCE, Infinity); + this.timeline.setEndAction(C.R_ONCE, Infinity); return this; }; @@ -1049,7 +1060,7 @@ Element.prototype.once = function() { * @return {anm.Element} itself */ Element.prototype.stay = function() { - this.time.setEndAction(C.R_STAY, Infinity); + this.timeline.setEndAction(C.R_STAY, Infinity); return this; }; @@ -1067,7 +1078,7 @@ Element.prototype.stay = function() { * @return {anm.Element} itself */ Element.prototype.loop = function(nrep) { - this.time.setEndAction(C.R_LOOP, nrep); + this.timeline.setEndAction(C.R_LOOP, nrep); return this; }; @@ -1086,12 +1097,12 @@ Element.prototype.loop = function(nrep) { * @return {anm.Element} itself */ Element.prototype.bounce = function(nrep) { - this.time.setEndAction(C.R_BOUNCE, nrep); + this.timeline.setEndAction(C.R_BOUNCE, nrep); return this; }; Element.prototype.mode = function(mode, nrep) { - this.time.setEndAction(mode, nrep); + this.timeline.setEndAction(mode, nrep); }; /** @@ -1109,7 +1120,7 @@ Element.prototype.mode = function(mode, nrep) { * @return {anm.Element} itself */ Element.prototype.jump = function(t) { - this.time.jump(t); + this.timeline.jump(t); return this; }; @@ -1130,22 +1141,22 @@ Element.prototype.jump = function(t) { Element.prototype.jumpTo = function(element) { var elm = is.str(selector) ? this.find(selector) : selector; if (!elm) return; - // var delta = this.time.getLastDelta (?) - this.time.jumpTo(elm); + // var delta = this.timeline.getLastDelta (?) + this.timeline.jumpTo(elm); return this; }; Element.prototype.jumpAt = function(at, t) { - this.time.jumpAt(at, t); + this.timeline.jumpAt(at, t); return this; }; Element.prototype.jumpToStart = function() { - this.time.jumpToStart(); + this.timeline.jumpToStart(); }; Element.prototype.getTime = function() { - return this.time.getLastPosition(); + return this.timeline.getLastPosition(); }; /** @@ -1159,7 +1170,7 @@ Element.prototype.getTime = function() { * @return {anm.Element} itself */ Element.prototype.play = function() { - this.time.continue(); + this.timeline.continue(); return this; } Element.prototype.continue = Element.prototype.play; // FIXME @@ -1178,7 +1189,7 @@ Element.prototype.continue = Element.prototype.play; // FIXME * @return {anm.Element} itself */ Element.prototype.stop = function() { - this.time.pause(); + this.timeline.pause(); return this; } Element.prototype.pause = Element.prototype.stop; // FIXME @@ -1201,7 +1212,7 @@ Element.prototype.pause = Element.prototype.stop; // FIXME * @return {anm.Element} itself */ Element.prototype.at = function(t, f) { - return this.time.addAction(t, f); + return this.timeline.addAction(t, f); } /** @@ -1441,7 +1452,7 @@ Element.prototype.detach = function() { * @return {Number} global time */ Element.prototype.gtime = function(ltime) { - this.time.getGlobalTime(); + this.timeline.getGlobalTime(); }; /** @@ -1463,13 +1474,13 @@ Element.prototype.gtime = function(ltime) { * @return {anm.Element} itself */ Element.prototype.band = function(start, stop) { - if (!is.defined(start)) return this.time.getBand(); - this.time.changeBand(start, is.defined(stop) ? stop : Infinity); + if (!is.defined(start)) return this.timeline.getBand(); + this.timeline.changeBand(start, is.defined(stop) ? stop : Infinity); return this; }; Element.prototype.getGlobalBand = function() { - return this.time.getGlobalBand(this.parent); + return this.timeline.getGlobalBand(this.parent); }; /** @@ -1491,11 +1502,11 @@ Element.prototype.duration = function(value) { }; Element.prototype.setDuration = function(duration) { - this.time.setDuration(duration); + this.timeline.setDuration(duration); }; Element.prototype.getDuration = function() { - return this.time.getDuration(); + return this.timeline.getDuration(); }; /** @@ -2339,7 +2350,7 @@ Element.prototype.__adaptModTime = function(modifier, ltime) { // TODO: move to Modifier class? var elm = this, - elm_duration = elm.time.getDuration(), // duration of the element's local band + elm_duration = elm.timeline.getDuration(), // duration of the element's local band mod_easing = modifier.$easing, // modifier easing mod_time = modifier.$band || modifier.$time, // time (or band) of the modifier, if set mod_relative = modifier.$relative, // is modifier time or band relative to elm duration or not @@ -2555,7 +2566,7 @@ Element.transferVisuals = function(src, trg) { }; Element.transferTime = function(src, trg) { - trg.time = src.time.clone(trg); + trg.timeline = src.timeline.clone(trg); }; // TODO: rename to matrixOf ? diff --git a/src/anm/animation/scene.js b/src/anm/animation/scene.js index 3617e06f..fd30991f 100644 --- a/src/anm/animation/scene.js +++ b/src/anm/animation/scene.js @@ -13,8 +13,8 @@ function Scene(anim, name, duration) { this.anim = anim; this.name = name; - this.time = new Timeline(this); - this.time.setDuration(is.num(duration) ? duration : Infinity); + this.timeline = new Timeline(this); + this.timeline.setDuration(is.num(duration) ? duration : Infinity); this.affectsChildren = true; @@ -23,8 +23,8 @@ function Scene(anim, name, duration) { } Scene.prototype.tick = function(dt) { - this.time.tick(dt); - if (this.time.fits()) { + this.timeline.tick(dt); + if (this.timeline.fits()) { this.each(function(child) { child.tick(dt); }); @@ -32,7 +32,7 @@ Scene.prototype.tick = function(dt) { }; Scene.prototype.render = function(ctx) { - if (this.time.fits()) { + if (this.timeline.fits()) { this.each(function(child) { child.render(ctx); }); @@ -46,11 +46,11 @@ Scene.prototype.duration = function(value) { }; Scene.prototype.setDuration = function(duration) { - this.time.setDuration(duration); + this.timeline.setDuration(duration); }; Scene.prototype.getDuration = function() { - return this.time.getDuration(); + return this.timeline.getDuration(); }; Scene.prototype.traverse = function(visitor, data) { @@ -159,23 +159,23 @@ Scene.prototype.getPath = function() { }; Scene.prototype.at = function(t, f) { - return this.time.addAction(t, f); + return this.timeline.addAction(t, f); }; Scene.prototype.continue = function() { - this.time.continue(); + this.timeline.continue(); return this; }; Scene.prototype.play = Scene.prototype.continue; // FIXME Scene.prototype.pause = function() { - this.time.pause(); + this.timeline.pause(); return this; }; Scene.prototype.stop = Scene.prototype.pause; // FIXME Scene.prototype.jump = function(t) { - this.time.jump(t); + this.timeline.jump(t); return this; }; @@ -190,29 +190,29 @@ Scene.prototype.jumpToStart = function() { }; Scene.prototype.jumpToEnd = function() { - this.time.jumpToEnd(); + this.timeline.jumpToEnd(); return this; }; Scene.prototype.jumpAt = function(at, t) { - this.time.jumpAt(at, t); + this.timeline.jumpAt(at, t); return this; }; Scene.prototype.getTime = function() { - return this.time.getLastPosition(); + return this.timeline.getLastPosition(); }; Scene.prototype.reset = function() { - this.time.reset(); + this.timeline.reset(); this.each(function(child) { child.reset(); }); }; Scene._fromElement = function(elm) { - var scene = new Scene(elm.anim, elm.name/*, elm.time.getDuration()*/); - scene.time = elm.time.clone(); + var scene = new Scene(elm.anim, elm.name/*, elm.timeline.getDuration()*/); + scene.timeline = elm.timeline.clone(); elm.each(function(child) { scene.add(child); }); diff --git a/src/anm/animation/timeline.js b/src/anm/animation/timeline.js index f36cd7d3..89b97ef8 100644 --- a/src/anm/animation/timeline.js +++ b/src/anm/animation/timeline.js @@ -276,16 +276,6 @@ Timeline.prototype.fireMessageAt = function(at, message) { this.addAction(at, function() { me.fireMessage(message); }); }; -Timeline.prototype._checkSwitcher = function(next) { - var parent = this.owner.parent; - if (!parent || !parent.switch) return next; - if (parent.switch === C.SWITCH_OFF) return NO_TIME; - if ((parent.switch === this.owner.name) && parent.switch_band) { - if (next === NO_TIME) return NO_TIME; - return next - parent.switch_band[0]; - } else return NO_TIME; -}; - Timeline.prototype._performActionsBetween = function(previous, next, dt) { if (!this.actions.length) return; var actionsPos = 0; diff --git a/src/anm/player.js b/src/anm/player.js index 1328ca5b..5f23a09d 100644 --- a/src/anm/player.js +++ b/src/anm/player.js @@ -503,7 +503,7 @@ Player.prototype.play = function(from, speed, stopAfter) { // FIXME: lines below should not modify animation time, but rather use some temporary time configuration // living through one playthrough and dying after stop. - if (is.num(speed)) anim.time.setSpeed(speed || 1); + if (is.num(speed)) anim.setSpeed(speed || 1); if (is.num(stopAfter)) { player.stopAfter = stopAfter; } else { @@ -622,7 +622,7 @@ Player.prototype.pause = function() { player.happens = C.PAUSED; - var anim_time = player.anim ? player.anim.time : null; + var anim_time = player.anim ? player.anim.timeline : null; if (anim_time && anim_time.fits()) player.drawCurrent(); player.fire(C.S_CHANGE_STATE, C.PAUSED); @@ -896,7 +896,7 @@ Player.prototype.drawAt = function(time) { var ctx_props = engine.getAnmProps(this.ctx); ctx_props.factor = this.factor(); - var prev_pos = anim.time.getLastPosition(); + var prev_pos = anim.getTime(); anim.jump(time); Render.next(0, this.ctx, this.anim, this.width, this.height, this.zoom, this.ribbonsColor, u_before, ext_after); anim.jump(prev_pos); @@ -1387,7 +1387,7 @@ Player.prototype._reset = function() { Player.prototype._pauseAndContinue = function() { var last_conf = this.__lastPlayConf; - var stoppedAt = this.anim ? this.anim.time.getLastPosition() : 0; + var stoppedAt = this.anim ? this.anim.getTime() : 0; this.pause(); this.play(stoppedAt, last_conf[1], last_conf[2]); }; @@ -1514,8 +1514,8 @@ Player.prototype.__beforeFrame = function(anim) { return function(time) { anim.clearAllLaters(); if (player.happens !== C.PLAYING) return false; - if (player.anim && (!player.anim.time.fits() || // FIXME: do using subscription anim.on(C.X_END, ...) - player.anim.time.isAfter(player.stopAfter))) { + if (player.anim && (!player.anim.timeline.fits() || // FIXME: do using subscription anim.on(C.X_END, ...) + player.anim.timeline.isAfter(player.stopAfter))) { player._complete(); return false; } diff --git a/src/module/audio-export.js b/src/module/audio-export.js index e559f4d0..95455e3b 100644 --- a/src/module/audio-export.js +++ b/src/module/audio-export.js @@ -16,7 +16,7 @@ Player.prototype.exportAudio = function() { if (this.anim) { this.anim.traverse(function(elm) { if (elm.is(C.ET_AUDIO)) { - var gband = elm.time.getGlobalBand(elm.parent); + var gband = elm.timeline.getGlobalBand(elm.parent); result.push({ 'url': elm._audio_url, 'band_offset': elm._audio_band_offset, 'start': gband[0], From 41892b752999750f0adf60851db129336b343b84 Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Wed, 16 Dec 2015 17:10:39 +0100 Subject: [PATCH 06/15] massive renamings in Timeline class, p.4 (timeline.fits() -> timeline.isActive()) --- src/anm/animation/animation.js | 8 +++--- src/anm/animation/element.js | 46 +++++++++++++++++----------------- src/anm/animation/scene.js | 4 +-- src/anm/animation/timeline.js | 2 +- src/anm/player.js | 4 +-- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/anm/animation/animation.js b/src/anm/animation/animation.js index 6418d330..36289fe0 100644 --- a/src/anm/animation/animation.js +++ b/src/anm/animation/animation.js @@ -202,9 +202,9 @@ Animation.prototype.traverse = function(visitor, data) { * @param {Object} [data] */ Animation.prototype.traverseVisible = function(visitor, data) { - if (this.currentScene && this.currentScene.timeline.fits()) { + if (this.currentScene && this.currentScene.timeline.isActive()) { this.currentScene.traverse(function(child) { - return (child.timeline.fits() && (visitor(child, data) === false)) ? false : true; + return (child.timeline.isActive() && (visitor(child, data) === false)) ? false : true; }); } return this; @@ -225,9 +225,9 @@ Animation.prototype.traverseVisible = function(visitor, data) { * @param {Object} [data] */ Animation.prototype.reverseTraverseVisible = function(visitor, data) { - if (this.currentScene && this.currentScene.timeline.fits()) { + if (this.currentScene && this.currentScene.timeline.isActive()) { this.currentScene.reverseTraverse(function(child) { - return (child.timeline.fits() && (visitor(child, data) === false)) ? false : true; + return (child.timeline.isActive() && (visitor(child, data) === false)) ? false : true; }); } return this; diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 350ecfee..0bda07fd 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -695,6 +695,27 @@ Element.prototype.invTransform = function(ctx) { return inv_matrix; }; +Element.prototype.tick = function(dt) { + // TODO: check switcher + if (!this.parent && this.scene && this.scene.affectsChildren) { + return this.timeline.tickRelative(this.scene.timeline, dt); + } else if (this.parent && this.parent.affectsChildren) { + return this.timeline.tickRelative(this.parent.timeline, dt); + } else { + return this.timeline.tick(dt); + } +}; + +Element.prototype._checkSwitcher = function(next) { + var parent = this.parent; + if (!parent || !parent.switch) return next; + if (parent.switch === C.SWITCH_OFF) return NO_TIME; + if ((parent.switch === this.name) && parent.switch_band) { + if (next === NO_TIME) return NO_TIME; + return next - parent.switch_band[0]; + } else return NO_TIME; +}; + /** * @method render * @chainable @@ -727,7 +748,7 @@ Element.prototype.render = function(ctx) { if (!Timeline.isKnownTime(ltime)) return; - var drawMe = this.timeline.fits() && + var drawMe = this.timeline.isActive() && this.modifiers(ltime, dt) && this.visible; // modifiers should be applied even if element isn't visible if (drawMe) { @@ -738,7 +759,7 @@ Element.prototype.render = function(ctx) { // which is even better, make all these checks to be modifiers // FIXME: call modifiers once for one moment of time. If there are several // masked elements, they will be called that number of times - renderMasked = mask.timeline.fits() && + renderMasked = mask.timeline.isActive() && mask.modifiers(mask_ltime, dt) && mask.visible; } @@ -837,27 +858,6 @@ Element.prototype.render = function(ctx) { return this; }; -Element.prototype.tick = function(dt) { - // TODO: check switcher - if (!this.parent && this.scene && this.scene.affectsChildren) { - return this.timeline.tickRelative(this.scene.timeline, dt); - } else if (this.parent && this.parent.affectsChildren) { - return this.timeline.tickRelative(this.parent.timeline, dt); - } else { - return this.timeline.tick(dt); - } -}; - -Element.prototype._checkSwitcher = function(next) { - var parent = this.parent; - if (!parent || !parent.switch) return next; - if (parent.switch === C.SWITCH_OFF) return NO_TIME; - if ((parent.switch === this.name) && parent.switch_band) { - if (next === NO_TIME) return NO_TIME; - return next - parent.switch_band[0]; - } else return NO_TIME; -}; - /** * @method pivot * @chainable diff --git a/src/anm/animation/scene.js b/src/anm/animation/scene.js index fd30991f..fa690269 100644 --- a/src/anm/animation/scene.js +++ b/src/anm/animation/scene.js @@ -24,7 +24,7 @@ function Scene(anim, name, duration) { Scene.prototype.tick = function(dt) { this.timeline.tick(dt); - if (this.timeline.fits()) { + if (this.timeline.isActive()) { this.each(function(child) { child.tick(dt); }); @@ -32,7 +32,7 @@ Scene.prototype.tick = function(dt) { }; Scene.prototype.render = function(ctx) { - if (this.timeline.fits()) { + if (this.timeline.isActive()) { this.each(function(child) { child.render(ctx); }); diff --git a/src/anm/animation/timeline.js b/src/anm/animation/timeline.js index 89b97ef8..a1643ccd 100644 --- a/src/anm/animation/timeline.js +++ b/src/anm/animation/timeline.js @@ -132,7 +132,7 @@ Timeline.prototype.endNow = function() { this.position = NO_TIME; }; -Timeline.prototype.fits = function() { +Timeline.prototype.isActive = function() { return (this.position !== NO_TIME) && (this.position >= 0) && (this.position <= this.duration); }; diff --git a/src/anm/player.js b/src/anm/player.js index 5f23a09d..c8600ec1 100644 --- a/src/anm/player.js +++ b/src/anm/player.js @@ -623,7 +623,7 @@ Player.prototype.pause = function() { player.happens = C.PAUSED; var anim_time = player.anim ? player.anim.timeline : null; - if (anim_time && anim_time.fits()) player.drawCurrent(); + if (anim_time && anim_time.isActive()) player.drawCurrent(); player.fire(C.S_CHANGE_STATE, C.PAUSED); player.fire(C.S_PAUSE, anim_time ? anim_time.getLastPosition() : Timeline.NO_TIME); @@ -1514,7 +1514,7 @@ Player.prototype.__beforeFrame = function(anim) { return function(time) { anim.clearAllLaters(); if (player.happens !== C.PLAYING) return false; - if (player.anim && (!player.anim.timeline.fits() || // FIXME: do using subscription anim.on(C.X_END, ...) + if (player.anim && (!player.anim.timeline.isActive() || // FIXME: do using subscription anim.on(C.X_END, ...) player.anim.timeline.isAfter(player.stopAfter))) { player._complete(); return false; From d8eb3ca87a1d05033b44f3f3ed8cad720082c72b Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Wed, 16 Dec 2015 17:15:47 +0100 Subject: [PATCH 07/15] move all child-ticking from Element.render to Element.tick, p.1 --- src/anm/animation/element.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 0bda07fd..62d34127 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -697,13 +697,18 @@ Element.prototype.invTransform = function(ctx) { Element.prototype.tick = function(dt) { // TODO: check switcher + var resultTime; if (!this.parent && this.scene && this.scene.affectsChildren) { - return this.timeline.tickRelative(this.scene.timeline, dt); + resultTime = this.timeline.tickRelative(this.scene.timeline, dt); } else if (this.parent && this.parent.affectsChildren) { - return this.timeline.tickRelative(this.parent.timeline, dt); + resultTime = this.timeline.tickRelative(this.parent.timeline, dt); } else { - return this.timeline.tick(dt); + resultTime = this.timeline.tick(dt); } + this.each(function(child) { + child.tick(dt); + }); + return resultTime; }; Element.prototype._checkSwitcher = function(next) { @@ -769,7 +774,6 @@ Element.prototype.render = function(ctx) { this.transform(ctx); this.painters(ctx); this.each(function(child) { - child.tick(dt); // FIXME: move to element.tick child.render(ctx); }); } else { @@ -834,7 +838,6 @@ Element.prototype.render = function(ctx) { mask.transform(mctx); mask.painters(mctx); mask.each(function(child) { - child.tick(dt); child.render(mctx); }); From 3b4602b23854591918039b5d5253364a4b428e32 Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Wed, 16 Dec 2015 17:22:38 +0100 Subject: [PATCH 08/15] fix syntax error in Timeline class --- src/anm/animation/timeline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anm/animation/timeline.js b/src/anm/animation/timeline.js index a1643ccd..f0817b63 100644 --- a/src/anm/animation/timeline.js +++ b/src/anm/animation/timeline.js @@ -101,7 +101,7 @@ Timeline.prototype.tick = function(dt) { var positionAdjusted = false; // this will be true if user manually changed time position with actions (i.e. with jump) if (next !== NO_TIME) { this._performActionsBetween(previous, next, dt); // actions could change this.position - if (this.position !=== previous) positionAdjusted = true; + if (this.position !== previous) positionAdjusted = true; if (!positionAdjusted) { // there were no jumps in time, so this.position stayed if ((previous <= 0) && (next > 0) && (next <= this.duration) && !this.passedStart) { From 637c9ef602bf80b1bc7240b1e3ca5bd7596ea5c5 Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Wed, 16 Dec 2015 17:35:10 +0100 Subject: [PATCH 09/15] massive renamings in Timeline class, p.5 (.time -> .timeline, continue) --- src/anm/animation/timeline.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/anm/animation/timeline.js b/src/anm/animation/timeline.js index f0817b63..dfe19d7d 100644 --- a/src/anm/animation/timeline.js +++ b/src/anm/animation/timeline.js @@ -168,7 +168,7 @@ Timeline.prototype.getGlobalBand = function(parent) { var cursor = parent; var start = this.start; while (cursor) { - start += cursor.time.start; + start += cursor.timeline.start; cursor = cursor.parent || cursor.scene; } return [start, this.duration]; @@ -186,7 +186,7 @@ Timeline.prototype.getGlobalStart = function() { var cursor = this.owner; var start = 0; while (cursor) { - start += cursor.time ? cursor.time.start : 0; + start += cursor.timeline ? cursor.timeline.start : 0; cursor = cursor.parent || cursor.scene; } return start; @@ -227,10 +227,10 @@ Timeline.prototype.jumpAt = function(at, t) { }; Timeline.prototype.jumpTo = function(child) { - var start = child.time.start, + var start = child.timeline.start, cursor = child.parent; while (cursor && (cursor !== this.owner)) { - start += cursor.time.start; + start += cursor.timeline.start; cursor = cursor.parent; } this.jump(start); From a9d15820e79b8b67039b9f02b82be1fb1172e7c8 Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Wed, 16 Dec 2015 18:04:15 +0100 Subject: [PATCH 10/15] move all child-ticking from Element.render to Element.tick, p.2 --- src/anm/animation/element.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 62d34127..2d51bb8e 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -109,8 +109,9 @@ function Element(name, draw, onframe) { this.level = 0; /** @property {Number} level how deep this element is located in animation tree @readonly */ this.anim = null; /** @property {anm.Animation} anim the animation this element belongs to / registered in, if it really belongs to one @readonly */ this.scene = null; /** @property {anm.Scene} scene the scene this element belongs to / registered in, if it really belongs to one @readonly */ - this.disabled = false; /** @property {Boolean} visible Is this element visible or not (called, but not drawn) */ - this.visible = true; /** @property {Boolean} disabled Is this element disabled or not */ + this.active = true; /** @property {Boolean} active Is this element active or not (internal flag to control if this element is "alive") @readonly */ + this.disabled = false; /** @property {Boolean} disabled Is this element disabled or not (not transformed, not drawn) */ + this.visible = true; /** @property {Boolean} visible Is this element visible or not (transformed, but not drawn) */ this.affectsChildren = true; /** @property {Boolean} affectsChildren Is this element local time affects children local time */ this.$data = null; /** @property {Any} $data user data */ @@ -696,6 +697,7 @@ Element.prototype.invTransform = function(ctx) { }; Element.prototype.tick = function(dt) { + if (this.disabled) return; // TODO: check switcher var resultTime; if (!this.parent && this.scene && this.scene.affectsChildren) { @@ -705,9 +707,13 @@ Element.prototype.tick = function(dt) { } else { resultTime = this.timeline.tick(dt); } - this.each(function(child) { - child.tick(dt); - }); + var isActive = this.timeline.isActive() && this.modifiers(resultTime, dt); + if (isActive) { + this.each(function(child) { + child.tick(dt); + }); + } + this.active = isActive; return resultTime; }; @@ -738,25 +744,17 @@ Element.prototype._checkSwitcher = function(next) { */ // > Element.render % (ctx: Context, gtime: Float, dt: Float) Element.prototype.render = function(ctx) { - if (this.disabled) return; + if (this.disabled || !this.active) return; this.rendering = true; - var ltime = this.timeline.getLastPosition(), - dt = this.timeline.getLastDelta(); - var mask = this.$mask, // FIXME: mask could tick and render several times renderMasked = false, mask_ltime; if (mask) { mask_ltime = mask.tick(dt); }; // FIXME: move to element.tick - if (!Timeline.isKnownTime(ltime)) return; - - var drawMe = this.timeline.isActive() && - this.modifiers(ltime, dt) && - this.visible; // modifiers should be applied even if element isn't visible - if (drawMe) { + if (this.visible) { ctx.save(); if (mask) { @@ -830,7 +828,6 @@ Element.prototype.render = function(ctx) { this.transform(bctx); this.painters(bctx); this.each(function(child) { - child.tick(dt); child.render(bctx, dt); }); From 9675b2656d5034d5fd83da5d1ef34e25f0253eab Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Thu, 17 Dec 2015 15:00:20 +0100 Subject: [PATCH 11/15] refactor masking, p.1 --- src/anm/animation/element.js | 39 +++++++++++++------------------- src/anm/graphics/sheet.js | 2 -- src/import/animatron-importer.js | 7 +++--- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 2d51bb8e..68a08df2 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -110,8 +110,9 @@ function Element(name, draw, onframe) { this.anim = null; /** @property {anm.Animation} anim the animation this element belongs to / registered in, if it really belongs to one @readonly */ this.scene = null; /** @property {anm.Scene} scene the scene this element belongs to / registered in, if it really belongs to one @readonly */ this.active = true; /** @property {Boolean} active Is this element active or not (internal flag to control if this element is "alive") @readonly */ - this.disabled = false; /** @property {Boolean} disabled Is this element disabled or not (not transformed, not drawn) */ - this.visible = true; /** @property {Boolean} visible Is this element visible or not (transformed, but not drawn) */ + this.disabled = false; /** @property {Boolean} disabled Is this element disabled or not (if disabled—not transformed and not drawn) */ + this.visible = true; /** @property {Boolean} visible Is this element visible or not (if not—transformed, but not drawn) */ + this.isMask = false; /** @property {Boolean} isMask Is this element a mask, or not (if yes—transformed, but not drawn) */ this.affectsChildren = true; /** @property {Boolean} affectsChildren Is this element local time affects children local time */ this.$data = null; /** @property {Any} $data user data */ @@ -744,30 +745,14 @@ Element.prototype._checkSwitcher = function(next) { */ // > Element.render % (ctx: Context, gtime: Float, dt: Float) Element.prototype.render = function(ctx) { - if (this.disabled || !this.active) return; + if (this.disabled || !this.active || this.isMask) return; this.rendering = true; - var mask = this.$mask, // FIXME: mask could tick and render several times - renderMasked = false, - mask_ltime; - - if (mask) { mask_ltime = mask.tick(dt); }; // FIXME: move to element.tick - if (this.visible) { ctx.save(); - if (mask) { - // FIXME: move this chain completely into one method, or, - // which is even better, make all these checks to be modifiers - // FIXME: call modifiers once for one moment of time. If there are several - // masked elements, they will be called that number of times - renderMasked = mask.timeline.isActive() && - mask.modifiers(mask_ltime, dt) && - mask.visible; - } - - if (!renderMasked) { + if (!this.$mask) { // draw directly to context, if has no mask this.transform(ctx); this.painters(ctx); @@ -776,6 +761,7 @@ Element.prototype.render = function(ctx) { }); } else { // FIXME: the complete mask process should be a Painter. + var mask = this.$mask; mask.ensureHasMaskCanvas(); var mcvs = mask.__maskCvs, @@ -784,7 +770,7 @@ Element.prototype.render = function(ctx) { bctx = mask.__backCtx; // FIXME: test if bounds are not empty - var bounds_pts = mask.bounds(mask_ltime).toPoints(); + var bounds_pts = mask.bounds().toPoints(); var minX = Number.MAX_VALUE, minY = Number.MAX_VALUE, maxX = Number.MIN_VALUE, maxY = Number.MIN_VALUE; @@ -1976,6 +1962,8 @@ Element.prototype.invalidateVisuals = function() { * @return {Object} bounds */ Element.prototype.bounds = function(ltime) { + var ltime = is.defined(ltime) ? ltime : this.getTime(); + if (is.defined(this.lastBoundsSavedAt) && (t_cmp(this.lastBoundsSavedAt, ltime) == 0)) return this.$bounds; @@ -2153,7 +2141,7 @@ Element.prototype.applyAComp = function(ctx) { }; /** - * @method mask + * @method maskWith * * Mask this element with another element. Literally, using this method way you * may produce animated masks and use masks with children and mask any elements with @@ -2164,12 +2152,17 @@ Element.prototype.applyAComp = function(ctx) { * * @return {anm.Element} itself */ -Element.prototype.mask = function(elm) { +Element.prototype.maskWith = function(elm) { if (!elm) return this.$mask; this.$mask = elm; return this; }; +Element.prototype.markAsMask = function() { + this.isMask = true; + return this; +}; + /** * @method noMask * diff --git a/src/anm/graphics/sheet.js b/src/anm/graphics/sheet.js index c5186e13..9ef0d411 100644 --- a/src/anm/graphics/sheet.js +++ b/src/anm/graphics/sheet.js @@ -47,8 +47,6 @@ function Sheet(src, callback, start_region) { this._thumbnail = false; // internal flag, used to load a player thumbnail } -var https = engine.isHttps; - /** * @private @method load */ diff --git a/src/import/animatron-importer.js b/src/import/animatron-importer.js index 3916f329..132e32a2 100644 --- a/src/import/animatron-importer.js +++ b/src/import/animatron-importer.js @@ -323,10 +323,9 @@ Import.branch = function(type, src, parent_src, parent_band, all, anim) { layer_trg.time.setEndAction(Import.mode(null)); } - // if do not masks any layers, just add to target + // if do not masks any layers, store it as a potential mask target // if do masks, set it as a mask for them while not adding if (!layer_src[3]) { // !masked - trg.add(layer_trg); _layers_targets.push(layer_trg); } else { // layer is a mask, apply it to the required number @@ -334,6 +333,7 @@ Import.branch = function(type, src, parent_src, parent_band, all, anim) { var mask = layer_trg, togo = layer_src[3], // layers below to apply mask targets_n = _layers_targets.length; + layer_trg.markAsMask(); if (togo > targets_n) { _reportError('No layers collected to apply mask, expected ' + togo + ', got ' + targets_n); @@ -341,10 +341,11 @@ Import.branch = function(type, src, parent_src, parent_band, all, anim) { } while (togo) { var masked = _layers_targets[targets_n-togo]; - masked.mask(mask); + masked.maskWith(mask); togo--; } } + trg.add(layer_trg); Import.callCustom(layer_trg, layer_src, TYPE_LAYER); From a8d367072aa73d2be6d2f351e9e0e06e26345454 Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Thu, 17 Dec 2015 15:41:19 +0100 Subject: [PATCH 12/15] fix renaming errors --- src/anm/animation/scene.js | 4 ++-- src/anm/animation/timeline.js | 1 - src/anm/render.js | 2 +- src/import/animatron-importer.js | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/anm/animation/scene.js b/src/anm/animation/scene.js index fa690269..5fa7046a 100644 --- a/src/anm/animation/scene.js +++ b/src/anm/animation/scene.js @@ -180,12 +180,12 @@ Scene.prototype.jump = function(t) { }; Scene.prototype.jumpTo = function(elm) { - this.time.jumpTo(elm); + this.timeline.jumpTo(elm); return this; }; Scene.prototype.jumpToStart = function() { - this.time.jumpToStart(0); + this.timeline.jumpToStart(0); return this; }; diff --git a/src/anm/animation/timeline.js b/src/anm/animation/timeline.js index dfe19d7d..b39081ae 100644 --- a/src/anm/animation/timeline.js +++ b/src/anm/animation/timeline.js @@ -63,7 +63,6 @@ Timeline.prototype.tick = function(dt) { if (this.paused) { this.lastDelta = 0; return this.position; } var next = (this.position !== NO_TIME) ? (this.position + dt) : NO_TIME; - next = this._checkSwitcher(next); // FIXME: move to Element.checkSwitcher if (next !== NO_TIME) { diff --git a/src/anm/render.js b/src/anm/render.js index 582e4827..d9d517c1 100644 --- a/src/anm/render.js +++ b/src/anm/render.js @@ -32,7 +32,7 @@ function r_loop(ctx, player, anim, before, after, before_render, after_render) { } if (player.happens !== C.PLAYING) return; - var timeline = anim.time; + var timeline = anim.timeline; var msec = (Date.now() - player.__startTime); var sec = msec / 1000; diff --git a/src/import/animatron-importer.js b/src/import/animatron-importer.js index 132e32a2..e39bf19d 100644 --- a/src/import/animatron-importer.js +++ b/src/import/animatron-importer.js @@ -318,9 +318,9 @@ Import.branch = function(type, src, parent_src, parent_band, all, anim) { */ // transfer repetition data if (layer_src[5]) { - layer_trg.time.setEndAction(Import.mode(layer_src[5][0], layer_src[5][1])); + layer_trg.mode(Import.mode(layer_src[5][0], layer_src[5][1])); } else { - layer_trg.time.setEndAction(Import.mode(null)); + layer_trg.mode(Import.mode(null)); } // if do not masks any layers, store it as a potential mask target From b8c5743262872f9ae6be490c8f5f1a6dde901061 Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Thu, 17 Dec 2015 16:04:14 +0100 Subject: [PATCH 13/15] fix more renaming errors --- src/anm/animation/animation.js | 16 ++++++++-------- src/anm/animation/element.js | 10 ++++++---- src/anm/animation/scene.js | 8 ++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/anm/animation/animation.js b/src/anm/animation/animation.js index 36289fe0..7074db20 100644 --- a/src/anm/animation/animation.js +++ b/src/anm/animation/animation.js @@ -202,9 +202,9 @@ Animation.prototype.traverse = function(visitor, data) { * @param {Object} [data] */ Animation.prototype.traverseVisible = function(visitor, data) { - if (this.currentScene && this.currentScene.timeline.isActive()) { + if (this.currentScene && this.currentScene.isActive()) { this.currentScene.traverse(function(child) { - return (child.timeline.isActive() && (visitor(child, data) === false)) ? false : true; + return (child.isActive() && (visitor(child, data) === false)) ? false : true; }); } return this; @@ -317,9 +317,9 @@ Animation.prototype.render = function(ctx) { }; Animation.prototype.tick = function(dt) { - var curSceneTime = this.currentScene.timeline; - if ((curSceneTime.pos + dt) < curSceneTime.duration) { - this.currentScene.tick(dt); + var currentScene = this.currentScene; + if ((currentScene.getTime() + dt) < currentScene.getDuration()) { + currentScene.tick(dt); this.timeline.tick(dt); } else { this._changeToNextScene(dt); @@ -329,9 +329,9 @@ Animation.prototype.tick = function(dt) { Animation.prototype._changeToNextScene = function(dt) { var nextScene = (this.currentSceneIdx < this.scenes.length) ? this.scenes[this.currentSceneIdx + 1] : null; - var currentSceneTime = this.currentScene.timeline; - var left = (currentSceneTime.duration - currentSceneTime.pos); - this.currentScene.tick(left); + var currentScene = this.currentScene; + var left = (currentScene.getDuration() - currentScene.getTime()); + currentScene.tick(left); if (nextScene) { this.currentSceneIdx++; this.currentScene = nextScene; diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 68a08df2..4da58758 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -116,7 +116,6 @@ function Element(name, draw, onframe) { this.affectsChildren = true; /** @property {Boolean} affectsChildren Is this element local time affects children local time */ this.$data = null; /** @property {Any} $data user data */ - this.shown = false; // system flag, set by engine this.registered = false; // is registered in animation or not this.rendering = false; // in process of rendering or not @@ -837,8 +836,6 @@ Element.prototype.render = function(ctx) { } ctx.restore(); } - // immediately after being drawn, element is shown, it is reasonable - this.shown = drawMe; this.__postRender(); this.rendering = false; return this; @@ -1495,6 +1492,10 @@ Element.prototype.getDuration = function() { return this.timeline.getDuration(); }; +Element.prototype.isActive = function() { + return !this.disabled && this.visible && !this.isMask && this.timeline.isActive(); +}; + /** * @private @method m_on * @@ -2429,7 +2430,8 @@ Element.prototype.__adaptModTime = function(modifier, ltime) { Element.prototype.__pbefore = function(ctx, type) { }; Element.prototype.__pafter = function(ctx, type) { }; Element.prototype.filterEvent = function(type, evt) { - if (this.shown) this.__saveEvt(type, evt); + /*if (this.visible && this.active)*/ + this.__saveEvt(type, evt); return true; }; diff --git a/src/anm/animation/scene.js b/src/anm/animation/scene.js index 5fa7046a..1c24adbc 100644 --- a/src/anm/animation/scene.js +++ b/src/anm/animation/scene.js @@ -203,6 +203,14 @@ Scene.prototype.getTime = function() { return this.timeline.getLastPosition(); }; +Scene.prototype.getDuration = function() { + return this.timeline.getDuration(); +}; + +Scene.prototype.isActive = function() { + return this.timeline.isActive(); +}; + Scene.prototype.reset = function() { this.timeline.reset(); this.each(function(child) { From 097e08dcdc96a9e928cd64de26d78fe8d496efee Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Thu, 17 Dec 2015 16:56:48 +0100 Subject: [PATCH 14/15] element.mode duplicates element.repeat, removed the first one --- src/anm/animation/element.js | 4 ---- src/import/animatron-importer.js | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 4da58758..61ac5f9a 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -1084,10 +1084,6 @@ Element.prototype.bounce = function(nrep) { return this; }; -Element.prototype.mode = function(mode, nrep) { - this.timeline.setEndAction(mode, nrep); -}; - /** * @method jump * @chainable diff --git a/src/import/animatron-importer.js b/src/import/animatron-importer.js index e39bf19d..a96d6836 100644 --- a/src/import/animatron-importer.js +++ b/src/import/animatron-importer.js @@ -318,9 +318,9 @@ Import.branch = function(type, src, parent_src, parent_band, all, anim) { */ // transfer repetition data if (layer_src[5]) { - layer_trg.mode(Import.mode(layer_src[5][0], layer_src[5][1])); + layer_trg.repeat(Import.mode(layer_src[5][0], layer_src[5][1])); } else { - layer_trg.mode(Import.mode(null)); + layer_trg.repeat(Import.mode(null)); } // if do not masks any layers, store it as a potential mask target From b234f3c3a4fb24206b5f8f154466e724e5ec1465 Mon Sep 17 00:00:00 2001 From: Ulric Wilfred Date: Thu, 17 Dec 2015 17:10:57 +0100 Subject: [PATCH 15/15] avoid using direct calls to timeline methods even more --- src/anm/animation/animation.js | 4 ++-- src/anm/animation/element.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/anm/animation/animation.js b/src/anm/animation/animation.js index 7074db20..34052798 100644 --- a/src/anm/animation/animation.js +++ b/src/anm/animation/animation.js @@ -225,9 +225,9 @@ Animation.prototype.traverseVisible = function(visitor, data) { * @param {Object} [data] */ Animation.prototype.reverseTraverseVisible = function(visitor, data) { - if (this.currentScene && this.currentScene.timeline.isActive()) { + if (this.currentScene && this.currentScene.isActive()) { this.currentScene.reverseTraverse(function(child) { - return (child.timeline.isActive() && (visitor(child, data) === false)) ? false : true; + return (child.isActive() && (visitor(child, data) === false)) ? false : true; }); } return this; diff --git a/src/anm/animation/element.js b/src/anm/animation/element.js index 61ac5f9a..39b0f564 100644 --- a/src/anm/animation/element.js +++ b/src/anm/animation/element.js @@ -2340,7 +2340,7 @@ Element.prototype.__adaptModTime = function(modifier, ltime) { // TODO: move to Modifier class? var elm = this, - elm_duration = elm.timeline.getDuration(), // duration of the element's local band + elm_duration = elm.getDuration(), // duration of the element's local band mod_easing = modifier.$easing, // modifier easing mod_time = modifier.$band || modifier.$time, // time (or band) of the modifier, if set mod_relative = modifier.$relative, // is modifier time or band relative to elm duration or not