Spaces:
Running
Running
Update main.js
Browse files
main.js
CHANGED
|
@@ -11,48 +11,43 @@ function log(msg) {
|
|
| 11 |
consoleEl.scrollTop = consoleEl.scrollHeight;
|
| 12 |
}
|
| 13 |
|
| 14 |
-
|
| 15 |
-
let gpu = null;
|
| 16 |
-
let world = null;
|
| 17 |
-
let agents = null;
|
| 18 |
let running = false;
|
| 19 |
|
| 20 |
-
/*
|
| 21 |
window.codexCommand = (input) => {
|
| 22 |
log("> " + input);
|
| 23 |
-
if (!parseCommand) return;
|
| 24 |
-
|
| 25 |
const cmd = parseCommand(input);
|
| 26 |
-
if (cmd && world)
|
| 27 |
-
world.apply(cmd);
|
| 28 |
-
}
|
| 29 |
};
|
| 30 |
|
| 31 |
-
/*
|
| 32 |
async function boot() {
|
| 33 |
log("Booting runtime...");
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
log("Compute mode: " + gpu.mode.toUpperCase());
|
| 38 |
-
} catch (e) {
|
| 39 |
-
log("GPU init failed — forcing CPU mode");
|
| 40 |
-
gpu = { mode: "cpu" };
|
| 41 |
-
}
|
| 42 |
|
| 43 |
world = new World(canvas, gpu);
|
| 44 |
agents = new Agents(world);
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
log("World initialized");
|
| 48 |
log("Type 'help' or natural language");
|
| 49 |
-
|
| 50 |
requestAnimationFrame(loop);
|
| 51 |
}
|
| 52 |
|
| 53 |
-
/*
|
| 54 |
let last = performance.now();
|
| 55 |
-
|
| 56 |
function loop(t) {
|
| 57 |
if (!running) return;
|
| 58 |
|
|
@@ -66,5 +61,4 @@ function loop(t) {
|
|
| 66 |
requestAnimationFrame(loop);
|
| 67 |
}
|
| 68 |
|
| 69 |
-
/* ---------- START ---------- */
|
| 70 |
boot();
|
|
|
|
| 11 |
consoleEl.scrollTop = consoleEl.scrollHeight;
|
| 12 |
}
|
| 13 |
|
| 14 |
+
let world, agents;
|
|
|
|
|
|
|
|
|
|
| 15 |
let running = false;
|
| 16 |
|
| 17 |
+
/* Command bridge */
|
| 18 |
window.codexCommand = (input) => {
|
| 19 |
log("> " + input);
|
|
|
|
|
|
|
| 20 |
const cmd = parseCommand(input);
|
| 21 |
+
if (cmd && world) world.apply(cmd);
|
|
|
|
|
|
|
| 22 |
};
|
| 23 |
|
| 24 |
+
/* Boot */
|
| 25 |
async function boot() {
|
| 26 |
log("Booting runtime...");
|
| 27 |
|
| 28 |
+
const gpu = await initGPU(canvas);
|
| 29 |
+
log("Compute mode: " + gpu.mode.toUpperCase());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
world = new World(canvas, gpu);
|
| 32 |
agents = new Agents(world);
|
| 33 |
|
| 34 |
+
waitForWorld();
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
function waitForWorld() {
|
| 38 |
+
if (!world.ready) {
|
| 39 |
+
requestAnimationFrame(waitForWorld);
|
| 40 |
+
return;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
log("World initialized");
|
| 44 |
log("Type 'help' or natural language");
|
| 45 |
+
running = true;
|
| 46 |
requestAnimationFrame(loop);
|
| 47 |
}
|
| 48 |
|
| 49 |
+
/* Loop */
|
| 50 |
let last = performance.now();
|
|
|
|
| 51 |
function loop(t) {
|
| 52 |
if (!running) return;
|
| 53 |
|
|
|
|
| 61 |
requestAnimationFrame(loop);
|
| 62 |
}
|
| 63 |
|
|
|
|
| 64 |
boot();
|