mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Give a viewer of its own a frame port, and use it for the active fires layer
findFrame and frameOf find the bound renderer's frame port or, for a caller's viewer with no renderer bound, one the Cesium adapter's factory builds over it, as findQuery and findDraw do. Unlike the renderer's own, it leaves the viewer's loop as its owner set it up: it listens to the scene's phases, asks for frames, holds by asking again after each one drawn, and maps suspend, the target rate and scene time onto the viewer. Its preUpdate says whether the tick draws by the same test the renderer's frame port makes, now shared by both. The active fires layer's cards and LOD watcher take their query and frame ports from findQuery and findFrame, in place of the layer's own copy of projection, occlusion and preRender over the viewer's scene.
This commit is contained in:
1 parent
784561a6ae
commit
4ed51930c2
12 files changed
+604
-132
No files matched your search
@@ -66,6 +66,7 @@ const unboundCredits = unboundPorts('credits');
|
||||
/** Draw ports are `{port, dispose, release}`, as credits ports are. */
|
||||
const unboundDraws = unboundPorts('draw');
|
||||
const unboundQueries = unboundPorts('query');
|
||||
const unboundFrames = unboundPorts('frame');
|
||||
|
||||
/**
|
||||
* Provide the factory `cameraOf` builds a camera port with for a scene
|
||||
@@ -110,6 +111,15 @@ export function provideUnboundQuery(build) {
|
||||
unboundQueries.provide(build);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the factory `findFrame` builds a frame port with for a scene
|
||||
* object no renderer is bound to, as `provideUnboundCamera` does.
|
||||
* @param {(host: object) => ({port: object, dispose: () => void} | null)} build
|
||||
*/
|
||||
export function provideUnboundFrame(build) {
|
||||
unboundFrames.provide(build);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the factory `findEffects` builds an effects port with for a
|
||||
* scene object no renderer is bound to, as `provideUnboundCamera` does.
|
||||
@@ -163,6 +173,7 @@ export function bindRenderer(host, renderer) {
|
||||
unboundCredits.supersede(host);
|
||||
unboundDraws.supersede(host);
|
||||
unboundQueries.drop(host);
|
||||
unboundFrames.drop(host);
|
||||
renderers.set(host, renderer);
|
||||
return () => {
|
||||
if (renderers.get(host) === renderer) renderers.delete(host);
|
||||
@@ -295,6 +306,31 @@ export function queryOf(host) {
|
||||
throw noPort(host, 'query');
|
||||
}
|
||||
|
||||
/**
|
||||
* The frame port of the renderer bound to `host`; with no renderer bound,
|
||||
* one built over `host` by the provided factory and kept with it while
|
||||
* `host` lives, as `findCamera` does. A built one listens to the loop
|
||||
* `host`'s owner runs, as they set it up. Bound later, a renderer's own
|
||||
* replaces it: its listeners hear nothing more and its holds end.
|
||||
* @param {object|null|undefined} host
|
||||
* @returns {import('./contract/frame').FramePort | null}
|
||||
*/
|
||||
export function findFrame(host) {
|
||||
return unboundFrames.find(host);
|
||||
}
|
||||
|
||||
/**
|
||||
* `findFrame`, for code that cannot start without one.
|
||||
* @param {object} host
|
||||
* @returns {import('./contract/frame').FramePort}
|
||||
* @throws When there is no frame port for `host`.
|
||||
*/
|
||||
export function frameOf(host) {
|
||||
const frame = findFrame(host);
|
||||
if (frame) return frame;
|
||||
throw noPort(host, 'run frames with');
|
||||
}
|
||||
|
||||
/**
|
||||
* `findCamera`, for code that needs the camera.
|
||||
* @param {object} host
|
||||
|
||||
Reference in new issue
Block a user