feat: BIOS boot replay on entry, VHS camcorder OSD telemetry
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -61,8 +61,8 @@ ducks, live. Peer-to-peer WebRTC via [Trystero](https://github.com/dmotz/tryster
|
||||
(serverless signaling over public Nostr relays), so it works from a static
|
||||
Space with no backend. Each tab broadcasts its duck's pose (trunk + 14
|
||||
joints + jaw + colour) at 10 Hz; up to 3 ghosts are rendered, extra peers
|
||||
stay connected but invisible. The header shows "N online" when peers are
|
||||
around.
|
||||
stay connected but invisible. The camcorder-style OSD in the top-right
|
||||
corner shows "N ONLINE" when peers are around.
|
||||
|
||||
## How it works
|
||||
|
||||
|
||||
+85
-12
@@ -42,19 +42,50 @@
|
||||
line-height: 1.8;
|
||||
}
|
||||
#brand b { color: var(--yellow); font-weight: 600; }
|
||||
/* BIOS/POST boot readout: hidden while the welcome modal is up (the
|
||||
real load runs silently behind it); rl.js reveals it after the
|
||||
first "Waddle in" and replays / tracks the milestones over an
|
||||
opaque dark screen before fading into the scene. */
|
||||
#loading {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 0.8rem;
|
||||
letter-spacing: 0.14em;
|
||||
text-transform: uppercase;
|
||||
color: rgba(255, 255, 255, 0.45);
|
||||
text-align: center;
|
||||
padding: 0 2rem;
|
||||
background: var(--ink);
|
||||
z-index: 20;
|
||||
pointer-events: none;
|
||||
opacity: 1;
|
||||
transition: opacity 0.45s ease;
|
||||
}
|
||||
#loading.off { opacity: 0; }
|
||||
#loading .post {
|
||||
min-width: min(380px, 84vw);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 0.72rem;
|
||||
line-height: 2.1;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
text-align: left;
|
||||
color: rgba(255, 210, 63, 0.72);
|
||||
text-shadow: 0 0 10px rgba(255, 210, 63, 0.2);
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
#loading .post > div:first-child {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
margin-bottom: 0.3rem;
|
||||
}
|
||||
/* Blinking block cursor at the end of the newest line */
|
||||
#loading .post > div:last-child::after {
|
||||
content: "\2588";
|
||||
margin-left: 0.4em;
|
||||
animation: post-blink 1s steps(1) infinite;
|
||||
}
|
||||
@keyframes post-blink {
|
||||
0%, 55% { opacity: 1; }
|
||||
56%, 100% { opacity: 0; }
|
||||
}
|
||||
/* Bottom edges: controls left, key hints right */
|
||||
#hud {
|
||||
@@ -115,6 +146,7 @@
|
||||
text-transform: uppercase;
|
||||
color: rgba(255, 210, 63, 0.8);
|
||||
text-align: right;
|
||||
text-shadow: 0 0 8px rgba(255, 210, 63, 0.3);
|
||||
}
|
||||
.mode .mode-text {
|
||||
position: absolute;
|
||||
@@ -221,6 +253,8 @@
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
.stickbox.live .stickdot { background: var(--yellow); }
|
||||
/* Camcorder OSD: REC light + VHS counter over the telemetry, all in
|
||||
a phosphor-glow monospace. No scanlines - the type does the work. */
|
||||
#stats-wrap {
|
||||
position: fixed;
|
||||
top: 1.4rem;
|
||||
@@ -229,20 +263,48 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 0.15rem;
|
||||
gap: 0.2rem;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
.osd-top {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.9rem;
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
text-shadow: 0 0 7px rgba(255, 255, 255, 0.28);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.osd-rec {
|
||||
color: #ff6a48;
|
||||
text-shadow: 0 0 9px rgba(255, 90, 60, 0.55);
|
||||
}
|
||||
.osd-rec .rec-dot {
|
||||
display: inline-block;
|
||||
animation: rec-blink 1.2s steps(1) infinite;
|
||||
}
|
||||
@keyframes rec-blink {
|
||||
0%, 58% { opacity: 1; }
|
||||
59%, 100% { opacity: 0.12; }
|
||||
}
|
||||
#stats {
|
||||
font-size: 0.68rem;
|
||||
letter-spacing: 0.08em;
|
||||
font-size: 0.62rem;
|
||||
letter-spacing: 0.14em;
|
||||
text-transform: uppercase;
|
||||
text-align: right;
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
color: rgba(255, 255, 255, 0.45);
|
||||
line-height: 1.7;
|
||||
font-variant-numeric: tabular-nums;
|
||||
text-shadow: 0 0 6px rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
@media (max-width: 700px) {
|
||||
#hud { flex-direction: column; align-items: flex-start; }
|
||||
#hud .keys { display: none; }
|
||||
#brand .sub { display: none; }
|
||||
/* Drop the OSD below the (single-line) brand so they never collide */
|
||||
#stats-wrap { top: 3.4rem; }
|
||||
}
|
||||
/* ── Welcome modal ─────────────────────────────────────────────── */
|
||||
/* display:flex would override the hidden attribute's UA display:none,
|
||||
@@ -520,6 +582,10 @@
|
||||
<span class="sub">MuJoCo + ONNX, live in your browser</span>
|
||||
</div>
|
||||
<div id="stats-wrap">
|
||||
<div class="osd-top">
|
||||
<span class="osd-rec"><span class="rec-dot">●</span> REC</span>
|
||||
<span id="osd-time">▶ 00:00:00</span>
|
||||
</div>
|
||||
<div class="mode" id="mode-label"><span class="mode-text">Run</span></div>
|
||||
<div id="stats"></div>
|
||||
</div>
|
||||
@@ -560,7 +626,7 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="loading">Compiling physics…</div>
|
||||
<div id="loading"><div class="post"></div></div>
|
||||
|
||||
<div id="welcome" hidden>
|
||||
<div class="card" role="dialog" aria-modal="true" aria-label="Microduck playground">
|
||||
@@ -650,6 +716,13 @@
|
||||
const close = () => {
|
||||
modal.classList.add("closing");
|
||||
setTimeout(() => { modal.hidden = true; }, 380);
|
||||
// First dismissal only: cue the BIOS boot replay in rl.js. The
|
||||
// flag covers the race where the user enters before the module
|
||||
// has finished evaluating.
|
||||
if (!window.__microduckEntered) {
|
||||
window.__microduckEntered = true;
|
||||
document.dispatchEvent(new CustomEvent("microduck:enter"));
|
||||
}
|
||||
};
|
||||
open();
|
||||
document.getElementById("welcome-go").addEventListener("click", close);
|
||||
@@ -673,7 +746,7 @@
|
||||
appended: a plain src attribute can 401 when the browser blocks the
|
||||
*.static.hf.space auth cookie inside the hub iframe. -->
|
||||
<script type="module">
|
||||
const V = "31"; // bump on rl.js changes to defeat heuristic caching
|
||||
const V = "32"; // bump on rl.js changes to defeat heuristic caching
|
||||
const sign = new URLSearchParams(location.search).get("__sign");
|
||||
const suffix = sign ? `&__sign=${encodeURIComponent(sign)}` : "";
|
||||
import(`./rl.js?v=${V}${suffix}`);
|
||||
|
||||
@@ -94,28 +94,87 @@ const mount = document.getElementById("scene");
|
||||
const loadingEl = document.getElementById("loading");
|
||||
const hudEl = document.getElementById("hud");
|
||||
const statsEl = document.getElementById("stats");
|
||||
const setLoading = (msg) => { loadingEl.textContent = msg; };
|
||||
const osdTimeEl = document.getElementById("osd-time");
|
||||
|
||||
// BIOS/POST boot readout. The real load runs silently behind the welcome
|
||||
// modal and only RECORDS milestones into bootLog; the readout itself plays
|
||||
// after the first "Waddle in": a rapid-fire replay when everything already
|
||||
// finished, or an honest live tracker (cursor blinking on the pending
|
||||
// line) when the user enters mid-load. Never slows the actual boot.
|
||||
const postEl = loadingEl.querySelector(".post");
|
||||
const bootLog = []; // { label, status, raw, el } - status null = pending
|
||||
const lineText = (e) =>
|
||||
e.raw || e.status === null ? e.label : `${e.label} `.padEnd(26, ".") + ` ${e.status}`;
|
||||
const bootLine = (label) => {
|
||||
const entry = { label, status: null, raw: false, el: null };
|
||||
bootLog.push(entry);
|
||||
return (status = "OK") => {
|
||||
entry.status = status;
|
||||
if (entry.el) entry.el.textContent = lineText(entry);
|
||||
};
|
||||
};
|
||||
// Plain line with no dotted leader (header / error text).
|
||||
const bootNote = (label) => {
|
||||
bootLog.push({ label, status: "", raw: true, el: null });
|
||||
};
|
||||
bootNote("Microduck BIOS v1.0");
|
||||
bootLine("MEMORY CHECK")("640K OK");
|
||||
bootLine("DUCK FIRMWARE")("PRESENT");
|
||||
|
||||
let bootDone = false;
|
||||
let biosStarted = false;
|
||||
const biosSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
async function playBios() {
|
||||
if (biosStarted) return;
|
||||
biosStarted = true;
|
||||
loadingEl.style.display = "flex";
|
||||
let i = 0;
|
||||
for (;;) {
|
||||
if (i < bootLog.length) {
|
||||
const entry = bootLog[i++];
|
||||
entry.el = document.createElement("div");
|
||||
entry.el.textContent = lineText(entry);
|
||||
postEl.appendChild(entry.el);
|
||||
// Honest mode: hold on a stage still in flight (its completer will
|
||||
// fill in the status), cursor blinking on it via CSS.
|
||||
while (entry.status === null && !bootDone) await biosSleep(60);
|
||||
await biosSleep(105); // rapid-fire pacing for finished lines
|
||||
} else if (bootDone) {
|
||||
break;
|
||||
} else {
|
||||
await biosSleep(60); // waiting for the next real stage
|
||||
}
|
||||
}
|
||||
const ready = document.createElement("div");
|
||||
ready.textContent = "READY.";
|
||||
postEl.appendChild(ready);
|
||||
await biosSleep(500);
|
||||
loadingEl.classList.add("off");
|
||||
await biosSleep(500);
|
||||
loadingEl.style.display = "none";
|
||||
}
|
||||
// Only the initial entry triggers the replay; reopening the modal from
|
||||
// the brand later never replays (biosStarted latches).
|
||||
if (window.__microduckEntered) playBios();
|
||||
else document.addEventListener("microduck:enter", () => playBios(), { once: true });
|
||||
|
||||
// Surface boot failures on the page itself: a rejected top-level await
|
||||
// otherwise leaves the loading screen up with no visible error.
|
||||
// otherwise leaves a dead page with no visible error.
|
||||
window.addEventListener("unhandledrejection", (e) => {
|
||||
const msg = e.reason?.stack || e.reason?.message || String(e.reason);
|
||||
setLoading(`Boot failed: ${msg}`);
|
||||
bootNote(`Boot failed: ${msg}`);
|
||||
playBios();
|
||||
console.error("[rl] unhandled rejection", e.reason);
|
||||
});
|
||||
window.addEventListener("error", (e) => {
|
||||
setLoading(`Boot failed: ${e.message}`);
|
||||
bootNote(`Boot failed: ${e.message}`);
|
||||
playBios();
|
||||
});
|
||||
const bootSteps = [];
|
||||
const traced = (label, p) => {
|
||||
bootSteps.push(label);
|
||||
const done = bootLine(label);
|
||||
return p.then(
|
||||
(v) => {
|
||||
bootSteps.splice(bootSteps.indexOf(label), 1);
|
||||
if (bootSteps.length) setLoading(`Loading ${bootSteps.join(", ")}\u2026`);
|
||||
return v;
|
||||
},
|
||||
(err) => { console.error(`[rl] ${label} FAILED`, err); throw err; },
|
||||
(v) => { done("OK"); return v; },
|
||||
(err) => { done("FAIL"); console.error(`[rl] ${label} FAILED`, err); throw err; },
|
||||
);
|
||||
};
|
||||
|
||||
@@ -198,14 +257,13 @@ async function buildPhysicsXml() {
|
||||
}
|
||||
|
||||
// ── Boot physics + policy in parallel with the render rig ──────────────
|
||||
setLoading("Loading MuJoCo WASM, policies and meshes\u2026");
|
||||
|
||||
const [mujoco, { xml, meshFiles }, k] = await Promise.all([
|
||||
traced("mujoco wasm", loadMujoco()),
|
||||
traced("physics xml", buildPhysicsXml()),
|
||||
traced("kinematics", loadKinematics(`${MODEL_DIR}/kinematics.json`)),
|
||||
traced("MUJOCO WASM", loadMujoco()),
|
||||
traced("PHYSICS MJCF", buildPhysicsXml()),
|
||||
traced("KINEMATICS", loadKinematics(`${MODEL_DIR}/kinematics.json`)),
|
||||
]);
|
||||
|
||||
const doneMeshes = bootLine("MESH ASSETS");
|
||||
const vfs = new mujoco.MjVFS();
|
||||
await Promise.all(
|
||||
meshFiles.map(async (f) => {
|
||||
@@ -216,12 +274,17 @@ await Promise.all(
|
||||
vfs.addBuffer(`assets/${f}`, new Uint8Array(buf));
|
||||
}),
|
||||
);
|
||||
doneMeshes(`${meshFiles.length} FILES`);
|
||||
|
||||
const sessions = {};
|
||||
let currentVariant = randomVariantName();
|
||||
const rigPromise = (async () => {
|
||||
return buildRig(k, { materialForMesh: materialHookFor(VARIANTS[currentVariant]) });
|
||||
const doneRig = bootLine("RENDER RIG");
|
||||
const rig = await buildRig(k, { materialForMesh: materialHookFor(VARIANTS[currentVariant]) });
|
||||
doneRig("OK");
|
||||
return rig;
|
||||
})();
|
||||
const donePolicies = bootLine("LOADING POLICIES");
|
||||
const sessionOpts = { executionProviders: ["wasm"] };
|
||||
[sessions.walk, sessions.sitstand, sessions.roll, sessions.kickL, sessions.kickR] =
|
||||
await Promise.all([
|
||||
@@ -231,10 +294,12 @@ const sessionOpts = { executionProviders: ["wasm"] };
|
||||
ort.InferenceSession.create(signed(POLICIES.kickL), sessionOpts),
|
||||
ort.InferenceSession.create(signed(POLICIES.kickR), sessionOpts),
|
||||
]);
|
||||
donePolicies("5/5");
|
||||
|
||||
setLoading("Compiling physics\u2026");
|
||||
const doneCompile = bootLine("COMPILING PHYSICS");
|
||||
const model = mujoco.MjModel.from_xml_string(xml, vfs);
|
||||
const data = new mujoco.MjData(model);
|
||||
doneCompile("COMPILED");
|
||||
|
||||
// Addresses resolved once. qpos/qvel/sensordata views are re-read at each
|
||||
// use: the WASM heap can grow and detach earlier TypedArray views.
|
||||
@@ -975,9 +1040,13 @@ function renderStats() {
|
||||
// The active policy lives in the big center label and the twist in the
|
||||
// mini sticks; up here only the bare telemetry remains.
|
||||
const peers = ghosts?.peerCount() ?? 0;
|
||||
// VHS counter: sim time as mm:ss:ff where ff counts control frames (50Hz).
|
||||
const t = data.time;
|
||||
const p2 = (n) => String(n).padStart(2, "0");
|
||||
osdTimeEl.textContent =
|
||||
`\u25b6 ${p2(Math.floor(t / 60))}:${p2(Math.floor(t) % 60)}:${p2(Math.floor((t % 1) * 50))}`;
|
||||
statsEl.textContent =
|
||||
`ctrl ${ctrlHz.toFixed(0)} Hz \u00b7 sim t ${data.time.toFixed(1)} s` +
|
||||
(peers ? ` \u00b7 ${peers + 1} online` : "");
|
||||
`CTRL ${ctrlHz.toFixed(0)}HZ` + (peers ? ` \u00b7 ${peers + 1} ONLINE` : "");
|
||||
|
||||
// Mini sticks: the dot mirrors the effective twist, lit yellow while the
|
||||
// user is actually driving.
|
||||
@@ -1029,7 +1098,10 @@ function loop() {
|
||||
renderStats();
|
||||
renderer.render(scene, camera);
|
||||
}
|
||||
loadingEl.style.display = "none";
|
||||
// Boot complete: the sim/HUD go live immediately. The BIOS readout (if
|
||||
// the user already waddled in, or when they do) sees bootDone and closes
|
||||
// with READY. + fade on its own.
|
||||
bootDone = true;
|
||||
hudEl.hidden = false;
|
||||
loop();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user