Removed Ghost.ArcEntities project, it's replaced by Ghost.Entities

Added Playback to EntityCommandBuffer
Added JobSchedular to world
Added ISystem and SystemGroup
Updated packages
This commit is contained in:
2025-12-08 20:44:56 +09:00
parent f44208b502
commit 5e276b289d
30 changed files with 2974 additions and 1597 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,198 @@
<#@ template language="C#" #>
<#@ output extension="gen.cs" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ include file="Helpers.ttinclude" #>
using Ghost.Core;
using Misaki.HighPerformance.LowLevel;
using Misaki.HighPerformance.LowLevel.Collections;
using System.Runtime.CompilerServices;
namespace Ghost.Entities;
public unsafe partial struct EntityQuery
{
<# for (var i = 1; i <= Amount; i++)
{
var generics = AppendParameters(i, "T{0}");
var compGenerics = AppendParameters(i, "ref T{0} component{0}");
var deconstrictOutPrams = AppendParameters(i, "out Ref<T{0}> component{0}");
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 2);
#>
public readonly ref struct ComponentIterator<<#= generics#>>
<#= restrictions #>
{
<# if (i > 1) { #>
public ref struct QueryItem
{
<# for (var j = 0; j < i; j++) { #>
public ref T<#= j #> component<#= j #>;
<# } #>
internal QueryItem(<#= compGenerics #>)
{
<# for (var j = 0; j < i; j++) { #>
this.component<#= j #> = ref component<#= j #>;
<# } #>
}
public void Deconstruct(<#= deconstrictOutPrams #>)
{
<# for (var j = 0; j < i; j++) { #>
component<#= j #> = new Ref<T<#= j #>>(ref this.component<#= j #>);
<# } #>
}
}
<# } #>
public ref struct Enumerator
{
private fixed int _compTypeIDs[<#= i #>];
private fixed int _offsets[<#= i #>];
private fixed long _compBasePtrs[<#= i #>];
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
private readonly EntityQueryMask _mask;
private readonly World _world;
private ref Archetype _currentArchetype;
private ref Chunk _currentChunk;
private byte* _chunkBasePtr;
private int _currentChunkEntityCount;
private int _currentArchetypeIndex;
private int _currentChunkIndex;
private int _currentEntityIndex;
internal Enumerator(ReadOnlyUnsafeCollection<Identifier<Archetype>> matchingArchetypes, EntityQueryMask mask, World world)
{
<# for (var j = 0; j < i; j++) { #>
_compTypeIDs[<#= j #>] = ComponentTypeID<T<#= j #>>.value;
_offsets[<#= j #>] = 0;
_compBasePtrs[<#= j #>] = 0;
<# } #>
_matchingArchetypes = matchingArchetypes;
_mask = mask;
_world = world;
Reset();
}
<# if (i > 1) { #>
public QueryItem Current => new(
<# for (var j = 0; j < i; j++) { #>
ref *(T<#= j #>*)(_compBasePtrs[<#= j #>] + _currentEntityIndex * sizeof(T<#= j #>))<#= j < i - 1 ? "," : "" #>
<# } #>
);
<# } else { #>
public ref T0 Current => ref *(T0*)(_compBasePtrs[0] + _currentEntityIndex * sizeof(T0));
<# } #>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetChunk(int chunkIndex)
{
_currentChunk = ref _currentArchetype.GetChunkReference(chunkIndex);
_chunkBasePtr = _currentChunk.GetUnsafePtr();
_currentChunkEntityCount = _currentChunk.Count;
for (var index = 0; index < <#= i #>; index++)
{
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
.GetValueOrThrow(ResultStatus.Success);
_offsets[index] = layout.offset;
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
}
}
public bool MoveNext()
{
while (true)
{
_currentEntityIndex++;
if (_currentEntityIndex < _currentChunk.Count)
{
var pChunkData = _currentChunk.GetUnsafePtr();
if (IsEntityValid(pChunkData, _currentEntityIndex, in _currentArchetype, in _mask))
{
return true;
}
continue;
}
_currentChunkIndex++;
if (!Unsafe.IsNullRef(ref _currentArchetype) && _currentChunkIndex < _currentArchetype.ChunkCount)
{
SetChunk(_currentChunkIndex);
_currentEntityIndex = -1; // Reset for new chunk
continue;
}
_currentArchetypeIndex++;
if (_currentArchetypeIndex < _matchingArchetypes.Count)
{
_currentArchetype = ref _world.GetArchetypeReference(_matchingArchetypes[_currentArchetypeIndex]);
_currentChunkIndex = 0;
if (_currentArchetype.ChunkCount > 0)
{
SetChunk(0);
_currentEntityIndex = -1;
continue;
}
// If archetype has no chunks, loop will try next archetype
}
else
{
return false; // End of all data
}
}
}
public void Reset()
{
_currentArchetype = ref Unsafe.NullRef<Archetype>();
_currentChunk = ref Unsafe.NullRef<Chunk>();
_currentArchetypeIndex = 0;
_currentChunkIndex = 0;
_currentEntityIndex = -1;
if (_matchingArchetypes.Count > 0)
{
_currentArchetype = ref _world.GetArchetypeReference(_matchingArchetypes[0]);
if (_currentArchetype.ChunkCount > 0)
{
SetChunk(0);
}
}
}
}
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
private readonly EntityQueryMask _mask;
private readonly World _world;
internal ComponentIterator(ReadOnlyUnsafeCollection<Identifier<Archetype>> matchingArchetypes, EntityQueryMask mask, World world)
{
_matchingArchetypes = matchingArchetypes;
_mask = mask;
_world = world;
}
public Enumerator GetEnumerator()
{
return new Enumerator(_matchingArchetypes, _mask, _world);
}
}
public readonly ComponentIterator<<#= generics#>> GetComponentIterator<<#= generics#>>()
<#= restrictions #>
{
return new ComponentIterator<<#= generics#>>(_matchingArchetypes.AsReadOnly(), _mask, World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success));
}
<# } #>
}

View File

@@ -1,4 +1,3 @@
using Ghost.Core;
using Misaki.HighPerformance.Jobs;
using Misaki.HighPerformance.LowLevel.Buffer;
@@ -24,7 +23,7 @@ internal unsafe struct JobEntityBatch<TJob, T0> : IJobParallelFor
public UnsafeList<int> offsets0;
public UnsafeList<int> bitsOffsets0;
public void Execute(int loopIndex, int threadIndex)
{
// 1. Get the specific pChunk for this thread
@@ -33,7 +32,7 @@ internal unsafe struct JobEntityBatch<TJob, T0> : IJobParallelFor
var off0 = offsets0[loopIndex];
var enableOff0 = bitsOffsets0[loopIndex];
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
var ptr0 = (T0*)(pChunk + off0);
@@ -69,10 +68,10 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1> : IJobParallelFor
public UnsafeList<int> offsets0;
public UnsafeList<int> bitsOffsets0;
public UnsafeList<int> offsets1;
public UnsafeList<int> bitsOffsets1;
public void Execute(int loopIndex, int threadIndex)
{
// 1. Get the specific pChunk for this thread
@@ -81,10 +80,10 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1> : IJobParallelFor
var off0 = offsets0[loopIndex];
var enableOff0 = bitsOffsets0[loopIndex];
var off1 = offsets1[loopIndex];
var enableOff1 = bitsOffsets1[loopIndex];
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
var ptr0 = (T0*)(pChunk + off0);
var ptr1 = (T1*)(pChunk + off1);
@@ -128,13 +127,13 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2> : IJobParallelFor
public UnsafeList<int> offsets0;
public UnsafeList<int> bitsOffsets0;
public UnsafeList<int> offsets1;
public UnsafeList<int> bitsOffsets1;
public UnsafeList<int> offsets2;
public UnsafeList<int> bitsOffsets2;
public void Execute(int loopIndex, int threadIndex)
{
// 1. Get the specific pChunk for this thread
@@ -143,13 +142,13 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2> : IJobParallelFor
var off0 = offsets0[loopIndex];
var enableOff0 = bitsOffsets0[loopIndex];
var off1 = offsets1[loopIndex];
var enableOff1 = bitsOffsets1[loopIndex];
var off2 = offsets2[loopIndex];
var enableOff2 = bitsOffsets2[loopIndex];
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
var ptr0 = (T0*)(pChunk + off0);
var ptr1 = (T1*)(pChunk + off1);
@@ -201,16 +200,16 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3> : IJobParallelFor
public UnsafeList<int> offsets0;
public UnsafeList<int> bitsOffsets0;
public UnsafeList<int> offsets1;
public UnsafeList<int> bitsOffsets1;
public UnsafeList<int> offsets2;
public UnsafeList<int> bitsOffsets2;
public UnsafeList<int> offsets3;
public UnsafeList<int> bitsOffsets3;
public void Execute(int loopIndex, int threadIndex)
{
// 1. Get the specific pChunk for this thread
@@ -219,16 +218,16 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3> : IJobParallelFor
var off0 = offsets0[loopIndex];
var enableOff0 = bitsOffsets0[loopIndex];
var off1 = offsets1[loopIndex];
var enableOff1 = bitsOffsets1[loopIndex];
var off2 = offsets2[loopIndex];
var enableOff2 = bitsOffsets2[loopIndex];
var off3 = offsets3[loopIndex];
var enableOff3 = bitsOffsets3[loopIndex];
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
var ptr0 = (T0*)(pChunk + off0);
var ptr1 = (T1*)(pChunk + off1);
@@ -288,19 +287,19 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4> : IJobParallelFo
public UnsafeList<int> offsets0;
public UnsafeList<int> bitsOffsets0;
public UnsafeList<int> offsets1;
public UnsafeList<int> bitsOffsets1;
public UnsafeList<int> offsets2;
public UnsafeList<int> bitsOffsets2;
public UnsafeList<int> offsets3;
public UnsafeList<int> bitsOffsets3;
public UnsafeList<int> offsets4;
public UnsafeList<int> bitsOffsets4;
public void Execute(int loopIndex, int threadIndex)
{
// 1. Get the specific pChunk for this thread
@@ -309,19 +308,19 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4> : IJobParallelFo
var off0 = offsets0[loopIndex];
var enableOff0 = bitsOffsets0[loopIndex];
var off1 = offsets1[loopIndex];
var enableOff1 = bitsOffsets1[loopIndex];
var off2 = offsets2[loopIndex];
var enableOff2 = bitsOffsets2[loopIndex];
var off3 = offsets3[loopIndex];
var enableOff3 = bitsOffsets3[loopIndex];
var off4 = offsets4[loopIndex];
var enableOff4 = bitsOffsets4[loopIndex];
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
var ptr0 = (T0*)(pChunk + off0);
var ptr1 = (T1*)(pChunk + off1);
@@ -389,22 +388,22 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5> : IJobParall
public UnsafeList<int> offsets0;
public UnsafeList<int> bitsOffsets0;
public UnsafeList<int> offsets1;
public UnsafeList<int> bitsOffsets1;
public UnsafeList<int> offsets2;
public UnsafeList<int> bitsOffsets2;
public UnsafeList<int> offsets3;
public UnsafeList<int> bitsOffsets3;
public UnsafeList<int> offsets4;
public UnsafeList<int> bitsOffsets4;
public UnsafeList<int> offsets5;
public UnsafeList<int> bitsOffsets5;
public void Execute(int loopIndex, int threadIndex)
{
// 1. Get the specific pChunk for this thread
@@ -413,22 +412,22 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5> : IJobParall
var off0 = offsets0[loopIndex];
var enableOff0 = bitsOffsets0[loopIndex];
var off1 = offsets1[loopIndex];
var enableOff1 = bitsOffsets1[loopIndex];
var off2 = offsets2[loopIndex];
var enableOff2 = bitsOffsets2[loopIndex];
var off3 = offsets3[loopIndex];
var enableOff3 = bitsOffsets3[loopIndex];
var off4 = offsets4[loopIndex];
var enableOff4 = bitsOffsets4[loopIndex];
var off5 = offsets5[loopIndex];
var enableOff5 = bitsOffsets5[loopIndex];
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
var ptr0 = (T0*)(pChunk + off0);
var ptr1 = (T1*)(pChunk + off1);
@@ -504,25 +503,25 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5, T6> : IJobPa
public UnsafeList<int> offsets0;
public UnsafeList<int> bitsOffsets0;
public UnsafeList<int> offsets1;
public UnsafeList<int> bitsOffsets1;
public UnsafeList<int> offsets2;
public UnsafeList<int> bitsOffsets2;
public UnsafeList<int> offsets3;
public UnsafeList<int> bitsOffsets3;
public UnsafeList<int> offsets4;
public UnsafeList<int> bitsOffsets4;
public UnsafeList<int> offsets5;
public UnsafeList<int> bitsOffsets5;
public UnsafeList<int> offsets6;
public UnsafeList<int> bitsOffsets6;
public void Execute(int loopIndex, int threadIndex)
{
// 1. Get the specific pChunk for this thread
@@ -531,25 +530,25 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5, T6> : IJobPa
var off0 = offsets0[loopIndex];
var enableOff0 = bitsOffsets0[loopIndex];
var off1 = offsets1[loopIndex];
var enableOff1 = bitsOffsets1[loopIndex];
var off2 = offsets2[loopIndex];
var enableOff2 = bitsOffsets2[loopIndex];
var off3 = offsets3[loopIndex];
var enableOff3 = bitsOffsets3[loopIndex];
var off4 = offsets4[loopIndex];
var enableOff4 = bitsOffsets4[loopIndex];
var off5 = offsets5[loopIndex];
var enableOff5 = bitsOffsets5[loopIndex];
var off6 = offsets6[loopIndex];
var enableOff6 = bitsOffsets6[loopIndex];
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
var ptr0 = (T0*)(pChunk + off0);
var ptr1 = (T1*)(pChunk + off1);
@@ -633,28 +632,28 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5, T6, T7> : IJ
public UnsafeList<int> offsets0;
public UnsafeList<int> bitsOffsets0;
public UnsafeList<int> offsets1;
public UnsafeList<int> bitsOffsets1;
public UnsafeList<int> offsets2;
public UnsafeList<int> bitsOffsets2;
public UnsafeList<int> offsets3;
public UnsafeList<int> bitsOffsets3;
public UnsafeList<int> offsets4;
public UnsafeList<int> bitsOffsets4;
public UnsafeList<int> offsets5;
public UnsafeList<int> bitsOffsets5;
public UnsafeList<int> offsets6;
public UnsafeList<int> bitsOffsets6;
public UnsafeList<int> offsets7;
public UnsafeList<int> bitsOffsets7;
public void Execute(int loopIndex, int threadIndex)
{
// 1. Get the specific pChunk for this thread
@@ -663,28 +662,28 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2, T3, T4, T5, T6, T7> : IJ
var off0 = offsets0[loopIndex];
var enableOff0 = bitsOffsets0[loopIndex];
var off1 = offsets1[loopIndex];
var enableOff1 = bitsOffsets1[loopIndex];
var off2 = offsets2[loopIndex];
var enableOff2 = bitsOffsets2[loopIndex];
var off3 = offsets3[loopIndex];
var enableOff3 = bitsOffsets3[loopIndex];
var off4 = offsets4[loopIndex];
var enableOff4 = bitsOffsets4[loopIndex];
var off5 = offsets5[loopIndex];
var enableOff5 = bitsOffsets5[loopIndex];
var off6 = offsets6[loopIndex];
var enableOff6 = bitsOffsets6[loopIndex];
var off7 = offsets7[loopIndex];
var enableOff7 = bitsOffsets7[loopIndex];
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
var ptr0 = (T0*)(pChunk + off0);
var ptr1 = (T1*)(pChunk + off1);
@@ -765,10 +764,12 @@ public unsafe partial struct EntityQuery
}
}
public JobHandle ScheduleEntityParallel<TJob, T0>(JobScheduler scheduler, TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
public JobHandle ScheduleEntityParallel<TJob, T0>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobEntityParallel<T0>
where T0 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
@@ -780,9 +781,7 @@ public unsafe partial struct EntityQuery
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref World.GetWorld(_worldID)
.GetValueOrThrow(ResultStatus.Success)
.GetArchetypeReference(archID);
ref var arch = ref world.GetArchetypeReference(archID);
if (arch.ChunkCount == 0)
{
@@ -821,7 +820,7 @@ public unsafe partial struct EntityQuery
};
var jobHandle = scheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
// 3. Dispose the temp lists
var disposeJob = new DisposeJobEntity1
@@ -835,7 +834,7 @@ public unsafe partial struct EntityQuery
};
scheduler.Schedule(ref disposeJob, jobHandle);
world.JobScheduler.Schedule(ref disposeJob, jobHandle);
return jobHandle;
}
@@ -867,11 +866,13 @@ public unsafe partial struct EntityQuery
}
}
public JobHandle ScheduleEntityParallel<TJob, T0, T1>(JobScheduler scheduler, TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
public JobHandle ScheduleEntityParallel<TJob, T0, T1>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobEntityParallel<T0, T1>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
@@ -886,9 +887,7 @@ public unsafe partial struct EntityQuery
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref World.GetWorld(_worldID)
.GetValueOrThrow(ResultStatus.Success)
.GetArchetypeReference(archID);
ref var arch = ref world.GetArchetypeReference(archID);
if (arch.ChunkCount == 0)
{
@@ -935,7 +934,7 @@ public unsafe partial struct EntityQuery
};
var jobHandle = scheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
// 3. Dispose the temp lists
var disposeJob = new DisposeJobEntity2
@@ -952,7 +951,7 @@ public unsafe partial struct EntityQuery
};
scheduler.Schedule(ref disposeJob, jobHandle);
world.JobScheduler.Schedule(ref disposeJob, jobHandle);
return jobHandle;
}
@@ -990,12 +989,14 @@ public unsafe partial struct EntityQuery
}
}
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2>(JobScheduler scheduler, TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobEntityParallel<T0, T1, T2>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
@@ -1013,9 +1014,7 @@ public unsafe partial struct EntityQuery
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref World.GetWorld(_worldID)
.GetValueOrThrow(ResultStatus.Success)
.GetArchetypeReference(archID);
ref var arch = ref world.GetArchetypeReference(archID);
if (arch.ChunkCount == 0)
{
@@ -1070,7 +1069,7 @@ public unsafe partial struct EntityQuery
};
var jobHandle = scheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
// 3. Dispose the temp lists
var disposeJob = new DisposeJobEntity3
@@ -1090,7 +1089,7 @@ public unsafe partial struct EntityQuery
};
scheduler.Schedule(ref disposeJob, jobHandle);
world.JobScheduler.Schedule(ref disposeJob, jobHandle);
return jobHandle;
}
@@ -1134,13 +1133,15 @@ public unsafe partial struct EntityQuery
}
}
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3>(JobScheduler scheduler, TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobEntityParallel<T0, T1, T2, T3>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
where T2 : unmanaged, IComponent
where T3 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
@@ -1161,9 +1162,7 @@ public unsafe partial struct EntityQuery
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref World.GetWorld(_worldID)
.GetValueOrThrow(ResultStatus.Success)
.GetArchetypeReference(archID);
ref var arch = ref world.GetArchetypeReference(archID);
if (arch.ChunkCount == 0)
{
@@ -1226,7 +1225,7 @@ public unsafe partial struct EntityQuery
};
var jobHandle = scheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
// 3. Dispose the temp lists
var disposeJob = new DisposeJobEntity4
@@ -1249,7 +1248,7 @@ public unsafe partial struct EntityQuery
};
scheduler.Schedule(ref disposeJob, jobHandle);
world.JobScheduler.Schedule(ref disposeJob, jobHandle);
return jobHandle;
}
@@ -1299,7 +1298,7 @@ public unsafe partial struct EntityQuery
}
}
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3, T4>(JobScheduler scheduler, TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3, T4>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobEntityParallel<T0, T1, T2, T3, T4>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -1307,6 +1306,8 @@ public unsafe partial struct EntityQuery
where T3 : unmanaged, IComponent
where T4 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
@@ -1330,9 +1331,7 @@ public unsafe partial struct EntityQuery
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref World.GetWorld(_worldID)
.GetValueOrThrow(ResultStatus.Success)
.GetArchetypeReference(archID);
ref var arch = ref world.GetArchetypeReference(archID);
if (arch.ChunkCount == 0)
{
@@ -1403,7 +1402,7 @@ public unsafe partial struct EntityQuery
};
var jobHandle = scheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
// 3. Dispose the temp lists
var disposeJob = new DisposeJobEntity5
@@ -1429,7 +1428,7 @@ public unsafe partial struct EntityQuery
};
scheduler.Schedule(ref disposeJob, jobHandle);
world.JobScheduler.Schedule(ref disposeJob, jobHandle);
return jobHandle;
}
@@ -1485,7 +1484,7 @@ public unsafe partial struct EntityQuery
}
}
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3, T4, T5>(JobScheduler scheduler, TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3, T4, T5>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobEntityParallel<T0, T1, T2, T3, T4, T5>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -1494,6 +1493,8 @@ public unsafe partial struct EntityQuery
where T4 : unmanaged, IComponent
where T5 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
@@ -1520,9 +1521,7 @@ public unsafe partial struct EntityQuery
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref World.GetWorld(_worldID)
.GetValueOrThrow(ResultStatus.Success)
.GetArchetypeReference(archID);
ref var arch = ref world.GetArchetypeReference(archID);
if (arch.ChunkCount == 0)
{
@@ -1601,7 +1600,7 @@ public unsafe partial struct EntityQuery
};
var jobHandle = scheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
// 3. Dispose the temp lists
var disposeJob = new DisposeJobEntity6
@@ -1630,7 +1629,7 @@ public unsafe partial struct EntityQuery
};
scheduler.Schedule(ref disposeJob, jobHandle);
world.JobScheduler.Schedule(ref disposeJob, jobHandle);
return jobHandle;
}
@@ -1692,7 +1691,7 @@ public unsafe partial struct EntityQuery
}
}
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3, T4, T5, T6>(JobScheduler scheduler, TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3, T4, T5, T6>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobEntityParallel<T0, T1, T2, T3, T4, T5, T6>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -1702,6 +1701,8 @@ public unsafe partial struct EntityQuery
where T5 : unmanaged, IComponent
where T6 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
@@ -1731,9 +1732,7 @@ public unsafe partial struct EntityQuery
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref World.GetWorld(_worldID)
.GetValueOrThrow(ResultStatus.Success)
.GetArchetypeReference(archID);
ref var arch = ref world.GetArchetypeReference(archID);
if (arch.ChunkCount == 0)
{
@@ -1820,7 +1819,7 @@ public unsafe partial struct EntityQuery
};
var jobHandle = scheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
// 3. Dispose the temp lists
var disposeJob = new DisposeJobEntity7
@@ -1852,7 +1851,7 @@ public unsafe partial struct EntityQuery
};
scheduler.Schedule(ref disposeJob, jobHandle);
world.JobScheduler.Schedule(ref disposeJob, jobHandle);
return jobHandle;
}
@@ -1920,7 +1919,7 @@ public unsafe partial struct EntityQuery
}
}
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3, T4, T5, T6, T7>(JobScheduler scheduler, TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
public JobHandle ScheduleEntityParallel<TJob, T0, T1, T2, T3, T4, T5, T6, T7>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobEntityParallel<T0, T1, T2, T3, T4, T5, T6, T7>
where T0 : unmanaged, IComponent
where T1 : unmanaged, IComponent
@@ -1931,6 +1930,8 @@ public unsafe partial struct EntityQuery
where T6 : unmanaged, IComponent
where T7 : unmanaged, IComponent
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
@@ -1963,9 +1964,7 @@ public unsafe partial struct EntityQuery
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref World.GetWorld(_worldID)
.GetValueOrThrow(ResultStatus.Success)
.GetArchetypeReference(archID);
ref var arch = ref world.GetArchetypeReference(archID);
if (arch.ChunkCount == 0)
{
@@ -2060,7 +2059,7 @@ public unsafe partial struct EntityQuery
};
var jobHandle = scheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
// 3. Dispose the temp lists
var disposeJob = new DisposeJobEntity8
@@ -2095,9 +2094,9 @@ public unsafe partial struct EntityQuery
};
scheduler.Schedule(ref disposeJob, jobHandle);
world.JobScheduler.Schedule(ref disposeJob, jobHandle);
return jobHandle;
}
}
}

