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.
26 lines
1.0 KiB
26 lines
1.0 KiB
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() => $"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() => HashCode.Combine(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); |
|
|
|
} |
|
} |