animclock

package
v0.2.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package animclock is the animation scheduler the application loop drives: launched pieces, the frame deadlines the loop wakes on, and the tick that advances them. The public timeline API lives in package anim; only the loop and tests reach this package.

Index

Constants

View Source
const FallbackInterval = time.Second / 4

FallbackInterval is the period a running piece ticks at while a surface waits on a frame callback, or no surface can show it: the callback paces it when the compositor answers, and an occluded window's animations still land.

View Source
const FrameInterval = time.Second / 60

FrameInterval is the period the timer paces a running piece at while no surface waits on a frame callback.

Variables

This section is empty.

Functions

func Active

func Active() bool

Active reports whether any piece is still running or scheduled.

func Drive

func Drive(fn func(now time.Time) bool) (cancel func())

Drive runs fn once per frame with the frame's instant until it reports false (settled) or the returned cancel runs.

func Due added in v0.2.5

func Due(now time.Time, pace Pace) bool

Due reports whether the clock's deadline at pace has come by now, so a pass that was not woken by a frame callback ticks it; a pass woken by anything else leaves running pieces where they are.

func Launch

func Launch(pieces []Piece) (cancel func())

Launch schedules pieces from the current instant and returns the cancel that stops every piece not yet finished. A piece with no duration and no offset lands at once, outside the schedule.

func Next

func Next(pace Pace) (time.Time, bool)

Next returns the earliest instant the loop must wake to keep the clock running at pace: one interval past the last tick while a piece is mid-flight, or a later piece's start while a timeline holds in a delay. At Timer a piece's end counts too, so its last frame lands on time. False means nothing runs and the loop may park.

func Now

func Now() time.Time

Now is the scheduler's current instant: the pinned one under SetClock.

func Reset

func Reset()

Reset drops every scheduled piece and driver.

func SetClock

func SetClock(fn func() time.Time) (restore func())

SetClock replaces the time source launches and deadlines read and returns the restore function; nil restores time.Now.

func Tick

func Tick(now time.Time) bool

Tick advances every running piece to now and drops finished or cancelled ones. Time never runs back: a now older than the last tick, or than the last launch (a compositor timestamp lags the local clock), counts as that instant. Callbacks run after the pass settles with the lock released, so they may launch or cancel freely; a callback cancelling its own timeline still stops that timeline's later pieces in the same tick. It reports whether any callback ran.

Types

type FrameClock added in v0.2.5

type FrameClock struct {
	// contains filtered or unexported fields
}

FrameClock converts a frame callback's timestamp, milliseconds from an undefined base that wraps, to an instant on the local clock.

func (*FrameClock) Instant added in v0.2.5

func (c *FrameClock) Instant(ms uint32, now time.Time) time.Time

Instant is when the compositor's ms happened on the local clock, never after now. It keeps the earliest local reading of the compositor's clock as its anchor, so a delivery's latency is what it subtracts, and starts again from now when ms sits further behind than any delivery plausibly does.

type Pace added in v0.2.5

type Pace uint8

Pace says what paces the clock.

const (
	// Timer paces the clock at FrameInterval: a surface could draw now.
	Timer Pace = iota
	// Fallback leaves pacing to frame callbacks, with FallbackInterval
	// under them: every surface that could draw waits on one.
	Fallback
)

type Piece

type Piece struct {
	At, Dur time.Duration
	Fn      func(t float64)
	Easing  func(t float64) float64
}

Piece is one flattened step of a timeline: fn runs with Easing of linear progress over [At, At+Dur) from the launch instant.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL