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
@@ -32,7 +32,7 @@ function services() {
|
||||
clearOverlaySource: noop,
|
||||
},
|
||||
geoid: {},
|
||||
sprites: {},
|
||||
sprites: { registerSpriteSet: noop },
|
||||
focus: {
|
||||
focusNowMs: (now) => now,
|
||||
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 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.state.records.byMmsi, two.state.records.byMmsi);
|
||||
assert.notEqual(one.state.feed, two.state.feed);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { bindFakeCesiumScene } from '../../testSupport/fakeCesiumScene.mjs';
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
function setup() {
|
||||
function setup({ focusPassIsNeeded = () => false } = {}) {
|
||||
let clock = 10_000;
|
||||
const requests = [];
|
||||
const holds = new Set();
|
||||
@@ -34,11 +34,11 @@ function setup() {
|
||||
clearOverlaySource: noop,
|
||||
},
|
||||
geoid: {},
|
||||
sprites: {},
|
||||
sprites: { registerSpriteSet: noop },
|
||||
focus: {
|
||||
focusNowMs: () => clock,
|
||||
getFocusTarget: () => null,
|
||||
focusPassIsNeeded: () => false,
|
||||
focusPassIsNeeded,
|
||||
forgetSpriteFocus: noop,
|
||||
},
|
||||
worldFocus: {},
|
||||
@@ -139,3 +139,48 @@ test('destroy cancels a pending trailing frame', (t) => {
|
||||
advance(VISIBILITY_UPDATE_MS);
|
||||
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,
|
||||
findQuery,
|
||||
} from '../../render/rendererOf.js';
|
||||
import { poseSignature } from '../../render/camera/poseSignature.js';
|
||||
import { createVesselIconBook } from './iconBook.js';
|
||||
import {
|
||||
VESSEL_LIFT_M,
|
||||
@@ -31,18 +32,6 @@ const SHIP_ICON_PX = 32;
|
||||
|
||||
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({
|
||||
vesselState,
|
||||
services,
|
||||
@@ -103,6 +92,7 @@ export function createRendering({
|
||||
}
|
||||
|
||||
const { registerSpriteSet } = services.sprites;
|
||||
let warnedNoSpriteOrder = false;
|
||||
const {
|
||||
forgetSpriteFocus,
|
||||
focusNowMs,
|
||||
@@ -153,7 +143,14 @@ export function createRendering({
|
||||
set.setColumns?.({ ids: [] });
|
||||
state.icons = createVesselIconBook(set);
|
||||
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). */
|
||||
@@ -313,12 +310,19 @@ export function createRendering({
|
||||
if (force) governorRequestRender('ais-vessels-update');
|
||||
const now = focusNowMs(performance.now());
|
||||
const focusTarget = getFocusTarget();
|
||||
const pose = state.viewer ? findCamera(state.viewer)?.pose() : null;
|
||||
const regularPass =
|
||||
force || now - state.lastVisibilityUpdate >= VISIBILITY_UPDATE_MS;
|
||||
const focusPass =
|
||||
focusPassIsNeeded(focusTarget, state.activeFocusCount) &&
|
||||
(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 (
|
||||
!regularPass &&
|
||||
pose &&
|
||||
|
||||
@@ -17,9 +17,6 @@ export function createVesselState({ source, services }) {
|
||||
|
||||
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({
|
||||
setEntries: setOverlayEntries,
|
||||
setVisible: setOverlaySourceVisible,
|
||||
|
||||
Reference in new issue
Block a user