networked spatial w/20s of latency

This commit is contained in:
spatialfree 2021-11-09 19:14:50 -05:00
parent a1c6aa1f6e
commit d1d5f16359
2 changed files with 34 additions and 19 deletions

View file

@ -24,6 +24,8 @@ public static class Mono {
public static Controller offHand, mainHand; public static Controller offHand, mainHand;
public static Model model = Model.FromFile("cursor.glb", Shader.Default);
public static void Run() { public static void Run() {
void GetIPs() void GetIPs()
{ {
@ -41,8 +43,8 @@ public static class Mono {
Peer peer0 = new Peer("peer0"); Peer peer0 = new Peer("peer0");
Peer peer1 = new Peer("peer1"); Peer peer1 = new Peer("peer1");
peer0.Start(1, true); peer0.Start(false);
peer1.Start(2, false); peer1.Start(false);
ColorCube cube = new ColorCube(); ColorCube cube = new ColorCube();
OrbitalView.strength = 4; OrbitalView.strength = 4;
@ -61,6 +63,12 @@ public static class Mono {
offHand = Input.Controller(Handed.Left); offHand = Input.Controller(Handed.Left);
mainHand = Input.Controller(Handed.Right); mainHand = Input.Controller(Handed.Right);
peer0.cursor = offHand.aim.position * new Vec3(1,1,-1);
peer1.cursor = mainHand.aim.position * new Vec3(1,1,-1);
model.Draw(Matrix.TS(peer0.peerCursor, 0.1f));
model.Draw(Matrix.TS(peer1.peerCursor, 0.1f));
// Matrix orbitMatrix = OrbitalView.transform; // Matrix orbitMatrix = OrbitalView.transform;
// cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix); // cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix);
// Default.MaterialHand["color"] = cube.color; // Default.MaterialHand["color"] = cube.color;
@ -92,33 +100,37 @@ public class Peer {
this.name = name; this.name = name;
} }
public async void Start(int increment, bool log) { public Vec3 cursor; // is this stored here???
public Vec3 peerCursor;
public async void Start(bool log) {
int port = 1234; int port = 1234;
string serverIP = "139.177.201.219"; string serverIP = "139.177.201.219";
// try connecting to the server // try connecting to the server
if (log) Console.WriteLine("{0} attempting to connect to server...", name); if (log) Console.WriteLine($"{name} attempting to connect to server...");
// create a new socket
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
// server endpoint
EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(serverIP), port); EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(serverIP), port);
socket.Connect(serverEndPoint); socket.Connect(serverEndPoint);
// send a message to the server
if (log) Console.WriteLine("{0} sending message to server...", name);
int test = 0;
// send every 0.1 seconds // send every 0.1 seconds
while (true) { while (true) {
byte[] data = new byte[1024];
int dataPos;
// send a message to the server // send a message to the server
test += increment; dataPos = 0;
socket.SendTo(BitConverter.GetBytes(test), serverEndPoint); BitConverter.GetBytes(cursor.x).CopyTo(data, dataPos); dataPos += 4;
BitConverter.GetBytes(cursor.y).CopyTo(data, dataPos); dataPos += 4;
BitConverter.GetBytes(cursor.z).CopyTo(data, dataPos); dataPos += 4;
socket.SendTo(data, serverEndPoint);
// receive a message from the server // receive a message from the server
byte[] data = new byte[1024]; dataPos = 0;
socket.ReceiveFrom(data, ref serverEndPoint); socket.ReceiveFrom(data, ref serverEndPoint);
if (log) Console.WriteLine("{0} received from server: {1}", name, BitConverter.ToInt32(data, 0)); peerCursor.x = BitConverter.ToSingle(data, dataPos); dataPos += 4;
peerCursor.y = BitConverter.ToSingle(data, dataPos); dataPos += 4;
peerCursor.z = BitConverter.ToSingle(data, dataPos); dataPos += 4;
// sleep for 0.1 seconds // sleep for 0.1 seconds
await Task.Delay(100); await Task.Delay(100);

View file

@ -22,9 +22,12 @@
- ~~claw cursor 30m~~ - ~~claw cursor 30m~~
- ~~refactor networking code to async based on video 1hr~~ - ~~refactor networking code to async based on video 1hr~~
- ~~haul the networking into stereokit 30m~~ - ~~haul the networking into stereokit 30m~~
- finish devtime tool 30m - ~~devtime tool 30m~~
- do something spatial with the data - ~~do something spatial with the data 48m~~
- make a batch script for niko so he can test things easily - devtime tool 30m
- why is the latency 20s? (client side?)
- make a batch script for niko so he can test things easily 32m (+script that does the "install")
- dead simple press to step through dofs - dead simple press to step through dofs
- gif maker - gif maker