Improve the usability of Result<T, E> and add new job schedule method to EntityQuery.

Added implicate conversion to Result<T, E> and RefResult<T, E>;
Added new ScheduleChunkParallel in EntityQuery;
Remove Ghost.SparseEntity from solution file. It's now completlty replaced by Ghost.Entities;
This commit is contained in:
2025-12-09 21:43:12 +09:00
parent 97d1118caa
commit 99c1a1980e
29 changed files with 646 additions and 553 deletions

View File

@@ -263,12 +263,12 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ResultStatus SetComponentData(int chunkIndex, int rowIndex, Identifier<IComponent> componentID, void* pComponent)
public readonly ErrorStatus SetComponentData(int chunkIndex, int rowIndex, Identifier<IComponent> componentID, void* pComponent)
{
var r = GetLayout(componentID);
if (r.Status != ResultStatus.Success)
if (r.Error != ErrorStatus.None)
{
return r.Status;
return r.Error;
}
var offset = r.Value.offset;
@@ -280,14 +280,14 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
MemoryUtility.MemCpy(dst, pComponent, (nuint)size);
return ResultStatus.Success;
return ErrorStatus.None;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void* GetComponentData(int chunkIndex, int rowIndex, Identifier<IComponent> componentID)
{
var r = GetLayout(componentID);
if (r.Status != ResultStatus.Success)
if (r.Error != ErrorStatus.None)
{
return null;
}
@@ -307,27 +307,27 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly Result<ComponentMemoryLayout, ResultStatus> GetLayout(int componentID)
public readonly Result<ComponentMemoryLayout, ErrorStatus> GetLayout(int componentID)
{
if (componentID >= _componentIDToLayoutIndex.Count)
{
return Result.Create(default(ComponentMemoryLayout), ResultStatus.InvalidArgument);
return ErrorStatus.InvalidArgument;
}
var layoutIndex = _componentIDToLayoutIndex[componentID];
if (layoutIndex == -1)
{
return Result.Create(default(ComponentMemoryLayout), ResultStatus.NotFound);
return ErrorStatus.NotFound;
}
return Result.Create(_layouts[layoutIndex], ResultStatus.Success);
return _layouts[layoutIndex];
}
public ResultStatus RemoveEntity(int chunkIndex, int rowIndex)
public ErrorStatus RemoveEntity(int chunkIndex, int rowIndex)
{
if (chunkIndex < 0 || chunkIndex >= _chunks.Count)
{
return ResultStatus.InvalidArgument;
return ErrorStatus.InvalidArgument;
}
ref var chunk = ref _chunks[chunkIndex];
@@ -341,13 +341,13 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
var pRowEntity = chunkBase + _entityIdsOffset + (sizeof(Entity) * rowIndex);
var wroldResult = World.GetWorld(_worldID);
if (wroldResult.Status != ResultStatus.Success)
if (wroldResult.Error != ErrorStatus.None)
{
return wroldResult.Status;
return wroldResult.Error;
}
var result = wroldResult.Value.EntityManager.UpdateEntityLocation(*(Entity*)pLastEntity, _id, chunkIndex, rowIndex);
if (result != ResultStatus.Success)
if (result != ErrorStatus.None)
{
return result;
}
@@ -367,7 +367,7 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
}
chunk.Count--;
return ResultStatus.Success;
return ErrorStatus.None;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View File

@@ -102,14 +102,16 @@ public unsafe class EntityCommandBuffer : IDisposable
return bufferPtr;
}
public void CreateEntity()
public void CreateEntity(int count = 1)
{
WriteHeader(ECBOpCode.CreateEntity);
Write(count);
}
public void CreateEntity(params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
public void CreateEntity(int count, params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
{
WriteHeader(ECBOpCode.CreateEntityWithComponents);
Write(count);
Write(componentTypeIDs.Length);
WriteSpan(componentTypeIDs);
}
@@ -150,23 +152,23 @@ public unsafe class EntityCommandBuffer : IDisposable
{
var cursor = 0;
var length = _buffer.Count;
var ptr = (byte*)_buffer.GetUnsafePtr();
while (cursor < length)
{
var op = *(ECBOpCode*)ptr[cursor];
cursor += sizeof(ECBOpCode);
var op = Read<ECBOpCode>(ref cursor);
switch (op)
{
case ECBOpCode.CreateEntity:
_entityManager.CreateEntity();
var count = Read<int>(ref cursor);
_entityManager.CreateEntities(count);
break;
case ECBOpCode.CreateEntityWithComponents:
var entityCount = Read<int>(ref cursor);
var compCount = Read<int>(ref cursor);
var compTypeIDs = ReadSpan<Identifier<IComponent>>(ref cursor, compCount);
_entityManager.CreateEntity(compTypeIDs);
_entityManager.CreateEntities(entityCount, compTypeIDs);
break;
case ECBOpCode.DestroyEntity:

View File

@@ -6,6 +6,14 @@ using System.Diagnostics;
namespace Ghost.Entities;
/// <summary>
/// A manager for creating, destroying, and managing entities and their components.
/// </summary>
/// <remarks>
/// All methods in this class are not thread-safe and all of them will cause structural changes if not mentioned otherwise.
/// Use <see cref="EntityCommandBuffer"/> to defer structural changes to a safe point.
/// Use <see cref="World.GetThreadLocalEntityCommandBuffer(int)"/> to get a thread-local command buffer for multithreaded scenarios.
/// </remarks>
public unsafe partial class EntityManager : IDisposable
{
private struct EntityLocation
@@ -30,19 +38,19 @@ public unsafe partial class EntityManager : IDisposable
Dispose();
}
internal ResultStatus UpdateEntityLocation(Entity entity, Identifier<Archetype> newArchetypeID, int newChunkIndex, int newRowIndex)
internal ErrorStatus UpdateEntityLocation(Entity entity, Identifier<Archetype> newArchetypeID, int newChunkIndex, int newRowIndex)
{
ref var location = ref _entityLocations.GetElementReferenceAt(entity.ID, entity.Generation, out var exist);
if (!exist)
{
return ResultStatus.NotFound;
return ErrorStatus.NotFound;
}
location.archetypeID = newArchetypeID;
location.chunkIndex = newChunkIndex;
location.rowIndex = newRowIndex;
return ResultStatus.Success;
return ErrorStatus.None;
}
/// <summary>
@@ -51,21 +59,10 @@ public unsafe partial class EntityManager : IDisposable
/// <returns>The created entity.</returns>
public Entity CreateEntity()
{
// Put into empty archetype
ref var emptyArchetype = ref _world.GetArchetypeReference(World.EmptyArchetypeID);
emptyArchetype.AllocateEntity(out var chunkIndex, out var rowIndex);
var entities = (Span<Entity>)stackalloc Entity[1];
CreateEntities(1, entities);
var id = _entityLocations.Add(new EntityLocation
{
archetypeID = World.EmptyArchetypeID,
chunkIndex = chunkIndex,
rowIndex = rowIndex
}, out var generation);
var entity = new Entity(id, generation);
emptyArchetype.SetEntity(chunkIndex, rowIndex, entity);
return entity;
return entities[0];
}
/// <summary>
@@ -75,28 +72,59 @@ public unsafe partial class EntityManager : IDisposable
/// <returns>The created entity.</returns>
public Entity CreateEntity(params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
{
var signatureHash = ComponentRegister.GetHashCode(componentTypeIDs);
var arcID = _world.GetArchetypeIDBySignatureHash(signatureHash);
var entities = (Span<Entity>)stackalloc Entity[1];
CreateEntities(1, entities, componentTypeIDs);
if (arcID.IsNotValid)
return entities[0];
}
/// <summary>
/// Create multiple entities with no components.
/// </summary>
/// <param name="count">The number of entities to create.</param>
/// <param name="entities">The span to store the created entities.</param>
public void CreateEntities(int count, Span<Entity> entities)
{
ref var emptyArchetype = ref _world.GetArchetypeReference(World.EmptyArchetypeID);
emptyArchetype.AllocateEntity(out var chunkIndex, out var rowIndex);
for (var i = 0; i < count; i++)
{
arcID = _world.CreateArchetype(componentTypeIDs, signatureHash);
var id = _entityLocations.Add(new EntityLocation
{
archetypeID = World.EmptyArchetypeID,
chunkIndex = chunkIndex,
rowIndex = rowIndex
}, out var generation);
var entity = new Entity(id, generation);
emptyArchetype.SetEntity(chunkIndex, rowIndex, entity);
entities[i] = entity;
}
}
ref var archetype = ref _world.GetArchetypeReference(arcID);
archetype.AllocateEntity(out var chunkIndex, out var rowIndex);
/// <summary>
/// Create multiple entities with no components.
/// </summary>
/// <param name="count">The number of entities to create.</param>
public void CreateEntities(int count)
{
ref var emptyArchetype = ref _world.GetArchetypeReference(World.EmptyArchetypeID);
emptyArchetype.AllocateEntity(out var chunkIndex, out var rowIndex);
var id = _entityLocations.Add(new EntityLocation
for (var i = 0; i < count; i++)
{
archetypeID = arcID,
chunkIndex = chunkIndex,
rowIndex = rowIndex
}, out var generation);
var id = _entityLocations.Add(new EntityLocation
{
archetypeID = World.EmptyArchetypeID,
chunkIndex = chunkIndex,
rowIndex = rowIndex
}, out var generation);
var entity = new Entity(id, generation);
archetype.SetEntity(chunkIndex, rowIndex, entity);
return entity;
var entity = new Entity(id, generation);
emptyArchetype.SetEntity(chunkIndex, rowIndex, entity);
}
}
/// <summary>
@@ -106,7 +134,7 @@ public unsafe partial class EntityManager : IDisposable
/// <param name="allocator">The allocator to use for the returned array.</param>
/// <param name="componentTypeIDs">The component type IDs to add to the entities. </param>
/// <returns>An array of the created entities.</returns>
public UnsafeArray<Entity> CreateEntities(int count, Allocator allocator, params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
public void CreateEntities(int count, Span<Entity> entities, params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
{
var signatureHash = ComponentRegister.GetHashCode(componentTypeIDs);
var arcID = _world.GetArchetypeIDBySignatureHash(signatureHash);
@@ -118,7 +146,6 @@ public unsafe partial class EntityManager : IDisposable
ref var archetype = ref _world.GetArchetypeReference(arcID);
var entities = new UnsafeArray<Entity>(count, allocator);
for (var i = 0; i < count; i++)
{
archetype.AllocateEntity(out var chunkIndex, out var rowIndex);
@@ -135,8 +162,6 @@ public unsafe partial class EntityManager : IDisposable
entities[i] = entity;
}
return entities;
}
/// <summary>
@@ -176,26 +201,26 @@ public unsafe partial class EntityManager : IDisposable
/// Destroy the specified entity.
/// </summary>
/// <returns>The result status of the operation.</returns>
public ResultStatus DestroyEntity(Entity entity)
public ErrorStatus DestroyEntity(Entity entity)
{
if (!_entityLocations.TryGetElementAt(entity.ID, entity.Generation, out var location))
{
return ResultStatus.NotFound;
return ErrorStatus.NotFound;
}
ref var archetype = ref _world.GetArchetypeReference(location.archetypeID);
var r = archetype.RemoveEntity(location.chunkIndex, location.rowIndex);
if (r != ResultStatus.Success)
if (r != ErrorStatus.None)
{
return r;
}
if (!_entityLocations.Remove(entity.ID, entity.Generation))
{
return ResultStatus.NotFound;
return ErrorStatus.NotFound;
}
return ResultStatus.Success;
return ErrorStatus.None;
}
/// <summary>
@@ -214,11 +239,11 @@ public unsafe partial class EntityManager : IDisposable
/// <param name="componentID">The component type ID of the singleton.</param>
/// <param name="pComponent">Pointer to the component data.</param>
/// <returns>The result status of the operation.</returns>
public ResultStatus CreateSingleton(Identifier<IComponent> componentID, void* pComponent)
public ErrorStatus CreateSingleton(Identifier<IComponent> componentID, void* pComponent)
{
if (pComponent == null)
{
return ResultStatus.InvalidArgument;
return ErrorStatus.InvalidArgument;
}
// Check if singleton already exists
@@ -227,7 +252,7 @@ public unsafe partial class EntityManager : IDisposable
if (arcID.IsValid)
{
return ResultStatus.InvalidArgument;
return ErrorStatus.InvalidArgument;
}
arcID = _world.CreateArchetype([componentID], signatureHash);
@@ -246,7 +271,7 @@ public unsafe partial class EntityManager : IDisposable
archetype.SetEntity(chunkIndex, rowIndex, entity);
archetype.SetComponentData(chunkIndex, rowIndex, componentID, pComponent);
return ResultStatus.Success;
return ErrorStatus.None;
}
/// <summary>
@@ -255,7 +280,7 @@ public unsafe partial class EntityManager : IDisposable
/// <typeparam name="T">The component type.</typeparam>
/// <param name="component">The component data.</param>
/// <returns>The result status of the operation.</returns>
public ResultStatus CreateSingleton<T>(T component = default)
public ErrorStatus CreateSingleton<T>(T component = default)
where T : unmanaged, IComponent
{
return CreateSingleton(ComponentTypeID<T>.value, &component);
@@ -278,7 +303,7 @@ public unsafe partial class EntityManager : IDisposable
ref var archetype = ref _world.GetArchetypeReference(arcID);
var layoutResult = archetype.GetLayout(componentID);
if (layoutResult.Status != ResultStatus.Success)
if (layoutResult.Error != ErrorStatus.None)
{
return null;
}
@@ -311,8 +336,8 @@ public unsafe partial class EntityManager : IDisposable
var src = oldArch._chunks[oldChunk].GetUnsafePtr() + layout.offset + (layout.size * oldRow);
var r = newArch.GetLayout(layout.componentID);
Debug.Assert(r.Status == ResultStatus.Success); // This should always be true if the system is consistent.
if (r.Status != ResultStatus.Success)
Debug.Assert(r.Error == ErrorStatus.None); // This should always be true if the system is consistent.
if (r.Error != ErrorStatus.None)
{
continue;
}
@@ -330,13 +355,13 @@ public unsafe partial class EntityManager : IDisposable
/// <param name="componentID">The component type ID to add.</param>
/// <param name="pComponent">Pointer to the component data.</param>
/// <returns>The result status of the operation.</returns>
public ResultStatus AddComponent(Entity entity, Identifier<IComponent> componentID, void* pComponent)
public ErrorStatus AddComponent(Entity entity, Identifier<IComponent> componentID, void* pComponent)
{
// Find current location
ref var location = ref _entityLocations.GetElementReferenceAt(entity.ID, entity.Generation, out var exist);
if (!exist)
{
return ResultStatus.NotFound;
return ErrorStatus.NotFound;
}
// Build new archetype signature
@@ -397,8 +422,8 @@ public unsafe partial class EntityManager : IDisposable
newArchetype.SetComponentData(newChunkIndex, newRowIndex, componentID, pComponent);
var r = oldArchetype.RemoveEntity(location.chunkIndex, location.rowIndex);
Debug.Assert(r == ResultStatus.Success); // We assert it because the entity should exist if the whole system is consistent.
if (r != ResultStatus.Success)
Debug.Assert(r == ErrorStatus.None); // We assert it because the entity should exist if the whole system is consistent.
if (r != ErrorStatus.None)
{
return r;
}
@@ -408,7 +433,7 @@ public unsafe partial class EntityManager : IDisposable
location.chunkIndex = newChunkIndex;
location.rowIndex = newRowIndex;
return ResultStatus.Success;
return ErrorStatus.None;
}
/// <summary>
@@ -418,7 +443,7 @@ public unsafe partial class EntityManager : IDisposable
/// <param name="entity">The entity to add the component to.</param>
/// <param name="component">The component data.</param>
/// <returns>The result status of the operation.</returns>
public ResultStatus AddComponent<T>(Entity entity, T component = default)
public ErrorStatus AddComponent<T>(Entity entity, T component = default)
where T : unmanaged, IComponent
{
return AddComponent(entity, ComponentTypeID<T>.value, &component);
@@ -430,13 +455,13 @@ public unsafe partial class EntityManager : IDisposable
/// <param name="entity">The entity to remove the component from.</param>
/// <param name="componentID">The component type ID to remove.</param>
/// <returns>The result status of the operation.</returns>
public ResultStatus RemoveComponent(Entity entity, Identifier<IComponent> componentID)
public ErrorStatus RemoveComponent(Entity entity, Identifier<IComponent> componentID)
{
// Find current location
ref var location = ref _entityLocations.GetElementReferenceAt(entity.ID, entity.Generation, out var exist);
if (!exist)
{
return ResultStatus.NotFound;
return ErrorStatus.NotFound;
}
// Build new archetype signature
@@ -492,8 +517,8 @@ public unsafe partial class EntityManager : IDisposable
newArchetype.SetEntity(newChunkIndex, newRowIndex, entity);
var r = oldArchetype.RemoveEntity(location.chunkIndex, location.rowIndex);
Debug.Assert(r == ResultStatus.Success); // We assert it because the entity should exist if the whole system is consistent.
if (r != ResultStatus.Success)
Debug.Assert(r == ErrorStatus.None); // We assert it because the entity should exist if the whole system is consistent.
if (r != ErrorStatus.None)
{
return r;
}
@@ -503,7 +528,7 @@ public unsafe partial class EntityManager : IDisposable
location.chunkIndex = newChunkIndex;
location.rowIndex = newRowIndex;
return ResultStatus.Success;
return ErrorStatus.None;
}
/// <summary>
@@ -512,7 +537,7 @@ public unsafe partial class EntityManager : IDisposable
/// <typeparam name="T">The component type.</typeparam>
/// <param name="entity">The entity to remove the component from.</param>
/// <returns>The result status of the operation.</returns>
public ResultStatus RemoveComponent<T>(Entity entity)
public ErrorStatus RemoveComponent<T>(Entity entity)
where T : unmanaged, IComponent
{
return RemoveComponent(entity, ComponentTypeID<T>.value);
@@ -525,17 +550,17 @@ public unsafe partial class EntityManager : IDisposable
/// <param name="componentID">The component type ID to set.</param>
/// <param name="pComponent">Pointer to the component data.</param>
/// <returns>The result status of the operation.</returns>
public ResultStatus SetComponent(Entity entity, Identifier<IComponent> componentID, void* pComponent)
public ErrorStatus SetComponent(Entity entity, Identifier<IComponent> componentID, void* pComponent)
{
if (!_entityLocations.TryGetElementAt(entity.ID, entity.Generation, out var location))
{
return ResultStatus.NotFound;
return ErrorStatus.NotFound;
}
ref var archetype = ref _world.GetArchetypeReference(location.archetypeID);
archetype.SetComponentData(location.chunkIndex, location.rowIndex, componentID, pComponent);
return ResultStatus.Success;
return ErrorStatus.None;
}
/// <summary>
@@ -544,7 +569,7 @@ public unsafe partial class EntityManager : IDisposable
/// <typeparam name="T">The component type.</typeparam>
/// <param name="entity">The entity to set the component data for.</param>
/// <param name="component">The component data.</param>
public ResultStatus SetComponent<T>(Entity entity, T component)
public ErrorStatus SetComponent<T>(Entity entity, T component)
where T : unmanaged, IComponent
{
return SetComponent(entity, ComponentTypeID<T>.value, &component);
@@ -616,11 +641,11 @@ public unsafe partial class EntityManager : IDisposable
/// <param name="componentID">The component type ID of the enableable component.</
/// <param name="enabled">True to enable the component, false to disable it.</param>
/// <returns>The result status of the operation.</returns>
public ResultStatus SetEnabled(Entity entity, Identifier<IComponent> componentID, bool enabled)
public ErrorStatus SetEnabled(Entity entity, Identifier<IComponent> componentID, bool enabled)
{
if (!_entityLocations.TryGetElementAt(entity.ID, entity.Generation, out var location))
{
return ResultStatus.NotFound;
return ErrorStatus.NotFound;
}
ref var archetype = ref _world.GetArchetypeReference(location.archetypeID);
@@ -628,9 +653,9 @@ public unsafe partial class EntityManager : IDisposable
var rowIndex = location.rowIndex;
var layoutResult = archetype.GetLayout(componentID);
if (layoutResult.Status != ResultStatus.Success)
if (layoutResult.Error != ErrorStatus.None)
{
return layoutResult.Status;
return layoutResult.Error;
}
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
@@ -649,7 +674,7 @@ public unsafe partial class EntityManager : IDisposable
maskBase[byteIndex] &= (byte)~(1 << bitIndex);
}
return ResultStatus.Success;
return ErrorStatus.None;
}
/// <summary>
@@ -659,7 +684,7 @@ public unsafe partial class EntityManager : IDisposable
/// <param name="entity">The entity to set the enabled state for.</param>
/// <param name="enabled">True to enable the component, false to disable it.</
/// <returns>The result status of the operation.</returns>
public ResultStatus SetEnabled<T>(Entity entity, bool enabled)
public ErrorStatus SetEnabled<T>(Entity entity, bool enabled)
where T : unmanaged, IEnableableComponent
{
return SetEnabled(entity, ComponentTypeID<T>.value, enabled);

View File

@@ -0,0 +1,87 @@
using Ghost.Core;
using Misaki.HighPerformance.Jobs;
using Misaki.HighPerformance.LowLevel.Collections;
using System.Runtime.CompilerServices;
namespace Ghost.Entities;
public interface IJobChunk
{
void Execute(ChunkView view, int threadIndex);
}
internal unsafe struct ChunkInfo
{
public Chunk* pChunk;
public Archetype* pArchetype;
}
internal unsafe struct JobChunkBatch<TJob> : IJobParallelFor
where TJob : unmanaged, IJobChunk
{
public TJob userJob;
public ReadOnlyUnsafeCollection<ChunkInfo> chunkInfos;
public void Execute(int loopIndex, int threadIndex)
{
var info = chunkInfos[loopIndex];
var view = new ChunkView(in *info.pArchetype, in *info.pChunk);
userJob.Execute(view, threadIndex);
}
}
internal struct DisposeJobChunk : IJob
{
public UnsafeList<ChunkInfo> list;
public void Execute(int threadIndex)
{
list.Dispose();
}
}
public unsafe partial struct EntityQuery
{
public JobHandle ScheduleChunkParallel<TJob>(TJob job, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobChunk
{
var world = World.GetWorld(_worldID).GetValueOrThrow();
var chunkInfos = new UnsafeList<ChunkInfo>(_matchingArchetypes.Count * 2, JobScheduler.TempAllocatorHandle);
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref world.GetArchetypeReference(archID);
for (int i = 0; i < arch.ChunkCount; i++)
{
var pChunk = (Chunk*)arch._chunks.GetUnsafePtr() + i;
chunkInfos.Add(new ChunkInfo
{
pArchetype = (Archetype*)Unsafe.AsPointer(ref arch),
pChunk = pChunk
});
}
}
var batchJob = new JobChunkBatch<TJob>
{
userJob = job,
chunkInfos = chunkInfos.AsReadOnly()
};
var handle = world.JobScheduler.ScheduleParallel(ref batchJob, chunkInfos.Count, batchSize, dependency);
var disposeJob = new DisposeJobChunk
{
list = chunkInfos
};
world.JobScheduler.Schedule(ref disposeJob, handle);
return handle;
}
}

View File

@@ -74,91 +74,102 @@ public struct EntityQueryMask : IDisposable, IEquatable<EntityQueryMask>
}
}
public unsafe partial struct EntityQuery : IIdentifierType, IDisposable
/// <summary>
/// Provides a read-only view over a chunk of entities and their component data within an archetype.
/// </summary>
/// <remarks>This does not filter disabled/enabled components. You must handle that manually.</remarks>
public readonly unsafe ref struct ChunkView
{
/// <summary>
/// Provides a read-only view over a chunk of entities and their component data within an archetype.
/// </summary>
/// <remarks>This does not filter disabled/enabled components. You must handle that manually.</remarks>
public readonly ref struct ChunkView
private readonly ReadOnlyUnsafeCollection<Archetype.ComponentMemoryLayout> _layouts;
private readonly byte* _pChunkData;
private readonly int _entityOffset;
private readonly int _entityCount;
public readonly int Count => _entityCount;
internal ChunkView(ReadOnlyUnsafeCollection<Archetype.ComponentMemoryLayout> layouts, byte* pChunkData, int entityOffset, int entityCount)
{
private readonly ref Archetype _archetype;
private readonly ref Chunk _chunk;
public readonly int Count => _chunk.Count;
internal ChunkView(ref Archetype archetype, int chunkIndex)
{
_archetype = ref archetype;
_chunk = ref archetype.GetChunkReference(chunkIndex);
}
/// <summary>
/// Returns a read-only span containing structuralAll entities stored in the current chunk.
/// </summary>
/// <returns>A read-only span of <see cref="Entity"/> values representing the entities in the chunk.</returns>
public readonly ReadOnlySpan<Entity> GetEntities()
{
var ptr = _chunk.GetUnsafePtr();
var pEntity = (Entity*)(ptr + _archetype.EntityIDsOffset);
return new ReadOnlySpan<Entity>(pEntity, _chunk.Count);
}
/// <summary>
/// Gets a span providing direct access to the component data of type T0 for structuralAll entities in the chunk.
/// </summary>
/// <typeparam name="T">The type of component to access. Must be an unmanaged type that implements <see cref="Component"/>.</typeparam>
/// <returns>A span of type <see cref="{T}"/> containing the component data for each entity in the chunk.</returns>
/// <exception cref="InvalidOperationException">Thrown if the specified component type is not present in the archetype.</exception>
public readonly Span<T> GetComponentData<T>()
where T : unmanaged, IComponent
{
var layout = _archetype.GetLayout(ComponentTypeID<T>.value).GetValueOrThrow(ResultStatus.Success);
var ptr = _chunk.GetUnsafePtr() + layout.offset;
return new Span<T>(ptr, _chunk.Count);
}
/// <summary>
/// Gets a bit set representing the enabled state of each instance of the specified enableable component
/// type within the current chunk.
/// </summary>
/// <typeparam name="T">The component type for which to retrieve enablement bits. Must be unmanaged and implement <see cref="IEnableableComponent"/>.</typeparam>
/// <returns>A <see cref="SpanBitSet"/> that provides access to the enablement bits for all instances of the specified component type in the chunk.</returns>
/// <exception cref="InvalidOperationException">Thrown if the specified component type does not support enablement.</exception>
public SpanBitSet GetEnableBits<T>()
where T : unmanaged, IEnableableComponent
{
var layout = _archetype.GetLayout(ComponentTypeID<T>.value).GetValueOrThrow(ResultStatus.Success);
if (layout.enableBitsOffset == -1)
{
throw new InvalidOperationException($"Component {typeof(T).FullName} is not enableable.");
}
var maskBase = _chunk.GetUnsafePtr() + layout.enableBitsOffset;
return new SpanBitSet(new Span<uint>(maskBase, (_chunk.Count + 31) / 32));
}
/// <summary>
/// Determines whether the specified component of type <typeparamref name="T"/> at the given index is currently enabled.
/// </summary>
/// <typeparam name="T">The type of the component to check. Must be an unmanaged type that implements <see cref="IEnableableComponent"/>.</typeparam>
/// <param name="index">The zero-based index of the component instance to check within the chunk.</param>
/// <returns>true if the component at the specified index is enabled; otherwise, false.</returns>
/// <exception cref="InvalidOperationException">Thrown if the specified component type <typeparamref name="T"/> does not support enable/disable functionality.</exception>
public readonly bool IsComponentEnabled<T>(int index)
where T : unmanaged, IEnableableComponent
{
var layout = _archetype.GetLayout(ComponentTypeID<T>.value).GetValueOrThrow(ResultStatus.Success);
if (layout.enableBitsOffset == -1)
{
throw new InvalidOperationException($"Component {typeof(T).FullName} is not enableable.");
}
var maskBase = _chunk.GetUnsafePtr() + layout.enableBitsOffset;
return CheckBit(maskBase, index);
}
_layouts = layouts;
_pChunkData = pChunkData;
_entityOffset = entityOffset;
_entityCount = entityCount;
}
internal ChunkView(ref readonly Archetype archetype, ref readonly Chunk chunk)
{
_layouts = archetype._layouts.AsReadOnly();
_pChunkData = chunk.GetUnsafePtr();
_entityOffset = archetype.EntityIDsOffset;
_entityCount = chunk.Count;
}
/// <summary>
/// Returns a read-only span containing structuralAll entities stored in the current chunk.
/// </summary>
/// <returns>A read-only span of <see cref="Entity"/> values representing the entities in the chunk.</returns>
public readonly ReadOnlySpan<Entity> GetEntities()
{
var pEntity = (Entity*)(_pChunkData + _entityOffset);
return new ReadOnlySpan<Entity>(pEntity, _entityCount);
}
/// <summary>
/// Gets a span providing direct access to the component data of type T0 for structuralAll entities in the chunk.
/// </summary>
/// <typeparam name="T">The type of component to access. Must be an unmanaged type that implements <see cref="Component"/>.</typeparam>
/// <returns>A span of type <see cref="{T}"/> containing the component data for each entity in the chunk.</returns>
/// <exception cref="InvalidOperationException">Thrown if the specified component type is not present in the archetype.</exception>
public readonly Span<T> GetComponentData<T>()
where T : unmanaged, IComponent
{
var layout = _layouts[ComponentTypeID<T>.value];
var pComponentData = _pChunkData + layout.offset;
return new Span<T>(pComponentData, _entityCount);
}
/// <summary>
/// Gets a bit set representing the enabled state of each instance of the specified enableable component
/// type within the current chunk.
/// </summary>
/// <typeparam name="T">The component type for which to retrieve enablement bits. Must be unmanaged and implement <see cref="IEnableableComponent"/>.</typeparam>
/// <returns>A <see cref="SpanBitSet"/> that provides access to the enablement bits for all instances of the specified component type in the chunk.</returns>
/// <exception cref="InvalidOperationException">Thrown if the specified component type does not support enablement.</exception>
public readonly SpanBitSet GetEnableBits<T>()
where T : unmanaged, IEnableableComponent
{
var layout = _layouts[ComponentTypeID<T>.value];
if (layout.enableBitsOffset == -1)
{
throw new InvalidOperationException($"Component {typeof(T).FullName} is not enableable.");
}
var maskBase = _pChunkData + layout.enableBitsOffset;
return new SpanBitSet(new Span<uint>(maskBase, (_entityCount + 31) / 32));
}
/// <summary>
/// Determines whether the specified component of type <typeparamref name="T"/> at the given index is currently enabled.
/// </summary>
/// <typeparam name="T">The type of the component to check. Must be an unmanaged type that implements <see cref="IEnableableComponent"/>.</typeparam>
/// <param name="index">The zero-based index of the component instance to check within the chunk.</param>
/// <returns>true if the component at the specified index is enabled; otherwise, false.</returns>
/// <exception cref="InvalidOperationException">Thrown if the specified component type <typeparamref name="T"/> does not support enable/disable functionality.</exception>
public readonly bool IsComponentEnabled<T>(int index)
where T : unmanaged, IEnableableComponent
{
var layout = _layouts[ComponentTypeID<T>.value];
if (layout.enableBitsOffset == -1)
{
throw new InvalidOperationException($"Component {typeof(T).FullName} is not enableable.");
}
var pMask = _pChunkData + layout.enableBitsOffset;
return EntityQuery.CheckBit(pMask, index);
}
}
public unsafe partial struct EntityQuery : IIdentifierType, IDisposable
{
/// <summary>
/// Provides an enumerator for iterating over chunks of entities and their component data that match a set of archetypes within a world.
/// </summary>
@@ -182,7 +193,8 @@ public unsafe partial struct EntityQuery : IIdentifierType, IDisposable
get
{
ref var archetype = ref _iterator._world.GetArchetypeReference(_iterator._matchingArchetypes[_archetypeIndex]);
return new ChunkView(ref archetype, _chunkIndex);
ref var chunk = ref archetype.GetChunkReference(_chunkIndex);
return new ChunkView(in archetype, in chunk);
}
}
@@ -250,7 +262,7 @@ public unsafe partial struct EntityQuery : IIdentifierType, IDisposable
{
// Get the EnableBitmask for this component in this chunk
var layoutResult = archetype.GetLayout(id);
if (layoutResult.Status != ResultStatus.Success
if (layoutResult.Error != ErrorStatus.None
// Not enableable, always true
|| layoutResult.Value.enableBitsOffset == -1)
{
@@ -269,7 +281,7 @@ public unsafe partial struct EntityQuery : IIdentifierType, IDisposable
while (it.Next(out var id))
{
var layoutResult = archetype.GetLayout(id);
if (layoutResult.Status != ResultStatus.Success)
if (layoutResult.Error != ErrorStatus.None)
{
continue;
}
@@ -290,7 +302,7 @@ public unsafe partial struct EntityQuery : IIdentifierType, IDisposable
while (it.Next(out var id))
{
var layoutResult = archetype.GetLayout(id);
if (layoutResult.Status != ResultStatus.Success)
if (layoutResult.Error != ErrorStatus.None)
{
continue;
}

View File

@@ -54,7 +54,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 1; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -124,7 +124,6 @@ public unsafe partial struct EntityQuery
}
}
}
}
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
@@ -147,10 +146,9 @@ public unsafe partial struct EntityQuery
public readonly ComponentIterator<T0> GetComponentIterator<T0>()
where T0 : unmanaged, IComponent
{
return new ComponentIterator<T0>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new ComponentIterator<T0>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct ComponentIterator<T0, T1>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -223,7 +221,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 2; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -293,7 +291,6 @@ public unsafe partial struct EntityQuery
}
}
}
}
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
@@ -317,10 +314,9 @@ public unsafe partial struct EntityQuery
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
{
return new ComponentIterator<T0, T1>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new ComponentIterator<T0, T1>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct ComponentIterator<T0, T1, T2>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -402,7 +398,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 3; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -472,7 +468,6 @@ public unsafe partial struct EntityQuery
}
}
}
}
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
@@ -497,10 +492,9 @@ public unsafe partial struct EntityQuery
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
{
return new ComponentIterator<T0, T1, T2>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new ComponentIterator<T0, T1, T2>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct ComponentIterator<T0, T1, T2, T3>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -591,7 +585,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 4; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -661,7 +655,6 @@ public unsafe partial struct EntityQuery
}
}
}
}
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
@@ -687,10 +680,9 @@ public unsafe partial struct EntityQuery
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
{
return new ComponentIterator<T0, T1, T2, T3>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new ComponentIterator<T0, T1, T2, T3>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct ComponentIterator<T0, T1, T2, T3, T4>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -790,7 +782,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 5; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -860,7 +852,6 @@ public unsafe partial struct EntityQuery
}
}
}
}
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
@@ -887,10 +878,9 @@ public unsafe partial struct EntityQuery
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
{
return new ComponentIterator<T0, T1, T2, T3, T4>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new ComponentIterator<T0, T1, T2, T3, T4>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct ComponentIterator<T0, T1, T2, T3, T4, T5>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -999,7 +989,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 6; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -1069,7 +1059,6 @@ public unsafe partial struct EntityQuery
}
}
}
}
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
@@ -1097,10 +1086,9 @@ public unsafe partial struct EntityQuery
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
{
return new ComponentIterator<T0, T1, T2, T3, T4, T5>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new ComponentIterator<T0, T1, T2, T3, T4, T5>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct ComponentIterator<T0, T1, T2, T3, T4, T5, T6>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -1218,7 +1206,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 7; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -1288,7 +1276,6 @@ public unsafe partial struct EntityQuery
}
}
}
}
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
@@ -1317,10 +1304,9 @@ public unsafe partial struct EntityQuery
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent
{
return new ComponentIterator<T0, T1, T2, T3, T4, T5, T6>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new ComponentIterator<T0, T1, T2, T3, T4, T5, T6>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct ComponentIterator<T0, T1, T2, T3, T4, T5, T6, T7>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -1447,7 +1433,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 8; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -1517,7 +1503,6 @@ public unsafe partial struct EntityQuery
}
}
}
}
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
@@ -1547,8 +1532,7 @@ public unsafe partial struct EntityQuery
where T6 : unmanaged, IComponent
where T7 : unmanaged, IComponent
{
return new ComponentIterator<T0, T1, T2, T3, T4, T5, T6, T7>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new ComponentIterator<T0, T1, T2, T3, T4, T5, T6, T7>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
}

