DebugSystem API
parent
26621e66fe
commit
428b375d88
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue