diff --git a/MonoNet.cs b/MonoNet.cs index 85d568a..7697e3e 100644 --- a/MonoNet.cs +++ b/MonoNet.cs @@ -4,7 +4,6 @@ using System.Net; using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; -using System.Text; public class MonoNet { public MonoNet() { @@ -40,34 +39,43 @@ public class MonoNet { EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ip), 1234); socket.Connect(serverEndPoint); data = new byte[1024]; - peers = new Peer[4]; + peers = new Peer[64]; - Thread.Sleep(1000); + Thread.Sleep(1000); // useful? bool running = true; while (running) { while (socket.Available > 0) { try {socket.Receive(data, 0, data.Length, SocketFlags.None);} catch (Exception e) { - Console.WriteLine("can't connect to the server"); + Console.WriteLine($"can't connect to the server: {e}"); return; } head = 0; int id = ReadInt(); if (id != 0) { + int index = -1; for (int i = 0; i < peers.Length; i++) { if (peers[i] != null) { if (peers[i].id == id) { - peers[i].cursor = ReadVec3(); + index = i; break; } } else { peers[i] = new Peer(id); - peers[i].cursor = ReadVec3(); + index = i; break; } } + if (index == -1) { + Console.WriteLine("too many peers"); + return; + } + peers[index].cursor = ReadVec3(); + peers[index].headset = ReadPose(); + peers[index].offHand = ReadPose(); + peers[index].mainHand = ReadPose(); } } @@ -75,6 +83,9 @@ public class MonoNet { head = 0; WriteInt(me.id); WriteVec3(me.cursor); + WritePose(me.headset); + WritePose(me.offHand); + WritePose(me.mainHand); socket.Send(data); await Task.Delay(1); @@ -143,9 +154,9 @@ public class MonoNet { { public int id; public Vec3 cursor; - // public Pose headset; - // public Pose offHand; - // public Pose mainHand; + public Pose headset; + public Pose offHand; + public Pose mainHand; public Peer(int id) { this.id = id; diff --git a/Program.cs b/Program.cs index 7831b27..1c9e6c5 100644 --- a/Program.cs +++ b/Program.cs @@ -23,12 +23,12 @@ public static class Mono { MonoNet net = new MonoNet(); net.Start(); - ColorCube cube = new ColorCube(); - OrbitalView.strength = 4; - OrbitalView.distance = 0.4f; - cube.thickness = 0.01f; + // ColorCube cube = new ColorCube(); + // OrbitalView.strength = 4; + // OrbitalView.distance = 0.4f; + // cube.thickness = 0.01f; - // StretchCursor stretchCursor = new StretchCursor(); + StretchCursor stretchCursor = new StretchCursor(); // ReachCursor reachCursor = new ReachCursor(); // SupineCursor supineCursor = new SupineCursor(); // ClawCursor clawCursor = new ClawCursor(); @@ -36,28 +36,28 @@ public static class Mono { // Oriel oriel = new Oriel(); // oriel.Start(); - Lerper lerper = new Lerper(); + // Lerper lerper = new Lerper(); while (SK.Step(() => { offHand = Input.Controller(Handed.Left); mainHand = Input.Controller(Handed.Right); - mainHand.aim = Input.Hand(Handed.Right).palm; - - // stretchCursor.Step(offHand.aim, mainHand.aim); + // mainHand.aim = Input.Hand(Handed.Right).palm; - net.me.cursor = Vec3.Up * (float)Math.Sin(Time.Total); - // net.me.headset = Input.Head; - // net.me.offHand = offHand.aim; - // net.me.mainHand = mainHand.aim; + stretchCursor.Step(offHand.aim, mainHand.aim); + net.me.cursor = stretchCursor.pos; + // net.me.cursor = Vec3.Up * (float)Math.Sin(Time.Total); + net.me.headset = Input.Head; + net.me.offHand = offHand.aim; + net.me.mainHand = mainHand.aim; for (int i = 0; i < net.peers.Length; i++) { MonoNet.Peer peer = net.peers[i]; if (peer != null) { net.Cubee(Matrix.TRS(peer.cursor, Quat.Identity, Vec3.One * 0.05f)); - // Cubee(NetPose(peer.Head.Value).ToMatrix(Vec3.One * 0.3f)); - // Cubee(NetPose(peer.LHand.Value).ToMatrix(Vec3.One * 0.1f)); - // Cubee(NetPose(peer.RHand.Value).ToMatrix(Vec3.One * 0.1f)); + net.Cubee(peer.headset.ToMatrix(Vec3.One * 0.3f)); + net.Cubee(peer.offHand.ToMatrix(Vec3.One * 0.1f)); + net.Cubee(peer.mainHand.ToMatrix(Vec3.One * 0.1f)); } }