View File

@@ -99,7 +99,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < <#= i #>; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -191,7 +191,7 @@ public unsafe partial struct EntityQuery
public readonly ComponentIterator<<#= generics#>> GetComponentIterator<<#= generics#>>()
<#= restrictions #>
{
return new ComponentIterator<<#= generics#>>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new ComponentIterator<<#= generics#>>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
<# } #>

View File

@@ -77,7 +77,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 1; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -169,7 +169,7 @@ public unsafe partial struct EntityQuery
public readonly EntityComponentIterator<T0> GetEntityComponentIterator<T0>()
where T0 : unmanaged, IComponent
{
return new EntityComponentIterator<T0>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new EntityComponentIterator<T0>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct EntityComponentIterator<T0, T1>
@@ -251,7 +251,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 2; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -344,7 +344,7 @@ public unsafe partial struct EntityQuery
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
{
return new EntityComponentIterator<T0, T1>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new EntityComponentIterator<T0, T1>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct EntityComponentIterator<T0, T1, T2>
@@ -435,7 +435,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 3; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -529,7 +529,7 @@ public unsafe partial struct EntityQuery
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
{
return new EntityComponentIterator<T0, T1, T2>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new EntityComponentIterator<T0, T1, T2>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct EntityComponentIterator<T0, T1, T2, T3>
@@ -629,7 +629,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 4; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -724,7 +724,7 @@ public unsafe partial struct EntityQuery
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
{
return new EntityComponentIterator<T0, T1, T2, T3>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new EntityComponentIterator<T0, T1, T2, T3>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct EntityComponentIterator<T0, T1, T2, T3, T4>
@@ -833,7 +833,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 5; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -929,7 +929,7 @@ public unsafe partial struct EntityQuery
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
{
return new EntityComponentIterator<T0, T1, T2, T3, T4>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new EntityComponentIterator<T0, T1, T2, T3, T4>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct EntityComponentIterator<T0, T1, T2, T3, T4, T5>
@@ -1047,7 +1047,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 6; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -1144,7 +1144,7 @@ public unsafe partial struct EntityQuery
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
{
return new EntityComponentIterator<T0, T1, T2, T3, T4, T5>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new EntityComponentIterator<T0, T1, T2, T3, T4, T5>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct EntityComponentIterator<T0, T1, T2, T3, T4, T5, T6>
@@ -1271,7 +1271,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 7; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -1369,7 +1369,7 @@ public unsafe partial struct EntityQuery
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent
{
return new EntityComponentIterator<T0, T1, T2, T3, T4, T5, T6>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new EntityComponentIterator<T0, T1, T2, T3, T4, T5, T6>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
public readonly ref struct EntityComponentIterator<T0, T1, T2, T3, T4, T5, T6, T7>
@@ -1505,7 +1505,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 8; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -1604,7 +1604,7 @@ public unsafe partial struct EntityQuery
where T6 : unmanaged, IComponent
where T7 : unmanaged, IComponent
{
return new EntityComponentIterator<T0, T1, T2, T3, T4, T5, T6, T7>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new EntityComponentIterator<T0, T1, T2, T3, T4, T5, T6, T7>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
}

View File

@@ -100,7 +100,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < <#= i #>; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
@@ -192,7 +192,7 @@ public unsafe partial struct EntityQuery
public readonly EntityComponentIterator<<#= generics#>> GetEntityComponentIterator<<#= generics#>>()
<#= restrictions #>
{
return new EntityComponentIterator<<#= generics#>>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
return new EntityComponentIterator<<#= generics#>>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow());
}
<# } #>

View File

@@ -1,4 +1,3 @@
using Ghost.Core;
namespace Ghost.Entities;
@@ -8,7 +7,7 @@ public unsafe partial struct EntityQuery
public readonly void ForEach<T0>(ForEach<T0> action)
where T0 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value };
var offsets = stackalloc int[1];
@@ -21,7 +20,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 1; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -64,7 +63,7 @@ public unsafe partial struct EntityQuery
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value };
var offsets = stackalloc int[2];
@@ -77,7 +76,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 2; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -122,7 +121,7 @@ public unsafe partial struct EntityQuery
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value };
var offsets = stackalloc int[3];
@@ -135,7 +134,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 3; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -182,7 +181,7 @@ public unsafe partial struct EntityQuery
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value };
var offsets = stackalloc int[4];
@@ -195,7 +194,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 4; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -244,7 +243,7 @@ public unsafe partial struct EntityQuery
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value };
var offsets = stackalloc int[5];
@@ -257,7 +256,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 5; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -308,7 +307,7 @@ public unsafe partial struct EntityQuery
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value, ComponentTypeID<T5>.value };
var offsets = stackalloc int[6];
@@ -321,7 +320,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 6; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -374,7 +373,7 @@ public unsafe partial struct EntityQuery
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value, ComponentTypeID<T5>.value, ComponentTypeID<T6>.value };
var offsets = stackalloc int[7];
@@ -387,7 +386,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 7; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -442,7 +441,7 @@ public unsafe partial struct EntityQuery
where T6 : unmanaged, IComponent
where T7 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value, ComponentTypeID<T5>.value, ComponentTypeID<T6>.value, ComponentTypeID<T7>.value };
var offsets = stackalloc int[8];
@@ -455,7 +454,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 8; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -504,7 +503,7 @@ public unsafe partial struct EntityQuery
public readonly void ForEach<T0>(ForEachWithEntity<T0> action)
where T0 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value };
var offsets = stackalloc int[1];
@@ -517,7 +516,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 1; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -561,7 +560,7 @@ public unsafe partial struct EntityQuery
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value };
var offsets = stackalloc int[2];
@@ -574,7 +573,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 2; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -620,7 +619,7 @@ public unsafe partial struct EntityQuery
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value };
var offsets = stackalloc int[3];
@@ -633,7 +632,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 3; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -681,7 +680,7 @@ public unsafe partial struct EntityQuery
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value };
var offsets = stackalloc int[4];
@@ -694,7 +693,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 4; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -744,7 +743,7 @@ public unsafe partial struct EntityQuery
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value };
var offsets = stackalloc int[5];
@@ -757,7 +756,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 5; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -809,7 +808,7 @@ public unsafe partial struct EntityQuery
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value, ComponentTypeID<T5>.value };
var offsets = stackalloc int[6];
@@ -822,7 +821,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 6; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -876,7 +875,7 @@ public unsafe partial struct EntityQuery
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value, ComponentTypeID<T5>.value, ComponentTypeID<T6>.value };
var offsets = stackalloc int[7];
@@ -889,7 +888,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 7; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -945,7 +944,7 @@ public unsafe partial struct EntityQuery
where T6 : unmanaged, IComponent
where T7 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value, ComponentTypeID<T5>.value, ComponentTypeID<T6>.value, ComponentTypeID<T7>.value };
var offsets = stackalloc int[8];
@@ -958,7 +957,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < 8; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -1005,4 +1004,4 @@ public unsafe partial struct EntityQuery
}
}
}
}

