forked from Misaki/GhostEngine
Support enableable components and query enhancements
- Upgraded `Misaki.HighPerformance.LowLevel` to v1.2.8. - Added `IEquatable` to `Handle<T>` and `Identifier<T>`. - Improved `Result` extensions with `[CallerArgumentExpression]`. - Introduced `SetEnabled` in `EntityManager` to toggle components. - Refactored `Chunk` and `Archetype` for enableable components. - Added `EntityQueryMask` for filtering enabled/disabled components. - Enhanced `QueryBuilder` with new filtering methods (`WithAll`, etc.). - Improved `EntityQuery.ForEach` with entity validation.
This commit is contained in:
@@ -14,18 +14,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[1];
|
||||
var basePtrs = stackalloc byte*[1];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 1; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -36,14 +38,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 1; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
|
||||
action(ref *pComp0);
|
||||
@@ -62,18 +70,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[2];
|
||||
var basePtrs = stackalloc byte*[2];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 2; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -84,14 +94,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 2; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
|
||||
@@ -112,18 +128,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[3];
|
||||
var basePtrs = stackalloc byte*[3];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 3; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -134,14 +152,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 3; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
@@ -164,18 +188,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[4];
|
||||
var basePtrs = stackalloc byte*[4];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 4; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -186,14 +212,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 4; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
@@ -218,18 +250,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[5];
|
||||
var basePtrs = stackalloc byte*[5];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 5; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -240,14 +274,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 5; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
@@ -274,18 +314,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[6];
|
||||
var basePtrs = stackalloc byte*[6];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 6; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -296,14 +338,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 6; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
@@ -332,18 +380,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[7];
|
||||
var basePtrs = stackalloc byte*[7];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 7; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -354,14 +404,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 7; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
@@ -392,18 +448,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[8];
|
||||
var basePtrs = stackalloc byte*[8];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 8; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -414,14 +472,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 8; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
@@ -437,7 +501,6 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public readonly void ForEach<T0>(ForEachWithEntity<T0> action)
|
||||
where T0 : unmanaged, IComponent
|
||||
{
|
||||
@@ -447,18 +510,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[1];
|
||||
var basePtrs = stackalloc byte*[1];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 1; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -469,17 +534,23 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 1; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
var pEntity = (Entity*)(chunk.GetUnsafePtr() + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
|
||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
action(*pEntity, ref *pComp0);
|
||||
}
|
||||
}
|
||||
@@ -496,18 +567,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[2];
|
||||
var basePtrs = stackalloc byte*[2];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 2; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -518,18 +591,24 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 2; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
var pEntity = (Entity*)(chunk.GetUnsafePtr() + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
|
||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
action(*pEntity, ref *pComp0,ref *pComp1);
|
||||
}
|
||||
}
|
||||
@@ -547,18 +626,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[3];
|
||||
var basePtrs = stackalloc byte*[3];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 3; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -569,19 +650,25 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 3; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
var pEntity = (Entity*)(chunk.GetUnsafePtr() + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
|
||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
action(*pEntity, ref *pComp0,ref *pComp1,ref *pComp2);
|
||||
}
|
||||
}
|
||||
@@ -600,18 +687,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[4];
|
||||
var basePtrs = stackalloc byte*[4];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 4; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -622,20 +711,26 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 4; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
var pEntity = (Entity*)(chunk.GetUnsafePtr() + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
var pComp3 = (T3*)(basePtrs[3] + (sizeof(T3) * entityIndex));
|
||||
|
||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
action(*pEntity, ref *pComp0,ref *pComp1,ref *pComp2,ref *pComp3);
|
||||
}
|
||||
}
|
||||
@@ -655,18 +750,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[5];
|
||||
var basePtrs = stackalloc byte*[5];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 5; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -677,21 +774,27 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 5; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
var pEntity = (Entity*)(chunk.GetUnsafePtr() + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
var pComp3 = (T3*)(basePtrs[3] + (sizeof(T3) * entityIndex));
|
||||
var pComp4 = (T4*)(basePtrs[4] + (sizeof(T4) * entityIndex));
|
||||
|
||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
action(*pEntity, ref *pComp0,ref *pComp1,ref *pComp2,ref *pComp3,ref *pComp4);
|
||||
}
|
||||
}
|
||||
@@ -712,18 +815,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[6];
|
||||
var basePtrs = stackalloc byte*[6];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 6; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -734,15 +839,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 6; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
var pEntity = (Entity*)(chunk.GetUnsafePtr() + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
@@ -750,6 +860,7 @@ public unsafe partial struct EntityQuery
|
||||
var pComp4 = (T4*)(basePtrs[4] + (sizeof(T4) * entityIndex));
|
||||
var pComp5 = (T5*)(basePtrs[5] + (sizeof(T5) * entityIndex));
|
||||
|
||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
action(*pEntity, ref *pComp0,ref *pComp1,ref *pComp2,ref *pComp3,ref *pComp4,ref *pComp5);
|
||||
}
|
||||
}
|
||||
@@ -771,18 +882,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[7];
|
||||
var basePtrs = stackalloc byte*[7];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 7; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -793,15 +906,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 7; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
var pEntity = (Entity*)(chunk.GetUnsafePtr() + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
@@ -810,6 +928,7 @@ public unsafe partial struct EntityQuery
|
||||
var pComp5 = (T5*)(basePtrs[5] + (sizeof(T5) * entityIndex));
|
||||
var pComp6 = (T6*)(basePtrs[6] + (sizeof(T6) * entityIndex));
|
||||
|
||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
action(*pEntity, ref *pComp0,ref *pComp1,ref *pComp2,ref *pComp3,ref *pComp4,ref *pComp5,ref *pComp6);
|
||||
}
|
||||
}
|
||||
@@ -832,18 +951,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[8];
|
||||
var basePtrs = stackalloc byte*[8];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < 8; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -854,15 +975,20 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < 8; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
var pEntity = (Entity*)(chunk.GetUnsafePtr() + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pComp0 = (T0*)(basePtrs[0] + (sizeof(T0) * entityIndex));
|
||||
var pComp1 = (T1*)(basePtrs[1] + (sizeof(T1) * entityIndex));
|
||||
var pComp2 = (T2*)(basePtrs[2] + (sizeof(T2) * entityIndex));
|
||||
@@ -872,6 +998,7 @@ public unsafe partial struct EntityQuery
|
||||
var pComp6 = (T6*)(basePtrs[6] + (sizeof(T6) * entityIndex));
|
||||
var pComp7 = (T7*)(basePtrs[7] + (sizeof(T7) * entityIndex));
|
||||
|
||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
action(*pEntity, ref *pComp0,ref *pComp1,ref *pComp2,ref *pComp3,ref *pComp4,ref *pComp5,ref *pComp6,ref *pComp7);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,19 @@ namespace Ghost.Entities;
|
||||
|
||||
public unsafe partial struct EntityQuery
|
||||
{
|
||||
<# for (var f = 0; f < 2; f++)
|
||||
{
|
||||
var isForEachWithEntity = f != 0;
|
||||
#>
|
||||
<# for (var i = 1; i <= Amount; i++)
|
||||
{
|
||||
var generics = AppendGenerics(i);
|
||||
var compGenerics = AppendGenericRefParameters(i);
|
||||
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 2);
|
||||
|
||||
var delegateTupe = isForEachWithEntity ? "ForEachWithEntity" : "ForEach";
|
||||
#>
|
||||
public readonly void ForEach<<#= generics #>>(ForEach<<#= generics #>> action)
|
||||
public readonly void ForEach<<#= generics #>>(<#= delegateTupe #><<#= generics #>> action)
|
||||
<#= restrictions #>
|
||||
{
|
||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
||||
@@ -25,18 +31,20 @@ public unsafe partial struct EntityQuery
|
||||
var offsets = stackalloc int[<#= i #>];
|
||||
var basePtrs = stackalloc byte*[<#= i #>];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
for (var i = 0; i < _matchingArchetypes.Count; i++)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
ref var archetype = ref world.GetArchetypeReference(_matchingArchetypes[i]);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < <#= i #>; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||
if (layoutResult.Status != ResultStatus.Success)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets[index] = layoutResult.Value.offset;
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
@@ -47,81 +55,35 @@ public unsafe partial struct EntityQuery
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
var pChunkData = chunk.GetUnsafePtr();
|
||||
|
||||
for (var index = 0; index < <#= i #>; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
basePtrs[index] = pChunkData + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
|
||||
{
|
||||
if (!IsEntityValid(pChunkData, entityIndex, in archetype, in _mask))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
<# for (var localIndex = 0; localIndex < i; localIndex++) { #>
|
||||
var pComp<#= localIndex #> = (T<#= localIndex #>*)(basePtrs[<#= localIndex #>] + (sizeof(T<#= localIndex #>) * entityIndex));
|
||||
<# } #>
|
||||
|
||||
action(<#= AppendRefParameters(i, "*pComp{0}") #>);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<# } #>
|
||||
|
||||
<# for (var i = 1; i <= Amount; i++)
|
||||
{
|
||||
var generics = AppendGenerics(i);
|
||||
var compGenerics = AppendGenericRefParameters(i);
|
||||
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 2);
|
||||
#>
|
||||
public readonly void ForEach<<#= generics #>>(ForEachWithEntity<<#= generics #>> action)
|
||||
<#= restrictions #>
|
||||
{
|
||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
||||
|
||||
var compTypeIDs = stackalloc int[] { <#= AppendGenerics(i, "ComponentTypeID<T{0}>.value") #> };
|
||||
var offsets = stackalloc int[<#= i #>];
|
||||
var basePtrs = stackalloc byte*[<#= i #>];
|
||||
|
||||
foreach (var archetypeID in _matchingArchetypes)
|
||||
{
|
||||
ref var archetype = ref world.GetArchetypeReference(archetypeID);
|
||||
var hasAllComponents = true;
|
||||
for (var index = 0; index < <#= i #>; index++)
|
||||
{
|
||||
offsets[index] = archetype.GetOffset(compTypeIDs[index]);
|
||||
if (offsets[index] == -1)
|
||||
{
|
||||
hasAllComponents = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasAllComponents)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var chunkIndex = 0; chunkIndex < archetype.ChunkCount; chunkIndex++)
|
||||
{
|
||||
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||
var count = chunk.Count;
|
||||
for (var index = 0; index < <#= i #>; index++)
|
||||
{
|
||||
basePtrs[index] = chunk.GetUnsafePtr() + offsets[index];
|
||||
}
|
||||
|
||||
for (var entityIndex = 0; entityIndex < count; entityIndex++)
|
||||
{
|
||||
var pEntity = (Entity*)(chunk.GetUnsafePtr() + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
<# for (var localIndex = 0; localIndex < i; localIndex++) { #>
|
||||
var pComp<#= localIndex #> = (T<#= localIndex #>*)(basePtrs[<#= localIndex #>] + (sizeof(T<#= localIndex #>) * entityIndex));
|
||||
<# } #>
|
||||
|
||||
<# if (isForEachWithEntity) { #>
|
||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||
action(*pEntity, <#= AppendRefParameters(i, "*pComp{0}") #>);
|
||||
<# } else { #>
|
||||
action(<#= AppendRefParameters(i, "*pComp{0}") #>);
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<# } #>
|
||||
<# } #>
|
||||
}
|
||||
278
Ghost.Entities/Templates/QueryBuilder.With.gen.cs
Normal file
278
Ghost.Entities/Templates/QueryBuilder.With.gen.cs
Normal file
@@ -0,0 +1,278 @@
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ghost.Entities;
|
||||
|
||||
public ref partial struct QueryBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'All' filter of the query.
|
||||
/// Targets entities that have all of the specified component types and those component(s) must be enabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAll<T0>()
|
||||
where T0 : unmanaged, IComponent
|
||||
{
|
||||
_all.Add(ComponentTypeID<T0>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Any' filter of the query.
|
||||
/// Targets entities that have at least one of the specified component types and those component(s) must be enabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAny<T0>()
|
||||
where T0 : unmanaged, IComponent
|
||||
{
|
||||
_any.Add(ComponentTypeID<T0>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Absent' filter of the query.
|
||||
/// Targets entities that do not have any of the specified component types.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAbsent<T0>()
|
||||
where T0 : unmanaged, IComponent
|
||||
{
|
||||
_absent.Add(ComponentTypeID<T0>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'None' filter of the query.
|
||||
/// Targets entities that do not have any of the specified component types, or those component(s) are disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithNone<T0>()
|
||||
where T0 : unmanaged, IComponent
|
||||
{
|
||||
_none.Add(ComponentTypeID<T0>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Disabled' filter of the query.
|
||||
/// Targets entities that have all of the specified component types and those component(s) are disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithDisabled<T0>()
|
||||
where T0 : unmanaged, IEnableableComponent
|
||||
{
|
||||
_disabled.Add(ComponentTypeID<T0>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Present' filter of the query.
|
||||
/// Targets entities that have all of the specified component types, regardless of whether those component(s) are enabled or disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithPresent<T0>()
|
||||
where T0 : unmanaged, IComponent
|
||||
{
|
||||
_present.Add(ComponentTypeID<T0>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'All' filter of the query.
|
||||
/// Targets entities that have all of the specified component types and those component(s) must be enabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAll<T0, T1>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
{
|
||||
_all.Add(ComponentTypeID<T0>.value);
|
||||
_all.Add(ComponentTypeID<T1>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Any' filter of the query.
|
||||
/// Targets entities that have at least one of the specified component types and those component(s) must be enabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAny<T0, T1>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
{
|
||||
_any.Add(ComponentTypeID<T0>.value);
|
||||
_any.Add(ComponentTypeID<T1>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Absent' filter of the query.
|
||||
/// Targets entities that do not have any of the specified component types.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAbsent<T0, T1>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
{
|
||||
_absent.Add(ComponentTypeID<T0>.value);
|
||||
_absent.Add(ComponentTypeID<T1>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'None' filter of the query.
|
||||
/// Targets entities that do not have any of the specified component types, or those component(s) are disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithNone<T0, T1>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
{
|
||||
_none.Add(ComponentTypeID<T0>.value);
|
||||
_none.Add(ComponentTypeID<T1>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Disabled' filter of the query.
|
||||
/// Targets entities that have all of the specified component types and those component(s) are disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithDisabled<T0, T1>()
|
||||
where T0 : unmanaged, IEnableableComponent
|
||||
where T1 : unmanaged, IEnableableComponent
|
||||
{
|
||||
_disabled.Add(ComponentTypeID<T0>.value);
|
||||
_disabled.Add(ComponentTypeID<T1>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Present' filter of the query.
|
||||
/// Targets entities that have all of the specified component types, regardless of whether those component(s) are enabled or disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithPresent<T0, T1>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
{
|
||||
_present.Add(ComponentTypeID<T0>.value);
|
||||
_present.Add(ComponentTypeID<T1>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'All' filter of the query.
|
||||
/// Targets entities that have all of the specified component types and those component(s) must be enabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAll<T0, T1, T2>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
where T2 : unmanaged, IComponent
|
||||
{
|
||||
_all.Add(ComponentTypeID<T0>.value);
|
||||
_all.Add(ComponentTypeID<T1>.value);
|
||||
_all.Add(ComponentTypeID<T2>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Any' filter of the query.
|
||||
/// Targets entities that have at least one of the specified component types and those component(s) must be enabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAny<T0, T1, T2>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
where T2 : unmanaged, IComponent
|
||||
{
|
||||
_any.Add(ComponentTypeID<T0>.value);
|
||||
_any.Add(ComponentTypeID<T1>.value);
|
||||
_any.Add(ComponentTypeID<T2>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Absent' filter of the query.
|
||||
/// Targets entities that do not have any of the specified component types.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAbsent<T0, T1, T2>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
where T2 : unmanaged, IComponent
|
||||
{
|
||||
_absent.Add(ComponentTypeID<T0>.value);
|
||||
_absent.Add(ComponentTypeID<T1>.value);
|
||||
_absent.Add(ComponentTypeID<T2>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'None' filter of the query.
|
||||
/// Targets entities that do not have any of the specified component types, or those component(s) are disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithNone<T0, T1, T2>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
where T2 : unmanaged, IComponent
|
||||
{
|
||||
_none.Add(ComponentTypeID<T0>.value);
|
||||
_none.Add(ComponentTypeID<T1>.value);
|
||||
_none.Add(ComponentTypeID<T2>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Disabled' filter of the query.
|
||||
/// Targets entities that have all of the specified component types and those component(s) are disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithDisabled<T0, T1, T2>()
|
||||
where T0 : unmanaged, IEnableableComponent
|
||||
where T1 : unmanaged, IEnableableComponent
|
||||
where T2 : unmanaged, IEnableableComponent
|
||||
{
|
||||
_disabled.Add(ComponentTypeID<T0>.value);
|
||||
_disabled.Add(ComponentTypeID<T1>.value);
|
||||
_disabled.Add(ComponentTypeID<T2>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Present' filter of the query.
|
||||
/// Targets entities that have all of the specified component types, regardless of whether those component(s) are enabled or disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithPresent<T0, T1, T2>()
|
||||
where T0 : unmanaged, IComponent
|
||||
where T1 : unmanaged, IComponent
|
||||
where T2 : unmanaged, IComponent
|
||||
{
|
||||
_present.Add(ComponentTypeID<T0>.value);
|
||||
_present.Add(ComponentTypeID<T1>.value);
|
||||
_present.Add(ComponentTypeID<T2>.value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
110
Ghost.Entities/Templates/QueryBuilder.With.tt
Normal file
110
Ghost.Entities/Templates/QueryBuilder.With.tt
Normal file
@@ -0,0 +1,110 @@
|
||||
<#@ template language="C#" #>
|
||||
<#@ output extension="gen.cs" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ include file="Helpers.ttinclude" #>
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ghost.Entities;
|
||||
|
||||
public ref partial struct QueryBuilder
|
||||
{
|
||||
<# for (var i = 1; i <= 3; i++)
|
||||
{
|
||||
var generics = AppendGenerics(i);
|
||||
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 2);
|
||||
var enableRestrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IEnableableComponent", 2);
|
||||
#>
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'All' filter of the query.
|
||||
/// Targets entities that have all of the specified component types and those component(s) must be enabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAll<<#= generics #>>()
|
||||
<#= restrictions #>
|
||||
{
|
||||
<# for (var j = 0; j < i; j++) { #>
|
||||
_all.Add(ComponentTypeID<T<#= j #>>.value);
|
||||
<# } #>
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Any' filter of the query.
|
||||
/// Targets entities that have at least one of the specified component types and those component(s) must be enabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAny<<#= generics #>>()
|
||||
<#= restrictions #>
|
||||
{
|
||||
<# for (var j = 0; j < i; j++) { #>
|
||||
_any.Add(ComponentTypeID<T<#= j #>>.value);
|
||||
<# } #>
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Absent' filter of the query.
|
||||
/// Targets entities that do not have any of the specified component types.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithAbsent<<#= generics #>>()
|
||||
<#= restrictions #>
|
||||
{
|
||||
<# for (var j = 0; j < i; j++) { #>
|
||||
_absent.Add(ComponentTypeID<T<#= j #>>.value);
|
||||
<# } #>
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'None' filter of the query.
|
||||
/// Targets entities that do not have any of the specified component types, or those component(s) are disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithNone<<#= generics #>>()
|
||||
<#= restrictions #>
|
||||
{
|
||||
<# for (var j = 0; j < i; j++) { #>
|
||||
_none.Add(ComponentTypeID<T<#= j #>>.value);
|
||||
<# } #>
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Disabled' filter of the query.
|
||||
/// Targets entities that have all of the specified component types and those component(s) are disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithDisabled<<#= generics #>>()
|
||||
<#= enableRestrictions #>
|
||||
{
|
||||
<# for (var j = 0; j < i; j++) { #>
|
||||
_disabled.Add(ComponentTypeID<T<#= j #>>.value);
|
||||
<# } #>
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified component type(s) to the 'Present' filter of the query.
|
||||
/// Targets entities that have all of the specified component types, regardless of whether those component(s) are enabled or disabled.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public QueryBuilder WithPresent<<#= generics #>>()
|
||||
<#= restrictions #>
|
||||
{
|
||||
<# for (var j = 0; j < i; j++) { #>
|
||||
_present.Add(ComponentTypeID<T<#= j #>>.value);
|
||||
<# } #>
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
<# } #>
|
||||
}
|
||||
Reference in New Issue
Block a user