feat: improve logger
This commit is contained in:
parent
070a5b52d0
commit
415d773610
@ -78,11 +78,20 @@ export const createLogger = (() => {
|
||||
return (scope: string) => {
|
||||
maxLength = Math.max(maxLength, scope.length);
|
||||
let muted = false;
|
||||
|
||||
let isGrouped = false;
|
||||
|
||||
function s(color: string, ...args: any) {
|
||||
return isGrouped ? [...args] : [`[%c${scope.padEnd(maxLength, " ")}]:`, `color: ${color}`, ...args];
|
||||
}
|
||||
|
||||
return {
|
||||
log: (...args: any[]) => !muted && console.log(`[%c${scope.padEnd(maxLength, " ")}]:`, "color: #888", ...args),
|
||||
info: (...args: any[]) => !muted && console.info(`[%c${scope.padEnd(maxLength, " ")}]:`, "color: #888", ...args),
|
||||
warn: (...args: any[]) => !muted && console.warn(`[%c${scope.padEnd(maxLength, " ")}]:`, "color: #888", ...args),
|
||||
error: (...args: any[]) => console.error(`[%c${scope.padEnd(maxLength, " ")}]:`, "color: #f88", ...args),
|
||||
log: (...args: any[]) => !muted && console.log(...s("#888", ...args)),
|
||||
info: (...args: any[]) => !muted && console.info(...s("#888", ...args)),
|
||||
warn: (...args: any[]) => !muted && console.warn(...s("#888", ...args)),
|
||||
error: (...args: any[]) => console.error(...s("#f88", ...args)),
|
||||
group: (...args: any[]) => { if (!muted) { console.groupCollapsed(...s("#888", ...args)); isGrouped = true; } },
|
||||
groupEnd: () => { if (!muted) { console.groupEnd(); isGrouped = false } },
|
||||
mute() {
|
||||
muted = true;
|
||||
},
|
||||
|
@ -1,5 +1,8 @@
|
||||
import type { Graph, NodeRegistry, NodeDefinition, RuntimeExecutor } from "@nodes/types";
|
||||
import { fastHash, concatEncodedArrays, encodeFloat, encodeNestedArray, decodeNestedArray } from "@nodes/utils"
|
||||
import { fastHash, concatEncodedArrays, encodeFloat, decodeNestedArray } from "@nodes/utils"
|
||||
import { createLogger } from "./helpers";
|
||||
|
||||
const log = createLogger("runtime-executor");
|
||||
|
||||
export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
|
||||
@ -131,7 +134,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
if (input.value !== undefined) {
|
||||
inputs[key] = input.value;
|
||||
} else {
|
||||
console.warn(`Setting ${input.setting} is not defined`);
|
||||
log.warn(`Setting ${input.setting} is not defined`);
|
||||
}
|
||||
} else {
|
||||
inputs[key] = settings[input.setting] as number;
|
||||
@ -160,8 +163,8 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
}
|
||||
|
||||
|
||||
// console.log(" ");
|
||||
// console.log("--> EXECUTING NODE " + node_type.id, node.id);
|
||||
// log.log(" ");
|
||||
// log.log("--> EXECUTING NODE " + node_type.id, node.id);
|
||||
|
||||
|
||||
// execute the node and store the result
|
||||
@ -174,11 +177,11 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
}))}`;
|
||||
|
||||
const a1 = performance.now();
|
||||
// console.log(`${a1 - a0}ms hashed inputs: ${node.id} -> ${cacheKey}`);
|
||||
// log.log(`${a1 - a0}ms hashed inputs: ${node.id} -> ${cacheKey}`);
|
||||
|
||||
if (false && this.cache[cacheKey] && this.cache[cacheKey].eol > Date.now()) {
|
||||
results[node.id] = this.cache[cacheKey].value;
|
||||
console.log(`Using cached value`);
|
||||
log.log(`Using cached value`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -199,32 +202,32 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
return value;
|
||||
});
|
||||
|
||||
// console.log(transformed_inputs);
|
||||
// log.log(transformed_inputs);
|
||||
|
||||
const a2 = performance.now();
|
||||
|
||||
// console.log(`${a2 - a1}ms TRANSFORMED_INPUTS`);
|
||||
// log.log(`${a2 - a1}ms TRANSFORMED_INPUTS`);
|
||||
|
||||
const encoded_inputs = concatEncodedArrays(transformed_inputs);
|
||||
const a3 = performance.now();
|
||||
console.groupCollapsed(`executing ${node_type.id || node.id}`);
|
||||
console.log(`Inputs:`, transformed_inputs);
|
||||
console.log(`Encoded Inputs:`, encoded_inputs);
|
||||
log.group(`executing ${node_type.id || node.id}`);
|
||||
log.log(`Inputs:`, transformed_inputs);
|
||||
log.log(`Encoded Inputs:`, encoded_inputs);
|
||||
results[node.id] = node_type.execute(encoded_inputs);
|
||||
console.log("Result:", results[node.id]);
|
||||
console.log("Result (decoded):", decodeNestedArray(results[node.id]));
|
||||
console.groupEnd();
|
||||
log.log("Result:", results[node.id]);
|
||||
log.log("Result (decoded):", decodeNestedArray(results[node.id]));
|
||||
log.groupEnd();
|
||||
const duration = performance.now() - a3;
|
||||
if (duration > 5) {
|
||||
this.cache[cacheKey] = { eol: Date.now() + 10_000, value: results[node.id] };
|
||||
// console.log(`Caching for 10 seconds`);
|
||||
// log.log(`Caching for 10 seconds`);
|
||||
}
|
||||
// console.log(`${duration}ms Executed`);
|
||||
// log.log(`${duration}ms Executed`);
|
||||
const a4 = performance.now();
|
||||
// console.log(`${a4 - a0}ms e2e duration`);
|
||||
// log.log(`${a4 - a0}ms e2e duration`);
|
||||
} catch (e) {
|
||||
console.groupEnd();
|
||||
console.error(`Error executing node ${node_type.id || node.id}`, e);
|
||||
log.groupEnd();
|
||||
log.error(`Error executing node ${node_type.id || node.id}`, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -65,11 +65,21 @@
|
||||
},
|
||||
shortcuts: {},
|
||||
nodeStore: {},
|
||||
graph: {},
|
||||
graph: {
|
||||
id: "graph",
|
||||
icon: "i-tabler-git-fork",
|
||||
definition: {
|
||||
randomSeed: {
|
||||
type: "boolean",
|
||||
label: "Random Seed",
|
||||
value: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
activeNode: {
|
||||
id: "Active Node",
|
||||
icon: "i-tabler-adjustments",
|
||||
props: { node: undefined, manager },
|
||||
props: { node: undefined, manager: undefined },
|
||||
component: ActiveNode,
|
||||
},
|
||||
};
|
||||
@ -122,18 +132,10 @@
|
||||
graph = templates.tree(store.amount);
|
||||
};
|
||||
|
||||
settings.graph = {
|
||||
icon: "i-tabler-git-fork",
|
||||
id: "graph",
|
||||
settings: writable(ev.detail.values),
|
||||
definition: {
|
||||
randomSeed: {
|
||||
type: "boolean",
|
||||
label: "Random Seed",
|
||||
value: true,
|
||||
},
|
||||
...ev.detail.types,
|
||||
},
|
||||
settings.graph.settings = writable(ev.detail.values);
|
||||
settings.graph.definition = {
|
||||
...settings.graph.definition,
|
||||
...ev.detail.types,
|
||||
};
|
||||
|
||||
settings = settings;
|
||||
|
@ -70,20 +70,27 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
for i in 0..points {
|
||||
let a = i as f64 / (points - 1) as f64;
|
||||
|
||||
let px = Vector2::new(j as f64 + a * length * scale, a * scale as f64);
|
||||
let pz = Vector2::new(a * scale as f64, j as f64 + a * length * scale);
|
||||
let px = Vector2::new(1000.0 + j as f64 + a * length * scale, a * scale as f64);
|
||||
let py = Vector2::new(2000.0 + j as f64 + a * length * scale, a * scale as f64);
|
||||
let pz = Vector2::new(3000.0 + j as f64 + a * length * scale, a * scale as f64);
|
||||
|
||||
let nx = open_simplex_2d(px, &hasher) as f32
|
||||
* strength
|
||||
* 0.1
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
|
||||
let ny = open_simplex_2d(py, &hasher) as f32
|
||||
* strength
|
||||
* 0.1
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
|
||||
let nz = open_simplex_2d(pz, &hasher) as f32
|
||||
* strength
|
||||
* 0.1
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
|
||||
plant[3 + i * 4] = encode_float(decode_float(plant[3 + i * 4]) + nx);
|
||||
plant[4 + i * 4] = encode_float(decode_float(plant[4 + i * 4]) + ny);
|
||||
plant[5 + i * 4] = encode_float(decode_float(plant[5 + i * 4]) + nz);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user