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.

81 lines
3.0KB

  1. #if UNITY_ECS
  2. using Svelto.Common;
  3. using Svelto.DataStructures;
  4. using Unity.Entities;
  5. using Unity.Jobs;
  6. namespace Svelto.ECS.SveltoOnDOTS
  7. {
  8. public class SyncDOTSToSveltoGroup : UnsortedJobifiedEnginesGroup<ISyncDOTSToSveltoEngine> {}
  9. public class SortedSyncDOTSToSveltoGroup<T_Order> : SortedJobifiedEnginesGroup<ISyncDOTSToSveltoEngine, T_Order>,
  10. ISyncDOTSToSveltoEngine where T_Order : struct, ISequenceOrder
  11. {
  12. public SortedSyncDOTSToSveltoGroup(FasterList<ISyncDOTSToSveltoEngine> engines) : base(engines)
  13. {
  14. }
  15. }
  16. public interface ISyncDOTSToSveltoEngine : IJobifiedEngine { }
  17. public abstract partial class SyncDOTSToSveltoEngine : SystemBase, ISyncDOTSToSveltoEngine
  18. {
  19. //The dependency returned is enough for the Svelto Engines running after this to take in consideration
  20. //the Systembase jobs. The svelto engines do not need to take in consideration the new dependencies created
  21. //by the World.Update because those are independent and are needed only by the next World.Update() jobs
  22. public JobHandle Execute(JobHandle inputDeps)
  23. {
  24. _inputDeps = inputDeps;
  25. Update(); //this complete the previous frame jobs so dependency cannot be modified atr this point
  26. return Dependency;
  27. }
  28. //TODO if this is correct must change SyncDOTSToSveltoGroup too
  29. protected sealed override void OnUpdate()
  30. {
  31. //SysteBase jobs that will use this Dependency will wait for inputDeps to be completed before to execute
  32. Dependency = JobHandle.CombineDependencies(Dependency, _inputDeps);
  33. OnSveltoUpdate();
  34. }
  35. protected abstract void OnSveltoUpdate();
  36. public abstract string name { get; }
  37. JobHandle _inputDeps;
  38. }
  39. public abstract partial class SortedSyncDOTSToSveltoEngine : SystemBase, ISyncDOTSToSveltoEngine
  40. {
  41. //The dependency returned is enough for the Svelto Engines running after this to take in consideration
  42. //the Systembase jobs. The svelto engines do not need to take in consideration the new dependencies created
  43. //by the World.Update because those are independent and are needed only by the next World.Update() jobs
  44. public JobHandle Execute(JobHandle inputDeps)
  45. {
  46. _inputDeps = inputDeps;
  47. Update(); //this complete the previous frame jobs so dependency cannot be modified atr this point
  48. return Dependency;
  49. }
  50. //TODO if this is correct must change SyncDOTSToSveltoGroup too
  51. protected sealed override void OnUpdate()
  52. {
  53. //SysteBase jobs that will use this Dependency will wait for inputDeps to be completed before to execute
  54. Dependency = JobHandle.CombineDependencies(Dependency, _inputDeps);
  55. OnSveltoUpdate();
  56. }
  57. protected abstract void OnSveltoUpdate();
  58. public abstract string name { get; }
  59. JobHandle _inputDeps;
  60. }
  61. }
  62. #endif