This commit is contained in:
Andras Schmelczer 2026-08-22 18:35:53 +01:00
commit 5017ff168a

View file

@ -1,9 +1,4 @@
// Determinism guard for the shared character simulation. The client predictor
// and the authoritative server run the EXACT same stepCharacterMovement; if it
// were non-deterministic (a stray Math.random / Date, or an order-dependent
// reduce) prediction would rubber-band and could never reconcile. This is also
// the regression net for the upcoming GC/scratch-pool perf rewrites: the pinned
// hash must not change unless physics behaviour is intentionally changed.
// Determinism guard: client predictor and server run the same stepCharacterMovement.
import { describe, it, expect } from 'vitest';
import { createRequire } from 'node:module';
@ -34,9 +29,7 @@ const makeBody = (center, radius) => ({
restitution: 0,
});
// A free-space world (no planets): the body is driven purely by the movement
// input force, posture springs and momentum decay — enough to exercise the
// deterministic core without coupling the test to planet SDF geometry.
// Free-space world (no planets): exercises the deterministic core without planet SDF geometry.
const emptyWorld = {
groundsNear: () => [],
stepBody: (body, dt) => {
@ -47,11 +40,7 @@ const emptyWorld = {
const stepSeconds = 1 / 200;
// A spinning planet, built exactly the way create-world builds one, wired up as
// the GroundSurface the shared movement collides against and is pulled by. The
// free-space run above deliberately avoids planet geometry, so without this the
// SDF, the gravity falloff and the on-surface branch — the parts most likely to
// be touched by a perf rewrite — have no pin at all.
// A spinning planet, built the way create-world builds one, so the SDF/gravity/on-surface branches have a pin too.
const makeSpinningPlanetWorld = () => {
Random.seed = 20;
const vertices = PlanetBase.createPlanetVertices(
@ -85,8 +74,6 @@ const makeSpinningPlanetWorld = () => {
};
};
// Walk a body across a spinning planet: gravity, the SDF outline, collision
// resolution, surface latching and the rotation carry all participate.
const runPlanetSimulation = () => {
const { surface, world } = makeSpinningPlanetWorld();
const start = vec2.fromValues(0, 250);
@ -120,8 +107,6 @@ const runPlanetSimulation = () => {
});
};
// Run a fixed, scripted input sequence through the shared sim and return a
// stable string snapshot of the final pose + carried momentum.
const runSimulation = () => {
const start = vec2.fromValues(100, 100);
const state = {
@ -164,8 +149,6 @@ describe('shared character simulation determinism', () => {
});
it('matches the pinned reference pose on a spinning planet', () => {
// Covers the planet SDF, the gravity falloff, collision resolution and the
// rotation carry, none of which the free-space run above touches.
expect(runPlanetSimulation()).toMatchSnapshot();
});
});