mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Let a host application place live contacts
createApplicationCatalog takes an optional placement provider. Its layer(kind) hands Flights, Military Flights, AIS Vessels, Transit and Rail a place(id, wallMs), and optionally observe(id, fix) and forget(id). While live, each layer tells it every fix it accepts and draws a contact where it places it: position, height (the layer's own when none is given), course and speed. A null answer, a provider that throws, a kind it leaves out, or no provider at all keeps the layer's own motion unchanged, and following the world clock the layers never ask it. A transit vehicle or train it holds still lets the render loop idle and is asked again each second; vessels ask for frames only while it places one, and stop when the layer turns off. Tests show the layers draw and reconcile exactly as before without a provider and with one that places nothing, draw where a provider places them, and idle while it holds them still.
This commit is contained in:
1 parent
e53cfef1d1
commit
6f830a2e70
46 files changed
+1417
-34
No files matched your search
@@ -186,13 +186,57 @@ export function recordFix(entry, fix, observation = {}) {
|
||||
);
|
||||
entry.currentEpoch = latest.epoch;
|
||||
if (context) entry.track.epochs.set(latest.epoch, context);
|
||||
entry.placement?.observe(entry.key, {
|
||||
timeMs: fix.t,
|
||||
lat: fix.lat,
|
||||
lon: fix.lon,
|
||||
altitudeM: NaN,
|
||||
speedMps: NaN,
|
||||
courseDeg: Number.isFinite(fix.bearingDeg) ? fix.bearingDeg : NaN,
|
||||
headingDeg: NaN,
|
||||
feedId: entry.feedId,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* How often a vehicle a host-supplied placement holds still is asked again
|
||||
* whether it moves, so it resumes without the frame loop running for it.
|
||||
*/
|
||||
export const PLACED_WAKE_MS = 1000;
|
||||
|
||||
/**
|
||||
* Advance a vehicle's playback to now. With a host-supplied placement
|
||||
* (`entry.placement`, ../../data/placementProvider.js) that places it, it is
|
||||
* drawn there, its course and speed the placement's (`entry.placed`); the
|
||||
* playback's own phase, motion and segment stand. `entry.placedMoving` says
|
||||
* whether the placed position changed since the placement was last asked at
|
||||
* an earlier time (true for its first answer, so one more frame can tell).
|
||||
*/
|
||||
export function updatePlayback(entry, wallNowMs, monoNowMs) {
|
||||
entry.clocks.wallNowMs = wallNowMs;
|
||||
entry.clocks.monoNowMs = monoNowMs;
|
||||
advance(entry.track, entry.clocks, entry.sample);
|
||||
const placed = entry.placement?.place(entry.key, wallNowMs) ?? null;
|
||||
const wasPlaced = entry.placed === true;
|
||||
entry.placed = placed !== null;
|
||||
if (!placed) entry.placedMoving = false;
|
||||
else if (!wasPlaced) entry.placedMoving = true;
|
||||
else if (wallNowMs !== entry.placedAtWallMs)
|
||||
entry.placedMoving =
|
||||
placed.lat !== entry.placedLat || placed.lon !== entry.placedLon;
|
||||
if (placed) {
|
||||
entry.placedLat = placed.lat;
|
||||
entry.placedLon = placed.lon;
|
||||
entry.placedAtWallMs = wallNowMs;
|
||||
const sample = entry.sample;
|
||||
sample.lat = placed.lat;
|
||||
sample.lon = placed.lon;
|
||||
if (Number.isFinite(placed.courseDeg))
|
||||
sample.segmentCourseDeg = placed.courseDeg;
|
||||
if (Number.isFinite(placed.speedMps))
|
||||
sample.segmentSpeedMps = placed.speedMps;
|
||||
}
|
||||
entry.resets = entry.track.resets;
|
||||
const segment = entry.segment;
|
||||
readFix(
|
||||
@@ -217,6 +261,16 @@ export function syncPlayback(entry, wallNowMs, monoNowMs = performance.now()) {
|
||||
}
|
||||
updatePlayback(entry, wallNowMs, monoNowMs);
|
||||
}
|
||||
/**
|
||||
* Whether a vehicle's drawn position changes on its own: a vehicle a
|
||||
* host-supplied placement draws moves while that placement's position
|
||||
* changes; any other while its playback glides along a segment.
|
||||
*/
|
||||
export function playbackMoving(entry) {
|
||||
if (entry.placed === true) return entry.placedMoving === true;
|
||||
const sample = entry.sample;
|
||||
return sample?.phase === 'playing' && sample.segmentSpeedMps > 0;
|
||||
}
|
||||
export function playbackPosition(entry) {
|
||||
if (!entry?.track) return null;
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user