Added Control Core
This commit is contained in:
parent
338936ace5
commit
735ad3b6dc
2
ClientMsg.cs.meta
Normal file
2
ClientMsg.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f73ac1131d4d7bd4a8f5b62500069867
|
@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7dcc9ff4cd6aac7448a2772858e1a501
|
||||
TextScriptImporter:
|
||||
guid: 7f964f406734cf74097d61697e5cafc9
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
@ -1,3 +1,5 @@
|
||||
using System;
|
||||
|
||||
class Angle
|
||||
{
|
||||
public static float Rad2Deg = 360.0f / ((float)Math.PI * 2);
|
||||
|
2
LinearAlgebra/Angle.cs.meta
Normal file
2
LinearAlgebra/Angle.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee99a6777ed47f743be8068c6ede98c8
|
@ -1,3 +1,5 @@
|
||||
using System;
|
||||
|
||||
namespace Passer.LinearAlgebra
|
||||
{
|
||||
public class Quat32
|
||||
|
@ -1,3 +1,5 @@
|
||||
#nullable enable
|
||||
|
||||
namespace Passer.Control.Core {
|
||||
|
||||
public class ModelUrlMsg : IMessage {
|
||||
@ -27,12 +29,15 @@ namespace Passer.Control.Core {
|
||||
}
|
||||
|
||||
public override byte Serialize(ref byte[] buffer) {
|
||||
if (this.url == null)
|
||||
return 0;
|
||||
|
||||
byte ix = 0;
|
||||
buffer[ix++] = ModelUrlMsg.Id;
|
||||
buffer[ix++] = this.networkId;
|
||||
buffer[ix++] = this.thingId; // Thing Id
|
||||
|
||||
buffer[ix++] = (byte)url.Length;
|
||||
buffer[ix++] = (byte)this.url.Length;
|
||||
for (int urlIx = 0; urlIx < this.url.Length; urlIx++)
|
||||
buffer[ix++] = (byte)url[urlIx];
|
||||
return ix;
|
||||
|
2
ModelUrlMsg.cs.meta
Normal file
2
ModelUrlMsg.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 711bdb0248c9f6848a6b4da15cc05db5
|
@ -1,3 +1,5 @@
|
||||
#nullable enable
|
||||
|
||||
namespace Passer.Control.Core {
|
||||
|
||||
public class NameMsg : IMessage {
|
||||
@ -27,14 +29,15 @@ namespace Passer.Control.Core {
|
||||
}
|
||||
|
||||
public override byte Serialize(ref byte[] buffer) {
|
||||
if (this.name == null)
|
||||
return 0;
|
||||
|
||||
byte ix = 0;
|
||||
buffer[ix++] = NameMsg.Id;
|
||||
buffer[ix++] = this.networkId;
|
||||
buffer[ix++] = this.thingId;
|
||||
|
||||
int nameLength = 0;
|
||||
if (this.name != null)
|
||||
nameLength = this.name.Length;
|
||||
int nameLength = this.name.Length;
|
||||
|
||||
buffer[ix++] = (byte)nameLength;
|
||||
for (int nameIx = 0; nameIx < nameLength; nameIx++)
|
||||
|
2
NameMsg.cs.meta
Normal file
2
NameMsg.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 462c645008baabe46b81f5d0ab83e26e
|
2
NetworkIdMsg.cs.meta
Normal file
2
NetworkIdMsg.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c51dae79b8c6f5a428349e1f4d34982c
|
@ -1,9 +1,10 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Passer.Control.Core {
|
||||
|
||||
@ -75,7 +76,7 @@ namespace Passer.Control.Core {
|
||||
byte[] data = udpClient.EndReceive(result, ref this.endPoint);
|
||||
// This does not yet take multi-packet messages into account!
|
||||
|
||||
Participant remoteParticipant = this.GetParticipant(endPoint.Address.ToString(), endPoint.Port);
|
||||
Participant? remoteParticipant = this.GetParticipant(endPoint.Address.ToString(), endPoint.Port);
|
||||
if (remoteParticipant == null) {
|
||||
remoteParticipant = this.AddParticipant(endPoint.Address.ToString(), endPoint.Port);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
|
2
ThingMsg.cs.meta
Normal file
2
ThingMsg.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 718e148be3eeb65498334ed008747482
|
@ -1,3 +1,5 @@
|
||||
using System;
|
||||
|
||||
namespace Passer.LinearAlgebra
|
||||
{
|
||||
|
||||
@ -261,9 +263,10 @@ namespace Passer.LinearAlgebra
|
||||
exp <<= 10;
|
||||
man++;
|
||||
man >>= 1;
|
||||
ushort uexp = (ushort)exp;
|
||||
if (sgn)
|
||||
return (ushort)(0x8000 | exp | man);
|
||||
return (ushort)(exp | man);
|
||||
return (ushort)(0x8000 | uexp | man);
|
||||
return (ushort)(uexp | man);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
|
2
float16.cs.meta
Normal file
2
float16.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 620fef383ba64a44995a234a71b2f189
|
8
test.meta
Normal file
8
test.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 239400f5314a5aa4bac98db5861f77a7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
7
test.sln.meta
Normal file
7
test.sln.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5d87461365fd8a4da528aa84a49e62c
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,84 +1,85 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
|
||||
using Passer.Control.Core;
|
||||
|
||||
namespace ControlCore.test;
|
||||
|
||||
public class Tests {
|
||||
[SetUp]
|
||||
public void Setup() {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_Participant() {
|
||||
Participant participant = new("127.0.0.1", 7681);
|
||||
|
||||
long milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
long startTime = milliseconds;
|
||||
while (milliseconds < startTime + 7000) {
|
||||
participant.Update(milliseconds);
|
||||
|
||||
Thread.Sleep(100);
|
||||
milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
namespace ControlCore.test {
|
||||
public class Tests {
|
||||
[SetUp]
|
||||
public void Setup() {
|
||||
}
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
[Test]
|
||||
public void Test_Participant() {
|
||||
Participant participant = new("127.0.0.1", 7681);
|
||||
|
||||
[Test]
|
||||
public void Test_SiteServer() {
|
||||
SiteServer siteServer = new(7681);
|
||||
long milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
long startTime = milliseconds;
|
||||
while (milliseconds < startTime + 7000) {
|
||||
participant.Update(milliseconds);
|
||||
|
||||
long milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
long startTime = milliseconds;
|
||||
while (milliseconds < startTime + 7000) {
|
||||
siteServer.Update(milliseconds);
|
||||
Thread.Sleep(100);
|
||||
milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
}
|
||||
|
||||
Thread.Sleep(100);
|
||||
milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
[Test]
|
||||
public void Test_SiteServer() {
|
||||
SiteServer siteServer = new(7681);
|
||||
|
||||
[Test]
|
||||
public void Test_SiteParticipant() {
|
||||
SiteServer siteServer = new(7681);
|
||||
Participant participant = new("127.0.0.1", 7681);
|
||||
long milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
long startTime = milliseconds;
|
||||
while (milliseconds < startTime + 7000) {
|
||||
siteServer.Update(milliseconds);
|
||||
|
||||
long milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
long startTime = milliseconds;
|
||||
while (milliseconds < startTime + 1000) {
|
||||
siteServer.Update(milliseconds);
|
||||
participant.Update(milliseconds);
|
||||
Thread.Sleep(100);
|
||||
milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
}
|
||||
|
||||
Thread.Sleep(100);
|
||||
milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
Assert.That(participant.networkId, Is.EqualTo(1));
|
||||
}
|
||||
[Test]
|
||||
public void Test_SiteParticipant() {
|
||||
SiteServer siteServer = new(7681);
|
||||
Participant participant = new("127.0.0.1", 7681);
|
||||
|
||||
[Test]
|
||||
public void Test_ThingMsg() {
|
||||
SiteServer siteServer = new();
|
||||
Participant participant = new("127.0.0.1");
|
||||
Thing thing = new() {
|
||||
name = "First Thing",
|
||||
modelUrl = "https://passer.life/extras/ant.jpg"
|
||||
};
|
||||
long milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
long startTime = milliseconds;
|
||||
while (milliseconds < startTime + 1000) {
|
||||
siteServer.Update(milliseconds);
|
||||
participant.Update(milliseconds);
|
||||
|
||||
long milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
long startTime = milliseconds;
|
||||
while (milliseconds < startTime + 7000) {
|
||||
siteServer.Update(milliseconds);
|
||||
participant.Update(milliseconds);
|
||||
Thread.Sleep(100);
|
||||
milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
}
|
||||
|
||||
Thread.Sleep(100);
|
||||
milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
Assert.That(participant.networkId, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
Assert.That(participant.networkId, Is.EqualTo(1));
|
||||
[Test]
|
||||
public void Test_ThingMsg() {
|
||||
SiteServer siteServer = new();
|
||||
Participant participant = new("127.0.0.1");
|
||||
Thing thing = new() {
|
||||
name = "First Thing",
|
||||
modelUrl = "https://passer.life/extras/ant.jpg"
|
||||
};
|
||||
|
||||
long milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
long startTime = milliseconds;
|
||||
while (milliseconds < startTime + 7000) {
|
||||
siteServer.Update(milliseconds);
|
||||
participant.Update(milliseconds);
|
||||
|
||||
Thread.Sleep(100);
|
||||
milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
}
|
||||
|
||||
Assert.That(participant.networkId, Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
test/UnitTest1.cs.meta
Normal file
2
test/UnitTest1.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 743b128a79ef8414fa29d7bb3b9e2ac8
|
7
test/test.csproj.meta
Normal file
7
test/test.csproj.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92729868a8379c04197dcb80d0276a63
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
x
Reference in New Issue
Block a user