mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Step the range ring's fronts and band on the Cyber sonar interval while the camera moves
The fronts and band are fixed in the world, so a camera move needs nothing of them: they now step 80 ms apart however many frames are drawn, as a parked view's do, and look the same moving or parked. Each frame checks only whether the camera crossed the rim height, which shows or hides them at once.
This commit is contained in:
1 parent
e4af6c8ed7
commit
3bca55831f
4 files changed
+36
-40
No files matched your search
@@ -95,9 +95,10 @@ export const AWARENESS_RANGE_RING_STYLE = Object.freeze({
|
||||
* (tracking, cockpit, orbit, a fly-to) do not. Below the band's height they
|
||||
* rest too. While they run they never hold
|
||||
* continuous rendering; each drawn frame arms one more step after the
|
||||
* Cyber sonar's 80 ms cadence, so the two never beat. The fronts move on
|
||||
* every frame the camera moves in, or while something else holds
|
||||
* continuous rendering; the band is repainted at most every 80 ms.
|
||||
* Cyber sonar's 80 ms cadence, so the two never beat. Fronts and band,
|
||||
* fixed in the world, step at that cadence however many frames are
|
||||
* drawn, so they look the same whether the camera moves or not; crossing
|
||||
* the rim height shows or hides them at once.
|
||||
* Skipped under prefers-reduced-motion. */
|
||||
export const AWARENESS_RANGE_PULSE = Object.freeze({
|
||||
count: 3,
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
* @description The Global Context range ring and its sonar pulses, drawn
|
||||
* through the renderer's draw port. The ring is a haloed line (a solid line
|
||||
* with an outline) 2.5 km above the ellipsoid. While pulses run, each pulse
|
||||
* front is a haloed line whose positions move each step: every
|
||||
* `CYBER_SONAR_RENDER_INTERVAL_MS` on a parked view, every frame the camera
|
||||
* moves in. The band behind the fronts is one flat ellipse at the same
|
||||
* height filled with a canvas painted anew at most every interval (a new
|
||||
* key for new content). Nothing here is
|
||||
* front is a haloed line whose positions move each step, every
|
||||
* `CYBER_SONAR_RENDER_INTERVAL_MS` whether the camera moves or not. The
|
||||
* band behind the fronts is one flat ellipse at the same height filled
|
||||
* with a canvas painted anew each step (a new key for new content). Nothing here is
|
||||
* pickable, so a click or tap near the ring reaches the contact underneath.
|
||||
* Under reduced motion, or where the renderer has no frame hooks, the ring
|
||||
* alone is drawn and stays.
|
||||
@@ -619,35 +618,30 @@ export function createRangeRing({
|
||||
next.step(nowMs);
|
||||
}
|
||||
};
|
||||
// The eye as the pulses were last drawn under it, to tell frames the
|
||||
// camera moved in from frames the pulses themselves asked for.
|
||||
const camera = findCamera(viewer);
|
||||
let lastEye = '';
|
||||
const eyeMoved = () => {
|
||||
const pose = camera?.pose();
|
||||
if (!pose) return false;
|
||||
const { position: p, direction: d } = pose;
|
||||
const eye = `${p.x},${p.y},${p.z},${d.x},${d.y},${d.z}`;
|
||||
if (eye === lastEye) return false;
|
||||
lastEye = eye;
|
||||
return true;
|
||||
};
|
||||
next.lastStepMs = performance.now();
|
||||
next.step(next.lastStepMs);
|
||||
// Each frame drawn while the camera moves, or held drawing, or at
|
||||
// least a Cyber sonar interval after the last step, steps them. A
|
||||
// step asks for the frame that draws it, which is no reason to step
|
||||
// again: a parked view, held by nothing, draws one frame each
|
||||
// interval, as the timer below asks.
|
||||
// Whether the camera was below the rim at the last step.
|
||||
let wasBelow = belowRim();
|
||||
// The fronts and band are fixed in the world: a camera move needs
|
||||
// nothing of them, so they step a Cyber sonar interval apart however
|
||||
// many frames are drawn, and look the same parked or moving. Each
|
||||
// frame checks only whether the camera crossed the rim height, which
|
||||
// shows or hides them at once. A step asks for the frame that draws
|
||||
// it, which is no reason to step again: a parked view draws one
|
||||
// frame each interval, as the timer below asks.
|
||||
const offPreRender = frame.on('preRender', () => {
|
||||
const nowMs = performance.now();
|
||||
const moved = eyeMoved();
|
||||
const below = belowRim();
|
||||
if (
|
||||
moved ||
|
||||
frame.diagnostics?.()?.holds?.length > 0 ||
|
||||
below !== wasBelow ||
|
||||
nowMs - next.lastStepMs >= CYBER_SONAR_RENDER_INTERVAL_MS
|
||||
)
|
||||
) {
|
||||
// A crossing at the instant of the last step must not reuse
|
||||
// that step's level.
|
||||
if (below !== wasBelow) levelMemo.nowMs = Number.NaN;
|
||||
wasBelow = below;
|
||||
stepRunning(nowMs);
|
||||
}
|
||||
});
|
||||
// Each drawn frame, whoever asked for it, arms one step a Cyber
|
||||
// sonar interval later, as the Cyber sonar scene does, whose changes
|
||||
|
||||
@@ -502,7 +502,7 @@ test('pulses ask for a frame 80 ms after each drawn frame instead of holding con
|
||||
assert.equal(pulseFrames(), frames, 'no frames once the ring is gone');
|
||||
});
|
||||
|
||||
test('a pulse frame draws the step made before it was asked for; only a moving camera steps every frame', (t) => {
|
||||
test('a pulse frame draws the step made before it was asked for; a moving camera steps nothing sooner', (t) => {
|
||||
const ring = ringRendering(t);
|
||||
const { rendering, state } = ring;
|
||||
const loop = frameLoop(t, ring);
|
||||
@@ -527,8 +527,8 @@ test('a pulse frame draws the step made before it was asked for; only a moving c
|
||||
assert.ok(pulses.length >= 9, `${pulses.length} pulse frames`);
|
||||
for (const [, stepMs, nowMs] of pulses) assert.equal(stepMs, nowMs);
|
||||
assert.equal(steps, pulses.length, 'one step a pulse frame');
|
||||
// Frames the camera moves in step each one: the fronts move, and the
|
||||
// soft band is painted again only a Cyber sonar interval on.
|
||||
// The fronts and band are fixed in the world: frames the camera moves
|
||||
// in within the interval step nothing, as a parked view's would not.
|
||||
steps = 0;
|
||||
const bandKey = drawn(ring).band.fill.image.key;
|
||||
for (let i = 0; i < 5; i++) {
|
||||
@@ -539,13 +539,14 @@ test('a pulse frame draws the step made before it was asked for; only a moving c
|
||||
);
|
||||
loop.draw();
|
||||
}
|
||||
assert.equal(steps, 5);
|
||||
assert.equal(drawn(ring).band.fill.image.key, bandKey);
|
||||
// A frame asked for by something else within the interval, the camera
|
||||
// parked, steps nothing.
|
||||
steps = 0;
|
||||
loop.draw();
|
||||
assert.equal(steps, 0);
|
||||
assert.equal(drawn(ring).band.fill.image.key, bandKey);
|
||||
// Crossing below the rim height hides them at once, interval or not.
|
||||
state.viewer.camera.positionCartographic = { height: 1_000 };
|
||||
loop.draw();
|
||||
assert.equal(steps, 1);
|
||||
assert.equal(drawn(ring).pulse(0).show, false);
|
||||
assert.equal(drawn(ring).band.show, false);
|
||||
});
|
||||
|
||||
test('a parked view stops asking for frames once the pulses rest', (t) => {
|
||||
|
||||
Reference in new issue
Block a user