diff --git a/README.md b/README.md index de163e8..0b4078c 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,4 @@ Includes support for the Unity game engine. # Basic components - RoboidControl::Thing -- RoboidControl::LocalParticipant -- RoboidControl::SiteServer \ No newline at end of file +- RoboidControl::Participant diff --git a/src/Participant.cs b/src/Participant.cs index 4fc8489..feb2f05 100644 --- a/src/Participant.cs +++ b/src/Participant.cs @@ -37,25 +37,33 @@ namespace RoboidControl { /// /// The network ID of the participant /// - public byte networkId; + public byte networkId = 0; /// /// The things managed by this participant /// - public readonly List things = new List(); + public readonly List things = new(); public virtual void Update(ulong currentTimeMS = 0) { int n = this.things.Count; for (int ix = 0; ix < n; ix++) { Thing thing = this.things[ix]; if (thing != null) - thing.Update(currentTimeMS, true); + thing.Update(currentTimeMS, true); } - } - public static List participants = new List(); + /// + /// The collection of known participants. + /// + public readonly static List participants = new(); + /// + /// Retrieve a participant using ip address and port number + /// + /// The ip address of the participant + /// The port number used to send messages to the participant + /// The participant or null if it is not found. public static Participant GetParticipant(string ipAddress, int port) { //Console.WriteLine($"Get Participant {ipAddress}:{port}"); foreach (Participant participant in Participant.participants) { @@ -64,14 +72,26 @@ namespace RoboidControl { } return null; } - public static Participant GetParticipant(int participantId) { - //Console.WriteLine($"Get Participant [participantId]"); + /// + /// Retrieve a participant using a network ID + /// + /// The network ID of the participant + /// The participant or null if it is not found. + public static Participant GetParticipant(int networkId) { + //Console.WriteLine($"Get Participant [networkId]"); foreach (Participant participant in Participant.participants) { - if (participant.networkId == participantId) + if (participant.networkId == networkId) return participant; } return null; } + + /// + /// Add a new participant to the collection of participants + /// + /// The IP address of the participant + /// The port used to send messages to this participant + /// The added participant public static Participant AddParticipant(string ipAddress, int port) { Console.WriteLine($"New Participant {ipAddress}:{port}"); Participant participant = new(ipAddress, port) { @@ -80,6 +100,11 @@ namespace RoboidControl { Participant.participants.Add(participant); return participant; } + /// + /// Add a new participant to the collection of participants + /// + /// The participant to add + /// This function only adds the participant if it is not yet in the collection public static void AddParticipant(Participant participant) { Participant foundParticipant = Participant.GetParticipant(participant.networkId); if (foundParticipant == null) diff --git a/src/Thing.cs b/src/Thing.cs index b6d145a..9ebd00f 100644 --- a/src/Thing.cs +++ b/src/Thing.cs @@ -269,7 +269,7 @@ namespace RoboidControl { /// /// Event triggered when the pose has changed /// - public event ChangeHandler OnPoseChanged = null; //delegate { }; + public event ChangeHandler OnPoseChanged = delegate { }; /// /// Boolean indicating that the thing has an updated position ///