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; speed: number;
isPlaying: boolean; isPlaying: boolean;
isPaused: boolean; isPaused: boolean;
forceAnalysis?: boolean;
} }

View File

@@ -26,6 +26,7 @@ import { materialHistory } from "./analyzer.state"; // Import readonly
// Use local variable. // Use local variable.
let localPreviousMaterials: any[] = []; let localPreviousMaterials: any[] = [];
let initialStartTime: string | null = null; // Track start time locally let initialStartTime: string | null = null; // Track start time locally
let lastAnalysisTime = 0;
onmessage = (e: MessageEvent<WorkerMessage>) => { onmessage = (e: MessageEvent<WorkerMessage>) => {
const { type, payload } = e.data; const { type, payload } = e.data;
@@ -50,14 +51,18 @@ onmessage = (e: MessageEvent<WorkerMessage>) => {
// Stopped // Stopped
resetState(); resetState();
localPreviousMaterials = []; localPreviousMaterials = [];
lastAnalysisTime = 0;
} else { } else {
// 1. Tracking // 1. Tracking - ALWAYS run to capture transient states
runTrackingLogic(payload); runTrackingLogic(payload);
// 2. Analysis // 2. Analysis - ONLY run if forced or throttled (1s)
const result = performAnalysis(payload); const now = Date.now();
if (payload.forceAnalysis || now - lastAnalysisTime >= 1000) {
postMessage(result); const result = performAnalysis(payload);
postMessage(result);
lastAnalysisTime = now;
}
} }
} }
}; };

View File

@@ -160,7 +160,7 @@ function ManufacturerInstance({ human }: { readonly human: HumanStatus }) {
const now = performance.now(); const now = performance.now();
if (!processStartTimeRef.current || !(action as HumanAction).processTime || !action) { if (!processStartTimeRef.current || !(action as HumanAction)?.processTime || !action) {
return; return;
} }