@esengine/ecs-framework 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +277 -0
  3. package/bin/Core.d.ts +198 -0
  4. package/bin/Core.d.ts.map +1 -0
  5. package/bin/Core.js +249 -0
  6. package/bin/Core.js.map +1 -0
  7. package/bin/ECS/Component.d.ts +119 -0
  8. package/bin/ECS/Component.d.ts.map +1 -0
  9. package/bin/ECS/Component.js +129 -0
  10. package/bin/ECS/Component.js.map +1 -0
  11. package/bin/ECS/Components/IUpdatable.d.ts +22 -0
  12. package/bin/ECS/Components/IUpdatable.d.ts.map +1 -0
  13. package/bin/ECS/Components/IUpdatable.js +17 -0
  14. package/bin/ECS/Components/IUpdatable.js.map +1 -0
  15. package/bin/ECS/Components/SceneComponent.d.ts +40 -0
  16. package/bin/ECS/Components/SceneComponent.d.ts.map +1 -0
  17. package/bin/ECS/Components/SceneComponent.js +57 -0
  18. package/bin/ECS/Components/SceneComponent.js.map +1 -0
  19. package/bin/ECS/Core/ComponentStorage.d.ts +182 -0
  20. package/bin/ECS/Core/ComponentStorage.d.ts.map +1 -0
  21. package/bin/ECS/Core/ComponentStorage.js +346 -0
  22. package/bin/ECS/Core/ComponentStorage.js.map +1 -0
  23. package/bin/ECS/Core/EventSystem.d.ts +236 -0
  24. package/bin/ECS/Core/EventSystem.d.ts.map +1 -0
  25. package/bin/ECS/Core/EventSystem.js +476 -0
  26. package/bin/ECS/Core/EventSystem.js.map +1 -0
  27. package/bin/ECS/Core/FluentAPI.d.ts +392 -0
  28. package/bin/ECS/Core/FluentAPI.d.ts.map +1 -0
  29. package/bin/ECS/Core/FluentAPI.js +575 -0
  30. package/bin/ECS/Core/FluentAPI.js.map +1 -0
  31. package/bin/ECS/Core/QuerySystem.d.ts +574 -0
  32. package/bin/ECS/Core/QuerySystem.d.ts.map +1 -0
  33. package/bin/ECS/Core/QuerySystem.js +1356 -0
  34. package/bin/ECS/Core/QuerySystem.js.map +1 -0
  35. package/bin/ECS/CoreEvents.d.ts +19 -0
  36. package/bin/ECS/CoreEvents.d.ts.map +1 -0
  37. package/bin/ECS/CoreEvents.js +20 -0
  38. package/bin/ECS/CoreEvents.js.map +1 -0
  39. package/bin/ECS/Entity.d.ts +585 -0
  40. package/bin/ECS/Entity.d.ts.map +1 -0
  41. package/bin/ECS/Entity.js +1079 -0
  42. package/bin/ECS/Entity.js.map +1 -0
  43. package/bin/ECS/Scene.d.ts +210 -0
  44. package/bin/ECS/Scene.d.ts.map +1 -0
  45. package/bin/ECS/Scene.js +267 -0
  46. package/bin/ECS/Scene.js.map +1 -0
  47. package/bin/ECS/Systems/EntitySystem.d.ts +185 -0
  48. package/bin/ECS/Systems/EntitySystem.d.ts.map +1 -0
  49. package/bin/ECS/Systems/EntitySystem.js +278 -0
  50. package/bin/ECS/Systems/EntitySystem.js.map +1 -0
  51. package/bin/ECS/Systems/IntervalSystem.d.ts +33 -0
  52. package/bin/ECS/Systems/IntervalSystem.d.ts.map +1 -0
  53. package/bin/ECS/Systems/IntervalSystem.js +50 -0
  54. package/bin/ECS/Systems/IntervalSystem.js.map +1 -0
  55. package/bin/ECS/Systems/PassiveSystem.d.ts +20 -0
  56. package/bin/ECS/Systems/PassiveSystem.d.ts.map +1 -0
  57. package/bin/ECS/Systems/PassiveSystem.js +21 -0
  58. package/bin/ECS/Systems/PassiveSystem.js.map +1 -0
  59. package/bin/ECS/Systems/ProcessingSystem.d.ts +24 -0
  60. package/bin/ECS/Systems/ProcessingSystem.d.ts.map +1 -0
  61. package/bin/ECS/Systems/ProcessingSystem.js +22 -0
  62. package/bin/ECS/Systems/ProcessingSystem.js.map +1 -0
  63. package/bin/ECS/Systems/index.d.ts +5 -0
  64. package/bin/ECS/Systems/index.d.ts.map +1 -0
  65. package/bin/ECS/Systems/index.js +6 -0
  66. package/bin/ECS/Systems/index.js.map +1 -0
  67. package/bin/ECS/Transform.d.ts +178 -0
  68. package/bin/ECS/Transform.d.ts.map +1 -0
  69. package/bin/ECS/Transform.js +249 -0
  70. package/bin/ECS/Transform.js.map +1 -0
  71. package/bin/ECS/Utils/Bits.d.ts +74 -0
  72. package/bin/ECS/Utils/Bits.d.ts.map +1 -0
  73. package/bin/ECS/Utils/Bits.js +142 -0
  74. package/bin/ECS/Utils/Bits.js.map +1 -0
  75. package/bin/ECS/Utils/ComponentTypeManager.d.ts +50 -0
  76. package/bin/ECS/Utils/ComponentTypeManager.d.ts.map +1 -0
  77. package/bin/ECS/Utils/ComponentTypeManager.js +84 -0
  78. package/bin/ECS/Utils/ComponentTypeManager.js.map +1 -0
  79. package/bin/ECS/Utils/EntityList.d.ts +108 -0
  80. package/bin/ECS/Utils/EntityList.d.ts.map +1 -0
  81. package/bin/ECS/Utils/EntityList.js +249 -0
  82. package/bin/ECS/Utils/EntityList.js.map +1 -0
  83. package/bin/ECS/Utils/EntityProcessorList.d.ts +53 -0
  84. package/bin/ECS/Utils/EntityProcessorList.d.ts.map +1 -0
  85. package/bin/ECS/Utils/EntityProcessorList.js +96 -0
  86. package/bin/ECS/Utils/EntityProcessorList.js.map +1 -0
  87. package/bin/ECS/Utils/IdentifierPool.d.ts +18 -0
  88. package/bin/ECS/Utils/IdentifierPool.d.ts.map +1 -0
  89. package/bin/ECS/Utils/IdentifierPool.js +27 -0
  90. package/bin/ECS/Utils/IdentifierPool.js.map +1 -0
  91. package/bin/ECS/Utils/Matcher.d.ts +63 -0
  92. package/bin/ECS/Utils/Matcher.d.ts.map +1 -0
  93. package/bin/ECS/Utils/Matcher.js +140 -0
  94. package/bin/ECS/Utils/Matcher.js.map +1 -0
  95. package/bin/ECS/Utils/index.d.ts +7 -0
  96. package/bin/ECS/Utils/index.d.ts.map +1 -0
  97. package/bin/ECS/Utils/index.js +8 -0
  98. package/bin/ECS/Utils/index.js.map +1 -0
  99. package/bin/ECS/index.d.ts +8 -0
  100. package/bin/ECS/index.d.ts.map +1 -0
  101. package/bin/ECS/index.js +9 -0
  102. package/bin/ECS/index.js.map +1 -0
  103. package/bin/Math/Edge.d.ts +23 -0
  104. package/bin/Math/Edge.d.ts.map +1 -0
  105. package/bin/Math/Edge.js +24 -0
  106. package/bin/Math/Edge.js.map +1 -0
  107. package/bin/Math/MathHelper.d.ts +75 -0
  108. package/bin/Math/MathHelper.d.ts.map +1 -0
  109. package/bin/Math/MathHelper.js +91 -0
  110. package/bin/Math/MathHelper.js.map +1 -0
  111. package/bin/Math/Rectangle.d.ts +126 -0
  112. package/bin/Math/Rectangle.d.ts.map +1 -0
  113. package/bin/Math/Rectangle.js +181 -0
  114. package/bin/Math/Rectangle.js.map +1 -0
  115. package/bin/Math/Vector2.d.ts +229 -0
  116. package/bin/Math/Vector2.d.ts.map +1 -0
  117. package/bin/Math/Vector2.js +338 -0
  118. package/bin/Math/Vector2.js.map +1 -0
  119. package/bin/Math/index.d.ts +5 -0
  120. package/bin/Math/index.d.ts.map +1 -0
  121. package/bin/Math/index.js +6 -0
  122. package/bin/Math/index.js.map +1 -0
  123. package/bin/Types/index.d.ts +22 -0
  124. package/bin/Types/index.d.ts.map +1 -0
  125. package/bin/Types/index.js +20 -0
  126. package/bin/Types/index.js.map +1 -0
  127. package/bin/Utils/Emitter.d.ts +43 -0
  128. package/bin/Utils/Emitter.d.ts.map +1 -0
  129. package/bin/Utils/Emitter.js +69 -0
  130. package/bin/Utils/Emitter.js.map +1 -0
  131. package/bin/Utils/Extensions/EdgeExt.d.ts +26 -0
  132. package/bin/Utils/Extensions/EdgeExt.d.ts.map +1 -0
  133. package/bin/Utils/Extensions/EdgeExt.js +41 -0
  134. package/bin/Utils/Extensions/EdgeExt.js.map +1 -0
  135. package/bin/Utils/Extensions/NumberExtension.d.ts +13 -0
  136. package/bin/Utils/Extensions/NumberExtension.d.ts.map +1 -0
  137. package/bin/Utils/Extensions/NumberExtension.js +17 -0
  138. package/bin/Utils/Extensions/NumberExtension.js.map +1 -0
  139. package/bin/Utils/Extensions/TypeUtils.d.ts +13 -0
  140. package/bin/Utils/Extensions/TypeUtils.d.ts.map +1 -0
  141. package/bin/Utils/Extensions/TypeUtils.js +15 -0
  142. package/bin/Utils/Extensions/TypeUtils.js.map +1 -0
  143. package/bin/Utils/Extensions/index.d.ts +4 -0
  144. package/bin/Utils/Extensions/index.d.ts.map +1 -0
  145. package/bin/Utils/Extensions/index.js +5 -0
  146. package/bin/Utils/Extensions/index.js.map +1 -0
  147. package/bin/Utils/GlobalManager.d.ts +32 -0
  148. package/bin/Utils/GlobalManager.d.ts.map +1 -0
  149. package/bin/Utils/GlobalManager.js +53 -0
  150. package/bin/Utils/GlobalManager.js.map +1 -0
  151. package/bin/Utils/PerformanceMonitor.d.ts +211 -0
  152. package/bin/Utils/PerformanceMonitor.d.ts.map +1 -0
  153. package/bin/Utils/PerformanceMonitor.js +270 -0
  154. package/bin/Utils/PerformanceMonitor.js.map +1 -0
  155. package/bin/Utils/Pool.d.ts +239 -0
  156. package/bin/Utils/Pool.d.ts.map +1 -0
  157. package/bin/Utils/Pool.js +449 -0
  158. package/bin/Utils/Pool.js.map +1 -0
  159. package/bin/Utils/Screen.d.ts +12 -0
  160. package/bin/Utils/Screen.d.ts.map +1 -0
  161. package/bin/Utils/Screen.js +14 -0
  162. package/bin/Utils/Screen.js.map +1 -0
  163. package/bin/Utils/Time.d.ts +55 -0
  164. package/bin/Utils/Time.d.ts.map +1 -0
  165. package/bin/Utils/Time.js +78 -0
  166. package/bin/Utils/Time.js.map +1 -0
  167. package/bin/Utils/Timers/ITimer.d.ts +16 -0
  168. package/bin/Utils/Timers/ITimer.d.ts.map +1 -0
  169. package/bin/Utils/Timers/ITimer.js +2 -0
  170. package/bin/Utils/Timers/ITimer.js.map +1 -0
  171. package/bin/Utils/Timers/Timer.d.ts +22 -0
  172. package/bin/Utils/Timers/Timer.d.ts.map +1 -0
  173. package/bin/Utils/Timers/Timer.js +46 -0
  174. package/bin/Utils/Timers/Timer.js.map +1 -0
  175. package/bin/Utils/Timers/TimerManager.d.ts +19 -0
  176. package/bin/Utils/Timers/TimerManager.d.ts.map +1 -0
  177. package/bin/Utils/Timers/TimerManager.js +33 -0
  178. package/bin/Utils/Timers/TimerManager.js.map +1 -0
  179. package/bin/Utils/index.d.ts +6 -0
  180. package/bin/Utils/index.d.ts.map +1 -0
  181. package/bin/Utils/index.js +7 -0
  182. package/bin/Utils/index.js.map +1 -0
  183. package/bin/index.d.ts +21 -0
  184. package/bin/index.d.ts.map +1 -0
  185. package/bin/index.js +26 -0
  186. package/bin/index.js.map +1 -0
  187. package/package.json +68 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,277 @@
