Updated Archetype

This commit is contained in:
2025-12-02 17:41:48 +09:00
parent 95cb9af16f
commit 63a70f1a74
3 changed files with 167 additions and 37 deletions

View File

@@ -5,34 +5,50 @@ using System.Runtime.CompilerServices;
namespace Ghost.ArcEntities;
internal struct ComponentInfo
public struct ComponentInfo
{
public int size;
public int alignment;
public int id;
}
internal static unsafe class ComponentType<T>
internal static unsafe class ComponentTypeID<T>
where T : unmanaged
{
public static readonly int Size = sizeof(T);
public static readonly int Alignment = (int)MemoryUtility.AlignOf<T>();
public static readonly int id = ComponentRegister.s_nextComponentTypeID++;
public static ComponentInfo GetInfo()
{
return new ComponentInfo
{
size = Size,
alignment = Alignment,
id = id
};
}
public static readonly int value = ComponentRegister.s_nextComponentTypeID++;
}
internal class ComponentRegister
internal static class ComponentRegister
{
internal static int s_nextComponentTypeID = 0;
internal static List<ComponentInfo> s_registeredComponents = new();
internal unsafe static int GetOrRegisterComponent<T>()
where T : unmanaged
{
var typeId = ComponentTypeID<T>.value;
while (s_registeredComponents.Count <= typeId)
{
s_registeredComponents.Add(default);
}
if (s_registeredComponents[typeId].size == 0)
{
s_registeredComponents[typeId] = new ComponentInfo
{
size = sizeof(T),
alignment = (int)MemoryUtility.AlignOf<T>(),
id = typeId
};
}
return typeId;
}
internal static ComponentInfo GetComponentInfo(int typeId)
{
return s_registeredComponents[typeId];
}
}
internal unsafe struct Chuck : IDisposable
@@ -43,7 +59,12 @@ internal unsafe struct Chuck : IDisposable
private int _count;
private int _capacity;
public int Count => _count;
public int Count
{
get => _count;
set => _count = value;
}
public int Capacity => _capacity;
public Chuck(int size, int capacity)