mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
Draw radio, transit and CCTV through one display each
- Radio: stations, clusters, the selection and its brackets are point and sprite sets; clusters come from the layer's engine-neutral screen clusterer with Cesium's EntityCluster rules, and clicks go through the selection dispatcher. One style module holds the sizes and colours. - Transit: vehicles are two sprite sets from an up-front atlas, rotated with Cesium's projected-rotation maths. The selected vehicle's trail is engine.lines in two lanes and 29 age bands, so trails are no longer draped over terrain until the contract has ground corridors. The Cesium contact trail renderer and its re-export go. - CCTV: markers, wedges, the plane outline and the calibration gizmo (rings, arrows, handles, drags through engine.input) draw on the contract. The textured monitor plane and the viewshed volume, which no primitive expresses yet, sit behind one seam, render/meshes.js, with a Cesium backend and a Navara backend the Navara mode passes in. Known gaps against Cesium: transit trails are not draped, and the surveillance-lens click correction runs only where the engine reports its style stage (Navara). Coupling: layer renderer lines fall from 2638/8735 to 1636/6953 (Cesium/Navara), ScreenSpaceEventHandler files from 15 to 10, `viewer` lines from 2014 to 1901.
This commit is contained in:
1 parent
fc75e245a6
commit
dc1144b947
68 files changed
+6216
-5326
No files matched your search
@@ -2,7 +2,9 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createTransitLayer } from './index.js';
|
||||
import { createTransitCesiumRenderer } from './render/cesium.js';
|
||||
import { createFakeEngine } from '../../globe/testing/fakeEngine.js';
|
||||
import { createTransitDisplay } from './render/display.js';
|
||||
import { transitTestAtlas } from './render/testAtlas.mjs';
|
||||
import {
|
||||
FEED_EVICT_AFTER_MS,
|
||||
FEED_STALE_AFTER_MS,
|
||||
@@ -88,7 +90,7 @@ function vehicle(id, lat, lon, atSeconds, extra = {}) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A Transit layer wired to a stub scene and a scripted proxy.
|
||||
* A Transit layer drawn on the fake globe engine, with a scripted proxy.
|
||||
*
|
||||
* The render governor is the real one, so "does this layer keep the render loop
|
||||
* awake?" is answered by the same code the app runs.
|
||||
@@ -160,6 +162,7 @@ function harness(
|
||||
east: at.lon + 0.1,
|
||||
north: at.lat + 0.1,
|
||||
},
|
||||
engineOptions = {},
|
||||
} = {},
|
||||
) {
|
||||
const viewRect = { ...view };
|
||||
@@ -167,25 +170,9 @@ function harness(
|
||||
apis: ['Date', 'setTimeout'],
|
||||
now: 1_789_000_000_000,
|
||||
});
|
||||
|
||||
for (const name of [
|
||||
'HTMLCanvasElement',
|
||||
'HTMLImageElement',
|
||||
'ImageBitmap',
|
||||
'OffscreenCanvas',
|
||||
]) {
|
||||
const prior = globalThis[name];
|
||||
globalThis[name] = class {};
|
||||
t.after(() => {
|
||||
if (prior === undefined) delete globalThis[name];
|
||||
else globalThis[name] = prior;
|
||||
});
|
||||
}
|
||||
t.mock.method(performance, 'now', () => Date.now() - 1_789_000_000_000);
|
||||
const originalFetch = globalThis.fetch;
|
||||
const originalDocument = globalThis.document;
|
||||
const primitives = [];
|
||||
const sprites = new Map();
|
||||
const pickOwners = new Map();
|
||||
const overlaySources = new Map();
|
||||
const credits = [];
|
||||
@@ -201,47 +188,39 @@ function harness(
|
||||
const originalWindow = globalThis.window;
|
||||
globalThis.window = new EventTarget();
|
||||
|
||||
const preRender = new Cesium.Event();
|
||||
const cameraChanged = new Cesium.Event();
|
||||
// The globe: a fake engine over `at`, looking straight down from
|
||||
// `altitude`, whose view rectangle is `view` (lookAt moves it).
|
||||
const engine = createFakeEngine(engineOptions);
|
||||
engine.fake.setPose({
|
||||
longitude: Cesium.Math.toRadians(at.lon),
|
||||
latitude: Cesium.Math.toRadians(at.lat),
|
||||
height: altitude,
|
||||
heading: 0,
|
||||
pitch: -Math.PI / 2,
|
||||
roll: 0,
|
||||
});
|
||||
let viewRectangle = () =>
|
||||
Cesium.Rectangle.fromDegrees(
|
||||
viewRect.west,
|
||||
viewRect.south,
|
||||
viewRect.east,
|
||||
viewRect.north,
|
||||
);
|
||||
engine.fake.script('viewRectangle', () => viewRectangle());
|
||||
// No terrain answers unless a test gives one (photoreal-style floors).
|
||||
let terrain = () => undefined;
|
||||
engine.fake.script('terrainHeight', (cartographic) => terrain(cartographic));
|
||||
let frameTime = 0;
|
||||
// The render governor's scene: requestRenderMode is what it switches.
|
||||
const viewer = {
|
||||
camera: {
|
||||
changed: cameraChanged,
|
||||
percentageChanged: 0.5,
|
||||
positionCartographic: {
|
||||
height: altitude,
|
||||
latitude: Cesium.Math.toRadians(at.lat),
|
||||
longitude: Cesium.Math.toRadians(at.lon),
|
||||
},
|
||||
computeViewRectangle() {
|
||||
return Cesium.Rectangle.fromDegrees(
|
||||
viewRect.west,
|
||||
viewRect.south,
|
||||
viewRect.east,
|
||||
viewRect.north,
|
||||
);
|
||||
},
|
||||
},
|
||||
camera: engine.camera,
|
||||
scene: {
|
||||
canvas: { addEventListener() {}, removeEventListener() {} },
|
||||
globe: { ellipsoid: Cesium.Ellipsoid.WGS84 },
|
||||
pick: () => undefined,
|
||||
requestRenderMode: false,
|
||||
maximumRenderTimeChange: 0,
|
||||
requestRender() {},
|
||||
preRender,
|
||||
primitives: {
|
||||
add(primitive) {
|
||||
primitives.push(primitive);
|
||||
return primitive;
|
||||
},
|
||||
remove(primitive) {
|
||||
const index = primitives.indexOf(primitive);
|
||||
if (index >= 0) primitives.splice(index, 1);
|
||||
return index >= 0;
|
||||
},
|
||||
contains: (primitive) => primitives.includes(primitive),
|
||||
raiseToTop() {},
|
||||
},
|
||||
// For the layers in a test that still bind a viewer's scene.
|
||||
preRender: engine.frames.preRender,
|
||||
postRender: engine.frames.postRender,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -263,14 +242,21 @@ function harness(
|
||||
const ground = groundStub(floorAt);
|
||||
/** Every call the floor cycle makes to the rendered-mesh sampler. */
|
||||
const meshCalls = [];
|
||||
let display = null;
|
||||
const layer = createTransitLayer({
|
||||
rendererFactory: createTransitCesiumRenderer,
|
||||
rendererFactory: (context) => {
|
||||
display = createTransitDisplay(engine, {
|
||||
...context,
|
||||
drawAtlas: transitTestAtlas,
|
||||
});
|
||||
return display;
|
||||
},
|
||||
source,
|
||||
services: {
|
||||
ground,
|
||||
mesh: {
|
||||
sampleMeshFloorCells(scene, points, options) {
|
||||
meshCalls.push({ scene, points: [...points], options });
|
||||
sampleMeshFloorCells(target, points, options) {
|
||||
meshCalls.push({ target, points: [...points], options });
|
||||
},
|
||||
},
|
||||
render: {
|
||||
@@ -278,12 +264,6 @@ function harness(
|
||||
holdContinuousRender,
|
||||
releaseContinuousRender,
|
||||
},
|
||||
sprites: {
|
||||
registerSpriteCollection: (id, collection) =>
|
||||
sprites.set(id, collection),
|
||||
unregisterSpriteCollection: (id) => sprites.delete(id),
|
||||
restoreSpriteOrder() {},
|
||||
},
|
||||
picking: {
|
||||
registerPickOwner: (id, predicate) => pickOwners.set(id, predicate),
|
||||
unregisterPickOwner: (id) => pickOwners.delete(id),
|
||||
@@ -294,7 +274,7 @@ function harness(
|
||||
clearOverlaySource: (id) => overlaySources.delete(id),
|
||||
},
|
||||
credits: {
|
||||
registerDynamicCredit: (_viewer, credit) => credits.push(credit?.key),
|
||||
registerDynamicCredit: (_engine, credit) => credits.push(credit?.key),
|
||||
transitFeedCredit: (feed) => ({
|
||||
key: `transit-${feed.id}`,
|
||||
html: feed.name,
|
||||
@@ -304,7 +284,7 @@ function harness(
|
||||
});
|
||||
|
||||
installRenderGovernor(viewer);
|
||||
layer.init(viewer);
|
||||
layer.init(viewer, { engine });
|
||||
|
||||
t.after(() => {
|
||||
try {
|
||||
@@ -312,6 +292,7 @@ function harness(
|
||||
} catch {
|
||||
/* a test may already have destroyed it */
|
||||
}
|
||||
engine.destroy();
|
||||
uninstallRenderGovernor(viewer);
|
||||
_resetRenderGovernorForTest();
|
||||
globalThis.fetch = originalFetch;
|
||||
@@ -321,11 +302,31 @@ function harness(
|
||||
else globalThis.window = originalWindow;
|
||||
});
|
||||
|
||||
const frame = () => {
|
||||
frameTime += 16;
|
||||
engine.fake.emit('frames.preUpdate', frameTime);
|
||||
engine.fake.emit('frames.preRender', frameTime);
|
||||
};
|
||||
const markerSets = () => {
|
||||
const state = layer._transitStateForTest();
|
||||
return new Map(
|
||||
[
|
||||
['transit', state._markers],
|
||||
['transit-motion', state._animatedMarkers],
|
||||
].filter(([, collection]) => collection),
|
||||
);
|
||||
};
|
||||
return {
|
||||
layer,
|
||||
viewer,
|
||||
primitives,
|
||||
sprites,
|
||||
engine,
|
||||
get display() {
|
||||
return display;
|
||||
},
|
||||
/** The marker collections by sprite-order id, while the layer has them. */
|
||||
get sprites() {
|
||||
return markerSets();
|
||||
},
|
||||
pickOwners,
|
||||
overlaySources,
|
||||
credits,
|
||||
@@ -338,9 +339,7 @@ function harness(
|
||||
},
|
||||
state: () => layer._transitStateForTest(),
|
||||
vehicles: () => [...layer._transitStateForTest()._vehicles.values()],
|
||||
frame() {
|
||||
preRender.raiseEvent();
|
||||
},
|
||||
frame,
|
||||
advance(ms) {
|
||||
t.mock.timers.tick(ms);
|
||||
},
|
||||
@@ -355,11 +354,11 @@ function harness(
|
||||
const until = Date.now() + ms;
|
||||
while (Date.now() + step <= until) {
|
||||
t.mock.timers.tick(step);
|
||||
preRender.raiseEvent();
|
||||
frame();
|
||||
}
|
||||
if (Date.now() < until) {
|
||||
t.mock.timers.tick(until - Date.now());
|
||||
preRender.raiseEvent();
|
||||
frame();
|
||||
}
|
||||
},
|
||||
holds: () => getRenderGovernorDiagnostics().holds,
|
||||
@@ -381,7 +380,7 @@ function harness(
|
||||
// a test about how long a sweep waits.
|
||||
parts.rendering.refreshVisibility();
|
||||
t.mock.timers.tick(16);
|
||||
preRender.raiseEvent();
|
||||
frame();
|
||||
}
|
||||
},
|
||||
/** What the style manager dispatches when the user picks a preset. */
|
||||
@@ -396,10 +395,47 @@ function harness(
|
||||
new CustomEvent('gev:vision-change', { detail: { style, cockpit } }),
|
||||
);
|
||||
},
|
||||
/** Move the camera's view rectangle, the way a real camera move would. */
|
||||
/**
|
||||
* Pan the camera over the centre of `next` at its height and report
|
||||
* `next` as its view rectangle, the way a real camera move would.
|
||||
*/
|
||||
lookAt(next) {
|
||||
Object.assign(viewRect, next);
|
||||
cameraChanged.raiseEvent();
|
||||
const height = engine.camera.height();
|
||||
engine.fake.setPose({
|
||||
longitude: Cesium.Math.toRadians((viewRect.west + viewRect.east) / 2),
|
||||
latitude: Cesium.Math.toRadians((viewRect.south + viewRect.north) / 2),
|
||||
height,
|
||||
});
|
||||
engine.fake.emit('camera.changed', 1);
|
||||
},
|
||||
/** The view rectangle the camera reports (undefined: none). */
|
||||
setViewRectangle(next) {
|
||||
viewRectangle = next;
|
||||
},
|
||||
/** The rendered terrain under a point (a globe with terrain shown). */
|
||||
setTerrain(heightAt) {
|
||||
terrain = (cartographic) =>
|
||||
heightAt(
|
||||
Cesium.Math.toDegrees(cartographic.latitude),
|
||||
Cesium.Math.toDegrees(cartographic.longitude),
|
||||
);
|
||||
},
|
||||
/** Places the camera (degrees and metres; angles in radians). */
|
||||
aim({ lat, lon, height, heading = 0, pitch = -Math.PI / 2, roll = 0 }) {
|
||||
engine.fake.setPose({
|
||||
longitude: Cesium.Math.toRadians(lon),
|
||||
latitude: Cesium.Math.toRadians(lat),
|
||||
height,
|
||||
heading,
|
||||
pitch,
|
||||
roll,
|
||||
});
|
||||
},
|
||||
/** A click at `position` whose pick is `picked`. */
|
||||
click(position, picked) {
|
||||
engine.fake.script('pick', picked);
|
||||
engine.fake.input('click', { position });
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -910,26 +946,32 @@ test('destroy releases every shared registration this layer took', async (t) =>
|
||||
}));
|
||||
app.layer.enable(app.viewer);
|
||||
await app.layer.update();
|
||||
await app.display.whenReady();
|
||||
assert.ok(app.sprites.has('transit'));
|
||||
assert.ok(app.pickOwners.has('transit'));
|
||||
assert.equal(app.primitives.length, 2);
|
||||
assert.deepEqual(
|
||||
app.engine.movers.list().map(({ id, count }) => [id, count]),
|
||||
[['transit-1', 1]],
|
||||
'the stationary fleet is one sprite set',
|
||||
);
|
||||
|
||||
app.layer.destroy(app.viewer);
|
||||
assert.equal(
|
||||
app.sprites.has('transit'),
|
||||
false,
|
||||
'the sprite collection is unregistered',
|
||||
'the marker collections are released',
|
||||
);
|
||||
assert.equal(
|
||||
app.pickOwners.has('transit'),
|
||||
false,
|
||||
'the pick owner is released',
|
||||
);
|
||||
assert.equal(
|
||||
app.primitives.length,
|
||||
0,
|
||||
'the primitive collection leaves the scene',
|
||||
assert.deepEqual(
|
||||
app.engine.movers.list(),
|
||||
[],
|
||||
'the sprite sets leave the scene',
|
||||
);
|
||||
assert.deepEqual(app.engine.lines.list(), []);
|
||||
assert.equal(app.holds().includes('transit'), false);
|
||||
assert.equal(app.state()._viewer, null);
|
||||
assert.equal(app.state()._dataManager, null);
|
||||
@@ -938,7 +980,8 @@ test('destroy releases every shared registration this layer took', async (t) =>
|
||||
test('two layers built from the factory share no state', async (t) => {
|
||||
const app = harness(t);
|
||||
const second = createTransitLayer({
|
||||
rendererFactory: createTransitCesiumRenderer,
|
||||
rendererFactory: ({ engine, ...context }) =>
|
||||
createTransitDisplay(engine, { ...context, drawAtlas: transitTestAtlas }),
|
||||
services: {
|
||||
ground: groundStub(() => 12),
|
||||
render: {
|
||||
@@ -946,11 +989,6 @@ test('two layers built from the factory share no state', async (t) => {
|
||||
holdContinuousRender,
|
||||
releaseContinuousRender,
|
||||
},
|
||||
sprites: {
|
||||
registerSpriteCollection() {},
|
||||
unregisterSpriteCollection() {},
|
||||
restoreSpriteOrder() {},
|
||||
},
|
||||
picking: { registerPickOwner() {}, unregisterPickOwner() {} },
|
||||
overlays: {
|
||||
setOverlayEntries() {},
|
||||
@@ -2307,16 +2345,16 @@ test('the floor cycle samples the rendered mesh for the cells it warms, with its
|
||||
'the sampler was asked after the floor resolved',
|
||||
);
|
||||
const call = app.meshCalls[0];
|
||||
assert.equal(call.scene, app.viewer.scene);
|
||||
assert.equal(call.target, app.engine);
|
||||
assert.deepEqual(
|
||||
call.points.map((p) => p.lat).sort(),
|
||||
[42.36, 42.37],
|
||||
'the in-view cells, and not the one off screen',
|
||||
);
|
||||
assert.equal(
|
||||
call.options.excludeObjects.length,
|
||||
2,
|
||||
'both in-view billboards excluded',
|
||||
assert.deepEqual(
|
||||
call.options.excludeObjects.map((set) => set.count()),
|
||||
[3],
|
||||
'the sprite set holding the fleet is excluded',
|
||||
);
|
||||
assert.ok(
|
||||
Math.abs(call.options.viewerLat - BOSTON.lat) < 1e-6,
|
||||
@@ -2673,7 +2711,8 @@ test('a long selected history shortens its oldest geometry before sacrificing th
|
||||
});
|
||||
|
||||
test('sparse rail reports preserve a bounded marker corridor with and without selection', async (t) => {
|
||||
const app = harness(t);
|
||||
// High enough that the 16 km run south of the camera stays in view.
|
||||
const app = harness(t, { altitude: 50_000 });
|
||||
const parts = app.layer._transitPartsForTest();
|
||||
const { seek } = await import('../../data/contactPlayback.js');
|
||||
let latitude = 42.36 - 16000 / 111320;
|
||||
@@ -2731,7 +2770,7 @@ test('sparse rail reports preserve a bounded marker corridor with and without se
|
||||
|
||||
test('missing rectangle still rejects the far side, and frustum rejection wins', async (t) => {
|
||||
const app = harness(t, { altitude: 100_000 });
|
||||
app.viewer.camera.computeViewRectangle = () => undefined;
|
||||
app.setViewRectangle(() => undefined);
|
||||
app.serve('mbta', () => ({
|
||||
status: 200,
|
||||
body: snapshot(
|
||||
@@ -2752,11 +2791,8 @@ test('missing rectangle still rejects the far side, and frustum rejection wins',
|
||||
[...app.state()._visible].map((e) => e.record.id),
|
||||
['near'],
|
||||
);
|
||||
app.viewer.camera.frustum = {
|
||||
computeCullingVolume: () => ({
|
||||
computeVisibility: () => Cesium.Intersect.OUTSIDE,
|
||||
}),
|
||||
};
|
||||
// The camera turns to the sky: the frustum holds no vehicle.
|
||||
app.aim({ ...BOSTON, height: 100_000, pitch: 0.5 });
|
||||
app.advance(250);
|
||||
app.layer._transitPartsForTest().rendering.refreshVisibility();
|
||||
assert.equal(app.state()._visible.size, 0);
|
||||
@@ -2827,7 +2863,11 @@ test('every styling path retains the mode palette and exact unpadded size', asyn
|
||||
const entry = app.vehicles()[0],
|
||||
parts = app.layer._transitPartsForTest();
|
||||
const check = (hex, display) => {
|
||||
assert.equal(entry.marker.color.toCssHexString().toUpperCase(), hex);
|
||||
const { red, green, blue, alpha } = entry.marker.color;
|
||||
assert.equal(
|
||||
new Cesium.Color(red, green, blue, alpha).toCssHexString().toUpperCase(),
|
||||
hex,
|
||||
);
|
||||
const svg = Buffer.from(
|
||||
entry.marker.image.split(',')[1],
|
||||
'base64',
|
||||
@@ -2877,11 +2917,8 @@ test('visible motion is recullable without a camera event and releases its hold
|
||||
await app.layer.update();
|
||||
app.layer._loadTransitFleetForTest(1, BOSTON, 1);
|
||||
assert.equal(app.state()._moving.size, 1);
|
||||
app.viewer.camera.frustum = {
|
||||
computeCullingVolume: () => ({
|
||||
computeVisibility: () => Cesium.Intersect.OUTSIDE,
|
||||
}),
|
||||
};
|
||||
// The camera turns to the sky: the frustum holds no vehicle.
|
||||
app.aim({ ...BOSTON, height: 30000, pitch: 0.5 });
|
||||
app.layer._transitPartsForTest().rendering.maintainPresentation();
|
||||
app.advance(250);
|
||||
assert.equal(app.state()._moving.size, 0);
|
||||
@@ -3052,11 +3089,6 @@ test('tab visibility synchronizes playback before the returning frame and remove
|
||||
for (const bounds of ['null', 'stale']) {
|
||||
test(`browser visibility starts an injected fleet with ${bounds} bounds and an unsampled hidden marker`, async (t) => {
|
||||
const app = harness(t);
|
||||
app.viewer.camera.frustum = {
|
||||
computeCullingVolume: () => ({
|
||||
computeVisibility: () => Cesium.Intersect.INSIDE,
|
||||
}),
|
||||
};
|
||||
app.layer.enable(app.viewer);
|
||||
const loaded = app.layer._loadTransitFleetForTest(4, BOSTON, 70, [
|
||||
'Red',
|
||||
@@ -3089,8 +3121,7 @@ for (const bounds of ['null', 'stale']) {
|
||||
test('keyless loaded terrain resolves a pending surface without needing a frame first', async (t) => {
|
||||
const app = harness(t, { floorAt: () => undefined });
|
||||
let floor;
|
||||
app.viewer.scene.globe.show = true;
|
||||
app.viewer.scene.globe.getHeight = () => floor;
|
||||
app.setTerrain(() => floor);
|
||||
app.serve('mbta', () => ({
|
||||
status: 200,
|
||||
body: snapshot(
|
||||
@@ -3117,7 +3148,6 @@ test('keyless loaded terrain resolves a pending surface without needing a frame
|
||||
|
||||
test('scripted keyless fleet keeps its known floor through selection and floor rereads', async (t) => {
|
||||
const app = harness(t, { floorAt: () => undefined });
|
||||
app.viewer.scene.globe.show = true;
|
||||
app.layer.enable(app.viewer);
|
||||
app.layer._loadTransitFleetForTest(4, BOSTON, 70);
|
||||
const parts = app.layer._transitPartsForTest(),
|
||||
@@ -3134,27 +3164,11 @@ test('scripted keyless fleet keeps its known floor through selection and floor r
|
||||
for (const count of [800, 3000]) {
|
||||
test(`real perspective frustum admits all ${count} moving budget fixtures`, async (t) => {
|
||||
const altitude = count === 800 ? 600 : 30000;
|
||||
const app = harness(t, { altitude, floorAt: () => undefined });
|
||||
const camera = app.viewer.camera;
|
||||
camera.positionWC = Cesium.Cartesian3.fromDegrees(
|
||||
BOSTON.lon,
|
||||
BOSTON.lat,
|
||||
// Straight down over Boston, 60° across a 1920 × 1080 view.
|
||||
const app = harness(t, {
|
||||
altitude,
|
||||
);
|
||||
camera.directionWC = Cesium.Cartesian3.negate(
|
||||
Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(
|
||||
camera.positionWC,
|
||||
new Cesium.Cartesian3(),
|
||||
),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(camera.positionWC);
|
||||
camera.upWC = Cesium.Matrix4.getColumn(enu, 1, new Cesium.Cartesian3());
|
||||
camera.frustum = new Cesium.PerspectiveFrustum({
|
||||
fov: Math.PI / 3,
|
||||
aspectRatio: 1920 / 1080,
|
||||
near: 1,
|
||||
far: 100000,
|
||||
floorAt: () => undefined,
|
||||
engineOptions: { width: 1920, height: 1080 },
|
||||
});
|
||||
app.layer.enable(app.viewer);
|
||||
const loaded = app.layer._loadTransitFleetForTest(
|
||||
@@ -3178,23 +3192,20 @@ test('click handler selects a migrated scripted billboard and prepares a valid d
|
||||
app.layer._loadTransitFleetForTest(4, BOSTON, 70);
|
||||
const entry = app.vehicles()[0];
|
||||
assert.equal(entry.markerCollection, app.state()._animatedMarkers);
|
||||
app.viewer.scene.pick = () => ({ primitive: entry.marker, id: entry.key });
|
||||
app
|
||||
.state()
|
||||
._clickHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)({
|
||||
position: new Cesium.Cartesian2(500, 400),
|
||||
});
|
||||
assert.equal(app.state()._selectedKey, entry.key);
|
||||
const body = app.layer._transitPartsForTest().trails.diagnostics().body;
|
||||
assert.ok(body.geometryInstances.length > 0);
|
||||
body._batchTableAttributeIndices = { color: 0, depthFailColor: 1 };
|
||||
assert.doesNotThrow(() =>
|
||||
Cesium.Primitive._updateColorAttribute(
|
||||
body,
|
||||
body.depthFailAppearance.vertexShaderSource,
|
||||
true,
|
||||
),
|
||||
await app.display.whenReady();
|
||||
app.click(
|
||||
{ x: 500, y: 400 },
|
||||
{ id: entry.key, owner: 'transit-motion-1', instance: 0 },
|
||||
);
|
||||
assert.equal(app.state()._selectedKey, entry.key);
|
||||
const { body } = app.layer._transitPartsForTest().trails.diagnostics();
|
||||
assert.ok(body.lines > 0);
|
||||
app.frame();
|
||||
// Where the scene hides the trail, its colour lane still draws, dimmed.
|
||||
const lanes = app.engine.lines
|
||||
.list()
|
||||
.map(({ id }) => app.engine.fake.line(id));
|
||||
assert.ok(lanes.some((line) => line.options.depthFailAlpha > 0));
|
||||
assert.ok(entry.trailSegments.length > 0);
|
||||
app.run(1000, 16);
|
||||
assert.equal(entry.marker.show, true);
|
||||
@@ -3242,14 +3253,14 @@ test('hot path reuses sample outputs and reads camera altitude once per frame',
|
||||
const out = new Cesium.Cartesian3();
|
||||
assert.equal(parts.trails.samplePosition(entry, entry.sample, out), out);
|
||||
const sample = entry.sample;
|
||||
const carto = h.viewer.camera.positionCartographic;
|
||||
const pose = h.engine.camera.pose;
|
||||
let reads = 0;
|
||||
Object.defineProperty(h.viewer.camera, 'positionCartographic', {
|
||||
configurable: true,
|
||||
get() {
|
||||
reads++;
|
||||
return carto;
|
||||
},
|
||||
h.engine.camera.pose = () => {
|
||||
reads++;
|
||||
return pose();
|
||||
};
|
||||
t.after(() => {
|
||||
h.engine.camera.pose = pose;
|
||||
});
|
||||
h.advance(17);
|
||||
h.frame();
|
||||
@@ -3265,7 +3276,8 @@ test('hot path reuses sample outputs and reads camera altitude once per frame',
|
||||
});
|
||||
|
||||
test('scripted straight and changing delay preserve ordinary-frame speed through polls', async (t) => {
|
||||
const h = harness(t, { altitude: 600 });
|
||||
// A wide view keeps the 1.6 km run north of the camera on screen.
|
||||
const h = harness(t, { altitude: 600, engineOptions: { fovy: 2.6 } });
|
||||
const start = Date.now();
|
||||
const modes = ['straight', 'gap', 'dup'];
|
||||
h.serve('mbta', () => {
|
||||
@@ -3390,7 +3402,7 @@ test('selected anchor rejects nonfinite marker coordinates before sampling and d
|
||||
assert.equal(card.position(), null);
|
||||
});
|
||||
|
||||
test('preset clicks preserve both pick id paths through moving and stationary collection migration', async (t) => {
|
||||
test('preset clicks select through moving and stationary collection migration', async (t) => {
|
||||
const app = harness(t, { floorAt: () => undefined });
|
||||
app.layer.enable(app.viewer);
|
||||
app.layer._loadTransitFleetForTest(4, BOSTON, 70);
|
||||
@@ -3409,13 +3421,11 @@ test('preset clicks preserve both pick id paths through moving and stationary co
|
||||
animated ? app.state()._animatedMarkers : app.state()._markers,
|
||||
);
|
||||
assert.equal(entry.marker.id, entry.key);
|
||||
for (const pick of [{ id: entry.key }, { primitive: entry.marker }]) {
|
||||
app.viewer.scene.pick = () => pick;
|
||||
app
|
||||
.state()
|
||||
._clickHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)(
|
||||
{ position: new Cesium.Cartesian2(500, 400) },
|
||||
);
|
||||
for (const owner of [
|
||||
undefined,
|
||||
animated ? 'transit-motion-1' : 'transit-1',
|
||||
]) {
|
||||
app.click({ x: 500, y: 400 }, { id: entry.key, owner, instance: 0 });
|
||||
assert.equal(app.state()._selectedKey, entry.key);
|
||||
parts.selection.clearSelection();
|
||||
}
|
||||
@@ -3442,36 +3452,42 @@ test('QA backwards seek reconstructs the pruned fixture paths before allocation
|
||||
});
|
||||
|
||||
test('sensor clicks map displayed pixels into the pre-shader pick buffer', async (t) => {
|
||||
const app = harness(t, { floorAt: () => undefined });
|
||||
// An engine that draws the sensor styles itself (render.style).
|
||||
const app = harness(t, {
|
||||
floorAt: () => undefined,
|
||||
engineOptions: {
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
canvas: { width: 1920, height: 1080 },
|
||||
visualStyles: {
|
||||
surveillance: ['pixelation'],
|
||||
thermal: ['pixelation'],
|
||||
},
|
||||
},
|
||||
});
|
||||
app.layer.enable(app.viewer);
|
||||
app.layer._loadTransitFleetForTest(4, BOSTON, 70);
|
||||
const entry = app.vehicles()[0],
|
||||
scene = app.viewer.scene;
|
||||
const entry = app.vehicles()[0];
|
||||
let actual;
|
||||
scene.pick = (p) => {
|
||||
const pick = (p) => {
|
||||
actual = { x: p.x, y: p.y };
|
||||
return { id: entry.key };
|
||||
};
|
||||
scene.canvas = {
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
clientWidth: 1920,
|
||||
clientHeight: 1080,
|
||||
};
|
||||
const uniforms = { intensity: 1, pixelation: 1 };
|
||||
scene.postProcessStages = {
|
||||
getStageByName: () => ({ enabled: true, uniforms }),
|
||||
};
|
||||
const click = app
|
||||
.state()
|
||||
._clickHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
const click = (position) => app.click(position, pick);
|
||||
app.engine.render.setStyle('surveillance', {
|
||||
intensity: 1,
|
||||
uniforms: { pixelation: 1 },
|
||||
});
|
||||
app.layer._transitPartsForTest().rendering.setStylePreset('surveillance');
|
||||
click({ position: new Cesium.Cartesian2(1440, 540) });
|
||||
click({ x: 1440, y: 540 });
|
||||
assert.ok(Math.abs(actual.x - 1472) < 1e-6);
|
||||
assert.equal(actual.y, 540);
|
||||
app.layer._transitPartsForTest().rendering.setStylePreset('thermal');
|
||||
uniforms.pixelation = 1.5;
|
||||
click({ position: new Cesium.Cartesian2(100.9, 200.1) });
|
||||
app.engine.render.setStyle('thermal', {
|
||||
intensity: 1,
|
||||
uniforms: { pixelation: 1.5 },
|
||||
});
|
||||
click({ x: 100.9, y: 200.1 });
|
||||
assert.ok(Math.abs(actual.x - 100.5) < 1e-6);
|
||||
assert.ok(Math.abs(actual.y - 201) < 1e-6);
|
||||
assert.equal(app.state()._selectedKey, entry.key);
|
||||
@@ -3618,7 +3634,6 @@ test('actual Traffic, Bikeshare and Transit lifecycles retain sensitivity in eve
|
||||
},
|
||||
},
|
||||
).lifecycle.methods;
|
||||
app.viewer.camera.moveEnd = new Cesium.Event();
|
||||
const layers = { traffic, bikeshare: bike, transit: app.layer };
|
||||
const orders = [
|
||||
['traffic', 'bikeshare', 'transit'],
|
||||
@@ -3661,54 +3676,27 @@ test('actual Traffic, Bikeshare and Transit lifecycles retain sensitivity in eve
|
||||
});
|
||||
|
||||
test('moving and stationary transit stay adjacent above CCTV and Bikeshare during migration', async (t) => {
|
||||
const {
|
||||
registerSpriteCollection,
|
||||
unregisterSpriteCollection,
|
||||
restoreSpriteOrder,
|
||||
} = await import('../../data/spriteOrder.js');
|
||||
const { SPRITE_LAYER_ORDER } = await import('../../data/spriteOrder.js');
|
||||
const app = harness(t);
|
||||
app.layer.enable(app.viewer);
|
||||
app.layer._loadTransitFleetForTest(1, BOSTON, 70);
|
||||
const cctv = {},
|
||||
bike = {},
|
||||
flights = {};
|
||||
app.primitives.push(cctv, bike, flights);
|
||||
app.viewer.scene.primitives.raiseToTop = (c) => {
|
||||
app.primitives.splice(app.primitives.indexOf(c), 1);
|
||||
app.primitives.push(c);
|
||||
};
|
||||
const collections = new Map([
|
||||
...app.sprites,
|
||||
['cctv', cctv],
|
||||
['bikeshare', bike],
|
||||
['flights', flights],
|
||||
]);
|
||||
for (const [id, collection] of collections)
|
||||
registerSpriteCollection(id, collection);
|
||||
t.after(() => {
|
||||
for (const [id, c] of collections) unregisterSpriteCollection(id, c);
|
||||
});
|
||||
await app.display.whenReady();
|
||||
const entry = app.vehicles()[0],
|
||||
parts = app.layer._transitPartsForTest();
|
||||
const order = (id) => app.engine.fake.moverSet(id)?.options.order;
|
||||
for (const moving of [true, false, true]) {
|
||||
entry.sample.phase = moving ? 'playing' : 'held';
|
||||
entry.sample.segmentSpeedMps = moving ? 1 : 0;
|
||||
entry.sample.segmentCourseDeg = NaN;
|
||||
parts.rendering.schedulePlayback(entry);
|
||||
restoreSpriteOrder(app.viewer);
|
||||
const active = app.primitives.indexOf(entry.markerCollection);
|
||||
assert.ok(active > app.primitives.indexOf(cctv));
|
||||
assert.ok(active > app.primitives.indexOf(bike));
|
||||
assert.ok(active < app.primitives.indexOf(flights));
|
||||
assert.equal(
|
||||
Math.abs(
|
||||
app.primitives.indexOf(app.state()._markers) -
|
||||
app.primitives.indexOf(app.state()._animatedMarkers),
|
||||
),
|
||||
1,
|
||||
);
|
||||
const active = order(moving ? 'transit-motion-1' : 'transit-1');
|
||||
assert.ok(active > SPRITE_LAYER_ORDER.indexOf('cctv'));
|
||||
assert.ok(active > SPRITE_LAYER_ORDER.indexOf('bikeshare'));
|
||||
assert.ok(active < SPRITE_LAYER_ORDER.indexOf('flights'));
|
||||
assert.equal(entry.marker.id, entry.key);
|
||||
}
|
||||
// Both sets now exist, the moving one directly above the stationary one.
|
||||
assert.equal(order('transit-motion-1') - order('transit-1'), 1);
|
||||
});
|
||||
|
||||
test('transit polls the supplied source and cancels it when disabled', async (t) => {
|
||||
@@ -3788,8 +3776,7 @@ for (const jump of ['setView', 'flyTo']) {
|
||||
test(`${jump} recovers a cold hidden vehicle within one visibility interval`, async (t) => {
|
||||
const app = harness(t, { floorAt: () => undefined });
|
||||
let floor;
|
||||
app.viewer.scene.globe.show = true;
|
||||
app.viewer.scene.globe.getHeight = () => floor;
|
||||
app.setTerrain(() => floor);
|
||||
app.serve('mbta', () => ({
|
||||
status: 200,
|
||||
body: snapshot('mbta', 'MBTA', [
|
||||
@@ -3805,11 +3792,15 @@ for (const jump of ['setView', 'flyTo']) {
|
||||
// timer or preRender is allowed to bootstrap the visibility recovery.
|
||||
clearTimeout(app.state()._floorTimer);
|
||||
app.state()._floorTimer = null;
|
||||
app.viewer.camera[jump] = () => {
|
||||
floor = 12;
|
||||
app.viewer.camera.changed.raiseEvent();
|
||||
};
|
||||
app.viewer.camera[jump]();
|
||||
floor = 12;
|
||||
const destination = Cesium.Cartesian3.fromDegrees(
|
||||
BOSTON.lon,
|
||||
BOSTON.lat,
|
||||
4_000,
|
||||
);
|
||||
if (jump === 'setView') app.engine.camera.setView({ destination });
|
||||
else app.engine.camera.flyTo({ destination, duration: 0 });
|
||||
app.engine.fake.emit('camera.changed', 1);
|
||||
app.advance(250);
|
||||
assert.equal(entry.marker.show, true);
|
||||
assert.equal(entry.heightPending, false);
|
||||
@@ -3841,7 +3832,7 @@ test('selected history is prepared while its head is hidden and remains shown ou
|
||||
app.state()._vehicles.set(entry.key, entry);
|
||||
});
|
||||
|
||||
test('selected draped history prepares geometry before surface heights resolve', async (t) => {
|
||||
test('selected history waits for its surface heights: lines are not draped', async (t) => {
|
||||
const app = harness(t, { floorAt: () => undefined });
|
||||
app.layer.enable(app.viewer);
|
||||
app.layer._loadTransitFleetForTest(1, BOSTON);
|
||||
@@ -3850,20 +3841,12 @@ test('selected draped history prepares geometry before surface heights resolve',
|
||||
delete entry.qaFloorM;
|
||||
entry.marker.show = false;
|
||||
entry.heightPending = true;
|
||||
// Exercise the real GroundPolylinePrimitive branch, without a WebGL context.
|
||||
const width = Cesium.ContextLimits._maximumAliasedLineWidth;
|
||||
Cesium.ContextLimits._maximumAliasedLineWidth = 1;
|
||||
t.after(() => {
|
||||
Cesium.ContextLimits._maximumAliasedLineWidth = width;
|
||||
});
|
||||
app.viewer.scene.frameState = { context: { depthTexture: true } };
|
||||
app.viewer.scene.groundPrimitives = app.viewer.scene.primitives;
|
||||
parts.selection.selectVehicle(entry.key);
|
||||
const trail = parts.trails.diagnostics();
|
||||
assert.equal(trail.ground, true);
|
||||
assert.ok(trail.body instanceof Cesium.GroundPolylinePrimitive);
|
||||
assert.ok(trail.segments > 0);
|
||||
assert.equal(trail.body.show, true);
|
||||
assert.equal(trail.ground, false);
|
||||
assert.equal(trail.segments, 0, 'no history before its floors resolve');
|
||||
assert.equal(trail.body, null);
|
||||
assert.deepEqual(app.engine.lines.list(), []);
|
||||
assert.equal(
|
||||
entry.displayPaths.size,
|
||||
0,
|
||||
@@ -3877,43 +3860,19 @@ test('parked transit reprojects held and reported courses at the bounded camera
|
||||
const { createRendering } = await import('./rendering.js');
|
||||
t.mock.timers.enable({ apis: ['Date'], now: 1000 });
|
||||
const position = Cesium.Cartesian3.fromDegrees(0, 0, 20);
|
||||
const cameraPosition = Cesium.Cartesian3.fromDegrees(0, 0, 1000);
|
||||
const scene = {
|
||||
frameState: { mode: Cesium.SceneMode.SCENE3D },
|
||||
canvas: { clientWidth: 1280, clientHeight: 800 },
|
||||
camera: {
|
||||
positionWC: cameraPosition,
|
||||
heading: 0,
|
||||
const engine = createFakeEngine({ width: 1280, height: 800 });
|
||||
t.after(() => engine.destroy());
|
||||
// Straight down from 1 km; each pose is a new frame.
|
||||
const pose = (heading) => {
|
||||
engine.fake.setPose({
|
||||
longitude: 0,
|
||||
latitude: 0,
|
||||
height: 1000,
|
||||
heading,
|
||||
pitch: -Math.PI / 2,
|
||||
roll: 0,
|
||||
frustum: new Cesium.PerspectiveFrustum({
|
||||
fov: Math.PI / 3,
|
||||
aspectRatio: 1.6,
|
||||
near: 1,
|
||||
far: 1e7,
|
||||
}),
|
||||
},
|
||||
};
|
||||
const pose = (heading) => {
|
||||
const camera = scene.camera;
|
||||
camera.heading = heading;
|
||||
camera.rightWC = new Cesium.Cartesian3(
|
||||
0,
|
||||
Math.cos(heading),
|
||||
-Math.sin(heading),
|
||||
);
|
||||
camera.upWC = new Cesium.Cartesian3(
|
||||
0,
|
||||
Math.sin(heading),
|
||||
Math.cos(heading),
|
||||
);
|
||||
camera.viewMatrix = Cesium.Matrix4.computeView(
|
||||
cameraPosition,
|
||||
new Cesium.Cartesian3(-1, 0, 0),
|
||||
camera.upWC,
|
||||
camera.rightWC,
|
||||
new Cesium.Matrix4(),
|
||||
);
|
||||
});
|
||||
engine.fake.emit('frames.preUpdate', 0);
|
||||
};
|
||||
pose(0);
|
||||
const make = (key, courseDeg, bearing) => ({
|
||||
@@ -3928,7 +3887,6 @@ test('parked transit reprojects held and reported courses at the bounded camera
|
||||
const unknown = make('unknown', null, null);
|
||||
const hidden = make('hidden', 90, 90);
|
||||
const state = {
|
||||
_viewer: { scene },
|
||||
_enabled: true,
|
||||
_vehicles: new Map(
|
||||
[held, reportedOnly, unknown, hidden].map((e) => [e.key, e]),
|
||||
@@ -3942,8 +3900,12 @@ test('parked transit reprojects held and reported courses at the bounded camera
|
||||
_rotationDirty: false,
|
||||
};
|
||||
const noop = () => {};
|
||||
const renderer = createTransitCesiumRenderer({ state, services: {} });
|
||||
renderer.attach(state._viewer);
|
||||
const renderer = createTransitDisplay(engine, {
|
||||
state,
|
||||
services: {},
|
||||
drawAtlas: transitTestAtlas,
|
||||
});
|
||||
renderer.attach();
|
||||
t.after(() => renderer.destroy());
|
||||
const rendering = createRendering({
|
||||
state,
|
||||
|
||||
Reference in new issue
Block a user