DebugSystem API

pull/1/head
cosmonaut 2022-03-25 12:32:35 -07:00
parent 26621e66fe
commit 428b375d88
3 changed files with 64 additions and 1 deletions

View File

@ -205,4 +205,33 @@ internal class ComponentDepot
filterSignatureToEntityIDs[filterSignature].Add(entityID);
}
// debug use only!
public IEnumerable<object> Debug_GetAllComponents(int entityID)
{
foreach (var (type, storage) in storages)
{
if (storage.Has(entityID))
{
yield return storage.Debug_Get(entityID);
}
}
}
public ReadOnlySpan<Entity> Debug_GetEntities(Type componentType)
{
return Lookup(componentType).AllEntities();
}
public IEnumerable<Type> Debug_SearchComponentType(string typeString)
{
foreach (var type in storages.Keys)
{
if (type.ToString().ToLower().Contains(typeString.ToLower()))
{
yield return type;
}
}
}
}

View File

@ -4,6 +4,9 @@ internal abstract class ComponentStorage
{
public abstract bool Has(int entityID);
public abstract void Remove(int entityID);
public abstract ReadOnlySpan<Entity> AllEntities();
public abstract object Debug_Get(int entityID);
}
internal class ComponentStorage<TComponent> : ComponentStorage where TComponent : struct
@ -29,6 +32,11 @@ internal class ComponentStorage<TComponent> : 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<TComponent> : ComponentStorage where TComponent
entityIDToStorageIndex.Clear();
}
public ReadOnlySpan<Entity> AllEntities()
public override ReadOnlySpan<Entity> AllEntities()
{
return new ReadOnlySpan<Entity>(storageIndexToEntities, 0, nextID);
}

26
src/DebugSystem.cs Normal file
View File

@ -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<object> Debug_GetAllComponents(Entity entity)
{
return ComponentDepot.Debug_GetAllComponents(entity.ID);
}
protected ReadOnlySpan<Entity> Debug_GetEntities(Type componentType)
{
return ComponentDepot.Debug_GetEntities(componentType);
}
protected IEnumerable<Type> Debug_SearchComponentType(string typeString)
{
return ComponentDepot.Debug_SearchComponentType(typeString);
}
}
}