feat: Implement simulation analyzer module with dedicated types, worker logic, and manufacturer instance UI.

This commit is contained in:
2025-12-29 12:01:53 +05:30
parent 7e33432c4f
commit b7da96e027
3 changed files with 12 additions and 6 deletions

View File

@@ -119,4 +119,5 @@ export interface AnalyzerStatePayload {
speed: number;
isPlaying: boolean;
isPaused: boolean;
forceAnalysis?: boolean;
}

View File

@@ -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;
}
}
}
};

View File

@@ -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;
}