From 17987c2c5fe5401cdadb774c5b62bb15cfff6f3e Mon Sep 17 00:00:00 2001 From: Daniel Lovell Date: Wed, 2 Oct 2024 00:30:01 -0700 Subject: [PATCH] Implement Event monitoring system Events are tracked and exported Monitoring of telemetry performance greatly optimized Assignment and threat table tracking fixed --- Assets/Scripts/Agent.cs | 11 +++-------- Assets/Scripts/IADS/IADS.cs | 14 +++++++------- Assets/Scripts/Interceptor.cs | 4 ++-- Assets/Scripts/Monitor.cs.meta | 2 +- Assets/Scripts/SimManager.cs | 12 ++++++------ Assets/Scripts/SimManager.cs.meta | 2 +- 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Assets/Scripts/Agent.cs b/Assets/Scripts/Agent.cs index 251cb13..c558055 100644 --- a/Assets/Scripts/Agent.cs +++ b/Assets/Scripts/Agent.cs @@ -94,10 +94,6 @@ public abstract class Agent : MonoBehaviour { return _isHit; } - public bool IsMiss() { - return _isMiss; - } - public void TerminateAgent() { _flightPhase = FlightPhase.TERMINATED; transform.position = new Vector3(0, 0, 0); @@ -105,18 +101,17 @@ public abstract class Agent : MonoBehaviour { } // Mark the agent as having hit the target or been hit. - public void HandleInterceptHit() { + public void HandleInterceptHit(Agent otherAgent) { _isHit = true; - if (this is Interceptor interceptor && _target is Threat threat) { + if (this is Interceptor interceptor && otherAgent is Threat threat) { OnInterceptHit?.Invoke(interceptor, threat); - } else if (this is Threat threatAgent && _target is Interceptor interceptorTarget) { + } else if (this is Threat threatAgent && otherAgent is Interceptor interceptorTarget) { OnInterceptHit?.Invoke(interceptorTarget, threatAgent); } TerminateAgent(); } public void HandleInterceptMiss() { - _isMiss = true; if (_target != null) { if (this is Interceptor interceptor && _target is Threat threat) { OnInterceptMiss?.Invoke(interceptor, threat); diff --git a/Assets/Scripts/IADS/IADS.cs b/Assets/Scripts/IADS/IADS.cs index e7b525c..13ac1ff 100644 --- a/Assets/Scripts/IADS/IADS.cs +++ b/Assets/Scripts/IADS/IADS.cs @@ -19,7 +19,7 @@ public class IADS : MonoBehaviour { private List _threatTable = new List(); private Dictionary _threatDataMap = new Dictionary(); - private List _assignentQueue = new List(); + private List _assignmentQueue = new List(); private void Awake() { if (Instance == null) { @@ -39,18 +39,18 @@ public class IADS : MonoBehaviour { } public void LateUpdate() { - if (_assignentQueue.Count > 0) { - AssignInterceptorsToThreats(_assignentQueue); - _assignentQueue.Clear(); + if (_assignmentQueue.Count > 0) { + AssignInterceptorsToThreats(_assignmentQueue); + _assignmentQueue.Clear(); } } public void RequestThreatAssignment(List interceptors) { - _assignentQueue.AddRange(interceptors); + _assignmentQueue.AddRange(interceptors); } public void RequestThreatAssignment(Interceptor interceptor) { - _assignentQueue.Add(interceptor); + _assignmentQueue.Add(interceptor); } @@ -140,7 +140,7 @@ public class IADS : MonoBehaviour { private void RegisterSimulationEnded() { _threatTable.Clear(); _threatDataMap.Clear(); - _assignentQueue.Clear(); + _assignmentQueue.Clear(); } } \ No newline at end of file diff --git a/Assets/Scripts/Interceptor.cs b/Assets/Scripts/Interceptor.cs index 7fa2d9d..d763773 100644 --- a/Assets/Scripts/Interceptor.cs +++ b/Assets/Scripts/Interceptor.cs @@ -87,8 +87,8 @@ public class Interceptor : Agent { // Set green for hit markerObject.GetComponent().material.color = new Color(0, 1, 0, 0.15f); // Mark both this agent and the other agent as hit - this.HandleInterceptHit(); - otherAgent.HandleInterceptHit(); + this.HandleInterceptHit(otherAgent); + otherAgent.HandleInterceptHit(otherAgent); } else { // Set red for miss diff --git a/Assets/Scripts/Monitor.cs.meta b/Assets/Scripts/Monitor.cs.meta index ec180b2..edcc466 100644 --- a/Assets/Scripts/Monitor.cs.meta +++ b/Assets/Scripts/Monitor.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: -5 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Assets/Scripts/SimManager.cs b/Assets/Scripts/SimManager.cs index e56eabd..0559cd5 100644 --- a/Assets/Scripts/SimManager.cs +++ b/Assets/Scripts/SimManager.cs @@ -93,8 +93,9 @@ public class SimManager : MonoBehaviour { } public void StartSimulation() { - InitializeSimulation(); OnSimulationStarted?.Invoke(); + InitializeSimulation(); + } public void PauseSimulation() { @@ -112,6 +113,9 @@ public class SimManager : MonoBehaviour { } private void InitializeSimulation() { + // Invoke the simulation started event to let listeners + // know to invoke their own handler behavior + OnSimulationStarted?.Invoke(); List missiles = new List(); // Create missiles based on config foreach (var swarmConfig in simulationConfig.interceptor_swarm_configs) { @@ -128,10 +132,6 @@ public class SimManager : MonoBehaviour { } } - - // Invoke the simulation started event to let listeners - // know to invoke their own handler behavior - OnSimulationStarted?.Invoke(); } public void AssignInterceptorsToThreats() { @@ -306,7 +306,7 @@ public class SimManager : MonoBehaviour { // Check if all missiles have terminated bool allInterceptorsTerminated = true; foreach (var interceptor in _interceptorObjects) { - if (interceptor != null && !interceptor.IsHit() && !interceptor.IsMiss()) { + if (interceptor != null && interceptor.GetFlightPhase() != Agent.FlightPhase.TERMINATED) { allInterceptorsTerminated = false; break; } diff --git a/Assets/Scripts/SimManager.cs.meta b/Assets/Scripts/SimManager.cs.meta index 0800619..5f75a53 100644 --- a/Assets/Scripts/SimManager.cs.meta +++ b/Assets/Scripts/SimManager.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: 100 icon: {instanceID: 0} userData: assetBundleName: