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.

64 lines
2.0KB

  1. using System;
  2. using System.Collections;
  3. namespace Svelto.ECS
  4. {
  5. public class WaitForSubmissionEnumerator : IEnumerator
  6. {
  7. class SubmissionEntityDescriptor : GenericEntityDescriptor<SubmissionSignalStruct>
  8. {
  9. internal static readonly ExclusiveGroup SubmissionGroup = new ExclusiveGroup();
  10. }
  11. readonly IEntityFactory _entityFactory;
  12. readonly IEntitiesDB _entitiesDB;
  13. readonly IEntityFunctions _entityFunctions;
  14. int _state;
  15. public WaitForSubmissionEnumerator(IEntityFunctions entityFunctions, IEntityFactory entityFactory,
  16. IEntitiesDB entitiesDb)
  17. {
  18. _entityFactory = entityFactory;
  19. _entityFunctions = entityFunctions;
  20. _entitiesDB = entitiesDb;
  21. }
  22. public bool MoveNext()
  23. {
  24. switch (_state)
  25. {
  26. case 0:
  27. _counter = _COUNTER++;
  28. _entityFactory.BuildEntity<SubmissionEntityDescriptor>(new EGID((uint) _counter,
  29. SubmissionEntityDescriptor.SubmissionGroup));
  30. _state = 1;
  31. return true;
  32. case 1:
  33. if (_entitiesDB.Exists<SubmissionSignalStruct>(new EGID((uint) _counter,
  34. SubmissionEntityDescriptor.SubmissionGroup)) == false)
  35. return true;
  36. _entityFunctions.RemoveEntity<SubmissionEntityDescriptor>(new EGID((uint) _counter,
  37. SubmissionEntityDescriptor.SubmissionGroup));
  38. _state = 0;
  39. return false;
  40. }
  41. throw new Exception("something is wrong");
  42. }
  43. void IEnumerator.Reset()
  44. {
  45. throw new NotImplementedException();
  46. }
  47. public object Current { get; }
  48. struct SubmissionSignalStruct : IEntityStruct
  49. {}
  50. int _counter;
  51. static int _COUNTER;
  52. }
  53. }