diff --git a/src/render/camera/events.js b/src/render/camera/events.js index df5e15479..cd3f26f3d 100644 --- a/src/render/camera/events.js +++ b/src/render/camera/events.js @@ -5,8 +5,9 @@ * export): * the listener lists, delivery (a throwing listener is reported, the rest * still run), the contract's per-listener `changed` measure, move detection - * (`moveStart` on a change, `moveEnd` 500 ms after the last one, never - * while following) and the command hooks (`onCommand`). A renderer calls + * (`moveStart` on a change, `moveEnd` 500 ms after the last one, as the + * reference measures them: a followed target that moves keeps the eye + * moving, one that stands still lets the move end) and the command hooks (`onCommand`). A renderer calls * `stepChanged()` and `stepMoveDetection()` once per frame, `command()` * before each camera command, and `emit()` for the events its engine * raises. @@ -52,18 +53,16 @@ function sameView(a, b) { /** * @param {{pose: () => import('../contract/camera').CameraPose, * world?: () => {position: object, direction: object, up: object}, - * following?: () => boolean, * report: (error: unknown) => void, thresholds?: boolean}} options `pose` * is read only while a `changed` listener is registered; `world` (the - * eye in world coordinates; `pose()` when omitted) and `following` (no - * `moveEnd` while true) are read by `stepMoveDetection`; `thresholds` + * eye in world coordinates; `pose()` when omitted) is read by + * `stepMoveDetection`; `thresholds` * false (a renderer without `cameraChangeThreshold`) ignores a listener's * own threshold, so every listener fires at 0.5. */ export function createCameraEvents({ pose, world = pose, - following = () => false, report, thresholds = true, }) { @@ -168,11 +167,7 @@ export function createCameraEvents({ moving = true; emit('moveStart'); } - } else if ( - moving && - !following() && - now - lastMovedAt >= MOVE_END_WAIT_MS - ) { + } else if (moving && now - lastMovedAt >= MOVE_END_WAIT_MS) { moving = false; emit('moveEnd'); } diff --git a/src/render/camera/events.test.mjs b/src/render/camera/events.test.mjs index d2e81750d..24fc8c53e 100644 --- a/src/render/camera/events.test.mjs +++ b/src/render/camera/events.test.mjs @@ -9,14 +9,12 @@ const view = (x) => ({ up: { x: 0, y: 0, z: 1 }, }); -test('moveStart on a change, moveEnd once nothing moved for 500 ms and nothing is followed', () => { +test('moveStart on a change, moveEnd once nothing moved for 500 ms', () => { let eye = view(7e6); - let following = false; const seen = []; const events = createCameraEvents({ pose: () => eye, world: () => eye, - following: () => following, report: (error) => assert.fail(error), }); events.on('moveStart', () => seen.push('start')); @@ -34,11 +32,7 @@ test('moveStart on a change, moveEnd once nothing moved for 500 ms and nothing i assert.deepEqual(seen, ['start']); events.stepMoveDetection(400 + MOVE_END_WAIT_MS - 1); assert.deepEqual(seen, ['start']); - following = true; events.stepMoveDetection(400 + MOVE_END_WAIT_MS); - assert.deepEqual(seen, ['start'], 'never while following'); - following = false; - events.stepMoveDetection(401 + MOVE_END_WAIT_MS); assert.deepEqual(seen, ['start', 'end']); }); diff --git a/src/render/cesium/camera.js b/src/render/cesium/camera.js index 00f140a9d..b717ef771 100644 --- a/src/render/cesium/camera.js +++ b/src/render/cesium/camera.js @@ -105,8 +105,8 @@ export function createCesiumCamera({ const removers = []; let lastWorld = null; // Camera events, measured on every tick: moveStart and moveEnd (500 ms - // after the last change of the eye or its field of view, by `now`, never - // while following), and `changed` per listener, where Cesium measures its + // after the last change of the eye or its field of view, by `now`, + // following or not, as Cesium's own), and `changed` per listener, where Cesium measures its // single threshold (`camera.percentageChanged`, which this leaves as it // is for everyone else listening to Cesium's own event). Cesium's own // moveStart and moveEnd are left out: it times them by the system clock. @@ -132,7 +132,6 @@ export function createCesiumCamera({ lastWorld = current; return lastWorld; }, - following: () => Boolean(following?.followed), report, thresholds: capabilities?.has('cameraChangeThreshold') ?? true, }); diff --git a/src/render/contract/camera.d.ts b/src/render/contract/camera.d.ts index 9f2da4435..ae87e7f8e 100644 --- a/src/render/contract/camera.d.ts +++ b/src/render/contract/camera.d.ts @@ -16,7 +16,9 @@ * view by the larger of the direction's turn over half the vertical field * of view and the eye's travel over its height, since the view last * fired. A frame can fire it twice, once for each measure. - * - `moveEnd` fires 500 ms after the last change, and never while following. + * - `moveEnd` fires 500 ms after the last change of the eye, following or + * not: a followed target that moves keeps the eye moving, and one that + * stands still lets the move end. * - A flight's `onCancel` and `onComplete` run synchronously, inside the call * or frame that ends it. * - Axes follow the usual convention: heading clockwise from north, pitch diff --git a/src/render/stub/camera.js b/src/render/stub/camera.js index dd98d0d3a..853cf90cf 100644 --- a/src/render/stub/camera.js +++ b/src/render/stub/camera.js @@ -110,7 +110,6 @@ export function createStubCamera({ direction: directionWC(), up: upWC(), }), - following: () => Boolean(followed), report, thresholds, }); diff --git a/src/render/stub/stub.test.mjs b/src/render/stub/stub.test.mjs index 55bd05b55..5e1d19f1f 100644 --- a/src/render/stub/stub.test.mjs +++ b/src/render/stub/stub.test.mjs @@ -180,7 +180,7 @@ test('the stub says where it draws an item, for a camera that is not its own', ( r.destroy(); }); -test('the stub camera ends no move while it follows', () => { +test('a follow ends its move once the target stands still, and never while it moves', () => { const r = createStubRenderer(); const seen = []; r.camera.on('moveStart', () => seen.push('start')); @@ -194,10 +194,18 @@ test('the stub camera ends no move while it follows', () => { viewFrom: { x: 0, y: -500, z: 300 }, }); r.testing.advance(2000); - assert.deepEqual(seen, ['start'], 'moveEnd waits for the follow to end'); - r.camera.follow(null); - r.testing.advance(1000); - assert.deepEqual(seen, ['start', 'end']); + assert.deepEqual(seen, ['start', 'end'], 'a still target ends the move'); + // A moving target keeps the eye moving: no moveEnd while it moves. + let east = 0; + r.camera.follow({ + key: 'moving', + position: () => + toEcef({ lon: -97.74 + (east += 1e-5), lat: 30.27, height: 0 }), + frame: 'enu', + viewFrom: { x: 0, y: -500, z: 300 }, + }); + r.testing.advance(2000); + assert.deepEqual(seen, ['start', 'end', 'start'], 'no end while it moves'); r.destroy(); });