Files
gods-eye-view/src/sceneCommandRelease.js
T
Sameh Khamis b9248bfce5 Keep the scene command trim in the Cesium adapter and take its installer off the Cesium list
The private-field trim of Cesium's reused per-pass command arrays moves to
src/render/cesium/sceneCommandRelease.js. The installer waits for the
renderer frame port's postRender after each layer disable and calls a trim
the application scene hands over, so it no longer touches the Cesium scene.
2026-11-07 05:29:57 -08:00

42 lines
1.3 KiB
JavaScript

/**
* Let a turned-off layer's memory go.
*
* A renderer may keep a turned-off layer's draw commands, and through them
* its whole data source, reachable after the layer stops drawing: the
* default renderer does (see `src/render/cesium/sceneCommandRelease.js`).
* After a layer finishes turning off, this asks for one frame and, once it
* is drawn, has the renderer trim what that frame no longer drew.
*/
/**
* After every layer disable, render one frame and trim once it is drawn.
* @param {{frame: import('./render/contract/frame').FramePort,
* dataManager: object, requestRender: (reason: string) => void,
* trim: () => void}} deps `trim` drops what the last drawn frame did not
* draw.
* @returns {() => void} uninstall
*/
export function installLayerReleaseTrim({
frame,
dataManager,
requestRender,
trim,
}) {
let removeOneShot = null;
const unsubscribe = dataManager.subscribe((change) => {
if (change?.type !== 'visibility' || change.enabled !== false) return;
if (removeOneShot) return; // a trim is already waiting for its frame
removeOneShot = frame.on('postRender', () => {
removeOneShot();
removeOneShot = null;
trim();
});
requestRender('layer-release-trim');
});
return () => {
unsubscribe();
removeOneShot?.();
removeOneShot = null;
};
}