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:
@@ -1,16 +1,16 @@
|
|||||||
|
using Misaki.HighPerformance.LowLevel;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Ghost.Core;
|
namespace Ghost.Core;
|
||||||
|
|
||||||
public readonly struct Result
|
public readonly struct Result
|
||||||
{
|
{
|
||||||
private readonly bool _isSuccess;
|
|
||||||
private readonly string? _message;
|
private readonly string? _message;
|
||||||
|
private readonly bool _isSuccess;
|
||||||
public readonly bool IsSuccess => _isSuccess;
|
|
||||||
public readonly bool IsFailure => !_isSuccess;
|
|
||||||
|
|
||||||
public readonly string? Message => _message;
|
public readonly string? Message => _message;
|
||||||
|
public readonly bool IsSuccess => _isSuccess;
|
||||||
|
public readonly bool IsFailure => !_isSuccess;
|
||||||
|
|
||||||
public Result(bool success, string? message = null)
|
public Result(bool success, string? message = null)
|
||||||
{
|
{
|
||||||
@@ -38,16 +38,10 @@ public readonly struct Result
|
|||||||
return Result<T>.Failure(message);
|
return Result<T>.Failure(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result<T, S> Create<T, S>(T value, S status)
|
public void Deconstruct(out bool success, out string? message)
|
||||||
where S : Enum
|
|
||||||
{
|
{
|
||||||
return new Result<T, S>(value, status);
|
success = IsSuccess;
|
||||||
}
|
message = Message;
|
||||||
|
|
||||||
public static RefResult<T, S> CreateRef<T, S>(ref T value, S status)
|
|
||||||
where S : Enum
|
|
||||||
{
|
|
||||||
return new RefResult<T, S>(ref value, status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => IsSuccess ? "OK" : $"Error: {Message}";
|
public override string ToString() => IsSuccess ? "OK" : $"Error: {Message}";
|
||||||
@@ -57,15 +51,14 @@ public readonly struct Result
|
|||||||
|
|
||||||
public readonly struct Result<T>
|
public readonly struct Result<T>
|
||||||
{
|
{
|
||||||
private readonly bool _isSuccess;
|
|
||||||
private readonly T _value;
|
private readonly T _value;
|
||||||
private readonly string? _message;
|
private readonly string? _message;
|
||||||
|
private readonly bool _isSuccess;
|
||||||
public readonly bool IsSuccess => _isSuccess;
|
|
||||||
public readonly bool IsFailure => !_isSuccess;
|
|
||||||
|
|
||||||
public readonly T Value => _value;
|
public readonly T Value => _value;
|
||||||
public readonly string? Message => _message;
|
public readonly string? Message => _message;
|
||||||
|
public readonly bool IsSuccess => _isSuccess;
|
||||||
|
public readonly bool IsFailure => !_isSuccess;
|
||||||
|
|
||||||
public Result(bool success, T value, string? message = null)
|
public Result(bool success, T value, string? message = null)
|
||||||
{
|
{
|
||||||
@@ -84,6 +77,13 @@ public readonly struct Result<T>
|
|||||||
return new Result<T>(false, default!, message);
|
return new Result<T>(false, default!, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Deconstruct(out bool success, out T value, out string? message)
|
||||||
|
{
|
||||||
|
success = IsSuccess;
|
||||||
|
value = Value;
|
||||||
|
message = Message;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString() => IsSuccess ? $"OK: {Value}" : $"Error: {Message}";
|
public override string ToString() => IsSuccess ? $"OK: {Value}" : $"Error: {Message}";
|
||||||
|
|
||||||
public static implicit operator Result<T>(T? data) => data is not null ? Success(data) : Failure(null);
|
public static implicit operator Result<T>(T? data) => data is not null ? Success(data) : Failure(null);
|
||||||
@@ -91,9 +91,9 @@ public readonly struct Result<T>
|
|||||||
public static implicit operator bool(Result<T> result) => result.IsSuccess;
|
public static implicit operator bool(Result<T> result) => result.IsSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ResultStatus : byte
|
public enum ErrorStatus : byte
|
||||||
{
|
{
|
||||||
Success,
|
None,
|
||||||
NotFound,
|
NotFound,
|
||||||
InvalidArgument,
|
InvalidArgument,
|
||||||
InvalidState,
|
InvalidState,
|
||||||
@@ -106,57 +106,97 @@ public enum ResultStatus : byte
|
|||||||
UnknownError
|
UnknownError
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly struct Result<T, S>
|
public readonly struct Result<T, E>
|
||||||
where S : Enum
|
where E : struct, Enum
|
||||||
{
|
{
|
||||||
private readonly T _value;
|
private readonly T _value;
|
||||||
private readonly S _status;
|
private readonly E _error;
|
||||||
|
private readonly bool _isSuccess;
|
||||||
|
|
||||||
public T Value => _value;
|
public T Value => _value;
|
||||||
public S Status => _status;
|
public E Error => _error;
|
||||||
|
public bool IsSuccess => _isSuccess;
|
||||||
|
public bool IsFailure => !_isSuccess;
|
||||||
|
|
||||||
public Result(T value, S status)
|
public Result(T value, E status, bool isSuccess)
|
||||||
{
|
{
|
||||||
_value = value;
|
_value = value;
|
||||||
_status = status;
|
_error = status;
|
||||||
|
_isSuccess = isSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result<T, S> Create(T value, S status)
|
public static Result<T, E> Success(T value)
|
||||||
{
|
{
|
||||||
return new Result<T, S>(value, status);
|
return new Result<T, E>(value, default, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => $"Value: {_value}, Status: {_status}";
|
public static Result<T, E> Failure(E status)
|
||||||
|
{
|
||||||
|
return new Result<T, E>(default!, status, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deconstruct(out bool success, out T value, out E status)
|
||||||
|
{
|
||||||
|
success = IsSuccess;
|
||||||
|
value = Value;
|
||||||
|
status = Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() => $"Value: {_value}, Status: {_error}";
|
||||||
|
|
||||||
|
public static implicit operator Result<T, E>(T data) => new(data, default, true);
|
||||||
|
public static implicit operator Result<T, E>(E status) => new(default!, status, false);
|
||||||
|
public static implicit operator bool(Result<T, E> result) => result.IsSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly ref struct RefResult<T, S>
|
public readonly ref struct RefResult<T, E>
|
||||||
where S : Enum
|
where E : struct, Enum
|
||||||
{
|
{
|
||||||
private readonly ref T _value;
|
private readonly ref T _value;
|
||||||
private readonly S _status;
|
private readonly E _error;
|
||||||
|
private readonly bool _isSuccess;
|
||||||
|
|
||||||
public ref T Value => ref _value;
|
public ref T Value => ref _value;
|
||||||
public S Status => _status;
|
public E Error => _error;
|
||||||
|
public bool IsSuccess => _isSuccess;
|
||||||
|
public bool IsFailure => !_isSuccess;
|
||||||
|
|
||||||
public RefResult(ref T value, S status)
|
public RefResult(ref T value, E error, bool isSuccess)
|
||||||
{
|
{
|
||||||
_value = ref value;
|
_value = ref value;
|
||||||
_status = status;
|
_error = error;
|
||||||
|
_isSuccess = isSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RefResult<T, S> Create(ref T value, S status)
|
public static RefResult<T, E> Success(ref T value)
|
||||||
{
|
{
|
||||||
return new RefResult<T, S>(ref value, status);
|
return new RefResult<T, E>(ref value, default, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => $"Value: {_value}, Status: {_status}";
|
public static RefResult<T, E> Failure(E error)
|
||||||
|
{
|
||||||
|
return new RefResult<T, E>(ref Unsafe.NullRef<T>(), error, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deconstruct(out bool success, out Ref<T> value, out E status)
|
||||||
|
{
|
||||||
|
success = IsSuccess;
|
||||||
|
value = new Ref<T>(ref Value);
|
||||||
|
status = Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() => $"Value: {_value}, Status: {_error}";
|
||||||
|
|
||||||
|
public static implicit operator RefResult<T, E>(Ref<T> data) => new(ref data.Get(), default, true);
|
||||||
|
public static implicit operator RefResult<T, E>(E error) => new(ref Unsafe.NullRef<T>(), error, false);
|
||||||
|
public static implicit operator bool(RefResult<T, E> result) => result.IsSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ResultExtensions
|
public static class ResultExtensions
|
||||||
{
|
{
|
||||||
public static void ThrowIfFailed(this ResultStatus result, [CallerArgumentExpression(nameof(result))] string? op = null)
|
public static void ThrowIfFailed(this ErrorStatus result, [CallerArgumentExpression(nameof(result))] string? op = null)
|
||||||
{
|
{
|
||||||
if (result != ResultStatus.Success)
|
if (result != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"{op} failed: {result}");
|
throw new InvalidOperationException($"{op} failed: {result}");
|
||||||
}
|
}
|
||||||
@@ -180,12 +220,12 @@ public static class ResultExtensions
|
|||||||
return result.Value;
|
return result.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T GetValueOrThrow<T, S>(this Result<T, S> result, S expect, [CallerArgumentExpression(nameof(result))] string? op = null)
|
public static T GetValueOrThrow<T, S>(this Result<T, S> result, [CallerArgumentExpression(nameof(result))] string? op = null)
|
||||||
where S : Enum
|
where S : struct, Enum
|
||||||
{
|
{
|
||||||
if (!EqualityComparer<S>.Default.Equals(result.Status, expect))
|
if (!result.IsSuccess)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"{op} failed: expected status {expect}, but got {result.Status}");
|
throw new InvalidOperationException($"{op} failed: status {result.Error}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.Value;
|
return result.Value;
|
||||||
@@ -196,10 +236,10 @@ public static class ResultExtensions
|
|||||||
return result.IsSuccess ? result.Value : defaultValue;
|
return result.IsSuccess ? result.Value : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T? GetValueOrDefault<T, S>(this Result<T, S> result, S expect, T? defaultValue = default)
|
public static T? GetValueOrDefault<T, S>(this Result<T, S> result, T? defaultValue = default)
|
||||||
where S : Enum
|
where S : struct, Enum
|
||||||
{
|
{
|
||||||
return (result.Status?.Equals(expect) ?? false) ? defaultValue : result.Value;
|
return result.IsSuccess ? result.Value : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetValue<T>(this Result<T> result, out T value)
|
public static bool TryGetValue<T>(this Result<T> result, out T value)
|
||||||
@@ -214,10 +254,10 @@ public static class ResultExtensions
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetValue<T, S>(this Result<T, S> result, S expect, out T value)
|
public static bool TryGetValue<T, S>(this Result<T, S> result, out T value)
|
||||||
where S : Enum
|
where S : struct, Enum
|
||||||
{
|
{
|
||||||
if (EqualityComparer<S>.Default.Equals(result.Status, expect))
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
value = result.Value;
|
value = result.Value;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
using Ghost.Test.Core;
|
using Ghost.Test.Core;
|
||||||
using Misaki.HighPerformance.Jobs;
|
using Misaki.HighPerformance.Jobs;
|
||||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
|
||||||
using Misaki.HighPerformance.Mathematics;
|
using Misaki.HighPerformance.Mathematics;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
namespace Ghost.Entities.Test;
|
namespace Ghost.Entities.Test;
|
||||||
|
|
||||||
internal struct TestEntityQueryJob : IJobEntity<Transform>
|
internal struct TestEntityQueryJob : IJobChunk
|
||||||
{
|
{
|
||||||
public readonly void Execute(Entity entity, ref Transform transform)
|
public void Execute(ChunkView view, int threadIndex)
|
||||||
{
|
{
|
||||||
transform.position += new float3(10, 10, 10);
|
var transforms = view.GetComponentData<Transform>();
|
||||||
|
for (var i = 0; i < view.Count; i++)
|
||||||
|
{
|
||||||
|
transforms[i].position += new float3(10, 10, 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,8 +25,6 @@ public partial class EntityTest : ITest
|
|||||||
{
|
{
|
||||||
_jobScheduler = new JobScheduler(4);
|
_jobScheduler = new JobScheduler(4);
|
||||||
_world = World.Create(_jobScheduler);
|
_world = World.Create(_jobScheduler);
|
||||||
|
|
||||||
Console.WriteLine(Unsafe.SizeOf<EntityQuery>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
@@ -39,7 +39,7 @@ public partial class EntityTest : ITest
|
|||||||
ref var query = ref _world.GetEntityQueryReference(queryID);
|
ref var query = ref _world.GetEntityQueryReference(queryID);
|
||||||
|
|
||||||
var testJob = new TestEntityQueryJob();
|
var testJob = new TestEntityQueryJob();
|
||||||
var handle = query.ScheduleEntityParallel<TestEntityQueryJob, Transform>(testJob, Allocator.Temp, 64, JobHandle.Invalid);
|
var handle = query.ScheduleChunkParallel(testJob, 64, JobHandle.Invalid);
|
||||||
_jobScheduler.WaitComplete(handle);
|
_jobScheduler.WaitComplete(handle);
|
||||||
|
|
||||||
query.ForEach<Transform>((e, ref t) =>
|
query.ForEach<Transform>((e, ref t) =>
|
||||||
|
|||||||
@@ -263,12 +263,12 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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);
|
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;
|
var offset = r.Value.offset;
|
||||||
@@ -280,14 +280,14 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
|
|||||||
|
|
||||||
MemoryUtility.MemCpy(dst, pComponent, (nuint)size);
|
MemoryUtility.MemCpy(dst, pComponent, (nuint)size);
|
||||||
|
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public readonly void* GetComponentData(int chunkIndex, int rowIndex, Identifier<IComponent> componentID)
|
public readonly void* GetComponentData(int chunkIndex, int rowIndex, Identifier<IComponent> componentID)
|
||||||
{
|
{
|
||||||
var r = GetLayout(componentID);
|
var r = GetLayout(componentID);
|
||||||
if (r.Status != ResultStatus.Success)
|
if (r.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -307,27 +307,27 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public readonly Result<ComponentMemoryLayout, ResultStatus> GetLayout(int componentID)
|
public readonly Result<ComponentMemoryLayout, ErrorStatus> GetLayout(int componentID)
|
||||||
{
|
{
|
||||||
if (componentID >= _componentIDToLayoutIndex.Count)
|
if (componentID >= _componentIDToLayoutIndex.Count)
|
||||||
{
|
{
|
||||||
return Result.Create(default(ComponentMemoryLayout), ResultStatus.InvalidArgument);
|
return ErrorStatus.InvalidArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
var layoutIndex = _componentIDToLayoutIndex[componentID];
|
var layoutIndex = _componentIDToLayoutIndex[componentID];
|
||||||
if (layoutIndex == -1)
|
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)
|
if (chunkIndex < 0 || chunkIndex >= _chunks.Count)
|
||||||
{
|
{
|
||||||
return ResultStatus.InvalidArgument;
|
return ErrorStatus.InvalidArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
ref var chunk = ref _chunks[chunkIndex];
|
ref var chunk = ref _chunks[chunkIndex];
|
||||||
@@ -341,13 +341,13 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
|
|||||||
var pRowEntity = chunkBase + _entityIdsOffset + (sizeof(Entity) * rowIndex);
|
var pRowEntity = chunkBase + _entityIdsOffset + (sizeof(Entity) * rowIndex);
|
||||||
|
|
||||||
var wroldResult = World.GetWorld(_worldID);
|
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);
|
var result = wroldResult.Value.EntityManager.UpdateEntityLocation(*(Entity*)pLastEntity, _id, chunkIndex, rowIndex);
|
||||||
if (result != ResultStatus.Success)
|
if (result != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -367,7 +367,7 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
chunk.Count--;
|
chunk.Count--;
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
@@ -102,14 +102,16 @@ public unsafe class EntityCommandBuffer : IDisposable
|
|||||||
return bufferPtr;
|
return bufferPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateEntity()
|
public void CreateEntity(int count = 1)
|
||||||
{
|
{
|
||||||
WriteHeader(ECBOpCode.CreateEntity);
|
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);
|
WriteHeader(ECBOpCode.CreateEntityWithComponents);
|
||||||
|
Write(count);
|
||||||
Write(componentTypeIDs.Length);
|
Write(componentTypeIDs.Length);
|
||||||
WriteSpan(componentTypeIDs);
|
WriteSpan(componentTypeIDs);
|
||||||
}
|
}
|
||||||
@@ -150,23 +152,23 @@ public unsafe class EntityCommandBuffer : IDisposable
|
|||||||
{
|
{
|
||||||
var cursor = 0;
|
var cursor = 0;
|
||||||
var length = _buffer.Count;
|
var length = _buffer.Count;
|
||||||
var ptr = (byte*)_buffer.GetUnsafePtr();
|
|
||||||
|
|
||||||
while (cursor < length)
|
while (cursor < length)
|
||||||
{
|
{
|
||||||
var op = *(ECBOpCode*)ptr[cursor];
|
var op = Read<ECBOpCode>(ref cursor);
|
||||||
cursor += sizeof(ECBOpCode);
|
|
||||||
|
|
||||||
switch (op)
|
switch (op)
|
||||||
{
|
{
|
||||||
case ECBOpCode.CreateEntity:
|
case ECBOpCode.CreateEntity:
|
||||||
_entityManager.CreateEntity();
|
var count = Read<int>(ref cursor);
|
||||||
|
_entityManager.CreateEntities(count);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECBOpCode.CreateEntityWithComponents:
|
case ECBOpCode.CreateEntityWithComponents:
|
||||||
|
var entityCount = Read<int>(ref cursor);
|
||||||
var compCount = Read<int>(ref cursor);
|
var compCount = Read<int>(ref cursor);
|
||||||
var compTypeIDs = ReadSpan<Identifier<IComponent>>(ref cursor, compCount);
|
var compTypeIDs = ReadSpan<Identifier<IComponent>>(ref cursor, compCount);
|
||||||
_entityManager.CreateEntity(compTypeIDs);
|
_entityManager.CreateEntities(entityCount, compTypeIDs);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECBOpCode.DestroyEntity:
|
case ECBOpCode.DestroyEntity:
|
||||||
|
|||||||
@@ -6,6 +6,14 @@ using System.Diagnostics;
|
|||||||
|
|
||||||
namespace Ghost.Entities;
|
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
|
public unsafe partial class EntityManager : IDisposable
|
||||||
{
|
{
|
||||||
private struct EntityLocation
|
private struct EntityLocation
|
||||||
@@ -30,19 +38,19 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
Dispose();
|
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);
|
ref var location = ref _entityLocations.GetElementReferenceAt(entity.ID, entity.Generation, out var exist);
|
||||||
if (!exist)
|
if (!exist)
|
||||||
{
|
{
|
||||||
return ResultStatus.NotFound;
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
location.archetypeID = newArchetypeID;
|
location.archetypeID = newArchetypeID;
|
||||||
location.chunkIndex = newChunkIndex;
|
location.chunkIndex = newChunkIndex;
|
||||||
location.rowIndex = newRowIndex;
|
location.rowIndex = newRowIndex;
|
||||||
|
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -51,21 +59,10 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
/// <returns>The created entity.</returns>
|
/// <returns>The created entity.</returns>
|
||||||
public Entity CreateEntity()
|
public Entity CreateEntity()
|
||||||
{
|
{
|
||||||
// Put into empty archetype
|
var entities = (Span<Entity>)stackalloc Entity[1];
|
||||||
ref var emptyArchetype = ref _world.GetArchetypeReference(World.EmptyArchetypeID);
|
CreateEntities(1, entities);
|
||||||
emptyArchetype.AllocateEntity(out var chunkIndex, out var rowIndex);
|
|
||||||
|
|
||||||
var id = _entityLocations.Add(new EntityLocation
|
return entities[0];
|
||||||
{
|
|
||||||
archetypeID = World.EmptyArchetypeID,
|
|
||||||
chunkIndex = chunkIndex,
|
|
||||||
rowIndex = rowIndex
|
|
||||||
}, out var generation);
|
|
||||||
|
|
||||||
var entity = new Entity(id, generation);
|
|
||||||
emptyArchetype.SetEntity(chunkIndex, rowIndex, entity);
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -75,28 +72,59 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
/// <returns>The created entity.</returns>
|
/// <returns>The created entity.</returns>
|
||||||
public Entity CreateEntity(params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
|
public Entity CreateEntity(params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
|
||||||
{
|
{
|
||||||
var signatureHash = ComponentRegister.GetHashCode(componentTypeIDs);
|
var entities = (Span<Entity>)stackalloc Entity[1];
|
||||||
var arcID = _world.GetArchetypeIDBySignatureHash(signatureHash);
|
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);
|
/// <summary>
|
||||||
archetype.AllocateEntity(out var chunkIndex, out var rowIndex);
|
/// 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,
|
var id = _entityLocations.Add(new EntityLocation
|
||||||
chunkIndex = chunkIndex,
|
{
|
||||||
rowIndex = rowIndex
|
archetypeID = World.EmptyArchetypeID,
|
||||||
}, out var generation);
|
chunkIndex = chunkIndex,
|
||||||
|
rowIndex = rowIndex
|
||||||
|
}, out var generation);
|
||||||
|
|
||||||
var entity = new Entity(id, generation);
|
var entity = new Entity(id, generation);
|
||||||
archetype.SetEntity(chunkIndex, rowIndex, entity);
|
emptyArchetype.SetEntity(chunkIndex, rowIndex, entity);
|
||||||
|
}
|
||||||
return entity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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="allocator">The allocator to use for the returned array.</param>
|
||||||
/// <param name="componentTypeIDs">The component type IDs to add to the entities. </param>
|
/// <param name="componentTypeIDs">The component type IDs to add to the entities. </param>
|
||||||
/// <returns>An array of the created entities.</returns>
|
/// <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 signatureHash = ComponentRegister.GetHashCode(componentTypeIDs);
|
||||||
var arcID = _world.GetArchetypeIDBySignatureHash(signatureHash);
|
var arcID = _world.GetArchetypeIDBySignatureHash(signatureHash);
|
||||||
@@ -118,7 +146,6 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
|
|
||||||
ref var archetype = ref _world.GetArchetypeReference(arcID);
|
ref var archetype = ref _world.GetArchetypeReference(arcID);
|
||||||
|
|
||||||
var entities = new UnsafeArray<Entity>(count, allocator);
|
|
||||||
for (var i = 0; i < count; i++)
|
for (var i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
archetype.AllocateEntity(out var chunkIndex, out var rowIndex);
|
archetype.AllocateEntity(out var chunkIndex, out var rowIndex);
|
||||||
@@ -135,8 +162,6 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
|
|
||||||
entities[i] = entity;
|
entities[i] = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
return entities;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -176,26 +201,26 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
/// Destroy the specified entity.
|
/// Destroy the specified entity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <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))
|
if (!_entityLocations.TryGetElementAt(entity.ID, entity.Generation, out var location))
|
||||||
{
|
{
|
||||||
return ResultStatus.NotFound;
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
ref var archetype = ref _world.GetArchetypeReference(location.archetypeID);
|
ref var archetype = ref _world.GetArchetypeReference(location.archetypeID);
|
||||||
var r = archetype.RemoveEntity(location.chunkIndex, location.rowIndex);
|
var r = archetype.RemoveEntity(location.chunkIndex, location.rowIndex);
|
||||||
if (r != ResultStatus.Success)
|
if (r != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_entityLocations.Remove(entity.ID, entity.Generation))
|
if (!_entityLocations.Remove(entity.ID, entity.Generation))
|
||||||
{
|
{
|
||||||
return ResultStatus.NotFound;
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -214,11 +239,11 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
/// <param name="componentID">The component type ID of the singleton.</param>
|
/// <param name="componentID">The component type ID of the singleton.</param>
|
||||||
/// <param name="pComponent">Pointer to the component data.</param>
|
/// <param name="pComponent">Pointer to the component data.</param>
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <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)
|
if (pComponent == null)
|
||||||
{
|
{
|
||||||
return ResultStatus.InvalidArgument;
|
return ErrorStatus.InvalidArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if singleton already exists
|
// Check if singleton already exists
|
||||||
@@ -227,7 +252,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
|
|
||||||
if (arcID.IsValid)
|
if (arcID.IsValid)
|
||||||
{
|
{
|
||||||
return ResultStatus.InvalidArgument;
|
return ErrorStatus.InvalidArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
arcID = _world.CreateArchetype([componentID], signatureHash);
|
arcID = _world.CreateArchetype([componentID], signatureHash);
|
||||||
@@ -246,7 +271,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
archetype.SetEntity(chunkIndex, rowIndex, entity);
|
archetype.SetEntity(chunkIndex, rowIndex, entity);
|
||||||
archetype.SetComponentData(chunkIndex, rowIndex, componentID, pComponent);
|
archetype.SetComponentData(chunkIndex, rowIndex, componentID, pComponent);
|
||||||
|
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -255,7 +280,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
/// <typeparam name="T">The component type.</typeparam>
|
/// <typeparam name="T">The component type.</typeparam>
|
||||||
/// <param name="component">The component data.</param>
|
/// <param name="component">The component data.</param>
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <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
|
where T : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
return CreateSingleton(ComponentTypeID<T>.value, &component);
|
return CreateSingleton(ComponentTypeID<T>.value, &component);
|
||||||
@@ -278,7 +303,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
|
|
||||||
ref var archetype = ref _world.GetArchetypeReference(arcID);
|
ref var archetype = ref _world.GetArchetypeReference(arcID);
|
||||||
var layoutResult = archetype.GetLayout(componentID);
|
var layoutResult = archetype.GetLayout(componentID);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (layoutResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -311,8 +336,8 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
|
|
||||||
var src = oldArch._chunks[oldChunk].GetUnsafePtr() + layout.offset + (layout.size * oldRow);
|
var src = oldArch._chunks[oldChunk].GetUnsafePtr() + layout.offset + (layout.size * oldRow);
|
||||||
var r = newArch.GetLayout(layout.componentID);
|
var r = newArch.GetLayout(layout.componentID);
|
||||||
Debug.Assert(r.Status == ResultStatus.Success); // This should always be true if the system is consistent.
|
Debug.Assert(r.Error == ErrorStatus.None); // This should always be true if the system is consistent.
|
||||||
if (r.Status != ResultStatus.Success)
|
if (r.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -330,13 +355,13 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
/// <param name="componentID">The component type ID to add.</param>
|
/// <param name="componentID">The component type ID to add.</param>
|
||||||
/// <param name="pComponent">Pointer to the component data.</param>
|
/// <param name="pComponent">Pointer to the component data.</param>
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <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
|
// Find current location
|
||||||
ref var location = ref _entityLocations.GetElementReferenceAt(entity.ID, entity.Generation, out var exist);
|
ref var location = ref _entityLocations.GetElementReferenceAt(entity.ID, entity.Generation, out var exist);
|
||||||
if (!exist)
|
if (!exist)
|
||||||
{
|
{
|
||||||
return ResultStatus.NotFound;
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build new archetype signature
|
// Build new archetype signature
|
||||||
@@ -397,8 +422,8 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
newArchetype.SetComponentData(newChunkIndex, newRowIndex, componentID, pComponent);
|
newArchetype.SetComponentData(newChunkIndex, newRowIndex, componentID, pComponent);
|
||||||
|
|
||||||
var r = oldArchetype.RemoveEntity(location.chunkIndex, location.rowIndex);
|
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.
|
Debug.Assert(r == ErrorStatus.None); // We assert it because the entity should exist if the whole system is consistent.
|
||||||
if (r != ResultStatus.Success)
|
if (r != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -408,7 +433,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
location.chunkIndex = newChunkIndex;
|
location.chunkIndex = newChunkIndex;
|
||||||
location.rowIndex = newRowIndex;
|
location.rowIndex = newRowIndex;
|
||||||
|
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -418,7 +443,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
/// <param name="entity">The entity to add the component to.</param>
|
/// <param name="entity">The entity to add the component to.</param>
|
||||||
/// <param name="component">The component data.</param>
|
/// <param name="component">The component data.</param>
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <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
|
where T : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
return AddComponent(entity, ComponentTypeID<T>.value, &component);
|
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="entity">The entity to remove the component from.</param>
|
||||||
/// <param name="componentID">The component type ID to remove.</param>
|
/// <param name="componentID">The component type ID to remove.</param>
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <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
|
// Find current location
|
||||||
ref var location = ref _entityLocations.GetElementReferenceAt(entity.ID, entity.Generation, out var exist);
|
ref var location = ref _entityLocations.GetElementReferenceAt(entity.ID, entity.Generation, out var exist);
|
||||||
if (!exist)
|
if (!exist)
|
||||||
{
|
{
|
||||||
return ResultStatus.NotFound;
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build new archetype signature
|
// Build new archetype signature
|
||||||
@@ -492,8 +517,8 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
newArchetype.SetEntity(newChunkIndex, newRowIndex, entity);
|
newArchetype.SetEntity(newChunkIndex, newRowIndex, entity);
|
||||||
|
|
||||||
var r = oldArchetype.RemoveEntity(location.chunkIndex, location.rowIndex);
|
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.
|
Debug.Assert(r == ErrorStatus.None); // We assert it because the entity should exist if the whole system is consistent.
|
||||||
if (r != ResultStatus.Success)
|
if (r != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -503,7 +528,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
location.chunkIndex = newChunkIndex;
|
location.chunkIndex = newChunkIndex;
|
||||||
location.rowIndex = newRowIndex;
|
location.rowIndex = newRowIndex;
|
||||||
|
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -512,7 +537,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
/// <typeparam name="T">The component type.</typeparam>
|
/// <typeparam name="T">The component type.</typeparam>
|
||||||
/// <param name="entity">The entity to remove the component from.</param>
|
/// <param name="entity">The entity to remove the component from.</param>
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <returns>The result status of the operation.</returns>
|
||||||
public ResultStatus RemoveComponent<T>(Entity entity)
|
public ErrorStatus RemoveComponent<T>(Entity entity)
|
||||||
where T : unmanaged, IComponent
|
where T : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
return RemoveComponent(entity, ComponentTypeID<T>.value);
|
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="componentID">The component type ID to set.</param>
|
||||||
/// <param name="pComponent">Pointer to the component data.</param>
|
/// <param name="pComponent">Pointer to the component data.</param>
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <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))
|
if (!_entityLocations.TryGetElementAt(entity.ID, entity.Generation, out var location))
|
||||||
{
|
{
|
||||||
return ResultStatus.NotFound;
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
ref var archetype = ref _world.GetArchetypeReference(location.archetypeID);
|
ref var archetype = ref _world.GetArchetypeReference(location.archetypeID);
|
||||||
archetype.SetComponentData(location.chunkIndex, location.rowIndex, componentID, pComponent);
|
archetype.SetComponentData(location.chunkIndex, location.rowIndex, componentID, pComponent);
|
||||||
|
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -544,7 +569,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
/// <typeparam name="T">The component type.</typeparam>
|
/// <typeparam name="T">The component type.</typeparam>
|
||||||
/// <param name="entity">The entity to set the component data for.</param>
|
/// <param name="entity">The entity to set the component data for.</param>
|
||||||
/// <param name="component">The component data.</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
|
where T : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
return SetComponent(entity, ComponentTypeID<T>.value, &component);
|
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="componentID">The component type ID of the enableable component.</
|
||||||
/// <param name="enabled">True to enable the component, false to disable it.</param>
|
/// <param name="enabled">True to enable the component, false to disable it.</param>
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <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))
|
if (!_entityLocations.TryGetElementAt(entity.ID, entity.Generation, out var location))
|
||||||
{
|
{
|
||||||
return ResultStatus.NotFound;
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
ref var archetype = ref _world.GetArchetypeReference(location.archetypeID);
|
ref var archetype = ref _world.GetArchetypeReference(location.archetypeID);
|
||||||
@@ -628,9 +653,9 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
var rowIndex = location.rowIndex;
|
var rowIndex = location.rowIndex;
|
||||||
|
|
||||||
var layoutResult = archetype.GetLayout(componentID);
|
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);
|
ref var chunk = ref archetype.GetChunkReference(chunkIndex);
|
||||||
@@ -649,7 +674,7 @@ public unsafe partial class EntityManager : IDisposable
|
|||||||
maskBase[byteIndex] &= (byte)~(1 << bitIndex);
|
maskBase[byteIndex] &= (byte)~(1 << bitIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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="entity">The entity to set the enabled state for.</param>
|
||||||
/// <param name="enabled">True to enable the component, false to disable it.</
|
/// <param name="enabled">True to enable the component, false to disable it.</
|
||||||
/// <returns>The result status of the operation.</returns>
|
/// <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
|
where T : unmanaged, IEnableableComponent
|
||||||
{
|
{
|
||||||
return SetEnabled(entity, ComponentTypeID<T>.value, enabled);
|
return SetEnabled(entity, ComponentTypeID<T>.value, enabled);
|
||||||
|
|||||||
87
Ghost.Entities/EntityQuery.JobChunk.cs
Normal file
87
Ghost.Entities/EntityQuery.JobChunk.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>
|
private readonly ReadOnlyUnsafeCollection<Archetype.ComponentMemoryLayout> _layouts;
|
||||||
/// Provides a read-only view over a chunk of entities and their component data within an archetype.
|
private readonly byte* _pChunkData;
|
||||||
/// </summary>
|
private readonly int _entityOffset;
|
||||||
/// <remarks>This does not filter disabled/enabled components. You must handle that manually.</remarks>
|
private readonly int _entityCount;
|
||||||
public readonly ref struct ChunkView
|
|
||||||
|
public readonly int Count => _entityCount;
|
||||||
|
|
||||||
|
internal ChunkView(ReadOnlyUnsafeCollection<Archetype.ComponentMemoryLayout> layouts, byte* pChunkData, int entityOffset, int entityCount)
|
||||||
{
|
{
|
||||||
private readonly ref Archetype _archetype;
|
_layouts = layouts;
|
||||||
private readonly ref Chunk _chunk;
|
_pChunkData = pChunkData;
|
||||||
|
_entityOffset = entityOffset;
|
||||||
public readonly int Count => _chunk.Count;
|
_entityCount = entityCount;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>
|
/// <summary>
|
||||||
/// Provides an enumerator for iterating over chunks of entities and their component data that match a set of archetypes within a world.
|
/// Provides an enumerator for iterating over chunks of entities and their component data that match a set of archetypes within a world.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -182,7 +193,8 @@ public unsafe partial struct EntityQuery : IIdentifierType, IDisposable
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
ref var archetype = ref _iterator._world.GetArchetypeReference(_iterator._matchingArchetypes[_archetypeIndex]);
|
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
|
// Get the EnableBitmask for this component in this chunk
|
||||||
var layoutResult = archetype.GetLayout(id);
|
var layoutResult = archetype.GetLayout(id);
|
||||||
if (layoutResult.Status != ResultStatus.Success
|
if (layoutResult.Error != ErrorStatus.None
|
||||||
// Not enableable, always true
|
// Not enableable, always true
|
||||||
|| layoutResult.Value.enableBitsOffset == -1)
|
|| layoutResult.Value.enableBitsOffset == -1)
|
||||||
{
|
{
|
||||||
@@ -269,7 +281,7 @@ public unsafe partial struct EntityQuery : IIdentifierType, IDisposable
|
|||||||
while (it.Next(out var id))
|
while (it.Next(out var id))
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(id);
|
var layoutResult = archetype.GetLayout(id);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (layoutResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -290,7 +302,7 @@ public unsafe partial struct EntityQuery : IIdentifierType, IDisposable
|
|||||||
while (it.Next(out var id))
|
while (it.Next(out var id))
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(id);
|
var layoutResult = archetype.GetLayout(id);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (layoutResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 1; index++)
|
for (var index = 0; index < 1; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,6 @@ public unsafe partial struct EntityQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||||
@@ -147,10 +146,9 @@ public unsafe partial struct EntityQuery
|
|||||||
public readonly ComponentIterator<T0> GetComponentIterator<T0>()
|
public readonly ComponentIterator<T0> GetComponentIterator<T0>()
|
||||||
where T0 : unmanaged, IComponent
|
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>
|
public readonly ref struct ComponentIterator<T0, T1>
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
@@ -223,7 +221,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 2; index++)
|
for (var index = 0; index < 2; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -293,7 +291,6 @@ public unsafe partial struct EntityQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||||
@@ -317,10 +314,9 @@ public unsafe partial struct EntityQuery
|
|||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : 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>
|
public readonly ref struct ComponentIterator<T0, T1, T2>
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
@@ -402,7 +398,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 3; index++)
|
for (var index = 0; index < 3; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -472,7 +468,6 @@ public unsafe partial struct EntityQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||||
@@ -497,10 +492,9 @@ public unsafe partial struct EntityQuery
|
|||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
where T2 : 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>
|
public readonly ref struct ComponentIterator<T0, T1, T2, T3>
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
@@ -591,7 +585,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 4; index++)
|
for (var index = 0; index < 4; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -661,7 +655,6 @@ public unsafe partial struct EntityQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||||
@@ -687,10 +680,9 @@ public unsafe partial struct EntityQuery
|
|||||||
where T2 : unmanaged, IComponent
|
where T2 : unmanaged, IComponent
|
||||||
where T3 : 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>
|
public readonly ref struct ComponentIterator<T0, T1, T2, T3, T4>
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
@@ -790,7 +782,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 5; index++)
|
for (var index = 0; index < 5; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -860,7 +852,6 @@ public unsafe partial struct EntityQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||||
@@ -887,10 +878,9 @@ public unsafe partial struct EntityQuery
|
|||||||
where T3 : unmanaged, IComponent
|
where T3 : unmanaged, IComponent
|
||||||
where T4 : 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>
|
public readonly ref struct ComponentIterator<T0, T1, T2, T3, T4, T5>
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
@@ -999,7 +989,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 6; index++)
|
for (var index = 0; index < 6; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -1069,7 +1059,6 @@ public unsafe partial struct EntityQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||||
@@ -1097,10 +1086,9 @@ public unsafe partial struct EntityQuery
|
|||||||
where T4 : unmanaged, IComponent
|
where T4 : unmanaged, IComponent
|
||||||
where T5 : 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>
|
public readonly ref struct ComponentIterator<T0, T1, T2, T3, T4, T5, T6>
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
@@ -1218,7 +1206,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 7; index++)
|
for (var index = 0; index < 7; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -1288,7 +1276,6 @@ public unsafe partial struct EntityQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||||
@@ -1317,10 +1304,9 @@ public unsafe partial struct EntityQuery
|
|||||||
where T5 : unmanaged, IComponent
|
where T5 : unmanaged, IComponent
|
||||||
where T6 : 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>
|
public readonly ref struct ComponentIterator<T0, T1, T2, T3, T4, T5, T6, T7>
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
@@ -1447,7 +1433,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 8; index++)
|
for (var index = 0; index < 8; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -1517,7 +1503,6 @@ public unsafe partial struct EntityQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||||
@@ -1547,8 +1532,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T6 : unmanaged, IComponent
|
where T6 : unmanaged, IComponent
|
||||||
where T7 : 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < <#= i #>; index++)
|
for (var index = 0; index < <#= i #>; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,7 @@ public unsafe partial struct EntityQuery
|
|||||||
public readonly ComponentIterator<<#= generics#>> GetComponentIterator<<#= generics#>>()
|
public readonly ComponentIterator<<#= generics#>> GetComponentIterator<<#= generics#>>()
|
||||||
<#= restrictions #>
|
<#= 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
<# } #>
|
<# } #>
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 1; index++)
|
for (var index = 0; index < 1; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ public unsafe partial struct EntityQuery
|
|||||||
public readonly EntityComponentIterator<T0> GetEntityComponentIterator<T0>()
|
public readonly EntityComponentIterator<T0> GetEntityComponentIterator<T0>()
|
||||||
where T0 : unmanaged, IComponent
|
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>
|
public readonly ref struct EntityComponentIterator<T0, T1>
|
||||||
@@ -251,7 +251,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 2; index++)
|
for (var index = 0; index < 2; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -344,7 +344,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : 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>
|
public readonly ref struct EntityComponentIterator<T0, T1, T2>
|
||||||
@@ -435,7 +435,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 3; index++)
|
for (var index = 0; index < 3; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -529,7 +529,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
where T2 : 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>
|
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++)
|
for (var index = 0; index < 4; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -724,7 +724,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T2 : unmanaged, IComponent
|
where T2 : unmanaged, IComponent
|
||||||
where T3 : 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>
|
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++)
|
for (var index = 0; index < 5; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -929,7 +929,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T3 : unmanaged, IComponent
|
where T3 : unmanaged, IComponent
|
||||||
where T4 : 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>
|
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++)
|
for (var index = 0; index < 6; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -1144,7 +1144,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T4 : unmanaged, IComponent
|
where T4 : unmanaged, IComponent
|
||||||
where T5 : 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>
|
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++)
|
for (var index = 0; index < 7; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -1369,7 +1369,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T5 : unmanaged, IComponent
|
where T5 : unmanaged, IComponent
|
||||||
where T6 : 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>
|
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++)
|
for (var index = 0; index < 8; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -1604,7 +1604,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T6 : unmanaged, IComponent
|
where T6 : unmanaged, IComponent
|
||||||
where T7 : 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < <#= i #>; index++)
|
for (var index = 0; index < <#= i #>; index++)
|
||||||
{
|
{
|
||||||
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
var layout = _currentArchetype.GetLayout(_compTypeIDs[index])
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
_offsets[index] = layout.offset;
|
_offsets[index] = layout.offset;
|
||||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ public unsafe partial struct EntityQuery
|
|||||||
public readonly EntityComponentIterator<<#= generics#>> GetEntityComponentIterator<<#= generics#>>()
|
public readonly EntityComponentIterator<<#= generics#>> GetEntityComponentIterator<<#= generics#>>()
|
||||||
<#= restrictions #>
|
<#= 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
<# } #>
|
<# } #>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
using Ghost.Core;
|
using Ghost.Core;
|
||||||
|
|
||||||
namespace Ghost.Entities;
|
namespace Ghost.Entities;
|
||||||
@@ -8,7 +7,7 @@ public unsafe partial struct EntityQuery
|
|||||||
public readonly void ForEach<T0>(ForEach<T0> action)
|
public readonly void ForEach<T0>(ForEach<T0> action)
|
||||||
where T0 : unmanaged, IComponent
|
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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value };
|
||||||
var offsets = stackalloc int[1];
|
var offsets = stackalloc int[1];
|
||||||
@@ -21,7 +20,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 1; index++)
|
for (var index = 0; index < 1; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -64,7 +63,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : 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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value };
|
||||||
var offsets = stackalloc int[2];
|
var offsets = stackalloc int[2];
|
||||||
@@ -77,7 +76,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 2; index++)
|
for (var index = 0; index < 2; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -122,7 +121,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
where T2 : 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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value };
|
||||||
var offsets = stackalloc int[3];
|
var offsets = stackalloc int[3];
|
||||||
@@ -135,7 +134,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 3; index++)
|
for (var index = 0; index < 3; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -182,7 +181,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T2 : unmanaged, IComponent
|
where T2 : unmanaged, IComponent
|
||||||
where T3 : 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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value };
|
||||||
var offsets = stackalloc int[4];
|
var offsets = stackalloc int[4];
|
||||||
@@ -195,7 +194,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 4; index++)
|
for (var index = 0; index < 4; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -244,7 +243,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T3 : unmanaged, IComponent
|
where T3 : unmanaged, IComponent
|
||||||
where T4 : 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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value };
|
||||||
var offsets = stackalloc int[5];
|
var offsets = stackalloc int[5];
|
||||||
@@ -257,7 +256,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 5; index++)
|
for (var index = 0; index < 5; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -308,7 +307,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T4 : unmanaged, IComponent
|
where T4 : unmanaged, IComponent
|
||||||
where T5 : 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 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];
|
var offsets = stackalloc int[6];
|
||||||
@@ -321,7 +320,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 6; index++)
|
for (var index = 0; index < 6; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -374,7 +373,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T5 : unmanaged, IComponent
|
where T5 : unmanaged, IComponent
|
||||||
where T6 : 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 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];
|
var offsets = stackalloc int[7];
|
||||||
@@ -387,7 +386,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 7; index++)
|
for (var index = 0; index < 7; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -442,7 +441,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T6 : unmanaged, IComponent
|
where T6 : unmanaged, IComponent
|
||||||
where T7 : 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 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];
|
var offsets = stackalloc int[8];
|
||||||
@@ -455,7 +454,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 8; index++)
|
for (var index = 0; index < 8; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -504,7 +503,7 @@ public unsafe partial struct EntityQuery
|
|||||||
public readonly void ForEach<T0>(ForEachWithEntity<T0> action)
|
public readonly void ForEach<T0>(ForEachWithEntity<T0> action)
|
||||||
where T0 : unmanaged, IComponent
|
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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value };
|
||||||
var offsets = stackalloc int[1];
|
var offsets = stackalloc int[1];
|
||||||
@@ -517,7 +516,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 1; index++)
|
for (var index = 0; index < 1; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -561,7 +560,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : 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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value };
|
||||||
var offsets = stackalloc int[2];
|
var offsets = stackalloc int[2];
|
||||||
@@ -574,7 +573,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 2; index++)
|
for (var index = 0; index < 2; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -620,7 +619,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
where T2 : 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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value };
|
||||||
var offsets = stackalloc int[3];
|
var offsets = stackalloc int[3];
|
||||||
@@ -633,7 +632,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 3; index++)
|
for (var index = 0; index < 3; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -681,7 +680,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T2 : unmanaged, IComponent
|
where T2 : unmanaged, IComponent
|
||||||
where T3 : 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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value };
|
||||||
var offsets = stackalloc int[4];
|
var offsets = stackalloc int[4];
|
||||||
@@ -694,7 +693,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 4; index++)
|
for (var index = 0; index < 4; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -744,7 +743,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T3 : unmanaged, IComponent
|
where T3 : unmanaged, IComponent
|
||||||
where T4 : 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 compTypeIDs = stackalloc int[] { ComponentTypeID<T0>.value, ComponentTypeID<T1>.value, ComponentTypeID<T2>.value, ComponentTypeID<T3>.value, ComponentTypeID<T4>.value };
|
||||||
var offsets = stackalloc int[5];
|
var offsets = stackalloc int[5];
|
||||||
@@ -757,7 +756,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 5; index++)
|
for (var index = 0; index < 5; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -809,7 +808,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T4 : unmanaged, IComponent
|
where T4 : unmanaged, IComponent
|
||||||
where T5 : 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 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];
|
var offsets = stackalloc int[6];
|
||||||
@@ -822,7 +821,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 6; index++)
|
for (var index = 0; index < 6; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -876,7 +875,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T5 : unmanaged, IComponent
|
where T5 : unmanaged, IComponent
|
||||||
where T6 : 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 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];
|
var offsets = stackalloc int[7];
|
||||||
@@ -889,7 +888,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 7; index++)
|
for (var index = 0; index < 7; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -945,7 +944,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T6 : unmanaged, IComponent
|
where T6 : unmanaged, IComponent
|
||||||
where T7 : 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 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];
|
var offsets = stackalloc int[8];
|
||||||
@@ -958,7 +957,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < 8; index++)
|
for (var index = 0; index < 8; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -1005,4 +1004,4 @@ public unsafe partial struct EntityQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ public unsafe partial struct EntityQuery
|
|||||||
#>
|
#>
|
||||||
<# for (var i = 1; i <= Amount; i++)
|
<# for (var i = 1; i <= Amount; i++)
|
||||||
{
|
{
|
||||||
var generics = AppendGenerics(i);
|
var generics = AppendParameters(i, "T{0}");
|
||||||
var compGenerics = AppendGenericRefParameters(i);
|
|
||||||
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 2);
|
var restrictions = AppendGenericRestrictionsMultiline(i, "unmanaged, IComponent", 2);
|
||||||
|
|
||||||
var delegateTupe = isForEachWithEntity ? "ForEachWithEntity" : "ForEach";
|
var delegateTupe = isForEachWithEntity ? "ForEachWithEntity" : "ForEach";
|
||||||
@@ -25,7 +24,7 @@ public unsafe partial struct EntityQuery
|
|||||||
public readonly void ForEach<<#= generics #>>(<#= delegateTupe #><<#= generics #>> action)
|
public readonly void ForEach<<#= generics #>>(<#= delegateTupe #><<#= generics #>> action)
|
||||||
<#= restrictions #>
|
<#= 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 compTypeIDs = stackalloc int[] { <#= AppendGenerics(i, "ComponentTypeID<T{0}>.value") #> };
|
||||||
var offsets = stackalloc int[<#= i #>];
|
var offsets = stackalloc int[<#= i #>];
|
||||||
@@ -38,7 +37,7 @@ public unsafe partial struct EntityQuery
|
|||||||
for (var index = 0; index < <#= i #>; index++)
|
for (var index = 0; index < <#= i #>; index++)
|
||||||
{
|
{
|
||||||
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
var layoutResult = archetype.GetLayout(compTypeIDs[index]);
|
||||||
if (layoutResult.Status != ResultStatus.Success)
|
if (!layoutResult)
|
||||||
{
|
{
|
||||||
hasAllComponents = false;
|
hasAllComponents = false;
|
||||||
break;
|
break;
|
||||||
@@ -75,9 +74,9 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
<# if (isForEachWithEntity) { #>
|
<# if (isForEachWithEntity) { #>
|
||||||
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
var pEntity = (Entity*)(pChunkData + archetype.EntityIDsOffset + (sizeof(Entity) * entityIndex));
|
||||||
action(*pEntity, <#= AppendRefParameters(i, "*pComp{0}") #>);
|
action(*pEntity, <#= AppendParameters(i, "ref *pComp{0}") #>);
|
||||||
<# } else { #>
|
<# } else { #>
|
||||||
action(<#= AppendRefParameters(i, "*pComp{0}") #>);
|
action(<#= AppendParameters(i, "ref *pComp{0}") #>);
|
||||||
<# } #>
|
<# } #>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,4 +85,4 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
<# } #>
|
<# } #>
|
||||||
<# } #>
|
<# } #>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace Ghost.Entities;
|
|||||||
public interface IJobEntity<T0>
|
public interface IJobEntity<T0>
|
||||||
where T0 : unmanaged, IComponent
|
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
|
internal unsafe struct JobEntityBatch<TJob, T0> : IJobParallelFor
|
||||||
@@ -43,7 +43,7 @@ internal unsafe struct JobEntityBatch<TJob, T0> : IJobParallelFor
|
|||||||
continue;
|
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 T0 : unmanaged, IComponent
|
||||||
where T1 : 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
|
internal unsafe struct JobEntityBatch<TJob, T0, T1> : IJobParallelFor
|
||||||
@@ -100,7 +100,7 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1> : IJobParallelFor
|
|||||||
continue;
|
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 T1 : unmanaged, IComponent
|
||||||
where T2 : 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
|
internal unsafe struct JobEntityBatch<TJob, T0, T1, T2> : IJobParallelFor
|
||||||
@@ -171,7 +171,7 @@ internal unsafe struct JobEntityBatch<TJob, T0, T1, T2> : IJobParallelFor
|
|||||||
continue;
|
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 T2 : unmanaged, IComponent
|
||||||
where T3 : 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
|
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;
|
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 T3 : unmanaged, IComponent
|
||||||
where T4 : 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
|
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;
|
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 T4 : unmanaged, IComponent
|
||||||
where T5 : 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
|
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;
|
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 T5 : unmanaged, IComponent
|
||||||
where T6 : 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
|
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;
|
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 T6 : unmanaged, IComponent
|
||||||
where T7 : 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
|
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;
|
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 TJob : unmanaged, IJobEntity<T0>
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||||
|
|
||||||
// 1. Flatten the World
|
// 1. Flatten the World
|
||||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||||
@@ -790,7 +790,7 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
// Get offsets ONCE per archetype
|
// Get offsets ONCE per archetype
|
||||||
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
|
|
||||||
// Add all chunks from this archetype
|
// Add all chunks from this archetype
|
||||||
for (var i = 0; i < arch.ChunkCount; i++)
|
for (var i = 0; i < arch.ChunkCount; i++)
|
||||||
@@ -871,7 +871,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent
|
||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||||
|
|
||||||
// 1. Flatten the World
|
// 1. Flatten the World
|
||||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||||
@@ -896,9 +896,9 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
// Get offsets ONCE per archetype
|
// Get offsets ONCE per archetype
|
||||||
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
|
|
||||||
// Add all chunks from this archetype
|
// Add all chunks from this archetype
|
||||||
for (var i = 0; i < arch.ChunkCount; i++)
|
for (var i = 0; i < arch.ChunkCount; i++)
|
||||||
@@ -995,7 +995,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T1 : unmanaged, IComponent
|
where T1 : unmanaged, IComponent
|
||||||
where T2 : unmanaged, IComponent
|
where T2 : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||||
|
|
||||||
// 1. Flatten the World
|
// 1. Flatten the World
|
||||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||||
@@ -1023,11 +1023,11 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
// Get offsets ONCE per archetype
|
// Get offsets ONCE per archetype
|
||||||
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
|
|
||||||
// Add all chunks from this archetype
|
// Add all chunks from this archetype
|
||||||
for (var i = 0; i < arch.ChunkCount; i++)
|
for (var i = 0; i < arch.ChunkCount; i++)
|
||||||
@@ -1140,7 +1140,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T2 : unmanaged, IComponent
|
where T2 : unmanaged, IComponent
|
||||||
where T3 : unmanaged, IComponent
|
where T3 : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||||
|
|
||||||
// 1. Flatten the World
|
// 1. Flatten the World
|
||||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||||
@@ -1171,13 +1171,13 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
// Get offsets ONCE per archetype
|
// Get offsets ONCE per archetype
|
||||||
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
|
|
||||||
// Add all chunks from this archetype
|
// Add all chunks from this archetype
|
||||||
for (var i = 0; i < arch.ChunkCount; i++)
|
for (var i = 0; i < arch.ChunkCount; i++)
|
||||||
@@ -1306,7 +1306,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T3 : unmanaged, IComponent
|
where T3 : unmanaged, IComponent
|
||||||
where T4 : unmanaged, IComponent
|
where T4 : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||||
|
|
||||||
// 1. Flatten the World
|
// 1. Flatten the World
|
||||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||||
@@ -1340,15 +1340,15 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
// Get offsets ONCE per archetype
|
// Get offsets ONCE per archetype
|
||||||
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
|
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
|
|
||||||
// Add all chunks from this archetype
|
// Add all chunks from this archetype
|
||||||
for (var i = 0; i < arch.ChunkCount; i++)
|
for (var i = 0; i < arch.ChunkCount; i++)
|
||||||
@@ -1493,7 +1493,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T4 : unmanaged, IComponent
|
where T4 : unmanaged, IComponent
|
||||||
where T5 : unmanaged, IComponent
|
where T5 : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||||
|
|
||||||
// 1. Flatten the World
|
// 1. Flatten the World
|
||||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||||
@@ -1530,17 +1530,17 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
// Get offsets ONCE per archetype
|
// Get offsets ONCE per archetype
|
||||||
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
|
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout5 = arch.GetLayout(ComponentTypeID<T5>.value)
|
var layout5 = arch.GetLayout(ComponentTypeID<T5>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
|
|
||||||
// Add all chunks from this archetype
|
// Add all chunks from this archetype
|
||||||
for (var i = 0; i < arch.ChunkCount; i++)
|
for (var i = 0; i < arch.ChunkCount; i++)
|
||||||
@@ -1701,7 +1701,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T5 : unmanaged, IComponent
|
where T5 : unmanaged, IComponent
|
||||||
where T6 : unmanaged, IComponent
|
where T6 : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||||
|
|
||||||
// 1. Flatten the World
|
// 1. Flatten the World
|
||||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||||
@@ -1741,19 +1741,19 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
// Get offsets ONCE per archetype
|
// Get offsets ONCE per archetype
|
||||||
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
|
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout5 = arch.GetLayout(ComponentTypeID<T5>.value)
|
var layout5 = arch.GetLayout(ComponentTypeID<T5>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout6 = arch.GetLayout(ComponentTypeID<T6>.value)
|
var layout6 = arch.GetLayout(ComponentTypeID<T6>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
|
|
||||||
// Add all chunks from this archetype
|
// Add all chunks from this archetype
|
||||||
for (var i = 0; i < arch.ChunkCount; i++)
|
for (var i = 0; i < arch.ChunkCount; i++)
|
||||||
@@ -1930,7 +1930,7 @@ public unsafe partial struct EntityQuery
|
|||||||
where T6 : unmanaged, IComponent
|
where T6 : unmanaged, IComponent
|
||||||
where T7 : unmanaged, IComponent
|
where T7 : unmanaged, IComponent
|
||||||
{
|
{
|
||||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||||
|
|
||||||
// 1. Flatten the World
|
// 1. Flatten the World
|
||||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||||
@@ -1973,21 +1973,21 @@ public unsafe partial struct EntityQuery
|
|||||||
|
|
||||||
// Get offsets ONCE per archetype
|
// Get offsets ONCE per archetype
|
||||||
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
var layout0 = arch.GetLayout(ComponentTypeID<T0>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
var layout1 = arch.GetLayout(ComponentTypeID<T1>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
var layout2 = arch.GetLayout(ComponentTypeID<T2>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
var layout3 = arch.GetLayout(ComponentTypeID<T3>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
|
var layout4 = arch.GetLayout(ComponentTypeID<T4>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout5 = arch.GetLayout(ComponentTypeID<T5>.value)
|
var layout5 = arch.GetLayout(ComponentTypeID<T5>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout6 = arch.GetLayout(ComponentTypeID<T6>.value)
|
var layout6 = arch.GetLayout(ComponentTypeID<T6>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
var layout7 = arch.GetLayout(ComponentTypeID<T7>.value)
|
var layout7 = arch.GetLayout(ComponentTypeID<T7>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
|
|
||||||
// Add all chunks from this archetype
|
// Add all chunks from this archetype
|
||||||
for (var i = 0; i < arch.ChunkCount; i++)
|
for (var i = 0; i < arch.ChunkCount; i++)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Ghost.Entities;
|
|||||||
public interface IJobEntity<<#= generics #>>
|
public interface IJobEntity<<#= generics #>>
|
||||||
<#= restrictions #>
|
<#= 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
|
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 #>>
|
where TJob : unmanaged, IJobEntity<<#= generics #>>
|
||||||
<#= restrictions #>
|
<#= restrictions #>
|
||||||
{
|
{
|
||||||
var world = World.GetWorld(_worldID).GetValueOrThrow(ResultStatus.Success);
|
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||||
|
|
||||||
// 1. Flatten the World
|
// 1. Flatten the World
|
||||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||||
@@ -129,7 +129,7 @@ public unsafe partial struct EntityQuery
|
|||||||
// Get offsets ONCE per archetype
|
// Get offsets ONCE per archetype
|
||||||
<# for (var j = 0; j < i; j++){ #>
|
<# for (var j = 0; j < i; j++){ #>
|
||||||
var layout<#= j #> = arch.GetLayout(ComponentTypeID<T<#= j #>>.value)
|
var layout<#= j #> = arch.GetLayout(ComponentTypeID<T<#= j #>>.value)
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
<# } #>
|
<# } #>
|
||||||
|
|
||||||
// Add all chunks from this archetype
|
// Add all chunks from this archetype
|
||||||
|
|||||||
@@ -1,92 +1,35 @@
|
|||||||
|
|
||||||
namespace Ghost.Entities;
|
namespace Ghost.Entities;
|
||||||
|
|
||||||
public delegate void ForEach<T0>(ref T0 component0)
|
public delegate void ForEach<T0>(ref T0 component0)
|
||||||
where T0 : unmanaged, IComponent;
|
where T0 : unmanaged, IComponent;
|
||||||
public delegate void ForEach<T0, T1>(ref T0 component0, ref T1 component1)
|
public delegate void ForEach<T0, T1>(ref T0 component0, ref T1 component1)
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent;
|
||||||
where T1 : unmanaged, IComponent;
|
|
||||||
public delegate void ForEach<T0, T1, T2>(ref T0 component0, ref T1 component1, ref T2 component2)
|
public delegate void ForEach<T0, T1, T2>(ref T0 component0, ref T1 component1, ref T2 component2)
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : 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)
|
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 T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : 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)
|
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 T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : 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)
|
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 T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent where T5 : 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)
|
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 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 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)
|
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 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 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)
|
public delegate void ForEachWithEntity<T0>(Entity entity, ref T0 component0)
|
||||||
where T0 : unmanaged, IComponent;
|
where T0 : unmanaged, IComponent;
|
||||||
public delegate void ForEachWithEntity<T0, T1>(Entity entity, ref T0 component0, ref T1 component1)
|
public delegate void ForEachWithEntity<T0, T1>(Entity entity, ref T0 component0, ref T1 component1)
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent;
|
||||||
where T1 : unmanaged, IComponent;
|
|
||||||
public delegate void ForEachWithEntity<T0, T1, T2>(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2)
|
public delegate void ForEachWithEntity<T0, T1, T2>(Entity entity, ref T0 component0, ref T1 component1, ref T2 component2)
|
||||||
where T0 : unmanaged, IComponent
|
where T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : 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)
|
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 T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : 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)
|
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 T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : 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)
|
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 T0 : unmanaged, IComponent where T1 : unmanaged, IComponent where T2 : unmanaged, IComponent where T3 : unmanaged, IComponent where T4 : unmanaged, IComponent where T5 : 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)
|
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 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 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)
|
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 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 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;
|
|
||||||
|
|||||||
@@ -10,18 +10,18 @@ namespace Ghost.Entities;
|
|||||||
{
|
{
|
||||||
var generics = AppendParameters(i, "T{0}");
|
var generics = AppendParameters(i, "T{0}");
|
||||||
var compGenerics = AppendParameters(i, "ref T{0} component{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 #>)
|
public delegate void ForEach<<#= generics #>>(<#= compGenerics #>)
|
||||||
<#= restrictions #>;
|
<#= restrictions #>;
|
||||||
<# } #>
|
<# } #>
|
||||||
|
|
||||||
<# for (var i = 1; i <= Amount; i++)
|
<# for (var i = 1; i <= Amount; i++)
|
||||||
{
|
{
|
||||||
var generics = AppendParameters(i, "T{0}");
|
var generics = AppendParameters(i, "T{0}");
|
||||||
var compGenerics = AppendParameters(i, "ref T{0} component{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 #>)
|
public delegate void ForEachWithEntity<<#= generics #>>(Entity entity, <#= compGenerics #>)
|
||||||
<#= restrictions #>;
|
<#= restrictions #>;
|
||||||
<# } #>
|
<# } #>
|
||||||
|
|||||||
@@ -144,4 +144,4 @@
|
|||||||
|
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
#>
|
#>
|
||||||
|
|||||||
@@ -48,20 +48,20 @@ public partial class World
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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)
|
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];
|
var world = s_worlds[id.value];
|
||||||
if (world is null)
|
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>
|
/// <summary>
|
||||||
/// Gets the main entity command buffer for this world.
|
/// Gets the main entity command buffer for this world.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Use <see cref="GetThreadLocalEntityCommandBuffer(int)"/> to get thread-local command buffers for multi-threaded jobs.
|
||||||
|
/// </remarks>
|
||||||
public EntityCommandBuffer EntityCommandBuffer => _entityCommandBuffer;
|
public EntityCommandBuffer EntityCommandBuffer => _entityCommandBuffer;
|
||||||
|
|
||||||
private World(Identifier<World> id, int entityCapacity, JobScheduler jobScheduler)
|
private World(Identifier<World> id, int entityCapacity, JobScheduler jobScheduler)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Ghost.Core;
|
using Ghost.Core;
|
||||||
using Ghost.Graphics.RHI;
|
using Ghost.Graphics.RHI;
|
||||||
|
using Misaki.HighPerformance.LowLevel;
|
||||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||||
using Misaki.HighPerformance.LowLevel.Collections;
|
using Misaki.HighPerformance.LowLevel.Collections;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@@ -83,15 +84,15 @@ public struct Material : IResourceReleasable, IHandleType
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public readonly unsafe Result<T, ResultStatus> GetPropertyCache<T>()
|
public readonly unsafe Result<T, ErrorStatus> GetPropertyCache<T>()
|
||||||
where T : unmanaged
|
where T : unmanaged
|
||||||
{
|
{
|
||||||
if (sizeof(T) != _cBufferCache.Size)
|
if (sizeof(T) != _cBufferCache.Size)
|
||||||
{
|
{
|
||||||
return Result.Create(default(T), ResultStatus.InvalidArgument);
|
return ErrorStatus.InvalidArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.Create(*(T*)_cBufferCache.CpuData.GetUnsafePtr(), ResultStatus.Success);
|
return *(T*)_cBufferCache.CpuData.GetUnsafePtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -106,28 +107,28 @@ public struct Material : IResourceReleasable, IHandleType
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public readonly unsafe ResultStatus SetPropertyCache<T>(ref readonly T data)
|
public readonly unsafe ErrorStatus SetPropertyCache<T>(ref readonly T data)
|
||||||
where T : unmanaged
|
where T : unmanaged
|
||||||
{
|
{
|
||||||
if (sizeof(T) != _cBufferCache.Size)
|
if (sizeof(T) != _cBufferCache.Size)
|
||||||
{
|
{
|
||||||
return ResultStatus.InvalidArgument;
|
return ErrorStatus.InvalidArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unsafe.WriteUnaligned(_cBufferCache.CpuData.GetUnsafePtr(), data);
|
Unsafe.WriteUnaligned(_cBufferCache.CpuData.GetUnsafePtr(), data);
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public readonly unsafe ResultStatus SetRawPropertyCache(ReadOnlySpan<byte> data)
|
public readonly unsafe ErrorStatus SetRawPropertyCache(ReadOnlySpan<byte> data)
|
||||||
{
|
{
|
||||||
if (data.Length != _cBufferCache.Size)
|
if (data.Length != _cBufferCache.Size)
|
||||||
{
|
{
|
||||||
return ResultStatus.InvalidArgument;
|
return ErrorStatus.InvalidArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unsafe.WriteUnaligned(_cBufferCache.CpuData.GetUnsafePtr(), data);
|
Unsafe.WriteUnaligned(_cBufferCache.CpuData.GetUnsafePtr(), data);
|
||||||
return ResultStatus.Success;
|
return ErrorStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public readonly unsafe ref struct RenderingContext
|
|||||||
CommandBufferType.Graphics => _engine.Device.GraphicsQueue,
|
CommandBufferType.Graphics => _engine.Device.GraphicsQueue,
|
||||||
CommandBufferType.Compute => _engine.Device.ComputeQueue,
|
CommandBufferType.Compute => _engine.Device.ComputeQueue,
|
||||||
CommandBufferType.Copy => _engine.Device.CopyQueue,
|
CommandBufferType.Copy => _engine.Device.CopyQueue,
|
||||||
_ => throw new ArgumentOutOfRangeException(),
|
_ => throw new InvalidOperationException("Unknown command buffer type."),
|
||||||
};
|
};
|
||||||
|
|
||||||
queue.Submit(commandBuffer);
|
queue.Submit(commandBuffer);
|
||||||
@@ -123,8 +123,8 @@ public readonly unsafe ref struct RenderingContext
|
|||||||
localToWorld = localToWorld,
|
localToWorld = localToWorld,
|
||||||
worldBoundsMin = meshData.BoundingBox.Min,
|
worldBoundsMin = meshData.BoundingBox.Min,
|
||||||
worldBoundsMax = meshData.BoundingBox.Max,
|
worldBoundsMax = meshData.BoundingBox.Max,
|
||||||
vertexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.VertexBuffer.AsResource()).GetValueOrThrow(ResultStatus.Success),
|
vertexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.VertexBuffer.AsResource()).GetValueOrThrow(),
|
||||||
indexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.IndexBuffer.AsResource()).GetValueOrThrow(ResultStatus.Success),
|
indexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.IndexBuffer.AsResource()).GetValueOrThrow(),
|
||||||
};
|
};
|
||||||
|
|
||||||
var bufferHandle = meshData.ObjectDataBuffer.AsResource();
|
var bufferHandle = meshData.ObjectDataBuffer.AsResource();
|
||||||
@@ -147,7 +147,7 @@ public readonly unsafe ref struct RenderingContext
|
|||||||
where T : unmanaged
|
where T : unmanaged
|
||||||
{
|
{
|
||||||
var desc = ResourceDatabase.GetResourceDescription(texture.AsResource())
|
var desc = ResourceDatabase.GetResourceDescription(texture.AsResource())
|
||||||
.GetValueOrThrow(ResultStatus.Success);
|
.GetValueOrThrow();
|
||||||
|
|
||||||
if (data.Length * sizeof(T) != desc.TextureDescription.GetTotalBytes())
|
if (data.Length * sizeof(T) != desc.TextureDescription.GetTotalBytes())
|
||||||
{
|
{
|
||||||
@@ -180,7 +180,7 @@ public readonly unsafe ref struct RenderingContext
|
|||||||
var shader = ResourceDatabase.GetShaderReference(materialRef.Shader);
|
var shader = ResourceDatabase.GetShaderReference(materialRef.Shader);
|
||||||
|
|
||||||
var keyResult = shader.TryGetPassKey(passName, out var passIndex);
|
var keyResult = shader.TryGetPassKey(passName, out var passIndex);
|
||||||
if (keyResult.Status != ResultStatus.Success)
|
if (keyResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
throw new Exception(keyResult.ToString());
|
throw new Exception(keyResult.ToString());
|
||||||
}
|
}
|
||||||
@@ -208,4 +208,4 @@ public readonly unsafe ref struct RenderingContext
|
|||||||
var threadGroupCountX = ((uint)meshRef.IndexCount + numThreadsX - 1) / numThreadsX;
|
var threadGroupCountX = ((uint)meshRef.IndexCount + numThreadsX - 1) / numThreadsX;
|
||||||
_directCmd.DispatchMesh(threadGroupCountX, 1, 1);
|
_directCmd.DispatchMesh(threadGroupCountX, 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,17 +101,17 @@ public class Shader : IResourceReleasable, IIdentifierType
|
|||||||
return ref _passes[index];
|
return ref _passes[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefResult<ShaderPass, ResultStatus> TryGetPassKey(string passName, out int passIndex)
|
public RefResult<ShaderPass, ErrorStatus> TryGetPassKey(string passName, out int passIndex)
|
||||||
{
|
{
|
||||||
var index = _passLookup.GetValueOrDefault(passName, -1);
|
var index = _passLookup.GetValueOrDefault(passName, -1);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
passIndex = -1;
|
passIndex = -1;
|
||||||
return Result.CreateRef(ref Unsafe.NullRef<ShaderPass>(), ResultStatus.NotFound);
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
passIndex = index;
|
passIndex = index;
|
||||||
return Result.CreateRef(ref _passes[index], ResultStatus.Success);
|
return RefResult<ShaderPass, ErrorStatus>.Success(ref _passes[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IResourceReleasable.ReleaseResource(IResourceDatabase database)
|
void IResourceReleasable.ReleaseResource(IResourceDatabase database)
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
[DoesNotReturn]
|
[DoesNotReturn]
|
||||||
#endif
|
#endif
|
||||||
private void RecordError(string cmdName, ResultStatus status)
|
private void RecordError(string cmdName, ErrorStatus status)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
throw new InvalidOperationException($"Error at {cmdName} with {status}");
|
throw new InvalidOperationException($"Error at {cmdName} with {status}");
|
||||||
@@ -183,7 +183,7 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
_commandList.Get()->Close();
|
_commandList.Get()->Close();
|
||||||
_isRecording = false;
|
_isRecording = false;
|
||||||
|
|
||||||
if (_lastError.Status != ResultStatus.Success)
|
if (_lastError.Status != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
return Result.Failure($"Command buffer ended with errors at {_lastError.CommandIndex}, command '{_lastError.CommandName}': {_lastError.Status}");
|
return Result.Failure($"Command buffer ended with errors at {_lastError.CommandIndex}, command '{_lastError.CommandName}': {_lastError.Status}");
|
||||||
}
|
}
|
||||||
@@ -220,21 +220,21 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
|
|
||||||
if (!desc.Resource.IsValid)
|
if (!desc.Resource.IsValid)
|
||||||
{
|
{
|
||||||
RecordError(nameof(ResourceBarrier), ResultStatus.InvalidArgument);
|
RecordError(nameof(ResourceBarrier), ErrorStatus.InvalidArgument);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var recordResult = _resourceDatabase.GetResourceRecord(desc.Resource);
|
var recordResult = _resourceDatabase.GetResourceRecord(desc.Resource);
|
||||||
if (recordResult.Status != ResultStatus.Success)
|
if (recordResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
RecordError(nameof(ResourceBarrier), recordResult.Status);
|
RecordError(nameof(ResourceBarrier), recordResult.Error);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ref var record = ref recordResult.Value;
|
ref var record = ref recordResult.Value;
|
||||||
if (record.state != desc.StateBefore)
|
if (record.state != desc.StateBefore)
|
||||||
{
|
{
|
||||||
RecordError(nameof(ResourceBarrier), ResultStatus.InvalidState);
|
RecordError(nameof(ResourceBarrier), ErrorStatus.InvalidState);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,9 +263,9 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
var recordResult = _resourceDatabase.GetResourceRecord(resource);
|
var recordResult = _resourceDatabase.GetResourceRecord(resource);
|
||||||
if (recordResult.Status != ResultStatus.Success)
|
if (recordResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
RecordError(nameof(ResourceBarrier), recordResult.Status);
|
RecordError(nameof(ResourceBarrier), recordResult.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,9 +284,9 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
IncrementCommandCount();
|
IncrementCommandCount();
|
||||||
|
|
||||||
var recordResult = _resourceDatabase.GetResourceRecord(resource);
|
var recordResult = _resourceDatabase.GetResourceRecord(resource);
|
||||||
if (recordResult.Status != ResultStatus.Success)
|
if (recordResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
RecordError(nameof(ResourceBarrier), recordResult.Status);
|
RecordError(nameof(ResourceBarrier), recordResult.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,14 +316,14 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
var handle = renderTargets[i];
|
var handle = renderTargets[i];
|
||||||
if (!handle.IsValid)
|
if (!handle.IsValid)
|
||||||
{
|
{
|
||||||
RecordError(nameof(SetRenderTargets), ResultStatus.InvalidArgument);
|
RecordError(nameof(SetRenderTargets), ErrorStatus.InvalidArgument);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var recordResult = _resourceDatabase.GetResourceRecord(handle.AsResource());
|
var recordResult = _resourceDatabase.GetResourceRecord(handle.AsResource());
|
||||||
if (recordResult.Status != ResultStatus.Success)
|
if (recordResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
RecordError(nameof(SetRenderTargets), recordResult.Status);
|
RecordError(nameof(SetRenderTargets), recordResult.Error);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,9 +337,9 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
if (pDsvHandle != null)
|
if (pDsvHandle != null)
|
||||||
{
|
{
|
||||||
var recordResult = _resourceDatabase.GetResourceRecord(depthTarget.AsResource());
|
var recordResult = _resourceDatabase.GetResourceRecord(depthTarget.AsResource());
|
||||||
if (recordResult.Status != ResultStatus.Success)
|
if (recordResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
RecordError(nameof(SetRenderTargets), recordResult.Status);
|
RecordError(nameof(SetRenderTargets), recordResult.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,14 +362,14 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
var rtDesc = rtDescs[i];
|
var rtDesc = rtDescs[i];
|
||||||
if (!rtDesc.Texture.IsValid)
|
if (!rtDesc.Texture.IsValid)
|
||||||
{
|
{
|
||||||
RecordError(nameof(BeginRenderPass), ResultStatus.InvalidArgument);
|
RecordError(nameof(BeginRenderPass), ErrorStatus.InvalidArgument);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var recordResult = _resourceDatabase.GetResourceRecord(rtDesc.Texture.AsResource());
|
var recordResult = _resourceDatabase.GetResourceRecord(rtDesc.Texture.AsResource());
|
||||||
if (recordResult.Status != ResultStatus.Success)
|
if (recordResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
RecordError(nameof(BeginRenderPass), recordResult.Status);
|
RecordError(nameof(BeginRenderPass), recordResult.Error);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,9 +402,9 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
if (pDsvDesc != null)
|
if (pDsvDesc != null)
|
||||||
{
|
{
|
||||||
var recordResult = _resourceDatabase.GetResourceRecord(depthDesc.Texture.AsResource());
|
var recordResult = _resourceDatabase.GetResourceRecord(depthDesc.Texture.AsResource());
|
||||||
if (recordResult.Status != ResultStatus.Success)
|
if (recordResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
RecordError(nameof(BeginRenderPass), recordResult.Status);
|
RecordError(nameof(BeginRenderPass), recordResult.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,10 +458,10 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
IncrementCommandCount();
|
IncrementCommandCount();
|
||||||
|
|
||||||
var psor = _pipelineLibrary.GetGraphicsPSO(pipelineKey);
|
var psor = _pipelineLibrary.GetGraphicsPSO(pipelineKey);
|
||||||
if (psor.Status != ResultStatus.Success)
|
if (psor.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
#if DEBUG || GHOST_EDITOR
|
#if DEBUG || GHOST_EDITOR
|
||||||
Logger.LogError($"Failed to get graphics pipeline state object for key {pipelineKey}: {psor.Status}");
|
Logger.LogError($"Failed to get graphics pipeline state object for key {pipelineKey}: {psor.Error}");
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -487,9 +487,9 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
IncrementCommandCount();
|
IncrementCommandCount();
|
||||||
|
|
||||||
var recordResult = _resourceDatabase.GetResourceRecord(buffer.AsResource());
|
var recordResult = _resourceDatabase.GetResourceRecord(buffer.AsResource());
|
||||||
if (recordResult.Status != ResultStatus.Success)
|
if (recordResult.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
RecordError(nameof(BeginRenderPass), recordResult.Status);
|
RecordError(nameof(BeginRenderPass), recordResult.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,7 +657,7 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
|
|||||||
var pSrcResource = _resourceDatabase.GetResource(src.AsResource());
|
var pSrcResource = _resourceDatabase.GetResource(src.AsResource());
|
||||||
if (pSrcResource == null || pDestResource == null)
|
if (pSrcResource == null || pDestResource == null)
|
||||||
{
|
{
|
||||||
RecordError(nameof(CopyBuffer), ResultStatus.InvalidArgument);
|
RecordError(nameof(CopyBuffer), ErrorStatus.InvalidArgument);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ internal unsafe class D3D12PipelineLibrary : IPipelineLibrary
|
|||||||
|
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
{
|
{
|
||||||
var fileBytes = File.ReadAllBytes(filePath!);
|
var fileBytes = File.ReadAllBytes(filePath);
|
||||||
fixed (byte* pFileBytes = fileBytes)
|
fixed (byte* pFileBytes = fileBytes)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(_device.NativeDevice.Get()->CreatePipelineLibrary(pFileBytes, (nuint)fileBytes.Length, __uuidof(pLibrary), (void**)&pLibrary));
|
ThrowIfFailed(_device.NativeDevice.Get()->CreatePipelineLibrary(pFileBytes, (nuint)fileBytes.Length, __uuidof(pLibrary), (void**)&pLibrary));
|
||||||
@@ -224,7 +224,7 @@ internal unsafe class D3D12PipelineLibrary : IPipelineLibrary
|
|||||||
RegisterSlot = info.BindPoint,
|
RegisterSlot = info.BindPoint,
|
||||||
RegisterSpace = info.Space,
|
RegisterSpace = info.Space,
|
||||||
SizeInBytes = info.Size,
|
SizeInBytes = info.Size,
|
||||||
Properties = info.Properties ?? Array.Empty<CBufferPropertyInfo>(),
|
Properties = info.Properties ?? [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,14 +401,14 @@ internal unsafe class D3D12PipelineLibrary : IPipelineLibrary
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<SharedPtr<ID3D12PipelineState>, ResultStatus> GetGraphicsPSO(GraphicsPipelineKey key)
|
public Result<SharedPtr<ID3D12PipelineState>, ErrorStatus> GetGraphicsPSO(GraphicsPipelineKey key)
|
||||||
{
|
{
|
||||||
if (_pipelineCache.TryGetValue(key, out var cacheEntry))
|
if (_pipelineCache.TryGetValue(key, out var cacheEntry))
|
||||||
{
|
{
|
||||||
return Result.Create(new SharedPtr<ID3D12PipelineState>(cacheEntry.pso.Get()), ResultStatus.Success);
|
return cacheEntry.pso.Share();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.Create(default(SharedPtr<ID3D12PipelineState>), ResultStatus.NotFound);
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
@@ -178,17 +178,17 @@ internal class D3D12ResourceDatabase : IResourceDatabase
|
|||||||
return _resources.Contains(handle.id, handle.generation);
|
return _resources.Contains(handle.id, handle.generation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefResult<ResourceRecord, ResultStatus> GetResourceRecord(Handle<GPUResource> handle)
|
public RefResult<ResourceRecord, ErrorStatus> GetResourceRecord(Handle<GPUResource> handle)
|
||||||
{
|
{
|
||||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||||
|
|
||||||
ref var info = ref _resources.GetElementReferenceAt(handle.id, handle.generation, out var exist);
|
ref var info = ref _resources.GetElementReferenceAt(handle.id, handle.generation, out var exist);
|
||||||
if (!exist)
|
if (!exist)
|
||||||
{
|
{
|
||||||
return Result.CreateRef(ref Unsafe.NullRef<ResourceRecord>(), ResultStatus.NotFound);
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.CreateRef(ref info, ResultStatus.Success);
|
return RefResult<ResourceRecord, ErrorStatus>.Success(ref info);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ref ResourceRecord GetResourceRecord(Handle<GPUResource> handle, out bool exist)
|
public ref ResourceRecord GetResourceRecord(Handle<GPUResource> handle, out bool exist)
|
||||||
@@ -202,7 +202,7 @@ internal class D3D12ResourceDatabase : IResourceDatabase
|
|||||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||||
|
|
||||||
var r = GetResourceRecord(handle);
|
var r = GetResourceRecord(handle);
|
||||||
if (r.Status != ResultStatus.Success)
|
if (r.Error != ErrorStatus.None)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -210,17 +210,17 @@ internal class D3D12ResourceDatabase : IResourceDatabase
|
|||||||
return r.Value.ResourcePtr;
|
return r.Value.ResourcePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<ResourceState, ResultStatus> GetResourceState(Handle<GPUResource> handle)
|
public Result<ResourceState, ErrorStatus> GetResourceState(Handle<GPUResource> handle)
|
||||||
{
|
{
|
||||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||||
|
|
||||||
var r = GetResourceRecord(handle);
|
var r = GetResourceRecord(handle);
|
||||||
if (r.Status != ResultStatus.Success)
|
if (!r)
|
||||||
{
|
{
|
||||||
return Result.Create(ResourceState.Common, r.Status);
|
return r.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.Create(r.Value.state, ResultStatus.Success);
|
return r.Value.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetResourceState(Handle<GPUResource> handle, ResourceState state)
|
public void SetResourceState(Handle<GPUResource> handle, ResourceState state)
|
||||||
@@ -236,31 +236,30 @@ internal class D3D12ResourceDatabase : IResourceDatabase
|
|||||||
info.state = state;
|
info.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<ResourceDesc, ResultStatus> GetResourceDescription(Handle<GPUResource> handle)
|
public Result<ResourceDesc, ErrorStatus> GetResourceDescription(Handle<GPUResource> handle)
|
||||||
{
|
{
|
||||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||||
|
|
||||||
var r = GetResourceRecord(handle);
|
var r = GetResourceRecord(handle);
|
||||||
|
if (!r)
|
||||||
if (r.Status != ResultStatus.Success)
|
|
||||||
{
|
{
|
||||||
return Result.Create(default(ResourceDesc), r.Status);
|
return r.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.Create(r.Value.desc, ResultStatus.Success);
|
return r.Value.desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<uint, ResultStatus> GetBindlessIndex(Handle<GPUResource> handle)
|
public Result<uint, ErrorStatus> GetBindlessIndex(Handle<GPUResource> handle)
|
||||||
{
|
{
|
||||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||||
|
|
||||||
ref var info = ref GetResourceRecord(handle, out var exist);
|
ref var info = ref GetResourceRecord(handle, out var exist);
|
||||||
if (!exist || !info.Allocated)
|
if (!exist || !info.Allocated)
|
||||||
{
|
{
|
||||||
return Result.Create(0u, ResultStatus.NotFound);
|
return ErrorStatus.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.Create((uint)info.viewGroup.srv.value, ResultStatus.Success);
|
return (uint)info.viewGroup.srv.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? GetResourceName(Handle<GPUResource> handle)
|
public string? GetResourceName(Handle<GPUResource> handle)
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ internal struct GraphicsPipelineHash
|
|||||||
// Do we need to store blend state?
|
// Do we need to store blend state?
|
||||||
// TODO: Variants
|
// TODO: Variants
|
||||||
|
|
||||||
public GraphicsPipelineKey GetKey()
|
public readonly GraphicsPipelineKey GetKey()
|
||||||
{
|
{
|
||||||
Span<ulong> data = stackalloc ulong[3 + D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT];
|
Span<ulong> data = stackalloc ulong[3 + D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT];
|
||||||
data[0] = Id.value;
|
data[0] = Id.value;
|
||||||
@@ -731,7 +731,7 @@ public struct CommandError
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultStatus Status
|
public ErrorStatus Status
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
@@ -988,4 +988,4 @@ public enum ComparisonFunction
|
|||||||
NotEqual,
|
NotEqual,
|
||||||
GreaterEqual,
|
GreaterEqual,
|
||||||
Always
|
Always
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public interface IResourceDatabase : IDisposable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="handle">The handle that uniquely identifies the resource whose state is to be retrieved.</param>
|
/// <param name="handle">The handle that uniquely identifies the resource whose state is to be retrieved.</param>
|
||||||
/// <returns>A ResourceState Value representing the current state of the resource associated with the specified handle.</returns>
|
/// <returns>A ResourceState Value representing the current state of the resource associated with the specified handle.</returns>
|
||||||
Result<ResourceState, ResultStatus> GetResourceState(Handle<GPUResource> handle);
|
Result<ResourceState, ErrorStatus> GetResourceState(Handle<GPUResource> handle);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the state of the specified resource handle to the given Value.
|
/// Sets the state of the specified resource handle to the given Value.
|
||||||
@@ -53,14 +53,14 @@ public interface IResourceDatabase : IDisposable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="handle">A handle that identifies the GPU resource for which to obtain the description. Must reference a valid resource.</param>
|
/// <param name="handle">A handle that identifies the GPU resource for which to obtain the description. Must reference a valid resource.</param>
|
||||||
/// <returns>A ResourceDesc structure containing details about the specified GPU resource.</returns>
|
/// <returns>A ResourceDesc structure containing details about the specified GPU resource.</returns>
|
||||||
Result<ResourceDesc, ResultStatus> GetResourceDescription(Handle<GPUResource> handle);
|
Result<ResourceDesc, ErrorStatus> GetResourceDescription(Handle<GPUResource> handle);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the bindless index associated with the specified GPU resource handle.
|
/// Retrieves the bindless index associated with the specified GPU resource handle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="handle">A handle to the GPU resource for which to obtain the bindless index. Must reference a valid, currently registered resource.</param>
|
/// <param name="handle">A handle to the GPU resource for which to obtain the bindless index. Must reference a valid, currently registered resource.</param>
|
||||||
/// <returns>The bindless index corresponding to the specified GPU resource handle. -1 if the resource does not support bindless access or is not found.</returns>
|
/// <returns>The bindless index corresponding to the specified GPU resource handle. -1 if the resource does not support bindless access or is not found.</returns>
|
||||||
Result<uint, ResultStatus> GetBindlessIndex(Handle<GPUResource> handle);
|
Result<uint, ErrorStatus> GetBindlessIndex(Handle<GPUResource> handle);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the name of the GPU resource associated with the specified handle.
|
/// Retrieves the name of the GPU resource associated with the specified handle.
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ internal class MeshRenderPass : IRenderPass
|
|||||||
public uint texture4;
|
public uint texture4;
|
||||||
public uint tex_sampler;
|
public uint tex_sampler;
|
||||||
|
|
||||||
private uint _padding1;
|
private readonly uint _padding1;
|
||||||
private uint _padding2;
|
private readonly uint _padding2;
|
||||||
private uint _padding3;
|
private readonly uint _padding3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Handle<Mesh> _mesh;
|
private Handle<Mesh> _mesh;
|
||||||
@@ -91,7 +91,7 @@ internal class MeshRenderPass : IRenderPass
|
|||||||
{
|
{
|
||||||
using var stream = File.OpenRead(_textureFiles[i]);
|
using var stream = File.OpenRead(_textureFiles[i]);
|
||||||
using var imageData = ImageResult.FromStream(stream, ColorComponents.RGBA);
|
using var imageData = ImageResult.FromStream(stream, ColorComponents.RGBA);
|
||||||
|
|
||||||
var desc = new TextureDesc
|
var desc = new TextureDesc
|
||||||
{
|
{
|
||||||
Width = imageData.Width,
|
Width = imageData.Width,
|
||||||
@@ -121,14 +121,14 @@ internal class MeshRenderPass : IRenderPass
|
|||||||
var matProps = new ShaderProperties_MyShader_Standard
|
var matProps = new ShaderProperties_MyShader_Standard
|
||||||
{
|
{
|
||||||
color = new float4(1.0f, 1.0f, 1.0f, 1.0f),
|
color = new float4(1.0f, 1.0f, 1.0f, 1.0f),
|
||||||
texture1 = ctx.ResourceDatabase.GetBindlessIndex(_textures[0].AsResource()).GetValueOrThrow(ResultStatus.Success),
|
texture1 = ctx.ResourceDatabase.GetBindlessIndex(_textures[0].AsResource()).GetValueOrThrow(),
|
||||||
texture2 = ctx.ResourceDatabase.GetBindlessIndex(_textures[1].AsResource()).GetValueOrThrow(ResultStatus.Success),
|
texture2 = ctx.ResourceDatabase.GetBindlessIndex(_textures[1].AsResource()).GetValueOrThrow(),
|
||||||
texture3 = ctx.ResourceDatabase.GetBindlessIndex(_textures[2].AsResource()).GetValueOrThrow(ResultStatus.Success),
|
texture3 = ctx.ResourceDatabase.GetBindlessIndex(_textures[2].AsResource()).GetValueOrThrow(),
|
||||||
texture4 = ctx.ResourceDatabase.GetBindlessIndex(_textures[3].AsResource()).GetValueOrThrow(ResultStatus.Success),
|
texture4 = ctx.ResourceDatabase.GetBindlessIndex(_textures[3].AsResource()).GetValueOrThrow(),
|
||||||
tex_sampler = (uint)sampler.value,
|
tex_sampler = (uint)sampler.value,
|
||||||
};
|
};
|
||||||
|
|
||||||
Debug.Assert(matRef.SetPropertyCache(in matProps) == ResultStatus.Success);
|
Debug.Assert(matRef.SetPropertyCache(in matProps) == ErrorStatus.None);
|
||||||
matRef.UploadData(ctx.DirectCommandBuffer);
|
matRef.UploadData(ctx.DirectCommandBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,7 @@
|
|||||||
<Project Path="Ghost.ArcEntities/Ghost.ArcEntities.csproj" />
|
<Project Path="Ghost.ArcEntities/Ghost.ArcEntities.csproj" />
|
||||||
<Project Path="Ghost.Core/Ghost.Core.csproj" />
|
<Project Path="Ghost.Core/Ghost.Core.csproj" />
|
||||||
<Project Path="Ghost.Engine/Ghost.Engine.csproj" />
|
<Project Path="Ghost.Engine/Ghost.Engine.csproj" />
|
||||||
<Project Path="Ghost.SparseEntities/Ghost.SparseEntities.csproj" />
|
<Project Path="Ghost.Entities/Ghost.Entities.csproj" />
|
||||||
<Project Path="Ghost.Entities/Ghost.Entities.csproj" Id="8d127b7f-dc6a-4814-8dc0-1aefe65b5d08" />
|
|
||||||
<Project Path="Ghost.Graphics/Ghost.Graphics.csproj" />
|
<Project Path="Ghost.Graphics/Ghost.Graphics.csproj" />
|
||||||
</Folder>
|
</Folder>
|
||||||
<Folder Name="/Test/">
|
<Folder Name="/Test/">
|
||||||
|
|||||||
Reference in New Issue
Block a user