@cjhd/cj-ecs 1.0.0 → 1.0.1

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 (74) hide show
  1. package/assets/common/component/MoveComponent.d.ts +141 -0
  2. package/assets/common/component/NodeComponent.d.ts +98 -0
  3. package/assets/common/system/MoveSystem.d.ts +17 -0
  4. package/assets/ecs/EcsComponent.d.ts +89 -0
  5. package/assets/ecs/{EcsDirty.ts → EcsDirty.d.ts} +340 -459
  6. package/assets/ecs/EcsEntity.d.ts +148 -0
  7. package/assets/ecs/EcsSingleton.d.ts +3 -0
  8. package/assets/ecs/EcsSystem.d.ts +96 -0
  9. package/assets/ecs.d.ts +126 -0
  10. package/assets/lib/EcsCache.d.ts +24 -0
  11. package/assets/lib/EcsFilter.d.ts +57 -0
  12. package/assets/lib/EcsManager.d.ts +251 -0
  13. package/assets/lib/{EcsObject.ts → EcsObject.d.ts} +360 -422
  14. package/assets/lib/EcsTimer.d.ts +119 -0
  15. package/assets/lib/EcsTween.d.ts +168 -0
  16. package/assets/lib/EcsUtils.d.ts +82 -0
  17. package/dist/cocos/assets/common/component/MoveComponent.js +4 -0
  18. package/dist/cocos/assets/common/component/NodeComponent.js +4 -0
  19. package/dist/cocos/assets/common/system/MoveSystem.js +2 -0
  20. package/dist/cocos/assets/ecs/EcsComponent.js +4 -0
  21. package/dist/cocos/assets/ecs/EcsDirty.js +4 -0
  22. package/dist/cocos/assets/ecs/EcsEntity.js +4 -0
  23. package/dist/cocos/assets/ecs/EcsSingleton.js +4 -0
  24. package/dist/cocos/assets/ecs/EcsSystem.js +2 -0
  25. package/dist/cocos/assets/ecs.js +2 -0
  26. package/dist/cocos/assets/lib/EcsCache.js +2 -0
  27. package/dist/cocos/assets/lib/EcsFilter.js +2 -0
  28. package/dist/cocos/assets/lib/EcsManager.js +4 -0
  29. package/dist/cocos/assets/lib/EcsObject.js +4 -0
  30. package/dist/cocos/assets/lib/EcsTimer.js +4 -0
  31. package/dist/cocos/assets/lib/EcsTween.js +4 -0
  32. package/dist/cocos/assets/lib/EcsUtils.js +2 -0
  33. package/dist/cocos/index.js +4 -0
  34. package/{index.ts → index.d.ts} +14 -33
  35. package/package.json +27 -7
  36. package/assets/common/component/MoveComponent.ts +0 -292
  37. package/assets/common/component/MoveComponent.ts.meta +0 -9
  38. package/assets/common/component/NodeComponent.ts +0 -315
  39. package/assets/common/component/NodeComponent.ts.meta +0 -9
  40. package/assets/common/component.meta +0 -12
  41. package/assets/common/system/MoveSystem.ts +0 -108
  42. package/assets/common/system/MoveSystem.ts.meta +0 -9
  43. package/assets/common/system.meta +0 -12
  44. package/assets/common.meta +0 -12
  45. package/assets/ecs/EcsComponent.ts +0 -244
  46. package/assets/ecs/EcsComponent.ts.meta +0 -9
  47. package/assets/ecs/EcsDirty.ts.meta +0 -9
  48. package/assets/ecs/EcsEntity.ts +0 -430
  49. package/assets/ecs/EcsEntity.ts.meta +0 -9
  50. package/assets/ecs/EcsSingleton.ts +0 -6
  51. package/assets/ecs/EcsSingleton.ts.meta +0 -9
  52. package/assets/ecs/EcsSystem.ts +0 -191
  53. package/assets/ecs/EcsSystem.ts.meta +0 -9
  54. package/assets/ecs.meta +0 -12
  55. package/assets/ecs.ts +0 -339
  56. package/assets/ecs.ts.meta +0 -9
  57. package/assets/lib/EcsCache.ts +0 -43
  58. package/assets/lib/EcsCache.ts.meta +0 -9
  59. package/assets/lib/EcsFilter.ts +0 -210
  60. package/assets/lib/EcsFilter.ts.meta +0 -9
  61. package/assets/lib/EcsManager.ts +0 -502
  62. package/assets/lib/EcsManager.ts.meta +0 -9
  63. package/assets/lib/EcsObject.ts.meta +0 -9
  64. package/assets/lib/EcsTimer.ts +0 -239
  65. package/assets/lib/EcsTimer.ts.meta +0 -9
  66. package/assets/lib/EcsTween.ts +0 -486
  67. package/assets/lib/EcsTween.ts.meta +0 -9
  68. package/assets/lib/EcsUtils.ts +0 -352
  69. package/assets/lib/EcsUtils.ts.meta +0 -9
  70. package/assets/lib.meta +0 -12
  71. package/assets.meta +0 -9
  72. package/index.ts.meta +0 -9
  73. package/package.json.meta +0 -11
  74. /package/{.cj-ecs.md → README.md} +0 -0
