mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Transit cockpit rides: hide the held icon, end a hold with the layer, no ellipsoid height
- A held vehicle's icon is hidden through the renderer (setShown, then flushMarkers). The icon sets draw a marker only as last pushed, so the direct marker.show write left a parked vehicle's icon drawn under the view's eye. - disable() ends the hold: turned off and on again, the vehicle shows and clicks and Escape reach the layer. - Far above the ground a vehicle with no floor is drawn on the ellipsoid. Its snapshot now reports groundHeightM null there, as near the ground, instead of -1.5 m. - The uneven-ground test also checks the snapshot mid-segment, where a blend of the two reports' floors would read about 55 m instead of 10 m.
This commit is contained in:
1 parent
624c229bc2
commit
134138931f
4 files changed
+123
-7
No files matched your search
@@ -84,12 +84,16 @@ export function createTransitCockpitSubject({ state, parts, services }) {
|
||||
* or held), which near the ground follows the terrain between reports;
|
||||
* else its segment's two reports' floors at the playback fraction. Null
|
||||
* while either floor is unknown, as on cold terrain, so a view waits for
|
||||
* the surface. Not `entry.heightM`, the floor at the newest report, which
|
||||
* playback has not reached yet.
|
||||
* the surface: far above the ground such a marker is drawn on the
|
||||
* ellipsoid, which is no floor. Not `entry.heightM`, the floor at the
|
||||
* newest report, which playback has not reached yet.
|
||||
*/
|
||||
function drawnFloorOf(entry) {
|
||||
const segment = entry.segment;
|
||||
if (!segment || entry.heightPending) return null;
|
||||
const from = segment.from?.h;
|
||||
const to = segment.to?.h;
|
||||
if (!Number.isFinite(from) || !Number.isFinite(to)) return null;
|
||||
const placed =
|
||||
entry.surfaceReady === true &&
|
||||
entry.hasRendered &&
|
||||
@@ -99,9 +103,6 @@ export function createTransitCockpitSubject({ state, parts, services }) {
|
||||
const drawn = toCartographicRadians(entry.marker.position);
|
||||
if (drawn) return drawn.height - liftM;
|
||||
}
|
||||
const from = segment.from?.h;
|
||||
const to = segment.to?.h;
|
||||
if (!Number.isFinite(from) || !Number.isFinite(to)) return null;
|
||||
const f = Number.isFinite(segment.fraction)
|
||||
? Math.max(0, Math.min(1, segment.fraction))
|
||||
: 1;
|
||||
@@ -173,11 +174,17 @@ export function createTransitCockpitSubject({ state, parts, services }) {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
/** Show or hide a vehicle's sprite and trail for the hold. */
|
||||
/**
|
||||
* Show or hide a vehicle's sprite and trail for the hold. The sprite goes
|
||||
* through the renderer (setShown, flushMarkers): its set draws a marker
|
||||
* only as last pushed.
|
||||
*/
|
||||
function repaint(entry) {
|
||||
if (!entry?.marker) return;
|
||||
if (entry.key === state._cockpitSubjectKey) entry.marker.show = false;
|
||||
if (entry.key === state._cockpitSubjectKey)
|
||||
parts.rendering.setShown(entry, false);
|
||||
else parts.rendering.placeSample(entry);
|
||||
parts.rendering.flushMarkers();
|
||||
parts.rendering.schedulePlayback(entry);
|
||||
parts.trails.update();
|
||||
state._detectRevision += 1;
|
||||
|
||||
@@ -165,6 +165,8 @@ export function createLifecycle({ state, services, parts }) {
|
||||
state._visible.clear();
|
||||
clearTimeout(state._cameraDebounceTimer);
|
||||
state._cameraDebounceTimer = null;
|
||||
// A hold ends with the layer (cockpitSubject.js).
|
||||
state._cockpitSubjectKey = null;
|
||||
parts.selection.clearSelection();
|
||||
state._overlayHost.setVisible(TRANSIT_SELECTED_OVERLAY_SOURCE_ID, false);
|
||||
parts.selection.removeClickHandler();
|
||||
|
||||
@@ -978,6 +978,34 @@ test('a held vehicle with no floor yet tells its view no height', async (t) => {
|
||||
assert.equal(app.layer.getCockpitSubject().position.groundHeightM, null);
|
||||
});
|
||||
|
||||
test('far above the ground, a held vehicle drawn on the ellipsoid tells its view no height', async (t) => {
|
||||
// Above the height gate a vehicle with no floor is drawn on the ellipsoid
|
||||
// at once, not held back; the ellipsoid is still no floor to stand a view
|
||||
// on.
|
||||
const app = harness(t, { altitude: 100_000, floorAt: () => undefined });
|
||||
app.serve('mbta', () => ({
|
||||
status: 200,
|
||||
body: snapshot(
|
||||
'mbta',
|
||||
'MBTA',
|
||||
[vehicle('bus-1', 42.36, -71.06, Date.now() / 1000)],
|
||||
{ fetchedAt: Date.now() },
|
||||
),
|
||||
}));
|
||||
app.layer.enable(app.viewer);
|
||||
await app.layer.update();
|
||||
app.settle();
|
||||
const [entry] = app.vehicles();
|
||||
assert.ok(app.layer.setCockpitSubject(entry.key) !== false);
|
||||
app.frame();
|
||||
assert.equal(entry.surfaceReady, true, 'it is drawn');
|
||||
const drawnM = Cesium.Cartographic.fromCartesian(
|
||||
entry.marker.position,
|
||||
).height;
|
||||
assert.ok(Math.abs(drawnM) < 1e-3, `on the ellipsoid, got ${drawnM} m`);
|
||||
assert.equal(app.layer.getCockpitSubject().position.groundHeightM, null);
|
||||
});
|
||||
|
||||
test('a vehicle waits for its floor rather than standing on the ellipsoid', async (t) => {
|
||||
// The shared ground-floor system answers from the rendered mesh cell or the
|
||||
// real DEM cell; until one of them is warm there is no honest height to draw
|
||||
@@ -2125,6 +2153,11 @@ test('a segment climbs from the ground it left to the ground it reaches', async
|
||||
Math.abs(height() - 11.5) < 3,
|
||||
`at the corridor floor, got ${height().toFixed(1)} m`,
|
||||
);
|
||||
// The two reports' floors blended at the fraction would say about 55 m.
|
||||
assert.ok(
|
||||
Math.abs(floor() + 1.5 - height()) < 1,
|
||||
`its snapshot stands on that floor too, got ${floor().toFixed(1)} m`,
|
||||
);
|
||||
app.run(TRANSIT_POLL_MS);
|
||||
assert.ok(
|
||||
Math.abs(height() - 101.5) < 1.5,
|
||||
@@ -4880,3 +4913,76 @@ test('a held vehicle hides, keeps moving out of view, and lets go when it goes',
|
||||
assert.equal(app.state()._cockpitSubjectKey, null);
|
||||
assert.equal(app.layer.getCockpitSubject(), null);
|
||||
});
|
||||
|
||||
test('turning Transit off ends a hold; on again, Escape deselects and the vehicle shows', async (t) => {
|
||||
const app = harness(t);
|
||||
const key = await busRunningNorth(app);
|
||||
assert.equal(app.layer.setCockpitSubject(key), true);
|
||||
app.layer.disable(app.viewer);
|
||||
assert.equal(
|
||||
app.state()._cockpitSubjectKey,
|
||||
null,
|
||||
'the hold ended with the layer',
|
||||
);
|
||||
// On again, without a release: the same bus is listed again.
|
||||
app.layer.enable(app.viewer);
|
||||
await app.layer.update();
|
||||
app.settle();
|
||||
app.run(TRANSIT_POLL_MS);
|
||||
await app.layer.update();
|
||||
app.settle();
|
||||
assert.equal(app.layer.focusVehicle(key), true);
|
||||
const [entry] = app.vehicles();
|
||||
app.frame();
|
||||
assert.equal(entry.marker.show, true, 'the vehicle is drawn, not held');
|
||||
globalThis.document.dispatchEvent(
|
||||
Object.assign(new Event('keydown'), { key: 'Escape' }),
|
||||
);
|
||||
assert.equal(app.state()._selectedKey, null, 'Escape deselects');
|
||||
});
|
||||
|
||||
test('a held parked vehicle draws no icon; let go, it draws its icon again', async (t) => {
|
||||
// A parked bus with no course: nothing moves or turns its icon, so only the
|
||||
// hold itself can take the icon out of the set that draws it.
|
||||
const app = harness(t);
|
||||
app.serve('mbta', () => ({
|
||||
status: 200,
|
||||
body: snapshot(
|
||||
'mbta',
|
||||
'MBTA',
|
||||
[vehicle('bus-1', 42.36, -71.06, reported(), { stopId: 'place-1' })],
|
||||
{ fetchedAt: Date.now() },
|
||||
),
|
||||
}));
|
||||
app.layer.enable(app.viewer);
|
||||
await app.layer.update();
|
||||
app.settle();
|
||||
for (let i = 0; i < 3; i += 1) {
|
||||
app.run(TRANSIT_POLL_MS);
|
||||
await app.layer.update();
|
||||
app.settle();
|
||||
}
|
||||
const key = 'mbta:bus-1';
|
||||
const [entry] = app.vehicles();
|
||||
const icon = () =>
|
||||
app.markers('still').get(key) ?? app.markers('moving').get(key);
|
||||
assert.equal(icon()?.show, true, 'drawn before the hold');
|
||||
assert.equal(app.layer.setCockpitSubject(key), true);
|
||||
// The view rides it for a while: frames, a sweep, a poll.
|
||||
app.run(2_000, 16);
|
||||
app.settle();
|
||||
app.run(TRANSIT_POLL_MS);
|
||||
await app.layer.update();
|
||||
app.settle();
|
||||
assert.equal(entry.marker.show, false, 'its marker is hidden');
|
||||
assert.equal(
|
||||
icon()?.show ?? false,
|
||||
false,
|
||||
'and so is the icon the set draws',
|
||||
);
|
||||
|
||||
assert.equal(app.layer.setCockpitSubject(null), true);
|
||||
app.advance(250);
|
||||
app.settle();
|
||||
assert.equal(icon()?.show, true, 'let go: drawn again');
|
||||
});
|
||||
@@ -1225,6 +1225,7 @@ export function createRendering({ state, services, parts }) {
|
||||
setNameOf,
|
||||
markerShown,
|
||||
markDirty,
|
||||
setShown,
|
||||
flushMarkers,
|
||||
removeMarker,
|
||||
watchCamera,
|
||||
|
||||
Reference in new issue
Block a user