ded / morpheus

A Brilliant Animator
504 stars 57 forks source link

rework framing method with proper feature detect #37

Closed rvagg closed 11 years ago

rvagg commented 11 years ago

A.K.A. uber-feature-detect

Further to the discussion @ #36 (/cc @danro)

In summary I've turned frame(fn) into a function that takes a render-function and puts it into the animation queue (or makes a queue if required). The function is then called with 2 arguments, (1) is the time-delta from the start of the animation, and (2) a callback that can be used to resubmit the render-function to the same queue.

When first loaded, frame will be the most basic version that does setTimeout and delta-calculation itself; meanwhile it runs a feature-detect on a requestAnimationFrame to see what kind of argument it provides. The alternatives allowed for are (1) standard epoch-Date-based timestamp and (2) performance.now()-based timestamp. If it finds an rAF that works like this, it replaces frame with an appropriate rAF-based alternative.

This should be pretty future-proof as the fallback should always work. However there may be a need to enhance it in future. e.g. if Mozilla's animationStartTime gets traction or if other browsers start using performance.now()-based timestamps and vendor-prefix now (note though that that won't break this implementation, they'll just fall back to the basic implementation).

I've also imported Bonzo's .jshintrc and I've added a test to ensure that duration is roughly obeyed, this should help detect shortcutting.

rvagg commented 11 years ago

will close this for now, am happy with @danro's fix in #38 for the immediate problem, I'll see if I can find time to work on this one a bit more and improve it.

35 can be closed too.