FLGameLogic.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using FL.FGUI;
  2. using FL.Map;
  3. using FL.Nodes;
  4. using System;
  5. using System.Collections.Generic;
  6. using XGame;
  7. using XGame.Framework;
  8. using XGame.Framework.FGUI;
  9. using XGame.Framework.Interfaces;
  10. using XGame.Framework.Map;
  11. using XGame.Framework.Nodes;
  12. using XGame.Framework.Quality;
  13. using XGame.Framework.Time;
  14. using XGame.Framework.UI;
  15. namespace FL.Launch
  16. {
  17. public class FLGameLogic : IGameLogic
  18. {
  19. #region 接口实现
  20. private ITimeModule _timeModule;
  21. private IMapModule _mapModule;
  22. private IUIModule _uiModule;
  23. private INodeTree _nodeTree;
  24. /// <summary>
  25. /// 按照Map、UI、NodeTree的顺序刷新
  26. /// </summary>
  27. private List<IUpdate> _updates;
  28. /// <summary>
  29. /// 按照Map、UI、NodeTree的顺序刷新
  30. /// </summary>
  31. private List<ILateUpdate> _lateUpdates;
  32. void IGameLogic.Init()
  33. {
  34. Log.Debug("FLGameLogic.Init");
  35. InitModules();
  36. InitUpdates();
  37. }
  38. void IGameLogic.Start()
  39. {
  40. Log.Debug("FLGameLogic.Start");
  41. var appNode = _nodeTree.Root as FLAppNode;
  42. var async = appNode.LoadAsync();
  43. async.On(_ =>
  44. {
  45. appNode.Enable();
  46. if (_nodeTree is IUpdate nodeUpdate)
  47. {
  48. _updates.Add(nodeUpdate);
  49. }
  50. if (_nodeTree is ILateUpdate nodeLateUpdate)
  51. {
  52. _lateUpdates.Add(nodeLateUpdate);
  53. }
  54. });
  55. }
  56. void IGameLogic.Update(int millisecond)
  57. {
  58. foreach (var update in _updates)
  59. {
  60. update?.Update(millisecond);
  61. }
  62. }
  63. void IGameLogic.LateUpdate(int millisecond)
  64. {
  65. foreach (var lateUpdate in _lateUpdates)
  66. {
  67. lateUpdate?.LateUpdate(millisecond);
  68. }
  69. }
  70. void IGameLogic.Dispose()
  71. {
  72. Log.Debug("FLGameLogic.Dispose");
  73. _updates.Clear();
  74. _lateUpdates.Clear();
  75. EventSingle.Dispose();
  76. UIKeys.Dispose();
  77. UINestedKeys.Dispose();
  78. MapKeys.Dispose();
  79. (_timeModule as IDisposable)?.Dispose();
  80. (_mapModule as IDisposable)?.Dispose();
  81. (_uiModule as IDisposable)?.Dispose();
  82. (_nodeTree as IDisposable)?.Dispose();
  83. }
  84. #endregion
  85. private void InitModules()
  86. {
  87. var qualityModule = new QualityModule();
  88. var timeModule = new TimeModule();
  89. timeModule.Initialize();
  90. _timeModule = timeModule;
  91. //UI
  92. var uiBuilder = new FguiModuleBuilder();
  93. uiBuilder.Build(qualityModule, _timeModule);
  94. _uiModule = uiBuilder.Product;
  95. //Map
  96. var mapBuilder = new MapModuleBuilder();
  97. mapBuilder.Build(qualityModule, timeModule, _uiModule);
  98. _mapModule = mapBuilder.Product;
  99. //NodeTree
  100. var nodeBuild = new NodeTreeBuilder();
  101. nodeBuild.Build(qualityModule, timeModule, _uiModule, _mapModule, typeof(FLAppNode));
  102. _nodeTree = nodeBuild.Product;
  103. }
  104. private void InitUpdates()
  105. {
  106. _updates = new List<IUpdate>();
  107. _lateUpdates = new List<ILateUpdate>();
  108. if (_mapModule is IUpdate mapUpdate)
  109. {
  110. _updates.Add(mapUpdate);
  111. }
  112. if (_mapModule is ILateUpdate mapLateUpdate)
  113. {
  114. _lateUpdates.Add(mapLateUpdate);
  115. }
  116. if (_uiModule is IUpdate uiUpdate)
  117. {
  118. _updates.Add(uiUpdate);
  119. }
  120. if (_uiModule is ILateUpdate uiLateUpdate)
  121. {
  122. _lateUpdates.Add(uiLateUpdate);
  123. }
  124. }
  125. }
  126. }