View File

@@ -16,8 +16,7 @@ public unsafe partial struct EntityQuery
#>
<# for (var i = 1; i <= Amount; i++)
{
var generics = AppendGenerics(i);
var compGenerics = AppendGenericRefParameters(i);
var generics = AppendParameters(i, "T{0}");
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 2);
var delegateTupe = isForEachWithEntity ? "ForEachWithEntity" : "ForEach";
@@ -25,7 +24,7 @@ public unsafe partial struct EntityQuery
public readonly void ForEach<<#= generics #>>(<#= delegateTupe #><<#= generics #>> action)
<#= restrictions #>
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
var compTypeIDs = stackalloc int[] { <#= AppendGenerics(i, "ComponentTypeID<T{0}>.value") #> };
var offsets = stackalloc int[<#= i #>];
@@ -38,7 +37,7 @@ public unsafe partial struct EntityQuery
for (var index = 0; index < <#= i #>; index++)
{
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
if (layoutResult.Status != ResultStatus.Success)
if (!layoutResult)
{
hasAllComponents = false;
break;
@@ -75,9 +74,9 @@ public unsafe partial struct EntityQuery
<# if (isForEachWithEntity) { #>
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
action(*pEntity, <#= AppendRefParameters(i, "*pComp{0}") #>);
action(*pEntity, <#= AppendParameters(i, "ref *pComp{0}") #>);
<# } else { #>
action(<#= AppendRefParameters(i, "*pComp{0}") #>);
action(<#= AppendParameters(i, "ref *pComp{0}") #>);
<# } #>
}
}
@@ -86,4 +85,4 @@ public unsafe partial struct EntityQuery
<# } #>
<# } #>
}
}

View File

@@ -8,7 +8,7 @@ namespace Ghost.Entities;
public interface IJobEntity<T0>
where T0 : unmanaged, IComponent
{
void Execute(Entity entity, ref T0 component0);
void Execute(Entity entity, ref T0 component0, int threadIndex);
}
internal unsafe struct JobEntityBatch<TJob, T0> : IJobParallelFor
@@ -43,7 +43,7 @@ internal unsafe struct JobEntityBatch<TJob, T0> : IJobParallelFor
continue;
}
userJob.Execute(pEntity[i], ref ptr0[i]);
userJob.Execute(pEntity[i], ref ptr0[i], threadIndex);
}
}
}
@@ -52,7 +52,7 @@ public interface IJobEntity<T0, T1>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
{
void Execute(Entity entity, ref T0 component0, ref T1 component1);
void Execute(Entity entity, ref T0 component0, ref T1 component1, int threadIndex);
}
internal unsafe struct JobEntityBatch<TJob, T0, T1> : IJobParallelFor
@@ -100,7 +100,7 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1> : IJobParallelFor
continue;
}
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i]);
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], threadIndex);
}
}
}
@@ -110,7 +110,7 @@ public interface IJobEntity<T0, T1, T2>
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
{
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2);
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, int threadIndex);
}
internal unsafe struct JobEntityBatch<TJob, T0, T1, T2> : IJobParallelFor
@@ -171,7 +171,7 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2> : IJobParallelFor
continue;
}
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i]);
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], threadIndex);
}
}
}
@@ -182,7 +182,7 @@ public interface IJobEntity<T0, T1, T2, T3>
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
{
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3);
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, int threadIndex);
}
internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3> : IJobParallelFor
@@ -256,7 +256,7 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3> : IJobParallelFor
continue;
}
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i]);
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i], threadIndex);
}
}
}
@@ -268,7 +268,7 @@ public interface IJobEntity<T0, T1, T2, T3, T4>
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
{
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4);
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, int threadIndex);
}
internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4> : IJobParallelFor
@@ -355,7 +355,7 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4> : IJobParallelFo
continue;
}
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i], ref ptr4[i]);
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i], ref ptr4[i], threadIndex);
}
}
}
@@ -368,7 +368,7 @@ public interface IJobEntity<T0, T1, T2, T3, T4, T5>
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
{
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5);
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5, int threadIndex);
}
internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5> : IJobParallelFor
@@ -468,7 +468,7 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5> : IJobParall
continue;
}
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i], ref ptr4[i], ref ptr5[i]);
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i], ref ptr4[i], ref ptr5[i], threadIndex);
}
}
}
@@ -482,7 +482,7 @@ public interface IJobEntity<T0, T1, T2, T3, T4, T5, T6>
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent
{
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5, ref T6 component6);
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5, ref T6 component6, int threadIndex);
}
internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5, T6> : IJobParallelFor
@@ -595,7 +595,7 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5, T6> : IJobPa
continue;
}
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i], ref ptr4[i], ref ptr5[i], ref ptr6[i]);
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i], ref ptr4[i], ref ptr5[i], ref ptr6[i], threadIndex);
}
}
}
@@ -610,7 +610,7 @@ public interface IJobEntity<T0, T1, T2, T3, T4, T5, T6, T7>
where T6 : unmanaged, IComponent
where T7 : unmanaged, IComponent
{
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5, ref T6 component6, ref T7 component7);
void Execute(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5, ref T6 component6, ref T7 component7, int threadIndex);
}
internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5, T6, T7> : IJobParallelFor
@@ -736,7 +736,7 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5, T6, T7> : IJ
continue;
}
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i], ref ptr4[i], ref ptr5[i], ref ptr6[i], ref ptr7[i]);
userJob.Execute(pEntity[i], ref ptr0[i], ref ptr1[i], ref ptr2[i], ref ptr3[i], ref ptr4[i], ref ptr5[i], ref ptr6[i], ref ptr7[i], threadIndex);
}
}
}
@@ -768,7 +768,7 @@ public unsafe partial struct EntityQuery
where TJob : unmanaged, IJobEntity<T0>
where T0 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
@@ -790,7 +790,7 @@ public unsafe partial struct EntityQuery
// Get offsets ONCE per archetype
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
// Add all chunks from this archetype
for (var i = 0; i < arch.ChunkCount; i++)
@@ -871,7 +871,7 @@ public unsafe partial struct EntityQuery
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
@@ -896,9 +896,9 @@ public unsafe partial struct EntityQuery
// Get offsets ONCE per archetype
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
// Add all chunks from this archetype
for (var i = 0; i < arch.ChunkCount; i++)
@@ -995,7 +995,7 @@ public unsafe partial struct EntityQuery
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
@@ -1023,11 +1023,11 @@ public unsafe partial struct EntityQuery
// Get offsets ONCE per archetype
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
// Add all chunks from this archetype
for (var i = 0; i < arch.ChunkCount; i++)
@@ -1140,7 +1140,7 @@ public unsafe partial struct EntityQuery
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
@@ -1171,13 +1171,13 @@ public unsafe partial struct EntityQuery
// Get offsets ONCE per archetype
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
// Add all chunks from this archetype
for (var i = 0; i < arch.ChunkCount; i++)
@@ -1306,7 +1306,7 @@ public unsafe partial struct EntityQuery
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
@@ -1340,15 +1340,15 @@ public unsafe partial struct EntityQuery
// Get offsets ONCE per archetype
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
// Add all chunks from this archetype
for (var i = 0; i < arch.ChunkCount; i++)
@@ -1493,7 +1493,7 @@ public unsafe partial struct EntityQuery
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
@@ -1530,17 +1530,17 @@ public unsafe partial struct EntityQuery
// Get offsets ONCE per archetype
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout5 = arch.GetLayout(ComponentTypeID<T5>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
// Add all chunks from this archetype
for (var i = 0; i < arch.ChunkCount; i++)
@@ -1701,7 +1701,7 @@ public unsafe partial struct EntityQuery
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
@@ -1741,19 +1741,19 @@ public unsafe partial struct EntityQuery
// Get offsets ONCE per archetype
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout5 = arch.GetLayout(ComponentTypeID<T5>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout6 = arch.GetLayout(ComponentTypeID<T6>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
// Add all chunks from this archetype
for (var i = 0; i < arch.ChunkCount; i++)
@@ -1930,7 +1930,7 @@ public unsafe partial struct EntityQuery
where T6 : unmanaged, IComponent
where T7 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
@@ -1973,21 +1973,21 @@ public unsafe partial struct EntityQuery
// Get offsets ONCE per archetype
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout5 = arch.GetLayout(ComponentTypeID<T5>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout6 = arch.GetLayout(ComponentTypeID<T6>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
var layout7 = arch.GetLayout(ComponentTypeID<T7>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
// Add all chunks from this archetype
for (var i = 0; i < arch.ChunkCount; i++)

View File

@@ -19,7 +19,7 @@ namespace Ghost.Entities;
public interface IJobEntity<<#= generics #>>
<#= restrictions #>
{
void Execute(Entity entity, <#= AppendParameters(i, "ref T{0} component{0}") #>);
void Execute(Entity entity, <#= AppendParameters(i, "ref T{0} component{0}") #>, int threadIndex);
}
internal unsafe struct JobEntityBatch<TJob, <#= generics #>> : IJobParallelFor
@@ -62,7 +62,7 @@ internal unsafe struct JobEntityBatch<TJob, <#= generics #>> : IJobParallelFor
}
<# } #>
userJob.Execute(pEntity[i], <#= AppendParameters(i, "ref ptr{0}[i]") #>);
userJob.Execute(pEntity[i], <#= AppendParameters(i, "ref ptr{0}[i]") #>, threadIndex);
}
}
}
@@ -104,7 +104,7 @@ public unsafe partial struct EntityQuery
where TJob : unmanaged, IJobEntity<<#= generics #>>
<#= restrictions #>
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
var world = World.GetWorld(_worldID).GetValueOrThrow();
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
@@ -129,7 +129,7 @@ public unsafe partial struct EntityQuery
// Get offsets ONCE per archetype
<# for (var j = 0; j < i; j++){ #>
var layout<#= j #> = arch.GetLayout(ComponentTypeID<T<#= j #>>.value)
.GetValueOrThrow(ResultStatus.Success);
.GetValueOrThrow();
<# } #>
// Add all chunks from this archetype

View File

@@ -1,92 +1,35 @@
namespace Ghost.Entities;
public delegate void ForEach<T0>(ref T0 component0)
where T0 : unmanaged, IComponent;
public delegate void ForEach<T0, T1>(ref T0 component0, ref T1 component1)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent;
public delegate void ForEach<T0, T1, T2>(ref T0 component0, ref T1 component1, ref T2 component2)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent;
public delegate void ForEach<T0, T1, T2, T3>(ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent;
public delegate void ForEach<T0, T1, T2, T3, T4>(ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent;
public delegate void ForEach<T0, T1, T2, T3, T4, T5>(ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent where T5 : unmanaged, IComponent;
public delegate void ForEach<T0, T1, T2, T3, T4, T5, T6>(ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5, ref T6 component6)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent where T5 : unmanaged, IComponent where T6 : unmanaged, IComponent;
public delegate void ForEach<T0, T1, T2, T3, T4, T5, T6, T7>(ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5, ref T6 component6, ref T7 component7)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent
where T7 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent where T5 : unmanaged, IComponent where T6 : unmanaged, IComponent where T7 : unmanaged, IComponent;
public delegate void ForEachWithEntity<T0>(Entity entity, ref T0 component0)
where T0 : unmanaged, IComponent;
public delegate void ForEachWithEntity<T0, T1>(Entity entity, ref T0 component0, ref T1 component1)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent;
public delegate void ForEachWithEntity<T0, T1, T2>(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent;
public delegate void ForEachWithEntity<T0, T1, T2, T3>(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent;
public delegate void ForEachWithEntity<T0, T1, T2, T3, T4>(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent;
public delegate void ForEachWithEntity<T0, T1, T2, T3, T4, T5>(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent where T5 : unmanaged, IComponent;
public delegate void ForEachWithEntity<T0, T1, T2, T3, T4, T5, T6>(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5, ref T6 component6)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent where T5 : unmanaged, IComponent where T6 : unmanaged, IComponent;
public delegate void ForEachWithEntity<T0, T1, T2, T3, T4, T5, T6, T7>(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2, ref T3 component3, ref T4 component4, ref T5 component5, ref T6 component6, ref T7 component7)
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent
where T7 : unmanaged, IComponent;
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent where T5 : unmanaged, IComponent where T6 : unmanaged, IComponent where T7 : unmanaged, IComponent;

View File

@@ -10,18 +10,18 @@ namespace Ghost.Entities;
{
var generics = AppendParameters(i, "T{0}");
var compGenerics = AppendParameters(i, "ref T{0} component{0}");
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 1);
var restrictions = AppendGenericRestrictions(i, "unmanaged, IComponent");
#>
public delegate void ForEach<<#= generics #>>(<#= compGenerics #>)
<#= restrictions #>;
<#= restrictions #>;
<# } #>
<# for (var i = 1; i <= Amount; i++)
{
var generics = AppendParameters(i, "T{0}");
var compGenerics = AppendParameters(i, "ref T{0} component{0}");
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 1);
var restrictions = AppendGenericRestrictions(i, "unmanaged, IComponent");
#>
public delegate void ForEachWithEntity<<#= generics #>>(Entity entity, <#= compGenerics #>)
<#= restrictions #>;
<#= restrictions #>;
<# } #>

View File

@@ -144,4 +144,4 @@
return sb;
}
#>
#>

View File

@@ -48,20 +48,20 @@ public partial class World
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Result<World, ResultStatus> GetWorld(Identifier<World> id)
public static Result<World, ErrorStatus> GetWorld(Identifier<World> id)
{
if (id.value < 0 || id.value >= s_worlds.Count)
{
return Result.Create(default(World)!, ResultStatus.NotFound);
return ErrorStatus.InvalidArgument;
}
var world = s_worlds[id.value];
if (world is null)
{
return Result.Create(default(World)!, ResultStatus.NotFound);
return ErrorStatus.NotFound;
}
return Result.Create(world, ResultStatus.Success);
return world;
}
}
@@ -102,6 +102,9 @@ public partial class World : IIdentifierType, IDisposable, IEquatable<World>
/// <summary>
/// Gets the main entity command buffer for this world.
/// </summary>
/// <remarks>
/// Use <see cref="GetThreadLocalEntityCommandBuffer(int)"/> to get thread-local command buffers for multi-threaded jobs.
/// </remarks>
public EntityCommandBuffer EntityCommandBuffer => _entityCommandBuffer;
private World(Identifier<World> id, int entityCapacity, JobScheduler jobScheduler)