A stable modding interface between Techblox and mods https://mod.exmods.org/
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.

AsyncUtilsEngine.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections;
  2. using System.Threading.Tasks;
  3. using RobocraftX.Schedulers;
  4. using Svelto.ECS;
  5. using Svelto.Tasks.ExtraLean;
  6. using GamecraftModdingAPI.Engines;
  7. namespace GamecraftModdingAPI.Utility
  8. {
  9. public class AsyncUtilsEngine : IApiEngine
  10. {
  11. private IEntityFunctions _efu;
  12. private IEntityFactory _efa;
  13. private IEnumerator WaitForSubmissionInternal(IEntityFunctions efu, IEntityFactory efa,
  14. EntitiesDB entitiesDB, TaskCompletionSource<object> task)
  15. {
  16. var waitEnumerator = new WaitForSubmissionEnumerator(efu, efa, entitiesDB);
  17. while (waitEnumerator.MoveNext())
  18. yield return null;
  19. task.SetResult(null);
  20. }
  21. private IEnumerator WaitForNextFrameInternal(TaskCompletionSource<object> task)
  22. {
  23. yield return null;
  24. task.SetResult(null);
  25. }
  26. public Task WaitForSubmission()
  27. {
  28. var task = new TaskCompletionSource<object>();
  29. WaitForSubmissionInternal(_efu, _efa, entitiesDB, task).RunOn(ExtraLean.EveryFrameStepRunner);
  30. return task.Task;
  31. }
  32. public Task WaitForNextFrame()
  33. {
  34. var task = new TaskCompletionSource<object>();
  35. WaitForNextFrameInternal(task).RunOn(ExtraLean.EveryFrameStepRunner);
  36. return task.Task;
  37. }
  38. public void Setup(IEntityFunctions efu, IEntityFactory efa)
  39. {
  40. _efu = efu;
  41. _efa = efa;
  42. }
  43. public void Ready()
  44. {
  45. }
  46. public EntitiesDB entitiesDB { get; set; }
  47. public void Dispose()
  48. {
  49. }
  50. public string Name { get; } = "GamecraftModdingAPIAsyncUtilsGameEngine";
  51. public bool isRemovable { get; } = false;
  52. }
  53. }