Cut duplicated and dead code across the engines, the layers and the QA scripts

- src/geo drops the ported debug argument checks and the tests that
  bitExact already covers; package boundaries accept a directory entry,
  so src/geo/ is listed once per group.
- Cesium no longer carries movers and lines nobody draws with: they are
  optional engine capabilities. The fake engine and the Cesium camera use
  the shared cameraMath; unused contract tables, clock.ticked, the
  'finest' surface detail and Navara click statistics are gone.
- ALPR keeps one overlay core and one presentation model for both
  engines, bikeshare one station bookkeeping, the Navara ground effects
  one definition helper; image atlases, view centres, mover banks and
  colours are shared.
- The legacy switch route, the clock offset and rate controls and other
  unused exports are removed.
- The acceptance runs the Navara draw, geo import and scope checks;
  scenarios use the harness switch and page helpers; the main chunk
  check keeps the size budget only and runs once in CI.
This commit is contained in:
German Khokhlov committed 2026-11-05 13:32:39 +04:00
1 parent c502404e1d
commit 7abf74518f
272 files changed
+4828 -10213

No files matched your search

+13 -174
View File
@@ -2,22 +2,12 @@ import * as Cesium from 'cesium';
import {
COLOR_NEUTRAL,
POINT_HEIGHT_OFFSET_M,
MAX_TOTAL_POINTS,
COLOR_OUTLINE,
} from '../../policy.js';
import {
capacityToPixelSize,
resolveCapacity,
statusToColor,
} from '../../presentation.js';
import { createStationPoints } from '../../stationPoints.js';
export function createRendering({
state: layerState,
services,
parts,
source,
}) {
const { governorRequestRender } = services.render;
export function createRendering(context) {
const { state: layerState } = context;
/**
* Create a Cartesian3 position for a station, terrain-clamped when possible.
@@ -44,59 +34,13 @@ export function createRendering({
return Cesium.Cartesian3.fromDegrees(lon, lat, height);
}
/**
* Get or create the runtime tracking object for a city.
* @param {string} cityId - City identifier.
* @returns {{ stationKeys: Set<string> }} City runtime object.
*/
function ensureCityRuntime(cityId) {
if (layerState._cityRuntime.has(cityId))
return layerState._cityRuntime.get(cityId);
const runtime = { stationKeys: new Set() };
layerState._cityRuntime.set(cityId, runtime);
return runtime;
}
/**
* Ensure point primitives exist for all stations in a city.
* Creates new points for stations not yet rendered; skips existing ones.
* Respects the MAX_TOTAL_POINTS global cap to prevent GPU overload.
* @param {string} cityId - City identifier.
* @param {Map<string, Object>} stationMap - Parsed station info map for the city.
*/
function ensureCityPoints(cityId, stationMap) {
// Deferred debounce/fetch completions mutate point primitives after the
// camera settled — each commit needs one frame in idle mode. (perf wave 2 fix)
governorRequestRender('bikeshare-points');
const runtime = ensureCityRuntime(cityId);
for (const station of stationMap.values()) {
const key = parts.model.stationKey(cityId, station.stationId);
if (layerState._stationRenderMap.has(key)) {
runtime.stationKeys.add(key);
continue;
}
// Enforce global point cap
if (layerState._stationRenderMap.size >= MAX_TOTAL_POINTS) {
if (!layerState._limitWarned) {
layerState._limitWarned = true;
console.warn(
`[Data:Bikeshare] Point cap reached (${MAX_TOTAL_POINTS}).`,
);
}
break;
}
const position = createStationPosition(station);
if (!position) continue;
// Add a point primitive with distance-based scale and translucency falloff
const point = layerState._pointCollection.add({
return createStationPoints(context, {
position: createStationPosition,
// A point primitive with distance-based scale and translucency falloff
create: (record, { position, pixelSize }) =>
layerState._pointCollection.add({
position,
pixelSize: capacityToPixelSize(station.capacity),
pixelSize,
color: COLOR_NEUTRAL,
outlineColor: COLOR_OUTLINE,
outlineWidth: 1,
@@ -108,113 +52,8 @@ export function createRendering({
0.15,
),
disableDepthTestDistance: 2500,
id: key,
});
layerState._stationRenderMap.set(key, {
key,
cityId,
stationId: station.stationId,
stationName: station.name,
point,
capacity: parts.model.toNonNegativeInteger(station.capacity),
publishedCapacity: parts.model.toNonNegativeInteger(station.capacity),
bikesAvailable: null,
docksAvailable: null,
isInstalled: station.isInstalled,
isRenting: station.isRenting,
isReturning: station.isReturning,
});
runtime.stationKeys.add(key);
}
layerState._count = layerState._stationRenderMap.size;
}
/**
* Remove all rendered point primitives for a city and clean up runtime state.
* Also clears any active selection if it belongs to this city.
* @param {string} cityId - City identifier to remove.
*/
function removeCityPoints(cityId) {
const runtime = layerState._cityRuntime.get(cityId);
if (!runtime) return;
// Clear selection if it belongs to the city being removed
if (
layerState._selectedKey &&
runtime.stationKeys.has(layerState._selectedKey)
) {
parts.selection._clearSelection();
}
for (const key of runtime.stationKeys) {
const record = layerState._stationRenderMap.get(key);
if (!record) continue;
layerState._pointCollection.remove(record.point);
layerState._stationRenderMap.delete(key);
}
layerState._cityRuntime.delete(cityId);
layerState._count = layerState._stationRenderMap.size;
}
/**
* Apply real-time status data to rendered station points for a city.
* Updates each point's color (availability ratio) and pixel size (capacity),
* and refreshes the render record's cached availability fields.
* @param {string} cityId - City identifier.
* @param {Map<string, Object>} statusMap - Parsed station status map.
*/
function applyStatusToPoints(cityId, statusMap) {
governorRequestRender('bikeshare-status');
const runtime = layerState._cityRuntime.get(cityId);
if (!runtime) return;
for (const key of runtime.stationKeys) {
const record = layerState._stationRenderMap.get(key);
if (!record) continue;
const status = statusMap.get(record.stationId) || null;
// Resolve from the published capacity, not last poll's derived value.
const capacity = resolveCapacity(
parts.model,
record.publishedCapacity,
status,
);
record.capacity = capacity;
record.bikesAvailable = parts.model.toNonNegativeInteger(
status?.bikesAvailable,
);
record.docksAvailable = parts.model.toNonNegativeInteger(
status?.docksAvailable,
);
record.isInstalled = parts.model.normalizeGbfsBool(
status?.isInstalled,
true,
);
record.isRenting = parts.model.normalizeGbfsBool(status?.isRenting, true);
record.isReturning = parts.model.normalizeGbfsBool(
status?.isReturning,
true,
);
// Update visual properties based on current status
record.point.pixelSize = capacityToPixelSize(capacity);
record.point.color = statusToColor(parts.model, status, capacity);
}
parts.selection.refreshSelectedCard();
}
return {
capacityToPixelSize,
createStationPosition,
ensureCityRuntime,
ensureCityPoints,
removeCityPoints,
applyStatusToPoints,
};
id: record.key,
}),
remove: (record) => layerState._pointCollection.remove(record.point),
});
}
@@ -1,9 +1,6 @@
import * as Cesium from 'cesium';
import { isPointerFree } from '../../../../data/inputOwnership.js';
import {
buildBikeshareSelectionLabel,
createBikeshareSelectedOverlayEntry,
} from '../../selectionModel.js';
import { createBikeshareSelectedOverlayEntry } from '../../selectionModel.js';
import {
BIKESHARE_SELECTED_OVERLAY_SOURCE_ID,
BIKESHARE_SELECTED_OVERLAY_SOURCE_OPTIONS,
@@ -140,8 +137,6 @@ export function createSelection({
}
return {
refreshSelectedCard,
buildSelectionLabel: buildBikeshareSelectionLabel,
createBikeshareSelectedOverlayEntry,
_clearSelection,
_selectStation,
_installClickHandler,
+18 -137
View File
@@ -1,6 +1,7 @@
import * as geo from '../../../geo/index.js';
import { selectionDispatcherFor } from '../../../data/selectionDispatcher.js';
import { CYAN } from '../../shared/color.js';
import { viewRectangleCenter } from '../../shared/viewRectangle.js';
import { createViewport } from '../viewport.js';
import {
BIKESHARE_SELECTED_OVERLAY_SOURCE_ID,
@@ -10,15 +11,9 @@ import {
MAX_TOTAL_POINTS,
POINT_HEIGHT_OFFSET_M,
} from '../policy.js';
import {
capacityToPixelSize,
resolveCapacity,
statusToColor,
} from '../presentation.js';
import {
buildBikeshareSelectionLabel,
createBikeshareSelectedOverlayEntry,
} from '../selectionModel.js';
import { capacityToPixelSize } from '../presentation.js';
import { createBikeshareSelectedOverlayEntry } from '../selectionModel.js';
import { createStationPoints } from '../stationPoints.js';
const LAYER_ID = 'bikeshare';
@@ -36,8 +31,6 @@ function pointSet(engine, { id, capacity, order, depthTest, point }) {
}
export function createBikeshareNavaraRenderer(engine, context) {
if (!engine?.movers || !engine?.camera?.viewRectangle)
throw new TypeError('Bikeshare requires a Navara globe engine');
const { state, services, parts } = context;
const normalSet = pointSet(engine, {
id: LAYER_ID,
@@ -85,13 +78,8 @@ export function createBikeshareNavaraRenderer(engine, context) {
};
const request = (reason) => services.render.governorRequestRender(reason);
const rendering = {
resolveCapacity: (capacity, status) =>
resolveCapacity(parts.model, capacity, status),
capacityToPixelSize,
statusToColor: (status, capacity) =>
statusToColor(parts.model, status, capacity),
createStationPosition(station) {
const rendering = createStationPoints(context, {
position(station) {
const lon = Number(station?.lon);
const lat = Number(station?.lat);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null;
@@ -105,122 +93,22 @@ export function createBikeshareNavaraRenderer(engine, context) {
(Number.isFinite(sampled) ? sampled : 0) + POINT_HEIGHT_OFFSET_M;
return geo.cartesian3.fromDegrees(lon, lat, height);
},
ensureCityRuntime(cityId) {
let runtime = state._cityRuntime.get(cityId);
if (!runtime) {
runtime = { stationKeys: new Set() };
state._cityRuntime.set(cityId, runtime);
}
return runtime;
create(record, { position, pixelSize }) {
record.index = state._stationRenderMap.size;
record.point = { position, pixelSize, color: COLOR_NEUTRAL, show: true };
syncPoint(record);
return record.point;
},
ensureCityPoints(cityId, stationMap) {
request('bikeshare-points');
const runtime = this.ensureCityRuntime(cityId);
for (const station of stationMap.values()) {
const key = parts.model.stationKey(cityId, station.stationId);
if (state._stationRenderMap.has(key)) {
runtime.stationKeys.add(key);
continue;
}
if (state._stationRenderMap.size >= MAX_TOTAL_POINTS) {
if (!state._limitWarned) {
state._limitWarned = true;
console.warn(
`[Data:Bikeshare] Point cap reached (${MAX_TOTAL_POINTS}).`,
);
}
break;
}
const position = this.createStationPosition(station);
if (!position) continue;
const record = {
key,
cityId,
stationId: station.stationId,
stationName: station.name,
index: state._stationRenderMap.size,
point: {
position,
pixelSize: capacityToPixelSize(station.capacity),
color: COLOR_NEUTRAL,
show: true,
},
capacity: parts.model.toNonNegativeInteger(station.capacity),
publishedCapacity: parts.model.toNonNegativeInteger(station.capacity),
bikesAvailable: null,
docksAvailable: null,
isInstalled: station.isInstalled,
isRenting: station.isRenting,
isReturning: station.isReturning,
};
state._stationRenderMap.set(key, record);
runtime.stationKeys.add(key);
syncPoint(record);
}
afterAdd() {
normalSet.setCount(state._stationRenderMap.size);
normalSet.commit();
state._count = state._stationRenderMap.size;
},
removeCityPoints(cityId) {
const runtime = state._cityRuntime.get(cityId);
if (!runtime) return;
if (state._selectedKey && runtime.stationKeys.has(state._selectedKey))
selection._clearSelection();
for (const key of runtime.stationKeys)
state._stationRenderMap.delete(key);
state._cityRuntime.delete(cityId);
resetNormalSet();
},
applyStatusToPoints(cityId, statusMap) {
request('bikeshare-status');
const runtime = state._cityRuntime.get(cityId);
if (!runtime) return;
for (const key of runtime.stationKeys) {
const record = state._stationRenderMap.get(key);
if (!record) continue;
const status = statusMap.get(record.stationId) || null;
// Resolve from the published capacity, not last poll's derived value.
record.capacity = resolveCapacity(
parts.model,
record.publishedCapacity,
status,
);
record.bikesAvailable = parts.model.toNonNegativeInteger(
status?.bikesAvailable,
);
record.docksAvailable = parts.model.toNonNegativeInteger(
status?.docksAvailable,
);
record.isInstalled = parts.model.normalizeGbfsBool(
status?.isInstalled,
true,
);
record.isRenting = parts.model.normalizeGbfsBool(
status?.isRenting,
true,
);
record.isReturning = parts.model.normalizeGbfsBool(
status?.isReturning,
true,
);
record.point.pixelSize = capacityToPixelSize(record.capacity);
record.point.color = statusToColor(
parts.model,
status,
record.capacity,
);
syncPoint(record);
}
normalSet.commit();
selection.refreshSelectedCard();
},
};
afterRemove: resetNormalSet,
update: syncPoint,
afterUpdate: () => normalSet.commit(),
});
const selection = {
buildSelectionLabel(record) {
return buildBikeshareSelectionLabel(record);
},
createBikeshareSelectedOverlayEntry,
refreshSelectedCard() {
const key = state._selectedKey;
const record = state._stationRenderMap.get(key);
@@ -278,10 +166,6 @@ export function createBikeshareNavaraRenderer(engine, context) {
}
request('bikeshare-selection');
},
_installClickHandler() {},
_onKeyDown(event) {
if (event.key === 'Escape' && state._selectedKey) this._clearSelection();
},
};
const viewport = createViewport({
@@ -291,12 +175,9 @@ export function createBikeshareNavaraRenderer(engine, context) {
getCameraCenterLatLon() {
const rect = engine.camera.viewRectangle();
if (rect) {
let east = rect.east;
if (east < rect.west) east += Math.PI * 2;
let longitude = (rect.west + east) / 2;
if (longitude > Math.PI) longitude -= Math.PI * 2;
const { latitude, longitude } = viewRectangleCenter(rect);
return {
lat: geo.math.toDegrees((rect.south + rect.north) / 2),
lat: geo.math.toDegrees(latitude),
lon: geo.math.toDegrees(longitude),
};
}