2024-08-05 11:13:13 +08:00
|
|
|
|
using DCFApixels.DragonECS.Internal;
|
|
|
|
|
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-10-02 22:13:10 +08:00
|
|
|
|
internal class EcsWhereToGroupExecutor : EcsQueryExecutor
|
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
|
|
|
|
private EcsGroup _filteredAllGroup;
|
|
|
|
|
private long _version;
|
|
|
|
|
|
2024-02-10 20:54:09 +08:00
|
|
|
|
private EcsGroup _filteredGroup;
|
|
|
|
|
|
2024-02-11 01:16:47 +08:00
|
|
|
|
private long _lastWorldVersion;
|
2024-08-23 22:31:43 +08:00
|
|
|
|
private PoolVersionsChecker _versionsChecker;
|
2024-02-10 20:54:09 +08:00
|
|
|
|
|
2024-08-24 12:29:58 +08:00
|
|
|
|
#region Properties
|
|
|
|
|
public long Version
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 21:02:18 +08:00
|
|
|
|
get { return _version; }
|
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-08-24 13:10:50 +08:00
|
|
|
|
_versionsChecker = new PoolVersionsChecker(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-08-24 21:02:18 +08:00
|
|
|
|
_filteredAllGroup.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();
|
|
|
|
|
if (_lastWorldVersion != World.Version || _versionsChecker.NextEquals() == false)
|
|
|
|
|
{
|
|
|
|
|
_version++;
|
|
|
|
|
_iterator.Iterate(World.Entities).CopyTo(_filteredAllGroup);
|
|
|
|
|
}
|
2024-08-24 13:10:50 +08:00
|
|
|
|
_lastWorldVersion = World.Version;
|
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-08-24 13:10:50 +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-08-24 21:02:18 +08:00
|
|
|
|
_iterator.Iterate(span).CopyTo(_filteredGroup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsReadonlyGroup Execute()
|
|
|
|
|
{
|
|
|
|
|
Execute_Iternal();
|
|
|
|
|
return _filteredAllGroup;
|
|
|
|
|
}
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsReadonlyGroup ExecuteFor(EcsSpan span)
|
|
|
|
|
{
|
|
|
|
|
ExecuteFor_Iternal(span);
|
|
|
|
|
return _filteredGroup;
|
2024-08-24 12:29:58 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS
|
|
|
|
|
{
|
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
[Il2CppSetOption(Option.NullChecks, false)]
|
|
|
|
|
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
|
|
|
|
#endif
|
2024-10-02 22:13:10 +08:00
|
|
|
|
public sealed class EcsWhereToGroupCache<TAspect> : EcsQueryCache where TAspect : EcsAspect, new()
|
2024-08-24 12:29:58 +08:00
|
|
|
|
{
|
|
|
|
|
private TAspect _aspect;
|
2024-10-02 22:13:10 +08:00
|
|
|
|
private EcsWhereToGroupExecutor _executor;
|
2024-02-10 20:54:09 +08:00
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
public TAspect Aspect
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 12:29:58 +08:00
|
|
|
|
get { return _aspect; }
|
2024-02-10 20:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
public sealed override long Version
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-10-02 22:13:10 +08:00
|
|
|
|
get { return _executor.Version; }
|
2024-02-10 20:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnInitialize/OnDestroy
|
|
|
|
|
protected sealed override void OnInitialize()
|
|
|
|
|
{
|
|
|
|
|
_aspect = World.GetAspect<TAspect>();
|
2024-10-02 22:13:10 +08:00
|
|
|
|
_executor = Mediator.GetCore<EcsWhereToGroupExecutor>(_aspect.Mask);
|
2024-02-10 20:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
protected sealed override void OnDestroy()
|
|
|
|
|
{
|
2024-10-02 22:13:10 +08:00
|
|
|
|
_executor.Destroy();
|
2024-02-10 20:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 13:10:50 +08:00
|
|
|
|
public EcsReadonlyGroup Execute()
|
2024-02-25 23:05:00 +08:00
|
|
|
|
{
|
2024-10-02 22:13:10 +08:00
|
|
|
|
return _executor.Execute();
|
2024-02-25 23:05:00 +08:00
|
|
|
|
}
|
2024-02-10 20:54:09 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 13:10:50 +08:00
|
|
|
|
public EcsReadonlyGroup ExecuteFor(EcsSpan span)
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-10-02 22:13:10 +08:00
|
|
|
|
return _executor.ExecuteFor(span);
|
2024-02-10 20:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|