FrameworkController.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Kailash.Framework.Adapter.Driven.Time;
  2. using System;
  3. using XGame.Framework.Data;
  4. using XGame.Framework.Database;
  5. using XGame.Framework.Memory;
  6. using XGame.Framework.ThreadScheduler;
  7. namespace XGame.Framework
  8. {
  9. internal class FrameworkController
  10. {
  11. private TimeCorrector _updateCorrector;
  12. private TimeCorrector _lateUpdateCorrector;
  13. /// <summary>
  14. /// 是否已销毁
  15. /// </summary>
  16. private Func<bool> _isDestroy;
  17. /// <summary>
  18. /// 是否已销毁
  19. /// </summary>
  20. private bool IsDestroy => _isDestroy?.Invoke() ?? true;
  21. public void Init(Func<bool> isDestroy)
  22. {
  23. _isDestroy = isDestroy;
  24. _updateCorrector = new TimeCorrector();
  25. _lateUpdateCorrector = new TimeCorrector();
  26. Profiler.BeginSample(this, "ObjectPool.Initialize");
  27. ObjectPool.Initialize();
  28. Profiler.EndSample();
  29. Profiler.BeginSample(this, "XOpencoding.Initialize");
  30. XOpencoding.Initialize();
  31. Profiler.EndSample();
  32. }
  33. public int Update()
  34. {
  35. FrameworkSchedulers.Update();
  36. if (IsDestroy)
  37. return 0;
  38. ThreadSchedulers.Update();
  39. if (IsDestroy)
  40. return 0;
  41. var elapse = _updateCorrector.GetCorrectedTime();
  42. MainThreadUpdateRegister.Update(elapse);
  43. return elapse;
  44. }
  45. public int LateUpdate()
  46. {
  47. var elapse = _lateUpdateCorrector.GetCorrectedTime();
  48. return elapse;
  49. }
  50. public void Dispose()
  51. {
  52. _isDestroy = null;
  53. FrameworkSchedulers.Dispose();
  54. ThreadSchedulers.Dispose();
  55. FrameworkEvent.Dispose();
  56. DataModule.Dispose();
  57. DatabaseModule.Dispose();
  58. ObjectPool.Dispose();
  59. XOpencoding.Dispose();
  60. MemoryMonitor.Dispose();
  61. }
  62. }
  63. }