mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Take the launches lifecycle off Cesium
The layer's entity data source is now created and removed by the rendering part, which owns the entities and stays on Cesium: the replay vehicle and the live payload move every frame, the selected site is the viewer's selected entity, and the orbits draw with their own materials. The hover keeps its pending pointer position as a plain point. Lifecycle leaves the allow-list.
This commit is contained in:
1 parent
e2dea507b9
commit
db2c579265
4 files changed
+42
-13
No files matched your search
@@ -112,6 +112,17 @@ async function fixture({ legacySource = false } = {}) {
|
||||
destroyLaunchPadZonePrimitive: noop,
|
||||
},
|
||||
rendering: {
|
||||
// As the rendering part owns the entities' data source.
|
||||
attach(target) {
|
||||
state._dataSource = new Cesium.CustomDataSource('rocket-launches');
|
||||
state._dataSource.show = false;
|
||||
target.dataSources.add(state._dataSource);
|
||||
},
|
||||
detach(target) {
|
||||
if (state._dataSource)
|
||||
target.dataSources.remove(state._dataSource, true);
|
||||
state._dataSource = null;
|
||||
},
|
||||
updateMissionFrame: noop,
|
||||
addLaunchEntity(record) {
|
||||
state._dataSource.entities.add({
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
|
||||
@@ -91,11 +90,15 @@ export function createLaunchHover({
|
||||
const at = now();
|
||||
const wait = HOVER_PICK_INTERVAL_MS - (at - lastPick);
|
||||
if (wait > 0) {
|
||||
// Cesium reuses the movement object, so keep a copy of the position.
|
||||
pendingPosition = Cesium.Cartesian2.clone(
|
||||
movement.endPosition,
|
||||
pendingPosition ?? undefined,
|
||||
);
|
||||
// The input source may reuse the movement object, so keep a copy of
|
||||
// the position.
|
||||
const end = movement.endPosition;
|
||||
if (end == null) pendingPosition = undefined;
|
||||
else {
|
||||
pendingPosition ??= { x: 0, y: 0 };
|
||||
pendingPosition.x = end.x;
|
||||
pendingPosition.y = end.y;
|
||||
}
|
||||
if (trailingTimer === null) trailingTimer = setTimer(trailing, wait);
|
||||
return;
|
||||
}
|
||||
@@ -127,9 +130,7 @@ export function createLifecycle({
|
||||
layerState._enabled = false;
|
||||
parts.panel.createMissionPanel();
|
||||
parts.overlays.createReplayVehicleOverlay();
|
||||
layerState._dataSource = new Cesium.CustomDataSource('rocket-launches');
|
||||
layerState._dataSource.show = false;
|
||||
viewer.dataSources.add(layerState._dataSource);
|
||||
parts.rendering.attach(viewer);
|
||||
layerState._count = 0;
|
||||
layerState._lastUpdate = null;
|
||||
layerState._stale = false;
|
||||
@@ -256,9 +257,7 @@ export function createLifecycle({
|
||||
layerState._replayTracks.clear();
|
||||
parts.panel.clearMissionPanel();
|
||||
layerState._viewer = null;
|
||||
if (layerState._dataSource)
|
||||
viewer.dataSources.remove(layerState._dataSource, true);
|
||||
layerState._dataSource = null;
|
||||
parts.rendering.detach(viewer);
|
||||
layerState._count = 0;
|
||||
layerState._orbitMatches = 0;
|
||||
layerState._lastUpdate = null;
|
||||
|
||||
@@ -37,6 +37,24 @@ export function createRendering({
|
||||
if (current !== next) graphic.show = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* The layer's entities, hidden until enabled. They stay entities: the
|
||||
* replay vehicle and the live payload move every frame, the selected site
|
||||
* is the viewer's selected entity, and the orbits draw with their own
|
||||
* materials.
|
||||
*/
|
||||
function attach(viewer) {
|
||||
layerState._dataSource = new Cesium.CustomDataSource('rocket-launches');
|
||||
layerState._dataSource.show = false;
|
||||
viewer.dataSources.add(layerState._dataSource);
|
||||
}
|
||||
|
||||
function detach(viewer) {
|
||||
if (layerState._dataSource)
|
||||
viewer.dataSources.remove(layerState._dataSource, true);
|
||||
layerState._dataSource = null;
|
||||
}
|
||||
|
||||
/** Make a launch's site marker the viewer's selected entity, or none. */
|
||||
function selectLaunchEntity(launchId) {
|
||||
const viewer = layerState._viewer;
|
||||
@@ -626,6 +644,8 @@ export function createRendering({
|
||||
}
|
||||
}
|
||||
return {
|
||||
attach,
|
||||
detach,
|
||||
setGraphicVisibility,
|
||||
selectLaunchEntity,
|
||||
isolateMission,
|
||||
|
||||
Reference in new issue
Block a user