Save all generated chunks instead of only chunks that were changed

This commit is contained in:
2026-10-11 02:02:01 -03:00
parent 44a39bf8ec
commit 5a59a63862
17 changed files with 644 additions and 314 deletions
+12 -2
View File
@@ -3,10 +3,18 @@ import type { WorldSave } from "./saves.ts";
// messages between server/main.ts (the host) and the game server worker
// read_chunk's buffer: an i32 the game waits on while it's READ_WAITING, then an i32 the chunk's length, then the
// chunk. a length of -1 is no chunk. READ_TOO_SMALL says the buffer is too small and the length is how big the chunk is
export const READ_WAITING = 0;
export const READ_DONE = 1;
export const READ_TOO_SMALL = 2;
export const READ_HEADER = 8;
export type HostToGame =
| {
type: "init";
save: WorldSave;
// level.json, and where the saved chunks are. the game reads them with read_chunk when it needs them
save: { level?: string; chunks: [number, number][] };
default_seed: string;
// in load order, with the scripts' code since the worker can't read files
mods: {
@@ -36,7 +44,9 @@ export type GameToHost =
// text is a json message, bytes a binary one
| { type: "send"; conn: number; data: string | Uint8Array<ArrayBuffer> }
| { type: "close"; conn: number }
// level.json and the chunks that changed
// level.json and the chunks generated or changed since the last save
| { type: "save"; save: Required<WorldSave>; final: boolean }
// the game waits on buffer for a saved chunk, see READ_WAITING
| { type: "read_chunk"; x: number; z: number; buffer: SharedArrayBuffer }
// the worker can't use the network, so the host fetches urls for it, like skins
| { type: "download"; id: number; url: string; max_bytes: number };