mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
fix EcsGroup
This commit is contained in:
parent
7a6dc93bdb
commit
89cb4c68b9
@ -10,6 +10,7 @@ using System.Runtime.InteropServices;
|
|||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
//_dense заполняется с индекса 1
|
//_dense заполняется с индекса 1
|
||||||
|
//в операциях изменяющих состояние группы нельзя итерироваться по this, либо осторожно учитывать этот момент
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 8)]
|
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 8)]
|
||||||
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||||
public readonly ref struct EcsReadonlyGroup
|
public readonly ref struct EcsReadonlyGroup
|
||||||
@ -369,17 +370,39 @@ namespace DCFApixels.DragonECS
|
|||||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
if (_source != group.World) Throw.Group_ArgumentDifferentWorldsException();
|
if (_source != group.World) Throw.Group_ArgumentDifferentWorldsException();
|
||||||
#endif
|
#endif
|
||||||
|
//if (group.Count > Count) // вариант 1. есть итерация по this
|
||||||
|
//{
|
||||||
|
// foreach (var item in this)
|
||||||
|
// if (group.Has(item))
|
||||||
|
// RemoveInternal(item);
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// foreach (var item in group)
|
||||||
|
// if (Has(item))
|
||||||
|
// RemoveInternal(item);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//foreach (var item in group) // вариант 2
|
||||||
|
// if (Has(item))
|
||||||
|
// RemoveInternal(item);
|
||||||
|
|
||||||
if (group.Count > Count)
|
if (group.Count > Count)
|
||||||
{
|
{
|
||||||
foreach (var item in this)
|
for (int i = _count; i > 0; i--)//итерация в обратном порядке исключает ошибки при удалении элементов
|
||||||
|
{
|
||||||
|
int item = _dense[i];
|
||||||
if (group.Has(item))
|
if (group.Has(item))
|
||||||
RemoveInternal(item);
|
RemoveInternal(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var item in group)
|
foreach (var item in group)
|
||||||
|
{
|
||||||
if (Has(item))
|
if (Has(item))
|
||||||
RemoveInternal(item);
|
RemoveInternal(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void ExceptWith(EcsSpan span)
|
public void ExceptWith(EcsSpan span)
|
||||||
@ -405,9 +428,12 @@ namespace DCFApixels.DragonECS
|
|||||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
if (World != group.World) Throw.Group_ArgumentDifferentWorldsException();
|
if (World != group.World) Throw.Group_ArgumentDifferentWorldsException();
|
||||||
#endif
|
#endif
|
||||||
foreach (var item in this)
|
for (int i = _count; i > 0; i--)//итерация в обратном порядке исключает ошибки при удалении элементов
|
||||||
|
{
|
||||||
|
int item = _dense[i];
|
||||||
if (!group.Has(item))
|
if (!group.Has(item))
|
||||||
RemoveInternal(item);
|
RemoveInternal(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user