SOURCE / PINNED RELEASE
Made of little things.
Impact Yard
- Release
- 09fe6aebec3c…
- Author-recorded commit
- 0696a4211733…
- License
- LICENSE
- Author’s source reference
- nostr://npub1n8ga89w8h6tvwamxusfyzexw8gjy84yxu9rxgnmk955cxtml4ujswzxydd/wss%3A%2F%2Fgit.napplet.soy%2F/n-0b3d7b60562
Archive hash verified: 823f5de0d2677ef2…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import assert from 'node:assert/strict';
import test from 'node:test';
import { createSimulation, FIXED_STEP } from '../src/simulation.ts';
const idle = { throttle: 0, steer: 0, brake: false };
function advance(sim, seconds, controls = idle) { for (let i = 0; i < Math.round(seconds / FIXED_STEP); i++) sim.step(FIXED_STEP, controls); }
test('the car climbs the ramp from a standing start at light and full throttle', () => {
for (const throttle of [0.2, 1]) {
const sim = createSimulation();
sim.chassis.position.set(18, 1.1, 5); sim.chassis.aabbNeedsUpdate = true;
advance(sim, 2);
let highest = 0, farthest = 5;
for (let i = 0; i < 12 / FIXED_STEP; i++) {
sim.step(FIXED_STEP, { ...idle, throttle });
highest = Math.max(highest, sim.chassis.position.y);
farthest = Math.min(farthest, sim.chassis.position.z);
}
assert.ok(highest > 3 && farthest < -11, `throttle ${throttle}: ramp climb stalled at z=${farthest.toFixed(2)}, height=${highest.toFixed(2)}`);
}
});
test('all 157 pieces remain stable at rest and suspension supports the chassis', () => {
const sim = createSimulation(); advance(sim, 8);
assert.equal(sim.props.length, 157); assert.equal(sim.stats().displaced, 0);
assert.ok(sim.chassis.position.y > 0.5 && sim.chassis.position.y < 0.8);
assert.ok(sim.stats().speed < 0.1);
});
test('accelerating into crates transfers momentum and leaves remote structures standing', () => {
const sim = createSimulation(); advance(sim, 3); advance(sim, 6, { ...idle, throttle: 1 });
assert.ok(sim.chassis.position.z < -5, 'accelerator moves the car toward the obstacles');
assert.ok(sim.stats().groups[0] >= 15, 'impact displaces most of the main crate stack');
assert.ok(sim.stats().groups.slice(1).every(count => count === 0));
assert.ok(sim.stats().peakImpact > 30);
for (const prop of sim.props) assert.ok(prop.body.position.y > -0.1 && Number.isFinite(prop.body.velocity.length()));
sim.rebuild(); advance(sim, 3);
assert.equal(sim.stats().displaced, 0); assert.equal(sim.stats().peakImpact, 0);
assert.ok(Math.abs(sim.chassis.position.z - 17) < 0.1);
});
test('left and right steering turn in the expected directions; brakes stop the vehicle', () => {
for (const steer of [-1, 1]) {
const sim = createSimulation(); advance(sim, 2); advance(sim, 1.5, { ...idle, throttle: 1, steer });
assert.ok(sim.chassis.position.x * steer < -3);
const movingSpeed = sim.stats().speed;
advance(sim, 2, { ...idle, brake: true });
assert.ok(sim.stats().speed < movingSpeed * 0.1);
}
});
test('reverse and recovery work without rebuilding the structures', () => {
const sim = createSimulation(); advance(sim, 2); advance(sim, 1, { ...idle, throttle: -1 });
assert.ok(sim.chassis.position.z > 20);
sim.props[0].body.position.x += 3;
sim.recover(); advance(sim, 1);
assert.ok(Math.abs(sim.chassis.position.z - 17) < 0.1);
assert.ok(sim.stats().displaced >= 1);
});
test('striking the new timber tower and arch brings down their supported pieces', () => {
for (const [x, z, group, minimum] of [[26, 25, 5, 18], [-10.8, -19, 6, 7]]) {
const sim = createSimulation();
sim.chassis.position.set(x, 1.1, z); sim.chassis.aabbNeedsUpdate = true;
advance(sim, 2); advance(sim, 3, { ...idle, throttle: 1 }); advance(sim, 8, { ...idle, brake: true });
assert.ok(sim.stats().groups[group] >= minimum, `group ${group} should collapse after impact`);
sim.rebuild(); advance(sim, 3);
assert.equal(sim.stats().displaced, 0, 'rebuild restores the new structures');
}
});
test('a domino collision continues to propagate after the driver brakes', () => {
const sim = createSimulation();
sim.chassis.position.set(-30, 1.1, 27); sim.chassis.aabbNeedsUpdate = true;
advance(sim, 2); advance(sim, 1.2, { ...idle, throttle: 1 });
const initially = sim.stats().groups[4];
advance(sim, 20, { ...idle, brake: true });
assert.ok(sim.stats().groups[4] >= initially + 4, 'falling panels should knock on into their neighbors');
assert.ok(sim.chassis.position.z > 16, 'the car stops near the beginning of the run');
});