mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
add Where query with sort
This commit is contained in:
parent
c5c2d0e30a
commit
e271c77cab
@ -101,6 +101,7 @@ namespace DCFApixels.DragonECS
|
|||||||
private EcsWorld _world;
|
private EcsWorld _world;
|
||||||
private EcsMask.Builder _maskBuilder;
|
private EcsMask.Builder _maskBuilder;
|
||||||
|
|
||||||
|
#region Properties
|
||||||
public IncludeMarker Inc
|
public IncludeMarker Inc
|
||||||
{
|
{
|
||||||
get { return new IncludeMarker(this); }
|
get { return new IncludeMarker(this); }
|
||||||
@ -113,9 +114,13 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
get { return new OptionalMarker(this); }
|
get { return new OptionalMarker(this); }
|
||||||
}
|
}
|
||||||
|
public EcsWorld World
|
||||||
|
{
|
||||||
|
get { return _world; }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public EcsWorld World => _world;
|
#region Constructors/New
|
||||||
|
|
||||||
private Builder(EcsWorld world)
|
private Builder(EcsWorld world)
|
||||||
{
|
{
|
||||||
_world = world;
|
_world = world;
|
||||||
@ -128,17 +133,19 @@ namespace DCFApixels.DragonECS
|
|||||||
EcsAspect newAspect;
|
EcsAspect newAspect;
|
||||||
|
|
||||||
var buildersStack = GetBuildersStack();
|
var buildersStack = GetBuildersStack();
|
||||||
buildersStack.Push(builder);
|
|
||||||
|
|
||||||
|
buildersStack.Push(builder);
|
||||||
newAspect = new TAspect();
|
newAspect = new TAspect();
|
||||||
newAspect.Init(builder);
|
newAspect.Init(builder);
|
||||||
buildersStack.Pop();
|
buildersStack.Pop();
|
||||||
|
|
||||||
newAspect._source = world;
|
newAspect._source = world;
|
||||||
builder.Build(out newAspect._mask);
|
builder.Build(out newAspect._mask);
|
||||||
newAspect._isBuilt = true;
|
newAspect._isBuilt = true;
|
||||||
|
|
||||||
return (TAspect)newAspect;
|
return (TAspect)newAspect;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Include/Exclude/Optional/Combine/Except
|
#region Include/Exclude/Optional/Combine/Except
|
||||||
public TPool IncludePool<TPool>() where TPool : IEcsPoolImplementation, new()
|
public TPool IncludePool<TPool>() where TPool : IEcsPoolImplementation, new()
|
||||||
@ -179,10 +186,12 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Build
|
||||||
private void Build(out EcsMask mask)
|
private void Build(out EcsMask mask)
|
||||||
{
|
{
|
||||||
mask = _maskBuilder.Build();
|
mask = _maskBuilder.Build();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region SupportReflectionHack
|
#region SupportReflectionHack
|
||||||
#if UNITY_2020_3_OR_NEWER
|
#if UNITY_2020_3_OR_NEWER
|
||||||
@ -293,6 +302,27 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region EcsAspectExtensions
|
||||||
|
//public static class EcsAspectExtensions
|
||||||
|
//{
|
||||||
|
// public static EcsAspect.Builder Inc<TPool>(this EcsAspect.Builder self, ref TPool pool) where TPool : IEcsPoolImplementation, new()
|
||||||
|
// {
|
||||||
|
// pool = self.IncludePool<TPool>();
|
||||||
|
// return self;
|
||||||
|
// }
|
||||||
|
// public static EcsAspect.Builder Exc<TPool>(this EcsAspect.Builder self, ref TPool pool) where TPool : IEcsPoolImplementation, new()
|
||||||
|
// {
|
||||||
|
// pool = self.ExcludePool<TPool>();
|
||||||
|
// return self;
|
||||||
|
// }
|
||||||
|
// public static EcsAspect.Builder Opt<TPool>(this EcsAspect.Builder self, ref TPool pool) where TPool : IEcsPoolImplementation, new()
|
||||||
|
// {
|
||||||
|
// pool = self.OptionalPool<TPool>();
|
||||||
|
// return self;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Constraint Markers
|
#region Constraint Markers
|
||||||
public readonly ref struct IncludeMarker
|
public readonly ref struct IncludeMarker
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
#if ENABLE_IL2CPP
|
#if ENABLE_IL2CPP
|
||||||
using Unity.IL2CPP.CompilerServices;
|
using Unity.IL2CPP.CompilerServices;
|
||||||
@ -79,18 +80,20 @@ namespace DCFApixels.DragonECS.Internal
|
|||||||
return new EcsSpan(World.id, _filteredEntities, _filteredEntitiesCount);
|
return new EcsSpan(World.id, _filteredEntities, _filteredEntitiesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
//public EcsSpan Execute(Comparison<int> comparison)
|
public EcsSpan Execute(Comparison<int> comparison)
|
||||||
//{
|
{
|
||||||
// Execute_Iternal();
|
Execute_Iternal();
|
||||||
// return new EcsSpan(World.id, _filteredAllEntities, _filteredAllEntitiesCount);
|
ArraySortHalperX<int>.Sort(_filteredAllEntities, comparison, _filteredAllEntitiesCount);
|
||||||
//}
|
return new EcsSpan(World.id, _filteredAllEntities, _filteredAllEntitiesCount);
|
||||||
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
}
|
||||||
//public EcsSpan ExecuteFor(EcsSpan span, Comparison<int> comparison)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
//{
|
public EcsSpan ExecuteFor(EcsSpan span, Comparison<int> comparison)
|
||||||
// ExecuteFor_Iternal(span);
|
{
|
||||||
// return new EcsSpan(World.id, _filteredEntities, _filteredEntitiesCount);
|
ExecuteFor_Iternal(span);
|
||||||
//}
|
ArraySortHalperX<int>.Sort(_filteredEntities, comparison, _filteredEntitiesCount);
|
||||||
|
return new EcsSpan(World.id, _filteredEntities, _filteredEntitiesCount);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,6 +142,16 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return _core.ExecuteFor(span);
|
return _core.ExecuteFor(span);
|
||||||
}
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public EcsSpan Execute(Comparison<int> comparison)
|
||||||
|
{
|
||||||
|
return _core.Execute(comparison);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public EcsSpan ExecuteFor(EcsSpan span, Comparison<int> comparison)
|
||||||
|
{
|
||||||
|
return _core.ExecuteFor(span, comparison);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace DCFApixels.DragonECS
|
using System;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public interface IEntityStorage
|
public interface IEntityStorage
|
||||||
{
|
{
|
||||||
@ -28,6 +30,28 @@
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
#region WhereToGroup
|
#region WhereToGroup
|
||||||
public static EcsReadonlyGroup WhereToGroup<TCollection, TAspect>(this TCollection entities, out TAspect aspect)
|
public static EcsReadonlyGroup WhereToGroup<TCollection, TAspect>(this TCollection entities, out TAspect aspect)
|
||||||
where TAspect : EcsAspect, new()
|
where TAspect : EcsAspect, new()
|
||||||
|
Loading…
Reference in New Issue
Block a user