mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
refactor(overlays): use the globe engine
The world overlay host takes its frames (frames.postRender), camera events
(camera.moveEnd), canvas size (host.size), projection matrix
(projector.viewProjection), horizon test (projector.horizonVisible) and
render requests (render.request('world-overlay')) from the globe engine.
initWorldOverlay accepts an engine or, for callers that still hold a
viewer, resolves the viewer's engine through engineFromViewer.
Contract: camera.position(result) becomes camera.livePosition, one
engine-owned object holding the current position, so per-frame readers
and paint lanes keep a live camera position without allocating; engine
events gain raiseValue for argument-list-free frame dispatch. Steady-state
frame allocation is unchanged (worker probe, 30 chunks: 2696/9536/38593
B/frame before and after; detection 473749 -> 408085).
This commit is contained in:
1 parent
58a196374f
commit
aaa6074663
11 files changed
+284
-134
No files matched your search
+34
-11
@@ -83,9 +83,10 @@
|
||||
*
|
||||
* @typedef {object} GlobeCamera
|
||||
* @property {() => CameraPose} pose Fresh values on every call.
|
||||
* @property {(result?: Cartesian3) => Cartesian3} position The pose's world
|
||||
* position; fills and returns `result` when given (no allocation, for
|
||||
* per-frame readers), else a fresh value.
|
||||
* @property {Cartesian3} livePosition The pose's world position as one
|
||||
* engine-owned object: the same object on every read, holding the current
|
||||
* position (at the latest when read). For per-frame readers, which must not
|
||||
* allocate; read-only, copy it to keep a value.
|
||||
* @property {() => number} height The camera's height above the WGS84
|
||||
* ellipsoid (the pose's cartographic height), without building a pose.
|
||||
* @property {(view: { destination: Cartesian3 | Rectangle, orientation?: Orientation }) => void} setView
|
||||
@@ -209,9 +210,10 @@ export const isEngineEvent = (value) =>
|
||||
value != null && value[ENGINE_EVENT] === true;
|
||||
|
||||
/**
|
||||
* An event with the contract's semantics (see EngineEvent). `raiseEvent` is
|
||||
* for engine implementations; a listener that throws propagates, and the
|
||||
* event stays usable.
|
||||
* An event with the contract's semantics (see EngineEvent). `raiseEvent` and
|
||||
* `raiseValue` (one argument, no argument list: for per-frame events) are for
|
||||
* engine implementations; a listener that throws propagates, and the event
|
||||
* stays usable.
|
||||
*/
|
||||
export function createEngineEvent() {
|
||||
let entries = [];
|
||||
@@ -226,6 +228,13 @@ export function createEngineEvent() {
|
||||
else entries.splice(entries.indexOf(entry), 1);
|
||||
return true;
|
||||
};
|
||||
const settle = () => {
|
||||
depth--;
|
||||
if (!depth && removedDuringRaise) {
|
||||
entries = entries.filter((entry) => entry.listener);
|
||||
removedDuringRaise = false;
|
||||
}
|
||||
};
|
||||
const event = {
|
||||
get numberOfListeners() {
|
||||
return entries.reduce(
|
||||
@@ -259,11 +268,21 @@ export function createEngineEvent() {
|
||||
if (listener) listener(...args);
|
||||
}
|
||||
} finally {
|
||||
depth--;
|
||||
if (!depth && removedDuringRaise) {
|
||||
entries = entries.filter((entry) => entry.listener);
|
||||
removedDuringRaise = false;
|
||||
settle();
|
||||
}
|
||||
},
|
||||
// raiseEvent(value) without an argument list, for per-frame events.
|
||||
raiseValue(value) {
|
||||
const snapshot = entries;
|
||||
const length = snapshot.length;
|
||||
depth++;
|
||||
try {
|
||||
for (let index = 0; index < length; index++) {
|
||||
const listener = snapshot[index].listener;
|
||||
if (listener) listener(value);
|
||||
}
|
||||
} finally {
|
||||
settle();
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -282,7 +301,11 @@ const SHAPE = {
|
||||
host: { container: isObject, canvas: isObject, size: isFunction },
|
||||
camera: {
|
||||
pose: isFunction,
|
||||
position: isFunction,
|
||||
livePosition: (value) =>
|
||||
value != null &&
|
||||
isNumber(value.x) &&
|
||||
isNumber(value.y) &&
|
||||
isNumber(value.z),
|
||||
height: isFunction,
|
||||
setView: isFunction,
|
||||
flyTo: isFunction,
|
||||
|
||||
Reference in new issue
Block a user