mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
The renderer seam: clicks go to the newest tool, recession and display groups through the contract, drawing at parity with Cesium
- Clicks: when two tools want the globe's clicks, the newest takes them and the older is told and turns itself off; a click is decided when it arrives, and ambient selection fires only when no tool holds the pointer. The "map is busy" paths and their strings are removed. - Recession: the limb fade is shared (src/render/recession.js) and reaches icon and model sets through SetSpec.recede; tuning applies on the next frame. - Display panel groups are published through src/ui/displayGroups.js; the Weather group and src/viewWeather.js are removed. - Draw port: a set whose icons only move is moved in place, and models that did not change are not restyled each frame, so moving fleets cost what they did when drawn directly; an untinted, fully opaque model is drawn without a colour. - Conformance: input.lease.lost checks the new lease inside onLost and reports a throwing onLost; draw.sets.recede covers model sets. - QA scripts read the renderer host instead of internals the seam replaced.
This commit is contained in:
1 parent
a0d299523d
commit
0ab31d4fb8
130 files changed
+5438
-1674
No files matched your search
+26
-103
@@ -20,14 +20,7 @@ import { roadLabel } from '../../data/routeSteps.js';
|
||||
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { hexColor } from '../../render/color.js';
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
import {
|
||||
t,
|
||||
msg,
|
||||
formatNumber,
|
||||
getLocale,
|
||||
translateKnown,
|
||||
} from '../../i18n/index.js';
|
||||
import { pointerOwnerName } from '../../data/pointerOwnerNames.js';
|
||||
import { t, msg, formatNumber, getLocale } from '../../i18n/index.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
formatQuantity,
|
||||
@@ -519,46 +512,6 @@ export function directionsRowControls(state) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Plain names for the tools that can be holding the pointer, and how to leave
|
||||
* each one. A tool missing from here still gets a usable sentence from its id.
|
||||
*/
|
||||
export const POINTER_TOOL_EXITS = Object.freeze({
|
||||
draw: Object.freeze({
|
||||
name: msg('Draw'),
|
||||
leave: msg('press Escape twice to leave Draw'),
|
||||
}),
|
||||
});
|
||||
|
||||
/**
|
||||
* What to say when a globe click cannot be armed because something else owns
|
||||
* the pointer.
|
||||
*
|
||||
* The claim failing used to be silent: the chip simply did not light and the
|
||||
* operator was left to guess which of the open tools was eating the click
|
||||
* (owner field test — he thought Directions was broken). So the message names
|
||||
* the tool and says how to put it down. Pure.
|
||||
* @param {string|null} owner Current pointer-owner id.
|
||||
* @param {'a'|'b'} which Endpoint that was being armed.
|
||||
* @returns {string|null} Toast text, or null when nothing holds the pointer.
|
||||
*/
|
||||
export function pointerBlockedMessage(owner, which) {
|
||||
const id = typeof owner === 'string' ? owner.trim() : '';
|
||||
if (!id || id === DIRECTIONS_POINTER_OWNER) return null;
|
||||
const endpoint = which === 'b' ? 'B' : 'A';
|
||||
const known = POINTER_TOOL_EXITS[id];
|
||||
if (!known)
|
||||
return t('{name} is active — turn {name} off, then set {endpoint}', {
|
||||
name: translateKnown(pointerOwnerName(id)),
|
||||
endpoint,
|
||||
});
|
||||
return t('{name} is active — {leave}, then set {endpoint}', {
|
||||
name: t(known.name),
|
||||
leave: t(known.leave),
|
||||
endpoint,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Which maneuvers get a dot on the globe: every one except departure and
|
||||
* arrival, which the A and B markers already stand for.
|
||||
@@ -675,29 +628,8 @@ export function stepIndexAtDistance(steps, traveledM) {
|
||||
* @returns {object}
|
||||
*/
|
||||
export function directionsStats(state) {
|
||||
const {
|
||||
mode,
|
||||
a,
|
||||
b,
|
||||
status,
|
||||
error,
|
||||
route,
|
||||
lastUpdate,
|
||||
armed,
|
||||
pointerBlocked,
|
||||
} = state;
|
||||
const { mode, a, b, status, error, route, lastUpdate, armed } = state;
|
||||
const source = 'OSM routing'; // English in layer state; the layer row translates it
|
||||
if (pointerBlocked) {
|
||||
return {
|
||||
count: route?.steps.length || 0,
|
||||
lastUpdate,
|
||||
error: msg(
|
||||
'Another map tool is using clicks — close it, then SET A again',
|
||||
),
|
||||
status: 'empty',
|
||||
source,
|
||||
};
|
||||
}
|
||||
if (status === 'routing') {
|
||||
return {
|
||||
count: 0,
|
||||
@@ -970,8 +902,6 @@ export function createDirectionsLayer({ services, source }) {
|
||||
let _renderHeld = false;
|
||||
let _rowControlsListener = null;
|
||||
let _dataManager = null;
|
||||
/** Set when arming failed because another tool holds the pointer. */
|
||||
let _pointerBlocked = false;
|
||||
/**
|
||||
* What `claimPointer` handed back for the claim this layer currently holds, or
|
||||
* null. Held rather than re-derived so the release names THIS claim: a claim
|
||||
@@ -1020,7 +950,6 @@ export function createDirectionsLayer({ services, source }) {
|
||||
lastUpdate: _lastUpdate,
|
||||
selectedStep: _selectedStep,
|
||||
flightStep: _flightStep,
|
||||
pointerBlocked: _pointerBlocked,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1346,11 +1275,14 @@ export function createDirectionsLayer({ services, source }) {
|
||||
* Give the pointer back, but only once the click that consumed it has finished
|
||||
* being dispatched.
|
||||
*
|
||||
* The input dispatcher decides who hears a click before any subscriber runs,
|
||||
* but DOM listeners on the canvas (evidence cards) still run later inside
|
||||
* the SAME browser event. Releasing the claim the instant this layer places
|
||||
* an endpoint would hand that same click to them. A timer, not a microtask:
|
||||
* a microtask checkpoint runs between two DOM listeners, which is exactly the
|
||||
* The input dispatcher decides who hears a click before any subscriber
|
||||
* runs, so its own click subscribers cannot hear this click once it is let
|
||||
* go. DOM `click` listeners on the canvas (the evidence cards) are another
|
||||
* matter: the renderer's click comes from the pointer's `up`, and the
|
||||
* browser's `click` follows inside the SAME input event, where they ask
|
||||
* `isPointerFree()`. Releasing the claim the instant this layer places an
|
||||
* endpoint would hand that same click to them. A timer, not a microtask: a
|
||||
* microtask checkpoint runs between two DOM listeners, which is exactly the
|
||||
* gap this closes.
|
||||
*/
|
||||
function releaseClaimAfterDispatch() {
|
||||
@@ -1368,7 +1300,6 @@ export function createDirectionsLayer({ services, source }) {
|
||||
*/
|
||||
function disarm({ afterDispatch = false } = {}) {
|
||||
_armed = null;
|
||||
_pointerBlocked = false;
|
||||
if (afterDispatch) releaseClaimAfterDispatch();
|
||||
else releaseClaim();
|
||||
}
|
||||
@@ -1403,8 +1334,9 @@ export function createDirectionsLayer({ services, source }) {
|
||||
* Arm (or cancel) a globe click for one endpoint.
|
||||
*
|
||||
* Placement is a TOOL: it takes the pointer so no ambient layer also selects
|
||||
* whatever happened to be under the click. If another tool already holds it,
|
||||
* this refuses — nothing is armed and the row says why.
|
||||
* whatever happened to be under the click. The newest claim takes over: the
|
||||
* tool holding it is told and turns itself off, and a newer tool taking it
|
||||
* disarms this layer.
|
||||
* @param {null|'a'|'b'} which
|
||||
* @returns {boolean} Whether the layer is armed after this call.
|
||||
*/
|
||||
@@ -1413,23 +1345,19 @@ export function createDirectionsLayer({ services, source }) {
|
||||
disarm();
|
||||
return false;
|
||||
}
|
||||
// A claim does not stack, not even under the same name — two live instances
|
||||
// of one tool are two owners. So re-arming for the other endpoint reuses the
|
||||
// lease already held instead of asking for a second one.
|
||||
// Two live instances of one tool are two owners, so a second claim under
|
||||
// the same name would end this layer's own. Re-arming for the other
|
||||
// endpoint reuses the lease already held instead.
|
||||
if (!services.input.isLeaseCurrent(_pointerClaim)) {
|
||||
const lease = services.input.claimPointer(DIRECTIONS_POINTER_OWNER);
|
||||
if (!lease) {
|
||||
_armed = null;
|
||||
_pointerBlocked = true;
|
||||
// The row already says it, but the row is not where the operator is
|
||||
// looking after pressing a chip — say it where the app says everything.
|
||||
const message = pointerBlockedMessage(
|
||||
services.input.pointerOwner(),
|
||||
which,
|
||||
);
|
||||
if (message) _shellSeams?.showToast?.(message);
|
||||
return false;
|
||||
}
|
||||
// The newest claim takes over: a tool holding the pointer is told and
|
||||
// turns itself off, and a newer one disarms this layer as Escape would.
|
||||
const lease = services.input.claimPointer(DIRECTIONS_POINTER_OWNER, {
|
||||
onLost: () => {
|
||||
if (_pointerClaim !== lease) return;
|
||||
disarm();
|
||||
notifyRow();
|
||||
},
|
||||
});
|
||||
_pointerClaim = lease;
|
||||
}
|
||||
// A pending release from the previous placement would otherwise hand the
|
||||
@@ -1438,7 +1366,6 @@ export function createDirectionsLayer({ services, source }) {
|
||||
clearTimeout(_releaseTimer);
|
||||
_releaseTimer = null;
|
||||
}
|
||||
_pointerBlocked = false;
|
||||
_armed = which;
|
||||
_clearStepSelection();
|
||||
return true;
|
||||
@@ -1741,7 +1668,6 @@ export function createDirectionsLayer({ services, source }) {
|
||||
*/
|
||||
enable(viewer) {
|
||||
_enabled = true;
|
||||
_pointerBlocked = false;
|
||||
if (_sets) _sets.steps.show = true;
|
||||
_overlayHost.setVisible(DIRECTIONS_STEP_OVERLAY_SOURCE_ID, true);
|
||||
_overlayHost.setVisible(DIRECTIONS_MARKER_OVERLAY_SOURCE_ID, true);
|
||||
@@ -1839,10 +1765,7 @@ export function createDirectionsLayer({ services, source }) {
|
||||
* the same immediate-navigation facade voice destinations use — so the route
|
||||
* dolly is one more caller of the single camera owner rather than a second
|
||||
* one. `floorFn`/`warmFn` are the shared ground floor the dolly flies over.
|
||||
* `showToast` is the app's own toast, so a refusal is said where the rest of
|
||||
* the UI says things.
|
||||
* @param {{runNavigation?: Function, floorFn?: Function, warmFn?: Function,
|
||||
* showToast?: Function}|null} services
|
||||
* @param {{runNavigation?: Function, floorFn?: Function, warmFn?: Function}|null} services
|
||||
*/
|
||||
attachShellServices(services) {
|
||||
_shellSeams = services || null;
|
||||
|
||||
@@ -20,10 +20,6 @@ const idle = {
|
||||
};
|
||||
|
||||
const cases = [
|
||||
[
|
||||
{ ...idle, pointerBlocked: true },
|
||||
'Another map tool is using clicks — close it, then SET A again',
|
||||
],
|
||||
[{ ...idle, status: 'error' }, 'No route found'],
|
||||
[
|
||||
{ ...idle, status: 'error', error: 'Routing timed out' },
|
||||
|
||||
@@ -123,6 +123,8 @@ export function createIcons({ flightState, services, parts }) {
|
||||
icons._planIcon(icao24, { fromCourseDeg: set.course(icao24, t) });
|
||||
return;
|
||||
}
|
||||
// Following the clock, not drawn at a time before it was there.
|
||||
set.setUnseen(icao24, flightState._drUnseen);
|
||||
const planned = set.expires(icao24) !== -Infinity;
|
||||
const prev = planned ? set.course(icao24, t) : null;
|
||||
// The pin holds the position; the renderer glides the course onto the
|
||||
|
||||
@@ -5,6 +5,14 @@ import { createFlightState } from './state.js';
|
||||
import { createIcons } from './icons.js';
|
||||
import { createContactIcons } from '../../data/aircraftIconLayer.js';
|
||||
import { layerPlacement } from '../../data/placementProvider.js';
|
||||
import {
|
||||
aircraftMotionRegime,
|
||||
createMotionRegime,
|
||||
fixEpochMs,
|
||||
} from '../../data/aircraftMotionRegime.js';
|
||||
import { mergeAircraftTimelineFixes } from '../../data/timelineHistory.js';
|
||||
import { julianFromEpochMs } from '../../geo/julian.js';
|
||||
import { TIMELINE_UNSEEN_MS } from '../../time/timelineFixes.js';
|
||||
|
||||
function services(focus = {}) {
|
||||
return {
|
||||
@@ -300,3 +308,110 @@ test('a live contact a placement places is drawn along where it places it', (t)
|
||||
icons._planIcon('p');
|
||||
assert.deepEqual(asked, []);
|
||||
});
|
||||
|
||||
/**
|
||||
* A layer following the world clock at `world.ms`, its contacts placed by
|
||||
* the shared regime on their own fixes around the time.
|
||||
*/
|
||||
function clockSetup(world) {
|
||||
const fields = { speed: 'velocity', track: 'true_track' };
|
||||
const { flightState, icons, set } = setup({
|
||||
motion: {
|
||||
_displayTimeAt: (ms) => julianFromEpochMs(ms),
|
||||
_fixEpochMs: fixEpochMs,
|
||||
_deadReckon: () => null,
|
||||
_motionRegime: (history, info, renderTime) =>
|
||||
aircraftMotionRegime(
|
||||
history,
|
||||
info,
|
||||
renderTime,
|
||||
fields,
|
||||
createMotionRegime(),
|
||||
),
|
||||
},
|
||||
});
|
||||
flightState.timeline = { active: () => true };
|
||||
flightState.now = () => world.ms;
|
||||
return { flightState, icons, set };
|
||||
}
|
||||
|
||||
/** A contact's row, never planned, and its own fixes at `times` (ms). */
|
||||
function onFixes(flightState, set, id, times) {
|
||||
set.put(
|
||||
{
|
||||
id,
|
||||
pos: { x: 0, y: 0, z: 0 },
|
||||
motion: { kind: 'hold', courseDeg: 0 },
|
||||
course: 0,
|
||||
size: [20, 20],
|
||||
show: true,
|
||||
focus: 1,
|
||||
meta: { layer: 'flights', id },
|
||||
},
|
||||
{ expiresAt: -Infinity },
|
||||
);
|
||||
flightState.records.data.set(id, { velocity: 100 });
|
||||
const history = mergeAircraftTimelineFixes(
|
||||
[],
|
||||
{
|
||||
fixes: times.map((atMs, i) => ({
|
||||
atMs,
|
||||
lat: 30,
|
||||
lon: i * 0.05,
|
||||
altitudeM: null,
|
||||
})),
|
||||
},
|
||||
{ renderAltitudeM: 3_000 },
|
||||
100,
|
||||
times[0],
|
||||
);
|
||||
flightState._positionHistory.set(id, history);
|
||||
return history;
|
||||
}
|
||||
|
||||
test('following the clock, a contact is not drawn before it was there, and is from its warm-up on', () => {
|
||||
const first = Date.UTC(2026, 10, 9, 12);
|
||||
const world = { ms: first - 10 * 60_000 };
|
||||
const { flightState, icons, set } = clockSetup(world);
|
||||
onFixes(flightState, set, 'c', [first, first + 60_000]);
|
||||
icons._planIcon('c');
|
||||
assert.equal(set.shown('c'), false, 'ten minutes before its first fix');
|
||||
assert.equal(set.expires('c'), first - TIMELINE_UNSEEN_MS);
|
||||
|
||||
// Half a minute before its first fix it is drawn, reaching it.
|
||||
world.ms = first - 30_000;
|
||||
icons._replanExpired(world.ms);
|
||||
assert.equal(set.shown('c'), true);
|
||||
|
||||
// The clock moved back: not there yet again.
|
||||
world.ms = first - 5 * 60_000;
|
||||
icons._replanExpired(world.ms);
|
||||
assert.equal(set.shown('c'), false);
|
||||
});
|
||||
|
||||
test('following the clock, a move back within the fixes draws a contact where it was then', () => {
|
||||
const t0 = Date.UTC(2026, 10, 9, 12);
|
||||
const world = { ms: t0 + 100_000 };
|
||||
const { flightState, icons, set } = clockSetup(world);
|
||||
const history = onFixes(flightState, set, 'c', [
|
||||
t0,
|
||||
t0 + 60_000,
|
||||
t0 + 120_000,
|
||||
]);
|
||||
icons._planIcon('c');
|
||||
icons._replanExpired(world.ms);
|
||||
// Back to half way between the first two fixes.
|
||||
world.ms = t0 + 30_000;
|
||||
icons._replanExpired(world.ms);
|
||||
const drawn = set.position('c', world.ms);
|
||||
const half = Cesium.Cartesian3.distance(
|
||||
history[0].position,
|
||||
history[1].position,
|
||||
);
|
||||
for (const fix of history.slice(0, 2))
|
||||
assert.ok(
|
||||
Math.abs(Cesium.Cartesian3.distance(drawn, fix.position) - half / 2) <
|
||||
half * 0.05,
|
||||
'half way between its first two fixes',
|
||||
);
|
||||
});
|
||||
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Wind streamlines baked from a wind grid (`streamlines.js`): the paths a
|
||||
* `windStreamlines` field draws.
|
||||
*/
|
||||
|
||||
/** A wind grid: row-major from `la1` (north) southward. */
|
||||
export interface WindGrid {
|
||||
u: Float32Array;
|
||||
v: Float32Array;
|
||||
nx: number;
|
||||
ny: number;
|
||||
lo1: number;
|
||||
la1: number;
|
||||
dx: number;
|
||||
dy: number;
|
||||
}
|
||||
|
||||
export interface WindPath {
|
||||
coordinates: Array<[lon: number, lat: number]>;
|
||||
speed: number;
|
||||
seed: number;
|
||||
phase: number;
|
||||
}
|
||||
|
||||
export const WIND_PATH_LIMIT: number;
|
||||
export const WIND_NARROW_PATH_LIMIT: number;
|
||||
export const WIND_PATH_STEPS: number;
|
||||
export const WIND_DISPLAY_HEIGHT_METERS: number;
|
||||
export const WIND_CELL_DEGREES: number;
|
||||
|
||||
/**
|
||||
* Bake streamlines once from a wind grid; with `bounds` (degrees), seeds
|
||||
* fall inside it and paths stop at its edges.
|
||||
*/
|
||||
export function bakeWindStreamlines(
|
||||
grid: WindGrid,
|
||||
options?: {
|
||||
count?: number;
|
||||
steps?: number;
|
||||
stepSeconds?: number;
|
||||
bounds?: {
|
||||
west: number;
|
||||
south: number;
|
||||
east: number;
|
||||
north: number;
|
||||
} | null;
|
||||
},
|
||||
): WindPath[];
|
||||
|
||||
/** Group baked paths by their middle coordinate. */
|
||||
export function groupWindPaths(
|
||||
paths: WindPath[],
|
||||
cellDegrees?: number,
|
||||
): Array<{ id: number; paths: WindPath[] }>;
|
||||
Reference in new issue
Block a user