Update EcsPool.cs

This commit is contained in:
DCFApixels 2025-05-01 14:48:44 +08:00
parent 85100b7d62
commit 2595c25db4

View File

@ -95,6 +95,7 @@ namespace DCFApixels.DragonECS
{
ref int itemIndex = ref _mapping[entityID];
#if DEBUG
if (entityID == EcsConsts.NULL_ENTITY_ID) { Throw.Ent_ThrowIsNotAlive(_source, entityID); }
if (_source.IsUsed(entityID) == false) { Throw.Ent_ThrowIsNotAlive(_source, entityID); }
if (itemIndex > 0) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); }
if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
@ -144,6 +145,9 @@ namespace DCFApixels.DragonECS
}
public ref T TryAddOrGet(int entityID)
{
#if DEBUG
if (entityID == EcsConsts.NULL_ENTITY_ID) { Throw.Ent_ThrowIsNotAlive(_source, entityID); }
#endif
ref int itemIndex = ref _mapping[entityID];
if (itemIndex <= 0)
{ //Add block
@ -185,6 +189,7 @@ namespace DCFApixels.DragonECS
{
ref int itemIndex = ref _mapping[entityID];
#if DEBUG
if (entityID == EcsConsts.NULL_ENTITY_ID) { Throw.Ent_ThrowIsNotAlive(_source, entityID); }
if (itemIndex <= 0) { EcsPoolThrowHelper.ThrowNotHaveComponent<T>(entityID); }
if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
#elif DRAGONECS_STABILITY_MODE
@ -237,9 +242,8 @@ namespace DCFApixels.DragonECS
#elif DRAGONECS_STABILITY_MODE
if (_isLocked) { return; }
#endif
_recycledItemsCount = 0; // спереди потому чтобы обнулялось, так как Del не обнуляет
_recycledItemsCount = 0; // ñïåðåäè ÷òîáû îáíóëÿëîñü, òàê êàê Del íå îáíóëÿåò
if (_itemsCount <= 0) { return; }
_itemsCount = 0;
var span = _source.Where(out SingleAspect<T> _);
foreach (var entityID in span)
{
@ -251,6 +255,8 @@ namespace DCFApixels.DragonECS
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
#endif
}
_itemsCount = 0;
_recycledItemsCount = 0;
}
#endregion