mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Take pointer input through one dispatcher per scene
Every layer and tool bound its own ScreenSpaceEventHandler and picked the same click again: with the usual layers on, one click ran about 26 scene.pick and 2 drillPick passes (120-215 ms in NYC with 18 layers). Pointer input now comes in through src/input/dispatcher.js, one handler per scene. A click is picked lazily and at most once per kind of query, and every subscriber reads the same ClickEvent (pick, hit, id, ownerId, gesture, drill, ground). The same click now costs 3 picks and 2 drills, 17-70 ms. - Ambient onClick subscribers run only while no tool holds the pointer, checked once per event; tools subscribe with their lease. Moves and releases always reach ambient subscribers, so hover and drags end cleanly. - Camera input and the viewer's stock select/track clicks are ref-counted holds (suspendCamera, suppressStockClicks). The dispatcher owns the controller's enableInputs, so a Cesium flight that ends no longer turns input back on under a drag or the cockpit. - The draw tool, imagery box, CCTV gizmo, cockpit, directions and every selecting layer use it; bindTrackingClickGesture is gone (the gesture is on the event). A source scan forbids new handlers, enableInputs writes and stock-click removal outside the dispatcher. - The sensor-style pick correction transit had now applies to every layer. - Radio's 8-pick near-miss ring is one 17x17 windowed drill. - A missed pick passed to pickContact is no longer picked again, and a touch tap's contact search shares the click's drill. - A gizmo drag whose release Cesium never reported ends on the next press instead of leaving the camera held. The dispatcher is exported as ./input with the pointer-lease functions, and documented in docs/APPLICATION.md.
This commit is contained in:
1 parent
83ec9473b6
commit
02d492a079
97 files changed
+2506
-1307
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { hitTestWorldOverlay } from '../../overlays/worldOverlay.js';
|
||||
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
@@ -82,7 +82,7 @@ export function createCyclonesLayer({
|
||||
selectedId = null,
|
||||
selectionIntent = 'auto',
|
||||
navigationGeneration = 0,
|
||||
clickHandler = null,
|
||||
selectionOwner = null,
|
||||
removeClickCapture = null;
|
||||
let enabled = false,
|
||||
loading = false,
|
||||
@@ -106,14 +106,9 @@ export function createCyclonesLayer({
|
||||
(typeof cesium.Cesium3DTileset === 'function' &&
|
||||
picked.primitive instanceof cesium.Cesium3DTileset)));
|
||||
function installSelection() {
|
||||
if (
|
||||
clickHandler ||
|
||||
!viewer?.scene?.canvas ||
|
||||
typeof cesium.ScreenSpaceEventHandler !== 'function'
|
||||
)
|
||||
return;
|
||||
const owner = new cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
clickHandler = owner;
|
||||
if (selectionOwner || !viewer?.scene?.canvas) return;
|
||||
const owner = {};
|
||||
selectionOwner = owner;
|
||||
// Snapshot before sibling bubble listeners can rebuild the overlay hit
|
||||
// rectangles. A vessel selection does that synchronously in the same click.
|
||||
const canvas = viewer.scene.canvas;
|
||||
@@ -154,28 +149,24 @@ export function createCyclonesLayer({
|
||||
canvas.removeEventListener?.(type, resetCapture, { capture: true });
|
||||
capturedHit = null;
|
||||
};
|
||||
owner.setInputAction((click) => {
|
||||
const unsubscribe = inputFor(viewer).onClick((event) => {
|
||||
const nativeHit = capturedHit;
|
||||
capturedHit = null;
|
||||
// Ambient selection yields to draw tools and Director; it never claims
|
||||
// the pointer, camera, or tracking state.
|
||||
if (
|
||||
!enabled ||
|
||||
destroyed ||
|
||||
clickHandler !== owner ||
|
||||
!isPointerFree() ||
|
||||
!click?.position
|
||||
)
|
||||
// Ambient selection yields to draw tools and Director (the dispatcher
|
||||
// skips a held pointer); it never claims the pointer, camera, or
|
||||
// tracking state.
|
||||
const position = event.screenPosition;
|
||||
if (!enabled || destroyed || selectionOwner !== owner || !position)
|
||||
return;
|
||||
// AIS cards paint above the globe on a pointer-events:none canvas. The
|
||||
// vessel handler resolves this same topmost hit before cyclone geometry.
|
||||
const captureMatches =
|
||||
nativeHit &&
|
||||
Math.abs(nativeHit.x - click.position.x) < 1 &&
|
||||
Math.abs(nativeHit.y - click.position.y) < 1;
|
||||
Math.abs(nativeHit.x - position.x) < 1 &&
|
||||
Math.abs(nativeHit.y - position.y) < 1;
|
||||
const hit = captureMatches
|
||||
? nativeHit
|
||||
: overlayHit(click.position.x, click.position.y);
|
||||
: overlayHit(position.x, position.y);
|
||||
if (hit.sourceId === VESSEL_OVERLAY_SOURCE_ID) return;
|
||||
// Storm cards and lead-hour labels paint on the same canvas; a click on
|
||||
// one selects its storm. An id from a superseded advisory changes nothing.
|
||||
@@ -184,18 +175,19 @@ export function createCyclonesLayer({
|
||||
if (id) layer.setParams({ stormId: id });
|
||||
return;
|
||||
}
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
const picked = event.pick;
|
||||
const id = rendering?.pickStorm(picked);
|
||||
if (id) layer.setParams({ stormId: id });
|
||||
else if (isSurfacePick(picked)) layer.setParams({ clear: true });
|
||||
}, cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
owner.unsubscribe = unsubscribe;
|
||||
}
|
||||
function removeSelection() {
|
||||
const owner = clickHandler;
|
||||
clickHandler = null;
|
||||
const owner = selectionOwner;
|
||||
selectionOwner = null;
|
||||
removeClickCapture?.();
|
||||
removeClickCapture = null;
|
||||
if (owner && !owner.isDestroyed?.()) owner.destroy();
|
||||
owner?.unsubscribe?.();
|
||||
}
|
||||
const layer = {
|
||||
id: 'weather-cyclones',
|
||||
@@ -520,7 +512,7 @@ export function createCyclonesLayer({
|
||||
enabled,
|
||||
loading,
|
||||
requestPending: !!request,
|
||||
selectionActive: clickHandler !== null,
|
||||
selectionActive: selectionOwner !== null,
|
||||
selectedId,
|
||||
selectionIntent,
|
||||
timerActive: false,
|
||||
|
||||
Reference in new issue
Block a user