mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
The renderer seam: clicks go to the newest tool, recession and display groups through the contract, drawing at parity with Cesium
- Clicks: when two tools want the globe's clicks, the newest takes them and the older is told and turns itself off; a click is decided when it arrives, and ambient selection fires only when no tool holds the pointer. The "map is busy" paths and their strings are removed. - Recession: the limb fade is shared (src/render/recession.js) and reaches icon and model sets through SetSpec.recede; tuning applies on the next frame. - Display panel groups are published through src/ui/displayGroups.js; the Weather group and src/viewWeather.js are removed. - Draw port: a set whose icons only move is moved in place, and models that did not change are not restyled each frame, so moving fleets cost what they did when drawn directly; an untinted, fully opaque model is drawn without a colour. - Conformance: input.lease.lost checks the new lease inside onLost and reports a throwing onLost; draw.sets.recede covers model sets. - QA scripts read the renderer host instead of internals the seam replaced.
This commit is contained in:
1 parent
a0d299523d
commit
0ab31d4fb8
130 files changed
+5438
-1674
No files matched your search
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Who hears each pointer event: the contract's input rules
|
||||
* (`router.js`).
|
||||
*/
|
||||
import type { InputPort, Lease, PointerEv } from '../contract/index';
|
||||
|
||||
/** Who an event went to: one lease's listeners, everyone else, or both. */
|
||||
export interface Recipients {
|
||||
lease: Lease | null;
|
||||
ambient: boolean;
|
||||
}
|
||||
|
||||
export interface InputRouter {
|
||||
/** The input port the router keeps. */
|
||||
port: InputPort;
|
||||
/**
|
||||
* Delivers one event to the listeners it belongs to. `before` runs first
|
||||
* with who it goes to (a renderer's stock behaviours); its error is
|
||||
* reported. A `move` or `up` always reads as going to both.
|
||||
*/
|
||||
dispatch(ev: PointerEv, before?: (to: Recipients) => void): Recipients;
|
||||
/** Live listeners, for leak checks. */
|
||||
listenerCount(): number;
|
||||
/** Ends delivery: no listener runs again, even for the event under way. */
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export function createInputRouter(options: {
|
||||
/** Where a listener's or a `grab`'s error goes. */
|
||||
report: (error: unknown) => void;
|
||||
/** The renderer's counted camera-input hold. */
|
||||
suspendCamera: (reason: string) => () => void;
|
||||
/** Stock behaviours beyond `select` and `dblclickFollow`. */
|
||||
behaviours?: string[];
|
||||
/** Told when a behaviour turns off (first hold) or on (last release). */
|
||||
onBehaviour?: (name: string, enabled: boolean) => void;
|
||||
/** Behaviours the renderer cannot do, as `false`: listed, reported disabled. */
|
||||
supported?: Record<string, boolean>;
|
||||
}): InputRouter;
|
||||
@@ -74,6 +74,8 @@ export function createInputRouter({
|
||||
|
||||
/** Each lease's `grab`, or null when it takes every press. */
|
||||
const leaseGrab = new WeakMap();
|
||||
/** Each lease's ending by a newer claim, which hands back its `onLost`. */
|
||||
const endLease = new WeakMap();
|
||||
/**
|
||||
* The presses under way, by button, from their `down`: `owner` is the
|
||||
* lease each went to, or null when it went to everyone else. A press's
|
||||
@@ -96,9 +98,12 @@ export function createInputRouter({
|
||||
};
|
||||
},
|
||||
claimPointer(owner, opts = {}) {
|
||||
if (currentLease) currentLease.release();
|
||||
// The newest claim takes over. The lease it ends is told once, after
|
||||
// this one holds the pointer, so its holder turns itself off.
|
||||
const ended = currentLease ? endLease.get(currentLease)() : null;
|
||||
let released = false;
|
||||
const grab = typeof opts.grab === 'function' ? opts.grab : null;
|
||||
const onLost = typeof opts.onLost === 'function' ? opts.onLost : null;
|
||||
const lease = {
|
||||
owner: String(owner),
|
||||
get current() {
|
||||
@@ -110,8 +115,19 @@ export function createInputRouter({
|
||||
if (currentLease === lease) currentLease = null;
|
||||
},
|
||||
};
|
||||
// Ends it for a newer claim; returns who to tell.
|
||||
endLease.set(lease, () => {
|
||||
lease.release();
|
||||
return onLost;
|
||||
});
|
||||
currentLease = lease;
|
||||
leaseGrab.set(lease, grab);
|
||||
if (ended)
|
||||
try {
|
||||
ended();
|
||||
} catch (error) {
|
||||
report(error);
|
||||
}
|
||||
return lease;
|
||||
},
|
||||
isPointerFree: () => currentLease === null,
|
||||
|
||||
@@ -122,3 +122,43 @@ test('dispose ends delivery, even of the event under way', () => {
|
||||
assert.equal(lease.current, false, 'the lease ended');
|
||||
assert.equal(port.isPointerFree(), true);
|
||||
});
|
||||
|
||||
test('a newer claim takes over and tells the lease it ended, once', () => {
|
||||
const { port, dispatch } = router();
|
||||
const lost = [];
|
||||
const a = port.claimPointer('a', { onLost: () => lost.push('a') });
|
||||
const heard = [];
|
||||
port.on('down', () => heard.push('a'), { lease: a });
|
||||
const b = port.claimPointer('b', {
|
||||
onLost: () => lost.push('b'),
|
||||
});
|
||||
port.on('down', () => heard.push('b'), { lease: b });
|
||||
assert.deepEqual(lost, ['a'], 'the old holder is told');
|
||||
assert.equal(a.current, false);
|
||||
assert.equal(b.current, true);
|
||||
dispatch(ev('down'));
|
||||
assert.deepEqual(heard, ['b'], 'the newest holder gets the press');
|
||||
a.release();
|
||||
assert.equal(b.current, true, "the old holder's late release frees nothing");
|
||||
assert.equal(port.isPointerFree(), false);
|
||||
assert.deepEqual(lost, ['a'], 'told once');
|
||||
b.release();
|
||||
assert.deepEqual(lost, ['a'], 'a holder that lets go is not told');
|
||||
assert.equal(port.isPointerFree(), true);
|
||||
});
|
||||
|
||||
test('the ended lease is told after the new one holds; its error is reported', () => {
|
||||
const errors = [];
|
||||
const { port } = router({ report: (error) => errors.push(error) });
|
||||
let seen = null;
|
||||
const a = port.claimPointer('a', {
|
||||
onLost: () => {
|
||||
seen = { free: port.isPointerFree(), current: a.current };
|
||||
throw new Error('onLost');
|
||||
},
|
||||
});
|
||||
const b = port.claimPointer('b');
|
||||
assert.deepEqual(seen, { free: false, current: false });
|
||||
assert.equal(b.current, true);
|
||||
assert.equal(errors.length, 1);
|
||||
});
|
||||
Reference in new issue
Block a user