Static participant list
This commit is contained in:
parent
97fdd74950
commit
86b12a7326
@ -33,7 +33,6 @@ namespace RoboidControl.Unity {
|
||||
}
|
||||
siteServer.site.Add(thing);
|
||||
core.OnPoseChanged += PoseChanged;
|
||||
//core.OnNameChanged += NameChanged;
|
||||
}
|
||||
|
||||
public static Thing Create(RoboidControl.Thing core) {
|
||||
@ -53,7 +52,6 @@ namespace RoboidControl.Unity {
|
||||
gameObj.transform.localRotation = core.orientation.ToQuaternion();
|
||||
|
||||
core.OnPoseChanged += component.PoseChanged;
|
||||
//core.OnNameChanged += component.NameChanged;
|
||||
return component;
|
||||
}
|
||||
|
||||
@ -104,12 +102,6 @@ namespace RoboidControl.Unity {
|
||||
this.transform.localRotation = core.orientation.ToQuaternion();
|
||||
}
|
||||
|
||||
private void NameChanged() {
|
||||
Debug.Log($"{this} name changed");
|
||||
if (this.gameObject.name != core.name)
|
||||
this.gameObject.name = core.name;
|
||||
}
|
||||
|
||||
private IEnumerator LoadJPG() {
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(core.modelUrl);
|
||||
yield return request.SendWebRequest();
|
||||
|
@ -139,9 +139,10 @@ namespace RoboidControl {
|
||||
|
||||
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
||||
public override byte Serialize(ref byte[] buffer) {
|
||||
|
||||
if (poseType == 0)
|
||||
return 0;
|
||||
#if DEBUG
|
||||
// System.Console.WriteLine($"Send PoseMsg [{this.networkId}/{this.thingId}] {this.poseType}");
|
||||
System.Console.WriteLine($"Send PoseMsg [{this.networkId}/{this.thingId}] {this.poseType}");
|
||||
#endif
|
||||
|
||||
byte ix = 0;
|
||||
|
@ -54,6 +54,38 @@ namespace RoboidControl {
|
||||
|
||||
}
|
||||
|
||||
public static List<Participant> participants = new List<Participant>();
|
||||
|
||||
public static Participant GetParticipant(string ipAddress, int port) {
|
||||
//Console.WriteLine($"Get Participant {ipAddress}:{port}");
|
||||
foreach (Participant participant in Participant.participants) {
|
||||
if (participant.ipAddress == ipAddress && participant.port == port)
|
||||
return participant;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static Participant GetParticipant(int participantId) {
|
||||
//Console.WriteLine($"Get Participant [participantId]");
|
||||
foreach (Participant participant in Participant.participants) {
|
||||
if (participant.networkId == participantId)
|
||||
return participant;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static Participant AddParticipant(string ipAddress, int port) {
|
||||
Console.WriteLine($"New Participant {ipAddress}:{port}");
|
||||
Participant participant = new(ipAddress, port) {
|
||||
networkId = (byte)(Participant.participants.Count + 1)
|
||||
};
|
||||
Participant.participants.Add(participant);
|
||||
return participant;
|
||||
}
|
||||
public static void AddParticipant(Participant participant) {
|
||||
Participant foundParticipant = Participant.GetParticipant(participant.networkId);
|
||||
if (foundParticipant == null)
|
||||
Participant.participants.Add(participant);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a thing with the given ids
|
||||
/// </summary>
|
||||
|
@ -69,24 +69,24 @@ namespace RoboidControl {
|
||||
return isolatedParticipant;
|
||||
}
|
||||
|
||||
public List<Participant> owners = new List<Participant>();
|
||||
// public List<Participant> owners = new List<Participant>();
|
||||
|
||||
public Participant GetParticipant(string ipAddress, int port) {
|
||||
//Console.WriteLine($"Get Participant {ipAddress}:{port}");
|
||||
foreach (Participant sender in owners) {
|
||||
if (sender.ipAddress == ipAddress && sender.port == port)
|
||||
return sender;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Participant AddParticipant(string ipAddress, int port) {
|
||||
Console.WriteLine($"New Participant {ipAddress}:{port}");
|
||||
Participant participant = new(ipAddress, port) {
|
||||
networkId = (byte)(this.owners.Count + 1)
|
||||
};
|
||||
owners.Add(participant);
|
||||
return participant;
|
||||
}
|
||||
// public Participant GetParticipant(string ipAddress, int port) {
|
||||
// //Console.WriteLine($"Get Participant {ipAddress}:{port}");
|
||||
// foreach (Participant sender in owners) {
|
||||
// if (sender.ipAddress == ipAddress && sender.port == port)
|
||||
// return sender;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
// public Participant AddParticipant(string ipAddress, int port) {
|
||||
// Console.WriteLine($"New Participant {ipAddress}:{port}");
|
||||
// Participant participant = new(ipAddress, port) {
|
||||
// networkId = (byte)(this.owners.Count + 1)
|
||||
// };
|
||||
// owners.Add(participant);
|
||||
// return participant;
|
||||
// }
|
||||
|
||||
// protected readonly Dictionary<byte, Func<Participant, byte, byte, Thing>> thingMsgProcessors = new();
|
||||
|
||||
@ -143,8 +143,8 @@ namespace RoboidControl {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int ownerIx = 0; ownerIx < this.owners.Count; ownerIx++) {
|
||||
Participant owner = this.owners[ownerIx];
|
||||
for (int ownerIx = 0; ownerIx < Participant.participants.Count; ownerIx++) {
|
||||
Participant owner = Participant.participants[ownerIx];
|
||||
owner.Update(currentTimeMS);
|
||||
}
|
||||
}
|
||||
@ -315,9 +315,9 @@ namespace RoboidControl {
|
||||
}
|
||||
|
||||
protected virtual void Process(Participant sender, PoseMsg msg) {
|
||||
// #if DEBUG
|
||||
// Console.WriteLine($"Participant: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}");
|
||||
// #endif
|
||||
#if DEBUG
|
||||
Console.WriteLine($"Participant: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}");
|
||||
#endif
|
||||
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||
if (thing != null) {
|
||||
if ((msg.poseType & PoseMsg.Pose_Position) != 0)
|
||||
|
@ -39,8 +39,9 @@ namespace RoboidControl {
|
||||
_touchedSomething = value;
|
||||
if (thisParticipant != null && this.owner != thisParticipant) {
|
||||
BinaryMsg msg = new(networkId, this);
|
||||
foreach (Participant remoteParticipant in thisParticipant.owners)
|
||||
thisParticipant.Send(remoteParticipant, msg);
|
||||
this.thisParticipant.Send(this.owner, msg);
|
||||
// foreach (Participant remoteParticipant in thisParticipant.participants)
|
||||
// thisParticipant.Send(remoteParticipant, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user