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.

58 lines
1.7KB

  1. using System;
  2. using System.Collections;
  3. namespace Svelto.ECS.Schedulers
  4. {
  5. public sealed class SimpleEntitiesSubmissionScheduler : EntitiesSubmissionScheduler
  6. {
  7. public SimpleEntitiesSubmissionScheduler(uint maxNumberOfOperationsPerFrame = UInt32.MaxValue)
  8. {
  9. _maxNumberOfOperationsPerFrame = maxNumberOfOperationsPerFrame;
  10. }
  11. public IEnumerator SubmitEntitiesAsync()
  12. {
  13. if (paused == false)
  14. {
  15. var submitEntities = _onTick.Invoke(_maxNumberOfOperationsPerFrame);
  16. while (submitEntities.MoveNext())
  17. yield return null;
  18. }
  19. }
  20. public IEnumerator SubmitEntitiesAsync(uint maxNumberOfOperationsPerFrame)
  21. {
  22. if (paused == false)
  23. {
  24. var submitEntities = _onTick.Invoke(maxNumberOfOperationsPerFrame);
  25. while (submitEntities.MoveNext())
  26. yield return null;
  27. }
  28. }
  29. public void SubmitEntities()
  30. {
  31. var enumerator = SubmitEntitiesAsync();
  32. while (enumerator.MoveNext());
  33. }
  34. public override bool paused { get; set; }
  35. public override void Dispose() { }
  36. protected internal override EnginesRoot.EntitiesSubmitter onTick
  37. {
  38. set
  39. {
  40. DBC.ECS.Check.Require(_onTick.IsUnused, "a scheduler can be exclusively used by one enginesRoot only");
  41. _onTick = value;
  42. }
  43. }
  44. EnginesRoot.EntitiesSubmitter _onTick;
  45. readonly uint _maxNumberOfOperationsPerFrame;
  46. }
  47. }