Update version support
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
using Ghost.Test.Core;
|
||||
using Misaki.HighPerformance.Jobs;
|
||||
using Misaki.HighPerformance.Mathematics;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Ghost.Entities.Test;
|
||||
|
||||
internal struct TestEntityQueryJob : IJobChunk
|
||||
internal struct TestChunkQueryJob : IJobChunk
|
||||
{
|
||||
public void Execute(ChunkView view, int threadIndex)
|
||||
public readonly void Execute(ChunkView view, int threadIndex)
|
||||
{
|
||||
var transforms = view.GetComponentData<Transform>();
|
||||
var transforms = view.GetComponentDataRW<Transform>();
|
||||
for (var i = 0; i < view.Count; i++)
|
||||
{
|
||||
transforms[i].position += new float3(10, 10, 10);
|
||||
@@ -16,6 +17,14 @@ internal struct TestEntityQueryJob : IJobChunk
|
||||
}
|
||||
}
|
||||
|
||||
internal struct TestEntityQueryJob : IJobEntity<Transform>
|
||||
{
|
||||
public readonly void Execute(Entity entity, ref Transform transform, int index)
|
||||
{
|
||||
transform.position += new float3(5, 5, 5);
|
||||
}
|
||||
}
|
||||
|
||||
public partial class EntityTest : ITest
|
||||
{
|
||||
private JobScheduler _jobScheduler = null!;
|
||||
@@ -42,42 +51,44 @@ public partial class EntityTest : ITest
|
||||
var queryID = new QueryBuilder().WithAllRW<Transform>().WithAbsent<Mesh>().Build(_world);
|
||||
ref var query = ref _world.GetEntityQueryReference(queryID);
|
||||
|
||||
// var testJob = new TestEntityQueryJob();
|
||||
// var handle = query.ScheduleChunkParallel(testJob, 64, JobHandle.Invalid);
|
||||
// _jobScheduler.WaitComplete(handle);
|
||||
|
||||
_world.EntityManager.AddScriptComponent<TestScriptComponent>(entity1);
|
||||
_world.EntityManager.RemoveComponent<ManagedEntityRef>(entity1); // This should destory the managed entity and call OnDestroy
|
||||
|
||||
_world.AdvanceVersion();
|
||||
|
||||
query.ForEach<Transform>((e, ref t) =>
|
||||
{
|
||||
Console.WriteLine($"Entity {e} Has Position: {t.position}");
|
||||
});
|
||||
var testJob = new TestEntityQueryJob();
|
||||
var handle = query.ScheduleEntityParallel<TestEntityQueryJob, Transform>(testJob, 64, JobHandle.Invalid);
|
||||
_jobScheduler.WaitComplete(handle);
|
||||
|
||||
//foreach (var (entity, transform) in query.GetEntityComponentIterator<Transform>())
|
||||
//{
|
||||
// Console.WriteLine($"Entity {entity} Updated Position: {transform.Get().position}");
|
||||
//}
|
||||
// _world.EntityManager.AddScriptComponent<TestScriptComponent>(entity1);
|
||||
// _world.EntityManager.RemoveComponent<ManagedEntityRef>(entity1); // This should destory the managed entity and call OnDestroy
|
||||
|
||||
// query.ForEach<Transform>((e, ref t) =>
|
||||
// {
|
||||
// Console.WriteLine($"Entity {e} Has Position: {t.position}");
|
||||
// });
|
||||
//
|
||||
// foreach (var (entity, transform) in query.GetEntityComponentIterator<Transform>())
|
||||
// {
|
||||
// Console.WriteLine($"Entity {entity} Updated Position: {transform.Get().position}");
|
||||
// }
|
||||
|
||||
foreach (var chunk in query.GetChunkIterator())
|
||||
{
|
||||
var transforms = chunk.GetComponentData<Transform>();
|
||||
var entities = chunk.GetEntities();
|
||||
var bits = chunk.GetEnableBits<Transform>();
|
||||
|
||||
var changed = chunk.HasChanged<Transform>(0);
|
||||
|
||||
var it = bits.GetIterator();
|
||||
while (it.Next(out var index) && index < chunk.Count)
|
||||
if (chunk.HasChanged<Transform>(0))
|
||||
{
|
||||
Console.WriteLine($"Entity {entities[index]} Updated Position: {transforms[index].position}");
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_world.EntityManager.DestroyEntity(entity1);
|
||||
_world.EntityManager.DestroyEntity(entity2);
|
||||
Debug.Assert(_world.EntityManager.DestroyEntity(entity1) == Core.ErrorStatus.None);
|
||||
Debug.Assert(_world.EntityManager.DestroyEntity(entity2) == Core.ErrorStatus.None);
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
|
||||
Reference in New Issue
Block a user