Implement Event monitoring system
Events are tracked and exported Monitoring of telemetry performance greatly optimized Assignment and threat table tracking fixedmaster
parent
0c7d69d632
commit
17987c2c5f
|
@ -94,10 +94,6 @@ public abstract class Agent : MonoBehaviour {
|
||||||
return _isHit;
|
return _isHit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsMiss() {
|
|
||||||
return _isMiss;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void TerminateAgent() {
|
public void TerminateAgent() {
|
||||||
_flightPhase = FlightPhase.TERMINATED;
|
_flightPhase = FlightPhase.TERMINATED;
|
||||||
transform.position = new Vector3(0, 0, 0);
|
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.
|
// Mark the agent as having hit the target or been hit.
|
||||||
public void HandleInterceptHit() {
|
public void HandleInterceptHit(Agent otherAgent) {
|
||||||
_isHit = true;
|
_isHit = true;
|
||||||
if (this is Interceptor interceptor && _target is Threat threat) {
|
if (this is Interceptor interceptor && otherAgent is Threat threat) {
|
||||||
OnInterceptHit?.Invoke(interceptor, 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);
|
OnInterceptHit?.Invoke(interceptorTarget, threatAgent);
|
||||||
}
|
}
|
||||||
TerminateAgent();
|
TerminateAgent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleInterceptMiss() {
|
public void HandleInterceptMiss() {
|
||||||
_isMiss = true;
|
|
||||||
if (_target != null) {
|
if (_target != null) {
|
||||||
if (this is Interceptor interceptor && _target is Threat threat) {
|
if (this is Interceptor interceptor && _target is Threat threat) {
|
||||||
OnInterceptMiss?.Invoke(interceptor, threat);
|
OnInterceptMiss?.Invoke(interceptor, threat);
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class IADS : MonoBehaviour {
|
||||||
private List<ThreatData> _threatTable = new List<ThreatData>();
|
private List<ThreatData> _threatTable = new List<ThreatData>();
|
||||||
private Dictionary<Threat, ThreatData> _threatDataMap = new Dictionary<Threat, ThreatData>();
|
private Dictionary<Threat, ThreatData> _threatDataMap = new Dictionary<Threat, ThreatData>();
|
||||||
|
|
||||||
private List<Interceptor> _assignentQueue = new List<Interceptor>();
|
private List<Interceptor> _assignmentQueue = new List<Interceptor>();
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
if (Instance == null) {
|
if (Instance == null) {
|
||||||
|
@ -39,18 +39,18 @@ public class IADS : MonoBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LateUpdate() {
|
public void LateUpdate() {
|
||||||
if (_assignentQueue.Count > 0) {
|
if (_assignmentQueue.Count > 0) {
|
||||||
AssignInterceptorsToThreats(_assignentQueue);
|
AssignInterceptorsToThreats(_assignmentQueue);
|
||||||
_assignentQueue.Clear();
|
_assignmentQueue.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RequestThreatAssignment(List<Interceptor> interceptors) {
|
public void RequestThreatAssignment(List<Interceptor> interceptors) {
|
||||||
_assignentQueue.AddRange(interceptors);
|
_assignmentQueue.AddRange(interceptors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RequestThreatAssignment(Interceptor interceptor) {
|
public void RequestThreatAssignment(Interceptor interceptor) {
|
||||||
_assignentQueue.Add(interceptor);
|
_assignmentQueue.Add(interceptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ public class IADS : MonoBehaviour {
|
||||||
private void RegisterSimulationEnded() {
|
private void RegisterSimulationEnded() {
|
||||||
_threatTable.Clear();
|
_threatTable.Clear();
|
||||||
_threatDataMap.Clear();
|
_threatDataMap.Clear();
|
||||||
_assignentQueue.Clear();
|
_assignmentQueue.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -87,8 +87,8 @@ public class Interceptor : Agent {
|
||||||
// Set green for hit
|
// Set green for hit
|
||||||
markerObject.GetComponent<Renderer>().material.color = new Color(0, 1, 0, 0.15f);
|
markerObject.GetComponent<Renderer>().material.color = new Color(0, 1, 0, 0.15f);
|
||||||
// Mark both this agent and the other agent as hit
|
// Mark both this agent and the other agent as hit
|
||||||
this.HandleInterceptHit();
|
this.HandleInterceptHit(otherAgent);
|
||||||
otherAgent.HandleInterceptHit();
|
otherAgent.HandleInterceptHit(otherAgent);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Set red for miss
|
// Set red for miss
|
||||||
|
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: -5
|
||||||
icon: {instanceID: 0}
|
icon: {instanceID: 0}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
|
|
|
@ -93,8 +93,9 @@ public class SimManager : MonoBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartSimulation() {
|
public void StartSimulation() {
|
||||||
InitializeSimulation();
|
|
||||||
OnSimulationStarted?.Invoke();
|
OnSimulationStarted?.Invoke();
|
||||||
|
InitializeSimulation();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PauseSimulation() {
|
public void PauseSimulation() {
|
||||||
|
@ -112,6 +113,9 @@ public class SimManager : MonoBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeSimulation() {
|
private void InitializeSimulation() {
|
||||||
|
// Invoke the simulation started event to let listeners
|
||||||
|
// know to invoke their own handler behavior
|
||||||
|
OnSimulationStarted?.Invoke();
|
||||||
List<Interceptor> missiles = new List<Interceptor>();
|
List<Interceptor> missiles = new List<Interceptor>();
|
||||||
// Create missiles based on config
|
// Create missiles based on config
|
||||||
foreach (var swarmConfig in simulationConfig.interceptor_swarm_configs) {
|
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() {
|
public void AssignInterceptorsToThreats() {
|
||||||
|
@ -306,7 +306,7 @@ public class SimManager : MonoBehaviour {
|
||||||
// Check if all missiles have terminated
|
// Check if all missiles have terminated
|
||||||
bool allInterceptorsTerminated = true;
|
bool allInterceptorsTerminated = true;
|
||||||
foreach (var interceptor in _interceptorObjects) {
|
foreach (var interceptor in _interceptorObjects) {
|
||||||
if (interceptor != null && !interceptor.IsHit() && !interceptor.IsMiss()) {
|
if (interceptor != null && interceptor.GetFlightPhase() != Agent.FlightPhase.TERMINATED) {
|
||||||
allInterceptorsTerminated = false;
|
allInterceptorsTerminated = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: 100
|
||||||
icon: {instanceID: 0}
|
icon: {instanceID: 0}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
|
|
Loading…
Reference in New Issue