mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
feat(time): the app clock on the engine
src/time/clock.js is the app's own time in ms since the epoch: by default
Date.now exactly (read at each call), with freeze/offset/rate/reset for QA
and tests, and one frame time latched per engine frame (beginFrame). The
contract gains engine.clock { now, frameTime, ticked }, in the fake engine
(a controllable wall clock, fake.advanceTime, fake.appClock), the contract
suite (one frame time for every listener of a frame, latched before
preUpdate, never decreasing), Cesium and Navara.
Cesium latches on the viewer clock's onTick, which CesiumWidget runs right
before scene.render, so scene listeners the app added before the engine
existed read the same frame time; the subscription appears on first use
and destroy removes it. The viewer clock itself is untouched: in the app
it never animates (shouldAnimate false, multiplier 1, its time frozen at
boot), and its time still drives Cesium's lighting as before. Navara
latches in the engine's handler of the view's preUpdate, and the look
reads the engine clock's frame time for the sun, so the app clock is the
one time source on Navara too.
src/time is a portable root in check-import-directions: no engine
packages, no browser globals.
This commit is contained in:
1 parent
27e28373d0
commit
f1a2df5cfe
20 files changed
+771
-13
No files matched your search
@@ -14,6 +14,7 @@ import {
|
||||
} from '../contract.js';
|
||||
import { cesiumFovy } from './cameraMath.js';
|
||||
import { createCameraModel } from './cameraModel.js';
|
||||
import { createNavaraClock } from './clock.js';
|
||||
import { createNavaraCredits } from './credits.js';
|
||||
import { createNavaraInput } from './input.js';
|
||||
import { createNavaraMaps } from './maps.js';
|
||||
@@ -68,16 +69,25 @@ function rayRaisedEllipsoid({ origin, direction }, height) {
|
||||
* container?: HTMLElement,
|
||||
* fetch?: typeof fetch,
|
||||
* clock?: object,
|
||||
* appClock?: import('../../time/clock.js').AppClock,
|
||||
* sharpen?: { set: (state: { enabled: boolean, amount: number }) => void, destroy: () => void },
|
||||
* }} options `hooks` are internals.js; `container` defaults to the
|
||||
* canvas's parent; `sharpen` draws render.setSharpen (sharpen.js; without
|
||||
* it the engine only keeps the state) and the engine destroys it; `fetch`
|
||||
* and `clock` are test seams.
|
||||
* it the engine only keeps the state) and the engine destroys it;
|
||||
* `appClock` (the engine clock's time) defaults to the page's app clock;
|
||||
* `fetch` and `clock` (the camera model's timers) are test seams.
|
||||
* @returns {import('../contract.js').GlobeEngine}
|
||||
*/
|
||||
export function createNavaraEngine(
|
||||
view,
|
||||
{ hooks, container, fetch, clock, sharpen: sharpenPort = null } = {},
|
||||
{
|
||||
hooks,
|
||||
container,
|
||||
fetch,
|
||||
clock,
|
||||
appClock,
|
||||
sharpen: sharpenPort = null,
|
||||
} = {},
|
||||
) {
|
||||
if (!view?.camera?.raw)
|
||||
throw new TypeError('createNavaraEngine needs a view');
|
||||
@@ -112,10 +122,14 @@ export function createNavaraEngine(
|
||||
preRender: createEngineEvent(),
|
||||
postRender: createEngineEvent(),
|
||||
};
|
||||
const engineClock = createNavaraClock(appClock ? { appClock } : {});
|
||||
// Defined below, with the surface and input it needs.
|
||||
let groundFloor = null;
|
||||
const handlers = {
|
||||
preUpdate: (time) => frames.preUpdate.raiseEvent(time),
|
||||
preUpdate: (time) => {
|
||||
engineClock.beginFrame();
|
||||
frames.preUpdate.raiseEvent(time);
|
||||
},
|
||||
preRender: (time) => {
|
||||
model.sync();
|
||||
groundFloor?.update();
|
||||
@@ -219,6 +233,7 @@ export function createNavaraEngine(
|
||||
input: input.input,
|
||||
credits: credits.credits,
|
||||
maps: maps.maps,
|
||||
clock: engineClock.clock,
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
|
||||
Reference in new issue
Block a user