Files
GhostEngine/Ghost.ArchetypeEntities/Registries/ComponentRegistry.cs
Misaki 0cf3104a6a Implement core entity management features
Added `Archetype` struct with chunk management and disposal.
Added `BitSet` class for managing collections of bits.
Added `Class1.cs` as a placeholder for graphics functionality.
Added `ComponentData` struct and `ComponentPool` class for component management.
Added `ComponentRegistry` for efficient component registration.
Added `EntityChangeQueue` as a placeholder for future changes.
Added `Helpers.ttinclude` and `QueryRefComponent.tt` for code generation.
Added `Signature` struct for managing component signatures.
Added `World` struct to manage the game world and entities.
Added `QueryRefComponent` delegates for querying entities.

Changed `Archetype.cs` to implement `IDisposable`.
Changed `AssemblyInfo.cs` to update global using directives.
Changed `Chunk.cs` to introduce `ChunkCollection` for chunk management.
Changed `Component.cs` to refine component management methods.
Changed `Entity.cs` to improve properties and methods.
Changed `Ghost.Entities.csproj` to update project properties.
Changed `Program.cs` to demonstrate entity creation and querying.
Changed `World.Query.cs` to facilitate querying with components.
2025-05-21 11:46:48 +09:00

22 lines
606 B
C#

namespace Ghost.Entities.Registries;
internal static class ComponentRegistry
{
private static readonly Dictionary<Type, ComponentData> _hashCodeToComponentMap = new(64);
public static unsafe ComponentData GetOrAdd<T>()
where T : unmanaged, IComponent
{
var type = typeof(T);
if (_hashCodeToComponentMap.TryGetValue(type, out var data))
{
return data;
}
var id = (ushort)_hashCodeToComponentMap.Count;
data = new ComponentData(id, sizeof(T));
_hashCodeToComponentMap.Add(type, data);
return data;
}
}