mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
refactor(military): Cesium rendering behind a renderer interface
Task 11a. The military flights logic no longer imports Cesium: it draws
through the shared aircraft renderer (src/layers/aircraft/render/cesium.js)
with the military's parameters in src/layers/military/render/cesium.js
(sprite-order slot 'military', jet.glb's 180° nose offset), registered for
'cesium' in the renderer registry and created at init(viewer, {engine}).
The same pure move as flights in 10a:
- Fleet: the BillboardCollection and its sprite-order slot (enable keeps
restoreSpriteOrder, as before); sprites stay Billboard handles.
- Models: fleet/tracked/preload glTF loads (asynchronous:false, MIX tint at
MODEL_COLOR_BLEND_AMOUNT, IR boost as `unlit` → the UNLIT CustomShader),
the model collection, setPose. The per-class specs keep their own nose
offset: setPose takes an optional offsetDeg (default the layer's), on
both aircraft renderers (same arithmetic, test added).
- Tracked: the ENU billboard Entity with its position/colour/rotation
callbacks (#FFD166, transparent amber once the model owns the visual),
viewFrom, followed through viewer.trackedEntity + the one exact tracked
frame; refocusTrackedById through follow.refocus.
- Trail: the entity trail and the floored live head segment.
- View: camera/scene reads, frame number, frustum and horizon tests,
render requests, frame events.
- Clicks and Escape go through the engine's selection dispatcher (the
ScreenSpaceEventHandler and keydown listener are gone); the cross-layer
untrack watches the renderer's follow. Same rules: cockpit clicks are
inert, the tracked visual/model is a no-op, another layer's pick is not
empty space, an unowned pick is.
- Colours are engine-neutral Rgba (MIL_ICON_COLOR #FFB800,
TRACKED_ICON_COLOR #FFD166, AMBER_TRANSPARENT), NearFarScalar →
nearFarScale; Cesium math → src/geo.
- check-import-directions: src/layers/military/ joins the rendered layers
(cesium only in render/cesium*.js).
- The military registry and the flights' duplicate suppression are
untouched.
Source-text tests updated with the moved code, same meaning:
- militaryAwareness.test: military's hasContact guard reads fleet.visible().
- trackingClickGesture.test: the military gesture rules are the
dispatcher's (selection gesture before select, click classifier before
the empty-space clear), military answers the empty click with a
user-origin clear — the same assertion flights already had.
- ownership.test: the services fixture names selection and renderer; the
app-composed services build the layer's Cesium renderer.
- renderers.test: flights and military have extracted Cesium renderers.
New tests: the military logic over a plain-data renderer and a fake engine
(amber fleet, click-select, #FFD166 tracked glyph, no-op on the tracked
visual, empty-click and Escape release, the keyboard left on destroy); the
plain-data renderer moved to src/testSupport for both aircraft layers;
setPose with a per-model offset.
W1 replay vs 7c7422e2 (the 10a reference run): every layer's counts, known
objects, screen points, tracking pose after 2 s, requests and the
city/global/orbit shots (sha256) identical. qa-military-names (it checks
the installations layer): the same verdict as 7c7422e2 (the zoom-markers
assertion fails on both). Main chunk 2,890,763 B (−2.9 KB).
This commit is contained in:
1 parent
e007350645
commit
7c0891deda
26 files changed
+829
-803
No files matched your search
@@ -0,0 +1,122 @@
|
||||
// An aircraft renderer of plain records (src/layers/aircraft/render/
|
||||
// contract.js), for testing an aircraft layer's logic alone: no Cesium, no
|
||||
// Navara. `calls` logs the tracked/follow calls; `sprites` holds the fleet.
|
||||
|
||||
import * as geo from '../geo/index.js';
|
||||
|
||||
/** A renderer of plain records, for the logic alone. */
|
||||
export function recordingAircraftRenderer(engine) {
|
||||
const calls = [];
|
||||
const sprites = new Set();
|
||||
const camera = {
|
||||
positionWC: geo.cartesian3.fromDegrees(-97.7, 30.2, 400_000),
|
||||
positionCartographic: geo.cartographic.fromDegrees(-97.7, 30.2, 400_000),
|
||||
rightWC: geo.cartesian3.create(1, 0, 0),
|
||||
upWC: geo.cartesian3.create(0, 0, 1),
|
||||
directionWC: geo.cartesian3.create(0, -1, 0),
|
||||
heading: 0,
|
||||
pitch: -Math.PI / 2,
|
||||
roll: 0,
|
||||
frustum: { fovy: 1 },
|
||||
};
|
||||
const scene = {
|
||||
camera,
|
||||
canvas: { clientHeight: 768 },
|
||||
frameState: { frameNumber: 1 },
|
||||
};
|
||||
let trackedSeq = 0;
|
||||
let following;
|
||||
const renderer = {
|
||||
kind: 'record',
|
||||
engine,
|
||||
calls,
|
||||
sprites,
|
||||
view: {
|
||||
camera,
|
||||
scene,
|
||||
surfaceOwner: engine,
|
||||
surfaceScene: engine,
|
||||
frameNumber: () => 1,
|
||||
viewportHeightPx: () => 768,
|
||||
frustumTester: () => () => true,
|
||||
horizon: () => ({ isPointVisible: () => true }),
|
||||
worldToWindow: () => ({ x: 0, y: 0 }),
|
||||
requestRender: () => calls.push(['requestRender']),
|
||||
on: () => () => {},
|
||||
holdFrames() {},
|
||||
closeFrameLatch() {},
|
||||
releaseFrames() {},
|
||||
},
|
||||
fleet: {
|
||||
shown: false,
|
||||
attach: () => calls.push(['attach']),
|
||||
detach: () => calls.push(['detach']),
|
||||
attached: () => true,
|
||||
visible: () => renderer.fleet.shown,
|
||||
setVisible(visible) {
|
||||
renderer.fleet.shown = visible;
|
||||
},
|
||||
add(spec) {
|
||||
const sprite = { ...spec };
|
||||
sprites.add(sprite);
|
||||
return sprite;
|
||||
},
|
||||
remove: (sprite) => sprites.delete(sprite),
|
||||
restoreOrder() {},
|
||||
restoreOrderOnEnable() {},
|
||||
},
|
||||
models: {
|
||||
live: () => true,
|
||||
setVisible() {},
|
||||
loadFleet: () => Promise.reject(new Error('no models here')),
|
||||
loadTracked: () => Promise.reject(new Error('no models here')),
|
||||
preload: () => Promise.reject(new Error('no models here')),
|
||||
add() {},
|
||||
remove() {},
|
||||
destroy() {},
|
||||
setPose() {},
|
||||
},
|
||||
tracked: {
|
||||
create(spec) {
|
||||
const handle = { id: `tracked-${++trackedSeq}`, spec };
|
||||
calls.push(['tracked.create', handle.id]);
|
||||
return handle;
|
||||
},
|
||||
remove: (handle) => calls.push(['tracked.remove', handle.id]),
|
||||
isLive: () => true,
|
||||
setImage() {},
|
||||
setViewFrom(handle, offset) {
|
||||
handle.viewFrom = offset;
|
||||
},
|
||||
billboardSize: () => null,
|
||||
},
|
||||
follow: {
|
||||
start(handle) {
|
||||
following = handle;
|
||||
calls.push(['follow.start', handle.id]);
|
||||
return () => calls.push(['follow.frameStop']);
|
||||
},
|
||||
refocus: (handle) => renderer.follow.start(handle),
|
||||
release() {
|
||||
following = undefined;
|
||||
calls.push(['follow.release']);
|
||||
},
|
||||
isFollowing: (handle) => following === handle,
|
||||
current: () => following,
|
||||
onChanged: () => () => {},
|
||||
},
|
||||
trails: {
|
||||
create: () => ({
|
||||
setPositions() {},
|
||||
setVisible() {},
|
||||
clear() {},
|
||||
destroy() {},
|
||||
}),
|
||||
createHead: ({ id }) => ({ id, show: true }),
|
||||
removeHead() {},
|
||||
},
|
||||
surfaceExclusions: () => [],
|
||||
destroy: () => calls.push(['destroy']),
|
||||
};
|
||||
return renderer;
|
||||
}
|
||||
Reference in new issue
Block a user