You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
2 years ago
|
using System;
|
||
|
|
||
|
namespace GameCore.TinyECS
|
||
|
{
|
||
|
public readonly struct Entity<TEnum> : IEquatable<Entity<TEnum>> where TEnum : unmanaged
|
||
|
{
|
||
|
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()
|
||
|
{
|
||
|
return $"Entity<{type}>({index},{generation})";
|
||
|
}
|
||
|
|
||
|
public bool Equals(Entity<TEnum> other)
|
||
|
{
|
||
|
return type.Equals(other.type) && index == other.index && generation == other.generation;
|
||
|
}
|
||
|
|
||
|
public override bool Equals(object obj)
|
||
|
{
|
||
|
return obj is Entity<TEnum> other && Equals(other);
|
||
|
}
|
||
|
|
||
|
public override int GetHashCode()
|
||
|
{
|
||
|
return HashCode.Combine(type, index, generation);
|
||
|
}
|
||
|
|
||
|
public static bool operator ==(Entity<TEnum> lhs, Entity<TEnum> rhs)
|
||
|
{
|
||
|
return lhs.Equals(rhs);
|
||
|
}
|
||
|
|
||
|
public static bool operator !=(Entity<TEnum> lhs, Entity<TEnum> rhs)
|
||
|
{
|
||
|
return !(lhs == rhs);
|
||
|
}
|
||
|
}
|
||
|
}
|