feat: some shit

This commit is contained in:
Max Richter
2026-01-23 02:28:17 +01:00
parent ab02a71ca5
commit 571bb2a5d3
10 changed files with 243 additions and 153 deletions

View File

@@ -2,6 +2,7 @@
import { getGraphState } from "../graph-state.svelte";
import { createNodePath } from "../helpers/index.js";
import type { NodeInstance } from "@nodarium/types";
import { appSettings } from "$lib/settings/app-settings.svelte";
const graphState = getGraphState();
@@ -43,7 +44,12 @@
<div class="wrapper" data-node-id={node.id} data-node-type={node.type}>
<div class="content">
{node.type.split("/").pop()} ({node.id})
{#if appSettings.value.nodeInterface.showNodeIds}
<span class="bg-white text-black! mr-2 px-1 rounded-sm opacity-30"
>{node.id}</span
>
{/if}
{node.type.split("/").pop()}
</div>
<div
class="click-target"

View File

@@ -87,8 +87,9 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
results: Record<number, Pointer> = {};
inputPtrs: Record<number, Pointer[]> = {};
allPtrs: Pointer[] = [];
seed = 123123;
seed = 42424242;
perf?: PerformanceStore;
@@ -202,11 +203,13 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
this.offset += length;
return {
const ptr = {
start,
end,
_title: title
};
this.allPtrs.push(ptr);
return ptr;
}
private printMemory() {
@@ -214,10 +217,13 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
console.log('MEMORY', this.memoryView.slice(0, 10));
}
async execute(graph: Graph, _settings: Record<string, unknown>) {
async execute(graph: Graph, settings: Record<string, unknown>) {
this.offset = 0;
this.inputPtrs = {};
this.seed = this.seed += 2;
this.results = {};
this.allPtrs = [];
if (this.isRunning) return undefined as unknown as Int32Array;
this.isRunning = true;
@@ -240,11 +246,22 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
(a, b) => (b.state?.depth || 0) - (a.state?.depth || 0)
);
console.log({ settings });
this.printMemory();
const seedPtr = this.writeToMemory(this.seed, 'seed');
const settingPtrs = new Map<string, Pointer>(
Object.entries(settings).map((
[key, value]
) => [key as string, this.writeToMemory(value as number, `setting.${key}`)])
);
for (const node of sortedNodes) {
const node_type = this.nodes.get(node.type)!;
console.log('---------------');
console.log('STARTING NODE EXECUTION', node_type.definition.id);
console.log('STARTING NODE EXECUTION', node_type.definition.id + '/' + node.id);
this.printMemory();
// console.log(node_type.definition.inputs);
@@ -252,23 +269,24 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
([key, input]) => {
// We should probably initially write this to memory
if (input.type === 'seed') {
return this.writeToMemory(this.seed);
return seedPtr;
}
const title = `${node.id}.${key}`;
// We should probably initially write this to memory
// If the input is linked to a setting, we use that value
// if (input.setting) {
// return getValue(input, settings[input.setting]);
// }
// TODO: handle nodes which reference undefined settings
if (input.setting) {
return settingPtrs.get(input.setting)!;
}
// check if the input is connected to another node
const inputNode = node.state.inputNodes[key];
if (inputNode) {
if (this.results[inputNode.id] === undefined) {
throw new Error(
`Node ${node.type} is missing input from node ${inputNode.type}`
`Node ${node.type}/${node.id} is missing input from node ${inputNode.type}/${inputNode.id}`
);
}
return this.results[inputNode.id];
@@ -317,6 +335,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
end: args[1],
_title: `${node.id} ->`
};
this.allPtrs.push(this.results[node.id]);
} else {
this.results[node.id] = {
start: this.offset,
@@ -324,6 +343,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
_title: `${node.id} ->`
};
this.offset += bytesWritten / 4;
this.allPtrs.push(this.results[node.id]);
}
console.log('FINISHED EXECUTION', {
bytesWritten,

View File

@@ -1,148 +1,147 @@
import { localState } from "$lib/helpers/localState.svelte";
import { localState } from '$lib/helpers/localState.svelte';
const themes = [
"dark",
"light",
"catppuccin",
"solarized",
"high-contrast",
"nord",
"dracula",
'dark',
'light',
'catppuccin',
'solarized',
'high-contrast',
'nord',
'dracula'
] as const;
export const AppSettingTypes = {
theme: {
type: "select",
type: 'select',
options: themes,
label: "Theme",
value: themes[0],
label: 'Theme',
value: themes[0]
},
showGrid: {
type: "boolean",
label: "Show Grid",
value: true,
type: 'boolean',
label: 'Show Grid',
value: true
},
centerCamera: {
type: "boolean",
label: "Center Camera",
value: true,
type: 'boolean',
label: 'Center Camera',
value: true
},
nodeInterface: {
title: "Node Interface",
title: 'Node Interface',
showNodeGrid: {
type: "boolean",
label: "Show Grid",
value: true,
type: 'boolean',
label: 'Show Grid',
value: true
},
snapToGrid: {
type: "boolean",
label: "Snap to Grid",
value: true,
type: 'boolean',
label: 'Snap to Grid',
value: true
},
showHelp: {
type: "boolean",
label: "Show Help",
value: false,
type: 'boolean',
label: 'Show Help',
value: false
},
showNodeIds: {
type: 'boolean',
label: 'Show Node Ids',
value: false
}
},
debug: {
title: "Debug",
title: 'Debug',
wireframe: {
type: "boolean",
label: "Wireframe",
value: false,
type: 'boolean',
label: 'Wireframe',
value: false
},
useWorker: {
type: "boolean",
label: "Execute in WebWorker",
value: true,
type: 'boolean',
label: 'Execute in WebWorker',
value: true
},
showIndices: {
type: "boolean",
label: "Show Indices",
value: false,
type: 'boolean',
label: 'Show Indices',
value: false
},
showPerformancePanel: {
type: "boolean",
label: "Show Performance Panel",
value: false,
type: 'boolean',
label: 'Show Performance Panel',
value: false
},
showBenchmarkPanel: {
type: "boolean",
label: "Show Benchmark Panel",
value: false,
type: 'boolean',
label: 'Show Benchmark Panel',
value: false
},
showVertices: {
type: "boolean",
label: "Show Vertices",
value: false,
type: 'boolean',
label: 'Show Vertices',
value: false
},
showStemLines: {
type: "boolean",
label: "Show Stem Lines",
value: false,
type: 'boolean',
label: 'Show Stem Lines',
value: false
},
showGraphJson: {
type: "boolean",
label: "Show Graph Source",
value: false,
type: 'boolean',
label: 'Show Graph Source',
value: false
},
cache: {
title: "Cache",
title: 'Cache',
useRuntimeCache: {
type: "boolean",
label: "Node Results",
value: true,
type: 'boolean',
label: 'Node Results',
value: true
},
useRegistryCache: {
type: "boolean",
label: "Node Source",
value: true,
},
type: 'boolean',
label: 'Node Source',
value: true
}
},
stressTest: {
title: "Stress Test",
title: 'Stress Test',
amount: {
type: "integer",
type: 'integer',
min: 2,
max: 15,
value: 4,
value: 4
},
loadGrid: {
type: "button",
label: "Load Grid",
type: 'button',
label: 'Load Grid'
},
loadTree: {
type: "button",
label: "Load Tree",
type: 'button',
label: 'Load Tree'
},
lottaFaces: {
type: "button",
label: "Load 'lots of faces'",
type: 'button',
label: "Load 'lots of faces'"
},
lottaNodes: {
type: "button",
label: "Load 'lots of nodes'",
type: 'button',
label: "Load 'lots of nodes'"
},
lottaNodesAndFaces: {
type: "button",
label: "Load 'lots of nodes and faces'",
},
},
},
type: 'button',
label: "Load 'lots of nodes and faces'"
}
}
}
} as const;
type SettingsToStore<T> =
T extends { value: infer V }
? V extends readonly string[]
? V[number]
type SettingsToStore<T> = T extends { value: infer V } ? V extends readonly string[] ? V[number]
: V
: T extends any[]
? {}
: T extends object
? {
[K in keyof T as T[K] extends object ? K : never]:
SettingsToStore<T[K]>
: T extends any[] ? {}
: T extends object ? {
[K in keyof T as T[K] extends object ? K : never]: SettingsToStore<T[K]>;
}
: never;
@@ -150,8 +149,8 @@ export function settingsToStore<T>(settings: T): SettingsToStore<T> {
const result = {} as any;
for (const key in settings) {
const value = settings[key];
if (value && typeof value === "object") {
if ("value" in value) {
if (value && typeof value === 'object') {
if ('value' in value) {
result[key] = value.value;
} else {
result[key] = settingsToStore(value);
@@ -162,8 +161,8 @@ export function settingsToStore<T>(settings: T): SettingsToStore<T> {
}
export let appSettings = localState(
"app-settings",
settingsToStore(AppSettingTypes),
'app-settings',
settingsToStore(AppSettingTypes)
);
$effect.root(() => {
@@ -173,7 +172,7 @@ $effect.root(() => {
const newClassName = `theme-${theme}`;
if (classes) {
for (const className of classes) {
if (className.startsWith("theme-") && className !== newClassName) {
if (className.startsWith('theme-') && className !== newClassName) {
classes.remove(className);
}
}