feat: Implement simulation analyzer module with dedicated types, worker logic, and manufacturer instance UI.
This commit is contained in:
@@ -119,4 +119,5 @@ export interface AnalyzerStatePayload {
|
||||
speed: number;
|
||||
isPlaying: boolean;
|
||||
isPaused: boolean;
|
||||
forceAnalysis?: boolean;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import { materialHistory } from "./analyzer.state"; // Import readonly
|
||||
// Use local variable.
|
||||
let localPreviousMaterials: any[] = [];
|
||||
let initialStartTime: string | null = null; // Track start time locally
|
||||
let lastAnalysisTime = 0;
|
||||
|
||||
onmessage = (e: MessageEvent<WorkerMessage>) => {
|
||||
const { type, payload } = e.data;
|
||||
@@ -50,14 +51,18 @@ onmessage = (e: MessageEvent<WorkerMessage>) => {
|
||||
// Stopped
|
||||
resetState();
|
||||
localPreviousMaterials = [];
|
||||
lastAnalysisTime = 0;
|
||||
} else {
|
||||
// 1. Tracking
|
||||
// 1. Tracking - ALWAYS run to capture transient states
|
||||
runTrackingLogic(payload);
|
||||
|
||||
// 2. Analysis
|
||||
const result = performAnalysis(payload);
|
||||
|
||||
postMessage(result);
|
||||
// 2. Analysis - ONLY run if forced or throttled (1s)
|
||||
const now = Date.now();
|
||||
if (payload.forceAnalysis || now - lastAnalysisTime >= 1000) {
|
||||
const result = performAnalysis(payload);
|
||||
postMessage(result);
|
||||
lastAnalysisTime = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -160,7 +160,7 @@ function ManufacturerInstance({ human }: { readonly human: HumanStatus }) {
|
||||
|
||||
const now = performance.now();
|
||||
|
||||
if (!processStartTimeRef.current || !(action as HumanAction).processTime || !action) {
|
||||
if (!processStartTimeRef.current || !(action as HumanAction)?.processTime || !action) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user