mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
Merge main into fix/earthquake-click-details
Resolves conflicts with main: a world focus target's own range past its framed radius replaces the kind's range (#1832), so a quake asks for its own range only past M6 and the earthquake framing stays its floor; FIRMS keeps main's marker stand-in under the card-on-top rule; launches keep main's label click and also read the card on top through the pick registry.
This commit is contained in:
commit
e87aa5190d
1337 files changed
+38638
-9950
No files matched your search
@@ -173,14 +173,15 @@ export function createRailCockpitSubject({
|
||||
|
||||
/**
|
||||
* Which way the train runs along its shape: as its binding learnt it from
|
||||
* successive reports, else from its drawn course against the line's
|
||||
* bearing there; 0 while neither tells.
|
||||
* successive reports, else from its operator's last reported bearing
|
||||
* against the line's bearing there; 0 while neither tells. Not the drawn
|
||||
* course: before the binding tells, that course is GPS jitter.
|
||||
*/
|
||||
function directionOf(entry) {
|
||||
const binding = entry.path;
|
||||
if (binding.direction === 1 || binding.direction === -1)
|
||||
return binding.direction;
|
||||
const course = finiteOrNull(entry.courseDeg);
|
||||
const course = finiteOrNull(binding.bearingDeg);
|
||||
const point = pointAtS(binding.path, binding.drawS, scratch);
|
||||
if (course === null || !Number.isFinite(point?.bearingDeg)) return 0;
|
||||
const turn = Math.abs(((course - point.bearingDeg + 540) % 360) - 180);
|
||||
@@ -205,8 +206,12 @@ export function createRailCockpitSubject({
|
||||
finiteOrNull(drawn?.lat) ?? finiteOrNull(sample?.lat) ?? record.lat;
|
||||
position.longitude =
|
||||
finiteOrNull(drawn?.lon) ?? finiteOrNull(sample?.lon) ?? record.lon;
|
||||
position.railHeightM = Number.isFinite(drawn?.h) ? drawn.h - liftM : null;
|
||||
position.heightQuality = Number.isFinite(drawn?.q) ? drawn.q : 0;
|
||||
const quality = Number.isFinite(drawn?.q) ? drawn.q : 0;
|
||||
// Quality 0: no floor known here, so no height; a view waits for the
|
||||
// surface.
|
||||
position.railHeightM =
|
||||
quality > 0 && Number.isFinite(drawn.h) ? drawn.h - liftM : null;
|
||||
position.heightQuality = quality;
|
||||
position.atMs = finiteOrNull(drawn?.at);
|
||||
|
||||
let path = null;
|
||||
|
||||
@@ -44,6 +44,13 @@ const PACK = Object.freeze({
|
||||
routes: { R1: [0] },
|
||||
});
|
||||
|
||||
/** A floor service that knows the ground everywhere, at 12 m. */
|
||||
const WARM_GROUND = Object.freeze({
|
||||
GROUND_FLOOR_LIFT_M: 1.5,
|
||||
cachedGroundFloor: () => 12,
|
||||
warmGroundFloor() {},
|
||||
});
|
||||
|
||||
/** Two trains on the line, T1 running east and T2 west, a step a poll. */
|
||||
async function onTheLine(t, options = {}) {
|
||||
const app = harness(t, {
|
||||
@@ -76,7 +83,7 @@ const T1 = railTrainKey('mbta-rail', 'T1');
|
||||
const T2 = railTrainKey('mbta-rail', 'T2');
|
||||
|
||||
test('the selected train reads as a snapshot of its place, motion and sources', async (t) => {
|
||||
const app = await onTheLine(t);
|
||||
const app = await onTheLine(t, { ground: WARM_GROUND });
|
||||
assert.equal(app.layer.getSelectedTrain(), null, 'nothing selected');
|
||||
app.parts().selection.selectTrain(T1);
|
||||
const view = app.layer.getSelectedTrain();
|
||||
@@ -105,6 +112,7 @@ test('the selected train reads as a snapshot of its place, motion and sources',
|
||||
assert.equal(view.provenance.positionSource, 'gps');
|
||||
assert.equal(view.provenance.timestampSource, 'vehicle');
|
||||
const drawn = app.entry(T1).drawnHeight;
|
||||
assert.ok(view.position.heightQuality > 0, 'on a known floor');
|
||||
assert.equal(view.position.railHeightM, drawn.h - 1.5);
|
||||
assert.ok(Number.isFinite(view.position.latitude));
|
||||
assert.ok(Array.isArray(view.stops));
|
||||
@@ -129,6 +137,71 @@ const stopList = (...names) =>
|
||||
state: 'upcoming',
|
||||
}));
|
||||
|
||||
test('a train drawn on an unknown floor reports no rail height', async (t) => {
|
||||
// The harness's floor service is always cold: the train is drawn on the
|
||||
// ellipsoid, which is no floor for a view to stand on.
|
||||
const app = await onTheLine(t);
|
||||
app.parts().selection.selectTrain(T1);
|
||||
const view = app.layer.getSelectedTrain();
|
||||
assert.equal(view.position.heightQuality, 0, 'no floor is known');
|
||||
assert.equal(
|
||||
view.position.railHeightM,
|
||||
null,
|
||||
'an unknown floor is no height',
|
||||
);
|
||||
});
|
||||
|
||||
test('a train on a known floor at sea level reports a rail height of 0 m', async (t) => {
|
||||
const app = await onTheLine(t, {
|
||||
ground: { ...WARM_GROUND, cachedGroundFloor: () => 0 },
|
||||
});
|
||||
app.parts().selection.selectTrain(T1);
|
||||
const { position } = app.layer.getSelectedTrain();
|
||||
assert.ok(position.heightQuality > 0, 'the floor is known');
|
||||
assert.equal(position.railHeightM, 0, 'a height, not none');
|
||||
});
|
||||
|
||||
test('a train first seen standing takes no direction from its GPS jitter', async (t) => {
|
||||
// Reports 13 m apart, and the course drawn between them, do not tell which
|
||||
// way it runs; an operator's bearing does.
|
||||
const app = harness(t, { paths: { 'mbta-rail': PACK }, at: BOSTON });
|
||||
let jitterM = 0;
|
||||
app.feeds.set('mbta-rail', () => [
|
||||
train('T1', LAT, LON0 + (1000 + jitterM) / KX),
|
||||
train('T2', LAT, LON0 + (3000 + jitterM) / KX, { bearing: 270 }),
|
||||
]);
|
||||
await app.enable();
|
||||
const seen = [];
|
||||
for (const next of [13, 0, 13, 0, 13, 0]) {
|
||||
jitterM = next;
|
||||
app.run(RAIL_POLL_MS);
|
||||
await app.poll();
|
||||
app.parts().selection.selectTrain(T1);
|
||||
const standing = app.layer.getSelectedTrain().path.direction;
|
||||
app.parts().selection.selectTrain(T2);
|
||||
seen.push([standing, app.layer.getSelectedTrain().path.direction]);
|
||||
}
|
||||
assert.deepEqual(seen, Array(6).fill([0, -1]));
|
||||
});
|
||||
|
||||
test('a standing train keeps its operator’s bearing through reports that leave it out', async (t) => {
|
||||
const app = harness(t, { paths: { 'mbta-rail': PACK }, at: BOSTON });
|
||||
let bearing = 270;
|
||||
app.feeds.set('mbta-rail', () => [
|
||||
train('T1', LAT, LON0 + 1000 / KX, { bearing }),
|
||||
]);
|
||||
await app.enable();
|
||||
const seen = [];
|
||||
for (const next of [270, 270, 270, null, null, null]) {
|
||||
bearing = next;
|
||||
app.run(RAIL_POLL_MS);
|
||||
await app.poll();
|
||||
app.parts().selection.selectTrain(T1);
|
||||
seen.push(app.layer.getSelectedTrain().path.direction);
|
||||
}
|
||||
assert.deepEqual(seen, Array(6).fill(-1));
|
||||
});
|
||||
|
||||
test('a snapshot read again while nothing changed is the one read before', async (t) => {
|
||||
let list = stopList('Alpha', 'Bravo', 'Charlie');
|
||||
const app = await onTheLine(t, {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { FIX_FLAGS } from '../../data/contactPlayback.js';
|
||||
import { pointAtS, projectOnPath } from '../../data/railPaths.js';
|
||||
|
||||
/**
|
||||
@@ -47,14 +48,23 @@ export function pathWindowM(dtMs) {
|
||||
return window > PATH_WINDOW_MAX_M ? NaN : window;
|
||||
}
|
||||
|
||||
/** Arc moved between two reports before it says which way a train runs (m). */
|
||||
const DIRECTION_MIN_M = 1;
|
||||
/**
|
||||
* Arc a train must move before it tells which way it runs (m); a standing
|
||||
* train's GPS jitter stays within it.
|
||||
*/
|
||||
export const DIRECTION_MIN_M = 15;
|
||||
|
||||
/** +1 or -1 for an arc step longer than DIRECTION_MIN_M, else `known`. */
|
||||
function directionOf(step, known) {
|
||||
return Number.isFinite(step) && Math.abs(step) > DIRECTION_MIN_M
|
||||
? Math.sign(step)
|
||||
: known;
|
||||
/**
|
||||
* The direction after one more arc position `s`: once `s` is DIRECTION_MIN_M
|
||||
* or more from `turn.s`, the sign of that move, and `turn.s` moves to `s`.
|
||||
*/
|
||||
function steer(direction, turn, s) {
|
||||
if (!Number.isFinite(s)) return direction;
|
||||
if (!Number.isFinite(turn.s)) turn.s = s;
|
||||
const step = s - turn.s;
|
||||
if (Math.abs(step) < DIRECTION_MIN_M) return direction;
|
||||
turn.s = s;
|
||||
return Math.sign(step);
|
||||
}
|
||||
|
||||
function createBinding(shapeIndex, path, via, s, fix) {
|
||||
@@ -64,14 +74,19 @@ function createBinding(shapeIndex, path, via, s, fix) {
|
||||
via,
|
||||
/**
|
||||
* Which way the drawn train runs along the shape: +1 along it, -1
|
||||
* against it, 0 until two reports or a playback segment tell. Kept until
|
||||
* a rebind. Once playback has placed the train, only playback changes
|
||||
* it: the newest reports run ahead of the drawn train, so a reversal
|
||||
* they show turns it when playback reaches it.
|
||||
* against it, 0 until it has moved DIRECTION_MIN_M (steer). Kept until
|
||||
* a rebind, and while the train stands.
|
||||
* Once a playback segment has told it (`directionPlayed`), only playback
|
||||
* changes it: the newest reports run ahead of the drawn train, so a
|
||||
* reversal they show turns it when playback reaches it.
|
||||
*/
|
||||
direction: 0,
|
||||
/** The direction the last placed playback segment ran, 0 before one. */
|
||||
drawDirection: 0,
|
||||
directionPlayed: false,
|
||||
/** steer() turn points: one for the reports, one for the played segments. */
|
||||
reportTurn: { s },
|
||||
playTurn: { s: NaN, epoch: NaN },
|
||||
/** The newest operator bearing its reports gave (deg), NaN before one. */
|
||||
bearingDeg: Number.isFinite(fix.bearingDeg) ? fix.bearingDeg : NaN,
|
||||
/** Arc and time of the newest report. */
|
||||
fixS: s,
|
||||
fixT: fix.t,
|
||||
@@ -124,7 +139,7 @@ function bestRouteShape(pack, routeId, fix, accept) {
|
||||
*
|
||||
* @param {object} pack From createRailPathPack.
|
||||
* @param {{tripId?: string, routeId?: string}} ids
|
||||
* @param {{t: number, lat: number, lon: number}} fix The newest report.
|
||||
* @param {{t: number, lat: number, lon: number, bearingDeg?: number}} fix The newest report.
|
||||
* @returns {object|null} A binding, or null to keep straight-line motion.
|
||||
*/
|
||||
export function bindTrainPath(pack, { tripId, routeId } = {}, fix) {
|
||||
@@ -146,7 +161,7 @@ export function bindTrainPath(pack, { tripId, routeId } = {}, fix) {
|
||||
/**
|
||||
* Follow a new report on the bound shape.
|
||||
* @param {object} binding
|
||||
* @param {{t: number, lat: number, lon: number}} fix
|
||||
* @param {{t: number, lat: number, lon: number, bearingDeg?: number}} fix
|
||||
* @returns {boolean} False when the report lies off the line: the binding is wrong.
|
||||
*/
|
||||
export function followFix(binding, fix) {
|
||||
@@ -159,8 +174,9 @@ export function followFix(binding, fix) {
|
||||
pathWindowM(fix.t - binding.fixT),
|
||||
);
|
||||
if (!hit || hit.offsetM > PATH_OFF_TRACK_M) return false;
|
||||
if (!binding.drawDirection)
|
||||
binding.direction = directionOf(hit.s - binding.fixS, binding.direction);
|
||||
if (!binding.directionPlayed)
|
||||
binding.direction = steer(binding.direction, binding.reportTurn, hit.s);
|
||||
if (Number.isFinite(fix.bearingDeg)) binding.bearingDeg = fix.bearingDeg;
|
||||
binding.fixS = hit.s;
|
||||
binding.fixT = fix.t;
|
||||
binding.fixLat = fix.lat;
|
||||
@@ -211,7 +227,7 @@ function projectReport(binding, fix, hintS, hintT) {
|
||||
*
|
||||
* @param {object} binding
|
||||
* @param {{fromSeq: number, toSeq: number, fraction: number}} sample Playback sample.
|
||||
* @param {{from: {seq:number, t:number, lat:number, lon:number},
|
||||
* @param {{from: {seq:number, t:number, lat:number, lon:number, flags?:number},
|
||||
* to: {seq:number, t:number, lat:number, lon:number}}} segment The sample's two reports.
|
||||
* @param {{lat?: number, lon?: number, bearingDeg?: number}} out
|
||||
* @returns {boolean} False when the train should stay on its straight-line point.
|
||||
@@ -253,11 +269,15 @@ export function placeOnPath(binding, sample, segment, out) {
|
||||
cache.sTo = sTo;
|
||||
cache.ok = Number.isFinite(sFrom) && Number.isFinite(sTo);
|
||||
if (cache.ok) {
|
||||
binding.drawDirection = directionOf(
|
||||
sTo - sFrom,
|
||||
binding.drawDirection || binding.direction || 0,
|
||||
);
|
||||
binding.direction = binding.drawDirection;
|
||||
const turn = binding.playTurn;
|
||||
// A break or a new epoch is a corrected position, not a move: steer
|
||||
// on from there.
|
||||
if (from.flags & FIX_FLAGS.BREAK || from.epoch !== turn.epoch)
|
||||
turn.s = sFrom;
|
||||
turn.epoch = from.epoch;
|
||||
binding.direction = steer(binding.direction, turn, sFrom);
|
||||
binding.direction = steer(binding.direction, turn, sTo);
|
||||
if (binding.direction) binding.directionPlayed = true;
|
||||
}
|
||||
}
|
||||
if (!cache.ok) return false;
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
FIX_FLAGS,
|
||||
advance,
|
||||
createSample,
|
||||
createTrack,
|
||||
insertFix,
|
||||
readFix,
|
||||
} from '../../data/contactPlayback.js';
|
||||
import { createRailPathPack } from '../../data/railPaths.js';
|
||||
import {
|
||||
PATH_OFF_TRACK_M,
|
||||
@@ -209,8 +217,9 @@ test('a binding learns which way its train runs, and keeps it through a stop', (
|
||||
assert.equal(along.direction, 0, 'one report tells no direction');
|
||||
assert.ok(followFix(along, fix(10_000, 700, 0)));
|
||||
assert.equal(along.direction, 1);
|
||||
// Standing still (under a metre) keeps what it learnt.
|
||||
assert.ok(followFix(along, fix(20_000, 700.4, 0)));
|
||||
// Standing at a stop, its reports jitter back 10 m: it keeps what it
|
||||
// learnt.
|
||||
assert.ok(followFix(along, fix(20_000, 690, 0)));
|
||||
assert.equal(along.direction, 1);
|
||||
const against = bindTrainPath(p, ids, fix(0, 1500, 0));
|
||||
assert.ok(followFix(against, fix(10_000, 1200, 0)));
|
||||
@@ -262,3 +271,185 @@ test('a report that runs back turns the drawn train only when playback does', ()
|
||||
);
|
||||
assert.equal(binding.direction, -1);
|
||||
});
|
||||
|
||||
test('a jump to a corrected position in a new playback epoch is no reversal', () => {
|
||||
const binding = bindTrainPath(
|
||||
pack(),
|
||||
{ tripId: 'full', routeId: 'main' },
|
||||
fix(0, 1000, 0),
|
||||
);
|
||||
const play = (seq, from, to) => {
|
||||
const { sample, segment } = playback(seq, seq + 1, from, to, 0.5);
|
||||
return placeOnPath(binding, sample, segment, {});
|
||||
};
|
||||
assert.ok(play(0, fix(0, 1000, 0), fix(60_000, 1600, 0)));
|
||||
assert.equal(binding.direction, 1);
|
||||
// The source puts it back at 1400 m: a new epoch whose first report is a
|
||||
// break, and no segment is played from 1600 m to there.
|
||||
const epoch = { epoch: 1 };
|
||||
assert.ok(
|
||||
play(
|
||||
5,
|
||||
{ ...fix(70_000, 1400, 0), ...epoch, flags: FIX_FLAGS.BREAK },
|
||||
{ ...fix(85_000, 1400, 0), ...epoch },
|
||||
),
|
||||
);
|
||||
assert.equal(binding.direction, 1, 'standing there, it keeps its way');
|
||||
// From there, a real move back still turns it.
|
||||
assert.ok(
|
||||
play(
|
||||
6,
|
||||
{ ...fix(85_000, 1400, 0), ...epoch },
|
||||
{ ...fix(100_000, 1380, 0), ...epoch },
|
||||
),
|
||||
);
|
||||
assert.equal(binding.direction, -1);
|
||||
});
|
||||
|
||||
test('a clock correction played from past its break is no reversal', () => {
|
||||
const binding = bindTrainPath(
|
||||
pack(),
|
||||
{ tripId: 'full', routeId: 'main' },
|
||||
fix(0, 600, 0),
|
||||
);
|
||||
const track = createTrack();
|
||||
const sample = createSample();
|
||||
const segment = { from: {}, to: {} };
|
||||
let now = 0;
|
||||
/** One report at `t`, then 15 s of frames; the direction after each. */
|
||||
const report = (t, eastM) => {
|
||||
insertFix(track, fix(t, eastM, 0), { receivedAt: now, wallNowMs: now });
|
||||
return [1, 2, 3].map(() => {
|
||||
now += 5000;
|
||||
advance(track, { wallNowMs: now, monoNowMs: now }, sample);
|
||||
if (sample.fromSeq >= 0) {
|
||||
readFix(track, sample.fromSeq - track.baseSeq, segment.from);
|
||||
readFix(track, sample.toSeq - track.baseSeq, segment.to);
|
||||
placeOnPath(binding, sample, segment, {});
|
||||
}
|
||||
return binding.direction;
|
||||
});
|
||||
};
|
||||
for (const eastM of [600, 750, 900, 1050, 1200, 1200, 1200, 1200])
|
||||
report(now, eastM);
|
||||
assert.equal(binding.direction, 1);
|
||||
assert.ok(binding.directionPlayed);
|
||||
// Its source's clock falls 120 s behind and puts it at 1000 m. The third
|
||||
// such report starts a new epoch, and playback starts at the newest one,
|
||||
// past the break.
|
||||
const seen = [0, 1, 2].flatMap(() => report(now - 120_000, 1000));
|
||||
assert.equal(track.resetReason, 'out-of-order');
|
||||
assert.deepEqual(seen, Array(9).fill(1));
|
||||
});
|
||||
|
||||
/** The direction after each played segment, `[fromM, toM]` 15 s apart. */
|
||||
function playDirections(binding, steps) {
|
||||
return steps.map(([fromM, toM], seq) => {
|
||||
const { sample, segment } = playback(
|
||||
seq,
|
||||
seq + 1,
|
||||
fix(seq * 15_000, fromM, 0),
|
||||
fix((seq + 1) * 15_000, toM, 0),
|
||||
0.5,
|
||||
);
|
||||
assert.ok(placeOnPath(binding, sample, segment, {}));
|
||||
return binding.direction;
|
||||
});
|
||||
}
|
||||
|
||||
/** The direction after each report, `eastMs` 15 s apart. */
|
||||
function reportDirections(binding, eastMs) {
|
||||
return eastMs.map((eastM, i) => {
|
||||
assert.ok(followFix(binding, fix((i + 1) * 15_000, eastM, 0)));
|
||||
return binding.direction;
|
||||
});
|
||||
}
|
||||
|
||||
test('a train that moves under 15 m a report still tells its direction', () => {
|
||||
const p = pack();
|
||||
const ids = { tripId: 'full', routeId: 'main' };
|
||||
// It sets off slowly, runs east, then backs out 10 m a report.
|
||||
const learnt = reportDirections(
|
||||
bindTrainPath(p, ids, fix(0, 1000, 0)),
|
||||
[1010, 1020, 1600, 1590, 1580, 1570],
|
||||
);
|
||||
assert.deepEqual(learnt, [0, 1, 1, 1, -1, -1], 'from the newest reports');
|
||||
const played = bindTrainPath(p, ids, fix(0, 1000, 0));
|
||||
assert.deepEqual(
|
||||
playDirections(played, [
|
||||
[1000, 1600],
|
||||
[1600, 1590],
|
||||
[1590, 1580],
|
||||
[1580, 1570],
|
||||
]),
|
||||
[1, 1, -1, -1],
|
||||
'from the played-back segments',
|
||||
);
|
||||
});
|
||||
|
||||
test('a train turns 15 m back from where it ran to, not 14.9 m', () => {
|
||||
const p = pack();
|
||||
const ids = { tripId: 'full', routeId: 'main' };
|
||||
for (const [backM, want, label] of [
|
||||
[1100, -1, '15 m back'],
|
||||
[1100.1, 1, '14.9 m back'],
|
||||
]) {
|
||||
const learnt = reportDirections(bindTrainPath(p, ids, fix(0, 1000, 0)), [
|
||||
1115,
|
||||
backM,
|
||||
]);
|
||||
assert.deepEqual(learnt, [1, want], `${label}, from the newest reports`);
|
||||
assert.deepEqual(
|
||||
playDirections(bindTrainPath(p, ids, fix(0, 1000, 0)), [
|
||||
[1000, 1115],
|
||||
[1115, backM],
|
||||
]),
|
||||
[1, want],
|
||||
`${label}, from the played-back segments`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('GPS jitter of up to 14 m at a standing train keeps its direction', () => {
|
||||
const p = pack();
|
||||
const ids = { tripId: 'full', routeId: 'main' };
|
||||
const learnt = reportDirections(
|
||||
bindTrainPath(p, ids, fix(0, 1000, 0)),
|
||||
[1600, 1588, 1600, 1586, 1599, 1587],
|
||||
);
|
||||
assert.deepEqual(learnt, [1, 1, 1, 1, 1, 1], 'from the newest reports');
|
||||
const played = bindTrainPath(p, ids, fix(0, 1000, 0));
|
||||
assert.deepEqual(
|
||||
playDirections(played, [
|
||||
[1000, 1600],
|
||||
[1600, 1588],
|
||||
[1588, 1600],
|
||||
[1600, 1586],
|
||||
[1586, 1599],
|
||||
]),
|
||||
[1, 1, 1, 1, 1],
|
||||
'from the played-back segments',
|
||||
);
|
||||
|
||||
// On both sides of where it stopped: 8 m either way, 16 m from end to end.
|
||||
assert.deepEqual(
|
||||
reportDirections(
|
||||
bindTrainPath(p, ids, fix(0, 600, 0)),
|
||||
[1000, 1008, 1000, 992, 1000, 1008],
|
||||
),
|
||||
[1, 1, 1, 1, 1, 1],
|
||||
'both sides, from the newest reports',
|
||||
);
|
||||
assert.deepEqual(
|
||||
playDirections(bindTrainPath(p, ids, fix(0, 600, 0)), [
|
||||
[600, 1000],
|
||||
[1000, 1008],
|
||||
[1008, 1000],
|
||||
[1000, 992],
|
||||
[992, 1000],
|
||||
[1000, 1008],
|
||||
]),
|
||||
[1, 1, 1, 1, 1, 1],
|
||||
'both sides, from the played-back segments',
|
||||
);
|
||||
});
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
import { displayMotion } from '../transit/movement.js';
|
||||
import { FIX_FLAGS, readFix } from '../../data/contactPlayback.js';
|
||||
import { roundHeadingDegrees } from '../../data/headingDegrees.js';
|
||||
import { DIRECTION_MIN_M } from './pathBinding.js';
|
||||
import {
|
||||
stopClock,
|
||||
stopLateMinutes,
|
||||
@@ -294,9 +295,6 @@ export function playbackModeFor(railMode) {
|
||||
: 'rail';
|
||||
}
|
||||
|
||||
/** Two reports closer than this are one place: a parked train's jitter (m). */
|
||||
export const FOLLOW_MIN_MOVE_M = 15;
|
||||
|
||||
const lastFix = {};
|
||||
const priorFix = {};
|
||||
|
||||
@@ -333,7 +331,7 @@ export function railTrainFollowable(entry) {
|
||||
sample.nextMotionT > sample.displayT
|
||||
)
|
||||
return true;
|
||||
return lastReportsApartM(entry.track) >= FOLLOW_MIN_MOVE_M;
|
||||
return lastReportsApartM(entry.track) >= DIRECTION_MIN_M;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,6 +48,7 @@ import {
|
||||
transitModelSpec,
|
||||
} from '../../data/fleetModels.js';
|
||||
import { createFleetModelLayer } from '../../data/fleetModelInstances.js';
|
||||
import { groundVehiclePartState } from '../../data/modelPartDrivers.js';
|
||||
|
||||
/** How often the trains near enough for a model are gathered again (wall ms). */
|
||||
const MODEL_CANDIDATES_MS = 500;
|
||||
@@ -924,6 +925,25 @@ export function createRendering({ state, services, parts }) {
|
||||
display: fleet.display,
|
||||
policy: fleet.policy,
|
||||
resolveAsset: fleet.resolveAsset,
|
||||
partState: vehiclePartState,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wheels rolling at the speed it is drawn moving at (else its reported
|
||||
* one), doors open while it stands at a stop.
|
||||
*/
|
||||
function vehiclePartState(item, table) {
|
||||
const entry = item.entry;
|
||||
const drawn = entry?.sample?.segmentSpeedMps;
|
||||
const reported = entry?.record?.speedMps;
|
||||
return groundVehiclePartState(table, {
|
||||
speedMps: Number.isFinite(drawn)
|
||||
? drawn
|
||||
: Number.isFinite(reported)
|
||||
? reported
|
||||
: null,
|
||||
atStop: entry?.record?.status === 'STOPPED_AT',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -978,11 +998,7 @@ export function createRendering({ state, services, parts }) {
|
||||
if (now - modelCandidatesAtMs >= MODEL_CANDIDATES_MS) {
|
||||
modelCandidatesAtMs = now;
|
||||
const eye = cameraPose()?.position;
|
||||
const policy = services.fleet.policy;
|
||||
const keepM =
|
||||
services.fleet.display?.()?.models3dMode === 'all'
|
||||
? policy.keepAllM
|
||||
: policy.keepM;
|
||||
const keepM = services.fleet.policy.keepM;
|
||||
const limitSq = keepM * keepM * 1.44;
|
||||
if (eye)
|
||||
for (const entry of state._trains.values()) {
|
||||
|
||||
Reference in new issue
Block a user