2024-11-05 15:50:03 +08:00
|
|
|
|
using DCFApixels.DragonECS.Core;
|
|
|
|
|
using System;
|
2024-08-05 11:13:13 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2024-08-24 12:29:58 +08:00
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
using Unity.IL2CPP.CompilerServices;
|
|
|
|
|
#endif
|
2023-12-24 15:40:19 +08:00
|
|
|
|
|
2024-08-24 12:29:58 +08:00
|
|
|
|
namespace DCFApixels.DragonECS.Internal
|
2023-05-07 00:50:02 +08:00
|
|
|
|
{
|
2024-04-28 19:43:10 +08:00
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
[Il2CppSetOption(Option.NullChecks, false)]
|
|
|
|
|
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
|
|
|
|
#endif
|
2024-11-07 08:22:10 +08:00
|
|
|
|
internal sealed class EcsWhereExecutor : MaskQueryExecutor
|
2023-12-24 15:40:19 +08:00
|
|
|
|
{
|
2024-08-24 12:29:58 +08:00
|
|
|
|
private EcsMaskIterator _iterator;
|
2024-11-05 15:50:03 +08:00
|
|
|
|
|
2024-08-24 21:02:18 +08:00
|
|
|
|
private int[] _filteredAllEntities = new int[32];
|
|
|
|
|
private int _filteredAllEntitiesCount = 0;
|
|
|
|
|
private int[] _filteredEntities = null;
|
2024-08-24 12:29:58 +08:00
|
|
|
|
private int _filteredEntitiesCount = 0;
|
|
|
|
|
|
2024-11-05 15:50:03 +08:00
|
|
|
|
private long _version;
|
2024-10-11 18:28:46 +08:00
|
|
|
|
private WorldStateVersionsChecker _versionsChecker;
|
2023-12-24 15:40:19 +08:00
|
|
|
|
|
|
|
|
|
#region Properties
|
2024-10-03 08:20:22 +08:00
|
|
|
|
public sealed override long Version
|
2023-12-24 15:40:19 +08:00
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 21:02:18 +08:00
|
|
|
|
get { return _version; }
|
2023-12-24 15:40:19 +08:00
|
|
|
|
}
|
2024-11-05 15:50:03 +08:00
|
|
|
|
public sealed override bool IsCached
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
get { return _versionsChecker.Check(); }
|
|
|
|
|
}
|
2024-11-07 08:22:10 +08:00
|
|
|
|
public sealed override int LastCachedCount
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
get { return _filteredAllEntitiesCount; }
|
|
|
|
|
}
|
2023-12-24 15:40:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2024-08-24 13:10:50 +08:00
|
|
|
|
#region OnInitialize/OnDestroy
|
|
|
|
|
protected sealed override void OnInitialize()
|
2023-12-24 15:40:19 +08:00
|
|
|
|
{
|
2024-10-11 18:28:46 +08:00
|
|
|
|
_versionsChecker = new WorldStateVersionsChecker(Mask);
|
2024-08-24 13:10:50 +08:00
|
|
|
|
_iterator = Mask.GetIterator();
|
2023-12-24 15:40:19 +08:00
|
|
|
|
}
|
2024-10-11 18:28:46 +08:00
|
|
|
|
protected sealed override void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
_versionsChecker.Dispose();
|
|
|
|
|
}
|
2023-12-24 15:40:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
2024-08-23 22:31:43 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 21:02:18 +08:00
|
|
|
|
private void Execute_Iternal()
|
2024-08-23 22:31:43 +08:00
|
|
|
|
{
|
2024-08-24 21:02:18 +08:00
|
|
|
|
World.ReleaseDelEntityBufferAllAuto();
|
2024-10-11 18:28:46 +08:00
|
|
|
|
if (_versionsChecker.CheckAndNext() == false)
|
2024-08-24 21:02:18 +08:00
|
|
|
|
{
|
|
|
|
|
_version++;
|
2024-10-10 19:57:19 +08:00
|
|
|
|
_filteredAllEntitiesCount = _iterator.IterateTo(World.Entities, ref _filteredAllEntities);
|
2024-08-24 21:02:18 +08:00
|
|
|
|
}
|
2024-08-24 12:29:58 +08:00
|
|
|
|
}
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 21:02:18 +08:00
|
|
|
|
private void ExecuteFor_Iternal(EcsSpan span)
|
2024-08-24 12:29:58 +08:00
|
|
|
|
{
|
|
|
|
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
|
|
|
|
if (span.IsNull) { Throw.ArgumentNull(nameof(span)); }
|
2024-10-31 16:27:53 +08:00
|
|
|
|
if (span.WorldID != World.ID) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
2024-08-24 12:29:58 +08:00
|
|
|
|
#endif
|
2024-08-24 21:02:18 +08:00
|
|
|
|
if (_filteredEntities == null)
|
2024-08-24 12:29:58 +08:00
|
|
|
|
{
|
2024-08-24 21:02:18 +08:00
|
|
|
|
_filteredEntities = new int[32];
|
2024-08-24 12:29:58 +08:00
|
|
|
|
}
|
2024-10-10 19:57:19 +08:00
|
|
|
|
_filteredEntitiesCount = _iterator.IterateTo(span, ref _filteredEntities);
|
2024-08-24 21:02:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsSpan Execute()
|
|
|
|
|
{
|
|
|
|
|
Execute_Iternal();
|
2024-10-31 16:27:53 +08:00
|
|
|
|
return new EcsSpan(World.ID, _filteredAllEntities, _filteredAllEntitiesCount);
|
2024-08-24 21:02:18 +08:00
|
|
|
|
}
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsSpan ExecuteFor(EcsSpan span)
|
|
|
|
|
{
|
|
|
|
|
ExecuteFor_Iternal(span);
|
2024-10-31 16:27:53 +08:00
|
|
|
|
return new EcsSpan(World.ID, _filteredEntities, _filteredEntitiesCount);
|
2024-08-23 22:31:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-26 11:08:42 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsSpan Execute(Comparison<int> comparison)
|
|
|
|
|
{
|
|
|
|
|
Execute_Iternal();
|
|
|
|
|
ArraySortHalperX<int>.Sort(_filteredAllEntities, comparison, _filteredAllEntitiesCount);
|
2024-10-31 16:27:53 +08:00
|
|
|
|
return new EcsSpan(World.ID, _filteredAllEntities, _filteredAllEntitiesCount);
|
2024-08-26 11:08:42 +08:00
|
|
|
|
}
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsSpan ExecuteFor(EcsSpan span, Comparison<int> comparison)
|
|
|
|
|
{
|
|
|
|
|
ExecuteFor_Iternal(span);
|
|
|
|
|
ArraySortHalperX<int>.Sort(_filteredEntities, comparison, _filteredEntitiesCount);
|
2024-10-31 16:27:53 +08:00
|
|
|
|
return new EcsSpan(World.ID, _filteredEntities, _filteredEntitiesCount);
|
2024-08-26 11:08:42 +08:00
|
|
|
|
}
|
2024-08-24 12:29:58 +08:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
2024-10-03 08:20:22 +08:00
|
|
|
|
}
|