mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 00:02:25 +00:00
Followed-contact mark fade scales with elapsed time; camera pose sampling runs until moveEnd; reinstalling drops the camera hold
This commit is contained in:
1 parent
30cc22fbef
commit
d54bed9cd9
4 files changed
+56
-14
No files matched your search
@@ -1,3 +1,3 @@
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- While anything moves (layers in motion, the camera, a followed contact), the globe now draws at the display's own refresh rate instead of a fixed 60 frames a second. A parked scene still ticks at most 60 times a second. Waits that counted frames (a followed contact's first position, a shared follow view, a trail's temporary copy) now count drawn time, so they last the same at any refresh rate.
|
- While anything moves (layers in motion, the camera, a followed contact), the globe now draws at the display's own refresh rate instead of a fixed 60 frames a second. A parked scene still ticks at most 60 times a second. Waits that counted frames (a followed contact's first position, a shared follow view, a trail's temporary copy) now count drawn time, so they last the same at any refresh rate. Screen marks over a followed contact fade out over the same time at any refresh rate.
|
||||||
@@ -399,7 +399,12 @@ export function createScreenAnnotationRenderer(
|
|||||||
// from the host's ACTUAL painted rectangle after final layout; the billboard extent
|
// from the host's ACTUAL painted rectangle after final layout; the billboard extent
|
||||||
// is unioned for aircraft/satellites that also own a native tracked graphic.
|
// is unioned for aircraft/satellites that also own a native tracked graphic.
|
||||||
const TRACKED_BBOX_MARGIN = 8; // px buffer added around the footprint
|
const TRACKED_BBOX_MARGIN = 8; // px buffer added around the footprint
|
||||||
const TRACKED_FADE_EASE = 0.22; // per-frame ease toward hidden(0) / visible(1)
|
// Ease toward hidden(0) / visible(1): this share of the gap closes in one
|
||||||
|
// 60 Hz frame (about 200 ms to settle), scaled by elapsed time so the fade
|
||||||
|
// takes as long at any refresh rate.
|
||||||
|
const TRACKED_FADE_EASE = 0.22;
|
||||||
|
const TRACKED_FADE_FRAME_MS = 1000 / 60;
|
||||||
|
let trackedFadeAtMs = NaN;
|
||||||
const TRACKED_HYSTERESIS_PX = 18; // dead-band so the overlap test can't flip-flop
|
const TRACKED_HYSTERESIS_PX = 18; // dead-band so the overlap test can't flip-flop
|
||||||
const _scratchTrackedWin = new Cesium.Cartesian2();
|
const _scratchTrackedWin = new Cesium.Cartesian2();
|
||||||
|
|
||||||
@@ -676,7 +681,17 @@ export function createScreenAnnotationRenderer(
|
|||||||
// footprints live in the world layer — so fully hiding an overlapped one is
|
// footprints live in the world layer — so fully hiding an overlapped one is
|
||||||
// safe and not jarring.
|
// safe and not jarring.
|
||||||
function fadeTracked(trackedRect) {
|
function fadeTracked(trackedRect) {
|
||||||
if (!shown()) return;
|
if (!shown()) {
|
||||||
|
trackedFadeAtMs = NaN;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const nowMs = performance.now();
|
||||||
|
const stepMs = Number.isFinite(trackedFadeAtMs)
|
||||||
|
? Math.min(Math.max(nowMs - trackedFadeAtMs, 0), 100)
|
||||||
|
: TRACKED_FADE_FRAME_MS;
|
||||||
|
trackedFadeAtMs = nowMs;
|
||||||
|
const ease =
|
||||||
|
1 - Math.pow(1 - TRACKED_FADE_EASE, stepMs / TRACKED_FADE_FRAME_MS);
|
||||||
let changed = false;
|
let changed = false;
|
||||||
for (const rec of records.values()) {
|
for (const rec of records.values()) {
|
||||||
const { anno, group } = rec;
|
const { anno, group } = rec;
|
||||||
@@ -705,10 +720,10 @@ export function createScreenAnnotationRenderer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const target = overlapping ? 0 : 1;
|
const target = overlapping ? 0 : 1;
|
||||||
const next = cur + (target - cur) * TRACKED_FADE_EASE;
|
const next = cur + (target - cur) * ease;
|
||||||
rec._trackedFade = Math.abs(next - target) < 0.02 ? target : next;
|
rec._trackedFade = Math.abs(next - target) < 0.02 ? target : next;
|
||||||
// The base alpha applies unless faded. (The CSS `transition: opacity` was
|
// The base alpha applies unless faded. (The CSS `transition: opacity` was
|
||||||
// removed from .gev-anno so this per-frame JS ease is the ONLY easing —
|
// removed from .gev-anno so this JS ease is the ONLY easing —
|
||||||
// previously the two fought and produced an opacity oscillation.)
|
// previously the two fought and produced an opacity oscillation.)
|
||||||
const opacity = String(
|
const opacity = String(
|
||||||
(anno.alpha ?? 1) * (rec._trackedFade !== 1 ? rec._trackedFade : 1),
|
(anno.alpha ?? 1) * (rec._trackedFade !== 1 ? rec._trackedFade : 1),
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ function applyMode() {
|
|||||||
const CAMERA_SAMPLE_MS = 250;
|
const CAMERA_SAMPLE_MS = 250;
|
||||||
const CAMERA_POSITION_TOLERANCE_M = 1e-3;
|
const CAMERA_POSITION_TOLERANCE_M = 1e-3;
|
||||||
const CAMERA_DIRECTION_TOLERANCE = 1e-9;
|
const CAMERA_DIRECTION_TOLERANCE = 1e-9;
|
||||||
const CAMERA_GIVE_UP_MS = 5 * 60_000;
|
|
||||||
|
|
||||||
function near(a, b, tolerance) {
|
function near(a, b, tolerance) {
|
||||||
return (
|
return (
|
||||||
@@ -86,9 +85,9 @@ function near(a, b, tolerance) {
|
|||||||
* a rounding error every frame, so `moveEnd` never comes (see
|
* a rounding error every frame, so `moveEnd` never comes (see
|
||||||
* `installGlobeInViewRecovery` in app/viewer.js). So from `moveStart` until
|
* `installGlobeInViewRecovery` in app/viewer.js). So from `moveStart` until
|
||||||
* `moveEnd` the pose is also sampled every 250 ms with a tolerance for that
|
* `moveEnd` the pose is also sampled every 250 ms with a tolerance for that
|
||||||
* drift: half a second at rest releases the hold, a later move takes it
|
* drift: half a second at rest releases the hold and a later move takes it
|
||||||
* again (Cesium raises no new `moveStart` under that drift), and sampling
|
* again (Cesium raises no new `moveStart` under that drift). Sampling runs
|
||||||
* stops five minutes after the camera last moved.
|
* until `moveEnd`, however long that takes; it costs four checks a second.
|
||||||
* @returns {(() => void)|null} Removes the listeners and the sampling.
|
* @returns {(() => void)|null} Removes the listeners and the sampling.
|
||||||
*/
|
*/
|
||||||
function watchCameraMotion(camera, { schedule, unschedule }) {
|
function watchCameraMotion(camera, { schedule, unschedule }) {
|
||||||
@@ -96,7 +95,6 @@ function watchCameraMotion(camera, { schedule, unschedule }) {
|
|||||||
const last = { position: null, direction: null };
|
const last = { position: null, direction: null };
|
||||||
let timer = null;
|
let timer = null;
|
||||||
let restingSamples = 0;
|
let restingSamples = 0;
|
||||||
let restingMs = 0;
|
|
||||||
const copy = (v) => (v ? { x: v.x, y: v.y, z: v.z } : null);
|
const copy = (v) => (v ? { x: v.x, y: v.y, z: v.z } : null);
|
||||||
const remember = () => {
|
const remember = () => {
|
||||||
last.position = copy(camera.positionWC);
|
last.position = copy(camera.positionWC);
|
||||||
@@ -118,12 +116,9 @@ function watchCameraMotion(camera, { schedule, unschedule }) {
|
|||||||
near(direction, last.direction, CAMERA_DIRECTION_TOLERANCE));
|
near(direction, last.direction, CAMERA_DIRECTION_TOLERANCE));
|
||||||
if (atRest) {
|
if (atRest) {
|
||||||
restingSamples += 1;
|
restingSamples += 1;
|
||||||
restingMs += CAMERA_SAMPLE_MS;
|
|
||||||
if (restingSamples >= 2) releaseContinuousRender('camera');
|
if (restingSamples >= 2) releaseContinuousRender('camera');
|
||||||
if (restingMs >= CAMERA_GIVE_UP_MS) return;
|
|
||||||
} else {
|
} else {
|
||||||
restingSamples = 0;
|
restingSamples = 0;
|
||||||
restingMs = 0;
|
|
||||||
holdContinuousRender('camera');
|
holdContinuousRender('camera');
|
||||||
}
|
}
|
||||||
remember();
|
remember();
|
||||||
@@ -133,7 +128,6 @@ function watchCameraMotion(camera, { schedule, unschedule }) {
|
|||||||
holdContinuousRender('camera');
|
holdContinuousRender('camera');
|
||||||
stopSampling();
|
stopSampling();
|
||||||
restingSamples = 0;
|
restingSamples = 0;
|
||||||
restingMs = 0;
|
|
||||||
remember();
|
remember();
|
||||||
timer = schedule(sample, CAMERA_SAMPLE_MS);
|
timer = schedule(sample, CAMERA_SAMPLE_MS);
|
||||||
});
|
});
|
||||||
@@ -175,6 +169,7 @@ export function installRenderGovernor(
|
|||||||
// explicit requests.
|
// explicit requests.
|
||||||
viewer.scene.maximumRenderTimeChange = Infinity;
|
viewer.scene.maximumRenderTimeChange = Infinity;
|
||||||
_removeCameraListeners?.();
|
_removeCameraListeners?.();
|
||||||
|
_holds.delete('camera');
|
||||||
_removeCameraListeners = watchCameraMotion(
|
_removeCameraListeners = watchCameraMotion(
|
||||||
viewer.camera ?? viewer.scene.camera,
|
viewer.camera ?? viewer.scene.camera,
|
||||||
timers,
|
timers,
|
||||||
|
|||||||
@@ -197,3 +197,35 @@ test('a camera that drifts by rounding errors and never raises moveEnd still rel
|
|||||||
assert.equal(scene.requestRenderMode, true);
|
assert.equal(scene.requestRenderMode, true);
|
||||||
assert.equal(timers.pending, 0);
|
assert.equal(timers.pending, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('sampling keeps running until moveEnd, so a move after a long drift still takes the hold', () => {
|
||||||
|
const { viewer, scene } = makeViewer();
|
||||||
|
const timers = fakeTimers();
|
||||||
|
viewer.camera = {
|
||||||
|
moveStart: makeEvent(),
|
||||||
|
moveEnd: makeEvent(),
|
||||||
|
positionWC: { x: 1, y: 0, z: 0 },
|
||||||
|
directionWC: { x: -1, y: 0, z: 0 },
|
||||||
|
};
|
||||||
|
installRenderGovernor(viewer, timers);
|
||||||
|
viewer.camera.moveStart.raise();
|
||||||
|
// Ten minutes at rest (2,400 samples): released, still sampling.
|
||||||
|
for (let i = 0; i < 2_400; i++) timers.run();
|
||||||
|
assert.equal(scene.requestRenderMode, true);
|
||||||
|
assert.equal(timers.pending, 1);
|
||||||
|
viewer.camera.positionWC = { x: 1_000, y: 0, z: 0 };
|
||||||
|
timers.run();
|
||||||
|
assert.equal(scene.requestRenderMode, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('installing again drops a camera hold the old listeners can no longer release', () => {
|
||||||
|
const { viewer, scene } = makeViewer();
|
||||||
|
const timers = fakeTimers();
|
||||||
|
viewer.camera = { moveStart: makeEvent(), moveEnd: makeEvent() };
|
||||||
|
installRenderGovernor(viewer, timers);
|
||||||
|
viewer.camera.moveStart.raise();
|
||||||
|
assert.equal(scene.requestRenderMode, false);
|
||||||
|
installRenderGovernor(viewer, timers);
|
||||||
|
assert.equal(scene.requestRenderMode, true);
|
||||||
|
assert.equal(timers.pending, 0);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user