mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
The embed view, the celestial-ring focus, the ground-guard lift, the Bhote Koshi approach and orbit, launch selection and replay flights, and the cockpit's view and takeover now drive the renderer's camera port. The contract gains a sineInOut easing, pinned by a conformance trace. A viewer with no renderer bound, such as one a caller of a public export brings, now gets a camera port too, as it already got an input port: cameraOf builds one over the viewer's own Cesium camera and keeps it for the viewer's life, until a renderer is bound. The Cesium adapter provides the factory as it loads; code that reaches Cesium takes cameraOf from the adapter so the factory comes with it, and findCamera answers null where a missing camera is not an error (HUD, share link, world focus, Recent Imagery's ZOOM IN). A test walks every package export and fails one that can reach the bridge without loading the factory. A destroyed viewer gets no camera and lets go of a built one, and the application renderer stays bound until its viewer is destroyed.
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
/**
|
|
* @module render/cesium/common
|
|
* @description What the Cesium ports share: the contract's listener rules
|
|
* and its positions as Cesium's.
|
|
*/
|
|
import * as Cesium from 'cesium';
|
|
|
|
/**
|
|
* One subscription list under the contract's listener rules: subscription
|
|
* order, one removed during delivery does not run, one added during
|
|
* delivery waits for the next event, and a throw goes to `onThrow` while
|
|
* the rest still run. Each subscription is its own entry, so a callback
|
|
* subscribed twice runs twice.
|
|
* @param {(error: unknown) => void} onThrow
|
|
*/
|
|
export function listenerList(onThrow) {
|
|
const entries = [];
|
|
return {
|
|
get size() {
|
|
return entries.length;
|
|
},
|
|
on(cb) {
|
|
const entry = { cb, live: true };
|
|
entries.push(entry);
|
|
return () => {
|
|
entry.live = false;
|
|
const i = entries.indexOf(entry);
|
|
if (i >= 0) entries.splice(i, 1);
|
|
};
|
|
},
|
|
fire(...args) {
|
|
for (const entry of entries.slice()) {
|
|
if (!entry.live) continue;
|
|
try {
|
|
entry.cb(...args);
|
|
} catch (error) {
|
|
onThrow(error);
|
|
}
|
|
}
|
|
},
|
|
clear() {
|
|
for (const entry of entries) entry.live = false;
|
|
entries.length = 0;
|
|
},
|
|
};
|
|
}
|
|
|
|
/** A contract position as ECEF. */
|
|
export function toCartesian(pos) {
|
|
if ('x' in pos) return new Cesium.Cartesian3(pos.x, pos.y, pos.z);
|
|
return Cesium.Cartesian3.fromDegrees(pos.lon, pos.lat, pos.height ?? 0);
|
|
}
|
|
|
|
/**
|
|
* Where a listener's throw goes with no `error` listener: the platform's
|
|
* `reportError` (or a rethrow on a microtask), as a browser reports an event
|
|
* listener's exception, loud, while the frame and the other listeners carry
|
|
* on.
|
|
*/
|
|
export function uncaught(error) {
|
|
if (typeof globalThis.reportError === 'function')
|
|
globalThis.reportError(error);
|
|
else
|
|
queueMicrotask(() => {
|
|
throw error;
|
|
});
|
|
}
|