From 22e09a7ed276e9fe6e0e78887a28388327f70537 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sat, 28 Mar 2026 18:47:45 +0800 Subject: [PATCH] Update EcsPool.cs --- src/Pools/EcsPool.cs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Pools/EcsPool.cs b/src/Pools/EcsPool.cs index 40d2629..0a7a87b 100644 --- a/src/Pools/EcsPool.cs +++ b/src/Pools/EcsPool.cs @@ -154,7 +154,7 @@ namespace DCFApixels.DragonECS } _mediator.RegisterComponent(entityID, _componentTypeID, _maskBit); ref T result = ref _items[itemIndex]; - EcsComponentLifecycle.OnAdd( _isCustomLifecycle, _customLifecycle, ref result, _worldID, entityID); + InvokeOnAdd(entityID, ref _items[itemIndex]); #if !DRAGONECS_DISABLE_POOLS_EVENTS if (_hasAnyListener) { _listeners.InvokeOnAddAndGet(entityID); } #endif @@ -206,7 +206,7 @@ namespace DCFApixels.DragonECS } } _mediator.RegisterComponent(entityID, _componentTypeID, _maskBit); - EcsComponentLifecycle.OnAdd(_isCustomLifecycle, _customLifecycle, ref _items[itemIndex], _worldID, entityID); + InvokeOnAdd(entityID, ref _items[itemIndex]); #if !DRAGONECS_DISABLE_POOLS_EVENTS if (_hasAnyListener) { _listeners.InvokeOnAdd(entityID); } #endif @@ -232,7 +232,7 @@ namespace DCFApixels.DragonECS if (itemIndex <= 0) { return; } if (_isLocked) { return; } #endif - EcsComponentLifecycle.OnDel( _isCustomLifecycle, _customLifecycle, ref _items[itemIndex], _worldID, entityID); + InvokeOnDel(entityID, ref _items[itemIndex]); if (_recycledItemsCount >= _recycledItems.Length) { Array.Resize(ref _recycledItems, ArrayUtility.NextPow2Safe(_recycledItemsCount)); @@ -284,7 +284,7 @@ namespace DCFApixels.DragonECS foreach (var entityID in span) { ref int itemIndex = ref _mapping[entityID]; - EcsComponentLifecycle.OnDel(_isCustomLifecycle, _customLifecycle, ref _items[itemIndex], _worldID, entityID); + InvokeOnDel(entityID, ref _items[itemIndex]); itemIndex = 0; _mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit); #if !DRAGONECS_DISABLE_POOLS_EVENTS @@ -317,6 +317,26 @@ namespace DCFApixels.DragonECS #endregion #region Other + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void InvokeOnAdd(int entityID, ref T component) + { + if (_isCustomLifecycle) + { + _customLifecycle.OnAdd(ref component, _worldID, entityID); + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void InvokeOnDel(int entityID, ref T component) + { + if (_isCustomLifecycle) + { + _customLifecycle.OnDel(ref component, _worldID, entityID); + } + else + { + component = default; + } + } void IEcsPool.AddEmpty(int entityID) { Add(entityID); } void IEcsPool.AddRaw(int entityID, object dataRaw) {