67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
namespace ChickenGameTest;
|
|
|
|
using System.Diagnostics;
|
|
using Godot;
|
|
using SJK.Functional;
|
|
|
|
public class TestStructural
|
|
{
|
|
public static void Test()
|
|
{
|
|
var a = new StructuralBuilder<object>()
|
|
.Add(new Vector3(0,0,0))
|
|
.Add(new Vector2(0,5))
|
|
.Add(new Vector4(0,0,0,0))
|
|
.Add(new Aabb())
|
|
.Add(new int())
|
|
.Add(new float())
|
|
.Add(new Node())
|
|
.Add(new Node())
|
|
.Add(new Node2D())
|
|
.Add("")
|
|
.Add(new test(){a = 5, b = "gg"})
|
|
.Build();
|
|
var registy = new StructuralInstanceManger<object>();
|
|
var b = registy.Add(a,new Vector2(1,2));
|
|
var c = registy.Add(a,new Vector2(1,2));
|
|
var d = registy.Canonicalize(new StructuralBuilder<object>(a).Add(new Vector2(1,2)).Build());
|
|
var g = new StructuralBuilder<object>(a).Add(Option<int>.Some(5)).Build();
|
|
var h = new StructuralBuilder<object>(a).Add(Option<int>.Some(5)).BuildMutable();
|
|
GD.Print(g.Equals(h));
|
|
GD.Print(ReferenceEquals(b,c));
|
|
GD.Print(ReferenceEquals(b,d));
|
|
GD.Print(ComponentType<Vector3>.Id);
|
|
GD.Print(ComponentType<Vector2>.Id);
|
|
|
|
var help = new StructuralBuilder<object>(a)
|
|
.CombineWith(b, static configure => configure
|
|
.Bind<Vector2>(static (a, b) => a + b)
|
|
.Ignore<Vector4>())
|
|
.Add(Vector2I.Zero)
|
|
.Build();
|
|
GD.Print(help.Get<Vector2>().Map(i=>$"{i}").OrDefault("none"));
|
|
var timer = new Stopwatch();
|
|
timer.Start();
|
|
for (int i = 0; i < 100000; i++)
|
|
{
|
|
var e = registy.AddOrReplaceAttribute(a,new test());
|
|
}
|
|
timer.Stop();
|
|
GD.Print(timer.Elapsed);
|
|
timer.Reset();
|
|
timer.Start();
|
|
for (int i = 0; i < 100000; i++)
|
|
{
|
|
var e = registy.Canonicalize(new StructuralBuilder<object>(a).Add(new test()).Build());
|
|
}
|
|
timer.Stop();
|
|
GD.Print(timer.Elapsed);
|
|
}
|
|
}
|
|
[ComponentOptions(CacheTransitions = true)]
|
|
record test
|
|
{
|
|
public int a;
|
|
public string b;
|
|
}
|