mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Navara's ground pass cut each corridor into chunks and tested them per screen cell, so dense corridor sets were slow (10,000 cost about 150 ms a frame). A corridor set is now cut into pieces along its great circles, sorted into lon/lat tiles, each with a pyramid of bins listing the segment runs within its margin; a pixel takes its tile and the finest bin that covers its reach and tests only those runs. At 10,000 corridors a frame now takes 11.8 ms still (Cesium 23 ms), at 15,000 17.9 ms. A pixel corridor's width is measured across the line, so diagonal lines no longer draw up to 1.4 times wider. Pixel corridors take three looks, evaluated on the GPU from a time uniform: Cesium's PolylineGlow falloff (glow), an alpha pulse and the annotation route's flowing dash. While a shown set pulses or flows the engine draws continuously, as Cesium did. Traffic's jam lines take the glow and pulse again and the Directions route its flowing dash and render hold, so on Cesium both match the drawing before they moved to the contract pixel for pixel. The contract suite passes on both engines (Cesium 69/69, Navara 72/72).
128 lines
3.6 KiB
JavaScript
128 lines
3.6 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createNavaraGround } from './index.js';
|
|
|
|
function fakeView({ height = () => 12 } = {}) {
|
|
const listeners = new Map();
|
|
return {
|
|
frames: 0,
|
|
on: (name, listener) => listeners.set(name, listener),
|
|
off: (name) => listeners.delete(name),
|
|
forceUpdate() {
|
|
this.frames++;
|
|
},
|
|
sampleTerrainHeight: ({ lat, lng }) => height(lng, lat),
|
|
postRender: () => listeners.get('postRender')?.(),
|
|
listening: () => listeners.size,
|
|
};
|
|
}
|
|
|
|
function fakePass() {
|
|
const states = [];
|
|
return {
|
|
states,
|
|
owner: { state: null },
|
|
set(state) {
|
|
states.push(state);
|
|
this.owner.state = state;
|
|
},
|
|
textureBytes: () => 0,
|
|
destroyed: false,
|
|
destroy() {
|
|
this.destroyed = true;
|
|
},
|
|
};
|
|
}
|
|
|
|
const square = (lon) => ({
|
|
rings: [
|
|
[
|
|
[lon, 0],
|
|
[lon + 1, 0],
|
|
[lon + 1, 1],
|
|
],
|
|
],
|
|
fill: [1, 0, 0, 1],
|
|
});
|
|
|
|
test('shown sets compose in order into one pass; hiding all hides it', () => {
|
|
const view = fakeView();
|
|
const pass = fakePass();
|
|
const ground = createNavaraGround(view, { createPass: () => pass });
|
|
const top = ground.ground.createSet({ id: 'top', kind: 'polygon', order: 1 });
|
|
const bottom = ground.ground.createSet({ id: 'bottom', kind: 'polygon' });
|
|
top.replace([square(0)]);
|
|
top.commit();
|
|
bottom.replace([square(2), square(4)]);
|
|
bottom.commit();
|
|
const state = pass.states.at(-1);
|
|
assert.equal(state.count, 3);
|
|
assert.ok(view.frames >= 2, 'each change asks for a frame');
|
|
top.show(false);
|
|
bottom.show(false);
|
|
assert.equal(pass.states.at(-1), null);
|
|
bottom.show(true);
|
|
assert.equal(pass.states.at(-1).count, 2);
|
|
assert.equal(ground.pickables().length, 2);
|
|
ground.destroy();
|
|
assert.equal(pass.destroyed, true);
|
|
assert.equal(view.listening(), 0);
|
|
});
|
|
|
|
test('a set packed before its terrain loaded is packed again later', () => {
|
|
let loaded = false;
|
|
const view = fakeView({ height: () => (loaded ? 30 : undefined) });
|
|
const pass = fakePass();
|
|
const ground = createNavaraGround(view, { createPass: () => pass });
|
|
const set = ground.ground.createSet({ id: 'zones', kind: 'polygon' });
|
|
set.replace([square(0)]);
|
|
set.commit();
|
|
const before = pass.states.length;
|
|
for (let frame = 0; frame < 29; frame++) view.postRender();
|
|
assert.equal(pass.states.length, before, 'not before 30 frames');
|
|
loaded = true;
|
|
view.postRender();
|
|
assert.equal(pass.states.length, before + 1, 'packed again with heights');
|
|
for (let frame = 0; frame < 500; frame++) view.postRender();
|
|
assert.equal(pass.states.length, before + 1, 'no more once it has them');
|
|
ground.destroy();
|
|
});
|
|
|
|
test('while a shown set pulses or dashes, every frame asks for the next', () => {
|
|
const view = fakeView();
|
|
const pass = fakePass();
|
|
const queued = [];
|
|
const ground = createNavaraGround(view, {
|
|
createPass: () => pass,
|
|
nextFrame: (run) => queued.push(run),
|
|
});
|
|
const set = ground.ground.createSet({ id: 'route', kind: 'corridor' });
|
|
set.replace([
|
|
{
|
|
positions: [
|
|
[0, 0],
|
|
[0.1, 0],
|
|
],
|
|
color: [0, 1, 1, 1],
|
|
widthPx: 9,
|
|
dash: { cells: 8, duty: 0.5, speed: 1 },
|
|
},
|
|
]);
|
|
set.commit();
|
|
const before = view.frames;
|
|
view.postRender();
|
|
view.postRender();
|
|
assert.equal(queued.length, 1, 'one request a display frame');
|
|
queued.shift()();
|
|
assert.equal(view.frames, before + 1);
|
|
set.show(false);
|
|
view.postRender();
|
|
assert.equal(queued.length, 0, 'none while hidden');
|
|
set.show(true);
|
|
view.postRender();
|
|
ground.destroy();
|
|
const destroyed = view.frames;
|
|
queued.shift()();
|
|
assert.equal(view.frames, destroyed, 'none after destroy');
|
|
});
|