@esengine/ecs-framework 2.1.48 → 2.1.50
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 +711 -859
- 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.50
|
|
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;
|
|
@@ -2020,16 +2032,6 @@ declare class GlobalEventBus {
|
|
|
2020
2032
|
*/
|
|
2021
2033
|
static reset(debugMode?: boolean): EventBus;
|
|
2022
2034
|
}
|
|
2023
|
-
/**
|
|
2024
|
-
* 事件装饰器工厂
|
|
2025
|
-
* 用于自动注册事件监听器
|
|
2026
|
-
*/
|
|
2027
|
-
declare function EventHandler$1(eventType: string, config?: IEventListenerConfig): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
2028
|
-
/**
|
|
2029
|
-
* 异步事件装饰器工厂
|
|
2030
|
-
* 用于自动注册异步事件监听器
|
|
2031
|
-
*/
|
|
2032
|
-
declare function AsyncEventHandler$1(eventType: string, config?: IEventListenerConfig): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
2033
2035
|
|
|
2034
2036
|
/**
|
|
2035
2037
|
* 高性能实体列表管理器
|
|
@@ -2043,8 +2045,13 @@ declare class EntityList {
|
|
|
2043
2045
|
private _entitiesToAdd;
|
|
2044
2046
|
private _entitiesToRemove;
|
|
2045
2047
|
private _isUpdating;
|
|
2048
|
+
private _enableEntityDirectUpdate;
|
|
2046
2049
|
get count(): number;
|
|
2047
2050
|
constructor(scene: any);
|
|
2051
|
+
/**
|
|
2052
|
+
* 设置是否启用实体直接更新
|
|
2053
|
+
*/
|
|
2054
|
+
setEnableEntityDirectUpdate(enabled: boolean): void;
|
|
2048
2055
|
/**
|
|
2049
2056
|
* 添加实体(立即添加或延迟添加)
|
|
2050
2057
|
* @param entity 要添加的实体
|
|
@@ -2074,7 +2081,7 @@ declare class EntityList {
|
|
|
2074
2081
|
*/
|
|
2075
2082
|
updateLists(): void;
|
|
2076
2083
|
/**
|
|
2077
|
-
*
|
|
2084
|
+
* 更新实体列表和实体
|
|
2078
2085
|
*/
|
|
2079
2086
|
update(): void;
|
|
2080
2087
|
/**
|
|
@@ -2106,7 +2113,7 @@ declare class EntityList {
|
|
|
2106
2113
|
* @param componentType 组件类型
|
|
2107
2114
|
* @returns 找到的所有实体数组
|
|
2108
2115
|
*/
|
|
2109
|
-
findEntitiesWithComponent<T extends Component>(componentType: new (...args:
|
|
2116
|
+
findEntitiesWithComponent<T extends Component>(componentType: new (...args: any[]) => T): Entity[];
|
|
2110
2117
|
/**
|
|
2111
2118
|
* 批量操作:对所有实体执行指定操作
|
|
2112
2119
|
* @param action 要执行的操作
|
|
@@ -2201,7 +2208,7 @@ declare class Matcher {
|
|
|
2201
2208
|
*/
|
|
2202
2209
|
static complex(): Matcher;
|
|
2203
2210
|
/**
|
|
2204
|
-
*
|
|
2211
|
+
* 创建空匙配器
|
|
2205
2212
|
*/
|
|
2206
2213
|
static empty(): Matcher;
|
|
2207
2214
|
/**
|
|
@@ -2493,97 +2500,15 @@ interface Archetype {
|
|
|
2493
2500
|
id: ArchetypeId;
|
|
2494
2501
|
/** 包含的组件类型 */
|
|
2495
2502
|
componentTypes: ComponentType[];
|
|
2496
|
-
/**
|
|
2497
|
-
entities: Entity
|
|
2498
|
-
/** 原型创建时间 */
|
|
2499
|
-
createdAt: number;
|
|
2500
|
-
/** 最后更新时间 */
|
|
2501
|
-
updatedAt: number;
|
|
2502
|
-
}
|
|
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;
|
|
2503
|
+
/** 属于该原型的实体集合 */
|
|
2504
|
+
entities: Set<Entity>;
|
|
2580
2505
|
}
|
|
2581
2506
|
|
|
2582
2507
|
/**
|
|
2583
2508
|
* 实体查询结果接口
|
|
2584
2509
|
*/
|
|
2585
2510
|
interface QueryResult {
|
|
2586
|
-
entities: Entity[];
|
|
2511
|
+
entities: readonly Entity[];
|
|
2587
2512
|
count: number;
|
|
2588
2513
|
/** 查询执行时间(毫秒) */
|
|
2589
2514
|
executionTime: number;
|
|
@@ -2594,13 +2519,6 @@ interface QueryResult {
|
|
|
2594
2519
|
* 高性能实体查询系统
|
|
2595
2520
|
*
|
|
2596
2521
|
* 提供快速的实体查询功能,支持按组件类型、标签、名称等多种方式查询实体。
|
|
2597
|
-
* 系统采用多级索引和智能缓存机制,确保在大量实体场景下的查询性能。
|
|
2598
|
-
*
|
|
2599
|
-
* 主要特性:
|
|
2600
|
-
* - 支持单组件和多组件查询
|
|
2601
|
-
* - 自动索引管理和缓存优化
|
|
2602
|
-
* - WebAssembly计算加速(如果可用)
|
|
2603
|
-
* - 详细的性能统计信息
|
|
2604
2522
|
*
|
|
2605
2523
|
* @example
|
|
2606
2524
|
* ```typescript
|
|
@@ -2615,15 +2533,13 @@ declare class QuerySystem {
|
|
|
2615
2533
|
private _logger;
|
|
2616
2534
|
private entities;
|
|
2617
2535
|
private entityIndex;
|
|
2618
|
-
private indexDirty;
|
|
2619
2536
|
private _version;
|
|
2620
2537
|
private queryCache;
|
|
2621
2538
|
private cacheMaxSize;
|
|
2622
2539
|
private cacheTimeout;
|
|
2623
|
-
private
|
|
2540
|
+
private componentMaskCache;
|
|
2624
2541
|
private componentIndexManager;
|
|
2625
2542
|
private archetypeSystem;
|
|
2626
|
-
private dirtyTrackingSystem;
|
|
2627
2543
|
private queryStats;
|
|
2628
2544
|
constructor();
|
|
2629
2545
|
/**
|
|
@@ -2672,9 +2588,21 @@ declare class QuerySystem {
|
|
|
2672
2588
|
*/
|
|
2673
2589
|
removeEntity(entity: Entity): void;
|
|
2674
2590
|
/**
|
|
2675
|
-
*
|
|
2591
|
+
* 更新实体在查询系统中的索引
|
|
2592
|
+
*
|
|
2593
|
+
* 当实体的组件组合发生变化时调用此方法,高效地更新实体在查询系统中的索引。
|
|
2594
|
+
*
|
|
2595
|
+
* @param entity 要更新的实体
|
|
2596
|
+
*/
|
|
2597
|
+
updateEntity(entity: Entity): void;
|
|
2598
|
+
/**
|
|
2599
|
+
* 将实体添加到各种索引中
|
|
2676
2600
|
*/
|
|
2677
2601
|
private addEntityToIndexes;
|
|
2602
|
+
private createAndSetMaskIndex;
|
|
2603
|
+
private createAndSetComponentIndex;
|
|
2604
|
+
private createAndSetTagIndex;
|
|
2605
|
+
private createAndSetNameIndex;
|
|
2678
2606
|
/**
|
|
2679
2607
|
* 从各种索引中移除实体
|
|
2680
2608
|
*/
|
|
@@ -2812,37 +2740,20 @@ declare class QuerySystem {
|
|
|
2812
2740
|
*/
|
|
2813
2741
|
private clearQueryCache;
|
|
2814
2742
|
/**
|
|
2815
|
-
*
|
|
2816
|
-
*
|
|
2817
|
-
* 用于外部调用清理缓存,通常在批量操作后使用。
|
|
2743
|
+
* 高效的缓存键生成
|
|
2818
2744
|
*/
|
|
2819
|
-
|
|
2745
|
+
private generateCacheKey;
|
|
2820
2746
|
/**
|
|
2821
|
-
*
|
|
2822
|
-
*
|
|
2823
|
-
* 对大量实体进行批量组件更新操作。
|
|
2747
|
+
* 清理查询缓存
|
|
2824
2748
|
*
|
|
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
|
-
* ```
|
|
2749
|
+
* 用于外部调用清理缓存,通常在批量操作后使用。
|
|
2836
2750
|
*/
|
|
2837
|
-
|
|
2838
|
-
entityId: number;
|
|
2839
|
-
componentMask: bigint;
|
|
2840
|
-
}>): void;
|
|
2751
|
+
clearCache(): void;
|
|
2841
2752
|
/**
|
|
2842
2753
|
* 创建组件掩码
|
|
2843
2754
|
*
|
|
2844
2755
|
* 根据组件类型列表生成对应的位掩码。
|
|
2845
|
-
*
|
|
2756
|
+
* 使用缓存避免重复计算。
|
|
2846
2757
|
*
|
|
2847
2758
|
* @param componentTypes 组件类型列表
|
|
2848
2759
|
* @returns 生成的位掩码
|
|
@@ -2855,7 +2766,7 @@ declare class QuerySystem {
|
|
|
2855
2766
|
/**
|
|
2856
2767
|
* 获取所有实体
|
|
2857
2768
|
*/
|
|
2858
|
-
getAllEntities(): Entity[];
|
|
2769
|
+
getAllEntities(): readonly Entity[];
|
|
2859
2770
|
/**
|
|
2860
2771
|
* 获取系统统计信息
|
|
2861
2772
|
*
|
|
@@ -2884,39 +2795,12 @@ declare class QuerySystem {
|
|
|
2884
2795
|
optimizationStats: {
|
|
2885
2796
|
componentIndex: any;
|
|
2886
2797
|
archetypeSystem: any;
|
|
2887
|
-
dirtyTracking: any;
|
|
2888
2798
|
};
|
|
2889
2799
|
cacheStats: {
|
|
2890
2800
|
size: number;
|
|
2891
2801
|
hitRate: string;
|
|
2892
2802
|
};
|
|
2893
2803
|
};
|
|
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
2804
|
/**
|
|
2921
2805
|
* 获取实体所属的原型信息
|
|
2922
2806
|
*
|
|
@@ -3299,7 +3183,7 @@ declare class Scene implements IScene {
|
|
|
3299
3183
|
*/
|
|
3300
3184
|
end(): void;
|
|
3301
3185
|
/**
|
|
3302
|
-
*
|
|
3186
|
+
* 更新场景
|
|
3303
3187
|
*/
|
|
3304
3188
|
update(): void;
|
|
3305
3189
|
/**
|
|
@@ -3307,6 +3191,11 @@ declare class Scene implements IScene {
|
|
|
3307
3191
|
* @param name 实体名称
|
|
3308
3192
|
*/
|
|
3309
3193
|
createEntity(name: string): Entity;
|
|
3194
|
+
/**
|
|
3195
|
+
* 清除所有EntitySystem的实体缓存
|
|
3196
|
+
* 当实体或组件发生变化时调用
|
|
3197
|
+
*/
|
|
3198
|
+
clearSystemEntityCaches(): void;
|
|
3310
3199
|
/**
|
|
3311
3200
|
* 在场景的实体列表中添加一个实体
|
|
3312
3201
|
* @param entity 要添加的实体
|
|
@@ -3364,6 +3253,11 @@ declare class Scene implements IScene {
|
|
|
3364
3253
|
* @param processor 要删除的处理器
|
|
3365
3254
|
*/
|
|
3366
3255
|
removeEntityProcessor(processor: EntitySystem): void;
|
|
3256
|
+
/**
|
|
3257
|
+
* 从场景中删除系统(removeEntityProcessor的别名)
|
|
3258
|
+
* @param system 系统
|
|
3259
|
+
*/
|
|
3260
|
+
removeSystem(system: EntitySystem): void;
|
|
3367
3261
|
/**
|
|
3368
3262
|
* 获取指定类型的EntitySystem处理器
|
|
3369
3263
|
* @param type 处理器类型
|
|
@@ -3413,7 +3307,7 @@ declare class Scene implements IScene {
|
|
|
3413
3307
|
* super(Transform, Velocity);
|
|
3414
3308
|
* }
|
|
3415
3309
|
*
|
|
3416
|
-
* protected process(entities: Entity[]): void {
|
|
3310
|
+
* protected process(entities: readonly Entity[]): void {
|
|
3417
3311
|
* for (const entity of entities) {
|
|
3418
3312
|
* const transform = entity.getComponent(Transform);
|
|
3419
3313
|
* const velocity = entity.getComponent(Velocity);
|
|
@@ -3430,10 +3324,21 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3430
3324
|
private _systemName;
|
|
3431
3325
|
private _initialized;
|
|
3432
3326
|
private _matcher;
|
|
3433
|
-
private _trackedEntities;
|
|
3434
3327
|
private _eventListeners;
|
|
3328
|
+
private _scene;
|
|
3329
|
+
protected logger: ReturnType<typeof createLogger>;
|
|
3435
3330
|
/**
|
|
3436
|
-
*
|
|
3331
|
+
* 实体ID映射缓存
|
|
3332
|
+
*/
|
|
3333
|
+
private _entityIdMap;
|
|
3334
|
+
private _entityIdMapVersion;
|
|
3335
|
+
private _entityIdMapSize;
|
|
3336
|
+
/**
|
|
3337
|
+
* 统一的实体缓存管理器
|
|
3338
|
+
*/
|
|
3339
|
+
private _entityCache;
|
|
3340
|
+
/**
|
|
3341
|
+
* 获取系统处理的实体列表
|
|
3437
3342
|
*/
|
|
3438
3343
|
get entities(): readonly Entity[];
|
|
3439
3344
|
/**
|
|
@@ -3454,7 +3359,6 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3454
3359
|
*/
|
|
3455
3360
|
get systemName(): string;
|
|
3456
3361
|
constructor(matcher?: Matcher);
|
|
3457
|
-
private _scene;
|
|
3458
3362
|
/**
|
|
3459
3363
|
* 这个系统所属的场景
|
|
3460
3364
|
*/
|
|
@@ -3481,6 +3385,11 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3481
3385
|
* 子类可以重写此方法进行初始化操作。
|
|
3482
3386
|
*/
|
|
3483
3387
|
protected onInitialize(): void;
|
|
3388
|
+
/**
|
|
3389
|
+
* 清除实体缓存(内部使用)
|
|
3390
|
+
* 当Scene中的实体发生变化时调用
|
|
3391
|
+
*/
|
|
3392
|
+
clearEntityCache(): void;
|
|
3484
3393
|
/**
|
|
3485
3394
|
* 重置系统状态
|
|
3486
3395
|
*
|
|
@@ -3509,20 +3418,22 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3509
3418
|
private extractEntityIds;
|
|
3510
3419
|
/**
|
|
3511
3420
|
* ID集合交集运算
|
|
3512
|
-
*
|
|
3513
|
-
* 使用单次扫描算法,选择较小集合进行迭代以提高效率
|
|
3514
3421
|
*/
|
|
3515
3422
|
private intersectIdSets;
|
|
3516
3423
|
/**
|
|
3517
3424
|
* ID集合差集运算
|
|
3518
|
-
*
|
|
3519
|
-
* 使用单次扫描算法计算setA - setB
|
|
3520
3425
|
*/
|
|
3521
3426
|
private differenceIdSets;
|
|
3427
|
+
/**
|
|
3428
|
+
* 获取或构建实体ID映射
|
|
3429
|
+
*/
|
|
3430
|
+
private getEntityIdMap;
|
|
3431
|
+
/**
|
|
3432
|
+
* 重建实体ID映射
|
|
3433
|
+
*/
|
|
3434
|
+
private rebuildEntityIdMap;
|
|
3522
3435
|
/**
|
|
3523
3436
|
* 从ID集合构建Entity数组
|
|
3524
|
-
*
|
|
3525
|
-
* 先构建ID到Entity的映射,然后根据ID集合构建结果数组
|
|
3526
3437
|
*/
|
|
3527
3438
|
private idSetToEntityArray;
|
|
3528
3439
|
/**
|
|
@@ -3533,14 +3444,10 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3533
3444
|
private executeComplexQuery;
|
|
3534
3445
|
/**
|
|
3535
3446
|
* 更新系统
|
|
3536
|
-
*
|
|
3537
|
-
* 在每帧调用,处理系统的主要逻辑。
|
|
3538
3447
|
*/
|
|
3539
3448
|
update(): void;
|
|
3540
3449
|
/**
|
|
3541
3450
|
* 后期更新系统
|
|
3542
|
-
*
|
|
3543
|
-
* 在所有系统的update方法执行完毕后调用。
|
|
3544
3451
|
*/
|
|
3545
3452
|
lateUpdate(): void;
|
|
3546
3453
|
/**
|
|
@@ -3556,7 +3463,7 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3556
3463
|
*
|
|
3557
3464
|
* @param entities 要处理的实体列表
|
|
3558
3465
|
*/
|
|
3559
|
-
protected process(entities: Entity[]): void;
|
|
3466
|
+
protected process(entities: readonly Entity[]): void;
|
|
3560
3467
|
/**
|
|
3561
3468
|
* 后期处理实体列表
|
|
3562
3469
|
*
|
|
@@ -3564,7 +3471,7 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3564
3471
|
*
|
|
3565
3472
|
* @param entities 要处理的实体列表
|
|
3566
3473
|
*/
|
|
3567
|
-
protected lateProcess(_entities: Entity[]): void;
|
|
3474
|
+
protected lateProcess(_entities: readonly Entity[]): void;
|
|
3568
3475
|
/**
|
|
3569
3476
|
* 系统处理完毕后调用
|
|
3570
3477
|
*
|
|
@@ -3641,13 +3548,21 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
3641
3548
|
*/
|
|
3642
3549
|
protected removeEventListener<T = any>(eventType: string, handler: EventHandler<T>): void;
|
|
3643
3550
|
/**
|
|
3644
|
-
*
|
|
3645
|
-
|
|
3646
|
-
|
|
3551
|
+
* 清理手动添加的事件监听器
|
|
3552
|
+
*/
|
|
3553
|
+
private cleanupManualEventListeners;
|
|
3554
|
+
/**
|
|
3555
|
+
* 框架内部销毁方法
|
|
3556
|
+
* 由框架调用,处理系统的完整销毁流程
|
|
3647
3557
|
*/
|
|
3648
|
-
|
|
3558
|
+
destroy(): void;
|
|
3559
|
+
/**
|
|
3560
|
+
* 获取Logger名称
|
|
3561
|
+
* 子类可以重写此方法来自定义logger名称
|
|
3562
|
+
*/
|
|
3563
|
+
protected getLoggerName(): string;
|
|
3649
3564
|
/**
|
|
3650
|
-
*
|
|
3565
|
+
* 用户销毁回调
|
|
3651
3566
|
*
|
|
3652
3567
|
* 当系统从场景中移除时调用,子类可以重写此方法进行清理操作。
|
|
3653
3568
|
* 注意:事件监听器会被框架自动清理,无需手动处理。
|
|
@@ -3776,6 +3691,10 @@ interface IScene {
|
|
|
3776
3691
|
* 创建实体
|
|
3777
3692
|
*/
|
|
3778
3693
|
createEntity(name: string): Entity;
|
|
3694
|
+
/**
|
|
3695
|
+
* 清除所有EntitySystem的实体缓存
|
|
3696
|
+
*/
|
|
3697
|
+
clearSystemEntityCaches(): void;
|
|
3779
3698
|
/**
|
|
3780
3699
|
* 添加实体
|
|
3781
3700
|
*/
|
|
@@ -3830,6 +3749,11 @@ interface ISceneConfig {
|
|
|
3830
3749
|
* 调试配置
|
|
3831
3750
|
*/
|
|
3832
3751
|
debug?: boolean;
|
|
3752
|
+
/**
|
|
3753
|
+
* 是否启用实体直接更新
|
|
3754
|
+
* @default false
|
|
3755
|
+
*/
|
|
3756
|
+
enableEntityDirectUpdate?: boolean;
|
|
3833
3757
|
}
|
|
3834
3758
|
|
|
3835
3759
|
/**
|
|
@@ -3887,6 +3811,12 @@ declare class Entity {
|
|
|
3887
3811
|
* 用于发射组件相关事件
|
|
3888
3812
|
*/
|
|
3889
3813
|
static eventBus: EventBus | null;
|
|
3814
|
+
/**
|
|
3815
|
+
* 通知Scene中的QuerySystem实体组件发生变动
|
|
3816
|
+
*
|
|
3817
|
+
* @param entity 发生组件变动的实体
|
|
3818
|
+
*/
|
|
3819
|
+
private static notifyQuerySystems;
|
|
3890
3820
|
/**
|
|
3891
3821
|
* 实体名称
|
|
3892
3822
|
*/
|
|
@@ -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 组件类型
|
|
@@ -5656,15 +5586,18 @@ declare class Core {
|
|
|
5656
5586
|
/**
|
|
5657
5587
|
* 获取WorldManager实例
|
|
5658
5588
|
*
|
|
5589
|
+
* @param config 可选的WorldManager配置,用于覆盖默认配置
|
|
5659
5590
|
* @returns WorldManager实例,如果未初始化则自动创建
|
|
5660
5591
|
*/
|
|
5661
|
-
static getWorldManager(): WorldManager;
|
|
5592
|
+
static getWorldManager(config?: Partial<IWorldManagerConfig>): WorldManager;
|
|
5662
5593
|
/**
|
|
5663
5594
|
* 启用World管理
|
|
5664
5595
|
*
|
|
5665
5596
|
* 显式启用World功能,用于多房间/多世界架构
|
|
5597
|
+
*
|
|
5598
|
+
* @param config 可选的WorldManager配置,用于覆盖默认配置
|
|
5666
5599
|
*/
|
|
5667
|
-
static enableWorldManager(): WorldManager;
|
|
5600
|
+
static enableWorldManager(config?: Partial<IWorldManagerConfig>): WorldManager;
|
|
5668
5601
|
/**
|
|
5669
5602
|
* 确保默认World存在
|
|
5670
5603
|
*
|
|
@@ -5946,6 +5879,315 @@ declare abstract class IntervalSystem extends EntitySystem {
|
|
|
5946
5879
|
protected getIntervalDelta(): number;
|
|
5947
5880
|
}
|
|
5948
5881
|
|
|
5882
|
+
/**
|
|
5883
|
+
* Worker处理函数类型
|
|
5884
|
+
* 用户编写的处理逻辑,会被序列化到Worker中执行
|
|
5885
|
+
*/
|
|
5886
|
+
type WorkerProcessFunction<T extends Record<string, any> = any> = (entities: T[], deltaTime: number, config?: any) => T[] | Promise<T[]>;
|
|
5887
|
+
/**
|
|
5888
|
+
* Worker配置接口
|
|
5889
|
+
*/
|
|
5890
|
+
interface WorkerSystemConfig {
|
|
5891
|
+
/** 是否启用Worker并行处理 */
|
|
5892
|
+
enableWorker?: boolean;
|
|
5893
|
+
/** Worker数量,默认为CPU核心数,自动限制在系统最大值内 */
|
|
5894
|
+
workerCount?: number;
|
|
5895
|
+
/** 每个Worker处理的实体数量,用于控制负载分布 */
|
|
5896
|
+
entitiesPerWorker?: number;
|
|
5897
|
+
/** 系统配置数据,会传递给Worker */
|
|
5898
|
+
systemConfig?: any;
|
|
5899
|
+
/** 是否使用SharedArrayBuffer优化 */
|
|
5900
|
+
useSharedArrayBuffer?: boolean;
|
|
5901
|
+
/** 每个实体在SharedArrayBuffer中占用的Float32数量 */
|
|
5902
|
+
entityDataSize?: number;
|
|
5903
|
+
/** 最大实体数量(用于预分配SharedArrayBuffer) */
|
|
5904
|
+
maxEntities?: number;
|
|
5905
|
+
}
|
|
5906
|
+
/**
|
|
5907
|
+
* SharedArrayBuffer处理函数类型
|
|
5908
|
+
*/
|
|
5909
|
+
type SharedArrayBufferProcessFunction = (sharedFloatArray: Float32Array, startIndex: number, endIndex: number, deltaTime: number, systemConfig?: any) => void;
|
|
5910
|
+
/**
|
|
5911
|
+
* 支持Worker并行处理的EntitySystem基类
|
|
5912
|
+
*
|
|
5913
|
+
* 支持传统Worker和SharedArrayBuffer两种优化模式:
|
|
5914
|
+
* - 传统模式:数据序列化传输,适用于复杂计算
|
|
5915
|
+
* - SharedArrayBuffer模式:零拷贝数据共享,适用于大量简单计算
|
|
5916
|
+
*
|
|
5917
|
+
* 用户需要实现:
|
|
5918
|
+
* 1. extractEntityData - 定义数据提取逻辑
|
|
5919
|
+
* 2. workerProcess - 编写处理函数(纯函数,可序列化)
|
|
5920
|
+
* 3. applyResult - 定义结果应用逻辑
|
|
5921
|
+
* 4. (可选) SharedArrayBuffer相关方法
|
|
5922
|
+
*
|
|
5923
|
+
* @example
|
|
5924
|
+
* ```typescript
|
|
5925
|
+
* class PhysicsSystem extends WorkerEntitySystem<PhysicsData> {
|
|
5926
|
+
* constructor() {
|
|
5927
|
+
* super(Matcher.all(Transform, Velocity), {
|
|
5928
|
+
* enableWorker: true,
|
|
5929
|
+
* workerCount: 8, // 指定8个worker,系统会自动限制在系统最大值内
|
|
5930
|
+
* entitiesPerWorker: 100, // 每个worker处理100个实体
|
|
5931
|
+
* useSharedArrayBuffer: true,
|
|
5932
|
+
* entityDataSize: 6, // x, y, vx, vy, radius, mass
|
|
5933
|
+
* maxEntities: 10000,
|
|
5934
|
+
* systemConfig: { gravity: 100, friction: 0.95 }
|
|
5935
|
+
* });
|
|
5936
|
+
* }
|
|
5937
|
+
*
|
|
5938
|
+
* protected getDefaultEntityDataSize(): number {
|
|
5939
|
+
* return 6; // x, y, vx, vy, radius, mass
|
|
5940
|
+
* }
|
|
5941
|
+
*
|
|
5942
|
+
* protected extractEntityData(entity: Entity): PhysicsData {
|
|
5943
|
+
* const transform = entity.getComponent(Transform);
|
|
5944
|
+
* const velocity = entity.getComponent(Velocity);
|
|
5945
|
+
* const physics = entity.getComponent(PhysicsComponent);
|
|
5946
|
+
* return {
|
|
5947
|
+
* x: transform.x,
|
|
5948
|
+
* y: transform.y,
|
|
5949
|
+
* vx: velocity.x,
|
|
5950
|
+
* vy: velocity.y,
|
|
5951
|
+
* radius: physics.radius,
|
|
5952
|
+
* mass: physics.mass
|
|
5953
|
+
* };
|
|
5954
|
+
* }
|
|
5955
|
+
*
|
|
5956
|
+
* protected workerProcess(entities: PhysicsData[], deltaTime: number, config: any): PhysicsData[] {
|
|
5957
|
+
* return entities.map(entity => {
|
|
5958
|
+
* // 应用重力
|
|
5959
|
+
* entity.vy += config.gravity * deltaTime;
|
|
5960
|
+
*
|
|
5961
|
+
* // 更新位置
|
|
5962
|
+
* entity.x += entity.vx * deltaTime;
|
|
5963
|
+
* entity.y += entity.vy * deltaTime;
|
|
5964
|
+
*
|
|
5965
|
+
* // 应用摩擦力
|
|
5966
|
+
* entity.vx *= config.friction;
|
|
5967
|
+
* entity.vy *= config.friction;
|
|
5968
|
+
*
|
|
5969
|
+
* return entity;
|
|
5970
|
+
* });
|
|
5971
|
+
* }
|
|
5972
|
+
*
|
|
5973
|
+
* protected applyResult(entity: Entity, result: PhysicsData): void {
|
|
5974
|
+
* const transform = entity.getComponent(Transform);
|
|
5975
|
+
* const velocity = entity.getComponent(Velocity);
|
|
5976
|
+
*
|
|
5977
|
+
* transform.x = result.x;
|
|
5978
|
+
* transform.y = result.y;
|
|
5979
|
+
* velocity.x = result.vx;
|
|
5980
|
+
* velocity.y = result.vy;
|
|
5981
|
+
* }
|
|
5982
|
+
*
|
|
5983
|
+
* // SharedArrayBuffer优化支持
|
|
5984
|
+
* protected writeEntityToBuffer(entityData: PhysicsData, offset: number): void {
|
|
5985
|
+
* if (!this.sharedFloatArray) return;
|
|
5986
|
+
*
|
|
5987
|
+
* this.sharedFloatArray[offset] = entityData.x;
|
|
5988
|
+
* this.sharedFloatArray[offset + 1] = entityData.y;
|
|
5989
|
+
* this.sharedFloatArray[offset + 2] = entityData.vx;
|
|
5990
|
+
* this.sharedFloatArray[offset + 3] = entityData.vy;
|
|
5991
|
+
* this.sharedFloatArray[offset + 4] = entityData.radius;
|
|
5992
|
+
* this.sharedFloatArray[offset + 5] = entityData.mass;
|
|
5993
|
+
* }
|
|
5994
|
+
*
|
|
5995
|
+
* protected readEntityFromBuffer(offset: number): PhysicsData | null {
|
|
5996
|
+
* if (!this.sharedFloatArray) return null;
|
|
5997
|
+
*
|
|
5998
|
+
* return {
|
|
5999
|
+
* x: this.sharedFloatArray[offset],
|
|
6000
|
+
* y: this.sharedFloatArray[offset + 1],
|
|
6001
|
+
* vx: this.sharedFloatArray[offset + 2],
|
|
6002
|
+
* vy: this.sharedFloatArray[offset + 3],
|
|
6003
|
+
* radius: this.sharedFloatArray[offset + 4],
|
|
6004
|
+
* mass: this.sharedFloatArray[offset + 5]
|
|
6005
|
+
* };
|
|
6006
|
+
* }
|
|
6007
|
+
*
|
|
6008
|
+
* protected getSharedArrayBufferProcessFunction(): SharedArrayBufferProcessFunction {
|
|
6009
|
+
* return function(sharedFloatArray: Float32Array, startIndex: number, endIndex: number, deltaTime: number, config: any) {
|
|
6010
|
+
* const entitySize = 6;
|
|
6011
|
+
* for (let i = startIndex; i < endIndex; i++) {
|
|
6012
|
+
* const offset = i * entitySize;
|
|
6013
|
+
*
|
|
6014
|
+
* // 读取数据
|
|
6015
|
+
* let x = sharedFloatArray[offset];
|
|
6016
|
+
* let y = sharedFloatArray[offset + 1];
|
|
6017
|
+
* let vx = sharedFloatArray[offset + 2];
|
|
6018
|
+
* let vy = sharedFloatArray[offset + 3];
|
|
6019
|
+
* const radius = sharedFloatArray[offset + 4];
|
|
6020
|
+
* const mass = sharedFloatArray[offset + 5];
|
|
6021
|
+
*
|
|
6022
|
+
* // 物理计算
|
|
6023
|
+
* vy += config.gravity * deltaTime;
|
|
6024
|
+
* x += vx * deltaTime;
|
|
6025
|
+
* y += vy * deltaTime;
|
|
6026
|
+
* vx *= config.friction;
|
|
6027
|
+
* vy *= config.friction;
|
|
6028
|
+
*
|
|
6029
|
+
* // 写回数据
|
|
6030
|
+
* sharedFloatArray[offset] = x;
|
|
6031
|
+
* sharedFloatArray[offset + 1] = y;
|
|
6032
|
+
* sharedFloatArray[offset + 2] = vx;
|
|
6033
|
+
* sharedFloatArray[offset + 3] = vy;
|
|
6034
|
+
* }
|
|
6035
|
+
* };
|
|
6036
|
+
* }
|
|
6037
|
+
* }
|
|
6038
|
+
*
|
|
6039
|
+
* interface PhysicsData {
|
|
6040
|
+
* x: number;
|
|
6041
|
+
* y: number;
|
|
6042
|
+
* vx: number;
|
|
6043
|
+
* vy: number;
|
|
6044
|
+
* radius: number;
|
|
6045
|
+
* mass: number;
|
|
6046
|
+
* }
|
|
6047
|
+
* ```
|
|
6048
|
+
*/
|
|
6049
|
+
declare abstract class WorkerEntitySystem<TEntityData = any> extends EntitySystem {
|
|
6050
|
+
protected config: Required<Omit<WorkerSystemConfig, 'systemConfig' | 'entitiesPerWorker'>> & {
|
|
6051
|
+
systemConfig?: any;
|
|
6052
|
+
entitiesPerWorker?: number;
|
|
6053
|
+
};
|
|
6054
|
+
private workerPool;
|
|
6055
|
+
private isProcessing;
|
|
6056
|
+
protected sharedBuffer: SharedArrayBuffer | null;
|
|
6057
|
+
protected sharedFloatArray: Float32Array | null;
|
|
6058
|
+
private platformAdapter;
|
|
6059
|
+
constructor(matcher?: Matcher, config?: WorkerSystemConfig);
|
|
6060
|
+
/**
|
|
6061
|
+
* 检查是否支持Worker
|
|
6062
|
+
*/
|
|
6063
|
+
private isWorkerSupported;
|
|
6064
|
+
/**
|
|
6065
|
+
* 检查是否支持SharedArrayBuffer
|
|
6066
|
+
*/
|
|
6067
|
+
private isSharedArrayBufferSupported;
|
|
6068
|
+
/**
|
|
6069
|
+
* 获取系统支持的最大Worker数量
|
|
6070
|
+
*/
|
|
6071
|
+
private getMaxSystemWorkerCount;
|
|
6072
|
+
/**
|
|
6073
|
+
* 获取实体数据大小 - 子类必须实现
|
|
6074
|
+
* 返回每个实体在SharedArrayBuffer中占用的Float32数量
|
|
6075
|
+
*/
|
|
6076
|
+
protected abstract getDefaultEntityDataSize(): number;
|
|
6077
|
+
/**
|
|
6078
|
+
* 初始化SharedArrayBuffer
|
|
6079
|
+
*/
|
|
6080
|
+
private initializeSharedArrayBuffer;
|
|
6081
|
+
/**
|
|
6082
|
+
* 初始化Worker池
|
|
6083
|
+
*/
|
|
6084
|
+
private initializeWorkerPool;
|
|
6085
|
+
/**
|
|
6086
|
+
* 创建Worker脚本
|
|
6087
|
+
*/
|
|
6088
|
+
private createWorkerScript;
|
|
6089
|
+
/**
|
|
6090
|
+
* 重写process方法,支持Worker并行处理
|
|
6091
|
+
*/
|
|
6092
|
+
protected process(entities: readonly Entity[]): void;
|
|
6093
|
+
/**
|
|
6094
|
+
* 使用SharedArrayBuffer优化的Worker处理
|
|
6095
|
+
*/
|
|
6096
|
+
private processWithSharedArrayBuffer;
|
|
6097
|
+
/**
|
|
6098
|
+
* 使用Worker并行处理
|
|
6099
|
+
*/
|
|
6100
|
+
private processWithWorker;
|
|
6101
|
+
/**
|
|
6102
|
+
* 同步处理(fallback)
|
|
6103
|
+
*/
|
|
6104
|
+
private processSynchronously;
|
|
6105
|
+
/**
|
|
6106
|
+
* 创建数据批次 - 支持用户指定每个Worker的实体数量
|
|
6107
|
+
*/
|
|
6108
|
+
private createBatches;
|
|
6109
|
+
/**
|
|
6110
|
+
* 将实体数据写入SharedArrayBuffer
|
|
6111
|
+
*/
|
|
6112
|
+
private writeEntitiesToSharedBuffer;
|
|
6113
|
+
/**
|
|
6114
|
+
* 将单个实体数据写入SharedArrayBuffer - 子类必须实现
|
|
6115
|
+
* @param entityData 实体数据
|
|
6116
|
+
* @param offset 在SharedArrayBuffer中的偏移位置(Float32索引)
|
|
6117
|
+
*/
|
|
6118
|
+
protected abstract writeEntityToBuffer(entityData: TEntityData, offset: number): void;
|
|
6119
|
+
/**
|
|
6120
|
+
* 创建SharedArrayBuffer任务 - 支持用户指定每个Worker的实体数量
|
|
6121
|
+
*/
|
|
6122
|
+
private createSharedArrayBufferTasks;
|
|
6123
|
+
/**
|
|
6124
|
+
* 从SharedArrayBuffer读取结果并应用
|
|
6125
|
+
*/
|
|
6126
|
+
private readResultsFromSharedBuffer;
|
|
6127
|
+
/**
|
|
6128
|
+
* 从SharedArrayBuffer读取单个实体数据 - 子类必须实现
|
|
6129
|
+
* @param offset 在SharedArrayBuffer中的偏移位置(Float32索引)
|
|
6130
|
+
* @returns 实体数据或null
|
|
6131
|
+
*/
|
|
6132
|
+
protected abstract readEntityFromBuffer(offset: number): TEntityData | null;
|
|
6133
|
+
/**
|
|
6134
|
+
* 获取SharedArrayBuffer处理函数 - 子类可选实现
|
|
6135
|
+
* 返回一个函数,该函数将被序列化到Worker中执行
|
|
6136
|
+
*/
|
|
6137
|
+
protected getSharedArrayBufferProcessFunction?(): SharedArrayBufferProcessFunction;
|
|
6138
|
+
/**
|
|
6139
|
+
* 提取实体数据 - 子类必须实现
|
|
6140
|
+
*
|
|
6141
|
+
* 将Entity转换为可序列化的数据对象
|
|
6142
|
+
*/
|
|
6143
|
+
protected abstract extractEntityData(entity: Entity): TEntityData;
|
|
6144
|
+
/**
|
|
6145
|
+
* Worker处理函数 - 子类必须实现
|
|
6146
|
+
*
|
|
6147
|
+
* 这个函数会被序列化并在Worker中执行,因此:
|
|
6148
|
+
* 1. 必须是纯函数,不能访问外部变量
|
|
6149
|
+
* 2. 不能使用闭包或this
|
|
6150
|
+
* 3. 只能使用标准JavaScript API
|
|
6151
|
+
*/
|
|
6152
|
+
protected abstract workerProcess(entities: TEntityData[], deltaTime: number, systemConfig?: any): TEntityData[] | Promise<TEntityData[]>;
|
|
6153
|
+
/**
|
|
6154
|
+
* 应用处理结果 - 子类必须实现
|
|
6155
|
+
*
|
|
6156
|
+
* 将Worker处理的结果应用回Entity的组件
|
|
6157
|
+
*/
|
|
6158
|
+
protected abstract applyResult(entity: Entity, result: TEntityData): void;
|
|
6159
|
+
/**
|
|
6160
|
+
* 更新Worker配置
|
|
6161
|
+
*/
|
|
6162
|
+
updateConfig(newConfig: Partial<WorkerSystemConfig>): void;
|
|
6163
|
+
/**
|
|
6164
|
+
* 重新初始化整个 Worker 系统(包括 SharedArrayBuffer)
|
|
6165
|
+
*/
|
|
6166
|
+
private reinitializeWorkerSystem;
|
|
6167
|
+
/**
|
|
6168
|
+
* 重新初始化 Worker 池(保持 SharedArrayBuffer)
|
|
6169
|
+
*/
|
|
6170
|
+
private reinitializeWorkerPool;
|
|
6171
|
+
/**
|
|
6172
|
+
* 获取系统性能信息
|
|
6173
|
+
*/
|
|
6174
|
+
getWorkerInfo(): {
|
|
6175
|
+
enabled: boolean;
|
|
6176
|
+
workerCount: number;
|
|
6177
|
+
entitiesPerWorker?: number;
|
|
6178
|
+
maxSystemWorkerCount: number;
|
|
6179
|
+
isProcessing: boolean;
|
|
6180
|
+
sharedArrayBufferSupported: boolean;
|
|
6181
|
+
sharedArrayBufferEnabled: boolean;
|
|
6182
|
+
currentMode: 'shared-buffer' | 'worker' | 'sync';
|
|
6183
|
+
};
|
|
6184
|
+
/**
|
|
6185
|
+
* 销毁系统时清理Worker池
|
|
6186
|
+
*/
|
|
6187
|
+
protected onDestroy(): void;
|
|
6188
|
+
protected getLoggerName(): string;
|
|
6189
|
+
}
|
|
6190
|
+
|
|
5949
6191
|
/**
|
|
5950
6192
|
* 64位位集合类,用于高效的位操作
|
|
5951
6193
|
* 支持最多64个位的设置、清除、查询和逻辑运算
|
|
@@ -6525,827 +6767,437 @@ declare function getComponentInstanceTypeName(component: Component): string;
|
|
|
6525
6767
|
declare function getSystemInstanceTypeName(system: EntitySystem): string;
|
|
6526
6768
|
|
|
6527
6769
|
/**
|
|
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
|
-
* ```
|
|
6770
|
+
* 组件对象池,用于复用组件实例以减少内存分配
|
|
6542
6771
|
*/
|
|
6543
|
-
declare class
|
|
6544
|
-
private
|
|
6545
|
-
|
|
6546
|
-
private
|
|
6547
|
-
|
|
6548
|
-
|
|
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;
|
|
6772
|
+
declare class ComponentPool<T extends Component> {
|
|
6773
|
+
private pool;
|
|
6774
|
+
private createFn;
|
|
6775
|
+
private resetFn?;
|
|
6776
|
+
private maxSize;
|
|
6777
|
+
constructor(createFn: () => T, resetFn?: (component: T) => void, maxSize?: number);
|
|
6575
6778
|
/**
|
|
6576
|
-
*
|
|
6577
|
-
*
|
|
6578
|
-
* 返回的实体必须至少包含其中一个指定的组件类型。
|
|
6579
|
-
*
|
|
6580
|
-
* @param componentTypes 组件类型列表
|
|
6581
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6779
|
+
* 获取一个组件实例
|
|
6582
6780
|
*/
|
|
6583
|
-
|
|
6781
|
+
acquire(): T;
|
|
6584
6782
|
/**
|
|
6585
|
-
*
|
|
6586
|
-
*
|
|
6587
|
-
* 返回的实体不能包含任何指定的组件类型。
|
|
6588
|
-
*
|
|
6589
|
-
* @param componentTypes 组件类型列表
|
|
6590
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6783
|
+
* 释放一个组件实例回池中
|
|
6591
6784
|
*/
|
|
6592
|
-
|
|
6785
|
+
release(component: T): void;
|
|
6593
6786
|
/**
|
|
6594
|
-
*
|
|
6595
|
-
*
|
|
6596
|
-
* 返回的实体必须具有指定的标签。
|
|
6597
|
-
*
|
|
6598
|
-
* @param tag 标签值
|
|
6599
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6787
|
+
* 预填充对象池
|
|
6600
6788
|
*/
|
|
6601
|
-
|
|
6789
|
+
prewarm(count: number): void;
|
|
6602
6790
|
/**
|
|
6603
|
-
*
|
|
6604
|
-
*
|
|
6605
|
-
* 返回的实体不能具有指定的标签。
|
|
6606
|
-
*
|
|
6607
|
-
* @param tag 标签值
|
|
6608
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6791
|
+
* 清空对象池
|
|
6609
6792
|
*/
|
|
6610
|
-
|
|
6793
|
+
clear(): void;
|
|
6611
6794
|
/**
|
|
6612
|
-
*
|
|
6613
|
-
*
|
|
6614
|
-
* 返回的实体必须处于激活状态(active = true)。
|
|
6615
|
-
*
|
|
6616
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6795
|
+
* 获取池中可用对象数量
|
|
6617
6796
|
*/
|
|
6618
|
-
|
|
6797
|
+
getAvailableCount(): number;
|
|
6619
6798
|
/**
|
|
6620
|
-
*
|
|
6621
|
-
*
|
|
6622
|
-
* 返回的实体必须处于启用状态(enabled = true)。
|
|
6623
|
-
*
|
|
6624
|
-
* @returns 查询构建器实例,支持链式调用
|
|
6799
|
+
* 获取池的最大容量
|
|
6625
6800
|
*/
|
|
6626
|
-
|
|
6801
|
+
getMaxSize(): number;
|
|
6802
|
+
}
|
|
6803
|
+
/**
|
|
6804
|
+
* 全局组件池管理器
|
|
6805
|
+
*/
|
|
6806
|
+
declare class ComponentPoolManager {
|
|
6807
|
+
private static instance;
|
|
6808
|
+
private pools;
|
|
6809
|
+
private constructor();
|
|
6810
|
+
static getInstance(): ComponentPoolManager;
|
|
6627
6811
|
/**
|
|
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
|
-
* ```
|
|
6812
|
+
* 注册组件池
|
|
6640
6813
|
*/
|
|
6641
|
-
|
|
6814
|
+
registerPool<T extends Component>(componentName: string, createFn: () => T, resetFn?: (component: T) => void, maxSize?: number): void;
|
|
6642
6815
|
/**
|
|
6643
|
-
*
|
|
6644
|
-
*
|
|
6645
|
-
* @returns 符合所有查询条件的实体数组
|
|
6816
|
+
* 获取组件实例
|
|
6646
6817
|
*/
|
|
6647
|
-
|
|
6818
|
+
acquireComponent<T extends Component>(componentName: string): T | null;
|
|
6648
6819
|
/**
|
|
6649
|
-
*
|
|
6650
|
-
*
|
|
6651
|
-
* @returns 第一个符合查询条件的实体,如果没有找到则返回null
|
|
6820
|
+
* 释放组件实例
|
|
6652
6821
|
*/
|
|
6653
|
-
|
|
6822
|
+
releaseComponent<T extends Component>(componentName: string, component: T): void;
|
|
6654
6823
|
/**
|
|
6655
|
-
*
|
|
6656
|
-
*
|
|
6657
|
-
* @returns 符合查询条件的实体数量
|
|
6824
|
+
* 预热所有池
|
|
6658
6825
|
*/
|
|
6659
|
-
count
|
|
6826
|
+
prewarmAll(count?: number): void;
|
|
6660
6827
|
/**
|
|
6661
|
-
*
|
|
6662
|
-
*
|
|
6663
|
-
* @param action 要执行的操作函数,接收匹配的实体作为参数
|
|
6828
|
+
* 清空所有池
|
|
6664
6829
|
*/
|
|
6665
|
-
|
|
6830
|
+
clearAll(): void;
|
|
6666
6831
|
/**
|
|
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分配器。
|
|
6832
|
+
* 重置管理器,移除所有注册的池
|
|
6720
6833
|
*/
|
|
6721
|
-
|
|
6834
|
+
reset(): void;
|
|
6722
6835
|
/**
|
|
6723
|
-
*
|
|
6724
|
-
*
|
|
6725
|
-
* @returns 当前管理的实体总数量
|
|
6836
|
+
* 获取池统计信息
|
|
6726
6837
|
*/
|
|
6727
|
-
|
|
6838
|
+
getPoolStats(): Map<string, {
|
|
6839
|
+
available: number;
|
|
6840
|
+
maxSize: number;
|
|
6841
|
+
}>;
|
|
6728
6842
|
/**
|
|
6729
|
-
*
|
|
6730
|
-
*
|
|
6731
|
-
* 只计算同时满足激活状态且未被销毁的实体。
|
|
6732
|
-
*
|
|
6733
|
-
* @returns 激活状态的实体数量
|
|
6843
|
+
* 获取池利用率信息(用于调试)
|
|
6734
6844
|
*/
|
|
6735
|
-
|
|
6845
|
+
getPoolUtilization(): Map<string, {
|
|
6846
|
+
used: number;
|
|
6847
|
+
total: number;
|
|
6848
|
+
utilization: number;
|
|
6849
|
+
}>;
|
|
6736
6850
|
/**
|
|
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
|
-
* ```
|
|
6851
|
+
* 获取指定组件的池利用率
|
|
6749
6852
|
*/
|
|
6750
|
-
|
|
6853
|
+
getComponentUtilization(componentName: string): number;
|
|
6854
|
+
}
|
|
6855
|
+
|
|
6856
|
+
/**
|
|
6857
|
+
* 类型工具类
|
|
6858
|
+
* 提供类型相关的实用方法
|
|
6859
|
+
*/
|
|
6860
|
+
declare class TypeUtils {
|
|
6751
6861
|
/**
|
|
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");
|
|
6862
|
+
* 获取对象的类型
|
|
6863
|
+
* @param obj 对象
|
|
6864
|
+
* @returns 对象的构造函数
|
|
6765
6865
|
*/
|
|
6766
|
-
|
|
6866
|
+
static getType(obj: any): any;
|
|
6867
|
+
}
|
|
6868
|
+
|
|
6869
|
+
/**
|
|
6870
|
+
* 数字扩展工具类
|
|
6871
|
+
* 提供数字转换的实用方法
|
|
6872
|
+
*/
|
|
6873
|
+
declare class NumberExtension {
|
|
6767
6874
|
/**
|
|
6768
|
-
*
|
|
6769
|
-
*
|
|
6770
|
-
*
|
|
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
|
-
* ```
|
|
6875
|
+
* 将值转换为数字
|
|
6876
|
+
* @param value 要转换的值
|
|
6877
|
+
* @returns 转换后的数字,如果值为undefined则返回0
|
|
6787
6878
|
*/
|
|
6788
|
-
|
|
6879
|
+
static toNumber(value: unknown): number;
|
|
6880
|
+
}
|
|
6881
|
+
|
|
6882
|
+
/**
|
|
6883
|
+
* 时间管理工具类
|
|
6884
|
+
* 提供游戏时间相关的功能,包括帧时间、总时间、时间缩放等
|
|
6885
|
+
*/
|
|
6886
|
+
declare class Time {
|
|
6789
6887
|
/**
|
|
6790
|
-
*
|
|
6791
|
-
*
|
|
6792
|
-
* 返回当前管理的所有实体的副本数组。
|
|
6793
|
-
*
|
|
6794
|
-
* @returns 所有实体的数组
|
|
6888
|
+
* 上一帧到当前帧的时间间隔(秒)
|
|
6795
6889
|
*/
|
|
6796
|
-
|
|
6890
|
+
static deltaTime: number;
|
|
6797
6891
|
/**
|
|
6798
|
-
*
|
|
6799
|
-
*
|
|
6800
|
-
* 支持字符串和数字类型的ID。
|
|
6801
|
-
*
|
|
6802
|
-
* @param id 实体ID,可以是字符串或数字
|
|
6803
|
-
* @returns 对应的实体,如果不存在则返回null
|
|
6892
|
+
* 未缩放的帧时间间隔(秒)
|
|
6804
6893
|
*/
|
|
6805
|
-
|
|
6894
|
+
static unscaledDeltaTime: number;
|
|
6806
6895
|
/**
|
|
6807
|
-
*
|
|
6808
|
-
*
|
|
6809
|
-
* 如果存在多个同名实体,返回第一个找到的实体。
|
|
6810
|
-
*
|
|
6811
|
-
* @param name 实体名称
|
|
6812
|
-
* @returns 匹配的实体,如果不存在则返回null
|
|
6896
|
+
* 游戏开始以来的总时间(秒)
|
|
6813
6897
|
*/
|
|
6814
|
-
|
|
6898
|
+
static totalTime: number;
|
|
6815
6899
|
/**
|
|
6816
|
-
*
|
|
6817
|
-
*
|
|
6818
|
-
* 返回所有具有指定标签的实体。
|
|
6819
|
-
*
|
|
6820
|
-
* @param tag 标签值
|
|
6821
|
-
* @returns 具有指定标签的实体数组
|
|
6900
|
+
* 未缩放的总时间(秒)
|
|
6822
6901
|
*/
|
|
6823
|
-
|
|
6902
|
+
static unscaledTotalTime: number;
|
|
6824
6903
|
/**
|
|
6825
|
-
*
|
|
6826
|
-
*
|
|
6827
|
-
* 遍历所有实体,查找包含指定组件类型的实体。
|
|
6828
|
-
*
|
|
6829
|
-
* @param componentType 组件类型
|
|
6830
|
-
* @returns 包含指定组件的实体数组
|
|
6831
|
-
*
|
|
6832
|
-
* @example
|
|
6833
|
-
* ```typescript
|
|
6834
|
-
* const entitiesWithHealth = entityManager.getEntitiesWithComponent(HealthComponent);
|
|
6835
|
-
* ```
|
|
6904
|
+
* 时间缩放比例
|
|
6836
6905
|
*/
|
|
6837
|
-
|
|
6906
|
+
static timeScale: number;
|
|
6838
6907
|
/**
|
|
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
|
-
* ```
|
|
6908
|
+
* 当前帧数
|
|
6853
6909
|
*/
|
|
6854
|
-
|
|
6910
|
+
static frameCount: number;
|
|
6855
6911
|
/**
|
|
6856
|
-
*
|
|
6857
|
-
*
|
|
6858
|
-
* @param componentTypes 组件类型数组
|
|
6859
|
-
* @param operation 查询操作:'AND' 或 'OR'
|
|
6860
|
-
* @returns 匹配的实体集合
|
|
6912
|
+
* 使用外部引擎提供的deltaTime更新时间信息
|
|
6913
|
+
* @param deltaTime 外部引擎提供的帧时间间隔(秒)
|
|
6861
6914
|
*/
|
|
6862
|
-
|
|
6915
|
+
static update(deltaTime: number): void;
|
|
6863
6916
|
/**
|
|
6864
|
-
*
|
|
6865
|
-
*
|
|
6866
|
-
* @param entity 修改的实体
|
|
6867
|
-
* @param componentTypes 修改的组件类型
|
|
6917
|
+
* 场景改变时重置时间
|
|
6868
6918
|
*/
|
|
6869
|
-
|
|
6919
|
+
static sceneChanged(): void;
|
|
6870
6920
|
/**
|
|
6871
|
-
*
|
|
6921
|
+
* 检查指定的时间间隔是否已经过去
|
|
6922
|
+
* @param interval 时间间隔(秒)
|
|
6923
|
+
* @param lastTime 上次检查的时间
|
|
6924
|
+
* @returns 是否已经过去指定时间
|
|
6872
6925
|
*/
|
|
6873
|
-
|
|
6926
|
+
static checkEvery(interval: number, lastTime: number): boolean;
|
|
6927
|
+
}
|
|
6928
|
+
|
|
6929
|
+
/**
|
|
6930
|
+
* 平台适配器接口
|
|
6931
|
+
* 用于适配不同的运行环境(浏览器、微信小游戏、字节跳动小游戏等)
|
|
6932
|
+
*/
|
|
6933
|
+
interface IPlatformAdapter {
|
|
6874
6934
|
/**
|
|
6875
|
-
*
|
|
6876
|
-
*
|
|
6877
|
-
* 允许外部代码监听和发射ECS相关事件。
|
|
6878
|
-
*
|
|
6879
|
-
* @returns 事件总线实例
|
|
6935
|
+
* 平台名称
|
|
6880
6936
|
*/
|
|
6881
|
-
|
|
6937
|
+
readonly name: string;
|
|
6882
6938
|
/**
|
|
6883
|
-
*
|
|
6884
|
-
*
|
|
6885
|
-
* 维护按名称查找实体的索引结构。支持添加和移除操作。
|
|
6886
|
-
*
|
|
6887
|
-
* @param entity 要更新索引的实体
|
|
6888
|
-
* @param isAdd true表示添加到索引,false表示从索引中移除
|
|
6939
|
+
* 平台版本信息
|
|
6889
6940
|
*/
|
|
6890
|
-
|
|
6941
|
+
readonly version?: string;
|
|
6891
6942
|
/**
|
|
6892
|
-
*
|
|
6893
|
-
*
|
|
6894
|
-
* 维护按标签查找实体的索引结构。支持添加和移除操作。
|
|
6895
|
-
*
|
|
6896
|
-
* @param entity 要更新索引的实体
|
|
6897
|
-
* @param isAdd true表示添加到索引,false表示从索引中移除
|
|
6943
|
+
* 检查是否支持Worker
|
|
6898
6944
|
*/
|
|
6899
|
-
|
|
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 {
|
|
6945
|
+
isWorkerSupported(): boolean;
|
|
6944
6946
|
/**
|
|
6945
|
-
*
|
|
6946
|
-
*
|
|
6947
|
-
* 核心存储结构,处理所有实体和组件的索引操作。
|
|
6947
|
+
* 检查是否支持SharedArrayBuffer
|
|
6948
6948
|
*/
|
|
6949
|
-
|
|
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();
|
|
6949
|
+
isSharedArrayBufferSupported(): boolean;
|
|
6969
6950
|
/**
|
|
6970
|
-
*
|
|
6951
|
+
* 获取硬件并发数(CPU核心数)
|
|
6971
6952
|
*/
|
|
6972
|
-
|
|
6953
|
+
getHardwareConcurrency(): number;
|
|
6973
6954
|
/**
|
|
6974
|
-
*
|
|
6955
|
+
* 创建Worker
|
|
6956
|
+
* @param script Worker脚本内容
|
|
6957
|
+
* @param options Worker选项
|
|
6975
6958
|
*/
|
|
6976
|
-
|
|
6959
|
+
createWorker(script: string, options?: WorkerCreationOptions): PlatformWorker;
|
|
6977
6960
|
/**
|
|
6978
|
-
*
|
|
6961
|
+
* 创建SharedArrayBuffer
|
|
6962
|
+
* @param length 缓冲区大小(字节)
|
|
6979
6963
|
*/
|
|
6980
|
-
|
|
6964
|
+
createSharedArrayBuffer(length: number): SharedArrayBuffer | null;
|
|
6981
6965
|
/**
|
|
6982
|
-
*
|
|
6966
|
+
* 获取高精度时间戳
|
|
6983
6967
|
*/
|
|
6984
|
-
|
|
6968
|
+
getHighResTimestamp(): number;
|
|
6985
6969
|
/**
|
|
6986
|
-
*
|
|
6970
|
+
* 获取平台特定的配置
|
|
6987
6971
|
*/
|
|
6988
|
-
|
|
6972
|
+
getPlatformConfig(): PlatformConfig;
|
|
6989
6973
|
/**
|
|
6990
|
-
*
|
|
6974
|
+
* 异步获取平台配置(包含需要异步获取的信息)
|
|
6991
6975
|
*/
|
|
6992
|
-
|
|
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;
|
|
6976
|
+
getPlatformConfigAsync?(): Promise<PlatformConfig>;
|
|
7032
6977
|
}
|
|
7033
6978
|
/**
|
|
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
|
-
* ```
|
|
6979
|
+
* Worker创建选项
|
|
7085
6980
|
*/
|
|
7086
|
-
|
|
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;
|
|
6981
|
+
interface WorkerCreationOptions {
|
|
7101
6982
|
/**
|
|
7102
|
-
*
|
|
7103
|
-
*
|
|
7104
|
-
* @param entity 要标记的实体
|
|
7105
|
-
* @param flags 脏标记位
|
|
7106
|
-
* @param modifiedComponents 修改的组件类型列表
|
|
6983
|
+
* Worker类型
|
|
7107
6984
|
*/
|
|
7108
|
-
|
|
6985
|
+
type?: 'classic' | 'module';
|
|
7109
6986
|
/**
|
|
7110
|
-
*
|
|
7111
|
-
*
|
|
7112
|
-
* @param entity 要检查的实体
|
|
7113
|
-
* @param flags 要检查的标记位
|
|
7114
|
-
* @returns 是否有指定的脏标记
|
|
6987
|
+
* 凭据模式
|
|
7115
6988
|
*/
|
|
7116
|
-
|
|
6989
|
+
credentials?: 'omit' | 'same-origin' | 'include';
|
|
7117
6990
|
/**
|
|
7118
|
-
*
|
|
7119
|
-
*
|
|
7120
|
-
* @param entity 要清除的实体
|
|
7121
|
-
* @param flags 要清除的标记位,默认清除所有
|
|
6991
|
+
* Worker名称(用于调试)
|
|
7122
6992
|
*/
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
*/
|
|
7130
|
-
getDirtyEntities(flags?: DirtyFlag): DirtyData[];
|
|
6993
|
+
name?: string;
|
|
6994
|
+
}
|
|
6995
|
+
/**
|
|
6996
|
+
* 平台Worker接口
|
|
6997
|
+
*/
|
|
6998
|
+
interface PlatformWorker {
|
|
7131
6999
|
/**
|
|
7132
|
-
*
|
|
7133
|
-
*
|
|
7134
|
-
* 使用时间分片的方式处理脏实体,避免单帧卡顿
|
|
7000
|
+
* 发送消息到Worker
|
|
7135
7001
|
*/
|
|
7136
|
-
|
|
7002
|
+
postMessage(message: any, transfer?: Transferable[]): void;
|
|
7137
7003
|
/**
|
|
7138
|
-
*
|
|
7139
|
-
*
|
|
7140
|
-
* @param listener 监听器配置
|
|
7004
|
+
* 监听Worker消息
|
|
7141
7005
|
*/
|
|
7142
|
-
|
|
7006
|
+
onMessage(handler: (event: {
|
|
7007
|
+
data: any;
|
|
7008
|
+
}) => void): void;
|
|
7143
7009
|
/**
|
|
7144
|
-
*
|
|
7145
|
-
*
|
|
7146
|
-
* @param callback 要移除的回调函数
|
|
7010
|
+
* 监听Worker错误
|
|
7147
7011
|
*/
|
|
7148
|
-
|
|
7012
|
+
onError(handler: (error: ErrorEvent) => void): void;
|
|
7149
7013
|
/**
|
|
7150
|
-
*
|
|
7014
|
+
* 终止Worker
|
|
7151
7015
|
*/
|
|
7152
|
-
|
|
7016
|
+
terminate(): void;
|
|
7153
7017
|
/**
|
|
7154
|
-
*
|
|
7018
|
+
* Worker状态
|
|
7155
7019
|
*/
|
|
7156
|
-
|
|
7020
|
+
readonly state: 'running' | 'terminated';
|
|
7021
|
+
}
|
|
7022
|
+
/**
|
|
7023
|
+
* 平台配置
|
|
7024
|
+
*/
|
|
7025
|
+
interface PlatformConfig {
|
|
7157
7026
|
/**
|
|
7158
|
-
*
|
|
7027
|
+
* 最大Worker数量限制
|
|
7159
7028
|
*/
|
|
7160
|
-
|
|
7029
|
+
maxWorkerCount: number;
|
|
7161
7030
|
/**
|
|
7162
|
-
*
|
|
7031
|
+
* 是否支持模块Worker
|
|
7163
7032
|
*/
|
|
7164
|
-
|
|
7033
|
+
supportsModuleWorker: boolean;
|
|
7165
7034
|
/**
|
|
7166
|
-
*
|
|
7167
|
-
*
|
|
7168
|
-
* @param batchSize 每次处理的最大实体数量
|
|
7169
|
-
* @param maxProcessingTime 每帧最大处理时间(毫秒)
|
|
7035
|
+
* 是否支持Transferable Objects
|
|
7170
7036
|
*/
|
|
7171
|
-
|
|
7037
|
+
supportsTransferableObjects: boolean;
|
|
7172
7038
|
/**
|
|
7173
|
-
*
|
|
7039
|
+
* SharedArrayBuffer的最大大小限制(字节)
|
|
7174
7040
|
*/
|
|
7175
|
-
|
|
7041
|
+
maxSharedArrayBufferSize?: number;
|
|
7176
7042
|
/**
|
|
7177
|
-
*
|
|
7043
|
+
* 平台特定的Worker脚本前缀(如果需要)
|
|
7178
7044
|
*/
|
|
7179
|
-
|
|
7045
|
+
workerScriptPrefix?: string;
|
|
7180
7046
|
/**
|
|
7181
|
-
*
|
|
7047
|
+
* 平台特定的限制和特性
|
|
7182
7048
|
*/
|
|
7183
|
-
|
|
7049
|
+
limitations?: {
|
|
7050
|
+
/**
|
|
7051
|
+
* 是否禁用eval(影响动态脚本创建)
|
|
7052
|
+
*/
|
|
7053
|
+
noEval?: boolean;
|
|
7054
|
+
/**
|
|
7055
|
+
* 是否需要特殊的Worker初始化
|
|
7056
|
+
*/
|
|
7057
|
+
requiresWorkerInit?: boolean;
|
|
7058
|
+
/**
|
|
7059
|
+
* 内存限制(字节)
|
|
7060
|
+
*/
|
|
7061
|
+
memoryLimit?: number;
|
|
7062
|
+
/**
|
|
7063
|
+
* Worker是否不受支持(用于明确标记不支持Worker的平台)
|
|
7064
|
+
*/
|
|
7065
|
+
workerNotSupported?: boolean;
|
|
7066
|
+
/**
|
|
7067
|
+
* Worker限制说明列表
|
|
7068
|
+
*/
|
|
7069
|
+
workerLimitations?: string[];
|
|
7070
|
+
};
|
|
7184
7071
|
/**
|
|
7185
|
-
*
|
|
7072
|
+
* 平台特定的扩展属性
|
|
7186
7073
|
*/
|
|
7187
|
-
|
|
7074
|
+
extensions?: Record<string, any>;
|
|
7188
7075
|
}
|
|
7189
|
-
|
|
7190
7076
|
/**
|
|
7191
|
-
*
|
|
7077
|
+
* 平台检测结果
|
|
7192
7078
|
*/
|
|
7193
|
-
|
|
7194
|
-
private pool;
|
|
7195
|
-
private createFn;
|
|
7196
|
-
private resetFn?;
|
|
7197
|
-
private maxSize;
|
|
7198
|
-
constructor(createFn: () => T, resetFn?: (component: T) => void, maxSize?: number);
|
|
7079
|
+
interface PlatformDetectionResult {
|
|
7199
7080
|
/**
|
|
7200
|
-
*
|
|
7201
|
-
*/
|
|
7202
|
-
acquire(): T;
|
|
7203
|
-
/**
|
|
7204
|
-
* 释放一个组件实例回池中
|
|
7205
|
-
*/
|
|
7206
|
-
release(component: T): void;
|
|
7207
|
-
/**
|
|
7208
|
-
* 预填充对象池
|
|
7081
|
+
* 平台类型
|
|
7209
7082
|
*/
|
|
7210
|
-
|
|
7083
|
+
platform: 'browser' | 'wechat-minigame' | 'bytedance-minigame' | 'alipay-minigame' | 'baidu-minigame' | 'nodejs' | 'unknown';
|
|
7211
7084
|
/**
|
|
7212
|
-
*
|
|
7085
|
+
* 是否确定检测结果
|
|
7213
7086
|
*/
|
|
7214
|
-
|
|
7087
|
+
confident: boolean;
|
|
7215
7088
|
/**
|
|
7216
|
-
*
|
|
7089
|
+
* 检测到的特征
|
|
7217
7090
|
*/
|
|
7218
|
-
|
|
7091
|
+
features: string[];
|
|
7219
7092
|
/**
|
|
7220
|
-
*
|
|
7093
|
+
* 建议使用的适配器类名
|
|
7221
7094
|
*/
|
|
7222
|
-
|
|
7095
|
+
adapterClass?: string;
|
|
7223
7096
|
}
|
|
7097
|
+
|
|
7224
7098
|
/**
|
|
7225
|
-
*
|
|
7099
|
+
* 平台检测器
|
|
7100
|
+
* 自动检测当前运行环境并返回对应的平台信息
|
|
7226
7101
|
*/
|
|
7227
|
-
declare class
|
|
7228
|
-
private static instance;
|
|
7229
|
-
private pools;
|
|
7230
|
-
private constructor();
|
|
7231
|
-
static getInstance(): ComponentPoolManager;
|
|
7102
|
+
declare class PlatformDetector {
|
|
7232
7103
|
/**
|
|
7233
|
-
*
|
|
7104
|
+
* 检测当前平台
|
|
7234
7105
|
*/
|
|
7235
|
-
|
|
7236
|
-
/**
|
|
7237
|
-
* 获取组件实例
|
|
7238
|
-
*/
|
|
7239
|
-
acquireComponent<T extends Component>(componentName: string): T | null;
|
|
7240
|
-
/**
|
|
7241
|
-
* 释放组件实例
|
|
7242
|
-
*/
|
|
7243
|
-
releaseComponent<T extends Component>(componentName: string, component: T): void;
|
|
7244
|
-
/**
|
|
7245
|
-
* 预热所有池
|
|
7246
|
-
*/
|
|
7247
|
-
prewarmAll(count?: number): void;
|
|
7106
|
+
static detect(): PlatformDetectionResult;
|
|
7248
7107
|
/**
|
|
7249
|
-
*
|
|
7108
|
+
* 检测是否为微信小游戏环境
|
|
7250
7109
|
*/
|
|
7251
|
-
|
|
7110
|
+
private static isWeChatMiniGame;
|
|
7252
7111
|
/**
|
|
7253
|
-
*
|
|
7112
|
+
* 检测是否为字节跳动小游戏环境
|
|
7254
7113
|
*/
|
|
7255
|
-
|
|
7114
|
+
private static isByteDanceMiniGame;
|
|
7256
7115
|
/**
|
|
7257
|
-
*
|
|
7116
|
+
* 检测是否为Node.js环境
|
|
7258
7117
|
*/
|
|
7259
|
-
|
|
7260
|
-
available: number;
|
|
7261
|
-
maxSize: number;
|
|
7262
|
-
}>;
|
|
7118
|
+
private static isNodeJS;
|
|
7263
7119
|
/**
|
|
7264
|
-
*
|
|
7120
|
+
* 检测是否为支付宝小游戏环境
|
|
7265
7121
|
*/
|
|
7266
|
-
|
|
7267
|
-
used: number;
|
|
7268
|
-
total: number;
|
|
7269
|
-
utilization: number;
|
|
7270
|
-
}>;
|
|
7122
|
+
private static isAlipayMiniGame;
|
|
7271
7123
|
/**
|
|
7272
|
-
*
|
|
7124
|
+
* 检测是否为百度小游戏环境
|
|
7273
7125
|
*/
|
|
7274
|
-
|
|
7275
|
-
}
|
|
7276
|
-
|
|
7277
|
-
/**
|
|
7278
|
-
* 类型工具类
|
|
7279
|
-
* 提供类型相关的实用方法
|
|
7280
|
-
*/
|
|
7281
|
-
declare class TypeUtils {
|
|
7126
|
+
private static isBaiduMiniGame;
|
|
7282
7127
|
/**
|
|
7283
|
-
*
|
|
7284
|
-
* @param obj 对象
|
|
7285
|
-
* @returns 对象的构造函数
|
|
7128
|
+
* 检测是否为浏览器环境
|
|
7286
7129
|
*/
|
|
7287
|
-
static
|
|
7288
|
-
}
|
|
7289
|
-
|
|
7290
|
-
/**
|
|
7291
|
-
* 数字扩展工具类
|
|
7292
|
-
* 提供数字转换的实用方法
|
|
7293
|
-
*/
|
|
7294
|
-
declare class NumberExtension {
|
|
7130
|
+
private static isBrowser;
|
|
7295
7131
|
/**
|
|
7296
|
-
*
|
|
7297
|
-
* @param value 要转换的值
|
|
7298
|
-
* @returns 转换后的数字,如果值为undefined则返回0
|
|
7132
|
+
* 获取详细的环境信息(用于调试)
|
|
7299
7133
|
*/
|
|
7300
|
-
static
|
|
7134
|
+
static getDetailedInfo(): Record<string, any>;
|
|
7301
7135
|
}
|
|
7302
7136
|
|
|
7303
7137
|
/**
|
|
7304
|
-
*
|
|
7305
|
-
*
|
|
7138
|
+
* 平台管理器
|
|
7139
|
+
* 用户需要手动注册平台适配器
|
|
7306
7140
|
*/
|
|
7307
|
-
declare class
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7141
|
+
declare class PlatformManager {
|
|
7142
|
+
private static instance;
|
|
7143
|
+
private adapter;
|
|
7144
|
+
private readonly logger;
|
|
7145
|
+
private constructor();
|
|
7312
7146
|
/**
|
|
7313
|
-
*
|
|
7147
|
+
* 获取单例实例
|
|
7314
7148
|
*/
|
|
7315
|
-
static
|
|
7149
|
+
static getInstance(): PlatformManager;
|
|
7316
7150
|
/**
|
|
7317
|
-
*
|
|
7151
|
+
* 获取当前平台适配器
|
|
7318
7152
|
*/
|
|
7319
|
-
|
|
7153
|
+
getAdapter(): IPlatformAdapter;
|
|
7320
7154
|
/**
|
|
7321
|
-
*
|
|
7155
|
+
* 注册平台适配器
|
|
7322
7156
|
*/
|
|
7323
|
-
|
|
7157
|
+
registerAdapter(adapter: IPlatformAdapter): void;
|
|
7324
7158
|
/**
|
|
7325
|
-
*
|
|
7159
|
+
* 检查是否已注册适配器
|
|
7326
7160
|
*/
|
|
7327
|
-
|
|
7161
|
+
hasAdapter(): boolean;
|
|
7328
7162
|
/**
|
|
7329
|
-
*
|
|
7163
|
+
* 获取平台适配器信息(用于调试)
|
|
7330
7164
|
*/
|
|
7331
|
-
|
|
7165
|
+
getAdapterInfo(): any;
|
|
7332
7166
|
/**
|
|
7333
|
-
*
|
|
7334
|
-
* @param deltaTime 外部引擎提供的帧时间间隔(秒)
|
|
7167
|
+
* 检查当前平台是否支持特定功能
|
|
7335
7168
|
*/
|
|
7336
|
-
|
|
7169
|
+
supportsFeature(feature: 'worker' | 'shared-array-buffer' | 'transferable-objects' | 'module-worker'): boolean;
|
|
7337
7170
|
/**
|
|
7338
|
-
*
|
|
7171
|
+
* 获取基础的Worker配置信息(不做自动决策)
|
|
7172
|
+
* 用户应该根据自己的业务需求来配置Worker参数
|
|
7339
7173
|
*/
|
|
7340
|
-
|
|
7174
|
+
getBasicWorkerConfig(): {
|
|
7175
|
+
platformSupportsWorker: boolean;
|
|
7176
|
+
platformSupportsSharedArrayBuffer: boolean;
|
|
7177
|
+
platformMaxWorkerCount: number;
|
|
7178
|
+
platformLimitations: any;
|
|
7179
|
+
};
|
|
7341
7180
|
/**
|
|
7342
|
-
*
|
|
7343
|
-
* @param interval 时间间隔(秒)
|
|
7344
|
-
* @param lastTime 上次检查的时间
|
|
7345
|
-
* @returns 是否已经过去指定时间
|
|
7181
|
+
* 异步获取完整的平台配置信息(包含性能信息)
|
|
7346
7182
|
*/
|
|
7347
|
-
|
|
7183
|
+
getFullPlatformConfig(): Promise<any>;
|
|
7348
7184
|
}
|
|
7349
7185
|
|
|
7350
|
-
|
|
7351
|
-
|
|
7186
|
+
/**
|
|
7187
|
+
* 平台适配模块导出
|
|
7188
|
+
*/
|
|
7189
|
+
|
|
7190
|
+
declare function registerPlatformAdapter(adapter: IPlatformAdapter): void;
|
|
7191
|
+
declare function getCurrentAdapter(): IPlatformAdapter;
|
|
7192
|
+
declare function getBasicWorkerConfig(): {
|
|
7193
|
+
platformSupportsWorker: boolean;
|
|
7194
|
+
platformSupportsSharedArrayBuffer: boolean;
|
|
7195
|
+
platformMaxWorkerCount: number;
|
|
7196
|
+
platformLimitations: any;
|
|
7197
|
+
};
|
|
7198
|
+
declare function getFullPlatformConfig(): Promise<any>;
|
|
7199
|
+
declare function supportsFeature(feature: 'worker' | 'shared-array-buffer' | 'transferable-objects' | 'module-worker'): boolean;
|
|
7200
|
+
declare function hasAdapter(): boolean;
|
|
7201
|
+
|
|
7202
|
+
export { 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, EventPriority, EventTypeValidator, Float32, Float64, FuncPack, GlobalEventBus, GlobalManager, HighPrecision, IdentifierPool, Int32, IntervalSystem, LogLevel, Logger, LoggerManager, Matcher, NumberExtension, PassiveSystem, PerformanceDataCollector, PerformanceMonitor, PerformanceWarningType, PlatformDetector, PlatformManager, Pool, PoolManager, ProcessingSystem, QuerySystem, SYSTEM_TYPE_NAME, Scene, SceneDataCollector, SerializeMap, SoAStorage, SparseSet, SystemDataCollector, Time, Timer, TimerManager, TypeSafeEventSystem, TypeUtils, WebSocketManager, WorkerEntitySystem, World, WorldManager, createECSAPI, createLogger, getBasicWorkerConfig, getComponentInstanceTypeName, getComponentTypeName, getCurrentAdapter, getFullPlatformConfig, getSystemInstanceTypeName, getSystemTypeName, hasAdapter, registerPlatformAdapter, resetLoggerColors, setGlobalLogLevel, setLoggerColors, supportsFeature };
|
|
7203
|
+
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, IPlatformAdapter, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IWorldConfig, IWorldManagerConfig, LoggerColorConfig, LoggerConfig, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PlatformConfig, PlatformDetectionResult, PlatformWorker, PoolStats, SharedArrayBufferProcessFunction, WorkerCreationOptions, WorkerProcessFunction, WorkerSystemConfig };
|