Files
Emil c7e86663d8
MVP checks / mvp (push) Canceled after 0s
Expand voxel gameplay, lighting, full-height streaming and world imports
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.
2026-09-17 02:10:53 +03:00

28 lines
1.2 KiB
JavaScript

import { TerrainState } from "./terrain-state.js";
import { loadLightProperties } from "./light-properties.js";
const state = loadLightProperties().then(properties => new TerrainState(properties));
let timer = null;
const send = message => {
const buffers = message.type === "light"
? [message.field.data.buffer, message.field.blockLevels.buffer, message.field.skyLevels.buffer]
: message.vertices ? [message.vertices.buffer, message.transparent.buffer] : [];
self.postMessage(message, buffers);
};
self.onmessage = ({ data }) => {
state.then(terrain => {
if (data.type === "sync") {
if (!terrain.sync(data)) return;
clearTimeout(timer);
timer = setTimeout(() => {
timer = null;
try { send(terrain.light({dirty:!data.independentMeshes})); }
catch (error) { send({ type: "error", epoch: terrain.epoch, version: terrain.version, error: error.message }); }
}, data.independentMeshes ? 225 : 0);
} else if (data.type === "mesh") {
try { send(terrain.mesh(data)); }
catch (error) { send({ ...data, error: error.message }); }
}
}).catch(error => send({ type: "error", epoch: data.epoch, version: data.version, error: error.message }));
};