mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
engine.movers.createSet({ id, kind: sprite|point|model, capacity, order,
depthTest, sprite|point|model, pickable }) → a MoverSet: set(index,
fields) stores an instance (position, screen rotation, orientation, rgba,
scale, atlas cell, show, pickId) in flat arrays, commit() uploads the
changed range once and requests one render, positionsView() reads the
positions, destroy() removes it; movers.list() for QA. The options, the
store and the registry are engine-neutral (src/globe/movers.js); the fake
engine keeps them for layer tests.
- Cesium: one primitive per set in an engine-owned PrimitiveCollection
added with the first set, in `order`: sprites a BillboardCollection
(one image per atlas cell, NearFarScalar, disableDepthTestDistance),
points a PointPrimitiveCollection, models a Model per instance.
- Navara: a public MeshDesc per set. Sprites and points are one
InstancedMesh of a quad, faced to the screen and sized in CSS pixels in
the vertex shader from uniforms (the pick pass draws the same
footprint), atlas uv, rotation, colour and scale per instance, drawn in
the transparent pass unlit; offsets from an origin that follows the
camera past max(1 km, 10 % of its height). Models: the glTF once, one
InstancedMesh per mesh, minimumPixelSize/maximumScale on the CPU per
drawn frame, colorBlend in the shader. Pickable sets register a
PickableInstancedMeshWrapper; pickIds.js maps batch ids back to
instances (used by Task 4).
- The contract suite draws three 24 px sprites on both engines: centred
within 2 px of worldToWindow, hidden by show:false, recoloured, gone on
destroy, and no frames added once the commit has drawn.
- qa-engine-bench --scenario=movers: 10 000 synthetic aircraft
(src/bench/syntheticFlights.js, moved from the Navara spike with its
test), every instance moved and committed every frame. p95 Navara
(look=minimal) / Cesium: global 5.2/7.0 ms, city 5.6/9.9, orbit 6.0/7.4
(0.74, 0.57, 0.81; gate 1.1). Cesium is measured without its 60 fps cap.
Main chunk 2,860,302 bytes (+9,706, +0.34 %: the Cesium movers).
111 lines
4.1 KiB
JavaScript
111 lines
4.1 KiB
JavaScript
// src/bench/syntheticFlights.js
|
||
const EARTH_RADIUS_M = 6_371_000;
|
||
const RADIANS = Math.PI / 180;
|
||
|
||
/** Small deterministic PRNG so both engines draw the same fleet. */
|
||
function mulberry32(seed) {
|
||
let state = seed >>> 0;
|
||
return () => {
|
||
state = (state + 0x6d2b79f5) >>> 0;
|
||
let t = state;
|
||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||
};
|
||
}
|
||
|
||
const wrapLongitude = (lon) => ((((lon + 180) % 360) + 360) % 360) - 180;
|
||
|
||
function checkNear(near, count) {
|
||
if (!Number.isInteger(near.count) || near.count < 0 || near.count > count)
|
||
throw new RangeError('near.count must be an integer in [0, count]');
|
||
if (!(near.radiusM >= 0) || !Number.isFinite(near.radiusM))
|
||
throw new RangeError('near.radiusM must be a non-negative number');
|
||
if (!Number.isFinite(near.lat) || !Number.isFinite(near.lng))
|
||
throw new RangeError('near.lat and near.lng must be finite');
|
||
const bands = nearBands(near);
|
||
if (
|
||
!(bands.minAltM <= bands.maxAltM) ||
|
||
!(bands.minSpeedMps <= bands.maxSpeedMps)
|
||
)
|
||
throw new RangeError('near altitude and speed bands must be ordered');
|
||
}
|
||
|
||
const nearBands = ({
|
||
minAltM = 300,
|
||
maxAltM = 3_000,
|
||
minSpeedMps = 10,
|
||
maxSpeedMps = 40,
|
||
}) => ({ minAltM, maxAltM, minSpeedMps, maxSpeedMps });
|
||
|
||
/**
|
||
* Deterministic synthetic aircraft for engine benchmarks. Each aircraft
|
||
* flies a great circle at constant speed on a spherical Earth.
|
||
*
|
||
* With `near: { lat, lng, radiusM, count }` the first `count` aircraft start
|
||
* uniformly over the disc of `radiusM` around that point, at `minAltM` to
|
||
* `maxAltM` (default 300–3000 m) and `minSpeedMps` to `maxSpeedMps` (default
|
||
* 10–40 m/s, slow enough to stay near the point for a bench run); the rest
|
||
* spread over the globe as without `near`.
|
||
*/
|
||
export function createSyntheticFlights({ count, seed = 1, near = null }) {
|
||
if (!Number.isInteger(count) || count < 0)
|
||
throw new RangeError('count must be a non-negative integer');
|
||
if (near) checkNear(near, count);
|
||
const random = mulberry32(seed);
|
||
const lat = new Float64Array(count);
|
||
const lon = new Float64Array(count);
|
||
const alt = new Float64Array(count);
|
||
const heading = new Float64Array(count);
|
||
const speed = new Float64Array(count);
|
||
const nearCount = near ? near.count : 0;
|
||
const bands = near ? nearBands(near) : null;
|
||
for (let i = 0; i < nearCount; i++) {
|
||
// Uniform over the disc: r = R·sqrt(u), then the spherical destination.
|
||
const distance = (near.radiusM * Math.sqrt(random())) / EARTH_RADIUS_M;
|
||
const bearing = random() * 2 * Math.PI;
|
||
const phi1 = near.lat * RADIANS;
|
||
const sinPhi2 =
|
||
Math.sin(phi1) * Math.cos(distance) +
|
||
Math.cos(phi1) * Math.sin(distance) * Math.cos(bearing);
|
||
const phi2 = Math.asin(sinPhi2);
|
||
const dLambda = Math.atan2(
|
||
Math.sin(bearing) * Math.sin(distance) * Math.cos(phi1),
|
||
Math.cos(distance) - Math.sin(phi1) * sinPhi2,
|
||
);
|
||
lat[i] = phi2 / RADIANS;
|
||
lon[i] = wrapLongitude(near.lng + dLambda / RADIANS);
|
||
alt[i] = bands.minAltM + random() * (bands.maxAltM - bands.minAltM);
|
||
heading[i] = random() * 360;
|
||
speed[i] =
|
||
bands.minSpeedMps + random() * (bands.maxSpeedMps - bands.minSpeedMps);
|
||
}
|
||
for (let i = nearCount; i < count; i++) {
|
||
lat[i] = Math.asin(2 * random() - 1) / RADIANS;
|
||
lon[i] = random() * 360 - 180;
|
||
alt[i] = 1_000 + random() * 11_000;
|
||
heading[i] = random() * 360;
|
||
speed[i] = 120 + random() * 130;
|
||
}
|
||
|
||
function advance(dtSeconds) {
|
||
for (let i = 0; i < count; i++) {
|
||
const distance = (speed[i] * dtSeconds) / EARTH_RADIUS_M;
|
||
const phi1 = lat[i] * RADIANS;
|
||
const theta = heading[i] * RADIANS;
|
||
const sinPhi2 =
|
||
Math.sin(phi1) * Math.cos(distance) +
|
||
Math.cos(phi1) * Math.sin(distance) * Math.cos(theta);
|
||
const phi2 = Math.asin(sinPhi2);
|
||
const dLambda = Math.atan2(
|
||
Math.sin(theta) * Math.sin(distance) * Math.cos(phi1),
|
||
Math.cos(distance) - Math.sin(phi1) * sinPhi2,
|
||
);
|
||
lat[i] = phi2 / RADIANS;
|
||
lon[i] = wrapLongitude(lon[i] + dLambda / RADIANS);
|
||
}
|
||
}
|
||
|
||
return { count, lat, lon, alt, heading, speed, advance };
|
||
}
|