Skip to content

Commit

Permalink
feat: gotoAnd同步运行wasm #262
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Feb 3, 2023
1 parent 380c82d commit 4184332
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 38 deletions.
28 changes: 7 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15635,6 +15635,7 @@
wasm.__wbg_set_animation_percent(this.ptr, arg0);
}
/**
* @param {number} node
* @param {number} direction
* @param {number} duration
* @param {number} fps
Expand Down Expand Up @@ -15742,8 +15743,8 @@
}
}, {
key: "new",
value: function _new(direction, duration, fps, delay, end_delay, fill, playback_rate, iterations, area_start, area_duration, easing) {
var ret = wasm.animation_new(direction, duration, fps, delay, end_delay, fill, playback_rate, iterations, area_start, area_duration, easing);
value: function _new(node, direction, duration, fps, delay, end_delay, fill, playback_rate, iterations, area_start, area_duration, easing) {
var ret = wasm.animation_new(node, direction, duration, fps, delay, end_delay, fill, playback_rate, iterations, area_start, area_duration, easing);
return Animation.__wrap(ret);
}
}]);
Expand Down Expand Up @@ -18263,7 +18264,7 @@
}
}

var wa = this.__wasmAnimation = wasm$1.Animation["new"](DIRECTION[this.__direction] || 0, this.__duration, this.__fps, this.__delay, this.__endDelay, FILLS[this.__fill] || 0, this.__playbackRate, iter, this.__areaStart, this.__areaDuration, easeType);
var wa = this.__wasmAnimation = wasm$1.Animation["new"](target.__wasmNode.ptr, DIRECTION[this.__direction] || 0, this.__duration, this.__fps, this.__delay, this.__endDelay, FILLS[this.__fill] || 0, this.__playbackRate, iter, this.__areaStart, this.__areaDuration, easeType);

if (easeType === EASING.EASE_CUSTOM) {
var v = ea.match(/[\d.]+/g);
Expand Down Expand Up @@ -18743,7 +18744,7 @@
var wasmChange = false;

if (wa) {
wasmChange = wa.goto_stop(v, dur);
wasmChange = wa.goto_stop(this.__currentTime, dur);
}

this.__calCurrent(this.__currentFrames, this.__currentFrame, v, dur, duration, {
Expand Down Expand Up @@ -18798,16 +18799,11 @@

this.__startTime = frame.__now = frame.__now || inject.now();
this.__playState = 'paused';
var wa = this.__wasmAnimation; // wasm的特殊标识,在root的before中统一遍历节点计算中需要知道

if (wa) {
wa.play_state = PLAY_STATE.PAUSED;
}

var wa = this.__wasmAnimation;
var wasmChange = false;

if (wa) {
wasmChange = wa.goto_stop(v, dur);
wasmChange = wa.goto_stop(this.__currentTime, dur);
}

this.__calCurrent(this.__currentFrames, this.__currentFrame, v, dur, duration, {
Expand All @@ -18823,7 +18819,6 @@
var duration = this.__duration;
var areaDuration = this.__areaDuration;
var dur = areaDuration ? Math.min(duration, areaDuration) : duration;
var wa = this.__wasmAnimation;

if (isNaN(v) || v < 0) {
throw new Error('Param of gotoAnd(Play/Stop) is illegal: ' + v);
Expand All @@ -18839,11 +18834,6 @@


this.__currentTime = v;

if (wa) {
wa.current_time = v;
}

v -= this.__delay - this.__areaStart;

if (v < 0) {
Expand All @@ -18855,10 +18845,6 @@
v -= dur * playCount;
this.__playCount = playCount;

if (wa) {
wa.play_count = playCount;
}

this.__initCurrentFrames(playCount);

return v;
Expand Down
2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions src/animate/Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ class Animation extends Event {
easeType = EASING.EASE_CUSTOM;
}
}
let wa = this.__wasmAnimation = wasm.Animation.new(DIRECTION[this.__direction] || 0, this.__duration, this.__fps,
let wa = this.__wasmAnimation = wasm.Animation.new(target.__wasmNode.ptr, DIRECTION[this.__direction] || 0, this.__duration, this.__fps,
this.__delay, this.__endDelay, FILLS[this.__fill] || 0, this.__playbackRate, iter,
this.__areaStart, this.__areaDuration, easeType);
if(easeType === EASING.EASE_CUSTOM) {
Expand Down Expand Up @@ -2030,7 +2030,7 @@ class Animation extends Event {
let wa = this.__wasmAnimation;
let wasmChange = false;
if(wa) {
wasmChange = wa.goto_stop(v, dur);
wasmChange = wa.goto_stop(this.__currentTime, dur);
}
this.__calCurrent(this.__currentFrames, this.__currentFrame, v, dur, duration, {
wasmChange,
Expand Down Expand Up @@ -2077,13 +2077,9 @@ class Animation extends Event {
this.__startTime = frame.__now = frame.__now || inject.now();
this.__playState = 'paused';
let wa = this.__wasmAnimation;
// wasm的特殊标识,在root的before中统一遍历节点计算中需要知道
if(wa) {
wa.play_state = PLAY_STATE.PAUSED;
}
let wasmChange = false;
if(wa) {
wasmChange = wa.goto_stop(v, dur);
wasmChange = wa.goto_stop(this.__currentTime, dur);
}
this.__calCurrent(this.__currentFrames, this.__currentFrame, v, dur, duration, {
wasmChange,
Expand All @@ -2097,7 +2093,6 @@ class Animation extends Event {
let duration = this.__duration;
let areaDuration = this.__areaDuration;
let dur = areaDuration ? Math.min(duration, areaDuration) : duration;
let wa = this.__wasmAnimation;
if(isNaN(v) || v < 0) {
throw new Error('Param of gotoAnd(Play/Stop) is illegal: ' + v);
}
Expand All @@ -2109,9 +2104,6 @@ class Animation extends Event {
}
// 在时间范围内设置好时间,复用play直接跳到播放点
this.__currentTime = v;
if(wa) {
wa.current_time = v;
}
v -= this.__delay - this.__areaStart;
if(v < 0) {
v = 0;
Expand All @@ -2120,9 +2112,6 @@ class Animation extends Event {
let playCount = Math.min(iterations - 1, Math.floor(v / dur));
v -= dur * playCount;
this.__playCount = playCount;
if(wa) {
wa.play_count = playCount;
}
this.__initCurrentFrames(playCount);
return v;
}
Expand Down
5 changes: 3 additions & 2 deletions src/wasm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export class Animation {
wasm.__wbg_set_animation_percent(this.ptr, arg0);
}
/**
* @param {number} node
* @param {number} direction
* @param {number} duration
* @param {number} fps
Expand All @@ -260,8 +261,8 @@ export class Animation {
* @param {number} easing
* @returns {Animation}
*/
static new(direction, duration, fps, delay, end_delay, fill, playback_rate, iterations, area_start, area_duration, easing) {
const ret = wasm.animation_new(direction, duration, fps, delay, end_delay, fill, playback_rate, iterations, area_start, area_duration, easing);
static new(node, direction, duration, fps, delay, end_delay, fill, playback_rate, iterations, area_start, area_duration, easing) {
const ret = wasm.animation_new(node, direction, duration, fps, delay, end_delay, fill, playback_rate, iterations, area_start, area_duration, easing);
return Animation.__wrap(ret);
}
/**
Expand Down

0 comments on commit 4184332

Please sign in to comment.