Sync daemon authority migration

This commit is contained in:
Meta Vens 2026-06-21 09:37:54 +01:00
commit 39a0dc8737
295 changed files with 25121 additions and 7360 deletions

View file

@ -6,11 +6,8 @@ using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text.RegularExpressions;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using Random = Unity.Mathematics.Random;
using Unity.Tiny;
using float2 = Unity.Mathematics.float2;
using float2 = CultMath.float2;
using Random = CultMath.Random;
public static class Extensions
{
@ -79,13 +76,13 @@ public static class Extensions
switch (rotation)
{
case ItemRotation.None:
return float2(0, 1);
return new float2(0, 1);
case ItemRotation.CounterClockwise:
return float2(-1, 0);
return new float2(-1, 0);
case ItemRotation.Reversed:
return float2(0, -1);
return new float2(0, -1);
case ItemRotation.Clockwise:
return float2(1, 0);
return new float2(1, 0);
default:
throw new ArgumentOutOfRangeException(nameof(rotation), rotation, null);
}
@ -98,11 +95,11 @@ public static class Extensions
case ItemRotation.None:
return v;
case ItemRotation.CounterClockwise:
return float2(-v.y, v.x);
return new float2(-v.y, v.x);
case ItemRotation.Reversed:
return float2(-v.x, -v.y);
return new float2(-v.x, -v.y);
case ItemRotation.Clockwise:
return float2(v.y, -v.x);
return new float2(v.y, -v.x);
default:
throw new ArgumentOutOfRangeException(nameof(rotation), rotation, null);
}
@ -112,9 +109,10 @@ public static class Extensions
//private static Random Random => (Random) (_random ??= new Random((uint) (DateTime.Now.Ticks%uint.MaxValue)));
// public static T RandomElement<T>(this IEnumerable<T> enumerable) => enumerable.ElementAt(Random.NextInt(0, enumerable.Count()));
public static float NextPowerDistribution(this ref Random random, float min, float max, float exp, float randexp) =>
pow((pow(max, exp + 1) - pow(min, exp + 1)) * pow(random.NextFloat(), randexp) + pow(min, exp + 1), 1 / (exp + 1));
MathF.Pow((MathF.Pow(max, exp + 1) - MathF.Pow(min, exp + 1)) * MathF.Pow(random.NextFloat(), randexp) + MathF.Pow(min, exp + 1), 1 / (exp + 1));
public static float NextUnbounded(this ref Random random) => 1 / (1 - random.NextFloat()) - 1;
public static float NextUnbounded(this ref Random random, float bias, float power, float ceiling) => 1 / (1 - pow(min(random.NextFloat(), ceiling), 1 - pow(clamp(bias,0,.99f), 1 / power))) - 1;
public static float NextUnbounded(this ref Random random, float bias, float power, float ceiling) =>
1 / (1 - MathF.Pow(MathF.Min(random.NextFloat(), ceiling), 1 - MathF.Pow(Clamp(bias, 0, .99f), 1 / power))) - 1;
public static bool IsDefault<T>(this T value) where T : struct
{
@ -130,8 +128,23 @@ public static class Extensions
public static float Angle(this float2 from, float2 to)
{
var num = sqrt(lengthsq(from) * lengthsq(to));
return num < 1.00000000362749E-15 ? 0.0f : acos(clamp(dot(from, to) / num, -1f, 1f)) * 57.29578f;
var num = MathF.Sqrt(LengthSquared(from) * LengthSquared(to));
return num < 1.00000000362749E-15 ? 0.0f : MathF.Acos(Clamp(Dot(from, to) / num, -1f, 1f)) * 57.29578f;
}
private static float Clamp(float value, float min, float max)
{
return value < min ? min : value > max ? max : value;
}
private static float Dot(float2 a, float2 b)
{
return a.x * b.x + a.y * b.y;
}
private static float LengthSquared(float2 value)
{
return Dot(value, value);
}
}