Moving layers redraw as fast as they move on screen, 3 to 30 times a second

Satellites, flights and vessels held the render loop at the display's rate
while they were on, so a view of slow-moving marks drew 100-170 frames a
second. Each now reads how fast its fastest mark crosses the screen and asks
for a frame whenever that mark would move half a pixel: never fewer than 3 a
second (animated marks never stall), never more than 30 (room in the frame
for the rest of the scene). Below 12 a second the layer asks for one frame at
a time on a timer; from there it holds the loop at 15, 20 or 30, rates the
display divides evenly (renderPace.js).

The render governor takes a rate per hold: the highest asked wins, a hold
with no rate draws at the display's rate. Following a target is capped at
30. Steering the camera (a drag, a pinch, the wheel) still draws at the
display's rate; it ends when the last pointer lifts, the wheel rests, or the
page loses focus or is hidden.

Draw sets whose motion clock is the owner's ('frames: owner') ask for no
frames for moving rows or for rows written in place; the owner's pace does.
The vessels layer places its contacts at most 30 times a second and writes
every move of a pass to its icons in one batch.

Measured in Chrome on a still camera (draws a second, before -> after):
satellites over the whole globe 162 -> 6, at 1,500 km 114 -> 30; flights over
the whole globe 132 -> 10, Europe 53 -> 5, London 114 -> 9. Planes move at
most 0.6 px between draws.
This commit is contained in:
Sameh Khamis committed 2026-11-23 18:56:44 -08:00
1 parent 43bd25382d
commit d50f04efeb
30 files changed
+1262 -82

No files matched your search

