mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(local-adsb): the selected aircraft's trail head ends on its icon every frame again
The head was a polyline entity whose positions were read each frame. Its draw-port line was redrawn at most every 100 ms while the aircraft flew, so its end lagged the icon. It is drawn each frame the aircraft moves, as the Flights trail head is; the trail still skips a head that has not moved.
This commit is contained in:
1 parent
6af4b08293
commit
0287ddb9be
2 files changed
+11
-20
No files matched your search
@@ -65,8 +65,6 @@ const MARKER_SPRITE = Object.freeze({
|
||||
});
|
||||
/** Markers and rings show within 2,000 km of the eye. */
|
||||
const MARKER_RANGE = Object.freeze([0, 2_000_000]);
|
||||
/** The longest the moving trail head waits to be drawn anew, ms. */
|
||||
const HEAD_REDRAW_MS = 100;
|
||||
/** Draw sets made, so each layer instance's sets have ids of their own. */
|
||||
let instances = 0;
|
||||
/** Trail lines pass through their aircraft; a click never stops on one. */
|
||||
@@ -417,12 +415,9 @@ export function createLocalAdsbLayer({
|
||||
|
||||
/**
|
||||
* The live head: the last heard fix to the extrapolated marker, dimmed
|
||||
* where the surface hides it. Nothing while either end is unknown.
|
||||
*
|
||||
* A line dimmed behind the surface is built anew when it moves, so the
|
||||
* head is redrawn when its fix changes, and otherwise at most
|
||||
* `HEAD_REDRAW_MS` apart while the aircraft flies on; a still aircraft
|
||||
* costs nothing a frame.
|
||||
* where the surface hides it, drawn each frame as the aircraft moves (the
|
||||
* trail skips a head that has not moved). Nothing while either end is
|
||||
* unknown.
|
||||
*/
|
||||
function drawTrailHead() {
|
||||
if (!selectedTrail?.trail?.setHead) return;
|
||||
@@ -430,15 +425,6 @@ export function createLocalAdsbLayer({
|
||||
const from = selectedTrail.lastFix;
|
||||
const positions =
|
||||
current?.position && from ? [from, { ...current.position }] : [];
|
||||
const at = now();
|
||||
if (
|
||||
positions.length &&
|
||||
from === selectedTrail.drawnFrom &&
|
||||
at - selectedTrail.drawnAt < HEAD_REDRAW_MS
|
||||
)
|
||||
return;
|
||||
selectedTrail.drawnFrom = from;
|
||||
selectedTrail.drawnAt = at;
|
||||
// The trail's head line: 'gev-trail' ids, claimed by the trail pick
|
||||
// owner so a click on it never reads as empty space; dimmed where the
|
||||
// surface hides it. A head that has not moved is not drawn again.
|
||||
@@ -464,9 +450,6 @@ export function createLocalAdsbLayer({
|
||||
trail: createTrail(viewer, { color: LOCAL_ADSB_COLOR, width: 2.5 }),
|
||||
// Live head: last heard fix → the extrapolated marker, every frame.
|
||||
lastFix: null,
|
||||
// From which fix and when the head was last drawn.
|
||||
drawnFrom: null,
|
||||
drawnAt: -Infinity,
|
||||
};
|
||||
refreshTrail();
|
||||
drawTrailHead();
|
||||
|
||||
@@ -508,6 +508,14 @@ test('the trail head runs from the last fix to the marker every frame, dimmed be
|
||||
Math.abs(toLonLatH(heads()[0].positions[1]).lat - after) < 1e-9,
|
||||
'the head follows the marker',
|
||||
);
|
||||
// The next frame too, as the entity's head was rebuilt every frame.
|
||||
clock.now = 101_016;
|
||||
listeners.get('preRender')();
|
||||
assert.deepEqual(
|
||||
heads()[0].positions[1],
|
||||
iconOf(draw, 'local-adsb:abc123').pos,
|
||||
'the head ends on the icon a frame later',
|
||||
);
|
||||
|
||||
// A frame where nothing moved leaves the head alone.
|
||||
const writes = trailSet().writes;
|
||||
|
||||
Reference in new issue
Block a user