mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
perf: draw at the display's refresh rate while anything moves
Remove the fixed 60 FPS cap. The render governor caps a parked scene at 60 ticks a second, since Cesium still runs the clock, data sources and update listeners on every animation frame when it skips the draw, and holds continuous render while the camera moves (moveStart to moveEnd, with pose sampling for cameras that drift by rounding errors and never raise moveEnd). Waits that counted frames (a tracked contact's first position, a shared follow view, a trail's temporary copy) now count drawn time through src/time/frameWait.js, so they last the same at any refresh rate.
This commit is contained in:
1 parent
8d9c907133
commit
9f4254e962
12 files changed
+380
-16
No files matched your search
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* A wait measured in time spent drawing frames, the same at any display
|
||||
* refresh rate.
|
||||
*
|
||||
* Each call to `tick()` adds the time since the previous call, but at most
|
||||
* MAX_STEP_MS, so a background tab, a parked scene or a hidden owner (which
|
||||
* draw no frames for this wait) does not use the wait up while nothing is on
|
||||
* screen.
|
||||
*/
|
||||
|
||||
/** The most one frame may add to a wait, in milliseconds. */
|
||||
export const MAX_STEP_MS = 100;
|
||||
|
||||
/**
|
||||
* Start a wait of `limitMs` drawn time.
|
||||
* @param {number} limitMs How long to wait, in milliseconds.
|
||||
* @param {() => number} [now] Clock in milliseconds.
|
||||
* @returns {{tick: () => boolean, pause: () => void}} `tick()` counts one
|
||||
* drawn frame and answers whether the wait is over; `pause()` makes the
|
||||
* next tick count nothing for the gap since the last one.
|
||||
*/
|
||||
export function createFrameWait(limitMs, now = () => performance.now()) {
|
||||
let waitedMs = 0;
|
||||
let lastMs = NaN;
|
||||
return {
|
||||
tick() {
|
||||
const at = now();
|
||||
if (Number.isFinite(lastMs))
|
||||
waitedMs += Math.min(Math.max(at - lastMs, 0), MAX_STEP_MS);
|
||||
lastMs = at;
|
||||
return waitedMs >= limitMs;
|
||||
},
|
||||
pause() {
|
||||
lastMs = NaN;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createFrameWait, MAX_STEP_MS } from './frameWait.js';
|
||||
|
||||
function clock() {
|
||||
let at = 0;
|
||||
return { now: () => at, advance: (ms) => (at += ms) };
|
||||
}
|
||||
|
||||
test('the wait lasts the same time at 60 and 240 frames a second', () => {
|
||||
for (const hz of [60, 240]) {
|
||||
const c = clock();
|
||||
const wait = createFrameWait(2_000, c.now);
|
||||
let frames = 0;
|
||||
while (!wait.tick()) {
|
||||
c.advance(1000 / hz);
|
||||
frames += 1;
|
||||
}
|
||||
assert.ok(Math.abs(c.now() - 2_000) <= 1000 / hz + 1e-6, `${hz} Hz ended at ${c.now()}`);
|
||||
assert.ok(frames > 0);
|
||||
}
|
||||
});
|
||||
|
||||
test('a long gap between frames adds at most one step', () => {
|
||||
const c = clock();
|
||||
const wait = createFrameWait(2_000, c.now);
|
||||
wait.tick();
|
||||
c.advance(60_000);
|
||||
assert.equal(wait.tick(), false, 'a background tab does not use the wait up');
|
||||
let drawnMs = MAX_STEP_MS;
|
||||
while (!wait.tick()) {
|
||||
c.advance(16);
|
||||
drawnMs += 16;
|
||||
}
|
||||
assert.ok(drawnMs >= 2_000 && drawnMs < 2_000 + 16 + MAX_STEP_MS);
|
||||
});
|
||||
|
||||
test('after pause the next tick adds nothing', () => {
|
||||
const c = clock();
|
||||
const wait = createFrameWait(150, c.now);
|
||||
wait.tick();
|
||||
c.advance(90);
|
||||
wait.tick();
|
||||
wait.pause();
|
||||
c.advance(90);
|
||||
assert.equal(wait.tick(), false);
|
||||
c.advance(60);
|
||||
assert.equal(wait.tick(), true);
|
||||
});
|
||||
Reference in new issue
Block a user