Redid inserrt logic and grid registry, added an test oven, and changed .vscode settings to try and get better debugging.

This commit is contained in:
2026-04-26 23:51:03 -04:00
parent 7d25f6d448
commit 4a7494ff6b
12 changed files with 294 additions and 68 deletions

View File

@@ -8,18 +8,21 @@ using System;
using System.Collections.Generic;
using System.Linq;
using ChickenGameTest;
using SJK.Functional;
public interface IVoxelGridRegistry
{
void Register<T>(T voxelNode, params Vector3I[] positions);
void UnRegister<T>(T voxelNode, params Vector3I[] positions);
void UnRegister(Guid id);
VoxelGuid Register<T>(T voxelNode, params Vector3I[] positions) where T : class;
void UnRegister(VoxelGuid id);
IEnumerable<T> Get<T>(Vector3I voxelPos);
IEnumerable<T> Get<T>(params Vector3I[] voxelPos);
}
public readonly record struct VoxelGuid(Guid Id);
public sealed class VoxelRegistry : IVoxelGridRegistry
{
private readonly Dictionary<Guid, VoxelEntry> _voxelPositions = new();
private readonly record struct VoxelEntry(object Item, Vector3I[] Entries);
private Dictionary<Vector3I, ICollection<object>> _data;
public VoxelRegistry()
{
@@ -48,7 +51,7 @@ public sealed class VoxelRegistry : IVoxelGridRegistry
}
}
public void Register<T>(T voxelNode, params Vector3I[] positions)
public VoxelGuid Register<T>(T voxelNode, params Vector3I[] positions) where T : class
{
void register(Vector3I pos, T point)
{
@@ -61,29 +64,21 @@ public sealed class VoxelRegistry : IVoxelGridRegistry
}
foreach (var pos in positions)
{
if (positions.Length > 1)
{
GD.Print("hhhhhhhhh ", pos);
}
register(pos, voxelNode);//TODO Acount For Rotation
}
var guid = new VoxelGuid(Guid.NewGuid());
_voxelPositions[guid.Id] = new(voxelNode, positions);
return guid;
}
public void UnRegister(Guid id) => throw new NotImplementedException();
public void UnRegister<T>(T voxelNode, params Vector3I[] positions)
{
void unRegister(Vector3I pos, T point)
public void UnRegister(VoxelGuid id) =>
_voxelPositions.GetValue(id.Id).IfSome(e =>
{
if (!_data.TryGetValue(pos, out var entrys))
foreach (var item in e.Entries)
{
return;
_data.GetValue(item).IfSome(i => i.Remove(e.Item));
}
entrys.Remove(point);
}
foreach (var item in positions)
{
unRegister(item, voxelNode);
}
}
});
}
public enum Direction