mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +08:00
add nullpage
This commit is contained in:
parent
0ca66e853b
commit
c865ea0e4f
@ -258,6 +258,8 @@ namespace DCFApixels.DragonECS
|
|||||||
private int _count = 0;
|
private int _count = 0;
|
||||||
internal bool _isReleased = true;
|
internal bool _isReleased = true;
|
||||||
|
|
||||||
|
private static readonly int* _nullPage = UnmanagedArrayUtility.NewAndInit<int>(PageSlot.SIZE);
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public short WorldID
|
public short WorldID
|
||||||
{
|
{
|
||||||
@ -334,7 +336,11 @@ namespace DCFApixels.DragonECS
|
|||||||
//_sparse = new int[world.Capacity];
|
//_sparse = new int[world.Capacity];
|
||||||
_totalCapacity = world.Capacity;
|
_totalCapacity = world.Capacity;
|
||||||
_sparsePagesCount = CalcSparseSize(_totalCapacity);
|
_sparsePagesCount = CalcSparseSize(_totalCapacity);
|
||||||
_sparsePages = UnmanagedArrayUtility.NewAndInit<PageSlot>(_sparsePagesCount);
|
_sparsePages = UnmanagedArrayUtility.New<PageSlot>(_sparsePagesCount);
|
||||||
|
for (int i = 0; i < _sparsePagesCount; i++)
|
||||||
|
{
|
||||||
|
_sparsePages[i] = PageSlot.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
@ -348,20 +354,14 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
//return _sparse[entityID] != 0;
|
//return _sparse[entityID] != 0;
|
||||||
PageSlot* page = _sparsePages + (entityID >> PageSlot.SHIFT);
|
PageSlot* page = _sparsePages + (entityID >> PageSlot.SHIFT);
|
||||||
|
return page->Indexes[entityID & PageSlot.MASK] != 0;
|
||||||
ReadOnlySpan<int> span = default;
|
|
||||||
if (page->Indexes != null)
|
|
||||||
{
|
|
||||||
span = new ReadOnlySpan<int>(page->Indexes, PageSlot.SIZE);
|
|
||||||
}
|
|
||||||
return page->Indexes != null && page->Indexes[entityID & PageSlot.MASK] != 0;
|
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public int IndexOf(int entityID)
|
public int IndexOf(int entityID)
|
||||||
{
|
{
|
||||||
//return _sparse[entityID];
|
//return _sparse[entityID];
|
||||||
PageSlot* page = _sparsePages + (entityID >> PageSlot.SHIFT);
|
PageSlot* page = _sparsePages + (entityID >> PageSlot.SHIFT);
|
||||||
return page->Indexes != null ? page->Indexes[entityID & PageSlot.MASK] : 0;
|
return page->Indexes[entityID & PageSlot.MASK];
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -404,11 +404,6 @@ namespace DCFApixels.DragonECS
|
|||||||
page->Indexes[entityID & PageSlot.MASK] = _count;
|
page->Indexes[entityID & PageSlot.MASK] = _count;
|
||||||
page->IndexesXOR ^= _count;
|
page->IndexesXOR ^= _count;
|
||||||
page->Count++;
|
page->Count++;
|
||||||
|
|
||||||
//if (page->Count == 1)
|
|
||||||
//{
|
|
||||||
// ReadOnlySpan<int> pageSpan = new ReadOnlySpan<int>(page->Indexes, PageSlot.SIZE);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveUnchecked(int entityID)
|
public void RemoveUnchecked(int entityID)
|
||||||
@ -447,18 +442,13 @@ namespace DCFApixels.DragonECS
|
|||||||
if (--page->Count == 0)
|
if (--page->Count == 0)
|
||||||
{
|
{
|
||||||
_source.ReturnPage(page->Indexes);
|
_source.ReturnPage(page->Indexes);
|
||||||
page->Indexes = null;
|
page->Indexes = _nullPage;
|
||||||
page->IndexesXOR = 0;
|
page->IndexesXOR = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
page->IndexesXOR ^= page->Indexes[localEntityID];
|
page->IndexesXOR ^= page->Indexes[localEntityID];
|
||||||
page->Indexes[localEntityID] = 0;
|
page->Indexes[localEntityID] = 0;
|
||||||
|
|
||||||
if (page->Count == 1)
|
|
||||||
{
|
|
||||||
ReadOnlySpan<int> pageSpan = new ReadOnlySpan<int>(page->Indexes, PageSlot.SIZE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,7 +478,7 @@ namespace DCFApixels.DragonECS
|
|||||||
for (int i = 0; i < _sparsePagesCount; i++)
|
for (int i = 0; i < _sparsePagesCount; i++)
|
||||||
{
|
{
|
||||||
var page = _sparsePages + i;
|
var page = _sparsePages + i;
|
||||||
if (page->Indexes != null)
|
if (page->Indexes != _nullPage)
|
||||||
{
|
{
|
||||||
//TODO тут надо оптимизировать отчисткой не всего а по dense списку
|
//TODO тут надо оптимизировать отчисткой не всего а по dense списку
|
||||||
for (int j = 0; j < PageSlot.SIZE; j++)
|
for (int j = 0; j < PageSlot.SIZE; j++)
|
||||||
@ -496,7 +486,7 @@ namespace DCFApixels.DragonECS
|
|||||||
page->Indexes[j] = 0;
|
page->Indexes[j] = 0;
|
||||||
}
|
}
|
||||||
_source.ReturnPage(page->Indexes);
|
_source.ReturnPage(page->Indexes);
|
||||||
page->Indexes = null;
|
page->Indexes = _nullPage;
|
||||||
}
|
}
|
||||||
page->IndexesXOR = 0;
|
page->IndexesXOR = 0;
|
||||||
page->Count = 0;
|
page->Count = 0;
|
||||||
@ -1449,7 +1439,11 @@ namespace DCFApixels.DragonECS
|
|||||||
_totalCapacity = newSize;
|
_totalCapacity = newSize;
|
||||||
var oldPagesCount = _sparsePagesCount;
|
var oldPagesCount = _sparsePagesCount;
|
||||||
_sparsePagesCount = CalcSparseSize(_totalCapacity);
|
_sparsePagesCount = CalcSparseSize(_totalCapacity);
|
||||||
_sparsePages = UnmanagedArrayUtility.ResizeAndInit<PageSlot>(_sparsePages, oldPagesCount, _sparsePagesCount);
|
_sparsePages = UnmanagedArrayUtility.Resize<PageSlot>(_sparsePages, _sparsePagesCount);
|
||||||
|
for (int i = oldPagesCount; i < _sparsePagesCount; i++)
|
||||||
|
{
|
||||||
|
_sparsePages[i] = PageSlot.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal void OnReleaseDelEntityBuffer_Internal(ReadOnlySpan<int> buffer)
|
internal void OnReleaseDelEntityBuffer_Internal(ReadOnlySpan<int> buffer)
|
||||||
@ -1511,9 +1505,17 @@ namespace DCFApixels.DragonECS
|
|||||||
public const int SIZE = 1 << SHIFT;
|
public const int SIZE = 1 << SHIFT;
|
||||||
public const int MASK = SIZE - 1;
|
public const int MASK = SIZE - 1;
|
||||||
|
|
||||||
|
public static readonly PageSlot Empty = new PageSlot(_nullPage, 0, 0);
|
||||||
|
|
||||||
public int* Indexes;
|
public int* Indexes;
|
||||||
public int IndexesXOR;
|
public int IndexesXOR;
|
||||||
public byte Count;
|
public byte Count;
|
||||||
|
public PageSlot(int* indexes, int indexesXOR, byte count)
|
||||||
|
{
|
||||||
|
Indexes = indexes;
|
||||||
|
IndexesXOR = indexesXOR;
|
||||||
|
Count = count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ namespace DCFApixels.DragonECS.Internal
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static T* New<T>(int capacity) where T : unmanaged
|
public static T* New<T>(int capacity) where T : unmanaged
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{typeof(T).Name} - {Marshal.SizeOf<T>()} - {capacity} - {Marshal.SizeOf<T>() * capacity}");
|
//Console.WriteLine($"{typeof(T).Name} - {Marshal.SizeOf<T>()} - {capacity} - {Marshal.SizeOf<T>() * capacity}");
|
||||||
return (T*)Marshal.AllocHGlobal(Marshal.SizeOf<T>() * capacity).ToPointer();
|
return (T*)Marshal.AllocHGlobal(Marshal.SizeOf<T>() * capacity).ToPointer();
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
Loading…
Reference in New Issue
Block a user