|
|
|
|
using System;
|
|
|
|
|
using GameCore.LowLevel;
|
|
|
|
|
using Unity.Collections.LowLevel.Unsafe;
|
|
|
|
|
|
|
|
|
|
namespace GameCore.TinyECS
|
|
|
|
|
{
|
|
|
|
|
public readonly struct Entity<TEnum> : IEquatable<Entity<TEnum>> where TEnum : unmanaged, IConvertible
|
|
|
|
|
{
|
|
|
|
|
public readonly TEnum type;
|
|
|
|
|
public readonly int index;
|
|
|
|
|
public readonly int generation;
|
|
|
|
|
|
|
|
|
|
public Entity(TEnum type, int index, int generation)
|
|
|
|
|
{
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.index = index;
|
|
|
|
|
this.generation = generation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() => $"Entity<{type}>({index},{generation})";
|
|
|
|
|
public bool Equals(Entity<TEnum> other) => type.Equals(other.type) && index == other.index && generation == other.generation;
|
|
|
|
|
public override bool Equals(object obj) => obj is Entity<TEnum> other && Equals(other);
|
|
|
|
|
public override int GetHashCode() => LowLevelUtility.HashCombine(UnsafeUtility.EnumToInt(type), index, generation);
|
|
|
|
|
public static bool operator ==(Entity<TEnum> lhs, Entity<TEnum> rhs) => lhs.Equals(rhs);
|
|
|
|
|
public static bool operator !=(Entity<TEnum> lhs, Entity<TEnum> rhs) => !(lhs == rhs);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|