Renderer · interface

GovernorLimits

Hold a frame budget by moving the drawing-buffer scale, and nothing else.

Explained in Hello world.

interface GovernorLimits
import type { GovernorLimits } from '@driftengine/core';

In depth

This is the safety net the GPU-budget design asks for, and the reason it is worth having is that it works on hardware nobody here owns — including hardware that does not exist yet. One of the three players whose reports started that design found the cure by hand: they shrank the browser window until the game was smooth. This does the same thing without asking anyone to.

Pure by design: no GL, no DOM, no clock. Frame times come in, a new scale comes out, and the caller decides what to do with it. That is what makes it testable at all, because every device it exists for is one no test machine has.

Asymmetric on purpose. Dropping is fast, because a player at 6 fps needs relief now. Raising is slow and waits behind several consecutive good windows, because a resolution that oscillates is more visible than one that is slightly too low.

Properties

NameTypeDescription
budgetMsreadonlynumberThe frame time a frame is allowed, in milliseconds. Longer than this is a long frame.
More

40 rather than 16.67, and that gap is the tolerance. This is not a governor for squeezing a machine from 55 fps to 60: it exists for the parts that render at 4 to 9 fps, and a trigger anywhere near the vsync interval would spend its life reacting to jitter on machines that are entirely fine. It is LONG_FRAME_MS from the consuming game's own frame health, deliberately, because that number has already been tuned against real false positives.

badSharereadonlynumberShare of a window's frames that must be long before the window counts as bad.
More

This is the guard that makes a busy high-end machine safe. One hitch in sixty frames is a 1.7% share and decides nothing; a garbage collection, a shader compile, a texture upload or another application grabbing the GPU all look like that. Half the window being long is not a hitch, it is the machine.

minScalereadonlynumberNever go below this. A soft picture beats a slideshow.
windowFramesreadonlynumberFrames per decision. One slow frame is noise; a window of them is evidence.
badWindowsreadonlynumberConsecutive bad windows before the scale actually moves.
More

The second half of the tolerance, and the same reasoning SLOW_WINDOWS carries in the game: one bad window is a level load, a world build, a tab that just came back. Two in a row is a machine, because none of those things happen twice in a row.

dropStepreadonlynumberHow far to drop in one decision.
raiseStepreadonlynumberHow far to raise in one decision. Deliberately smaller than dropStep.
raisePatiencereadonlynumberConsecutive clean windows required before raising at all.