Gesso.Time
- Package
- purescript-gesso
- Repository
- smilack/purescript-gesso
Timestamps, time deltas, intervals, and requestAnimationFrame
#Delta Source
type Delta = { delta :: Number, last :: Number, now :: Number }
A current time, a previous time, and the difference between them. All values are in milliseconds.
For per-frame updates and the rendering function, last
is the time of the
previous animation frame and now
is the time of the current animation
frame.
For fixed-rate updates, last
is the scheduled time of the previous
fixed-rate update and now
is the update's scheduled time.
For interaction events and Halogen queries, last
is the time of the
previous animation frame and now
is the event's arrival time.
#Now Source
newtype Now
The current time in milliseconds, or the time at which a value became
Stamped
.
#RequestAnimationFrameId Source
newtype RequestAnimationFrameId
A RequestAnimationFrameId
is returned when calling
requestAnimationFrame
. This can be used to cancel the request.
#Stamped Source
type Stamped a = { item :: a, time :: Number }
An item and a specific time associated with that item. Used for comparing
timestamped values produced by stamp
and
stampInterval
.
#StampedBatch Source
type StampedBatch a = { items :: List (Stamped a), last :: Last }
Results of repeatedly timestamping a function at certain interval:
last
: the timestamp of the latest item in the listitems
: a list of repeated applications ofDelta
s to the function, with timestamps
#cancelAnimationFrame Source
cancelAnimationFrame :: RequestAnimationFrameId -> Window -> Effect Unit
Cancel a request for an animation frame using the RequestAnimationFrameId
returned by requestAnimationFrame
.
#requestAnimationFrame Source
requestAnimationFrame :: (Now -> Effect Unit) -> Window -> Effect RequestAnimationFrameId
An interface to window.requestAnimationFrame
which passes the timestamp
argument to the callback function.
Provided because requestAnimationFrame
in Web.HTML.Window
only accepts
an Effect Unit
instead of a Number -> Effect Unit
.
#stamp Source
stamp :: forall a. Last -> (Delta -> a) -> Effect (Stamped a)
For a last
timestamp and a function f :: Delta -> a
(such as
Gesso.Application.Behavior.UpdateFunction
, create a
Delta
between last
and the current time, apply the delta to f
, and
return a record containing the current time and the result of f delta
.
#stampInterval Source
stampInterval :: forall a. Last -> (Delta -> a) -> Interval -> Effect (StampedBatch a)
Repeatedly timestamp a function at a given interval, starting at the last
time plus the interval, as long as the timestamp does not pass the current
time.
The last
value in the returned record should be saved by the caller to
pass in as the last
argument for the next call to stampInterval
.
#toRatio Source
toRatio :: Last -> Interval -> Now -> Number
Convert the span between two periods of time to a unitless number of
intervals, typically between 0.0
and 1.0
. The result is used with
linear interpolation to find a weighted average between two values.
For a Never
interval, returns 1
, signalling to use the newer value and
ignore the older.