From 4f5d6e09e4daa8c38c6dd4fb0ca924721ae2382f Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 3 Nov 2024 19:02:07 +0800 Subject: [PATCH] update --- src/EcsAspect.cs | 32 ++++++++++++++++++++++++++------ src/EcsPipeline.Builder.cs | 4 +++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/EcsAspect.cs b/src/EcsAspect.cs index 0099606..a08d23c 100644 --- a/src/EcsAspect.cs +++ b/src/EcsAspect.cs @@ -38,12 +38,13 @@ namespace DCFApixels.DragonECS } #endregion + //Инициализация аспектов проходит в синхронизированном состоянии, поэтому использование _staticMaskCache потоко безопасно. + private static Dictionary _staticMaskCache = new Dictionary(); + internal EcsWorld _source; internal EcsMask _mask; private bool _isBuilt = false; - - //Инициализация аспектов проходит в синхронизированном состоянии, поэтому использование _staticMaskCache потоко безопасно. - private static Dictionary _staticMaskCache = new Dictionary(); + private IEcsPool[] _pools; #region Properties public EcsMask Mask @@ -58,6 +59,10 @@ namespace DCFApixels.DragonECS { get { return _isBuilt; } } + public ReadOnlySpan Pools + { + get { return _pools; } + } /// /// Статическая инициализация означет что каждый новый эекземпляр идентичен другому, инициализация стандартным путем создает идентичные экземпляры, поэтому значение по умолчанию true. /// @@ -81,6 +86,9 @@ namespace DCFApixels.DragonECS private EcsWorld _world; private EcsStaticMask.Builder _maskBuilder; + private IEcsPool[] _poolsBuffer = new IEcsPool[8]; + private int _poolsBufferCount; + #region Properties public IncludeMarker Inc { @@ -146,6 +154,8 @@ namespace DCFApixels.DragonECS } } newAspect._mask = staticMask.ToMask(world); + var pools = new IEcsPool[builder._poolsBufferCount]; + Array.Copy(builder._poolsBuffer, pools, pools.Length); newAspect._isBuilt = true; _constructorBuildersStackIndex--; @@ -156,21 +166,31 @@ namespace DCFApixels.DragonECS #region Include/Exclude/Optional/Combine/Except public TPool IncludePool() where TPool : IEcsPoolImplementation, new() { - var pool = _world.GetPoolInstance(); + var pool = CachePool(); IncludeImplicit(pool.ComponentType); return pool; } public TPool ExcludePool() where TPool : IEcsPoolImplementation, new() { - var pool = _world.GetPoolInstance(); + var pool = CachePool(); ExcludeImplicit(pool.ComponentType); return pool; } public TPool OptionalPool() where TPool : IEcsPoolImplementation, new() { - return _world.GetPoolInstance(); + return CachePool(); } + private TPool CachePool() where TPool : IEcsPoolImplementation, new() + { + var pool = _world.GetPoolInstance(); + if(_poolsBufferCount >= _poolsBuffer.Length) + { + Array.Resize(ref _poolsBuffer, _poolsBuffer.Length); + } + _poolsBuffer[_poolsBufferCount++] = pool; + return pool; + } private void IncludeImplicit(Type type) { if (_maskBuilder.IsNull == false) diff --git a/src/EcsPipeline.Builder.cs b/src/EcsPipeline.Builder.cs index 4292d83..a02c197 100644 --- a/src/EcsPipeline.Builder.cs +++ b/src/EcsPipeline.Builder.cs @@ -558,7 +558,9 @@ namespace DCFApixels.DragonECS if (AreMatchingOrderIdentical(listA, listB) == false) { //Для слияния списков слоев, нужно чтобы названия слоев, присутствующие в обоих списках, появлялись в одном и том же порядке в обоих списках - Throw.Exception("To merge layer lists, the names of the layers present in both lists must appear in the same order in both lists."); + + //TODO все еще не работает!!! + //Throw.Exception("To merge layer lists, the names of the layers present in both lists must appear in the same order in both lists."); } HashSet seen = new HashSet();