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.

122 lines
3.8KB

  1. using System.Runtime.CompilerServices;
  2. using Svelto.DataStructures;
  3. using Svelto.ECS.Internal;
  4. namespace Svelto.ECS
  5. {
  6. public readonly ref struct EntityCollection<T> where T : struct, _IInternalEntityComponent
  7. {
  8. public EntityCollection(IBuffer<T> buffer, IEntityIDs entityIDs, uint count) : this()
  9. {
  10. DBC.ECS.Check.Require(count == 0 || buffer.isValid, "Buffer is found in impossible state");
  11. this.buffer = buffer;
  12. this.entityIDs = entityIDs;
  13. this.count = count;
  14. }
  15. public uint count { get; }
  16. public readonly IBufferBase buffer;
  17. public readonly IEntityIDs entityIDs;
  18. }
  19. public readonly ref struct EntityCollection<T1, T2> where T1 : struct, _IInternalEntityComponent
  20. where T2 : struct, _IInternalEntityComponent
  21. {
  22. internal EntityCollection(in EntityCollection<T1> array1, in EntityCollection<T2> array2)
  23. {
  24. buffer1 = array1;
  25. buffer2 = array2;
  26. }
  27. public int count => (int)buffer1.count;
  28. public EntityCollection<T2> buffer2
  29. {
  30. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  31. get;
  32. }
  33. public EntityCollection<T1> buffer1
  34. {
  35. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  36. get;
  37. }
  38. }
  39. public readonly ref struct EntityCollection<T1, T2, T3> where T3 : struct, _IInternalEntityComponent
  40. where T2 : struct, _IInternalEntityComponent
  41. where T1 : struct, _IInternalEntityComponent
  42. {
  43. internal EntityCollection
  44. (in EntityCollection<T1> array1, in EntityCollection<T2> array2, in EntityCollection<T3> array3)
  45. {
  46. buffer1 = array1;
  47. buffer2 = array2;
  48. buffer3 = array3;
  49. }
  50. public EntityCollection<T1> buffer1
  51. {
  52. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  53. get;
  54. }
  55. public EntityCollection<T2> buffer2
  56. {
  57. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  58. get;
  59. }
  60. public EntityCollection<T3> buffer3
  61. {
  62. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  63. get;
  64. }
  65. public int count => (int)buffer1.count;
  66. }
  67. public readonly ref struct EntityCollection<T1, T2, T3, T4> where T1 : struct, _IInternalEntityComponent
  68. where T2 : struct, _IInternalEntityComponent
  69. where T3 : struct, _IInternalEntityComponent
  70. where T4 : struct, _IInternalEntityComponent
  71. {
  72. internal EntityCollection
  73. (in EntityCollection<T1> array1, in EntityCollection<T2> array2, in EntityCollection<T3> array3
  74. , in EntityCollection<T4> array4)
  75. {
  76. buffer1 = array1;
  77. buffer2 = array2;
  78. buffer3 = array3;
  79. buffer4 = array4;
  80. }
  81. public EntityCollection<T1> buffer1
  82. {
  83. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  84. get;
  85. }
  86. public EntityCollection<T2> buffer2
  87. {
  88. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  89. get;
  90. }
  91. public EntityCollection<T3> buffer3
  92. {
  93. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  94. get;
  95. }
  96. public EntityCollection<T4> buffer4
  97. {
  98. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  99. get;
  100. }
  101. public int count => (int)buffer1.count;
  102. }
  103. }