aa1f2b276e4b8ff8d8e1a2e1a9a8ea3d558b97fd.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, ECSModel, ECSComblockSystem, ECSRootSystem, ECSSystem, _crd;
  4. function _reportPossibleCrUseOfecs(extras) {
  5. _reporterNs.report("ecs", "./ECS", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfECSEntity(extras) {
  8. _reporterNs.report("ECSEntity", "./ECSEntity", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfECSGroup(extras) {
  11. _reporterNs.report("ECSGroup", "./ECSGroup", _context.meta, extras);
  12. }
  13. function _reportPossibleCrUseOfECSModel(extras) {
  14. _reporterNs.report("ECSModel", "./ECSModel", _context.meta, extras);
  15. }
  16. _export({
  17. ECSComblockSystem: void 0,
  18. ECSRootSystem: void 0,
  19. ECSSystem: void 0
  20. });
  21. return {
  22. setters: [function (_unresolved_) {
  23. _reporterNs = _unresolved_;
  24. }, function (_cc) {
  25. _cclegacy = _cc.cclegacy;
  26. }, function (_unresolved_2) {
  27. ECSModel = _unresolved_2.ECSModel;
  28. }],
  29. execute: function () {
  30. _crd = true;
  31. _cclegacy._RF.push({}, "9261fRWg2RBY5kxbFJsY1QC", "ECSSystem", undefined);
  32. /** 继承此类实现具体业务逻辑的系统 */
  33. _export("ECSComblockSystem", ECSComblockSystem = class ECSComblockSystem {
  34. /** 构造函数 */
  35. constructor() {
  36. this.group = void 0;
  37. this.dt = 0;
  38. this.enteredEntities = null;
  39. this.removedEntities = null;
  40. this.hasEntityEnter = false;
  41. this.hasEntityRemove = false;
  42. this.hasUpdate = false;
  43. this.tmpExecute = null;
  44. this.execute = void 0;
  45. let hasOwnProperty = Object.hasOwnProperty;
  46. let prototype = Object.getPrototypeOf(this);
  47. let hasEntityEnter = hasOwnProperty.call(prototype, 'entityEnter');
  48. let hasEntityRemove = hasOwnProperty.call(prototype, 'entityRemove');
  49. let hasFirstUpdate = hasOwnProperty.call(prototype, 'firstUpdate');
  50. let hasUpdate = hasOwnProperty.call(prototype, 'update');
  51. this.hasEntityEnter = hasEntityEnter;
  52. this.hasEntityRemove = hasEntityRemove;
  53. this.hasUpdate = hasUpdate;
  54. if (hasEntityEnter || hasEntityRemove) {
  55. this.enteredEntities = new Map();
  56. this.removedEntities = new Map();
  57. this.execute = this.execute1;
  58. this.group = (_crd && ECSModel === void 0 ? (_reportPossibleCrUseOfECSModel({
  59. error: Error()
  60. }), ECSModel) : ECSModel).createGroup(this.filter());
  61. this.group.watchEntityEnterAndRemove(this.enteredEntities, this.removedEntities);
  62. } else {
  63. this.execute = this.execute0;
  64. this.group = (_crd && ECSModel === void 0 ? (_reportPossibleCrUseOfECSModel({
  65. error: Error()
  66. }), ECSModel) : ECSModel).createGroup(this.filter());
  67. }
  68. if (hasFirstUpdate) {
  69. this.tmpExecute = this.execute;
  70. this.execute = this.updateOnce;
  71. }
  72. }
  73. /** 系统实始化 */
  74. init() {}
  75. /** 系统释放事件 */
  76. onDestroy() {}
  77. /** 是否存在实体 */
  78. hasEntity() {
  79. return this.group.count > 0;
  80. }
  81. /**
  82. * 先执行entityEnter,最后执行firstUpdate
  83. * @param dt
  84. * @returns
  85. */
  86. updateOnce(dt) {
  87. if (this.group.count === 0) {
  88. return;
  89. }
  90. this.dt = dt; // 处理刚进来的实体
  91. if (this.enteredEntities.size > 0) {
  92. var entities = this.enteredEntities.values();
  93. for (let entity of entities) {
  94. this.entityEnter(entity);
  95. }
  96. this.enteredEntities.clear();
  97. } // 只执行firstUpdate
  98. for (let entity of this.group.matchEntities) {
  99. this.firstUpdate(entity);
  100. }
  101. this.execute = this.tmpExecute;
  102. this.execute(dt);
  103. this.tmpExecute = null;
  104. }
  105. /**
  106. * 只执行update
  107. * @param dt
  108. * @returns
  109. */
  110. execute0(dt) {
  111. if (this.group.count === 0) return;
  112. this.dt = dt; // 执行update
  113. if (this.hasUpdate) {
  114. for (let entity of this.group.matchEntities) {
  115. this.update(entity);
  116. }
  117. }
  118. }
  119. /**
  120. * 先执行entityRemove,再执行entityEnter,最后执行update
  121. * @param dt
  122. * @returns
  123. */
  124. execute1(dt) {
  125. let entities;
  126. if (this.removedEntities.size > 0) {
  127. if (this.hasEntityRemove) {
  128. entities = this.removedEntities.values();
  129. for (let entity of entities) {
  130. this.entityRemove(entity);
  131. }
  132. }
  133. this.removedEntities.clear();
  134. }
  135. if (this.group.count === 0) return;
  136. this.dt = dt; // 处理刚进来的实体
  137. if (this.enteredEntities.size > 0) {
  138. if (this.hasEntityEnter) {
  139. entities = this.enteredEntities.values();
  140. for (let entity of entities) {
  141. this.entityEnter(entity);
  142. }
  143. }
  144. this.enteredEntities.clear();
  145. } // 执行update
  146. if (this.hasUpdate) {
  147. for (let entity of this.group.matchEntities) {
  148. this.update(entity);
  149. }
  150. }
  151. }
  152. /**
  153. * 实体过滤规则
  154. *
  155. * 根据提供的组件过滤实体。
  156. */
  157. });
  158. /** 根System,对游戏中的System遍历从这里开始,一个System组合中只能有一个RootSystem,可以有多个并行的RootSystem */
  159. ECSComblockSystem.s = true;
  160. _export("ECSRootSystem", ECSRootSystem = class ECSRootSystem {
  161. constructor() {
  162. this.executeSystemFlows = [];
  163. this.systemCnt = 0;
  164. }
  165. add(system) {
  166. if (system instanceof ECSSystem) {
  167. // 将嵌套的System都“摊平”,放在根System中进行遍历,减少execute的频繁进入退出。
  168. Array.prototype.push.apply(this.executeSystemFlows, system.comblockSystems);
  169. } else {
  170. this.executeSystemFlows.push(system);
  171. }
  172. this.systemCnt = this.executeSystemFlows.length;
  173. return this;
  174. }
  175. init() {
  176. // 自动注册系统组件
  177. (_crd && ECSModel === void 0 ? (_reportPossibleCrUseOfECSModel({
  178. error: Error()
  179. }), ECSModel) : ECSModel).systems.forEach(sys => this.add(sys)); // 初始化组件
  180. this.executeSystemFlows.forEach(sys => sys.init());
  181. }
  182. execute(dt) {
  183. for (let i = 0; i < this.systemCnt; i++) {
  184. // @ts-ignore
  185. this.executeSystemFlows[i].execute(dt);
  186. }
  187. }
  188. clear() {
  189. this.executeSystemFlows.forEach(sys => sys.onDestroy());
  190. }
  191. });
  192. /** 系统组合器,用于将多个相同功能模块的系统逻辑上放在一起,系统也可以嵌套系统 */
  193. _export("ECSSystem", ECSSystem = class ECSSystem {
  194. constructor() {
  195. this._comblockSystems = [];
  196. }
  197. get comblockSystems() {
  198. return this._comblockSystems;
  199. }
  200. add(system) {
  201. if (system instanceof ECSSystem) {
  202. Array.prototype.push.apply(this._comblockSystems, system._comblockSystems);
  203. system._comblockSystems.length = 0;
  204. } else {
  205. this._comblockSystems.push(system);
  206. }
  207. return this;
  208. }
  209. });
  210. _cclegacy._RF.pop();
  211. _crd = false;
  212. }
  213. };
  214. });
  215. //# sourceMappingURL=aa1f2b276e4b8ff8d8e1a2e1a9a8ea3d558b97fd.js.map