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.

49 lines
1.3KB

  1. using System.Runtime.CompilerServices;
  2. using System.Threading;
  3. using Svelto.DataStructures;
  4. namespace Svelto.ECS
  5. {
  6. //these are not meant to be held or passed by parameter.
  7. //however cannot be ref struct because of DOTS lambda design for entity queries Entities.ForEach
  8. public struct EntityFilterIndices
  9. {
  10. public EntityFilterIndices(NB<uint> indices, uint count)
  11. {
  12. _indices = indices;
  13. _count = count;
  14. _index = 0;
  15. }
  16. public int count
  17. {
  18. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  19. get => (int)_count;
  20. }
  21. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  22. public uint Get(uint index) => _indices[index];
  23. public uint this[uint index]
  24. {
  25. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  26. get => _indices[index];
  27. }
  28. public uint this[int index]
  29. {
  30. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  31. get => _indices[index];
  32. }
  33. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  34. public uint Next()
  35. {
  36. return _indices[Interlocked.Increment(ref _index) - 1];
  37. }
  38. readonly NBInternal<uint> _indices;
  39. readonly uint _count;
  40. int _index;
  41. }
  42. }