@esengine/ecs-framework 2.1.48 → 2.1.49
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.cjs +2 -2
- package/index.cjs.map +1 -1
- package/index.d.ts +95 -828
- package/index.es5.js +2 -2
- package/index.es5.js.map +1 -1
- package/index.mjs +2 -2
- package/index.mjs.map +1 -1
- package/index.umd.js +2 -2
- package/index.umd.js.map +1 -1
- package/package.json +2 -7
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @esengine/ecs-framework v2.1.
|
|
2
|
+
* @esengine/ecs-framework v2.1.49
|
|
3
3
|
* TypeScript definitions
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -557,7 +557,10 @@ interface IComponent {
|
|
|
557
557
|
onEnabled(): void;
|
|
558
558
|
/** 组件禁用时的回调 */
|
|
559
559
|
onDisabled(): void;
|
|
560
|
-
/**
|
|
560
|
+
/**
|
|
561
|
+
* 更新组件
|
|
562
|
+
* @deprecated 不符合ECS架构规范,建议使用EntitySystem来处理更新逻辑
|
|
563
|
+
*/
|
|
561
564
|
update(): void;
|
|
562
565
|
}
|
|
563
566
|
/**
|
|
@@ -1053,6 +1056,8 @@ declare abstract class Component implements IComponent {
|
|
|
1053
1056
|
* 更新顺序
|
|
1054
1057
|
*
|
|
1055
1058
|
* 决定组件在更新循环中的执行顺序。
|
|
1059
|
+
*
|
|
1060
|
+
* @see EntitySystem
|
|
1056
1061
|
*/
|
|
1057
1062
|
private _updateOrder;
|
|
1058
1063
|
/**
|
|
@@ -1066,6 +1071,7 @@ declare abstract class Component implements IComponent {
|
|
|
1066
1071
|
*
|
|
1067
1072
|
* 组件的实际启用状态取决于自身状态和所属实体的状态。
|
|
1068
1073
|
*
|
|
1074
|
+
* @deprecated 不符合ECS架构规范,建议自己实现DisabledComponent标记组件替代
|
|
1069
1075
|
* @returns 如果组件和所属实体都启用则返回true
|
|
1070
1076
|
*/
|
|
1071
1077
|
get enabled(): boolean;
|
|
@@ -1074,18 +1080,23 @@ declare abstract class Component implements IComponent {
|
|
|
1074
1080
|
*
|
|
1075
1081
|
* 当状态改变时会触发相应的生命周期回调。
|
|
1076
1082
|
*
|
|
1083
|
+
* @deprecated 不符合ECS架构规范,建议自己实现DisabledComponent标记组件替代
|
|
1077
1084
|
* @param value - 新的启用状态
|
|
1078
1085
|
*/
|
|
1079
1086
|
set enabled(value: boolean);
|
|
1080
1087
|
/**
|
|
1081
1088
|
* 获取更新顺序
|
|
1082
1089
|
*
|
|
1090
|
+
* @deprecated 不符合ECS架构规范,更新顺序应该由EntitySystem管理
|
|
1091
|
+
* @see EntitySystem
|
|
1083
1092
|
* @returns 组件的更新顺序值
|
|
1084
1093
|
*/
|
|
1085
1094
|
get updateOrder(): number;
|
|
1086
1095
|
/**
|
|
1087
1096
|
* 设置更新顺序
|
|
1088
1097
|
*
|
|
1098
|
+
* @deprecated 不符合ECS架构规范,更新顺序应该由EntitySystem管理
|
|
1099
|
+
* @see EntitySystem
|
|
1089
1100
|
* @param value - 新的更新顺序值
|
|
1090
1101
|
*/
|
|
1091
1102
|
set updateOrder(value: number);
|
|
@@ -1116,8 +1127,7 @@ declare abstract class Component implements IComponent {
|
|
|
1116
1127
|
/**
|
|
1117
1128
|
* 更新组件
|
|
1118
1129
|
*
|
|
1119
|
-
*
|
|
1120
|
-
* 子类应该重写此方法来实现具体的更新逻辑。
|
|
1130
|
+
* @deprecated 不符合ECS架构规范,建议使用EntitySystem来处理更新逻辑
|
|
1121
1131
|
*/
|
|
1122
1132
|
update(): void;
|
|
1123
1133
|
}
|
|
@@ -1828,14 +1838,16 @@ declare class EventBus implements IEventBus {
|
|
|
1828
1838
|
* 发射事件
|
|
1829
1839
|
* @param eventType 事件类型
|
|
1830
1840
|
* @param data 事件数据
|
|
1841
|
+
* @param enhance 是否增强事件数据(添加timestamp、eventId等),默认false提升性能
|
|
1831
1842
|
*/
|
|
1832
|
-
emit<T>(eventType: string, data: T): void;
|
|
1843
|
+
emit<T>(eventType: string, data: T, enhance?: boolean): void;
|
|
1833
1844
|
/**
|
|
1834
1845
|
* 异步发射事件
|
|
1835
1846
|
* @param eventType 事件类型
|
|
1836
1847
|
* @param data 事件数据
|
|
1848
|
+
* @param enhance 是否增强事件数据(添加timestamp、eventId等),默认false提升性能
|
|
1837
1849
|
*/
|
|
1838
|
-
emitAsync<T>(eventType: string, data: T): Promise<void>;
|
|
1850
|
+
emitAsync<T>(eventType: string, data: T, enhance?: boolean): Promise<void>;
|
|
1839
1851
|
/**
|
|
1840
1852
|
* 监听事件
|
|
1841
1853
|
* @param eventType 事件类型
|
|
@@ -1987,7 +1999,7 @@ declare class EventBus implements IEventBus {
|
|
|
1987
1999
|
*/
|
|
1988
2000
|
onPerformanceWarning(handler: (data: IPerformanceEventData) => void, config?: IEventListenerConfig): string;
|
|
1989
2001
|
/**
|
|
1990
|
-
*
|
|
2002
|
+
* 验证事件类型(仅在debug模式下执行,提升性能)
|
|
1991
2003
|
* @param eventType 事件类型
|
|
1992
2004
|
*/
|
|
1993
2005
|
private validateEventType;
|
|
@@ -2043,8 +2055,13 @@ declare class EntityList {
|
|
|
2043
2055
|
private _entitiesToAdd;
|
|
2044
2056
|
private _entitiesToRemove;
|
|
2045
2057
|
private _isUpdating;
|
|
2058
|
+
private _enableEntityDirectUpdate;
|
|
2046
2059
|
get count(): number;
|
|
2047
2060
|
constructor(scene: any);
|
|
2061
|
+
/**
|
|
2062
|
+
* 设置是否启用实体直接更新
|
|
2063
|
+
*/
|
|
2064
|
+
setEnableEntityDirectUpdate(enabled: boolean): void;
|
|
2048
2065
|
/**
|
|
2049
2066
|
* 添加实体(立即添加或延迟添加)
|
|
2050
2067
|
* @param entity 要添加的实体
|
|
@@ -2074,7 +2091,7 @@ declare class EntityList {
|
|
|
2074
2091
|
*/
|
|
2075
2092
|
updateLists(): void;
|
|
2076
2093
|
/**
|
|
2077
|
-
*
|
|
2094
|
+
* 更新实体列表和实体
|
|
2078
2095
|
*/
|
|
2079
2096
|
update(): void;
|
|
2080
2097
|
/**
|
|
@@ -2106,7 +2123,7 @@ declare class EntityList {
|
|
|
2106
2123
|
* @param componentType 组件类型
|
|
2107
2124
|
* @returns 找到的所有实体数组
|
|
2108
2125
|
*/
|
|
2109
|
-
findEntitiesWithComponent<T extends Component>(componentType: new (...args:
|
|
2126
|
+
findEntitiesWithComponent<T extends Component>(componentType: new (...args: any[]) => T): Entity[];
|
|
2110
2127
|
/**
|
|
2111
2128
|
* 批量操作:对所有实体执行指定操作
|
|
2112
2129
|
* @param action 要执行的操作
|
|
@@ -2201,7 +2218,7 @@ declare class Matcher {
|
|
|
2201
2218
|
*/
|
|
2202
2219
|
static complex(): Matcher;
|
|
2203
2220
|
/**
|
|
2204
|
-
*
|
|
2221
|
+
* 创建空匙配器
|
|
2205
2222
|
*/
|
|
2206
2223
|
static empty(): Matcher;
|
|
2207
2224
|
/**
|
|
@@ -2500,90 +2517,12 @@ interface Archetype {
|
|
|
2500
2517
|
/** 最后更新时间 */
|
|
2501
2518
|
updatedAt: number;
|
|
2502
2519
|
}
|
|
2503
|
-
/**
|
|
2504
|
-
* 原型查询结果
|
|
2505
|
-
*/
|
|
2506
|
-
interface ArchetypeQueryResult {
|
|
2507
|
-
/** 匹配的原型列表 */
|
|
2508
|
-
archetypes: Archetype[];
|
|
2509
|
-
/** 所有匹配实体的总数 */
|
|
2510
|
-
totalEntities: number;
|
|
2511
|
-
/** 查询执行时间(毫秒) */
|
|
2512
|
-
executionTime: number;
|
|
2513
|
-
/** 是否使用了缓存 */
|
|
2514
|
-
fromCache: boolean;
|
|
2515
|
-
}
|
|
2516
|
-
/**
|
|
2517
|
-
* Archetype系统
|
|
2518
|
-
*
|
|
2519
|
-
* 根据实体的组件组合将实体分组到不同的原型中,提供高效的查询性能。
|
|
2520
|
-
*/
|
|
2521
|
-
declare class ArchetypeSystem {
|
|
2522
|
-
/** 所有原型的映射表 */
|
|
2523
|
-
private _archetypes;
|
|
2524
|
-
/** 实体到原型的映射 */
|
|
2525
|
-
private _entityToArchetype;
|
|
2526
|
-
/** 组件类型到原型的映射 */
|
|
2527
|
-
private _componentToArchetypes;
|
|
2528
|
-
/** 查询缓存 */
|
|
2529
|
-
private _queryCache;
|
|
2530
|
-
private _cacheTimeout;
|
|
2531
|
-
private _maxCacheSize;
|
|
2532
|
-
/**
|
|
2533
|
-
* 添加实体到原型系统
|
|
2534
|
-
*/
|
|
2535
|
-
addEntity(entity: Entity): void;
|
|
2536
|
-
/**
|
|
2537
|
-
* 从原型系统中移除实体
|
|
2538
|
-
*/
|
|
2539
|
-
removeEntity(entity: Entity): void;
|
|
2540
|
-
/**
|
|
2541
|
-
* 查询包含指定组件组合的原型
|
|
2542
|
-
*/
|
|
2543
|
-
queryArchetypes(componentTypes: ComponentType[], operation?: 'AND' | 'OR'): ArchetypeQueryResult;
|
|
2544
|
-
/**
|
|
2545
|
-
* 获取实体所属的原型
|
|
2546
|
-
*/
|
|
2547
|
-
getEntityArchetype(entity: Entity): Archetype | undefined;
|
|
2548
|
-
/**
|
|
2549
|
-
* 获取所有原型
|
|
2550
|
-
*/
|
|
2551
|
-
getAllArchetypes(): Archetype[];
|
|
2552
|
-
/**
|
|
2553
|
-
* 清空所有数据
|
|
2554
|
-
*/
|
|
2555
|
-
clear(): void;
|
|
2556
|
-
/**
|
|
2557
|
-
* 获取实体的组件类型列表
|
|
2558
|
-
*/
|
|
2559
|
-
private getEntityComponentTypes;
|
|
2560
|
-
/**
|
|
2561
|
-
* 生成原型ID
|
|
2562
|
-
*/
|
|
2563
|
-
private generateArchetypeId;
|
|
2564
|
-
/**
|
|
2565
|
-
* 创建新原型
|
|
2566
|
-
*/
|
|
2567
|
-
private createArchetype;
|
|
2568
|
-
/**
|
|
2569
|
-
* 检查原型是否包含所有指定组件
|
|
2570
|
-
*/
|
|
2571
|
-
private archetypeContainsAllComponents;
|
|
2572
|
-
/**
|
|
2573
|
-
* 更新组件索引
|
|
2574
|
-
*/
|
|
2575
|
-
private updateComponentIndexes;
|
|
2576
|
-
/**
|
|
2577
|
-
* 使查询缓存失效
|
|
2578
|
-
*/
|
|
2579
|
-
private invalidateQueryCache;
|
|
2580
|
-
}
|
|
2581
2520
|
|
|
2582
2521
|
/**
|
|
2583
2522
|
* 实体查询结果接口
|
|
2584
2523
|
*/
|
|
2585
2524
|
interface QueryResult {
|
|
2586
|
-
entities: Entity[];
|
|
2525
|
+
entities: readonly Entity[];
|
|
2587
2526
|
count: number;
|
|
2588
2527
|
/** 查询执行时间(毫秒) */
|
|
2589
2528
|
executionTime: number;
|
|
@@ -2615,15 +2554,15 @@ declare class QuerySystem {
|
|
|
2615
2554
|
private _logger;
|
|
2616
2555
|
private entities;
|
|
2617
2556
|
private entityIndex;
|
|
2618
|
-
private indexDirty;
|
|
2619
2557
|
private _version;
|
|
2620
2558
|
private queryCache;
|
|
2621
2559
|
private cacheMaxSize;
|
|
2622
2560
|
private cacheTimeout;
|
|
2623
|
-
private
|
|
2561
|
+
private componentNameCache;
|
|
2562
|
+
private cacheKeyCache;
|
|
2563
|
+
private componentMaskCache;
|
|
2624
2564
|
private componentIndexManager;
|
|
2625
2565
|
private archetypeSystem;
|
|
2626
|
-
private dirtyTrackingSystem;
|
|
2627
2566
|
private queryStats;
|
|
2628
2567
|
constructor();
|
|
2629
2568
|
/**
|
|
@@ -2672,9 +2611,13 @@ declare class QuerySystem {
|
|
|
2672
2611
|
*/
|
|
2673
2612
|
removeEntity(entity: Entity): void;
|
|
2674
2613
|
/**
|
|
2675
|
-
*
|
|
2614
|
+
* 将实体添加到各种索引中
|
|
2676
2615
|
*/
|
|
2677
2616
|
private addEntityToIndexes;
|
|
2617
|
+
private createAndSetMaskIndex;
|
|
2618
|
+
private createAndSetComponentIndex;
|
|
2619
|
+
private createAndSetTagIndex;
|
|
2620
|
+
private createAndSetNameIndex;
|
|
2678
2621
|
/**
|
|
2679
2622
|
* 从各种索引中移除实体
|
|
2680
2623
|
*/
|
|
@@ -2812,37 +2755,20 @@ declare class QuerySystem {
|
|
|
2812
2755
|
*/
|
|
2813
2756
|
private clearQueryCache;
|
|
2814
2757
|
/**
|
|
2815
|
-
*
|
|
2816
|
-
*
|
|
2817
|
-
* 用于外部调用清理缓存,通常在批量操作后使用。
|
|
2758
|
+
* 高效的缓存键生成
|
|
2818
2759
|
*/
|
|
2819
|
-
|
|
2760
|
+
private generateCacheKey;
|
|
2820
2761
|
/**
|
|
2821
|
-
*
|
|
2822
|
-
*
|
|
2823
|
-
* 对大量实体进行批量组件更新操作。
|
|
2762
|
+
* 清理查询缓存
|
|
2824
2763
|
*
|
|
2825
|
-
*
|
|
2826
|
-
*
|
|
2827
|
-
* @example
|
|
2828
|
-
* ```typescript
|
|
2829
|
-
* // 批量更新实体的组件配置
|
|
2830
|
-
* const updates = [
|
|
2831
|
-
* { entityId: 1, componentMask: BigInt(0b1011) },
|
|
2832
|
-
* { entityId: 2, componentMask: BigInt(0b1101) }
|
|
2833
|
-
* ];
|
|
2834
|
-
* querySystem.batchUpdateComponents(updates);
|
|
2835
|
-
* ```
|
|
2764
|
+
* 用于外部调用清理缓存,通常在批量操作后使用。
|
|
2836
2765
|
*/
|
|
2837
|
-
|
|
2838
|
-
entityId: number;
|
|
2839
|
-
componentMask: bigint;
|
|
2840
|
-
}>): void;
|
|
2766
|
+
clearCache(): void;
|
|
2841
2767
|
/**
|
|
2842
2768
|
* 创建组件掩码
|
|
2843
2769
|
*
|
|
2844
2770
|
* 根据组件类型列表生成对应的位掩码。
|
|
2845
|
-
*
|
|
2771
|
+
* 使用缓存避免重复计算。
|
|
2846
2772
|
*
|
|
2847
2773
|
* @param componentTypes 组件类型列表
|
|
2848
2774
|
* @returns 生成的位掩码
|
|
@@ -2855,7 +2781,7 @@ declare class QuerySystem {
|
|
|
2855
2781
|
/**
|
|
2856
2782
|
* 获取所有实体
|
|
2857
2783
|
*/
|
|
2858
|
-
getAllEntities(): Entity[];
|
|
2784
|
+
getAllEntities(): readonly Entity[];
|
|
2859
2785
|
/**
|
|
2860
2786
|
* 获取系统统计信息
|
|
2861
2787
|
*
|
|
@@ -2884,39 +2810,12 @@ declare class QuerySystem {
|
|
|
2884
2810
|
optimizationStats: {
|
|
2885
2811
|
componentIndex: any;
|
|
2886
2812
|
archetypeSystem: any;
|
|
2887
|
-
dirtyTracking: any;
|
|
2888
2813
|
};
|
|
2889
2814
|
cacheStats: {
|
|
2890
2815
|
size: number;
|
|
2891
2816
|
hitRate: string;
|
|
2892
2817
|
};
|
|
2893
2818
|
};
|
|
2894
|
-
/**
|
|
2895
|
-
* 配置脏标记系统
|
|
2896
|
-
*
|
|
2897
|
-
* @param batchSize 批处理大小
|
|
2898
|
-
* @param maxProcessingTime 最大处理时间
|
|
2899
|
-
*/
|
|
2900
|
-
configureDirtyTracking(batchSize: number, maxProcessingTime: number): void;
|
|
2901
|
-
/**
|
|
2902
|
-
* 手动触发性能优化
|
|
2903
|
-
*/
|
|
2904
|
-
optimizePerformance(): void;
|
|
2905
|
-
/**
|
|
2906
|
-
* 开始新的帧
|
|
2907
|
-
*/
|
|
2908
|
-
beginFrame(): void;
|
|
2909
|
-
/**
|
|
2910
|
-
* 结束当前帧
|
|
2911
|
-
*/
|
|
2912
|
-
endFrame(): void;
|
|
2913
|
-
/**
|
|
2914
|
-
* 标记实体组件已修改(用于脏标记追踪)
|
|
2915
|
-
*
|
|
2916
|
-
* @param entity 修改的实体
|
|
2917
|
-
* @param componentTypes 修改的组件类型
|
|
2918
|
-
*/
|
|
2919
|
-
markEntityDirty(entity: Entity, componentTypes: ComponentType[]): void;
|
|
2920
2819
|
/**
|
|
2921
2820
|
* 获取实体所属的原型信息
|
|
2922
2821
|
*
|
|
@@ -3299,7 +3198,7 @@ declare class Scene implements IScene {
|
|
|
3299
3198
|
*/
|
|
3300
3199
|
end(): void;
|
|
3301
3200
|
/**
|
|
3302
|
-
*
|
|
3201
|
+
* 更新场景
|
|
3303
3202
|
*/
|
|
3304
3203
|
update(): void;
|
|
3305
3204
|
/**
|
|
@@ -3307,6 +3206,11 @@ declare class Scene implements IScene {
|
|
|
3307
3206
|
* @param name 实体名称
|
|
3308
3207
|
*/
|
|
3309
3208
|
createEntity(name: string): Entity;
|
|
3209
|
+
/**
|
|
3210
|
+
* 清除所有EntitySystem的实体缓存
|
|
3211
|
+
* 当实体或组件发生变化时调用
|
|
3212
|
+
*/
|
|
3213
|
+
clearSystemEntityCaches(): void;
|
|
3310
3214
|
/**
|
|
3311
3215
|
* 在场景的实体列表中添加一个实体
|
|
3312
3216
|
* @param entity 要添加的实体
|
|
@@ -3364,6 +3268,11 @@ declare class Scene implements IScene {
|
|
|
3364
3268
|
* @param processor 要删除的处理器
|
|
3365
3269
|
*/
|
|
3366
3270
|
removeEntityProcessor(processor: EntitySystem): void;
|
|
3271
|
+
/**
|
|
3272
|
+
* 从场景中删除系统(removeEntityProcessor的别名)
|
|
3273
|
+
* @param system 系统
|
|
3274
|
+
*/
|
|
3275
|
+
removeSystem(system: EntitySystem): void;
|
|
3367
3276
|
/**
|
|
3368
3277
|
* 获取指定类型的EntitySystem处理器
|
|
3369
3278
|
* @param type 处理器类型
|
|
@@ -3413,7 +3322,7 @@ declare class Scene implements IScene {
|
|
|
3413
3322
|
* super(Transform, Velocity);
|
|
3414
3323
|
* }
|
|
3415
3324
|
*
|
|
3416
|
-
* protected process(entities: Entity[]): void {
|
|
3325
|
+
* protected process(entities: readonly Entity[]): void {
|
|
3417
3326
|
* for (const entity of entities) {
|
|
3418
3327
|
* const transform = entity.getComponent(Transform);
|
|
3419
3328
|
* const velocity = entity.getComponent(Velocity);
|
|
@@ -3430,10 +3339,20 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3430
3339
|
private _systemName;
|
|
3431
3340
|
private _initialized;
|
|
3432
3341
|
private _matcher;
|
|
3433
|
-
private _trackedEntities;
|
|
3434
3342
|
private _eventListeners;
|
|
3343
|
+
private _scene;
|
|
3344
|
+
/**
|
|
3345
|
+
* 实体ID映射缓存
|
|
3346
|
+
*/
|
|
3347
|
+
private _entityIdMap;
|
|
3348
|
+
private _entityIdMapVersion;
|
|
3349
|
+
private _entityIdMapSize;
|
|
3435
3350
|
/**
|
|
3436
|
-
*
|
|
3351
|
+
* 统一的实体缓存管理器
|
|
3352
|
+
*/
|
|
3353
|
+
private _entityCache;
|
|
3354
|
+
/**
|
|
3355
|
+
* 获取系统处理的实体列表
|
|
3437
3356
|
*/
|
|
3438
3357
|
get entities(): readonly Entity[];
|
|
3439
3358
|
/**
|
|
@@ -3454,7 +3373,6 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3454
3373
|
*/
|
|
3455
3374
|
get systemName(): string;
|
|
3456
3375
|
constructor(matcher?: Matcher);
|
|
3457
|
-
private _scene;
|
|
3458
3376
|
/**
|
|
3459
3377
|
* 这个系统所属的场景
|
|
3460
3378
|
*/
|
|
@@ -3481,6 +3399,11 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3481
3399
|
* 子类可以重写此方法进行初始化操作。
|
|
3482
3400
|
*/
|
|
3483
3401
|
protected onInitialize(): void;
|
|
3402
|
+
/**
|
|
3403
|
+
* 清除实体缓存(内部使用)
|
|
3404
|
+
* 当Scene中的实体发生变化时调用
|
|
3405
|
+
*/
|
|
3406
|
+
clearEntityCache(): void;
|
|
3484
3407
|
/**
|
|
3485
3408
|
* 重置系统状态
|
|
3486
3409
|
*
|
|
@@ -3509,20 +3432,22 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3509
3432
|
private extractEntityIds;
|
|
3510
3433
|
/**
|
|
3511
3434
|
* ID集合交集运算
|
|
3512
|
-
*
|
|
3513
|
-
* 使用单次扫描算法,选择较小集合进行迭代以提高效率
|
|
3514
3435
|
*/
|
|
3515
3436
|
private intersectIdSets;
|
|
3516
3437
|
/**
|
|
3517
3438
|
* ID集合差集运算
|
|
3518
|
-
*
|
|
3519
|
-
* 使用单次扫描算法计算setA - setB
|
|
3520
3439
|
*/
|
|
3521
3440
|
private differenceIdSets;
|
|
3441
|
+
/**
|
|
3442
|
+
* 获取或构建实体ID映射
|
|
3443
|
+
*/
|
|
3444
|
+
private getEntityIdMap;
|
|
3445
|
+
/**
|
|
3446
|
+
* 重建实体ID映射
|
|
3447
|
+
*/
|
|
3448
|
+
private rebuildEntityIdMap;
|
|
3522
3449
|
/**
|
|
3523
3450
|
* 从ID集合构建Entity数组
|
|
3524
|
-
*
|
|
3525
|
-
* 先构建ID到Entity的映射,然后根据ID集合构建结果数组
|
|
3526
3451
|
*/
|
|
3527
3452
|
private idSetToEntityArray;
|
|
3528
3453
|
/**
|
|
@@ -3533,14 +3458,10 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3533
3458
|
private executeComplexQuery;
|
|
3534
3459
|
/**
|
|
3535
3460
|
* 更新系统
|
|
3536
|
-
*
|
|
3537
|
-
* 在每帧调用,处理系统的主要逻辑。
|
|
3538
3461
|
*/
|
|
3539
3462
|
update(): void;
|
|
3540
3463
|
/**
|
|
3541
3464
|
* 后期更新系统
|
|
3542
|
-
*
|
|
3543
|
-
* 在所有系统的update方法执行完毕后调用。
|
|
3544
3465
|
*/
|
|
3545
3466
|
lateUpdate(): void;
|
|
3546
3467
|
/**
|
|
@@ -3556,7 +3477,7 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3556
3477
|
*
|
|
3557
3478
|
* @param entities 要处理的实体列表
|
|
3558
3479
|
*/
|
|
3559
|
-
protected process(entities: Entity[]): void;
|
|
3480
|
+
protected process(entities: readonly Entity[]): void;
|
|
3560
3481
|
/**
|
|
3561
3482
|
* 后期处理实体列表
|
|
3562
3483
|
*
|
|
@@ -3564,7 +3485,7 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3564
3485
|
*
|
|
3565
3486
|
* @param entities 要处理的实体列表
|
|
3566
3487
|
*/
|
|
3567
|
-
protected lateProcess(_entities: Entity[]): void;
|
|
3488
|
+
protected lateProcess(_entities: readonly Entity[]): void;
|
|
3568
3489
|
/**
|
|
3569
3490
|
* 系统处理完毕后调用
|
|
3570
3491
|
*
|
|
@@ -3776,6 +3697,10 @@ interface IScene {
|
|
|
3776
3697
|
* 创建实体
|
|
3777
3698
|
*/
|
|
3778
3699
|
createEntity(name: string): Entity;
|
|
3700
|
+
/**
|
|
3701
|
+
* 清除所有EntitySystem的实体缓存
|
|
3702
|
+
*/
|
|
3703
|
+
clearSystemEntityCaches(): void;
|
|
3779
3704
|
/**
|
|
3780
3705
|
* 添加实体
|
|
3781
3706
|
*/
|
|
@@ -3830,6 +3755,11 @@ interface ISceneConfig {
|
|
|
3830
3755
|
* 调试配置
|
|
3831
3756
|
*/
|
|
3832
3757
|
debug?: boolean;
|
|
3758
|
+
/**
|
|
3759
|
+
* 是否启用实体直接更新
|
|
3760
|
+
* @default false
|
|
3761
|
+
*/
|
|
3762
|
+
enableEntityDirectUpdate?: boolean;
|
|
3833
3763
|
}
|
|
3834
3764
|
|
|
3835
3765
|
/**
|
|
@@ -4519,11 +4449,11 @@ declare class ECSFluentAPI {
|
|
|
4519
4449
|
*/
|
|
4520
4450
|
query(): QueryBuilder;
|
|
4521
4451
|
/**
|
|
4522
|
-
*
|
|
4452
|
+
* 查找实体
|
|
4523
4453
|
* @param componentTypes 组件类型
|
|
4524
4454
|
* @returns 实体数组
|
|
4525
4455
|
*/
|
|
4526
|
-
find(...componentTypes: ComponentType[]): Entity[];
|
|
4456
|
+
find(...componentTypes: ComponentType[]): readonly Entity[];
|
|
4527
4457
|
/**
|
|
4528
4458
|
* 查找第一个匹配的实体
|
|
4529
4459
|
* @param componentTypes 组件类型
|
|
@@ -6524,669 +6454,6 @@ declare function getComponentInstanceTypeName(component: Component): string;
|
|
|
6524
6454
|
*/
|
|
6525
6455
|
declare function getSystemInstanceTypeName(system: EntitySystem): string;
|
|
6526
6456
|
|
|
6527
|
-
/**
|
|
6528
|
-
* 实体查询构建器
|
|
6529
|
-
*
|
|
6530
|
-
* 提供流式API来构建复杂的实体查询条件。支持组件过滤、标签过滤、状态过滤和自定义条件。
|
|
6531
|
-
*
|
|
6532
|
-
* @example
|
|
6533
|
-
* ```typescript
|
|
6534
|
-
* const results = entityManager.query()
|
|
6535
|
-
* .withAll(PositionComponent, HealthComponent)
|
|
6536
|
-
* .without(VelocityComponent)
|
|
6537
|
-
* .withTag(1)
|
|
6538
|
-
* .active()
|
|
6539
|
-
* .where(entity => entity.name.startsWith("Player"))
|
|
6540
|
-
* .execute();
|
|
6541
|
-
* ```
|
|
6542
|
-
*/
|
|
6543
|
-
declare class EntityQueryBuilder {
|
|
6544
|
-
private entityManager;
|
|
6545
|
-
/** 必须包含的组件类型 */
|
|
6546
|
-
private _allComponents;
|
|
6547
|
-
/** 至少包含一个的组件类型 */
|
|
6548
|
-
private _anyComponents;
|
|
6549
|
-
/** 不能包含的组件类型 */
|
|
6550
|
-
private _withoutComponents;
|
|
6551
|
-
/** 必须包含的标签 */
|
|
6552
|
-
private _withTags;
|
|
6553
|
-
/** 不能包含的标签 */
|
|
6554
|
-
private _withoutTags;
|
|
6555
|
-
/** 是否只查询激活状态的实体 */
|
|
6556
|
-
private _activeOnly;
|
|
6557
|
-
/** 是否只查询启用状态的实体 */
|
|
6558
|
-
private _enabledOnly;
|
|
6559
|
-
/** 自定义过滤条件 */
|
|
6560
|
-
private _customPredicates;
|
|
6561
|
-
/**
|
|
6562
|
-
* 创建查询构建器实例
|
|
6563
|
-
* @param entityManager 实体管理器实例
|
|
6564
|
-
*/
|
|
6565
|
-
constructor(entityManager: EntityManager);
|
|
6566
|
-
/**
|
|
6567
|
-
* 添加必须包含的组件条件
|
|
6568
|
-
*
|
|
6569
|
-
* 返回的实体必须包含所有指定的组件类型。
|
|
6570
|
-
*
|
|
6571
|
-
* @param componentTypes 组件类型列表
|
|
6572
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6573
|
-
*/
|
|
6574
|
-
withAll(...componentTypes: ComponentType[]): EntityQueryBuilder;
|
|
6575
|
-
/**
|
|
6576
|
-
* 添加至少包含一个的组件条件
|
|
6577
|
-
*
|
|
6578
|
-
* 返回的实体必须至少包含其中一个指定的组件类型。
|
|
6579
|
-
*
|
|
6580
|
-
* @param componentTypes 组件类型列表
|
|
6581
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6582
|
-
*/
|
|
6583
|
-
withAny(...componentTypes: ComponentType[]): EntityQueryBuilder;
|
|
6584
|
-
/**
|
|
6585
|
-
* 添加不能包含的组件条件
|
|
6586
|
-
*
|
|
6587
|
-
* 返回的实体不能包含任何指定的组件类型。
|
|
6588
|
-
*
|
|
6589
|
-
* @param componentTypes 组件类型列表
|
|
6590
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6591
|
-
*/
|
|
6592
|
-
without(...componentTypes: ComponentType[]): EntityQueryBuilder;
|
|
6593
|
-
/**
|
|
6594
|
-
* 添加必须包含的标签条件
|
|
6595
|
-
*
|
|
6596
|
-
* 返回的实体必须具有指定的标签。
|
|
6597
|
-
*
|
|
6598
|
-
* @param tag 标签值
|
|
6599
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6600
|
-
*/
|
|
6601
|
-
withTag(tag: number): EntityQueryBuilder;
|
|
6602
|
-
/**
|
|
6603
|
-
* 添加不能包含的标签条件
|
|
6604
|
-
*
|
|
6605
|
-
* 返回的实体不能具有指定的标签。
|
|
6606
|
-
*
|
|
6607
|
-
* @param tag 标签值
|
|
6608
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6609
|
-
*/
|
|
6610
|
-
withoutTag(tag: number): EntityQueryBuilder;
|
|
6611
|
-
/**
|
|
6612
|
-
* 添加激活状态过滤条件
|
|
6613
|
-
*
|
|
6614
|
-
* 返回的实体必须处于激活状态(active = true)。
|
|
6615
|
-
*
|
|
6616
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6617
|
-
*/
|
|
6618
|
-
active(): EntityQueryBuilder;
|
|
6619
|
-
/**
|
|
6620
|
-
* 添加启用状态过滤条件
|
|
6621
|
-
*
|
|
6622
|
-
* 返回的实体必须处于启用状态(enabled = true)。
|
|
6623
|
-
*
|
|
6624
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6625
|
-
*/
|
|
6626
|
-
enabled(): EntityQueryBuilder;
|
|
6627
|
-
/**
|
|
6628
|
-
* 添加自定义过滤条件
|
|
6629
|
-
*
|
|
6630
|
-
* 允许用户定义复杂的过滤逻辑。
|
|
6631
|
-
*
|
|
6632
|
-
* @param predicate 自定义过滤函数,接收实体作为参数,返回布尔值
|
|
6633
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6634
|
-
*
|
|
6635
|
-
* @example
|
|
6636
|
-
* ```typescript
|
|
6637
|
-
* .where(entity => entity.name.startsWith("Player"))
|
|
6638
|
-
* .where(entity => entity.components.length > 5)
|
|
6639
|
-
* ```
|
|
6640
|
-
*/
|
|
6641
|
-
where(predicate: (entity: Entity) => boolean): EntityQueryBuilder;
|
|
6642
|
-
/**
|
|
6643
|
-
* 执行查询并返回所有匹配的实体
|
|
6644
|
-
*
|
|
6645
|
-
* @returns 符合所有查询条件的实体数组
|
|
6646
|
-
*/
|
|
6647
|
-
execute(): Entity[];
|
|
6648
|
-
/**
|
|
6649
|
-
* 执行查询并返回第一个匹配的实体
|
|
6650
|
-
*
|
|
6651
|
-
* @returns 第一个符合查询条件的实体,如果没有找到则返回null
|
|
6652
|
-
*/
|
|
6653
|
-
first(): Entity | null;
|
|
6654
|
-
/**
|
|
6655
|
-
* 执行查询并返回匹配实体的数量
|
|
6656
|
-
*
|
|
6657
|
-
* @returns 符合查询条件的实体数量
|
|
6658
|
-
*/
|
|
6659
|
-
count(): number;
|
|
6660
|
-
/**
|
|
6661
|
-
* 对所有匹配的实体执行指定操作
|
|
6662
|
-
*
|
|
6663
|
-
* @param action 要执行的操作函数,接收匹配的实体作为参数
|
|
6664
|
-
*/
|
|
6665
|
-
forEach(action: (entity: Entity) => void): void;
|
|
6666
|
-
/**
|
|
6667
|
-
* 检查实体是否匹配所有查询条件
|
|
6668
|
-
*
|
|
6669
|
-
* 按优先级顺序检查各种过滤条件,一旦发现不匹配立即返回false。
|
|
6670
|
-
*
|
|
6671
|
-
* @param entity 要检查的实体
|
|
6672
|
-
* @returns 实体是否匹配所有查询条件
|
|
6673
|
-
*/
|
|
6674
|
-
private matchesEntity;
|
|
6675
|
-
}
|
|
6676
|
-
/**
|
|
6677
|
-
* 实体管理器
|
|
6678
|
-
*
|
|
6679
|
-
* 提供统一的实体管理和查询机制,支持高效的实体操作。
|
|
6680
|
-
* 包括实体的创建、销毁、查询和索引管理功能。
|
|
6681
|
-
*
|
|
6682
|
-
* @example
|
|
6683
|
-
* ```typescript
|
|
6684
|
-
* const entityManager = new EntityManager();
|
|
6685
|
-
*
|
|
6686
|
-
* // 创建实体
|
|
6687
|
-
* const player = entityManager.createEntity("Player");
|
|
6688
|
-
*
|
|
6689
|
-
* // 查询实体
|
|
6690
|
-
* const playerEntity = entityManager.getEntityByName("Player");
|
|
6691
|
-
*
|
|
6692
|
-
* // 复杂查询
|
|
6693
|
-
* const results = entityManager.query()
|
|
6694
|
-
* .withAll(HealthComponent, PositionComponent)
|
|
6695
|
-
* .active()
|
|
6696
|
-
* .execute();
|
|
6697
|
-
* ```
|
|
6698
|
-
*/
|
|
6699
|
-
declare class EntityManager {
|
|
6700
|
-
/** 主要实体存储,使用ID作为键 */
|
|
6701
|
-
private _entities;
|
|
6702
|
-
/** 按名称索引的实体映射 */
|
|
6703
|
-
private _entitiesByName;
|
|
6704
|
-
/** 按标签索引的实体映射 */
|
|
6705
|
-
private _entitiesByTag;
|
|
6706
|
-
/** 实体ID分配器 */
|
|
6707
|
-
private _identifierPool;
|
|
6708
|
-
/** 已销毁实体的ID集合 */
|
|
6709
|
-
private _destroyedEntities;
|
|
6710
|
-
/** 性能优化系统 */
|
|
6711
|
-
private _componentIndexManager;
|
|
6712
|
-
private _archetypeSystem;
|
|
6713
|
-
private _dirtyTrackingSystem;
|
|
6714
|
-
/** 事件总线 */
|
|
6715
|
-
private _eventBus;
|
|
6716
|
-
/**
|
|
6717
|
-
* 创建实体管理器实例
|
|
6718
|
-
*
|
|
6719
|
-
* 初始化内部数据结构和ID分配器。
|
|
6720
|
-
*/
|
|
6721
|
-
constructor();
|
|
6722
|
-
/**
|
|
6723
|
-
* 获取实体总数
|
|
6724
|
-
*
|
|
6725
|
-
* @returns 当前管理的实体总数量
|
|
6726
|
-
*/
|
|
6727
|
-
get entityCount(): number;
|
|
6728
|
-
/**
|
|
6729
|
-
* 获取激活状态的实体数量
|
|
6730
|
-
*
|
|
6731
|
-
* 只计算同时满足激活状态且未被销毁的实体。
|
|
6732
|
-
*
|
|
6733
|
-
* @returns 激活状态的实体数量
|
|
6734
|
-
*/
|
|
6735
|
-
get activeEntityCount(): number;
|
|
6736
|
-
/**
|
|
6737
|
-
* 创建新实体
|
|
6738
|
-
*
|
|
6739
|
-
* 分配唯一ID并将实体添加到管理系统中,同时更新相关索引。
|
|
6740
|
-
*
|
|
6741
|
-
* @param name 实体名称,如果未指定则使用时间戳生成默认名称
|
|
6742
|
-
* @returns 创建的实体实例
|
|
6743
|
-
*
|
|
6744
|
-
* @example
|
|
6745
|
-
* ```typescript
|
|
6746
|
-
* const player = entityManager.createEntity("Player");
|
|
6747
|
-
* const enemy = entityManager.createEntity(); // 使用默认名称
|
|
6748
|
-
* ```
|
|
6749
|
-
*/
|
|
6750
|
-
createEntity(name?: string): Entity;
|
|
6751
|
-
/**
|
|
6752
|
-
* 批量创建实体
|
|
6753
|
-
*
|
|
6754
|
-
* 为了优化大量实体创建的性能,批量处理索引更新和事件发射。
|
|
6755
|
-
* 适用于需要创建大量实体的场景,如子弹、粒子等。
|
|
6756
|
-
*
|
|
6757
|
-
* @param count 要创建的实体数量
|
|
6758
|
-
* @param namePrefix 实体名称前缀,默认为 Entity
|
|
6759
|
-
* @param skipEvents 是否跳过事件发射以提升性能,默认为 false
|
|
6760
|
-
* @returns 创建的实体数组
|
|
6761
|
-
*
|
|
6762
|
-
* @example
|
|
6763
|
-
* const bullets = entityManager.createEntitiesBatch(100, "Bullet", true);
|
|
6764
|
-
* const particles = entityManager.createEntitiesBatch(500, "Particle");
|
|
6765
|
-
*/
|
|
6766
|
-
createEntitiesBatch(count: number, namePrefix?: string, skipEvents?: boolean): Entity[];
|
|
6767
|
-
/**
|
|
6768
|
-
* 销毁实体
|
|
6769
|
-
*
|
|
6770
|
-
* 支持通过实体对象、名称或ID来销毁实体。
|
|
6771
|
-
* 会清理所有相关索引并回收ID。
|
|
6772
|
-
*
|
|
6773
|
-
* @param entityOrId 要销毁的实体,可以是实体对象、名称字符串或ID数字
|
|
6774
|
-
* @returns 是否成功销毁实体
|
|
6775
|
-
*
|
|
6776
|
-
* @example
|
|
6777
|
-
* ```typescript
|
|
6778
|
-
* // 通过实体对象销毁
|
|
6779
|
-
* entityManager.destroyEntity(player);
|
|
6780
|
-
*
|
|
6781
|
-
* // 通过名称销毁
|
|
6782
|
-
* entityManager.destroyEntity("Enemy_1");
|
|
6783
|
-
*
|
|
6784
|
-
* // 通过ID销毁
|
|
6785
|
-
* entityManager.destroyEntity(123);
|
|
6786
|
-
* ```
|
|
6787
|
-
*/
|
|
6788
|
-
destroyEntity(entityOrId: Entity | string | number): boolean;
|
|
6789
|
-
/**
|
|
6790
|
-
* 获取所有实体
|
|
6791
|
-
*
|
|
6792
|
-
* 返回当前管理的所有实体的副本数组。
|
|
6793
|
-
*
|
|
6794
|
-
* @returns 所有实体的数组
|
|
6795
|
-
*/
|
|
6796
|
-
getAllEntities(): Entity[];
|
|
6797
|
-
/**
|
|
6798
|
-
* 根据ID获取实体
|
|
6799
|
-
*
|
|
6800
|
-
* 支持字符串和数字类型的ID。
|
|
6801
|
-
*
|
|
6802
|
-
* @param id 实体ID,可以是字符串或数字
|
|
6803
|
-
* @returns 对应的实体,如果不存在则返回null
|
|
6804
|
-
*/
|
|
6805
|
-
getEntity(id: string | number): Entity | null;
|
|
6806
|
-
/**
|
|
6807
|
-
* 根据名称获取实体
|
|
6808
|
-
*
|
|
6809
|
-
* 如果存在多个同名实体,返回第一个找到的实体。
|
|
6810
|
-
*
|
|
6811
|
-
* @param name 实体名称
|
|
6812
|
-
* @returns 匹配的实体,如果不存在则返回null
|
|
6813
|
-
*/
|
|
6814
|
-
getEntityByName(name: string): Entity | null;
|
|
6815
|
-
/**
|
|
6816
|
-
* 根据标签获取实体列表
|
|
6817
|
-
*
|
|
6818
|
-
* 返回所有具有指定标签的实体。
|
|
6819
|
-
*
|
|
6820
|
-
* @param tag 标签值
|
|
6821
|
-
* @returns 具有指定标签的实体数组
|
|
6822
|
-
*/
|
|
6823
|
-
getEntitiesByTag(tag: number): Entity[];
|
|
6824
|
-
/**
|
|
6825
|
-
* 获取包含指定组件的所有实体
|
|
6826
|
-
*
|
|
6827
|
-
* 遍历所有实体,查找包含指定组件类型的实体。
|
|
6828
|
-
*
|
|
6829
|
-
* @param componentType 组件类型
|
|
6830
|
-
* @returns 包含指定组件的实体数组
|
|
6831
|
-
*
|
|
6832
|
-
* @example
|
|
6833
|
-
* ```typescript
|
|
6834
|
-
* const entitiesWithHealth = entityManager.getEntitiesWithComponent(HealthComponent);
|
|
6835
|
-
* ```
|
|
6836
|
-
*/
|
|
6837
|
-
getEntitiesWithComponent<T extends Component>(componentType: ComponentType<T>): Entity[];
|
|
6838
|
-
/**
|
|
6839
|
-
* 创建查询构建器
|
|
6840
|
-
*
|
|
6841
|
-
* 返回一个新的查询构建器实例,用于构建复杂的实体查询。
|
|
6842
|
-
*
|
|
6843
|
-
* @returns 新的查询构建器实例
|
|
6844
|
-
*
|
|
6845
|
-
* @example
|
|
6846
|
-
* ```typescript
|
|
6847
|
-
* const results = entityManager.query()
|
|
6848
|
-
* .withAll(PositionComponent, HealthComponent)
|
|
6849
|
-
* .without(VelocityComponent)
|
|
6850
|
-
* .active()
|
|
6851
|
-
* .execute();
|
|
6852
|
-
* ```
|
|
6853
|
-
*/
|
|
6854
|
-
query(): EntityQueryBuilder;
|
|
6855
|
-
/**
|
|
6856
|
-
* 使用组件索引进行多组件查询
|
|
6857
|
-
*
|
|
6858
|
-
* @param componentTypes 组件类型数组
|
|
6859
|
-
* @param operation 查询操作:'AND' 或 'OR'
|
|
6860
|
-
* @returns 匹配的实体集合
|
|
6861
|
-
*/
|
|
6862
|
-
queryWithComponentIndex(componentTypes: ComponentType[], operation: 'AND' | 'OR'): Set<Entity>;
|
|
6863
|
-
/**
|
|
6864
|
-
* 标记实体组件已修改
|
|
6865
|
-
*
|
|
6866
|
-
* @param entity 修改的实体
|
|
6867
|
-
* @param componentTypes 修改的组件类型
|
|
6868
|
-
*/
|
|
6869
|
-
markEntityDirty(entity: Entity, componentTypes: ComponentType[]): void;
|
|
6870
|
-
/**
|
|
6871
|
-
* 获取性能优化统计信息
|
|
6872
|
-
*/
|
|
6873
|
-
getOptimizationStats(): any;
|
|
6874
|
-
/**
|
|
6875
|
-
* 获取事件总线实例
|
|
6876
|
-
*
|
|
6877
|
-
* 允许外部代码监听和发射ECS相关事件。
|
|
6878
|
-
*
|
|
6879
|
-
* @returns 事件总线实例
|
|
6880
|
-
*/
|
|
6881
|
-
get eventBus(): EventBus;
|
|
6882
|
-
/**
|
|
6883
|
-
* 更新名称索引
|
|
6884
|
-
*
|
|
6885
|
-
* 维护按名称查找实体的索引结构。支持添加和移除操作。
|
|
6886
|
-
*
|
|
6887
|
-
* @param entity 要更新索引的实体
|
|
6888
|
-
* @param isAdd true表示添加到索引,false表示从索引中移除
|
|
6889
|
-
*/
|
|
6890
|
-
private updateNameIndex;
|
|
6891
|
-
/**
|
|
6892
|
-
* 更新标签索引
|
|
6893
|
-
*
|
|
6894
|
-
* 维护按标签查找实体的索引结构。支持添加和移除操作。
|
|
6895
|
-
*
|
|
6896
|
-
* @param entity 要更新索引的实体
|
|
6897
|
-
* @param isAdd true表示添加到索引,false表示从索引中移除
|
|
6898
|
-
*/
|
|
6899
|
-
private updateTagIndex;
|
|
6900
|
-
}
|
|
6901
|
-
|
|
6902
|
-
/**
|
|
6903
|
-
* 索引统计信息
|
|
6904
|
-
*/
|
|
6905
|
-
interface IndexStats {
|
|
6906
|
-
/** 索引大小 */
|
|
6907
|
-
size: number;
|
|
6908
|
-
/** 内存使用量(字节) */
|
|
6909
|
-
memoryUsage: number;
|
|
6910
|
-
/** 查询次数 */
|
|
6911
|
-
queryCount: number;
|
|
6912
|
-
/** 平均查询时间(毫秒) */
|
|
6913
|
-
avgQueryTime: number;
|
|
6914
|
-
/** 最后更新时间 */
|
|
6915
|
-
lastUpdated: number;
|
|
6916
|
-
}
|
|
6917
|
-
/**
|
|
6918
|
-
* 组件索引接口
|
|
6919
|
-
*/
|
|
6920
|
-
interface IComponentIndex {
|
|
6921
|
-
/** 添加实体到索引 */
|
|
6922
|
-
addEntity(entity: Entity): void;
|
|
6923
|
-
/** 从索引中移除实体 */
|
|
6924
|
-
removeEntity(entity: Entity): void;
|
|
6925
|
-
/** 查询包含指定组件的实体 */
|
|
6926
|
-
query(componentType: ComponentType): Set<Entity>;
|
|
6927
|
-
/** 批量查询多个组件 */
|
|
6928
|
-
queryMultiple(componentTypes: ComponentType[], operation: 'AND' | 'OR'): Set<Entity>;
|
|
6929
|
-
/** 清空索引 */
|
|
6930
|
-
clear(): void;
|
|
6931
|
-
/** 获取索引统计信息 */
|
|
6932
|
-
getStats(): IndexStats;
|
|
6933
|
-
}
|
|
6934
|
-
/**
|
|
6935
|
-
* 通用组件索引实现
|
|
6936
|
-
*
|
|
6937
|
-
* 基于Sparse Set算法:
|
|
6938
|
-
* - O(1)的实体添加、删除、查找
|
|
6939
|
-
* - 高效的位运算查询
|
|
6940
|
-
* - 内存紧凑的存储结构
|
|
6941
|
-
* - 缓存友好的遍历性能
|
|
6942
|
-
*/
|
|
6943
|
-
declare class ComponentIndex implements IComponentIndex {
|
|
6944
|
-
/**
|
|
6945
|
-
* 组件稀疏集合
|
|
6946
|
-
*
|
|
6947
|
-
* 核心存储结构,处理所有实体和组件的索引操作。
|
|
6948
|
-
*/
|
|
6949
|
-
private _sparseSet;
|
|
6950
|
-
private _queryCount;
|
|
6951
|
-
private _totalQueryTime;
|
|
6952
|
-
private _lastUpdated;
|
|
6953
|
-
constructor();
|
|
6954
|
-
addEntity(entity: Entity): void;
|
|
6955
|
-
removeEntity(entity: Entity): void;
|
|
6956
|
-
query(componentType: ComponentType): Set<Entity>;
|
|
6957
|
-
queryMultiple(componentTypes: ComponentType[], operation: 'AND' | 'OR'): Set<Entity>;
|
|
6958
|
-
clear(): void;
|
|
6959
|
-
getStats(): IndexStats;
|
|
6960
|
-
}
|
|
6961
|
-
/**
|
|
6962
|
-
* 组件索引管理器
|
|
6963
|
-
*
|
|
6964
|
-
* 使用统一的组件索引实现,自动优化查询性能。
|
|
6965
|
-
*/
|
|
6966
|
-
declare class ComponentIndexManager {
|
|
6967
|
-
private _index;
|
|
6968
|
-
constructor();
|
|
6969
|
-
/**
|
|
6970
|
-
* 添加实体到索引
|
|
6971
|
-
*/
|
|
6972
|
-
addEntity(entity: Entity): void;
|
|
6973
|
-
/**
|
|
6974
|
-
* 从索引中移除实体
|
|
6975
|
-
*/
|
|
6976
|
-
removeEntity(entity: Entity): void;
|
|
6977
|
-
/**
|
|
6978
|
-
* 查询包含指定组件的实体
|
|
6979
|
-
*/
|
|
6980
|
-
query(componentType: ComponentType): Set<Entity>;
|
|
6981
|
-
/**
|
|
6982
|
-
* 批量查询多个组件
|
|
6983
|
-
*/
|
|
6984
|
-
queryMultiple(componentTypes: ComponentType[], operation: 'AND' | 'OR'): Set<Entity>;
|
|
6985
|
-
/**
|
|
6986
|
-
* 获取索引统计信息
|
|
6987
|
-
*/
|
|
6988
|
-
getStats(): IndexStats;
|
|
6989
|
-
/**
|
|
6990
|
-
* 清空索引
|
|
6991
|
-
*/
|
|
6992
|
-
clear(): void;
|
|
6993
|
-
}
|
|
6994
|
-
|
|
6995
|
-
/**
|
|
6996
|
-
* 脏标记类型
|
|
6997
|
-
*/
|
|
6998
|
-
declare enum DirtyFlag {
|
|
6999
|
-
/** 组件数据已修改 */
|
|
7000
|
-
COMPONENT_MODIFIED = 1,
|
|
7001
|
-
/** 组件已添加 */
|
|
7002
|
-
COMPONENT_ADDED = 2,
|
|
7003
|
-
/** 组件已移除 */
|
|
7004
|
-
COMPONENT_REMOVED = 4,
|
|
7005
|
-
/** 实体位置已改变 */
|
|
7006
|
-
TRANSFORM_CHANGED = 8,
|
|
7007
|
-
/** 实体状态已改变 */
|
|
7008
|
-
STATE_CHANGED = 16,
|
|
7009
|
-
/** 自定义标记1 */
|
|
7010
|
-
CUSTOM_1 = 256,
|
|
7011
|
-
/** 自定义标记2 */
|
|
7012
|
-
CUSTOM_2 = 512,
|
|
7013
|
-
/** 自定义标记3 */
|
|
7014
|
-
CUSTOM_3 = 1024,
|
|
7015
|
-
/** 所有标记 */
|
|
7016
|
-
ALL = 4294967295
|
|
7017
|
-
}
|
|
7018
|
-
/**
|
|
7019
|
-
* 脏标记数据
|
|
7020
|
-
*/
|
|
7021
|
-
interface DirtyData {
|
|
7022
|
-
/** 实体引用 */
|
|
7023
|
-
entity: Entity;
|
|
7024
|
-
/** 脏标记位 */
|
|
7025
|
-
flags: number;
|
|
7026
|
-
/** 修改的组件类型列表 */
|
|
7027
|
-
modifiedComponents: Set<ComponentType>;
|
|
7028
|
-
/** 标记时间戳 */
|
|
7029
|
-
timestamp: number;
|
|
7030
|
-
/** 帧编号 */
|
|
7031
|
-
frameNumber: number;
|
|
7032
|
-
}
|
|
7033
|
-
/**
|
|
7034
|
-
* 脏标记监听器
|
|
7035
|
-
*/
|
|
7036
|
-
interface DirtyListener {
|
|
7037
|
-
/** 感兴趣的标记类型 */
|
|
7038
|
-
flags: number;
|
|
7039
|
-
/** 回调函数 */
|
|
7040
|
-
callback: (dirtyData: DirtyData) => void;
|
|
7041
|
-
/** 监听器优先级(数字越小优先级越高) */
|
|
7042
|
-
priority?: number;
|
|
7043
|
-
}
|
|
7044
|
-
/**
|
|
7045
|
-
* 脏标记统计信息
|
|
7046
|
-
*/
|
|
7047
|
-
interface DirtyStats {
|
|
7048
|
-
/** 当前脏实体数量 */
|
|
7049
|
-
dirtyEntityCount: number;
|
|
7050
|
-
/** 总标记次数 */
|
|
7051
|
-
totalMarkings: number;
|
|
7052
|
-
/** 总清理次数 */
|
|
7053
|
-
totalCleanups: number;
|
|
7054
|
-
/** 监听器数量 */
|
|
7055
|
-
listenerCount: number;
|
|
7056
|
-
/** 平均每帧脏实体数量 */
|
|
7057
|
-
avgDirtyPerFrame: number;
|
|
7058
|
-
/** 内存使用量估算 */
|
|
7059
|
-
estimatedMemoryUsage: number;
|
|
7060
|
-
}
|
|
7061
|
-
/**
|
|
7062
|
-
* 脏标记追踪系统
|
|
7063
|
-
*
|
|
7064
|
-
* 提供高效的组件和实体变更追踪,避免不必要的计算和更新。
|
|
7065
|
-
* 支持细粒度的脏标记和批量处理机制。
|
|
7066
|
-
*
|
|
7067
|
-
* @example
|
|
7068
|
-
* ```typescript
|
|
7069
|
-
* const dirtySystem = new DirtyTrackingSystem();
|
|
7070
|
-
*
|
|
7071
|
-
* // 标记实体的位置组件已修改
|
|
7072
|
-
* dirtySystem.markDirty(entity, DirtyFlag.TRANSFORM_CHANGED, [PositionComponent]);
|
|
7073
|
-
*
|
|
7074
|
-
* // 监听位置变化
|
|
7075
|
-
* dirtySystem.addListener({
|
|
7076
|
-
* flags: DirtyFlag.TRANSFORM_CHANGED,
|
|
7077
|
-
* callback: (data) => {
|
|
7078
|
-
* logger.debug('Entity position changed:', data.entity.name);
|
|
7079
|
-
* }
|
|
7080
|
-
* });
|
|
7081
|
-
*
|
|
7082
|
-
* // 处理所有脏标记
|
|
7083
|
-
* dirtySystem.processDirtyEntities();
|
|
7084
|
-
* ```
|
|
7085
|
-
*/
|
|
7086
|
-
declare class DirtyTrackingSystem {
|
|
7087
|
-
private static readonly _logger;
|
|
7088
|
-
/** 脏实体映射表 */
|
|
7089
|
-
private _dirtyEntities;
|
|
7090
|
-
/** 脏标记监听器 */
|
|
7091
|
-
private _listeners;
|
|
7092
|
-
/** 性能统计 */
|
|
7093
|
-
private _stats;
|
|
7094
|
-
/** 当前帧编号 */
|
|
7095
|
-
private _currentFrame;
|
|
7096
|
-
private _batchSize;
|
|
7097
|
-
private _maxProcessingTime;
|
|
7098
|
-
/** 延迟处理队列 */
|
|
7099
|
-
private _processingQueue;
|
|
7100
|
-
private _isProcessing;
|
|
7101
|
-
/**
|
|
7102
|
-
* 标记实体为脏状态
|
|
7103
|
-
*
|
|
7104
|
-
* @param entity 要标记的实体
|
|
7105
|
-
* @param flags 脏标记位
|
|
7106
|
-
* @param modifiedComponents 修改的组件类型列表
|
|
7107
|
-
*/
|
|
7108
|
-
markDirty(entity: Entity, flags: DirtyFlag, modifiedComponents?: ComponentType[]): void;
|
|
7109
|
-
/**
|
|
7110
|
-
* 检查实体是否有指定的脏标记
|
|
7111
|
-
*
|
|
7112
|
-
* @param entity 要检查的实体
|
|
7113
|
-
* @param flags 要检查的标记位
|
|
7114
|
-
* @returns 是否有指定的脏标记
|
|
7115
|
-
*/
|
|
7116
|
-
isDirty(entity: Entity, flags?: DirtyFlag): boolean;
|
|
7117
|
-
/**
|
|
7118
|
-
* 清除实体的脏标记
|
|
7119
|
-
*
|
|
7120
|
-
* @param entity 要清除的实体
|
|
7121
|
-
* @param flags 要清除的标记位,默认清除所有
|
|
7122
|
-
*/
|
|
7123
|
-
clearDirty(entity: Entity, flags?: DirtyFlag): void;
|
|
7124
|
-
/**
|
|
7125
|
-
* 获取所有脏实体
|
|
7126
|
-
*
|
|
7127
|
-
* @param flags 过滤标记位,只返回包含指定标记的实体
|
|
7128
|
-
* @returns 脏实体数据数组
|
|
7129
|
-
*/
|
|
7130
|
-
getDirtyEntities(flags?: DirtyFlag): DirtyData[];
|
|
7131
|
-
/**
|
|
7132
|
-
* 批量处理脏实体
|
|
7133
|
-
*
|
|
7134
|
-
* 使用时间分片的方式处理脏实体,避免单帧卡顿
|
|
7135
|
-
*/
|
|
7136
|
-
processDirtyEntities(): void;
|
|
7137
|
-
/**
|
|
7138
|
-
* 添加脏标记监听器
|
|
7139
|
-
*
|
|
7140
|
-
* @param listener 监听器配置
|
|
7141
|
-
*/
|
|
7142
|
-
addListener(listener: DirtyListener): void;
|
|
7143
|
-
/**
|
|
7144
|
-
* 移除脏标记监听器
|
|
7145
|
-
*
|
|
7146
|
-
* @param callback 要移除的回调函数
|
|
7147
|
-
*/
|
|
7148
|
-
removeListener(callback: (dirtyData: DirtyData) => void): void;
|
|
7149
|
-
/**
|
|
7150
|
-
* 开始新的帧
|
|
7151
|
-
*/
|
|
7152
|
-
beginFrame(): void;
|
|
7153
|
-
/**
|
|
7154
|
-
* 结束当前帧
|
|
7155
|
-
*/
|
|
7156
|
-
endFrame(): void;
|
|
7157
|
-
/**
|
|
7158
|
-
* 获取统计信息
|
|
7159
|
-
*/
|
|
7160
|
-
getStats(): DirtyStats;
|
|
7161
|
-
/**
|
|
7162
|
-
* 清空所有脏标记和统计信息
|
|
7163
|
-
*/
|
|
7164
|
-
clear(): void;
|
|
7165
|
-
/**
|
|
7166
|
-
* 配置批量处理参数
|
|
7167
|
-
*
|
|
7168
|
-
* @param batchSize 每次处理的最大实体数量
|
|
7169
|
-
* @param maxProcessingTime 每帧最大处理时间(毫秒)
|
|
7170
|
-
*/
|
|
7171
|
-
configureBatchProcessing(batchSize: number, maxProcessingTime: number): void;
|
|
7172
|
-
/**
|
|
7173
|
-
* 处理单个脏实体
|
|
7174
|
-
*/
|
|
7175
|
-
private processEntity;
|
|
7176
|
-
/**
|
|
7177
|
-
* 通知监听器
|
|
7178
|
-
*/
|
|
7179
|
-
private notifyListeners;
|
|
7180
|
-
/**
|
|
7181
|
-
* 帧结束时的统计更新
|
|
7182
|
-
*/
|
|
7183
|
-
private onFrameEnd;
|
|
7184
|
-
/**
|
|
7185
|
-
* 估算内存使用量
|
|
7186
|
-
*/
|
|
7187
|
-
private estimateMemoryUsage;
|
|
7188
|
-
}
|
|
7189
|
-
|
|
7190
6457
|
/**
|
|
7191
6458
|
* 组件对象池,用于复用组件实例以减少内存分配
|
|
7192
6459
|
*/
|
|
@@ -7347,5 +6614,5 @@ declare class Time {
|
|
|
7347
6614
|
static checkEvery(interval: number, lastTime: number): boolean;
|
|
7348
6615
|
}
|
|
7349
6616
|
|
|
7350
|
-
export {
|
|
7351
|
-
export type {
|
|
6617
|
+
export { AsyncEventHandler$1 as AsyncEventHandler, BitMask64Utils, Bits, COMPONENT_TYPE_NAME, Colors, Component, ComponentDataCollector, ComponentPool, ComponentPoolManager, ComponentRegistry, ComponentSparseSet, ComponentStorage, ComponentTypeManager, ConsoleLogger, Core, DebugManager, ECSComponent, ECSEventType, ECSFluentAPI, ECSSystem, EVENT_TYPES, Emitter, EnableSoA, Entity, EntityDataCollector, EntityList, EntityProcessorList, EntitySystem, EventBus, EventHandler$1 as EventHandler, EventPriority, EventTypeValidator, Float32, Float64, FuncPack, GlobalEventBus, GlobalManager, HighPrecision, IdentifierPool, Int32, IntervalSystem, LogLevel, Logger, LoggerManager, Matcher, NumberExtension, PassiveSystem, PerformanceDataCollector, PerformanceMonitor, PerformanceWarningType, Pool, PoolManager, ProcessingSystem, QuerySystem, SYSTEM_TYPE_NAME, Scene, SceneDataCollector, SerializeMap, SoAStorage, SparseSet, SystemDataCollector, Time, Timer, TimerManager, TypeSafeEventSystem, TypeUtils, WebSocketManager, World, WorldManager, createECSAPI, createLogger, getComponentInstanceTypeName, getComponentTypeName, getSystemInstanceTypeName, getSystemTypeName, resetLoggerColors, setGlobalLogLevel, setLoggerColors };
|
|
6618
|
+
export type { BitMask64Data, ComponentType$1 as ComponentType, EventListenerConfig, EventStats, IComponent, IComponentDebugData, IComponentEventData, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IWorldConfig, IWorldManagerConfig, LoggerColorConfig, LoggerConfig, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PoolStats };
|