mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +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 consumer 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.
90 lines
2.8 KiB
JavaScript
90 lines
2.8 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
bindRenderer,
|
|
cameraOf,
|
|
findCamera,
|
|
provideUnboundCamera,
|
|
rendererOf,
|
|
} from './rendererOf.js';
|
|
|
|
test('a scene finds its renderer until it is unbound', () => {
|
|
const scene = {};
|
|
const renderer = { id: 'r' };
|
|
assert.equal(rendererOf(scene), null);
|
|
assert.equal(rendererOf(null), null);
|
|
const unbind = bindRenderer(scene, renderer);
|
|
assert.equal(rendererOf(scene), renderer);
|
|
assert.throws(() => bindRenderer(scene, { id: 'other' }), /already has/);
|
|
unbind();
|
|
assert.equal(rendererOf(scene), null);
|
|
});
|
|
|
|
test('a stale unbind leaves a later binding alone', () => {
|
|
const scene = {};
|
|
const unbindFirst = bindRenderer(scene, { id: 'first' });
|
|
unbindFirst();
|
|
const second = { id: 'second' };
|
|
bindRenderer(scene, second);
|
|
unbindFirst();
|
|
assert.equal(rendererOf(scene), second);
|
|
});
|
|
|
|
test('cameraOf names the missing renderer instead of returning nothing', () => {
|
|
const scene = {};
|
|
assert.throws(() => cameraOf(scene), /no renderer camera/);
|
|
const camera = { pose() {} };
|
|
const unbind = bindRenderer(scene, { camera });
|
|
assert.equal(cameraOf(scene), camera);
|
|
unbind();
|
|
});
|
|
|
|
test('with no renderer bound, cameraOf builds one camera per scene until a renderer is bound', (t) => {
|
|
t.after(() => provideUnboundCamera(null));
|
|
const built = [];
|
|
provideUnboundCamera((host) => {
|
|
if (!host.camera) return null;
|
|
const entry = { port: { id: built.length }, disposed: 0 };
|
|
entry.dispose = () => (entry.disposed += 1);
|
|
built.push(entry);
|
|
return entry;
|
|
});
|
|
const viewer = { camera: {} };
|
|
assert.equal(cameraOf(viewer), built[0].port);
|
|
assert.equal(cameraOf(viewer), built[0].port, 'kept, not rebuilt');
|
|
assert.equal(built.length, 1);
|
|
assert.throws(
|
|
() => cameraOf({}),
|
|
/no renderer camera/,
|
|
'nothing to build over',
|
|
);
|
|
assert.equal(findCamera({}), null);
|
|
assert.equal(findCamera(null), null);
|
|
|
|
const camera = { pose() {} };
|
|
const unbind = bindRenderer(viewer, { camera });
|
|
assert.equal(
|
|
built[0].disposed,
|
|
1,
|
|
'the renderer supersedes the built camera',
|
|
);
|
|
assert.equal(cameraOf(viewer), camera);
|
|
unbind();
|
|
assert.equal(cameraOf(viewer), built[1].port, 'unbound again: a fresh one');
|
|
});
|
|
|
|
test('a destroyed scene gets no built camera, and lets go of the one it had', (t) => {
|
|
t.after(() => provideUnboundCamera(null));
|
|
let disposed = 0;
|
|
provideUnboundCamera(() => ({ port: {}, dispose: () => (disposed += 1) }));
|
|
let destroyed = false;
|
|
const viewer = { isDestroyed: () => destroyed };
|
|
cameraOf(viewer);
|
|
destroyed = true;
|
|
assert.throws(() => cameraOf(viewer), /destroyed/);
|
|
assert.equal(disposed, 1);
|
|
assert.equal(findCamera(viewer), null, 'findCamera answers null instead');
|
|
assert.throws(() => cameraOf(viewer), /destroyed/);
|
|
assert.equal(disposed, 1, 'once');
|
|
});
|