diff --git a/MonoNet.cs b/MonoNet.cs index 7a7b36b..bb92176 100644 --- a/MonoNet.cs +++ b/MonoNet.cs @@ -2,29 +2,22 @@ using StereoKit; using System; using System.Net; using System.Net.Sockets; -using FlatBuffers; -// using NetData; using System.Threading; using System.Threading.Tasks; using System.Text; public class MonoNet { - public int myID; - public MonoNet(int myID) { - this.myID = myID; + public MonoNet() { + Random rnd = new Random(); + me = new Peer(rnd.Next(1, 256)); // temp, until unique usernames } public Socket socket; - // public NetworkStream stream; byte[] data; int head; + public Peer me; public Peer[] peers; - public Vec3 cursor; // are these stored here??? - public Pose headset; - public Pose offHand; - public Pose mainHand; - public async void Start() { string publicIP, localIP; // GetIPs(); @@ -59,65 +52,36 @@ public class MonoNet { Console.WriteLine("can't connect to the server"); return; } - // ByteBuffer bb = new ByteBuffer(data); - // NetData.Peer peer = NetData.Peer.GetRootAsPeer(bb); - // int id = peer.Id; head = 0; int id = ReadInt(); if (id != 0) { for (int i = 0; i < peers.Length; i++) { if (peers[i] != null) { if (peers[i].id == id) { - // peers[i].cursor = NetVec3(peer.Cursor.Value); peers[i].cursor = ReadVec3(); break; } } else { - // if (peer.Cursor.HasValue) { - // peers[i] = new Peer(id, NetVec3(peer.Cursor.Value)); - // break; - // } - peers[i] = new Peer(id, ReadVec3()); + peers[i] = new Peer(id); + peers[i].cursor = ReadVec3(); break; } } } } - - // FlatBufferBuilder fbb = new FlatBufferBuilder(1024); - // NetData.Peer.StartPeer(fbb); - // NetData.Peer.AddId(fbb, myID); - // NetData.Peer.AddCursor(fbb, Vec3Net(cursor, ref fbb)); - // var p = NetData.Peer.EndPeer(fbb); - // fbb.Finish(p.Value); - // socket.Send(fbb.SizedByteArray()); data = new byte[1024]; head = 0; - WriteInt(myID); - WriteVec3(cursor); + WriteInt(me.id); + WriteVec3(me.cursor); socket.Send(data); - await Task.Delay(100); + await Task.Delay(10); } socket.Close(); } - public Vec3 NetVec3(NetData.Vec3 v) { - return new Vec3(v.X, v.Y, v.Z); - } Offset Vec3Net(Vec3 v, ref FlatBufferBuilder fbb) { - return NetData.Vec3.CreateVec3(fbb, v.x, v.y, v.z); - } - - public Quat NetQuat(NetData.Quat q) { - return new Quat(q.X, q.Y, q.Z, q.W); - } - - public Pose NetPose(NetData.Pose p) { - return new Pose(NetVec3(p.Pos), NetQuat(p.Rot)); - } - int ReadInt() { int value = BitConverter.ToInt32(data, head); head += 4; @@ -179,10 +143,12 @@ public class MonoNet { { public int id; public Vec3 cursor; + // public Pose headset; + // public Pose offHand; + // public Pose mainHand; - public Peer(int id, Vec3 cursor) { + public Peer(int id) { this.id = id; - this.cursor = cursor; } } } diff --git a/NetData/Peer.cs b/NetData/Peer.cs deleted file mode 100644 index fc72922..0000000 --- a/NetData/Peer.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// automatically generated by the FlatBuffers compiler, do not modify -// - -namespace NetData -{ - -using global::System; -using global::System.Collections.Generic; -using global::FlatBuffers; - -public struct Peer : IFlatbufferObject -{ - private Table __p; - public ByteBuffer ByteBuffer { get { return __p.bb; } } - public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_1_12_0(); } - public static Peer GetRootAsPeer(ByteBuffer _bb) { return GetRootAsPeer(_bb, new Peer()); } - public static Peer GetRootAsPeer(ByteBuffer _bb, Peer obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } - public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); } - public Peer __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public int Id { get { int o = __p.__offset(4); return o != 0 ? __p.bb.GetInt(o + __p.bb_pos) : (int)0; } } - public NetData.Pose? Head { get { int o = __p.__offset(6); return o != 0 ? (NetData.Pose?)(new NetData.Pose()).__assign(o + __p.bb_pos, __p.bb) : null; } } - public NetData.Pose? LHand { get { int o = __p.__offset(8); return o != 0 ? (NetData.Pose?)(new NetData.Pose()).__assign(o + __p.bb_pos, __p.bb) : null; } } - public NetData.Pose? RHand { get { int o = __p.__offset(10); return o != 0 ? (NetData.Pose?)(new NetData.Pose()).__assign(o + __p.bb_pos, __p.bb) : null; } } - public NetData.Vec3? Cursor { get { int o = __p.__offset(12); return o != 0 ? (NetData.Vec3?)(new NetData.Vec3()).__assign(o + __p.bb_pos, __p.bb) : null; } } - - public static void StartPeer(FlatBufferBuilder builder) { builder.StartTable(5); } - public static void AddId(FlatBufferBuilder builder, int id) { builder.AddInt(0, id, 0); } - public static void AddHead(FlatBufferBuilder builder, Offset headOffset) { builder.AddStruct(1, headOffset.Value, 0); } - public static void AddLHand(FlatBufferBuilder builder, Offset lHandOffset) { builder.AddStruct(2, lHandOffset.Value, 0); } - public static void AddRHand(FlatBufferBuilder builder, Offset rHandOffset) { builder.AddStruct(3, rHandOffset.Value, 0); } - public static void AddCursor(FlatBufferBuilder builder, Offset cursorOffset) { builder.AddStruct(4, cursorOffset.Value, 0); } - public static Offset EndPeer(FlatBufferBuilder builder) { - int o = builder.EndTable(); - return new Offset(o); - } - public static void FinishPeerBuffer(FlatBufferBuilder builder, Offset offset) { builder.Finish(offset.Value); } - public static void FinishSizePrefixedPeerBuffer(FlatBufferBuilder builder, Offset offset) { builder.FinishSizePrefixed(offset.Value); } -}; - - -} diff --git a/NetData/Pose.cs b/NetData/Pose.cs deleted file mode 100644 index 0c49445..0000000 --- a/NetData/Pose.cs +++ /dev/null @@ -1,38 +0,0 @@ -// -// automatically generated by the FlatBuffers compiler, do not modify -// - -namespace NetData -{ - -using global::System; -using global::System.Collections.Generic; -using global::FlatBuffers; - -public struct Pose : IFlatbufferObject -{ - private Struct __p; - public ByteBuffer ByteBuffer { get { return __p.bb; } } - public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); } - public Pose __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public NetData.Vec3 Pos { get { return (new NetData.Vec3()).__assign(__p.bb_pos + 0, __p.bb); } } - public NetData.Quat Rot { get { return (new NetData.Quat()).__assign(__p.bb_pos + 12, __p.bb); } } - - public static Offset CreatePose(FlatBufferBuilder builder, float pos_X, float pos_Y, float pos_Z, float rot_X, float rot_Y, float rot_Z, float rot_W) { - builder.Prep(4, 28); - builder.Prep(4, 16); - builder.PutFloat(rot_W); - builder.PutFloat(rot_Z); - builder.PutFloat(rot_Y); - builder.PutFloat(rot_X); - builder.Prep(4, 12); - builder.PutFloat(pos_Z); - builder.PutFloat(pos_Y); - builder.PutFloat(pos_X); - return new Offset(builder.Offset); - } -}; - - -} diff --git a/NetData/Quat.cs b/NetData/Quat.cs deleted file mode 100644 index 21fd8b4..0000000 --- a/NetData/Quat.cs +++ /dev/null @@ -1,35 +0,0 @@ -// -// automatically generated by the FlatBuffers compiler, do not modify -// - -namespace NetData -{ - -using global::System; -using global::System.Collections.Generic; -using global::FlatBuffers; - -public struct Quat : IFlatbufferObject -{ - private Struct __p; - public ByteBuffer ByteBuffer { get { return __p.bb; } } - public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); } - public Quat __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public float X { get { return __p.bb.GetFloat(__p.bb_pos + 0); } } - public float Y { get { return __p.bb.GetFloat(__p.bb_pos + 4); } } - public float Z { get { return __p.bb.GetFloat(__p.bb_pos + 8); } } - public float W { get { return __p.bb.GetFloat(__p.bb_pos + 12); } } - - public static Offset CreateQuat(FlatBufferBuilder builder, float X, float Y, float Z, float W) { - builder.Prep(4, 16); - builder.PutFloat(W); - builder.PutFloat(Z); - builder.PutFloat(Y); - builder.PutFloat(X); - return new Offset(builder.Offset); - } -}; - - -} diff --git a/NetData/Vec3.cs b/NetData/Vec3.cs deleted file mode 100644 index 9623a2f..0000000 --- a/NetData/Vec3.cs +++ /dev/null @@ -1,33 +0,0 @@ -// -// automatically generated by the FlatBuffers compiler, do not modify -// - -namespace NetData -{ - -using global::System; -using global::System.Collections.Generic; -using global::FlatBuffers; - -public struct Vec3 : IFlatbufferObject -{ - private Struct __p; - public ByteBuffer ByteBuffer { get { return __p.bb; } } - public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); } - public Vec3 __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public float X { get { return __p.bb.GetFloat(__p.bb_pos + 0); } } - public float Y { get { return __p.bb.GetFloat(__p.bb_pos + 4); } } - public float Z { get { return __p.bb.GetFloat(__p.bb_pos + 8); } } - - public static Offset CreateVec3(FlatBufferBuilder builder, float X, float Y, float Z) { - builder.Prep(4, 12); - builder.PutFloat(Z); - builder.PutFloat(Y); - builder.PutFloat(X); - return new Offset(builder.Offset); - } -}; - - -} diff --git a/Program.cs b/Program.cs index 417462c..7831b27 100644 --- a/Program.cs +++ b/Program.cs @@ -20,8 +20,7 @@ public static class Mono { public static Controller offHand, mainHand; public static void Run() { - Random rnd = new Random(); - MonoNet net = new MonoNet(rnd.Next(1, 256)); // temp, until unique usernames + MonoNet net = new MonoNet(); net.Start(); ColorCube cube = new ColorCube(); @@ -48,10 +47,10 @@ public static class Mono { // stretchCursor.Step(offHand.aim, mainHand.aim); - net.cursor = Vec3.Up * (float)Math.Sin(Time.Total); - net.headset = Input.Head; - net.offHand = offHand.aim; - net.mainHand = mainHand.aim; + 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) { diff --git a/oriels.csproj b/oriels.csproj index a45360d..a7aaa31 100644 --- a/oriels.csproj +++ b/oriels.csproj @@ -7,7 +7,6 @@ - diff --git a/schema.fbs b/schema.fbs deleted file mode 100644 index 4f53089..0000000 --- a/schema.fbs +++ /dev/null @@ -1,31 +0,0 @@ -namespace NetData; - -attribute "priority"; - -struct Vec3 { - x:float; - y:float; - z:float; -} - -struct Quat { - x:float; - y:float; - z:float; - w:float; -} - -struct Pose { - pos:Vec3; - rot:Quat; -} - -table Peer { - id:int; - head:Pose; - l_hand:Pose; - r_hand:Pose; - cursor:Vec3; -} - -root_type Peer; \ No newline at end of file