+15 -1
View File
@@ -465,6 +465,8 @@ export function createAircraftIcons({
* @type {Map<string, {drawn: number, checked: number}>}
*/
const rotors = new Map();
/** When a rotor in view was last given a new frame (wall ms). */
let rotorDrawnAtMs = -Infinity;
/** The delayed instant (epoch ms) every untracked contact is drawn at. */
const _displayMs = () =>
@@ -492,7 +494,8 @@ export function createAircraftIcons({
const motionClock = (scene) =>
scene
? { kind: 'scene' }
: { kind: 'live', delayMs: displayDelay.currentMs };
: // The layer's pace asks for the frames its moving rows need.
{ kind: 'live', delayMs: displayDelay.currentMs, frames: 'owner' };
/**
* Once a frame: move the display delay on, and put the set's motion on
@@ -930,6 +933,7 @@ export function createAircraftIcons({
const query = viewer ? findQuery(viewer) : null;
const eye = viewer ? findCamera(viewer)?.pose()?.position : null;
let active = 0;
let fading = 0;
for (const id of icons.ids()) {
if (!icons.shown(id) && !state._models.has(id)) continue;
const item = icons.item(id);
@@ -952,10 +956,13 @@ export function createAircraftIcons({
spriteHalfHeightPx: item.size[1] * half,
});
if (focus.active || focus.transitioning) active++;
if (focus.transitioning) fading++;
if (focusAlphaNeedsWrite(current, focus.factor))
icons.setFocus(id, focus.factor);
}
state._iconFocusActive = active;
// Rows still fading in or out, for the layer's pace.
state._iconFocusFading = fading;
}
/**
@@ -1043,6 +1050,7 @@ export function createAircraftIcons({
if (!_aboveHorizon(position, occluder)) continue;
if (inView && !inView(position)) continue;
rotor.drawn = frame;
rotorDrawnAtMs = nowMs;
if (tracked) {
parts.tracking?._syncTrackedBillboardImage?.();
continue;
@@ -1106,6 +1114,11 @@ export function createAircraftIcons({
return rotors.size > 0;
}
/** When a rotor in view was last given a new frame (wall ms), for the pace. */
function _rotorDrawnAtMs() {
return rotorDrawnAtMs;
}
/** Add a row for a new contact, hidden while it is the tracked one. */
function _addIcon(icao24) {
state._icons.put(_baseItem(icao24, icao24 !== state._trackedIcao), {
@@ -1178,6 +1191,7 @@ export function createAircraftIcons({
_fleetLook,
_turnRotors,
_rotorsTurning,
_rotorDrawnAtMs,
_addIcon,
_forgetContact,
_iconIds,
+25 -5
View File
@@ -37,7 +37,11 @@ test('following the world clock, contacts draw at the world’s time on the scen
icons._createIcons(viewer);
const set = draw.find('flights-icons:');
// Live: a poll interval behind real time, on the delayed live clock.
assert.deepEqual(set.spec.motionClock, { kind: 'live', delayMs: 30_000 });
assert.deepEqual(set.spec.motionClock, {
kind: 'live',
delayMs: 30_000,
frames: 'owner',
});
assert.equal(icons._displayMs(), Date.now() - 30_000);
following = true;
assert.equal(icons._displayMs(), WORLD_MS, 'the world’s time, no delay');
@@ -45,7 +49,11 @@ test('following the world clock, contacts draw at the world’s time on the scen
assert.deepEqual(set.spec.motionClock, { kind: 'scene' });
following = false;
icons._syncMotionClock();
assert.deepEqual(set.spec.motionClock, { kind: 'live', delayMs: 30_000 });
assert.deepEqual(set.spec.motionClock, {
kind: 'live',
delayMs: 30_000,
frames: 'owner',
});
icons._disposeIcons();
});
@@ -68,7 +76,11 @@ test('as the display delay moves, the renderer’s live clock and the layer’s
});
icons._createIcons(viewer);
const set = draw.find('flights-icons:');
assert.deepEqual(set.spec.motionClock, { kind: 'live', delayMs: 30_000 });
assert.deepEqual(set.spec.motionClock, {
kind: 'live',
delayMs: 30_000,
frames: 'owner',
});
// Reports 90 s old every 30 s: the delay heads for about two minutes.
for (let i = 0; i < 20; i++)
delay.noteReport(WORLD_MS, WORLD_MS - 90_000, WORLD_MS - 120_000);
@@ -76,7 +88,11 @@ test('as the display delay moves, the renderer’s live clock and the layer’s
t.mock.timers.setTime(WORLD_MS + 10_000);
icons._syncMotionClock();
// 10 s at 0.2 s/s: 2 s more, on both the renderer's clock and the layer's.
assert.deepEqual(set.spec.motionClock, { kind: 'live', delayMs: 32_000 });
assert.deepEqual(set.spec.motionClock, {
kind: 'live',
delayMs: 32_000,
frames: 'owner',
});
assert.equal(icons._displayMs(), Date.now() - 32_000);
// Following the world clock: no delay, and it is not moved on meanwhile.
following = true;
@@ -87,7 +103,11 @@ test('as the display delay moves, the renderer’s live clock and the layer’s
assert.equal(delay.currentMs, 32_000);
following = false;
icons._syncMotionClock();
assert.deepEqual(set.spec.motionClock, { kind: 'live', delayMs: 34_000 });
assert.deepEqual(set.spec.motionClock, {
kind: 'live',
delayMs: 34_000,
frames: 'owner',
});
icons._disposeIcons();
});
+77
View File
@@ -14,6 +14,12 @@ import {
showModel,
} from './modelRecord.js';
import { modelDrawnScale } from './modelVisualAnchor.js';
import {
createRenderPace,
createScreenSpeed,
paceHzForSpeed,
} from '../renderPace.js';
import { ROTOR_FPS } from './rotorFrames.js';
import { fleetModelSet, fleetPartTable } from './fleetModels.js';
import { aircraftLayerPartState } from './modelPartDrivers.js';
import { findCamera, findDraw, rendererOf } from '../render/rendererOf.js';
@@ -119,6 +125,70 @@ export function createAircraftModels({
let instances = 0;
/** The fleet items this tick wrote, sent together when it ends. */
let pendingItems = [];
// The pace: how often the fleet is drawn while nothing else draws
// (renderPace.js). The icons move on the GPU, so a frame is all a move
// takes; an airliner crosses a hundredth of a pixel a second on the whole
// globe and hundreds from close by, so the rate follows the fastest icon
// in view.
const pace = createRenderPace({ owner: setPrefix, render: services.render });
const screenSpeed = createScreenSpeed();
/** How often the icons' on-screen speed is read, in ms. */
const PACE_READ_MS = 250;
/** Each icon's move is read over this much of its drawn path, in ms. */
const PACE_SPAN_MS = 1000;
/** While icons fade for a focus change, they are drawn this often. */
const PACE_FADE_HZ = 20;
/** A rotor drawn this recently is in view. */
const PACE_ROTOR_SEEN_MS = 600;
let paceReadMs = -Infinity;
let pacePxPerSec = 0;
/**
* The fastest icon in view's speed on screen, in pixels a second: each
* shown icon's drawn position now and PACE_SPAN_MS on, which takes in a
* new fix being blended in as well as its flight.
*/
function _readIconSpeed(pose) {
const icons = state._icons;
if (!icons || !screenSpeed.begin(pose, _viewport().height)) return 0;
const t = parts.icons._displayMs();
for (const id of icons.ids()) {
if (!icons.shown(id)) continue;
screenSpeed.add(
icons.position(id, t),
icons.position(id, t + PACE_SPAN_MS),
);
}
return screenSpeed.pxPerSec(PACE_SPAN_MS / 1000);
}
/**
* Draws a second the fleet needs as the camera stands (the pace clamps
* it to its range). Infinity: as often as the pace allows.
*/
function _paceHz(nowMs = Date.now()) {
const pose = _pose();
if (!pose?.position) return Infinity;
// Models, and the Cockpit's contacts, are moved on every frame.
if (
state._cockpitContactMode ||
state._models.size ||
_modelRegimeActive(pose)
)
return Infinity;
if (nowMs - paceReadMs >= PACE_READ_MS) {
paceReadMs = nowMs;
pacePxPerSec = _readIconSpeed(pose);
}
let hz = paceHzForSpeed(pacePxPerSec);
if (state._iconFocusFading > 0 && hz < PACE_FADE_HZ) hz = PACE_FADE_HZ;
// A helicopter in view turns its rotor ROTOR_FPS times a second.
const rotorAtMs = parts.icons._rotorDrawnAtMs?.() ?? -Infinity;
if (nowMs - rotorAtMs < PACE_ROTOR_SEEN_MS && hz < ROTOR_FPS)
hz = ROTOR_FPS;
return hz;
}
/** The ground sample's exclusions, kept while the sets they name live. */
let exclusions = null;
@@ -952,6 +1022,7 @@ export function createAircraftModels({
}
}
state._icons?.flush();
pace.set(_paceHz());
}
}
@@ -1136,5 +1207,11 @@ export function createAircraftModels({
_handBackDeselected,
_updateTrackedModel,
_fleetTick,
_paceHz,
_startPace: () => {
paceReadMs = -Infinity;
pace.start();
},
_stopPace: pace.stop,
};
}
+18 -14
View File
@@ -34,6 +34,7 @@ import { readLayerSource } from '../testSupport/readLayerSource.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { PACE_MIN_HZ } from '../renderPace.js';
import {
DETECTION_ENABLE_FADE_MS,
@@ -448,31 +449,34 @@ test('the render-governor gate covers the parked case, with teeth on the painter
// until some unrelated frame happens along.
//
// It cannot, and the reason is structural rather than lucky: an AIR bracket can
// only exist while an aircraft layer is enabled, and both aircraft layers take a
// continuous-render hold for their own per-frame fleet animation. So for exactly
// as long as there is anything to bracket, the scene is rendering every frame
// and the overlay repaints with it. (Measured live 2026-08-23 on a parked
// camera: an outside-aircraft population change moved the painted bracket count
// with no camera input, holds = ["flights"], requestRenderMode = false.)
// only exist while an aircraft layer is enabled, and both aircraft layers pace
// the render loop for their fleet (src/renderPace.js): never fewer than
// PACE_MIN_HZ frames a second however still the camera, more as the fleet
// moves faster on screen. So for exactly as long as there is anything to
// bracket, the scene keeps drawing and the overlay repaints with it, at most a
// third of a second behind. (Before the pace the layers held the loop on every
// frame; measured live 2026-08-23 on a parked camera, an outside-aircraft
// population change moved the painted bracket count with no camera input.)
//
// That is a COUPLING, so it deserves a pin. If a later perf pass strips these
// holds the way it stripped detection's — a reasonable-looking change — bracket
// That is a COUPLING, so it deserves a pin. If a later perf pass stops the
// aircraft layers pacing, or lets the pace's floor reach zero, bracket
// promptness goes with them, silently. This test is where that shows up.
test('aircraft brackets stay prompt because the aircraft layers hold the render loop', async () => {
test('aircraft brackets stay prompt because the aircraft layers pace the render loop', async () => {
assert.ok(PACE_MIN_HZ >= 3, 'a still scene still draws a few times a second');
for (const file of ['./flights.js', './militaryFlights.js']) {
const source = readLayerSource(new URL(file, import.meta.url));
const enable = /\n([ \t]*)enable\([\s\S]*?\n\1\},/.exec(source)?.[0];
assert.ok(enable, `${file}: enable() is still identifiable`);
assert.match(
enable,
/holdContinuousRender\('(flights|military)'\)/,
`${file}: enabling the layer must hold continuous render — detection no longer ` +
'holds one, so this is what keeps its AIR brackets repainting on a parked scene',
/parts\.rendering\._startPace\(\)/,
`${file}: enabling the layer must start its pace — detection no longer ` +
'holds the loop, so this is what keeps its AIR brackets repainting on a parked scene',
);
assert.match(
source,
/releaseContinuousRender\('(flights|military)'\)/,
`${file}: and the hold must be released, or the governor can never idle`,
/parts\.rendering\._stopPace\(\)/,
`${file}: and the pace must be stopped, or the governor can never idle`,
);
}
});