Added ScheduleEntityParallel and IJobEntityParallel for parallel querying

This commit is contained in:
2025-12-07 11:45:25 +09:00
parent 30c1d99959
commit 02084c1e47
10 changed files with 2388 additions and 72 deletions

View File

@@ -1,15 +1,28 @@
using Ghost.Test.Core;
using Misaki.HighPerformance.Jobs;
using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.Mathematics;
using System;
namespace Ghost.Entities.Test;
internal struct TestEntityQueryJob : IJobEntityParallel<Transform>
{
public readonly void Execute(Entity entity, ref Transform transform)
{
transform.position += new float3(10, 10, 10);
}
}
public partial class ArcEntityTest : ITest
{
private World _world = null!;
private JobScheduler _jobScheduler = null!;
public void Setup()
{
_world = World.Create();
_jobScheduler = new JobScheduler(4);
}
public void Run()
@@ -20,23 +33,27 @@ public partial class ArcEntityTest : ITest
var queryID = new QueryBuilder().WithAll<Transform>().Build(_world);
ref var query = ref _world.GetEntityQueryReference(queryID);
query.ForEach<Transform>((ref t) =>
var testJob = new TestEntityQueryJob();
var handle = query.ScheduleEntityParallel<TestEntityQueryJob, Transform>(_jobScheduler, testJob, Allocator.Temp, 64, JobHandle.Invalid);
_jobScheduler.WaitComplete(handle);
query.ForEach<Transform>((e, ref t) =>
{
t.position = new float3(1, 2, 3);
Console.WriteLine($"Entity {e} Has Position: {t.position}");
});
foreach (var chunk in query.GetChunkIterator())
{
var transforms = chunk.GetComponentData<Transform>();
var entities = chunk.GetEntities();
var bits = chunk.GetEnableBits<Transform>();
var it = bits.GetIterator();
while (it.Next(out var index) && index < chunk.Count)
{
Console.WriteLine($"Entity {entities[index]} Updated Position: {transforms[index].position}");
}
}
//foreach (var chunk in query.GetChunkIterator())
//{
// var transforms = chunk.GetComponentData<Transform>();
// var entities = chunk.GetEntities();
// var bits = chunk.GetEnableBits<Transform>();
// var it = bits.GetIterator();
// while (it.Next(out var index) && index < chunk.Count)
// {
// Console.WriteLine($"Entity {entities[index]} Updated Position: {transforms[index].position}");
// }
//}
}
public void Cleanup()