mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 11:12:18 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6c241a68e | ||
|
|
f42980a04d |
No files matched your search
@@ -1,5 +0,0 @@
|
||||
- Fix rendering stopping for good after a wheel zoom with the pointer on the
|
||||
centre of a whole-globe view. Cesium's zoom could ask the camera to rotate
|
||||
about a zero axis; that rotation is now ignored, and a render loop stopped by
|
||||
any error is restarted from the last drawn camera pose, up to three times in
|
||||
ten seconds (mazy1998, #1704).
|
||||
@@ -0,0 +1,3 @@
|
||||
- Shorten the freeze when Submarine cables is switched on from about 1.4 s to
|
||||
about 0.2 s. Landing markers are now shown a few dozen per frame instead of
|
||||
all at once (mazy1998, #1707).
|
||||
@@ -8158,6 +8158,12 @@ Cesium's multipart suffixes. Each segment gets its own feature's styling, click
|
||||
destination and horizon-culling reference, and each source feature has one
|
||||
reference stem. The source collections are not modified.
|
||||
|
||||
Landing markers are ground-clamped billboards, and Cesium reads the terrain
|
||||
height as it creates each one. They start hidden and the horizon sweep shows
|
||||
the visible ones 48 per rendered frame (`CABLE_LANDING_REVEALS_PER_FRAME`),
|
||||
so switching the layer on does not do every read in one task; hiding is still
|
||||
immediate.
|
||||
|
||||
Natural Earth regions and neighborhood polygon lookup are package exports.
|
||||
Their existing lazy loaders, retry behavior, bundled datasets and attribution
|
||||
are unchanged. The cable dataset remains CC BY-NC-SA 3.0 and is not covered by
|
||||
|
||||
@@ -207,7 +207,6 @@
|
||||
"modules": [
|
||||
"src/app/viewer.js",
|
||||
"src/app/atmosphereCompat.js",
|
||||
"src/app/renderRecovery.js",
|
||||
"src/globeInView.js",
|
||||
"src/sky/starrySky.js",
|
||||
"src/sky/stars.js",
|
||||
@@ -2611,7 +2610,6 @@
|
||||
"src/sky/starrySky.js",
|
||||
"src/sky/stars.js",
|
||||
"src/app/atmosphereCompat.js",
|
||||
"src/app/renderRecovery.js",
|
||||
"src/bloom.js",
|
||||
"src/camera.js",
|
||||
"src/cameraGroundGuard.js",
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
/**
|
||||
* Keeps one bad frame from stopping the globe for good.
|
||||
*
|
||||
* Cesium's render loop stops itself on the first error a frame throws and
|
||||
* leaves an error panel over the canvas; nothing restarts it short of a
|
||||
* reload. Two things here:
|
||||
*
|
||||
* 1. `guardDegenerateRotation` removes one such error at its cause. Zooming
|
||||
* with the wheel above 1,000 km, Cesium turns the globe from the point under
|
||||
* the screen centre towards the point under the pointer
|
||||
* (`ScreenSpaceCameraController` `handleZoom`): it normalizes both points,
|
||||
* takes their dot product, and rotates about their cross product when the
|
||||
* dot product is below 1. With the pointer on the centre pixel the two
|
||||
* points are the same, but a unit vector's dot product with itself often
|
||||
* rounds to 0.9999999999999999, so the check passes and the cross product is
|
||||
* the zero vector. `Camera.rotate` then normalizes it and throws
|
||||
* "normalized result is not a number" from `Scene.initializeFrame`, which
|
||||
* runs outside the scene's own error handling. Builds without Cesium's
|
||||
* debug checks would write NaN into the camera instead.
|
||||
*
|
||||
* 2. `installRenderRecovery` restarts the loop after any error that stops it,
|
||||
* from the last pose a frame was drawn with, a bounded number of times.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { governorRequestRender } from '../renderGovernor.js';
|
||||
|
||||
/** Restarts allowed within RECOVERY_WINDOW_MS before the error is left to stand. */
|
||||
export const RECOVERY_LIMIT = 3;
|
||||
/** An error that keeps coming back this fast is not one a restart gets past. */
|
||||
export const RECOVERY_WINDOW_MS = 10_000;
|
||||
|
||||
/**
|
||||
* Make `camera.rotate` ignore an axis it cannot normalize (zero or not finite)
|
||||
* and an angle that is not finite. There is nothing to rotate about, so the
|
||||
* camera stays where it is and the caller carries on; Cesium's wheel zoom
|
||||
* still moves the camera in after the skipped turn.
|
||||
* @param {Cesium.Camera} camera
|
||||
* @returns {() => void} Restore the camera's own rotate.
|
||||
*/
|
||||
export function guardDegenerateRotation(camera) {
|
||||
const own = Object.hasOwn(camera, 'rotate');
|
||||
const rotate = camera.rotate;
|
||||
const guarded = function (axis, angle) {
|
||||
if (axis) {
|
||||
const magnitudeSquared = Cesium.Cartesian3.magnitudeSquared(axis);
|
||||
if (
|
||||
!(magnitudeSquared > 0) ||
|
||||
!Number.isFinite(magnitudeSquared) ||
|
||||
(angle !== undefined && !Number.isFinite(angle))
|
||||
)
|
||||
return;
|
||||
}
|
||||
return rotate.call(this, axis, angle);
|
||||
};
|
||||
camera.rotate = guarded;
|
||||
return () => {
|
||||
if (camera.rotate !== guarded) return;
|
||||
if (own) camera.rotate = rotate;
|
||||
else delete camera.rotate;
|
||||
};
|
||||
}
|
||||
|
||||
function finite(cartesian) {
|
||||
return (
|
||||
Number.isFinite(cartesian?.x) &&
|
||||
Number.isFinite(cartesian?.y) &&
|
||||
Number.isFinite(cartesian?.z)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart Cesium's render loop when an error stops it.
|
||||
*
|
||||
* Cesium reports a stopped loop only through `showErrorPanel`: errors thrown
|
||||
* while a frame is prepared (camera input, in `Scene.initializeFrame`) never
|
||||
* reach `scene.renderError`, so that event alone would miss them. The panel
|
||||
* call is the one place both kinds of stop pass through, after the loop is
|
||||
* already off.
|
||||
*
|
||||
* On a stop this puts the camera back on the last pose a frame was drawn
|
||||
* with, discards the input that was being applied (Cesium skips its own reset
|
||||
* when the frame throws, so the same gesture would otherwise run again), and
|
||||
* turns the loop back on. After RECOVERY_LIMIT restarts inside
|
||||
* RECOVERY_WINDOW_MS the error is shown as before and rendering stays stopped.
|
||||
* @param {Cesium.Viewer} viewer
|
||||
* @param {object} [options]
|
||||
* @param {() => number} [options.now]
|
||||
* @param {(reason: string) => void} [options.requestRender]
|
||||
* @returns {() => void} Idempotent disposer.
|
||||
*/
|
||||
export function installRenderRecovery(
|
||||
viewer,
|
||||
{ now = () => performance.now(), requestRender = governorRequestRender } = {},
|
||||
) {
|
||||
const widget = viewer?.cesiumWidget;
|
||||
const scene = viewer?.scene;
|
||||
const camera = viewer?.camera;
|
||||
if (!widget?.showErrorPanel || !scene?.postRender || !camera)
|
||||
throw new TypeError('A complete Cesium viewer is required');
|
||||
|
||||
// The pose of the last frame that drew: three vector copies a frame.
|
||||
const position = new Cesium.Cartesian3();
|
||||
const direction = new Cesium.Cartesian3();
|
||||
const up = new Cesium.Cartesian3();
|
||||
let hasPose = false;
|
||||
const removePostRender = scene.postRender.addEventListener(() => {
|
||||
if (!finite(camera.position) || !finite(camera.direction)) return;
|
||||
Cesium.Cartesian3.clone(camera.position, position);
|
||||
Cesium.Cartesian3.clone(camera.direction, direction);
|
||||
Cesium.Cartesian3.clone(camera.up, up);
|
||||
hasPose = true;
|
||||
});
|
||||
|
||||
const recoveredAt = [];
|
||||
const own = Object.hasOwn(widget, 'showErrorPanel');
|
||||
const showErrorPanel = widget.showErrorPanel;
|
||||
const recovering = function (title, message, error) {
|
||||
const at = now();
|
||||
while (recoveredAt.length && at - recoveredAt[0] > RECOVERY_WINDOW_MS)
|
||||
recoveredAt.shift();
|
||||
// Only a stopped loop is restarted; other panels (a failed start-up, a
|
||||
// caller's own message) are shown as they are.
|
||||
if (
|
||||
viewer.useDefaultRenderLoop !== false ||
|
||||
recoveredAt.length >= RECOVERY_LIMIT
|
||||
)
|
||||
return showErrorPanel.call(this, title, message, error);
|
||||
recoveredAt.push(at);
|
||||
console.error(
|
||||
`[viewer] render loop stopped by an error; restarting (${recoveredAt.length} of ${RECOVERY_LIMIT})`,
|
||||
error,
|
||||
);
|
||||
if (hasPose) {
|
||||
Cesium.Cartesian3.clone(position, camera.position);
|
||||
Cesium.Cartesian3.clone(direction, camera.direction);
|
||||
Cesium.Cartesian3.clone(up, camera.up);
|
||||
Cesium.Cartesian3.cross(camera.direction, camera.up, camera.right);
|
||||
}
|
||||
// Cesium has no public way to drop the input a failed frame left queued.
|
||||
scene.screenSpaceCameraController?._aggregator?.reset?.();
|
||||
viewer.useDefaultRenderLoop = true;
|
||||
requestRender('render-recovery');
|
||||
};
|
||||
widget.showErrorPanel = recovering;
|
||||
|
||||
let active = true;
|
||||
return () => {
|
||||
if (!active) return;
|
||||
active = false;
|
||||
removePostRender?.();
|
||||
if (widget.showErrorPanel !== recovering) return;
|
||||
if (own) widget.showErrorPanel = showErrorPanel;
|
||||
else delete widget.showErrorPanel;
|
||||
};
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import {
|
||||
guardDegenerateRotation,
|
||||
installRenderRecovery,
|
||||
RECOVERY_LIMIT,
|
||||
RECOVERY_WINDOW_MS,
|
||||
} from './renderRecovery.js';
|
||||
|
||||
/** Cesium's own Camera.rotate on a camera-shaped object, with no scene behind it. */
|
||||
function cameraFixture() {
|
||||
const camera = Object.create(Cesium.Camera.prototype);
|
||||
camera.position = new Cesium.Cartesian3(28_378_137, 0, 0);
|
||||
camera.direction = new Cesium.Cartesian3(-1, 0, 0);
|
||||
camera.up = new Cesium.Cartesian3(0, 0, 1);
|
||||
camera.right = new Cesium.Cartesian3(0, 1, 0);
|
||||
camera._adjustOrthographicFrustum = () => {};
|
||||
return camera;
|
||||
}
|
||||
|
||||
const pose = (camera) =>
|
||||
[camera.position, camera.direction, camera.up, camera.right].map((v) =>
|
||||
Cesium.Cartesian3.clone(v),
|
||||
);
|
||||
|
||||
test("the wheel zoom's own arithmetic hands Camera.rotate a zero axis", () => {
|
||||
// What handleZoom computes with the pointer on the centre pixel: the same
|
||||
// picked point twice. The dot product rounds below 1, the cross product is 0.
|
||||
const picked = Cesium.Cartesian3.fromDegrees(-41.11, -13.37);
|
||||
const pickedNormal = Cesium.Cartesian3.normalize(
|
||||
picked,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const centreNormal = Cesium.Cartesian3.normalize(
|
||||
picked,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const axis = Cesium.Cartesian3.cross(
|
||||
pickedNormal,
|
||||
centreNormal,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
assert.deepEqual([axis.x, axis.y, axis.z], [0, 0, 0]);
|
||||
|
||||
const unguarded = cameraFixture();
|
||||
assert.throws(() => unguarded.rotate(axis, 0.01), /not a number/);
|
||||
|
||||
const camera = cameraFixture();
|
||||
const before = pose(camera);
|
||||
guardDegenerateRotation(camera);
|
||||
assert.doesNotThrow(() => camera.rotate(axis, 0.01));
|
||||
assert.deepEqual(pose(camera), before);
|
||||
});
|
||||
|
||||
test('an axis or angle that is not finite leaves the camera where it is', () => {
|
||||
const camera = cameraFixture();
|
||||
const before = pose(camera);
|
||||
guardDegenerateRotation(camera);
|
||||
camera.rotate(new Cesium.Cartesian3(NaN, 0, 1), 0.01);
|
||||
camera.rotate(new Cesium.Cartesian3(Infinity, 0, 1), 0.01);
|
||||
camera.rotate(Cesium.Cartesian3.UNIT_Z, NaN);
|
||||
camera.rotate(Cesium.Cartesian3.UNIT_Z, Infinity);
|
||||
assert.deepEqual(pose(camera), before);
|
||||
});
|
||||
|
||||
test('an ordinary rotation is exactly what Cesium does unguarded', () => {
|
||||
const axis = new Cesium.Cartesian3(0.2, -0.5, 0.84);
|
||||
const plain = cameraFixture();
|
||||
plain.rotate(axis, 0.37);
|
||||
plain.rotate(Cesium.Cartesian3.UNIT_Z);
|
||||
|
||||
const camera = cameraFixture();
|
||||
const restore = guardDegenerateRotation(camera);
|
||||
camera.rotate(axis, 0.37);
|
||||
// No angle: Cesium's default amount still applies.
|
||||
camera.defaultRotateAmount = plain.defaultRotateAmount;
|
||||
camera.rotate(Cesium.Cartesian3.UNIT_Z);
|
||||
assert.deepEqual(pose(camera), pose(plain));
|
||||
|
||||
restore();
|
||||
assert.equal(Object.hasOwn(camera, 'rotate'), false);
|
||||
assert.equal(camera.rotate, Cesium.Camera.prototype.rotate);
|
||||
});
|
||||
|
||||
/** Vector equality as Cesium has it: a recomputed right vector may hold -0. */
|
||||
function assertPose(camera, expected) {
|
||||
pose(camera).forEach((vector, i) =>
|
||||
assert.ok(Cesium.Cartesian3.equals(vector, expected[i]), `vector ${i}`),
|
||||
);
|
||||
}
|
||||
|
||||
function viewerFixture() {
|
||||
const postRender = new Cesium.Event();
|
||||
const panels = [];
|
||||
const resets = [];
|
||||
const camera = cameraFixture();
|
||||
const viewer = {
|
||||
camera,
|
||||
useDefaultRenderLoop: true,
|
||||
cesiumWidget: {
|
||||
showErrorPanel(title, message, error) {
|
||||
panels.push({ title, message, error });
|
||||
},
|
||||
},
|
||||
scene: {
|
||||
postRender,
|
||||
screenSpaceCameraController: {
|
||||
_aggregator: { reset: () => resets.push(true) },
|
||||
},
|
||||
},
|
||||
};
|
||||
// What Cesium's loop does when a frame throws.
|
||||
const fail = (error = new Error('frame failed')) => {
|
||||
viewer.useDefaultRenderLoop = false;
|
||||
viewer.cesiumWidget.showErrorPanel('Rendering has stopped.', undefined, error);
|
||||
};
|
||||
return { viewer, camera, postRender, panels, resets, fail };
|
||||
}
|
||||
|
||||
function quietly(run) {
|
||||
const original = console.error;
|
||||
const logged = [];
|
||||
console.error = (...args) => logged.push(args);
|
||||
try {
|
||||
run();
|
||||
} finally {
|
||||
console.error = original;
|
||||
}
|
||||
return logged;
|
||||
}
|
||||
|
||||
test('a stopped render loop restarts from the last drawn pose', () => {
|
||||
const { viewer, camera, postRender, panels, resets, fail } = viewerFixture();
|
||||
const requests = [];
|
||||
installRenderRecovery(viewer, {
|
||||
now: () => 0,
|
||||
requestRender: (reason) => requests.push(reason),
|
||||
});
|
||||
postRender.raiseEvent();
|
||||
const drawn = pose(camera);
|
||||
|
||||
// The failed frame left the camera unusable.
|
||||
camera.position.x = NaN;
|
||||
camera.direction.y = NaN;
|
||||
const error = new Error('normalized result is not a number');
|
||||
const logged = quietly(() => fail(error));
|
||||
|
||||
assert.equal(viewer.useDefaultRenderLoop, true);
|
||||
assert.deepEqual(panels, []);
|
||||
assertPose(camera, drawn);
|
||||
assert.deepEqual(resets, [true]);
|
||||
assert.deepEqual(requests, ['render-recovery']);
|
||||
assert.equal(logged.length, 1);
|
||||
assert.equal(logged[0][1], error);
|
||||
});
|
||||
|
||||
test('a frame drawn with a broken camera is not kept as the pose to return to', () => {
|
||||
const { viewer, camera, postRender, fail } = viewerFixture();
|
||||
installRenderRecovery(viewer, { now: () => 0, requestRender: () => {} });
|
||||
postRender.raiseEvent();
|
||||
const drawn = pose(camera);
|
||||
camera.position.x = NaN;
|
||||
postRender.raiseEvent();
|
||||
quietly(() => fail());
|
||||
assertPose(camera, drawn);
|
||||
});
|
||||
|
||||
test('an error that keeps returning is shown and rendering stays stopped', () => {
|
||||
const { viewer, panels, fail } = viewerFixture();
|
||||
let at = 0;
|
||||
installRenderRecovery(viewer, { now: () => at, requestRender: () => {} });
|
||||
quietly(() => {
|
||||
for (let i = 0; i < RECOVERY_LIMIT; i++) {
|
||||
at += 100;
|
||||
fail();
|
||||
assert.equal(viewer.useDefaultRenderLoop, true, `restart ${i + 1}`);
|
||||
}
|
||||
at += 100;
|
||||
fail();
|
||||
});
|
||||
assert.equal(viewer.useDefaultRenderLoop, false);
|
||||
assert.equal(panels.length, 1);
|
||||
assert.equal(panels[0].title, 'Rendering has stopped.');
|
||||
|
||||
// Once the window has passed, a later, unrelated error is recovered again.
|
||||
at += RECOVERY_WINDOW_MS + 1;
|
||||
quietly(() => fail());
|
||||
assert.equal(viewer.useDefaultRenderLoop, true);
|
||||
assert.equal(panels.length, 1);
|
||||
});
|
||||
|
||||
test('a panel shown while the loop is running is left alone', () => {
|
||||
const { viewer, panels, resets } = viewerFixture();
|
||||
installRenderRecovery(viewer, { now: () => 0, requestRender: () => {} });
|
||||
viewer.cesiumWidget.showErrorPanel('Error constructing CesiumWidget.', 'x');
|
||||
assert.equal(panels.length, 1);
|
||||
assert.deepEqual(resets, []);
|
||||
});
|
||||
|
||||
test('disposing restores the widget and stops recording poses', () => {
|
||||
const { viewer, postRender, panels, fail } = viewerFixture();
|
||||
const original = viewer.cesiumWidget.showErrorPanel;
|
||||
const dispose = installRenderRecovery(viewer, {
|
||||
now: () => 0,
|
||||
requestRender: () => {},
|
||||
});
|
||||
assert.equal(postRender.numberOfListeners, 1);
|
||||
dispose();
|
||||
dispose();
|
||||
assert.equal(postRender.numberOfListeners, 0);
|
||||
assert.equal(viewer.cesiumWidget.showErrorPanel, original);
|
||||
fail();
|
||||
assert.equal(viewer.useDefaultRenderLoop, false);
|
||||
assert.equal(panels.length, 1);
|
||||
});
|
||||
|
||||
test('an incomplete viewer is refused', () => {
|
||||
assert.throws(() => installRenderRecovery({}), TypeError);
|
||||
});
|
||||
@@ -1,9 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { applyModelAtmosphereWorkaround } from './atmosphereCompat.js';
|
||||
import {
|
||||
guardDegenerateRotation,
|
||||
installRenderRecovery,
|
||||
} from './renderRecovery.js';
|
||||
import { StarrySky } from '../sky/starrySky.js';
|
||||
import {
|
||||
FREE_LOOK_MAX_HEIGHT_METERS,
|
||||
@@ -419,11 +415,6 @@ export function createApplicationViewer({ container, creditContainer }) {
|
||||
if (globalThis.matchMedia?.('(pointer: coarse)').matches)
|
||||
viewer.scene.screenSpaceCameraController.zoomFactor *= 3;
|
||||
limitZoomOut(viewer);
|
||||
// Cesium's wheel zoom can hand the camera a zero rotation axis and stop
|
||||
// the render loop for good; and whatever else stops it, restart it rather
|
||||
// than leave the globe dead until a reload. See app/renderRecovery.js.
|
||||
guardDegenerateRotation(viewer.camera);
|
||||
installRenderRecovery(viewer);
|
||||
// Before any tile builds a draw command: Cesium's per-vertex model
|
||||
// atmosphere fails to LINK on Apple's Metal backend and kills the
|
||||
// render loop. See app/atmosphereCompat.js.
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import * as Cesium from 'cesium';
|
||||
import { MAP_STACKS } from '../mapStackController.js';
|
||||
import { CABLE_LANDING_REVEALS_PER_FRAME } from '../layers/submarineCables/policy.js';
|
||||
import {
|
||||
CABLE_LABEL_DEPTH_DECISION,
|
||||
CABLE_OVERLAY_COLLISION_CAPACITY,
|
||||
@@ -2003,3 +2004,62 @@ test('every bundled cable segment is associated with its source feature', async
|
||||
env.layer.destroy(env.viewer);
|
||||
}
|
||||
});
|
||||
|
||||
test('landing markers are revealed a few per frame, never all in one', async () => {
|
||||
// Node has no canvas for GeoJSON point pins, so short lines stand in for
|
||||
// the markers (see createRealCableLayerHarness); the staging is the same.
|
||||
const count = CABLE_LANDING_REVEALS_PER_FRAME * 2 + 10;
|
||||
const landingPoints = Array.from({ length: count }, (_, i) => {
|
||||
const lon = -45 + (i % 20) * 0.5;
|
||||
const lat = 30 + Math.floor(i / 20);
|
||||
return {
|
||||
type: 'Feature',
|
||||
id: `landing-${i}`,
|
||||
properties: { id: `landing-${i}`, name: `Landing ${i}` },
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: [
|
||||
[lon, lat],
|
||||
[lon + 0.01, lat + 0.01],
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
const env = await createRealCableLayerHarness({
|
||||
source: geometrySource([], landingPoints),
|
||||
});
|
||||
try {
|
||||
let renderRequests = 0;
|
||||
env.viewer.scene.requestRender = () => {
|
||||
renderRequests++;
|
||||
};
|
||||
const entities = env.dataSources[1].entities.values;
|
||||
const shown = () => entities.filter((entity) => entity.show).length;
|
||||
assert.equal(entities.length, count);
|
||||
assert.equal(shown(), 0, 'nothing is shown before the first sweep');
|
||||
|
||||
env.raiseSweep();
|
||||
assert.equal(shown(), CABLE_LANDING_REVEALS_PER_FRAME);
|
||||
assert.ok(renderRequests > 0, 'another frame is asked for');
|
||||
env.raiseSweep();
|
||||
assert.equal(shown(), CABLE_LANDING_REVEALS_PER_FRAME * 2);
|
||||
env.raiseSweep();
|
||||
assert.equal(shown(), count, 'every visible marker ends up shown');
|
||||
|
||||
renderRequests = 0;
|
||||
env.raiseSweep();
|
||||
assert.equal(renderRequests, 0, 'a finished reveal asks for no frames');
|
||||
|
||||
// Markers over the horizon are hidden at once and are not revealed.
|
||||
env.viewer.camera.positionWC = Cesium.Cartesian3.fromDegrees(
|
||||
140,
|
||||
-35,
|
||||
4_500_000,
|
||||
);
|
||||
for (const fn of env.listeners.moveEnd) fn();
|
||||
env.raiseSweep();
|
||||
assert.equal(shown(), 0);
|
||||
} finally {
|
||||
env.layer.destroy(env.viewer);
|
||||
}
|
||||
});
|
||||
@@ -185,6 +185,10 @@ export function createIngestion({ state, parts, source }) {
|
||||
if (!reference) return;
|
||||
|
||||
parts.rendering.styleLandingEntity(entity, feature);
|
||||
// Hidden until the sweep reveals it: a shown landing marker reads the
|
||||
// terrain height as Cesium creates it, and all of them at once froze
|
||||
// the page (see CABLE_LANDING_REVEALS_PER_FRAME).
|
||||
entity.show = false;
|
||||
parts.interaction.registerPickEntity(entity, {
|
||||
kind: 'landing-point',
|
||||
reference,
|
||||
@@ -193,6 +197,7 @@ export function createIngestion({ state, parts, source }) {
|
||||
state._surfaceRecords.push({
|
||||
entity,
|
||||
base: Cesium.Cartesian3.fromDegrees(reference.lon, reference.lat, 0),
|
||||
staged: true,
|
||||
});
|
||||
if (landingReferences.has(index)) return;
|
||||
landingReferences.add(index);
|
||||
|
||||
@@ -38,12 +38,10 @@ export function createLifecycle({ state, parts, source, mapStackEventTarget }) {
|
||||
// never emit moveEnd — reach the motion fallback. No render is
|
||||
// requested for a fallback sweep: it only fires while the camera is
|
||||
// already moving, so frames are flowing by construction.
|
||||
if (
|
||||
!state._enabled ||
|
||||
!state._loaded ||
|
||||
!state._referenceSweepGate.shouldRun(viewer.camera)
|
||||
)
|
||||
return;
|
||||
if (!state._enabled || !state._loaded) return;
|
||||
// Landing markers left over from the last sweep, a few per frame.
|
||||
parts.rendering.revealLandingMarkers();
|
||||
if (!state._referenceSweepGate.shouldRun(viewer.camera)) return;
|
||||
parts.rendering.updateReferenceVisibility();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -66,6 +66,16 @@ export const CABLE_LABEL_DEPTH_DECISION = Object.freeze({
|
||||
depthTested: false,
|
||||
});
|
||||
|
||||
/**
|
||||
* Landing markers shown per rendered frame. Each one is a ground-clamped
|
||||
* billboard, and Cesium reads the terrain height when it creates one.
|
||||
* Showing all 1,917 in the frame after the layer was switched on did those
|
||||
* reads in a single task (measured 1.2 s on a loaded globe); a few dozen per
|
||||
* frame keeps each frame short and the markers still fill in within a second.
|
||||
*/
|
||||
|
||||
export const CABLE_LANDING_REVEALS_PER_FRAME = 48;
|
||||
|
||||
/**
|
||||
* `MAP_STACKS` ids that render imagery on the SHOWN Cesium globe (the ion
|
||||
* Bing stacks + OSM). Deliberately an explicit allowlist, not "anything that
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
probeTranslucentMarkerBlend,
|
||||
commitTranslucentMarkerBlend,
|
||||
} from './surface.js';
|
||||
import { CABLE_LANDING_REVEALS_PER_FRAME } from './policy.js';
|
||||
import {
|
||||
clampLabel,
|
||||
createCableOverlayEntry,
|
||||
@@ -40,6 +41,7 @@ export function createRendering({ state }) {
|
||||
state._referenceDataSource = null;
|
||||
state._referenceRecords = [];
|
||||
state._surfaceRecords = [];
|
||||
state._pendingLandingReveals.length = 0;
|
||||
state._pickByEntity = new WeakMap();
|
||||
state._referenceLabelCount = 0;
|
||||
state._publishScratch.length = 0;
|
||||
@@ -201,6 +203,26 @@ export function createRendering({ state }) {
|
||||
state._referenceRecords.push(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the next few landing markers the last sweep found visible, and ask
|
||||
* for another frame while any are left. Called from the sweep and then once
|
||||
* per rendered frame, so a parked camera costs nothing once the list is
|
||||
* empty.
|
||||
*/
|
||||
|
||||
function revealLandingMarkers() {
|
||||
const pending = state._pendingLandingReveals;
|
||||
if (!pending.length) return;
|
||||
let budget = CABLE_LANDING_REVEALS_PER_FRAME;
|
||||
while (pending.length && budget > 0) {
|
||||
const record = pending.pop();
|
||||
if (!record.visible || record.entity.show) continue;
|
||||
record.entity.show = true;
|
||||
budget--;
|
||||
}
|
||||
if (pending.length) state._viewer?.scene?.requestRender?.();
|
||||
}
|
||||
|
||||
function updateReferenceVisibility() {
|
||||
if (!state._enabled || !state._viewer?.camera) return;
|
||||
const cameraPos = state._viewer.camera.positionWC;
|
||||
@@ -224,12 +246,16 @@ export function createRendering({ state }) {
|
||||
if (visible)
|
||||
updateCableReferenceStem(record, cameraPos, canvasHeight, fov);
|
||||
}
|
||||
state._pendingLandingReveals.length = 0;
|
||||
for (const record of state._surfaceRecords) {
|
||||
const visible = occluder.isPointVisible(record.base);
|
||||
if (record.entity.show !== visible) {
|
||||
record.entity.show = visible;
|
||||
}
|
||||
record.visible = visible;
|
||||
if (record.entity.show === visible) continue;
|
||||
// Landing markers are shown a few per frame; hiding is immediate.
|
||||
if (visible && record.staged) state._pendingLandingReveals.push(record);
|
||||
else record.entity.show = visible;
|
||||
}
|
||||
revealLandingMarkers();
|
||||
const winners = selectCableReferenceLabelWinners(state._referenceRecords);
|
||||
let changed = winners.length !== state._lastPublishedCount;
|
||||
for (let i = 0; i < winners.length; i++) {
|
||||
@@ -269,6 +295,7 @@ export function createRendering({ state }) {
|
||||
applyCableClassification,
|
||||
styleLandingEntity,
|
||||
addReferenceStem,
|
||||
revealLandingMarkers,
|
||||
updateReferenceVisibility,
|
||||
};
|
||||
}
|
||||
@@ -51,6 +51,11 @@ export function createState({ sweepClock, overlayHost }) {
|
||||
|
||||
state._surfaceRecords = [];
|
||||
|
||||
/** Landing records the last sweep found visible but not shown yet; drained
|
||||
* a few per frame (CABLE_LANDING_REVEALS_PER_FRAME). */
|
||||
|
||||
state._pendingLandingReveals = [];
|
||||
|
||||
state._clickHandler = null;
|
||||
|
||||
state._preRenderRemover = null;
|
||||
|
||||
Reference in new issue
Block a user