Mirror of Svelto.ECS because we're a fan of it
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

63 linhas
1.8KB

  1. namespace Svelto.ECS
  2. {
  3. public readonly ref struct NativeEntityFilterIterator<T> where T : unmanaged, IEntityComponent
  4. {
  5. internal NativeEntityFilterIterator(NativeEntityFilterCollection<T> filter)
  6. {
  7. _filter = filter;
  8. }
  9. public Iterator GetEnumerator() => new Iterator(_filter);
  10. readonly NativeEntityFilterCollection<T> _filter;
  11. public ref struct Iterator
  12. {
  13. internal Iterator(NativeEntityFilterCollection<T> filter)
  14. {
  15. _filter = filter;
  16. _indexGroup = -1;
  17. _current = default;
  18. }
  19. public bool MoveNext()
  20. {
  21. while (++_indexGroup < _filter.groupCount)
  22. {
  23. _current = _filter.GetGroup(_indexGroup);
  24. if (_current.count > 0) break;
  25. }
  26. return _indexGroup < _filter.groupCount;
  27. }
  28. public void Reset()
  29. {
  30. _indexGroup = -1;
  31. }
  32. public RefCurrent Current => new RefCurrent(_current);
  33. int _indexGroup;
  34. readonly NativeEntityFilterCollection<T> _filter;
  35. NativeEntityFilterCollection<T>.GroupFilters _current;
  36. }
  37. public readonly ref struct RefCurrent
  38. {
  39. internal RefCurrent(NativeEntityFilterCollection<T>.GroupFilters filter)
  40. {
  41. _filter = filter;
  42. }
  43. public void Deconstruct(out EntityFilterIndices indices, out ExclusiveGroupStruct group)
  44. {
  45. indices = _filter.indices;
  46. group = _filter.group;
  47. }
  48. readonly NativeEntityFilterCollection<T>.GroupFilters _filter;
  49. }
  50. }
  51. }