Support enableable components and query enhancements

- Upgraded `Misaki.HighPerformance.LowLevel` to v1.2.8.
- Added `IEquatable` to `Handle<T>` and `Identifier<T>`.
- Improved `Result` extensions with `[CallerArgumentExpression]`.
- Introduced `SetEnabled` in `EntityManager` to toggle components.
- Refactored `Chunk` and `Archetype` for enableable components.
- Added `EntityQueryMask` for filtering enabled/disabled components.
- Enhanced `QueryBuilder` with new filtering methods (`WithAll`, etc.).
- Improved `EntityQuery.ForEach` with entity validation.
This commit is contained in:
2025-12-05 22:38:11 +09:00
parent 224b2b2dd5
commit 30c1d99959
16 changed files with 1203 additions and 448 deletions

View File

@@ -21,7 +21,7 @@
<ItemGroup>
<PackageReference Include="Misaki.HighPerformance" Version="1.0.1" />
<PackageReference Include="Misaki.HighPerformance.LowLevel" Version="1.2.6" />
<PackageReference Include="Misaki.HighPerformance.LowLevel" Version="1.2.8" />
<PackageReference Include="Misaki.HighPerformance.Mathematics" Version="1.2.6" />
<PackageReference Include="System.IO.Hashing" Version="10.0.0" />
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.26100.5" />

View File

@@ -4,7 +4,7 @@ public interface IHandleType;
public interface IIdentifierType;
public interface IKeyType;
public readonly struct Handle<T>
public readonly struct Handle<T> : IEquatable<Handle<T>>
where T : IHandleType
{
public readonly int id;
@@ -57,7 +57,7 @@ public readonly struct Handle<T>
}
}
public readonly struct Identifier<T>
public readonly struct Identifier<T> : IEquatable<Identifier<T>>
where T : IIdentifierType
{
public readonly int value;
@@ -74,7 +74,7 @@ public readonly struct Identifier<T>
public readonly override int GetHashCode()
{
return value.GetHashCode();
return value;
}
public readonly override bool Equals(object? obj)

View File

@@ -1,3 +1,6 @@
using System.Runtime.CompilerServices;
using TerraFX.Interop.DirectX;
namespace Ghost.Core;
public readonly struct Result
@@ -152,38 +155,38 @@ public readonly ref struct RefResult<T, S>
public static class ResultExtensions
{
public static void ThrowIfFailed(this ResultStatus result)
public static void ThrowIfFailed(this ResultStatus result, [CallerArgumentExpression(nameof(result))] string? op = null)
{
if (result != ResultStatus.Success)
{
throw new InvalidOperationException($"Operation failed: {result}");
throw new InvalidOperationException($"{op} failed: {result}");
}
}
public static void ThrowIfFailed(this Result result)
public static void ThrowIfFailed(this Result result, [CallerArgumentExpression(nameof(result))] string? op = null)
{
if (!result.IsSuccess)
{
throw new InvalidOperationException($"Operation failed: {result.Message}");
throw new InvalidOperationException($"{op} failed: {result.Message}");
}
}
public static T GetValueOrThrow<T>(this Result<T> result)
public static T GetValueOrThrow<T>(this Result<T> result, [CallerArgumentExpression(nameof(result))] string? op = null)
{
if (!result.IsSuccess)
{
throw new InvalidOperationException($"Operation failed: {result.Message}");
throw new InvalidOperationException($"{op} failed: {result.Message}");
}
return result.Value;
}
public static T GetValueOrThrow<T, S>(this Result<T, S> result, S expect)
public static T GetValueOrThrow<T, S>(this Result<T, S> result, S expect, [CallerArgumentExpression(nameof(result))] string? op = null)
where S : Enum
{
if (!EqualityComparer<S>.Default.Equals(result.Status, expect))
{
throw new InvalidOperationException($"Operation failed: expected status {expect}, but got {result.Status}");
throw new InvalidOperationException($"{op} failed: expected status {expect}, but got {result.Status}");
}
return result.Value;
@@ -212,6 +215,19 @@ public static class ResultExtensions
return false;
}
public static bool TryGetValue<T, S>(this Result<T, S> result, S expect, out T value)
where S : Enum
{
if (EqualityComparer<S>.Default.Equals(result.Status, expect))
{
value = result.Value;
return true;
}
value = default!;
return false;
}
public static Result OnSuccess(this Result result, Action action)
{
if (result.IsSuccess)