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