diff --git a/src/ComponentDepot.cs b/src/ComponentDepot.cs index 02afb20..beb96de 100644 --- a/src/ComponentDepot.cs +++ b/src/ComponentDepot.cs @@ -205,4 +205,33 @@ internal class ComponentDepot filterSignatureToEntityIDs[filterSignature].Add(entityID); } + + // debug use only! + + public IEnumerable Debug_GetAllComponents(int entityID) + { + foreach (var (type, storage) in storages) + { + if (storage.Has(entityID)) + { + yield return storage.Debug_Get(entityID); + } + } + } + + public ReadOnlySpan Debug_GetEntities(Type componentType) + { + return Lookup(componentType).AllEntities(); + } + + public IEnumerable Debug_SearchComponentType(string typeString) + { + foreach (var type in storages.Keys) + { + if (type.ToString().ToLower().Contains(typeString.ToLower())) + { + yield return type; + } + } + } } diff --git a/src/ComponentStorage.cs b/src/ComponentStorage.cs index 54ca698..7844c6c 100644 --- a/src/ComponentStorage.cs +++ b/src/ComponentStorage.cs @@ -4,6 +4,9 @@ internal abstract class ComponentStorage { public abstract bool Has(int entityID); public abstract void Remove(int entityID); + public abstract ReadOnlySpan AllEntities(); + + public abstract object Debug_Get(int entityID); } internal class ComponentStorage : ComponentStorage where TComponent : struct @@ -29,6 +32,11 @@ internal class ComponentStorage : ComponentStorage where TComponent return ref components[entityIDToStorageIndex[entityID]]; } + public override object Debug_Get(int entityID) + { + return components[entityIDToStorageIndex[entityID]]; + } + public ref readonly TComponent Get() { #if DEBUG @@ -89,7 +97,7 @@ internal class ComponentStorage : ComponentStorage where TComponent entityIDToStorageIndex.Clear(); } - public ReadOnlySpan AllEntities() + public override ReadOnlySpan AllEntities() { return new ReadOnlySpan(storageIndexToEntities, 0, nextID); } diff --git a/src/DebugSystem.cs b/src/DebugSystem.cs new file mode 100644 index 0000000..0697800 --- /dev/null +++ b/src/DebugSystem.cs @@ -0,0 +1,26 @@ +// NOTE: these methods are very inefficient +// this class should only be used in debugging contexts!! +namespace MoonTools.ECS +{ + public abstract class DebugSystem : System + { + protected DebugSystem(World world) : base(world) + { + } + + protected IEnumerable Debug_GetAllComponents(Entity entity) + { + return ComponentDepot.Debug_GetAllComponents(entity.ID); + } + + protected ReadOnlySpan Debug_GetEntities(Type componentType) + { + return ComponentDepot.Debug_GetEntities(componentType); + } + + protected IEnumerable Debug_SearchComponentType(string typeString) + { + return ComponentDepot.Debug_SearchComponentType(typeString); + } + } +}