From cf5b36490f72bafe7b9ebe1214cbc7638f52e027 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Fri, 3 May 2024 01:33:55 +0200 Subject: [PATCH] feat: some tweaks --- app/src/lib/graph-interface/graph-manager.ts | 4 +- app/src/lib/helpers/index.ts | 52 ++++ app/src/lib/node-store/DraggableNode.svelte | 2 - .../lib/performance/PerformanceViewer.svelte | 230 +++++++++--------- .../lib/settings/panels/ExportSettings.svelte | 40 +-- app/src/routes/+page.svelte | 99 +++----- nodes/max/plantarium/rotate/src/input.json | 14 +- nodes/max/plantarium/rotate/src/lib.rs | 5 +- 8 files changed, 235 insertions(+), 211 deletions(-) diff --git a/app/src/lib/graph-interface/graph-manager.ts b/app/src/lib/graph-interface/graph-manager.ts index 42a4bdb..6a5c19e 100644 --- a/app/src/lib/graph-interface/graph-manager.ts +++ b/app/src/lib/graph-interface/graph-manager.ts @@ -11,6 +11,8 @@ const logger = createLogger("graph-manager"); logger.mute(); +const clone = "structuredClone" in self ? self.structuredClone : (args: any) => JSON.parse(JSON.stringify(args)); + function areSocketsCompatible(output: string | undefined, inputs: string | string[] | undefined) { if (Array.isArray(inputs) && output) { return inputs.includes(output); @@ -67,7 +69,7 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, " const serialized = { id: this.graph.id, settings: this.settings, nodes, edges }; logger.groupEnd(); - return serialized; + return clone(serialized); } diff --git a/app/src/lib/helpers/index.ts b/app/src/lib/helpers/index.ts index 974ab54..6dc0b71 100644 --- a/app/src/lib/helpers/index.ts +++ b/app/src/lib/helpers/index.ts @@ -155,3 +155,55 @@ export function humanizeDuration(durationInMilliseconds: number) { return durationString.trim(); } +export function debounceAsyncFunction(func: (...args: T) => Promise): (...args: T) => Promise { + let currentPromise: Promise | null = null; + let nextArgs: T | null = null; + let resolveNext: ((result: R) => void) | null = null; + + const debouncedFunction = async (...args: T): Promise => { + if (currentPromise) { + // Store the latest arguments and create a new promise to resolve them later + nextArgs = args; + return new Promise((resolve) => { + resolveNext = resolve; + }); + } else { + // Execute the function immediately + try { + currentPromise = func(...args); + const result = await currentPromise; + return result; + } finally { + currentPromise = null; + // If there are stored arguments, call the function again with the latest arguments + if (nextArgs) { + const argsToUse = nextArgs; + const resolver = resolveNext; + nextArgs = null; + resolveNext = null; + resolver!(await debouncedFunction(...argsToUse)); + } + } + } + }; + + return debouncedFunction; +} + +export function withArgsChangeOnly(func: (...args: T) => R): (...args: T) => R { + let lastArgs: T | undefined = undefined; + let lastResult: R; + + return (...args: T): R => { + // Check if arguments are the same as last call + if (lastArgs && args.length === lastArgs.length && args.every((val, index) => val === lastArgs?.[index])) { + return lastResult; // Return cached result if arguments haven't changed + } + + // Call the function with new arguments + lastResult = func(...args); + lastArgs = args; // Update stored arguments + return lastResult; // Return new result + }; +} + diff --git a/app/src/lib/node-store/DraggableNode.svelte b/app/src/lib/node-store/DraggableNode.svelte index 804f7d0..82fa680 100644 --- a/app/src/lib/node-store/DraggableNode.svelte +++ b/app/src/lib/node-store/DraggableNode.svelte @@ -4,8 +4,6 @@ export let node: NodeDefinition; - $: console.log({ node }); - let dragging = false; let nodeData = { diff --git a/app/src/lib/performance/PerformanceViewer.svelte b/app/src/lib/performance/PerformanceViewer.svelte index 5fcc674..83fa37e 100644 --- a/app/src/lib/performance/PerformanceViewer.svelte +++ b/app/src/lib/performance/PerformanceViewer.svelte @@ -176,7 +176,7 @@ } -{#key $activeType} +{#key $activeType && data} {#if $activeType === "cache-hit"} {/if} -{/key} -
-
- - +
+
+ + +
+ + {#if data.length !== 0} + + +

General

+ + + + + + + + {#each getPerformanceData(!showAverage) as [key, value]} + + + + + {/each} + + + + + + + + + + + + + + + + + {#each getNodePerformanceData(!showAverage) as [key, value]} + + + + + + {/each} + + + + + + + + + + + + + + + + {#each getViewerPerformanceData(!showAverage) as [key, value]} + + + + + {/each} + +
+ {round(getTotalPerformance(!showAverage))}ms + ($activeType = "total")} + > + total({Math.floor( + 1000 / getTotalPerformance(showAverage), + )}fps) +
+ {round(value)}ms + ($activeType = key)} + > + {key} +
{data.length}Samples
+

Nodes

+
{getCacheRatio(!showAverage)}% ($activeType = "cache-hit")}>cache hits
+ {round(value)}ms + ($activeType = key)} + > + {key.split("/").slice(-1).join("/")} +
+

Viewer

+
{humanizeNumber(getLast("total-vertices"))}Vertices
{humanizeNumber(getLast("total-faces"))}Faces
+ {round(value)}ms + ($activeType = key)} + > + {key.split("/").slice(-1).join("/")} +
+ {:else} +

No runs available

+ {/if}
- - {#if data.length !== 0} - - -

General

- - - - - - - - {#each getPerformanceData(!showAverage) as [key, value]} - - - - - {/each} - - - - - - - - - - - - - - - - - {#each getNodePerformanceData(!showAverage) as [key, value]} - - - - - - {/each} - - - - - - - - - - - - - - - - {#each getViewerPerformanceData(!showAverage) as [key, value]} - - - - - {/each} - -
- {round(getTotalPerformance(!showAverage))}ms - ($activeType = "total")} - > - total({Math.floor(1000 / getTotalPerformance(showAverage))}fps) -
- {round(value)}ms - ($activeType = key)} - > - {key} -
{data.length}Samples
-

Nodes

-
{getCacheRatio(!showAverage)}% ($activeType = "cache-hit")}>cache hits
- {round(value)}ms - ($activeType = key)} - > - {key.split("/").slice(-1).join("/")} -
-

Viewer

-
{humanizeNumber(getLast("total-vertices"))}Vertices
{humanizeNumber(getLast("total-faces"))}Faces
- {round(value)}ms - ($activeType = key)} - > - {key.split("/").slice(-1).join("/")} -
- {:else} -

No runs available

- {/if} -
+{/key}