Spaces:
Running
Running
Update main.js
Browse files
main.js
CHANGED
|
@@ -1,133 +1,57 @@
|
|
| 1 |
-
//
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
import { spawnAgent, updateAgents } from "./agents.js";
|
| 7 |
-
import { loadURL } from "./web.js";
|
| 8 |
-
import { llmIntent } from "./llm.js";
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
function resize() {
|
| 15 |
-
canvas.width = canvas.clientWidth;
|
| 16 |
-
canvas.height = canvas.clientHeight;
|
| 17 |
}
|
| 18 |
-
window.addEventListener("resize", resize);
|
| 19 |
-
resize();
|
| 20 |
-
|
| 21 |
-
// ---- Console ----
|
| 22 |
-
const log = document.getElementById("log");
|
| 23 |
-
const input = document.getElementById("input");
|
| 24 |
-
|
| 25 |
-
function print(msg) {
|
| 26 |
-
log.innerHTML += msg + "<br/>";
|
| 27 |
-
log.scrollTop = log.scrollHeight;
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
// ---- Core Parameters (STABLE) ----
|
| 31 |
-
let Psi = 0.03; // Intent injection (low, stable)
|
| 32 |
-
let sigma = 0.15; // Diffusion strength
|
| 33 |
-
let running = true;
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
print("CodexReality3D v9-HA ONLINE");
|
| 38 |
-
print("World initialized (stable)");
|
| 39 |
-
print("Type `help` or natural language");
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
return { type: "pause" };
|
| 59 |
-
|
| 60 |
-
if (t.includes("resume"))
|
| 61 |
-
return { type: "resume" };
|
| 62 |
-
|
| 63 |
-
if (t === "help")
|
| 64 |
-
return { type: "help" };
|
| 65 |
-
|
| 66 |
-
return { type: "llm", text };
|
| 67 |
-
}
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
print("Opening web → " + intent.url);
|
| 74 |
-
loadURL(intent.url);
|
| 75 |
-
break;
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
print("Agent spawned");
|
| 80 |
-
break;
|
| 81 |
|
| 82 |
-
|
| 83 |
-
Psi = intent.value;
|
| 84 |
-
print("Ψ = " + Psi.toFixed(3));
|
| 85 |
-
break;
|
| 86 |
-
|
| 87 |
-
case "pause":
|
| 88 |
-
running = false;
|
| 89 |
-
print("Simulation paused");
|
| 90 |
-
break;
|
| 91 |
-
|
| 92 |
-
case "resume":
|
| 93 |
-
running = true;
|
| 94 |
-
print("Simulation resumed");
|
| 95 |
-
break;
|
| 96 |
-
|
| 97 |
-
case "help":
|
| 98 |
-
print("Commands:");
|
| 99 |
-
print(" open <url>");
|
| 100 |
-
print(" spawn agent");
|
| 101 |
-
print(" brighter / dimmer");
|
| 102 |
-
print(" pause / resume");
|
| 103 |
-
break;
|
| 104 |
-
|
| 105 |
-
case "llm":
|
| 106 |
-
const cmd = await llmIntent(intent.text);
|
| 107 |
-
route(cmd);
|
| 108 |
-
break;
|
| 109 |
}
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
// ---- Input ----
|
| 113 |
-
input.addEventListener("keydown", e => {
|
| 114 |
-
if (e.key === "Enter") {
|
| 115 |
-
const text = input.value.trim();
|
| 116 |
-
if (!text) return;
|
| 117 |
-
print("> " + text);
|
| 118 |
-
route(parseIntent(text));
|
| 119 |
-
input.value = "";
|
| 120 |
-
}
|
| 121 |
-
});
|
| 122 |
|
| 123 |
-
|
| 124 |
-
function loop() {
|
| 125 |
-
if (running) {
|
| 126 |
-
updateWorld(Psi, sigma);
|
| 127 |
-
updateAgents();
|
| 128 |
-
}
|
| 129 |
-
renderWorld(ctx, canvas);
|
| 130 |
-
requestAnimationFrame(loop);
|
| 131 |
}
|
| 132 |
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// main.js — Codex Capsule v9.2
|
| 2 |
+
import { initGPU } from "./gpu.js";
|
| 3 |
+
import { World } from "./world.js";
|
| 4 |
+
import { Agents } from "./agents.js";
|
| 5 |
+
import { LLM } from "./llm.js";
|
| 6 |
|
| 7 |
+
const consoleEl = document.getElementById("console");
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
function log(msg) {
|
| 10 |
+
consoleEl.textContent += msg + "\n";
|
| 11 |
+
consoleEl.scrollTop = consoleEl.scrollHeight;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
log("CodexReality3D v9.2");
|
| 15 |
+
log("Initializing...");
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
const state = {
|
| 18 |
+
gpu: null,
|
| 19 |
+
world: null,
|
| 20 |
+
agents: null,
|
| 21 |
+
llm: null,
|
| 22 |
+
};
|
| 23 |
|
| 24 |
+
(async function boot() {
|
| 25 |
+
state.gpu = await initGPU();
|
| 26 |
|
| 27 |
+
state.world = new World(state.gpu);
|
| 28 |
+
state.agents = new Agents();
|
| 29 |
+
state.llm = new LLM();
|
| 30 |
|
| 31 |
+
log(`Runtime mode: ${state.gpu.mode.toUpperCase()}`);
|
| 32 |
+
log("World initialized");
|
| 33 |
+
log("Type 'help' or natural language");
|
| 34 |
|
| 35 |
+
startLoop();
|
| 36 |
+
})();
|
| 37 |
|
| 38 |
+
let last = performance.now();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
function startLoop() {
|
| 41 |
+
function tick(now) {
|
| 42 |
+
const dt = Math.min((now - last) / 1000, 0.033);
|
| 43 |
+
last = now;
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
state.world.update(dt);
|
| 46 |
+
state.agents.update(dt);
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
requestAnimationFrame(tick);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
requestAnimationFrame(tick);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
}
|
| 53 |
|
| 54 |
+
window.codexCommand = (input) => {
|
| 55 |
+
log("> " + input);
|
| 56 |
+
state.llm.handle(input, state);
|
| 57 |
+
};
|