From ed6f5fe0df213447cafed9cc1ac1a6bfab5e2a10 Mon Sep 17 00:00:00 2001 From: Paula Date: Sun, 22 Nov 2026 18:47:49 -0300 Subject: [PATCH] Deno compile --- deno.json | 3 ++- desktop/main.ts | 24 +++++++++++++++++++++--- docs/modding_plan.md | 7 +++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/deno.json b/deno.json index ad4e4d8..c2c37a2 100644 --- a/deno.json +++ b/deno.json @@ -9,7 +9,8 @@ "pack-mod": "deno run --allow-read --allow-write --allow-run --allow-env tools/pack_mod.ts", "test": "deno test --allow-read --allow-write --allow-run --allow-net tests/", "bench": "deno bench --allow-read --allow-write --allow-run tests/", - "desktop": "deno run --unstable-webgpu --allow-read --allow-write --allow-net --allow-ffi --allow-env=CUBI_SERVER,CUBI_CLIENT_UPDATES,HOME,USERPROFILE,APPDATA,XDG_DATA_HOME desktop/main.ts" + "desktop": "deno run --unstable-webgpu --allow-read --allow-write --allow-net --allow-ffi --allow-env=CUBI_SERVER,CUBI_CLIENT_UPDATES,HOME,USERPROFILE,APPDATA,XDG_DATA_HOME desktop/main.ts", + "compile": "deno run -A build.ts --once && deno compile --unstable-webgpu --allow-read --allow-write --allow-net --allow-ffi --allow-env=CUBI_SERVER,CUBI_CLIENT_UPDATES,HOME,USERPROFILE,APPDATA,XDG_DATA_HOME --include build --include server_mods --include server/game/worker.ts --include server/game/worldgen_worker.ts --include server/content_worker.ts --include desktop/config.json --output dist/cubi desktop/main.ts" }, "compilerOptions": { "lib": ["dom", "dom.asynciterable", "dom.iterable", "deno.ns", "deno.unstable", "deno.webgpu"] diff --git a/desktop/main.ts b/desktop/main.ts index 89c78ad..3a584ca 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -26,11 +26,28 @@ try { console.error(`No sound: ${(e as Error).message}`); } -const app = desktop_app((message) => { +// the app can't go on. it says why in a message box, a packaged app has no terminal to read it in +function fail(message: string) { console.error(message); - game_window.show_error("bworld", `The singleplayer world stopped: ${message}`); + game_window.set_grabbed(false); + game_window.show_error("bworld", message); + audio?.close(); + game_window.close(); Deno.exit(1); +} + +// an error nothing caught, even a throw while starting, ends the app through fail. ending deno with it instead unloads +// openal while its thread still plays, which crashes before the error is printed +addEventListener("error", (event) => { + event.preventDefault(); + fail(String(event.error?.stack ?? event.message)); }); +addEventListener("unhandledrejection", (event) => { + event.preventDefault(); + fail(String(event.reason?.stack ?? event.reason)); +}); + +const app = desktop_app((message) => fail(`The singleplayer world stopped: ${message}`)); const server = Deno.serve( { hostname: "127.0.0.1", port: 0, onListen() {} }, @@ -65,7 +82,8 @@ async function start_client(page: URL) { }); worker.onmessage = (event: MessageEvent) => handle(event.data); worker.onerror = (event) => { - console.error(`The client stopped: ${event.message}`); + event.preventDefault(); + fail(`The client stopped: ${event.message}`); }; client = worker; send({ diff --git a/docs/modding_plan.md b/docs/modding_plan.md index 53c0db2..7da04b4 100644 --- a/docs/modding_plan.md +++ b/docs/modding_plan.md @@ -431,7 +431,6 @@ saved before any of this plays exactly the same. - **Importing Minecraft's terrain.** Datapacks' noise settings assume a world from -64 to 320 and Minecraft's noises. The formats are close enough that an importer could translate them, but the result wouldn't look like Minecraft's. Not a goal for now. -- **Generation's loose ends.** The desktop app isn't packaged yet, and a package will need the worldgen worker in it. In - a world without land, the spawn search looks 32 chunks out on the game thread, which the server now does at startup. - Saved chunks are read on the game thread, which waits for the host (see `read_chunk` in `server/game/worker.ts`): much - faster than generating them, but Minecraft reads them ahead instead. +- **Generation's loose ends.** In a world without land, the spawn search looks 32 chunks out on the game thread, which + the server now does at startup. Saved chunks are read on the game thread, which waits for the host (see `read_chunk` + in `server/game/worker.ts`): much faster than generating them, but Minecraft reads them ahead instead.