mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
fix(cockpit): a provider's subject rides where it is drawn, and the documented provider rides a moving train
- A frame with no speedMps gets an exact anchor: an inertial one ran on at zero speed and closed at 0.75 m/s, so the camera fell kilometres behind a moving train. The docs example now passes speedMps and anchor: 'exact', a name for its HUD, and isEntryAllowed for a train bound to its line. - Transit's snapshot height is the floor where playback draws the vehicle, not the newest report's floor uphill, and null while that floor is cold, so a view waits for the surface instead of standing on the ellipsoid. - Rail's direction follows playback once it has placed the train: a report that runs back (a reversal, or GPS jitter) no longer turns the view while the drawn train still runs forward. - A frame's id is trimmed as the candidate's is. - A double-click on the selected vessel no longer enters an application's subject that took entry after it. - The docs import from gods-eye-view/..., the package's name.
This commit is contained in:
1 parent
974023510f
commit
4bb7b411e9
10 files changed
+161
-21
No files matched your search
@@ -63,10 +63,15 @@ function createBinding(shapeIndex, path, via, s, fix) {
|
||||
path,
|
||||
via,
|
||||
/**
|
||||
* Which way the train runs along the shape: +1 along it, -1 against it,
|
||||
* 0 until two reports or a playback segment tell. Kept until a rebind.
|
||||
* 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.
|
||||
*/
|
||||
direction: 0,
|
||||
/** The direction the last placed playback segment ran, 0 before one. */
|
||||
drawDirection: 0,
|
||||
/** Arc and time of the newest report. */
|
||||
fixS: s,
|
||||
fixT: fix.t,
|
||||
@@ -154,7 +159,8 @@ export function followFix(binding, fix) {
|
||||
pathWindowM(fix.t - binding.fixT),
|
||||
);
|
||||
if (!hit || hit.offsetM > PATH_OFF_TRACK_M) return false;
|
||||
binding.direction = directionOf(hit.s - binding.fixS, binding.direction);
|
||||
if (!binding.drawDirection)
|
||||
binding.direction = directionOf(hit.s - binding.fixS, binding.direction);
|
||||
binding.fixS = hit.s;
|
||||
binding.fixT = fix.t;
|
||||
binding.fixLat = fix.lat;
|
||||
@@ -246,8 +252,13 @@ export function placeOnPath(binding, sample, segment, out) {
|
||||
cache.sFrom = sFrom;
|
||||
cache.sTo = sTo;
|
||||
cache.ok = Number.isFinite(sFrom) && Number.isFinite(sTo);
|
||||
if (cache.ok)
|
||||
binding.direction = directionOf(sTo - sFrom, binding.direction ?? 0);
|
||||
if (cache.ok) {
|
||||
binding.drawDirection = directionOf(
|
||||
sTo - sFrom,
|
||||
binding.drawDirection || binding.direction || 0,
|
||||
);
|
||||
binding.direction = binding.drawDirection;
|
||||
}
|
||||
}
|
||||
if (!cache.ok) return false;
|
||||
const f = Number.isFinite(sample.fraction)
|
||||
|
||||
@@ -234,3 +234,31 @@ test('a binding learns which way its train runs, and keeps it through a stop', (
|
||||
);
|
||||
assert.equal(rebound?.direction ?? 0, 0);
|
||||
});
|
||||
|
||||
test('a report that runs back turns the drawn train only when playback does', () => {
|
||||
const p = pack();
|
||||
const ids = { tripId: 'full', routeId: 'main' };
|
||||
const binding = bindTrainPath(p, ids, fix(0, 300, 0));
|
||||
const forward = {
|
||||
from: { seq: 1, ...fix(0, 300, 0) },
|
||||
to: { seq: 2, ...fix(10_000, 500, 0) },
|
||||
};
|
||||
const sample = (fraction) => ({ fromSeq: 1, toSeq: 2, fraction });
|
||||
assert.ok(placeOnPath(binding, sample(0.2), forward, {}));
|
||||
assert.equal(binding.direction, 1);
|
||||
// The newest report lies behind the last one (a reversal, or GPS jitter)
|
||||
// while playback still draws the forward segment.
|
||||
assert.ok(followFix(binding, fix(10_000, 500, 0)));
|
||||
assert.ok(followFix(binding, fix(20_000, 450, 0)));
|
||||
assert.ok(placeOnPath(binding, sample(0.6), forward, {}));
|
||||
assert.equal(binding.direction, 1, 'the drawn train still runs forward');
|
||||
// Playback reaches the reversed segment: now it turns.
|
||||
const back = {
|
||||
from: { seq: 2, ...fix(10_000, 500, 0) },
|
||||
to: { seq: 3, ...fix(20_000, 450, 0) },
|
||||
};
|
||||
assert.ok(
|
||||
placeOnPath(binding, { fromSeq: 2, toSeq: 3, fraction: 0.5 }, back, {}),
|
||||
);
|
||||
assert.equal(binding.direction, -1);
|
||||
});
|
||||
Reference in new issue
Block a user