FrameworkController.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using XGame.Framework.Data;
  3. using XGame.Framework.Database;
  4. using XGame.Framework.Memory;
  5. using XGame.Framework.ThreadScheduler;
  6. using XGame.Framework.Time;
  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. ListPool.Initialize();
  29. Profiler.EndSample();
  30. Profiler.BeginSample(this, "XOpencoding.Initialize");
  31. XOpencoding.Initialize();
  32. Profiler.EndSample();
  33. }
  34. public int Update()
  35. {
  36. FrameworkSchedulers.Update();
  37. if (IsDestroy)
  38. return 0;
  39. ThreadSchedulers.Update();
  40. if (IsDestroy)
  41. return 0;
  42. var elapse = _updateCorrector.GetCorrectedTime();
  43. MainThreadUpdateRegister.Update(elapse);
  44. return elapse;
  45. }
  46. public int LateUpdate()
  47. {
  48. var elapse = _lateUpdateCorrector.GetCorrectedTime();
  49. return elapse;
  50. }
  51. public void Dispose()
  52. {
  53. _isDestroy = null;
  54. FrameworkSchedulers.Dispose();
  55. ThreadSchedulers.Dispose();
  56. FrameworkEvent.Dispose();
  57. DataModule.Dispose();
  58. DatabaseModule.Dispose();
  59. ListPool.Dispose();
  60. ObjectPool.Dispose();
  61. XOpencoding.Dispose();
  62. MemoryMonitor.Dispose();
  63. }
  64. }
  65. }