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.

54 lines
1.6KB

  1. using System.Runtime.CompilerServices;
  2. namespace Svelto.ECS
  3. {
  4. public readonly struct ExclusiveBuildGroup
  5. {
  6. internal ExclusiveBuildGroup(ExclusiveGroupStruct group, ushort range)
  7. {
  8. _range = range;
  9. this.group = group;
  10. }
  11. public static implicit operator ExclusiveBuildGroup(ExclusiveGroupStruct group)
  12. {
  13. return new ExclusiveBuildGroup(group, 0);
  14. }
  15. public static implicit operator ExclusiveBuildGroup(ExclusiveGroup group)
  16. {
  17. return new ExclusiveBuildGroup(group, 0);
  18. }
  19. public static implicit operator ExclusiveGroupStruct(ExclusiveBuildGroup group)
  20. {
  21. return group.group;
  22. }
  23. public static ExclusiveGroupStruct operator +(ExclusiveBuildGroup c1, uint c2)
  24. {
  25. DBC.ECS.Check.Require(c2 < c1._range, $"group out of range, {c2} max range is {c1._range}");
  26. return c1.group + c2;
  27. }
  28. public override string ToString()
  29. {
  30. return group.ToName();
  31. }
  32. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  33. internal uint Offset(ExclusiveGroupStruct exclusiveGroupStruct)
  34. {
  35. DBC.ECS.Check.Require((exclusiveGroupStruct.id - group.id) < _range, "group out of range");
  36. var offset = (uint)exclusiveGroupStruct.id - (uint)group.id;
  37. return offset;
  38. }
  39. internal ExclusiveGroupStruct @group { get; }
  40. readonly ushort _range;
  41. public bool isInvalid => group == ExclusiveGroupStruct.Invalid;
  42. }
  43. }