View File

@@ -35,7 +35,7 @@ internal unsafe struct JobEntityBatch<TJob, <#= generics #>> : IJobParallelFor
<# for (var j = 0; j < i; j++){ #>
public UnsafeList<int> offsets<#= j #>;
public UnsafeList<int> bitsOffsets<#= j #>;
<# } #>
public void Execute(int loopIndex, int threadIndex)
{
@@ -46,7 +46,7 @@ internal unsafe struct JobEntityBatch<TJob, <#= generics #>> : IJobParallelFor
<# for (var j = 0; j < i; j++){ #>
var off<#= j #> = offsets<#= j #>[loopIndex];
var enableOff<#= j #> = bitsOffsets<#= j #>[loopIndex];
<# } #>
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
<# for (var j = 0; j < i; j++){ #>
@@ -100,10 +100,12 @@ public unsafe partial struct EntityQuery
}
}
public JobHandle ScheduleEntityParallel<TJob, <#= generics #>>(JobScheduler scheduler, TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
public JobHandle ScheduleEntityParallel<TJob, <#= generics #>>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
where TJob : unmanaged, IJobEntityParallel<<#= generics #>>
<#= restrictions #>
{
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
// 1. Flatten the World
var chunkList = new UnsafeList<IntPtr>(128, allocator);
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
@@ -117,9 +119,7 @@ public unsafe partial struct EntityQuery
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
{
ref var arch = ref World.GetWorld(_worldID)
.GetValueOrThrow(ResultStatus.Success)
.GetArchetypeReference(archID);
ref var arch = ref world.GetArchetypeReference(archID);
if (arch.ChunkCount == 0)
{
@@ -164,7 +164,7 @@ public unsafe partial struct EntityQuery
<# } #>
};
var jobHandle = scheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
// 3. Dispose the temp lists
var disposeJob = new DisposeJobEntity<#= i #>
@@ -180,10 +180,10 @@ public unsafe partial struct EntityQuery
<# } #>
};
scheduler.Schedule(ref disposeJob, jobHandle);
world.JobScheduler.Schedule(ref disposeJob, jobHandle);
return jobHandle;
}
<# } #>
}
}

