@esengine/ecs-framework 2.0.6 → 2.0.7
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/bin/Core.js +21 -17
- package/bin/Core.js.map +1 -1
- package/bin/ECS/Component.js +5 -1
- package/bin/ECS/Component.js.map +1 -1
- package/bin/ECS/Components/IUpdatable.js +7 -2
- package/bin/ECS/Components/IUpdatable.js.map +1 -1
- package/bin/ECS/Components/SceneComponent.js +5 -1
- package/bin/ECS/Components/SceneComponent.js.map +1 -1
- package/bin/ECS/Core/BitMaskOptimizer.d.ts +75 -0
- package/bin/ECS/Core/BitMaskOptimizer.d.ts.map +1 -0
- package/bin/ECS/Core/BitMaskOptimizer.js +165 -0
- package/bin/ECS/Core/BitMaskOptimizer.js.map +1 -0
- package/bin/ECS/Core/ComponentPool.d.ts +72 -0
- package/bin/ECS/Core/ComponentPool.d.ts.map +1 -0
- package/bin/ECS/Core/ComponentPool.js +128 -0
- package/bin/ECS/Core/ComponentPool.js.map +1 -0
- package/bin/ECS/Core/ComponentStorage.js +9 -3
- package/bin/ECS/Core/ComponentStorage.js.map +1 -1
- package/bin/ECS/Core/EventSystem.js +12 -6
- package/bin/ECS/Core/EventSystem.js.map +1 -1
- package/bin/ECS/Core/FluentAPI.js +24 -17
- package/bin/ECS/Core/FluentAPI.js.map +1 -1
- package/bin/ECS/Core/IndexUpdateBatcher.d.ts +100 -0
- package/bin/ECS/Core/IndexUpdateBatcher.d.ts.map +1 -0
- package/bin/ECS/Core/IndexUpdateBatcher.js +223 -0
- package/bin/ECS/Core/IndexUpdateBatcher.js.map +1 -0
- package/bin/ECS/Core/QuerySystem.d.ts +292 -444
- package/bin/ECS/Core/QuerySystem.d.ts.map +1 -1
- package/bin/ECS/Core/QuerySystem.js +661 -1075
- package/bin/ECS/Core/QuerySystem.js.map +1 -1
- package/bin/ECS/CoreEvents.js +5 -2
- package/bin/ECS/CoreEvents.js.map +1 -1
- package/bin/ECS/Entity.js +17 -12
- package/bin/ECS/Entity.js.map +1 -1
- package/bin/ECS/Scene.d.ts +18 -2
- package/bin/ECS/Scene.d.ts.map +1 -1
- package/bin/ECS/Scene.js +67 -19
- package/bin/ECS/Scene.js.map +1 -1
- package/bin/ECS/Systems/EntitySystem.js +9 -5
- package/bin/ECS/Systems/EntitySystem.js.map +1 -1
- package/bin/ECS/Systems/IntervalSystem.js +8 -4
- package/bin/ECS/Systems/IntervalSystem.js.map +1 -1
- package/bin/ECS/Systems/PassiveSystem.js +6 -2
- package/bin/ECS/Systems/PassiveSystem.js.map +1 -1
- package/bin/ECS/Systems/ProcessingSystem.js +6 -2
- package/bin/ECS/Systems/ProcessingSystem.js.map +1 -1
- package/bin/ECS/Systems/index.js +11 -4
- package/bin/ECS/Systems/index.js.map +1 -1
- package/bin/ECS/Utils/Bits.js +5 -1
- package/bin/ECS/Utils/Bits.js.map +1 -1
- package/bin/ECS/Utils/ComponentTypeManager.js +8 -4
- package/bin/ECS/Utils/ComponentTypeManager.js.map +1 -1
- package/bin/ECS/Utils/EntityList.js +5 -1
- package/bin/ECS/Utils/EntityList.js.map +1 -1
- package/bin/ECS/Utils/EntityProcessorList.js +5 -1
- package/bin/ECS/Utils/EntityProcessorList.js.map +1 -1
- package/bin/ECS/Utils/IdentifierPool.js +5 -1
- package/bin/ECS/Utils/IdentifierPool.js.map +1 -1
- package/bin/ECS/Utils/Matcher.js +8 -4
- package/bin/ECS/Utils/Matcher.js.map +1 -1
- package/bin/ECS/Utils/index.js +15 -6
- package/bin/ECS/Utils/index.js.map +1 -1
- package/bin/ECS/index.js +27 -6
- package/bin/ECS/index.js.map +1 -1
- package/bin/Testing/Performance/benchmark.d.ts +6 -0
- package/bin/Testing/Performance/benchmark.d.ts.map +1 -0
- package/bin/Testing/Performance/benchmark.js +639 -0
- package/bin/Testing/Performance/benchmark.js.map +1 -0
- package/bin/Testing/Unit/bitmask-optimizer.test.d.ts +2 -0
- package/bin/Testing/Unit/bitmask-optimizer.test.d.ts.map +1 -0
- package/bin/Testing/Unit/bitmask-optimizer.test.js +164 -0
- package/bin/Testing/Unit/bitmask-optimizer.test.js.map +1 -0
- package/bin/Testing/Unit/component-pool.test.d.ts +5 -0
- package/bin/Testing/Unit/component-pool.test.d.ts.map +1 -0
- package/bin/Testing/Unit/component-pool.test.js +149 -0
- package/bin/Testing/Unit/component-pool.test.js.map +1 -0
- package/bin/Testing/test-runner.d.ts +51 -0
- package/bin/Testing/test-runner.d.ts.map +1 -0
- package/bin/Testing/test-runner.js +159 -0
- package/bin/Testing/test-runner.js.map +1 -0
- package/bin/Types/index.js +7 -4
- package/bin/Types/index.js.map +1 -1
- package/bin/Utils/Emitter.js +7 -2
- package/bin/Utils/Emitter.js.map +1 -1
- package/bin/Utils/Extensions/NumberExtension.js +5 -1
- package/bin/Utils/Extensions/NumberExtension.js.map +1 -1
- package/bin/Utils/Extensions/TypeUtils.js +5 -1
- package/bin/Utils/Extensions/TypeUtils.js.map +1 -1
- package/bin/Utils/Extensions/index.js +7 -2
- package/bin/Utils/Extensions/index.js.map +1 -1
- package/bin/Utils/GlobalManager.js +5 -1
- package/bin/Utils/GlobalManager.js.map +1 -1
- package/bin/Utils/PerformanceMonitor.js +7 -3
- package/bin/Utils/PerformanceMonitor.js.map +1 -1
- package/bin/Utils/Pool.js +9 -3
- package/bin/Utils/Pool.js.map +1 -1
- package/bin/Utils/Time.js +5 -1
- package/bin/Utils/Time.js.map +1 -1
- package/bin/Utils/Timers/ITimer.js +2 -1
- package/bin/Utils/Timers/Timer.js +7 -3
- package/bin/Utils/Timers/Timer.js.map +1 -1
- package/bin/Utils/Timers/TimerManager.js +8 -4
- package/bin/Utils/Timers/TimerManager.js.map +1 -1
- package/bin/Utils/WasmCore.d.ts +234 -0
- package/bin/Utils/WasmCore.d.ts.map +1 -0
- package/bin/Utils/WasmCore.js +634 -0
- package/bin/Utils/WasmCore.js.map +1 -0
- package/bin/Utils/index.d.ts +10 -0
- package/bin/Utils/index.d.ts.map +1 -1
- package/bin/Utils/index.js +36 -5
- package/bin/Utils/index.js.map +1 -1
- package/bin/index.d.ts +1 -2
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +42 -14
- package/bin/index.js.map +1 -1
- package/package.json +54 -74
- package/bin/Utils/AccelerationProvider.d.ts +0 -192
- package/bin/Utils/AccelerationProvider.d.ts.map +0 -1
- package/bin/Utils/AccelerationProvider.js +0 -261
- package/bin/Utils/AccelerationProvider.js.map +0 -1
- package/bin/Utils/WasmBridge.d.ts +0 -152
- package/bin/Utils/WasmBridge.d.ts.map +0 -1
- package/bin/Utils/WasmBridge.js +0 -336
- package/bin/Utils/WasmBridge.js.map +0 -1
|
@@ -13,7 +13,7 @@ export declare enum QueryConditionType {
|
|
|
13
13
|
NONE = "none"
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* 查询条件接口
|
|
17
17
|
*/
|
|
18
18
|
export interface QueryCondition {
|
|
19
19
|
type: QueryConditionType;
|
|
@@ -21,30 +21,7 @@ export interface QueryCondition {
|
|
|
21
21
|
mask: bigint;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
|
-
export type ComponentTuple<T extends readonly ComponentType[]> = {
|
|
27
|
-
[K in keyof T]: T[K] extends ComponentType<infer C> ? C : never;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* 类型安全的查询结果
|
|
31
|
-
*/
|
|
32
|
-
export interface TypedQueryResult<T extends readonly ComponentType[]> {
|
|
33
|
-
entities: Entity[];
|
|
34
|
-
components: ComponentTuple<T>[];
|
|
35
|
-
count: number;
|
|
36
|
-
executionTime: number;
|
|
37
|
-
fromCache: boolean;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 实体和组件的配对结果
|
|
41
|
-
*/
|
|
42
|
-
export interface EntityComponentPair<T extends readonly ComponentType[]> {
|
|
43
|
-
entity: Entity;
|
|
44
|
-
components: ComponentTuple<T>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* 实体查询结果
|
|
24
|
+
* 实体查询结果接口
|
|
48
25
|
*/
|
|
49
26
|
export interface QueryResult {
|
|
50
27
|
entities: Entity[];
|
|
@@ -54,521 +31,392 @@ export interface QueryResult {
|
|
|
54
31
|
/** 是否来自缓存 */
|
|
55
32
|
fromCache: boolean;
|
|
56
33
|
}
|
|
57
|
-
/**
|
|
58
|
-
* 查询性能统计
|
|
59
|
-
*/
|
|
60
|
-
interface QueryPerformanceStats {
|
|
61
|
-
totalQueries: number;
|
|
62
|
-
averageExecutionTime: number;
|
|
63
|
-
cacheHitRate: number;
|
|
64
|
-
indexHitRate: number;
|
|
65
|
-
slowQueries: Array<{
|
|
66
|
-
query: string;
|
|
67
|
-
executionTime: number;
|
|
68
|
-
timestamp: number;
|
|
69
|
-
}>;
|
|
70
|
-
}
|
|
71
34
|
/**
|
|
72
35
|
* 高性能实体查询系统
|
|
73
|
-
*
|
|
36
|
+
*
|
|
37
|
+
* 提供快速的实体查询功能,支持按组件类型、标签、名称等多种方式查询实体。
|
|
38
|
+
* 系统采用多级索引和智能缓存机制,确保在大量实体场景下的查询性能。
|
|
39
|
+
*
|
|
40
|
+
* 主要特性:
|
|
41
|
+
* - 支持单组件和多组件查询
|
|
42
|
+
* - 自动索引管理和缓存优化
|
|
43
|
+
* - WebAssembly计算加速(如果可用)
|
|
44
|
+
* - 详细的性能统计信息
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // 查询所有包含Position和Velocity组件的实体
|
|
49
|
+
* const movingEntities = querySystem.queryAll(PositionComponent, VelocityComponent);
|
|
50
|
+
*
|
|
51
|
+
* // 查询特定标签的实体
|
|
52
|
+
* const playerEntities = querySystem.queryByTag(PLAYER_TAG);
|
|
53
|
+
* ```
|
|
74
54
|
*/
|
|
75
55
|
export declare class QuerySystem {
|
|
76
56
|
private entities;
|
|
77
|
-
private
|
|
78
|
-
private cacheTimeout;
|
|
79
|
-
private maxCacheSize;
|
|
80
|
-
private cacheHits;
|
|
81
|
-
private cacheMisses;
|
|
57
|
+
private wasmAvailable;
|
|
82
58
|
private entityIndex;
|
|
83
|
-
private performanceStats;
|
|
84
59
|
private indexDirty;
|
|
85
|
-
private
|
|
86
|
-
private
|
|
87
|
-
private
|
|
88
|
-
private
|
|
89
|
-
private
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
60
|
+
private queryCache;
|
|
61
|
+
private cacheMaxSize;
|
|
62
|
+
private cacheTimeout;
|
|
63
|
+
private componentPoolManager;
|
|
64
|
+
private bitMaskOptimizer;
|
|
65
|
+
private indexUpdateBatcher;
|
|
66
|
+
private queryStats;
|
|
67
|
+
constructor();
|
|
68
|
+
/**
|
|
69
|
+
* 初始化WebAssembly支持
|
|
70
|
+
*
|
|
71
|
+
* 自动检测运行环境并启用WebAssembly计算加速。
|
|
72
|
+
* 如果WebAssembly不可用,系统将自动回退到JavaScript实现。
|
|
73
|
+
*/
|
|
74
|
+
private initializeWasm;
|
|
75
|
+
/**
|
|
76
|
+
* 设置实体列表并重建索引
|
|
77
|
+
*
|
|
78
|
+
* 当实体集合发生大规模变化时调用此方法。
|
|
79
|
+
* 系统将重新构建所有索引以确保查询性能。
|
|
80
|
+
*
|
|
81
|
+
* @param entities 新的实体列表
|
|
93
82
|
*/
|
|
94
83
|
setEntities(entities: Entity[]): void;
|
|
95
84
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
85
|
+
* 添加单个实体到查询系统
|
|
86
|
+
*
|
|
87
|
+
* 将新实体添加到查询系统中,并自动更新相关索引。
|
|
88
|
+
* 为了提高批量添加性能,可以延迟缓存清理。
|
|
89
|
+
*
|
|
90
|
+
* @param entity 要添加的实体
|
|
91
|
+
* @param deferCacheClear 是否延迟缓存清理(用于批量操作)
|
|
98
92
|
*/
|
|
99
|
-
addEntity(entity: Entity): void;
|
|
93
|
+
addEntity(entity: Entity, deferCacheClear?: boolean): void;
|
|
100
94
|
/**
|
|
101
95
|
* 批量添加实体
|
|
102
|
-
*
|
|
96
|
+
*
|
|
97
|
+
* 高效地批量添加多个实体,减少缓存清理次数。
|
|
98
|
+
* 使用Set来避免O(n)的重复检查。
|
|
99
|
+
*
|
|
100
|
+
* @param entities 要添加的实体列表
|
|
103
101
|
*/
|
|
104
102
|
addEntities(entities: Entity[]): void;
|
|
105
103
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
104
|
+
* 批量添加实体(无重复检查版本)
|
|
105
|
+
*
|
|
106
|
+
* 假设所有实体都是新的,跳过重复检查以获得最大性能。
|
|
107
|
+
* 仅在确保没有重复实体时使用。
|
|
108
|
+
*
|
|
109
|
+
* @param entities 要添加的实体列表
|
|
108
110
|
*/
|
|
109
|
-
|
|
111
|
+
addEntitiesUnchecked(entities: Entity[]): void;
|
|
110
112
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
+
* 从查询系统移除实体
|
|
114
|
+
*
|
|
115
|
+
* 从查询系统中移除指定实体,并清理相关索引。
|
|
116
|
+
*
|
|
117
|
+
* @param entity 要移除的实体
|
|
113
118
|
*/
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* 调度批量更新
|
|
117
|
-
*/
|
|
118
|
-
private scheduleBatchUpdate;
|
|
119
|
-
/**
|
|
120
|
-
* 处理批量更新
|
|
121
|
-
*/
|
|
122
|
-
private processBatchUpdates;
|
|
123
|
-
/**
|
|
124
|
-
* 强制立即处理所有待处理的更新
|
|
125
|
-
*/
|
|
126
|
-
flushUpdates(): void;
|
|
127
|
-
/**
|
|
128
|
-
* 无效化所有索引
|
|
129
|
-
*/
|
|
130
|
-
private invalidateIndexes;
|
|
119
|
+
removeEntity(entity: Entity): void;
|
|
131
120
|
/**
|
|
132
|
-
*
|
|
133
|
-
* @param entity 实体
|
|
121
|
+
* 将实体添加到各种索引中(优化版本)
|
|
134
122
|
*/
|
|
135
123
|
private addEntityToIndexes;
|
|
136
124
|
/**
|
|
137
|
-
*
|
|
138
|
-
* @param entity 实体
|
|
125
|
+
* 从各种索引中移除实体
|
|
139
126
|
*/
|
|
140
127
|
private removeEntityFromIndexes;
|
|
141
128
|
/**
|
|
142
129
|
* 重建所有索引
|
|
130
|
+
*
|
|
131
|
+
* 清空并重新构建所有查询索引。
|
|
132
|
+
* 通常在大量实体变更后调用以确保索引一致性。
|
|
143
133
|
*/
|
|
144
134
|
private rebuildIndexes;
|
|
145
|
-
/**
|
|
146
|
-
* 确保索引是最新的
|
|
147
|
-
*/
|
|
148
|
-
private ensureIndexesUpdated;
|
|
149
135
|
/**
|
|
150
136
|
* 查询包含所有指定组件的实体
|
|
151
|
-
*
|
|
152
|
-
*
|
|
137
|
+
*
|
|
138
|
+
* 返回同时包含所有指定组件类型的实体列表。
|
|
139
|
+
* 系统会自动选择最高效的查询策略,包括索引查找和缓存机制。
|
|
140
|
+
*
|
|
141
|
+
* @param componentTypes 要查询的组件类型列表
|
|
142
|
+
* @returns 查询结果,包含匹配的实体和性能信息
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* // 查询同时具有位置和速度组件的实体
|
|
147
|
+
* const result = querySystem.queryAll(PositionComponent, VelocityComponent);
|
|
148
|
+
* console.log(`找到 ${result.count} 个移动实体`);
|
|
149
|
+
* ```
|
|
153
150
|
*/
|
|
154
151
|
queryAll(...componentTypes: ComponentType[]): QueryResult;
|
|
155
152
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
153
|
+
* 多组件查询算法
|
|
154
|
+
*
|
|
155
|
+
* 针对多组件查询场景的高效算法实现。
|
|
156
|
+
* 通过选择最小的组件集合作为起点,减少需要检查的实体数量。
|
|
157
|
+
*
|
|
158
|
+
* @param componentTypes 组件类型列表
|
|
159
|
+
* @returns 匹配的实体列表
|
|
159
160
|
*/
|
|
160
|
-
|
|
161
|
+
private queryMultipleComponents;
|
|
161
162
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
163
|
+
* 线性扫描查询
|
|
164
|
+
*
|
|
165
|
+
* 当索引不可用时的备用查询方法。
|
|
166
|
+
* 遍历所有实体进行组件匹配检查。
|
|
167
|
+
*
|
|
168
|
+
* @param componentTypes 组件类型列表
|
|
169
|
+
* @returns 匹配的实体列表
|
|
165
170
|
*/
|
|
166
|
-
|
|
171
|
+
private queryByLinearScan;
|
|
167
172
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
173
|
+
* 查询包含任意指定组件的实体
|
|
174
|
+
*
|
|
175
|
+
* 返回包含任意一个指定组件类型的实体列表。
|
|
176
|
+
* 使用集合合并算法确保高效的查询性能。
|
|
177
|
+
*
|
|
178
|
+
* @param componentTypes 要查询的组件类型列表
|
|
179
|
+
* @returns 查询结果,包含匹配的实体和性能信息
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* // 查询具有武器或护甲组件的实体
|
|
184
|
+
* const result = querySystem.queryAny(WeaponComponent, ArmorComponent);
|
|
185
|
+
* console.log(`找到 ${result.count} 个装备实体`);
|
|
186
|
+
* ```
|
|
171
187
|
*/
|
|
172
|
-
|
|
188
|
+
queryAny(...componentTypes: ComponentType[]): QueryResult;
|
|
173
189
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
190
|
+
* 查询不包含任何指定组件的实体
|
|
191
|
+
*
|
|
192
|
+
* 返回不包含任何指定组件类型的实体列表。
|
|
193
|
+
* 适用于排除特定类型实体的查询场景。
|
|
194
|
+
*
|
|
195
|
+
* @param componentTypes 要排除的组件类型列表
|
|
196
|
+
* @returns 查询结果,包含匹配的实体和性能信息
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* // 查询不具有AI和玩家控制组件的实体(如静态物体)
|
|
201
|
+
* const result = querySystem.queryNone(AIComponent, PlayerControlComponent);
|
|
202
|
+
* console.log(`找到 ${result.count} 个静态实体`);
|
|
203
|
+
* ```
|
|
176
204
|
*/
|
|
177
|
-
|
|
205
|
+
queryNone(...componentTypes: ComponentType[]): QueryResult;
|
|
178
206
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
207
|
+
* 按标签查询实体
|
|
208
|
+
*
|
|
209
|
+
* 返回具有指定标签的所有实体。
|
|
210
|
+
* 标签查询使用专用索引,具有很高的查询性能。
|
|
211
|
+
*
|
|
212
|
+
* @param tag 要查询的标签值
|
|
213
|
+
* @returns 查询结果,包含匹配的实体和性能信息
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* // 查询所有玩家实体
|
|
218
|
+
* const players = querySystem.queryByTag(PLAYER_TAG);
|
|
219
|
+
* ```
|
|
182
220
|
*/
|
|
183
221
|
queryByTag(tag: number): QueryResult;
|
|
184
222
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
223
|
+
* 按名称查询实体
|
|
224
|
+
*
|
|
225
|
+
* 返回具有指定名称的所有实体。
|
|
226
|
+
* 名称查询使用专用索引,适用于查找特定的命名实体。
|
|
227
|
+
*
|
|
228
|
+
* @param name 要查询的实体名称
|
|
229
|
+
* @returns 查询结果,包含匹配的实体和性能信息
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* // 查找名为"Player"的实体
|
|
234
|
+
* const player = querySystem.queryByName("Player");
|
|
235
|
+
* ```
|
|
188
236
|
*/
|
|
189
237
|
queryByName(name: string): QueryResult;
|
|
190
238
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
239
|
+
* 按单个组件类型查询实体
|
|
240
|
+
*
|
|
241
|
+
* 返回包含指定组件类型的所有实体。
|
|
242
|
+
* 这是最基础的查询方法,具有最高的查询性能。
|
|
243
|
+
*
|
|
244
|
+
* @param componentType 要查询的组件类型
|
|
245
|
+
* @returns 查询结果,包含匹配的实体和性能信息
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* // 查询所有具有位置组件的实体
|
|
250
|
+
* const entitiesWithPosition = querySystem.queryByComponent(PositionComponent);
|
|
251
|
+
* ```
|
|
194
252
|
*/
|
|
195
253
|
queryByComponent<T extends Component>(componentType: ComponentType<T>): QueryResult;
|
|
196
254
|
/**
|
|
197
|
-
*
|
|
198
|
-
* @param componentTypes 组件类型数组
|
|
199
|
-
* @returns 类型安全的查询结果
|
|
200
|
-
*/
|
|
201
|
-
queryAllTyped<T extends readonly ComponentType[]>(...componentTypes: T): TypedQueryResult<T>;
|
|
202
|
-
/**
|
|
203
|
-
* 查询具有特定组件组合的实体并返回组件实例
|
|
204
|
-
* @param componentTypes 组件类型数组
|
|
205
|
-
* @returns 实体和对应组件的映射
|
|
206
|
-
*/
|
|
207
|
-
queryWithComponents<T extends readonly ComponentType[]>(...componentTypes: T): EntityComponentPair<T>[];
|
|
208
|
-
/**
|
|
209
|
-
* 迭代查询结果,为每个匹配的实体执行回调
|
|
210
|
-
* @param componentTypes 组件类型数组
|
|
211
|
-
* @param callback 回调函数
|
|
212
|
-
*/
|
|
213
|
-
forEachWithComponents<T extends readonly ComponentType[]>(componentTypes: T, callback: (entity: Entity, components: ComponentTuple<T>) => void): void;
|
|
214
|
-
/**
|
|
215
|
-
* 查询单个组件类型的实体,返回类型安全的结果
|
|
216
|
-
* @param componentType 组件类型
|
|
217
|
-
* @returns 实体和组件的配对数组
|
|
218
|
-
*/
|
|
219
|
-
queryComponentTyped<T extends Component>(componentType: ComponentType<T>): Array<{
|
|
220
|
-
entity: Entity;
|
|
221
|
-
component: T;
|
|
222
|
-
}>;
|
|
223
|
-
/**
|
|
224
|
-
* 查询两个组件类型的实体,返回类型安全的结果
|
|
225
|
-
* @param componentType1 第一个组件类型
|
|
226
|
-
* @param componentType2 第二个组件类型
|
|
227
|
-
* @returns 实体和组件的配对数组
|
|
228
|
-
*/
|
|
229
|
-
queryTwoComponents<T1 extends Component, T2 extends Component>(componentType1: ComponentType<T1>, componentType2: ComponentType<T2>): Array<{
|
|
230
|
-
entity: Entity;
|
|
231
|
-
component1: T1;
|
|
232
|
-
component2: T2;
|
|
233
|
-
}>;
|
|
234
|
-
/**
|
|
235
|
-
* 查询三个组件类型的实体,返回类型安全的结果
|
|
236
|
-
* @param componentType1 第一个组件类型
|
|
237
|
-
* @param componentType2 第二个组件类型
|
|
238
|
-
* @param componentType3 第三个组件类型
|
|
239
|
-
* @returns 实体和组件的配对数组
|
|
240
|
-
*/
|
|
241
|
-
queryThreeComponents<T1 extends Component, T2 extends Component, T3 extends Component>(componentType1: ComponentType<T1>, componentType2: ComponentType<T2>, componentType3: ComponentType<T3>): Array<{
|
|
242
|
-
entity: Entity;
|
|
243
|
-
component1: T1;
|
|
244
|
-
component2: T2;
|
|
245
|
-
component3: T3;
|
|
246
|
-
}>;
|
|
247
|
-
/**
|
|
248
|
-
* 执行单个条件查询
|
|
249
|
-
* @param condition 查询条件
|
|
250
|
-
* @returns 查询结果
|
|
251
|
-
*/
|
|
252
|
-
private query;
|
|
253
|
-
/**
|
|
254
|
-
* 使用索引优化查询
|
|
255
|
-
* @param condition 查询条件
|
|
256
|
-
* @returns 查询结果或null(如果无法优化)
|
|
257
|
-
*/
|
|
258
|
-
private queryWithIndexOptimization;
|
|
259
|
-
/**
|
|
260
|
-
* 更新性能统计
|
|
261
|
-
* @param executionTime 执行时间
|
|
262
|
-
* @param fromIndex 是否来自索引
|
|
263
|
-
*/
|
|
264
|
-
private updatePerformanceStats;
|
|
265
|
-
/**
|
|
266
|
-
* 根据条件过滤实体
|
|
267
|
-
* @param entities 实体数组
|
|
268
|
-
* @param condition 查询条件
|
|
269
|
-
* @returns 过滤后的实体数组
|
|
270
|
-
*/
|
|
271
|
-
private filterEntitiesByCondition;
|
|
272
|
-
/**
|
|
273
|
-
* 检查实体是否匹配条件
|
|
274
|
-
* @param entity 实体
|
|
275
|
-
* @param condition 查询条件
|
|
276
|
-
* @returns 是否匹配
|
|
255
|
+
* 从缓存获取查询结果
|
|
277
256
|
*/
|
|
278
|
-
private
|
|
257
|
+
private getFromCache;
|
|
279
258
|
/**
|
|
280
|
-
*
|
|
281
|
-
* @param componentTypes 组件类型数组
|
|
282
|
-
* @returns 位掩码
|
|
259
|
+
* 添加查询结果到缓存
|
|
283
260
|
*/
|
|
284
|
-
private
|
|
261
|
+
private addToCache;
|
|
285
262
|
/**
|
|
286
|
-
*
|
|
287
|
-
* @param condition 查询条件
|
|
288
|
-
* @returns 缓存键
|
|
263
|
+
* 清理缓存
|
|
289
264
|
*/
|
|
290
|
-
private
|
|
265
|
+
private cleanupCache;
|
|
291
266
|
/**
|
|
292
|
-
*
|
|
293
|
-
* @param conditions 查询条件数组
|
|
294
|
-
* @returns 缓存键
|
|
267
|
+
* 清除所有查询缓存
|
|
295
268
|
*/
|
|
296
|
-
private
|
|
269
|
+
private clearQueryCache;
|
|
297
270
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*/
|
|
302
|
-
private getCachedResult;
|
|
303
|
-
/**
|
|
304
|
-
* 缓存查询结果
|
|
305
|
-
* @param cacheKey 缓存键
|
|
306
|
-
* @param entities 实体数组
|
|
307
|
-
*/
|
|
308
|
-
private cacheResult;
|
|
309
|
-
/**
|
|
310
|
-
* 清空查询缓存
|
|
271
|
+
* 公共方法:清理查询缓存
|
|
272
|
+
*
|
|
273
|
+
* 用于外部调用清理缓存,通常在批量操作后使用。
|
|
311
274
|
*/
|
|
312
275
|
clearCache(): void;
|
|
313
276
|
/**
|
|
314
|
-
*
|
|
315
|
-
|
|
316
|
-
|
|
277
|
+
* 批量更新实体组件
|
|
278
|
+
*
|
|
279
|
+
* 对大量实体进行批量组件更新操作。
|
|
280
|
+
* 当更新数量超过阈值时,系统会自动使用WebAssembly加速。
|
|
281
|
+
*
|
|
282
|
+
* @param updates 更新操作列表,包含实体ID和新的组件掩码
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* // 批量更新实体的组件配置
|
|
287
|
+
* const updates = [
|
|
288
|
+
* { entityId: 1, componentMask: BigInt(0b1011) },
|
|
289
|
+
* { entityId: 2, componentMask: BigInt(0b1101) }
|
|
290
|
+
* ];
|
|
291
|
+
* querySystem.batchUpdateComponents(updates);
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
batchUpdateComponents(updates: Array<{
|
|
295
|
+
entityId: number;
|
|
296
|
+
componentMask: bigint;
|
|
297
|
+
}>): void;
|
|
298
|
+
/**
|
|
299
|
+
* JavaScript实现的批量更新
|
|
300
|
+
*/
|
|
301
|
+
private batchUpdateComponentsJS;
|
|
302
|
+
/**
|
|
303
|
+
* 获取加速状态信息
|
|
304
|
+
*
|
|
305
|
+
* 返回当前查询系统的加速状态和性能信息。
|
|
306
|
+
* 包括WebAssembly可用性、缓存统计等详细信息。
|
|
307
|
+
*
|
|
308
|
+
* @returns 加速状态信息对象
|
|
309
|
+
*/
|
|
310
|
+
getAccelerationStatus(): {
|
|
311
|
+
wasmEnabled: boolean;
|
|
312
|
+
currentProvider: string;
|
|
313
|
+
availableProviders: string[];
|
|
314
|
+
performanceInfo?: any;
|
|
315
|
+
};
|
|
317
316
|
/**
|
|
318
|
-
*
|
|
317
|
+
* 切换加速提供者
|
|
318
|
+
*
|
|
319
|
+
* 兼容性接口,保持向后兼容。
|
|
320
|
+
* 系统会自动选择最佳的实现方式。
|
|
321
|
+
*
|
|
322
|
+
* @param providerName 提供者名称
|
|
323
|
+
* @returns 是否切换成功
|
|
324
|
+
*/
|
|
325
|
+
switchAccelerationProvider(providerName: string): Promise<boolean>;
|
|
326
|
+
/**
|
|
327
|
+
* 创建组件掩码
|
|
328
|
+
*
|
|
329
|
+
* 根据组件类型列表生成对应的位掩码。
|
|
330
|
+
* 使用位掩码优化器进行缓存和预计算。
|
|
331
|
+
*
|
|
332
|
+
* @param componentTypes 组件类型列表
|
|
333
|
+
* @returns 生成的位掩码
|
|
334
|
+
*/
|
|
335
|
+
private createComponentMask;
|
|
336
|
+
/**
|
|
337
|
+
* 获取系统统计信息
|
|
338
|
+
*
|
|
339
|
+
* 返回查询系统的详细统计信息,包括实体数量、索引状态、
|
|
340
|
+
* 查询性能统计等,用于性能监控和调试。
|
|
341
|
+
*
|
|
342
|
+
* @returns 系统统计信息对象
|
|
319
343
|
*/
|
|
320
344
|
getStats(): {
|
|
321
345
|
entityCount: number;
|
|
322
|
-
cacheSize: number;
|
|
323
|
-
cacheHits: number;
|
|
324
|
-
cacheMisses: number;
|
|
325
|
-
hitRate: number;
|
|
326
|
-
maxCacheSize: number;
|
|
327
346
|
indexStats: {
|
|
328
347
|
maskIndexSize: number;
|
|
329
348
|
componentIndexSize: number;
|
|
330
349
|
tagIndexSize: number;
|
|
331
350
|
nameIndexSize: number;
|
|
332
351
|
};
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
*/
|
|
342
|
-
optimizeIndexes(): void;
|
|
343
|
-
/**
|
|
344
|
-
* 批量查询多个条件
|
|
345
|
-
* @param queries 查询条件数组
|
|
346
|
-
* @returns 查询结果数组
|
|
347
|
-
*/
|
|
348
|
-
batchQuery(queries: QueryCondition[]): QueryResult[];
|
|
349
|
-
/**
|
|
350
|
-
* 设置缓存配置
|
|
351
|
-
* @param maxSize 最大缓存大小
|
|
352
|
-
* @param timeout 缓存超时时间(毫秒)
|
|
353
|
-
*/
|
|
354
|
-
setCacheConfig(maxSize: number, timeout: number): void;
|
|
355
|
-
/**
|
|
356
|
-
* 重置统计信息
|
|
357
|
-
*/
|
|
358
|
-
resetStats(): void;
|
|
359
|
-
/**
|
|
360
|
-
* 预热查询缓存
|
|
361
|
-
* @param commonQueries 常用查询条件数组
|
|
362
|
-
*/
|
|
363
|
-
warmUpCache(commonQueries: QueryCondition[]): void;
|
|
364
|
-
/**
|
|
365
|
-
* 获取实体变更监听器
|
|
366
|
-
* @param condition 查询条件
|
|
367
|
-
* @param callback 变更回调
|
|
368
|
-
* @returns 取消监听的函数
|
|
369
|
-
*/
|
|
370
|
-
watchQuery(condition: QueryCondition, callback: (entities: Entity[], changeType: 'added' | 'removed' | 'updated') => void): () => void;
|
|
371
|
-
/**
|
|
372
|
-
* 获取查询结果的快照
|
|
373
|
-
* @param condition 查询条件
|
|
374
|
-
* @returns 查询快照
|
|
375
|
-
*/
|
|
376
|
-
createSnapshot(condition: QueryCondition): {
|
|
377
|
-
entities: Entity[];
|
|
378
|
-
timestamp: number;
|
|
379
|
-
condition: QueryCondition;
|
|
380
|
-
};
|
|
381
|
-
/**
|
|
382
|
-
* 比较两个查询快照
|
|
383
|
-
* @param snapshot1 第一个快照
|
|
384
|
-
* @param snapshot2 第二个快照
|
|
385
|
-
* @returns 比较结果
|
|
386
|
-
*/
|
|
387
|
-
compareSnapshots(snapshot1: ReturnType<QuerySystem['createSnapshot']>, snapshot2: ReturnType<QuerySystem['createSnapshot']>): {
|
|
388
|
-
added: Entity[];
|
|
389
|
-
removed: Entity[];
|
|
390
|
-
unchanged: Entity[];
|
|
352
|
+
accelerationStatus: ReturnType<QuerySystem['getAccelerationStatus']>;
|
|
353
|
+
queryStats: {
|
|
354
|
+
totalQueries: number;
|
|
355
|
+
cacheHits: number;
|
|
356
|
+
indexHits: number;
|
|
357
|
+
linearScans: number;
|
|
358
|
+
cacheHitRate: string;
|
|
359
|
+
};
|
|
391
360
|
};
|
|
392
|
-
/**
|
|
393
|
-
* 执行并行查询
|
|
394
|
-
* @param conditions 查询条件数组
|
|
395
|
-
* @returns Promise<查询结果数组>
|
|
396
|
-
*/
|
|
397
|
-
parallelQuery(conditions: QueryCondition[]): Promise<QueryResult[]>;
|
|
398
|
-
/**
|
|
399
|
-
* 获取查询建议
|
|
400
|
-
* @param entities 实体数组
|
|
401
|
-
* @returns 查询优化建议
|
|
402
|
-
*/
|
|
403
|
-
getQuerySuggestions(entities: Entity[]): string[];
|
|
404
|
-
/**
|
|
405
|
-
* 导出查询统计数据
|
|
406
|
-
* @returns 统计数据的JSON字符串
|
|
407
|
-
*/
|
|
408
|
-
exportStats(): string;
|
|
409
|
-
/**
|
|
410
|
-
* 导入查询统计数据
|
|
411
|
-
* @param statsJson 统计数据的JSON字符串
|
|
412
|
-
*/
|
|
413
|
-
importStats(statsJson: string): void;
|
|
414
361
|
}
|
|
415
362
|
/**
|
|
416
|
-
*
|
|
417
|
-
*
|
|
363
|
+
* 查询构建器
|
|
364
|
+
*
|
|
365
|
+
* 提供链式API来构建复杂的实体查询条件。
|
|
366
|
+
* 支持组合多种查询条件,创建灵活的查询表达式。
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* const result = new QueryBuilder(querySystem)
|
|
371
|
+
* .withAll(PositionComponent, VelocityComponent)
|
|
372
|
+
* .without(DeadComponent)
|
|
373
|
+
* .execute();
|
|
374
|
+
* ```
|
|
418
375
|
*/
|
|
419
376
|
export declare class QueryBuilder {
|
|
420
377
|
private conditions;
|
|
421
378
|
private querySystem;
|
|
422
379
|
constructor(querySystem: QuerySystem);
|
|
423
380
|
/**
|
|
424
|
-
* 添加"
|
|
425
|
-
*
|
|
426
|
-
* @
|
|
381
|
+
* 添加"必须包含所有组件"条件
|
|
382
|
+
*
|
|
383
|
+
* @param componentTypes 必须包含的组件类型
|
|
384
|
+
* @returns 查询构建器实例,支持链式调用
|
|
427
385
|
*/
|
|
428
386
|
withAll(...componentTypes: ComponentType[]): QueryBuilder;
|
|
429
387
|
/**
|
|
430
|
-
* 添加"
|
|
431
|
-
*
|
|
432
|
-
* @
|
|
388
|
+
* 添加"必须包含任意组件"条件
|
|
389
|
+
*
|
|
390
|
+
* @param componentTypes 必须包含其中任意一个的组件类型
|
|
391
|
+
* @returns 查询构建器实例,支持链式调用
|
|
433
392
|
*/
|
|
434
393
|
withAny(...componentTypes: ComponentType[]): QueryBuilder;
|
|
435
394
|
/**
|
|
436
|
-
* 添加"
|
|
437
|
-
*
|
|
438
|
-
* @
|
|
395
|
+
* 添加"不能包含任何组件"条件
|
|
396
|
+
*
|
|
397
|
+
* @param componentTypes 不能包含的组件类型
|
|
398
|
+
* @returns 查询构建器实例,支持链式调用
|
|
439
399
|
*/
|
|
440
400
|
without(...componentTypes: ComponentType[]): QueryBuilder;
|
|
441
401
|
/**
|
|
442
|
-
*
|
|
443
|
-
*
|
|
402
|
+
* 执行查询并返回结果
|
|
403
|
+
*
|
|
404
|
+
* 根据已添加的查询条件执行实体查询。
|
|
405
|
+
*
|
|
406
|
+
* @returns 查询结果,包含匹配的实体和性能信息
|
|
444
407
|
*/
|
|
445
408
|
execute(): QueryResult;
|
|
446
409
|
/**
|
|
447
|
-
*
|
|
448
|
-
* @returns 实体或null
|
|
449
|
-
*/
|
|
450
|
-
first(): Entity | null;
|
|
451
|
-
/**
|
|
452
|
-
* 检查是否有匹配的实体
|
|
453
|
-
* @returns 是否有匹配
|
|
454
|
-
*/
|
|
455
|
-
any(): boolean;
|
|
456
|
-
/**
|
|
457
|
-
* 获取匹配实体的数量
|
|
458
|
-
* @returns 实体数量
|
|
459
|
-
*/
|
|
460
|
-
count(): number;
|
|
461
|
-
/**
|
|
462
|
-
* 对每个匹配的实体执行操作
|
|
463
|
-
* @param callback 回调函数
|
|
410
|
+
* 创建组件掩码
|
|
464
411
|
*/
|
|
465
|
-
|
|
412
|
+
private createComponentMask;
|
|
466
413
|
/**
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
* 创建组件类型的位掩码
|
|
473
|
-
* @param componentTypes 组件类型数组
|
|
474
|
-
* @returns 位掩码
|
|
475
|
-
*/
|
|
476
|
-
private createMask;
|
|
477
|
-
/**
|
|
478
|
-
* 重置查询条件
|
|
479
|
-
* @returns 查询构建器
|
|
414
|
+
* 重置查询构建器
|
|
415
|
+
*
|
|
416
|
+
* 清除所有已添加的查询条件,重新开始构建查询。
|
|
417
|
+
*
|
|
418
|
+
* @returns 查询构建器实例,支持链式调用
|
|
480
419
|
*/
|
|
481
420
|
reset(): QueryBuilder;
|
|
482
|
-
private tagFilter?;
|
|
483
|
-
private nameFilter?;
|
|
484
|
-
private limitCount?;
|
|
485
|
-
private offsetCount?;
|
|
486
|
-
private sortFunction?;
|
|
487
|
-
/**
|
|
488
|
-
* 添加标签过滤条件
|
|
489
|
-
* @param tag 标签
|
|
490
|
-
* @returns 查询构建器实例
|
|
491
|
-
*/
|
|
492
|
-
withTag(tag: number): QueryBuilder;
|
|
493
|
-
/**
|
|
494
|
-
* 添加名称过滤条件
|
|
495
|
-
* @param name 名称
|
|
496
|
-
* @returns 查询构建器实例
|
|
497
|
-
*/
|
|
498
|
-
withName(name: string): QueryBuilder;
|
|
499
|
-
/**
|
|
500
|
-
* 限制结果数量
|
|
501
|
-
* @param limit 最大结果数量
|
|
502
|
-
* @returns 查询构建器实例
|
|
503
|
-
*/
|
|
504
|
-
limit(limit: number): QueryBuilder;
|
|
505
|
-
/**
|
|
506
|
-
* 跳过指定数量的结果
|
|
507
|
-
* @param offset 跳过的数量
|
|
508
|
-
* @returns 查询构建器实例
|
|
509
|
-
*/
|
|
510
|
-
offset(offset: number): QueryBuilder;
|
|
511
|
-
/**
|
|
512
|
-
* 对结果进行排序
|
|
513
|
-
* @param compareFn 比较函数
|
|
514
|
-
* @returns 查询构建器实例
|
|
515
|
-
*/
|
|
516
|
-
orderBy(compareFn: (a: Entity, b: Entity) => number): QueryBuilder;
|
|
517
|
-
/**
|
|
518
|
-
* 按更新顺序排序
|
|
519
|
-
* @returns 查询构建器实例
|
|
520
|
-
*/
|
|
521
|
-
orderByUpdateOrder(): QueryBuilder;
|
|
522
|
-
/**
|
|
523
|
-
* 按ID排序
|
|
524
|
-
* @returns 查询构建器实例
|
|
525
|
-
*/
|
|
526
|
-
orderById(): QueryBuilder;
|
|
527
|
-
/**
|
|
528
|
-
* 按名称排序
|
|
529
|
-
* @returns 查询构建器实例
|
|
530
|
-
*/
|
|
531
|
-
orderByName(): QueryBuilder;
|
|
532
|
-
/**
|
|
533
|
-
* 克隆查询构建器
|
|
534
|
-
* @returns 新的查询构建器
|
|
535
|
-
*/
|
|
536
|
-
clone(): QueryBuilder;
|
|
537
|
-
/**
|
|
538
|
-
* 添加自定义过滤器
|
|
539
|
-
* @param predicate 过滤谓词
|
|
540
|
-
* @returns 查询构建器实例
|
|
541
|
-
*/
|
|
542
|
-
filter(predicate: (entity: Entity) => boolean): QueryBuilder;
|
|
543
|
-
/**
|
|
544
|
-
* 映射查询结果
|
|
545
|
-
* @param mapper 映射函数
|
|
546
|
-
* @returns 映射后的结果数组
|
|
547
|
-
*/
|
|
548
|
-
map<T>(mapper: (entity: Entity) => T): T[];
|
|
549
|
-
/**
|
|
550
|
-
* 查找第一个满足条件的实体
|
|
551
|
-
* @param predicate 查找谓词
|
|
552
|
-
* @returns 实体或null
|
|
553
|
-
*/
|
|
554
|
-
find(predicate?: (entity: Entity) => boolean): Entity | null;
|
|
555
|
-
/**
|
|
556
|
-
* 检查是否所有实体都满足条件
|
|
557
|
-
* @param predicate 检查谓词
|
|
558
|
-
* @returns 是否所有实体都满足条件
|
|
559
|
-
*/
|
|
560
|
-
every(predicate: (entity: Entity) => boolean): boolean;
|
|
561
|
-
/**
|
|
562
|
-
* 检查是否有实体满足条件
|
|
563
|
-
* @param predicate 检查谓词
|
|
564
|
-
* @returns 是否有实体满足条件
|
|
565
|
-
*/
|
|
566
|
-
some(predicate: (entity: Entity) => boolean): boolean;
|
|
567
|
-
/**
|
|
568
|
-
* 获取查询的调试信息
|
|
569
|
-
* @returns 调试信息字符串
|
|
570
|
-
*/
|
|
571
|
-
getDebugInfo(): string;
|
|
572
421
|
}
|
|
573
|
-
export {};
|
|
574
422
|
//# sourceMappingURL=QuerySystem.d.ts.map
|