SodiumFRP / sodium-typescript

Typescript/Javascript implementation of Sodium FRP (Functional Reactive Programming) library
126 stars 17 forks source link

Timers and requestAnimationFrame #49

Open dakom opened 6 years ago

dakom commented 6 years ago

The typescript code includes a couple timers for Seconds and Millisecond alarms.

Small question about those - can we switch to performance.now() instead of Date.now() ?

On a bigger topic - animation on the web is typically driven by the timestamp passed to requestAnimationFrame callbacks. I'm not sure about the exact implementation details, but calculating deltatime from that timestamp results in smoother animation than calculating it from a new performance.now() snapshot when the callback is run.

Can we add a TimerSystem implementation based around requestAnimationFrame and the timestamp that gets passed to it? How does this gel with Sodium's approach to time in general?

clinuxrulz commented 5 years ago

I've just noticed this library exposes TimerSystemImpl which allows users use their own timer for the TimerSystem. (The TimerSystemImpl gets passed to the TimerSystems constructor).

This would allow you to use requestAnimationFrame and performance.now.