LordXido commited on
Commit
d278682
·
verified ·
1 Parent(s): 2fa7c78

Update main.js

Browse files
Files changed (1) hide show
  1. main.js +17 -23
main.js CHANGED
@@ -11,48 +11,43 @@ function log(msg) {
11
  consoleEl.scrollTop = consoleEl.scrollHeight;
12
  }
13
 
14
- /* ---------- GLOBAL STATE ---------- */
15
- let gpu = null;
16
- let world = null;
17
- let agents = null;
18
  let running = false;
19
 
20
- /* ---------- COMMAND BRIDGE ---------- */
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
- /* ---------- BOOT ---------- */
32
  async function boot() {
33
  log("Booting runtime...");
34
 
35
- try {
36
- gpu = await initGPU(canvas);
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
- running = true;
 
 
 
 
 
 
 
 
47
  log("World initialized");
48
  log("Type 'help' or natural language");
49
-
50
  requestAnimationFrame(loop);
51
  }
52
 
53
- /* ---------- LOOP ---------- */
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();