MVP checks / mvp (push) Waiting to run
Add shared Rust/WASM physics, worker meshing and diagnostics, 64-chunk full-height streaming, atlas texture support, and baseline world import. Document the current implementation and include the supplied in-game lobby screenshot.
78 lines
2.8 KiB
JavaScript
78 lines
2.8 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
direction,
|
|
raycast,
|
|
rayBox,
|
|
multiply,
|
|
perspective,
|
|
viewMatrix,
|
|
project,
|
|
unitBox,
|
|
isFullCube,
|
|
} from "../math.js";
|
|
test("translucent cubes do not hide opaque surfaces behind glass", () => {
|
|
assert.equal(isFullCube({ render: [unitBox], opacity: 0.3 }), false);
|
|
assert.equal(isFullCube({ render: [unitBox], opacity: 1 }), true);
|
|
});
|
|
test("camera axes and world projection match the server coordinate convention", () => {
|
|
assert.deepEqual(direction(0, 0), [0, 0, -1]);
|
|
const east = direction(Math.PI / 2, 0);
|
|
assert.ok(Math.abs(east[0] - 1) < 1e-8);
|
|
const vp = multiply(
|
|
perspective(Math.PI / 2, 1, 0.1, 100),
|
|
viewMatrix([0, 2, 8], 0, 0),
|
|
);
|
|
const center = project([0, 2, 0], vp, 100, 100);
|
|
assert.ok(Math.abs(center[0] - 50) < 1e-5 && Math.abs(center[1] - 50) < 1e-5);
|
|
assert.equal(project([0, 2, 20], vp, 100, 100), null);
|
|
});
|
|
test("DDA resolves negative world coordinates and nearest entry face", () => {
|
|
const blocks = new Map([
|
|
["-1,0,-2", 1],
|
|
["-1,0,-4", 1],
|
|
]),
|
|
materials = new Map([[1, { render: [unitBox] }]]);
|
|
const hit = raycast([-0.5, 0.5, 0], [0, 0, -1], blocks, materials);
|
|
assert.deepEqual(hit.pos, [-1, 0, -2]);
|
|
assert.deepEqual(hit.normal, [0, 0, 1]);
|
|
assert.equal(hit.distance, 1);
|
|
});
|
|
test("ray selection respects slab geometry and reach instead of selecting empty half", () => {
|
|
const blocks = new Map([["0,0,-2", 1]]),
|
|
materials = new Map([
|
|
[1, { render: [{ min: [0, 0, 0], max: [1, 0.5, 1] }] }],
|
|
]);
|
|
assert.equal(raycast([0.5, 0.75, 0], [0, 0, -1], blocks, materials), null);
|
|
assert.ok(raycast([0.5, 0.25, 0], [0, 0, -1], blocks, materials));
|
|
assert.equal(
|
|
raycast([0.5, 0.25, 10], [0, 0, -1], blocks, materials, 6),
|
|
null,
|
|
);
|
|
});
|
|
test("axis aligned ray slabs reject parallel paths outside a box", () => {
|
|
assert.equal(rayBox([2, 0.5, 3], [0, 0, -1], [0, 0, 0], [1, 1, 1], 6), null);
|
|
assert.equal(
|
|
rayBox([0.5, 0.5, 3], [0, 0, -1], [0, 0, 0], [1, 1, 1], 6).distance,
|
|
2,
|
|
);
|
|
});
|
|
|
|
test("selection intersects a fence extension owned by the cell below", () => {
|
|
const blocks = new Map([["0,0,-2", 1]]),
|
|
materials = new Map([
|
|
[1, { render: [{ min: [0.375, 0, 0.375], max: [0.625, 1.5, 0.625] }] }],
|
|
]);
|
|
const hit = raycast([0.5, 1.25, 0], [0, 0, -1], blocks, materials);
|
|
assert.deepEqual(hit.pos, [0, 0, -2]);
|
|
assert.deepEqual(hit.normal, [0, 0, 1]);
|
|
assert.equal(hit.distance, 1.375);
|
|
});
|
|
test("package geometry is selectable across its documented three-block extent", () => {
|
|
const blocks = new Map([["0,0,0", 1]]);
|
|
const materials = new Map([[1, { render: [{min:[0,0,0],max:[1,3,1]}] }]]);
|
|
const hit = raycast([0.5,2.5,4], [0,0,-1], blocks, materials, 6);
|
|
assert.deepEqual(hit.pos,[0,0,0]);
|
|
assert.deepEqual(hit.normal,[0,0,1]);
|
|
});
|