mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw the traffic dots through the draw port and read the road surface through renderer ports
The traffic layer's vehicle dots are now a points set on the draw port, moved, added to and taken from in place each frame, instead of a Cesium point collection. Road surface heights and readiness read the query, camera, frame and globe ports and the heights service instead of the scene; the surface identity and "any tileset drawn" checks, which the contract cannot answer, move to rendering.js with the heat lines. animation.js, style.js and surface.js leave the Cesium allow-list. The Cesium draw port compares a moved point's look without allocating: colours by index, and a frozen colour or curve of plain data by identity, so a thousand dots moved every frame cost about what direct writes did. The traffic QA scripts read the dots' draw items.
This commit is contained in:
1 parent
d9db5199ed
commit
bbd6049e21
24 files changed
+872
-467
No files matched your search
+73
-14
@@ -1049,8 +1049,31 @@ export function createCesiumDraw({
|
||||
'displayRange',
|
||||
];
|
||||
|
||||
/**
|
||||
* What a point's look keeps of an item member: a frozen value of plain
|
||||
* members (a frozen colour or curve) as it is, since it cannot change and
|
||||
* is then told unchanged by identity; anything else as a `plainCopy`.
|
||||
*/
|
||||
function lookCopy(value) {
|
||||
if (!value || typeof value !== 'object' || !Object.isFrozen(value))
|
||||
return plainCopy(value);
|
||||
// Only plain data cannot change: no getters, nothing inherited.
|
||||
const proto = Object.getPrototypeOf(value);
|
||||
if (proto !== Object.prototype && proto !== Array.prototype)
|
||||
return plainCopy(value);
|
||||
for (const key of Reflect.ownKeys(value)) {
|
||||
const member = Object.getOwnPropertyDescriptor(value, key);
|
||||
if (
|
||||
!('value' in member) ||
|
||||
(member.value !== null && typeof member.value === 'object')
|
||||
)
|
||||
return plainCopy(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/** A copy of the item members a point's look is drawn from. */
|
||||
const pointLookOf = (item) => LOOK_FROM.map((key) => plainCopy(item[key]));
|
||||
const pointLookOf = (item) => LOOK_FROM.map((key) => lookCopy(item[key]));
|
||||
|
||||
/**
|
||||
* Whether `value` holds what `kept` (a `plainCopy` of a colour, curve or
|
||||
@@ -1067,6 +1090,13 @@ export function createCesiumDraw({
|
||||
)
|
||||
return false;
|
||||
if (Array.isArray(kept) !== Array.isArray(value)) return false;
|
||||
if (Array.isArray(value)) {
|
||||
// Colours, read by index: a `for...in` over an array is far slower.
|
||||
if (kept.length !== value.length) return false;
|
||||
for (let i = 0; i < value.length; i++)
|
||||
if (!Object.is(kept[i], value[i])) return false;
|
||||
return true;
|
||||
}
|
||||
let count = 0;
|
||||
for (const key in value) {
|
||||
if (value[key] === undefined) continue;
|
||||
@@ -1083,28 +1113,57 @@ export function createCesiumDraw({
|
||||
const value = item[LOOK_FROM[i]];
|
||||
if (sameLookValue(was.look[i], value)) continue;
|
||||
was.primitive[LOOK[i][0]] = LOOK[i][1](item);
|
||||
was.look[i] = plainCopy(value);
|
||||
was.look[i] = lookCopy(value);
|
||||
}
|
||||
}
|
||||
|
||||
const PLACE_KEYS = ['x', 'y', 'z', 'lon', 'lat', 'height'];
|
||||
|
||||
/**
|
||||
* Where an item is, as its values when drawn: a caller may change the
|
||||
* position object it passes and send the same one again.
|
||||
*/
|
||||
const placeOf = (item) =>
|
||||
PLACE_KEYS.map((key) => item.pos?.[key]).concat(item.height);
|
||||
const placeOf = (item) => {
|
||||
const pos = item.pos;
|
||||
return [
|
||||
pos?.x,
|
||||
pos?.y,
|
||||
pos?.z,
|
||||
pos?.lon,
|
||||
pos?.lat,
|
||||
pos?.height,
|
||||
item.height,
|
||||
];
|
||||
};
|
||||
|
||||
/** Whether an item is somewhere else than `at`; if so, `at` takes it. */
|
||||
/**
|
||||
* Whether an item is somewhere else than `at`; if so, `at` takes it. Read
|
||||
* member by member, by name: points moved every frame are compared every
|
||||
* frame.
|
||||
*/
|
||||
function movedFrom(at, item) {
|
||||
let moved = !Object.is(item.height, at[PLACE_KEYS.length]);
|
||||
for (let i = 0; !moved && i < PLACE_KEYS.length; i++)
|
||||
moved = !Object.is(item.pos?.[PLACE_KEYS[i]], at[i]);
|
||||
if (!moved) return false;
|
||||
for (let i = 0; i < PLACE_KEYS.length; i++)
|
||||
at[i] = item.pos?.[PLACE_KEYS[i]];
|
||||
at[PLACE_KEYS.length] = item.height;
|
||||
const pos = item.pos;
|
||||
const x = pos?.x;
|
||||
const y = pos?.y;
|
||||
const z = pos?.z;
|
||||
const lon = pos?.lon;
|
||||
const lat = pos?.lat;
|
||||
const height = pos?.height;
|
||||
if (
|
||||
Object.is(x, at[0]) &&
|
||||
Object.is(y, at[1]) &&
|
||||
Object.is(z, at[2]) &&
|
||||
Object.is(lon, at[3]) &&
|
||||
Object.is(lat, at[4]) &&
|
||||
Object.is(height, at[5]) &&
|
||||
Object.is(item.height, at[6])
|
||||
)
|
||||
return false;
|
||||
at[0] = x;
|
||||
at[1] = y;
|
||||
at[2] = z;
|
||||
at[3] = lon;
|
||||
at[4] = lat;
|
||||
at[5] = height;
|
||||
at[6] = item.height;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user