< Summary

Class:CommsManager
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Managers/CommsManager.cs
Covered lines:28
Uncovered lines:9
Coverable lines:37
Total lines:60
Line coverage:75.6% (28 of 37)
Covered branches:0
Total branches:0
Covered methods:8
Total methods:11
Method coverage:72.7% (8 of 11)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CommsManager()0%2100%
AddNode(...)0%110100%
ContainsNode(...)0%2100%
Awake()0%3.713057.14%
Start()0%110100%
FixedUpdate()0%110100%
SendMessage(...)0%2100%
RegisterSimulationEnded()0%110100%
RegisterNewAgent(...)0%220100%

File(s)

/github/workspace/Assets/Scripts/Managers/CommsManager.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4// The comunication manager manages the communication nodes and handles communication between
 5// agents.
 6public class CommsManager : MonoBehaviour {
 37  public static CommsManager Instance { get; private set; }
 8
 9  // Mailbox for queued messages.
 010  private readonly Mailbox _mailbox = new Mailbox();
 11
 12  // Map from agent to the communication node.
 013  private readonly HashSet<CommsNode> _nodes = new HashSet<CommsNode>();
 14
 15  // Add a communication node. This function should only be used by the IADS and in tests.
 116  public void AddNode(CommsNode node) => _nodes.Add(node);
 17
 018  public bool ContainsNode(CommsNode node) => _nodes.Contains(node);
 19
 120  private void Awake() {
 121    if (Instance != null && Instance != this) {
 022      Destroy(gameObject);
 023      return;
 24    }
 125    Instance = this;
 126  }
 27
 128  private void Start() {
 129    SimManager.Instance.OnSimulationStarted += _mailbox.Clear;
 130    SimManager.Instance.OnSimulationEnded += RegisterSimulationEnded;
 131    SimManager.Instance.OnNewInterceptor += RegisterNewAgent;
 132    SimManager.Instance.OnNewLauncher += RegisterNewAgent;
 133  }
 34
 7735  private void FixedUpdate() {
 7736    _mailbox.Deliver();
 7737  }
 38
 039  public void SendMessage(Message message) {
 040    _mailbox.Send(message);
 041  }
 42
 1143  private void RegisterSimulationEnded() {
 1144    _nodes.Clear();
 1145    _mailbox.Clear();
 1146  }
 47
 4048  private void RegisterNewAgent(IAgent agent) {
 5449    if (agent.CommsNode != null) {
 1450      _nodes.Add(agent.CommsNode);
 1451      return;
 52    }
 53
 2654    var commsNode = new CommsNode(agent.StaticConfig.AgentType);
 2655    agent.CommsNode = commsNode;
 2656    agent.OnTerminated +=
 057        _ => _nodes.Remove(commsNode);
 2658    _nodes.Add(commsNode);
 4059  }
 60}