mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
fix(flights): panels show the reported ground speed while a placement waits
A host-supplied placement's speed is how fast the marker is drawn. While it waits for its fixes to catch up it stands still at 0, so tracked-aircraft panels and the cockpit readout showed 0 m/s for an aircraft in flight. displayedKinematics now takes derivedFromPlacement: when the drawn speed is a placement's, the reported ground speed is shown, and the placement's only when nothing is reported. The placement speed still drives motion and dead reckoning. Civil and military tracked descriptors pass it from the new _drSpeedPlaced scratch, which placeLiveAircraft sets.
This commit is contained in:
1 parent
953af60e1d
commit
d79494ac89
8 files changed
+98
-6
No files matched your search
+13
-5
@@ -127,19 +127,27 @@ export function courseSlewCapDps(speedMps, maxDps, minDps = COURSE_MIN_DPS) {
|
||||
* fixes still describe clear movement. The delayed renderer already derives a
|
||||
* matching segment speed and course from those fixes, so tracking and cockpit
|
||||
* consumers should prefer that pair over stale poll fields.
|
||||
*
|
||||
* A host-supplied placement's speed (`derivedFromPlacement`) is how fast the
|
||||
* marker is drawn, not how fast the aircraft goes: a placement waiting for its
|
||||
* fixes to catch up stands still at 0. The reported ground speed is shown
|
||||
* then, and the placement's only when nothing is reported.
|
||||
*/
|
||||
export function displayedKinematics({
|
||||
derivedSpeedMps,
|
||||
derivedTrackDeg,
|
||||
reportedSpeedMps,
|
||||
reportedTrackDeg,
|
||||
derivedFromPlacement = false,
|
||||
} = {}) {
|
||||
const reported = Number.isFinite(reportedSpeedMps);
|
||||
return {
|
||||
speedMps: Number.isFinite(derivedSpeedMps)
|
||||
? Math.max(0, derivedSpeedMps)
|
||||
: Number.isFinite(reportedSpeedMps)
|
||||
? Math.max(0, reportedSpeedMps)
|
||||
: null,
|
||||
speedMps:
|
||||
Number.isFinite(derivedSpeedMps) && !(derivedFromPlacement && reported)
|
||||
? Math.max(0, derivedSpeedMps)
|
||||
: reported
|
||||
? Math.max(0, reportedSpeedMps)
|
||||
: null,
|
||||
trackDeg: Number.isFinite(derivedTrackDeg)
|
||||
? derivedTrackDeg
|
||||
: Number.isFinite(reportedTrackDeg)
|
||||
|
||||
@@ -43,6 +43,13 @@ test('displayedKinematics preserves a derived stop and falls back when unavailab
|
||||
}), { speedMps: 80, trackDeg: 180 });
|
||||
});
|
||||
|
||||
test('displayedKinematics shows the reported speed over a placement standing still', () => {
|
||||
const placed = { derivedSpeedMps: 0, derivedTrackDeg: 90, derivedFromPlacement: true };
|
||||
assert.deepEqual(displayedKinematics({ ...placed, reportedSpeedMps: 230, reportedTrackDeg: 88 }),
|
||||
{ speedMps: 230, trackDeg: 90 });
|
||||
assert.deepEqual(displayedKinematics(placed), { speedMps: 0, trackDeg: 90 });
|
||||
});
|
||||
|
||||
test('stale coasting follows last source contact without allowing indefinite drift', () => {
|
||||
const fix = 1_000_000;
|
||||
assert.equal(staleCoastLimitSeconds({ fixEpochMs: fix }), 60);
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as Cesium from 'cesium';
|
||||
import { createMotion } from './motion.js';
|
||||
import { arcOffsetEnu } from '../../data/motionModel.js';
|
||||
import { createMotion as createMilitaryMotion } from '../military/motion.js';
|
||||
import { createQueries } from './queries.js';
|
||||
import { createQueries as createMilitaryQueries } from '../military/queries.js';
|
||||
import { layerPlacement } from '../../data/placementProvider.js';
|
||||
import { observeLiveAircraft } from './placed.js';
|
||||
|
||||
@@ -248,18 +250,77 @@ const declining = (asked) =>
|
||||
);
|
||||
|
||||
// Each kind's record carries only its own kinematics fields.
|
||||
for (const [name, create, record] of [
|
||||
for (const [name, create, record, queriesOf] of [
|
||||
[
|
||||
'civil',
|
||||
createMotion,
|
||||
{ velocity: 100, true_track: 90, renderAltitudeM: 1234 },
|
||||
createQueries,
|
||||
],
|
||||
[
|
||||
'military',
|
||||
createMilitaryMotion,
|
||||
{ speedMps: 100, track: 90, renderAltitudeM: 1234 },
|
||||
createMilitaryQueries,
|
||||
],
|
||||
]) {
|
||||
test(`${name} aircraft waiting where a placement holds them still show their reported speed`, () => {
|
||||
// Drawn standing (speed 0) while its fixes catch up: the aircraft has
|
||||
// not stopped, and the panels say what it reports.
|
||||
const placement = layerPlacement(
|
||||
{
|
||||
layer: () => ({
|
||||
place: () => ({
|
||||
lat: 30.5,
|
||||
lon: -96.5,
|
||||
altitudeM: 2000,
|
||||
courseDeg: 90,
|
||||
speedMps: 0,
|
||||
extrapolating: false,
|
||||
}),
|
||||
}),
|
||||
},
|
||||
'aircraft',
|
||||
);
|
||||
const { flightState, motion, start } = placedScenario(
|
||||
create,
|
||||
placement,
|
||||
record,
|
||||
);
|
||||
flightState.now = () => start + 2000;
|
||||
flightState.feed = {};
|
||||
flightState.records.missingPolls = new Map();
|
||||
const describe = (kinematics) => {
|
||||
flightState.records.data.set('abc123', { ...record, ...kinematics });
|
||||
return queriesOf({
|
||||
flightState,
|
||||
services: {
|
||||
aircraftPresentation: {
|
||||
tr3bTypeLabel: (_, label) => label,
|
||||
tr3bAircraftClass: () => null,
|
||||
},
|
||||
labels: { formatFlightLevel: String },
|
||||
militaryRegistry: {},
|
||||
focus: {},
|
||||
recession: {},
|
||||
},
|
||||
parts: {
|
||||
motion,
|
||||
icons: { _iconPosition: () => null },
|
||||
tracking: { _routeIsPlausible: () => false },
|
||||
testing: {},
|
||||
},
|
||||
})._describeFlight('abc123');
|
||||
};
|
||||
const waiting = describe({});
|
||||
assert.equal(flightState._drSpeedMps, 0);
|
||||
assert.equal(waiting.velocityMps, 100);
|
||||
// Nothing reported: the speed it is drawn at.
|
||||
const unreported =
|
||||
name === 'civil' ? { velocity: undefined } : { speedMps: undefined };
|
||||
assert.equal(describe(unreported).velocityMps, 0);
|
||||
});
|
||||
|
||||
test(`${name} aircraft move as before without a placement or with one that places nothing`, () => {
|
||||
const own = placedScenario(create, null, record).drawn;
|
||||
const asked = [];
|
||||
|
||||
@@ -61,6 +61,7 @@ export function placeLiveAircraft(
|
||||
history,
|
||||
out,
|
||||
) {
|
||||
flightState._drSpeedPlaced = false;
|
||||
if (!placement || followsClock(flightState)) return false;
|
||||
const placed = placeAircraftAt(
|
||||
placement,
|
||||
@@ -73,6 +74,7 @@ export function placeLiveAircraft(
|
||||
if (!placed) return false;
|
||||
flightState._drCourseDeg = placed.courseDeg;
|
||||
flightState._drSpeedMps = placed.speedMps;
|
||||
flightState._drSpeedPlaced = true;
|
||||
flightState._drCourseHold = placed.speedMps < COURSE_HOLD_SPEED_MPS;
|
||||
flightState._drExtrapolating = placed.extrapolating;
|
||||
return true;
|
||||
|
||||
@@ -145,6 +145,7 @@ export function createQueries({
|
||||
derivedSpeedMps: flightState._drSpeedMps,
|
||||
derivedTrackDeg: flightState._drCourseDeg,
|
||||
reportedSpeedMps: info?.velocity,
|
||||
derivedFromPlacement: flightState._drSpeedPlaced === true,
|
||||
reportedTrackDeg: info?.true_track,
|
||||
});
|
||||
const carto = toLonLatH(basePos);
|
||||
|
||||
@@ -266,6 +266,12 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._drSpeedMps = null;
|
||||
|
||||
/** Sibling scratch: whether `_drSpeedMps` is a host-supplied placement's,
|
||||
* the speed it is drawn at (0 while it waits for its fixes), for motion
|
||||
* only; panels show the reported ground speed (`displayedKinematics`). */
|
||||
|
||||
flightState._drSpeedPlaced = false;
|
||||
|
||||
flightState._drCourseHold = false;
|
||||
|
||||
/** Sibling scratch: whether the position `_deadReckon` just returned came from
|
||||
|
||||
@@ -109,6 +109,7 @@ export function createQueries({
|
||||
derivedSpeedMps: flightState._drSpeedMps,
|
||||
derivedTrackDeg: flightState._drCourseDeg,
|
||||
reportedSpeedMps: info?.speedMps,
|
||||
derivedFromPlacement: flightState._drSpeedPlaced === true,
|
||||
reportedTrackDeg: info?.track,
|
||||
});
|
||||
const carto = toLonLatH(basePos);
|
||||
|
||||
@@ -230,6 +230,12 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._drSpeedMps = null;
|
||||
|
||||
/** Sibling scratch: whether `_drSpeedMps` is a host-supplied placement's,
|
||||
* the speed it is drawn at (0 while it waits for its fixes), for motion
|
||||
* only; panels show the reported ground speed (`displayedKinematics`). */
|
||||
|
||||
flightState._drSpeedPlaced = false;
|
||||
|
||||
flightState._drCourseHold = false;
|
||||
|
||||
/** Set by `_deadReckon`: following the clock, the time drawn is well
|
||||
|
||||
Reference in new issue
Block a user