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:
German Khokhlov committed 2026-10-15 18:32:40 +04:00
1 parent 58a196374f
commit aaa6074663
11 files changed
+284 -134

No files matched your search

+3 -7
View File
@@ -111,13 +111,9 @@ export function createCesiumCamera(viewer) {
fovy: cesium.frustum.fovy,
};
},
position(result) {
const { x, y, z } = cesium.positionWC;
if (!result) return geo.cartesian3.create(x, y, z);
result.x = x;
result.y = y;
result.z = z;
return result;
// Cesium updates positionWC in place; it is the live object.
get livePosition() {
return cesium.positionWC;
},
height: () => cesium.positionCartographic.height,
setView(view) {
+3 -9
View File
@@ -347,16 +347,10 @@ test('rectangle destinations become a Cesium.Rectangle in flyTo and setView', ()
}
});
test('position fills a result from positionWC and height reads the camera cartographic', () => {
test('livePosition is the Cesium camera positionWC and height reads its cartographic', () => {
const { camera, cesium } = setup();
cesium.positionCartographic = new Cesium.Cartographic(0.1, 0.2, 1234.5);
const result = geo.cartesian3.create();
assert.equal(camera.position(result), result);
assert.deepEqual({ ...result }, { x: 7e6, y: 1e5, z: 2e5 });
const fresh = camera.position();
notCesium(fresh, 'position()');
assert.notEqual(fresh, cesium.positionWC);
assert.deepEqual({ ...fresh }, { x: 7e6, y: 1e5, z: 2e5 });
assert.equal(camera.livePosition, cesium.positionWC);
assert.equal(camera.height(), 1234.5);
});
@@ -364,5 +358,5 @@ test('the camera is the viewer camera (Viewer.camera is scene.camera)', () => {
const viewer = createFakeViewer();
const own = { ...viewer.camera, positionWC: new Cesium.Cartesian3(1, 2, 3) };
const { camera } = createCesiumCamera({ ...viewer, camera: own });
assert.deepEqual({ ...camera.position() }, { x: 1, y: 2, z: 3 });
assert.equal(camera.livePosition, own.positionWC);
});
+1 -1
View File
@@ -18,7 +18,7 @@ import { createEngineEvent } from '../contract.js';
export function bridgeEvent(source, mapArgs, { unary } = {}) {
const event = createEngineEvent();
const forward = unary
? (a, b, c) => event.raiseEvent(unary(a, b, c))
? (a, b, c) => event.raiseValue(unary(a, b, c))
: mapArgs
? (...args) => event.raiseEvent(...mapArgs(...args))
: (...args) => event.raiseEvent(...args);