Code updated (untested) to v0.4 Roboidcontrol
This commit is contained in:
parent
1c6a404dfd
commit
5c34066d8e
@ -0,0 +1,15 @@
|
||||
using Passer.Humanoid;
|
||||
|
||||
namespace RoboidControl
|
||||
{
|
||||
|
||||
public class BoneThing : Thing
|
||||
{
|
||||
protected HumanoidTarget.TargetedBone bone;
|
||||
|
||||
public BoneThing(HumanoidTarget.TargetedBone bone)
|
||||
{
|
||||
this.bone = bone;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33f05ee51ff6f7042b3e22723bcfc4f5
|
||||
guid: a87af0c7c5ff3ac468fc4f1c5997a2da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@ -1,26 +0,0 @@
|
||||
# You can override the included template(s) by including variable overrides
|
||||
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
|
||||
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/pipeline/#customization
|
||||
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
|
||||
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
|
||||
# Note that environment variables can be set in several places
|
||||
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
- review
|
||||
- dast
|
||||
- staging
|
||||
- canary
|
||||
- production
|
||||
- incremental rollout 10%
|
||||
- incremental rollout 25%
|
||||
- incremental rollout 50%
|
||||
- incremental rollout 100%
|
||||
- performance
|
||||
- cleanup
|
||||
sast:
|
||||
stage: test
|
||||
include:
|
||||
- template: Auto-DevOps.gitlab-ci.yml
|
@ -1,109 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.Sockets;
|
||||
using System.IO;
|
||||
|
||||
namespace Passer.Control {
|
||||
|
||||
public class Client {
|
||||
//public ConnectionMethod connection;
|
||||
public UdpClient udpClient;
|
||||
public string ipAddress;
|
||||
public int port;
|
||||
public Stream dataStream;
|
||||
|
||||
public byte networkId = 0;
|
||||
|
||||
public readonly ConcurrentQueue<IMessage> messageQueue = new();
|
||||
|
||||
public static Client GetClient(string ipAddress, int port) {
|
||||
foreach (Client c in clients) {
|
||||
if (c.ipAddress == ipAddress && c.port == port)
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static public List<Client> clients = new List<Client>();
|
||||
|
||||
public Client(UdpClient udpClient, int port) {
|
||||
this.udpClient = udpClient;
|
||||
this.ipAddress = null;
|
||||
this.port = port;
|
||||
this.dataStream = new EchoStream();
|
||||
clients.Add(this);
|
||||
}
|
||||
|
||||
public virtual void ProcessMessages() {
|
||||
while (this.messageQueue.TryDequeue(out IMessage msg))
|
||||
ProcessMessage(msg);
|
||||
}
|
||||
|
||||
public void ProcessMessage(IMessage msg) {
|
||||
switch (msg) {
|
||||
case ClientMsg clientMsg:
|
||||
ProcessClient(clientMsg);
|
||||
break;
|
||||
case NetworkIdMsg networkId:
|
||||
ProcessNetworkId(networkId);
|
||||
break;
|
||||
case InvestigateMsg investigate:
|
||||
ProcessInvestigate(investigate);
|
||||
break;
|
||||
case ThingMsg thing:
|
||||
ProcessThing(thing);
|
||||
break;
|
||||
case NameMsg name:
|
||||
UnityEngine.Debug.Log($"Name [{name.networkId}/{name.thingId}] {name.name}");
|
||||
ProcessName(name);
|
||||
break;
|
||||
case ModelUrlMsg modelUrl:
|
||||
ProcessModelUrl(modelUrl);
|
||||
break;
|
||||
case PoseMsg pose:
|
||||
ProcessPose(pose);
|
||||
break;
|
||||
case CustomMsg custom:
|
||||
ProcessCustom(custom);
|
||||
break;
|
||||
case TextMsg text:
|
||||
ProcessText(text);
|
||||
break;
|
||||
case DestroyMsg destroy:
|
||||
ProcessDestroy(destroy);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
ForwardMessage(msg);
|
||||
}
|
||||
|
||||
protected virtual void ProcessClient(ClientMsg client) { }
|
||||
|
||||
protected virtual void ProcessNetworkId(NetworkIdMsg networkId) { }
|
||||
|
||||
protected virtual void ProcessInvestigate(InvestigateMsg investigate) { }
|
||||
|
||||
protected virtual void ProcessThing(ThingMsg thing) { }
|
||||
|
||||
protected virtual void ProcessName(NameMsg name) { }
|
||||
|
||||
protected virtual void ProcessModelUrl(ModelUrlMsg modelUrl) { }
|
||||
|
||||
protected virtual void ProcessPose(PoseMsg pose) { }
|
||||
|
||||
protected virtual void ProcessCustom(CustomMsg custom) { }
|
||||
|
||||
protected virtual void ProcessText(TextMsg text) { }
|
||||
|
||||
protected virtual void ProcessDestroy(DestroyMsg destroy) { }
|
||||
|
||||
private void ForwardMessage(IMessage msg) {
|
||||
foreach (Client client in Client.clients) {
|
||||
if (client == this)
|
||||
continue;
|
||||
//UnityEngine.Debug.Log($"---> {client.ipAddress}");
|
||||
IMessage.SendMsg(client, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db9cd79cff119a9438110ead000031c3
|
@ -1,173 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
public class EchoStream : Stream {
|
||||
public override bool CanTimeout { get; } = true;
|
||||
public override int ReadTimeout { get; set; } = Timeout.Infinite;
|
||||
public override int WriteTimeout { get; set; } = Timeout.Infinite;
|
||||
public override bool CanRead { get; } = true;
|
||||
public override bool CanSeek { get; } = false;
|
||||
public override bool CanWrite { get; } = true;
|
||||
|
||||
public bool CopyBufferOnWrite { get; set; } = false;
|
||||
|
||||
private readonly object _lock = new object();
|
||||
|
||||
// Default underlying mechanism for BlockingCollection is ConcurrentQueue<T>, which is what we want
|
||||
private readonly BlockingCollection<byte[]> _Buffers;
|
||||
private int _maxQueueDepth = 10;
|
||||
|
||||
private byte[] m_buffer = null;
|
||||
private int m_offset = 0;
|
||||
private int m_count = 0;
|
||||
|
||||
private bool m_Closed = false;
|
||||
private bool m_FinalZero = false; //after the stream is closed, set to true after returning a 0 for read()
|
||||
public override void Close() {
|
||||
m_Closed = true;
|
||||
|
||||
// release any waiting writes
|
||||
_Buffers.CompleteAdding();
|
||||
}
|
||||
|
||||
public bool DataAvailable {
|
||||
get {
|
||||
return _Buffers.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
private long _Length = 0L;
|
||||
public override long Length {
|
||||
get {
|
||||
return _Length;
|
||||
}
|
||||
}
|
||||
|
||||
private long _Position = 0L;
|
||||
public override long Position {
|
||||
get {
|
||||
return _Position;
|
||||
}
|
||||
set {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public EchoStream() : this(10) {
|
||||
}
|
||||
|
||||
public EchoStream(int maxQueueDepth) {
|
||||
_maxQueueDepth = maxQueueDepth;
|
||||
_Buffers = new BlockingCollection<byte[]>(_maxQueueDepth);
|
||||
}
|
||||
|
||||
// we override the xxxxAsync functions because the default base class shares state between ReadAsync and WriteAsync, which causes a hang if both are called at once
|
||||
public new Task WriteAsync(byte[] buffer, int offset, int count) {
|
||||
return Task.Run(() => Write(buffer, offset, count));
|
||||
}
|
||||
|
||||
// we override the xxxxAsync functions because the default base class shares state between ReadAsync and WriteAsync, which causes a hang if both are called at once
|
||||
public new Task<int> ReadAsync(byte[] buffer, int offset, int count) {
|
||||
return Task.Run(() => {
|
||||
return Read(buffer, offset, count);
|
||||
});
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count) {
|
||||
if (m_Closed || buffer.Length - offset < count || count <= 0)
|
||||
return;
|
||||
|
||||
byte[] newBuffer;
|
||||
if (!CopyBufferOnWrite && offset == 0 && count == buffer.Length)
|
||||
newBuffer = buffer;
|
||||
else {
|
||||
newBuffer = new byte[count];
|
||||
System.Buffer.BlockCopy(buffer, offset, newBuffer, 0, count);
|
||||
}
|
||||
if (!_Buffers.TryAdd(newBuffer, WriteTimeout))
|
||||
throw new TimeoutException("EchoStream Write() Timeout");
|
||||
|
||||
_Length += count;
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) {
|
||||
if (count == 0)
|
||||
return 0;
|
||||
lock (_lock) {
|
||||
if (m_count == 0 && _Buffers.Count == 0) {
|
||||
if (m_Closed) {
|
||||
if (!m_FinalZero) {
|
||||
m_FinalZero = true;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (_Buffers.TryTake(out m_buffer, ReadTimeout)) {
|
||||
m_offset = 0;
|
||||
m_count = m_buffer.Length;
|
||||
}
|
||||
else {
|
||||
if (m_Closed) {
|
||||
if (!m_FinalZero) {
|
||||
m_FinalZero = true;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int returnBytes = 0;
|
||||
while (count > 0) {
|
||||
if (m_count == 0) {
|
||||
if (_Buffers.TryTake(out m_buffer, 0)) {
|
||||
m_offset = 0;
|
||||
m_count = m_buffer.Length;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
var bytesToCopy = (count < m_count) ? count : m_count;
|
||||
System.Buffer.BlockCopy(m_buffer, m_offset, buffer, offset, bytesToCopy);
|
||||
m_offset += bytesToCopy;
|
||||
m_count -= bytesToCopy;
|
||||
offset += bytesToCopy;
|
||||
count -= bytesToCopy;
|
||||
|
||||
returnBytes += bytesToCopy;
|
||||
}
|
||||
|
||||
_Position += returnBytes;
|
||||
|
||||
return returnBytes;
|
||||
}
|
||||
}
|
||||
|
||||
public override int ReadByte() {
|
||||
byte[] returnValue = new byte[1];
|
||||
return (Read(returnValue, 0, 1) <= 0 ? -1 : (int)returnValue[0]);
|
||||
}
|
||||
|
||||
public override void Flush() {
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long value) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 422516a56cbf14d46aaa0b1bc09115bf
|
@ -1,72 +0,0 @@
|
||||
using Passer;
|
||||
|
||||
public class LowLevelMessages {
|
||||
|
||||
public static void SendSpherical(byte[] buffer, ref byte ix, Spherical v) {
|
||||
SendAngle8(buffer, ref ix, v.horizontal);
|
||||
SendAngle8(buffer, ref ix, v.vertical);
|
||||
SendFloat16(buffer, ref ix, new float16(v.distance));
|
||||
}
|
||||
|
||||
public static Spherical ReceiveSpherical(byte[] data, ref byte ix) {
|
||||
float horizontal = ReceiveAngle8(data, ref ix);
|
||||
float vertical = ReceiveAngle8(data, ref ix);
|
||||
float distance = ReceiveFloat16(data, ref ix);
|
||||
Spherical v = new(distance, horizontal, vertical);
|
||||
return v;
|
||||
}
|
||||
|
||||
public static void SendQuat32(byte[] buffer, ref byte ix, Quat32 q) {
|
||||
int qx = (int)(q.x * 127 + 128);
|
||||
int qy = (int)(q.y * 127 + 128);
|
||||
int qz = (int)(q.z * 127 + 128);
|
||||
int qw = (int)(q.w * 255);
|
||||
if (q.w < 0) {
|
||||
qx = -qx;
|
||||
qy = -qy;
|
||||
qz = -qz;
|
||||
qw = -qw;
|
||||
}
|
||||
|
||||
buffer[ix++] = (byte)qx;
|
||||
buffer[ix++] = (byte)qy;
|
||||
buffer[ix++] = (byte)qz;
|
||||
buffer[ix++] = (byte)qw;
|
||||
}
|
||||
public static Quat32 ReceiveQuat32(byte[] data, ref byte ix) {
|
||||
Quat32 q = new(
|
||||
(data[ix++] - 128.0F) / 127.0F,
|
||||
(data[ix++] - 128.0F) / 127.0F,
|
||||
(data[ix++] - 128.0F) / 127.0F,
|
||||
data[ix++] / 255.0F);
|
||||
return q;
|
||||
}
|
||||
|
||||
public static void SendAngle8(byte[] buffer, ref byte ix, float angle) {
|
||||
// Normalize angle
|
||||
while (angle >= 180)
|
||||
angle -= 360;
|
||||
while (angle < -180)
|
||||
angle += 360;
|
||||
buffer[ix++] = (byte)((angle / 360.0f) * 256.0f);
|
||||
}
|
||||
|
||||
public static float ReceiveAngle8(byte[] data, ref byte ix) {
|
||||
float value = (data[ix++] * 180) / 128.0F;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void SendFloat16(byte[] data, ref byte ix, float16 f) {
|
||||
ushort binary = f.GetBinary();
|
||||
data[ix++] = (byte)(binary >> 8);
|
||||
data[ix++] = (byte)(binary & 255);
|
||||
}
|
||||
|
||||
public static float ReceiveFloat16(byte[] data, ref byte ix) {
|
||||
ushort value = (ushort)(data[ix++] << 8 | data[ix++]);
|
||||
float16 f16 = new();
|
||||
f16.SetBinary(value);
|
||||
float f = f16.toFloat();
|
||||
return f;
|
||||
}
|
||||
}
|
@ -1,535 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Passer.Control {
|
||||
|
||||
public class IMessage {
|
||||
public IMessage() { }
|
||||
public IMessage(byte[] buffer) {
|
||||
Deserialize(buffer);
|
||||
}
|
||||
|
||||
public virtual byte[] Serialize() { return null; }
|
||||
public virtual void Deserialize(byte[] buffer) { }
|
||||
|
||||
public static bool SendMsg(Client client, IMessage msg) {
|
||||
return SendMsg(client, msg.Serialize());
|
||||
}
|
||||
public static bool SendMsg(Client client, byte[] buffer) {
|
||||
if (client == null || client.ipAddress == null)
|
||||
return false;
|
||||
|
||||
//UnityEngine.Debug.Log($"Send msg {buffer[0]} to {client.ipAddress}");
|
||||
client.udpClient.Send(buffer, buffer.Length, client.ipAddress, client.port);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool PublishMsg(Client client, IMessage msg) {
|
||||
return PublishMsg(client, msg.Serialize());
|
||||
}
|
||||
public static bool PublishMsg(Client client, byte[] buffer) {
|
||||
if (client == null)
|
||||
return false;
|
||||
|
||||
client.udpClient.Send(buffer, buffer.Length, "127.0.0.1", client.port);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<byte[]> Receive(Stream dataStream, byte packetSize) {
|
||||
byte[] buffer = new byte[packetSize - 1]; // without msgId
|
||||
int byteCount = dataStream.Read(buffer, 0, packetSize - 1);
|
||||
while (byteCount < packetSize - 1) {
|
||||
// not all bytes have been read, wait and try again
|
||||
await Task.Delay(1);
|
||||
byteCount += dataStream.Read(buffer, byteCount, packetSize - 1 - byteCount);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
#region Client
|
||||
|
||||
public class ClientMsg : IMessage {
|
||||
public const byte Id = 0xA0;
|
||||
public const byte length = 2;
|
||||
public byte networkId;
|
||||
|
||||
public ClientMsg(byte networkId) {
|
||||
this.networkId = networkId;
|
||||
}
|
||||
public ClientMsg(byte[] buffer) : base(buffer) { }
|
||||
|
||||
public override byte[] Serialize() {
|
||||
byte[] buffer = new byte[ClientMsg.length];
|
||||
buffer[0] = ClientMsg.Id;
|
||||
buffer[1] = networkId;
|
||||
return buffer;
|
||||
}
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
base.Deserialize(buffer);
|
||||
uint ix = 0;
|
||||
networkId = buffer[ix];
|
||||
}
|
||||
|
||||
public static bool Send(Client client, byte networkId) {
|
||||
ClientMsg msg = new(networkId);
|
||||
return SendMsg(client, msg);
|
||||
}
|
||||
public static bool Publish(Client client, byte networkId) {
|
||||
ClientMsg msg = new(networkId);
|
||||
return PublishMsg(client, msg);
|
||||
}
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
if (packetSize != length)
|
||||
return false;
|
||||
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
ClientMsg msg = new(buffer);
|
||||
|
||||
if (client.networkId == 0) {
|
||||
client.networkId = (byte)(Client.clients.Count);
|
||||
NetworkIdMsg.Send(client, client.networkId);
|
||||
client.messageQueue.Enqueue(msg);
|
||||
}
|
||||
else if (msg.networkId == 0) {
|
||||
NetworkIdMsg.Send(client, client.networkId);
|
||||
client.messageQueue.Enqueue(msg);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Client
|
||||
|
||||
#region Network Id
|
||||
|
||||
public class NetworkIdMsg : IMessage {
|
||||
public const byte Id = 0xA1;
|
||||
public const byte length = 2;
|
||||
public byte networkId;
|
||||
|
||||
NetworkIdMsg(byte networkId) {
|
||||
this.networkId = networkId;
|
||||
}
|
||||
NetworkIdMsg(byte[] buffer) : base(buffer) { }
|
||||
|
||||
public override byte[] Serialize() {
|
||||
byte[] buffer = new byte[NetworkIdMsg.length];
|
||||
buffer[0] = NetworkIdMsg.Id;
|
||||
buffer[1] = this.networkId;
|
||||
return buffer;
|
||||
}
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
uint ix = 0;
|
||||
this.networkId = buffer[ix];
|
||||
}
|
||||
|
||||
public static bool Send(Client client, byte networkId) {
|
||||
NetworkIdMsg msg = new(networkId);
|
||||
return SendMsg(client, msg);
|
||||
}
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
if (packetSize != length)
|
||||
return false;
|
||||
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
NetworkIdMsg msg = new(buffer);
|
||||
client.messageQueue.Enqueue(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Network Id
|
||||
|
||||
#region Investigate
|
||||
|
||||
public class InvestigateMsg : IMessage {
|
||||
public const byte Id = 0x81;
|
||||
public const byte length = 3;
|
||||
public byte networkId;
|
||||
public byte thingId;
|
||||
|
||||
public InvestigateMsg(byte networkId, byte thingId) {
|
||||
this.networkId = networkId;
|
||||
this.thingId = thingId;
|
||||
}
|
||||
public InvestigateMsg(byte[] buffer) : base(buffer) { }
|
||||
|
||||
public override byte[] Serialize() {
|
||||
byte[] buffer = new byte[InvestigateMsg.length];
|
||||
buffer[0] = InvestigateMsg.Id;
|
||||
buffer[1] = this.networkId;
|
||||
buffer[2] = this.thingId;
|
||||
return buffer;
|
||||
}
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
uint ix = 0;
|
||||
this.networkId = buffer[ix++];
|
||||
this.thingId = buffer[ix++];
|
||||
}
|
||||
|
||||
public static bool Send(Client client, byte networkId, byte thingId) {
|
||||
InvestigateMsg msg = new(networkId, thingId);
|
||||
return SendMsg(client, msg);
|
||||
}
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
if (packetSize != length)
|
||||
return false;
|
||||
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
InvestigateMsg msg = new(buffer);
|
||||
client.messageQueue.Enqueue(msg);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Investigate
|
||||
|
||||
#region Thing
|
||||
|
||||
public class ThingMsg : IMessage {
|
||||
public const byte length = 5;
|
||||
public const byte Id = 0x80;
|
||||
public byte networkId;
|
||||
public byte thingId;
|
||||
public byte thingType;
|
||||
public byte parentId;
|
||||
|
||||
public ThingMsg(byte networkId, byte thingId, byte thingType, byte parentId) {
|
||||
this.thingId = thingId;
|
||||
this.thingType = thingType;
|
||||
this.parentId = parentId;
|
||||
}
|
||||
public ThingMsg(byte[] buffer) : base(buffer) { }
|
||||
|
||||
public override byte[] Serialize() {
|
||||
byte[] buffer = new byte[ThingMsg.length];
|
||||
byte ix = 0;
|
||||
buffer[ix++] = ThingMsg.Id;
|
||||
buffer[ix++] = this.networkId;
|
||||
buffer[ix++] = this.thingId;
|
||||
buffer[ix++] = this.thingType;
|
||||
buffer[ix] = this.parentId;
|
||||
return buffer;
|
||||
}
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
uint ix = 0;
|
||||
this.networkId = buffer[ix++];
|
||||
this.thingId = buffer[ix++];
|
||||
this.thingType = buffer[ix++];
|
||||
this.parentId = buffer[ix];
|
||||
}
|
||||
|
||||
public static bool Send(Client client, byte thingId, byte thingType, byte parentId) {
|
||||
ThingMsg msg = new(client.networkId, thingId, thingType, parentId);
|
||||
return SendMsg(client, msg);
|
||||
}
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
if (packetSize != length)
|
||||
return false;
|
||||
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
ThingMsg msg = new(buffer);
|
||||
|
||||
// Do no process poses with nwid == 0 (== local)
|
||||
//if (msg.networkId == 0)
|
||||
// return true;
|
||||
|
||||
client.messageQueue.Enqueue(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Thing
|
||||
|
||||
#region Name
|
||||
|
||||
public class NameMsg : IMessage {
|
||||
public const byte Id = 0x91; // 145
|
||||
public const byte length = 4;
|
||||
public byte networkId;
|
||||
public byte thingId;
|
||||
public byte len;
|
||||
public string name;
|
||||
|
||||
public NameMsg(byte networkId, byte thingId, string name) {
|
||||
this.networkId = networkId;
|
||||
this.thingId = thingId;
|
||||
this.name = name;
|
||||
}
|
||||
public NameMsg(byte[] buffer) : base(buffer) { }
|
||||
|
||||
public override byte[] Serialize() {
|
||||
byte[] buffer = new byte[length + this.name.Length];
|
||||
byte ix = 0;
|
||||
buffer[ix++] = NameMsg.Id;
|
||||
buffer[ix++] = this.networkId;
|
||||
buffer[ix++] = this.thingId;
|
||||
buffer[ix++] = (byte)this.name.Length;
|
||||
for (int nameIx = 0; nameIx < this.name.Length; nameIx++, ix++)
|
||||
buffer[ix] = (byte)this.name[nameIx];
|
||||
return buffer;
|
||||
}
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
byte ix = 0;
|
||||
this.networkId = buffer[ix++];
|
||||
this.thingId = buffer[ix++];
|
||||
int strlen = buffer[ix++];
|
||||
this.name = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, strlen);
|
||||
}
|
||||
|
||||
public static bool Send(Client client, byte networkId, byte thingId, string name) {
|
||||
NameMsg msg = new(networkId, thingId, name);
|
||||
return SendMsg(client, msg);
|
||||
}
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
NameMsg msg = new(buffer);
|
||||
|
||||
client.messageQueue.Enqueue(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Model URL
|
||||
|
||||
public class ModelUrlMsg : IMessage {
|
||||
public const byte Id = 0x90; // (144) Model URL
|
||||
public byte networkId;
|
||||
public byte thingId;
|
||||
public Spherical position;
|
||||
public float scale;
|
||||
public string url;
|
||||
|
||||
public ModelUrlMsg(byte networkId, byte thingId, string url, float scale = 1) {
|
||||
this.networkId = networkId;
|
||||
this.thingId = thingId;
|
||||
this.url = url;
|
||||
this.scale = scale;
|
||||
this.position = Spherical.zero;
|
||||
}
|
||||
public ModelUrlMsg(byte[] buffer) : base(buffer) { }
|
||||
|
||||
public override byte[] Serialize() {
|
||||
byte[] buffer = new byte[this.url.Length + 6];
|
||||
byte ix = 0;
|
||||
buffer[ix++] = ModelUrlMsg.Id;
|
||||
buffer[ix++] = this.networkId;
|
||||
buffer[ix++] = this.thingId; // Thing Id
|
||||
LowLevelMessages.SendFloat16(buffer, ref ix, new float16(1.0f));
|
||||
|
||||
buffer[ix++] = (byte)url.Length;
|
||||
for (int urlIx = 0; urlIx < this.url.Length; urlIx++, ix++)
|
||||
buffer[ix] = (byte)url[urlIx];
|
||||
return buffer;
|
||||
}
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
byte ix = 0;
|
||||
this.networkId = buffer[ix++];
|
||||
this.thingId = buffer[ix++];
|
||||
this.scale = LowLevelMessages.ReceiveFloat16(buffer, ref ix);
|
||||
int strlen = buffer[ix++];
|
||||
url = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, strlen);
|
||||
}
|
||||
|
||||
public static bool Send(Client client, byte networkId, byte thingId, string modelUrl) {
|
||||
ModelUrlMsg msg = new(networkId, thingId, modelUrl);
|
||||
return SendMsg(client, msg);
|
||||
}
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
ModelUrlMsg msg = new(buffer);
|
||||
client.messageQueue.Enqueue(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Model URL
|
||||
|
||||
#region Pose
|
||||
|
||||
public class PoseMsg : IMessage {
|
||||
public const byte Id = 0x10;
|
||||
public const byte length = 4 + 4 + 4;
|
||||
public byte networkId;
|
||||
public byte thingId;
|
||||
|
||||
public byte poseType;
|
||||
public const byte Pose_Position = 0x01;
|
||||
public const byte Pose_Orientation = 0x02;
|
||||
|
||||
public Spherical position;
|
||||
public Quat32 orientation;
|
||||
|
||||
public PoseMsg(byte networkId, byte thingId, Spherical position, Quat32 orientation) {
|
||||
this.networkId = networkId;
|
||||
this.thingId = thingId;
|
||||
this.position = position;
|
||||
this.orientation = orientation;
|
||||
this.poseType = 0;
|
||||
if (this.position != null)
|
||||
this.poseType |= Pose_Position;
|
||||
else
|
||||
this.position = new Spherical(0, 0, 0);
|
||||
if (this.orientation != null)
|
||||
this.poseType |= Pose_Orientation;
|
||||
else
|
||||
this.orientation = new Quat32(0, 0, 0, 1);
|
||||
}
|
||||
public PoseMsg(byte[] buffer) : base(buffer) { }
|
||||
|
||||
public override byte[] Serialize() {
|
||||
byte[] buffer = new byte[PoseMsg.length];
|
||||
byte ix = 0;
|
||||
buffer[ix++] = PoseMsg.Id;
|
||||
buffer[ix++] = this.networkId;
|
||||
buffer[ix++] = this.thingId;
|
||||
buffer[ix++] = this.poseType;
|
||||
|
||||
LowLevelMessages.SendSpherical(buffer, ref ix, this.position);
|
||||
LowLevelMessages.SendQuat32(buffer, ref ix, this.orientation);
|
||||
return buffer;
|
||||
}
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
byte ix = 0;
|
||||
this.networkId = buffer[ix++];
|
||||
this.thingId = buffer[ix++];
|
||||
this.poseType = buffer[ix++];
|
||||
|
||||
//if ((poseType & Pose_Position) != 0)
|
||||
this.position = LowLevelMessages.ReceiveSpherical(buffer, ref ix);
|
||||
//if ((poseType & Pose_Orientation) != 0) {
|
||||
this.orientation = LowLevelMessages.ReceiveQuat32(buffer, ref ix);
|
||||
}
|
||||
|
||||
public static bool Send(Client client, byte thingId, Spherical position, Quat32 orientation) {
|
||||
PoseMsg msg = new(client.networkId, thingId, position, orientation);
|
||||
return SendMsg(client, msg);
|
||||
}
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
if (packetSize != length)
|
||||
return false;
|
||||
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
PoseMsg msg = new(buffer);
|
||||
|
||||
// Do no process poses with nwid == 0 (== local)
|
||||
if (msg.networkId == 0)
|
||||
return true;
|
||||
|
||||
client.messageQueue.Enqueue(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Pose
|
||||
|
||||
#region Custom
|
||||
|
||||
public class CustomMsg : IMessage {
|
||||
public const byte Id = 0xB1;
|
||||
public byte networkId;
|
||||
public byte thingId;
|
||||
public byte[] bytes;
|
||||
|
||||
public CustomMsg(byte[] buffer) : base(buffer) { }
|
||||
public CustomMsg(byte networkId, byte thingId, byte[] bytes) : base() {
|
||||
this.networkId = networkId;
|
||||
this.thingId = thingId;
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public override byte[] Serialize() {
|
||||
byte[] buffer = new byte[3 + this.bytes.Length];
|
||||
byte ix = 0;
|
||||
buffer[ix++] = CustomMsg.Id;
|
||||
buffer[ix++] = this.networkId;
|
||||
buffer[ix++] = this.thingId;
|
||||
//buffer[ix++] = (byte)bytes.Length;
|
||||
foreach (byte b in bytes)
|
||||
buffer[ix++] = b;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
byte ix = 0;
|
||||
this.networkId = buffer[ix++];
|
||||
this.thingId = buffer[ix++];
|
||||
byte length = (byte)(buffer.Length - ix);//buffer[ix++];
|
||||
this.bytes = new byte[length];
|
||||
for (uint bytesIx = 0; bytesIx < length; bytesIx++)
|
||||
this.bytes[bytesIx] = buffer[ix++];
|
||||
}
|
||||
|
||||
public static void Send(Client client, byte thingId, byte[] bytes) {
|
||||
CustomMsg msg = new(client.networkId, thingId, bytes);
|
||||
SendMsg(client, msg);
|
||||
}
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
CustomMsg msg = new(buffer);
|
||||
client.messageQueue.Enqueue(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Custom
|
||||
|
||||
#region Text
|
||||
|
||||
public class TextMsg : IMessage {
|
||||
public const byte Id = 0xB0;
|
||||
public string text;
|
||||
|
||||
public TextMsg(byte[] buffer) : base(buffer) { }
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
uint ix = 0;
|
||||
uint strlen = buffer[ix++];
|
||||
this.text = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, (int)strlen);
|
||||
}
|
||||
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
TextMsg msg = new(buffer);
|
||||
|
||||
client.messageQueue.Enqueue(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Destroy
|
||||
|
||||
public class DestroyMsg : IMessage {
|
||||
public const byte Id = 0x20;
|
||||
public const byte length = 2;
|
||||
public byte networkId;
|
||||
public byte thingId;
|
||||
|
||||
public DestroyMsg(byte[] buffer) : base(buffer) { }
|
||||
|
||||
public override void Deserialize(byte[] buffer) {
|
||||
this.networkId = buffer[0];
|
||||
this.thingId = buffer[1];
|
||||
}
|
||||
|
||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||
if (packetSize != length)
|
||||
return false;
|
||||
|
||||
byte[] buffer = await Receive(dataStream, packetSize);
|
||||
DestroyMsg msg = new(buffer);
|
||||
|
||||
client.messageQueue.Enqueue(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion Destroy
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3f26f22a5422a44997b39a1844ab2ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,15 +0,0 @@
|
||||
namespace Passer {
|
||||
public class Quat32 {
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
public float w;
|
||||
|
||||
public Quat32(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96aa3cf18eaeb574d9265704d68000da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,93 +0,0 @@
|
||||
# ControlCore
|
||||
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin http://gitlab.passervr.com/passer/csharp/controlcore.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](http://gitlab.passervr.com/passer/csharp/controlcore/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b79b5b373e9ced4abe72eb4d2f83c6a
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,66 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Passer.Control {
|
||||
|
||||
public static class SiteServer {
|
||||
|
||||
public static async Task ReceiveData(Stream dataStream, Client client) {
|
||||
while (true) {
|
||||
byte packetSize = (byte)dataStream.ReadByte();
|
||||
if (packetSize != 0xFF)
|
||||
await ReceiveData(dataStream, client, packetSize);
|
||||
// else timeout
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task ReceiveData(Stream dataStream, Client client, byte packetSize) {
|
||||
byte msgId = (byte)dataStream.ReadByte();
|
||||
if (msgId == 0xFF) {
|
||||
// Timeout
|
||||
return;
|
||||
}
|
||||
|
||||
//UnityEngine.Debug.Log($"R {msgId} from {client.ipAddress}");
|
||||
bool result = false;
|
||||
switch (msgId) {
|
||||
case ClientMsg.Id: // 0xA0 / 160
|
||||
result = await ClientMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
case NetworkIdMsg.Id: // 0xA1 / 161
|
||||
result = await NetworkIdMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
case InvestigateMsg.Id: // 0x81
|
||||
result = await InvestigateMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
case ThingMsg.Id: // 0x80 / 128
|
||||
result = await ThingMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
case NameMsg.Id: // 0x91 / 145
|
||||
result = await NameMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
case ModelUrlMsg.Id: // 0x90 / 144
|
||||
result = await ModelUrlMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
case PoseMsg.Id: // 0x10 / 16
|
||||
result = await PoseMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
case CustomMsg.Id: // 0xB1 / 177
|
||||
result = await CustomMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
case TextMsg.Id: // 0xB0 / 176
|
||||
result = await TextMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
case DestroyMsg.Id: // 0x20 / 32
|
||||
result = await DestroyMsg.Receive(dataStream, client, packetSize);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (result == false) {
|
||||
packetSize = msgId; // skip 1 byte, msgId is possibly a packet size byte
|
||||
await ReceiveData(dataStream, client, packetSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53345abb9310d344baa67c19a8d8249f
|
@ -1,15 +0,0 @@
|
||||
namespace Passer {
|
||||
public class Spherical {
|
||||
public float distance;
|
||||
public float horizontal;
|
||||
public float vertical;
|
||||
|
||||
public static Spherical zero = new(0, 0, 0);
|
||||
|
||||
public Spherical(float distance, float horizontal, float vertical) {
|
||||
this.distance = distance;
|
||||
this.horizontal = horizontal;
|
||||
this.vertical = vertical;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,6 @@
|
||||
using RoboidControl;
|
||||
|
||||
public class HumanoidThing : Thing
|
||||
{
|
||||
public HumanoidThing(bool invokeEvent = true) : base(Type.HUmanoid, invokeEvent) {}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 157cf85b523c1f648adc007539f8b736
|
||||
guid: 4ec67072d500b33449ba4485378f7b22
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98ee056958e257046a58cddcbcb661e3
|
||||
guid: 0e93fb67f760ca94092664257138720b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
@ -1,57 +0,0 @@
|
||||
using Passer.Humanoid.Tracking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Passer.LinearAlgebra {
|
||||
|
||||
public class Spherical16 {
|
||||
|
||||
public float16 distance;
|
||||
public byte horizontal;
|
||||
public byte vertical;
|
||||
|
||||
public Spherical16(float distance, float horizontal = 0, float vertical = 0) {
|
||||
horizontal = Angle.Normalize(horizontal);
|
||||
vertical = Angle.Normalize(vertical);
|
||||
this.distance = new float16(distance);
|
||||
this.horizontal = (byte)(horizontal * 128.0f / 180.0f);
|
||||
this.vertical = (byte)(vertical * 128.0f / 180.0f);
|
||||
}
|
||||
|
||||
public static Spherical16 FromVector3(Vector3 v) {
|
||||
float distance = v.magnitude;
|
||||
if (distance == 0.0f) {
|
||||
return new Spherical16(distance);
|
||||
}
|
||||
else {
|
||||
float verticalAngle = (Mathf.PI / 2 - Mathf.Acos(v.y / distance)) * Mathf.Rad2Deg;
|
||||
float horizontalAngle = Mathf.Atan2(v.x, v.z) * Mathf.Rad2Deg;
|
||||
Debug.Log($"sph {horizontalAngle} {verticalAngle} {distance}");
|
||||
return new Spherical16(distance, horizontalAngle, verticalAngle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Quat32 {
|
||||
public byte qx;
|
||||
public byte qy;
|
||||
public byte qz;
|
||||
public byte qw;
|
||||
|
||||
public Quat32(Quaternion q) {
|
||||
int qx = (int)(q.x * 127 + 128);
|
||||
int qy = (int)(q.y * 127 + 128);
|
||||
int qz = (int)(q.z * 127 + 128);
|
||||
int qw = (int)(q.w * 255);
|
||||
if (q.w < 0) {
|
||||
qx = -qx;
|
||||
qy = -qy;
|
||||
qz = -qz;
|
||||
qw = -qw;
|
||||
}
|
||||
this.qx = (byte)(qx);
|
||||
this.qy = (byte)(qy);
|
||||
this.qz = (byte)(qz);
|
||||
this.qw = (byte)(qw);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79bdc65d83f2c8e43bac904e283c6c46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,54 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Passer.Control;
|
||||
|
||||
public class Thing : MonoBehaviour {
|
||||
public Client client;
|
||||
public byte networkId;
|
||||
public byte thingId;
|
||||
public byte objectType;
|
||||
public string modelUrl;
|
||||
//protected Sensor sensor;
|
||||
|
||||
public static List<Thing> allThings = new();
|
||||
|
||||
public static Thing GetThing(byte networkId, byte thingId) {
|
||||
Thing thing = allThings.Find(aThing => aThing.networkId == networkId && aThing.thingId == thingId);
|
||||
return thing;
|
||||
}
|
||||
|
||||
protected virtual void Init() {
|
||||
//if (this.objectType == 2) {
|
||||
// sensor = this.gameObject.AddComponent<DistanceSensor>();
|
||||
// sensor.thing = this;
|
||||
//}
|
||||
}
|
||||
|
||||
public static Thing Create(GameObject obj, Client client, byte networkId, byte objId, byte objType) {
|
||||
Thing thing = obj.AddComponent<Thing>();
|
||||
thing.client = client;
|
||||
thing.thingId = objId;
|
||||
thing.objectType = objType;
|
||||
thing.networkId = networkId;
|
||||
thing.Init();
|
||||
allThings.Add(thing);
|
||||
|
||||
return thing;
|
||||
}
|
||||
|
||||
public virtual Thing CopyTo(GameObject obj) {
|
||||
//Debug.Log($"copy {obj}");
|
||||
Thing foundThing = Thing.Create(obj, this.client, this.networkId, this.thingId, this.objectType);
|
||||
Destroy(this.gameObject);
|
||||
return foundThing;
|
||||
}
|
||||
|
||||
public void ProcessBytes(byte[] bytes) {
|
||||
//if (sensor != null)
|
||||
// sensor.ProcessBytes(bytes);
|
||||
}
|
||||
//public void Update() {
|
||||
// if (objectId == 0)
|
||||
// Debug.Log(this.transform.eulerAngles);
|
||||
//}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbfb00fc659e2d8489a48aafec5ddfc5
|
@ -1,258 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class float16 {
|
||||
//
|
||||
// FILE: float16.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.8
|
||||
// PURPOSE: library for Float16s for Arduino
|
||||
// URL: http://en.wikipedia.org/wiki/Half-precision_floating-point_format
|
||||
|
||||
ushort _value;
|
||||
|
||||
public float16() { _value = 0; }
|
||||
|
||||
public float16(float f) {
|
||||
_value = f32tof16(f);
|
||||
}
|
||||
|
||||
public float toFloat() {
|
||||
return f16tof32(_value);
|
||||
}
|
||||
|
||||
public ushort GetBinary() { return _value; }
|
||||
public void SetBinary(ushort value) { _value = value; }
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// EQUALITIES
|
||||
//
|
||||
/*
|
||||
bool float16::operator ==(const float16 &f) { return (_value == f._value); }
|
||||
|
||||
bool float16::operator !=(const float16 &f) { return (_value != f._value); }
|
||||
|
||||
bool float16::operator >(const float16 &f) {
|
||||
if ((_value & 0x8000) && (f._value & 0x8000))
|
||||
return _value < f._value;
|
||||
if (_value & 0x8000)
|
||||
return false;
|
||||
if (f._value & 0x8000)
|
||||
return true;
|
||||
return _value > f._value;
|
||||
}
|
||||
|
||||
bool float16::operator >=(const float16 &f) {
|
||||
if ((_value & 0x8000) && (f._value & 0x8000))
|
||||
return _value <= f._value;
|
||||
if (_value & 0x8000)
|
||||
return false;
|
||||
if (f._value & 0x8000)
|
||||
return true;
|
||||
return _value >= f._value;
|
||||
}
|
||||
|
||||
bool float16::operator <(const float16 &f) {
|
||||
if ((_value & 0x8000) && (f._value & 0x8000))
|
||||
return _value > f._value;
|
||||
if (_value & 0x8000)
|
||||
return true;
|
||||
if (f._value & 0x8000)
|
||||
return false;
|
||||
return _value < f._value;
|
||||
}
|
||||
|
||||
bool float16::operator <=(const float16 &f) {
|
||||
if ((_value & 0x8000) && (f._value & 0x8000))
|
||||
return _value >= f._value;
|
||||
if (_value & 0x8000)
|
||||
return true;
|
||||
if (f._value & 0x8000)
|
||||
return false;
|
||||
return _value <= f._value;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// NEGATION
|
||||
//
|
||||
float16 float16::operator -() {
|
||||
float16 f16;
|
||||
f16.setBinary(_value ^ 0x8000);
|
||||
return f16;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// MATH
|
||||
//
|
||||
float16 float16::operator +(const float16 &f) {
|
||||
return float16(this->toDouble() + f.toDouble());
|
||||
}
|
||||
|
||||
float16 float16::operator -(const float16 &f) {
|
||||
return float16(this->toDouble() - f.toDouble());
|
||||
}
|
||||
|
||||
float16 float16::operator *(const float16 &f) {
|
||||
return float16(this->toDouble() * f.toDouble());
|
||||
}
|
||||
|
||||
float16 float16::operator /(const float16 &f) {
|
||||
return float16(this->toDouble() / f.toDouble());
|
||||
}
|
||||
|
||||
float16 & float16::operator+=(const float16 &f) {
|
||||
*this = this->toDouble() + f.toDouble();
|
||||
return *this;
|
||||
}
|
||||
|
||||
float16 & float16::operator-=(const float16 &f) {
|
||||
*this = this->toDouble() - f.toDouble();
|
||||
return *this;
|
||||
}
|
||||
|
||||
float16 & float16::operator*=(const float16 &f) {
|
||||
*this = this->toDouble() * f.toDouble();
|
||||
return *this;
|
||||
}
|
||||
|
||||
float16 & float16::operator/=(const float16 &f) {
|
||||
*this = this->toDouble() / f.toDouble();
|
||||
return *this;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// MATH HELPER FUNCTIONS
|
||||
//
|
||||
int float16::sign() {
|
||||
if (_value & 0x8000)
|
||||
return -1;
|
||||
if (_value & 0xFFFF)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool float16::isZero() { return ((_value & 0x7FFF) == 0x0000); }
|
||||
|
||||
bool float16::isNaN() {
|
||||
if ((_value & 0x7C00) != 0x7C00)
|
||||
return false;
|
||||
if ((_value & 0x03FF) == 0x0000)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool float16::isInf() { return ((_value == 0x7C00) || (_value == 0xFC00)); }
|
||||
*/
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// CORE CONVERSION
|
||||
//
|
||||
float f16tof32(ushort _value) {
|
||||
//ushort sgn;
|
||||
ushort man;
|
||||
int exp;
|
||||
float f;
|
||||
|
||||
//Debug.Log($"{_value}");
|
||||
|
||||
bool sgn = (_value & 0x8000) > 0;
|
||||
exp = (_value & 0x7C00) >> 10;
|
||||
man = (ushort)(_value & 0x03FF);
|
||||
|
||||
//Debug.Log($"{sgn} {exp} {man}");
|
||||
|
||||
// ZERO
|
||||
if ((_value & 0x7FFF) == 0) {
|
||||
return sgn ? -0 : 0;
|
||||
}
|
||||
// NAN & INF
|
||||
if (exp == 0x001F) {
|
||||
if (man == 0)
|
||||
return sgn ? float.NegativeInfinity : float.PositiveInfinity; //-INFINITY : INFINITY;
|
||||
else
|
||||
return float.NaN; // NAN;
|
||||
}
|
||||
|
||||
// SUBNORMAL/NORMAL
|
||||
if (exp == 0)
|
||||
f = 0;
|
||||
else
|
||||
f = 1;
|
||||
|
||||
// PROCESS MANTISSE
|
||||
for (int i = 9; i >= 0; i--) {
|
||||
f *= 2;
|
||||
if ((man & (1 << i)) != 0)
|
||||
f = f + 1;
|
||||
}
|
||||
//Debug.Log($"{f}");
|
||||
f = f * Mathf.Pow(2.0f, exp - 25);
|
||||
if (exp == 0) {
|
||||
f = f * Mathf.Pow(2.0f, -13); // 5.96046447754e-8;
|
||||
}
|
||||
//Debug.Log($"{f}");
|
||||
return sgn ? -f : f;
|
||||
}
|
||||
|
||||
ushort f32tof16(float f) {
|
||||
//uint t = *(uint*)&f;
|
||||
uint t = (uint)BitConverter.SingleToInt32Bits(f);
|
||||
// man bits = 10; but we keep 11 for rounding
|
||||
ushort man = (ushort)((t & 0x007FFFFF) >> 12);
|
||||
short exp = (short)((t & 0x7F800000) >> 23);
|
||||
bool sgn = (t & 0x80000000) != 0;
|
||||
|
||||
// handle 0
|
||||
if ((t & 0x7FFFFFFF) == 0) {
|
||||
return sgn ? (ushort)0x8000 : (ushort)0x0000;
|
||||
}
|
||||
// denormalized float32 does not fit in float16
|
||||
if (exp == 0x00) {
|
||||
return sgn ? (ushort)0x8000 : (ushort)0x0000;
|
||||
}
|
||||
// handle infinity & NAN
|
||||
if (exp == 0x00FF) {
|
||||
if (man != 0)
|
||||
return 0xFE00; // NAN
|
||||
return sgn ? (ushort)0xFC00 : (ushort)0x7C00; // -INF : INF
|
||||
}
|
||||
|
||||
// normal numbers
|
||||
exp = (short)(exp - 127 + 15);
|
||||
// overflow does not fit => INF
|
||||
if (exp > 30) {
|
||||
return sgn ? (ushort)0xFC00 : (ushort)0x7C00; // -INF : INF
|
||||
}
|
||||
// subnormal numbers
|
||||
if (exp < -38) {
|
||||
return sgn ? (ushort)0x8000 : (ushort)0x0000; // -0 or 0 ? just 0 ?
|
||||
}
|
||||
if (exp <= 0) // subnormal
|
||||
{
|
||||
man >>= (exp + 14);
|
||||
// rounding
|
||||
man++;
|
||||
man >>= 1;
|
||||
if (sgn)
|
||||
return (ushort)(0x8000 | man);
|
||||
return man;
|
||||
}
|
||||
|
||||
// normal
|
||||
// TODO rounding
|
||||
exp <<= 10;
|
||||
man++;
|
||||
man >>= 1;
|
||||
if (sgn)
|
||||
return (ushort)(0x8000 | exp | man);
|
||||
return (ushort)(exp | man);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebe91dca635b85f4f94fb2469970b423
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
x
Reference in New Issue
Block a user