@@ -1,422 +1,360 @@
1
- import { Node } from 'cc';
2
- import type { EcsDirtyMask, IEcsComponentDirtySink, IEcsObservedQuery } from '../ecs/EcsDirty';
3
- import { UuidMaker } from './EcsUtils';
4
-
5
- /**
6
- * 过滤器
7
- */
8
- export interface IFilter {
9
- /**
10
- * 有这些组件中的任何一个
11
- */
12
- any(...args: ITypeofComponent[]): this
13
- /**
14
- * 必须包含所有这些组件
15
- * - 让数量最少的组件作为第一个参数,会获得更好的性能
16
- */
17
- all(...args: ITypeofComponent[]): this
18
- /**
19
- * 仅仅只有这些组件
20
- * - 让数量最少的组件作为第一个参数,会获得更好的性能
21
- */
22
- only(...args: ITypeofComponent[]): this
23
- /**
24
- * 不能包含其中的任何一个组件
25
- */
26
- exclude(...args: ITypeofComponent[]): this
27
- }
28
-
29
- /**uuid生成器 */
30
- export const entityUuidMaker = new UuidMaker();
31
- export const componentUuidMaker = new UuidMaker();
32
- export const systemUuidMaker = new UuidMaker();
33
- export const singletonUuidMaker = new UuidMaker();
34
-
35
- export abstract class EcsBase {
36
- /**类名 */
37
- static ecsName = 'EcsBase';
38
- /**类名 */
39
- public get ecsName() {
40
- return (this.constructor as typeof EcsBase).ecsName;
41
- }
42
- }
43
-
44
- /**实体基类 */
45
- export abstract class EcsBaseEntity extends EcsBase {
46
- static updateUUID(ins: EcsBaseEntity) {
47
- ins._uuid = entityUuidMaker.create();
48
- }
49
-
50
- static init(entity: EcsBaseEntity, ecs: IECS, node: Node | null = null) {
51
- return entity.innerInit(ecs, node);
52
- }
53
-
54
- static addComponent(entity: EcsBaseEntity, com: IComponent) {
55
- return entity.innerAddComponent(com);
56
- }
57
-
58
- static removeComponent(entity: EcsBaseEntity, com: IComponent) {
59
- return entity.innerRemoveComponent(com);
60
- }
61
-
62
- /**唯一ID */
63
- private _uuid = entityUuidMaker.create();
64
- public get uuid() {
65
- return this._uuid;
66
- }
67
-
68
- /**允许回收复用(默认false) */
69
- static allowRecycling = false;
70
- /**允许回收复用(默认false) */
71
- public get allowRecycling() {
72
- return (this.constructor as typeof EcsBaseEntity).allowRecycling;
73
- }
74
-
75
- /**添加*/
76
- protected abstract onAdd(): any;
77
- /**生效*/
78
- protected abstract onEnable(): any;
79
- /**失效*/
80
- protected abstract onDisable(): any;
81
- /**移除*/
82
- protected abstract onRemove(): any;
83
-
84
- /**
85
- * 内部初始化函数
86
- */
87
- protected abstract innerInit(ecs: IECS, node?: Node | null): void;
88
-
89
- /**
90
- * 添加组件(内部调用)
91
- */
92
- protected abstract innerAddComponent(com: IComponent): void;
93
-
94
- /**
95
- * 移除组件(内部调用)
96
- */
97
- protected abstract innerRemoveComponent(com: IComponent): void;
98
- }
99
-
100
- /**组件基类 */
101
- export abstract class EcsBaseComponent extends EcsBase {
102
- /**内部函数 */
103
- static updateUUID(ins: EcsBaseComponent) {
104
- ins._uuid = componentUuidMaker.create();
105
- }
106
-
107
- /**唯一ID */
108
- private _uuid = componentUuidMaker.create();
109
- public get uuid() {
110
- return this._uuid;
111
- }
112
-
113
- /**允许回收复用(默认false) */
114
- static allowRecycling = false;
115
- /**允许回收复用(默认false) */
116
- public get allowRecycling() {
117
- return (this.constructor as typeof EcsBaseComponent).allowRecycling;
118
- }
119
-
120
- /**允许在同一个实体中重复添加(默认false) */
121
- static allowMultiple = false;
122
- /**允许在同一个实体中重复添加(默认false) */
123
- public get allowMultiple() {
124
- return (this.constructor as typeof EcsBaseComponent).allowMultiple;
125
- }
126
-
127
- /**添加*/
128
- protected abstract onAdd(): any;
129
- /**生效*/
130
- protected abstract onEnable(): any;
131
- /**失效*/
132
- protected abstract onDisable(): any;
133
- /**移除*/
134
- protected abstract onRemove(): any;
135
- }
136
-
137
- /**系统基类 */
138
- export abstract class EcsBaseSystem extends EcsBase {
139
- /**唯一ID */
140
- private _uuid = systemUuidMaker.create();
141
- public get uuid() {
142
- return this._uuid;
143
- }
144
-
145
- static onAdd(system: EcsBaseSystem) {
146
- system.onAdd();
147
- }
148
-
149
- static onRemove(system: EcsBaseSystem) {
150
- system.onRemove();
151
- }
152
-
153
- static execute(system: EcsBaseSystem, dt: number, args: any[]) {
154
- system.execute(dt, ...args);
155
- }
156
-
157
- static beforeExecute(system: EcsBaseSystem, dt: number, args: any[]) {
158
- system.beforeExecute(dt, ...args);
159
- }
160
-
161
- static afterExecute(system: EcsBaseSystem, dt: number, args: any[]) {
162
- system.afterExecute(dt, ...args);
163
- }
164
-
165
- static update(system: EcsBaseSystem, dt: number, args: any[]) {
166
- system.update(dt, ...args);
167
- }
168
-
169
- static beforeUpdate(system: EcsBaseSystem, dt: number, args: any[]) {
170
- system.beforeUpdate(dt, ...args);
171
- }
172
-
173
- static afterUpdate(system: EcsBaseSystem, dt: number, args: any[]) {
174
- system.afterUpdate(dt, ...args);
175
- }
176
-
177
- /**添加*/
178
- protected abstract onAdd(): any;
179
- /**移除*/
180
- protected abstract onRemove(): any;
181
-
182
- protected abstract execute(dt?: number, ...args: any[]): any;
183
- protected abstract beforeExecute(dt?: number, ...args: any[]): any;
184
- protected abstract afterExecute(dt?: number, ...args: any[]): any;
185
-
186
- // 由ecs.update驱动
187
- protected abstract update(dt?: number, ...args: any[]): any;
188
- protected abstract beforeUpdate(dt?: number, ...args: any[]): any;
189
- protected abstract afterUpdate(dt?: number, ...args: any[]): any;
190
- }
191
-
192
- /**单例基类 */
193
- export abstract class EcsBaseSingleton extends EcsBase {
194
- /**唯一ID */
195
- private _uuid = singletonUuidMaker.create();
196
- public get uuid() {
197
- return this._uuid;
198
- }
199
- }
200
-
201
- export type IEntityUUID = number;
202
- export type IComponentName = string;
203
- export type IComponentUUID = number;
204
- export type IFlag = number[];
205
-
206
- export type ITypeofEntity = { new(): IEntity, ecsName: string, allowRecycling: boolean };
207
- export type ITypeofComponent = { new(): IComponent, ecsName: string, allowRecycling: boolean, allowMultiple: boolean };
208
- export type ITypeofSystem = { new(ecs: IECS): ISystem, ecsName: string };
209
- export type ITypeofSingleton = { new(): ISingleton, ecsName: string };
210
-
211
- export interface IEntity extends EcsBaseEntity {
212
- /**
213
- * 是否有效
214
- */
215
- readonly isValid: boolean
216
- /**
217
- * 绑定的节点
218
- */
219
- node: Node | null
220
- /**
221
- * 标记是否生效(为false后将不会被查询到)
222
- */
223
- enabled: boolean
224
- /**
225
- * 销毁
226
- * 会在触发onDisable和移除所有组件之后才会isValid设为false
227
- */
228
- destroy(): boolean
229
- /**
230
- * 检查是否仅包含全部
231
- */
232
- checkFlagAll(flag: IFlag): boolean
233
- /**
234
- * 检查是否包含任一
235
- */
236
- checkFlagAny(flag: IFlag): boolean
237
- /**
238
- * 检查是否仅包含全部
239
- */
240
- checkFlagOnly(flag: IFlag): boolean
241
- /**
242
- * 是否存在指定名字的启用组件
243
- */
244
- hasEnabledComponentName(componentName: IComponentName): boolean
245
- /**
246
- * 添加相应类型的组件
247
- * @see 同add
248
- * @param param 类型
249
- */
250
- addComponent<T extends ITypeofComponent>(Com: T): InstanceType<T> | null
251
- /**
252
- * 添加相应类型的组件
253
- * @param param 类型
254
- * @returns
255
- */
256
- add<T extends ITypeofComponent>(Com: T): InstanceType<T> | null
257
- /**
258
- * 移除相应类型的第一个组件
259
- * @see 同remove
260
- * @param param 类型
261
- */
262
- removeComponent(Com: ITypeofComponent | IComponent): boolean
263
- /**
264
- * 移除相应类型的第一个组件
265
- * @param param 类型
266
- */
267
- remove(Com: ITypeofComponent | IComponent): boolean
268
- /**
269
- * 移除相应组件的所有组件
270
- * @see 同removeAll
271
- * @param Com 类型
272
- */
273
- removeComponents(Com: ITypeofComponent): boolean;
274
- /**
275
- * 移除相应组件的所有组件
276
- * @param Com 类型
277
- * @returns
278
- */
279
- removeAll(Com: ITypeofComponent): boolean;
280
- /**
281
- * 有没有相应类型的组件
282
- * @see 同has
283
- */
284
- hasComponent(Com: ITypeofComponent): boolean
285
- /**
286
- * 有没有相应类型的组件
287
- */
288
- has(Com: ITypeofComponent): boolean
289
- /**
290
- * 获取相应类型的组件
291
- * @see 同get
292
- */
293
- getComponent<T extends ITypeofComponent>(Com: T): InstanceType<T> | null
294
- /**
295
- * 获取相应类型的组件
296
- */
297
- get<T extends ITypeofComponent>(Com: T): InstanceType<T> | null
298
- /**
299
- * 获取相应类型的组件
300
- * @see 同getAll
301
- */
302
- getComponents<T extends ITypeofComponent>(Com: T): InstanceType<T>[]
303
- /**
304
- * 获取相应类型的组件
305
- */
306
- getAll<T extends ITypeofComponent>(Com: T): InstanceType<T>[]
307
- }
308
-
309
- export interface IComponent<E extends IEntity = IEntity> extends EcsBaseComponent {
310
- /**是否有效*/
311
- readonly isValid: boolean
312
-
313
- /**是否有效(如果当前正处于销毁流程中,也会返回false)*/
314
- readonly isStrictValid: boolean
315
-
316
- /**
317
- * 标记是否生效(为false代表不会被查询到)
318
- */
319
- enabled: boolean
320
- /**
321
- * 表示该组件是否被启用并且所在的实体也处于启用状态(为false代表不会被查询到)
322
- */
323
- readonly enabledInHierarchy: boolean
324
- /**当前组件所在的实体 */
325
- readonly entity: E | null;
326
- readonly dirty: boolean;
327
- readonly dirtyMask: EcsDirtyMask;
328
- readonly dirtyVersion: number;
329
- hasDirty(mask: EcsDirtyMask): boolean;
330
- markDirty(mask?: EcsDirtyMask): void;
331
- clearDirty(mask?: EcsDirtyMask): void;
332
- clearDirtySilent(): void;
333
- /**销毁当前组件 */
334
- destroy(): boolean;
335
- }
336
-
337
- export type ISystem = EcsBaseSystem;
338
-
339
- export type ISingleton = EcsBaseSingleton;
340
-
341
- export interface IECS {
342
- /**
343
- * 查询实体
344
- */
345
- query<T extends IEntity>(filter: IFilter): T[];
346
- query<T extends IComponent>(filter: IFilter, Component: { new(): T }): T[];
347
- query<T>(filter: IFilter, Component?: ITypeofComponent): T[];
348
- /**
349
- * 查询实体
350
- */
351
- find<T extends IEntity>(filter: IFilter): T;
352
- find<T extends IComponent>(filter: IFilter, Component: { new(): T }): T;
353
- find<T>(filter: IFilter, Component?: ITypeofComponent): T;
354
- /**
355
- * 查询实体是否存在
356
- */
357
- exist(filter: IFilter): boolean;
358
- /**
359
- * 根据uuid查询实体
360
- */
361
- findByUuid(uuid: IEntityUUID): IEntity | null;
362
- /**
363
- * 根据uuid查询实体是否存在
364
- */
365
- existByUuid(uuid: IEntityUUID): boolean;
366
- /**
367
- * 添加系统
368
- */
369
- addSystem<T extends ITypeofSystem>(System: T): void
370
- /**
371
- * 移除系统
372
- */
373
- removeSystem<T extends ITypeofSystem>(System: T): void
374
- /**
375
- * 添加单例组件
376
- */
377
- addSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T>
378
- /**
379
- * 添加单例组件
380
- */
381
- addSingleton<T extends ISingleton>(param: T): T
382
- /**
383
- * 获取单例组件
384
- */
385
- getSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T> | null
386
- /**
387
- * 移除单例组件
388
- */
389
- removeSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T> | null
390
- /**
391
- * 创建一个实体
392
- */
393
- createEntity<T extends ITypeofEntity>(Entity: T, options?: Node | { node?: Node }): InstanceType<T>
394
- /**
395
- * 清理系统、实体、组件、单例组件(都不会触发生命周期)
396
- */
397
- clear(): any
398
- /**
399
- * 开始批量组件增删,延迟刷新系统 matcher
400
- */
401
- beginMutation(): void
402
- /**
403
- * 结束批量组件增删,并刷新受影响实体的系统 matcher
404
- */
405
- endMutation(): void
406
- setDirtySink(sink: IEcsComponentDirtySink | null): void
407
- getDirtySink(): IEcsComponentDirtySink | null
408
- setObservedQuery(query: IEcsObservedQuery | null): void
409
- getObservedQuery(): IEcsObservedQuery | null
410
- /**
411
- * 用于逻辑帧
412
- * 执行顺序:
413
- * [系统的beforeExecute] -> [系统的execute] ->[系统的afterExecute]
414
- */
415
- execute(dt: number, ...args: any[]): any
416
- /**
417
- * 用于渲染帧
418
- * 执行顺序:
419
- * [系统的beforeUpdate] -> [系统的update] -> [系统的afterUpdate]
420
- */
421
- update(dt: number, ...args: any[]): any
422
- }
1
+ import { Node } from 'cc';
2
+ import type { EcsDirtyMask, IEcsComponentDirtySink, IEcsObservedQuery } from '../ecs/EcsDirty';
3
+ import { UuidMaker } from './EcsUtils';
4
+ /**
5
+ * 过滤器
6
+ */
7
+ export interface IFilter {
8
+ /**
9
+ * 有这些组件中的任何一个
10
+ */
11
+ any(...args: ITypeofComponent[]): this;
12
+ /**
13
+ * 必须包含所有这些组件
14
+ * - 让数量最少的组件作为第一个参数,会获得更好的性能
15
+ */
16
+ all(...args: ITypeofComponent[]): this;
17
+ /**
18
+ * 仅仅只有这些组件
19
+ * - 让数量最少的组件作为第一个参数,会获得更好的性能
20
+ */
21
+ only(...args: ITypeofComponent[]): this;
22
+ /**
23
+ * 不能包含其中的任何一个组件
24
+ */
25
+ exclude(...args: ITypeofComponent[]): this;
26
+ }
27
+ /**uuid生成器 */
28
+ export declare const entityUuidMaker: UuidMaker;
29
+ export declare const componentUuidMaker: UuidMaker;
30
+ export declare const systemUuidMaker: UuidMaker;
31
+ export declare const singletonUuidMaker: UuidMaker;
32
+ export declare abstract class EcsBase {
33
+ /**类名 */
34
+ static ecsName: string;
35
+ /**类名 */
36
+ get ecsName(): string;
37
+ }
38
+ /**实体基类 */
39
+ export declare abstract class EcsBaseEntity extends EcsBase {
40
+ static updateUUID(ins: EcsBaseEntity): void;
41
+ static init(entity: EcsBaseEntity, ecs: IECS, node?: Node | null): void;
42
+ static addComponent(entity: EcsBaseEntity, com: IComponent): void;
43
+ static removeComponent(entity: EcsBaseEntity, com: IComponent): void;
44
+ /**唯一ID */
45
+ private _uuid;
46
+ get uuid(): number;
47
+ /**允许回收复用(默认false) */
48
+ static allowRecycling: boolean;
49
+ /**允许回收复用(默认false) */
50
+ get allowRecycling(): boolean;
51
+ /**添加*/
52
+ protected abstract onAdd(): any;
53
+ /**生效*/
54
+ protected abstract onEnable(): any;
55
+ /**失效*/
56
+ protected abstract onDisable(): any;
57
+ /**移除*/
58
+ protected abstract onRemove(): any;
59
+ /**
60
+ * 内部初始化函数
61
+ */
62
+ protected abstract innerInit(ecs: IECS, node?: Node | null): void;
63
+ /**
64
+ * 添加组件(内部调用)
65
+ */
66
+ protected abstract innerAddComponent(com: IComponent): void;
67
+ /**
68
+ * 移除组件(内部调用)
69
+ */
70
+ protected abstract innerRemoveComponent(com: IComponent): void;
71
+ }
72
+ /**组件基类 */
73
+ export declare abstract class EcsBaseComponent extends EcsBase {
74
+ /**内部函数 */
75
+ static updateUUID(ins: EcsBaseComponent): void;
76
+ /**唯一ID */
77
+ private _uuid;
78
+ get uuid(): number;
79
+ /**允许回收复用(默认false) */
80
+ static allowRecycling: boolean;
81
+ /**允许回收复用(默认false) */
82
+ get allowRecycling(): boolean;
83
+ /**允许在同一个实体中重复添加(默认false) */
84
+ static allowMultiple: boolean;
85
+ /**允许在同一个实体中重复添加(默认false) */
86
+ get allowMultiple(): boolean;
87
+ /**添加*/
88
+ protected abstract onAdd(): any;
89
+ /**生效*/
90
+ protected abstract onEnable(): any;
91
+ /**失效*/
92
+ protected abstract onDisable(): any;
93
+ /**移除*/
94
+ protected abstract onRemove(): any;
95
+ }
96
+ /**系统基类 */
97
+ export declare abstract class EcsBaseSystem extends EcsBase {
98
+ /**唯一ID */
99
+ private _uuid;
100
+ get uuid(): number;
101
+ static onAdd(system: EcsBaseSystem): void;
102
+ static onRemove(system: EcsBaseSystem): void;
103
+ static execute(system: EcsBaseSystem, dt: number, args: any[]): void;
104
+ static beforeExecute(system: EcsBaseSystem, dt: number, args: any[]): void;
105
+ static afterExecute(system: EcsBaseSystem, dt: number, args: any[]): void;
106
+ static update(system: EcsBaseSystem, dt: number, args: any[]): void;
107
+ static beforeUpdate(system: EcsBaseSystem, dt: number, args: any[]): void;
108
+ static afterUpdate(system: EcsBaseSystem, dt: number, args: any[]): void;
109
+ /**添加*/
110
+ protected abstract onAdd(): any;
111
+ /**移除*/
112
+ protected abstract onRemove(): any;
113
+ protected abstract execute(dt?: number, ...args: any[]): any;
114
+ protected abstract beforeExecute(dt?: number, ...args: any[]): any;
115
+ protected abstract afterExecute(dt?: number, ...args: any[]): any;
116
+ protected abstract update(dt?: number, ...args: any[]): any;
117
+ protected abstract beforeUpdate(dt?: number, ...args: any[]): any;
118
+ protected abstract afterUpdate(dt?: number, ...args: any[]): any;
119
+ }
120
+ /**单例基类 */
121
+ export declare abstract class EcsBaseSingleton extends EcsBase {
122
+ /**唯一ID */
123
+ private _uuid;
124
+ get uuid(): number;
125
+ }
126
+ export type IEntityUUID = number;
127
+ export type IComponentName = string;
128
+ export type IComponentUUID = number;
129
+ export type IFlag = number[];
130
+ export type ITypeofEntity = {
131
+ new (): IEntity;
132
+ ecsName: string;
133
+ allowRecycling: boolean;
134
+ };
135
+ export type ITypeofComponent = {
136
+ new (): IComponent;
137
+ ecsName: string;
138
+ allowRecycling: boolean;
139
+ allowMultiple: boolean;
140
+ };
141
+ export type ITypeofSystem = {
142
+ new (ecs: IECS): ISystem;
143
+ ecsName: string;
144
+ };
145
+ export type ITypeofSingleton = {
146
+ new (): ISingleton;
147
+ ecsName: string;
148
+ };
149
+ export interface IEntity extends EcsBaseEntity {
150
+ /**
151
+ * 是否有效
152
+ */
153
+ readonly isValid: boolean;
154
+ /**
155
+ * 绑定的节点
156
+ */
157
+ node: Node | null;
158
+ /**
159
+ * 标记是否生效(为false后将不会被查询到)
160
+ */
161
+ enabled: boolean;
162
+ /**
163
+ * 销毁
164
+ * 会在触发onDisable和移除所有组件之后才会isValid设为false
165
+ */
166
+ destroy(): boolean;
167
+ /**
168
+ * 检查是否仅包含全部
169
+ */
170
+ checkFlagAll(flag: IFlag): boolean;
171
+ /**
172
+ * 检查是否包含任一
173
+ */
174
+ checkFlagAny(flag: IFlag): boolean;
175
+ /**
176
+ * 检查是否仅包含全部
177
+ */
178
+ checkFlagOnly(flag: IFlag): boolean;
179
+ /**
180
+ * 是否存在指定名字的启用组件
181
+ */
182
+ hasEnabledComponentName(componentName: IComponentName): boolean;
183
+ /**
184
+ * 添加相应类型的组件
185
+ * @see 同add
186
+ * @param param 类型
187
+ */
188
+ addComponent<T extends ITypeofComponent>(Com: T): InstanceType<T> | null;
189
+ /**
190
+ * 添加相应类型的组件
191
+ * @param param 类型
192
+ * @returns
193
+ */
194
+ add<T extends ITypeofComponent>(Com: T): InstanceType<T> | null;
195
+ /**
196
+ * 移除相应类型的第一个组件
197
+ * @see 同remove
198
+ * @param param 类型
199
+ */
200
+ removeComponent(Com: ITypeofComponent | IComponent): boolean;
201
+ /**
202
+ * 移除相应类型的第一个组件
203
+ * @param param 类型
204
+ */
205
+ remove(Com: ITypeofComponent | IComponent): boolean;
206
+ /**
207
+ * 移除相应组件的所有组件
208
+ * @see 同removeAll
209
+ * @param Com 类型
210
+ */
211
+ removeComponents(Com: ITypeofComponent): boolean;
212
+ /**
213
+ * 移除相应组件的所有组件
214
+ * @param Com 类型
215
+ * @returns
216
+ */
217
+ removeAll(Com: ITypeofComponent): boolean;
218
+ /**
219
+ * 有没有相应类型的组件
220
+ * @see 同has
221
+ */
222
+ hasComponent(Com: ITypeofComponent): boolean;
223
+ /**
224
+ * 有没有相应类型的组件
225
+ */
226
+ has(Com: ITypeofComponent): boolean;
227
+ /**
228
+ * 获取相应类型的组件
229
+ * @see 同get
230
+ */
231
+ getComponent<T extends ITypeofComponent>(Com: T): InstanceType<T> | null;
232
+ /**
233
+ * 获取相应类型的组件
234
+ */
235
+ get<T extends ITypeofComponent>(Com: T): InstanceType<T> | null;
236
+ /**
237
+ * 获取相应类型的组件
238
+ * @see 同getAll
239
+ */
240
+ getComponents<T extends ITypeofComponent>(Com: T): InstanceType<T>[];
241
+ /**
242
+ * 获取相应类型的组件
243
+ */
244
+ getAll<T extends ITypeofComponent>(Com: T): InstanceType<T>[];
245
+ }
246
+ export interface IComponent<E extends IEntity = IEntity> extends EcsBaseComponent {
247
+ /**是否有效*/
248
+ readonly isValid: boolean;
249
+ /**是否有效(如果当前正处于销毁流程中,也会返回false)*/
250
+ readonly isStrictValid: boolean;
251
+ /**
252
+ * 标记是否生效(为false代表不会被查询到)
253
+ */
254
+ enabled: boolean;
255
+ /**
256
+ * 表示该组件是否被启用并且所在的实体也处于启用状态(为false代表不会被查询到)
257
+ */
258
+ readonly enabledInHierarchy: boolean;
259
+ /**当前组件所在的实体 */
260
+ readonly entity: E | null;
261
+ readonly dirty: boolean;
262
+ readonly dirtyMask: EcsDirtyMask;
263
+ readonly dirtyVersion: number;
264
+ hasDirty(mask: EcsDirtyMask): boolean;
265
+ markDirty(mask?: EcsDirtyMask): void;
266
+ clearDirty(mask?: EcsDirtyMask): void;
267
+ clearDirtySilent(): void;
268
+ /**销毁当前组件 */
269
+ destroy(): boolean;
270
+ }
271
+ export type ISystem = EcsBaseSystem;
272
+ export type ISingleton = EcsBaseSingleton;
273
+ export interface IECS {
274
+ /**
275
+ * 查询实体
276
+ */
277
+ query<T extends IEntity>(filter: IFilter): T[];
278
+ query<T extends IComponent>(filter: IFilter, Component: {
279
+ new (): T;
280
+ }): T[];
281
+ query<T>(filter: IFilter, Component?: ITypeofComponent): T[];
282
+ /**
283
+ * 查询实体
284
+ */
285
+ find<T extends IEntity>(filter: IFilter): T;
286
+ find<T extends IComponent>(filter: IFilter, Component: {
287
+ new (): T;
288
+ }): T;
289
+ find<T>(filter: IFilter, Component?: ITypeofComponent): T;
290
+ /**
291
+ * 查询实体是否存在
292
+ */
293
+ exist(filter: IFilter): boolean;
294
+ /**
295
+ * 根据uuid查询实体
296
+ */
297
+ findByUuid(uuid: IEntityUUID): IEntity | null;
298
+ /**
299
+ * 根据uuid查询实体是否存在
300
+ */
301
+ existByUuid(uuid: IEntityUUID): boolean;
302
+ /**
303
+ * 添加系统
304
+ */
305
+ addSystem<T extends ITypeofSystem>(System: T): void;
306
+ /**
307
+ * 移除系统
308
+ */
309
+ removeSystem<T extends ITypeofSystem>(System: T): void;
310
+ /**
311
+ * 添加单例组件
312
+ */
313
+ addSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T>;
314
+ /**
315
+ * 添加单例组件
316
+ */
317
+ addSingleton<T extends ISingleton>(param: T): T;
318
+ /**
319
+ * 获取单例组件
320
+ */
321
+ getSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T> | null;
322
+ /**
323
+ * 移除单例组件
324
+ */
325
+ removeSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T> | null;
326
+ /**
327
+ * 创建一个实体
328
+ */
329
+ createEntity<T extends ITypeofEntity>(Entity: T, options?: Node | {
330
+ node?: Node;
331
+ }): InstanceType<T>;
332
+ /**
333
+ * 清理系统、实体、组件、单例组件(都不会触发生命周期)
334
+ */
335
+ clear(): any;
336
+ /**
337
+ * 开始批量组件增删,延迟刷新系统 matcher
338
+ */
339
+ beginMutation(): void;
340
+ /**
341
+ * 结束批量组件增删,并刷新受影响实体的系统 matcher
342
+ */
343
+ endMutation(): void;
344
+ setDirtySink(sink: IEcsComponentDirtySink | null): void;
345
+ getDirtySink(): IEcsComponentDirtySink | null;
346
+ setObservedQuery(query: IEcsObservedQuery | null): void;
347
+ getObservedQuery(): IEcsObservedQuery | null;
348
+ /**
349
+ * 用于逻辑帧
350
+ * 执行顺序:
351
+ * [系统的beforeExecute] -> [系统的execute] ->[系统的afterExecute]
352
+ */
353
+ execute(dt: number, ...args: any[]): any;
354
+ /**
355
+ * 用于渲染帧
356
+ * 执行顺序:
357
+ * [系统的beforeUpdate] -> [系统的update] -> [系统的afterUpdate]
358
+ */
359
+ update(dt: number, ...args: any[]): any;
360
+ }