2024-08-05 11:13:13 +08:00
|
|
|
|
using DCFApixels.DragonECS.Internal;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
2023-12-24 15:40:19 +08:00
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS
|
2023-05-07 00:50:02 +08:00
|
|
|
|
{
|
2024-04-28 19:43:10 +08:00
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
using Unity.IL2CPP.CompilerServices;
|
|
|
|
|
[Il2CppSetOption(Option.NullChecks, false)]
|
|
|
|
|
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
|
|
|
|
#endif
|
2024-07-05 22:13:17 +08:00
|
|
|
|
public sealed class EcsWhereExecutor<TAspect> : EcsQueryExecutor where TAspect : EcsAspect, new()
|
2023-12-24 15:40:19 +08:00
|
|
|
|
{
|
|
|
|
|
private TAspect _aspect;
|
|
|
|
|
private int[] _filteredEntities;
|
2024-02-26 07:20:19 +08:00
|
|
|
|
private int _filteredEntitiesCount;
|
2023-12-24 15:40:19 +08:00
|
|
|
|
|
2024-02-11 01:16:47 +08:00
|
|
|
|
private long _lastWorldVersion;
|
2024-08-23 22:31:43 +08:00
|
|
|
|
private PoolVersionsChecker _versionsChecker;
|
2023-12-24 15:40:19 +08:00
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
public TAspect Aspect
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
get => _aspect;
|
|
|
|
|
}
|
|
|
|
|
public sealed override long Version
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-02-11 01:16:47 +08:00
|
|
|
|
get => _lastWorldVersion;
|
2023-12-24 15:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnInitialize/OnDestroy
|
|
|
|
|
protected sealed override void OnInitialize()
|
|
|
|
|
{
|
|
|
|
|
_aspect = World.GetAspect<TAspect>();
|
|
|
|
|
_filteredEntities = new int[32];
|
2024-08-23 22:31:43 +08:00
|
|
|
|
_versionsChecker = new PoolVersionsChecker(_aspect._mask);
|
2023-12-24 15:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
protected sealed override void OnDestroy() { }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
2024-08-23 22:31:43 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private void Filter(EcsSpan span)
|
|
|
|
|
{
|
|
|
|
|
_filteredEntitiesCount = _aspect.GetIteratorFor(span).CopyTo(ref _filteredEntities);
|
|
|
|
|
_lastWorldVersion = World.Version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
// public EcsSpan Execute(Comparison<int> comparison)
|
|
|
|
|
// {
|
|
|
|
|
// return ExecuteFor(_aspect.World.Entities, comparison);
|
|
|
|
|
// }
|
|
|
|
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
// public EcsSpan ExecuteFor(EcsSpan span, Comparison<int> comparison)
|
|
|
|
|
// {
|
|
|
|
|
//#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
|
|
|
|
// if (span.IsNull) { Throw.ArgumentNull(nameof(span)); }
|
|
|
|
|
// if (span.WorldID != WorldID) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
|
|
|
|
//#endif
|
|
|
|
|
// World.ReleaseDelEntityBufferAllAuto();
|
|
|
|
|
// if (_lastWorldVersion != World.Version)
|
|
|
|
|
// {
|
|
|
|
|
// Filter(span);
|
|
|
|
|
// }
|
|
|
|
|
// Array.Sort<int>(_filteredEntities, 0, _filteredEntitiesCount, comparison);
|
|
|
|
|
// }
|
|
|
|
|
|
2023-12-24 15:40:19 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-02-25 23:05:00 +08:00
|
|
|
|
public EcsSpan Execute()
|
|
|
|
|
{
|
|
|
|
|
return ExecuteFor(_aspect.World.Entities);
|
|
|
|
|
}
|
2023-12-24 15:40:19 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-12-31 13:07:53 +08:00
|
|
|
|
public EcsSpan ExecuteFor(EcsSpan span)
|
2023-12-24 15:40:19 +08:00
|
|
|
|
{
|
|
|
|
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
2024-08-05 11:13:13 +08:00
|
|
|
|
if (span.IsNull) { Throw.ArgumentNull(nameof(span)); }
|
|
|
|
|
if (span.WorldID != WorldID) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
2023-12-24 15:40:19 +08:00
|
|
|
|
#endif
|
2024-08-23 22:31:43 +08:00
|
|
|
|
World.ReleaseDelEntityBufferAllAuto();
|
|
|
|
|
if (_lastWorldVersion != World.Version || _versionsChecker.NextEquals() == false)
|
2024-02-11 01:16:47 +08:00
|
|
|
|
{
|
2024-08-23 22:31:43 +08:00
|
|
|
|
Filter(span);
|
2024-02-11 01:16:47 +08:00
|
|
|
|
}
|
2024-08-23 22:31:43 +08:00
|
|
|
|
return new EcsSpan(WorldID, _filteredEntities, _filteredEntitiesCount);
|
2023-12-24 15:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2023-05-07 00:50:02 +08:00
|
|
|
|
}
|