View File

@@ -1,21 +1,92 @@
namespace Ghost.Entities;
public delegate void ForEach<T0>(ref T0 t0Component);
public delegate void ForEach<T0, T1>(ref T0 t0Component,ref T1 t1Component);
public delegate void ForEach<T0, T1, T2>(ref T0 t0Component,ref T1 t1Component,ref T2 t2Component);
public delegate void ForEach<T0, T1, T2, T3>(ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component);
public delegate void ForEach<T0, T1, T2, T3, T4>(ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component);
public delegate void ForEach<T0, T1, T2, T3, T4, T5>(ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component);
public delegate void ForEach<T0, T1, T2, T3, T4, T5, T6>(ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component);
public delegate void ForEach<T0, T1, T2, T3, T4, T5, T6, T7>(ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component);
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;
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;
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;
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;
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;
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;
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;
public delegate void ForEachWithEntity<T0>(Entity entity, ref T0 t0Component);
public delegate void ForEachWithEntity<T0, T1>(Entity entity, ref T0 t0Component,ref T1 t1Component);
public delegate void ForEachWithEntity<T0, T1, T2>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component);
public delegate void ForEachWithEntity<T0, T1, T2, T3>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component);
public delegate void ForEachWithEntity<T0, T1, T2, T3, T4>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component);
public delegate void ForEachWithEntity<T0, T1, T2, T3, T4, T5>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component);
public delegate void ForEachWithEntity<T0, T1, T2, T3, T4, T5, T6>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component);
public delegate void ForEachWithEntity<T0, T1, T2, T3, T4, T5, T6, T7>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component);
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;
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;
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;
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;
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;
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;
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;

View File

@@ -4,21 +4,24 @@
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ include file="Helpers.ttinclude" #>
namespace Ghost.Entities;
<# for (var i = 1; i <= Amount; i++)
{
var generics = AppendGenerics(i);
var compGenerics = AppendGenericRefParameters(i);
var generics = AppendParameters(i, "T{0}");
var compGenerics = AppendParameters(i, "ref T{0} component{0}");
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 1);
#>
public delegate void ForEach<<#= generics #>>(<#= compGenerics #>);
public delegate void ForEach<<#= generics #>>(<#= compGenerics #>)
<#= restrictions #>;
<# } #>
<# for (var i = 1; i <= Amount; i++)
{
var generics = AppendGenerics(i);
var compGenerics = AppendGenericRefParameters(i);
var generics = AppendParameters(i, "T{0}");
var compGenerics = AppendParameters(i, "ref T{0} component{0}");
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 1);
#>
public delegate void ForEachWithEntity<<#= generics #>>(Entity entity, <#= compGenerics #>);
<# } #>
public delegate void ForEachWithEntity<<#= generics #>>(Entity entity, <#= compGenerics #>)
<#= restrictions #>;
<# } #>