@esengine/ecs-framework 2.1.7 → 2.1.8
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.
- package/index.d.ts +3753 -15
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,22 +1,3760 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @esengine/ecs-framework
|
|
3
3
|
* 高性能ECS框架 - 适用于Cocos Creator和Laya引擎
|
|
4
|
-
* 版本: 2.1.
|
|
5
|
-
* 构建时间: 2025-06-
|
|
4
|
+
* 版本: 2.1.8
|
|
5
|
+
* 构建时间: 2025-06-09T06:23:45.962Z
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
export declare class Core {
|
|
9
|
+
/**
|
|
10
|
+
* 核心事件发射器
|
|
11
|
+
*
|
|
12
|
+
* 用于发布和订阅核心级别的事件,如帧更新、场景切换等。
|
|
13
|
+
*/
|
|
14
|
+
static emitter: Emitter<CoreEvents>;
|
|
15
|
+
/**
|
|
16
|
+
* 游戏暂停状态
|
|
17
|
+
*
|
|
18
|
+
* 当设置为true时,游戏循环将暂停执行。
|
|
19
|
+
*/
|
|
20
|
+
static paused: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 全局核心实例
|
|
23
|
+
*/
|
|
24
|
+
private static _instance;
|
|
25
|
+
/**
|
|
26
|
+
* 实体系统启用状态
|
|
27
|
+
*
|
|
28
|
+
* 控制是否启用ECS实体系统功能。
|
|
29
|
+
*/
|
|
30
|
+
static entitySystemsEnabled: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 调试模式标志
|
|
33
|
+
*
|
|
34
|
+
* 在调试模式下会启用额外的性能监控和错误检查。
|
|
35
|
+
*/
|
|
36
|
+
readonly debug: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* 待切换的场景
|
|
39
|
+
*
|
|
40
|
+
* 存储下一帧要切换到的场景实例。
|
|
41
|
+
*/
|
|
42
|
+
_nextScene: Scene | null;
|
|
43
|
+
/**
|
|
44
|
+
* 全局管理器集合
|
|
45
|
+
*
|
|
46
|
+
* 存储所有注册的全局管理器实例。
|
|
47
|
+
*/
|
|
48
|
+
_globalManagers: GlobalManager[];
|
|
49
|
+
/**
|
|
50
|
+
* 定时器管理器
|
|
51
|
+
*
|
|
52
|
+
* 负责管理所有的游戏定时器。
|
|
53
|
+
*/
|
|
54
|
+
_timerManager: TimerManager;
|
|
55
|
+
/**
|
|
56
|
+
* 性能监控器
|
|
57
|
+
*
|
|
58
|
+
* 监控游戏性能并提供优化建议。
|
|
59
|
+
*/
|
|
60
|
+
_performanceMonitor: PerformanceMonitor;
|
|
61
|
+
/**
|
|
62
|
+
* 对象池管理器
|
|
63
|
+
*
|
|
64
|
+
* 管理所有对象池的生命周期。
|
|
65
|
+
*/
|
|
66
|
+
_poolManager: PoolManager;
|
|
67
|
+
/**
|
|
68
|
+
* ECS流式API
|
|
69
|
+
*
|
|
70
|
+
* 提供便捷的ECS操作接口。
|
|
71
|
+
*/
|
|
72
|
+
_ecsAPI?: ECSFluentAPI;
|
|
73
|
+
/**
|
|
74
|
+
* 当前活动场景
|
|
75
|
+
*/
|
|
76
|
+
_scene?: Scene;
|
|
77
|
+
/**
|
|
78
|
+
* 创建核心实例
|
|
79
|
+
*
|
|
80
|
+
* @param debug - 是否启用调试模式,默认为true
|
|
81
|
+
* @param enableEntitySystems - 是否启用实体系统,默认为true
|
|
82
|
+
*/
|
|
83
|
+
private constructor();
|
|
84
|
+
/**
|
|
85
|
+
* 获取核心实例
|
|
86
|
+
*
|
|
87
|
+
* @returns 全局核心实例
|
|
88
|
+
*/
|
|
89
|
+
static get Instance(): Core;
|
|
90
|
+
/**
|
|
91
|
+
* 获取当前活动的场景
|
|
92
|
+
*
|
|
93
|
+
* @returns 当前场景实例,如果没有则返回null
|
|
94
|
+
*/
|
|
95
|
+
static get scene(): Scene | null;
|
|
96
|
+
/**
|
|
97
|
+
* 设置当前活动的场景
|
|
98
|
+
*
|
|
99
|
+
* 如果当前没有场景,会立即切换;否则会在下一帧切换。
|
|
100
|
+
*
|
|
101
|
+
* @param value - 要设置的场景实例
|
|
102
|
+
* @throws {Error}
|
|
103
|
+
|
|
104
|
+
export interface IUpdatable {
|
|
105
|
+
enabled: boolean;
|
|
106
|
+
updateOrder: number;
|
|
107
|
+
update(): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export declare class IUpdatableComparer {
|
|
111
|
+
compare(a: IUpdatable, b: IUpdatable): number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export declare class SceneComponent {
|
|
115
|
+
/** 组件所属的场景 */
|
|
116
|
+
scene: Scene;
|
|
117
|
+
/** 更新顺序 */
|
|
118
|
+
updateOrder: number;
|
|
119
|
+
/** 是否启用 */
|
|
120
|
+
private _enabled;
|
|
121
|
+
/** 获取是否启用 */
|
|
122
|
+
get enabled(): boolean;
|
|
123
|
+
/** 设置是否启用 */
|
|
124
|
+
set enabled(value: boolean);
|
|
125
|
+
/**
|
|
126
|
+
* 当组件启用时调用
|
|
127
|
+
*/
|
|
128
|
+
onEnabled(): void;
|
|
129
|
+
/**
|
|
130
|
+
* 当组件禁用时调用
|
|
131
|
+
*/
|
|
132
|
+
onDisabled(): void;
|
|
133
|
+
/**
|
|
134
|
+
* 当组件从场景中移除时调用
|
|
135
|
+
*/
|
|
136
|
+
onRemovedFromScene(): void;
|
|
137
|
+
/**
|
|
138
|
+
* 每帧更新
|
|
139
|
+
*/
|
|
140
|
+
update(): void;
|
|
141
|
+
/**
|
|
142
|
+
* 比较组件的更新顺序
|
|
143
|
+
* @param other 其他组件
|
|
144
|
+
* @returns 比较结果
|
|
145
|
+
*/
|
|
146
|
+
compare(other: SceneComponent): number;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type ArchetypeId = string;
|
|
150
|
+
/**
|
|
151
|
+
* 原型数据结构
|
|
152
|
+
*/
|
|
153
|
+
export interface Archetype {
|
|
154
|
+
/** 原型唯一标识符 */
|
|
155
|
+
id: ArchetypeId;
|
|
156
|
+
/** 包含的组件类型 */
|
|
157
|
+
componentTypes: ComponentType[];
|
|
158
|
+
/** 属于该原型的实体列表 */
|
|
159
|
+
entities: Entity[];
|
|
160
|
+
/** 原型创建时间 */
|
|
161
|
+
createdAt: number;
|
|
162
|
+
/** 最后更新时间 */
|
|
163
|
+
updatedAt: number;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface ArchetypeQueryResult {
|
|
167
|
+
/** 匹配的原型列表 */
|
|
168
|
+
archetypes: Archetype[];
|
|
169
|
+
/** 所有匹配实体的总数 */
|
|
170
|
+
totalEntities: number;
|
|
171
|
+
/** 查询执行时间(毫秒) */
|
|
172
|
+
executionTime: number;
|
|
173
|
+
/** 是否使用了缓存 */
|
|
174
|
+
fromCache: boolean;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export declare class ArchetypeSystem {
|
|
178
|
+
/** 所有原型的映射表 */
|
|
179
|
+
private _archetypes;
|
|
180
|
+
/** 实体到原型的映射 */
|
|
181
|
+
private _entityToArchetype;
|
|
182
|
+
/** 组件类型到原型的映射 */
|
|
183
|
+
private _componentToArchetypes;
|
|
184
|
+
/** 查询缓存 */
|
|
185
|
+
private _queryCache;
|
|
186
|
+
private _cacheTimeout;
|
|
187
|
+
private _maxCacheSize;
|
|
188
|
+
/**
|
|
189
|
+
* 添加实体到原型系统
|
|
190
|
+
*/
|
|
191
|
+
addEntity(entity: Entity): void;
|
|
192
|
+
/**
|
|
193
|
+
* 从原型系统中移除实体
|
|
194
|
+
*/
|
|
195
|
+
removeEntity(entity: Entity): void;
|
|
196
|
+
/**
|
|
197
|
+
* 查询包含指定组件组合的原型
|
|
198
|
+
*/
|
|
199
|
+
queryArchetypes(componentTypes: ComponentType[], operation?: 'AND' | 'OR'): ArchetypeQueryResult;
|
|
200
|
+
/**
|
|
201
|
+
* 获取实体所属的原型
|
|
202
|
+
*/
|
|
203
|
+
getEntityArchetype(entity: Entity): Archetype | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* 获取所有原型
|
|
206
|
+
*/
|
|
207
|
+
getAllArchetypes(): Archetype[];
|
|
208
|
+
/**
|
|
209
|
+
* 清空所有数据
|
|
210
|
+
*/
|
|
211
|
+
clear(): void;
|
|
212
|
+
/**
|
|
213
|
+
* 获取实体的组件类型列表
|
|
214
|
+
*/
|
|
215
|
+
private getEntityComponentTypes;
|
|
216
|
+
/**
|
|
217
|
+
* 生成原型ID
|
|
218
|
+
*/
|
|
219
|
+
private generateArchetypeId;
|
|
220
|
+
/**
|
|
221
|
+
* 创建新原型
|
|
222
|
+
*/
|
|
223
|
+
private createArchetype;
|
|
224
|
+
/**
|
|
225
|
+
* 检查原型是否包含所有指定组件
|
|
226
|
+
*/
|
|
227
|
+
private archetypeContainsAllComponents;
|
|
228
|
+
/**
|
|
229
|
+
* 更新组件索引
|
|
230
|
+
*/
|
|
231
|
+
private updateComponentIndexes;
|
|
232
|
+
/**
|
|
233
|
+
* 使查询缓存失效
|
|
234
|
+
*/
|
|
235
|
+
private invalidateQueryCache;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export type ArchetypeId = string;
|
|
239
|
+
|
|
240
|
+
export declare class BitMaskOptimizer {
|
|
241
|
+
private static instance;
|
|
242
|
+
private maskCache;
|
|
243
|
+
private componentTypeMap;
|
|
244
|
+
private nextComponentId;
|
|
245
|
+
private constructor();
|
|
246
|
+
static getInstance(): BitMaskOptimizer;
|
|
247
|
+
/**
|
|
248
|
+
* 注册组件类型
|
|
249
|
+
*/
|
|
250
|
+
registerComponentType(componentName: string): number;
|
|
251
|
+
/**
|
|
252
|
+
* 获取组件类型ID
|
|
253
|
+
*/
|
|
254
|
+
getComponentTypeId(componentName: string): number | undefined;
|
|
255
|
+
/**
|
|
256
|
+
* 创建单个组件的掩码
|
|
257
|
+
*/
|
|
258
|
+
createSingleComponentMask(componentName: string): bigint;
|
|
259
|
+
/**
|
|
260
|
+
* 创建多个组件的组合掩码
|
|
261
|
+
*/
|
|
262
|
+
createCombinedMask(componentNames: string[]): bigint;
|
|
263
|
+
/**
|
|
264
|
+
* 检查掩码是否包含指定组件
|
|
265
|
+
*/
|
|
266
|
+
maskContainsComponent(mask: bigint, componentName: string): boolean;
|
|
267
|
+
/**
|
|
268
|
+
* 检查掩码是否包含所有指定组件
|
|
269
|
+
*/
|
|
270
|
+
maskContainsAllComponents(mask: bigint, componentNames: string[]): boolean;
|
|
271
|
+
/**
|
|
272
|
+
* 检查掩码是否包含任一指定组件
|
|
273
|
+
*/
|
|
274
|
+
maskContainsAnyComponent(mask: bigint, componentNames: string[]): boolean;
|
|
275
|
+
/**
|
|
276
|
+
* 添加组件到掩码
|
|
277
|
+
*/
|
|
278
|
+
addComponentToMask(mask: bigint, componentName: string): bigint;
|
|
279
|
+
/**
|
|
280
|
+
* 从掩码中移除组件
|
|
281
|
+
*/
|
|
282
|
+
removeComponentFromMask(mask: bigint, componentName: string): bigint;
|
|
283
|
+
/**
|
|
284
|
+
* 预计算常用掩码组合
|
|
285
|
+
*/
|
|
286
|
+
precomputeCommonMasks(commonCombinations: string[][]): void;
|
|
287
|
+
/**
|
|
288
|
+
* 获取掩码缓存统计信息
|
|
289
|
+
*/
|
|
290
|
+
getCacheStats(): {
|
|
291
|
+
size: number;
|
|
292
|
+
componentTypes: number;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export declare enum IndexType {
|
|
296
|
+
/** 哈希索引 - 最快查找 */
|
|
297
|
+
HASH = "hash",
|
|
298
|
+
/** 位图索引 - 内存高效 */
|
|
299
|
+
BITMAP = "bitmap",
|
|
300
|
+
/** 排序索引 - 支持范围查询 */
|
|
301
|
+
SORTED = "sorted"
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface IndexStats {
|
|
305
|
+
/** 索引类型 */
|
|
306
|
+
type: IndexType;
|
|
307
|
+
/** 索引大小 */
|
|
308
|
+
size: number;
|
|
309
|
+
/** 内存使用量(字节) */
|
|
310
|
+
memoryUsage: number;
|
|
311
|
+
/** 查询次数 */
|
|
312
|
+
queryCount: number;
|
|
313
|
+
/** 平均查询时间(毫秒) */
|
|
314
|
+
avgQueryTime: number;
|
|
315
|
+
/** 最后更新时间 */
|
|
316
|
+
lastUpdated: number;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface IComponentIndex {
|
|
320
|
+
/** 索引类型 */
|
|
321
|
+
readonly type: IndexType;
|
|
322
|
+
/** 添加实体到索引 */
|
|
323
|
+
addEntity(entity: Entity): void;
|
|
324
|
+
/** 从索引中移除实体 */
|
|
325
|
+
removeEntity(entity: Entity): void;
|
|
326
|
+
/** 查询包含指定组件的实体 */
|
|
327
|
+
query(componentType: ComponentType): Set<Entity>;
|
|
328
|
+
/** 批量查询多个组件 */
|
|
329
|
+
queryMultiple(componentTypes: ComponentType[], operation: 'AND' | 'OR'): Set<Entity>;
|
|
330
|
+
/** 清空索引 */
|
|
331
|
+
clear(): void;
|
|
332
|
+
/** 获取索引统计信息 */
|
|
333
|
+
getStats(): IndexStats;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export declare class HashComponentIndex implements IComponentIndex {
|
|
337
|
+
readonly type = IndexType.HASH;
|
|
338
|
+
private _componentToEntities;
|
|
339
|
+
private _entityToComponents;
|
|
340
|
+
private _queryCount;
|
|
341
|
+
private _totalQueryTime;
|
|
342
|
+
private _lastUpdated;
|
|
343
|
+
addEntity(entity: Entity): void;
|
|
344
|
+
removeEntity(entity: Entity): void;
|
|
345
|
+
query(componentType: ComponentType): Set<Entity>;
|
|
346
|
+
queryMultiple(componentTypes: ComponentType[], operation: 'AND' | 'OR'): Set<Entity>;
|
|
347
|
+
clear(): void;
|
|
348
|
+
getStats(): IndexStats;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export declare class BitmapComponentIndex implements IComponentIndex {
|
|
352
|
+
readonly type = IndexType.BITMAP;
|
|
353
|
+
private _componentTypeToBit;
|
|
354
|
+
private _entityToBitmap;
|
|
355
|
+
private _bitToEntities;
|
|
356
|
+
private _nextBit;
|
|
357
|
+
private _queryCount;
|
|
358
|
+
private _totalQueryTime;
|
|
359
|
+
private _lastUpdated;
|
|
360
|
+
addEntity(entity: Entity): void;
|
|
361
|
+
removeEntity(entity: Entity): void;
|
|
362
|
+
query(componentType: ComponentType): Set<Entity>;
|
|
363
|
+
queryMultiple(componentTypes: ComponentType[], operation: 'AND' | 'OR'): Set<Entity>;
|
|
364
|
+
clear(): void;
|
|
365
|
+
getStats(): IndexStats;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export declare class ComponentIndexManager {
|
|
369
|
+
private _activeIndex;
|
|
370
|
+
private _indexHistory;
|
|
371
|
+
private _autoOptimize;
|
|
372
|
+
private _optimizationThreshold;
|
|
373
|
+
constructor(initialType?: IndexType);
|
|
374
|
+
/**
|
|
375
|
+
* 添加实体到索引
|
|
376
|
+
*/
|
|
377
|
+
addEntity(entity: Entity): void;
|
|
378
|
+
/**
|
|
379
|
+
* 从索引中移除实体
|
|
380
|
+
*/
|
|
381
|
+
removeEntity(entity: Entity): void;
|
|
382
|
+
/**
|
|
383
|
+
* 查询包含指定组件的实体
|
|
384
|
+
*/
|
|
385
|
+
query(componentType: ComponentType): Set<Entity>;
|
|
386
|
+
/**
|
|
387
|
+
* 批量查询多个组件
|
|
388
|
+
*/
|
|
389
|
+
queryMultiple(componentTypes: ComponentType[], operation: 'AND' | 'OR'): Set<Entity>;
|
|
390
|
+
/**
|
|
391
|
+
* 手动切换索引类型
|
|
392
|
+
*/
|
|
393
|
+
switchIndexType(type: IndexType): void;
|
|
394
|
+
/**
|
|
395
|
+
* 启用/禁用自动优化
|
|
396
|
+
*/
|
|
397
|
+
setAutoOptimize(enabled: boolean): void;
|
|
398
|
+
/**
|
|
399
|
+
* 获取当前索引统计信息
|
|
400
|
+
*/
|
|
401
|
+
getStats(): IndexStats;
|
|
402
|
+
/**
|
|
403
|
+
* 获取所有索引类型的历史统计信息
|
|
404
|
+
*/
|
|
405
|
+
getAllStats(): Map<IndexType, IndexStats>;
|
|
406
|
+
/**
|
|
407
|
+
* 清空索引
|
|
408
|
+
*/
|
|
409
|
+
clear(): void;
|
|
410
|
+
/**
|
|
411
|
+
* 创建指定类型的索引
|
|
412
|
+
*/
|
|
413
|
+
private createIndex;
|
|
414
|
+
/**
|
|
415
|
+
* 检查是否需要优化索引
|
|
416
|
+
*/
|
|
417
|
+
private checkOptimization;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export declare class ComponentPool<T extends Component> {
|
|
421
|
+
private pool;
|
|
422
|
+
private createFn;
|
|
423
|
+
private resetFn?;
|
|
424
|
+
private maxSize;
|
|
425
|
+
constructor(createFn: () => T, resetFn?: (component: T) => void, maxSize?: number);
|
|
426
|
+
/**
|
|
427
|
+
* 获取一个组件实例
|
|
428
|
+
*/
|
|
429
|
+
acquire(): T;
|
|
430
|
+
/**
|
|
431
|
+
* 释放一个组件实例回池中
|
|
432
|
+
*/
|
|
433
|
+
release(component: T): void;
|
|
434
|
+
/**
|
|
435
|
+
* 预填充对象池
|
|
436
|
+
*/
|
|
437
|
+
prewarm(count: number): void;
|
|
438
|
+
/**
|
|
439
|
+
* 清空对象池
|
|
440
|
+
*/
|
|
441
|
+
clear(): void;
|
|
442
|
+
/**
|
|
443
|
+
* 获取池中可用对象数量
|
|
444
|
+
*/
|
|
445
|
+
getAvailableCount(): number;
|
|
446
|
+
/**
|
|
447
|
+
* 获取池的最大容量
|
|
448
|
+
*/
|
|
449
|
+
getMaxSize(): number;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export declare class ComponentPoolManager {
|
|
453
|
+
private static instance;
|
|
454
|
+
private pools;
|
|
455
|
+
private constructor();
|
|
456
|
+
static getInstance(): ComponentPoolManager;
|
|
457
|
+
/**
|
|
458
|
+
* 注册组件池
|
|
459
|
+
*/
|
|
460
|
+
registerPool<T extends Component>(componentName: string, createFn: () => T, resetFn?: (component: T) => void, maxSize?: number): void;
|
|
461
|
+
/**
|
|
462
|
+
* 获取组件实例
|
|
463
|
+
*/
|
|
464
|
+
acquireComponent<T extends Component>(componentName: string): T | null;
|
|
465
|
+
/**
|
|
466
|
+
* 释放组件实例
|
|
467
|
+
*/
|
|
468
|
+
releaseComponent<T extends Component>(componentName: string, component: T): void;
|
|
469
|
+
/**
|
|
470
|
+
* 预热所有池
|
|
471
|
+
*/
|
|
472
|
+
prewarmAll(count?: number): void;
|
|
473
|
+
/**
|
|
474
|
+
* 清空所有池
|
|
475
|
+
*/
|
|
476
|
+
clearAll(): void;
|
|
477
|
+
/**
|
|
478
|
+
* 获取池统计信息
|
|
479
|
+
*/
|
|
480
|
+
getPoolStats(): Map<string, {
|
|
481
|
+
available: number;
|
|
482
|
+
maxSize: number;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export type ComponentType<T extends Component = Component> = new (...args: any[]) => T;
|
|
486
|
+
/**
|
|
487
|
+
* 组件注册表
|
|
488
|
+
* 管理组件类型的位掩码分配
|
|
489
|
+
*/
|
|
490
|
+
export declare class ComponentRegistry {
|
|
491
|
+
private static componentTypes;
|
|
492
|
+
private static nextBitIndex;
|
|
493
|
+
private static maxComponents;
|
|
494
|
+
/**
|
|
495
|
+
* 注册组件类型并分配位掩码
|
|
496
|
+
* @param componentType 组件类型
|
|
497
|
+
* @returns 分配的位索引
|
|
498
|
+
*/
|
|
499
|
+
static register<T extends Component>(componentType: ComponentType<T>): number;
|
|
500
|
+
/**
|
|
501
|
+
* 获取组件类型的位掩码
|
|
502
|
+
* @param componentType 组件类型
|
|
503
|
+
* @returns 位掩码
|
|
504
|
+
*/
|
|
505
|
+
static getBitMask<T extends Component>(componentType: ComponentType<T>): bigint;
|
|
506
|
+
/**
|
|
507
|
+
* 获取组件类型的位索引
|
|
508
|
+
* @param componentType 组件类型
|
|
509
|
+
* @returns 位索引
|
|
510
|
+
*/
|
|
511
|
+
static getBitIndex<T extends Component>(componentType: ComponentType<T>): number;
|
|
512
|
+
/**
|
|
513
|
+
* 检查组件类型是否已注册
|
|
514
|
+
* @param componentType 组件类型
|
|
515
|
+
* @returns 是否已注册
|
|
516
|
+
*/
|
|
517
|
+
static isRegistered<T extends Component>(componentType: ComponentType<T>): boolean;
|
|
518
|
+
/**
|
|
519
|
+
* 获取所有已注册的组件类型
|
|
520
|
+
* @returns 组件类型映射
|
|
521
|
+
*/
|
|
522
|
+
static getAllRegisteredTypes(): Map<Function, number>;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export declare class ComponentStorage<T extends Component> {
|
|
526
|
+
private components;
|
|
527
|
+
private entityToIndex;
|
|
528
|
+
private indexToEntity;
|
|
529
|
+
private freeIndices;
|
|
530
|
+
private componentType;
|
|
531
|
+
private _size;
|
|
532
|
+
constructor(componentType: ComponentType<T>);
|
|
533
|
+
/**
|
|
534
|
+
* 添加组件
|
|
535
|
+
* @param entityId 实体ID
|
|
536
|
+
* @param component 组件实例
|
|
537
|
+
*/
|
|
538
|
+
addComponent(entityId: number, component: T): void;
|
|
539
|
+
/**
|
|
540
|
+
* 获取组件
|
|
541
|
+
* @param entityId 实体ID
|
|
542
|
+
* @returns 组件实例或null
|
|
543
|
+
*/
|
|
544
|
+
getComponent(entityId: number): T | null;
|
|
545
|
+
/**
|
|
546
|
+
* 检查实体是否有此组件
|
|
547
|
+
* @param entityId 实体ID
|
|
548
|
+
* @returns 是否有组件
|
|
549
|
+
*/
|
|
550
|
+
hasComponent(entityId: number): boolean;
|
|
551
|
+
/**
|
|
552
|
+
* 移除组件
|
|
553
|
+
* @param entityId 实体ID
|
|
554
|
+
* @returns 被移除的组件或null
|
|
555
|
+
*/
|
|
556
|
+
removeComponent(entityId: number): T | null;
|
|
557
|
+
/**
|
|
558
|
+
* 高效遍历所有组件
|
|
559
|
+
* @param callback 回调函数
|
|
560
|
+
*/
|
|
561
|
+
forEach(callback: (component: T, entityId: number, index: number) => void): void;
|
|
562
|
+
/**
|
|
563
|
+
* 获取所有组件(密集数组)
|
|
564
|
+
* @returns 组件数组
|
|
565
|
+
*/
|
|
566
|
+
getDenseArray(): {
|
|
567
|
+
components: T[];
|
|
568
|
+
entityIds: number[];
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export declare class ComponentStorageManager {
|
|
572
|
+
private storages;
|
|
573
|
+
/**
|
|
574
|
+
* 获取或创建组件存储器
|
|
575
|
+
* @param componentType 组件类型
|
|
576
|
+
* @returns 组件存储器
|
|
577
|
+
*/
|
|
578
|
+
getStorage<T extends Component>(componentType: ComponentType<T>): ComponentStorage<T>;
|
|
579
|
+
/**
|
|
580
|
+
* 添加组件
|
|
581
|
+
* @param entityId 实体ID
|
|
582
|
+
* @param component 组件实例
|
|
583
|
+
*/
|
|
584
|
+
addComponent<T extends Component>(entityId: number, component: T): void;
|
|
585
|
+
/**
|
|
586
|
+
* 获取组件
|
|
587
|
+
* @param entityId 实体ID
|
|
588
|
+
* @param componentType 组件类型
|
|
589
|
+
* @returns 组件实例或null
|
|
590
|
+
*/
|
|
591
|
+
getComponent<T extends Component>(entityId: number, componentType: ComponentType<T>): T | null;
|
|
592
|
+
/**
|
|
593
|
+
* 检查实体是否有组件
|
|
594
|
+
* @param entityId 实体ID
|
|
595
|
+
* @param componentType 组件类型
|
|
596
|
+
* @returns 是否有组件
|
|
597
|
+
*/
|
|
598
|
+
hasComponent<T extends Component>(entityId: number, componentType: ComponentType<T>): boolean;
|
|
599
|
+
/**
|
|
600
|
+
* 移除组件
|
|
601
|
+
* @param entityId 实体ID
|
|
602
|
+
* @param componentType 组件类型
|
|
603
|
+
* @returns 被移除的组件或null
|
|
604
|
+
*/
|
|
605
|
+
removeComponent<T extends Component>(entityId: number, componentType: ComponentType<T>): T | null;
|
|
606
|
+
/**
|
|
607
|
+
* 移除实体的所有组件
|
|
608
|
+
* @param entityId 实体ID
|
|
609
|
+
*/
|
|
610
|
+
removeAllComponents(entityId: number): void;
|
|
611
|
+
/**
|
|
612
|
+
* 获取实体的组件位掩码
|
|
613
|
+
* @param entityId 实体ID
|
|
614
|
+
* @returns 组件位掩码
|
|
615
|
+
*/
|
|
616
|
+
getComponentMask(entityId: number): bigint;
|
|
617
|
+
/**
|
|
618
|
+
* 压缩所有存储器
|
|
619
|
+
*/
|
|
620
|
+
compactAll(): void;
|
|
621
|
+
/**
|
|
622
|
+
* 获取所有存储器的统计信息
|
|
623
|
+
*/
|
|
624
|
+
getAllStats(): Map<string, any>;
|
|
625
|
+
/**
|
|
626
|
+
* 清空所有存储器
|
|
627
|
+
*/
|
|
628
|
+
clear(): void;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
export type ComponentType<T extends Component = Component> = new (...args: any[]) => T;
|
|
632
|
+
|
|
633
|
+
export declare enum DirtyFlag {
|
|
634
|
+
/** 组件数据已修改 */
|
|
635
|
+
COMPONENT_MODIFIED = 1,
|
|
636
|
+
/** 组件已添加 */
|
|
637
|
+
COMPONENT_ADDED = 2,
|
|
638
|
+
/** 组件已移除 */
|
|
639
|
+
COMPONENT_REMOVED = 4,
|
|
640
|
+
/** 实体位置已改变 */
|
|
641
|
+
TRANSFORM_CHANGED = 8,
|
|
642
|
+
/** 实体状态已改变 */
|
|
643
|
+
STATE_CHANGED = 16,
|
|
644
|
+
/** 自定义标记1 */
|
|
645
|
+
CUSTOM_1 = 256,
|
|
646
|
+
/** 自定义标记2 */
|
|
647
|
+
CUSTOM_2 = 512,
|
|
648
|
+
/** 自定义标记3 */
|
|
649
|
+
CUSTOM_3 = 1024,
|
|
650
|
+
/** 所有标记 */
|
|
651
|
+
ALL = 4294967295
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
export interface DirtyData {
|
|
655
|
+
/** 实体引用 */
|
|
656
|
+
entity: Entity;
|
|
657
|
+
/** 脏标记位 */
|
|
658
|
+
flags: number;
|
|
659
|
+
/** 修改的组件类型列表 */
|
|
660
|
+
modifiedComponents: Set<ComponentType>;
|
|
661
|
+
/** 标记时间戳 */
|
|
662
|
+
timestamp: number;
|
|
663
|
+
/** 帧编号 */
|
|
664
|
+
frameNumber: number;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export interface DirtyListener {
|
|
668
|
+
/** 感兴趣的标记类型 */
|
|
669
|
+
flags: number;
|
|
670
|
+
/** 回调函数 */
|
|
671
|
+
callback: (dirtyData: DirtyData) => void;
|
|
672
|
+
/** 监听器优先级(数字越小优先级越高) */
|
|
673
|
+
priority?: number;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export interface DirtyStats {
|
|
677
|
+
/** 当前脏实体数量 */
|
|
678
|
+
dirtyEntityCount: number;
|
|
679
|
+
/** 总标记次数 */
|
|
680
|
+
totalMarkings: number;
|
|
681
|
+
/** 总清理次数 */
|
|
682
|
+
totalCleanups: number;
|
|
683
|
+
/** 监听器数量 */
|
|
684
|
+
listenerCount: number;
|
|
685
|
+
/** 平均每帧脏实体数量 */
|
|
686
|
+
avgDirtyPerFrame: number;
|
|
687
|
+
/** 内存使用量估算 */
|
|
688
|
+
estimatedMemoryUsage: number;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
export declare class DirtyTrackingSystem {
|
|
692
|
+
/** 脏实体映射表 */
|
|
693
|
+
private _dirtyEntities;
|
|
694
|
+
/** 脏标记监听器 */
|
|
695
|
+
private _listeners;
|
|
696
|
+
/** 性能统计 */
|
|
697
|
+
private _stats;
|
|
698
|
+
/** 当前帧编号 */
|
|
699
|
+
private _currentFrame;
|
|
700
|
+
private _batchSize;
|
|
701
|
+
private _maxProcessingTime;
|
|
702
|
+
/** 延迟处理队列 */
|
|
703
|
+
private _processingQueue;
|
|
704
|
+
private _isProcessing;
|
|
705
|
+
/**
|
|
706
|
+
* 标记实体为脏状态
|
|
707
|
+
*
|
|
708
|
+
* @param entity 要标记的实体
|
|
709
|
+
* @param flags 脏标记位
|
|
710
|
+
* @param modifiedComponents 修改的组件类型列表
|
|
711
|
+
*/
|
|
712
|
+
markDirty(entity: Entity, flags: DirtyFlag, modifiedComponents?: ComponentType[]): void;
|
|
713
|
+
/**
|
|
714
|
+
* 检查实体是否有指定的脏标记
|
|
715
|
+
*
|
|
716
|
+
* @param entity 要检查的实体
|
|
717
|
+
* @param flags 要检查的标记位
|
|
718
|
+
* @returns 是否有指定的脏标记
|
|
719
|
+
*/
|
|
720
|
+
isDirty(entity: Entity, flags?: DirtyFlag): boolean;
|
|
721
|
+
/**
|
|
722
|
+
* 清除实体的脏标记
|
|
723
|
+
*
|
|
724
|
+
* @param entity 要清除的实体
|
|
725
|
+
* @param flags 要清除的标记位,默认清除所有
|
|
726
|
+
*/
|
|
727
|
+
clearDirty(entity: Entity, flags?: DirtyFlag): void;
|
|
728
|
+
/**
|
|
729
|
+
* 获取所有脏实体
|
|
730
|
+
*
|
|
731
|
+
* @param flags 过滤标记位,只返回包含指定标记的实体
|
|
732
|
+
* @returns 脏实体数据数组
|
|
733
|
+
*/
|
|
734
|
+
getDirtyEntities(flags?: DirtyFlag): DirtyData[];
|
|
735
|
+
/**
|
|
736
|
+
* 批量处理脏实体
|
|
737
|
+
*
|
|
738
|
+
* 使用时间分片的方式处理脏实体,避免单帧卡顿
|
|
739
|
+
*/
|
|
740
|
+
processDirtyEntities(): void;
|
|
741
|
+
/**
|
|
742
|
+
* 添加脏标记监听器
|
|
743
|
+
*
|
|
744
|
+
* @param listener 监听器配置
|
|
745
|
+
*/
|
|
746
|
+
addListener(listener: DirtyListener): void;
|
|
747
|
+
/**
|
|
748
|
+
* 移除脏标记监听器
|
|
749
|
+
*
|
|
750
|
+
* @param callback 要移除的回调函数
|
|
751
|
+
*/
|
|
752
|
+
removeListener(callback: (dirtyData: DirtyData) => void): void;
|
|
753
|
+
/**
|
|
754
|
+
* 开始新的帧
|
|
755
|
+
*/
|
|
756
|
+
beginFrame(): void;
|
|
757
|
+
/**
|
|
758
|
+
* 结束当前帧
|
|
759
|
+
*/
|
|
760
|
+
endFrame(): void;
|
|
761
|
+
/**
|
|
762
|
+
* 获取统计信息
|
|
763
|
+
*/
|
|
764
|
+
getStats(): DirtyStats;
|
|
765
|
+
/**
|
|
766
|
+
* 清空所有脏标记和统计信息
|
|
767
|
+
*/
|
|
768
|
+
clear(): void;
|
|
769
|
+
/**
|
|
770
|
+
* 配置批量处理参数
|
|
771
|
+
*
|
|
772
|
+
* @param batchSize 每次处理的最大实体数量
|
|
773
|
+
* @param maxProcessingTime 每帧最大处理时间(毫秒)
|
|
774
|
+
*/
|
|
775
|
+
configureBatchProcessing(batchSize: number, maxProcessingTime: number): void;
|
|
776
|
+
/**
|
|
777
|
+
* 处理单个脏实体
|
|
778
|
+
*/
|
|
779
|
+
private processEntity;
|
|
780
|
+
/**
|
|
781
|
+
* 通知监听器
|
|
782
|
+
*/
|
|
783
|
+
private notifyListeners;
|
|
784
|
+
/**
|
|
785
|
+
* 帧结束时的统计更新
|
|
786
|
+
*/
|
|
787
|
+
private onFrameEnd;
|
|
788
|
+
/**
|
|
789
|
+
* 估算内存使用量
|
|
790
|
+
*/
|
|
791
|
+
private estimateMemoryUsage;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
export declare class EntityQueryBuilder {
|
|
795
|
+
private entityManager;
|
|
796
|
+
/** 必须包含的组件类型 */
|
|
797
|
+
private _allComponents;
|
|
798
|
+
/** 至少包含一个的组件类型 */
|
|
799
|
+
private _anyComponents;
|
|
800
|
+
/** 不能包含的组件类型 */
|
|
801
|
+
private _withoutComponents;
|
|
802
|
+
/** 必须包含的标签 */
|
|
803
|
+
private _withTags;
|
|
804
|
+
/** 不能包含的标签 */
|
|
805
|
+
private _withoutTags;
|
|
806
|
+
/** 是否只查询激活状态的实体 */
|
|
807
|
+
private _activeOnly;
|
|
808
|
+
/** 是否只查询启用状态的实体 */
|
|
809
|
+
private _enabledOnly;
|
|
810
|
+
/** 自定义过滤条件 */
|
|
811
|
+
private _customPredicates;
|
|
812
|
+
/**
|
|
813
|
+
* 创建查询构建器实例
|
|
814
|
+
* @param entityManager 实体管理器实例
|
|
815
|
+
*/
|
|
816
|
+
constructor(entityManager: EntityManager);
|
|
817
|
+
/**
|
|
818
|
+
* 添加必须包含的组件条件
|
|
819
|
+
*
|
|
820
|
+
* 返回的实体必须包含所有指定的组件类型。
|
|
821
|
+
*
|
|
822
|
+
* @param componentTypes 组件类型列表
|
|
823
|
+
* @returns 查询构建器实例,支持链式调用
|
|
824
|
+
*/
|
|
825
|
+
withAll(...componentTypes: ComponentType[]): EntityQueryBuilder;
|
|
826
|
+
/**
|
|
827
|
+
* 添加至少包含一个的组件条件
|
|
828
|
+
*
|
|
829
|
+
* 返回的实体必须至少包含其中一个指定的组件类型。
|
|
830
|
+
*
|
|
831
|
+
* @param componentTypes 组件类型列表
|
|
832
|
+
* @returns 查询构建器实例,支持链式调用
|
|
833
|
+
*/
|
|
834
|
+
withAny(...componentTypes: ComponentType[]): EntityQueryBuilder;
|
|
835
|
+
/**
|
|
836
|
+
* 添加不能包含的组件条件
|
|
837
|
+
*
|
|
838
|
+
* 返回的实体不能包含任何指定的组件类型。
|
|
839
|
+
*
|
|
840
|
+
* @param componentTypes 组件类型列表
|
|
841
|
+
* @returns 查询构建器实例,支持链式调用
|
|
842
|
+
*/
|
|
843
|
+
without(...componentTypes: ComponentType[]): EntityQueryBuilder;
|
|
844
|
+
/**
|
|
845
|
+
* 添加必须包含的标签条件
|
|
846
|
+
*
|
|
847
|
+
* 返回的实体必须具有指定的标签。
|
|
848
|
+
*
|
|
849
|
+
* @param tag 标签值
|
|
850
|
+
* @returns 查询构建器实例,支持链式调用
|
|
851
|
+
*/
|
|
852
|
+
withTag(tag: number): EntityQueryBuilder;
|
|
853
|
+
/**
|
|
854
|
+
* 添加不能包含的标签条件
|
|
855
|
+
*
|
|
856
|
+
* 返回的实体不能具有指定的标签。
|
|
857
|
+
*
|
|
858
|
+
* @param tag 标签值
|
|
859
|
+
* @returns 查询构建器实例,支持链式调用
|
|
860
|
+
*/
|
|
861
|
+
withoutTag(tag: number): EntityQueryBuilder;
|
|
862
|
+
/**
|
|
863
|
+
* 添加激活状态过滤条件
|
|
864
|
+
*
|
|
865
|
+
* 返回的实体必须处于激活状态(active = true)。
|
|
866
|
+
*
|
|
867
|
+
* @returns 查询构建器实例,支持链式调用
|
|
868
|
+
*/
|
|
869
|
+
active(): EntityQueryBuilder;
|
|
870
|
+
/**
|
|
871
|
+
* 添加启用状态过滤条件
|
|
872
|
+
*
|
|
873
|
+
* 返回的实体必须处于启用状态(enabled = true)。
|
|
874
|
+
*
|
|
875
|
+
* @returns 查询构建器实例,支持链式调用
|
|
876
|
+
*/
|
|
877
|
+
enabled(): EntityQueryBuilder;
|
|
878
|
+
/**
|
|
879
|
+
* 添加自定义过滤条件
|
|
880
|
+
*
|
|
881
|
+
* 允许用户定义复杂的过滤逻辑。
|
|
882
|
+
*
|
|
883
|
+
* @param predicate 自定义过滤函数,接收实体作为参数,返回布尔值
|
|
884
|
+
* @returns 查询构建器实例,支持链式调用
|
|
885
|
+
*
|
|
886
|
+
* @example
|
|
887
|
+
* ```typescript
|
|
888
|
+
* .where(entity => entity.name.startsWith("Player"))
|
|
889
|
+
* .where(entity => entity.components.length > 5)
|
|
890
|
+
* ```
|
|
891
|
+
*/
|
|
892
|
+
where(predicate: (entity: Entity) => boolean): EntityQueryBuilder;
|
|
893
|
+
/**
|
|
894
|
+
* 执行查询并返回所有匹配的实体
|
|
895
|
+
*
|
|
896
|
+
* @returns 符合所有查询条件的实体数组
|
|
897
|
+
*/
|
|
898
|
+
execute(): Entity[];
|
|
899
|
+
/**
|
|
900
|
+
* 执行查询并返回第一个匹配的实体
|
|
901
|
+
*
|
|
902
|
+
* @returns 第一个符合查询条件的实体,如果没有找到则返回null
|
|
903
|
+
*/
|
|
904
|
+
first(): Entity | null;
|
|
905
|
+
/**
|
|
906
|
+
* 执行查询并返回匹配实体的数量
|
|
907
|
+
*
|
|
908
|
+
* @returns 符合查询条件的实体数量
|
|
909
|
+
*/
|
|
910
|
+
count(): number;
|
|
911
|
+
/**
|
|
912
|
+
* 对所有匹配的实体执行指定操作
|
|
913
|
+
*
|
|
914
|
+
* @param action 要执行的操作函数,接收匹配的实体作为参数
|
|
915
|
+
*/
|
|
916
|
+
forEach(action: (entity: Entity) => void): void;
|
|
917
|
+
/**
|
|
918
|
+
* 检查实体是否匹配所有查询条件
|
|
919
|
+
*
|
|
920
|
+
* 按优先级顺序检查各种过滤条件,一旦发现不匹配立即返回false。
|
|
921
|
+
*
|
|
922
|
+
* @param entity 要检查的实体
|
|
923
|
+
* @returns 实体是否匹配所有查询条件
|
|
924
|
+
*/
|
|
925
|
+
private matchesEntity;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
export declare class EntityManager {
|
|
929
|
+
/** 主要实体存储,使用ID作为键 */
|
|
930
|
+
private _entities;
|
|
931
|
+
/** 按名称索引的实体映射 */
|
|
932
|
+
private _entitiesByName;
|
|
933
|
+
/** 按标签索引的实体映射 */
|
|
934
|
+
private _entitiesByTag;
|
|
935
|
+
/** 实体ID分配器 */
|
|
936
|
+
private _identifierPool;
|
|
937
|
+
/** 已销毁实体的ID集合 */
|
|
938
|
+
private _destroyedEntities;
|
|
939
|
+
/** 性能优化系统 */
|
|
940
|
+
private _componentIndexManager;
|
|
941
|
+
private _archetypeSystem;
|
|
942
|
+
private _dirtyTrackingSystem;
|
|
943
|
+
/** 事件总线 */
|
|
944
|
+
private _eventBus;
|
|
945
|
+
/**
|
|
946
|
+
* 创建实体管理器实例
|
|
947
|
+
*
|
|
948
|
+
* 初始化内部数据结构和ID分配器。
|
|
949
|
+
*/
|
|
950
|
+
constructor();
|
|
951
|
+
/**
|
|
952
|
+
* 获取实体总数
|
|
953
|
+
*
|
|
954
|
+
* @returns 当前管理的实体总数量
|
|
955
|
+
*/
|
|
956
|
+
get entityCount(): number;
|
|
957
|
+
/**
|
|
958
|
+
* 获取激活状态的实体数量
|
|
959
|
+
*
|
|
960
|
+
* 只计算同时满足激活状态且未被销毁的实体。
|
|
961
|
+
*
|
|
962
|
+
* @returns 激活状态的实体数量
|
|
963
|
+
*/
|
|
964
|
+
get activeEntityCount(): number;
|
|
965
|
+
/**
|
|
966
|
+
* 创建新实体
|
|
967
|
+
*
|
|
968
|
+
* 分配唯一ID并将实体添加到管理系统中,同时更新相关索引。
|
|
969
|
+
*
|
|
970
|
+
* @param name 实体名称,如果未指定则使用时间戳生成默认名称
|
|
971
|
+
* @returns 创建的实体实例
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* ```typescript
|
|
975
|
+
* const player = entityManager.createEntity("Player");
|
|
976
|
+
* const enemy = entityManager.createEntity(); // 使用默认名称
|
|
977
|
+
* ```
|
|
978
|
+
*/
|
|
979
|
+
createEntity(name?: string): Entity;
|
|
980
|
+
/**
|
|
981
|
+
* 销毁实体
|
|
982
|
+
*
|
|
983
|
+
* 支持通过实体对象、名称或ID来销毁实体。
|
|
984
|
+
* 会清理所有相关索引并回收ID。
|
|
985
|
+
*
|
|
986
|
+
* @param entityOrId 要销毁的实体,可以是实体对象、名称字符串或ID数字
|
|
987
|
+
* @returns 是否成功销毁实体
|
|
988
|
+
*
|
|
989
|
+
* @example
|
|
990
|
+
* ```typescript
|
|
991
|
+
* // 通过实体对象销毁
|
|
992
|
+
* entityManager.destroyEntity(player);
|
|
993
|
+
*
|
|
994
|
+
* // 通过名称销毁
|
|
995
|
+
* entityManager.destroyEntity("Enemy_1");
|
|
996
|
+
*
|
|
997
|
+
* // 通过ID销毁
|
|
998
|
+
* entityManager.destroyEntity(123);
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
1001
|
+
destroyEntity(entityOrId: Entity | string | number): boolean;
|
|
1002
|
+
/**
|
|
1003
|
+
* 获取所有实体
|
|
1004
|
+
*
|
|
1005
|
+
* 返回当前管理的所有实体的副本数组。
|
|
1006
|
+
*
|
|
1007
|
+
* @returns 所有实体的数组
|
|
1008
|
+
*/
|
|
1009
|
+
getAllEntities(): Entity[];
|
|
1010
|
+
/**
|
|
1011
|
+
* 根据ID获取实体
|
|
1012
|
+
*
|
|
1013
|
+
* 支持字符串和数字类型的ID。
|
|
1014
|
+
*
|
|
1015
|
+
* @param id 实体ID,可以是字符串或数字
|
|
1016
|
+
* @returns 对应的实体,如果不存在则返回null
|
|
1017
|
+
*/
|
|
1018
|
+
getEntity(id: string | number): Entity | null;
|
|
1019
|
+
/**
|
|
1020
|
+
* 根据名称获取实体
|
|
1021
|
+
*
|
|
1022
|
+
* 如果存在多个同名实体,返回第一个找到的实体。
|
|
1023
|
+
*
|
|
1024
|
+
* @param name 实体名称
|
|
1025
|
+
* @returns 匹配的实体,如果不存在则返回null
|
|
1026
|
+
*/
|
|
1027
|
+
getEntityByName(name: string): Entity | null;
|
|
1028
|
+
/**
|
|
1029
|
+
* 根据标签获取实体列表
|
|
1030
|
+
*
|
|
1031
|
+
* 返回所有具有指定标签的实体。
|
|
1032
|
+
*
|
|
1033
|
+
* @param tag 标签值
|
|
1034
|
+
* @returns 具有指定标签的实体数组
|
|
1035
|
+
*/
|
|
1036
|
+
getEntitiesByTag(tag: number): Entity[];
|
|
1037
|
+
/**
|
|
1038
|
+
* 获取包含指定组件的所有实体
|
|
1039
|
+
*
|
|
1040
|
+
* 遍历所有实体,查找包含指定组件类型的实体。
|
|
1041
|
+
*
|
|
1042
|
+
* @param componentType 组件类型
|
|
1043
|
+
* @returns 包含指定组件的实体数组
|
|
1044
|
+
*
|
|
1045
|
+
* @example
|
|
1046
|
+
* ```typescript
|
|
1047
|
+
* const entitiesWithHealth = entityManager.getEntitiesWithComponent(HealthComponent);
|
|
1048
|
+
* ```
|
|
1049
|
+
*/
|
|
1050
|
+
getEntitiesWithComponent<T extends Component>(componentType: ComponentType<T>): Entity[];
|
|
1051
|
+
/**
|
|
1052
|
+
* 创建查询构建器
|
|
1053
|
+
*
|
|
1054
|
+
* 返回一个新的查询构建器实例,用于构建复杂的实体查询。
|
|
1055
|
+
*
|
|
1056
|
+
* @returns 新的查询构建器实例
|
|
1057
|
+
*
|
|
1058
|
+
* @example
|
|
1059
|
+
* ```typescript
|
|
1060
|
+
* const results = entityManager.query()
|
|
1061
|
+
* .withAll(PositionComponent, HealthComponent)
|
|
1062
|
+
* .without(VelocityComponent)
|
|
1063
|
+
* .active()
|
|
1064
|
+
* .execute();
|
|
1065
|
+
* ```
|
|
1066
|
+
*/
|
|
1067
|
+
query(): EntityQueryBuilder;
|
|
1068
|
+
/**
|
|
1069
|
+
* 使用组件索引进行多组件查询
|
|
1070
|
+
*
|
|
1071
|
+
* @param componentTypes 组件类型数组
|
|
1072
|
+
* @param operation 查询操作:'AND' 或 'OR'
|
|
1073
|
+
* @returns 匹配的实体集合
|
|
1074
|
+
*/
|
|
1075
|
+
queryWithComponentIndex(componentTypes: ComponentType[], operation: 'AND' | 'OR'): Set<Entity>;
|
|
1076
|
+
/**
|
|
1077
|
+
* 标记实体组件已修改
|
|
1078
|
+
*
|
|
1079
|
+
* @param entity 修改的实体
|
|
1080
|
+
* @param componentTypes 修改的组件类型
|
|
1081
|
+
*/
|
|
1082
|
+
markEntityDirty(entity: Entity, componentTypes: ComponentType[]): void;
|
|
1083
|
+
/**
|
|
1084
|
+
* 获取性能优化统计信息
|
|
1085
|
+
*/
|
|
1086
|
+
getOptimizationStats(): any;
|
|
1087
|
+
/**
|
|
1088
|
+
* 获取事件总线实例
|
|
1089
|
+
*
|
|
1090
|
+
* 允许外部代码监听和发射ECS相关事件。
|
|
1091
|
+
*
|
|
1092
|
+
* @returns 事件总线实例
|
|
1093
|
+
*/
|
|
1094
|
+
get eventBus(): EventBus;
|
|
1095
|
+
/**
|
|
1096
|
+
* 更新名称索引
|
|
1097
|
+
*
|
|
1098
|
+
* 维护按名称查找实体的索引结构。支持添加和移除操作。
|
|
1099
|
+
*
|
|
1100
|
+
* @param entity 要更新索引的实体
|
|
1101
|
+
* @param isAdd true表示添加到索引,false表示从索引中移除
|
|
1102
|
+
*/
|
|
1103
|
+
private updateNameIndex;
|
|
1104
|
+
/**
|
|
1105
|
+
* 更新标签索引
|
|
1106
|
+
*
|
|
1107
|
+
* 维护按标签查找实体的索引结构。支持添加和移除操作。
|
|
1108
|
+
*
|
|
1109
|
+
* @param entity 要更新索引的实体
|
|
1110
|
+
* @param isAdd true表示添加到索引,false表示从索引中移除
|
|
1111
|
+
*/
|
|
1112
|
+
private updateTagIndex;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
export declare class EventBus implements IEventBus {
|
|
1116
|
+
private eventSystem;
|
|
1117
|
+
private eventIdCounter;
|
|
1118
|
+
private isDebugMode;
|
|
1119
|
+
constructor(debugMode?: boolean);
|
|
1120
|
+
/**
|
|
1121
|
+
* 发射事件
|
|
1122
|
+
* @param eventType 事件类型
|
|
1123
|
+
* @param data 事件数据
|
|
1124
|
+
*/
|
|
1125
|
+
emit<T>(eventType: string, data: T): void;
|
|
1126
|
+
/**
|
|
1127
|
+
* 异步发射事件
|
|
1128
|
+
* @param eventType 事件类型
|
|
1129
|
+
* @param data 事件数据
|
|
1130
|
+
*/
|
|
1131
|
+
emitAsync<T>(eventType: string, data: T): Promise<void>;
|
|
1132
|
+
/**
|
|
1133
|
+
* 监听事件
|
|
1134
|
+
* @param eventType 事件类型
|
|
1135
|
+
* @param handler 事件处理器
|
|
1136
|
+
* @param config 监听器配置
|
|
1137
|
+
* @returns 监听器ID
|
|
1138
|
+
*/
|
|
1139
|
+
on<T>(eventType: string, handler: (data: T) => void, config?: IEventListenerConfig): string;
|
|
1140
|
+
/**
|
|
1141
|
+
* 监听事件(一次性)
|
|
1142
|
+
* @param eventType 事件类型
|
|
1143
|
+
* @param handler 事件处理器
|
|
1144
|
+
* @param config 监听器配置
|
|
1145
|
+
* @returns 监听器ID
|
|
1146
|
+
*/
|
|
1147
|
+
once<T>(eventType: string, handler: (data: T) => void, config?: IEventListenerConfig): string;
|
|
1148
|
+
/**
|
|
1149
|
+
* 异步监听事件
|
|
1150
|
+
* @param eventType 事件类型
|
|
1151
|
+
* @param handler 异步事件处理器
|
|
1152
|
+
* @param config 监听器配置
|
|
1153
|
+
* @returns 监听器ID
|
|
1154
|
+
*/
|
|
1155
|
+
onAsync<T>(eventType: string, handler: (data: T) => Promise<void>, config?: IEventListenerConfig): string;
|
|
1156
|
+
/**
|
|
1157
|
+
* 移除事件监听器
|
|
1158
|
+
* @param eventType 事件类型
|
|
1159
|
+
* @param listenerId 监听器ID
|
|
1160
|
+
*/
|
|
1161
|
+
off(eventType: string, listenerId: string): boolean;
|
|
1162
|
+
/**
|
|
1163
|
+
* 移除指定事件类型的所有监听器
|
|
1164
|
+
* @param eventType 事件类型
|
|
1165
|
+
*/
|
|
1166
|
+
offAll(eventType: string): void;
|
|
1167
|
+
/**
|
|
1168
|
+
* 检查是否有指定事件的监听器
|
|
1169
|
+
* @param eventType 事件类型
|
|
1170
|
+
*/
|
|
1171
|
+
hasListeners(eventType: string): boolean;
|
|
1172
|
+
/**
|
|
1173
|
+
* 获取事件统计信息
|
|
1174
|
+
* @param eventType 事件类型(可选)
|
|
1175
|
+
*/
|
|
1176
|
+
getStats(eventType?: string): IEventStats | Map<string, IEventStats>;
|
|
1177
|
+
/**
|
|
1178
|
+
* 清空所有监听器
|
|
1179
|
+
*/
|
|
1180
|
+
clear(): void;
|
|
1181
|
+
/**
|
|
1182
|
+
* 启用或禁用事件系统
|
|
1183
|
+
* @param enabled 是否启用
|
|
1184
|
+
*/
|
|
1185
|
+
setEnabled(enabled: boolean): void;
|
|
1186
|
+
/**
|
|
1187
|
+
* 设置调试模式
|
|
1188
|
+
* @param debug 是否启用调试
|
|
1189
|
+
*/
|
|
1190
|
+
setDebugMode(debug: boolean): void;
|
|
1191
|
+
/**
|
|
1192
|
+
* 设置最大监听器数量
|
|
1193
|
+
* @param max 最大数量
|
|
1194
|
+
*/
|
|
1195
|
+
setMaxListeners(max: number): void;
|
|
1196
|
+
/**
|
|
1197
|
+
* 获取监听器数量
|
|
1198
|
+
* @param eventType 事件类型
|
|
1199
|
+
*/
|
|
1200
|
+
getListenerCount(eventType: string): number;
|
|
1201
|
+
/**
|
|
1202
|
+
* 设置事件批处理配置
|
|
1203
|
+
* @param eventType 事件类型
|
|
1204
|
+
* @param batchSize 批处理大小
|
|
1205
|
+
* @param delay 延迟时间(毫秒)
|
|
1206
|
+
*/
|
|
1207
|
+
setBatchConfig(eventType: string, batchSize: number, delay: number): void;
|
|
1208
|
+
/**
|
|
1209
|
+
* 刷新指定事件的批处理队列
|
|
1210
|
+
* @param eventType 事件类型
|
|
1211
|
+
*/
|
|
1212
|
+
flushBatch(eventType: string): void;
|
|
1213
|
+
/**
|
|
1214
|
+
* 重置事件统计
|
|
1215
|
+
* @param eventType 事件类型(可选)
|
|
1216
|
+
*/
|
|
1217
|
+
resetStats(eventType?: string): void;
|
|
1218
|
+
/**
|
|
1219
|
+
* 发射实体创建事件
|
|
1220
|
+
* @param entityData 实体事件数据
|
|
1221
|
+
*/
|
|
1222
|
+
emitEntityCreated(entityData: IEntityEventData): void;
|
|
1223
|
+
/**
|
|
1224
|
+
* 发射实体销毁事件
|
|
1225
|
+
* @param entityData 实体事件数据
|
|
1226
|
+
*/
|
|
1227
|
+
emitEntityDestroyed(entityData: IEntityEventData): void;
|
|
1228
|
+
/**
|
|
1229
|
+
* 发射组件添加事件
|
|
1230
|
+
* @param componentData 组件事件数据
|
|
1231
|
+
*/
|
|
1232
|
+
emitComponentAdded(componentData: IComponentEventData): void;
|
|
1233
|
+
/**
|
|
1234
|
+
* 发射组件移除事件
|
|
1235
|
+
* @param componentData 组件事件数据
|
|
1236
|
+
*/
|
|
1237
|
+
emitComponentRemoved(componentData: IComponentEventData): void;
|
|
1238
|
+
/**
|
|
1239
|
+
* 发射系统添加事件
|
|
1240
|
+
* @param systemData 系统事件数据
|
|
1241
|
+
*/
|
|
1242
|
+
emitSystemAdded(systemData: ISystemEventData): void;
|
|
1243
|
+
/**
|
|
1244
|
+
* 发射系统移除事件
|
|
1245
|
+
* @param systemData 系统事件数据
|
|
1246
|
+
*/
|
|
1247
|
+
emitSystemRemoved(systemData: ISystemEventData): void;
|
|
1248
|
+
/**
|
|
1249
|
+
* 发射场景变化事件
|
|
1250
|
+
* @param sceneData 场景事件数据
|
|
1251
|
+
*/
|
|
1252
|
+
emitSceneChanged(sceneData: ISceneEventData): void;
|
|
1253
|
+
/**
|
|
1254
|
+
* 发射性能警告事件
|
|
1255
|
+
* @param performanceData 性能事件数据
|
|
1256
|
+
*/
|
|
1257
|
+
emitPerformanceWarning(performanceData: IPerformanceEventData): void;
|
|
1258
|
+
/**
|
|
1259
|
+
* 监听实体创建事件
|
|
1260
|
+
* @param handler 事件处理器
|
|
1261
|
+
* @param config 监听器配置
|
|
1262
|
+
*/
|
|
1263
|
+
onEntityCreated(handler: (data: IEntityEventData) => void, config?: IEventListenerConfig): string;
|
|
1264
|
+
/**
|
|
1265
|
+
* 监听组件添加事件
|
|
1266
|
+
* @param handler 事件处理器
|
|
1267
|
+
* @param config 监听器配置
|
|
1268
|
+
*/
|
|
1269
|
+
onComponentAdded(handler: (data: IComponentEventData) => void, config?: IEventListenerConfig): string;
|
|
1270
|
+
/**
|
|
1271
|
+
* 监听系统错误事件
|
|
1272
|
+
* @param handler 事件处理器
|
|
1273
|
+
* @param config 监听器配置
|
|
1274
|
+
*/
|
|
1275
|
+
onSystemError(handler: (data: ISystemEventData) => void, config?: IEventListenerConfig): string;
|
|
1276
|
+
/**
|
|
1277
|
+
* 监听性能警告事件
|
|
1278
|
+
* @param handler 事件处理器
|
|
1279
|
+
* @param config 监听器配置
|
|
1280
|
+
*/
|
|
1281
|
+
onPerformanceWarning(handler: (data: IPerformanceEventData) => void, config?: IEventListenerConfig): string;
|
|
1282
|
+
/**
|
|
1283
|
+
* 验证事件类型
|
|
1284
|
+
* @param eventType 事件类型
|
|
1285
|
+
*/
|
|
1286
|
+
private validateEventType;
|
|
1287
|
+
/**
|
|
1288
|
+
* 增强事件数据
|
|
1289
|
+
* @param eventType 事件类型
|
|
1290
|
+
* @param data 原始数据
|
|
1291
|
+
*/
|
|
1292
|
+
private enhanceEventData;
|
|
1293
|
+
/**
|
|
1294
|
+
* 转换EventStats为IEventStats
|
|
1295
|
+
* @param stats EventStats实例
|
|
1296
|
+
*/
|
|
1297
|
+
private convertEventStats;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
export declare class GlobalEventBus {
|
|
1301
|
+
private static instance;
|
|
1302
|
+
/**
|
|
1303
|
+
* 获取全局事件总线实例
|
|
1304
|
+
* @param debugMode 是否启用调试模式
|
|
1305
|
+
*/
|
|
1306
|
+
static getInstance(debugMode?: boolean): EventBus;
|
|
1307
|
+
/**
|
|
1308
|
+
* 重置全局事件总线实例
|
|
1309
|
+
* @param debugMode 是否启用调试模式
|
|
1310
|
+
*/
|
|
1311
|
+
static reset(debugMode?: boolean): EventBus;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
export type EventHandler<T = any> = (event: T) => void;
|
|
1315
|
+
/**
|
|
1316
|
+
* 异步事件处理器函数类型
|
|
1317
|
+
*/
|
|
1318
|
+
export type AsyncEventHandler<T = any> = (event: T) => Promise<void>;
|
|
1319
|
+
/**
|
|
1320
|
+
* 事件监听器配置
|
|
1321
|
+
*/
|
|
1322
|
+
export interface EventListenerConfig {
|
|
1323
|
+
/** 是否只执行一次 */
|
|
1324
|
+
once?: boolean;
|
|
1325
|
+
/** 优先级(数字越大优先级越高) */
|
|
1326
|
+
priority?: number;
|
|
1327
|
+
/** 是否异步执行 */
|
|
1328
|
+
async?: boolean;
|
|
1329
|
+
/** 执行上下文 */
|
|
1330
|
+
context?: any;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
export interface EventStats {
|
|
1334
|
+
/** 事件类型 */
|
|
1335
|
+
eventType: string;
|
|
1336
|
+
/** 监听器数量 */
|
|
1337
|
+
listenerCount: number;
|
|
1338
|
+
/** 触发次数 */
|
|
1339
|
+
triggerCount: number;
|
|
1340
|
+
/** 总执行时间(毫秒) */
|
|
1341
|
+
totalExecutionTime: number;
|
|
1342
|
+
/** 平均执行时间(毫秒) */
|
|
1343
|
+
averageExecutionTime: number;
|
|
1344
|
+
/** 最后触发时间 */
|
|
1345
|
+
lastTriggerTime: number;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
export interface EventBatchConfig {
|
|
1349
|
+
/** 批处理大小 */
|
|
1350
|
+
batchSize: number;
|
|
1351
|
+
/** 批处理延迟(毫秒) */
|
|
1352
|
+
delay: number;
|
|
1353
|
+
/** 是否启用批处理 */
|
|
1354
|
+
enabled: boolean;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
export declare class TypeSafeEventSystem {
|
|
1358
|
+
private listeners;
|
|
1359
|
+
private stats;
|
|
1360
|
+
private batchQueue;
|
|
1361
|
+
private batchTimers;
|
|
1362
|
+
private batchConfigs;
|
|
1363
|
+
private nextListenerId;
|
|
1364
|
+
private isEnabled;
|
|
1365
|
+
private maxListeners;
|
|
1366
|
+
/**
|
|
1367
|
+
* 添加事件监听器
|
|
1368
|
+
* @param eventType 事件类型
|
|
1369
|
+
* @param handler 事件处理器
|
|
1370
|
+
* @param config 监听器配置
|
|
1371
|
+
* @returns 监听器ID(用于移除)
|
|
1372
|
+
*/
|
|
1373
|
+
on<T>(eventType: string, handler: EventHandler<T>, config?: EventListenerConfig): string;
|
|
1374
|
+
/**
|
|
1375
|
+
* 添加一次性事件监听器
|
|
1376
|
+
* @param eventType 事件类型
|
|
1377
|
+
* @param handler 事件处理器
|
|
1378
|
+
* @param config 监听器配置
|
|
1379
|
+
* @returns 监听器ID
|
|
1380
|
+
*/
|
|
1381
|
+
once<T>(eventType: string, handler: EventHandler<T>, config?: EventListenerConfig): string;
|
|
1382
|
+
/**
|
|
1383
|
+
* 添加异步事件监听器
|
|
1384
|
+
* @param eventType 事件类型
|
|
1385
|
+
* @param handler 异步事件处理器
|
|
1386
|
+
* @param config 监听器配置
|
|
1387
|
+
* @returns 监听器ID
|
|
1388
|
+
*/
|
|
1389
|
+
onAsync<T>(eventType: string, handler: AsyncEventHandler<T>, config?: EventListenerConfig): string;
|
|
1390
|
+
/**
|
|
1391
|
+
* 移除事件监听器
|
|
1392
|
+
* @param eventType 事件类型
|
|
1393
|
+
* @param listenerId 监听器ID
|
|
1394
|
+
* @returns 是否成功移除
|
|
1395
|
+
*/
|
|
1396
|
+
off(eventType: string, listenerId: string): boolean;
|
|
1397
|
+
/**
|
|
1398
|
+
* 移除指定事件类型的所有监听器
|
|
1399
|
+
* @param eventType 事件类型
|
|
1400
|
+
*/
|
|
1401
|
+
offAll(eventType: string): void;
|
|
1402
|
+
/**
|
|
1403
|
+
* 触发事件
|
|
1404
|
+
* @param eventType 事件类型
|
|
1405
|
+
* @param event 事件数据
|
|
1406
|
+
* @returns Promise(如果有异步监听器)
|
|
1407
|
+
*/
|
|
1408
|
+
emit<T>(eventType: string, event: T): Promise<void>;
|
|
1409
|
+
/**
|
|
1410
|
+
* 同步触发事件(忽略异步监听器)
|
|
1411
|
+
* @param eventType 事件类型
|
|
1412
|
+
* @param event 事件数据
|
|
1413
|
+
*/
|
|
1414
|
+
emitSync<T>(eventType: string, event: T): void;
|
|
1415
|
+
/**
|
|
1416
|
+
* 设置事件批处理配置
|
|
1417
|
+
* @param eventType 事件类型
|
|
1418
|
+
* @param config 批处理配置
|
|
1419
|
+
*/
|
|
1420
|
+
setBatchConfig(eventType: string, config: EventBatchConfig): void;
|
|
1421
|
+
/**
|
|
1422
|
+
* 立即处理指定事件类型的批处理队列
|
|
1423
|
+
* @param eventType 事件类型
|
|
1424
|
+
*/
|
|
1425
|
+
flushBatch(eventType: string): void;
|
|
1426
|
+
/**
|
|
1427
|
+
* 获取事件统计信息
|
|
1428
|
+
* @param eventType 事件类型(可选)
|
|
1429
|
+
* @returns 统计信息
|
|
1430
|
+
*/
|
|
1431
|
+
getStats(eventType?: string): EventStats | Map<string, EventStats>;
|
|
1432
|
+
/**
|
|
1433
|
+
* 重置统计信息
|
|
1434
|
+
* @param eventType 事件类型(可选,不指定则重置所有)
|
|
1435
|
+
*/
|
|
1436
|
+
resetStats(eventType?: string): void;
|
|
1437
|
+
/**
|
|
1438
|
+
* 启用/禁用事件系统
|
|
1439
|
+
* @param enabled 是否启用
|
|
1440
|
+
*/
|
|
1441
|
+
setEnabled(enabled: boolean): void;
|
|
1442
|
+
/**
|
|
1443
|
+
* 检查是否有指定事件类型的监听器
|
|
1444
|
+
* @param eventType 事件类型
|
|
1445
|
+
* @returns 是否有监听器
|
|
1446
|
+
*/
|
|
1447
|
+
hasListeners(eventType: string): boolean;
|
|
1448
|
+
/**
|
|
1449
|
+
* 获取指定事件类型的监听器数量
|
|
1450
|
+
* @param eventType 事件类型
|
|
1451
|
+
* @returns 监听器数量
|
|
1452
|
+
*/
|
|
1453
|
+
getListenerCount(eventType: string): number;
|
|
1454
|
+
/**
|
|
1455
|
+
* 清空所有事件监听器和数据
|
|
1456
|
+
*/
|
|
1457
|
+
clear(): void;
|
|
1458
|
+
/**
|
|
1459
|
+
* 设置每个事件类型的最大监听器数量
|
|
1460
|
+
* @param max 最大数量
|
|
1461
|
+
*/
|
|
1462
|
+
setMaxListeners(max: number): void;
|
|
1463
|
+
/**
|
|
1464
|
+
* 添加监听器的内部实现
|
|
1465
|
+
* @param eventType 事件类型
|
|
1466
|
+
* @param handler 事件处理器
|
|
1467
|
+
* @param config 配置
|
|
1468
|
+
* @returns 监听器ID
|
|
1469
|
+
*/
|
|
1470
|
+
private addListener;
|
|
1471
|
+
/**
|
|
1472
|
+
* 执行事件的内部实现
|
|
1473
|
+
* @param eventType 事件类型
|
|
1474
|
+
* @param event 事件数据
|
|
1475
|
+
*/
|
|
1476
|
+
private executeEvent;
|
|
1477
|
+
/**
|
|
1478
|
+
* 按优先级排序监听器
|
|
1479
|
+
* @param listeners 监听器数组
|
|
1480
|
+
* @returns 排序后的监听器数组
|
|
1481
|
+
*/
|
|
1482
|
+
private sortListenersByPriority;
|
|
1483
|
+
/**
|
|
1484
|
+
* 移除指定的监听器
|
|
1485
|
+
* @param eventType 事件类型
|
|
1486
|
+
* @param listenerIds 要移除的监听器ID数组
|
|
1487
|
+
*/
|
|
1488
|
+
private removeListeners;
|
|
1489
|
+
/**
|
|
1490
|
+
* 添加事件到批处理队列
|
|
1491
|
+
* @param eventType 事件类型
|
|
1492
|
+
* @param event 事件数据
|
|
1493
|
+
*/
|
|
1494
|
+
private addToBatch;
|
|
1495
|
+
/**
|
|
1496
|
+
* 处理批处理事件
|
|
1497
|
+
* @param eventType 事件类型
|
|
1498
|
+
* @param batch 批处理事件数组
|
|
1499
|
+
*/
|
|
1500
|
+
private processBatch;
|
|
1501
|
+
/**
|
|
1502
|
+
* 清除指定事件类型的批处理
|
|
1503
|
+
* @param eventType 事件类型
|
|
1504
|
+
*/
|
|
1505
|
+
private clearBatch;
|
|
1506
|
+
/**
|
|
1507
|
+
* 清除所有批处理
|
|
1508
|
+
*/
|
|
1509
|
+
private clearAllBatches;
|
|
1510
|
+
/**
|
|
1511
|
+
* 更新事件统计信息
|
|
1512
|
+
* @param eventType 事件类型
|
|
1513
|
+
* @param executionTime 执行时间
|
|
1514
|
+
*/
|
|
1515
|
+
private updateStats;
|
|
1516
|
+
/**
|
|
1517
|
+
* 创建空的统计信息
|
|
1518
|
+
* @param eventType 事件类型
|
|
1519
|
+
* @returns 空的统计信息
|
|
1520
|
+
*/
|
|
1521
|
+
private createEmptyStats;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
export type EventHandler<T = any> = (event: T) => void;
|
|
1525
|
+
/**
|
|
1526
|
+
* 异步事件处理器函数类型
|
|
1527
|
+
*/
|
|
1528
|
+
export type AsyncEventHandler<T = any> = (event: T) => Promise<void>;
|
|
1529
|
+
|
|
1530
|
+
export declare class EntityBuilder {
|
|
1531
|
+
private entity;
|
|
1532
|
+
private scene;
|
|
1533
|
+
private storageManager;
|
|
1534
|
+
constructor(scene: Scene, storageManager: ComponentStorageManager);
|
|
1535
|
+
/**
|
|
1536
|
+
* 设置实体名称
|
|
1537
|
+
* @param name 实体名称
|
|
1538
|
+
* @returns 实体构建器
|
|
1539
|
+
*/
|
|
1540
|
+
named(name: string): EntityBuilder;
|
|
1541
|
+
/**
|
|
1542
|
+
* 设置实体标签
|
|
1543
|
+
* @param tag 标签
|
|
1544
|
+
* @returns 实体构建器
|
|
1545
|
+
*/
|
|
1546
|
+
tagged(tag: number): EntityBuilder;
|
|
1547
|
+
/**
|
|
1548
|
+
* 添加组件
|
|
1549
|
+
* @param component 组件实例
|
|
1550
|
+
* @returns 实体构建器
|
|
1551
|
+
*/
|
|
1552
|
+
with<T extends Component>(component: T): EntityBuilder;
|
|
1553
|
+
/**
|
|
1554
|
+
* 添加多个组件
|
|
1555
|
+
* @param components 组件数组
|
|
1556
|
+
* @returns 实体构建器
|
|
1557
|
+
*/
|
|
1558
|
+
withComponents(...components: Component[]): EntityBuilder;
|
|
1559
|
+
/**
|
|
1560
|
+
* 条件性添加组件
|
|
1561
|
+
* @param condition 条件
|
|
1562
|
+
* @param component 组件实例
|
|
1563
|
+
* @returns 实体构建器
|
|
1564
|
+
*/
|
|
1565
|
+
withIf<T extends Component>(condition: boolean, component: T): EntityBuilder;
|
|
1566
|
+
/**
|
|
1567
|
+
* 使用工厂函数创建并添加组件
|
|
1568
|
+
* @param factory 组件工厂函数
|
|
1569
|
+
* @returns 实体构建器
|
|
1570
|
+
*/
|
|
1571
|
+
withFactory<T extends Component>(factory: () => T): EntityBuilder;
|
|
1572
|
+
/**
|
|
1573
|
+
* 配置组件属性
|
|
1574
|
+
* @param componentType 组件类型
|
|
1575
|
+
* @param configurator 配置函数
|
|
1576
|
+
* @returns 实体构建器
|
|
1577
|
+
*/
|
|
1578
|
+
configure<T extends Component>(componentType: ComponentType<T>, configurator: (component: T) => void): EntityBuilder;
|
|
1579
|
+
/**
|
|
1580
|
+
* 设置实体为启用状态
|
|
1581
|
+
* @param enabled 是否启用
|
|
1582
|
+
* @returns 实体构建器
|
|
1583
|
+
*/
|
|
1584
|
+
enabled(enabled?: boolean): EntityBuilder;
|
|
1585
|
+
/**
|
|
1586
|
+
* 设置实体为活跃状态
|
|
1587
|
+
* @param active 是否活跃
|
|
1588
|
+
* @returns 实体构建器
|
|
1589
|
+
*/
|
|
1590
|
+
active(active?: boolean): EntityBuilder;
|
|
1591
|
+
/**
|
|
1592
|
+
* 添加子实体
|
|
1593
|
+
* @param childBuilder 子实体构建器
|
|
1594
|
+
* @returns 实体构建器
|
|
1595
|
+
*/
|
|
1596
|
+
withChild(childBuilder: EntityBuilder): EntityBuilder;
|
|
1597
|
+
/**
|
|
1598
|
+
* 批量添加子实体
|
|
1599
|
+
* @param childBuilders 子实体构建器数组
|
|
1600
|
+
* @returns 实体构建器
|
|
1601
|
+
*/
|
|
1602
|
+
withChildren(...childBuilders: EntityBuilder[]): EntityBuilder;
|
|
1603
|
+
/**
|
|
1604
|
+
* 使用工厂函数创建子实体
|
|
1605
|
+
* @param childFactory 子实体工厂函数
|
|
1606
|
+
* @returns 实体构建器
|
|
1607
|
+
*/
|
|
1608
|
+
withChildFactory(childFactory: (parent: Entity) => EntityBuilder): EntityBuilder;
|
|
1609
|
+
/**
|
|
1610
|
+
* 条件性添加子实体
|
|
1611
|
+
* @param condition 条件
|
|
1612
|
+
* @param childBuilder 子实体构建器
|
|
1613
|
+
* @returns 实体构建器
|
|
1614
|
+
*/
|
|
1615
|
+
withChildIf(condition: boolean, childBuilder: EntityBuilder): EntityBuilder;
|
|
1616
|
+
/**
|
|
1617
|
+
* 构建并返回实体
|
|
1618
|
+
* @returns 构建的实体
|
|
1619
|
+
*/
|
|
1620
|
+
build(): Entity;
|
|
1621
|
+
/**
|
|
1622
|
+
* 构建实体并添加到场景
|
|
1623
|
+
* @returns 构建的实体
|
|
1624
|
+
*/
|
|
1625
|
+
spawn(): Entity;
|
|
1626
|
+
/**
|
|
1627
|
+
* 克隆当前构建器
|
|
1628
|
+
* @returns 新的实体构建器
|
|
1629
|
+
*/
|
|
1630
|
+
clone(): EntityBuilder;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
export declare class SceneBuilder {
|
|
1634
|
+
private scene;
|
|
1635
|
+
constructor();
|
|
1636
|
+
/**
|
|
1637
|
+
* 设置场景名称
|
|
1638
|
+
* @param name 场景名称
|
|
1639
|
+
* @returns 场景构建器
|
|
1640
|
+
*/
|
|
1641
|
+
named(name: string): SceneBuilder;
|
|
1642
|
+
/**
|
|
1643
|
+
* 添加实体
|
|
1644
|
+
* @param entity 实体
|
|
1645
|
+
* @returns 场景构建器
|
|
1646
|
+
*/
|
|
1647
|
+
withEntity(entity: Entity): SceneBuilder;
|
|
1648
|
+
/**
|
|
1649
|
+
* 使用实体构建器添加实体
|
|
1650
|
+
* @param builderFn 实体构建器函数
|
|
1651
|
+
* @returns 场景构建器
|
|
1652
|
+
*/
|
|
1653
|
+
withEntityBuilder(builderFn: (builder: EntityBuilder) => EntityBuilder): SceneBuilder;
|
|
1654
|
+
/**
|
|
1655
|
+
* 批量添加实体
|
|
1656
|
+
* @param entities 实体数组
|
|
1657
|
+
* @returns 场景构建器
|
|
1658
|
+
*/
|
|
1659
|
+
withEntities(...entities: Entity[]): SceneBuilder;
|
|
1660
|
+
/**
|
|
1661
|
+
* 添加系统
|
|
1662
|
+
* @param system 系统实例
|
|
1663
|
+
* @returns 场景构建器
|
|
1664
|
+
*/
|
|
1665
|
+
withSystem(system: any): SceneBuilder;
|
|
1666
|
+
/**
|
|
1667
|
+
* 批量添加系统
|
|
1668
|
+
* @param systems 系统数组
|
|
1669
|
+
* @returns 场景构建器
|
|
1670
|
+
*/
|
|
1671
|
+
withSystems(...systems: any[]): SceneBuilder;
|
|
1672
|
+
/**
|
|
1673
|
+
* 构建并返回场景
|
|
1674
|
+
* @returns 构建的场景
|
|
1675
|
+
*/
|
|
1676
|
+
build(): Scene;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
export declare class ComponentBuilder<T extends Component> {
|
|
1680
|
+
private component;
|
|
1681
|
+
constructor(componentClass: new (...args: any[]) => T, ...args: any[]);
|
|
1682
|
+
/**
|
|
1683
|
+
* 设置组件属性
|
|
1684
|
+
* @param property 属性名
|
|
1685
|
+
* @param value 属性值
|
|
1686
|
+
* @returns 组件构建器
|
|
1687
|
+
*/
|
|
1688
|
+
set<K extends keyof T>(property: K, value: T[K]): ComponentBuilder<T>;
|
|
1689
|
+
/**
|
|
1690
|
+
* 使用配置函数设置组件
|
|
1691
|
+
* @param configurator 配置函数
|
|
1692
|
+
* @returns 组件构建器
|
|
1693
|
+
*/
|
|
1694
|
+
configure(configurator: (component: T) => void): ComponentBuilder<T>;
|
|
1695
|
+
/**
|
|
1696
|
+
* 条件性设置属性
|
|
1697
|
+
* @param condition 条件
|
|
1698
|
+
* @param property 属性名
|
|
1699
|
+
* @param value 属性值
|
|
1700
|
+
* @returns 组件构建器
|
|
1701
|
+
*/
|
|
1702
|
+
setIf<K extends keyof T>(condition: boolean, property: K, value: T[K]): ComponentBuilder<T>;
|
|
1703
|
+
/**
|
|
1704
|
+
* 构建并返回组件
|
|
1705
|
+
* @returns 构建的组件
|
|
1706
|
+
*/
|
|
1707
|
+
build(): T;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
export declare class ECSFluentAPI {
|
|
1711
|
+
private scene;
|
|
1712
|
+
private querySystem;
|
|
1713
|
+
private eventSystem;
|
|
1714
|
+
constructor(scene: Scene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem);
|
|
1715
|
+
/**
|
|
1716
|
+
* 创建实体构建器
|
|
1717
|
+
* @returns 实体构建器
|
|
1718
|
+
*/
|
|
1719
|
+
createEntity(): EntityBuilder;
|
|
1720
|
+
/**
|
|
1721
|
+
* 创建场景构建器
|
|
1722
|
+
* @returns 场景构建器
|
|
1723
|
+
*/
|
|
1724
|
+
createScene(): SceneBuilder;
|
|
1725
|
+
/**
|
|
1726
|
+
* 创建组件构建器
|
|
1727
|
+
* @param componentClass 组件类
|
|
1728
|
+
* @param args 构造参数
|
|
1729
|
+
* @returns 组件构建器
|
|
1730
|
+
*/
|
|
1731
|
+
createComponent<T extends Component>(componentClass: new (...args: any[]) => T, ...args: any[]): ComponentBuilder<T>;
|
|
1732
|
+
/**
|
|
1733
|
+
* 创建查询构建器
|
|
1734
|
+
* @returns 查询构建器
|
|
1735
|
+
*/
|
|
1736
|
+
query(): QueryBuilder;
|
|
1737
|
+
/**
|
|
1738
|
+
* 查找实体(简化版)
|
|
1739
|
+
* @param componentTypes 组件类型
|
|
1740
|
+
* @returns 实体数组
|
|
1741
|
+
*/
|
|
1742
|
+
find(...componentTypes: ComponentType[]): Entity[];
|
|
1743
|
+
/**
|
|
1744
|
+
* 查找第一个匹配的实体
|
|
1745
|
+
* @param componentTypes 组件类型
|
|
1746
|
+
* @returns 实体或null
|
|
1747
|
+
*/
|
|
1748
|
+
findFirst(...componentTypes: ComponentType[]): Entity | null;
|
|
1749
|
+
/**
|
|
1750
|
+
* 按名称查找实体
|
|
1751
|
+
* @param name 实体名称
|
|
1752
|
+
* @returns 实体或null
|
|
1753
|
+
*/
|
|
1754
|
+
findByName(name: string): Entity | null;
|
|
1755
|
+
/**
|
|
1756
|
+
* 按标签查找实体
|
|
1757
|
+
* @param tag 标签
|
|
1758
|
+
* @returns 实体数组
|
|
1759
|
+
*/
|
|
1760
|
+
findByTag(tag: number): Entity[];
|
|
1761
|
+
/**
|
|
1762
|
+
* 触发事件
|
|
1763
|
+
* @param eventType 事件类型
|
|
1764
|
+
* @param event 事件数据
|
|
1765
|
+
*/
|
|
1766
|
+
emit<T>(eventType: string, event: T): void;
|
|
1767
|
+
/**
|
|
1768
|
+
* 异步触发事件
|
|
1769
|
+
* @param eventType 事件类型
|
|
1770
|
+
* @param event 事件数据
|
|
1771
|
+
*/
|
|
1772
|
+
emitAsync<T>(eventType: string, event: T): Promise<void>;
|
|
1773
|
+
/**
|
|
1774
|
+
* 监听事件
|
|
1775
|
+
* @param eventType 事件类型
|
|
1776
|
+
* @param handler 事件处理器
|
|
1777
|
+
* @returns 监听器ID
|
|
1778
|
+
*/
|
|
1779
|
+
on<T>(eventType: string, handler: (event: T) => void): string;
|
|
1780
|
+
/**
|
|
1781
|
+
* 一次性监听事件
|
|
1782
|
+
* @param eventType 事件类型
|
|
1783
|
+
* @param handler 事件处理器
|
|
1784
|
+
* @returns 监听器ID
|
|
1785
|
+
*/
|
|
1786
|
+
once<T>(eventType: string, handler: (event: T) => void): string;
|
|
1787
|
+
/**
|
|
1788
|
+
* 移除事件监听器
|
|
1789
|
+
* @param eventType 事件类型
|
|
1790
|
+
* @param listenerId 监听器ID
|
|
1791
|
+
*/
|
|
1792
|
+
off(eventType: string, listenerId: string): void;
|
|
1793
|
+
/**
|
|
1794
|
+
* 批量操作实体
|
|
1795
|
+
* @param entities 实体数组
|
|
1796
|
+
* @returns 批量操作器
|
|
1797
|
+
*/
|
|
1798
|
+
batch(entities: Entity[]): EntityBatchOperator;
|
|
1799
|
+
/**
|
|
1800
|
+
* 获取场景统计信息
|
|
1801
|
+
* @returns 统计信息
|
|
1802
|
+
*/
|
|
1803
|
+
getStats(): {
|
|
1804
|
+
entityCount: number;
|
|
1805
|
+
systemCount: number;
|
|
1806
|
+
componentStats: Map<string, any>;
|
|
1807
|
+
queryStats: any;
|
|
1808
|
+
eventStats: Map<string, any>;
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
export declare class EntityBatchOperator {
|
|
1812
|
+
private entities;
|
|
1813
|
+
constructor(entities: Entity[]);
|
|
1814
|
+
/**
|
|
1815
|
+
* 批量添加组件
|
|
1816
|
+
* @param component 组件实例
|
|
1817
|
+
* @returns 批量操作器
|
|
1818
|
+
*/
|
|
1819
|
+
addComponent<T extends Component>(component: T): EntityBatchOperator;
|
|
1820
|
+
/**
|
|
1821
|
+
* 批量移除组件
|
|
1822
|
+
* @param componentType 组件类型
|
|
1823
|
+
* @returns 批量操作器
|
|
1824
|
+
*/
|
|
1825
|
+
removeComponent<T extends Component>(componentType: ComponentType<T>): EntityBatchOperator;
|
|
1826
|
+
/**
|
|
1827
|
+
* 批量设置活跃状态
|
|
1828
|
+
* @param active 是否活跃
|
|
1829
|
+
* @returns 批量操作器
|
|
1830
|
+
*/
|
|
1831
|
+
setActive(active: boolean): EntityBatchOperator;
|
|
1832
|
+
/**
|
|
1833
|
+
* 批量设置标签
|
|
1834
|
+
* @param tag 标签
|
|
1835
|
+
* @returns 批量操作器
|
|
1836
|
+
*/
|
|
1837
|
+
setTag(tag: number): EntityBatchOperator;
|
|
1838
|
+
/**
|
|
1839
|
+
* 批量执行操作
|
|
1840
|
+
* @param operation 操作函数
|
|
1841
|
+
* @returns 批量操作器
|
|
1842
|
+
*/
|
|
1843
|
+
forEach(operation: (entity: Entity, index: number) => void): EntityBatchOperator;
|
|
1844
|
+
/**
|
|
1845
|
+
* 过滤实体
|
|
1846
|
+
* @param predicate 过滤条件
|
|
1847
|
+
* @returns 新的批量操作器
|
|
1848
|
+
*/
|
|
1849
|
+
filter(predicate: (entity: Entity) => boolean): EntityBatchOperator;
|
|
1850
|
+
/**
|
|
1851
|
+
* 获取实体数组
|
|
1852
|
+
* @returns 实体数组
|
|
1853
|
+
*/
|
|
1854
|
+
toArray(): Entity[];
|
|
1855
|
+
/**
|
|
1856
|
+
* 获取实体数量
|
|
1857
|
+
* @returns 实体数量
|
|
1858
|
+
*/
|
|
1859
|
+
count(): number;
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
export declare enum IndexUpdateType {
|
|
1863
|
+
ADD_ENTITY = "add_entity",
|
|
1864
|
+
REMOVE_ENTITY = "remove_entity",
|
|
1865
|
+
UPDATE_ENTITY = "update_entity"
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
export interface IndexUpdateOperation {
|
|
1869
|
+
type: IndexUpdateType;
|
|
1870
|
+
entity: Entity;
|
|
1871
|
+
oldMask?: bigint;
|
|
1872
|
+
newMask?: bigint;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
export declare class IndexUpdateBatcher {
|
|
1876
|
+
private pendingOperations;
|
|
1877
|
+
private isProcessing;
|
|
1878
|
+
private batchSize;
|
|
1879
|
+
private flushTimeout;
|
|
1880
|
+
private flushDelay;
|
|
1881
|
+
/**
|
|
1882
|
+
* 添加索引更新操作
|
|
1883
|
+
*/
|
|
1884
|
+
addOperation(operation: IndexUpdateOperation): void;
|
|
1885
|
+
/**
|
|
1886
|
+
* 批量添加实体
|
|
1887
|
+
*/
|
|
1888
|
+
addEntities(entities: Entity[]): void;
|
|
1889
|
+
/**
|
|
1890
|
+
* 批量移除实体
|
|
1891
|
+
*/
|
|
1892
|
+
removeEntities(entities: Entity[]): void;
|
|
1893
|
+
/**
|
|
1894
|
+
* 批量更新实体
|
|
1895
|
+
*/
|
|
1896
|
+
updateEntities(updates: Array<{
|
|
1897
|
+
entity: Entity;
|
|
1898
|
+
oldMask: bigint;
|
|
1899
|
+
newMask: bigint;
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
export declare enum QueryConditionType {
|
|
1903
|
+
/** 必须包含所有指定组件 */
|
|
1904
|
+
ALL = "all",
|
|
1905
|
+
/** 必须包含任意一个指定组件 */
|
|
1906
|
+
ANY = "any",
|
|
1907
|
+
/** 不能包含任何指定组件 */
|
|
1908
|
+
NONE = "none"
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
export interface QueryCondition {
|
|
1912
|
+
type: QueryConditionType;
|
|
1913
|
+
componentTypes: ComponentType[];
|
|
1914
|
+
mask: bigint;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
export interface QueryResult {
|
|
1918
|
+
entities: Entity[];
|
|
1919
|
+
count: number;
|
|
1920
|
+
/** 查询执行时间(毫秒) */
|
|
1921
|
+
executionTime: number;
|
|
1922
|
+
/** 是否来自缓存 */
|
|
1923
|
+
fromCache: boolean;
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
export declare class QuerySystem {
|
|
1927
|
+
private entities;
|
|
1928
|
+
private wasmAvailable;
|
|
1929
|
+
private entityIndex;
|
|
1930
|
+
private indexDirty;
|
|
1931
|
+
private queryCache;
|
|
1932
|
+
private cacheMaxSize;
|
|
1933
|
+
private cacheTimeout;
|
|
1934
|
+
private componentPoolManager;
|
|
1935
|
+
private bitMaskOptimizer;
|
|
1936
|
+
private indexUpdateBatcher;
|
|
1937
|
+
private componentIndexManager;
|
|
1938
|
+
private archetypeSystem;
|
|
1939
|
+
private dirtyTrackingSystem;
|
|
1940
|
+
private queryStats;
|
|
1941
|
+
constructor();
|
|
1942
|
+
/**
|
|
1943
|
+
* 初始化WebAssembly支持
|
|
1944
|
+
*
|
|
1945
|
+
* 自动检测运行环境并启用WebAssembly计算加速。
|
|
1946
|
+
* 如果WebAssembly不可用,系统将自动回退到JavaScript实现。
|
|
1947
|
+
*/
|
|
1948
|
+
private initializeWasm;
|
|
1949
|
+
/**
|
|
1950
|
+
* 设置实体列表并重建索引
|
|
1951
|
+
*
|
|
1952
|
+
* 当实体集合发生大规模变化时调用此方法。
|
|
1953
|
+
* 系统将重新构建所有索引以确保查询性能。
|
|
1954
|
+
*
|
|
1955
|
+
* @param entities 新的实体列表
|
|
1956
|
+
*/
|
|
1957
|
+
setEntities(entities: Entity[]): void;
|
|
1958
|
+
/**
|
|
1959
|
+
* 添加单个实体到查询系统
|
|
1960
|
+
*
|
|
1961
|
+
* 将新实体添加到查询系统中,并自动更新相关索引。
|
|
1962
|
+
* 为了提高批量添加性能,可以延迟缓存清理。
|
|
1963
|
+
*
|
|
1964
|
+
* @param entity 要添加的实体
|
|
1965
|
+
* @param deferCacheClear 是否延迟缓存清理(用于批量操作)
|
|
1966
|
+
*/
|
|
1967
|
+
addEntity(entity: Entity, deferCacheClear?: boolean): void;
|
|
1968
|
+
/**
|
|
1969
|
+
* 批量添加实体
|
|
1970
|
+
*
|
|
1971
|
+
* 高效地批量添加多个实体,减少缓存清理次数。
|
|
1972
|
+
* 使用Set来避免O(n)的重复检查。
|
|
1973
|
+
*
|
|
1974
|
+
* @param entities 要添加的实体列表
|
|
1975
|
+
*/
|
|
1976
|
+
addEntities(entities: Entity[]): void;
|
|
1977
|
+
/**
|
|
1978
|
+
* 批量添加实体(无重复检查版本)
|
|
1979
|
+
*
|
|
1980
|
+
* 假设所有实体都是新的,跳过重复检查以获得最大性能。
|
|
1981
|
+
* 仅在确保没有重复实体时使用。
|
|
1982
|
+
*
|
|
1983
|
+
* @param entities 要添加的实体列表
|
|
1984
|
+
*/
|
|
1985
|
+
addEntitiesUnchecked(entities: Entity[]): void;
|
|
1986
|
+
/**
|
|
1987
|
+
* 从查询系统移除实体
|
|
1988
|
+
*
|
|
1989
|
+
* 从查询系统中移除指定实体,并清理相关索引。
|
|
1990
|
+
*
|
|
1991
|
+
* @param entity 要移除的实体
|
|
1992
|
+
*/
|
|
1993
|
+
removeEntity(entity: Entity): void;
|
|
1994
|
+
/**
|
|
1995
|
+
* 将实体添加到各种索引中(优化版本)
|
|
1996
|
+
*/
|
|
1997
|
+
private addEntityToIndexes;
|
|
1998
|
+
/**
|
|
1999
|
+
* 从各种索引中移除实体
|
|
2000
|
+
*/
|
|
2001
|
+
private removeEntityFromIndexes;
|
|
2002
|
+
/**
|
|
2003
|
+
* 重建所有索引
|
|
2004
|
+
*
|
|
2005
|
+
* 清空并重新构建所有查询索引。
|
|
2006
|
+
* 通常在大量实体变更后调用以确保索引一致性。
|
|
2007
|
+
*/
|
|
2008
|
+
private rebuildIndexes;
|
|
2009
|
+
/**
|
|
2010
|
+
* 查询包含所有指定组件的实体
|
|
2011
|
+
*
|
|
2012
|
+
* 返回同时包含所有指定组件类型的实体列表。
|
|
2013
|
+
* 系统会自动选择最高效的查询策略,包括索引查找和缓存机制。
|
|
2014
|
+
*
|
|
2015
|
+
* @param componentTypes 要查询的组件类型列表
|
|
2016
|
+
* @returns 查询结果,包含匹配的实体和性能信息
|
|
2017
|
+
*
|
|
2018
|
+
* @example
|
|
2019
|
+
* ```typescript
|
|
2020
|
+
* // 查询同时具有位置和速度组件的实体
|
|
2021
|
+
* const result = querySystem.queryAll(PositionComponent, VelocityComponent);
|
|
2022
|
+
* console.log(`找到 ${result.count}
|
|
2023
|
+
|
|
2024
|
+
export declare class QueryBuilder {
|
|
2025
|
+
private conditions;
|
|
2026
|
+
private querySystem;
|
|
2027
|
+
constructor(querySystem: QuerySystem);
|
|
2028
|
+
/**
|
|
2029
|
+
* 添加"必须包含所有组件"条件
|
|
2030
|
+
*
|
|
2031
|
+
* @param componentTypes 必须包含的组件类型
|
|
2032
|
+
* @returns 查询构建器实例,支持链式调用
|
|
2033
|
+
*/
|
|
2034
|
+
withAll(...componentTypes: ComponentType[]): QueryBuilder;
|
|
2035
|
+
/**
|
|
2036
|
+
* 添加"必须包含任意组件"条件
|
|
2037
|
+
*
|
|
2038
|
+
* @param componentTypes 必须包含其中任意一个的组件类型
|
|
2039
|
+
* @returns 查询构建器实例,支持链式调用
|
|
2040
|
+
*/
|
|
2041
|
+
withAny(...componentTypes: ComponentType[]): QueryBuilder;
|
|
2042
|
+
/**
|
|
2043
|
+
* 添加"不能包含任何组件"条件
|
|
2044
|
+
*
|
|
2045
|
+
* @param componentTypes 不能包含的组件类型
|
|
2046
|
+
* @returns 查询构建器实例,支持链式调用
|
|
2047
|
+
*/
|
|
2048
|
+
without(...componentTypes: ComponentType[]): QueryBuilder;
|
|
2049
|
+
/**
|
|
2050
|
+
* 执行查询并返回结果
|
|
2051
|
+
*
|
|
2052
|
+
* 根据已添加的查询条件执行实体查询。
|
|
2053
|
+
*
|
|
2054
|
+
* @returns 查询结果,包含匹配的实体和性能信息
|
|
2055
|
+
*/
|
|
2056
|
+
execute(): QueryResult;
|
|
2057
|
+
/**
|
|
2058
|
+
* 创建组件掩码
|
|
2059
|
+
*/
|
|
2060
|
+
private createComponentMask;
|
|
2061
|
+
/**
|
|
2062
|
+
* 重置查询构建器
|
|
2063
|
+
*
|
|
2064
|
+
* 清除所有已添加的查询条件,重新开始构建查询。
|
|
2065
|
+
*
|
|
2066
|
+
* @returns 查询构建器实例,支持链式调用
|
|
2067
|
+
*/
|
|
2068
|
+
reset(): QueryBuilder;
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
export declare enum CoreEvents {
|
|
2072
|
+
/**
|
|
2073
|
+
* 当场景发生变化时触发
|
|
2074
|
+
*/
|
|
2075
|
+
sceneChanged = 0,
|
|
2076
|
+
/**
|
|
2077
|
+
* 每帧更新事件
|
|
2078
|
+
*/
|
|
2079
|
+
frameUpdated = 1,
|
|
2080
|
+
/**
|
|
2081
|
+
* 当渲染发生时触发
|
|
2082
|
+
*/
|
|
2083
|
+
renderChanged = 2
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
export declare enum ECSEventType {
|
|
2087
|
+
ENTITY_CREATED = "entity:created",
|
|
2088
|
+
ENTITY_DESTROYED = "entity:destroyed",
|
|
2089
|
+
ENTITY_ENABLED = "entity:enabled",
|
|
2090
|
+
ENTITY_DISABLED = "entity:disabled",
|
|
2091
|
+
ENTITY_TAG_ADDED = "entity:tag:added",
|
|
2092
|
+
ENTITY_TAG_REMOVED = "entity:tag:removed",
|
|
2093
|
+
ENTITY_NAME_CHANGED = "entity:name:changed",
|
|
2094
|
+
COMPONENT_ADDED = "component:added",
|
|
2095
|
+
COMPONENT_REMOVED = "component:removed",
|
|
2096
|
+
COMPONENT_MODIFIED = "component:modified",
|
|
2097
|
+
COMPONENT_ENABLED = "component:enabled",
|
|
2098
|
+
COMPONENT_DISABLED = "component:disabled",
|
|
2099
|
+
SYSTEM_ADDED = "system:added",
|
|
2100
|
+
SYSTEM_REMOVED = "system:removed",
|
|
2101
|
+
SYSTEM_ENABLED = "system:enabled",
|
|
2102
|
+
SYSTEM_DISABLED = "system:disabled",
|
|
2103
|
+
SYSTEM_PROCESSING_START = "system:processing:start",
|
|
2104
|
+
SYSTEM_PROCESSING_END = "system:processing:end",
|
|
2105
|
+
SYSTEM_ERROR = "system:error",
|
|
2106
|
+
SCENE_CREATED = "scene:created",
|
|
2107
|
+
SCENE_DESTROYED = "scene:destroyed",
|
|
2108
|
+
SCENE_ACTIVATED = "scene:activated",
|
|
2109
|
+
SCENE_DEACTIVATED = "scene:deactivated",
|
|
2110
|
+
SCENE_PAUSED = "scene:paused",
|
|
2111
|
+
SCENE_RESUMED = "scene:resumed",
|
|
2112
|
+
QUERY_EXECUTED = "query:executed",
|
|
2113
|
+
QUERY_CACHE_HIT = "query:cache:hit",
|
|
2114
|
+
QUERY_CACHE_MISS = "query:cache:miss",
|
|
2115
|
+
QUERY_OPTIMIZED = "query:optimized",
|
|
2116
|
+
PERFORMANCE_WARNING = "performance:warning",
|
|
2117
|
+
PERFORMANCE_CRITICAL = "performance:critical",
|
|
2118
|
+
MEMORY_USAGE_HIGH = "memory:usage:high",
|
|
2119
|
+
FRAME_RATE_DROP = "frame:rate:drop",
|
|
2120
|
+
INDEX_CREATED = "index:created",
|
|
2121
|
+
INDEX_UPDATED = "index:updated",
|
|
2122
|
+
INDEX_OPTIMIZED = "index:optimized",
|
|
2123
|
+
ARCHETYPE_CREATED = "archetype:created",
|
|
2124
|
+
ARCHETYPE_ENTITY_ADDED = "archetype:entity:added",
|
|
2125
|
+
ARCHETYPE_ENTITY_REMOVED = "archetype:entity:removed",
|
|
2126
|
+
DIRTY_MARK_ADDED = "dirty:mark:added",
|
|
2127
|
+
DIRTY_BATCH_PROCESSED = "dirty:batch:processed",
|
|
2128
|
+
ERROR_OCCURRED = "error:occurred",
|
|
2129
|
+
WARNING_ISSUED = "warning:issued",
|
|
2130
|
+
FRAMEWORK_INITIALIZED = "framework:initialized",
|
|
2131
|
+
FRAMEWORK_SHUTDOWN = "framework:shutdown",
|
|
2132
|
+
DEBUG_INFO = "debug:info",
|
|
2133
|
+
DEBUG_STATS_UPDATED = "debug:stats:updated"
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
export declare enum EventPriority {
|
|
2137
|
+
LOWEST = 0,
|
|
2138
|
+
LOW = 25,
|
|
2139
|
+
NORMAL = 50,
|
|
2140
|
+
HIGH = 75,
|
|
2141
|
+
HIGHEST = 100,
|
|
2142
|
+
CRITICAL = 200
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
export declare const EVENT_TYPES: {
|
|
2146
|
+
readonly CORE: {
|
|
2147
|
+
readonly SCENE_CHANGED: "core:scene:changed";
|
|
2148
|
+
readonly FRAME_UPDATED: "core:frame:updated";
|
|
2149
|
+
readonly RENDER_CHANGED: "core:render:changed";
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
export declare class EventTypeValidator {
|
|
2153
|
+
private static validTypes;
|
|
2154
|
+
/**
|
|
2155
|
+
* 验证事件类型是否有效
|
|
2156
|
+
* @param eventType 事件类型
|
|
2157
|
+
* @returns 是否有效
|
|
2158
|
+
*/
|
|
2159
|
+
static isValid(eventType: string): boolean;
|
|
2160
|
+
/**
|
|
2161
|
+
* 获取所有有效的事件类型
|
|
2162
|
+
* @returns 事件类型数组
|
|
2163
|
+
*/
|
|
2164
|
+
static getAllValidTypes(): string[];
|
|
2165
|
+
/**
|
|
2166
|
+
* 添加自定义事件类型
|
|
2167
|
+
* @param eventType 事件类型
|
|
2168
|
+
*/
|
|
2169
|
+
static addCustomType(eventType: string): void;
|
|
2170
|
+
/**
|
|
2171
|
+
* 移除自定义事件类型
|
|
2172
|
+
* @param eventType 事件类型
|
|
2173
|
+
*/
|
|
2174
|
+
static removeCustomType(eventType: string): void;
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
export declare class EntityComparer {
|
|
2178
|
+
/**
|
|
2179
|
+
* 比较两个实体
|
|
2180
|
+
*
|
|
2181
|
+
* @param self - 第一个实体
|
|
2182
|
+
* @param other - 第二个实体
|
|
2183
|
+
* @returns 比较结果,负数表示self优先级更高,正数表示other优先级更高,0表示相等
|
|
2184
|
+
*/
|
|
2185
|
+
compare(self: Entity, other: Entity): number;
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
export declare class Entity {
|
|
2189
|
+
/**
|
|
2190
|
+
* 实体比较器实例
|
|
2191
|
+
*/
|
|
2192
|
+
static entityComparer: EntityComparer;
|
|
2193
|
+
/**
|
|
2194
|
+
* 全局事件总线实例
|
|
2195
|
+
* 用于发射组件相关事件
|
|
2196
|
+
*/
|
|
2197
|
+
static eventBus: EventBus | null;
|
|
2198
|
+
/**
|
|
2199
|
+
* 实体名称
|
|
2200
|
+
*
|
|
2201
|
+
* 用于标识和调试的友好名称。
|
|
2202
|
+
*/
|
|
2203
|
+
name: string;
|
|
2204
|
+
/**
|
|
2205
|
+
* 实体唯一标识符
|
|
2206
|
+
*
|
|
2207
|
+
* 在场景中唯一的数字标识符。
|
|
2208
|
+
*/
|
|
2209
|
+
readonly id: number;
|
|
2210
|
+
/**
|
|
2211
|
+
* 组件集合
|
|
2212
|
+
*
|
|
2213
|
+
* 存储实体拥有的所有组件。
|
|
2214
|
+
*/
|
|
2215
|
+
readonly components: Component[];
|
|
2216
|
+
/**
|
|
2217
|
+
* 所属场景引用
|
|
2218
|
+
*
|
|
2219
|
+
* 指向实体所在的场景实例。
|
|
2220
|
+
*/
|
|
2221
|
+
scene: any;
|
|
2222
|
+
/**
|
|
2223
|
+
* 更新间隔
|
|
2224
|
+
*
|
|
2225
|
+
* 控制实体更新的频率,值越大更新越不频繁。
|
|
2226
|
+
*/
|
|
2227
|
+
updateInterval: number;
|
|
2228
|
+
/**
|
|
2229
|
+
* 销毁状态标志
|
|
2230
|
+
*
|
|
2231
|
+
* 标记实体是否已被销毁。
|
|
2232
|
+
*/
|
|
2233
|
+
_isDestroyed: boolean;
|
|
2234
|
+
/**
|
|
2235
|
+
* 父实体引用
|
|
2236
|
+
*
|
|
2237
|
+
* 指向父级实体,用于构建实体层次结构。
|
|
2238
|
+
*/
|
|
2239
|
+
private _parent;
|
|
2240
|
+
/**
|
|
2241
|
+
* 子实体集合
|
|
2242
|
+
*
|
|
2243
|
+
* 存储所有子级实体的数组。
|
|
2244
|
+
*/
|
|
2245
|
+
private _children;
|
|
2246
|
+
/**
|
|
2247
|
+
* 激活状态
|
|
2248
|
+
*
|
|
2249
|
+
* 控制实体是否处于激活状态。
|
|
2250
|
+
*/
|
|
2251
|
+
private _active;
|
|
2252
|
+
/**
|
|
2253
|
+
* 实体标签
|
|
2254
|
+
*
|
|
2255
|
+
* 用于分类和查询的数字标签。
|
|
2256
|
+
*/
|
|
2257
|
+
private _tag;
|
|
2258
|
+
/**
|
|
2259
|
+
* 启用状态
|
|
2260
|
+
*
|
|
2261
|
+
* 控制实体是否启用更新和处理。
|
|
2262
|
+
*/
|
|
2263
|
+
private _enabled;
|
|
2264
|
+
/**
|
|
2265
|
+
* 更新顺序
|
|
2266
|
+
*
|
|
2267
|
+
* 控制实体在系统中的更新优先级。
|
|
2268
|
+
*/
|
|
2269
|
+
private _updateOrder;
|
|
2270
|
+
/**
|
|
2271
|
+
* 组件位掩码
|
|
2272
|
+
*
|
|
2273
|
+
* 用于快速查询实体拥有的组件类型。
|
|
2274
|
+
*/
|
|
2275
|
+
private _componentMask;
|
|
2276
|
+
/**
|
|
2277
|
+
* 组件类型到索引的映射
|
|
2278
|
+
*
|
|
2279
|
+
* 用于快速定位组件在数组中的位置。
|
|
2280
|
+
*/
|
|
2281
|
+
private _componentTypeToIndex;
|
|
2282
|
+
/**
|
|
2283
|
+
* 组件缓存
|
|
2284
|
+
*
|
|
2285
|
+
* 高性能组件访问缓存。
|
|
2286
|
+
*/
|
|
2287
|
+
private _componentCache;
|
|
2288
|
+
/**
|
|
2289
|
+
* 组件访问统计
|
|
2290
|
+
*
|
|
2291
|
+
* 记录组件访问的性能统计信息。
|
|
2292
|
+
*/
|
|
2293
|
+
private _componentAccessStats;
|
|
2294
|
+
/**
|
|
2295
|
+
* 构造函数
|
|
2296
|
+
*
|
|
2297
|
+
* @param name - 实体名称
|
|
2298
|
+
* @param id - 实体唯一标识符
|
|
2299
|
+
*/
|
|
2300
|
+
constructor(name: string, id: number);
|
|
2301
|
+
/**
|
|
2302
|
+
* 获取销毁状态
|
|
2303
|
+
*
|
|
2304
|
+
* @returns 如果实体已被销毁则返回true
|
|
2305
|
+
*/
|
|
2306
|
+
get isDestroyed(): boolean;
|
|
2307
|
+
/**
|
|
2308
|
+
* 获取父实体
|
|
2309
|
+
*
|
|
2310
|
+
* @returns 父实体,如果没有父实体则返回null
|
|
2311
|
+
*/
|
|
2312
|
+
get parent(): Entity | null;
|
|
2313
|
+
/**
|
|
2314
|
+
* 获取子实体数组的只读副本
|
|
2315
|
+
*
|
|
2316
|
+
* @returns 子实体数组的副本
|
|
2317
|
+
*/
|
|
2318
|
+
get children(): readonly Entity[];
|
|
2319
|
+
/**
|
|
2320
|
+
* 获取子实体数量
|
|
2321
|
+
*
|
|
2322
|
+
* @returns 子实体的数量
|
|
2323
|
+
*/
|
|
2324
|
+
get childCount(): number;
|
|
2325
|
+
/**
|
|
2326
|
+
* 获取活跃状态
|
|
2327
|
+
*
|
|
2328
|
+
* @returns 如果实体处于活跃状态则返回true
|
|
2329
|
+
*/
|
|
2330
|
+
get active(): boolean;
|
|
2331
|
+
/**
|
|
2332
|
+
* 设置活跃状态
|
|
2333
|
+
*
|
|
2334
|
+
* 设置实体的活跃状态,会影响子实体的有效活跃状态。
|
|
2335
|
+
*
|
|
2336
|
+
* @param value - 新的活跃状态
|
|
2337
|
+
*/
|
|
2338
|
+
set active(value: boolean);
|
|
2339
|
+
/**
|
|
2340
|
+
* 获取实体的有效活跃状态
|
|
2341
|
+
*
|
|
2342
|
+
* 考虑父实体的活跃状态,只有当实体本身和所有父实体都处于活跃状态时才返回true。
|
|
2343
|
+
*
|
|
2344
|
+
* @returns 有效的活跃状态
|
|
2345
|
+
*/
|
|
2346
|
+
get activeInHierarchy(): boolean;
|
|
2347
|
+
/**
|
|
2348
|
+
* 获取实体标签
|
|
2349
|
+
*
|
|
2350
|
+
* @returns 实体的数字标签
|
|
2351
|
+
*/
|
|
2352
|
+
get tag(): number;
|
|
2353
|
+
/**
|
|
2354
|
+
* 设置实体标签
|
|
2355
|
+
*
|
|
2356
|
+
* @param value - 新的标签值
|
|
2357
|
+
*/
|
|
2358
|
+
set tag(value: number);
|
|
2359
|
+
/**
|
|
2360
|
+
* 获取启用状态
|
|
2361
|
+
*
|
|
2362
|
+
* @returns 如果实体已启用则返回true
|
|
2363
|
+
*/
|
|
2364
|
+
get enabled(): boolean;
|
|
2365
|
+
/**
|
|
2366
|
+
* 设置启用状态
|
|
2367
|
+
*
|
|
2368
|
+
* @param value - 新的启用状态
|
|
2369
|
+
*/
|
|
2370
|
+
set enabled(value: boolean);
|
|
2371
|
+
/**
|
|
2372
|
+
* 获取更新顺序
|
|
2373
|
+
*
|
|
2374
|
+
* @returns 实体的更新顺序值
|
|
2375
|
+
*/
|
|
2376
|
+
get updateOrder(): number;
|
|
2377
|
+
/**
|
|
2378
|
+
* 设置更新顺序
|
|
2379
|
+
*
|
|
2380
|
+
* @param value - 新的更新顺序值
|
|
2381
|
+
*/
|
|
2382
|
+
set updateOrder(value: number);
|
|
2383
|
+
/**
|
|
2384
|
+
* 获取组件位掩码
|
|
2385
|
+
*
|
|
2386
|
+
* @returns 实体的组件位掩码
|
|
2387
|
+
*/
|
|
2388
|
+
get componentMask(): bigint;
|
|
2389
|
+
/**
|
|
2390
|
+
* 创建并添加组件
|
|
2391
|
+
*
|
|
2392
|
+
* @param componentType - 组件类型
|
|
2393
|
+
* @param args - 组件构造函数参数
|
|
2394
|
+
* @returns 创建的组件实例
|
|
2395
|
+
*/
|
|
2396
|
+
createComponent<T extends Component>(componentType: ComponentType<T>, ...args: any[]): T;
|
|
2397
|
+
/**
|
|
2398
|
+
* 内部添加组件方法(不进行重复检查,用于初始化)
|
|
2399
|
+
*
|
|
2400
|
+
* @param component - 要添加的组件实例
|
|
2401
|
+
* @returns 添加的组件实例
|
|
2402
|
+
*/
|
|
2403
|
+
private addComponentInternal;
|
|
2404
|
+
/**
|
|
2405
|
+
* 添加组件到实体
|
|
2406
|
+
*
|
|
2407
|
+
* @param component - 要添加的组件实例
|
|
2408
|
+
* @returns 添加的组件实例
|
|
2409
|
+
* @throws {Error}
|
|
2410
|
+
|
|
2411
|
+
export declare class Scene {
|
|
2412
|
+
/**
|
|
2413
|
+
* 场景名称
|
|
2414
|
+
*
|
|
2415
|
+
* 用于标识和调试的友好名称。
|
|
2416
|
+
*/
|
|
2417
|
+
name: string;
|
|
2418
|
+
/**
|
|
2419
|
+
* 场景中的实体集合
|
|
2420
|
+
*
|
|
2421
|
+
* 管理场景内所有实体的生命周期。
|
|
2422
|
+
*/
|
|
2423
|
+
readonly entities: EntityList;
|
|
2424
|
+
/**
|
|
2425
|
+
* 实体系统处理器集合
|
|
2426
|
+
*
|
|
2427
|
+
* 管理场景内所有实体系统的执行。
|
|
2428
|
+
*/
|
|
2429
|
+
readonly entityProcessors: EntityProcessorList;
|
|
2430
|
+
/**
|
|
2431
|
+
* 实体ID池
|
|
2432
|
+
*
|
|
2433
|
+
* 用于分配和回收实体的唯一标识符。
|
|
2434
|
+
*/
|
|
2435
|
+
readonly identifierPool: IdentifierPool;
|
|
2436
|
+
/**
|
|
2437
|
+
* 组件存储管理器
|
|
2438
|
+
*
|
|
2439
|
+
* 高性能的组件存储和查询系统。
|
|
2440
|
+
*/
|
|
2441
|
+
readonly componentStorageManager: ComponentStorageManager;
|
|
2442
|
+
/**
|
|
2443
|
+
* 查询系统
|
|
2444
|
+
*
|
|
2445
|
+
* 基于位掩码的高性能实体查询系统。
|
|
2446
|
+
*/
|
|
2447
|
+
readonly querySystem: QuerySystem;
|
|
2448
|
+
/**
|
|
2449
|
+
* 事件系统
|
|
2450
|
+
*
|
|
2451
|
+
* 类型安全的事件系统。
|
|
2452
|
+
*/
|
|
2453
|
+
readonly eventSystem: TypeSafeEventSystem;
|
|
2454
|
+
/**
|
|
2455
|
+
* 场景是否已开始运行
|
|
2456
|
+
*/
|
|
2457
|
+
private _didSceneBegin;
|
|
2458
|
+
/**
|
|
2459
|
+
* 获取系统列表(兼容性属性)
|
|
2460
|
+
*/
|
|
2461
|
+
get systems(): EntitySystem[];
|
|
2462
|
+
/**
|
|
2463
|
+
* 创建场景实例
|
|
2464
|
+
* @param enableWasmAcceleration 是否启用WebAssembly加速,默认为true
|
|
2465
|
+
*/
|
|
2466
|
+
constructor(enableWasmAcceleration?: boolean);
|
|
2467
|
+
/**
|
|
2468
|
+
* 初始化场景
|
|
2469
|
+
*
|
|
2470
|
+
* 在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
|
|
2471
|
+
*/
|
|
2472
|
+
initialize(): void;
|
|
2473
|
+
/**
|
|
2474
|
+
* 场景开始运行时的回调
|
|
2475
|
+
*
|
|
2476
|
+
* 在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
|
|
2477
|
+
*/
|
|
2478
|
+
onStart(): void;
|
|
2479
|
+
/**
|
|
2480
|
+
* 场景卸载时的回调
|
|
2481
|
+
*
|
|
2482
|
+
* 在场景被销毁时调用,可以在此方法中执行清理工作。
|
|
2483
|
+
*/
|
|
2484
|
+
unload(): void;
|
|
2485
|
+
/**
|
|
2486
|
+
* 开始场景,启动实体处理器等
|
|
2487
|
+
*
|
|
2488
|
+
* 这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
|
|
2489
|
+
*/
|
|
2490
|
+
begin(): void;
|
|
2491
|
+
/**
|
|
2492
|
+
* 结束场景,清除实体、实体处理器等
|
|
2493
|
+
*
|
|
2494
|
+
* 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
|
|
2495
|
+
*/
|
|
2496
|
+
end(): void;
|
|
2497
|
+
/**
|
|
2498
|
+
* 更新场景,更新实体组件、实体处理器等
|
|
2499
|
+
*/
|
|
2500
|
+
update(): void;
|
|
2501
|
+
/**
|
|
2502
|
+
* 将实体添加到此场景,并返回它
|
|
2503
|
+
* @param name 实体名称
|
|
2504
|
+
*/
|
|
2505
|
+
createEntity(name: string): Entity;
|
|
2506
|
+
/**
|
|
2507
|
+
* 在场景的实体列表中添加一个实体
|
|
2508
|
+
* @param entity 要添加的实体
|
|
2509
|
+
* @param deferCacheClear 是否延迟缓存清理(用于批量操作)
|
|
2510
|
+
*/
|
|
2511
|
+
addEntity(entity: Entity, deferCacheClear?: boolean): Entity;
|
|
2512
|
+
/**
|
|
2513
|
+
* 批量创建实体(高性能版本)
|
|
2514
|
+
* @param count 要创建的实体数量
|
|
2515
|
+
* @param namePrefix 实体名称前缀
|
|
2516
|
+
* @returns 创建的实体列表
|
|
2517
|
+
*/
|
|
2518
|
+
createEntities(count: number, namePrefix?: string): Entity[];
|
|
2519
|
+
/**
|
|
2520
|
+
* 批量创建实体
|
|
2521
|
+
* @param count 要创建的实体数量
|
|
2522
|
+
* @param namePrefix 实体名称前缀
|
|
2523
|
+
* @returns 创建的实体列表
|
|
2524
|
+
*/
|
|
2525
|
+
createEntitiesOld(count: number, namePrefix?: string): Entity[];
|
|
2526
|
+
/**
|
|
2527
|
+
* 从场景中删除所有实体
|
|
2528
|
+
*/
|
|
2529
|
+
destroyAllEntities(): void;
|
|
2530
|
+
/**
|
|
2531
|
+
* 搜索并返回第一个具有名称的实体
|
|
2532
|
+
* @param name 实体名称
|
|
2533
|
+
*/
|
|
2534
|
+
findEntity(name: string): Entity | null;
|
|
2535
|
+
/**
|
|
2536
|
+
* 根据ID查找实体
|
|
2537
|
+
* @param id 实体ID
|
|
2538
|
+
*/
|
|
2539
|
+
findEntityById(id: number): Entity | null;
|
|
2540
|
+
/**
|
|
2541
|
+
* 根据标签查找实体
|
|
2542
|
+
* @param tag 实体标签
|
|
2543
|
+
*/
|
|
2544
|
+
findEntitiesByTag(tag: number): Entity[];
|
|
2545
|
+
/**
|
|
2546
|
+
* 根据名称查找实体(别名方法)
|
|
2547
|
+
* @param name 实体名称
|
|
2548
|
+
*/
|
|
2549
|
+
getEntityByName(name: string): Entity | null;
|
|
2550
|
+
/**
|
|
2551
|
+
* 根据标签查找实体(别名方法)
|
|
2552
|
+
* @param tag 实体标签
|
|
2553
|
+
*/
|
|
2554
|
+
getEntitiesByTag(tag: number): Entity[];
|
|
2555
|
+
/**
|
|
2556
|
+
* 在场景中添加一个EntitySystem处理器
|
|
2557
|
+
* @param processor 处理器
|
|
2558
|
+
*/
|
|
2559
|
+
addEntityProcessor(processor: EntitySystem): EntitySystem;
|
|
2560
|
+
/**
|
|
2561
|
+
* 添加系统到场景(addEntityProcessor的别名)
|
|
2562
|
+
* @param system 系统
|
|
2563
|
+
*/
|
|
2564
|
+
addSystem(system: EntitySystem): EntitySystem;
|
|
2565
|
+
/**
|
|
2566
|
+
* 从场景中删除EntitySystem处理器
|
|
2567
|
+
* @param processor 要删除的处理器
|
|
2568
|
+
*/
|
|
2569
|
+
removeEntityProcessor(processor: EntitySystem): void;
|
|
2570
|
+
/**
|
|
2571
|
+
* 获取指定类型的EntitySystem处理器
|
|
2572
|
+
* @param type 处理器类型
|
|
2573
|
+
*/
|
|
2574
|
+
getEntityProcessor<T extends EntitySystem>(type: new (...args: any[]) => T): T | null;
|
|
2575
|
+
/**
|
|
2576
|
+
* 获取场景统计信息
|
|
2577
|
+
*/
|
|
2578
|
+
getStats(): {
|
|
2579
|
+
entityCount: number;
|
|
2580
|
+
processorCount: number;
|
|
2581
|
+
componentStorageStats: Map<string, any>;
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
export declare class Bits {
|
|
2585
|
+
private _words;
|
|
2586
|
+
private static readonly WORD_SIZE;
|
|
2587
|
+
constructor();
|
|
2588
|
+
/**
|
|
2589
|
+
* 设置指定位置的位为1
|
|
2590
|
+
* @param index 位置索引
|
|
2591
|
+
*/
|
|
2592
|
+
set(index: number): void;
|
|
2593
|
+
/**
|
|
2594
|
+
* 清除指定位置的位(设为0)
|
|
2595
|
+
* @param index 位置索引
|
|
2596
|
+
*/
|
|
2597
|
+
clear(index: number): void;
|
|
2598
|
+
/**
|
|
2599
|
+
* 获取指定位置的位值
|
|
2600
|
+
* @param index 位置索引
|
|
2601
|
+
* @returns 位值(true或false)
|
|
2602
|
+
*/
|
|
2603
|
+
get(index: number): boolean;
|
|
2604
|
+
/**
|
|
2605
|
+
* 检查是否包含所有指定的位
|
|
2606
|
+
* @param other 另一个Bits对象
|
|
2607
|
+
* @returns 如果包含所有位则返回true
|
|
2608
|
+
*/
|
|
2609
|
+
containsAll(other: Bits): boolean;
|
|
2610
|
+
/**
|
|
2611
|
+
* 检查是否包含任意一个指定的位
|
|
2612
|
+
* @param other 另一个Bits对象
|
|
2613
|
+
* @returns 如果包含任意位则返回true
|
|
2614
|
+
*/
|
|
2615
|
+
intersects(other: Bits): boolean;
|
|
2616
|
+
/**
|
|
2617
|
+
* 检查是否不包含任何指定的位
|
|
2618
|
+
* @param other 另一个Bits对象
|
|
2619
|
+
* @returns 如果不包含任何位则返回true
|
|
2620
|
+
*/
|
|
2621
|
+
excludes(other: Bits): boolean;
|
|
2622
|
+
/**
|
|
2623
|
+
* 清空所有位
|
|
2624
|
+
*/
|
|
2625
|
+
clearAll(): void;
|
|
2626
|
+
/**
|
|
2627
|
+
* 检查是否为空(没有设置任何位)
|
|
2628
|
+
* @returns 如果为空则返回true
|
|
2629
|
+
*/
|
|
2630
|
+
isEmpty(): boolean;
|
|
2631
|
+
/**
|
|
2632
|
+
* 获取设置的位数量
|
|
2633
|
+
* @returns 设置的位数量
|
|
2634
|
+
*/
|
|
2635
|
+
cardinality(): number;
|
|
2636
|
+
/**
|
|
2637
|
+
* 计算一个32位整数中设置的位数量
|
|
2638
|
+
* @param n 32位整数
|
|
2639
|
+
* @returns 设置的位数量
|
|
2640
|
+
*/
|
|
2641
|
+
private popCount;
|
|
2642
|
+
/**
|
|
2643
|
+
* 复制另一个Bits对象
|
|
2644
|
+
* @param other 要复制的Bits对象
|
|
2645
|
+
*/
|
|
2646
|
+
copyFrom(other: Bits): void;
|
|
2647
|
+
/**
|
|
2648
|
+
* 创建当前Bits的副本
|
|
2649
|
+
* @returns 新的Bits对象
|
|
2650
|
+
*/
|
|
2651
|
+
clone(): Bits;
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
export declare class ComponentTypeManager {
|
|
2655
|
+
private static _instance;
|
|
2656
|
+
private _componentTypes;
|
|
2657
|
+
private _typeNames;
|
|
2658
|
+
private _nextTypeId;
|
|
2659
|
+
/**
|
|
2660
|
+
* 获取单例实例
|
|
2661
|
+
*/
|
|
2662
|
+
static get instance(): ComponentTypeManager;
|
|
2663
|
+
private constructor();
|
|
2664
|
+
/**
|
|
2665
|
+
* 获取组件类型的ID
|
|
2666
|
+
* @param componentType 组件类型构造函数
|
|
2667
|
+
* @returns 组件类型ID
|
|
2668
|
+
*/
|
|
2669
|
+
getTypeId<T extends Component>(componentType: new (...args: any[]) => T): number;
|
|
2670
|
+
/**
|
|
2671
|
+
* 获取组件类型名称
|
|
2672
|
+
* @param typeId 组件类型ID
|
|
2673
|
+
* @returns 组件类型名称
|
|
2674
|
+
*/
|
|
2675
|
+
getTypeName(typeId: number): string;
|
|
2676
|
+
/**
|
|
2677
|
+
* 创建包含指定组件类型的Bits对象
|
|
2678
|
+
* @param componentTypes 组件类型构造函数数组
|
|
2679
|
+
* @returns Bits对象
|
|
2680
|
+
*/
|
|
2681
|
+
createBits(...componentTypes: (new (...args: any[]) => Component)[]): Bits;
|
|
2682
|
+
/**
|
|
2683
|
+
* 获取实体的组件位掩码
|
|
2684
|
+
* @param components 组件数组
|
|
2685
|
+
* @returns Bits对象
|
|
2686
|
+
*/
|
|
2687
|
+
getEntityBits(components: Component[]): Bits;
|
|
2688
|
+
/**
|
|
2689
|
+
* 重置管理器(主要用于测试)
|
|
2690
|
+
*/
|
|
2691
|
+
reset(): void;
|
|
2692
|
+
/**
|
|
2693
|
+
* 获取已注册的组件类型数量
|
|
2694
|
+
*/
|
|
2695
|
+
get registeredTypeCount(): number;
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
export declare class EntityList {
|
|
2699
|
+
buffer: Entity[];
|
|
2700
|
+
private _scene;
|
|
2701
|
+
private _idToEntity;
|
|
2702
|
+
private _nameToEntities;
|
|
2703
|
+
private _entitiesToAdd;
|
|
2704
|
+
private _entitiesToRemove;
|
|
2705
|
+
private _isUpdating;
|
|
2706
|
+
get count(): number;
|
|
2707
|
+
constructor(scene: any);
|
|
2708
|
+
/**
|
|
2709
|
+
* 添加实体(立即添加或延迟添加)
|
|
2710
|
+
* @param entity 要添加的实体
|
|
2711
|
+
*/
|
|
2712
|
+
add(entity: Entity): void;
|
|
2713
|
+
/**
|
|
2714
|
+
* 立即添加实体
|
|
2715
|
+
* @param entity 要添加的实体
|
|
2716
|
+
*/
|
|
2717
|
+
private addImmediate;
|
|
2718
|
+
/**
|
|
2719
|
+
* 移除实体(立即移除或延迟移除)
|
|
2720
|
+
* @param entity 要移除的实体
|
|
2721
|
+
*/
|
|
2722
|
+
remove(entity: Entity): void;
|
|
2723
|
+
/**
|
|
2724
|
+
* 立即移除实体
|
|
2725
|
+
* @param entity 要移除的实体
|
|
2726
|
+
*/
|
|
2727
|
+
private removeImmediate;
|
|
2728
|
+
/**
|
|
2729
|
+
* 移除所有实体
|
|
2730
|
+
*/
|
|
2731
|
+
removeAllEntities(): void;
|
|
2732
|
+
/**
|
|
2733
|
+
* 更新实体列表,处理延迟操作
|
|
2734
|
+
*/
|
|
2735
|
+
updateLists(): void;
|
|
2736
|
+
/**
|
|
2737
|
+
* 更新所有实体
|
|
2738
|
+
*/
|
|
2739
|
+
update(): void;
|
|
2740
|
+
/**
|
|
2741
|
+
* 根据名称查找实体(使用索引,O(1)复杂度)
|
|
2742
|
+
* @param name 实体名称
|
|
2743
|
+
* @returns 找到的第一个实体或null
|
|
2744
|
+
*/
|
|
2745
|
+
findEntity(name: string): Entity | null;
|
|
2746
|
+
/**
|
|
2747
|
+
* 根据名称查找所有实体
|
|
2748
|
+
* @param name 实体名称
|
|
2749
|
+
* @returns 找到的所有实体数组
|
|
2750
|
+
*/
|
|
2751
|
+
findEntitiesByName(name: string): Entity[];
|
|
2752
|
+
/**
|
|
2753
|
+
* 根据ID查找实体(使用索引,O(1)复杂度)
|
|
2754
|
+
* @param id 实体ID
|
|
2755
|
+
* @returns 找到的实体或null
|
|
2756
|
+
*/
|
|
2757
|
+
findEntityById(id: number): Entity | null;
|
|
2758
|
+
/**
|
|
2759
|
+
* 根据标签查找实体
|
|
2760
|
+
* @param tag 标签
|
|
2761
|
+
* @returns 找到的所有实体数组
|
|
2762
|
+
*/
|
|
2763
|
+
findEntitiesByTag(tag: number): Entity[];
|
|
2764
|
+
/**
|
|
2765
|
+
* 根据组件类型查找实体
|
|
2766
|
+
* @param componentType 组件类型
|
|
2767
|
+
* @returns 找到的所有实体数组
|
|
2768
|
+
*/
|
|
2769
|
+
findEntitiesWithComponent<T extends Component>(componentType: new (...args: any[]) => T): Entity[];
|
|
2770
|
+
/**
|
|
2771
|
+
* 批量操作:对所有实体执行指定操作
|
|
2772
|
+
* @param action 要执行的操作
|
|
2773
|
+
*/
|
|
2774
|
+
forEach(action: (entity: Entity) => void): void;
|
|
2775
|
+
/**
|
|
2776
|
+
* 批量操作:对符合条件的实体执行指定操作
|
|
2777
|
+
* @param predicate 筛选条件
|
|
2778
|
+
* @param action 要执行的操作
|
|
2779
|
+
*/
|
|
2780
|
+
forEachWhere(predicate: (entity: Entity) => boolean, action: (entity: Entity) => void): void;
|
|
2781
|
+
/**
|
|
2782
|
+
* 更新名称索引
|
|
2783
|
+
* @param entity 实体
|
|
2784
|
+
* @param isAdd 是否为添加操作
|
|
2785
|
+
*/
|
|
2786
|
+
private updateNameIndex;
|
|
2787
|
+
/**
|
|
2788
|
+
* 获取实体列表的统计信息
|
|
2789
|
+
* @returns 统计信息
|
|
2790
|
+
*/
|
|
2791
|
+
getStats(): {
|
|
2792
|
+
totalEntities: number;
|
|
2793
|
+
activeEntities: number;
|
|
2794
|
+
pendingAdd: number;
|
|
2795
|
+
pendingRemove: number;
|
|
2796
|
+
nameIndexSize: number;
|
|
2797
|
+
}
|
|
2798
|
+
|
|
2799
|
+
export declare class EntityProcessorList {
|
|
2800
|
+
private _processors;
|
|
2801
|
+
private _isDirty;
|
|
2802
|
+
/**
|
|
2803
|
+
* 设置为脏状态,需要重新排序
|
|
2804
|
+
*/
|
|
2805
|
+
setDirty(): void;
|
|
2806
|
+
/**
|
|
2807
|
+
* 添加实体处理器
|
|
2808
|
+
* @param processor 要添加的处理器
|
|
2809
|
+
*/
|
|
2810
|
+
add(processor: EntitySystem): void;
|
|
2811
|
+
/**
|
|
2812
|
+
* 移除实体处理器
|
|
2813
|
+
* @param processor 要移除的处理器
|
|
2814
|
+
*/
|
|
2815
|
+
remove(processor: EntitySystem): void;
|
|
2816
|
+
/**
|
|
2817
|
+
* 获取指定类型的处理器
|
|
2818
|
+
* @param type 处理器类型
|
|
2819
|
+
*/
|
|
2820
|
+
getProcessor<T extends EntitySystem>(type: new (...args: any[]) => T): T | null;
|
|
2821
|
+
/**
|
|
2822
|
+
* 开始处理
|
|
2823
|
+
*/
|
|
2824
|
+
begin(): void;
|
|
2825
|
+
/**
|
|
2826
|
+
* 结束处理
|
|
2827
|
+
*/
|
|
2828
|
+
end(): void;
|
|
2829
|
+
/**
|
|
2830
|
+
* 更新所有处理器
|
|
2831
|
+
*/
|
|
2832
|
+
update(): void;
|
|
2833
|
+
/**
|
|
2834
|
+
* 后期更新所有处理器
|
|
2835
|
+
*/
|
|
2836
|
+
lateUpdate(): void;
|
|
2837
|
+
/**
|
|
2838
|
+
* 排序处理器
|
|
2839
|
+
*/
|
|
2840
|
+
private sortProcessors;
|
|
2841
|
+
/** 获取处理器列表 */
|
|
2842
|
+
get processors(): EntitySystem[];
|
|
2843
|
+
/** 获取处理器数量 */
|
|
2844
|
+
get count(): number;
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
export declare class IdentifierPool {
|
|
2848
|
+
private _nextAvailableId;
|
|
2849
|
+
private _ids;
|
|
2850
|
+
/**
|
|
2851
|
+
* 获取一个可用的ID
|
|
2852
|
+
*/
|
|
2853
|
+
checkOut(): number;
|
|
2854
|
+
/**
|
|
2855
|
+
* 回收一个ID
|
|
2856
|
+
* @param id 要回收的ID
|
|
2857
|
+
*/
|
|
2858
|
+
checkIn(id: number): void;
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
export declare class Matcher {
|
|
2862
|
+
protected allSet: (new (...args: any[]) => Component)[];
|
|
2863
|
+
protected exclusionSet: (new (...args: any[]) => Component)[];
|
|
2864
|
+
protected oneSet: (new (...args: any[]) => Component)[];
|
|
2865
|
+
private _allBits?;
|
|
2866
|
+
private _exclusionBits?;
|
|
2867
|
+
private _oneBits?;
|
|
2868
|
+
private _isDirty;
|
|
2869
|
+
static empty(): Matcher;
|
|
2870
|
+
getAllSet(): (new (...args: any[]) => Component)[];
|
|
2871
|
+
getExclusionSet(): (new (...args: any[]) => Component)[];
|
|
2872
|
+
getOneSet(): (new (...args: any[]) => Component)[];
|
|
2873
|
+
/**
|
|
2874
|
+
* 检查实体是否匹配条件
|
|
2875
|
+
* @param entity 要检查的实体
|
|
2876
|
+
* @returns 是否匹配
|
|
2877
|
+
*/
|
|
2878
|
+
isInterestedEntity(entity: Entity): boolean;
|
|
2879
|
+
/**
|
|
2880
|
+
* 检查组件位掩码是否匹配条件
|
|
2881
|
+
* @param componentBits 组件位掩码
|
|
2882
|
+
* @returns 是否匹配
|
|
2883
|
+
*/
|
|
2884
|
+
isInterested(componentBits: Bits): boolean;
|
|
2885
|
+
/**
|
|
2886
|
+
* 添加所有包含的组件类型
|
|
2887
|
+
* @param types 所有包含的组件类型列表
|
|
2888
|
+
*/
|
|
2889
|
+
all(...types: (new (...args: any[]) => Component)[]): Matcher;
|
|
2890
|
+
/**
|
|
2891
|
+
* 添加排除包含的组件类型
|
|
2892
|
+
* @param types 排除包含的组件类型列表
|
|
2893
|
+
*/
|
|
2894
|
+
exclude(...types: (new (...args: any[]) => Component)[]): Matcher;
|
|
2895
|
+
/**
|
|
2896
|
+
* 添加至少包含其中之一的组件类型
|
|
2897
|
+
* @param types 至少包含其中之一的组件类型列表
|
|
2898
|
+
*/
|
|
2899
|
+
one(...types: (new (...args: any[]) => Component)[]): Matcher;
|
|
2900
|
+
/**
|
|
2901
|
+
* 获取实体的组件位掩码
|
|
2902
|
+
* @param entity 实体
|
|
2903
|
+
* @returns 组件位掩码
|
|
2904
|
+
*/
|
|
2905
|
+
private getEntityBits;
|
|
2906
|
+
/**
|
|
2907
|
+
* 如果位掩码已过期,则更新它们
|
|
2908
|
+
*/
|
|
2909
|
+
private updateBitsIfDirty;
|
|
2910
|
+
/**
|
|
2911
|
+
* 创建匹配器的字符串表示(用于调试)
|
|
2912
|
+
* @returns 字符串表示
|
|
2913
|
+
*/
|
|
2914
|
+
toString(): string;
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
export declare class TestRunner {
|
|
2918
|
+
private results;
|
|
2919
|
+
/**
|
|
2920
|
+
* 运行所有单元测试
|
|
2921
|
+
*/
|
|
2922
|
+
runUnitTests(): Promise<void>;
|
|
2923
|
+
/**
|
|
2924
|
+
* 运行性能测试
|
|
2925
|
+
*/
|
|
2926
|
+
runPerformanceTests(): Promise<void>;
|
|
2927
|
+
/**
|
|
2928
|
+
* 运行集成测试
|
|
2929
|
+
*/
|
|
2930
|
+
runIntegrationTests(): Promise<void>;
|
|
2931
|
+
/**
|
|
2932
|
+
* 运行所有测试
|
|
2933
|
+
*/
|
|
2934
|
+
runAllTests(): Promise<void>;
|
|
2935
|
+
/**
|
|
2936
|
+
* 运行单个测试
|
|
2937
|
+
*/
|
|
2938
|
+
private runTest;
|
|
2939
|
+
/**
|
|
2940
|
+
* 打印测试摘要
|
|
2941
|
+
*/
|
|
2942
|
+
private printSummary;
|
|
2943
|
+
/**
|
|
2944
|
+
* 打印最终测试摘要
|
|
2945
|
+
*/
|
|
2946
|
+
private printFinalSummary;
|
|
2947
|
+
/**
|
|
2948
|
+
* 清除测试结果
|
|
2949
|
+
*/
|
|
2950
|
+
clearResults(): void;
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
export declare class FuncPack {
|
|
2954
|
+
/** 函数 */
|
|
2955
|
+
func: Function;
|
|
2956
|
+
/** 上下文 */
|
|
2957
|
+
context: any;
|
|
2958
|
+
constructor(func: Function, context: any);
|
|
2959
|
+
}
|
|
2960
|
+
|
|
2961
|
+
export declare class Emitter<T> {
|
|
2962
|
+
private _messageTable;
|
|
2963
|
+
constructor();
|
|
2964
|
+
/**
|
|
2965
|
+
* 开始监听项
|
|
2966
|
+
* @param eventType 监听类型
|
|
2967
|
+
* @param handler 监听函数
|
|
2968
|
+
* @param context 监听上下文
|
|
2969
|
+
*/
|
|
2970
|
+
addObserver(eventType: T, handler: Function, context: any): void;
|
|
2971
|
+
/**
|
|
2972
|
+
* 移除监听项
|
|
2973
|
+
* @param eventType 事件类型
|
|
2974
|
+
* @param handler 事件函数
|
|
2975
|
+
*/
|
|
2976
|
+
removeObserver(eventType: T, handler: Function): void;
|
|
2977
|
+
/**
|
|
2978
|
+
* 触发该事件
|
|
2979
|
+
* @param eventType 事件类型
|
|
2980
|
+
* @param data 事件数据
|
|
2981
|
+
*/
|
|
2982
|
+
emit(eventType: T, ...data: any[]): void;
|
|
2983
|
+
/**
|
|
2984
|
+
* 判断是否存在该类型的观察者
|
|
2985
|
+
* @param eventType 事件类型
|
|
2986
|
+
* @param handler 事件函数
|
|
2987
|
+
*/
|
|
2988
|
+
hasObserver(eventType: T, handler: Function): boolean;
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
export declare class NumberExtension {
|
|
2992
|
+
/**
|
|
2993
|
+
* 将值转换为数字
|
|
2994
|
+
* @param value 要转换的值
|
|
2995
|
+
* @returns 转换后的数字,如果值为undefined则返回0
|
|
2996
|
+
*/
|
|
2997
|
+
static toNumber(value: any): number;
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
export declare class TypeUtils {
|
|
3001
|
+
/**
|
|
3002
|
+
* 获取对象的类型
|
|
3003
|
+
* @param obj 对象
|
|
3004
|
+
* @returns 对象的构造函数
|
|
3005
|
+
*/
|
|
3006
|
+
static getType(obj: any): any;
|
|
3007
|
+
}
|
|
3008
|
+
|
|
3009
|
+
export declare class GlobalManager {
|
|
3010
|
+
/**
|
|
3011
|
+
* 表示管理器是否启用
|
|
3012
|
+
*/
|
|
3013
|
+
_enabled: boolean;
|
|
3014
|
+
/**
|
|
3015
|
+
* 获取或设置管理器是否启用
|
|
3016
|
+
*/
|
|
3017
|
+
get enabled(): boolean;
|
|
3018
|
+
set enabled(value: boolean);
|
|
3019
|
+
/**
|
|
3020
|
+
* 设置管理器是否启用
|
|
3021
|
+
* @param isEnabled 如果为true,则启用管理器;否则禁用管理器
|
|
3022
|
+
*/
|
|
3023
|
+
setEnabled(isEnabled: boolean): void;
|
|
3024
|
+
/**
|
|
3025
|
+
* 在启用管理器时调用的回调方法
|
|
3026
|
+
*/
|
|
3027
|
+
protected onEnabled(): void;
|
|
3028
|
+
/**
|
|
3029
|
+
* 在禁用管理器时调用的回调方法
|
|
3030
|
+
*/
|
|
3031
|
+
protected onDisabled(): void;
|
|
3032
|
+
/**
|
|
3033
|
+
* 更新管理器状态的方法
|
|
3034
|
+
*/
|
|
3035
|
+
update(): void;
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
export interface PerformanceData {
|
|
3039
|
+
/** 系统名称 */
|
|
3040
|
+
name: string;
|
|
3041
|
+
/** 执行时间(毫秒) */
|
|
3042
|
+
executionTime: number;
|
|
3043
|
+
/** 处理的实体数量 */
|
|
3044
|
+
entityCount: number;
|
|
3045
|
+
/** 平均每个实体的处理时间 */
|
|
3046
|
+
averageTimePerEntity: number;
|
|
3047
|
+
/** 最后更新时间戳 */
|
|
3048
|
+
lastUpdateTime: number;
|
|
3049
|
+
/** 内存使用量(字节) */
|
|
3050
|
+
memoryUsage?: number;
|
|
3051
|
+
/** CPU使用率(百分比) */
|
|
3052
|
+
cpuUsage?: number;
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
export interface PerformanceStats {
|
|
3056
|
+
/** 总执行时间 */
|
|
3057
|
+
totalTime: number;
|
|
3058
|
+
/** 平均执行时间 */
|
|
3059
|
+
averageTime: number;
|
|
3060
|
+
/** 最小执行时间 */
|
|
3061
|
+
minTime: number;
|
|
3062
|
+
/** 最大执行时间 */
|
|
3063
|
+
maxTime: number;
|
|
3064
|
+
/** 执行次数 */
|
|
3065
|
+
executionCount: number;
|
|
3066
|
+
/** 最近的执行时间列表 */
|
|
3067
|
+
recentTimes: number[];
|
|
3068
|
+
/** 标准差 */
|
|
3069
|
+
standardDeviation: number;
|
|
3070
|
+
/** 95百分位数 */
|
|
3071
|
+
percentile95: number;
|
|
3072
|
+
/** 99百分位数 */
|
|
3073
|
+
percentile99: number;
|
|
3074
|
+
}
|
|
3075
|
+
|
|
3076
|
+
export declare enum PerformanceWarningType {
|
|
3077
|
+
HIGH_EXECUTION_TIME = "high_execution_time",
|
|
3078
|
+
HIGH_MEMORY_USAGE = "high_memory_usage",
|
|
3079
|
+
HIGH_CPU_USAGE = "high_cpu_usage",
|
|
3080
|
+
FREQUENT_GC = "frequent_gc",
|
|
3081
|
+
LOW_FPS = "low_fps",
|
|
3082
|
+
HIGH_ENTITY_COUNT = "high_entity_count"
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
export interface PerformanceWarning {
|
|
3086
|
+
type: PerformanceWarningType;
|
|
3087
|
+
systemName: string;
|
|
3088
|
+
message: string;
|
|
3089
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
3090
|
+
timestamp: number;
|
|
3091
|
+
value: number;
|
|
3092
|
+
threshold: number;
|
|
3093
|
+
suggestion?: string;
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
export interface PerformanceThresholds {
|
|
3097
|
+
/** 执行时间阈值(毫秒) */
|
|
3098
|
+
executionTime: {
|
|
3099
|
+
warning: number;
|
|
3100
|
+
critical: number;
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
export declare class PerformanceMonitor {
|
|
3104
|
+
private static _instance;
|
|
3105
|
+
private _systemData;
|
|
3106
|
+
private _systemStats;
|
|
3107
|
+
private _warnings;
|
|
3108
|
+
private _isEnabled;
|
|
3109
|
+
private _maxRecentSamples;
|
|
3110
|
+
private _maxWarnings;
|
|
3111
|
+
private _thresholds;
|
|
3112
|
+
private _fpsHistory;
|
|
3113
|
+
private _lastFrameTime;
|
|
3114
|
+
private _frameCount;
|
|
3115
|
+
private _fpsUpdateInterval;
|
|
3116
|
+
private _lastFpsUpdate;
|
|
3117
|
+
private _currentFps;
|
|
3118
|
+
private _memoryCheckInterval;
|
|
3119
|
+
private _lastMemoryCheck;
|
|
3120
|
+
private _memoryHistory;
|
|
3121
|
+
private _gcCount;
|
|
3122
|
+
private _lastGcCheck;
|
|
3123
|
+
private _gcCheckInterval;
|
|
3124
|
+
/**
|
|
3125
|
+
* 获取单例实例
|
|
3126
|
+
*/
|
|
3127
|
+
static get instance(): PerformanceMonitor;
|
|
3128
|
+
private constructor();
|
|
3129
|
+
/**
|
|
3130
|
+
* 启用性能监控
|
|
3131
|
+
*/
|
|
3132
|
+
enable(): void;
|
|
3133
|
+
/**
|
|
3134
|
+
* 禁用性能监控
|
|
3135
|
+
*/
|
|
3136
|
+
disable(): void;
|
|
3137
|
+
/**
|
|
3138
|
+
* 检查是否启用了性能监控
|
|
3139
|
+
*/
|
|
3140
|
+
get isEnabled(): boolean;
|
|
3141
|
+
/**
|
|
3142
|
+
* 开始监控系统性能
|
|
3143
|
+
* @param systemName 系统名称
|
|
3144
|
+
* @returns 开始时间戳
|
|
3145
|
+
*/
|
|
3146
|
+
startMonitoring(systemName: string): number;
|
|
3147
|
+
/**
|
|
3148
|
+
* 结束监控并记录性能数据
|
|
3149
|
+
* @param systemName 系统名称
|
|
3150
|
+
* @param startTime 开始时间戳
|
|
3151
|
+
* @param entityCount 处理的实体数量
|
|
3152
|
+
*/
|
|
3153
|
+
endMonitoring(systemName: string, startTime: number, entityCount?: number): void;
|
|
3154
|
+
/**
|
|
3155
|
+
* 更新系统统计信息
|
|
3156
|
+
* @param systemName 系统名称
|
|
3157
|
+
* @param executionTime 执行时间
|
|
3158
|
+
*/
|
|
3159
|
+
private updateStats;
|
|
3160
|
+
/**
|
|
3161
|
+
* 计算高级统计信息
|
|
3162
|
+
* @param stats 统计信息对象
|
|
3163
|
+
*/
|
|
3164
|
+
private calculateAdvancedStats;
|
|
3165
|
+
/**
|
|
3166
|
+
* 获取系统的当前性能数据
|
|
3167
|
+
* @param systemName 系统名称
|
|
3168
|
+
* @returns 性能数据或undefined
|
|
3169
|
+
*/
|
|
3170
|
+
getSystemData(systemName: string): PerformanceData | undefined;
|
|
3171
|
+
/**
|
|
3172
|
+
* 获取系统的统计信息
|
|
3173
|
+
* @param systemName 系统名称
|
|
3174
|
+
* @returns 统计信息或undefined
|
|
3175
|
+
*/
|
|
3176
|
+
getSystemStats(systemName: string): PerformanceStats | undefined;
|
|
3177
|
+
/**
|
|
3178
|
+
* 获取所有系统的性能数据
|
|
3179
|
+
* @returns 所有系统的性能数据
|
|
3180
|
+
*/
|
|
3181
|
+
getAllSystemData(): Map<string, PerformanceData>;
|
|
3182
|
+
/**
|
|
3183
|
+
* 获取所有系统的统计信息
|
|
3184
|
+
* @returns 所有系统的统计信息
|
|
3185
|
+
*/
|
|
3186
|
+
getAllSystemStats(): Map<string, PerformanceStats>;
|
|
3187
|
+
/**
|
|
3188
|
+
* 获取性能报告
|
|
3189
|
+
* @returns 格式化的性能报告字符串
|
|
3190
|
+
*/
|
|
3191
|
+
getPerformanceReport(): string;
|
|
3192
|
+
/**
|
|
3193
|
+
* 重置所有性能数据
|
|
3194
|
+
*/
|
|
3195
|
+
reset(): void;
|
|
3196
|
+
/**
|
|
3197
|
+
* 重置指定系统的性能数据
|
|
3198
|
+
* @param systemName 系统名称
|
|
3199
|
+
*/
|
|
3200
|
+
resetSystem(systemName: string): void;
|
|
3201
|
+
/**
|
|
3202
|
+
* 获取性能警告
|
|
3203
|
+
* @param thresholdMs 警告阈值(毫秒)
|
|
3204
|
+
* @returns 超过阈值的系统列表
|
|
3205
|
+
*/
|
|
3206
|
+
getPerformanceWarnings(thresholdMs?: number): string[];
|
|
3207
|
+
/**
|
|
3208
|
+
* 设置最大保留样本数
|
|
3209
|
+
* @param maxSamples 最大样本数
|
|
3210
|
+
*/
|
|
3211
|
+
setMaxRecentSamples(maxSamples: number): void;
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
export interface IPoolable {
|
|
3215
|
+
/**
|
|
3216
|
+
* 重置对象状态,准备重用
|
|
3217
|
+
*/
|
|
3218
|
+
reset(): void;
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3221
|
+
export interface PoolStats {
|
|
3222
|
+
/** 池中对象数量 */
|
|
3223
|
+
size: number;
|
|
3224
|
+
/** 池的最大大小 */
|
|
3225
|
+
maxSize: number;
|
|
3226
|
+
/** 总共创建的对象数量 */
|
|
3227
|
+
totalCreated: number;
|
|
3228
|
+
/** 总共获取的次数 */
|
|
3229
|
+
totalObtained: number;
|
|
3230
|
+
/** 总共释放的次数 */
|
|
3231
|
+
totalReleased: number;
|
|
3232
|
+
/** 命中率(从池中获取的比例) */
|
|
3233
|
+
hitRate: number;
|
|
3234
|
+
/** 内存使用估算(字节) */
|
|
3235
|
+
estimatedMemoryUsage: number;
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
export declare class Pool<T extends IPoolable> {
|
|
3239
|
+
private static _pools;
|
|
3240
|
+
private _objects;
|
|
3241
|
+
private _createFn;
|
|
3242
|
+
private _maxSize;
|
|
3243
|
+
private _stats;
|
|
3244
|
+
private _objectSize;
|
|
3245
|
+
/**
|
|
3246
|
+
* 构造函数
|
|
3247
|
+
* @param createFn 创建对象的函数
|
|
3248
|
+
* @param maxSize 池的最大大小,默认100
|
|
3249
|
+
* @param estimatedObjectSize 估算的单个对象大小(字节),默认1024
|
|
3250
|
+
*/
|
|
3251
|
+
constructor(createFn: () => T, maxSize?: number, estimatedObjectSize?: number);
|
|
3252
|
+
/**
|
|
3253
|
+
* 获取指定类型的对象池
|
|
3254
|
+
* @param type 对象类型
|
|
3255
|
+
* @param maxSize 池的最大大小
|
|
3256
|
+
* @param estimatedObjectSize 估算的单个对象大小
|
|
3257
|
+
* @returns 对象池实例
|
|
3258
|
+
*/
|
|
3259
|
+
static getPool<T extends IPoolable>(type: new (...args: any[]) => T, maxSize?: number, estimatedObjectSize?: number): Pool<T>;
|
|
3260
|
+
/**
|
|
3261
|
+
* 从池中获取对象
|
|
3262
|
+
* @returns 对象实例
|
|
3263
|
+
*/
|
|
3264
|
+
obtain(): T;
|
|
3265
|
+
/**
|
|
3266
|
+
* 将对象归还到池中
|
|
3267
|
+
* @param obj 要归还的对象
|
|
3268
|
+
*/
|
|
3269
|
+
free(obj: T): void;
|
|
3270
|
+
/**
|
|
3271
|
+
* 预热池,创建指定数量的对象
|
|
3272
|
+
* @param count 要创建的对象数量
|
|
3273
|
+
*/
|
|
3274
|
+
warmUp(count: number): void;
|
|
3275
|
+
/**
|
|
3276
|
+
* 清空池
|
|
3277
|
+
*/
|
|
3278
|
+
clear(): void;
|
|
3279
|
+
/**
|
|
3280
|
+
* 获取池中对象数量
|
|
3281
|
+
*/
|
|
3282
|
+
get size(): number;
|
|
3283
|
+
/**
|
|
3284
|
+
* 获取池的最大大小
|
|
3285
|
+
*/
|
|
3286
|
+
get maxSize(): number;
|
|
3287
|
+
/**
|
|
3288
|
+
* 设置池的最大大小
|
|
3289
|
+
*/
|
|
3290
|
+
set maxSize(value: number);
|
|
3291
|
+
/**
|
|
3292
|
+
* 获取池的统计信息
|
|
3293
|
+
*/
|
|
3294
|
+
getStats(): PoolStats;
|
|
3295
|
+
/**
|
|
3296
|
+
* 重置统计信息
|
|
3297
|
+
*/
|
|
3298
|
+
resetStats(): void;
|
|
3299
|
+
/**
|
|
3300
|
+
* 更新命中率
|
|
3301
|
+
*/
|
|
3302
|
+
private _updateHitRate;
|
|
3303
|
+
/**
|
|
3304
|
+
* 更新内存使用估算
|
|
3305
|
+
*/
|
|
3306
|
+
private _updateMemoryUsage;
|
|
3307
|
+
/**
|
|
3308
|
+
* 静态方法:从指定类型的池中获取对象
|
|
3309
|
+
* @param type 对象类型
|
|
3310
|
+
* @returns 对象实例
|
|
3311
|
+
*/
|
|
3312
|
+
static obtain<T extends IPoolable>(type: new (...args: any[]) => T): T;
|
|
3313
|
+
/**
|
|
3314
|
+
* 静态方法:将对象归还到对应类型的池中
|
|
3315
|
+
* @param type 对象类型
|
|
3316
|
+
* @param obj 要归还的对象
|
|
3317
|
+
*/
|
|
3318
|
+
static free<T extends IPoolable>(type: new (...args: any[]) => T, obj: T): void;
|
|
3319
|
+
/**
|
|
3320
|
+
* 静态方法:预热指定类型的池
|
|
3321
|
+
* @param type 对象类型
|
|
3322
|
+
* @param count 要创建的对象数量
|
|
3323
|
+
*/
|
|
3324
|
+
static warmUp<T extends IPoolable>(type: new (...args: any[]) => T, count: number): void;
|
|
3325
|
+
/**
|
|
3326
|
+
* 静态方法:清空指定类型的池
|
|
3327
|
+
* @param type 对象类型
|
|
3328
|
+
*/
|
|
3329
|
+
static clearPool<T extends IPoolable>(type: new (...args: any[]) => T): void;
|
|
3330
|
+
/**
|
|
3331
|
+
* 静态方法:清空所有池
|
|
3332
|
+
*/
|
|
3333
|
+
static clearAllPools(): void;
|
|
3334
|
+
/**
|
|
3335
|
+
* 静态方法:获取池的统计信息
|
|
3336
|
+
* @returns 池的统计信息
|
|
3337
|
+
*/
|
|
3338
|
+
static getStats(): {
|
|
3339
|
+
[typeName: string]: PoolStats;
|
|
3340
|
+
}
|
|
3341
|
+
|
|
3342
|
+
export declare class TieredObjectPool<T extends IPoolable> {
|
|
3343
|
+
private pools;
|
|
3344
|
+
private createFn;
|
|
3345
|
+
private resetFn;
|
|
3346
|
+
private tierSizes;
|
|
3347
|
+
private totalObtained;
|
|
3348
|
+
private totalReleased;
|
|
3349
|
+
/**
|
|
3350
|
+
* 构造函数
|
|
3351
|
+
* @param createFn 创建对象的函数
|
|
3352
|
+
* @param resetFn 重置对象的函数
|
|
3353
|
+
* @param tierSizes 各层级的大小,默认[10, 50, 200]
|
|
3354
|
+
* @param estimatedObjectSize 估算的单个对象大小
|
|
3355
|
+
*/
|
|
3356
|
+
constructor(createFn: () => T, resetFn: (obj: T) => void, tierSizes?: number[], estimatedObjectSize?: number);
|
|
3357
|
+
/**
|
|
3358
|
+
* 获取对象
|
|
3359
|
+
* @returns 对象实例
|
|
3360
|
+
*/
|
|
3361
|
+
obtain(): T;
|
|
3362
|
+
/**
|
|
3363
|
+
* 释放对象
|
|
3364
|
+
* @param obj 要释放的对象
|
|
3365
|
+
*/
|
|
3366
|
+
release(obj: T): void;
|
|
3367
|
+
/**
|
|
3368
|
+
* 预热所有池
|
|
3369
|
+
* @param totalCount 总预热数量
|
|
3370
|
+
*/
|
|
3371
|
+
warmUp(totalCount: number): void;
|
|
3372
|
+
/**
|
|
3373
|
+
* 清空所有池
|
|
3374
|
+
*/
|
|
3375
|
+
clear(): void;
|
|
3376
|
+
/**
|
|
3377
|
+
* 获取统计信息
|
|
3378
|
+
*/
|
|
3379
|
+
getStats(): {
|
|
3380
|
+
totalSize: number;
|
|
3381
|
+
totalMaxSize: number;
|
|
3382
|
+
totalMemoryUsage: number;
|
|
3383
|
+
tierStats: PoolStats[];
|
|
3384
|
+
hitRate: number;
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3387
|
+
export declare class PoolManager {
|
|
3388
|
+
private static instance;
|
|
3389
|
+
private pools;
|
|
3390
|
+
private autoCompactInterval;
|
|
3391
|
+
private lastCompactTime;
|
|
3392
|
+
static getInstance(): PoolManager;
|
|
3393
|
+
/**
|
|
3394
|
+
* 注册池
|
|
3395
|
+
* @param name 池名称
|
|
3396
|
+
* @param pool 池实例
|
|
3397
|
+
*/
|
|
3398
|
+
registerPool<T extends IPoolable>(name: string, pool: Pool<T> | TieredObjectPool<T>): void;
|
|
3399
|
+
/**
|
|
3400
|
+
* 获取池
|
|
3401
|
+
* @param name 池名称
|
|
3402
|
+
* @returns 池实例
|
|
3403
|
+
*/
|
|
3404
|
+
getPool<T extends IPoolable>(name: string): Pool<T> | TieredObjectPool<T> | null;
|
|
3405
|
+
/**
|
|
3406
|
+
* 更新池管理器(应在游戏循环中调用)
|
|
3407
|
+
*/
|
|
3408
|
+
update(): void;
|
|
3409
|
+
/**
|
|
3410
|
+
* 压缩所有池(清理碎片)
|
|
3411
|
+
*/
|
|
3412
|
+
compactAllPools(): void;
|
|
3413
|
+
/**
|
|
3414
|
+
* 获取所有池的统计信息
|
|
3415
|
+
*/
|
|
3416
|
+
getAllStats(): Map<string, any>;
|
|
3417
|
+
/**
|
|
3418
|
+
* 生成性能报告
|
|
3419
|
+
*/
|
|
3420
|
+
generateReport(): string;
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
export declare class Time {
|
|
3424
|
+
/**
|
|
3425
|
+
* 上一帧到当前帧的时间间隔(秒)
|
|
3426
|
+
*/
|
|
3427
|
+
static deltaTime: number;
|
|
3428
|
+
/**
|
|
3429
|
+
* 未缩放的帧时间间隔(秒)
|
|
3430
|
+
*/
|
|
3431
|
+
static unscaledDeltaTime: number;
|
|
3432
|
+
/**
|
|
3433
|
+
* 游戏开始以来的总时间(秒)
|
|
3434
|
+
*/
|
|
3435
|
+
static totalTime: number;
|
|
3436
|
+
/**
|
|
3437
|
+
* 未缩放的总时间(秒)
|
|
3438
|
+
*/
|
|
3439
|
+
static unscaledTotalTime: number;
|
|
3440
|
+
/**
|
|
3441
|
+
* 时间缩放比例
|
|
3442
|
+
*/
|
|
3443
|
+
static timeScale: number;
|
|
3444
|
+
/**
|
|
3445
|
+
* 当前帧数
|
|
3446
|
+
*/
|
|
3447
|
+
static frameCount: number;
|
|
3448
|
+
/**
|
|
3449
|
+
* 上一帧的时间戳
|
|
3450
|
+
*/
|
|
3451
|
+
private static _lastTime;
|
|
3452
|
+
/**
|
|
3453
|
+
* 是否为第一次更新
|
|
3454
|
+
*/
|
|
3455
|
+
private static _isFirstUpdate;
|
|
3456
|
+
/**
|
|
3457
|
+
* 更新时间信息
|
|
3458
|
+
* @param currentTime 当前时间戳(毫秒)
|
|
3459
|
+
*/
|
|
3460
|
+
static update(currentTime?: number): void;
|
|
3461
|
+
/**
|
|
3462
|
+
* 场景改变时重置时间
|
|
3463
|
+
*/
|
|
3464
|
+
static sceneChanged(): void;
|
|
3465
|
+
/**
|
|
3466
|
+
* 检查指定的时间间隔是否已经过去
|
|
3467
|
+
* @param interval 时间间隔(秒)
|
|
3468
|
+
* @param lastTime 上次检查的时间
|
|
3469
|
+
* @returns 是否已经过去指定时间
|
|
3470
|
+
*/
|
|
3471
|
+
static checkEvery(interval: number, lastTime: number): boolean;
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
export interface ITimer {
|
|
3475
|
+
context: any;
|
|
3476
|
+
/**
|
|
3477
|
+
* 调用stop以停止此计时器再次运行。这对非重复计时器没有影响。
|
|
3478
|
+
*/
|
|
3479
|
+
stop(): void;
|
|
3480
|
+
/**
|
|
3481
|
+
* 将计时器的运行时间重置为0
|
|
3482
|
+
*/
|
|
3483
|
+
reset(): void;
|
|
3484
|
+
/**
|
|
3485
|
+
* 返回投向T的上下文,作为方便
|
|
3486
|
+
*/
|
|
3487
|
+
getContext<T>(): T;
|
|
3488
|
+
}
|
|
3489
|
+
|
|
3490
|
+
export declare class Timer implements ITimer {
|
|
3491
|
+
context: any;
|
|
3492
|
+
_timeInSeconds: number;
|
|
3493
|
+
_repeats: boolean;
|
|
3494
|
+
_onTime: (timer: ITimer) => void;
|
|
3495
|
+
_isDone: boolean;
|
|
3496
|
+
_elapsedTime: number;
|
|
3497
|
+
getContext<T>(): T;
|
|
3498
|
+
reset(): void;
|
|
3499
|
+
stop(): void;
|
|
3500
|
+
tick(): boolean;
|
|
3501
|
+
initialize(timeInsSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): void;
|
|
3502
|
+
/**
|
|
3503
|
+
* 空出对象引用,以便在js需要时GC可以清理它们的引用
|
|
3504
|
+
*/
|
|
3505
|
+
unload(): void;
|
|
3506
|
+
}
|
|
3507
|
+
|
|
3508
|
+
export declare class TimerManager extends GlobalManager {
|
|
3509
|
+
_timers: Timer[];
|
|
3510
|
+
update(): void;
|
|
3511
|
+
/**
|
|
3512
|
+
* 调度一个一次性或重复的计时器,该计时器将调用已传递的动作
|
|
3513
|
+
* @param timeInSeconds
|
|
3514
|
+
* @param repeats
|
|
3515
|
+
* @param context
|
|
3516
|
+
* @param onTime
|
|
3517
|
+
*/
|
|
3518
|
+
schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): Timer;
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3521
|
+
export declare class WasmEcsCore {
|
|
3522
|
+
private wasmLoader;
|
|
3523
|
+
private jsFallback;
|
|
3524
|
+
private initialized;
|
|
3525
|
+
private usingWasm;
|
|
3526
|
+
constructor();
|
|
3527
|
+
setSilent(silent: boolean): void;
|
|
3528
|
+
initialize(): Promise<boolean>;
|
|
3529
|
+
createEntity(): EntityId;
|
|
3530
|
+
destroyEntity(entityId: EntityId): boolean;
|
|
3531
|
+
updateEntityMask(entityId: EntityId, mask: ComponentMask): void;
|
|
3532
|
+
batchUpdateMasks(entityIds: EntityId[], masks: ComponentMask[]): void;
|
|
3533
|
+
queryEntities(mask: ComponentMask, maxResults?: number): QueryResult;
|
|
3534
|
+
queryCached(mask: ComponentMask): QueryResult;
|
|
3535
|
+
queryMultipleComponents(masks: ComponentMask[], maxResults?: number): QueryResult;
|
|
3536
|
+
queryWithExclusion(includeMask: ComponentMask, excludeMask: ComponentMask, maxResults?: number): QueryResult;
|
|
3537
|
+
getEntityMask(entityId: EntityId): ComponentMask | null;
|
|
3538
|
+
entityExists(entityId: EntityId): boolean;
|
|
3539
|
+
createComponentMask(componentIds: number[]): ComponentMask;
|
|
3540
|
+
maskContainsComponent(mask: ComponentMask, componentId: number): boolean;
|
|
3541
|
+
getPerformanceStats(): PerformanceStats;
|
|
3542
|
+
clear(): void;
|
|
3543
|
+
isUsingWasm(): boolean;
|
|
3544
|
+
isInitialized(): boolean;
|
|
3545
|
+
private ensureInitialized;
|
|
3546
|
+
cleanup(): void;
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
export declare class JavaScriptFallback {
|
|
3550
|
+
private jsEntityMasks;
|
|
3551
|
+
private jsNextEntityId;
|
|
3552
|
+
private jsQueryCount;
|
|
3553
|
+
private jsUpdateCount;
|
|
3554
|
+
createEntity(): EntityId;
|
|
3555
|
+
destroyEntity(entityId: EntityId): boolean;
|
|
3556
|
+
updateEntityMask(entityId: EntityId, mask: ComponentMask): void;
|
|
3557
|
+
batchUpdateMasks(entityIds: EntityId[], masks: ComponentMask[]): void;
|
|
3558
|
+
queryEntities(mask: ComponentMask, maxResults?: number): QueryResult;
|
|
3559
|
+
queryCached(mask: ComponentMask): QueryResult;
|
|
3560
|
+
queryMultipleComponents(masks: ComponentMask[], maxResults?: number): QueryResult;
|
|
3561
|
+
queryWithExclusion(includeMask: ComponentMask, excludeMask: ComponentMask, maxResults?: number): QueryResult;
|
|
3562
|
+
getEntityMask(entityId: EntityId): ComponentMask | null;
|
|
3563
|
+
entityExists(entityId: EntityId): boolean;
|
|
3564
|
+
createComponentMask(componentIds: number[]): ComponentMask;
|
|
3565
|
+
maskContainsComponent(mask: ComponentMask, componentId: number): boolean;
|
|
3566
|
+
getPerformanceStats(): PerformanceStats;
|
|
3567
|
+
clear(): void;
|
|
3568
|
+
getEntityCount(): number;
|
|
3569
|
+
}
|
|
3570
|
+
|
|
3571
|
+
export declare class WasmLoader {
|
|
3572
|
+
private wasmModule;
|
|
3573
|
+
private wasmCore;
|
|
3574
|
+
private silent;
|
|
3575
|
+
setSilent(silent: boolean): void;
|
|
3576
|
+
loadWasmModule(): Promise<boolean>;
|
|
3577
|
+
private initializeWasmModule;
|
|
3578
|
+
getWasmCore(): WasmEcsCoreInstance | null;
|
|
3579
|
+
getWasmModule(): WasmModule | null;
|
|
3580
|
+
cleanup(): void;
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3583
|
+
export type EntityId = number;
|
|
3584
|
+
export type ComponentMask = bigint;
|
|
3585
|
+
export interface QueryResult {
|
|
3586
|
+
entities: Uint32Array;
|
|
3587
|
+
count: number;
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3590
|
+
export interface PerformanceStats {
|
|
3591
|
+
entityCount: number;
|
|
3592
|
+
indexCount: number;
|
|
3593
|
+
queryCount: number;
|
|
3594
|
+
updateCount: number;
|
|
3595
|
+
wasmEnabled: boolean;
|
|
3596
|
+
}
|
|
3597
|
+
|
|
3598
|
+
export interface WasmEcsCoreInstance {
|
|
3599
|
+
create_entity(): number;
|
|
3600
|
+
destroy_entity(entity_id: number): boolean;
|
|
3601
|
+
update_entity_mask(entity_id: number, mask: bigint): void;
|
|
3602
|
+
batch_update_masks(entity_ids: Uint32Array, masks: BigUint64Array): void;
|
|
3603
|
+
query_entities(mask: bigint, max_results: number): number;
|
|
3604
|
+
get_query_result_count(): number;
|
|
3605
|
+
query_cached(mask: bigint): number;
|
|
3606
|
+
get_cached_query_count(mask: bigint): number;
|
|
3607
|
+
query_multiple_components(masks: BigUint64Array, max_results: number): number;
|
|
3608
|
+
query_with_exclusion(include_mask: bigint, exclude_mask: bigint, max_results: number): number;
|
|
3609
|
+
get_entity_mask(entity_id: number): bigint;
|
|
3610
|
+
entity_exists(entity_id: number): boolean;
|
|
3611
|
+
get_entity_count(): number;
|
|
3612
|
+
get_performance_stats(): Array<any>;
|
|
3613
|
+
clear(): void;
|
|
3614
|
+
rebuild_query_cache(): void;
|
|
3615
|
+
free?(): void;
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
export interface WasmModule {
|
|
3619
|
+
EcsCore: new () => WasmEcsCoreInstance;
|
|
3620
|
+
create_component_mask: (componentIds: Uint32Array) => ComponentMask;
|
|
3621
|
+
mask_contains_component: (mask: ComponentMask, componentId: number) => boolean;
|
|
3622
|
+
default: (input?: any) => Promise<any>;
|
|
3623
|
+
initSync?: (input: any) => any;
|
|
3624
|
+
memory?: WebAssembly.Memory;
|
|
3625
|
+
}
|
|
3626
|
+
|
|
3627
|
+
export type EntityId = number;
|
|
3628
|
+
export type ComponentMask = bigint;
|
|
3629
|
+
|
|
3630
|
+
export type Query = import('./Wasm').QueryResult;
|
|
3631
|
+
|
|
3632
|
+
export function create_component_mask(component_ids: Uint32Array): bigint;
|
|
3633
|
+
/**
|
|
3634
|
+
* 检查掩码是否包含指定组件
|
|
3635
|
+
*/
|
|
3636
|
+
export function mask_contains_component(mask: bigint, component_id: number): boolean;
|
|
8
3637
|
/**
|
|
9
|
-
*
|
|
10
|
-
* 适用于Laya、Cocos等游戏引擎的小游戏开发
|
|
3638
|
+
* 初始化函数
|
|
11
3639
|
*/
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3640
|
+
export function main(): void;
|
|
3641
|
+
/**
|
|
3642
|
+
* 高性能ECS核心,专注于实体查询和掩码管理
|
|
3643
|
+
*/
|
|
3644
|
+
export class EcsCore {
|
|
3645
|
+
free(): void;
|
|
3646
|
+
/**
|
|
3647
|
+
* 创建新的ECS核心
|
|
3648
|
+
*/
|
|
3649
|
+
constructor();
|
|
3650
|
+
/**
|
|
3651
|
+
* 创建新实体
|
|
3652
|
+
*/
|
|
3653
|
+
create_entity(): number;
|
|
3654
|
+
/**
|
|
3655
|
+
* 删除实体
|
|
3656
|
+
*/
|
|
3657
|
+
destroy_entity(entity_id: number): boolean;
|
|
3658
|
+
/**
|
|
3659
|
+
* 更新实体的组件掩码
|
|
3660
|
+
*/
|
|
3661
|
+
update_entity_mask(entity_id: number, mask: bigint): void;
|
|
3662
|
+
/**
|
|
3663
|
+
* 批量更新实体掩码
|
|
3664
|
+
*/
|
|
3665
|
+
batch_update_masks(entity_ids: Uint32Array, masks: BigUint64Array): void;
|
|
3666
|
+
/**
|
|
3667
|
+
* 查询实体
|
|
3668
|
+
*/
|
|
3669
|
+
query_entities(mask: bigint, max_results: number): number;
|
|
3670
|
+
/**
|
|
3671
|
+
* 获取查询结果数量
|
|
3672
|
+
*/
|
|
3673
|
+
get_query_result_count(): number;
|
|
3674
|
+
/**
|
|
3675
|
+
* 缓存查询实体
|
|
3676
|
+
*/
|
|
3677
|
+
query_cached(mask: bigint): number;
|
|
3678
|
+
/**
|
|
3679
|
+
* 获取缓存查询结果数量
|
|
3680
|
+
*/
|
|
3681
|
+
get_cached_query_count(mask: bigint): number;
|
|
3682
|
+
/**
|
|
3683
|
+
* 多组件查询
|
|
3684
|
+
*/
|
|
3685
|
+
query_multiple_components(masks: BigUint64Array, max_results: number): number;
|
|
3686
|
+
/**
|
|
3687
|
+
* 排除查询
|
|
3688
|
+
*/
|
|
3689
|
+
query_with_exclusion(include_mask: bigint, exclude_mask: bigint, max_results: number): number;
|
|
3690
|
+
/**
|
|
3691
|
+
* 获取实体的组件掩码
|
|
3692
|
+
*/
|
|
3693
|
+
get_entity_mask(entity_id: number): bigint;
|
|
3694
|
+
/**
|
|
3695
|
+
* 检查实体是否存在
|
|
3696
|
+
*/
|
|
3697
|
+
entity_exists(entity_id: number): boolean;
|
|
3698
|
+
/**
|
|
3699
|
+
* 获取实体数量
|
|
3700
|
+
*/
|
|
3701
|
+
get_entity_count(): number;
|
|
3702
|
+
/**
|
|
3703
|
+
* 获取性能统计信息
|
|
3704
|
+
*/
|
|
3705
|
+
get_performance_stats(): Array<any>;
|
|
3706
|
+
/**
|
|
3707
|
+
* 清理所有数据
|
|
3708
|
+
*/
|
|
3709
|
+
clear(): void;
|
|
3710
|
+
/**
|
|
3711
|
+
* 重建查询缓存
|
|
3712
|
+
*/
|
|
3713
|
+
rebuild_query_cache(): void;
|
|
3714
|
+
}
|
|
3715
|
+
|
|
3716
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
3717
|
+
|
|
3718
|
+
export interface InitOutput {
|
|
3719
|
+
readonly memory: WebAssembly.Memory;
|
|
3720
|
+
readonly __wbg_ecscore_free: (a: number, b: number) => void;
|
|
3721
|
+
readonly ecscore_new: () => number;
|
|
3722
|
+
readonly ecscore_create_entity: (a: number) => number;
|
|
3723
|
+
readonly ecscore_destroy_entity: (a: number, b: number) => number;
|
|
3724
|
+
readonly ecscore_update_entity_mask: (a: number, b: number, c: bigint) => void;
|
|
3725
|
+
readonly ecscore_batch_update_masks: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
3726
|
+
readonly ecscore_query_entities: (a: number, b: bigint, c: number) => number;
|
|
3727
|
+
readonly ecscore_get_query_result_count: (a: number) => number;
|
|
3728
|
+
readonly ecscore_query_cached: (a: number, b: bigint) => number;
|
|
3729
|
+
readonly ecscore_get_cached_query_count: (a: number, b: bigint) => number;
|
|
3730
|
+
readonly ecscore_query_multiple_components: (a: number, b: number, c: number, d: number) => number;
|
|
3731
|
+
readonly ecscore_query_with_exclusion: (a: number, b: bigint, c: bigint, d: number) => number;
|
|
3732
|
+
readonly ecscore_get_entity_mask: (a: number, b: number) => bigint;
|
|
3733
|
+
readonly ecscore_entity_exists: (a: number, b: number) => number;
|
|
3734
|
+
readonly ecscore_get_entity_count: (a: number) => number;
|
|
3735
|
+
readonly ecscore_get_performance_stats: (a: number) => any;
|
|
3736
|
+
readonly ecscore_clear: (a: number) => void;
|
|
3737
|
+
readonly ecscore_rebuild_query_cache: (a: number) => void;
|
|
3738
|
+
readonly create_component_mask: (a: number, b: number) => bigint;
|
|
3739
|
+
readonly mask_contains_component: (a: bigint, b: number) => number;
|
|
3740
|
+
readonly main: () => void;
|
|
3741
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
3742
|
+
readonly __externref_table_alloc: () => number;
|
|
3743
|
+
readonly __wbindgen_export_2: WebAssembly.Table;
|
|
3744
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
3745
|
+
readonly __wbindgen_start: () => void;
|
|
3746
|
+
}
|
|
3747
|
+
|
|
3748
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
3749
|
+
/**
|
|
3750
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
3751
|
+
* a precompiled `WebAssembly.Module`.
|
|
3752
|
+
*
|
|
3753
|
+
* @param {{ module: SyncInitInput }}
|
|
3754
|
+
|
|
3755
|
+
export function initSync(module: { module: SyncInitInput }
|
|
3756
|
+
|
|
3757
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
3758
|
+
|
|
3759
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
3760
|
+
|