1
+ # ECS Framework
2
+
3
+ [![npm version](https://badge.fury.io/js/%40esengine%2Fecs-framework.svg)](https://badge.fury.io/js/%40esengine%2Fecs-framework)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ 一个轻量级的 TypeScript ECS(Entity-Component-System)框架,专为小游戏开发设计,适用于 Laya、Cocos 等游戏引擎。
7
+
8
+ ## ✨ 特性
9
+
10
+ - 🚀 **轻量级 ECS 架构** - 基于实体组件系统,提供清晰的代码结构
11
+ - 📡 **事件系统** - 内置 Emitter 事件发射器,支持类型安全的事件管理
12
+ - ⏰ **定时器系统** - 完整的定时器管理,支持延迟和重复任务
13
+ - 🔍 **查询系统** - 基于位掩码的高性能实体查询
14
+ - 🛠️ **性能监控** - 内置性能监控工具,帮助优化游戏性能
15
+ - 🎯 **对象池** - 内存管理优化,减少垃圾回收压力
16
+ - 📊 **数学库** - 完整的 2D 数学运算支持
17
+
18
+ ## 📦 安装
19
+
20
+ ```bash
21
+ npm install @esengine/ecs-framework
22
+ ```
23
+
24
+ ## 🚀 快速开始
25
+
26
+ ### 1. 初始化框架
27
+
28
+ ```typescript
29
+ import * as es from '@esengine/ecs-framework';
30
+
31
+ // 创建 Core 实例
32
+ const core = es.Core.create(true); // true 表示开启调试模式
33
+
34
+ // 在游戏循环中更新框架
35
+ function gameLoop() {
36
+ // 发送帧更新事件
37
+ es.Core.emitter.emit(es.CoreEvents.frameUpdated);
38
+ }
39
+ ```
40
+
41
+ ### 2. 创建场景
42
+
43
+ ```typescript
44
+ class GameScene extends es.Scene {
45
+ public initialize() {
46
+ // 创建玩家实体
47
+ const player = this.createEntity("Player");
48
+
49
+ // 设置位置
50
+ player.position = new es.Vector2(100, 100);
51
+
52
+ // 添加自定义组件
53
+ const movement = player.addComponent(new MovementComponent());
54
+
55
+ // 添加系统
56
+ this.addEntityProcessor(new MovementSystem());
57
+ }
58
+
59
+ public onStart() {
60
+ console.log("游戏场景已启动");
61
+ }
62
+ }
63
+
64
+ // 设置当前场景
65
+ es.Core.scene = new GameScene();
66
+ ```
67
+
68
+ ### 3. 创建组件
69
+
70
+ ```typescript
71
+ class MovementComponent extends es.Component {
72
+ public speed: number = 100;
73
+ public direction: es.Vector2 = es.Vector2.zero;
74
+
75
+ public update() {
76
+ if (this.direction.length > 0) {
77
+ const movement = this.direction.multiply(this.speed * es.Time.deltaTime);
78
+ this.entity.position = this.entity.position.add(movement);
79
+ }
80
+ }
81
+ }
82
+ ```
83
+
84
+ ### 4. 创建系统
85
+
86
+ ```typescript
87
+ class MovementSystem extends es.EntitySystem {
88
+ protected process(entities: es.Entity[]) {
89
+ for (const entity of entities) {
90
+ const movement = entity.getComponent(MovementComponent);
91
+ if (movement) {
92
+ movement.update();
93
+ }
94
+ }
95
+ }
96
+ }
97
+ ```
98
+
99
+ ## 📚 核心概念
100
+
101
+ ### Entity(实体)
102
+ 实体是游戏世界中的基本对象,包含位置、旋转、缩放等基本属性,可以添加组件来扩展功能。
103
+
104
+ ```typescript
105
+ const entity = scene.createEntity("MyEntity");
106
+ entity.position = new es.Vector2(100, 200);
107
+ entity.rotation = Math.PI / 4;
108
+ entity.scale = new es.Vector2(2, 2);
109
+ ```
110
+
111
+ ### Component(组件)
112
+ 组件包含数据和行为,定义了实体的特性。
113
+
114
+ ```typescript
115
+ class HealthComponent extends es.Component {
116
+ public maxHealth: number = 100;
117
+ public currentHealth: number = 100;
118
+
119
+ public takeDamage(damage: number) {
120
+ this.currentHealth = Math.max(0, this.currentHealth - damage);
121
+ if (this.currentHealth <= 0) {
122
+ this.entity.destroy();
123
+ }
124
+ }
125
+ }
126
+ ```
127
+
128
+ ### System(系统)
129
+ 系统处理实体集合,实现游戏逻辑。
130
+
131
+ ```typescript
132
+ class HealthSystem extends es.EntitySystem {
133
+ protected process(entities: es.Entity[]) {
134
+ for (const entity of entities) {
135
+ const health = entity.getComponent(HealthComponent);
136
+ if (health && health.currentHealth <= 0) {
137
+ entity.destroy();
138
+ }
139
+ }
140
+ }
141
+ }
142
+ ```
143
+
144
+ ## 🎮 高级功能
145
+
146
+ ### 事件系统
147
+
148
+ ```typescript
149
+ // 监听事件
150
+ es.Core.emitter.addObserver(es.CoreEvents.frameUpdated, this.onFrameUpdate, this);
151
+
152
+ // 发射自定义事件
153
+ es.Core.emitter.emit("playerDied", { player: entity, score: 1000 });
154
+
155
+ // 移除监听
156
+ es.Core.emitter.removeObserver(es.CoreEvents.frameUpdated, this.onFrameUpdate);
157
+ ```
158
+
159
+ ### 定时器系统
160
+
161
+ ```typescript
162
+ // 延迟执行
163
+ es.Core.schedule(2.0, false, this, (timer) => {
164
+ console.log("2秒后执行");
165
+ });
166
+
167
+ // 重复执行
168
+ es.Core.schedule(1.0, true, this, (timer) => {
169
+ console.log("每秒执行一次");
170
+ });
171
+ ```
172
+
173
+ ### 实体查询
174
+
175
+ ```typescript
176
+ // 按名称查找
177
+ const player = scene.findEntity("Player");
178
+
179
+ // 按标签查找
180
+ const enemies = scene.findEntitiesByTag(1);
181
+
182
+ // 按ID查找
183
+ const entity = scene.findEntityById(123);
184
+ ```
185
+
186
+ ### 性能监控
187
+
188
+ ```typescript
189
+ // 获取性能数据
190
+ const monitor = es.PerformanceMonitor.instance;
191
+ console.log("平均FPS:", monitor.averageFPS);
192
+ console.log("内存使用:", monitor.memoryUsage);
193
+ ```
194
+
195
+ ## 🛠️ 开发工具
196
+
197
+ ### 对象池
198
+
199
+ ```typescript
200
+ // 创建对象池
201
+ class BulletPool extends es.Pool<Bullet> {
202
+ protected createObject(): Bullet {
203
+ return new Bullet();
204
+ }
205
+ }
206
+
207
+ const bulletPool = new BulletPool();
208
+
209
+ // 获取对象
210
+ const bullet = bulletPool.obtain();
211
+
212
+ // 释放对象
213
+ bulletPool.free(bullet);
214
+ ```
215
+
216
+ ### 实体调试
217
+
218
+ ```typescript
219
+ // 获取实体调试信息
220
+ const debugInfo = entity.getDebugInfo();
221
+ console.log("实体信息:", debugInfo);
222
+
223
+ // 获取场景统计
224
+ const stats = scene.getStats();
225
+ console.log("场景统计:", stats);
226
+ ```
227
+
228
+ ## 📖 文档
229
+
230
+ - [快速入门](docs/getting-started.md) - 从零开始学习框架使用
231
+ - [核心概念](docs/core-concepts.md) - 深入了解 ECS 架构和设计原理
232
+ - [查询系统使用指南](docs/query-system-usage.md) - 学习高性能查询系统的详细用法
233
+
234
+ ## 🔗 扩展库
235
+
236
+ - [路径寻找库](https://github.com/esengine/ecs-astar) - A*、广度优先、Dijkstra、GOAP 算法
237
+ - [AI 系统](https://github.com/esengine/BehaviourTree-ai) - 行为树、效用 AI 系统
238
+
239
+ ## 🤝 贡献
240
+
241
+ 欢迎提交 Issue 和 Pull Request!
242
+
243
+ ### 开发环境设置
244
+
245
+ ```bash
246
+ # 克隆项目
247
+ git clone https://github.com/esengine/ecs-framework.git
248
+
249
+ # 进入源码目录
250
+ cd ecs-framework/source
251
+
252
+ # 安装依赖
253
+ npm install
254
+
255
+ # 构建项目
256
+ npm run build
257
+
258
+ # 运行测试
259
+ npm test
260
+ ```
261
+
262
+ ### 构建要求
263
+
264
+ - Node.js >= 14.0.0
265
+ - TypeScript >= 4.0.0
266
+
267
+ ## 📄 许可证
268
+
269
+ 本项目采用 [MIT](LICENSE) 许可证。
270
+
271
+ ## 💬 交流群
272
+
273
+ 加入 QQ 群讨论:[ecs游戏框架交流](https://jq.qq.com/?_wv=1027&k=29w1Nud6)
274
+
275
+ ---
276
+
277
+ **ECS Framework** - 让游戏开发更简单、更高效!
package/bin/Core.d.ts ADDED
@@ -0,0 +1,198 @@
1
+ import { Emitter } from './Utils/Emitter';
2
+ import { CoreEvents } from './ECS/CoreEvents';
3
+ import { GlobalManager } from './Utils/GlobalManager';
4
+ import { TimerManager } from './Utils/Timers/TimerManager';
5
+ import { ITimer } from './Utils/Timers/ITimer';
6
+ import { PerformanceMonitor } from './Utils/PerformanceMonitor';
7
+ import { PoolManager } from './Utils/Pool';
8
+ import { ECSFluentAPI } from './ECS/Core/FluentAPI';
9
+ import { Scene } from './ECS/Scene';
10
+ /**
11
+ * 游戏引擎核心类
12
+ *
13
+ * 负责管理游戏的生命周期、场景切换、全局管理器和定时器系统。
14
+ * 提供统一的游戏循环和事件分发机制。
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // 创建核心实例
19
+ * const core = Core.create(true);
20
+ *
21
+ * // 设置场景
22
+ * Core.scene = new MyScene();
23
+ *
24
+ * // 调度定时器
25
+ * Core.schedule(1.0, false, null, (timer) => {
26
+ * console.log("1秒后执行");
27
+ * });
28
+ * ```
29
+ */
30
+ export declare class Core {
31
+ /**
32
+ * 核心事件发射器
33
+ *
34
+ * 用于发布和订阅核心级别的事件,如帧更新、场景切换等。
35
+ */
36
+ static emitter: Emitter<CoreEvents>;
37
+ /**
38
+ * 游戏暂停状态
39
+ *
40
+ * 当设置为true时,游戏循环将暂停执行。
41
+ */
42
+ static paused: boolean;
43
+ /**
44
+ * 全局核心实例
45
+ */
46
+ private static _instance;
47
+ /**
48
+ * 实体系统启用状态
49
+ *
50
+ * 控制是否启用ECS实体系统功能。
51
+ */
52
+ static entitySystemsEnabled: boolean;
53
+ /**
54
+ * 调试模式标志
55
+ *
56
+ * 在调试模式下会启用额外的性能监控和错误检查。
57
+ */
58
+ readonly debug: boolean;
59
+ /**
60
+ * 待切换的场景
61
+ *
62
+ * 存储下一帧要切换到的场景实例。
63
+ */
64
+ _nextScene: Scene | null;
65
+ /**
66
+ * 全局管理器集合
67
+ *
68
+ * 存储所有注册的全局管理器实例。
69
+ */
70
+ _globalManagers: GlobalManager[];
71
+ /**
72
+ * 定时器管理器
73
+ *
74
+ * 负责管理所有的游戏定时器。
75
+ */
76
+ _timerManager: TimerManager;
77
+ /**
78
+ * 性能监控器
79
+ *
80
+ * 监控游戏性能并提供优化建议。
81
+ */
82
+ _performanceMonitor: PerformanceMonitor;
83
+ /**
84
+ * 对象池管理器
85
+ *
86
+ * 管理所有对象池的生命周期。
87
+ */
88
+ _poolManager: PoolManager;
89
+ /**
90
+ * ECS流式API
91
+ *
92
+ * 提供便捷的ECS操作接口。
93
+ */
94
+ _ecsAPI?: ECSFluentAPI;
95
+ /**
96
+ * 当前活动场景
97
+ */
98
+ _scene?: Scene;
99
+ /**
100
+ * 创建核心实例
101
+ *
102
+ * @param debug - 是否启用调试模式,默认为true
103
+ * @param enableEntitySystems - 是否启用实体系统,默认为true
104
+ */
105
+ private constructor();
106
+ /**
107
+ * 获取核心实例
108
+ *
109
+ * @returns 全局核心实例
110
+ */
111
+ static get Instance(): Core;
112
+ /**
113
+ * 获取当前活动的场景
114
+ *
115
+ * @returns 当前场景实例,如果没有则返回null
116
+ */
117
+ static get scene(): Scene | null;
118
+ /**
119
+ * 设置当前活动的场景
120
+ *
121
+ * 如果当前没有场景,会立即切换;否则会在下一帧切换。
122
+ *
123
+ * @param value - 要设置的场景实例
124
+ * @throws {Error} 当场景为空时抛出错误
125
+ */
126
+ static set scene(value: Scene | null);
127
+ /**
128
+ * 创建Core实例
129
+ *
130
+ * 如果实例已存在,则返回现有实例。
131
+ *
132
+ * @param debug - 是否为调试模式,默认为true
133
+ * @returns Core实例
134
+ */
135
+ static create(debug?: boolean): Core;
136
+ /**
137
+ * 注册全局管理器
138
+ *
139
+ * 将管理器添加到全局管理器列表中,并启用它。
140
+ *
141
+ * @param manager - 要注册的全局管理器
142
+ */
143
+ static registerGlobalManager(manager: GlobalManager): void;
144
+ /**
145
+ * 注销全局管理器
146
+ *
147
+ * 从全局管理器列表中移除管理器,并禁用它。
148
+ *
149
+ * @param manager - 要注销的全局管理器
150
+ */
151
+ static unregisterGlobalManager(manager: GlobalManager): void;
152
+ /**
153
+ * 获取指定类型的全局管理器
154
+ *
155
+ * @param type - 管理器类型构造函数
156
+ * @returns 管理器实例,如果未找到则返回null
157
+ */
158
+ static getGlobalManager<T extends GlobalManager>(type: new (...args: any[]) => T): T | null;
159
+ /**
160
+ * 调度定时器
161
+ *
162
+ * 创建一个定时器,在指定时间后执行回调函数。
163
+ *
164
+ * @param timeInSeconds - 延迟时间(秒)
165
+ * @param repeats - 是否重复执行,默认为false
166
+ * @param context - 回调函数的上下文,默认为null
167
+ * @param onTime - 定时器触发时的回调函数
168
+ * @returns 创建的定时器实例
169
+ */
170
+ static schedule(timeInSeconds: number, repeats: boolean | undefined, context: any | undefined, onTime: (timer: ITimer) => void): import(".").Timer;
171
+ /**
172
+ * 获取ECS流式API
173
+ *
174
+ * @returns ECS API实例,如果未初始化则返回null
175
+ */
176
+ static get ecsAPI(): ECSFluentAPI | null;
177
+ /**
178
+ * 场景切换回调
179
+ *
180
+ * 在场景切换时调用,用于重置时间系统等。
181
+ */
182
+ onSceneChanged(): void;
183
+ /**
184
+ * 初始化核心系统
185
+ *
186
+ * 执行核心系统的初始化逻辑。
187
+ */
188
+ protected initialize(): void;
189
+ /**
190
+ * 游戏主循环更新
191
+ *
192
+ * 每帧调用,负责更新时间系统、全局管理器和当前场景。
193
+ *
194
+ * @param currentTime - 当前时间戳,默认为-1(使用系统时间)
195
+ */
196
+ protected update(currentTime?: number): void;
197
+ }
198
+ //# sourceMappingURL=Core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Core.d.ts","sourceRoot":"","sources":["../src/Core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAgB,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,IAAI;IACb;;;;OAIG;IACH,OAAc,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3C;;;;OAIG;IACH,OAAc,MAAM,UAAS;IAE7B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS,CAAO;IAE/B;;;;OAIG;IACH,OAAc,oBAAoB,EAAE,OAAO,CAAC;IAE5C;;;;OAIG;IACH,SAAgB,KAAK,EAAE,OAAO,CAAC;IAE/B;;;;OAIG;IACI,UAAU,EAAE,KAAK,GAAG,IAAI,CAAQ;IAEvC;;;;OAIG;IACI,eAAe,EAAE,aAAa,EAAE,CAAM;IAE7C;;;;OAIG;IACI,aAAa,EAAE,YAAY,CAAC;IAEnC;;;;OAIG;IACI,mBAAmB,EAAE,kBAAkB,CAAC;IAE/C;;;;OAIG;IACI,YAAY,EAAE,WAAW,CAAC;IAEjC;;;;OAIG;IACI,OAAO,CAAC,EAAE,YAAY,CAAC;IAE9B;;OAEG;IACI,MAAM,CAAC,EAAE,KAAK,CAAC;IAEtB;;;;;OAKG;IACH,OAAO;IAoBP;;;;OAIG;IACH,WAAkB,QAAQ,SAEzB;IAED;;;;OAIG;IACH,WAAkB,KAAK,IAAI,KAAK,GAAG,IAAI,CAItC;IAED;;;;;;;OAOG;IACH,WAAkB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAc1C;IAED;;;;;;;OAOG;WACW,MAAM,CAAC,KAAK,GAAE,OAAc,GAAG,IAAI;IAOjD;;;;;;OAMG;WACW,qBAAqB,CAAC,OAAO,EAAE,aAAa;IAK1D;;;;;;OAMG;WACW,uBAAuB,CAAC,OAAO,EAAE,aAAa;IAK5D;;;;;OAKG;WACW,gBAAgB,CAAC,CAAC,SAAS,aAAa,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI;IAQlG;;;;;;;;;;OAUG;WACW,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,YAAQ,EAAE,OAAO,EAAE,GAAG,YAAO,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;IAI5H;;;;OAIG;IACH,WAAkB,MAAM,IAAI,YAAY,GAAG,IAAI,CAE9C;IAED;;;;OAIG;IACI,cAAc;IAUrB;;;;OAIG;IACH,SAAS,CAAC,UAAU;IAIpB;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,CAAC,WAAW,GAAE,MAAW,GAAG,IAAI;CA8CnD"}