Drive the camera orbit and the FPS readout through the frame port

The orbit controller and the frame-rate monitor had left the Cesium
allow-list but still hooked the scene's preRender and postRender events.
They now listen through the frame port; the monitor looks the port up
each time it is shown, so a renderer bound after it was created is the
one it counts.
This commit is contained in:
Sameh Khamis committed 2026-11-07 01:04:47 -08:00
1 parent d0aa8d8f7d
commit 30b6be1da0
4 files changed
+20 -7

No files matched your search

+6 -3
View File
@@ -1,5 +1,6 @@
import { useStatusStore } from './stores/status.js';
import { applicationPinia } from './vueRuntime.js';
import { findFrame } from '../render/rendererOf.js';
/**
* Count rendered globe frames while the optional readout is visible. The
@@ -10,9 +11,9 @@ export function createFrameRateMonitor({
documentRef = document,
store = useStatusStore(applicationPinia()),
}) {
const frameEvent = viewer?.scene?.postRender;
const frameOfViewer = () => findFrame(viewer);
// A page without the scene chrome has no title bar to show it in.
if (!documentRef.getElementById('title-bar') || !frameEvent)
if (!documentRef.getElementById('title-bar') || !frameOfViewer())
return { destroy() {} };
// i18n-ignore: FPS is a unit code, the same in every language
@@ -43,7 +44,9 @@ export function createFrameRateMonitor({
startedAt = performance.now();
// i18n-ignore: FPS is a unit code, the same in every language
present({ visible: true, text: 'FPS —' });
removeFrameListener = frameEvent.addEventListener(() => {
// Looked up when shown, so a renderer bound since creation is the one
// counted.
removeFrameListener = frameOfViewer()?.on('postRender', () => {
frames++;
});
timer = setInterval(() => {
+4
View File
@@ -1,6 +1,8 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { createFrameRateMonitor } from './frameRateMonitor.js';
import { bindRenderer } from '../render/rendererOf.js';
import { fakeSceneFrame } from '../testSupport/fakeCesiumScene.mjs';
function fixture(t) {
const keys = new Set();
@@ -27,6 +29,7 @@ function fixture(t) {
},
},
};
bindRenderer(viewer, { frame: fakeSceneFrame(viewer) });
const monitor = createFrameRateMonitor({ viewer, documentRef, store });
t.after(() => monitor.destroy());
return {
@@ -133,6 +136,7 @@ test("destroying an earlier monitor leaves a newer one's readout", () => {
const viewer = {
scene: { postRender: { addEventListener: () => () => {} } },
};
bindRenderer(viewer, { frame: fakeSceneFrame(viewer) });
const first = createFrameRateMonitor({ viewer, documentRef, store });
const second = createFrameRateMonitor({ viewer, documentRef, store });
const shown = store.fps;
+7 -1
View File
@@ -8,6 +8,8 @@ import { createPinia } from 'pinia';
import { useStatusStore } from './stores/status.js';
import { createFrameRateMonitor } from './frameRateMonitor.js';
import SceneChromeView from './views/SceneChromeView.vue';
import { bindRenderer } from '../render/rendererOf.js';
import { fakeSceneFrame } from '../testSupport/fakeCesiumScene.mjs';
test('the FPS readout sits in the title bar, hidden until the backquote key', async (t) => {
document.body.replaceChildren();
@@ -18,8 +20,12 @@ test('the FPS readout sits in the title bar, hidden until the backquote key', as
const readout = () =>
document.querySelector('#title-bar .frame-rate-readout');
assert.equal(readout(), null, 'no readout without a monitor');
const viewer = {
scene: { postRender: { addEventListener: () => () => {} } },
};
bindRenderer(viewer, { frame: fakeSceneFrame(viewer) });
const monitor = createFrameRateMonitor({
viewer: { scene: { postRender: { addEventListener: () => () => {} } } },
viewer,
store: useStatusStore(pinia),
});
t.after(() => monitor.destroy());