2022-04-08 05:52:03 +00:00
|
|
|
|
// NOTE: these methods are very inefficient
|
2022-03-25 19:32:35 +00:00
|
|
|
|
// this class should only be used in debugging contexts!!
|
2022-04-03 21:46:52 +00:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
2022-04-08 05:52:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2022-03-25 19:32:35 +00:00
|
|
|
|
namespace MoonTools.ECS
|
|
|
|
|
{
|
|
|
|
|
public abstract class DebugSystem : System
|
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
private Dictionary<Type, Filter> singleComponentFilters = new Dictionary<Type, Filter>();
|
|
|
|
|
|
2022-03-25 19:32:35 +00:00
|
|
|
|
protected DebugSystem(World world) : base(world)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected IEnumerable<object> Debug_GetAllComponents(Entity entity)
|
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
foreach (var typeIndex in EntityStorage.ComponentTypeIndices(entity.ID))
|
|
|
|
|
{
|
2022-12-06 01:46:18 +00:00
|
|
|
|
yield return ComponentDepot.UntypedGet(entity.ID, typeIndex);
|
2022-12-03 07:43:54 +00:00
|
|
|
|
}
|
2022-03-25 19:32:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-03 21:46:52 +00:00
|
|
|
|
protected IEnumerable<Entity> Debug_GetEntities(Type componentType)
|
2022-03-25 19:32:35 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
if (!singleComponentFilters.ContainsKey(componentType))
|
|
|
|
|
{
|
|
|
|
|
singleComponentFilters.Add(componentType, new Filter(FilterStorage, new HashSet<int>(ComponentTypeIndices.GetIndex(componentType)), new HashSet<int>()));
|
|
|
|
|
}
|
|
|
|
|
return singleComponentFilters[componentType].Entities;
|
2022-03-25 19:32:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected IEnumerable<Type> Debug_SearchComponentType(string typeString)
|
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
foreach (var type in ComponentTypeIndices.Types)
|
|
|
|
|
{
|
|
|
|
|
if (type.ToString().ToLower().Contains(typeString.ToLower()))
|
|
|
|
|
{
|
|
|
|
|
yield return type;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-25 19:32:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-03 21:46:52 +00:00
|
|
|
|
#endif
|