2024-08-26 11:08:42 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
EcsWorld world = span.World;
|
2024-02-25 23:05:00 +08:00
|
|
|
|
var executor = world.GetExecutor<EcsWhereExecutor<TAspect>>();
|
2024-02-10 20:54:09 +08:00
|
|
|
|
aspect = executor.Aspect;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
EcsWorld world = span.World;
|
|
|
|
|
var executor = world.GetExecutor<EcsWhereExecutor<TAspect>>();
|
|
|
|
|
aspect = executor.Aspect;
|
|
|
|
|
return executor.ExecuteFor(span, comparison);
|
|
|
|
|
}
|
|
|
|
|
#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
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
EcsWorld world = span.World;
|
|
|
|
|
var executor = world.GetExecutor<EcsWhereToGroupExecutor<TAspect>>();
|
|
|
|
|
aspect = executor.Aspect;
|
|
|
|
|
return executor.ExecuteFor(span);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|