feat(globe): implement the engine on Cesium

createCesiumEngine wraps an existing viewer without changing it: camera, picker, projector, frames, render (through the render governor), surface, input, credits and maps, with geo values out and Cesium values in at the boundary. Map and surface code is shared with src/maps and services/groundSnap instead of copied. scripts/qa-globe-contract.mjs runs the contract suite against the engine in headless Chrome; the camera-events check now waits for the previous move to end, as Cesium's moveStart marks a move from rest.
This commit is contained in:
German Khokhlov committed 2026-10-15 17:43:05 +04:00
1 parent cd94a26b9f
commit d831cbd23a
33 files changed
+2374 -32

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
// Contract events in front of Cesium events. The Cesium subscription exists
// only while the contract event has listeners, so creating the engine adds
// nothing to the scene (Cesium does per-frame work for camera.changed only
// while someone listens).
import { createEngineEvent } from '../contract.js';
/**
* @param {{ addEventListener: Function, removeEventListener: Function }} source A Cesium.Event.
* @param {(...args: any[]) => any[]} [mapArgs] Cesium arguments → contract arguments.
* @returns {{ event: import('../contract.js').EngineEvent, detach: () => void }}
*/
export function bridgeEvent(source, mapArgs) {
const event = createEngineEvent();
const forward = mapArgs
? (...args) => event.raiseEvent(...mapArgs(...args))
: (...args) => event.raiseEvent(...args);
let attached = false;
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);
};
const add = event.addEventListener;
const remove = event.removeEventListener;
event.addEventListener = (listener) => {
const removeListener = add(listener);
sync();
return () => {
removeListener();
sync();
};
};
event.removeEventListener = (listener) => {
const removed = remove(listener);
sync();
return removed;
};
return {
event,
detach() {
detached = true;
sync();
},
};
}