mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +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)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public int Last() { return _dense[_count]; }
|
public int Last() { return _dense[_count]; }
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return CollectionUtility.EntitiesToString(_dense.Skip(1).Take(_count), "group");
|
return CollectionUtility.EntitiesToString(_dense.Skip(1).Take(_count), "group");
|
||||||
|
@ -462,8 +462,7 @@ namespace DCFApixels.DragonECS
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unchecked { _version++; }
|
unchecked { _version++; }
|
||||||
count = Math.Min(count, _delEntBufferCount);
|
count = Math.Max(0, Math.Min(count, _delEntBufferCount));
|
||||||
count = Math.Max(count, 0);
|
|
||||||
_delEntBufferCount -= count;
|
_delEntBufferCount -= count;
|
||||||
int slisedCount = count;
|
int slisedCount = count;
|
||||||
|
|
||||||
@ -488,6 +487,17 @@ namespace DCFApixels.DragonECS
|
|||||||
_pools[i].OnReleaseDelEntityBuffer(bufferSlised);
|
_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);
|
_listeners.InvokeOnReleaseDelEntityBuffer(buffer);
|
||||||
for (int i = 0; i < buffer.Length; i++)
|
for (int i = 0; i < buffer.Length; i++)
|
||||||
@ -525,25 +535,28 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
if (_groups[i].TryGetTarget(out EcsGroup group))
|
if (_groups[i].TryGetTarget(out EcsGroup group))
|
||||||
{
|
{
|
||||||
group.OnWorldResize(newSize);
|
group.OnWorldResize_Internal(newSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int last = _groups.Count - 1;
|
RemoveGroupAt(i--);
|
||||||
_groups[i--] = _groups[last];
|
|
||||||
_groups.RemoveAt(last);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (var item in _pools)
|
foreach (var item in _pools)
|
||||||
{
|
{
|
||||||
item.OnWorldResize(newSize);
|
item.OnWorldResize(newSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
_listeners.InvokeOnWorldResize(newSize);
|
_listeners.InvokeOnWorldResize(newSize);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Groups Pool
|
#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)
|
internal void RegisterGroup(EcsGroup group)
|
||||||
{
|
{
|
||||||
_groups.Add(new WeakReference<EcsGroup>(group));
|
_groups.Add(new WeakReference<EcsGroup>(group));
|
||||||
|
Loading…
Reference in New Issue
Block a user