mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
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:
1 parent
cd94a26b9f
commit
d831cbd23a
33 files changed
+2374
-32
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { isEngineEvent } from '../contract.js';
|
||||
import { bridgeEvent } from './events.js';
|
||||
|
||||
test('a bridged event is a contract event that subscribes to Cesium lazily', () => {
|
||||
const source = new Cesium.Event();
|
||||
const { event, detach } = bridgeEvent(source);
|
||||
assert.ok(isEngineEvent(event));
|
||||
assert.equal(source.numberOfListeners, 0, 'creation must not subscribe');
|
||||
const seen = [];
|
||||
const remove = event.addEventListener((value) => seen.push(value));
|
||||
assert.equal(source.numberOfListeners, 1);
|
||||
source.raiseEvent(0.25);
|
||||
assert.deepEqual(seen, [0.25]);
|
||||
remove();
|
||||
assert.equal(source.numberOfListeners, 0, 'last removal unsubscribes');
|
||||
source.raiseEvent(0.5);
|
||||
assert.deepEqual(seen, [0.25]);
|
||||
detach();
|
||||
});
|
||||
|
||||
test('a bridged event maps Cesium arguments and keeps contract semantics', () => {
|
||||
const source = new Cesium.Event();
|
||||
const { event } = bridgeEvent(source, (scene, time) => [time * 2]);
|
||||
const seen = [];
|
||||
const listener = (value) => seen.push(value);
|
||||
event.addEventListener(listener);
|
||||
event.addEventListener(listener);
|
||||
assert.equal(source.numberOfListeners, 1);
|
||||
source.raiseEvent({}, 3);
|
||||
assert.deepEqual(seen, [6], 'a listener added twice fires once');
|
||||
assert.equal(event.removeEventListener(listener), true);
|
||||
assert.equal(source.numberOfListeners, 0);
|
||||
assert.equal(event.removeEventListener(listener), false);
|
||||
});
|
||||
|
||||
test('a listener removed during dispatch unsubscribes after the dispatch', () => {
|
||||
const source = new Cesium.Event();
|
||||
const { event } = bridgeEvent(source);
|
||||
let calls = 0;
|
||||
const once = () => {
|
||||
calls++;
|
||||
event.removeEventListener(once);
|
||||
};
|
||||
event.addEventListener(once);
|
||||
source.raiseEvent();
|
||||
source.raiseEvent();
|
||||
assert.equal(calls, 1);
|
||||
assert.equal(source.numberOfListeners, 0);
|
||||
});
|
||||
|
||||
test('detach drops the Cesium subscription for good', () => {
|
||||
const source = new Cesium.Event();
|
||||
const { event, detach } = bridgeEvent(source);
|
||||
event.addEventListener(() => {});
|
||||
detach();
|
||||
assert.equal(source.numberOfListeners, 0);
|
||||
event.addEventListener(() => assert.fail('detached event fired'));
|
||||
assert.equal(source.numberOfListeners, 0);
|
||||
source.raiseEvent();
|
||||
});
|
||||
Reference in new issue
Block a user