2024-11-05 15:50:03 +08:00
|
|
|
|
using DCFApixels.DragonECS.Core;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
2024-08-24 12:29:58 +08:00
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
using Unity.IL2CPP.CompilerServices;
|
|
|
|
|
#endif
|
2024-02-10 20:54:09 +08:00
|
|
|
|
|
2024-08-24 12:29:58 +08:00
|
|
|
|
namespace DCFApixels.DragonECS.Internal
|
2024-02-10 20:54:09 +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 EcsWhereToGroupExecutor : MaskQueryExecutor
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-08-24 12:29:58 +08:00
|
|
|
|
private EcsMaskIterator _iterator;
|
2024-08-24 21:02:18 +08:00
|
|
|
|
|
2024-11-05 15:50:03 +08:00
|
|
|
|
private EcsGroup _filteredAllGroup;
|
2024-02-10 20:54:09 +08:00
|
|
|
|
private EcsGroup _filteredGroup;
|
|
|
|
|
|
2024-11-05 15:50:03 +08:00
|
|
|
|
private long _version;
|
2024-10-11 18:28:46 +08:00
|
|
|
|
private WorldStateVersionsChecker _versionsChecker;
|
2024-02-10 20:54:09 +08:00
|
|
|
|
|
2024-11-17 21:43:50 +08:00
|
|
|
|
public bool _isDestroyed = false;
|
|
|
|
|
|
2024-08-24 12:29:58 +08:00
|
|
|
|
#region Properties
|
2024-10-03 08:20:22 +08:00
|
|
|
|
public sealed override long Version
|
2024-08-24 12:29:58 +08:00
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 21:02:18 +08:00
|
|
|
|
get { return _version; }
|
2024-08-24 12:29:58 +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 _filteredAllGroup.Count; }
|
|
|
|
|
}
|
2024-08-24 12:29:58 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2024-08-24 13:10:50 +08:00
|
|
|
|
#region OnInitialize/OnDestroy
|
|
|
|
|
protected sealed override void OnInitialize()
|
2024-08-24 12:29:58 +08:00
|
|
|
|
{
|
2024-10-11 18:28:46 +08:00
|
|
|
|
_versionsChecker = new WorldStateVersionsChecker(Mask);
|
2024-08-24 21:02:18 +08:00
|
|
|
|
_filteredAllGroup = EcsGroup.New(World);
|
2024-08-24 13:10:50 +08:00
|
|
|
|
_iterator = Mask.GetIterator();
|
2024-08-24 12:29:58 +08:00
|
|
|
|
}
|
2024-08-24 13:10:50 +08:00
|
|
|
|
protected sealed override void OnDestroy()
|
2024-08-24 12:29:58 +08:00
|
|
|
|
{
|
2024-11-17 21:43:50 +08:00
|
|
|
|
if (_isDestroyed) { return; }
|
|
|
|
|
_isDestroyed = true;
|
2024-08-24 21:02:18 +08:00
|
|
|
|
_filteredAllGroup.Dispose();
|
2024-10-11 18:28:46 +08:00
|
|
|
|
_versionsChecker.Dispose();
|
2024-08-24 12:29:58 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 21:02:18 +08:00
|
|
|
|
private void Execute_Iternal()
|
2024-08-24 12:29:58 +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
|
|
|
|
_iterator.IterateTo(World.Entities, _filteredAllGroup);
|
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
|
|
|
|
{
|
2024-02-10 20:54:09 +08:00
|
|
|
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
2024-08-24 12:29:58 +08:00
|
|
|
|
if (span.IsNull) { Throw.ArgumentNull(nameof(span)); }
|
2024-10-31 16:27:53 +08:00
|
|
|
|
if (span.WorldID != World.ID) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
2024-02-10 20:54:09 +08:00
|
|
|
|
#endif
|
2024-08-24 21:02:18 +08:00
|
|
|
|
if (_filteredGroup == null)
|
2024-08-24 12:29:58 +08:00
|
|
|
|
{
|
2024-08-24 21:02:18 +08:00
|
|
|
|
_filteredGroup = EcsGroup.New(World);
|
2024-08-24 12:29:58 +08:00
|
|
|
|
}
|
2024-10-10 19:57:19 +08:00
|
|
|
|
_iterator.IterateTo(span, _filteredGroup);
|
2024-08-24 21:02:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsReadonlyGroup Execute()
|
|
|
|
|
{
|
|
|
|
|
Execute_Iternal();
|
|
|
|
|
return _filteredAllGroup;
|
|
|
|
|
}
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsReadonlyGroup ExecuteFor(EcsSpan span)
|
|
|
|
|
{
|
2025-03-11 14:30:33 +08:00
|
|
|
|
if (span.IsSourceEntities)
|
|
|
|
|
{
|
|
|
|
|
return Execute();
|
|
|
|
|
}
|
2024-08-24 21:02:18 +08:00
|
|
|
|
ExecuteFor_Iternal(span);
|
|
|
|
|
return _filteredGroup;
|
2024-08-24 12:29:58 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2024-10-03 08:20:22 +08:00
|
|
|
|
}
|