mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +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
@@ -26,6 +26,7 @@ import {
|
||||
translateKnown,
|
||||
} from '../../i18n/index.js';
|
||||
import { pointerOwnerName } from '../../data/pointerOwnerNames.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
formatQuantity,
|
||||
quantitySeparator,
|
||||
@@ -897,7 +898,7 @@ export function createDirectionsLayer({ services, source }) {
|
||||
let _routeEntity = null;
|
||||
let _stepPoints = null;
|
||||
let _selectedStep = null;
|
||||
let _clickHandler = null;
|
||||
let _clickSubscription = null;
|
||||
let _renderHeld = false;
|
||||
let _rowControlsListener = null;
|
||||
let _dataManager = null;
|
||||
@@ -1212,12 +1213,12 @@ export function createDirectionsLayer({ services, source }) {
|
||||
* Give the pointer back, but only once the click that consumed it has finished
|
||||
* being dispatched.
|
||||
*
|
||||
* Every layer binds its own handler to the same canvas, and they all run
|
||||
* inside ONE browser event. Releasing the claim the instant this layer places
|
||||
* an endpoint hands the rest of that same click to every ambient handler
|
||||
* registered after this one — placing A on top of a bikeshare station also
|
||||
* deselected the station. A timer, not a microtask: a microtask checkpoint
|
||||
* runs between two DOM listeners, which is exactly the gap this closes.
|
||||
* The input dispatcher decides who hears a click before any subscriber runs,
|
||||
* but DOM listeners on the canvas (evidence cards) still run later inside
|
||||
* the SAME browser event. Releasing the claim the instant this layer places
|
||||
* an endpoint would hand that same click to them. A timer, not a microtask:
|
||||
* a microtask checkpoint runs between two DOM listeners, which is exactly the
|
||||
* gap this closes.
|
||||
*/
|
||||
function releaseClaimAfterDispatch() {
|
||||
if (_pointerClaim === null || _releaseTimer) return;
|
||||
@@ -1243,8 +1244,8 @@ export function createDirectionsLayer({ services, source }) {
|
||||
* Place one endpoint at a picked ground point and reroute when both are set.
|
||||
*
|
||||
* The globe click handler is the only caller in the running app; it is
|
||||
* exported because a ScreenSpaceEventHandler needs a real canvas, and the
|
||||
* ownership timing this function decides is exactly what has to be tested.
|
||||
* exported so the ownership timing this function decides can be tested on
|
||||
* its own.
|
||||
* @param {'a'|'b'} which Which endpoint to place.
|
||||
* @param {{lat: number, lon: number}} point Ground point in degrees.
|
||||
* @returns {boolean} Whether the endpoint was placed.
|
||||
@@ -1521,25 +1522,28 @@ export function createDirectionsLayer({ services, source }) {
|
||||
}
|
||||
|
||||
function _installClickHandler(viewer) {
|
||||
if (_clickHandler) return;
|
||||
_clickHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
_clickHandler.setInputAction((click) => {
|
||||
if (!_enabled) return;
|
||||
// Placement acts only while this layer actually HOLDS the pointer, and the
|
||||
// maneuver-dot selection below is an ambient handler like any other: it
|
||||
// yields the moment a tool (this one included) owns the click.
|
||||
// The lease, not the owner name: a superseded instance of this layer must
|
||||
// not act on a click its replacement owns.
|
||||
if (_armed && services.input.isLeaseCurrent(_pointerClaim)) {
|
||||
const point = pickGround(click.position);
|
||||
if (_clickSubscription) return;
|
||||
const input = inputFor(viewer);
|
||||
// Placement acts only while this layer actually HOLDS the pointer. The
|
||||
// lease, not the owner name: a superseded instance of this layer must not
|
||||
// act on a click its replacement owns.
|
||||
const offPlace = input.onPointer(
|
||||
'click',
|
||||
(event) => {
|
||||
if (!_enabled || !_armed) return;
|
||||
const point = pickGround(event.position);
|
||||
if (!point) return;
|
||||
placeDirectionsEndpoint(_armed, point);
|
||||
return;
|
||||
}
|
||||
if (!services.input.isPointerFree()) return;
|
||||
},
|
||||
{ lease: () => _pointerClaim },
|
||||
);
|
||||
// The maneuver-dot selection is an ambient handler like any other: it
|
||||
// yields the moment a tool (this one included) owns the click.
|
||||
const offSelect = input.onClick((event) => {
|
||||
if (!_enabled) return;
|
||||
let picked = null;
|
||||
try {
|
||||
picked = viewer.scene.pick(click.position);
|
||||
picked = event.pick;
|
||||
} catch {
|
||||
picked = null;
|
||||
}
|
||||
@@ -1549,16 +1553,18 @@ export function createDirectionsLayer({ services, source }) {
|
||||
return;
|
||||
}
|
||||
if (_selectedStep !== null) _clearStepSelection();
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
_clickSubscription = () => {
|
||||
offPlace();
|
||||
offSelect();
|
||||
};
|
||||
if (typeof document !== 'undefined')
|
||||
document.addEventListener('keydown', _onKeyDown);
|
||||
}
|
||||
|
||||
function _removeClickHandler() {
|
||||
if (_clickHandler) {
|
||||
_clickHandler.destroy();
|
||||
_clickHandler = null;
|
||||
}
|
||||
_clickSubscription?.();
|
||||
_clickSubscription = null;
|
||||
// Teardown can outlive the document (page unload, and every headless test).
|
||||
if (typeof document !== 'undefined')
|
||||
document.removeEventListener('keydown', _onKeyDown);
|
||||
@@ -1739,9 +1745,8 @@ export function createDirectionsLayer({ services, source }) {
|
||||
|
||||
/**
|
||||
* Place one endpoint at a picked ground point. The globe click handler is
|
||||
* the only caller in the running app; it is on the instance because a
|
||||
* ScreenSpaceEventHandler needs a real canvas, and the ownership timing
|
||||
* this decides is exactly what has to be tested.
|
||||
* the only caller in the running app; it is on the instance so the
|
||||
* ownership timing this decides can be tested on its own.
|
||||
*/
|
||||
placeEndpoint: placeDirectionsEndpoint,
|
||||
|
||||
|
||||
Reference in new issue
Block a user