nodes/app/src/routes/+page.svelte

126 lines
3.3 KiB
Svelte
Raw Normal View History

2024-03-06 14:01:07 +01:00
<script lang="ts">
2024-04-10 14:27:23 +02:00
import Grid from "$lib/grid";
2024-04-15 22:13:43 +02:00
import GraphInterface from "$lib/graph-interface";
import { MemoryRuntimeExecutor } from "$lib/runtime-executor";
import { RemoteNodeRegistry } from "$lib/node-registry";
import * as templates from "$lib/graph-templates";
2024-04-10 21:57:03 +02:00
import type { Graph } from "@nodes/types";
2024-04-18 00:02:50 +02:00
import { decode, encode, decodeFloat, encodeFloat } from "@nodes/utils";
2024-04-16 15:32:23 +02:00
import Viewer from "$lib/viewer/Viewer.svelte";
globalThis.decode = decode;
globalThis.encode = encode;
2024-04-16 15:32:23 +02:00
globalThis.df = decodeFloat;
globalThis.en = encodeFloat;
2024-03-06 18:31:06 +01:00
2024-04-18 00:02:50 +02:00
globalThis.ci = function createIndeces(resX: number, stemLength = 1) {
const index = new Uint16Array(resX * (Math.max(stemLength, 1) - 1) * 6);
for (let i = 0; i < stemLength; i++) {
const indexOffset = i * resX * 6;
const positionOffset = i * resX;
for (let j = 0; j < resX; j++) {
const _indexOffset = indexOffset + j * 6;
const _positionOffset = positionOffset + j;
console.log(`iio: ${_indexOffset} pio: ${_positionOffset} j: ${j}`);
if (j === resX - 1) {
index[_indexOffset + 0] = _positionOffset + 1;
index[_indexOffset + 1] = _positionOffset - resX + 1;
index[_indexOffset + 2] = _positionOffset;
index[_indexOffset + 3] = _positionOffset;
index[_indexOffset + 4] = _positionOffset + resX;
index[_indexOffset + 5] = _positionOffset + 1;
} else {
index[_indexOffset + 0] = _positionOffset + resX + 1;
index[_indexOffset + 1] = _positionOffset + 1;
index[_indexOffset + 2] = _positionOffset;
index[_indexOffset + 3] = _positionOffset;
index[_indexOffset + 4] = _positionOffset + resX;
index[_indexOffset + 5] = _positionOffset + resX + 1;
}
}
}
return index;
};
2024-04-10 14:27:23 +02:00
const nodeRegistry = new RemoteNodeRegistry("http://localhost:3001");
const runtimeExecutor = new MemoryRuntimeExecutor(nodeRegistry);
2024-04-16 15:32:23 +02:00
let res: Int32Array;
2024-04-10 21:57:03 +02:00
let time = 0;
2024-03-19 16:56:42 +01:00
let graph = localStorage.getItem("graph")
? JSON.parse(localStorage.getItem("graph")!)
: templates.grid(3, 3);
2024-03-19 16:56:42 +01:00
2024-04-10 21:57:03 +02:00
function handleResult(event: CustomEvent<Graph>) {
let a = performance.now();
2024-04-16 15:32:23 +02:00
res = runtimeExecutor.execute(event.detail);
2024-04-10 21:57:03 +02:00
time = performance.now() - a;
2024-04-18 00:02:50 +02:00
console.log({ res, time });
}
2024-03-06 18:31:06 +01:00
2024-04-10 21:57:03 +02:00
function handleSave(event: CustomEvent<Graph>) {
localStorage.setItem("graph", JSON.stringify(event.detail));
}
2024-03-06 14:01:07 +01:00
</script>
2024-04-10 14:27:23 +02:00
<div class="wrapper">
<header>
header
<button
on:click={() => {
graph = templates.grid(10, 10);
}}>grid stress-test</button
>
</header>
2024-04-10 14:27:23 +02:00
<Grid.Row>
<Grid.Cell>
2024-04-16 15:32:23 +02:00
<Viewer result={res} />
</Grid.Cell>
<Grid.Cell>
{#key graph}
2024-04-10 21:57:03 +02:00
<GraphInterface
registry={nodeRegistry}
{graph}
on:result={handleResult}
on:save={handleSave}
/>
{/key}
2024-04-10 14:27:23 +02:00
</Grid.Cell>
</Grid.Row>
2024-03-06 14:01:07 +01:00
</div>
<style>
2024-04-10 14:27:23 +02:00
header {
border-bottom: solid thin white;
2024-03-06 14:01:07 +01:00
}
2024-03-20 02:17:58 +01:00
.wrapper {
2024-04-10 14:27:23 +02:00
height: 100vh;
width: 100vw;
color: white;
display: grid;
grid-template-rows: 50px 1fr;
}
2024-03-06 14:01:07 +01:00
:global(html) {
background: rgb(13, 19, 32);
background: linear-gradient(
180deg,
rgba(13, 19, 32, 1) 0%,
rgba(8, 12, 21, 1) 100%
);
}
:global(body) {
margin: 0;
position: relative;
}
</style>