Files
gods-eye-view/src/globe/navara/windFlow.js
T
German Khokhlov 52c6f68bd5 Enforce engine SDK boundaries and rehearse every layer display
Restrict runtime SDK imports to their engine directories, including package
subpaths, re-exports and dynamic imports. Keep three measured, reasoned
exceptions for the Bhote Koshi property-record models and reject stale
exceptions. Move the Cesium annotation renderers and both wind adapters to
their engine folders, preserving their implementations and lazy loading.

Load all 35 manifest display entries on a fake engine with an unknown kind
and no native extensions. Draw small fixtures and verify resource and
subscription cleanup before destroying the engine. Name the three entries
without display factories as skips. Update the architecture, infrastructure
lifecycle and engine integration documentation to describe the code today.

Cesium behavior is unchanged, and Navara keeps its existing behavior. The
weather comparison harness supplies the Navara flow-mesh factory and accepts
the previous backend location for comparison runs. No user-visible strings
change.

Cesium layer-renderer lines fall from 14 to 0, Navara layer-renderer lines
from 314 to 189, outside-engine Cesium import files from 5 to 3, viewer lines
from 933 to 910, extension reads from 4 to 3, and engine-name lines from 36
to 33. No coupling count grows. Targeted checks pass: 845 tests, three named
rehearsal skips. Import directions, package boundaries, formatting and syntax
checks pass.

Checked in the browser, keyless: the contract suite passes on Navara and on
Cesium apart from the camera-events check that also fails intermittently
before; Navara annotations pass across engine switches; the ground-look
comparison is pixel-identical. qa-draw-tool's hidden-line check and the wind
engine switch fail the same way before this change.
2026-11-07 16:06:43 +04:00

125 lines
3.5 KiB
JavaScript

import {
bakeWindStreamlines,
WIND_DISPLAY_HEIGHT_METERS,
WIND_NARROW_PATH_LIMIT,
WIND_PATH_LIMIT,
} from '../../layers/wind/streamlines.js';
import { sameWind } from '../../layers/wind/model.js';
const clamp = (n) => Math.max(0, Math.min(1, n));
/**
* The wind's streamlines on Navara (the display's flow backend,
* render/display.js): baked paths as one flow mesh in Navara's view, faded
* in with the camera's height and moved by the page clock while the scene
* is shown and motion is allowed. The colour field is the display's.
*/
export function createWindNavaraFlow(engine, native, createWindFlowMesh) {
const canvas = engine.host.canvas,
media = matchMedia('(prefers-reduced-motion: reduce)');
let snapshot = null,
field = null,
mesh = null,
removeFrame = null,
lastTime = null,
seconds = 0,
paths = 0,
fade = 0,
budget = 0;
let running = false,
paused = false;
const wake = () => engine.render.request('wind');
const limit = () =>
canvas.clientWidth < 700 ? WIND_NARROW_PATH_LIMIT : WIND_PATH_LIMIT;
const build = () => {
mesh?.destroy();
mesh = null;
budget = limit();
const baked = bakeWindStreamlines(field, { count: budget });
paths = baked.length;
if (paths)
mesh = createWindFlowMesh(native, baked, WIND_DISPLAY_HEIGHT_METERS);
};
const frame = () => {
if (!running || document.hidden) {
lastTime = null;
return;
}
const h = engine.camera.pose().cartographic.height;
if (field && budget !== limit()) build();
fade = clamp((h - 15000) / 45000);
const still = paused || media.matches;
const now = performance.now();
if (!still && fade && lastTime != null)
seconds += Math.min(0.1, (now - lastTime) / 1000);
lastTime = !still && fade ? now : null;
mesh?.update({
time: seconds % 10000,
fade,
still,
width: canvas.clientWidth,
height: canvas.clientHeight,
});
if (mesh && !still && fade) wake();
};
const reset = () => {
mesh?.destroy();
mesh = null;
field = snapshot = null;
paths = 0;
lastTime = null;
};
const preferenceChanged = () => {
lastTime = null;
wake();
};
return {
attach() {
removeFrame = engine.frames.preRender.addEventListener(frame);
media.addEventListener('change', preferenceChanged);
document.addEventListener('visibilitychange', preferenceChanged);
},
/** A wind snapshot; its paths are baked again when its vectors changed. */
setField(next) {
const nextField = { ...next.grid, u: next.u, v: next.v };
const changed = !sameWind(snapshot, next, field, nextField);
snapshot = next;
field = nextField;
if (changed || !mesh) build();
wake();
},
setOptions(next) {
paused = next.paused;
wake();
},
start() {
running = true;
wake();
},
stop() {
running = false;
lastTime = null;
},
clear: reset,
destroy() {
running = false;
removeFrame?.();
media.removeEventListener('change', preferenceChanged);
document.removeEventListener('visibilitychange', preferenceChanged);
reset();
},
getParticleCount: () => paths,
getDiagnostics: () => ({
renderMode: 'gpu-streamlines',
reducedMotion: media.matches,
gpu: {
pathCount: paths,
phaseSeconds: seconds,
ready: Boolean(mesh),
heightFade: fade,
vertexCount: (mesh?.segments ?? 0) * 4,
},
}),
};
}