From 39861492672f636217658dd73dc6ee825a5c0593 Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 17 Mar 2025 11:06:52 +0800 Subject: [PATCH] update mask, add world.TryFindPoolInstance --- src/EcsAspect.cs | 12 ++++++------ src/EcsMask.cs | 20 +++++++++++++++----- src/EcsWorld.pools.cs | 11 +++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/EcsAspect.cs b/src/EcsAspect.cs index 1f56e26..13f38e4 100644 --- a/src/EcsAspect.cs +++ b/src/EcsAspect.cs @@ -272,13 +272,13 @@ namespace DCFApixels.DragonECS public TPool IncludePool() where TPool : IEcsPoolImplementation, new() { var pool = CachePool(); - IncludeImplicit(pool.ComponentType); + SetMaskInclude(pool.ComponentType); return pool; } public TPool ExcludePool() where TPool : IEcsPoolImplementation, new() { var pool = CachePool(); - ExcludeImplicit(pool.ComponentType); + SetMaskExclude(pool.ComponentType); return pool; } public TPool OptionalPool() where TPool : IEcsPoolImplementation, new() @@ -291,14 +291,14 @@ namespace DCFApixels.DragonECS var pool = _world.GetPoolInstance(); return pool; } - private void IncludeImplicit(Type type) + public void SetMaskInclude(Type type) { if (_maskBuilder.IsNull == false) { _maskBuilder.Inc(type); } } - private void ExcludeImplicit(Type type) + public void SetMaskExclude(Type type) { if (_maskBuilder.IsNull == false) { @@ -334,8 +334,8 @@ namespace DCFApixels.DragonECS IncludePool(); ExcludePool(); OptionalPool(); - IncludeImplicit(null); - ExcludeImplicit(null); + SetMaskInclude(null); + SetMaskExclude(null); } #endregion } diff --git a/src/EcsMask.cs b/src/EcsMask.cs index acd36e6..3a88fdc 100644 --- a/src/EcsMask.cs +++ b/src/EcsMask.cs @@ -488,7 +488,7 @@ namespace DCFApixels.DragonECS [Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.ArrayBoundsChecks, false)] #endif - public class EcsMaskIterator + public class EcsMaskIterator : IDisposable { // TODO есть идея перенести эти ChunckBuffer-ы в стек, // для этого нужно проработать дизайн так чтобы память в стеке выделялась за пределами итератора и GetEnumerator, @@ -555,6 +555,15 @@ namespace DCFApixels.DragonECS } } unsafe ~EcsMaskIterator() + { + Cleanup(false); + } + public void Dispose() + { + Cleanup(true); + GC.SuppressFinalize(this); + } + private void Cleanup(bool disposing) { _sortIncBuffer.ReadonlyDispose(); //_sortExcBuffer.ReadonlyDispose();// использует общую памяять с _sortIncBuffer; @@ -563,7 +572,7 @@ namespace DCFApixels.DragonECS } #endregion - #region SortConstraints + #region SortConstraints/TryFindEntityStorage private unsafe int SortConstraints_Internal() { UnsafeArray sortIncBuffer = _sortIncBuffer; @@ -611,7 +620,7 @@ namespace DCFApixels.DragonECS // Поэтому исключающее ограничение игнорируется для maxEntites. return maxEntites; } - private unsafe bool TryGetEntityStorage(out IEntityStorage storage) + private unsafe bool TryFindEntityStorage(out IEntityStorage storage) { if (_isHasAnyEntityStorage) { @@ -737,7 +746,7 @@ namespace DCFApixels.DragonECS { return new Enumerator(_span.Slice(0, 0), _iterator); } - if (_iterator.TryGetEntityStorage(out IEntityStorage storage)) + if (_iterator.TryFindEntityStorage(out IEntityStorage storage)) { return new Enumerator(storage.ToSpan(), _iterator); } @@ -811,6 +820,7 @@ namespace DCFApixels.DragonECS #region Iterate/Enumerable OnlyInc [MethodImpl(MethodImplOptions.AggressiveInlining)] public OnlyIncEnumerable IterateOnlyInc(EcsSpan span) { return new OnlyIncEnumerable(this, span); } + #if ENABLE_IL2CPP [Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.ArrayBoundsChecks, false)] @@ -876,7 +886,7 @@ namespace DCFApixels.DragonECS { return new Enumerator(_span.Slice(0, 0), _iterator); } - if (_iterator.TryGetEntityStorage(out IEntityStorage storage)) + if (_iterator.TryFindEntityStorage(out IEntityStorage storage)) { return new Enumerator(storage.ToSpan(), _iterator); } diff --git a/src/EcsWorld.pools.cs b/src/EcsWorld.pools.cs index 1c1d047..357b891 100644 --- a/src/EcsWorld.pools.cs +++ b/src/EcsWorld.pools.cs @@ -40,6 +40,17 @@ namespace DCFApixels.DragonECS { return FindPoolInstance_Internal(GetComponentTypeID(componentType)); } + public bool TryFindPoolInstance(int componentTypeID, out IEcsPool pool) + { + pool = FindPoolInstance(componentTypeID); + return pool.IsNullOrDummy() == false; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool TryFindPoolInstance(Type componentType, out IEcsPool pool) + { + pool = FindPoolInstance(componentType); + return pool.IsNullOrDummy() == false; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] private IEcsPool FindPoolInstance_Internal(int componentTypeID) {