Files
the-nexus/modules/core/ticker.js
Claude (Opus 4.6) 09c83e8734
Some checks failed
Deploy Nexus / deploy (push) Has been cancelled
Staging Smoke Test / smoke-test (push) Has been cancelled
[claude] Phase 1: Core Foundation — scene, ticker, theme, state (#410) (#463)
2026-03-24 22:16:49 +00:00

32 lines
862 B
JavaScript

// modules/core/ticker.js — Global Animation Clock
// Single requestAnimationFrame loop. No module may call RAF directly.
// All modules subscribe their update(elapsed, delta) function here.
import * as THREE from 'three';
const _clock = new THREE.Clock();
const _subs = [];
/** Register an update function: fn(elapsed, delta) */
export function subscribe(fn) {
if (!_subs.includes(fn)) _subs.push(fn);
}
/** Remove a previously registered update function */
export function unsubscribe(fn) {
const i = _subs.indexOf(fn);
if (i !== -1) _subs.splice(i, 1);
}
function _tick() {
requestAnimationFrame(_tick);
const delta = _clock.getDelta();
const elapsed = _clock.getElapsedTime();
for (const fn of _subs) fn(elapsed, delta);
}
/** Start the single RAF loop. Call once from app.js. */
export function start() {
_clock.start();
_tick();
}