mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +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
@@ -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