mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Tidy the vessels layer on the draw port: shared pose key, lazy pose, frame reasons, sprite order
The camera pose key moves to render/camera/poseSignature.js, Cesium-free, and iconOrientation's cameraPoseSignature builds the same key through it. The vessels frame hook reads the pose only when a pass runs or a moved camera could still need its trailing pass, and the unused focus scratch point goes. The draw port takes the frame port's requestRender, so a GPU icon set's own frames (its images packed into the atlas) are asked for under the reason icons:<set id> in the frame diagnostics, where the vessels layer's own ais-vessels-icons reason used to be. Other draw requests are unchanged. A host with no registerSpriteSet still draws the ships and warns once. The vessels draw test now checks the sprite order finds the set's host, and that a torn-down layer draws a new set registered in the old one's place. The new motion, icon book and pose key tests join the format check.
This commit is contained in:
1 parent
7a9c7b4d96
commit
1c8cf240c4
14 files changed
+334
-76
No files matched your search
@@ -58,6 +58,9 @@
|
|||||||
"src/render/cesium/cameraControls.test.mjs",
|
"src/render/cesium/cameraControls.test.mjs",
|
||||||
"src/render/input/router.js",
|
"src/render/input/router.js",
|
||||||
"src/render/input/router.test.mjs",
|
"src/render/input/router.test.mjs",
|
||||||
|
"src/render/motion/iconMotion.test.mjs",
|
||||||
|
"src/render/motion/iconBook.test.mjs",
|
||||||
|
"src/render/camera/poseSignature.test.mjs",
|
||||||
"src/render/cesium/internals.test.mjs",
|
"src/render/cesium/internals.test.mjs",
|
||||||
"src/render/cesium/tileRequests.js",
|
"src/render/cesium/tileRequests.js",
|
||||||
"src/render/cesium/tileRequests.test.mjs",
|
"src/render/cesium/tileRequests.test.mjs",
|
||||||
|
|||||||
@@ -1453,6 +1453,7 @@
|
|||||||
"src/data/cockpitContactDot.js",
|
"src/data/cockpitContactDot.js",
|
||||||
"src/data/contactMatch.js",
|
"src/data/contactMatch.js",
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/idSwitches.js",
|
"src/data/idSwitches.js",
|
||||||
"src/data/layerState.js",
|
"src/data/layerState.js",
|
||||||
"src/data/layerStateTokenReservations.json",
|
"src/data/layerStateTokenReservations.json",
|
||||||
@@ -1559,6 +1560,7 @@
|
|||||||
"src/data/cockpitContactDot.js",
|
"src/data/cockpitContactDot.js",
|
||||||
"src/data/contactMatch.js",
|
"src/data/contactMatch.js",
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/idSwitches.js",
|
"src/data/idSwitches.js",
|
||||||
"src/data/layerState.js",
|
"src/data/layerState.js",
|
||||||
"src/data/layerStateTokenReservations.json",
|
"src/data/layerStateTokenReservations.json",
|
||||||
@@ -1656,6 +1658,7 @@
|
|||||||
"src/data/cockpitContactDot.js",
|
"src/data/cockpitContactDot.js",
|
||||||
"src/data/contactMatch.js",
|
"src/data/contactMatch.js",
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/idSwitches.js",
|
"src/data/idSwitches.js",
|
||||||
"src/data/layerState.js",
|
"src/data/layerState.js",
|
||||||
"src/data/layerStateCoordinator.js",
|
"src/data/layerStateCoordinator.js",
|
||||||
@@ -1694,6 +1697,7 @@
|
|||||||
"src/layers/vessels/queries.js",
|
"src/layers/vessels/queries.js",
|
||||||
"src/geo/vector.js",
|
"src/geo/vector.js",
|
||||||
"src/layers/vessels/rendering.js",
|
"src/layers/vessels/rendering.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/render/motion/iconBook.js",
|
"src/render/motion/iconBook.js",
|
||||||
"src/layers/vessels/iconBook.js",
|
"src/layers/vessels/iconBook.js",
|
||||||
"src/data/entityRecords.js",
|
"src/data/entityRecords.js",
|
||||||
@@ -2182,6 +2186,7 @@
|
|||||||
"src/cyberSonar.js",
|
"src/cyberSonar.js",
|
||||||
"src/cockpitMath.js",
|
"src/cockpitMath.js",
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/militaryAwarenessEngine.js",
|
"src/data/militaryAwarenessEngine.js",
|
||||||
"src/geo/index.js",
|
"src/geo/index.js",
|
||||||
"src/data/installationNames.js",
|
"src/data/installationNames.js",
|
||||||
@@ -2390,6 +2395,7 @@
|
|||||||
"src/data/cctvLod.js",
|
"src/data/cctvLod.js",
|
||||||
"src/data/cctvViewshed.js",
|
"src/data/cctvViewshed.js",
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/trackingClickGesture.js",
|
"src/data/trackingClickGesture.js",
|
||||||
"src/layers/cctv/calibration.js",
|
"src/layers/cctv/calibration.js",
|
||||||
"src/layers/cctv/cards.js",
|
"src/layers/cctv/cards.js",
|
||||||
@@ -2667,6 +2673,7 @@
|
|||||||
"exports": ["./layers/radio"],
|
"exports": ["./layers/radio"],
|
||||||
"modules": [
|
"modules": [
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/idSwitches.js",
|
"src/data/idSwitches.js",
|
||||||
"src/data/layerState.js",
|
"src/data/layerState.js",
|
||||||
"src/data/layerStateTokenReservations.json",
|
"src/data/layerStateTokenReservations.json",
|
||||||
@@ -3181,6 +3188,7 @@
|
|||||||
"src/data/groundFloor.js",
|
"src/data/groundFloor.js",
|
||||||
"src/data/groundSnap.js",
|
"src/data/groundSnap.js",
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/infrastructure.js",
|
"src/data/infrastructure.js",
|
||||||
"src/data/osmOverlays.js",
|
"src/data/osmOverlays.js",
|
||||||
"src/data/installationFeedback.js",
|
"src/data/installationFeedback.js",
|
||||||
@@ -4156,6 +4164,7 @@
|
|||||||
"src/data/focusDeemphasis.js",
|
"src/data/focusDeemphasis.js",
|
||||||
"src/data/geoid.js",
|
"src/data/geoid.js",
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/infrastructure.js",
|
"src/data/infrastructure.js",
|
||||||
"src/data/osmOverlays.js",
|
"src/data/osmOverlays.js",
|
||||||
"src/data/installationFeedback.js",
|
"src/data/installationFeedback.js",
|
||||||
@@ -5455,6 +5464,7 @@
|
|||||||
"src/data/gtfsRealtime.js",
|
"src/data/gtfsRealtime.js",
|
||||||
"src/geoDistance.js",
|
"src/geoDistance.js",
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/inputOwnership.js",
|
"src/data/inputOwnership.js",
|
||||||
"src/data/labelArbiter.js",
|
"src/data/labelArbiter.js",
|
||||||
"src/data/meshFloorSampler.js",
|
"src/data/meshFloorSampler.js",
|
||||||
@@ -5532,6 +5542,7 @@
|
|||||||
"modules": [
|
"modules": [
|
||||||
"src/data/headingDegrees.js",
|
"src/data/headingDegrees.js",
|
||||||
"src/data/iconOrientation.js",
|
"src/data/iconOrientation.js",
|
||||||
|
"src/render/camera/poseSignature.js",
|
||||||
"src/data/inputOwnership.js",
|
"src/data/inputOwnership.js",
|
||||||
"src/data/transitFeeds.js",
|
"src/data/transitFeeds.js",
|
||||||
"src/geoDistance.js",
|
"src/geoDistance.js",
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
* unverified math swap, decides whether exact projection becomes preferred.
|
* unverified math swap, decides whether exact projection becomes preferred.
|
||||||
*/
|
*/
|
||||||
import * as Cesium from 'cesium';
|
import * as Cesium from 'cesium';
|
||||||
|
import { poseSignature } from '../render/camera/poseSignature.js';
|
||||||
|
|
||||||
/** Meters used to give the course vector a stable projection magnitude. */
|
/** Meters used to give the course vector a stable projection magnitude. */
|
||||||
const FORWARD_PROBE_M = 2000;
|
const FORWARD_PROBE_M = 2000;
|
||||||
@@ -257,11 +258,12 @@ export function horizonOccluder(camera) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function cameraPoseSignature(camera) {
|
export function cameraPoseSignature(camera) {
|
||||||
const p = camera.positionWC;
|
return poseSignature({
|
||||||
return (
|
position: camera.positionWC,
|
||||||
`${Math.round(p.x / 10)}:${Math.round(p.y / 10)}:${Math.round(p.z / 10)}:` +
|
heading: camera.heading,
|
||||||
`${camera.heading.toFixed(3)}:${camera.pitch.toFixed(3)}:${camera.roll.toFixed(3)}`
|
pitch: camera.pitch,
|
||||||
);
|
roll: camera.roll,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function services() {
|
|||||||
clearOverlaySource: noop,
|
clearOverlaySource: noop,
|
||||||
},
|
},
|
||||||
geoid: {},
|
geoid: {},
|
||||||
sprites: {},
|
sprites: { registerSpriteSet: noop },
|
||||||
focus: {
|
focus: {
|
||||||
focusNowMs: (now) => now,
|
focusNowMs: (now) => now,
|
||||||
getFocusTarget: () => null,
|
getFocusTarget: () => null,
|
||||||
@@ -99,7 +99,7 @@ test('vessel construction is inert and each instance owns its records, icon cach
|
|||||||
};
|
};
|
||||||
const one = createVesselState({ source, services: services() });
|
const one = createVesselState({ source, services: services() });
|
||||||
const two = createVesselState({ source, services: services() });
|
const two = createVesselState({ source, services: services() });
|
||||||
for (const key of ['state', 'shipIconCache', '_scratchFocusScreen'])
|
for (const key of ['state', 'shipIconCache'])
|
||||||
assert.notEqual(one[key], two[key]);
|
assert.notEqual(one[key], two[key]);
|
||||||
assert.notEqual(one.state.records.byMmsi, two.state.records.byMmsi);
|
assert.notEqual(one.state.records.byMmsi, two.state.records.byMmsi);
|
||||||
assert.notEqual(one.state.feed, two.state.feed);
|
assert.notEqual(one.state.feed, two.state.feed);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { bindFakeCesiumScene } from '../../testSupport/fakeCesiumScene.mjs';
|
|||||||
|
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
|
|
||||||
function setup() {
|
function setup({ focusPassIsNeeded = () => false } = {}) {
|
||||||
let clock = 10_000;
|
let clock = 10_000;
|
||||||
const requests = [];
|
const requests = [];
|
||||||
const holds = new Set();
|
const holds = new Set();
|
||||||
@@ -34,11 +34,11 @@ function setup() {
|
|||||||
clearOverlaySource: noop,
|
clearOverlaySource: noop,
|
||||||
},
|
},
|
||||||
geoid: {},
|
geoid: {},
|
||||||
sprites: {},
|
sprites: { registerSpriteSet: noop },
|
||||||
focus: {
|
focus: {
|
||||||
focusNowMs: () => clock,
|
focusNowMs: () => clock,
|
||||||
getFocusTarget: () => null,
|
getFocusTarget: () => null,
|
||||||
focusPassIsNeeded: () => false,
|
focusPassIsNeeded,
|
||||||
forgetSpriteFocus: noop,
|
forgetSpriteFocus: noop,
|
||||||
},
|
},
|
||||||
worldFocus: {},
|
worldFocus: {},
|
||||||
@@ -139,3 +139,48 @@ test('destroy cancels a pending trailing frame', (t) => {
|
|||||||
advance(VISIBILITY_UPDATE_MS);
|
advance(VISIBILITY_UPDATE_MS);
|
||||||
assert.deepEqual(requests, []);
|
assert.deepEqual(requests, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('frames inside the cadence with a trailing frame waiting read no camera pose', () => {
|
||||||
|
const { camera, timers, advance, frame } = setup();
|
||||||
|
let reads = 0;
|
||||||
|
const position = camera.positionWC;
|
||||||
|
Object.defineProperty(camera, 'positionWC', {
|
||||||
|
get: () => (reads++, position),
|
||||||
|
});
|
||||||
|
frame();
|
||||||
|
assert.ok(reads > 0, 'the cadence pass reads it');
|
||||||
|
advance(100);
|
||||||
|
camera.heading = 0.5;
|
||||||
|
reads = 0;
|
||||||
|
frame();
|
||||||
|
assert.ok(reads > 0, 'a skipped frame reads it to see the camera moved');
|
||||||
|
assert.equal(timers.size, 1);
|
||||||
|
reads = 0;
|
||||||
|
for (let i = 0; i < 5; i += 1) {
|
||||||
|
advance(100);
|
||||||
|
frame();
|
||||||
|
}
|
||||||
|
assert.equal(reads, 0, 'the trailing frame already waits');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a focus pass reads the camera pose even with a trailing frame waiting', () => {
|
||||||
|
let focusing = false;
|
||||||
|
const { camera, timers, advance, frame } = setup({
|
||||||
|
focusPassIsNeeded: () => focusing,
|
||||||
|
});
|
||||||
|
let reads = 0;
|
||||||
|
const position = camera.positionWC;
|
||||||
|
Object.defineProperty(camera, 'positionWC', {
|
||||||
|
get: () => (reads++, position),
|
||||||
|
});
|
||||||
|
frame();
|
||||||
|
advance(100);
|
||||||
|
camera.heading = 0.5;
|
||||||
|
frame();
|
||||||
|
assert.equal(timers.size, 1);
|
||||||
|
focusing = true;
|
||||||
|
reads = 0;
|
||||||
|
advance(100);
|
||||||
|
frame();
|
||||||
|
assert.ok(reads > 0, 'the focus pass needs the eye');
|
||||||
|
});
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
findFrame,
|
findFrame,
|
||||||
findQuery,
|
findQuery,
|
||||||
} from '../../render/rendererOf.js';
|
} from '../../render/rendererOf.js';
|
||||||
|
import { poseSignature } from '../../render/camera/poseSignature.js';
|
||||||
import { createVesselIconBook } from './iconBook.js';
|
import { createVesselIconBook } from './iconBook.js';
|
||||||
import {
|
import {
|
||||||
VESSEL_LIFT_M,
|
VESSEL_LIFT_M,
|
||||||
@@ -31,18 +32,6 @@ const SHIP_ICON_PX = 32;
|
|||||||
|
|
||||||
let instances = 0;
|
let instances = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* The camera pose a pass evaluated, to the precision that moves what it
|
|
||||||
* draws: the eye to 10 m and its angles to a milliradian.
|
|
||||||
*/
|
|
||||||
function poseSignature(pose) {
|
|
||||||
const p = pose.position;
|
|
||||||
return (
|
|
||||||
`${Math.round(p.x / 10)}:${Math.round(p.y / 10)}:${Math.round(p.z / 10)}:` +
|
|
||||||
`${pose.heading.toFixed(3)}:${pose.pitch.toFixed(3)}:${pose.roll.toFixed(3)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createRendering({
|
export function createRendering({
|
||||||
vesselState,
|
vesselState,
|
||||||
services,
|
services,
|
||||||
@@ -103,6 +92,7 @@ export function createRendering({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { registerSpriteSet } = services.sprites;
|
const { registerSpriteSet } = services.sprites;
|
||||||
|
let warnedNoSpriteOrder = false;
|
||||||
const {
|
const {
|
||||||
forgetSpriteFocus,
|
forgetSpriteFocus,
|
||||||
focusNowMs,
|
focusNowMs,
|
||||||
@@ -153,7 +143,14 @@ export function createRendering({
|
|||||||
set.setColumns?.({ ids: [] });
|
set.setColumns?.({ ids: [] });
|
||||||
state.icons = createVesselIconBook(set);
|
state.icons = createVesselIconBook(set);
|
||||||
state.icons.show = state.feed.enabled;
|
state.icons.show = state.feed.enabled;
|
||||||
registerSpriteSet?.('ais', set.id);
|
if (registerSpriteSet) registerSpriteSet('ais', set.id);
|
||||||
|
else if (!warnedNoSpriteOrder) {
|
||||||
|
// Drawn still, but not raised over the other sprite layers.
|
||||||
|
warnedNoSpriteOrder = true;
|
||||||
|
console.warn(
|
||||||
|
'[Data:ais-live-vessels] the host has no registerSpriteSet; ships keep their draw order',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Let the icon draw set go (the layer is destroyed). */
|
/** Let the icon draw set go (the layer is destroyed). */
|
||||||
@@ -313,12 +310,19 @@ export function createRendering({
|
|||||||
if (force) governorRequestRender('ais-vessels-update');
|
if (force) governorRequestRender('ais-vessels-update');
|
||||||
const now = focusNowMs(performance.now());
|
const now = focusNowMs(performance.now());
|
||||||
const focusTarget = getFocusTarget();
|
const focusTarget = getFocusTarget();
|
||||||
const pose = state.viewer ? findCamera(state.viewer)?.pose() : null;
|
|
||||||
const regularPass =
|
const regularPass =
|
||||||
force || now - state.lastVisibilityUpdate >= VISIBILITY_UPDATE_MS;
|
force || now - state.lastVisibilityUpdate >= VISIBILITY_UPDATE_MS;
|
||||||
const focusPass =
|
const focusPass =
|
||||||
focusPassIsNeeded(focusTarget, state.activeFocusCount) &&
|
focusPassIsNeeded(focusTarget, state.activeFocusCount) &&
|
||||||
(force || now - state.lastFocusUpdate >= FOCUS_UPDATE_MS);
|
(force || now - state.lastFocusUpdate >= FOCUS_UPDATE_MS);
|
||||||
|
// The pose is read only when a pass runs or a moved camera could still
|
||||||
|
// need its trailing pass: most frames fall inside the cadence with one
|
||||||
|
// already waiting.
|
||||||
|
const pose =
|
||||||
|
state.viewer &&
|
||||||
|
(regularPass || focusPass || !state.trailingVisibilityTimer)
|
||||||
|
? findCamera(state.viewer)?.pose()
|
||||||
|
: null;
|
||||||
if (
|
if (
|
||||||
!regularPass &&
|
!regularPass &&
|
||||||
pose &&
|
pose &&
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ export function createVesselState({ source, services }) {
|
|||||||
|
|
||||||
vesselState._lastCamPoseSig = '';
|
vesselState._lastCamPoseSig = '';
|
||||||
|
|
||||||
/** Screen position the focus pass projects into, reused every pass. */
|
|
||||||
vesselState._scratchFocusScreen = { x: 0, y: 0 };
|
|
||||||
|
|
||||||
vesselState.DEFAULT_VESSEL_OVERLAY_HOST = Object.freeze({
|
vesselState.DEFAULT_VESSEL_OVERLAY_HOST = Object.freeze({
|
||||||
setEntries: setOverlayEntries,
|
setEntries: setOverlayEntries,
|
||||||
setVisible: setOverlaySourceVisible,
|
setVisible: setOverlaySourceVisible,
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* @module render/camera/poseSignature
|
||||||
|
* @description A cheap "did the camera move" key for gating passes that
|
||||||
|
* depend on the view: the eye's ECEF position to 10 m and its heading, pitch
|
||||||
|
* and roll (radians) to a milliradian. It takes a camera port pose or any
|
||||||
|
* `{position, heading, pitch, roll}`, so a renderer's own camera reads the
|
||||||
|
* same key.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{position: {x: number, y: number, z: number}, heading: number,
|
||||||
|
* pitch: number, roll: number}} pose
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function poseSignature(pose) {
|
||||||
|
const p = pose.position;
|
||||||
|
return (
|
||||||
|
`${Math.round(p.x / 10)}:${Math.round(p.y / 10)}:${Math.round(p.z / 10)}:` +
|
||||||
|
`${pose.heading.toFixed(3)}:${pose.pitch.toFixed(3)}:${pose.roll.toFixed(3)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { readFileSync } from 'node:fs';
|
||||||
|
import test from 'node:test';
|
||||||
|
import { cameraPoseSignature } from '../../data/iconOrientation.js';
|
||||||
|
import { poseSignature } from './poseSignature.js';
|
||||||
|
|
||||||
|
const pose = {
|
||||||
|
position: { x: 3_975_123.4, y: 289_456.7, z: 4_998_765.1 },
|
||||||
|
heading: 1.23456,
|
||||||
|
pitch: -0.7071,
|
||||||
|
roll: 0.0004,
|
||||||
|
};
|
||||||
|
|
||||||
|
test('the pose key holds the eye to 10 m and its angles to a milliradian', () => {
|
||||||
|
assert.equal(poseSignature(pose), '397512:28946:499877:1.235:-0.707:0.000');
|
||||||
|
const near = {
|
||||||
|
...pose,
|
||||||
|
position: { ...pose.position, x: pose.position.x + 1 },
|
||||||
|
heading: pose.heading + 0.0003,
|
||||||
|
};
|
||||||
|
assert.equal(poseSignature(near), poseSignature(pose), 'too small to move');
|
||||||
|
assert.notEqual(
|
||||||
|
poseSignature({ ...pose, pitch: pose.pitch + 0.002 }),
|
||||||
|
poseSignature(pose),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a Cesium camera keys the same as the pose it reads', () => {
|
||||||
|
const camera = {
|
||||||
|
positionWC: pose.position,
|
||||||
|
heading: pose.heading,
|
||||||
|
pitch: pose.pitch,
|
||||||
|
roll: pose.roll,
|
||||||
|
};
|
||||||
|
assert.equal(cameraPoseSignature(camera), poseSignature(pose));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the pose key imports no renderer', () => {
|
||||||
|
const source = readFileSync(
|
||||||
|
new URL('./poseSignature.js', import.meta.url),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
assert.doesNotMatch(source, /from 'cesium'/);
|
||||||
|
});
|
||||||
@@ -139,13 +139,18 @@ const ANCHORS = {
|
|||||||
* sets by id, a version that changes with them, the scene's 3D tilesets and
|
* sets by id, a version that changes with them, the scene's 3D tilesets and
|
||||||
* the clamp-state watch the frame loop runs after each draw.
|
* the clamp-state watch the frame loop runs after each draw.
|
||||||
* @param {{scene: object, report: (error: unknown) => void,
|
* @param {{scene: object, report: (error: unknown) => void,
|
||||||
* capabilities?: ReadonlySet<string>}} options `capabilities` gate the
|
* capabilities?: ReadonlySet<string>,
|
||||||
* GPU icon sets' members (by default they all are).
|
* requestRender?: (reason: string) => void}} options `capabilities` gate
|
||||||
|
* the GPU icon sets' members (by default they all are); `requestRender`,
|
||||||
|
* the frame port's, asks for the frames a GPU icon set needs on its own
|
||||||
|
* (its images packed), under the reason `icons:<set id>` (by default the
|
||||||
|
* scene's, with no reason).
|
||||||
*/
|
*/
|
||||||
export function createCesiumDraw({
|
export function createCesiumDraw({
|
||||||
scene,
|
scene,
|
||||||
report,
|
report,
|
||||||
capabilities = new Set(GPU_ICON_CAPABILITIES),
|
capabilities = new Set(GPU_ICON_CAPABILITIES),
|
||||||
|
requestRender: requestFrame = null,
|
||||||
}) {
|
}) {
|
||||||
const sets = new Map();
|
const sets = new Map();
|
||||||
// Bumped on every change to the sets or what they hold.
|
// Bumped on every change to the sets or what they hold.
|
||||||
@@ -322,7 +327,11 @@ export function createCesiumDraw({
|
|||||||
toColor,
|
toColor,
|
||||||
imageOf: (record, image) => iconImage(record, image),
|
imageOf: (record, image) => iconImage(record, image),
|
||||||
peekImage: (image) => atlases.get(image.atlas)?.[image.slot],
|
peekImage: (image) => atlases.get(image.atlas)?.[image.slot],
|
||||||
requestRender,
|
requestRender: (reason) => {
|
||||||
|
if (!live()) return;
|
||||||
|
if (requestFrame) requestFrame(reason);
|
||||||
|
else scene.requestRender();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+127
-43
@@ -1704,12 +1704,12 @@ test('icons scale, fade and show by eye distance, and drop the curves in place',
|
|||||||
set.dispose();
|
set.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('the vessels layer draws its ships as one GPU icon set that holds them on course', async () => {
|
/**
|
||||||
|
* The vessels layer over a fake scene, drawing through the draw port, with
|
||||||
|
* `sprites` as its sprite-order services.
|
||||||
|
*/
|
||||||
|
async function vesselLayerOver(scene, sprites) {
|
||||||
const { createVesselLayer } = await import('../../layers/vessels/index.js');
|
const { createVesselLayer } = await import('../../layers/vessels/index.js');
|
||||||
const { IconSetPrimitive } = await import('../../data/iconSetPrimitive.js');
|
|
||||||
const { ICON_CULL_LIFT, ICON_ROTATES } =
|
|
||||||
await import('../../data/iconSet.js');
|
|
||||||
const scene = fakeScene();
|
|
||||||
const part = createCesiumDraw({
|
const part = createCesiumDraw({
|
||||||
scene,
|
scene,
|
||||||
report: (error) => assert.fail(error),
|
report: (error) => assert.fail(error),
|
||||||
@@ -1738,7 +1738,7 @@ test('the vessels layer draws its ships as one GPU icon set that holds them on c
|
|||||||
clearOverlaySource: noop,
|
clearOverlaySource: noop,
|
||||||
},
|
},
|
||||||
geoid: {},
|
geoid: {},
|
||||||
sprites: {},
|
sprites,
|
||||||
focus: {
|
focus: {
|
||||||
focusNowMs: (now) => now,
|
focusNowMs: (now) => now,
|
||||||
getFocusTarget: () => null,
|
getFocusTarget: () => null,
|
||||||
@@ -1753,46 +1753,130 @@ test('the vessels layer draws its ships as one GPU icon set that holds them on c
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
layer.testing._setVesselStateForTest({ viewer, icons: null });
|
return { layer, viewer, part, unbind };
|
||||||
layer.testing._reconcileVesselsForTest(viewer, [
|
}
|
||||||
{ mmsi: '244000001', lat: 51.95, lon: 4.1, heading: 90, speed: 12 },
|
|
||||||
{ mmsi: '244000002', lat: 51.96, lon: 4.2, course: 200, speed: 2 },
|
test('the vessels layer draws its ships as one GPU icon set that holds them on course', async () => {
|
||||||
]);
|
const { IconSetPrimitive } = await import('../../data/iconSetPrimitive.js');
|
||||||
const [host] = scene.added;
|
const { ICON_CULL_LIFT, ICON_ROTATES } =
|
||||||
assert.ok(host instanceof IconSetPrimitive, 'one GPU icon set');
|
await import('../../data/iconSet.js');
|
||||||
assert.match(host.drawSetId, /^ais-vessels:\d+$/);
|
const spriteOrder = await import('../../data/spriteOrder.js');
|
||||||
const record = part.sets.get(host.drawSetId);
|
const scene = fakeScene();
|
||||||
const set = record.gpu.set;
|
const registered = [];
|
||||||
assert.equal(set.count, 2);
|
const { layer, viewer, part, unbind } = await vesselLayerOver(scene, {
|
||||||
const row = set.row('244000001');
|
registerSpriteSet(layerId, setId) {
|
||||||
const tau = set.seconds(Cesium.JulianDate.now());
|
registered.push([layerId, setId]);
|
||||||
assert.equal(set.course(row, tau), 90, 'held on its heading');
|
return spriteOrder.registerSpriteSet(layerId, setId);
|
||||||
assert.equal(set.course(set.row('244000002'), tau), 200, 'or its course');
|
},
|
||||||
assert.equal(set.width(row), 32);
|
|
||||||
assert.ok(Math.abs(set.scale(row) - 0.68) < 1e-6, 'scaled by speed');
|
|
||||||
assert.equal(set.flags(row) & ICON_ROTATES, ICON_ROTATES);
|
|
||||||
assert.equal(set.flags(row) & ICON_CULL_LIFT, ICON_CULL_LIFT);
|
|
||||||
assert.ok(set.depthTestDistance(row) >= 1e30, 'over depth everywhere');
|
|
||||||
const at = Cesium.Cartographic.fromCartesian(set.position(row, tau));
|
|
||||||
assert.ok(Math.abs(Cesium.Math.toDegrees(at.longitude) - 4.1) < 1e-6);
|
|
||||||
assert.ok(Math.abs(Cesium.Math.toDegrees(at.latitude) - 51.95) < 1e-6);
|
|
||||||
const facade = { show: true };
|
|
||||||
assert.deepEqual(drawHitOf(host._pickObject('244000001', null, facade)), {
|
|
||||||
set: host.drawSetId,
|
|
||||||
id: '244000001',
|
|
||||||
meta: { layer: 'ais-live-vessels', id: '244000001' },
|
|
||||||
surface: false,
|
|
||||||
});
|
});
|
||||||
|
const military = { name: 'military' };
|
||||||
|
try {
|
||||||
|
layer.testing._setVesselStateForTest({ viewer, icons: null });
|
||||||
|
layer.testing._reconcileVesselsForTest(viewer, [
|
||||||
|
{ mmsi: '244000001', lat: 51.95, lon: 4.1, heading: 90, speed: 12 },
|
||||||
|
{ mmsi: '244000002', lat: 51.96, lon: 4.2, course: 200, speed: 2 },
|
||||||
|
]);
|
||||||
|
const [host] = scene.added;
|
||||||
|
assert.ok(host instanceof IconSetPrimitive, 'one GPU icon set');
|
||||||
|
assert.match(host.drawSetId, /^ais-vessels:\d+$/);
|
||||||
|
const record = part.sets.get(host.drawSetId);
|
||||||
|
const set = record.gpu.set;
|
||||||
|
assert.equal(set.count, 2);
|
||||||
|
const row = set.row('244000001');
|
||||||
|
const tau = set.seconds(Cesium.JulianDate.now());
|
||||||
|
assert.equal(set.course(row, tau), 90, 'held on its heading');
|
||||||
|
assert.equal(set.course(set.row('244000002'), tau), 200, 'or its course');
|
||||||
|
assert.equal(set.width(row), 32);
|
||||||
|
assert.ok(Math.abs(set.scale(row) - 0.68) < 1e-6, 'scaled by speed');
|
||||||
|
assert.equal(set.flags(row) & ICON_ROTATES, ICON_ROTATES);
|
||||||
|
assert.equal(set.flags(row) & ICON_CULL_LIFT, ICON_CULL_LIFT);
|
||||||
|
assert.ok(set.depthTestDistance(row) >= 1e30, 'over depth everywhere');
|
||||||
|
const at = Cesium.Cartographic.fromCartesian(set.position(row, tau));
|
||||||
|
assert.ok(Math.abs(Cesium.Math.toDegrees(at.longitude) - 4.1) < 1e-6);
|
||||||
|
assert.ok(Math.abs(Cesium.Math.toDegrees(at.latitude) - 51.95) < 1e-6);
|
||||||
|
const facade = { show: true };
|
||||||
|
assert.deepEqual(drawHitOf(host._pickObject('244000001', null, facade)), {
|
||||||
|
set: host.drawSetId,
|
||||||
|
id: '244000001',
|
||||||
|
meta: { layer: 'ais-live-vessels', id: '244000001' },
|
||||||
|
surface: false,
|
||||||
|
});
|
||||||
|
|
||||||
// A poll that moves one and drops the other writes rows, not a new host.
|
// A poll that moves one and drops the other writes rows, not a new host.
|
||||||
layer.testing._reconcileVesselsForTest(viewer, [
|
layer.testing._reconcileVesselsForTest(viewer, [
|
||||||
{ mmsi: '244000001', lat: 51.95, lon: 4.12, heading: 95, speed: 12 },
|
{ mmsi: '244000001', lat: 51.95, lon: 4.12, heading: 95, speed: 12 },
|
||||||
]);
|
]);
|
||||||
assert.equal(scene.added[0], host);
|
assert.equal(scene.added[0], host);
|
||||||
assert.equal(set.count, 1);
|
assert.equal(set.count, 1);
|
||||||
assert.equal(set.course(set.row('244000001'), tau), 95);
|
assert.equal(set.course(set.row('244000001'), tau), 95);
|
||||||
|
|
||||||
|
// The sprite order finds the host by its set id and stacks it under the
|
||||||
|
// military sprites.
|
||||||
|
assert.deepEqual(registered, [['ais', host.drawSetId]]);
|
||||||
|
spriteOrder.registerSpriteCollection('military', military);
|
||||||
|
const stack = (list) => ({
|
||||||
|
scene: {
|
||||||
|
primitives: {
|
||||||
|
get: (i) => list[i],
|
||||||
|
get length() {
|
||||||
|
return list.length;
|
||||||
|
},
|
||||||
|
contains: (p) => list.includes(p),
|
||||||
|
raiseToTop(p) {
|
||||||
|
list.splice(list.indexOf(p), 1);
|
||||||
|
list.push(p);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const order = [military, host, { name: 'other' }];
|
||||||
|
spriteOrder.restoreSpriteOrder(stack(order));
|
||||||
|
assert.deepEqual(
|
||||||
|
order.map((p) => p.name ?? p.drawSetId),
|
||||||
|
['other', host.drawSetId, 'military'],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Torn down and drawn again: a new set, registered in the old one's
|
||||||
|
// place, with the old host gone from the scene.
|
||||||
|
layer.destroy(viewer);
|
||||||
|
assert.equal(scene.added.length, 0, 'destroyed: the set goes');
|
||||||
|
layer.testing._setVesselStateForTest({ viewer, icons: null });
|
||||||
|
layer.testing._reconcileVesselsForTest(viewer, [
|
||||||
|
{ mmsi: '244000003', lat: 51.9, lon: 4.0, heading: 10, speed: 5 },
|
||||||
|
]);
|
||||||
|
assert.equal(scene.added.length, 1);
|
||||||
|
const [again] = scene.added;
|
||||||
|
assert.notEqual(again, host);
|
||||||
|
assert.notEqual(again.drawSetId, host.drawSetId, 'a new set id');
|
||||||
|
assert.equal(part.sets.has(host.drawSetId), false);
|
||||||
|
assert.deepEqual(registered.at(-1), ['ais', again.drawSetId]);
|
||||||
|
const stray = { name: 'stray' };
|
||||||
|
const next = [military, again, stray];
|
||||||
|
spriteOrder.restoreSpriteOrder(stack(next));
|
||||||
|
assert.deepEqual(next, [stray, again, military], 'the new host is raised');
|
||||||
|
layer.destroy(viewer);
|
||||||
|
assert.equal(scene.added.length, 0);
|
||||||
|
} finally {
|
||||||
|
spriteOrder.unregisterSpriteCollection('military', military);
|
||||||
|
spriteOrder.unregisterSpriteCollection('ais');
|
||||||
|
unbind();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('vessels on a host with no sprite-set registry still draw, and say so once', async (t) => {
|
||||||
|
const warnings = [];
|
||||||
|
t.mock.method(console, 'warn', (...args) => warnings.push(args.join(' ')));
|
||||||
|
const scene = fakeScene();
|
||||||
|
const { layer, viewer, unbind } = await vesselLayerOver(scene, {});
|
||||||
|
const ship = { mmsi: '244000001', lat: 51.95, lon: 4.1, heading: 90 };
|
||||||
|
layer.testing._setVesselStateForTest({ viewer, icons: null });
|
||||||
|
layer.testing._reconcileVesselsForTest(viewer, [ship]);
|
||||||
|
assert.equal(scene.added.length, 1, 'drawn');
|
||||||
|
layer.destroy(viewer);
|
||||||
|
layer.testing._setVesselStateForTest({ viewer, icons: null });
|
||||||
|
layer.testing._reconcileVesselsForTest(viewer, [ship]);
|
||||||
|
const said = warnings.filter((w) => w.includes('registerSpriteSet'));
|
||||||
|
assert.equal(said.length, 1, 'once, not per set');
|
||||||
layer.destroy(viewer);
|
layer.destroy(viewer);
|
||||||
assert.equal(scene.added.length, 0, 'destroyed: the set goes');
|
|
||||||
unbind();
|
unbind();
|
||||||
});
|
});
|
||||||
@@ -174,7 +174,7 @@ function rasterPxOf(url, item) {
|
|||||||
* toColor: (color: unknown) => Cesium.Color,
|
* toColor: (color: unknown) => Cesium.Color,
|
||||||
* imageOf: (record: object, image: unknown) => unknown,
|
* imageOf: (record: object, image: unknown) => unknown,
|
||||||
* peekImage: (ref: {atlas: string, slot: string}) => unknown,
|
* peekImage: (ref: {atlas: string, slot: string}) => unknown,
|
||||||
* requestRender: () => void}} options `imageOf` reads an atlas slot
|
* requestRender: (reason: string) => void}} options `imageOf` reads an atlas slot
|
||||||
* through the draw port's atlases (undefined while it is not registered),
|
* through the draw port's atlases (undefined while it is not registered),
|
||||||
* noting that the set draws from it; `peekImage` only reads it.
|
* noting that the set draws from it; `peekImage` only reads it.
|
||||||
*/
|
*/
|
||||||
@@ -286,7 +286,7 @@ export function createGpuIcons({
|
|||||||
set,
|
set,
|
||||||
renderTime: (frameState) =>
|
renderTime: (frameState) =>
|
||||||
clockTime(frameState, new Cesium.JulianDate()),
|
clockTime(frameState, new Cesium.JulianDate()),
|
||||||
requestRender,
|
requestRender: () => requestRender(`icons:${spec.id}`),
|
||||||
cull: () => spec.horizonCull === true,
|
cull: () => spec.horizonCull === true,
|
||||||
// Picked as the draw port's other items are: `{set, id, meta,
|
// Picked as the draw port's other items are: `{set, id, meta,
|
||||||
// lodGroup}` as the item now is, hidden row by row for drill picks.
|
// lodGroup}` as the item now is, hidden row by row for drill picks.
|
||||||
|
|||||||
@@ -833,3 +833,36 @@ test('the atlas holds more than 64 images, every one addressed on WebGL 2', asyn
|
|||||||
);
|
);
|
||||||
assert.equal(slots.size, 70, 'each its own slot');
|
assert.equal(slots.size, 70, 'each its own slot');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a GPU icon set asks the frame port for its atlas frames, under its own reason', async () => {
|
||||||
|
const { iconAtlas } = await import('../../data/iconAtlas.js');
|
||||||
|
const onChange = iconAtlas.onChange;
|
||||||
|
const heard = [];
|
||||||
|
iconAtlas.onChange = (listener) => (heard.push(listener), () => {});
|
||||||
|
try {
|
||||||
|
const reasons = [];
|
||||||
|
const { scene, draw } = drawOver({
|
||||||
|
requestRender: (reason) => reasons.push(reason),
|
||||||
|
});
|
||||||
|
const set = draw.icons({ id: 'gpu:reason' });
|
||||||
|
set.set([icon('a', { motion: { kind: 'hold' } })]);
|
||||||
|
assert.equal(heard.length, 1, 'its host listens for packed images');
|
||||||
|
const before = scene.renders;
|
||||||
|
heard[0]();
|
||||||
|
assert.deepEqual(reasons, ['icons:gpu:reason']);
|
||||||
|
assert.equal(scene.renders, before, 'through the frame port only');
|
||||||
|
set.dispose();
|
||||||
|
|
||||||
|
// With no frame port, the scene's own request, as before.
|
||||||
|
const bare = drawOver();
|
||||||
|
const bareSet = bare.draw.icons({ id: 'gpu:bare' });
|
||||||
|
bareSet.set([icon('a', { motion: { kind: 'hold' } })]);
|
||||||
|
assert.equal(heard.length, 2);
|
||||||
|
const was = bare.scene.renders;
|
||||||
|
heard[1]();
|
||||||
|
assert.equal(bare.scene.renders, was + 1);
|
||||||
|
bareSet.dispose();
|
||||||
|
} finally {
|
||||||
|
iconAtlas.onChange = onChange;
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -290,7 +290,12 @@ export function createCesiumPorts(widget, { capabilities, credentials = {} }) {
|
|||||||
|
|
||||||
// --- Draw ------------------------------------------------------------------
|
// --- Draw ------------------------------------------------------------------
|
||||||
|
|
||||||
const drawPart = createCesiumDraw({ scene, report, capabilities });
|
const drawPart = createCesiumDraw({
|
||||||
|
scene,
|
||||||
|
report,
|
||||||
|
capabilities,
|
||||||
|
requestRender: (reason) => frame.requestRender(reason),
|
||||||
|
});
|
||||||
const { port: draw, sets, tilesets } = drawPart;
|
const { port: draw, sets, tilesets } = drawPart;
|
||||||
|
|
||||||
const cameraPart = createCesiumCamera({ scene, camera, report, widget });
|
const cameraPart = createCesiumCamera({ scene, camera, report, widget });
|
||||||
|
|||||||
Reference in new issue
Block a user