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

@@ -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: