mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +08:00
refacotr GetComponents(debug) & add GetComponentTypeIDs(debug)
This commit is contained in:
parent
c05cd91c4e
commit
330261b971
@ -1,5 +1,6 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
@ -624,43 +625,35 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Debug Components
|
#region Debug Components
|
||||||
|
private static int[] _componentIDsBuffer = new int[64];
|
||||||
|
public ReadOnlySpan<int> GetComponentTypeIDs(int entityID)
|
||||||
|
{
|
||||||
|
int count = GetComponentTypeIDs(entityID, ref _componentIDsBuffer);
|
||||||
|
return new ReadOnlySpan<int>(_componentIDsBuffer, 0, count);
|
||||||
|
}
|
||||||
public void GetComponents(int entityID, List<object> list)
|
public void GetComponents(int entityID, List<object> list)
|
||||||
{
|
{
|
||||||
list.Clear();
|
list.Clear();
|
||||||
var itemsCount = GetComponentsCount(entityID);
|
int count = GetComponentTypeIDs(entityID, ref _componentIDsBuffer);
|
||||||
if (itemsCount <= 0) { return; }
|
for (int i = 0; i < count; i++)
|
||||||
int poolIndex = 0;
|
|
||||||
uint bit;
|
|
||||||
for (int chunkIndex = entityID * _entityComponentMaskLength, chunkIndexMax = chunkIndex + _entityComponentMaskLength; chunkIndex < chunkIndexMax; chunkIndex++)
|
|
||||||
{
|
{
|
||||||
bit = 0x0000_0001;
|
list.Add(_pools[_componentIDsBuffer[i]].GetRaw(entityID));
|
||||||
int chunk = _entityComponentMasks[chunkIndex];
|
|
||||||
if (chunk == 0)
|
|
||||||
{
|
|
||||||
poolIndex += COMPONENT_MASK_CHUNK_SIZE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (bit != 0)
|
|
||||||
{
|
|
||||||
if ((chunk & bit) != 0)
|
|
||||||
{
|
|
||||||
itemsCount--;
|
|
||||||
list.Add(_pools[poolIndex].GetRaw(entityID));
|
|
||||||
if (itemsCount <= 0) { goto exit; }
|
|
||||||
}
|
|
||||||
bit <<= 1;
|
|
||||||
poolIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exit:;
|
|
||||||
}
|
}
|
||||||
public void GetComponentTypes(int entityID, HashSet<Type> typeSet)
|
public void GetComponentTypes(int entityID, HashSet<Type> typeSet)
|
||||||
{
|
{
|
||||||
typeSet.Clear();
|
typeSet.Clear();
|
||||||
|
int count = GetComponentTypeIDs(entityID, ref _componentIDsBuffer);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
typeSet.Add(_pools[_componentIDsBuffer[i]].ComponentType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private int GetComponentTypeIDs(int entityID, ref int[] componentIDs)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
var itemsCount = GetComponentsCount(entityID);
|
var itemsCount = GetComponentsCount(entityID);
|
||||||
if(itemsCount <= 0) { return; }
|
if (itemsCount <= 0) { return count; }
|
||||||
int poolIndex = 0;
|
int poolIndex = 0;
|
||||||
uint bit;
|
uint bit;
|
||||||
for (int chunkIndex = entityID * _entityComponentMaskLength, chunkIndexMax = chunkIndex + _entityComponentMaskLength; chunkIndex < chunkIndexMax; chunkIndex++)
|
for (int chunkIndex = entityID * _entityComponentMaskLength, chunkIndexMax = chunkIndex + _entityComponentMaskLength; chunkIndex < chunkIndexMax; chunkIndex++)
|
||||||
@ -678,7 +671,11 @@ namespace DCFApixels.DragonECS
|
|||||||
if ((chunk & bit) != 0)
|
if ((chunk & bit) != 0)
|
||||||
{
|
{
|
||||||
itemsCount--;
|
itemsCount--;
|
||||||
typeSet.Add(_pools[poolIndex].ComponentType);
|
if(count > componentIDs.Length)
|
||||||
|
{
|
||||||
|
Array.Resize(ref componentIDs, count << 1);
|
||||||
|
}
|
||||||
|
componentIDs[count++] = _pools[poolIndex].ComponentTypeID;
|
||||||
if (itemsCount <= 0) { goto exit; }
|
if (itemsCount <= 0) { goto exit; }
|
||||||
}
|
}
|
||||||
bit <<= 1;
|
bit <<= 1;
|
||||||
@ -687,6 +684,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit:;
|
exit:;
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user