mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 17:22:19 +00:00
Sprites for helicopters, ground vehicles, stations and vessel types; history to live without an empty map; model parts in Cesium
Aircraft icons are one size; helicopters turn a three-frame rotor while airborne or moving; ADS-B ground vehicles share one amber sprite and stations/obstacles one mast; vessels get hull sprites by type and one buoy. Going live keeps contacts until the first live answer and replaces them by id; fast playback holds before the loaded positions end and prefetches ahead. Cesium models move their parts from the optional model part state.
This commit is contained in:
1 parent
624c229bc2
commit
7186f720df
97 files changed
+6586
-343
No files matched your search
@@ -6,10 +6,12 @@ import {
|
||||
createContactIcons,
|
||||
floorCoastArc,
|
||||
} from './aircraftIconLayer.js';
|
||||
import { COAST_FLOOR_LIFT_M } from './motionModel.js';
|
||||
import { COAST_FLOOR_LIFT_M, recoveryMs } from './motionModel.js';
|
||||
import { fromDegrees, toCartographicRadians } from '../geo/ellipsoid.js';
|
||||
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
|
||||
import { createDisplayDelay } from './displayDelay.js';
|
||||
import { aircraftIcon, FLEET_ICON_PX } from './aircraftIcons.js';
|
||||
import { ROTOR_STILL_FRAME } from './rotorFrames.js';
|
||||
|
||||
const WORLD_MS = Date.UTC(2026, 10, 1, 12, 0);
|
||||
|
||||
@@ -199,3 +201,283 @@ test('a coast over known ground that never rises is planned once', () => {
|
||||
'held on the ground where the coast stopped',
|
||||
);
|
||||
});
|
||||
|
||||
test('only airborne helicopters in view turn their rotor, written when the frame steps', (t) => {
|
||||
t.mock.timers.enable({ apis: ['Date'], now: WORLD_MS });
|
||||
const here = fromDegrees(0, 30, 300);
|
||||
const away = fromDegrees(90, 30, 300);
|
||||
const records = new Map([
|
||||
['h1', { klass: 'helicopter', onGround: false }],
|
||||
['h2', { klass: 'helicopter', onGround: true }],
|
||||
['p1', { klass: 'airliner', onGround: false }],
|
||||
['h3', { klass: 'helicopter', onGround: false }],
|
||||
]);
|
||||
const state = {
|
||||
now: () => Date.now(),
|
||||
_icons: createContactIcons(),
|
||||
_positionHistory: new Map(),
|
||||
_cockpitNearContacts: new Set(),
|
||||
records: { data: records, missingPolls: new Map() },
|
||||
};
|
||||
const icons = createAircraftIcons({
|
||||
state,
|
||||
services: { focus: { focusPassIsNeeded: () => false } },
|
||||
parts: {
|
||||
rendering: {
|
||||
_iconKind: (_id, klass) => klass,
|
||||
_fleetBillboardColor: () => [1, 1, 1, 1],
|
||||
_fleetBillboardScale: () => 1,
|
||||
},
|
||||
},
|
||||
layerId: 'flights',
|
||||
courseMaxDps: 3,
|
||||
cockpitContactSizePx: 8,
|
||||
});
|
||||
for (const id of records.keys()) {
|
||||
state._icons.put(
|
||||
{
|
||||
id,
|
||||
pos: id === 'h3' ? away : here,
|
||||
motion: { kind: 'hold', courseDeg: 0 },
|
||||
size: [20, 20],
|
||||
},
|
||||
{ expiresAt: Infinity },
|
||||
);
|
||||
icons._applyIconPresentation(id);
|
||||
}
|
||||
const image = (id) => state._icons.item(id).image;
|
||||
// The grounded helicopter holds the still frame.
|
||||
assert.equal(
|
||||
image('h2'),
|
||||
aircraftIcon('helicopter', FLEET_ICON_PX, ROTOR_STILL_FRAME),
|
||||
);
|
||||
const h3Before = image('h3');
|
||||
const writes = new Map();
|
||||
const update = state._icons.update;
|
||||
state._icons.update = (id, patch, options) => {
|
||||
writes.set(id, (writes.get(id) ?? 0) + 1);
|
||||
return update(id, patch, options);
|
||||
};
|
||||
// The fleet pass, every 80 ms for a second; h3 is out of view.
|
||||
const inView = (p) => Math.abs(p.x - here.x) < 1;
|
||||
const seen = new Set();
|
||||
for (let step = 0; step <= 12; step++) {
|
||||
if (step) t.mock.timers.tick(80);
|
||||
icons._turnRotors(Date.now(), Date.now(), inView);
|
||||
seen.add(image('h1'));
|
||||
}
|
||||
// Through every frame, written only on the steps its frame changed.
|
||||
assert.equal(seen.size, 3);
|
||||
for (const frame of [0, 1, 2])
|
||||
assert.ok(seen.has(aircraftIcon('helicopter', FLEET_ICON_PX, frame)));
|
||||
assert.ok(
|
||||
writes.get('h1') >= 8 && writes.get('h1') <= 11,
|
||||
`${writes.get('h1')} writes`,
|
||||
);
|
||||
assert.equal(writes.get('h2') ?? 0, 0, 'grounded: frozen');
|
||||
assert.equal(writes.get('p1') ?? 0, 0, 'not a helicopter');
|
||||
assert.equal(writes.get('h3') ?? 0, 0, 'out of view');
|
||||
assert.equal(image('h3'), h3Before);
|
||||
// Landing freezes it on the still frame.
|
||||
records.get('h1').onGround = true;
|
||||
icons._applyIconPresentation('h1');
|
||||
const landed = writes.get('h1');
|
||||
t.mock.timers.tick(400);
|
||||
icons._turnRotors(Date.now(), Date.now(), inView);
|
||||
assert.equal(writes.get('h1'), landed);
|
||||
assert.equal(
|
||||
image('h1'),
|
||||
aircraftIcon('helicopter', FLEET_ICON_PX, ROTOR_STILL_FRAME),
|
||||
);
|
||||
});
|
||||
|
||||
/** An icon layer over helicopters `ids`, all at `here`, for the rotor tests. */
|
||||
function rotorFixture(records, positions, tracking = {}) {
|
||||
const state = {
|
||||
now: () => Date.now(),
|
||||
_icons: createContactIcons(),
|
||||
_positionHistory: new Map(),
|
||||
_cockpitNearContacts: new Set(),
|
||||
records: { data: records, missingPolls: new Map() },
|
||||
};
|
||||
const icons = createAircraftIcons({
|
||||
state,
|
||||
services: { focus: { focusPassIsNeeded: () => false } },
|
||||
parts: {
|
||||
rendering: {
|
||||
_iconKind: (_id, klass) => klass,
|
||||
_fleetBillboardColor: () => [1, 1, 1, 1],
|
||||
_fleetBillboardScale: () => 1,
|
||||
},
|
||||
tracking,
|
||||
},
|
||||
layerId: 'flights',
|
||||
courseMaxDps: 3,
|
||||
cockpitContactSizePx: 8,
|
||||
});
|
||||
for (const id of records.keys()) {
|
||||
state._icons.put(
|
||||
{
|
||||
id,
|
||||
pos: positions[id],
|
||||
motion: { kind: 'hold', courseDeg: 0 },
|
||||
size: [20, 20],
|
||||
},
|
||||
{ expiresAt: Infinity },
|
||||
);
|
||||
icons._applyIconPresentation(id);
|
||||
}
|
||||
return { state, icons };
|
||||
}
|
||||
|
||||
test('a tracked helicopter that lands shows the still frame at once', (t) => {
|
||||
t.mock.timers.enable({ apis: ['Date'], now: WORLD_MS });
|
||||
const records = new Map([['h1', { klass: 'helicopter', onGround: false }]]);
|
||||
let synced = 0;
|
||||
const { state, icons } = rotorFixture(
|
||||
records,
|
||||
{ h1: fromDegrees(0, 30, 300) },
|
||||
{ _syncTrackedBillboardImage: () => synced++ },
|
||||
);
|
||||
state._trackedIcao = 'h1';
|
||||
assert.equal(icons._rotorsTurning(), true);
|
||||
records.get('h1').onGround = true;
|
||||
icons._applyIconPresentation('h1');
|
||||
assert.equal(synced, 1, 'the tracked billboard is given its images again');
|
||||
assert.equal(icons._rotorsTurning(), false);
|
||||
assert.equal(
|
||||
icons._fleetLook('h1').image,
|
||||
aircraftIcon('helicopter', FLEET_ICON_PX, ROTOR_STILL_FRAME),
|
||||
);
|
||||
// Taxiing faster than 1 m/s, its rotor turns again, as the model's does.
|
||||
records.get('h1').velocity = 5;
|
||||
icons._applyIconPresentation('h1');
|
||||
assert.equal(icons._rotorsTurning(), true);
|
||||
records.get('h1').velocity = 0;
|
||||
icons._applyIconPresentation('h1');
|
||||
assert.equal(synced, 2);
|
||||
assert.equal(icons._rotorsTurning(), false);
|
||||
// An untracked one landing does not touch the tracked billboard.
|
||||
records.get('h1').onGround = false;
|
||||
icons._applyIconPresentation('h1');
|
||||
state._trackedIcao = null;
|
||||
records.get('h1').onGround = true;
|
||||
icons._applyIconPresentation('h1');
|
||||
assert.equal(synced, 2);
|
||||
});
|
||||
|
||||
test('a helicopter out of view is judged once per rotor frame, not every pass', (t) => {
|
||||
t.mock.timers.enable({ apis: ['Date'], now: WORLD_MS });
|
||||
const records = new Map();
|
||||
const positions = {};
|
||||
for (let i = 0; i < 300; i++) {
|
||||
const id = `h${i}`;
|
||||
records.set(id, { klass: 'helicopter', onGround: false });
|
||||
positions[id] = fromDegrees(90, 30, 300);
|
||||
}
|
||||
const { state, icons } = rotorFixture(records, positions);
|
||||
let judged = 0;
|
||||
const inView = () => {
|
||||
judged++;
|
||||
return false;
|
||||
};
|
||||
const writes = [];
|
||||
const update = state._icons.update;
|
||||
state._icons.update = (id, ...rest) => {
|
||||
writes.push(id);
|
||||
return update(id, ...rest);
|
||||
};
|
||||
// Passes 10 ms apart for 2 s: 200 passes over 300 helicopters, all out of
|
||||
// view. Each is judged at most once per frame step (20 steps), and not on
|
||||
// a step back onto the frame it is drawn at.
|
||||
for (let pass = 0; pass < 200; pass++) {
|
||||
t.mock.timers.tick(10);
|
||||
icons._turnRotors(Date.now(), Date.now(), inView);
|
||||
}
|
||||
assert.ok(judged <= 300 * 21, `${judged} judgements`);
|
||||
assert.ok(judged >= 300 * 10, `${judged} judgements`);
|
||||
assert.equal(writes.length, 0, 'none in view: no image written');
|
||||
});
|
||||
|
||||
test('back at live, a placed contact eases from where it is drawn over a recovery, nose along the way', (t) => {
|
||||
t.mock.timers.enable({ apis: ['Date'], now: WORLD_MS });
|
||||
const drawnAt = fromDegrees(0, 30, 3_000);
|
||||
const SPEED = 200;
|
||||
// The placement has it 2 km east of where it is drawn, flying east.
|
||||
const placedAt = (wallMs) => {
|
||||
const east = 2_000 + (SPEED * (wallMs - WORLD_MS)) / 1000;
|
||||
return fromDegrees(east / (111_320 * Math.cos(Math.PI / 6)), 30, 3_000);
|
||||
};
|
||||
const plan = (handover, keep = {}) => {
|
||||
const state = {
|
||||
now: () => Date.now(),
|
||||
_icons: createContactIcons(),
|
||||
_positionHistory: new Map([['c', [{ epochMs: WORLD_MS }]]]),
|
||||
records: { data: new Map([['c', {}]]) },
|
||||
};
|
||||
const icons = createAircraftIcons({
|
||||
state,
|
||||
services: { focus: { focusPassIsNeeded: () => false } },
|
||||
parts: {
|
||||
motion: { _displayTimeAt: (ms) => ms, _fixEpochMs: (f) => f.epochMs },
|
||||
},
|
||||
layerId: 'flights',
|
||||
courseMaxDps: 3,
|
||||
cockpitContactSizePx: 8,
|
||||
placeAt: (_id, wallMs, _info, _history, out) => {
|
||||
Object.assign(out, placedAt(wallMs));
|
||||
return { courseDeg: 90, speedMps: SPEED };
|
||||
},
|
||||
});
|
||||
state._icons.put(
|
||||
{
|
||||
id: 'c',
|
||||
pos: drawnAt,
|
||||
motion: { kind: 'hold', courseDeg: 0 },
|
||||
course: 0,
|
||||
size: [20, 20],
|
||||
},
|
||||
{ expiresAt: -Infinity },
|
||||
);
|
||||
icons._planIcon('c', handover ? { handover: true } : undefined);
|
||||
keep.icons = icons;
|
||||
return state._icons;
|
||||
};
|
||||
const metres = (a, b) => Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z);
|
||||
|
||||
const eased = plan(true);
|
||||
const end = eased.expires('c');
|
||||
assert.equal(end, WORLD_MS + recoveryMs(2_000, SPEED));
|
||||
assert.ok(end - WORLD_MS > 1_000, 'longer than a placed plan');
|
||||
assert.ok(metres(eased.position('c', WORLD_MS, {}), drawnAt) < 1);
|
||||
assert.ok(metres(eased.position('c', end, {}), placedAt(end)) < 1);
|
||||
// The nose points along the way from where it is drawn to where it goes.
|
||||
assert.ok(Math.abs(eased.course('c', WORLD_MS) - 90) < 1);
|
||||
|
||||
const plain = plan(false);
|
||||
assert.ok(
|
||||
metres(plain.position('c', WORLD_MS, {}), placedAt(WORLD_MS)) < 1,
|
||||
'without the handover it is drawn where it is placed',
|
||||
);
|
||||
|
||||
// The next answer comes 15 s in, the ease still running: it eases on from
|
||||
// where it is drawn then, not cut to where it is placed.
|
||||
const keep = {};
|
||||
const easing = plan(true, keep);
|
||||
const firstEnd = easing.expires('c');
|
||||
assert.ok(firstEnd - WORLD_MS > 15_000, 'an ease longer than a poll');
|
||||
t.mock.timers.tick(15_000);
|
||||
const at = Date.now();
|
||||
const drawnThen = easing.position('c', at, {});
|
||||
keep.icons._planIcon('c');
|
||||
assert.ok(metres(easing.position('c', at, {}), drawnThen) < 1);
|
||||
const reEnd = easing.expires('c');
|
||||
assert.ok(reEnd > at + 1_000, 'eases on');
|
||||
assert.ok(metres(easing.position('c', reEnd, {}), placedAt(reEnd)) < 1);
|
||||
// Once it has caught up, the next answer draws it where it is placed.
|
||||
t.mock.timers.tick(reEnd - at + 1);
|
||||
keep.icons._planIcon('c');
|
||||
assert.ok(
|
||||
metres(easing.position('c', Date.now(), {}), placedAt(Date.now())) < 1,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user