-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeTickLoop.test.mjs
More file actions
43 lines (38 loc) · 1.48 KB
/
Copy pathRuntimeTickLoop.test.mjs
File metadata and controls
43 lines (38 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Toolbox Aid
David Quesenberry
06/02/2026
RuntimeTickLoop.test.mjs
*/
import assert from "node:assert/strict";
import {
RUNTIME_TICK_LOOP_ERRORS,
advanceRuntimeTick,
createRuntimeTickLoop,
} from "../../src/engine/runtime/runtimeTickLoop.js";
export function run() {
const startResult = createRuntimeTickLoop({ fixedDeltaMs: 100 });
assert.equal(startResult.valid, true);
assert.deepEqual(startResult.tick, { frame: 0, elapsedMs: 0, fixedDeltaMs: 100, deltaSeconds: 0.1 });
const nextResult = advanceRuntimeTick(startResult.tick);
assert.equal(nextResult.valid, true);
assert.deepEqual(nextResult.tick, { frame: 1, elapsedMs: 100, fixedDeltaMs: 100, deltaSeconds: 0.1 });
assert.equal(
nextResult.tick.deltaSeconds,
startResult.tick.deltaSeconds,
'Runtime tick advance should reuse the precomputed deltaSeconds value.'
);
const legacyTickResult = advanceRuntimeTick({ frame: 2, elapsedMs: 200, fixedDeltaMs: 100 });
assert.equal(legacyTickResult.valid, true);
assert.deepEqual(
legacyTickResult.tick,
{ frame: 3, elapsedMs: 300, fixedDeltaMs: 100, deltaSeconds: 0.1 },
'Runtime tick advance should preserve compatibility for ticks without deltaSeconds.'
);
const invalidResult = createRuntimeTickLoop({ fixedDeltaMs: 0 });
assert.equal(invalidResult.valid, false);
assert.deepEqual(invalidResult.errors.map((error) => error.code), [RUNTIME_TICK_LOOP_ERRORS.FIXED_DELTA_INVALID]);
}
if (import.meta.url === `file://${process.argv[1]}`) {
run();
}