feat: added LiteNetLib networking integration
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class AABBNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, AABB data)
|
||||
{
|
||||
Vector2DNetPacker.Write(writer, data.LowerBoundary);
|
||||
Vector2DNetPacker.Write(writer, data.UpperBoundary);
|
||||
}
|
||||
|
||||
internal static AABB Read(NetDataReader reader)
|
||||
{
|
||||
Vector2D lowerBoundary = Vector2DNetPacker.Read(reader);
|
||||
Vector2D upperBoundary = Vector2DNetPacker.Read(reader);
|
||||
|
||||
return new AABB(lowerBoundary, upperBoundary);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class CircleNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Circle data)
|
||||
{
|
||||
Vector2DNetPacker.Write(writer, data.Center);
|
||||
writer.Put(data.Radius);
|
||||
}
|
||||
|
||||
internal static Circle Read(NetDataReader reader)
|
||||
{
|
||||
Vector2D center = Vector2DNetPacker.Read(reader);
|
||||
float radius = reader.GetFloat();
|
||||
|
||||
return new Circle(center, radius);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class ColorHSVNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, ColorHSV data)
|
||||
{
|
||||
writer.Put(data.Hue);
|
||||
writer.Put(data.Saturation);
|
||||
writer.Put(data.Value);
|
||||
}
|
||||
|
||||
internal static ColorHSV Read(NetDataReader reader)
|
||||
{
|
||||
float hue = reader.GetFloat();
|
||||
float saturation = reader.GetFloat();
|
||||
float value = reader.GetFloat();
|
||||
|
||||
return new ColorHSV(hue, saturation, value);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class ColorRGBANetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, ColorRGBA data)
|
||||
{
|
||||
writer.Put(data.R);
|
||||
writer.Put(data.G);
|
||||
writer.Put(data.B);
|
||||
writer.Put(data.A);
|
||||
}
|
||||
|
||||
internal static ColorRGBA Read(NetDataReader reader)
|
||||
{
|
||||
byte red = reader.GetByte();
|
||||
byte green = reader.GetByte();
|
||||
byte blue = reader.GetByte();
|
||||
byte alpha = reader.GetByte();
|
||||
|
||||
return new ColorRGBA(red, green, blue, alpha);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class ColorRGBNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, ColorRGB data)
|
||||
{
|
||||
writer.Put(data.R);
|
||||
writer.Put(data.G);
|
||||
writer.Put(data.B);
|
||||
}
|
||||
|
||||
internal static ColorRGB Read(NetDataReader reader)
|
||||
{
|
||||
byte red = reader.GetByte();
|
||||
byte green = reader.GetByte();
|
||||
byte blue = reader.GetByte();
|
||||
|
||||
return new ColorRGB(red, green, blue);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class Line2DEquationNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Line2DEquation data)
|
||||
{
|
||||
writer.Put(data.Slope);
|
||||
writer.Put(data.OffsetY);
|
||||
}
|
||||
|
||||
internal static Line2DEquation Read(NetDataReader reader)
|
||||
{
|
||||
float slope = reader.GetFloat();
|
||||
float offsetY = reader.GetFloat();
|
||||
|
||||
return new Line2DEquation(slope, offsetY);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class Line2DNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Line2D data)
|
||||
{
|
||||
Vector2DNetPacker.Write(writer, data.From);
|
||||
Vector2DNetPacker.Write(writer, data.To);
|
||||
}
|
||||
|
||||
internal static Line2D Read(NetDataReader reader)
|
||||
{
|
||||
Vector2D from = Vector2DNetPacker.Read(reader);
|
||||
Vector2D to = Vector2DNetPacker.Read(reader);
|
||||
|
||||
return new Line2D(from, to);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class Projection1DNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Projection1D data)
|
||||
{
|
||||
writer.Put(data.Min);
|
||||
writer.Put(data.Max);
|
||||
}
|
||||
|
||||
internal static Projection1D Read(NetDataReader reader)
|
||||
{
|
||||
float min = reader.GetFloat();
|
||||
float max = reader.GetFloat();
|
||||
|
||||
return new Projection1D(min, max);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class QuaternionNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Quaternion data)
|
||||
{
|
||||
writer.Put(data.X);
|
||||
writer.Put(data.Y);
|
||||
writer.Put(data.Z);
|
||||
writer.Put(data.W);
|
||||
}
|
||||
|
||||
internal static Quaternion Read(NetDataReader reader)
|
||||
{
|
||||
float x = reader.GetFloat();
|
||||
float y = reader.GetFloat();
|
||||
float z = reader.GetFloat();
|
||||
float w = reader.GetFloat();
|
||||
|
||||
return new Quaternion(x, y, z, w);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class Shape2DNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Shape2D data)
|
||||
{
|
||||
writer.Put(data.Vertices.Count);
|
||||
foreach (Vector2D vertex in data.Vertices)
|
||||
Vector2DNetPacker.Write(writer, vertex);
|
||||
}
|
||||
|
||||
internal static Shape2D Read(NetDataReader reader)
|
||||
{
|
||||
int verticesCount = reader.GetInt();
|
||||
List<Vector2D> vertices = new(verticesCount);
|
||||
|
||||
for (int i = 0; i < verticesCount; i++)
|
||||
vertices.Add(Vector2DNetPacker.Read(reader));
|
||||
|
||||
return new Shape2D(vertices);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class TriangleNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Triangle data)
|
||||
{
|
||||
Vector2DNetPacker.Write(writer, data.A);
|
||||
Vector2DNetPacker.Write(writer, data.B);
|
||||
Vector2DNetPacker.Write(writer, data.C);
|
||||
}
|
||||
|
||||
internal static Triangle Read(NetDataReader reader)
|
||||
{
|
||||
Vector2D a = Vector2DNetPacker.Read(reader);
|
||||
Vector2D b = Vector2DNetPacker.Read(reader);
|
||||
Vector2D c = Vector2DNetPacker.Read(reader);
|
||||
|
||||
return new Triangle(a, b, c);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class Vector2DNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Vector2D data)
|
||||
{
|
||||
writer.Put(data.X);
|
||||
writer.Put(data.Y);
|
||||
}
|
||||
|
||||
internal static Vector2D Read(NetDataReader reader)
|
||||
{
|
||||
float x = reader.GetFloat();
|
||||
float y = reader.GetFloat();
|
||||
|
||||
return new Vector2D(x, y);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
internal static class Vector3DNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Vector3D data)
|
||||
{
|
||||
writer.Put(data.X);
|
||||
writer.Put(data.Y);
|
||||
writer.Put(data.Z);
|
||||
}
|
||||
|
||||
internal static Vector3D Read(NetDataReader reader)
|
||||
{
|
||||
float x = reader.GetFloat();
|
||||
float y = reader.GetFloat();
|
||||
float z = reader.GetFloat();
|
||||
|
||||
return new Vector3D(x, y, z);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user