forked from Misaki/GhostEngine
- Updated Misaki.HighPerformance package versions in Core and Graphics projects. - Added IsTrimmable to Ghost.Engine.csproj for trimming support. - Renamed GetOrRegisterComponent to GetOrRegisterComponentID and updated all usages. - Component registration codegen now uses a static class with [ModuleInitializer], no longer requires [EngineEntry]. - Improved JSON serialization: added string support, introduced Utf8JsonObjectScope/ArrayScope, and new extension methods for cleaner JSON writing. - Removed [SkipLocalsInit] from Hierarchy and LocalToWorld. - Fixed Entity.Invalid to use INVALID_ID for both fields. - Minor cleanup: clarified comments, reorganized Ghost.Generator in solution, and disabled component serialization generator.
48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Ghost.Entities;
|
|
|
|
[StructLayout(LayoutKind.Sequential, Size = 8)]
|
|
public readonly record struct Entity
|
|
{
|
|
public const EntityID INVALID_ID = -1;
|
|
|
|
private readonly EntityID _id;
|
|
private readonly GenerationID _generation;
|
|
|
|
public EntityID ID
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get => _id;
|
|
}
|
|
|
|
public GenerationID Generation
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get => _generation;
|
|
}
|
|
|
|
public bool IsValid
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get => ID != INVALID_ID;
|
|
}
|
|
|
|
public static Entity Invalid
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get => new(INVALID_ID, INVALID_ID);
|
|
}
|
|
|
|
internal Entity(EntityID id, GenerationID generation)
|
|
{
|
|
_id = id;
|
|
_generation = generation;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"Entity {{ Index: {ID}, Generation: {Generation} }}";
|
|
}
|
|
} |