mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +08:00
add deletion of released entities in groups
This commit is contained in:
parent
a714388549
commit
301fe5a55b
@ -853,7 +853,25 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Last() { return _dense[_count]; }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void OnWorldResize(int newSize) { Array.Resize(ref _sparse, newSize); }
|
||||
internal void OnWorldResize_Internal(int newSize)
|
||||
{
|
||||
Array.Resize(ref _sparse, newSize);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void OnReleaseDelEntityBuffer_Internal(ReadOnlySpan<int> buffer)
|
||||
{
|
||||
if (_count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var entityID in buffer)
|
||||
{
|
||||
if (Has(entityID))
|
||||
{
|
||||
Remove_Internal(entityID);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return CollectionUtility.EntitiesToString(_dense.Skip(1).Take(_count), "group");
|
||||
|
@ -462,8 +462,7 @@ namespace DCFApixels.DragonECS
|
||||
return;
|
||||
}
|
||||
unchecked { _version++; }
|
||||
count = Math.Min(count, _delEntBufferCount);
|
||||
count = Math.Max(count, 0);
|
||||
count = Math.Max(0, Math.Min(count, _delEntBufferCount));
|
||||
_delEntBufferCount -= count;
|
||||
int slisedCount = count;
|
||||
|
||||
@ -488,6 +487,17 @@ namespace DCFApixels.DragonECS
|
||||
_pools[i].OnReleaseDelEntityBuffer(bufferSlised);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < _groups.Count; i++)
|
||||
{
|
||||
if (_groups[i].TryGetTarget(out EcsGroup group) && group.IsReleased)
|
||||
{
|
||||
group.OnReleaseDelEntityBuffer_Internal(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveGroupAt(i--);
|
||||
}
|
||||
}
|
||||
|
||||
_listeners.InvokeOnReleaseDelEntityBuffer(buffer);
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
@ -525,25 +535,28 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
if (_groups[i].TryGetTarget(out EcsGroup group))
|
||||
{
|
||||
group.OnWorldResize(newSize);
|
||||
group.OnWorldResize_Internal(newSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
int last = _groups.Count - 1;
|
||||
_groups[i--] = _groups[last];
|
||||
_groups.RemoveAt(last);
|
||||
RemoveGroupAt(i--);
|
||||
}
|
||||
}
|
||||
foreach (var item in _pools)
|
||||
{
|
||||
item.OnWorldResize(newSize);
|
||||
}
|
||||
|
||||
_listeners.InvokeOnWorldResize(newSize);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Groups Pool
|
||||
private void RemoveGroupAt(int index)
|
||||
{
|
||||
int last = _groups.Count - 1;
|
||||
_groups[index] = _groups[last];
|
||||
_groups.RemoveAt(last);
|
||||
}
|
||||
internal void RegisterGroup(EcsGroup group)
|
||||
{
|
||||
_groups.Add(new WeakReference<EcsGroup>(group));
|
||||
|
Loading…
Reference in New Issue
Block a user