mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Listen to the camera through the camera port in the transit layer
Transit lowered the one camera-change threshold every listener shared to 0.05, through a claim ledger. The camera port measures each listener against its own threshold, so Transit now asks for 0.05 on its own port listener, nobody else's trigger changes, and the ledger goes. A new listener measures from the view at the next tick, so the layer looks at the view once more after that tick, and a move made in between is not missed. Disable always removes both subscriptions. The billboards, the occluder and frustum checks and the frame probe still drive Cesium, so the renderer stays on the Cesium list.
This commit is contained in:
1 parent
d513034f3d
commit
b5fa86a20a
11 files changed
+115
-213
No files matched your search
@@ -4629,8 +4629,9 @@ Playback reserves numeric scratch before the first sample, including unknown
|
|||||||
heights, and reuses caller-owned sample and segment storage.
|
heights, and reuses caller-owned sample and segment storage.
|
||||||
|
|
||||||
**Scene work.** Stationary and animated billboards use separate, adjacent
|
**Scene work.** Stationary and animated billboards use separate, adjacent
|
||||||
collections above CCTV and Bikeshare. Traffic, Bikeshare and Transit share camera
|
collections above CCTV and Bikeshare. Transit listens to the camera port at its
|
||||||
sensitivity claims; the original sensitivity returns after the last release.
|
own `changed` threshold (0.05); the port measures each listener separately, so no
|
||||||
|
layer changes another's camera trigger.
|
||||||
Visibility checks combine the camera frustum and ellipsoid occlusion at no more
|
Visibility checks combine the camera frustum and ellipsoid occlusion at no more
|
||||||
than 4 Hz; missing map bounds do not admit the globe's far side. Camera arrivals
|
than 4 Hz; missing map bounds do not admit the globe's far side. Camera arrivals
|
||||||
rebuild an unprepared or cold marker corridor during that visibility sweep,
|
rebuild an unprepared or cold marker corridor during that visibility sweep,
|
||||||
|
|||||||
@@ -834,7 +834,6 @@
|
|||||||
"src/tooling/transitProvider.test.mjs",
|
"src/tooling/transitProvider.test.mjs",
|
||||||
"src/app/layers/transit.js",
|
"src/app/layers/transit.js",
|
||||||
"src/data/transitIcons.js",
|
"src/data/transitIcons.js",
|
||||||
"src/data/cameraSensitivity.js",
|
|
||||||
"src/data/contactPlayback.js",
|
"src/data/contactPlayback.js",
|
||||||
"src/data/contactTrailRenderer.js",
|
"src/data/contactTrailRenderer.js",
|
||||||
"src/data/contactTrailRenderer.test.mjs",
|
"src/data/contactTrailRenderer.test.mjs",
|
||||||
|
|||||||
@@ -2169,7 +2169,6 @@
|
|||||||
"installations-layer": {
|
"installations-layer": {
|
||||||
"exports": ["./layers/installations"],
|
"exports": ["./layers/installations"],
|
||||||
"modules": [
|
"modules": [
|
||||||
"src/data/cameraSensitivity.js",
|
|
||||||
"src/data/installationFeedback.js",
|
"src/data/installationFeedback.js",
|
||||||
"src/data/militaryInstallationData.js",
|
"src/data/militaryInstallationData.js",
|
||||||
"src/data/installationNames.js",
|
"src/data/installationNames.js",
|
||||||
@@ -2336,7 +2335,6 @@
|
|||||||
"traffic-layer": {
|
"traffic-layer": {
|
||||||
"exports": ["./layers/traffic"],
|
"exports": ["./layers/traffic"],
|
||||||
"modules": [
|
"modules": [
|
||||||
"src/data/cameraSensitivity.js",
|
|
||||||
"src/data/flowMatch.js",
|
"src/data/flowMatch.js",
|
||||||
"src/data/tomtomTiles.js",
|
"src/data/tomtomTiles.js",
|
||||||
"src/data/trafficBounds.js",
|
"src/data/trafficBounds.js",
|
||||||
@@ -2455,7 +2453,6 @@
|
|||||||
"src/layers/bikeshare/viewport.js",
|
"src/layers/bikeshare/viewport.js",
|
||||||
"src/geo/vector.js",
|
"src/geo/vector.js",
|
||||||
"src/data/inputOwnership.js",
|
"src/data/inputOwnership.js",
|
||||||
"src/data/cameraSensitivity.js",
|
|
||||||
"src/i18n/index.js",
|
"src/i18n/index.js",
|
||||||
"src/i18n/locale.js",
|
"src/i18n/locale.js",
|
||||||
"src/i18n/locales/ar.json",
|
"src/i18n/locales/ar.json",
|
||||||
@@ -3913,7 +3910,6 @@
|
|||||||
"src/layers/transit/state.js",
|
"src/layers/transit/state.js",
|
||||||
"src/layers/transit/testing.js",
|
"src/layers/transit/testing.js",
|
||||||
"src/layers/transit/viewport.js",
|
"src/layers/transit/viewport.js",
|
||||||
"src/data/cameraSensitivity.js",
|
|
||||||
"src/data/contactPlayback.js",
|
"src/data/contactPlayback.js",
|
||||||
"src/data/contactTrailRenderer.js",
|
"src/data/contactTrailRenderer.js",
|
||||||
"src/data/transitProxy.js",
|
"src/data/transitProxy.js",
|
||||||
@@ -4707,7 +4703,6 @@
|
|||||||
"src/layers/transit/state.js",
|
"src/layers/transit/state.js",
|
||||||
"src/layers/transit/testing.js",
|
"src/layers/transit/testing.js",
|
||||||
"src/layers/transit/viewport.js",
|
"src/layers/transit/viewport.js",
|
||||||
"src/data/cameraSensitivity.js",
|
|
||||||
"src/data/contactPlayback.js",
|
"src/data/contactPlayback.js",
|
||||||
"src/data/contactTrailRenderer.js",
|
"src/data/contactTrailRenderer.js",
|
||||||
"src/data/transitProxy.js",
|
"src/data/transitProxy.js",
|
||||||
@@ -5636,7 +5631,6 @@
|
|||||||
"src/geo/vector.js",
|
"src/geo/vector.js",
|
||||||
"src/render/cesium/common.js",
|
"src/render/cesium/common.js",
|
||||||
"src/data/approxDistance.js",
|
"src/data/approxDistance.js",
|
||||||
"src/data/cameraSensitivity.js",
|
|
||||||
"src/data/contactPlayback.js",
|
"src/data/contactPlayback.js",
|
||||||
"src/data/contactTrailRenderer.js",
|
"src/data/contactTrailRenderer.js",
|
||||||
"src/render/color.js",
|
"src/render/color.js",
|
||||||
@@ -5776,7 +5770,6 @@
|
|||||||
"src/geo/polyline.js",
|
"src/geo/polyline.js",
|
||||||
"src/render/cesium/gpuIcons.js",
|
"src/render/cesium/gpuIcons.js",
|
||||||
"src/render/motion/iconMotion.js",
|
"src/render/motion/iconMotion.js",
|
||||||
"src/data/cameraSensitivity.js",
|
|
||||||
"src/data/contactPlayback.js",
|
"src/data/contactPlayback.js",
|
||||||
"src/data/contactTrailRenderer.js",
|
"src/data/contactTrailRenderer.js",
|
||||||
"src/render/color.js",
|
"src/render/color.js",
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
// src/data/cameraSensitivity.js
|
|
||||||
/**
|
|
||||||
* Shared claims on `camera.percentageChanged`.
|
|
||||||
*
|
|
||||||
* `camera.changed` fires once the view has moved by this fraction, and it is a
|
|
||||||
* single number on the camera that every listener in the app shares. Several
|
|
||||||
* layers want it finer than the default — transit asks for 0.05 so it
|
|
||||||
* notices it has entered a coverage area (bikeshare and traffic did too,
|
|
||||||
* before they listened through the renderer's camera port at their own
|
|
||||||
* threshold) — and
|
|
||||||
* each of them used to write the number directly and hand back whatever it
|
|
||||||
* remembered.
|
|
||||||
*
|
|
||||||
* That cannot work, because a number is not an owner. Two layers asking for the
|
|
||||||
* same 0.05 write the same value, so when the first one leaves it sees its own
|
|
||||||
* number still in place, concludes nothing else has claimed it, and restores
|
|
||||||
* the coarse default out from under a layer that is still running. The symptom
|
|
||||||
* is a camera-driven layer that quietly stops noticing the camera: Transit is
|
|
||||||
* turned off and Bikeshare stops loading new cities until something else nudges
|
|
||||||
* it.
|
|
||||||
*
|
|
||||||
* So ownership is tracked explicitly. Claims are named, the camera gets the
|
|
||||||
* finest value anyone has asked for, and the original value returns only when
|
|
||||||
* the last claim is gone. Claiming twice under one name replaces that claim.
|
|
||||||
*
|
|
||||||
* This is bookkeeping, not policy: it never decides what a layer should ask
|
|
||||||
* for, only that nobody's answer is taken away while they still need it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @type {WeakMap<object, {base: number, claims: Map<string, number>}>} */
|
|
||||||
const _cameras = new WeakMap();
|
|
||||||
|
|
||||||
/** The value Cesium starts a camera at, used when the camera reports nothing. */
|
|
||||||
const DEFAULT_PERCENTAGE_CHANGED = 0.5;
|
|
||||||
|
|
||||||
function ledgerFor(camera) {
|
|
||||||
let ledger = _cameras.get(camera);
|
|
||||||
if (!ledger) {
|
|
||||||
const base = Number.isFinite(camera.percentageChanged)
|
|
||||||
? camera.percentageChanged
|
|
||||||
: DEFAULT_PERCENTAGE_CHANGED;
|
|
||||||
ledger = { base, claims: new Map() };
|
|
||||||
_cameras.set(camera, ledger);
|
|
||||||
}
|
|
||||||
return ledger;
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyLedger(camera, ledger) {
|
|
||||||
let value = ledger.base;
|
|
||||||
for (const claimed of ledger.claims.values()) {
|
|
||||||
if (claimed < value) value = claimed;
|
|
||||||
}
|
|
||||||
camera.percentageChanged = value;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ask for a camera-change sensitivity at least as fine as `value`.
|
|
||||||
* @param {object|null|undefined} camera A Cesium camera (or anything with `percentageChanged`).
|
|
||||||
* @param {string} owner Stable claim name, usually the layer id.
|
|
||||||
* @param {number} value Requested `percentageChanged`.
|
|
||||||
* @returns {number|null} The value now in force, or null when there is no camera.
|
|
||||||
*/
|
|
||||||
export function claimCameraSensitivity(camera, owner, value) {
|
|
||||||
if (!camera || !owner || !Number.isFinite(value)) return null;
|
|
||||||
const ledger = ledgerFor(camera);
|
|
||||||
ledger.claims.set(owner, value);
|
|
||||||
return applyLedger(camera, ledger);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Give up one claim. The camera keeps the finest value still claimed by
|
|
||||||
* somebody else, and returns to its original only when none are left.
|
|
||||||
* @param {object|null|undefined} camera
|
|
||||||
* @param {string} owner
|
|
||||||
* @returns {number|null} The value now in force, or null when there is no camera.
|
|
||||||
*/
|
|
||||||
export function releaseCameraSensitivity(camera, owner) {
|
|
||||||
if (!camera || !owner) return null;
|
|
||||||
const ledger = _cameras.get(camera);
|
|
||||||
if (!ledger) return null;
|
|
||||||
if (!ledger.claims.delete(owner)) return camera.percentageChanged;
|
|
||||||
const applied = applyLedger(camera, ledger);
|
|
||||||
if (ledger.claims.size === 0) _cameras.delete(camera);
|
|
||||||
return applied;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Who currently holds a claim. For tests and diagnostics only.
|
|
||||||
* @param {object|null|undefined} camera
|
|
||||||
* @returns {Array<string>}
|
|
||||||
*/
|
|
||||||
export function cameraSensitivityClaims(camera) {
|
|
||||||
const ledger = camera ? _cameras.get(camera) : null;
|
|
||||||
return ledger ? [...ledger.claims.keys()] : [];
|
|
||||||
}
|
|
||||||
@@ -63,9 +63,7 @@ export function createLifecycle({
|
|||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
// "Did the camera move" uses the same quantization as the fleet
|
// "Did the camera move" uses the same quantization as the fleet
|
||||||
// rotation pass's cameraPoseSignature (render/cesium/iconOrientation;
|
// rotation pass's cameraPoseSignature (render/cesium/iconOrientation;
|
||||||
// keep the two in step), read from the camera port's pose, rather than
|
// keep the two in step), read from the camera port's pose.
|
||||||
// camera.changed, whose granularity is globally degraded by other layers
|
|
||||||
// mutating camera.percentageChanged.
|
|
||||||
const poseSig = cameraMotionSignature(layerState.viewer);
|
const poseSig = cameraMotionSignature(layerState.viewer);
|
||||||
if (poseSig !== layerState.lastCameraPoseSig) {
|
if (poseSig !== layerState.lastCameraPoseSig) {
|
||||||
layerState.lastCameraPoseSig = poseSig;
|
layerState.lastCameraPoseSig = poseSig;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { TRANSIT_POLL_MS } from './policy.js';
|
|||||||
* and height maps, the in-flight requests, the manager handle and the overlay
|
* and height maps, the in-flight requests, the manager handle and the overlay
|
||||||
* host all live on the instance this returns, and `destroy()` releases every
|
* host all live on the instance this returns, and `destroy()` releases every
|
||||||
* shared registration it took (sprite collection, pick owner, render hold,
|
* shared registration it took (sprite collection, pick owner, render hold,
|
||||||
* camera sensitivity).
|
* camera listener).
|
||||||
*
|
*
|
||||||
* @param {{services: object}} options
|
* @param {{services: object}} options
|
||||||
* @returns {object} The data-layer module the manager registers.
|
* @returns {object} The data-layer module the manager registers.
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import { TRANSIT_ENABLED_FEEDS } from '../../data/transitFeeds.js';
|
|||||||
/**
|
/**
|
||||||
* Init / enable / disable / update / destroy for one Transit layer instance.
|
* Init / enable / disable / update / destroy for one Transit layer instance.
|
||||||
* Everything acquired here is released here — primitives, listeners, the sprite
|
* Everything acquired here is released here — primitives, listeners, the sprite
|
||||||
* registration, the pick owner, the render hold, and the camera sensitivity
|
* registration, the pick owner, the render hold, and the camera listener.
|
||||||
* this layer borrowed.
|
|
||||||
* @param {object} context
|
* @param {object} context
|
||||||
* @returns {object}
|
* @returns {object}
|
||||||
*/
|
*/
|
||||||
@@ -139,7 +138,8 @@ export function createLifecycle({ state, services, parts }) {
|
|||||||
registerPickOwner('transit', (pickedId) => state._vehicles.has(pickedId));
|
registerPickOwner('transit', (pickedId) => state._vehicles.has(pickedId));
|
||||||
if (!state._cameraChangedAttached) {
|
if (!state._cameraChangedAttached) {
|
||||||
parts.rendering.watchCamera(viewer, parts.viewport.onCameraChanged);
|
parts.rendering.watchCamera(viewer, parts.viewport.onCameraChanged);
|
||||||
state._cameraChangedAttached = true;
|
// Attached only with a camera to listen to, so a later enable retries.
|
||||||
|
state._cameraChangedAttached = state._cameraChangedOff !== null;
|
||||||
}
|
}
|
||||||
parts.rendering.startFrames(viewer);
|
parts.rendering.startFrames(viewer);
|
||||||
parts.viewport.runProximityCheck();
|
parts.viewport.runProximityCheck();
|
||||||
@@ -169,10 +169,9 @@ export function createLifecycle({ state, services, parts }) {
|
|||||||
state._overlayHost.setVisible(TRANSIT_SELECTED_OVERLAY_SOURCE_ID, false);
|
state._overlayHost.setVisible(TRANSIT_SELECTED_OVERLAY_SOURCE_ID, false);
|
||||||
parts.selection.removeClickHandler();
|
parts.selection.removeClickHandler();
|
||||||
unregisterPickOwner('transit');
|
unregisterPickOwner('transit');
|
||||||
if (state._cameraChangedAttached) {
|
// Unconditional: whatever watching started, none of it outlives this.
|
||||||
parts.rendering.unwatchCamera(viewer, parts.viewport.onCameraChanged);
|
parts.rendering.unwatchCamera();
|
||||||
state._cameraChangedAttached = false;
|
state._cameraChangedAttached = false;
|
||||||
}
|
|
||||||
parts.rendering.stopFrames();
|
parts.rendering.stopFrames();
|
||||||
parts.ingestion.abortAllInFlight();
|
parts.ingestion.abortAllInFlight();
|
||||||
state._activeFeeds.clear();
|
state._activeFeeds.clear();
|
||||||
|
|||||||
@@ -28,11 +28,6 @@ const lat = (entry) =>
|
|||||||
Cesium.Math.toDegrees(
|
Cesium.Math.toDegrees(
|
||||||
Cesium.Cartographic.fromCartesian(entry.marker.position).latitude,
|
Cesium.Cartographic.fromCartesian(entry.marker.position).latitude,
|
||||||
);
|
);
|
||||||
import {
|
|
||||||
cameraSensitivityClaims,
|
|
||||||
claimCameraSensitivity,
|
|
||||||
releaseCameraSensitivity,
|
|
||||||
} from '../../data/cameraSensitivity.js';
|
|
||||||
import {
|
import {
|
||||||
_resetRenderGovernorForTest,
|
_resetRenderGovernorForTest,
|
||||||
getRenderGovernorDiagnostics,
|
getRenderGovernorDiagnostics,
|
||||||
@@ -209,6 +204,8 @@ function harness(
|
|||||||
|
|
||||||
const preRender = new Cesium.Event();
|
const preRender = new Cesium.Event();
|
||||||
const cameraChanged = new Cesium.Event();
|
const cameraChanged = new Cesium.Event();
|
||||||
|
const cameraListeners = new Set();
|
||||||
|
const preUpdates = new Set();
|
||||||
const viewer = {
|
const viewer = {
|
||||||
camera: {
|
camera: {
|
||||||
changed: cameraChanged,
|
changed: cameraChanged,
|
||||||
@@ -317,7 +314,28 @@ function harness(
|
|||||||
const unbindCamera = bindRenderer(viewer, {
|
const unbindCamera = bindRenderer(viewer, {
|
||||||
draw,
|
draw,
|
||||||
query: fakeSceneQuery(viewer),
|
query: fakeSceneQuery(viewer),
|
||||||
|
// Only the tick the layer's camera listener waits on.
|
||||||
|
frame: {
|
||||||
|
on(phase, cb) {
|
||||||
|
if (phase !== 'preUpdate') return () => {};
|
||||||
|
preUpdates.add(cb);
|
||||||
|
return () => preUpdates.delete(cb);
|
||||||
|
},
|
||||||
|
requestRender() {},
|
||||||
|
},
|
||||||
camera: {
|
camera: {
|
||||||
|
// `changed` listeners, each at its own threshold, fired by the fake
|
||||||
|
// camera's own event as a real camera move fires them.
|
||||||
|
on(event, cb, options = {}) {
|
||||||
|
if (event !== 'changed') return () => {};
|
||||||
|
const listener = { cb, threshold: options.threshold ?? 0.5 };
|
||||||
|
cameraListeners.add(listener);
|
||||||
|
const remove = cameraChanged.addEventListener(cb);
|
||||||
|
return () => {
|
||||||
|
cameraListeners.delete(listener);
|
||||||
|
remove();
|
||||||
|
};
|
||||||
|
},
|
||||||
pose() {
|
pose() {
|
||||||
const carto = viewer.camera.positionCartographic;
|
const carto = viewer.camera.positionCartographic;
|
||||||
return {
|
return {
|
||||||
@@ -365,6 +383,16 @@ function harness(
|
|||||||
layer,
|
layer,
|
||||||
viewer,
|
viewer,
|
||||||
draw,
|
draw,
|
||||||
|
/** One frame tick, as the frame port's `preUpdate` hears it. */
|
||||||
|
tick() {
|
||||||
|
for (const cb of [...preUpdates]) cb({ frame: 0 });
|
||||||
|
},
|
||||||
|
/** Move the view rectangle without the camera reporting the move. */
|
||||||
|
moveQuietly(next) {
|
||||||
|
Object.assign(viewRect, next);
|
||||||
|
},
|
||||||
|
/** The thresholds of the camera port's `changed` listeners. */
|
||||||
|
cameraThresholds: () => [...cameraListeners].map((l) => l.threshold),
|
||||||
input,
|
input,
|
||||||
primitives,
|
primitives,
|
||||||
sprites,
|
sprites,
|
||||||
@@ -878,63 +906,42 @@ test('the render hold follows real motion, and is released when everything settl
|
|||||||
);
|
);
|
||||||
assert.equal(app.viewer.scene.requestRenderMode, true);
|
assert.equal(app.viewer.scene.requestRenderMode, true);
|
||||||
});
|
});
|
||||||
test('disable hands back the camera sensitivity it borrowed', async (t) => {
|
test('the layer listens to the camera at its own fine threshold while enabled', async (t) => {
|
||||||
const app = harness(t);
|
const app = harness(t);
|
||||||
assert.equal(app.viewer.camera.percentageChanged, 0.5);
|
assert.deepEqual(app.cameraThresholds(), []);
|
||||||
app.layer.enable(app.viewer);
|
app.layer.enable(app.viewer);
|
||||||
assert.equal(
|
assert.deepEqual(
|
||||||
app.viewer.camera.percentageChanged,
|
app.cameraThresholds(),
|
||||||
0.05,
|
[0.05],
|
||||||
'the layer needs a finer camera trigger',
|
'the layer needs a finer camera trigger, as its own',
|
||||||
);
|
);
|
||||||
app.layer.disable(app.viewer);
|
|
||||||
assert.equal(app.viewer.camera.percentageChanged, 0.5, 'and gives it back');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('disable leaves the fine camera trigger another layer asked for', async (t) => {
|
|
||||||
// The sequence that broke it: two layers ask for the SAME sensitivity, so
|
|
||||||
// the value on the camera cannot say who owns it. Transit used to compare
|
|
||||||
// the number, find its own 0.05 still there, and hand the coarse default
|
|
||||||
// back while Bikeshare was still driving off the fine one.
|
|
||||||
const app = harness(t);
|
|
||||||
assert.equal(app.viewer.camera.percentageChanged, 0.5);
|
|
||||||
|
|
||||||
app.layer.enable(app.viewer);
|
|
||||||
assert.equal(app.viewer.camera.percentageChanged, 0.05);
|
|
||||||
|
|
||||||
claimCameraSensitivity(app.viewer.camera, 'bikeshare', 0.05);
|
|
||||||
app.layer.disable(app.viewer);
|
|
||||||
|
|
||||||
assert.equal(
|
|
||||||
app.viewer.camera.percentageChanged,
|
|
||||||
0.05,
|
|
||||||
'bikeshare is still enabled, so the fine trigger stays',
|
|
||||||
);
|
|
||||||
assert.deepEqual(cameraSensitivityClaims(app.viewer.camera), ['bikeshare']);
|
|
||||||
|
|
||||||
releaseCameraSensitivity(app.viewer.camera, 'bikeshare');
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
app.viewer.camera.percentageChanged,
|
app.viewer.camera.percentageChanged,
|
||||||
0.5,
|
0.5,
|
||||||
'and the original returns once the last claim is gone',
|
'and leaves the camera every other listener shares as it was',
|
||||||
);
|
|
||||||
assert.deepEqual(cameraSensitivityClaims(app.viewer.camera), []);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('a finer claim wins while it stands, and the coarser one survives it', async (t) => {
|
|
||||||
const app = harness(t);
|
|
||||||
app.layer.enable(app.viewer);
|
|
||||||
claimCameraSensitivity(app.viewer.camera, 'traffic', 0.01);
|
|
||||||
assert.equal(app.viewer.camera.percentageChanged, 0.01);
|
|
||||||
|
|
||||||
releaseCameraSensitivity(app.viewer.camera, 'traffic');
|
|
||||||
assert.equal(
|
|
||||||
app.viewer.camera.percentageChanged,
|
|
||||||
0.05,
|
|
||||||
'transit still needs its own trigger',
|
|
||||||
);
|
);
|
||||||
app.layer.disable(app.viewer);
|
app.layer.disable(app.viewer);
|
||||||
assert.equal(app.viewer.camera.percentageChanged, 0.5);
|
assert.deepEqual(app.cameraThresholds(), [], 'and stops on disable');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a move before the camera listener first measures is still looked at', async (t) => {
|
||||||
|
const app = harness(t);
|
||||||
|
app.layer.enable(app.viewer);
|
||||||
|
// The move lands before the listener's first tick, so it is the view the
|
||||||
|
// listener measures from and never reports.
|
||||||
|
app.moveQuietly({ west: -71.2, south: 10, east: -71.0, north: 10.2 });
|
||||||
|
app.tick();
|
||||||
|
assert.ok(app.state()._viewBounds.south > 40, 'not looked at yet');
|
||||||
|
app.tick();
|
||||||
|
assert.ok(
|
||||||
|
app.state()._viewBounds.south < 11,
|
||||||
|
'looked at once the first tick is past',
|
||||||
|
);
|
||||||
|
app.moveQuietly({ west: -71.2, south: 42.3, east: -71.0, north: 42.5 });
|
||||||
|
app.tick();
|
||||||
|
app.tick();
|
||||||
|
assert.ok(app.state()._viewBounds.south < 11, 'once, not every tick');
|
||||||
|
app.layer.disable(app.viewer);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('destroy releases every shared registration this layer took', async (t) => {
|
test('destroy releases every shared registration this layer took', async (t) => {
|
||||||
@@ -957,6 +964,7 @@ test('destroy releases every shared registration this layer took', async (t) =>
|
|||||||
assert.equal(app.primitives.length, 2);
|
assert.equal(app.primitives.length, 2);
|
||||||
|
|
||||||
app.layer.destroy(app.viewer);
|
app.layer.destroy(app.viewer);
|
||||||
|
assert.deepEqual(app.cameraThresholds(), [], 'the camera listener goes');
|
||||||
assert.equal(
|
assert.equal(
|
||||||
app.sprites.has('transit'),
|
app.sprites.has('transit'),
|
||||||
false,
|
false,
|
||||||
@@ -3617,7 +3625,7 @@ test('reject then selected history backfill cannot resurrect a 111 km displaceme
|
|||||||
assert.equal(entry.track.resets, 0);
|
assert.equal(entry.track.resets, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('the actual Transit lifecycle retains its sensitivity in every enable/disable order, Traffic and Bikeshare among them', async (t) => {
|
test('the actual Transit lifecycle keeps exactly its own camera listener in every enable/disable order, Traffic and Bikeshare among them', async (t) => {
|
||||||
const { createLifecycle: trafficLifecycle } =
|
const { createLifecycle: trafficLifecycle } =
|
||||||
await import('../traffic/lifecycle.js');
|
await import('../traffic/lifecycle.js');
|
||||||
const { createLifecycle: bikeLifecycle } =
|
const { createLifecycle: bikeLifecycle } =
|
||||||
@@ -3696,6 +3704,7 @@ test('the actual Transit lifecycle retains its sensitivity in every enable/disab
|
|||||||
},
|
},
|
||||||
transit: app.layer,
|
transit: app.layer,
|
||||||
};
|
};
|
||||||
|
// Only transit listens on this viewer's camera port.
|
||||||
const claimants = new Set(['transit']);
|
const claimants = new Set(['transit']);
|
||||||
const orders = [
|
const orders = [
|
||||||
['traffic', 'bikeshare', 'transit'],
|
['traffic', 'bikeshare', 'transit'],
|
||||||
@@ -3718,27 +3727,21 @@ test('the actual Transit lifecycle retains its sensitivity in every enable/disab
|
|||||||
assert.equal(trafficCamera.listenerCount('changed'), 1);
|
assert.equal(trafficCamera.listenerCount('changed'), 1);
|
||||||
assert.equal(trafficFrames.size, 1);
|
assert.equal(trafficFrames.size, 1);
|
||||||
}
|
}
|
||||||
assert.equal(
|
|
||||||
app.viewer.camera.percentageChanged,
|
|
||||||
active.size ? 0.05 : 0.5,
|
|
||||||
);
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
new Set(cameraSensitivityClaims(app.viewer.camera)),
|
app.cameraThresholds(),
|
||||||
active,
|
active.has('transit') ? [0.05] : [],
|
||||||
);
|
);
|
||||||
|
assert.equal(app.viewer.camera.percentageChanged, 0.5);
|
||||||
}
|
}
|
||||||
for (const id of disable) {
|
for (const id of disable) {
|
||||||
layers[id].disable(app.viewer);
|
layers[id].disable(app.viewer);
|
||||||
active.delete(id);
|
active.delete(id);
|
||||||
assert.equal(
|
assert.deepEqual(
|
||||||
app.viewer.camera.percentageChanged,
|
app.cameraThresholds(),
|
||||||
active.size ? 0.05 : 0.5,
|
active.has('transit') ? [0.05] : [],
|
||||||
`${enable} / ${disable} after ${id}`,
|
`${enable} / ${disable} after ${id}`,
|
||||||
);
|
);
|
||||||
assert.deepEqual(
|
assert.equal(app.viewer.camera.percentageChanged, 0.5);
|
||||||
new Set(cameraSensitivityClaims(app.viewer.camera)),
|
|
||||||
active,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
assert.equal(bikeCamera.listenerCount('changed'), 0);
|
assert.equal(bikeCamera.listenerCount('changed'), 0);
|
||||||
assert.equal(trafficCamera.listenerCount('changed'), 0);
|
assert.equal(trafficCamera.listenerCount('changed'), 0);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export const ACTIVATION_ENTER_ALTITUDE_M = ACTIVATION_ALTITUDE_M - 150_000;
|
|||||||
export const ACTIVATION_EXIT_ALTITUDE_M = ACTIVATION_ALTITUDE_M + 150_000;
|
export const ACTIVATION_EXIT_ALTITUDE_M = ACTIVATION_ALTITUDE_M + 150_000;
|
||||||
/** Debounce (ms) for camera-change proximity checks. */
|
/** Debounce (ms) for camera-change proximity checks. */
|
||||||
export const CAMERA_DEBOUNCE_MS = 340;
|
export const CAMERA_DEBOUNCE_MS = 340;
|
||||||
/** Camera sensitivity this layer asks for while it is enabled. */
|
/** The `changed` threshold this layer's camera listener asks for. */
|
||||||
export const CAMERA_PERCENTAGE_CHANGED = 0.05;
|
export const CAMERA_PERCENTAGE_CHANGED = 0.05;
|
||||||
/** Extra coverage radius (km) granted to a feed that is already active, so it does not flap at the edge. */
|
/** Extra coverage radius (km) granted to a feed that is already active, so it does not flap at the edge. */
|
||||||
export const RANGE_SLACK_KM = 40;
|
export const RANGE_SLACK_KM = 40;
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ import * as Cesium from 'cesium';
|
|||||||
// The Cesium camera factory: given a viewer of a caller's own, with no
|
// The Cesium camera factory: given a viewer of a caller's own, with no
|
||||||
// renderer bound, the layer's camera reads find a camera port.
|
// renderer bound, the layer's camera reads find a camera port.
|
||||||
import '../../render/cesium/camera.js';
|
import '../../render/cesium/camera.js';
|
||||||
|
import '../../render/cesium/frame.js';
|
||||||
import { webglContext } from '../../render/cesium/internals.js';
|
import { webglContext } from '../../render/cesium/internals.js';
|
||||||
import {
|
import { findCamera, findFrame } from '../../render/rendererOf.js';
|
||||||
claimCameraSensitivity,
|
|
||||||
releaseCameraSensitivity,
|
|
||||||
} from '../../data/cameraSensitivity.js';
|
|
||||||
import {
|
import {
|
||||||
cameraPoseSignature,
|
cameraPoseSignature,
|
||||||
perspectiveProjectedRotation,
|
perspectiveProjectedRotation,
|
||||||
@@ -122,32 +120,39 @@ export function createRendering({ state, services, parts }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listen for the camera moving, borrowing its change sensitivity through
|
* Listen for the camera moving, at this layer's own threshold.
|
||||||
* the shared claim ledger.
|
|
||||||
*
|
*
|
||||||
* `camera.changed` fires on a percentage of the view moving, and this layer
|
* The camera port measures `changed` per listener, so this layer's finer
|
||||||
* needs a finer trigger than the default to notice it has entered a feed's
|
* trigger (it needs to notice it has entered a feed's coverage) is its own
|
||||||
* coverage. It is a single shared number, so the claim is registered by name
|
* and leaves every other listener's untouched.
|
||||||
* rather than written directly: comparing the VALUE on the way out could not
|
|
||||||
* tell this layer's 0.05 from anybody else's, and handing back the coarse
|
|
||||||
* default while Bikeshare was still relying on a fine one was exactly the
|
|
||||||
* bug that produced.
|
|
||||||
* @param {object} viewer
|
* @param {object} viewer
|
||||||
* @param {() => void} onChanged
|
* @param {() => void} onChanged
|
||||||
*/
|
*/
|
||||||
function watchCamera(viewer, onChanged) {
|
function watchCamera(viewer, onChanged) {
|
||||||
viewer.camera.changed.addEventListener(onChanged);
|
unwatchCamera();
|
||||||
claimCameraSensitivity(
|
state._cameraChangedOff =
|
||||||
viewer?.camera,
|
findCamera(viewer)?.on('changed', onChanged, {
|
||||||
'transit',
|
threshold: CAMERA_PERCENTAGE_CHANGED,
|
||||||
CAMERA_PERCENTAGE_CHANGED,
|
}) ?? null;
|
||||||
);
|
// A new listener measures from the view at the next tick, so a move made
|
||||||
|
// before that tick never reaches it: look again once that tick is past.
|
||||||
|
if (!state._cameraChangedOff) return;
|
||||||
|
let ticks = 0;
|
||||||
|
state._cameraFirstTickOff =
|
||||||
|
findFrame(viewer)?.on('preUpdate', () => {
|
||||||
|
if (++ticks < 2) return;
|
||||||
|
state._cameraFirstTickOff?.();
|
||||||
|
state._cameraFirstTickOff = null;
|
||||||
|
onChanged();
|
||||||
|
}) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Stop listening and give the claim up; the camera keeps anyone else's. */
|
/** Stop listening for the camera moving. */
|
||||||
function unwatchCamera(viewer, onChanged) {
|
function unwatchCamera() {
|
||||||
viewer.camera.changed.removeEventListener(onChanged);
|
state._cameraChangedOff?.();
|
||||||
releaseCameraSensitivity(viewer?.camera, 'transit');
|
state._cameraChangedOff = null;
|
||||||
|
state._cameraFirstTickOff?.();
|
||||||
|
state._cameraFirstTickOff = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Run the per-frame glide before each render, once. */
|
/** Run the per-frame glide before each render, once. */
|
||||||
|
|||||||
@@ -36,12 +36,12 @@ export function createState({ services }) {
|
|||||||
state._generation = 0;
|
state._generation = 0;
|
||||||
|
|
||||||
state._cameraChangedAttached = false;
|
state._cameraChangedAttached = false;
|
||||||
|
/** Removes the camera port listener; null when not listening. */
|
||||||
|
state._cameraChangedOff = null;
|
||||||
|
/** Removes the one-shot look after the camera listener's first tick. */
|
||||||
|
state._cameraFirstTickOff = null;
|
||||||
state._cameraDebounceTimer = null;
|
state._cameraDebounceTimer = null;
|
||||||
state._altitudeGateOpen = false;
|
state._altitudeGateOpen = false;
|
||||||
/** Camera sensitivity as we found it, so disable() can hand it back. */
|
|
||||||
state._priorPercentageChanged = null;
|
|
||||||
/** The value this layer actually wrote, for an identity-guarded restore. */
|
|
||||||
state._appliedPercentageChanged = null;
|
|
||||||
|
|
||||||
/** @type {(() => void)|null} */
|
/** @type {(() => void)|null} */
|
||||||
state._preRenderRemove = null;
|
state._preRenderRemove = null;
|
||||||
|
|||||||
Reference in new issue
Block a user