add LastCachedCount for executors

This commit is contained in:
Mikhail 2024-11-07 08:22:10 +08:00
parent 51452fe90d
commit f12c01ed10
3 changed files with 22 additions and 9 deletions

View File

@ -11,7 +11,7 @@ namespace DCFApixels.DragonECS.Internal
[Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)] [Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif #endif
internal class EcsWhereExecutor : MaskQueryExecutor internal sealed class EcsWhereExecutor : MaskQueryExecutor
{ {
private EcsMaskIterator _iterator; private EcsMaskIterator _iterator;
@ -34,6 +34,11 @@ namespace DCFApixels.DragonECS.Internal
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return _versionsChecker.Check(); } get { return _versionsChecker.Check(); }
} }
public sealed override int LastCachedCount
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return _filteredAllEntitiesCount; }
}
#endregion #endregion
#region OnInitialize/OnDestroy #region OnInitialize/OnDestroy

View File

@ -10,7 +10,7 @@ namespace DCFApixels.DragonECS.Internal
[Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)] [Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif #endif
internal class EcsWhereToGroupExecutor : MaskQueryExecutor internal sealed class EcsWhereToGroupExecutor : MaskQueryExecutor
{ {
private EcsMaskIterator _iterator; private EcsMaskIterator _iterator;
@ -31,6 +31,11 @@ namespace DCFApixels.DragonECS.Internal
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return _versionsChecker.Check(); } get { return _versionsChecker.Check(); }
} }
public sealed override int LastCachedCount
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return _filteredAllGroup.Count; }
}
#endregion #endregion
#region OnInitialize/OnDestroy #region OnInitialize/OnDestroy

View File

@ -9,23 +9,24 @@ namespace DCFApixels.DragonECS
public partial class EcsWorld public partial class EcsWorld
{ {
private readonly Dictionary<(Type, object), IQueryExecutorImplementation> _executorCoures; private readonly Dictionary<(Type, object), IQueryExecutorImplementation> _executorCoures;
public TExecutor GetExecutorForMask<TExecutor>(IComponentMask gmask) public TExecutor GetExecutorForMask<TExecutor>(IComponentMask gmask)
where TExecutor : MaskQueryExecutor, new() where TExecutor : MaskQueryExecutor, new()
{ {
var coreType = typeof(TExecutor); var executorType = typeof(TExecutor);
//проверяет ключ по абстрактной маске //проверяет ключ по абстрактной маске
if (_executorCoures.TryGetValue((coreType, gmask), out IQueryExecutorImplementation executor) == false) if (_executorCoures.TryGetValue((executorType, gmask), out IQueryExecutorImplementation executor) == false)
{ {
var mask = gmask.ToMask(this); var mask = gmask.ToMask(this);
//проверяет ключ по конкретной маске, или что конкретная и абстрактая одна и таже //проверяет ключ по конкретной маске, или что конкретная и абстрактая одна и таже
if (mask == gmask || if (mask == gmask ||
_executorCoures.TryGetValue((coreType, mask), out executor) == false) _executorCoures.TryGetValue((executorType, mask), out executor) == false)
{ {
TExecutor newCore = new TExecutor(); TExecutor executorCore = new TExecutor();
newCore.Initialize(this, mask); executorCore.Initialize(this, mask);
executor = newCore; executor = executorCore;
} }
_executorCoures.Add((coreType, gmask), executor); _executorCoures.Add((executorType, gmask), executor);
} }
return (TExecutor)executor; return (TExecutor)executor;
} }
@ -39,6 +40,7 @@ namespace DCFApixels.DragonECS.Core
EcsWorld World { get; } EcsWorld World { get; }
long Version { get; } long Version { get; }
bool IsCached { get; } bool IsCached { get; }
int LastCachedCount { get; }
void Destroy(); void Destroy();
} }
public abstract class MaskQueryExecutor : IQueryExecutorImplementation public abstract class MaskQueryExecutor : IQueryExecutorImplementation
@ -62,6 +64,7 @@ namespace DCFApixels.DragonECS.Core
} }
public abstract long Version { get; } public abstract long Version { get; }
public abstract bool IsCached { get; } public abstract bool IsCached { get; }
public abstract int LastCachedCount { get; }
internal void Initialize(EcsWorld world, EcsMask mask) internal void Initialize(EcsWorld world, EcsMask mask)
{ {
_source = world; _source = world;