From f12c01ed10184b50151871f2f9d8210b892089f1 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 7 Nov 2024 08:22:10 +0800 Subject: [PATCH] add LastCachedCount for executors --- src/Executors/EcsWhereExecutor.cs | 7 ++++++- src/Executors/EcsWhereToGroupExecutor.cs | 7 ++++++- src/Executors/MaskQueryExecutor.cs | 17 ++++++++++------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Executors/EcsWhereExecutor.cs b/src/Executors/EcsWhereExecutor.cs index 9162a9d..936abc4 100644 --- a/src/Executors/EcsWhereExecutor.cs +++ b/src/Executors/EcsWhereExecutor.cs @@ -11,7 +11,7 @@ namespace DCFApixels.DragonECS.Internal [Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.ArrayBoundsChecks, false)] #endif - internal class EcsWhereExecutor : MaskQueryExecutor + internal sealed class EcsWhereExecutor : MaskQueryExecutor { private EcsMaskIterator _iterator; @@ -34,6 +34,11 @@ namespace DCFApixels.DragonECS.Internal [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _versionsChecker.Check(); } } + public sealed override int LastCachedCount + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _filteredAllEntitiesCount; } + } #endregion #region OnInitialize/OnDestroy diff --git a/src/Executors/EcsWhereToGroupExecutor.cs b/src/Executors/EcsWhereToGroupExecutor.cs index e885b18..7f626e0 100644 --- a/src/Executors/EcsWhereToGroupExecutor.cs +++ b/src/Executors/EcsWhereToGroupExecutor.cs @@ -10,7 +10,7 @@ namespace DCFApixels.DragonECS.Internal [Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.ArrayBoundsChecks, false)] #endif - internal class EcsWhereToGroupExecutor : MaskQueryExecutor + internal sealed class EcsWhereToGroupExecutor : MaskQueryExecutor { private EcsMaskIterator _iterator; @@ -31,6 +31,11 @@ namespace DCFApixels.DragonECS.Internal [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _versionsChecker.Check(); } } + public sealed override int LastCachedCount + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _filteredAllGroup.Count; } + } #endregion #region OnInitialize/OnDestroy diff --git a/src/Executors/MaskQueryExecutor.cs b/src/Executors/MaskQueryExecutor.cs index ffa58e0..aac7f35 100644 --- a/src/Executors/MaskQueryExecutor.cs +++ b/src/Executors/MaskQueryExecutor.cs @@ -9,23 +9,24 @@ namespace DCFApixels.DragonECS public partial class EcsWorld { private readonly Dictionary<(Type, object), IQueryExecutorImplementation> _executorCoures; + public TExecutor GetExecutorForMask(IComponentMask gmask) 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); //проверяет ключ по конкретной маске, или что конкретная и абстрактая одна и таже if (mask == gmask || - _executorCoures.TryGetValue((coreType, mask), out executor) == false) + _executorCoures.TryGetValue((executorType, mask), out executor) == false) { - TExecutor newCore = new TExecutor(); - newCore.Initialize(this, mask); - executor = newCore; + TExecutor executorCore = new TExecutor(); + executorCore.Initialize(this, mask); + executor = executorCore; } - _executorCoures.Add((coreType, gmask), executor); + _executorCoures.Add((executorType, gmask), executor); } return (TExecutor)executor; } @@ -39,6 +40,7 @@ namespace DCFApixels.DragonECS.Core EcsWorld World { get; } long Version { get; } bool IsCached { get; } + int LastCachedCount { get; } void Destroy(); } public abstract class MaskQueryExecutor : IQueryExecutorImplementation @@ -62,6 +64,7 @@ namespace DCFApixels.DragonECS.Core } public abstract long Version { get; } public abstract bool IsCached { get; } + public abstract int LastCachedCount { get; } internal void Initialize(EcsWorld world, EcsMask mask) { _source = world;