Added Control Core

This commit is contained in:
Pascal Serrarens 2025-01-06 10:35:00 +01:00
parent 338936ace5
commit 735ad3b6dc
20 changed files with 128 additions and 72 deletions

2
ClientMsg.cs.meta Normal file
View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f73ac1131d4d7bd4a8f5b62500069867

View File

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 7dcc9ff4cd6aac7448a2772858e1a501 guid: 7f964f406734cf74097d61697e5cafc9
TextScriptImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:

View File

@ -1,3 +1,5 @@
using System;
class Angle class Angle
{ {
public static float Rad2Deg = 360.0f / ((float)Math.PI * 2); public static float Rad2Deg = 360.0f / ((float)Math.PI * 2);

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ee99a6777ed47f743be8068c6ede98c8

View File

@ -1,3 +1,5 @@
using System;
namespace Passer.LinearAlgebra namespace Passer.LinearAlgebra
{ {
public class Quat32 public class Quat32

View File

@ -1,3 +1,5 @@
#nullable enable
namespace Passer.Control.Core { namespace Passer.Control.Core {
public class ModelUrlMsg : IMessage { public class ModelUrlMsg : IMessage {
@ -27,12 +29,15 @@ namespace Passer.Control.Core {
} }
public override byte Serialize(ref byte[] buffer) { public override byte Serialize(ref byte[] buffer) {
if (this.url == null)
return 0;
byte ix = 0; byte ix = 0;
buffer[ix++] = ModelUrlMsg.Id; buffer[ix++] = ModelUrlMsg.Id;
buffer[ix++] = this.networkId; buffer[ix++] = this.networkId;
buffer[ix++] = this.thingId; // Thing Id 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++) for (int urlIx = 0; urlIx < this.url.Length; urlIx++)
buffer[ix++] = (byte)url[urlIx]; buffer[ix++] = (byte)url[urlIx];
return ix; return ix;

2
ModelUrlMsg.cs.meta Normal file
View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 711bdb0248c9f6848a6b4da15cc05db5

View File

@ -1,3 +1,5 @@
#nullable enable
namespace Passer.Control.Core { namespace Passer.Control.Core {
public class NameMsg : IMessage { public class NameMsg : IMessage {
@ -27,14 +29,15 @@ namespace Passer.Control.Core {
} }
public override byte Serialize(ref byte[] buffer) { public override byte Serialize(ref byte[] buffer) {
if (this.name == null)
return 0;
byte ix = 0; byte ix = 0;
buffer[ix++] = NameMsg.Id; buffer[ix++] = NameMsg.Id;
buffer[ix++] = this.networkId; buffer[ix++] = this.networkId;
buffer[ix++] = this.thingId; buffer[ix++] = this.thingId;
int nameLength = 0; int nameLength = this.name.Length;
if (this.name != null)
nameLength = this.name.Length;
buffer[ix++] = (byte)nameLength; buffer[ix++] = (byte)nameLength;
for (int nameIx = 0; nameIx < nameLength; nameIx++) for (int nameIx = 0; nameIx < nameLength; nameIx++)

2
NameMsg.cs.meta Normal file
View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 462c645008baabe46b81f5d0ab83e26e

2
NetworkIdMsg.cs.meta Normal file
View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c51dae79b8c6f5a428349e1f4d34982c

View File

@ -1,9 +1,10 @@
#nullable enable
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.IO;
using System.Threading.Tasks;
namespace Passer.Control.Core { namespace Passer.Control.Core {
@ -75,7 +76,7 @@ namespace Passer.Control.Core {
byte[] data = udpClient.EndReceive(result, ref this.endPoint); byte[] data = udpClient.EndReceive(result, ref this.endPoint);
// This does not yet take multi-packet messages into account! // 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) { if (remoteParticipant == null) {
remoteParticipant = this.AddParticipant(endPoint.Address.ToString(), endPoint.Port); remoteParticipant = this.AddParticipant(endPoint.Address.ToString(), endPoint.Port);
} }

View File

@ -1,3 +1,4 @@
using System;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;

2
ThingMsg.cs.meta Normal file
View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 718e148be3eeb65498334ed008747482

View File

@ -1,3 +1,5 @@
using System;
namespace Passer.LinearAlgebra namespace Passer.LinearAlgebra
{ {
@ -261,9 +263,10 @@ namespace Passer.LinearAlgebra
exp <<= 10; exp <<= 10;
man++; man++;
man >>= 1; man >>= 1;
ushort uexp = (ushort)exp;
if (sgn) if (sgn)
return (ushort)(0x8000 | exp | man); return (ushort)(0x8000 | uexp | man);
return (ushort)(exp | man); return (ushort)(uexp | man);
} }
// -- END OF FILE -- // -- END OF FILE --

2
float16.cs.meta Normal file
View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 620fef383ba64a44995a234a71b2f189

8
test.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 239400f5314a5aa4bac98db5861f77a7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
test.sln.meta Normal file
View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d5d87461365fd8a4da528aa84a49e62c
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,11 +1,11 @@
using System; using System;
using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using Passer.Control.Core; using Passer.Control.Core;
namespace ControlCore.test; namespace ControlCore.test {
public class Tests {
public class Tests {
[SetUp] [SetUp]
public void Setup() { public void Setup() {
} }
@ -81,4 +81,5 @@ public class Tests {
Assert.That(participant.networkId, Is.EqualTo(1)); Assert.That(participant.networkId, Is.EqualTo(1));
} }
}
} }

2
test/UnitTest1.cs.meta Normal file
View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 743b128a79ef8414fa29d7bb3b9e2ac8

7
test/test.csproj.meta Normal file
View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 92729868a8379c04197dcb80d0276a63
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: