Server actually ticks

This commit is contained in:
2026-09-25 13:25:25 -03:00
parent 2a2ccae9ce
commit dfabe40e7a
18 changed files with 763 additions and 79 deletions
+5 -2
View File
@@ -2,7 +2,7 @@
// runs the game in a worker without any permissions, the host does files and networking
import type { GameServer } from "./game_server.ts";
import { TICK_MS } from "./game_server.ts";
import { GameLoop } from "./game_loop.ts";
import { GameToHost, HostToGame } from "./host_protocol.ts";
import { data_url, start_game } from "./load_mods.ts";
@@ -68,7 +68,10 @@ async function init(message: Extract<HostToGame, { type: "init" }>) {
return;
}
setInterval(() => game!.tick(), TICK_MS);
const loop = new GameLoop(() => game!.tick());
game.loop = loop;
loop.start();
setInterval(() => {
if (game!.world.dirty) {
post({ type: "save", data: game!.save(), final: false });