encompass-cs/encompass-cs/Entity.cs

44 lines
977 B
C#
Raw Normal View History

using System;
2019-06-13 02:51:36 +00:00
namespace Encompass
{
/// <summary>
/// An Entity is a structure composed of a unique ID and a collection of Components.
/// An Entity may only have a single Component of any particular Type.
/// </summary>
2019-07-18 21:02:57 +00:00
public struct Entity : IEquatable<Entity>
2019-06-13 02:51:36 +00:00
{
2019-12-20 20:52:38 +00:00
public readonly int ID;
2019-06-13 02:51:36 +00:00
2019-12-20 20:52:38 +00:00
internal Entity(int id)
2019-06-16 01:05:56 +00:00
{
ID = id;
2019-06-13 02:51:36 +00:00
}
2019-07-18 21:02:57 +00:00
public override bool Equals(object obj)
{
2019-12-20 20:52:38 +00:00
return obj is Entity entity && Equals(entity);
2019-07-18 21:02:57 +00:00
}
public bool Equals(Entity other)
{
return other.ID == ID;
}
public static bool operator ==(Entity one, Entity two)
{
return one.Equals(two);
}
public static bool operator !=(Entity one, Entity two)
{
return !one.Equals(two);
}
public override int GetHashCode()
{
2020-03-20 07:09:57 +00:00
return HashCode.Combine(ID);
2019-07-18 21:02:57 +00:00
}
2019-06-13 02:51:36 +00:00
}
}