Update archtype ecs

This commit is contained in:
2025-12-02 16:40:23 +09:00
parent 9d991bf316
commit 95cb9af16f
7 changed files with 392 additions and 6 deletions

View File

@@ -0,0 +1,81 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ghost.ArcEntities;
[StructLayout(LayoutKind.Sequential, Size = 8)]
public struct Entity : IEquatable<Entity>, IComparable<Entity>
{
public const EntityID INVALID_ID = -1;
private EntityID _id;
private GenerationID _generation;
public readonly EntityID ID
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _id;
}
public readonly GenerationID Generation
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _generation;
}
public readonly bool IsValid
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ID != INVALID_ID;
}
public static Entity Invalid
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new(INVALID_ID, GenerationID.MaxValue);
}
internal Entity(EntityID id, GenerationID generation)
{
_id = id;
_generation = generation;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void IncrementGeneration() => _generation++;
public readonly bool Equals(Entity other)
{
return _id == other._id && _generation == other._generation;
}
public readonly int CompareTo(Entity other)
{
return _id.CompareTo(other._id);
}
public override readonly bool Equals(object? obj)
{
return obj is Entity other && Equals(other);
}
public override readonly int GetHashCode()
{
return _id.GetHashCode();
}
public static bool operator ==(Entity left, Entity right)
{
return left.Equals(right);
}
public static bool operator !=(Entity left, Entity right)
{
return !(left == right);
}
public override readonly string ToString()
{
return $"Entity {{ Index: {ID}, Generation: {Generation} }}";
}
}