Mirror of Svelto.ECS because we're a fan of it
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.

78 lines
2.0KB

  1. using System;
  2. using System.Collections.Generic;
  3. #pragma warning disable 660,661
  4. namespace Svelto.ECS
  5. {
  6. //todo: add debug map
  7. [Serialization.DoNotSerialize]
  8. [Serializable]
  9. public struct EGID:IEquatable<EGID>,IEqualityComparer<EGID>,IComparable<EGID>
  10. {
  11. public uint entityID => (uint) (_GID & 0xFFFFFFFF);
  12. public ExclusiveGroup.ExclusiveGroupStruct groupID => new ExclusiveGroup.ExclusiveGroupStruct((uint) (_GID >> 32));
  13. public static bool operator ==(EGID obj1, EGID obj2)
  14. {
  15. return obj1._GID == obj2._GID;
  16. }
  17. public static bool operator !=(EGID obj1, EGID obj2)
  18. {
  19. return obj1._GID != obj2._GID;
  20. }
  21. public EGID(uint entityID, ExclusiveGroup.ExclusiveGroupStruct groupID) : this()
  22. {
  23. _GID = MAKE_GLOBAL_ID(entityID, groupID);
  24. }
  25. static ulong MAKE_GLOBAL_ID(uint entityId, uint groupId)
  26. {
  27. return (ulong)groupId << 32 | ((ulong)entityId & 0xFFFFFFFF);
  28. }
  29. public static explicit operator uint(EGID id)
  30. {
  31. return id.entityID;
  32. }
  33. //in the way it's used, ulong must be always the same for each id/group
  34. public static explicit operator ulong(EGID id) { return id._GID; }
  35. public bool Equals(EGID other)
  36. {
  37. return _GID == other._GID;
  38. }
  39. public bool Equals(EGID x, EGID y)
  40. {
  41. return x == y;
  42. }
  43. public int GetHashCode(EGID obj)
  44. {
  45. return _GID.GetHashCode();
  46. }
  47. public int CompareTo(EGID other)
  48. {
  49. return _GID.CompareTo(other._GID);
  50. }
  51. internal EGID(uint entityID, uint groupID) : this()
  52. {
  53. _GID = MAKE_GLOBAL_ID(entityID, groupID);
  54. }
  55. public override string ToString()
  56. {
  57. return "id ".FastConcat(entityID).FastConcat(" group ").FastConcat(groupID);
  58. }
  59. readonly ulong _GID;
  60. }
  61. }