cleaned out
This commit is contained in:
parent
14bddf6dd0
commit
c6d1859a52
8 changed files with 18 additions and 234 deletions
60
MonoNet.cs
60
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<NetData.Vec3> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
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<NetData.Pose> headOffset) { builder.AddStruct(1, headOffset.Value, 0); }
|
||||
public static void AddLHand(FlatBufferBuilder builder, Offset<NetData.Pose> lHandOffset) { builder.AddStruct(2, lHandOffset.Value, 0); }
|
||||
public static void AddRHand(FlatBufferBuilder builder, Offset<NetData.Pose> rHandOffset) { builder.AddStruct(3, rHandOffset.Value, 0); }
|
||||
public static void AddCursor(FlatBufferBuilder builder, Offset<NetData.Vec3> cursorOffset) { builder.AddStruct(4, cursorOffset.Value, 0); }
|
||||
public static Offset<NetData.Peer> EndPeer(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
return new Offset<NetData.Peer>(o);
|
||||
}
|
||||
public static void FinishPeerBuffer(FlatBufferBuilder builder, Offset<NetData.Peer> offset) { builder.Finish(offset.Value); }
|
||||
public static void FinishSizePrefixedPeerBuffer(FlatBufferBuilder builder, Offset<NetData.Peer> offset) { builder.FinishSizePrefixed(offset.Value); }
|
||||
};
|
||||
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
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<NetData.Pose> 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<NetData.Pose>(builder.Offset);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
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<NetData.Quat> 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<NetData.Quat>(builder.Offset);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
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<NetData.Vec3> 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<NetData.Vec3>(builder.Offset);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
11
Program.cs
11
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) {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FlatBuffers.Core" Version="1.12.0" />
|
||||
<PackageReference Include="StereoKit" Version="0.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
31
schema.fbs
31
schema.fbs
|
@ -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;
|
Loading…
Add table
Reference in a new issue