mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
fix(rail, transit): a train or vehicle a first-person view holds draws no 3D model either, since the view's eye is inside it; let go, its model draws again
The fleet models (#1714) draw nearby trains and vehicles under the 3D toggle. A held one now leaves out its model as it does its icon, as the Vessels layer does for its bridge subject: its model item is hidden, and handing the visual back to its icon keeps the icon hidden while held. Tests drive each layer with the real fleet-model layer and a stubbed glTF loader; both fail without the fix.
This commit is contained in:
1 parent
546ac22708
commit
974023510f
12 files changed
+212
-17
No files matched your search
@@ -95,8 +95,8 @@ function reuse(previous, next) {
|
||||
* and a part that did not change (its feed, its line, its stops) is the same
|
||||
* object in the next one, so a view can read it on every frame. `path.line`
|
||||
* is a frozen copy of the train's line for `pointAtS` and `projectOnPath`.
|
||||
* `setCockpitSubject(key)` holds a train: its marker, card and selected line
|
||||
* are hidden, it stays selected (so its stops stay fresh and its feed stays
|
||||
* `setCockpitSubject(key)` holds a train: its marker, 3D model, card and
|
||||
* selected line are hidden, it stays selected (so its stops stay fresh and its feed stays
|
||||
* polled at any distance) and clicks and Escape no longer change the
|
||||
* selection. A held train keeps moving, hidden, and keeps the selection when
|
||||
* its category is turned off, and is the copy of its train drawn though
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
import { RAIL_SELECTED_OVERLAY_SOURCE_ID } from './policy.js';
|
||||
import { publicRailCatalog } from '../../data/railFeeds.js';
|
||||
import { pointAtS } from '../../data/railPaths.js';
|
||||
import { fleetModelFakes } from '../../testSupport/fleetModelFakes.mjs';
|
||||
|
||||
const M_PER_DEG = 111_320;
|
||||
const LAT = 42.36;
|
||||
@@ -228,6 +229,38 @@ test('a held train hides its marker and card and keeps the selection', async (t)
|
||||
);
|
||||
});
|
||||
|
||||
test('a held train draws no 3D model either; let go, its model draws again', async (t) => {
|
||||
const models = await fleetModelFakes(t);
|
||||
const app = await onTheLine(t, { fleet: models.fleet, altitude: 1_000 });
|
||||
// A model's load answers off the frame; the next frames place it.
|
||||
const frames = async () => {
|
||||
app.run(500);
|
||||
await app.settle();
|
||||
app.run(500);
|
||||
};
|
||||
await frames();
|
||||
assert.equal(models.drawn(T1).length, 1, 'near the camera: its model');
|
||||
assert.equal(app.entry(T1).modelOwnsVisual, true);
|
||||
assert.equal(app.entry(T1).marker.show, false, 'its icon hands over');
|
||||
|
||||
assert.equal(app.layer.setCockpitSubject(T1), true);
|
||||
app.run(250);
|
||||
// The view's eye is inside the train.
|
||||
assert.equal(models.drawn(T1).length, 0, 'no model');
|
||||
assert.equal(app.entry(T1).modelOwnsVisual, false);
|
||||
assert.equal(app.entry(T1).marker.show, false, 'and no icon');
|
||||
assert.equal(models.drawn(T2).length, 1, 'another train keeps its model');
|
||||
await frames();
|
||||
assert.equal(models.drawn(T1).length, 0, 'not on a later frame either');
|
||||
assert.equal(app.entry(T1).marker.show, false);
|
||||
|
||||
assert.equal(app.layer.setCockpitSubject(null), true);
|
||||
await frames();
|
||||
assert.equal(models.drawn(T1).length, 1, 'let go: its model again');
|
||||
assert.equal(app.entry(T1).modelOwnsVisual, true);
|
||||
assert.equal(app.entry(T1).marker.show, false);
|
||||
});
|
||||
|
||||
const MADRID = { lat: 40.4168, lon: -3.7038 };
|
||||
|
||||
test('a held train stays the copy drawn when another feed’s copy outranks it, and keeps moving', async (t) => {
|
||||
|
||||
@@ -89,7 +89,7 @@ function createState({ services }) {
|
||||
_heldFeedId: null,
|
||||
/**
|
||||
* The train a first-person view holds (cockpitSubject.js), or null: its
|
||||
* marker and card are hidden and the selection stays on it.
|
||||
* marker, 3D model and card are hidden and the selection stays on it.
|
||||
*/
|
||||
_cockpitSubjectKey: null,
|
||||
/**
|
||||
|
||||
@@ -526,7 +526,7 @@ export function createRendering({ state, services, parts }) {
|
||||
/**
|
||||
* Whether a train's icon is drawn: shown, not drawn by its model, and no
|
||||
* first-person view rides it (cockpitSubject.js). A held train keeps its
|
||||
* playback; only its icon hides.
|
||||
* playback; only its icon and model hide.
|
||||
*/
|
||||
function markerShown(entry) {
|
||||
return (
|
||||
@@ -760,7 +760,9 @@ export function createRendering({ state, services, parts }) {
|
||||
}
|
||||
item.position = entry.marker.position;
|
||||
item.headingDeg = Number.isFinite(entry.courseDeg) ? entry.courseDeg : 0;
|
||||
item.show = categoryShown(entry);
|
||||
// A train a first-person view rides draws no model: the camera is inside
|
||||
// it (cockpitSubject.js).
|
||||
item.show = categoryShown(entry) && entry.key !== state._cockpitSubjectKey;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ function reuse(previous, next) {
|
||||
* that did not change (its feed, its stop) is the same object in the next
|
||||
* one, so a view can read it on every frame. Transit has no route shapes or
|
||||
* stops, so a snapshot names only the vehicle's last reported stop.
|
||||
* `setCockpitSubject(key)` holds a vehicle: its sprite, card, trail and
|
||||
* detection box are hidden, it keeps moving when it is out of the camera's
|
||||
* `setCockpitSubject(key)` holds a vehicle: its sprite, 3D model, card,
|
||||
* trail and detection box are hidden, it keeps moving when it is out of the camera's
|
||||
* view, its feed stays polled, and clicks and Escape no longer change the
|
||||
* selection. The hold ends with `setCockpitSubject(null)`, and on
|
||||
* its own when the vehicle is removed or the layer is turned off.
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
VEHICLE_MAX_FIX_AGE_MS,
|
||||
} from './policy.js';
|
||||
import { FLOOR_WARM_PER_POLL } from './policy.js';
|
||||
import { fleetModelFakes } from '../../testSupport/fleetModelFakes.mjs';
|
||||
import {
|
||||
FUTURE_STAMP_TOLERANCE_MS,
|
||||
ORDER_REJECTS_BEFORE_RESET,
|
||||
@@ -66,6 +67,25 @@ function snapshot(
|
||||
};
|
||||
}
|
||||
|
||||
/** A camera's place and frame looking straight down from `altitude` over `at`. */
|
||||
function lookingDown(at, altitude) {
|
||||
const positionWC = Cesium.Cartesian3.fromDegrees(at.lon, at.lat, altitude);
|
||||
const up = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(
|
||||
positionWC,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
return {
|
||||
positionWC,
|
||||
directionWC: Cesium.Cartesian3.negate(up, new Cesium.Cartesian3()),
|
||||
upWC: Cesium.Cartesian3.UNIT_Z,
|
||||
frustum: {
|
||||
computeCullingVolume: () => ({
|
||||
computeVisibility: () => Cesium.Intersect.INSIDE,
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** A vehicle record as the proxy emits it, with its timestamp source resolved. */
|
||||
function vehicle(id, lat, lon, atSeconds, extra = {}) {
|
||||
return {
|
||||
@@ -160,6 +180,9 @@ function harness(
|
||||
east: at.lon + 0.1,
|
||||
north: at.lat + 0.1,
|
||||
},
|
||||
// Fleet-model services (testSupport/fleetModelFakes.mjs), with a camera
|
||||
// looking straight down for them; without them vehicles stay icons.
|
||||
fleet = null,
|
||||
} = {},
|
||||
) {
|
||||
const viewRect = { ...view };
|
||||
@@ -220,6 +243,7 @@ function harness(
|
||||
viewRect.north,
|
||||
);
|
||||
},
|
||||
...(fleet ? lookingDown(at, altitude) : {}),
|
||||
},
|
||||
scene: {
|
||||
canvas: { addEventListener() {}, removeEventListener() {} },
|
||||
@@ -266,6 +290,7 @@ function harness(
|
||||
const layer = createTransitLayer({
|
||||
source,
|
||||
services: {
|
||||
...(fleet ? { fleet } : {}),
|
||||
ground,
|
||||
mesh: {
|
||||
sampleMeshFloorCells(scene, points, options) {
|
||||
@@ -4217,6 +4242,42 @@ test('a vehicle read again while nothing changed is the snapshot read before', a
|
||||
assert.equal(app.layer.getSelectedVehicle(), moved);
|
||||
});
|
||||
|
||||
test('a held vehicle draws no 3D model either; let go, its model draws again', async (t) => {
|
||||
const models = await fleetModelFakes(t);
|
||||
const app = harness(t, { fleet: models.fleet, altitude: 1_000 });
|
||||
const key = await busRunningNorth(app);
|
||||
const [entry] = app.vehicles();
|
||||
assert.notEqual(entry.mode, 'unknown', 'a mode its model is chosen by');
|
||||
// The throttled sweep runs; a model's load answers off the frame and the
|
||||
// next frames place it.
|
||||
const frames = async () => {
|
||||
app.advance(250);
|
||||
app.settle();
|
||||
for (let i = 0; i < 8; i += 1) await Promise.resolve();
|
||||
app.settle();
|
||||
};
|
||||
await frames();
|
||||
assert.equal(models.drawn(key).length, 1, 'near the camera: its model');
|
||||
assert.equal(entry.modelOwnsVisual, true);
|
||||
assert.equal(entry.marker.show, false, 'its icon hands over');
|
||||
|
||||
assert.equal(app.layer.setCockpitSubject(key), true);
|
||||
app.frame();
|
||||
// The view's eye is inside the vehicle.
|
||||
assert.equal(models.drawn(key).length, 0, 'no model');
|
||||
assert.equal(entry.modelOwnsVisual, false);
|
||||
assert.equal(entry.marker.show, false, 'and no icon');
|
||||
await frames();
|
||||
assert.equal(models.drawn(key).length, 0, 'not on a later frame either');
|
||||
assert.equal(entry.marker.show, false);
|
||||
|
||||
assert.equal(app.layer.setCockpitSubject(null), true);
|
||||
await frames();
|
||||
assert.equal(models.drawn(key).length, 1, 'let go: its model again');
|
||||
assert.equal(entry.modelOwnsVisual, true);
|
||||
assert.equal(entry.marker.show, false);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
@@ -493,7 +493,7 @@ export function createRendering({ state, services, parts }) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Hand an entry's visual back to its icon. */
|
||||
/** Hand an entry's visual back to its icon, unless a view rides it. */
|
||||
function handBack(entry) {
|
||||
if (!entry.modelOwnsVisual) return;
|
||||
entry.modelOwnsVisual = false;
|
||||
@@ -501,7 +501,8 @@ export function createRendering({ state, services, parts }) {
|
||||
entry.marker.show =
|
||||
vehicleInView(entry) &&
|
||||
!entry.heightPending &&
|
||||
entry.surfaceReady !== false;
|
||||
entry.surfaceReady !== false &&
|
||||
entry.key !== state._cockpitSubjectKey;
|
||||
}
|
||||
|
||||
function updateModels() {
|
||||
@@ -538,7 +539,12 @@ export function createRendering({ state, services, parts }) {
|
||||
}
|
||||
item.position = entry.marker.position;
|
||||
item.headingDeg = Number.isFinite(entry.courseDeg) ? entry.courseDeg : 0;
|
||||
item.show = !entry.heightPending && entry.surfaceReady !== false;
|
||||
// A vehicle a first-person view rides draws no model: the camera is
|
||||
// inside it (cockpitSubject.js).
|
||||
item.show =
|
||||
!entry.heightPending &&
|
||||
entry.surfaceReady !== false &&
|
||||
entry.key !== state._cockpitSubjectKey;
|
||||
next.set(entry.key, item);
|
||||
}
|
||||
for (const [key, item] of modelItems)
|
||||
|
||||
@@ -99,8 +99,8 @@ export function createState({ services }) {
|
||||
state._selectedAtMs = null;
|
||||
/**
|
||||
* The vehicle a first-person view holds (cockpitSubject.js), or null: its
|
||||
* sprite, card, trail and detection box are hidden, and it keeps moving
|
||||
* out of the camera's view.
|
||||
* sprite, 3D model, card, trail and detection box are hidden, and it keeps
|
||||
* moving out of the camera's view.
|
||||
* @type {string|null}
|
||||
*/
|
||||
state._cockpitSubjectKey = null;
|
||||
|
||||
Reference in new issue
Block a user