mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
perf(cockpit): a Rail or Transit snapshot read again while nothing in it changed is the one read before
getSelectedTrain, getSelectedVehicle and getCockpitSubject fill drafts and freeze a new object only for a part whose values changed, so a view that reads them on every frame builds nothing while the train or vehicle stands still, and a moving one keeps its feed, stop and provenance objects. A train's stops are copied once per list the stops provider returns, each stop a frozen copy, instead of on every call.
This commit is contained in:
1 parent
a4f321a9ef
commit
294ccc0ee8
4 files changed
+303
-141
No files matched your search
@@ -4196,6 +4196,27 @@ test('the selected vehicle reads as a snapshot of its place, motion and source',
|
||||
assert.ok(Number.isFinite(view.position.latitude));
|
||||
});
|
||||
|
||||
test('a vehicle read again while nothing changed is the snapshot read before', async (t) => {
|
||||
const app = harness(t);
|
||||
const key = await busRunningNorth(app);
|
||||
app.layer._transitPartsForTest().selection.selectVehicle(key);
|
||||
const first = app.layer.getSelectedVehicle();
|
||||
assert.equal(app.layer.getSelectedVehicle(), first, 'the same snapshot');
|
||||
// It moves on: a new snapshot at its new place, what did not change kept.
|
||||
app.run(TRANSIT_POLL_MS);
|
||||
await app.layer.update();
|
||||
app.settle();
|
||||
app.run(TRANSIT_POLL_MS);
|
||||
const moved = app.layer.getSelectedVehicle();
|
||||
assert.notEqual(moved, first, 'a new snapshot');
|
||||
assert.ok(Object.isFrozen(moved) && Object.isFrozen(moved.position));
|
||||
assert.ok(moved.position.latitude > first.position.latitude, 'moved');
|
||||
assert.equal(moved.feed, first.feed);
|
||||
assert.equal(moved.stop, first.stop);
|
||||
assert.equal(moved.provenance, first.provenance);
|
||||
assert.equal(app.layer.getSelectedVehicle(), moved);
|
||||
});
|
||||
|
||||
test('selectedAtMs is the user’s selection time; a hold and a deselection leave none', async (t) => {
|
||||
const app = harness(t);
|
||||
const key = await busRunningNorth(app);
|
||||
|
||||
Reference in new issue
Block a user