mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(render): Recent Imagery's swipe slots wait for each other's tiles without redrawing
The two slots share one small request budget through one admit hook. When one slot held it, the other's deferred tiles asked the Cesium globe for a redraw every 250 ms, about four extra frames a second while tiles loaded; before, they waited for the holder's tile, whose settling draws the frame that asks again. Layers given the same admit now share their waits: with one of their tiles in flight, nothing more is asked for. A layer deferring while an unrelated layer loads still retries after 250 ms.
This commit is contained in:
1 parent
ecf8b31756
commit
96ef7f509e
3 files changed
+39
-8
No files matched your search
@@ -334,6 +334,29 @@ test('a layer deferring while another has a request in flight asks for a frame',
|
||||
assert.deepEqual(renders, ['imagery']);
|
||||
});
|
||||
|
||||
test('layers sharing an admit wait for each other’s tiles, asking for no frame', (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
const { scene, port, renders } = setup();
|
||||
// A budget of one shared by two layers, as Recent Imagery's swipe slots.
|
||||
let inFlight = 0;
|
||||
const admit = (_tile, issue) => {
|
||||
if (inFlight >= 1) return undefined;
|
||||
inFlight += 1;
|
||||
return issue();
|
||||
};
|
||||
port.imagery.add({ kind: 'xyz', url: url('a'), admit });
|
||||
port.imagery.add({ kind: 'xyz', url: url('b'), admit });
|
||||
const [holder, waiting] = [0, 1].map(
|
||||
(i) => scene.imageryLayers.get(i).imageryProvider,
|
||||
);
|
||||
Object.getPrototypeOf(holder).requestImage = () => new Promise(() => {});
|
||||
assert.ok(holder.requestImage(0, 0, 1), 'in flight');
|
||||
renders.length = 0;
|
||||
assert.equal(waiting.requestImage(0, 0, 1), undefined);
|
||||
t.mock.timers.tick(TILE_RETRY_DELAY_MS * 4);
|
||||
assert.deepEqual(renders, [], 'the holder’s settling is the later frame');
|
||||
});
|
||||
|
||||
test('fetchTile fetches in place of the provider, with the URL it would fetch', async (t) => {
|
||||
const asked = [];
|
||||
const answers = [{ defer: true }, { missing: true }];
|
||||
|
||||
@@ -250,9 +250,10 @@ function guarded(run) {
|
||||
* `maxConcurrentRequests` are in flight.
|
||||
*
|
||||
* A tile `admit` defers is asked again on a later frame: the one a request
|
||||
* of the same layer in flight asks for as it settles, or, with none in
|
||||
* flight (`busy`), the one `retrySoon` asks for. So a layer whose own
|
||||
* budget is full never keeps the scene drawing while it waits.
|
||||
* of a layer with the same `admit` in flight asks for as it settles, or,
|
||||
* with none in flight (`busy`), the one `retrySoon` asks for. So layers
|
||||
* whose shared budget is full never keep the scene drawing while they
|
||||
* wait.
|
||||
* @param {object} provider
|
||||
* @param {import('../contract/globe').ImagerySpec} spec
|
||||
* @param {{started: () => void, settled: () => void, retrySoon: () => void,
|
||||
@@ -366,6 +367,8 @@ export function createCesiumImagery(
|
||||
/** Port layers, bottom to top. */
|
||||
const layers = [];
|
||||
let pending = 0;
|
||||
/** Tiles in flight by the `admit` their layers share. */
|
||||
const admitPending = new Map();
|
||||
let retryTimer = null;
|
||||
let disposed = false;
|
||||
const waiters = [];
|
||||
@@ -512,17 +515,21 @@ export function createCesiumImagery(
|
||||
};
|
||||
const signals = new Set();
|
||||
const requests = new Set();
|
||||
let layerPending = 0;
|
||||
// Layers given one `admit` share its waits: a tile it defers is asked
|
||||
// again on the frame any of their tiles asks for as it settles.
|
||||
const shared = spec.admit ?? {};
|
||||
const ctx = {
|
||||
busy: () => layerPending > 0,
|
||||
busy: () => (admitPending.get(shared) ?? 0) > 0,
|
||||
requests,
|
||||
started: () => {
|
||||
pending += 1;
|
||||
layerPending += 1;
|
||||
admitPending.set(shared, (admitPending.get(shared) ?? 0) + 1);
|
||||
},
|
||||
settled: () => {
|
||||
pending -= 1;
|
||||
layerPending -= 1;
|
||||
const left = (admitPending.get(shared) ?? 1) - 1;
|
||||
if (left > 0) admitPending.set(shared, left);
|
||||
else admitPending.delete(shared);
|
||||
if (!disposed) requestRender('imagery');
|
||||
},
|
||||
retrySoon,
|
||||
|
||||
Vendored
+2
-1
@@ -111,7 +111,8 @@ export interface ImagerySpec {
|
||||
/**
|
||||
* `imageHooks`: decides each tile request on the main thread: call
|
||||
* `issue()` to fetch it, or return `undefined` to defer it and be asked
|
||||
* again on a later frame. `fetchTile`'s `defer` does the same anywhere.
|
||||
* again on a later frame. Layers given the same function share its waits:
|
||||
* while one of their tiles is in flight, its settling is that frame. `fetchTile`'s `defer` does the same anywhere.
|
||||
* With both, `admit` decides first and an issued request goes through
|
||||
* `fetchTile`; each defers on its own.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user