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.

83 lines
2.6KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Svelto.Tasks.Lean;
  7. using Svelto.Tasks.ExtraLean;
  8. namespace GamecraftModdingAPI.Tasks
  9. {
  10. /// <summary>
  11. /// Asynchronous task scheduling for ISchedulables.
  12. /// Asynchronous tasks will not freeze the main program, which makes them ideal for slow or blocking operations which don't need to be completed post-haste.
  13. /// The functionality of this class works in any state.
  14. /// </summary>
  15. public static class Scheduler
  16. {
  17. public static Svelto.Tasks.Lean.Unity.UpdateMonoRunner leanRunnerUI
  18. {
  19. get
  20. {
  21. return RobocraftX.Schedulers.Lean.UIScheduler;
  22. }
  23. }
  24. public static Svelto.Tasks.ExtraLean.Unity.UpdateMonoRunner extraLeanRunnerUI
  25. {
  26. get
  27. {
  28. return RobocraftX.Schedulers.ExtraLean.UIScheduler;
  29. }
  30. }
  31. public static readonly Svelto.Tasks.ExtraLean.Unity.UpdateMonoRunner extraLeanRunner = new Svelto.Tasks.ExtraLean.Unity.UpdateMonoRunner("GamecraftModdingAPIExtraLean");
  32. public static readonly Svelto.Tasks.Lean.Unity.UpdateMonoRunner leanRunner = new Svelto.Tasks.Lean.Unity.UpdateMonoRunner("GamecraftModdingAPILean");
  33. /// <summary>
  34. /// Schedule a task to run asynchronously.
  35. /// This uses custom task runners (by default) to not interfere with the game.
  36. /// </summary>
  37. /// <param name="toRun">The task to run</param>
  38. /// <param name="extraLean">Schedule toRun on an extra lean runner?</param>
  39. /// <param name="ui">Schedule toRun on Gamecraft's built-in UI task runner?</param>
  40. public static void Schedule(ISchedulable toRun, bool extraLean = false, bool ui = false)
  41. {
  42. if (extraLean)
  43. {
  44. if (ui)
  45. {
  46. toRun.Run().RunOn(extraLeanRunnerUI);
  47. }
  48. else
  49. {
  50. toRun.Run().RunOn(extraLeanRunner);
  51. }
  52. }
  53. else
  54. {
  55. if (ui)
  56. {
  57. toRun.Run().RunOn(leanRunnerUI);
  58. }
  59. else
  60. {
  61. toRun.Run().RunOn(leanRunner);
  62. }
  63. }
  64. }
  65. public static void Dispose()
  66. {
  67. leanRunner.Stop();
  68. extraLeanRunner.Stop();
  69. leanRunner.Dispose();
  70. extraLeanRunner.Dispose();
  71. }
  72. }
  73. }