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.

59 lines
1.6KB

  1. #if GODOT
  2. using System;
  3. using Godot;
  4. namespace Svelto.ECS.Schedulers.Godot
  5. {
  6. //The EntitySubmissionScheduler has been introduced to make the entity components submission logic platform independent
  7. //You can customize the scheduler if you wish
  8. public class GodotEntitySubmissionScheduler : EntitiesSubmissionScheduler
  9. {
  10. readonly GodotScheduler _scheduler;
  11. EnginesRoot.EntitiesSubmitter _onTick;
  12. /// <summary>
  13. /// Unlike unity. Creating a gameObject with new GameObject(name) will not add it to the current scene
  14. /// It needs to be added as a child to the scene (which is also a ~~gameObject~~Node)
  15. /// </summary>
  16. /// <param name="name"></param>
  17. /// <param name="parent"></param>
  18. public GodotEntitySubmissionScheduler(string name, Node parent)
  19. {
  20. _scheduler = new GodotScheduler();
  21. _scheduler.onTick = SubmitEntities;
  22. parent.AddChild(_scheduler);
  23. }
  24. private void SubmitEntities()
  25. {
  26. try
  27. {
  28. _onTick.SubmitEntities();
  29. }
  30. catch (Exception e)
  31. {
  32. paused = true;
  33. Svelto.Console.LogException(e);
  34. throw;
  35. }
  36. }
  37. protected internal override EnginesRoot.EntitiesSubmitter onTick
  38. {
  39. set => _onTick = value;
  40. }
  41. public override void Dispose()
  42. {
  43. if (_scheduler != null)
  44. {
  45. _scheduler.QueueFree();
  46. }
  47. }
  48. }
  49. }
  50. #endif