Files
GhostEngine/Ghost.Entities/Entity.cs
Misaki 40d333b004 Refactor project structure and enhance functionality
Changed the project namespace from `Ghost.Editor` to `Ghost.App` across multiple files.
Changed the `InternalsVisibleTo` attribute in `AssemblyInfo.cs` to include `Ghost.App`.
Changed the `ProjectRepository` class to add new asynchronous methods for retrieving projects by ID, name, and metadata path.
Changed the `ProjectService` class to utilize the new asynchronous project loading methods.
Changed the `SceneGraph` classes to improve node management and serialization.
Changed the `EntityManager` class to enhance entity management with new component handling methods.
Added new test classes, `EntityTest` and `SerializationTest`, to ensure reliability in entity and serialization systems.
Added the `Ghost.App` project file to establish a modular project structure.
Added the `Ghost.Generator` project for automated component serialization code generation.
Updated UI components to reflect the new namespace for proper functionality.
2025-06-07 20:54:07 +09:00

82 lines
1.8 KiB
C#

using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
namespace Ghost.Entities;
[SkipLocalsInit]
public struct Entity : IEquatable<Entity>, IComparable<Entity>
{
public const EntityID INVALID_ID = -1;
[JsonInclude]
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;
}
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} }}";
}
}