Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-878]): clamp fly delta so a post-freeze preset change animates

Adam Eivy373d47665b4d
diff --git a/client/src/utils/cityPhotoMode.js b/client/src/utils/cityPhotoMode.js
index f965ee98d2..83a6457db6 100644
--- a/client/src/utils/cityPhotoMode.js
+++ b/client/src/utils/cityPhotoMode.js
@@ -42,8 +42,16 @@ export function cyclePreset(currentId, direction = 1) {
// and `done` (true once settled) so the component can stop invalidating the demand loop.
export const FLY_DURATION = 1.1;
+// Cap the per-step delta to a frame-sized maximum. In demand mode the loop sleeps while the scene
+// is frozen, so the FIRST frame after a freeze (e.g. when the user cycles presets) carries a
+// delta equal to the whole idle gap — often several seconds. Unclamped, that would complete the
+// fly in a single step and the camera would snap instead of animating. Clamping keeps every fly
+// smooth (~at least FLY_DURATION/MAX_FLY_DELTA frames) regardless of how long the scene was idle.
+export const MAX_FLY_DELTA = 1 / 30; // seconds — one 30fps frame
+
export function stepFly(progress, deltaSeconds) {
- const safeDelta = Number.isFinite(deltaSeconds) && deltaSeconds > 0 ? deltaSeconds : 0;
+ const rawDelta = Number.isFinite(deltaSeconds) && deltaSeconds > 0 ? deltaSeconds : 0;
+ const safeDelta = Math.min(rawDelta, MAX_FLY_DELTA);
const next = Math.min(1, (Number.isFinite(progress) ? progress : 1) + safeDelta / FLY_DURATION);
return { progress: next, t: smoothstep(next), done: next >= 1 };
}
diff --git a/client/src/utils/cityPhotoMode.test.js b/client/src/utils/cityPhotoMode.test.js
index 086be272c9..524ea018bc 100644
--- a/client/src/utils/cityPhotoMode.test.js
+++ b/client/src/utils/cityPhotoMode.test.js
@@ -6,9 +6,11 @@ import {
cyclePreset,
stepFly,
FLY_DURATION,
+ MAX_FLY_DELTA,
buildPostcardStats,
screenshotFilename,
} from './cityPhotoMode';
+import { smoothstep } from './easing';
describe('PHOTO_PRESETS', () => {
it('has unique ids and a position + target each', () => {
@@ -52,14 +54,21 @@ describe('cyclePreset', () => {
});
describe('stepFly', () => {
- it('advances progress by delta/duration and eases t', () => {
- const { progress, t, done } = stepFly(0, FLY_DURATION / 2);
- expect(progress).toBeCloseTo(0.5, 5);
- expect(t).toBeCloseTo(0.5, 5); // smoothstep(0.5) === 0.5
+ it('advances progress by delta/duration and eases t for a frame-sized delta', () => {
+ const { progress, t, done } = stepFly(0, MAX_FLY_DELTA);
+ expect(progress).toBeCloseTo(MAX_FLY_DELTA / FLY_DURATION, 5);
+ expect(t).toBeCloseTo(smoothstep(progress), 5);
expect(done).toBe(false);
});
- it('clamps progress to 1 and reports done at/after the duration', () => {
- const { progress, t, done } = stepFly(0.9, FLY_DURATION);
+ it('clamps a huge idle delta to one frame so a fly never snaps in a single step', () => {
+ // In demand mode the first frame after a freeze carries the whole idle gap as delta. The fly
+ // must still advance only one frame's worth, not jump straight to settled.
+ const { progress, done } = stepFly(0, 9999);
+ expect(progress).toBeCloseTo(MAX_FLY_DELTA / FLY_DURATION, 5);
+ expect(done).toBe(false);
+ });
+ it('clamps progress to 1 and reports done once enough frames accumulate', () => {
+ const { progress, t, done } = stepFly(0.999, MAX_FLY_DELTA);
expect(progress).toBe(1);
expect(t).toBe(1);
expect(done).toBe(true);