mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Merge main through #1637 into the renderer seam
Ports the cockpit bridge view, the orbital view riding a satellite with ground-site focus, satellite classes and draw-mark row actions onto the renderer contract. The orbital view's imagery look-ahead pre-load is dropped (no contract member); tiles load as they come on screen.
This commit is contained in:
commit
e48ed3eb9e
169 files changed
+22415
-681
No files matched your search
@@ -22,6 +22,12 @@ export function trackedEntityDrawn(entity) {
|
||||
return typeof drawn === 'function' ? drawn(entity) !== false : true;
|
||||
}
|
||||
|
||||
/** A camera pose's heading in degrees, or 0 when it has none. */
|
||||
function cameraHeadingDeg(pose) {
|
||||
const heading = pose?.heading;
|
||||
return Number.isFinite(heading) ? (heading * 180) / Math.PI : 0;
|
||||
}
|
||||
|
||||
export function readAircraftInfo() {
|
||||
// In cockpit mode the controller stops the camera following (see enter()),
|
||||
// so the cockpit's own handle is the tracked identity there.
|
||||
@@ -33,14 +39,27 @@ export function readAircraftInfo() {
|
||||
});
|
||||
}
|
||||
|
||||
/** The selected vessel the bridge view would ride, or rides; null without one. */
|
||||
export function readVesselInfo() {
|
||||
return this.services.aisLiveVesselsLayer?.getCockpitSubject?.() || null;
|
||||
}
|
||||
|
||||
/** The tracked satellite the orbital view would ride, or rides; null without one. */
|
||||
export function readSatelliteInfo() {
|
||||
return this.services.satellitesLayer?.getCockpitSubject?.() || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The layer the active view rides: the aircraft's own layer. It is read from
|
||||
* the followed aircraft's key once the layer has dropped its tracking, so a layer
|
||||
* turned off still names itself.
|
||||
* @returns {'flights'|'military'|null}
|
||||
* The layer the active view rides: Live AIS Vessels on a bridge, Satellites
|
||||
* in orbit, else the aircraft's own layer. It is read from the followed
|
||||
* aircraft's key once the layer has dropped its tracking, so a layer turned
|
||||
* off still names itself.
|
||||
* @returns {'flights'|'military'|'ais-live-vessels'|'satellites'|null}
|
||||
*/
|
||||
export function readSubjectLayerId() {
|
||||
if (!this.active) return null;
|
||||
if (this.subjectKind === 'vessel') return 'ais-live-vessels';
|
||||
if (this.subjectKind === 'satellite') return 'satellites';
|
||||
const layerId = this.readAircraftInfo()?.layerId;
|
||||
if (layerId) return layerId;
|
||||
const [prefix] = String(this.trackedFollow?.key || '').split(':');
|
||||
@@ -48,23 +67,30 @@ export function readSubjectLayerId() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The subject entry would take: a followed aircraft.
|
||||
* @returns {'aircraft'|null}
|
||||
* The subject entry would take: a followed aircraft first, then the
|
||||
* tracked satellite, else the selected vessel. Vessels are never followed
|
||||
* through the camera's follow, so an aircraft and a vessel cannot be live
|
||||
* through the same owner.
|
||||
* @returns {'aircraft'|'satellite'|'vessel'|null}
|
||||
*/
|
||||
export function resolveEntryKind() {
|
||||
return this.readAircraftInfo() && followedOf(this.viewer)?.entity?.position
|
||||
? 'aircraft'
|
||||
: null;
|
||||
if (this.readAircraftInfo() && followedOf(this.viewer)?.entity?.position)
|
||||
return 'aircraft';
|
||||
if (this.readSatelliteInfo()) return 'satellite';
|
||||
return this.readVesselInfo() ? 'vessel' : null;
|
||||
}
|
||||
|
||||
export function dispatchCockpitModeChanged(active, info = null) {
|
||||
const subjectId = active
|
||||
? String(info?.icao24 || '')
|
||||
? String(info?.icao24 || info?.mmsi || info?.noradId || '')
|
||||
.trim()
|
||||
.toLowerCase() || null
|
||||
: null;
|
||||
const layerId =
|
||||
active && ['flights', 'military'].includes(info?.layerId)
|
||||
active &&
|
||||
['flights', 'military', 'ais-live-vessels', 'satellites'].includes(
|
||||
info?.layerId,
|
||||
)
|
||||
? info.layerId
|
||||
: null;
|
||||
window.dispatchEvent(
|
||||
@@ -119,17 +145,35 @@ export function syncEntry() {
|
||||
const info = this.readAircraftInfo();
|
||||
const trackedContact = !!(info && followedOf(this.viewer)?.entity?.position);
|
||||
this.syncTr3bToggle(trackedContact ? info : null);
|
||||
const available = !!(this.isEntryAllowed() && trackedContact);
|
||||
const orbitContact = !trackedContact && !!this.readSatelliteInfo();
|
||||
const bridgeContact =
|
||||
!trackedContact && !orbitContact && !!this.readVesselInfo();
|
||||
let entryKind = null;
|
||||
if (trackedContact) entryKind = this.isEntryAllowed() ? 'aircraft' : null;
|
||||
else if (orbitContact)
|
||||
entryKind = this.isOrbitEntryAllowed() ? 'satellite' : null;
|
||||
else if (bridgeContact)
|
||||
entryKind = this.isBridgeEntryAllowed() ? 'vessel' : null;
|
||||
const available = entryKind !== null;
|
||||
// Change-only publishes: this runs on a preUpdate cadence, and a fresh
|
||||
// presence every frame would re-render the views even when nothing
|
||||
// changed. (perf item 9)
|
||||
if (this.presence.entryAvailable === available) return;
|
||||
if (
|
||||
this.presence.entryAvailable === available &&
|
||||
this.presence.entryKind === entryKind
|
||||
)
|
||||
return;
|
||||
this.presence.entryAvailable = available;
|
||||
this.presence.entryKind = entryKind;
|
||||
this.publishPresenceView();
|
||||
}
|
||||
|
||||
export function navigateContext(direction, options = {}) {
|
||||
if (this.destroyed) return false;
|
||||
// Contact navigation moves between aircraft; a bridge does not jump ship
|
||||
// and an orbital view stays with its satellite.
|
||||
if (this.subjectKind === 'vessel' || this.subjectKind === 'satellite')
|
||||
return false;
|
||||
const method = direction < 0 ? 'navigatePrevious' : 'navigateNext';
|
||||
const wasActive = this.active;
|
||||
if (wasActive) this.contextNavigationDeadlineMs = performance.now() + 1500;
|
||||
@@ -148,6 +192,11 @@ export function navigateContext(direction, options = {}) {
|
||||
}
|
||||
|
||||
export function _adoptTrackedEntity(nowMs, suppliedInfo = null) {
|
||||
// An aircraft followed from the bridge or from orbit ends that view (see
|
||||
// the vessel and orbital camera updates); it is never adopted as its
|
||||
// subject.
|
||||
if (this.subjectKind === 'vessel' || this.subjectKind === 'satellite')
|
||||
return false;
|
||||
const nextFollowed = followedOf(this.viewer);
|
||||
const nextEntity = nextFollowed?.entity;
|
||||
if (
|
||||
@@ -178,14 +227,34 @@ export function _adoptTrackedEntity(nowMs, suppliedInfo = null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function enter() {
|
||||
/**
|
||||
* Enter first person on a tracked aircraft or, with none tracked, the
|
||||
* tracked satellite's orbital view or the selected vessel's bridge.
|
||||
* @param {{kind?: 'aircraft'|'satellite'|'vessel'|null}} [options] Restrict
|
||||
* entry to one subject kind; voice entry is aircraft-only.
|
||||
* @returns {boolean} True when the view was entered.
|
||||
*/
|
||||
export function enter({ kind = null } = {}) {
|
||||
if (this.destroyed) return false;
|
||||
if (this.active) return false;
|
||||
if (!this.isEntryAllowed()) return false;
|
||||
const info = this.readAircraftInfo();
|
||||
const followed = followedOf(this.viewer);
|
||||
const entity = followed?.entity;
|
||||
if (!info || !entity?.position) return false;
|
||||
const subjectKind = kind ?? this.resolveEntryKind() ?? 'aircraft';
|
||||
const vessel = subjectKind === 'vessel';
|
||||
const satellite = subjectKind === 'satellite';
|
||||
const allowed = vessel
|
||||
? this.isBridgeEntryAllowed()
|
||||
: satellite
|
||||
? this.isOrbitEntryAllowed()
|
||||
: this.isEntryAllowed();
|
||||
if (!allowed) return false;
|
||||
const info = vessel
|
||||
? this.readVesselInfo()
|
||||
: satellite
|
||||
? this.readSatelliteInfo()
|
||||
: this.readAircraftInfo();
|
||||
// Only an aircraft is ridden through the followed entity.
|
||||
const followed = vessel || satellite ? null : followedOf(this.viewer);
|
||||
const entity = followed?.entity ?? null;
|
||||
if (!info || (!vessel && !satellite && !entity?.position)) return false;
|
||||
this.entryFocusOrigin =
|
||||
document.activeElement instanceof HTMLElement
|
||||
? document.activeElement
|
||||
@@ -193,11 +262,32 @@ export function enter() {
|
||||
// Retire deferred navigation before cancelFlight can run its callbacks.
|
||||
this.onCameraTakeover?.();
|
||||
cameraOf(this.viewer).cancelFlight();
|
||||
this.subjectKind = subjectKind;
|
||||
// Each session reads its own water: never a height left from the last.
|
||||
this.vesselWaterline = null;
|
||||
this.vesselFix = null;
|
||||
this.subjectId = vessel ? info.mmsi : satellite ? info.noradId : null;
|
||||
this.trackedEntity = entity;
|
||||
this.trackedFollow = followed;
|
||||
this.trackedEntityWasShown = entity.show;
|
||||
entity.show = false;
|
||||
this.heading = normalizeHeading(info.track ?? 0);
|
||||
if (entity) {
|
||||
this.trackedEntityWasShown = entity.show;
|
||||
entity.show = false;
|
||||
} else if (satellite) {
|
||||
// The layer hides the satellite's own marks and dims the other orbits.
|
||||
this.services.satellitesLayer?.setCockpitSubject?.(info.noradId);
|
||||
this.beginOrbital();
|
||||
} else {
|
||||
this.services.aisLiveVesselsLayer?.setCockpitSubject?.(info.mmsi);
|
||||
}
|
||||
// A ship reporting neither heading nor course keeps the camera's own
|
||||
// heading: no direction is made up for it.
|
||||
this.heading = normalizeHeading(
|
||||
Number.isFinite(info.track)
|
||||
? info.track
|
||||
: vessel
|
||||
? cameraHeadingDeg(cameraOf(this.viewer).pose())
|
||||
: 0,
|
||||
);
|
||||
this.lastFrameMs = performance.now();
|
||||
this.lastCameraUpdateMs = 0;
|
||||
this.lastHudUpdateMs = 0;
|
||||
@@ -209,6 +299,8 @@ export function enter() {
|
||||
this.surfaceFallback = false;
|
||||
this.cockpitAnchorValid = false;
|
||||
this.lastCameraUpdateMs = 0;
|
||||
// Every bridge opens looking over the bow.
|
||||
this.resetLook({ immediate: true });
|
||||
this.active = true;
|
||||
// Cockpit animates the camera from preUpdate every frame — preUpdate only
|
||||
// runs on rendered frames, so idle mode would freeze the cockpit solid.
|
||||
@@ -218,33 +310,70 @@ export function enter() {
|
||||
this.releaseCameraInput?.();
|
||||
this.releaseCameraInput = inputFor(this.viewer).suspendCamera('cockpit');
|
||||
document.body.classList.add('cockpit-mode');
|
||||
// Bridge styling reaches surfaces outside the HUD (exit row, side panels).
|
||||
if (vessel) document.body.classList.add('cockpit-bridge');
|
||||
if (satellite) document.body.classList.add('cockpit-orbit');
|
||||
// Activation hides the entry and TR-3B chip; clearing the chip's signature
|
||||
// lets the exit-path syncEntry publish it again.
|
||||
this._tr3bSignature = null;
|
||||
Object.assign(this.presence, {
|
||||
active: true,
|
||||
entryAvailable: false,
|
||||
entryKind: null,
|
||||
subjectKind,
|
||||
tr3b: null,
|
||||
});
|
||||
this.publishPresenceView();
|
||||
// Only a bridge has a radar.
|
||||
if (!vessel) this.publishRadar(null);
|
||||
this.signalItems = [];
|
||||
this.signalSignatures.clear();
|
||||
this.showBriefPage(0);
|
||||
this.startBriefRotation();
|
||||
const trackLabel =
|
||||
info.callsign || info.registration || info.icao24 || t('AIRCRAFT');
|
||||
const trackHeading = formatHeadingReadout(info.track ?? 0);
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
t('{label} · COURSE {heading}°', {
|
||||
label: trackLabel,
|
||||
heading: trackHeading,
|
||||
}),
|
||||
);
|
||||
if (satellite) {
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
t('{label} · NADIR VIEW', { label: info.name }),
|
||||
);
|
||||
} else if (vessel) {
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
// A ship with no true heading is held on its course over ground; one
|
||||
// with neither is named without a direction.
|
||||
info.trackSource === 'course'
|
||||
? t('{label} · COURSE {heading}°', {
|
||||
label: info.name,
|
||||
heading: trackHeading,
|
||||
})
|
||||
: info.trackSource === 'heading'
|
||||
? t('{label} · HEADING {heading}°', {
|
||||
label: info.name,
|
||||
heading: trackHeading,
|
||||
})
|
||||
: t('{label} · NO HEADING', { label: info.name }),
|
||||
);
|
||||
} else {
|
||||
const trackLabel =
|
||||
info.callsign || info.registration || info.icao24 || t('AIRCRAFT');
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
t('{label} · COURSE {heading}°', {
|
||||
label: trackLabel,
|
||||
heading: trackHeading,
|
||||
}),
|
||||
);
|
||||
}
|
||||
this.updateHud(info, performance.now(), true);
|
||||
this.setVisionMode(this.getInitialVisionMode());
|
||||
// Orbit always opens in the plain optical picture; the vision styles stay
|
||||
// one click away.
|
||||
this.setVisionMode(satellite ? 'optical' : this.getInitialVisionMode());
|
||||
this.scheduleContextLayout();
|
||||
// The exit button shows when Vue flushes the presence; focus it after.
|
||||
Promise.resolve().then(() => {
|
||||
@@ -261,11 +390,19 @@ export function exit({ restoreTracking = true } = {}) {
|
||||
if (!this.active) return false;
|
||||
const entity = this.trackedEntity;
|
||||
const followed = this.trackedFollow;
|
||||
const vesselSubject = this.subjectKind === 'vessel' ? this.subjectId : null;
|
||||
const satelliteSubject =
|
||||
this.subjectKind === 'satellite' ? this.subjectId : null;
|
||||
this.active = false;
|
||||
this.subjectKind = null;
|
||||
this.vesselWaterline = null;
|
||||
this.vesselFix = null;
|
||||
this.subjectId = null;
|
||||
this.services.releaseContinuousRender('cockpit');
|
||||
this.trackedEntity = null;
|
||||
this.trackedFollow = null;
|
||||
this.heading = null;
|
||||
this.resetLook({ immediate: true });
|
||||
this.cockpitAnchorValid = false;
|
||||
this.surfaceWaitStartedMs = 0;
|
||||
this.surfaceAcquiring = false;
|
||||
@@ -278,13 +415,21 @@ export function exit({ restoreTracking = true } = {}) {
|
||||
this.regionalBriefAbort = null;
|
||||
this.regionalBriefRequestToken += 1;
|
||||
this.regionalBriefSubjectId = null;
|
||||
document.body.classList.remove('cockpit-mode');
|
||||
document.body.classList.remove(
|
||||
'cockpit-mode',
|
||||
'cockpit-bridge',
|
||||
'cockpit-orbit',
|
||||
);
|
||||
// The camera's own field of view returns before any follow resumes.
|
||||
this.endOrbital();
|
||||
this.onExited?.();
|
||||
this.publishUtilityLayout(null);
|
||||
this.presence.active = false;
|
||||
this.presence.subjectKind = null;
|
||||
this.publishPresenceView();
|
||||
this.routeView.visible = false;
|
||||
this.clearPredictiveRoute();
|
||||
this.publishRadar(null);
|
||||
this.setVisionMode('optical');
|
||||
this.releaseCameraInput?.();
|
||||
this.releaseCameraInput = null;
|
||||
@@ -292,10 +437,20 @@ export function exit({ restoreTracking = true } = {}) {
|
||||
Boolean(entity) && trackedEntityDrawn.call(this, entity);
|
||||
if (present()) entity.show = this.trackedEntityWasShown;
|
||||
this.trackedEntityWasShown = true;
|
||||
if (vesselSubject)
|
||||
this.services.aisLiveVesselsLayer?.setCockpitSubject?.(null);
|
||||
if (satelliteSubject !== null)
|
||||
this.services.satellitesLayer?.setCockpitSubject?.(null);
|
||||
this.dispatchCockpitModeChanged(false);
|
||||
if (restoreTracking && present()) {
|
||||
resumeFollowing(this.viewer, followed);
|
||||
this.restoreTrackingFrame(entity);
|
||||
} else if (restoreTracking && vesselSubject) {
|
||||
// Back to the selected vessel's map view, through the layer's own focus.
|
||||
this.services.aisLiveVesselsLayer?.focusSelectedVessel?.();
|
||||
} else if (restoreTracking && satelliteSubject !== null) {
|
||||
// Back to the satellite's follow camera, through the layer's own refocus.
|
||||
this.services.satellitesLayer?.refocusTrackedById?.(satelliteSubject);
|
||||
}
|
||||
this.syncEntry();
|
||||
// Back to whichever entry was used: the Contacts button or the readout's.
|
||||
|
||||
Reference in new issue
Block a user