feat(globe): engine members and the viewer bridge for the shell

Contract: camera.position(result?) and camera.height() for per-frame
readers, render.request(reason?), maps.releasePhotorealTiles, sources
with a caller-owned ready provider, isGlobeEngine. engine.maps now hides
every tileset it has shown, lets the last imagery/photoreal call win, and
setPhotorealTiles(null) restores the last base imagery and its credit
instead of leaving the photoreal credit on a bare globe.

Cesium engine: reads the Viewer camera/canvas aliases, detaches bridged
events through the remover Cesium returns, raises frame timestamps
without allocating, re-aims the horizon occluder only when the camera
moved, and renders the scene directly when the governor governs another
viewer (or none yet). engineFromViewer returns the registered scene
engine of a viewer, else builds and caches one. The render governor stays
the Cesium render backend under engine.render and gains
isRenderGovernorInstalled.
This commit is contained in:
German Khokhlov committed 2026-10-15 18:18:19 +04:00
1 parent a5c98c6b07
commit 58a196374f
26 files changed
+657 -45

No files matched your search

+21 -11
View File
@@ -6,23 +6,33 @@
import { createEngineEvent } from '../contract.js';
/**
* @param {{ addEventListener: Function, removeEventListener: Function }} source A Cesium.Event.
* @param {(...args: any[]) => any[]} [mapArgs] Cesium arguments → contract arguments.
* @param {{ addEventListener: (listener: Function) => () => void }} source A
* Cesium.Event (its addEventListener returns the remover the bridge uses).
* @param {((...args: any[]) => any[]) | null} [mapArgs] Cesium arguments →
* contract arguments.
* @param {{ unary?: (...args: any[]) => any }} [options] `unary` maps the
* Cesium arguments to the one contract argument without building an
* argument list (for per-frame events).
* @returns {{ event: import('../contract.js').EngineEvent, detach: () => void }}
*/
export function bridgeEvent(source, mapArgs) {
export function bridgeEvent(source, mapArgs, { unary } = {}) {
const event = createEngineEvent();
const forward = mapArgs
? (...args) => event.raiseEvent(...mapArgs(...args))
: (...args) => event.raiseEvent(...args);
let attached = false;
const forward = unary
? (a, b, c) => event.raiseEvent(unary(a, b, c))
: mapArgs
? (...args) => event.raiseEvent(...mapArgs(...args))
: (...args) => event.raiseEvent(...args);
let removeForward = null;
let detached = false;
const sync = () => {
const wanted = !detached && event.numberOfListeners > 0;
if (wanted === attached) return;
attached = wanted;
if (wanted) source.addEventListener(forward);
else source.removeEventListener(forward);
if (wanted === (removeForward !== null)) return;
if (wanted) removeForward = source.addEventListener(forward);
else {
const remove = removeForward;
removeForward = null;
remove();
}
};
const add = event.addEventListener;
const remove = event.removeEventListener;