2024-10-03 08:20:22 +08:00
|
|
|
|
using DCFApixels.DragonECS.Internal;
|
|
|
|
|
using System;
|
2024-08-26 11:08:42 +08:00
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-02-11 00:42:49 +08:00
|
|
|
|
public interface IEntityStorage
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
EcsWorld World { get; }
|
2024-02-10 20:54:09 +08:00
|
|
|
|
EcsSpan ToSpan();
|
|
|
|
|
}
|
|
|
|
|
public static class Queries
|
|
|
|
|
{
|
|
|
|
|
#region Where
|
|
|
|
|
public static EcsSpan Where<TCollection, TAspect>(this TCollection entities, out TAspect aspect)
|
2024-07-05 22:13:17 +08:00
|
|
|
|
where TAspect : EcsAspect, new()
|
2024-02-11 00:42:49 +08:00
|
|
|
|
where TCollection : IEntityStorage
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
if(ReferenceEquals(entities, entities.World))
|
|
|
|
|
{
|
|
|
|
|
entities.World.GetQueryCache(out EcsWhereExecutor executor, out aspect);
|
|
|
|
|
return executor.Execute();
|
|
|
|
|
}
|
2024-02-10 20:54:09 +08:00
|
|
|
|
return entities.ToSpan().Where(out aspect);
|
|
|
|
|
}
|
|
|
|
|
public static EcsSpan Where<TAspect>(this EcsReadonlyGroup group, out TAspect aspect)
|
2024-07-05 22:13:17 +08:00
|
|
|
|
where TAspect : EcsAspect, new()
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
|
|
|
|
return group.ToSpan().Where(out aspect);
|
|
|
|
|
}
|
|
|
|
|
public static EcsSpan Where<TAspect>(this EcsSpan span, out TAspect aspect)
|
2024-07-05 22:13:17 +08:00
|
|
|
|
where TAspect : EcsAspect, new()
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
span.World.GetQueryCache(out EcsWhereExecutor executor, out aspect);
|
2024-10-03 08:20:22 +08:00
|
|
|
|
return executor.ExecuteFor(span);
|
|
|
|
|
}
|
2024-10-05 18:05:33 +08:00
|
|
|
|
|
|
|
|
|
public static EcsSpan Where<TCollection>(this TCollection entities, IEcsComponentMask mask)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
where TCollection : IEntityStorage
|
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
if (ReferenceEquals(entities, entities.World))
|
|
|
|
|
{
|
|
|
|
|
var executor = entities.World.GetExecutor<EcsWhereExecutor>(mask);
|
|
|
|
|
return executor.Execute();
|
|
|
|
|
}
|
2024-10-03 08:20:22 +08:00
|
|
|
|
return entities.ToSpan().Where(mask);
|
|
|
|
|
}
|
2024-10-05 18:05:33 +08:00
|
|
|
|
public static EcsSpan Where(this EcsReadonlyGroup group, IEcsComponentMask mask)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
{
|
|
|
|
|
return group.ToSpan().Where(mask);
|
|
|
|
|
}
|
2024-10-05 18:05:33 +08:00
|
|
|
|
public static EcsSpan Where(this EcsSpan span, IEcsComponentMask mask)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
var executor = span.World.GetExecutor<EcsWhereExecutor>(mask);
|
2024-02-10 20:54:09 +08:00
|
|
|
|
return executor.ExecuteFor(span);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2024-08-26 11:08:42 +08:00
|
|
|
|
#region Where with sort
|
|
|
|
|
public static EcsSpan Where<TCollection, TAspect>(this TCollection entities, out TAspect aspect, Comparison<int> comparison)
|
|
|
|
|
where TAspect : EcsAspect, new()
|
|
|
|
|
where TCollection : IEntityStorage
|
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
if (ReferenceEquals(entities, entities.World))
|
|
|
|
|
{
|
|
|
|
|
entities.World.GetQueryCache(out EcsWhereExecutor executor, out aspect);
|
|
|
|
|
return executor.Execute(comparison);
|
|
|
|
|
}
|
2024-08-26 11:08:42 +08:00
|
|
|
|
return entities.ToSpan().Where(out aspect, comparison);
|
|
|
|
|
}
|
|
|
|
|
public static EcsSpan Where<TAspect>(this EcsReadonlyGroup group, out TAspect aspect, Comparison<int> comparison)
|
|
|
|
|
where TAspect : EcsAspect, new()
|
|
|
|
|
{
|
|
|
|
|
return group.ToSpan().Where(out aspect, comparison);
|
|
|
|
|
}
|
|
|
|
|
public static EcsSpan Where<TAspect>(this EcsSpan span, out TAspect aspect, Comparison<int> comparison)
|
|
|
|
|
where TAspect : EcsAspect, new()
|
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
span.World.GetQueryCache(out EcsWhereExecutor executor, out aspect);
|
2024-10-03 08:20:22 +08:00
|
|
|
|
return executor.ExecuteFor(span, comparison);
|
|
|
|
|
}
|
2024-10-05 18:05:33 +08:00
|
|
|
|
|
|
|
|
|
public static EcsSpan Where<TCollection>(this TCollection entities, IEcsComponentMask mask, Comparison<int> comparison)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
where TCollection : IEntityStorage
|
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
if (ReferenceEquals(entities, entities.World))
|
|
|
|
|
{
|
|
|
|
|
EcsWhereExecutor executor = entities.World.GetExecutor<EcsWhereExecutor>(mask);
|
|
|
|
|
return executor.Execute(comparison);
|
|
|
|
|
}
|
2024-10-03 08:20:22 +08:00
|
|
|
|
return entities.ToSpan().Where(mask, comparison);
|
|
|
|
|
}
|
2024-10-05 18:05:33 +08:00
|
|
|
|
public static EcsSpan Where(this EcsReadonlyGroup group, IEcsComponentMask mask, Comparison<int> comparison)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
{
|
|
|
|
|
return group.ToSpan().Where(mask, comparison);
|
|
|
|
|
}
|
2024-10-05 18:05:33 +08:00
|
|
|
|
public static EcsSpan Where(this EcsSpan span, IEcsComponentMask mask, Comparison<int> comparison)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
var executor = span.World.GetExecutor<EcsWhereExecutor>(mask);
|
2024-10-03 08:20:22 +08:00
|
|
|
|
return executor.ExecuteFor(span);
|
|
|
|
|
}
|
2024-08-26 11:08:42 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2024-02-10 20:54:09 +08:00
|
|
|
|
#region WhereToGroup
|
2024-02-11 01:29:18 +08:00
|
|
|
|
public static EcsReadonlyGroup WhereToGroup<TCollection, TAspect>(this TCollection entities, out TAspect aspect)
|
2024-07-05 22:13:17 +08:00
|
|
|
|
where TAspect : EcsAspect, new()
|
2024-02-11 00:42:49 +08:00
|
|
|
|
where TCollection : IEntityStorage
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
if (ReferenceEquals(entities, entities.World))
|
|
|
|
|
{
|
|
|
|
|
entities.World.GetQueryCache(out EcsWhereToGroupExecutor executor, out aspect);
|
|
|
|
|
return executor.Execute();
|
|
|
|
|
}
|
2024-02-10 20:54:09 +08:00
|
|
|
|
return entities.ToSpan().WhereToGroup(out aspect);
|
|
|
|
|
}
|
|
|
|
|
public static EcsReadonlyGroup WhereToGroup<TAspect>(this EcsReadonlyGroup group, out TAspect aspect)
|
2024-07-05 22:13:17 +08:00
|
|
|
|
where TAspect : EcsAspect, new()
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
|
|
|
|
return group.ToSpan().WhereToGroup(out aspect);
|
|
|
|
|
}
|
2024-02-11 01:29:18 +08:00
|
|
|
|
public static EcsReadonlyGroup WhereToGroup<TAspect>(this EcsSpan span, out TAspect aspect)
|
2024-07-05 22:13:17 +08:00
|
|
|
|
where TAspect : EcsAspect, new()
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
span.World.GetQueryCache(out EcsWhereToGroupExecutor executor, out aspect);
|
2024-10-03 08:20:22 +08:00
|
|
|
|
return executor.ExecuteFor(span);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-05 18:05:33 +08:00
|
|
|
|
public static EcsReadonlyGroup WhereToGroup<TCollection>(this TCollection entities, IEcsComponentMask mask)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
where TCollection : IEntityStorage
|
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
if (ReferenceEquals(entities, entities.World))
|
|
|
|
|
{
|
|
|
|
|
EcsWhereToGroupExecutor executor = entities.World.GetExecutor<EcsWhereToGroupExecutor>(mask);
|
|
|
|
|
return executor.Execute();
|
|
|
|
|
}
|
2024-10-03 08:20:22 +08:00
|
|
|
|
return entities.ToSpan().WhereToGroup(mask);
|
|
|
|
|
}
|
2024-10-05 18:05:33 +08:00
|
|
|
|
public static EcsReadonlyGroup WhereToGroup(this EcsReadonlyGroup group, IEcsComponentMask mask)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
{
|
|
|
|
|
return group.ToSpan().WhereToGroup(mask);
|
|
|
|
|
}
|
2024-10-05 18:05:33 +08:00
|
|
|
|
public static EcsReadonlyGroup WhereToGroup(this EcsSpan span, IEcsComponentMask mask)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
{
|
2024-10-05 18:05:33 +08:00
|
|
|
|
var executor = span.World.GetExecutor<EcsWhereToGroupExecutor>(mask);
|
2024-02-10 20:54:09 +08:00
|
|
|
|
return executor.ExecuteFor(span);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2024-10-03 08:20:22 +08:00
|
|
|
|
}
|