Demo tick source, and structure for other demos
This commit is contained in:
parent
7d25c3e676
commit
3dbca6edb6
3 changed files with 50 additions and 0 deletions
11
debug.html
Normal file
11
debug.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Misc. Infrastructure POCs</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="js/debug.js"></script>
|
||||
<script>
|
||||
document.body.append(...TickDebug());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
3
debug.ts
Normal file
3
debug.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { TickDebug } from "./debug/tick";
|
||||
|
||||
Object.assign(globalThis, { TickDebug });
|
36
debug/tick.ts
Normal file
36
debug/tick.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { h } from "../lib/html";
|
||||
import { Cancel } from "../lib/source";
|
||||
import { tick } from "../lib/tick";
|
||||
|
||||
export function TickDebug() {
|
||||
const output = h("pre", {});
|
||||
|
||||
const tickSource = tick(30);
|
||||
let cancel: Cancel;
|
||||
|
||||
const begin = () => {
|
||||
// reset / init
|
||||
cancel?.();
|
||||
output.innerHTML = "";
|
||||
// subscribe to source, stash cancellation func
|
||||
cancel = tickSource((tick) => {
|
||||
switch (tick[0]) {
|
||||
case "physics":
|
||||
output.append(`${new Date().toISOString()}: Physics\n`);
|
||||
break;
|
||||
case "render":
|
||||
output.append(
|
||||
`${new Date().toISOString()}: Render (dt=${tick[1]})\n`
|
||||
);
|
||||
break;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const end = () => cancel?.();
|
||||
|
||||
const start = h("button", { onclick: begin }, "Begin");
|
||||
const stop = h("button", { onclick: end }, "Cease");
|
||||
|
||||
return [h("h1", {}, "Tick Event Demo"), start, stop, output, h("hr")];
|
||||
}
|
Loading…
Add table
Reference in a new issue