fix: added missing types for new primitives
This commit is contained in:
@@ -144,18 +144,26 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicat
|
|||||||
{
|
{
|
||||||
// I know, ugly af. I need to find a better way
|
// I know, ugly af. I need to find a better way
|
||||||
netPacketProcessor.RegisterNestedType(AABB2DNetPacker.Write, AABB2DNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(AABB2DNetPacker.Write, AABB2DNetPacker.Read);
|
||||||
|
netPacketProcessor.RegisterNestedType(AABB3DNetPacker.Write, AABB3DNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(CircleNetPacker.Write, CircleNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(CircleNetPacker.Write, CircleNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(ColorHSVNetPacker.Write, ColorHSVNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(ColorHSVNetPacker.Write, ColorHSVNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(ColorRGBANetPacker.Write, ColorRGBANetPacker.Read);
|
netPacketProcessor.RegisterNestedType(ColorHSVANetPacker.Write, ColorHSVANetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(ColorRGBNetPacker.Write, ColorRGBNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(ColorRGBNetPacker.Write, ColorRGBNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(Line2DEquationNetPacker.Write, Line2DEquationNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(ColorRGBANetPacker.Write, ColorRGBANetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(Line2DNetPacker.Write, Line2DNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(Line2DNetPacker.Write, Line2DNetPacker.Read);
|
||||||
|
netPacketProcessor.RegisterNestedType(Line2DEquationNetPacker.Write, Line2DEquationNetPacker.Read);
|
||||||
|
netPacketProcessor.RegisterNestedType(Line3DNetPacker.Write, Line3DNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(Projection1DNetPacker.Write, Projection1DNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(Projection1DNetPacker.Write, Projection1DNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(QuaternionNetPacker.Write, QuaternionNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(QuaternionNetPacker.Write, QuaternionNetPacker.Read);
|
||||||
|
netPacketProcessor.RegisterNestedType(Ray2DNetPacker.Write, Ray2DNetPacker.Read);
|
||||||
|
netPacketProcessor.RegisterNestedType(Ray3DNetPacker.Write, Ray3DNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(Shape2DNetPacker.Write, Shape2DNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(Shape2DNetPacker.Write, Shape2DNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(TriangleNetPacker.Write, TriangleNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(TriangleNetPacker.Write, TriangleNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(Vector2DNetPacker.Write, Vector2DNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(Vector2DNetPacker.Write, Vector2DNetPacker.Read);
|
||||||
|
netPacketProcessor.RegisterNestedType(Vector2DIntNetPacker.Write, Vector2DIntNetPacker.Read);
|
||||||
netPacketProcessor.RegisterNestedType(Vector3DNetPacker.Write, Vector3DNetPacker.Read);
|
netPacketProcessor.RegisterNestedType(Vector3DNetPacker.Write, Vector3DNetPacker.Read);
|
||||||
|
netPacketProcessor.RegisterNestedType(Vector3DIntNetPacker.Write, Vector3DIntNetPacker.Read);
|
||||||
|
netPacketProcessor.RegisterNestedType(Vector4DNetPacker.Write, Vector4DNetPacker.Read);
|
||||||
}
|
}
|
||||||
|
|
||||||
public INetworkCommunicator SubscribeToPackets<T>(Event<IConnection, T>.EventHandler callback)
|
public INetworkCommunicator SubscribeToPackets<T>(Event<IConnection, T>.EventHandler callback)
|
||||||
|
@@ -0,0 +1,26 @@
|
|||||||
|
using LiteNetLib.Utils;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Network;
|
||||||
|
|
||||||
|
internal static class ColorHSVANetPacker
|
||||||
|
{
|
||||||
|
internal static void Write(NetDataWriter writer, ColorHSVA data)
|
||||||
|
{
|
||||||
|
writer.Put(data.Hue);
|
||||||
|
writer.Put(data.Saturation);
|
||||||
|
writer.Put(data.Value);
|
||||||
|
writer.Put(data.Alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static ColorHSVA Read(NetDataReader reader)
|
||||||
|
{
|
||||||
|
float hue = reader.GetFloat();
|
||||||
|
float saturation = reader.GetFloat();
|
||||||
|
float value = reader.GetFloat();
|
||||||
|
float alpha = reader.GetFloat();
|
||||||
|
|
||||||
|
return new ColorHSVA(hue, saturation, value, alpha);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
using LiteNetLib.Utils;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Network;
|
||||||
|
|
||||||
|
internal static class Line3DNetPacker
|
||||||
|
{
|
||||||
|
internal static void Write(NetDataWriter writer, Line3D data)
|
||||||
|
{
|
||||||
|
Vector3DNetPacker.Write(writer, data.From);
|
||||||
|
Vector3DNetPacker.Write(writer, data.To);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static Line3D Read(NetDataReader reader)
|
||||||
|
{
|
||||||
|
Vector3D from = Vector3DNetPacker.Read(reader);
|
||||||
|
Vector3D to = Vector3DNetPacker.Read(reader);
|
||||||
|
|
||||||
|
return new Line3D(from, to);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
using LiteNetLib.Utils;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Network;
|
||||||
|
|
||||||
|
internal static class Ray2DNetPacker
|
||||||
|
{
|
||||||
|
internal static void Write(NetDataWriter writer, Ray2D data)
|
||||||
|
{
|
||||||
|
Vector2DNetPacker.Write(writer, data.Origin);
|
||||||
|
Vector2DNetPacker.Write(writer, data.Direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static Ray2D Read(NetDataReader reader)
|
||||||
|
{
|
||||||
|
Vector2D from = Vector2DNetPacker.Read(reader);
|
||||||
|
Vector2D direction = Vector2DNetPacker.Read(reader);
|
||||||
|
|
||||||
|
return new Ray2D(from, direction);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
using LiteNetLib.Utils;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Network;
|
||||||
|
|
||||||
|
internal static class Ray3DNetPacker
|
||||||
|
{
|
||||||
|
internal static void Write(NetDataWriter writer, Ray3D data)
|
||||||
|
{
|
||||||
|
Vector3DNetPacker.Write(writer, data.Origin);
|
||||||
|
Vector3DNetPacker.Write(writer, data.Direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static Ray3D Read(NetDataReader reader)
|
||||||
|
{
|
||||||
|
Vector3D from = Vector3DNetPacker.Read(reader);
|
||||||
|
Vector3D direction = Vector3DNetPacker.Read(reader);
|
||||||
|
|
||||||
|
return new Ray3D(from, direction);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
using LiteNetLib.Utils;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Network;
|
||||||
|
|
||||||
|
internal static class Vector2DIntNetPacker
|
||||||
|
{
|
||||||
|
internal static void Write(NetDataWriter writer, Vector2DInt data)
|
||||||
|
{
|
||||||
|
writer.Put(data.X);
|
||||||
|
writer.Put(data.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static Vector2DInt Read(NetDataReader reader)
|
||||||
|
{
|
||||||
|
int x = reader.GetInt();
|
||||||
|
int y = reader.GetInt();
|
||||||
|
|
||||||
|
return new Vector2DInt(x, y);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,24 @@
|
|||||||
|
using LiteNetLib.Utils;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Network;
|
||||||
|
|
||||||
|
internal static class Vector3DIntNetPacker
|
||||||
|
{
|
||||||
|
internal static void Write(NetDataWriter writer, Vector3DInt data)
|
||||||
|
{
|
||||||
|
writer.Put(data.X);
|
||||||
|
writer.Put(data.Y);
|
||||||
|
writer.Put(data.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static Vector3DInt Read(NetDataReader reader)
|
||||||
|
{
|
||||||
|
int x = reader.GetInt();
|
||||||
|
int y = reader.GetInt();
|
||||||
|
int z = reader.GetInt();
|
||||||
|
|
||||||
|
return new Vector3DInt(x, y, z);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,26 @@
|
|||||||
|
using LiteNetLib.Utils;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Network;
|
||||||
|
|
||||||
|
internal static class Vector4DNetPacker
|
||||||
|
{
|
||||||
|
internal static void Write(NetDataWriter writer, Vector4D data)
|
||||||
|
{
|
||||||
|
writer.Put(data.X);
|
||||||
|
writer.Put(data.Y);
|
||||||
|
writer.Put(data.Z);
|
||||||
|
writer.Put(data.W);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static Vector4D Read(NetDataReader reader)
|
||||||
|
{
|
||||||
|
float x = reader.GetFloat();
|
||||||
|
float y = reader.GetFloat();
|
||||||
|
float z = reader.GetFloat();
|
||||||
|
float w = reader.GetFloat();
|
||||||
|
|
||||||
|
return new Vector4D(x, y, z, w);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
using YamlDotNet.Core.Events;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace Engine.Serializers.Yaml;
|
||||||
|
|
||||||
|
public class ColorHSVAConverter : EngineTypeYamlSerializerBase<ColorHSVA>
|
||||||
|
{
|
||||||
|
private static readonly int SUBSTRING_START_LENGTH = nameof(ColorHSVA).Length + 1;
|
||||||
|
|
||||||
|
public override ColorHSVA Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||||
|
{
|
||||||
|
string value = parser.Consume<Scalar>().Value;
|
||||||
|
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
|
||||||
|
string[] values = insideParenthesis.Split(", ");
|
||||||
|
return new ColorHSVA(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]), float.Parse(values[3]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||||
|
{
|
||||||
|
ColorHSVA hsva = (ColorHSVA)value!;
|
||||||
|
emitter.Emit(new Scalar($"{nameof(ColorHSVA)}({hsva.Hue}, {hsva.Saturation}, {hsva.Value}, {hsva.Alpha})"));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
using YamlDotNet.Core.Events;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace Engine.Serializers.Yaml;
|
||||||
|
|
||||||
|
public class Line3DConverter : EngineTypeYamlSerializerBase<Line3D>
|
||||||
|
{
|
||||||
|
public override Line3D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||||
|
{
|
||||||
|
parser.Consume<MappingStart>();
|
||||||
|
|
||||||
|
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Line3D.From)) != 0)
|
||||||
|
throw new ArgumentException($"{nameof(Line3D)} mapping must start with {nameof(Line3D.From)}");
|
||||||
|
Vector3D from = (Vector3D)rootDeserializer(typeof(Vector3D))!;
|
||||||
|
|
||||||
|
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Line3D.To)) != 0)
|
||||||
|
throw new ArgumentException($"{nameof(Line3D)} mapping must end with {nameof(Line3D.To)}");
|
||||||
|
Vector3D to = (Vector3D)rootDeserializer(typeof(Vector3D))!;
|
||||||
|
|
||||||
|
parser.Consume<MappingEnd>();
|
||||||
|
|
||||||
|
return new Line3D(from, to);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||||
|
{
|
||||||
|
Line3D line3D = (Line3D)value!;
|
||||||
|
|
||||||
|
emitter.Emit(new MappingStart());
|
||||||
|
emitter.Emit(new Scalar(nameof(Line3D.From)));
|
||||||
|
serializer(line3D.From, typeof(Vector3D));
|
||||||
|
emitter.Emit(new Scalar(nameof(Line3D.To)));
|
||||||
|
serializer(line3D.To, typeof(Vector3D));
|
||||||
|
emitter.Emit(new MappingEnd());
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
using YamlDotNet.Core.Events;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace Engine.Serializers.Yaml;
|
||||||
|
|
||||||
|
public class Ray2DConverter : EngineTypeYamlSerializerBase<Ray2D>
|
||||||
|
{
|
||||||
|
public override Ray2D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||||
|
{
|
||||||
|
parser.Consume<MappingStart>();
|
||||||
|
|
||||||
|
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Ray2D.Origin)) != 0)
|
||||||
|
throw new ArgumentException($"{nameof(Ray2D)} mapping must start with {nameof(Ray2D.Origin)}");
|
||||||
|
Vector2D origin = (Vector2D)rootDeserializer(typeof(Vector2D))!;
|
||||||
|
|
||||||
|
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Ray2D.Direction)) != 0)
|
||||||
|
throw new ArgumentException($"{nameof(Ray2D)} mapping must end with {nameof(Ray2D.Direction)}");
|
||||||
|
Vector2D direction = (Vector2D)rootDeserializer(typeof(Vector2D))!;
|
||||||
|
|
||||||
|
parser.Consume<MappingEnd>();
|
||||||
|
|
||||||
|
return new Ray2D(origin, direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||||
|
{
|
||||||
|
Ray2D ray2D = (Ray2D)value!;
|
||||||
|
|
||||||
|
emitter.Emit(new MappingStart());
|
||||||
|
emitter.Emit(new Scalar(nameof(ray2D.Origin)));
|
||||||
|
serializer(ray2D.Origin, typeof(Vector2D));
|
||||||
|
emitter.Emit(new Scalar(nameof(ray2D.Direction)));
|
||||||
|
serializer(ray2D.Direction, typeof(Vector2D));
|
||||||
|
emitter.Emit(new MappingEnd());
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
using YamlDotNet.Core.Events;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace Engine.Serializers.Yaml;
|
||||||
|
|
||||||
|
public class Ray3DConverter : EngineTypeYamlSerializerBase<Ray3D>
|
||||||
|
{
|
||||||
|
public override Ray3D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||||
|
{
|
||||||
|
parser.Consume<MappingStart>();
|
||||||
|
|
||||||
|
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Ray3D.Origin)) != 0)
|
||||||
|
throw new ArgumentException($"{nameof(Ray3D)} mapping must start with {nameof(Ray3D.Origin)}");
|
||||||
|
Vector3D origin = (Vector3D)rootDeserializer(typeof(Vector3D))!;
|
||||||
|
|
||||||
|
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Ray3D.Direction)) != 0)
|
||||||
|
throw new ArgumentException($"{nameof(Ray3D)} mapping must end with {nameof(Ray3D.Direction)}");
|
||||||
|
Vector3D direction = (Vector3D)rootDeserializer(typeof(Vector3D))!;
|
||||||
|
|
||||||
|
parser.Consume<MappingEnd>();
|
||||||
|
|
||||||
|
return new Ray3D(origin, direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||||
|
{
|
||||||
|
Ray3D ray3D = (Ray3D)value!;
|
||||||
|
|
||||||
|
emitter.Emit(new MappingStart());
|
||||||
|
emitter.Emit(new Scalar(nameof(ray3D.Origin)));
|
||||||
|
serializer(ray3D.Origin, typeof(Vector3D));
|
||||||
|
emitter.Emit(new Scalar(nameof(ray3D.Direction)));
|
||||||
|
serializer(ray3D.Direction, typeof(Vector3D));
|
||||||
|
emitter.Emit(new MappingEnd());
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
using YamlDotNet.Core.Events;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace Engine.Serializers.Yaml;
|
||||||
|
|
||||||
|
public class Vector2DIntConverter : EngineTypeYamlSerializerBase<Vector2DInt>
|
||||||
|
{
|
||||||
|
private static readonly int SUBSTRING_START_LENGTH = nameof(Vector2DInt).Length + 1;
|
||||||
|
|
||||||
|
public override Vector2DInt Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||||
|
{
|
||||||
|
string value = parser.Consume<Scalar>().Value;
|
||||||
|
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
|
||||||
|
string[] values = insideParenthesis.Split(", ");
|
||||||
|
return new Vector2DInt(int.Parse(values[0]), int.Parse(values[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||||
|
{
|
||||||
|
Vector2DInt vector2DInt = (Vector2DInt)value!;
|
||||||
|
emitter.Emit(new Scalar($"{nameof(Vector2DInt)}({vector2DInt.X}, {vector2DInt.Y})"));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
using YamlDotNet.Core.Events;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace Engine.Serializers.Yaml;
|
||||||
|
|
||||||
|
public class Vector3DIntConverter : EngineTypeYamlSerializerBase<Vector3DInt>
|
||||||
|
{
|
||||||
|
private static readonly int SUBSTRING_START_LENGTH = nameof(Vector3DInt).Length + 1;
|
||||||
|
|
||||||
|
public override Vector3DInt Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||||
|
{
|
||||||
|
string value = parser.Consume<Scalar>().Value;
|
||||||
|
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
|
||||||
|
string[] values = insideParenthesis.Split(", ");
|
||||||
|
return new Vector3DInt(int.Parse(values[0]), int.Parse(values[1]), int.Parse(values[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||||
|
{
|
||||||
|
Vector3DInt vector3DInt = (Vector3DInt)value!;
|
||||||
|
emitter.Emit(new Scalar($"{nameof(Vector3DInt)}({vector3DInt.X}, {vector3DInt.Y}, {vector3DInt.Z})"));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
using YamlDotNet.Core.Events;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace Engine.Serializers.Yaml;
|
||||||
|
|
||||||
|
public class Vector4DConverter : EngineTypeYamlSerializerBase<Vector4D>
|
||||||
|
{
|
||||||
|
private static readonly int SUBSTRING_START_LENGTH = nameof(Vector4D).Length + 1;
|
||||||
|
|
||||||
|
public override Vector4D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||||
|
{
|
||||||
|
string value = parser.Consume<Scalar>().Value;
|
||||||
|
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
|
||||||
|
string[] values = insideParenthesis.Split(", ");
|
||||||
|
return new Vector4D(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]), float.Parse(values[3]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||||
|
{
|
||||||
|
Vector4D vector4D = (Vector4D)value!;
|
||||||
|
emitter.Emit(new Scalar($"{nameof(Vector4D)}({vector4D.X}, {vector4D.Y}, {vector4D.Z}, {vector4D.W})"));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,31 @@
|
|||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Tween;
|
||||||
|
|
||||||
|
public static class TweenLine3DExtensions
|
||||||
|
{
|
||||||
|
private static readonly BoxedPool<Line3D> boxedLine3DPool = new(2);
|
||||||
|
|
||||||
|
public static ITween TweenLine3D(this Line3D initialLine3D, ITweenManager tweenManager, float duration, Line3D targetLine3D, System.Action<Line3D> setMethod)
|
||||||
|
{
|
||||||
|
Boxed<Line3D> boxedInitial = boxedLine3DPool.Get(initialLine3D);
|
||||||
|
Boxed<Line3D> boxedTarget = boxedLine3DPool.Get(targetLine3D);
|
||||||
|
|
||||||
|
ITween tween = tweenManager.StartTween(duration,
|
||||||
|
t => setMethod?.Invoke(
|
||||||
|
new Line3D(
|
||||||
|
boxedInitial.Value.From.Lerp(boxedTarget.Value.From, t),
|
||||||
|
boxedInitial.Value.To.Lerp(boxedTarget.Value.To, t)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
tween.OnComplete(() =>
|
||||||
|
{
|
||||||
|
boxedLine3DPool.Return(boxedInitial);
|
||||||
|
boxedLine3DPool.Return(boxedTarget);
|
||||||
|
});
|
||||||
|
|
||||||
|
return tween;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,31 @@
|
|||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Tween;
|
||||||
|
|
||||||
|
public static class TweenRay2DExtensions
|
||||||
|
{
|
||||||
|
private static readonly BoxedPool<Ray2D> boxedRay2DPool = new(2);
|
||||||
|
|
||||||
|
public static ITween TweenRay2D(this Ray2D initialRay2D, ITweenManager tweenManager, float duration, Ray2D targetRay2D, System.Action<Ray2D> setMethod)
|
||||||
|
{
|
||||||
|
Boxed<Ray2D> boxedInitial = boxedRay2DPool.Get(initialRay2D);
|
||||||
|
Boxed<Ray2D> boxedTarget = boxedRay2DPool.Get(targetRay2D);
|
||||||
|
|
||||||
|
ITween tween = tweenManager.StartTween(duration,
|
||||||
|
t => setMethod?.Invoke(
|
||||||
|
new Ray2D(
|
||||||
|
boxedInitial.Value.Origin.Lerp(boxedTarget.Value.Origin, t),
|
||||||
|
boxedInitial.Value.Direction.Lerp(boxedTarget.Value.Direction, t).Normalized
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
tween.OnComplete(() =>
|
||||||
|
{
|
||||||
|
boxedRay2DPool.Return(boxedInitial);
|
||||||
|
boxedRay2DPool.Return(boxedTarget);
|
||||||
|
});
|
||||||
|
|
||||||
|
return tween;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,31 @@
|
|||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Tween;
|
||||||
|
|
||||||
|
public static class TweenRay3DExtensions
|
||||||
|
{
|
||||||
|
private static readonly BoxedPool<Ray3D> boxedRay3DPool = new(2);
|
||||||
|
|
||||||
|
public static ITween TweenRay3D(this Ray3D initialRay3D, ITweenManager tweenManager, float duration, Ray3D targetRay3D, System.Action<Ray3D> setMethod)
|
||||||
|
{
|
||||||
|
Boxed<Ray3D> boxedInitial = boxedRay3DPool.Get(initialRay3D);
|
||||||
|
Boxed<Ray3D> boxedTarget = boxedRay3DPool.Get(targetRay3D);
|
||||||
|
|
||||||
|
ITween tween = tweenManager.StartTween(duration,
|
||||||
|
t => setMethod?.Invoke(
|
||||||
|
new Ray3D(
|
||||||
|
boxedInitial.Value.Origin.Lerp(boxedTarget.Value.Origin, t),
|
||||||
|
boxedInitial.Value.Direction.Lerp(boxedTarget.Value.Direction, t).Normalized
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
tween.OnComplete(() =>
|
||||||
|
{
|
||||||
|
boxedRay3DPool.Return(boxedInitial);
|
||||||
|
boxedRay3DPool.Return(boxedTarget);
|
||||||
|
});
|
||||||
|
|
||||||
|
return tween;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,24 @@
|
|||||||
|
using Engine.Core;
|
||||||
|
|
||||||
|
namespace Engine.Systems.Tween;
|
||||||
|
|
||||||
|
public static class TweenVector4DExtensions
|
||||||
|
{
|
||||||
|
private static readonly BoxedPool<Vector4D> boxedVector4DPool = new(2);
|
||||||
|
|
||||||
|
public static ITween TweenVector4D(this Vector4D initialVector4D, ITweenManager tweenManager, float duration, Vector4D targetVector4D, System.Action<Vector4D> setMethod)
|
||||||
|
{
|
||||||
|
Boxed<Vector4D> boxedInitial = boxedVector4DPool.Get(initialVector4D);
|
||||||
|
Boxed<Vector4D> boxedTarget = boxedVector4DPool.Get(targetVector4D);
|
||||||
|
|
||||||
|
ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.Lerp(boxedTarget.Value, t)));
|
||||||
|
|
||||||
|
tween.OnComplete(() =>
|
||||||
|
{
|
||||||
|
boxedVector4DPool.Return(boxedInitial);
|
||||||
|
boxedVector4DPool.Return(boxedTarget);
|
||||||
|
});
|
||||||
|
|
||||||
|
return tween;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user