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-08-24 12:29:58 +08:00
|
|
|
|
internal readonly struct EcsWhereToGroupExecutorCoreList : IEcsWorldComponent<EcsWhereToGroupExecutorCoreList>
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-08-24 12:29:58 +08:00
|
|
|
|
internal readonly EcsWhereToGroupExecutorCore[] _cores;
|
|
|
|
|
public EcsWhereToGroupExecutorCoreList(EcsWhereToGroupExecutorCore[] cores)
|
|
|
|
|
{
|
|
|
|
|
_cores = cores;
|
|
|
|
|
}
|
|
|
|
|
public void Init(ref EcsWhereToGroupExecutorCoreList component, EcsWorld world)
|
|
|
|
|
{
|
|
|
|
|
component = new EcsWhereToGroupExecutorCoreList(new EcsWhereToGroupExecutorCore[64]);
|
|
|
|
|
}
|
|
|
|
|
public void OnDestroy(ref EcsWhereToGroupExecutorCoreList component, EcsWorld world)
|
|
|
|
|
{
|
|
|
|
|
component = default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
[Il2CppSetOption(Option.NullChecks, false)]
|
|
|
|
|
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
|
|
|
|
#endif
|
|
|
|
|
internal class EcsWhereToGroupExecutorCore
|
|
|
|
|
{
|
|
|
|
|
private EcsWorld _source;
|
|
|
|
|
|
|
|
|
|
private EcsMaskIterator _iterator;
|
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)]
|
|
|
|
|
get { return _lastWorldVersion; }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructors/Destroy
|
|
|
|
|
public EcsWhereToGroupExecutorCore(EcsWorld source, EcsAspect aspect)
|
|
|
|
|
{
|
|
|
|
|
_source = source;
|
|
|
|
|
_versionsChecker = new PoolVersionsChecker(aspect.Mask);
|
|
|
|
|
}
|
|
|
|
|
public void Destroy()
|
|
|
|
|
{
|
|
|
|
|
_filteredGroup.Dispose();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private void Filter(EcsSpan span)
|
|
|
|
|
{
|
|
|
|
|
_iterator.Iterate(span).CopyTo(_filteredGroup);
|
|
|
|
|
_lastWorldVersion = _source.Version;
|
|
|
|
|
}
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsSpan Execute()
|
|
|
|
|
{
|
|
|
|
|
return ExecuteFor(_source.Entities);
|
|
|
|
|
}
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public EcsSpan ExecuteFor(EcsSpan span)
|
|
|
|
|
{
|
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)); }
|
|
|
|
|
if (span.WorldID != _source.id) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
2024-02-10 20:54:09 +08:00
|
|
|
|
#endif
|
2024-08-24 12:29:58 +08:00
|
|
|
|
_source.ReleaseDelEntityBufferAllAuto();
|
|
|
|
|
if (_lastWorldVersion != _source.Version || _versionsChecker.NextEquals() == false)
|
|
|
|
|
{
|
|
|
|
|
Filter(span);
|
|
|
|
|
}
|
|
|
|
|
return _filteredGroup.Readonly;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS
|
|
|
|
|
{
|
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
[Il2CppSetOption(Option.NullChecks, false)]
|
|
|
|
|
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
|
|
|
|
#endif
|
|
|
|
|
public sealed class EcsWhereToGroupExecutor<TAspect> : EcsQueryExecutor where TAspect : EcsAspect, new()
|
|
|
|
|
{
|
|
|
|
|
private TAspect _aspect;
|
|
|
|
|
private EcsWhereToGroupExecutorCore _core;
|
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-08-24 12:29:58 +08:00
|
|
|
|
get { return _core.Version; }
|
2024-02-10 20:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnInitialize/OnDestroy
|
|
|
|
|
protected sealed override void OnInitialize()
|
|
|
|
|
{
|
|
|
|
|
_aspect = World.GetAspect<TAspect>();
|
|
|
|
|
_filteredGroup = EcsGroup.New(World);
|
2024-08-23 22:31:43 +08:00
|
|
|
|
_versionsChecker = new PoolVersionsChecker(_aspect._mask);
|
2024-02-10 20:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
protected sealed override void OnDestroy()
|
|
|
|
|
{
|
2024-08-24 12:29:58 +08:00
|
|
|
|
_core.Destroy();
|
2024-02-10 20:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 12:29:58 +08:00
|
|
|
|
public EcsSpan Execute()
|
2024-02-25 23:05:00 +08:00
|
|
|
|
{
|
2024-08-24 12:29:58 +08:00
|
|
|
|
return _core.Execute();
|
2024-02-25 23:05:00 +08:00
|
|
|
|
}
|
2024-02-10 20:54:09 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-08-24 12:29:58 +08:00
|
|
|
|
public EcsSpan ExecuteFor(EcsSpan span)
|
2024-02-10 20:54:09 +08:00
|
|
|
|
{
|
2024-08-24 12:29:58 +08:00
|
|
|
|
return _core.ExecuteFor(span);
|
2024-02-10 20:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|