SOURCE / PINNED RELEASE
Made of little things.
Impact Yard remix
- Release
- 5b31a37bbd07…
- Author-recorded commit
- 7762f7efb018…
- License
- LICENSE
- Author’s source reference
- nostr://npub1n8ga89w8h6tvwamxusfyzexw8gjy84yxu9rxgnmk955cxtml4ujswzxydd/wss%3A%2F%2Fgit.napplet.soy%2F/n-c1d8c061b02
Archive hash verified: c640627baa321925…. 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 { ARENA, BOOST, createSimulation, FIXED_STEP, GROUPS, SITE_APPROACHES } 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 590 pieces remain stable at rest and suspension supports the chassis', () => {
const sim = createSimulation(); advance(sim, 12);
assert.equal(sim.props.length, 590); 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('all additions fit inside the 360 metre arena and the new complexes exceed 28 metres', () => {
const sim = createSimulation();
assert.equal(ARENA.halfSize * 2, 360);
assert.equal(GROUPS.length, 17);
for (let group = 7; group < GROUPS.length; group++) {
const pieces = sim.props.filter(prop => prop.group === group);
assert.ok(Math.max(...pieces.map(prop => prop.start.y + prop.size[1] / 2)) >= (group >= 12 ? 28 : 10));
for (const prop of pieces) {
assert.ok(Math.abs(prop.start.x) + prop.size[0] / 2 < ARENA.halfSize - 5);
assert.ok(Math.abs(prop.start.z) + prop.size[2] / 2 < ARENA.halfSize - 5);
}
}
});
test('complexes keep collapsing after the rocket stops and emit bounded impact effects', () => {
for (let group = 12; group < GROUPS.length; group++) {
const sim = createSimulation(); sim.visit(group); advance(sim, 3);
assert.equal(sim.stats().displaced, 0, `${GROUPS[group].name} must stand before impact`);
const highPieces = sim.props.filter(p => p.group === group && p.start.y > 15);
const fallen = () => highPieces.filter(p => p.body.position.y < p.start.y - 8).length;
sim.drainImpacts(); sim.boost(); advance(sim, 1.4);
const initiallyFallen = fallen();
assert.equal(sim.rocketState().active, false);
const initialEffects = sim.drainImpacts();
assert.ok(initialEffects.length > 0 && initialEffects.length <= 64);
advance(sim, 20, { ...idle, brake: true });
assert.ok(fallen() >= initiallyFallen + 8, `${GROUPS[group].name}: upper pieces must continue falling after thrust ends (${initiallyFallen} → ${fallen()})`);
assert.ok(fallen() >= highPieces.length * 0.4, `${GROUPS[group].name}: substantial upper structure must fall`);
const effects = sim.drainImpacts(); assert.ok(effects.length > 0 && effects.length <= 64);
assert.deepEqual(sim.drainImpacts(), [], 'effects are consumed once');
for (const prop of sim.props) assert.ok(Number.isFinite(prop.body.velocity.length()) && prop.body.position.y > -2);
assert.ok(Math.abs(sim.chassis.position.x) < ARENA.halfSize && Math.abs(sim.chassis.position.z) < ARENA.halfSize);
}
});
test('site visits, recovery and rebuild preserve their intended checkpoints and rotated geometry', () => {
const sim = createSimulation();
for (let site = 0; site < GROUPS.length; site++) {
sim.visit(site); advance(sim, 1);
const [x, z] = SITE_APPROACHES[site];
assert.ok(Math.abs(sim.chassis.position.x - x) < 0.1 && Math.abs(sim.chassis.position.z - z) < 0.1, `clear approach for ${GROUPS[site].name}`);
assert.ok(sim.chassis.position.y > 0.5 && sim.chassis.position.y < 0.8);
}
sim.boost(); advance(sim, 0.3); sim.recover();
assert.equal(sim.chassis.position.x, SITE_APPROACHES[16][0]);
sim.props.find(p => p.group === 15).body.quaternion.setFromEuler(1, 2, 3);
sim.rebuild();
for (const prop of sim.props) assert.deepEqual(prop.body.quaternion, prop.startRotation);
assert.deepEqual(sim.drainImpacts(), []);
assert.equal(sim.chassis.position.z, 17);
advance(sim, 8); assert.equal(sim.stats().displaced, 0);
});
test('rocket kicks immediately, sustains thrust without throttle and recharges once', () => {
const sim = createSimulation();
sim.chassis.position.set(40, 1.1, 65); sim.chassis.aabbNeedsUpdate = true;
advance(sim, 2);
const start = sim.chassis.position.clone();
assert.equal(sim.boost(), true);
assert.ok(sim.stats().speed > 95, 'F gives an immediate violent impulse');
assert.ok(sim.chassis.position.distanceTo(start) < 0.01, 'boost changes velocity, not position');
assert.equal(sim.boost(), false, 'cannot stack bursts during recharge');
advance(sim, 1.1);
assert.ok(sim.stats().speed > 180, `sustained rocket speed ${sim.stats().speed}`);
assert.ok(sim.chassis.position.z < 20);
assert.equal(sim.rocketState().active, true);
advance(sim, 0.15);
assert.equal(sim.rocketState().active, false);
assert.equal(sim.boost(), false);
advance(sim, BOOST.recharge, { ...idle, brake: true });
assert.equal(sim.rocketState().cooldown, 0);
assert.equal(sim.boost(), true);
sim.cancelBoost(); assert.equal(sim.rocketState().active, false);
sim.recover(); assert.equal(sim.rocketState().cooldown, 0);
sim.boost(); advance(sim, FIXED_STEP, { ...idle, brake: true });
assert.equal(sim.rocketState().active, false, 'brake cuts the engine');
sim.rebuild(); assert.deepEqual(sim.rocketState(), { active: false, cooldown: 0, charge: 1 });
});
test('airborne rocket follows the car heading and does not need tire contact', () => {
const sim = createSimulation();
sim.chassis.position.set(40, 35, 65);
sim.chassis.quaternion.setFromEuler(0, Math.PI / 2, 0); sim.chassis.aabbNeedsUpdate = true;
sim.boost(); advance(sim, 0.5);
assert.ok(sim.chassis.velocity.x < -40);
assert.ok(Math.abs(sim.chassis.velocity.z) < 0.5);
assert.ok(sim.chassis.position.y > 30);
});
test('rocket impacts break each mega structure without tunnelling through the yard', () => {
for (const [x, z, group, minimum] of [[0, -38, 7, 8], [51, -30, 8, 10], [54, 45, 9, 20], [-57, 36, 10, 6], [-21.8, 75, 11, 7]]) {
const sim = createSimulation();
sim.chassis.position.set(x, 1.1, z); sim.chassis.aabbNeedsUpdate = true;
advance(sim, 2); sim.boost(); advance(sim, 2);
advance(sim, 18, { ...idle, brake: true });
assert.ok(sim.stats().groups[group] >= minimum, `${GROUPS[group].name}: only ${sim.stats().groups[group]} pieces displaced`);
assert.ok(Math.abs(sim.chassis.position.x) < ARENA.halfSize && Math.abs(sim.chassis.position.z) < ARENA.halfSize);
for (const prop of sim.props) assert.ok(Number.isFinite(prop.body.velocity.length()) && prop.body.position.y > -2);
}
});
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');
});