Screen helpers · class

FramePacer

Explained in Recording and clips.

class FramePacer
import { FramePacer } from '@driftengine/core';

Constructor

new

constructor(targetFps: number)
ParameterTypeDescription
targetFpsnumber

Properties

NameTypeDescription
targetFpsreadonlynumber

Accessors

NameTypeDescription
reportgetFramePacingReport

Methods

due

due(nowMs: number): boolean

Whether this animation frame is one the recording wants, without committing.

ParameterTypeDescription
nowMsnumber
More

The query half of offer, and it exists so a caller can decide before rendering whether the frame it is about to draw will be kept. A renderer that draws every animation frame and then discards most of them spends its whole budget competing with the frame it means to keep.

Called once per animation frame, before drawing. That is also where the loop's own interval is measured, since it is the only call that sees every frame: offer only sees the ones that were drawn.

Allocation-free: this is called from inside a render loop.

offer

offer(nowMs: number): boolean

Commit to the frame due was asked about.

ParameterTypeDescription
nowMsnumber
More

nowMs must be the instant due was given, not the instant the frame finished drawing. Both halves have to agree about when the frame is, or a frame is counted twice — once on the way in and once on the way out — and the loop's measured interval comes out at half its true value.

A caller with nothing to gate may pass whatever clock it has, as long as it is the same one every frame.

resetMeasurement

resetMeasurement(): void

Forget what has been measured, keep the schedule.

More

For a recording with a warm-up in front of it: the frames a device spends getting an encoder and a driver going are genuinely awful — measured at 411 ms and 503 ms for a 1080x1920 clip — and they are not what the clip is like. Left in the report they become the worst gap and a couple of slipped frames, which is the evidence an export decides whether to warn the player on.

The schedule survives on purpose: it was chosen from those same frames and it is still right.