ControlCore compatibility

This commit is contained in:
Pascal Serrarens 2024-12-11 11:31:10 +01:00
parent 11a0509ed3
commit 9a5d9544f9
4 changed files with 64 additions and 3 deletions

View File

@ -168,8 +168,8 @@ namespace Passer.Control {
this.thingId = buffer[ix++]; this.thingId = buffer[ix++];
} }
public static bool Send(Client client, byte thingId) { public static bool Send(Client client, byte networkId, byte thingId) {
InvestigateMsg msg = new(client.networkId, thingId); InvestigateMsg msg = new(networkId, thingId);
return SendMsg(client, msg); return SendMsg(client, msg);
} }
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) { public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
@ -406,7 +406,6 @@ namespace Passer.Control {
return SendMsg(client, msg); return SendMsg(client, msg);
} }
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) { public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
UnityEngine.Debug.Log("Receive pose");
if (packetSize != length) if (packetSize != length)
return false; return false;

View File

@ -128,6 +128,7 @@ namespace Passer.Humanoid {
public class HumanoidClient : Client { public class HumanoidClient : Client {
readonly HumanoidPlayer player; readonly HumanoidPlayer player;
public List<Thing> allThings = new();
public HumanoidClient(UdpClient udpClient, string ipAddress, int port, HumanoidPlayer player) : base(udpClient, port) { public HumanoidClient(UdpClient udpClient, string ipAddress, int port, HumanoidPlayer player) : base(udpClient, port) {
this.player = player; this.player = player;
@ -141,7 +142,12 @@ namespace Passer.Humanoid {
player.ProcessNetworkId(this, msg); player.ProcessNetworkId(this, msg);
} }
protected override void ProcessName(NameMsg msg) {
Debug.Log($"Name [{msg.networkId}/{msg.thingId} {msg.name}]");
}
protected override void ProcessModelUrl(ModelUrlMsg msg) { protected override void ProcessModelUrl(ModelUrlMsg msg) {
Debug.Log($"Model [{msg.networkId}/{msg.thingId} {msg.url}]");
int ix = msg.url.LastIndexOf("."); int ix = msg.url.LastIndexOf(".");
if (ix < 0) if (ix < 0)
return; return;
@ -153,6 +159,16 @@ namespace Passer.Humanoid {
player.ProcessGltfModel(msg); player.ProcessGltfModel(msg);
} }
} }
protected override void ProcessPose(PoseMsg msg) {
Debug.Log($"Pose [{msg.networkId}/{msg.thingId}]");
Thing thing = allThings.Find(thing => thing.networkId == msg.networkId && thing.thingId == msg.thingId);
if (thing == null) {
Debug.Log($"Unknown thing [{msg.networkId}/{msg.thingId}]");
thing = Thing.Create(player.gameObject, this, msg.thingId, 0);
InvestigateMsg.Send(this, msg.networkId, msg.thingId);
}
}
} }
protected virtual void Awake() { protected virtual void Awake() {

View File

@ -0,0 +1,44 @@
using UnityEngine;
using Passer.Control;
public class Thing : MonoBehaviour {
public Client client;
public byte networkId;
public byte thingId;
public byte objectType;
//protected Sensor sensor;
protected virtual void Init() {
//if (this.objectType == 2) {
// sensor = this.gameObject.AddComponent<DistanceSensor>();
// sensor.thing = this;
//}
}
public static Thing Create(GameObject obj, Client client, byte objId, byte objType) {
Thing thing = obj.AddComponent<Thing>();
thing.client = client;
thing.thingId = objId;
thing.objectType = objType;
thing.networkId = client.networkId;
thing.Init();
return thing;
}
public virtual Thing CopyTo(GameObject obj) {
//Debug.Log($"copy {obj}");
Thing foundThing = Thing.Create(obj, this.client, this.thingId, this.objectType);
Destroy(this.gameObject);
return foundThing;
}
//public void ProcessBytes(byte[] bytes) {
// if (sensor != null)
// sensor.ProcessBytes(bytes);
//}
//public void Update() {
// if (objectId == 0)
// Debug.Log(this.transform.eulerAngles);
//}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: dbfb00fc659e2d8489a48aafec5ddfc5