Aetheria/Assets/Scripts/ServerShared/MathResolver.cs
Reinier Vens f643f6cc8a New Inventory System + Overhaul
Removed universal GameContext references
Refactored GameContext: It's now only responsible for item management. As such it's now called ItemManager
GlobalData is gone, relevant settings are distributed amongst specialized settings classes
Entities are no longer database entries, references to them are now direct - Zone is reponsible for storing them in ZonePacks
Controller subtypes are now generic classes, class argument is task type
Inventory is now a 2D grid instead of a list
Entity temperature is now a 2D grid instead of a number
Item sizes are now arbitrary shapes instead of a number
Hardpoints are now arbitrary shapes instead
Equipped items have their own temperatures
Map view now displays sunlight colors
Integrated Allegorithmic Substance Plugin
Imported Djinni ship and assigned Substance materials
Removed Node Editor framework (might come back later but needs work to integrate with behavior system)
2020-12-10 23:20:38 +00:00

79 lines
2.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;
using MessagePack.Formatters;
using Unity.Mathematics;
using static Unity.Mathematics.math;
public class MathResolver : IFormatterResolver
{
public static readonly MathResolver Instance = new MathResolver();
private MathResolver()
{
}
public IMessagePackFormatter<T> GetFormatter<T>()
{
return FormatterCache<T>.Formatter;
}
private static class FormatterCache<T>
{
public static readonly IMessagePackFormatter<T> Formatter;
static FormatterCache()
{
Formatter = (IMessagePackFormatter<T>)MathResolverResolverGetFormatterHelper.GetFormatter(typeof(T));
}
}
}
internal static class MathResolverResolverGetFormatterHelper
{
private static readonly Dictionary<Type, object> FormatterMap = new Dictionary<Type, object>()
{
// standard
{ typeof(float2), new Float2Formatter() },
{ typeof(int2), new Int2Formatter() },
{ typeof(float3), new Float3Formatter() },
{ typeof(float4), new Float4Formatter() },
{ typeof(float2?), new StaticNullableFormatter<float2>(new Float2Formatter()) },
{ typeof(int2?), new StaticNullableFormatter<int2>(new Int2Formatter()) },
{ typeof(float3?), new StaticNullableFormatter<float3>(new Float3Formatter()) },
{ typeof(float4?), new StaticNullableFormatter<float4>(new Float4Formatter()) },
// standard + array
{ typeof(float2[]), new ArrayFormatter<float2>() },
{ typeof(int2[]), new ArrayFormatter<int2>() },
{ typeof(float3[]), new ArrayFormatter<float3>() },
{ typeof(float4[]), new ArrayFormatter<float4>() },
{ typeof(float2?[]), new ArrayFormatter<float2?>() },
{ typeof(int2?[]), new ArrayFormatter<float2?>() },
{ typeof(float3?[]), new ArrayFormatter<float3?>() },
{ typeof(float4?[]), new ArrayFormatter<float4?>() },
// standard + list
{ typeof(List<float2>), new ListFormatter<float2>() },
{ typeof(List<int2>), new ListFormatter<int2>() },
{ typeof(List<float3>), new ListFormatter<float3>() },
{ typeof(List<float4>), new ListFormatter<float4>() },
{ typeof(List<float2?>), new ListFormatter<float2?>() },
{ typeof(List<int2?>), new ListFormatter<int2?>() },
{ typeof(List<float3?>), new ListFormatter<float3?>() },
{ typeof(List<float4?>), new ListFormatter<float4?>() },
};
internal static object GetFormatter(Type t)
{
object formatter;
if (FormatterMap.TryGetValue(t, out formatter))
{
return formatter;
}
return null;
}
}