Giter Site home page Giter Site logo

Comments (1)

aarthificial avatar aarthificial commented on May 18, 2024

switching to a x8 slowdown causes a recomputation that requires eight times as many frames to be computed.

There's no x8 slowdown, max is x4. But the recalculation that happens seems to be a leftover from before https://github.com/motion-canvas/core/issues/57
The goal of recalculation is to compute the new starting and ending frames which are currently independent of the speed. So I believe recalculation, in this case, could simply be omitted.

Currently, if the thread runner gets out of sync with the audio, the audio time is adjusted

That's not entirely true. If present, the audio serves as a master clock.
If the animation is ahead, it will wait until the next requestAnimationFrame:

// Do nothing if paused or is ahead of the audio.
else if (
state.paused ||
(state.speed === 1 &&
this.audio.isReady() &&
this.audio.isInRange(this.project.time) &&
this.audio.getTime() < this.project.time)
) {
this.request();
return;
}

If the animation is behind, it will try to catch on:

// Seek to synchronize animation with audio.
else if (
this.audio.isReady() &&
state.speed === 1 &&
this.audio.isInRange(this.project.time) &&
this.project.time < this.audio.getTime() - MAX_AUDIO_DESYNC
) {
const seekFrame = this.project.secondsToFrames(this.audio.getTime());
state.finished = await this.project.seek(seekFrame);
}

So the framerate is variable, but it's controlled by the requestAnimationFrame loop and not the project itself.
The audio is only adjusted if the speed is different than 1 for obvious reasons.

When it comes to seeking/recalculation optimization, I played around with this idea when working on https://github.com/motion-canvas/core/issues/57 since the implementation was already there. If you set the speed to a high number, say 10, you'll see the performance gains you're talking about. But the disadvantage you've mentioned was the reason I dropped it.

Personally, I wouldn't say that accessing a value during a tween is bad practice.
It would only be a problem if you were to use this value to modify the timing. Pass it to waitFor or something like that.
Otherwise, the worst it could do is to produce some visual artifacts/discrepancies which I think would be an acceptable trade-off.

Anyway, as you've mentioned in the note, let's leave this as a ripcord for now.

from motion-canvas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.