mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(camera): moveEnd fires during a follow once the eye stands still, as Cesium's did
Cesium raised moveEnd 500 ms after the camera last moved, following or not: a followed target that moves keeps the eye moving, and one that stands still (a marker, a parked aircraft) lets the move end once the user stops orbiting it. The port never raised moveEnd while following, so Weather, Recent Imagery, the share link and every other moveEnd listener stopped catching up around a still target. The rule is now the eye's alone, through the shared camera events.
This commit is contained in:
1 parent
63a6595eaf
commit
5d48503c51
6 files changed
+25
-28
No files matched your search
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
Vendored
+3
-1
@@ -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
|
||||
|
||||
@@ -110,7 +110,6 @@ export function createStubCamera({
|
||||
direction: directionWC(),
|
||||
up: upWC(),
|
||||
}),
|
||||
following: () => Boolean(followed),
|
||||
report,
|
||||
thresholds,
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user